From bbb60e4fefdd404d8d696369804b556b404bb0c1 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 30 Nov 2009 12:24:59 -0500 Subject: [PATCH] libext2fs: Improve flex_bg inode table placement algorithm When trying to find the best place for the inode table in the last flex block group, use the true size for the flex_bg's portion of the inode table instead of the worst case required size of the inode table fragment if the file system is resized. This fixes a corner case where if the size of the filesystem is just big enough that there is only room for a single block group in the last flex_bg, and that partial block group is too small for the full portion of the inode table, the inode table is placed in the very first block group: Group 64: (Blocks 2097152-2099199) [INODE_UNINIT, ITABLE_ZEROED] Checksum 0xd305, unused inodes 8080 Block bitmap at 2097152 (+0), Inode bitmap at 2097168 (+16) Inode table at 8626-9130 (+4292878770) ^^^^^^^^^ Thanks to Vyacheslav Dubeyko for pointing this out. Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/alloc_tables.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c index 8547ad6..55e6174 100644 --- a/lib/ext2fs/alloc_tables.c +++ b/lib/ext2fs/alloc_tables.c @@ -181,6 +181,8 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, blk_t prev_block = 0; if (group && fs->group_desc[group-1].bg_inode_table) prev_block = fs->group_desc[group-1].bg_inode_table; + if (last_grp == fs->group_desc_count) + rem_grps = last_grp - group; group_blk = flexbg_offset(fs, group, prev_block, bmap, flexbg_size * 2, fs->inode_blocks_per_group * -- 1.8.3.1