path: root/mkfs.c
diff options
authorJan Kara <>2012-02-10 11:49:19 +0100
committerChris Mason <>2012-07-03 16:27:46 -0400
commit1ee733a9ca10f5dc4c7954efcc18f9033abbe218 (patch)
tree0ee4853a1cbe5992546eae2b8a1c58c29f9bcb15 /mkfs.c
parentff2b80b460bbb5ff85f543661be218ffab0e286b (diff)
mkfs: Handle creation of filesystem larger than the first device
On Wed 08-02-12 22:05:26, Phillip Susi wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 02/08/2012 06:20 PM, Jan Kara wrote: > > Thanks for your reply. I admit I was not sure what exactly size argument > > should be. So after looking into the code for a while I figured it should > > be a total size of the filesystem - or differently it should be size of > > virtual block address space in the filesystem. Thus when filesystem has > > more devices (or admin wants to add more devices later), it can be larger > > than the first device. But I'm not really a btrfs developper so I might be > > wrong and of course feel free to fix the issue as you deem fit. > > The size of the fs is the total size of the individual disks. When you > limit the size, you limit the size of a disk, not the whole fs. IIRC, > mkfs initializes the fs on the first disk, which is why it was using that > size as the size of the whole fs, and then adds the other disks after ( > which then add their size to the total fs size ). OK, I missed that btrfs_add_to_fsid() increases total size of the filesystem. So now I agree with you. New patch is attached. Thanks for your review. > It might be nice if > mkfs could take sizes for each disk, but it only seems to take one size > for the initial disk. Yes, but I don't see a realistic usecase so I don't think it's really worth the work. Honza -- Jan Kara <> SUSE Labs, CR >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 <>
Diffstat (limited to 'mkfs.c')
1 files changed, 4 insertions, 0 deletions
diff --git a/mkfs.c b/mkfs.c
index 4aff2fd5..aa508198 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1313,6 +1313,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++];