ext2resize fix how to calculate an offset
PATCH 21/24 ext2resize fix how to calculate an offset
Summary of this patch:
[21/24] fix the bug that an offset of an inode table is erroneously
calculated
- Running ext2resize results in failure due to an erroneous offset of an inode table, then I fix how to calculate it.
Signed-off-by Takashi Sato [email protected]
---
a/ext2resize-1.1.19/src/ext2_block_relocator.c renamed from src/ext2_block_relocator.c +4 -0
@@ -496,6 +496,10 @@ static int ext2_block_relocator_grab_bloint raid_bb, raid_ib;int itend = state->newallocoffset; +if (!ext2_bg_has_super (fs, group)) + itend = fs->gd[group].bg_inode_table + +fs->inodeblocks - start; + bpg = fs->sb.s_blocks_per_group;if (start + bpg > fs->newblocks) bpg = fs->newblocks - start;
a/ext2resize-1.1.19/src/ext2.h renamed from src/ext2.h +1 -1
@@ -262,7 +262,7 @@ static int __inline__ ext2_is_data_block group = blk / fs->sb.s_blocks_per_group; blk %= fs->sb.s_blocks_per_group; -if (ext2_bg_has_super (fs, group) && blk <= fs->gdblocks) +if (ext2_bg_has_super (fs, group) && blk <= fs->gdblocks + fs->resgdblocks)return 0 ; if (block == fs->gd[group].bg_block_bitmap ||
a/ext2resize-1.1.19/src/ext2_meta.c renamed from src/ext2_meta.c +7 -3
@@ -109,6 +109,12 @@ int ext2_metadata_push(struct ext2_fs *fint has_sb;int diff; + has_sb =ext2_bg_has_super (fs, group); +if (!has_sb) + new_itoffset =2 ; +else + new_itoffset = fs->newgdblocks +3 ; + diff = start + new_itoffset - fs->gd[group].bg_inode_table; old_itend =fs->gd[group].bg_inode_table +fs->inodeblocks -start; new_itend = new_itoffset + fs->inodeblocks;
@@ -116,8 +122,6 @@ int ext2_metadata_push(struct ext2_fs *fif (start + bpg > fs->sb.s_blocks_count) bpg = fs->sb.s_blocks_count - start; - has_sb =ext2_bg_has_super (fs, group); - bb = fs->gd[group].bg_block_bitmap - start; ib = fs->gd[group].bg_inode_bitmap - start;if (fs->stride) {
@@ -187,7 +191,7 @@ int ext2_metadata_push(struct ext2_fs *f group + 1, fs->numgroups); } - fs->itoffset = new_itoffset; + fs->itoffset = fs->newgdblocks +3 ;if (fs->flags &FL_VERBOSE )printf ("\n" );
a/ext2resize-1.1.19/src/ext2_resize.c renamed from src/ext2_resize.c +7 -3
@@ -157,7 +157,7 @@ static int ext2_add_group(struct ext2_fsreturn 1 ; } -static int ext2_del_group (struct ext2_fs *fs) +static int ext2_del_group (struct ext2_fs *fs,int old_gdblocks) {blk_t admin;int group = fs->numgroups -1 ;
@@ -170,7 +170,7 @@ static int ext2_del_group(struct ext2_fs has_sb =ext2_bg_has_super (fs, group); - admin = fs->inodeblocks + (has_sb ? fs->gdblocks +3 :2 ); + admin = fs->inodeblocks + (has_sb ? old_gdblocks +3 :2 ); bpg = fs->sb.s_blocks_count - fs->sb.s_first_data_block - group * fs->sb.s_blocks_per_group;
@@ -407,6 +407,8 @@ static int ext2_grow_fs(struct ext2_fs *static int ext2_shrink_fs (struct ext2_fs *fs) { +int old_gdblocks; +if (fs->flags &FL_DEBUG )printf ("%s\n" , __FUNCTION__);
@@ -435,6 +437,8 @@ static int ext2_shrink_fs(struct ext2_fsif (!ext2_block_relocate (fs))return 0 ; + old_gdblocks = fs->gdblocks; +while (fs->sb.s_blocks_count > fs->newblocks) {blk_t sizelast = (fs->sb.s_blocks_count - fs->sb.s_first_data_block) -
@@ -445,7 +449,7 @@ static int ext2_shrink_fs(struct ext2_fs fs->sb.s_blocks_count))return 0 ; }else { -if (!ext2_del_group (fs)) +if (!ext2_del_group (fs, old_gdblocks))return 0 ; } }