From: Theodore Ts'o Date: Tue, 1 Oct 2013 02:35:14 +0000 (-0400) Subject: resize2fs: fix -M size calculations to avoid cutting off the inode table X-Git-Tag: v1.42.9~143 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2215293c7e85c88d2fbc06f9e9438fca9a25213c;p=thirdparty%2Fe2fsprogs.git resize2fs: fix -M size calculations to avoid cutting off the inode table If the file system's inode table blocks in the last block group are located in the middle or the end of the block group, it's possible for resize2fs -M to use a size which will require relocating the inode table blocks in the last block group. This can lead to all sorts of problems, so solve it by simply guaranteeing that we will never do that. Reported-by: Eric Sandeen Signed-off-by: "Theodore Ts'o" --- diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 51b85b816..1e4ac1920 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -2224,6 +2224,15 @@ blk64_t calculate_minimum_resize_size(ext2_filsys fs, int flags) blks_needed = (groups-1) * EXT2_BLOCKS_PER_GROUP(fs->super); blks_needed += overhead; + /* + * Make sure blks_needed covers the end of the inode table in + * the last block group. + */ + overhead = ext2fs_inode_table_loc(fs, groups-1) + + fs->inode_blocks_per_group; + if (blks_needed < overhead) + blks_needed = overhead; + #ifdef RESIZE2FS_DEBUG if (flags & RESIZE_DEBUG_MIN_CALC) printf("Estimated blocks needed: %llu\n", blks_needed);