From: Eric Sandeen Date: Tue, 12 Sep 2006 18:56:16 +0000 (-0400) Subject: Create new ext2fs library inlines: ext2fs_group_{first,last}_block() X-Git-Tag: E2FSPROGS-1_40-WIP-1114~51 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=abf23439d51a3ddbca475b931abebd381ff7ceea;p=tools%2Fe2fsprogs.git Create new ext2fs library inlines: ext2fs_group_{first,last}_block() Create new ext2fs library inline functions in order to calculate the starting and ending blocks in a block group. Signed-off-by: Eric Sandeen --- diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 48920d5..e934899 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,5 +1,11 @@ 2006-08-30 Eric Sandeen + * pass1.c (new_table_block, handle_fs_bad_blocks): + * super.c (check_super_block): + Use new inlines to calculate group first & last blocks. + +2006-08-30 Eric Sandeen + * e2fsck.h (e2fsck): Use unsigned types for filesystem counters. * emptydir.c (add_empty_dirblock): * iscan.c (main): diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index 4065466..e6778af 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -1890,6 +1890,7 @@ static void new_table_block(e2fsck_t ctx, blk_t first_block, int group, { ext2_filsys fs = ctx->fs; blk_t old_block = *new_block; + blk_t last_block; int i; char *buf; struct problem_context pctx; @@ -1900,8 +1901,8 @@ static void new_table_block(e2fsck_t ctx, blk_t first_block, int group, pctx.blk = old_block; pctx.str = name; - pctx.errcode = ext2fs_get_free_blocks(fs, first_block, - first_block + fs->super->s_blocks_per_group, + last_block = ext2fs_group_last_block(fs, group); + pctx.errcode = ext2fs_get_free_blocks(fs, first_block, last_block, num, ctx->block_found_map, new_block); if (pctx.errcode) { pctx.num = num; @@ -1952,9 +1953,11 @@ static void handle_fs_bad_blocks(e2fsck_t ctx) { ext2_filsys fs = ctx->fs; dgrp_t i; - int first_block = fs->super->s_first_data_block; + int first_block; for (i = 0; i < fs->group_desc_count; i++) { + first_block = ext2fs_group_first_block(fs, i); + if (ctx->invalid_block_bitmap_flag[i]) { new_table_block(ctx, first_block, i, _("block bitmap"), 1, &fs->group_desc[i].bg_block_bitmap); @@ -1969,7 +1972,6 @@ static void handle_fs_bad_blocks(e2fsck_t ctx) &fs->group_desc[i].bg_inode_table); ctx->flags |= E2F_FLAG_RESTART; } - first_block += fs->super->s_blocks_per_group; } ctx->invalid_bitmaps = 0; } diff --git a/e2fsck/super.c b/e2fsck/super.c index ab11cbb..ae40531 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -569,11 +569,9 @@ void check_super_block(e2fsck_t ctx) for (i = 0, gd=fs->group_desc; i < fs->group_desc_count; i++, gd++) { pctx.group = i; - - if (i == fs->group_desc_count - 1) - last_block = sb->s_blocks_count - 1; - else - last_block = first_block + blocks_per_group - 1; + + first_block = ext2fs_group_first_block(fs, i); + last_block = ext2fs_group_last_block(fs, i); if ((gd->bg_block_bitmap < first_block) || (gd->bg_block_bitmap > last_block)) { @@ -608,7 +606,6 @@ void check_super_block(e2fsck_t ctx) } free_blocks += gd->bg_free_blocks_count; free_inodes += gd->bg_free_inodes_count; - first_block += sb->s_blocks_per_group; if ((gd->bg_free_blocks_count > sb->s_blocks_per_group) || (gd->bg_free_inodes_count > sb->s_inodes_per_group) || diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 1cf2040..ddd6e9f 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,5 +1,13 @@ 2006-08-30 Eric Sandeen + * alloc_tables.c (ext2fs_allocate_group_table): + * check_desc.c (ext2fs_check_desc): + Use new inlines to calculate group first & last blocks. + * ext2fs.h: + Create new inlines to calculate first/last group blocks. + +2006-08-30 Eric Sandeen + * bmove.c (process_block): * getsize.c (main): * icount.c (ext2fs_create_icount2, insert_icount_el): diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c index dec49bd..4ad2ba9 100644 --- a/lib/ext2fs/alloc_tables.c +++ b/lib/ext2fs/alloc_tables.c @@ -34,12 +34,8 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, blk_t group_blk, start_blk, last_blk, new_blk, blk; int j; - group_blk = fs->super->s_first_data_block + - (group * fs->super->s_blocks_per_group); - - last_blk = group_blk + fs->super->s_blocks_per_group; - if (last_blk >= fs->super->s_blocks_count) - last_blk = fs->super->s_blocks_count - 1; + group_blk = ext2fs_group_first_block(fs, group); + last_blk = ext2fs_group_last_block(fs, group); if (!bmap) bmap = fs->block_map; @@ -54,8 +50,8 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group, return retval; start_blk += fs->inode_blocks_per_group; start_blk += ((fs->stride * group) % - (last_blk - start_blk)); - if (start_blk > last_blk) + (last_blk - start_blk + 1)); + if (start_blk >= last_blk) start_blk = group_blk; } else start_blk = group_blk; diff --git a/lib/ext2fs/check_desc.c b/lib/ext2fs/check_desc.c index 2dd982e..3150d3e 100644 --- a/lib/ext2fs/check_desc.c +++ b/lib/ext2fs/check_desc.c @@ -38,11 +38,9 @@ errcode_t ext2fs_check_desc(ext2_filsys fs) EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS); for (i = 0; i < fs->group_desc_count; i++) { - if (i == fs->group_desc_count - 1) - last_block = fs->super->s_blocks_count - 1; - else - last_block = first_block + - fs->super->s_blocks_per_group - 1; + first_block = ext2fs_group_first_block(fs, i); + last_block = ext2fs_group_last_block(fs, i); + /* * Check to make sure block bitmap for group is * located within the group. @@ -65,8 +63,6 @@ errcode_t ext2fs_check_desc(ext2_filsys fs) ((fs->group_desc[i].bg_inode_table + fs->inode_blocks_per_group) > last_block)) return EXT2_ET_GDESC_BAD_INODE_TABLE; - - first_block += fs->super->s_blocks_per_group; } return 0; } diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 8ca5723..87026f2 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -963,6 +963,8 @@ extern int ext2fs_test_ib_dirty(ext2_filsys fs); extern int ext2fs_test_bb_dirty(ext2_filsys fs); extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk); extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino); +extern blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group); +extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group); extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs, struct ext2_inode *inode); extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b); @@ -1127,6 +1129,26 @@ _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) return (ino - 1) / fs->super->s_inodes_per_group; } +/* + * Return the first block (inclusive) in a group + */ +_INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group) +{ + return fs->super->s_first_data_block + + (group * fs->super->s_blocks_per_group); +} + +/* + * Return the last block (inclusive) in a group + */ +_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group) +{ + return (group == fs->group_desc_count - 1 ? + fs->super->s_blocks_count - 1 : + ext2fs_group_first_block(fs, group) + + (fs->super->s_blocks_per_group - 1)); +} + _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs, struct ext2_inode *inode) { diff --git a/misc/ChangeLog b/misc/ChangeLog index da27353..b53fce6 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,5 +1,10 @@ 2006-08-30 Eric Sandeen + * dumpe2fs.c (list_desc): Use new inlines to calculate group + first & last blocks. + +2006-08-30 Eric Sandeen + * dumpe2fs.c (list_bad_blocks): * e2image.c (output_meta_data_blocks, write_raw_image_file): * mke2fs.c (test_disk, handle_bad_blocks): Fix printf formats. diff --git a/misc/dumpe2fs.c b/misc/dumpe2fs.c index 4488339..68e8850 100644 --- a/misc/dumpe2fs.c +++ b/misc/dumpe2fs.c @@ -153,13 +153,11 @@ static void list_desc (ext2_filsys fs) else old_desc_blocks = fs->desc_blocks; for (i = 0; i < fs->group_desc_count; i++) { + first_block = ext2fs_group_first_block(fs, i); + last_block = ext2fs_group_last_block(fs, i); + ext2fs_super_and_bgd_loc(fs, i, &super_blk, &old_desc_blk, &new_desc_blk, 0); - if (i == fs->group_desc_count - 1) - last_block = fs->super->s_blocks_count - 1; - else - last_block = first_block + - fs->super->s_blocks_per_group - 1; printf (_("Group %lu: (Blocks "), i); print_range(first_block, last_block); @@ -226,7 +224,6 @@ static void list_desc (ext2_filsys fs) fputc('\n', stdout); inode_bitmap += fs->super->s_inodes_per_group / 8; } - first_block += fs->super->s_blocks_per_group; } } diff --git a/tests/ChangeLog b/tests/ChangeLog index b44a717..6c9152a 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2006-08-30 Eric Sandeen + + * m_raid_opt/expect.1: + Change expected values for last group due to correctly + calculated last block when using strides. + 2006-08-06 Theodore Tso * Makefile.in, test_config: If available, use unified diffs to diff --git a/tests/m_raid_opt/expect.1 b/tests/m_raid_opt/expect.1 index 590879a..44c5b46 100644 --- a/tests/m_raid_opt/expect.1 +++ b/tests/m_raid_opt/expect.1 @@ -944,8 +944,8 @@ Group 126: (Blocks 129025-130048) Free inodes: 32257-32512 Group 127: (Blocks 130049-131071) Group descriptor at 130049 - Block bitmap at 130744 (+695), Inode bitmap at 130745 (+696) + Block bitmap at 130743 (+694), Inode bitmap at 130744 (+695) Inode table at 130050-130081 (+1) 988 free blocks, 256 free inodes, 0 directories - Free blocks: 130082-130743, 130746-131071 + Free blocks: 130082-130742, 130745-131071 Free inodes: 32513-32768