>From e5f46872232520310c56327593c02ef6a7f5ea33 Mon Sep 17 00:00:00 2001 From: Jan Kara Date: Fri, 10 Feb 2012 11:44:44 +0100 Subject: [PATCH] mkfs: Handle creation of filesystem larger than the first device mkfs does not properly check requested size of the filesystem. Thus if the requested size is larger than the first device, it happily creates larger filesystem than a device it resides on which results in 'attemp to access beyond end of device' messages from the kernel. So verify specified filesystem size against the size of the first device. CC: David Sterba Signed-off-by: Jan Kara --- mkfs.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/mkfs.c b/mkfs.c index e3ced19..3afe9eb 100644 --- a/mkfs.c +++ b/mkfs.c @@ -1282,6 +1282,10 @@ int main(int ac, char **av) ret = btrfs_prepare_device(fd, file, zero_end, &dev_block_count, &mixed); if (block_count == 0) block_count = dev_block_count; + else if (block_count > dev_block_count) { + fprintf(stderr, "%s is smaller than requested size\n", file); + exit(1); + } } else { ac = 0; file = av[optind++]; -- 1.7.1