2008-04-23 16:38:52

by Celine Bourde

[permalink] [raw]
Subject: flexbg metadata offset


There is a problem on offset metadata. In all flexbg groups the block
between the last block bitmap and the first inode bitmap is not used,
which introduces a hole.

This patch changes this. It corrects the offset of flexbg metadata,
specifically at the end of the disk, if the number of groups isn't
a multiple of the -G option argument.

C?line Bourde.

Signed-off-by: Bourde Celine <[email protected]>

diff -r -u a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c
--- a/lib/ext2fs/alloc_tables.c 2008-04-23 17:32:39.000000000 -0400
+++ b/lib/ext2fs/alloc_tables.c 2008-04-23 17:31:52.000000000 -0400
@@ -84,7 +84,7 @@
errcode_t retval;
blk_t group_blk, start_blk, last_blk, new_blk, blk;
dgrp_t last_grp;
- int j, rem_grps, flexbg_size = 0;
+ int j, rem_grps, flexbg_size = 0, last_flexbg_size = 0;

group_blk = ext2fs_group_first_block(fs, group);
last_blk = ext2fs_group_last_block(fs, group);
@@ -96,10 +96,14 @@
EXT4_FEATURE_INCOMPAT_FLEX_BG) &&
fs->super->s_log_groups_per_flex) {
flexbg_size = 1 << fs->super->s_log_groups_per_flex;
+ last_flexbg_size = fs->group_desc_count -
+ ((group / flexbg_size) * flexbg_size);
last_grp = group | (flexbg_size - 1);
- rem_grps = last_grp - group;
if (last_grp > fs->group_desc_count)
last_grp = fs->group_desc_count;
+ if (last_flexbg_size > flexbg_size)
+ last_flexbg_size = flexbg_size;
+ rem_grps = last_grp - group;
}

/*
@@ -151,7 +155,8 @@
if (group && fs->group_desc[group-1].bg_inode_bitmap)
prev_block = fs->group_desc[group-1].bg_inode_bitmap;
start_blk = flexbg_offset(fs, group, prev_block, bmap,
- flexbg_size, rem_grps);
+ last_flexbg_size - 1,
+ rem_grps);
last_blk = ext2fs_group_last_block(fs, last_grp);
}

@@ -182,7 +187,7 @@
if (group && fs->group_desc[group-1].bg_inode_table)
prev_block = fs->group_desc[group-1].bg_inode_table;
group_blk = flexbg_offset(fs, group, prev_block, bmap,
- flexbg_size * 2,
+ last_flexbg_size * 2 - 1,
fs->inode_blocks_per_group *
rem_grps);
last_blk = ext2fs_group_last_block(fs, last_grp);