Btrfs-progs: add missing write check for mkfs
authorFilipe David Borba Manana <fdmanana@gmail.com>
Wed, 3 Jul 2013 17:30:41 +0000 (18:30 +0100)
committerDavid Sterba <dsterba@suse.cz>
Fri, 9 Aug 2013 12:32:33 +0000 (14:32 +0200)
Assert that the writes of the device and chunk tree
roots succeed. This verification is currently done
for all other tree roots, however it was missing for
those 2 trees.

Would these tree root writes fail, but all others succeed,
it would lead to a corrupted/incomplete btrfs filesystem,
or, more likely some weird failure later on in mkfs.btrfs
inside open_ctree().

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
utils.c

diff --git a/utils.c b/utils.c
index ced85aa..3676c8c 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -346,6 +346,7 @@ int make_btrfs(int fd, const char *device, const char *label,
        btrfs_set_header_nritems(buf, nritems);
        csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
        ret = pwrite(fd, buf->data, leafsize, blocks[3]);
+       BUG_ON(ret != leafsize);
 
        /* create the device tree */
        memset(buf->data+sizeof(struct btrfs_header), 0,
@@ -381,6 +382,7 @@ int make_btrfs(int fd, const char *device, const char *label,
        btrfs_set_header_nritems(buf, nritems);
        csum_tree_block_size(buf, BTRFS_CRC32_SIZE, 0);
        ret = pwrite(fd, buf->data, leafsize, blocks[4]);
+       BUG_ON(ret != leafsize);
 
        /* create the FS root */
        memset(buf->data+sizeof(struct btrfs_header), 0,