]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Create new ext2fs library inlines: ext2fs_group_{first,last}_block()
authorEric Sandeen <esandeen@redhat.com>
Tue, 12 Sep 2006 18:56:16 +0000 (14:56 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 12 Sep 2006 18:56:16 +0000 (14:56 -0400)
Create new ext2fs library inline functions in order to calculate
the starting and ending blocks in a block group.

Signed-off-by: Eric Sandeen <esandeen@redhat.com>
e2fsck/ChangeLog
e2fsck/pass1.c
e2fsck/super.c
lib/ext2fs/ChangeLog
lib/ext2fs/alloc_tables.c
lib/ext2fs/check_desc.c
lib/ext2fs/ext2fs.h
misc/ChangeLog
misc/dumpe2fs.c
tests/ChangeLog
tests/m_raid_opt/expect.1

index 48920d5b6b7b8d9caf972bcc2213663fd3c1db24..e9348992a288e68734b4a163ebe5983f271dad9d 100644 (file)
@@ -1,3 +1,9 @@
+2006-08-30  Eric Sandeen <esandeen@redhat.com>
+
+       * 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 <esandeen@redhat.com>
 
        * e2fsck.h (e2fsck): Use unsigned types for filesystem counters.
index 40654662498e1158a34ffad5c4a5734831d24f5f..e6778af1f176dad98eb0c8c2225d3823a9cab61a 100644 (file)
@@ -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;
 }
index ab11cbb713fd040a0c934ce63cf36c7129c7e106..ae40531ccee40d160084b88b1ab6dbb1148a96b3 100644 (file)
@@ -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) ||
index 1cf2040e812fa7b188f333a751f2c875749caca9..ddd6e9f499df6bc17704aa2b913f8a83cd30abcd 100644 (file)
@@ -1,3 +1,11 @@
+2006-08-30  Eric Sandeen <esandeen@redhat.com>
+
+       * 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 <esandeen@redhat.com>
 
        * bmove.c (process_block):
index dec49bdae2681dba77e211b105f6066cbd6c5b96..4ad2ba9d0ab9c2c0e7258775abf3913690ec9923 100644 (file)
@@ -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;
index 2dd982ed0aa9597c0d9a451476fa6242fb4e1023..3150d3ee990ccf095d7428552a411c911f5af27f 100644 (file)
@@ -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;
 }
index 8ca5723fc7651cb324c036305ad8c8c8177d2576..87026f25dfd5b7f298ee409c1cea65b5ac2ceb15 100644 (file)
@@ -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)
 {
index da273533da5a241886b645802d8c561ba84d3800..b53fce69747ead80f33be9b63be262ef473c4446 100644 (file)
@@ -1,3 +1,8 @@
+2006-08-30  Eric Sandeen <esandeen@redhat.com>
+
+       * dumpe2fs.c (list_desc): Use new inlines to calculate group 
+               first & last blocks.
+
 2006-08-30  Eric Sandeen <esandeen@redhat.com>
 
        * dumpe2fs.c (list_bad_blocks):
index 448833990400c68e8b761dc54a5c91cfd521445e..68e885080dcbcaa0f2e93797fa298bfc612d4b2c 100644 (file)
@@ -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;
        }
 }
 
index b44a717b960b2b33dc0f508ee78fc9c4c7618fdc..6c9152a064d1c027c774e4ceaec008be53ef441a 100644 (file)
@@ -1,3 +1,9 @@
+2006-08-30  Eric Sandeen <esandeen@redhat.com>
+
+       * 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  <tytso@mit.edu>
 
        * Makefile.in, test_config: If available, use unified diffs to
index 590879a82be8e950212521ddcc4b27ef6a9d963b..44c5b46d2f7dc2619bf485e8bf53b75c1260030a 100644 (file)
@@ -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