Even if the size of rootdir given by -r option is larger than the
specified partition, zero_output_file() is still called. It will take
time to fill up the partition with zero if the partition is big, and
end up with an EIO.
The size should be checked before zeroing the partition.
Signed-off-by: Guangyu Sun <guangyu.sun@xxxxxxxxxx>
---
mkfs.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/mkfs.c b/mkfs.c
index 71aea40..ea61180 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1475,12 +1475,31 @@ int main(int ac, char **av)
exit(1);
}
} else {
+ struct stat st;
+ u64 size;
+
fd = open_target(file);
if (fd < 0) {
fprintf(stderr, "unable to open the %s\n", file);
exit(1);
}
+ if (fstat(fd, &st) < 0) {
+ fprintf(stderr, "unable to stat %s\n", file);
+ exit(1);
+ }
+
+ size = btrfs_device_size(fd, &st);
+ if (size == 0) {
+ fprintf(stderr, "unable to find %s size\n", file);
+ exit(1);
+ }
+
+ if (size < block_count) {
+ fprintf(stderr, "%s is smaller than requested size\n", file);
+ exit(1);
+ }
+
first_file = file;
ret = zero_output_file(fd, block_count, sectorsize);
if (ret) {
--
1.7.9.5
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html