From c58a08e673a10d0e5fa4855ca58ab2cbf48fd029 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 19 Jan 2009 08:43:36 -0500 Subject: [PATCH] resize2fs: Move all required blocks for ext4 filesystems In the function blocks_to_move(), when checking to see if a block group's block bitmap is initialized, we need to check the old_fs's block group descriptors, not the new file system's (already truncated) group descriptor data structures. Otherwise we will end up derferencing past the end of the array boundary, and the resulting garbage value may indicate that the bitmap is uninitialized, and so all of the blocks in that block group will be skipped, resulting in some blocks not getting marked as needing relocation. This showed up in the following test case: mke2fs -t ext4 -b 1024 test.img 1048576 resize2fs test.img 80000 The journal inode after the resize operation looked like this: debugfs: stat <8> Inode: 8 Type: regular Mode: 0600 Flags: 0x80000 ... BLOCKS: (IND):35385, (0-5836):2356-8192, (5837-21959):8454-24576, (21960-32506):24838-35 384, (32507-32767):434177-434437 TOTAL: 32769 The blocks 434177-434437 were not moved because block group 53 was wrongly thought to have an unitialized block group. Signed-off-by: "Theodore Ts'o" --- resize/resize2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resize/resize2fs.c b/resize/resize2fs.c index abe05f5..e7a08da 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -745,7 +745,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs) g = ext2fs_group_of_blk(fs, blk); if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super, EXT4_FEATURE_RO_COMPAT_GDT_CSUM) && - (fs->group_desc[g].bg_flags & EXT2_BG_BLOCK_UNINIT)) { + (old_fs->group_desc[g].bg_flags & EXT2_BG_BLOCK_UNINIT)) { /* * The block bitmap is uninitialized, so skip * to the next block group. -- 1.8.3.1