btrfs-progs: mkfs: check for sane sectorsize earlier
authorDavid Sterba <dsterba@suse.com>
Wed, 31 Aug 2016 18:16:35 +0000 (20:16 +0200)
committerDavid Sterba <dsterba@suse.com>
Wed, 21 Sep 2016 12:12:38 +0000 (14:12 +0200)
Signed-off-by: David Sterba <dsterba@suse.com>
mkfs.c
utils.c

diff --git a/mkfs.c b/mkfs.c
index 4b88987..a4b0ce7 100644 (file)
--- a/mkfs.c
+++ b/mkfs.c
@@ -1636,6 +1636,12 @@ int main(int argc, char **argv)
                                 features))
                exit(1);
 
+       if (sectorsize < sizeof(struct btrfs_super_block)) {
+               error("sectorsize smaller than superblock: %u < %zu",
+                               sectorsize, sizeof(struct btrfs_super_block));
+               exit(1);
+       }
+
        /* Check device/block_count after the nodesize is determined */
        if (block_count && block_count < btrfs_min_dev_size(nodesize)) {
                error("size %llu is too small to make a usable filesystem",
diff --git a/utils.c b/utils.c
index 393e573..e164fdd 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -1420,7 +1420,6 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg,
        }
 
        /* and write out the super block */
-       BUG_ON(sizeof(super) > cfg->sectorsize);
        memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
        memcpy(buf->data, &super, sizeof(super));
        buf->len = BTRFS_SUPER_INFO_SIZE;