Whamcloud - gitweb
Convert to use block group accessor functions
authorValerie Aurora Henson <vaurora@redhat.com>
Mon, 26 Oct 2009 01:43:47 +0000 (21:43 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 26 Oct 2009 01:43:47 +0000 (21:43 -0400)
Convert direct accesses to use the following block group accessor
functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(),
ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(),
ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(),
ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(),
ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(),
ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set()

Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: Nick Dokos <nicholas.dokos@hp.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
28 files changed:
debugfs/set_fields.c
e2fsck/journal.c
e2fsck/pass1.c
e2fsck/pass1b.c
e2fsck/pass2.c
e2fsck/pass5.c
e2fsck/super.c
lib/ext2fs/alloc.c
lib/ext2fs/alloc_stats.c
lib/ext2fs/alloc_tables.c
lib/ext2fs/check_desc.c
lib/ext2fs/closefs.c
lib/ext2fs/csum.c
lib/ext2fs/dblist.c
lib/ext2fs/imager.c
lib/ext2fs/initialize.c
lib/ext2fs/inode.c
lib/ext2fs/mkjournal.c
lib/ext2fs/openfs.c
lib/ext2fs/rw_bitmaps.c
lib/ext2fs/tst_iscan.c
misc/dumpe2fs.c
misc/e2image.c
misc/mke2fs.c
misc/tune2fs.c
resize/main.c
resize/online.c
resize/resize2fs.c

index 7ba7782..88cf411 100644 (file)
@@ -415,7 +415,10 @@ static errcode_t parse_gd_csum(struct field_set_info *info, char *arg)
 
        if (strcmp(arg, "calc") == 0) {
                ext2fs_group_desc_csum_set(current_fs, set_bg);
-               set_gd = current_fs->group_desc[set_bg];
+               memcpy(&set_gd, ext2fs_group_desc(current_fs,
+                                       current_fs->group_desc,
+                                       set_bg),
+                       sizeof(set_gd));
                printf("Checksum set to 0x%04x\n",
                       ext2fs_bg_checksum(current_fs, set_bg));
                return 0;
@@ -570,10 +573,14 @@ void do_set_block_group_descriptor(int argc, char *argv[])
                return;
        }
 
-       set_gd = current_fs->group_desc[set_bg];
+       memcpy(&set_gd, ext2fs_group_desc(current_fs,
+                               current_fs->group_desc, set_bg),
+               sizeof(set_gd));
 
        if (ss->func(ss, argv[3]) == 0) {
-               current_fs->group_desc[set_bg] = set_gd;
+               memcpy(ext2fs_group_desc(current_fs,
+                               current_fs->group_desc, set_bg),
+                      &set_gd, sizeof(set_gd));
                ext2fs_mark_super_dirty(current_fs);
        }
 }
index ffb1723..57783eb 100644 (file)
@@ -1011,7 +1011,7 @@ void e2fsck_move_ext3_journal(e2fsck_t ctx)
        group = ext2fs_group_of_ino(fs, ino);
        ext2fs_unmark_inode_bitmap2(fs->inode_map, ino);
        ext2fs_mark_ib_dirty(fs);
-       fs->group_desc[group].bg_free_inodes_count++;
+       ext2fs_bg_free_inodes_count_set(fs, group, ext2fs_bg_free_inodes_count(fs, group) + 1);
        ext2fs_group_desc_csum_set(fs, group);
        fs->super->s_free_inodes_count++;
        return;
index 46b155c..567d407 100644 (file)
@@ -2023,16 +2023,16 @@ static char *describe_illegal_block(ext2_filsys fs, blk_t block)
                                "of group %d", i);
                        break;
                }
-               if (block == fs->group_desc[i].bg_block_bitmap) {
+               if (block == ext2fs_block_bitmap_loc(fs, i)) {
                        sprintf(problem, "is the block bitmap of group %d", i);
                        break;
                }
-               if (block == fs->group_desc[i].bg_inode_bitmap) {
+               if (block == ext2fs_inode_bitmap_loc(fs, i)) {
                        sprintf(problem, "is the inode bitmap of group %d", i);
                        break;
                }
-               if (block >= fs->group_desc[i].bg_inode_table &&
-                   (block < fs->group_desc[i].bg_inode_table
+               if (block >= ext2fs_inode_table_loc(fs, i) &&
+                   (block < ext2fs_inode_table_loc(fs, i)
                     + fs->inode_blocks_per_group)) {
                        sprintf(problem, "is in the inode table of group %d",
                                i);
@@ -2322,22 +2322,22 @@ static int process_bad_block(ext2_filsys fs,
                        return 0;
                }
        skip_super:
-               if (blk == fs->group_desc[i].bg_block_bitmap) {
+               if (blk == ext2fs_block_bitmap_loc(fs, i)) {
                        if (fix_problem(ctx, PR_1_BB_BAD_BLOCK, pctx)) {
                                ctx->invalid_block_bitmap_flag[i]++;
                                ctx->invalid_bitmaps++;
                        }
                        return 0;
                }
-               if (blk == fs->group_desc[i].bg_inode_bitmap) {
+               if (blk == ext2fs_inode_bitmap_loc(fs, i)) {
                        if (fix_problem(ctx, PR_1_IB_BAD_BLOCK, pctx)) {
                                ctx->invalid_inode_bitmap_flag[i]++;
                                ctx->invalid_bitmaps++;
                        }
                        return 0;
                }
-               if ((blk >= fs->group_desc[i].bg_inode_table) &&
-                   (blk < (fs->group_desc[i].bg_inode_table +
+               if ((blk >= ext2fs_inode_table_loc(fs, i)) &&
+                   (blk < (ext2fs_inode_table_loc(fs, i) +
                            fs->inode_blocks_per_group))) {
                        /*
                         * If there are bad blocks in the inode table,
@@ -2520,8 +2520,8 @@ static void mark_table_blocks(e2fsck_t ctx)
                /*
                 * Mark the blocks used for the inode table
                 */
-               if (fs->group_desc[i].bg_inode_table) {
-                       for (j = 0, b = fs->group_desc[i].bg_inode_table;
+               if (ext2fs_inode_table_loc(fs, i)) {
+                       for (j = 0, b = ext2fs_inode_table_loc(fs, i);
                             j < fs->inode_blocks_per_group;
                             j++, b++) {
                                if (ext2fs_test_block_bitmap2(ctx->block_found_map,
@@ -2543,34 +2543,34 @@ static void mark_table_blocks(e2fsck_t ctx)
                /*
                 * Mark block used for the block bitmap
                 */
-               if (fs->group_desc[i].bg_block_bitmap) {
+               if (ext2fs_block_bitmap_loc(fs, i)) {
                        if (ext2fs_test_block_bitmap2(ctx->block_found_map,
-                                    fs->group_desc[i].bg_block_bitmap)) {
-                               pctx.blk = fs->group_desc[i].bg_block_bitmap;
+                                    ext2fs_block_bitmap_loc(fs, i))) {
+                               pctx.blk = ext2fs_block_bitmap_loc(fs, i);
                                if (fix_problem(ctx, PR_1_BB_CONFLICT, &pctx)) {
                                        ctx->invalid_block_bitmap_flag[i]++;
                                        ctx->invalid_bitmaps++;
                                }
                        } else {
                            ext2fs_mark_block_bitmap2(ctx->block_found_map,
-                                    fs->group_desc[i].bg_block_bitmap);
+                                    ext2fs_block_bitmap_loc(fs, i));
                    }
 
                }
                /*
                 * Mark block used for the inode bitmap
                 */
-               if (fs->group_desc[i].bg_inode_bitmap) {
+               if (ext2fs_inode_bitmap_loc(fs, i)) {
                        if (ext2fs_test_block_bitmap2(ctx->block_found_map,
-                                    fs->group_desc[i].bg_inode_bitmap)) {
-                               pctx.blk = fs->group_desc[i].bg_inode_bitmap;
+                                    ext2fs_inode_bitmap_loc(fs, i))) {
+                               pctx.blk = ext2fs_inode_bitmap_loc(fs, i);
                                if (fix_problem(ctx, PR_1_IB_CONFLICT, &pctx)) {
                                        ctx->invalid_inode_bitmap_flag[i]++;
                                        ctx->invalid_bitmaps++;
                                }
                        } else {
                            ext2fs_mark_block_bitmap2(ctx->block_found_map,
-                                    fs->group_desc[i].bg_inode_bitmap);
+                                    ext2fs_inode_bitmap_loc(fs, i));
                        }
                }
        }
index 003827d..5142367 100644 (file)
@@ -837,15 +837,15 @@ static int check_if_fs_block(e2fsck_t ctx, blk_t test_block)
                }
 
                /* Check the inode table */
-               if ((fs->group_desc[i].bg_inode_table) &&
-                   (test_block >= fs->group_desc[i].bg_inode_table) &&
-                   (test_block < (fs->group_desc[i].bg_inode_table +
+               if ((ext2fs_inode_table_loc(fs, i)) &&
+                   (test_block >= ext2fs_inode_table_loc(fs, i)) &&
+                   (test_block < (ext2fs_inode_table_loc(fs, i) +
                                   fs->inode_blocks_per_group)))
                        return 1;
 
                /* Check the bitmap blocks */
-               if ((test_block == fs->group_desc[i].bg_block_bitmap) ||
-                   (test_block == fs->group_desc[i].bg_inode_bitmap))
+               if ((test_block == ext2fs_block_bitmap_loc(fs, i)) ||
+                   (test_block == ext2fs_inode_bitmap_loc(fs, i)))
                        return 1;
 
                first_block += fs->super->s_blocks_per_group;
index cbf1457..df969ca 100644 (file)
@@ -976,7 +976,7 @@ out_htree:
                group = ext2fs_group_of_ino(fs, dirent->inode);
                first_unused_inode = group * fs->super->s_inodes_per_group +
                                        1 + fs->super->s_inodes_per_group -
-                                       fs->group_desc[group].bg_itable_unused;
+                                       ext2fs_bg_itable_unused(fs, group);
                cd->pctx.group = group;
 
                /*
@@ -1003,7 +1003,7 @@ out_htree:
                } else if (dirent->inode >= first_unused_inode) {
                        pctx.num = dirent->inode;
                        if (fix_problem(ctx, PR_2_INOREF_IN_UNUSED, &cd->pctx)){
-                               fs->group_desc[group].bg_itable_unused = 0;
+                               ext2fs_bg_itable_unused_set(fs, group, 0);
                                ext2fs_mark_super_dirty(fs);
                                ctx->flags |= E2F_FLAG_RESTART_LATER;
                        } else {
index ef8e141..b22a838 100644 (file)
@@ -196,15 +196,15 @@ redo_counts:
 
                        bitmap = 0;
                        if ((i == super_blk) ||
-                               (old_desc_blk && old_desc_blocks &&
-                               (i >= old_desc_blk) &&
-                               (i < old_desc_blk + old_desc_blocks)) ||
-                               (new_desc_blk && (i == new_desc_blk)) ||
-                               (i == fs->group_desc[group].bg_block_bitmap) ||
-                               (i == fs->group_desc[group].bg_inode_bitmap) ||
-                               (i >= fs->group_desc[group].bg_inode_table &&
-                               (i < fs->group_desc[group].bg_inode_table +
-                                       fs->inode_blocks_per_group))) {
+                           (old_desc_blk && old_desc_blocks &&
+                            (i >= old_desc_blk) &&
+                            (i < old_desc_blk + old_desc_blocks)) ||
+                           (new_desc_blk && (i == new_desc_blk)) ||
+                           (i == ext2fs_block_bitmap_loc(fs, group)) ||
+                           (i == ext2fs_inode_bitmap_loc(fs, group)) ||
+                           (i >= ext2fs_inode_table_loc(fs, group) &&
+                            (i < ext2fs_inode_table_loc(fs, group) +
+                             fs->inode_blocks_per_group))) {
                                bitmap = 1;
                                actual = (actual != 0);
                                count++;
@@ -335,9 +335,9 @@ redo_counts:
                ext2fs_unmark_valid(fs);
 
        for (i = 0; i < fs->group_desc_count; i++) {
-               if (free_array[i] != fs->group_desc[i].bg_free_blocks_count) {
+               if (free_array[i] != ext2fs_bg_free_blocks_count(fs, i)) {
                        pctx.group = i;
-                       pctx.blk = fs->group_desc[i].bg_free_blocks_count;
+                       pctx.blk = ext2fs_bg_free_blocks_count(fs, i);
                        pctx.blk2 = free_array[i];
 
                        if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT_GROUP,
@@ -564,27 +564,25 @@ do_counts:
                ext2fs_unmark_valid(fs);
 
        for (i = 0; i < fs->group_desc_count; i++) {
-               if (free_array[i] != fs->group_desc[i].bg_free_inodes_count) {
+               if (free_array[i] != ext2fs_bg_free_inodes_count(fs, i)) {
                        pctx.group = i;
-                       pctx.ino = fs->group_desc[i].bg_free_inodes_count;
+                       pctx.ino = ext2fs_bg_free_inodes_count(fs, i);
                        pctx.ino2 = free_array[i];
                        if (fix_problem(ctx, PR_5_FREE_INODE_COUNT_GROUP,
                                        &pctx)) {
-                               fs->group_desc[i].bg_free_inodes_count =
-                                       free_array[i];
+                               ext2fs_bg_free_inodes_count_set(fs, i, free_array[i]);
                                ext2fs_mark_super_dirty(fs);
                        } else
                                ext2fs_unmark_valid(fs);
                }
-               if (dir_array[i] != fs->group_desc[i].bg_used_dirs_count) {
+               if (dir_array[i] != ext2fs_bg_used_dirs_count(fs, i)) {
                        pctx.group = i;
-                       pctx.ino = fs->group_desc[i].bg_used_dirs_count;
+                       pctx.ino = ext2fs_bg_used_dirs_count(fs, i);
                        pctx.ino2 = dir_array[i];
 
                        if (fix_problem(ctx, PR_5_FREE_DIR_COUNT_GROUP,
                                        &pctx)) {
-                               fs->group_desc[i].bg_used_dirs_count =
-                                       dir_array[i];
+                               ext2fs_bg_used_dirs_count_set(fs, i, dir_array[i]);
                                ext2fs_mark_super_dirty(fs);
                        } else
                                ext2fs_unmark_valid(fs);
index fbc8b8a..4c989cc 100644 (file)
@@ -458,7 +458,6 @@ void check_super_block(e2fsck_t ctx)
        ext2_filsys fs = ctx->fs;
        blk_t   first_block, last_block;
        struct ext2_super_block *sb = fs->super;
-       struct ext2_group_desc *gd;
        problem_t       problem;
        blk_t   blocks_per_group = fs->super->s_blocks_per_group;
        blk_t   bpg_max;
@@ -587,7 +586,7 @@ void check_super_block(e2fsck_t ctx)
 
        csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                               EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
-       for (i = 0, gd=fs->group_desc; i < fs->group_desc_count; i++, gd++) {
+       for (i = 0; i < fs->group_desc_count; i++) {
                pctx.group = i;
 
                if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
@@ -596,43 +595,43 @@ void check_super_block(e2fsck_t ctx)
                        last_block = ext2fs_group_last_block(fs, i);
                }
 
-               if ((gd->bg_block_bitmap < first_block) ||
-                   (gd->bg_block_bitmap > last_block)) {
-                       pctx.blk = gd->bg_block_bitmap;
+               if ((ext2fs_block_bitmap_loc(fs, i) < first_block) ||
+                   (ext2fs_block_bitmap_loc(fs, i) > last_block)) {
+                       pctx.blk = ext2fs_block_bitmap_loc(fs, i);
                        if (fix_problem(ctx, PR_0_BB_NOT_GROUP, &pctx))
-                               gd->bg_block_bitmap = 0;
+                               ext2fs_block_bitmap_loc_set(fs, i, 0);
                }
-               if (gd->bg_block_bitmap == 0) {
+               if (ext2fs_block_bitmap_loc(fs, i) == 0) {
                        ctx->invalid_block_bitmap_flag[i]++;
                        ctx->invalid_bitmaps++;
                }
-               if ((gd->bg_inode_bitmap < first_block) ||
-                   (gd->bg_inode_bitmap > last_block)) {
-                       pctx.blk = gd->bg_inode_bitmap;
+               if ((ext2fs_inode_bitmap_loc(fs, i) < first_block) ||
+                   (ext2fs_inode_bitmap_loc(fs, i) > last_block)) {
+                       pctx.blk = ext2fs_inode_bitmap_loc(fs, i);
                        if (fix_problem(ctx, PR_0_IB_NOT_GROUP, &pctx))
-                               gd->bg_inode_bitmap = 0;
+                               ext2fs_inode_bitmap_loc_set(fs, i, 0);
                }
-               if (gd->bg_inode_bitmap == 0) {
+               if (ext2fs_inode_bitmap_loc(fs, i) == 0) {
                        ctx->invalid_inode_bitmap_flag[i]++;
                        ctx->invalid_bitmaps++;
                }
-               if ((gd->bg_inode_table < first_block) ||
-                   ((gd->bg_inode_table +
+               if ((ext2fs_inode_table_loc(fs, i) < first_block) ||
+                   ((ext2fs_inode_table_loc(fs, i) +
                      fs->inode_blocks_per_group - 1) > last_block)) {
-                       pctx.blk = gd->bg_inode_table;
+                       pctx.blk = ext2fs_inode_table_loc(fs, i);
                        if (fix_problem(ctx, PR_0_ITABLE_NOT_GROUP, &pctx))
-                               gd->bg_inode_table = 0;
+                               ext2fs_inode_table_loc_set(fs, i, 0);
                }
-               if (gd->bg_inode_table == 0) {
+               if (ext2fs_inode_table_loc(fs, i) == 0) {
                        ctx->invalid_inode_table_flag[i]++;
                        ctx->invalid_bitmaps++;
                }
-               free_blocks += gd->bg_free_blocks_count;
-               free_inodes += gd->bg_free_inodes_count;
+               free_blocks += ext2fs_bg_free_blocks_count(fs, i);
+               free_inodes += ext2fs_bg_free_inodes_count(fs, i);
 
-               if ((gd->bg_free_blocks_count > sb->s_blocks_per_group) ||
-                   (gd->bg_free_inodes_count > sb->s_inodes_per_group) ||
-                   (gd->bg_used_dirs_count > sb->s_inodes_per_group))
+               if ((ext2fs_bg_free_blocks_count(fs, i) > sb->s_blocks_per_group) ||
+                   (ext2fs_bg_free_inodes_count(fs, i) > sb->s_inodes_per_group) ||
+                   (ext2fs_bg_used_dirs_count(fs, i) > sb->s_inodes_per_group))
                        ext2fs_unmark_valid(fs);
 
                should_be = 0;
@@ -640,7 +639,7 @@ void check_super_block(e2fsck_t ctx)
                        if (fix_problem(ctx, PR_0_GDT_CSUM, &pctx)) {
                                ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
                                ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
-                               gd->bg_itable_unused = 0;
+                               ext2fs_bg_itable_unused_set(fs, i, 0);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
@@ -649,11 +648,11 @@ void check_super_block(e2fsck_t ctx)
                if (!csum_flag &&
                    (ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) ||
                     ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) ||
-                    gd->bg_itable_unused != 0)){
+                    ext2fs_bg_itable_unused(fs, i) != 0)) {
                        if (fix_problem(ctx, PR_0_GDT_UNINIT, &pctx)) {
                                ext2fs_bg_flags_clear(fs, i, EXT2_BG_BLOCK_UNINIT);
                                ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
-                               gd->bg_itable_unused = 0;
+                               ext2fs_bg_itable_unused_set(fs, i, 0);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
@@ -678,11 +677,11 @@ void check_super_block(e2fsck_t ctx)
                }
 
                if (csum_flag &&
-                   (gd->bg_itable_unused > gd->bg_free_inodes_count ||
-                    gd->bg_itable_unused > sb->s_inodes_per_group)) {
-                       pctx.blk = gd->bg_itable_unused;
+                   (ext2fs_bg_itable_unused(fs, i) > ext2fs_bg_free_inodes_count(fs, i) ||
+                    ext2fs_bg_itable_unused(fs, i) > sb->s_inodes_per_group)) {
+                       pctx.blk = ext2fs_bg_itable_unused(fs, i);
                        if (fix_problem(ctx, PR_0_GDT_ITABLE_UNUSED, &pctx)) {
-                               gd->bg_itable_unused = 0;
+                               ext2fs_bg_itable_unused_set(fs, i, 0);
                                should_be = 1;
                        }
                        ext2fs_unmark_valid(fs);
index 932103d..b9eefb3 100644 (file)
@@ -59,10 +59,10 @@ static void check_block_uninit(ext2_filsys fs, ext2fs_block_bitmap map,
                     (blk >= old_desc_blk) &&
                     (blk < old_desc_blk + old_desc_blocks)) ||
                    (new_desc_blk && (blk == new_desc_blk)) ||
-                   (blk == fs->group_desc[group].bg_block_bitmap) ||
-                   (blk == fs->group_desc[group].bg_inode_bitmap) ||
-                   (blk >= fs->group_desc[group].bg_inode_table &&
-                    (blk < fs->group_desc[group].bg_inode_table
+                   (blk == ext2fs_block_bitmap_loc(fs, group)) ||
+                   (blk == ext2fs_inode_bitmap_loc(fs, group)) ||
+                   (blk >= ext2fs_inode_table_loc(fs, group) &&
+                    (blk < ext2fs_inode_table_loc(fs, group)
                      + fs->inode_blocks_per_group)))
                        ext2fs_fast_mark_block_bitmap2(map, blk);
                else
index 7229385..254da71 100644 (file)
@@ -31,9 +31,9 @@ void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
                ext2fs_mark_inode_bitmap2(fs->inode_map, ino);
        else
                ext2fs_unmark_inode_bitmap2(fs->inode_map, ino);
-       fs->group_desc[group].bg_free_inodes_count -= inuse;
+       ext2fs_bg_free_inodes_count_set(fs, group, ext2fs_bg_free_inodes_count(fs, group) - inuse);
        if (isdir)
-               fs->group_desc[group].bg_used_dirs_count += inuse;
+               ext2fs_bg_used_dirs_count_set(fs, group, ext2fs_bg_used_dirs_count(fs, group) + inuse);
 
        /* We don't strictly need to be clearing the uninit flag if inuse < 0
         * (i.e. freeing inodes) but it also means something is bad. */
@@ -41,13 +41,11 @@ void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
        if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
                ext2_ino_t first_unused_inode = fs->super->s_inodes_per_group -
-                       fs->group_desc[group].bg_itable_unused +
+                       ext2fs_bg_itable_unused(fs, group) +
                        group * fs->super->s_inodes_per_group + 1;
 
                if (ino >= first_unused_inode)
-                       fs->group_desc[group].bg_itable_unused =
-                               group * fs->super->s_inodes_per_group +
-                               fs->super->s_inodes_per_group - ino;
+                       ext2fs_bg_itable_unused_set(fs, group, group * fs->super->s_inodes_per_group + fs->super->s_inodes_per_group - ino);
                ext2fs_group_desc_csum_set(fs, group);
        }
 
@@ -76,7 +74,7 @@ void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse)
                ext2fs_mark_block_bitmap2(fs->block_map, blk);
        else
                ext2fs_unmark_block_bitmap2(fs->block_map, blk);
-       fs->group_desc[group].bg_free_blocks_count -= inuse;
+       ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) - inuse);
        ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
        ext2fs_group_desc_csum_set(fs, group);
 
index 8141ec3..696829f 100644 (file)
@@ -122,14 +122,14 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
        if (flexbg_size) {
                blk64_t prev_block = 0;
 
-               if (group && fs->group_desc[group-1].bg_block_bitmap)
-                       prev_block = fs->group_desc[group-1].bg_block_bitmap;
+               if (group && ext2fs_block_bitmap_loc(fs, group - 1))
+                       prev_block = ext2fs_block_bitmap_loc(fs, group - 1);
                start_blk = flexbg_offset(fs, group, prev_block, bmap,
                                                 0, rem_grps, 1);
                last_blk = ext2fs_group_last_block(fs, last_grp);
        }
 
-       if (!fs->group_desc[group].bg_block_bitmap) {
+       if (!ext2fs_block_bitmap_loc(fs, group)) {
                retval = ext2fs_get_free_blocks(fs, start_blk, last_blk,
                                                1, bmap, &new_blk);
                if (retval == EXT2_ET_BLOCK_ALLOC_FAIL)
@@ -138,10 +138,10 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
                if (retval)
                        return retval;
                ext2fs_mark_block_bitmap2(bmap, new_blk);
-               fs->group_desc[group].bg_block_bitmap = new_blk;
+               ext2fs_block_bitmap_loc_set(fs, group, new_blk);
                if (flexbg_size) {
                        dgrp_t gr = ext2fs_group_of_blk(fs, new_blk);
-                       fs->group_desc[gr].bg_free_blocks_count--;
+                       ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1);
                        ext2fs_free_blocks_count_add(fs->super, -1);
                        ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
                        ext2fs_group_desc_csum_set(fs, gr);
@@ -149,15 +149,15 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
        }
 
        if (flexbg_size) {
-               blk_t prev_block = 0;
-               if (group && fs->group_desc[group-1].bg_inode_bitmap)
-                       prev_block = fs->group_desc[group-1].bg_inode_bitmap;
+               blk64_t prev_block = 0;
+               if (group && ext2fs_inode_bitmap_loc(fs, group - 1))
+                       prev_block = ext2fs_inode_bitmap_loc(fs, group - 1);
                start_blk = flexbg_offset(fs, group, prev_block, bmap,
                                                 flexbg_size, rem_grps, 1);
                last_blk = ext2fs_group_last_block(fs, last_grp);
        }
 
-       if (!fs->group_desc[group].bg_inode_bitmap) {
+       if (!ext2fs_inode_bitmap_loc(fs, group)) {
                retval = ext2fs_get_free_blocks(fs, start_blk, last_blk,
                                                1, bmap, &new_blk);
                if (retval == EXT2_ET_BLOCK_ALLOC_FAIL)
@@ -166,10 +166,10 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
                if (retval)
                        return retval;
                ext2fs_mark_block_bitmap2(bmap, new_blk);
-               fs->group_desc[group].bg_inode_bitmap = new_blk;
+               ext2fs_inode_bitmap_loc_set(fs, group, new_blk);
                if (flexbg_size) {
                        dgrp_t gr = ext2fs_group_of_blk(fs, new_blk);
-                       fs->group_desc[gr].bg_free_blocks_count--;
+                       ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1);
                        ext2fs_free_blocks_count_add(fs->super, -1);
                        ext2fs_bg_flags_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
                        ext2fs_group_desc_csum_set(fs, gr);
@@ -180,9 +180,9 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
         * Allocate the inode table
         */
        if (flexbg_size) {
-               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;
+               blk64_t prev_block = 0;
+               if (group && ext2fs_inode_table_loc(fs, group - 1))
+                       prev_block = ext2fs_inode_table_loc(fs, group - 1);
                group_blk = flexbg_offset(fs, group, prev_block, bmap,
                                                 flexbg_size * 2,
                                                 fs->inode_blocks_per_group *
@@ -191,7 +191,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
                last_blk = ext2fs_group_last_block(fs, last_grp);
        }
 
-       if (!fs->group_desc[group].bg_inode_table) {
+       if (!ext2fs_inode_table_loc(fs, group)) {
                retval = ext2fs_get_free_blocks(fs, group_blk, last_blk,
                                                fs->inode_blocks_per_group,
                                                bmap, &new_blk);
@@ -203,14 +203,14 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
                        ext2fs_mark_block_bitmap2(bmap, blk);
                        if (flexbg_size) {
                                dgrp_t gr = ext2fs_group_of_blk(fs, blk);
-                               fs->group_desc[gr].bg_free_blocks_count--;
+                               ext2fs_bg_free_blocks_count_set(fs, gr, ext2fs_bg_free_blocks_count(fs, gr) - 1);
                                ext2fs_free_blocks_count_add(fs->super, -1);
                                ext2fs_bg_flags_clear(fs, gr,
                                                     EXT2_BG_BLOCK_UNINIT);
                                ext2fs_group_desc_csum_set(fs, gr);
                        }
                }
-               fs->group_desc[group].bg_inode_table = new_blk;
+               ext2fs_inode_table_loc_set(fs, group, new_blk);
        }
        ext2fs_group_desc_csum_set(fs, group);
        return 0;
index 3ce38e6..321bf74 100644 (file)
@@ -36,7 +36,7 @@ errcode_t ext2fs_check_desc(ext2_filsys fs)
        dgrp_t i;
        blk_t first_block = fs->super->s_first_data_block;
        blk_t last_block = ext2fs_blocks_count(fs->super)-1;
-       blk_t blk, b;
+       blk64_t blk, b;
        int j;
 
        EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
@@ -60,7 +60,7 @@ errcode_t ext2fs_check_desc(ext2_filsys fs)
                /*
                 * Check to make sure the block bitmap for group is sane
                 */
-               blk = fs->group_desc[i].bg_block_bitmap;
+               blk = ext2fs_block_bitmap_loc(fs, i);
                if (blk < first_block || blk > last_block ||
                    ext2fs_test_block_bitmap2(bmap, blk)) {
                        retval = EXT2_ET_GDESC_BAD_BLOCK_MAP;
@@ -71,7 +71,7 @@ errcode_t ext2fs_check_desc(ext2_filsys fs)
                /*
                 * Check to make sure the inode bitmap for group is sane
                 */
-               blk = fs->group_desc[i].bg_inode_bitmap;
+               blk = ext2fs_inode_bitmap_loc(fs, i);
                if (blk < first_block || blk > last_block ||
                    ext2fs_test_block_bitmap2(bmap, blk)) {
                        retval = EXT2_ET_GDESC_BAD_INODE_MAP;
@@ -82,7 +82,7 @@ errcode_t ext2fs_check_desc(ext2_filsys fs)
                /*
                 * Check to make sure the inode table for group is sane
                 */
-               blk = fs->group_desc[i].bg_inode_table;
+               blk = ext2fs_inode_table_loc(fs, i);
                if (blk < first_block ||
                    ((blk + fs->inode_blocks_per_group - 1) > last_block)) {
                        retval = EXT2_ET_GDESC_BAD_INODE_TABLE;
index c505f00..8b2e096 100644 (file)
@@ -304,7 +304,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
        }
 #else
        super_shadow = fs->super;
-       group_shadow = fs->group_desc;
+       group_shadow = ext2fs_group_desc(fs, fs->group_desc, 0);
 #endif
 
        /*
index c2a177d..f02d676 100644 (file)
@@ -34,7 +34,7 @@ STATIC __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group)
        __u16 crc = 0;
        struct ext2_group_desc *desc;
 
-       desc = &fs->group_desc[group];
+       desc = ext2fs_group_desc(fs, fs->group_desc, group);
 
        if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
                int offset = offsetof(struct ext2_group_desc, bg_checksum);
@@ -53,7 +53,6 @@ STATIC __u16 ext2fs_group_desc_csum(ext2_filsys fs, dgrp_t group)
                crc = ext2fs_crc16(crc, &group, sizeof(group));
                crc = ext2fs_crc16(crc, desc, offset);
                offset += sizeof(desc->bg_checksum); /* skip checksum */
-               assert(offset == sizeof(*desc));
                /* for checksum of struct ext4_group_desc do the rest...*/
                if (offset < fs->super->s_desc_size) {
                        crc = ext2fs_crc16(crc, (char *)desc + offset,
@@ -68,7 +67,7 @@ int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group)
 {
        if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM) &&
-           (fs->group_desc[group].bg_checksum !=
+           (ext2fs_bg_checksum(fs, group) !=
             ext2fs_group_desc_csum(fs, group)))
                return 0;
 
@@ -77,10 +76,13 @@ int ext2fs_group_desc_csum_verify(ext2_filsys fs, dgrp_t group)
 
 void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group)
 {
-       if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
-                                      EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
-               fs->group_desc[group].bg_checksum =
-                       ext2fs_group_desc_csum(fs, group);
+       if (!EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
+               return;
+
+       /* ext2fs_bg_checksum_set() sets the actual checksum field but
+        * does not calculate the checksum itself. */
+       ext2fs_bg_checksum_set(fs, group, ext2fs_group_desc_csum(fs, group));
 }
 
 static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap,
@@ -103,7 +105,6 @@ static __u32 find_last_inode_ingrp(ext2fs_inode_bitmap bitmap,
 errcode_t ext2fs_set_gdt_csum(ext2_filsys fs)
 {
        struct ext2_super_block *sb = fs->super;
-       struct ext2_group_desc *bg = fs->group_desc;
        int dirty = 0;
        dgrp_t i;
 
@@ -114,27 +115,31 @@ errcode_t ext2fs_set_gdt_csum(ext2_filsys fs)
                                        EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
                return 0;
 
-       for (i = 0; i < fs->group_desc_count; i++, bg++) {
-               int old_csum = bg->bg_checksum;
-               int old_unused = bg->bg_itable_unused;
-               int old_flags = bg->bg_flags;
+       for (i = 0; i < fs->group_desc_count; i++) {
+               unsigned int old_csum = ext2fs_bg_checksum(fs, i);
+               int old_unused = ext2fs_bg_itable_unused(fs, i);
+               unsigned int old_flags = ext2fs_bg_flags(fs, i);
+               int old_free_inodes_count = ext2fs_bg_free_inodes_count(fs, i);
 
-               if (bg->bg_free_inodes_count == sb->s_inodes_per_group) {
-                       bg->bg_flags |= EXT2_BG_INODE_UNINIT;
-                       bg->bg_itable_unused = sb->s_inodes_per_group;
+               if (old_free_inodes_count == sb->s_inodes_per_group) {
+                       ext2fs_bg_flags_set(fs, i, EXT2_BG_INODE_UNINIT);
+                       ext2fs_bg_itable_unused_set(fs, i, sb->s_inodes_per_group);
                } else {
-                       bg->bg_flags &= ~EXT2_BG_INODE_UNINIT;
-                       bg->bg_itable_unused = sb->s_inodes_per_group -
+                       int unused =
+                               sb->s_inodes_per_group -
                                find_last_inode_ingrp(fs->inode_map,
-                                                     sb->s_inodes_per_group,i);
+                                                     sb->s_inodes_per_group, i);
+
+                       ext2fs_bg_flags_clear(fs, i, EXT2_BG_INODE_UNINIT);
+                       ext2fs_bg_itable_unused_set(fs, i, unused);
                }
 
                ext2fs_group_desc_csum_set(fs, i);
-               if (old_flags != bg->bg_flags)
+               if (old_flags != ext2fs_bg_flags(fs, i))
                        dirty = 1;
-               if (old_unused != bg->bg_itable_unused)
+               if (old_unused != ext2fs_bg_itable_unused(fs, i))
                        dirty = 1;
-               if (old_csum != bg->bg_checksum)
+               if (old_csum != ext2fs_bg_checksum(fs, i))
                        dirty = 1;
        }
        if (dirty)
@@ -196,12 +201,12 @@ int main(int argc, char **argv)
        fs->super->s_feature_ro_compat = EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
 
        for (i=0; i < fs->group_desc_count; i++) {
-               fs->group_desc[i].bg_block_bitmap = 124;
-               fs->group_desc[i].bg_inode_bitmap = 125;
-               fs->group_desc[i].bg_inode_table = 126;
-               fs->group_desc[i].bg_free_blocks_count = 31119;
-               fs->group_desc[i].bg_free_inodes_count = 15701;
-               fs->group_desc[i].bg_used_dirs_count = 2;
+               ext2fs_block_bitmap_loc_set(fs, i, 124);
+               ext2fs_inode_bitmap_loc_set(fs, i, 125);
+               ext2fs_inode_table_loc_set(fs, i, 126);
+               ext2fs_bg_free_blocks_count_set(fs, i, 31119);
+               ext2fs_bg_free_inodes_count_set(fs, i, 15701);
+               ext2fs_bg_used_dirs_count_set(fs, i, 2);
                ext2fs_bg_flags_zap(fs, i);
        };
 
@@ -224,7 +229,7 @@ int main(int argc, char **argv)
                printf("checksums for different groups shouldn't match\n");
                exit(1);
        }
-       fs->group_desc[0].bg_checksum = csum1;
+       ext2fs_bg_checksum_set(fs, 0, csum1);
        csum2 = ext2fs_group_desc_csum(fs, 0);
        print_csum("csum_set", fs, 0);
        if (csum1 != csum2) {
@@ -241,9 +246,10 @@ int main(int argc, char **argv)
                printf("checksums for different filesystems shouldn't match\n");
                exit(1);
        }
-       csum1 = fs->group_desc[0].bg_checksum = ext2fs_group_desc_csum(fs, 0);
+       csum1 = ext2fs_group_desc_csum(fs, 0);
+       ext2fs_bg_checksum_set(fs, 0, csum1);
        print_csum("csum_new", fs, 0);
-       fs->group_desc[0].bg_free_blocks_count = 1;
+       ext2fs_bg_free_blocks_count_set(fs, 0, 1);
        csum2 = ext2fs_group_desc_csum(fs, 0);
        print_csum("csum_blk", fs, 0);
        if (csum1 == csum2) {
index 4a80367..300ad35 100644 (file)
@@ -37,10 +37,10 @@ errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs)
        num_dirs = 0;
        max_dirs = fs->super->s_inodes_per_group;
        for (i = 0; i < fs->group_desc_count; i++) {
-               if (fs->group_desc[i].bg_used_dirs_count > max_dirs)
+               if (ext2fs_bg_used_dirs_count(fs, i) > max_dirs)
                        num_dirs += max_dirs / 8;
                else
-                       num_dirs += fs->group_desc[i].bg_used_dirs_count;
+                       num_dirs += ext2fs_bg_used_dirs_count(fs, i);
        }
        if (num_dirs > fs->super->s_inodes_count)
                num_dirs = fs->super->s_inodes_count;
index 948b1ac..9559ebb 100644 (file)
@@ -71,7 +71,7 @@ errcode_t ext2fs_image_inode_write(ext2_filsys fs, int fd, int flags)
                return ENOMEM;
 
        for (group = 0; group < fs->group_desc_count; group++) {
-               blk = fs->group_desc[(unsigned)group].bg_inode_table;
+               blk = ext2fs_inode_table_loc(fs, (unsigned)group);
                if (!blk) {
                        retval = EXT2_ET_MISSING_INODE_TABLE;
                        goto errout;
@@ -145,7 +145,7 @@ errcode_t ext2fs_image_inode_read(ext2_filsys fs, int fd,
                return ENOMEM;
 
        for (group = 0; group < fs->group_desc_count; group++) {
-               blk = fs->group_desc[(unsigned)group].bg_inode_table;
+               blk = ext2fs_inode_table_loc(fs, (unsigned)group);
                if (!blk) {
                        retval = EXT2_ET_MISSING_INODE_TABLE;
                        goto errout;
index 986dd28..36a35a0 100644 (file)
@@ -410,7 +410,7 @@ ipg_retry:
                        numblocks = super->s_inodes_per_group;
                        if (i == 0)
                                numblocks -= super->s_first_ino;
-                       fs->group_desc[i].bg_itable_unused = numblocks;
+                       ext2fs_bg_itable_unused_set(fs, i, numblocks);
                }
                numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);
                if (fs->super->s_log_groups_per_flex)
@@ -419,10 +419,9 @@ ipg_retry:
                ext2fs_free_blocks_count_set(super,
                                             ext2fs_free_blocks_count(super) +
                                             numblocks);
-               fs->group_desc[i].bg_free_blocks_count = numblocks;
-               fs->group_desc[i].bg_free_inodes_count =
-                       fs->super->s_inodes_per_group;
-               fs->group_desc[i].bg_used_dirs_count = 0;
+               ext2fs_bg_free_blocks_count_set(fs, i, numblocks);
+               ext2fs_bg_free_inodes_count_set(fs, i, fs->super->s_inodes_per_group);
+               ext2fs_bg_used_dirs_count_set(fs, i, 0);
                ext2fs_group_desc_csum_set(fs, i);
        }
 
index 6e3adbc..1e18195 100644 (file)
@@ -33,7 +33,7 @@ struct ext2_struct_inode_scan {
        errcode_t               magic;
        ext2_filsys             fs;
        ext2_ino_t              current_inode;
-       blk_t                   current_block;
+       blk64_t                 current_block;
        dgrp_t                  current_group;
        ext2_ino_t              inodes_left;
        blk_t                   blocks_left;
@@ -143,14 +143,14 @@ errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
        scan->current_group = 0;
        scan->groups_left = fs->group_desc_count - 1;
        scan->inode_buffer_blocks = buffer_blocks ? buffer_blocks : 8;
-       scan->current_block = scan->fs->
-               group_desc[scan->current_group].bg_inode_table;
+       scan->current_block = ext2fs_inode_table_loc(scan->fs,
+                                                    scan->current_group);
        scan->inodes_left = EXT2_INODES_PER_GROUP(scan->fs->super);
        scan->blocks_left = scan->fs->inode_blocks_per_group;
        if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
                scan->inodes_left -=
-                       fs->group_desc[scan->current_group].bg_itable_unused;
+                       ext2fs_bg_itable_unused(fs, scan->current_group);
                scan->blocks_left =
                        (scan->inodes_left +
                         (fs->blocksize / scan->inode_size - 1)) *
@@ -233,8 +233,8 @@ static errcode_t get_next_blockgroup(ext2_inode_scan scan)
        scan->current_group++;
        scan->groups_left--;
 
-       scan->current_block =fs->group_desc[scan->current_group].bg_inode_table;
-
+       scan->current_block = ext2fs_inode_table_loc(scan->fs,
+                                                    scan->current_group);
        scan->current_inode = scan->current_group *
                EXT2_INODES_PER_GROUP(fs->super);
 
@@ -244,7 +244,7 @@ static errcode_t get_next_blockgroup(ext2_inode_scan scan)
        if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                       EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
                scan->inodes_left -=
-                       fs->group_desc[scan->current_group].bg_itable_unused;
+                       ext2fs_bg_itable_unused(fs, scan->current_group);
                scan->blocks_left =
                        (scan->inodes_left +
                         (fs->blocksize / scan->inode_size - 1)) *
@@ -569,9 +569,9 @@ errcode_t ext2fs_read_inode_full(ext2_filsys fs, ext2_ino_t ino,
                offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
                        EXT2_INODE_SIZE(fs->super);
                block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super);
-               if (!fs->group_desc[(unsigned)group].bg_inode_table)
+               if (!ext2fs_inode_table_loc(fs, (unsigned) group))
                        return EXT2_ET_MISSING_INODE_TABLE;
-               block_nr = fs->group_desc[(unsigned)group].bg_inode_table +
+               block_nr = ext2fs_inode_table_loc(fs, group) +
                        block;
                io = fs->io;
        }
@@ -688,11 +688,11 @@ errcode_t ext2fs_write_inode_full(ext2_filsys fs, ext2_ino_t ino,
        offset = ((ino - 1) % EXT2_INODES_PER_GROUP(fs->super)) *
                EXT2_INODE_SIZE(fs->super);
        block = offset >> EXT2_BLOCK_SIZE_BITS(fs->super);
-       if (!fs->group_desc[(unsigned) group].bg_inode_table) {
+       if (!ext2fs_inode_table_loc(fs, (unsigned) group)) {
                retval = EXT2_ET_MISSING_INODE_TABLE;
                goto errout;
        }
-       block_nr = fs->group_desc[(unsigned) group].bg_inode_table + block;
+       block_nr = ext2fs_inode_table_loc(fs, (unsigned) group) + block;
 
        offset &= (EXT2_BLOCK_SIZE(fs->super) - 1);
 
index 6ba1174..eff177f 100644 (file)
@@ -327,7 +327,7 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
        if (fs->super->s_log_groups_per_flex && (group > log_flex)) {
                group = group & ~(log_flex - 1);
                while ((group < fs->group_desc_count) &&
-                      fs->group_desc[group].bg_free_blocks_count == 0)
+                      ext2fs_bg_free_blocks_count(fs, group) == 0)
                        group++;
                if (group == fs->group_desc_count)
                        group = 0;
@@ -337,8 +337,8 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
        end = ((group+1) < fs->group_desc_count) ? group+1 : group;
        group = start;
        for (i=start+1; i <= end; i++)
-               if (fs->group_desc[i].bg_free_blocks_count >
-                   fs->group_desc[group].bg_free_blocks_count)
+               if (ext2fs_bg_free_blocks_count(fs, i) >
+                   ext2fs_bg_free_blocks_count(fs, group))
                        group = i;
 
        es.goal = (fs->super->s_blocks_per_group * group) +
index 8b24619..52f56c0 100644 (file)
@@ -353,7 +353,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
                for (group = 0; group < fs->group_desc_count; group++) {
                        ext2fs_bg_flags_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
                        ext2fs_bg_flags_clear(fs, group, EXT2_BG_INODE_UNINIT);
-                       fs->group_desc[group].bg_itable_unused = 0;
+                       ext2fs_bg_itable_unused_set(fs, group, 0);
                }
                ext2fs_mark_super_dirty(fs);
        }
index f85473a..962678c 100644 (file)
@@ -36,7 +36,7 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
        errcode_t       retval;
        char            *block_buf, *inode_buf;
        int             csum_flag = 0;
-       blk_t           blk;
+       blk64_t         blk;
        blk64_t         blk_itr = fs->super->s_first_data_block;
        ext2_ino_t      ino_itr = 1;
 
@@ -88,7 +88,7 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
                                for (j = nbits; j < fs->blocksize * 8; j++)
                                        ext2fs_set_bit(j, block_buf);
                }
-               blk = fs->group_desc[i].bg_block_bitmap;
+               blk = ext2fs_block_bitmap_loc(fs, i);
                if (blk) {
                        retval = io_channel_write_blk64(fs->io, blk, 1,
                                                        block_buf);
@@ -111,7 +111,7 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
                if (retval)
                        return retval;
 
-               blk = fs->group_desc[i].bg_inode_bitmap;
+               blk = ext2fs_inode_bitmap_loc(fs, i);
                if (blk) {
                        retval = io_channel_write_blk64(fs->io, blk, 1,
                                                      inode_buf);
@@ -144,9 +144,9 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
        int csum_flag = 0;
        int do_image = fs->flags & EXT2_FLAG_IMAGE_FILE;
        unsigned int    cnt;
-       blk_t   blk;
+       blk64_t blk;
        blk64_t blk_itr = fs->super->s_first_data_block;
-       blk_t   blk_cnt;
+       blk64_t   blk_cnt;
        ext2_ino_t ino_itr = 1;
        ext2_ino_t ino_cnt;
 
@@ -235,7 +235,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
 
        for (i = 0; i < fs->group_desc_count; i++) {
                if (block_bitmap) {
-                       blk = fs->group_desc[i].bg_block_bitmap;
+                       blk = ext2fs_block_bitmap_loc(fs, i);
                        if (csum_flag &&
                            ext2fs_bg_flags_test(fs, i, EXT2_BG_BLOCK_UNINIT) &&
                            ext2fs_group_desc_csum_verify(fs, i))
@@ -257,7 +257,7 @@ static errcode_t read_bitmaps(ext2_filsys fs, int do_inode, int do_block)
                        blk_itr += block_nbytes << 3;
                }
                if (inode_bitmap) {
-                       blk = fs->group_desc[i].bg_inode_bitmap;
+                       blk = ext2fs_inode_bitmap_loc(fs, i);
                        if (csum_flag &&
                            ext2fs_bg_flags_test(fs, i, EXT2_BG_INODE_UNINIT) &&
                            ext2fs_group_desc_csum_verify(fs, i))
index 6c3abb3..26d8da5 100644 (file)
@@ -188,7 +188,7 @@ static void check_map(void)
                ext2fs_mark_block_bitmap2(touched_map, test_vec[i]);
        }
        for (i = 0; i < test_fs->group_desc_count; i++) {
-               for (j=0, blk = test_fs->group_desc[i].bg_inode_table;
+               for (j=0, blk = ext2fs_inode_table_loc(test_fs, i);
                     j < test_fs->inode_blocks_per_group;
                     j++, blk++) {
                        if (!ext2fs_test_block_bitmap2(touched_map, blk) &&
index cb9c1ab..298dbb2 100644 (file)
@@ -170,9 +170,9 @@ static void list_desc (ext2_filsys fs)
                fputs(")", stdout);
                print_bg_opts(fs, i);
                if (fs->super->s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
-                       printf(_("  Checksum 0x%04x, unused inodes %d\n"),
-                              fs->group_desc[i].bg_checksum,
-                              fs->group_desc[i].bg_itable_unused);
+                       printf(_("  Checksum 0x%04x, unused inodes %u\n"),
+                              ext2fs_bg_checksum(fs, i),
+                              ext2fs_bg_itable_unused(fs, i));
                has_super = ((i==0) || super_blk);
                if (has_super) {
                        printf (_("  %s superblock at "),
@@ -198,31 +198,31 @@ static void list_desc (ext2_filsys fs)
                if (has_super)
                        fputc('\n', stdout);
                fputs(_("  Block bitmap at "), stdout);
-               print_number(fs->group_desc[i].bg_block_bitmap);
-               diff = fs->group_desc[i].bg_block_bitmap - first_block;
+               print_number(ext2fs_block_bitmap_loc(fs, i));
+               diff = ext2fs_block_bitmap_loc(fs, i) - first_block;
                if (diff >= 0)
                        printf(" (+%ld)", diff);
                fputs(_(", Inode bitmap at "), stdout);
-               print_number(fs->group_desc[i].bg_inode_bitmap);
-               diff = fs->group_desc[i].bg_inode_bitmap - first_block;
+               print_number(ext2fs_inode_bitmap_loc(fs, i));
+               diff = ext2fs_inode_bitmap_loc(fs, i) - first_block;
                if (diff >= 0)
                        printf(" (+%ld)", diff);
                fputs(_("\n  Inode table at "), stdout);
-               print_range(fs->group_desc[i].bg_inode_table,
-                           fs->group_desc[i].bg_inode_table +
+               print_range(ext2fs_inode_table_loc(fs, i),
+                           ext2fs_inode_table_loc(fs, i) +
                            inode_blocks_per_group - 1);
-               diff = fs->group_desc[i].bg_inode_table - first_block;
+               diff = ext2fs_inode_table_loc(fs, i) - first_block;
                if (diff > 0)
                        printf(" (+%ld)", diff);
                printf (_("\n  %u free blocks, %u free inodes, "
                          "%u directories%s"),
-                       fs->group_desc[i].bg_free_blocks_count,
-                       fs->group_desc[i].bg_free_inodes_count,
-                       fs->group_desc[i].bg_used_dirs_count,
-                       fs->group_desc[i].bg_itable_unused ? "" : "\n");
-               if (fs->group_desc[i].bg_itable_unused)
+                       ext2fs_bg_free_blocks_count(fs, i),
+                       ext2fs_bg_free_inodes_count(fs, i),
+                       ext2fs_bg_used_dirs_count(fs, i),
+                       ext2fs_bg_itable_unused(fs, i) ? "" : "\n");
+               if (ext2fs_bg_itable_unused(fs, i))
                        printf (_(", %u unused inodes\n"),
-                               fs->group_desc[i].bg_itable_unused);
+                               ext2fs_bg_itable_unused(fs, i));
                if (block_bitmap) {
                        fputs(_("  Free blocks: "), stdout);
                        ext2fs_get_block_bitmap_range2(fs->block_map,
index 3802c99..0ee2b1e 100644 (file)
@@ -267,8 +267,8 @@ static void mark_table_blocks(ext2_filsys fs)
                /*
                 * Mark the blocks used for the inode table
                 */
-               if (fs->group_desc[i].bg_inode_table) {
-                       for (j = 0, b = fs->group_desc[i].bg_inode_table;
+               if (ext2fs_inode_table_loc(fs, i)) {
+                       for (j = 0, b = ext2fs_inode_table_loc(fs, i);
                             j < (unsigned) fs->inode_blocks_per_group;
                             j++, b++)
                                ext2fs_mark_block_bitmap2(meta_block_map, b);
@@ -277,17 +277,17 @@ static void mark_table_blocks(ext2_filsys fs)
                /*
                 * Mark block used for the block bitmap
                 */
-               if (fs->group_desc[i].bg_block_bitmap) {
+               if (ext2fs_block_bitmap_loc(fs, i)) {
                        ext2fs_mark_block_bitmap2(meta_block_map,
-                                    fs->group_desc[i].bg_block_bitmap);
+                                    ext2fs_block_bitmap_loc(fs, i));
                }
 
                /*
                 * Mark block used for the inode bitmap
                 */
-               if (fs->group_desc[i].bg_inode_bitmap) {
+               if (ext2fs_inode_bitmap_loc(fs, i)) {
                        ext2fs_mark_block_bitmap2(meta_block_map,
-                                fs->group_desc[i].bg_inode_bitmap);
+                                ext2fs_inode_bitmap_loc(fs, i));
                }
        }
 }
index a2e2319..4fb6dfe 100644 (file)
@@ -274,7 +274,7 @@ _("Warning: the backup superblock/group descriptors at block %u contain\n"
                                                group_block);
                                group_bad++;
                                group = ext2fs_group_of_blk(fs, group_block+j);
-                               fs->group_desc[group].bg_free_blocks_count++;
+                               ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
                                ext2fs_group_desc_csum_set(fs, group);
                                ext2fs_free_blocks_count_add(fs->super, 1);
                        }
@@ -311,13 +311,13 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag)
        for (i = 0; i < fs->group_desc_count; i++) {
                ext2fs_numeric_progress_update(fs, &progress, i);
 
-               blk = fs->group_desc[i].bg_inode_table;
+               blk = ext2fs_inode_table_loc(fs, i);
                num = fs->inode_blocks_per_group;
 
                if (lazy_flag) {
                        ipb = fs->blocksize / EXT2_INODE_SIZE(fs->super);
                        num = ((((fs->super->s_inodes_per_group -
-                                 fs->group_desc[i].bg_itable_unused) *
+                                 ext2fs_bg_itable_unused(fs, i)) *
                                 EXT2_INODE_SIZE(fs->super)) +
                                EXT2_BLOCK_SIZE(fs->super) - 1) /
                               EXT2_BLOCK_SIZE(fs->super));
index 8daf632..df3c0cb 100644 (file)
@@ -261,7 +261,7 @@ static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr,
        block = *blocknr;
        ext2fs_unmark_block_bitmap2(fs->block_map, block);
        group = ext2fs_group_of_blk(fs, block);
-       fs->group_desc[group].bg_free_blocks_count++;
+       ext2fs_bg_free_blocks_count_set(fs, group, ext2fs_bg_free_blocks_count(fs, group) + 1);
        ext2fs_group_desc_csum_set(fs, group);
        ext2fs_free_blocks_count_add(fs->super, 1);
        return 0;
@@ -980,10 +980,10 @@ static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp,
                return retval;
 
        for (i = 0; i < fs->group_desc_count; i++) {
-               start_blk = fs->group_desc[i].bg_inode_table +
+               start_blk = ext2fs_inode_table_loc(fs, i) +
                                        fs->inode_blocks_per_group;
 
-               end_blk = fs->group_desc[i].bg_inode_table +
+               end_blk = ext2fs_inode_table_loc(fs, i) +
                                        new_ino_blks_per_grp;
 
                for (j = start_blk; j < end_blk; j++) {
@@ -1019,9 +1019,9 @@ static int ext2fs_is_meta_block(ext2_filsys fs, blk_t blk)
 {
        dgrp_t group;
        group = ext2fs_group_of_blk(fs, blk);
-       if (fs->group_desc[group].bg_block_bitmap == blk)
+       if (ext2fs_block_bitmap_loc(fs, group) == blk)
                return 1;
-       if (fs->group_desc[group].bg_inode_bitmap == blk)
+       if (ext2fs_inode_bitmap_loc(fs, group) == blk)
                return 1;
        return 0;
 }
@@ -1231,20 +1231,20 @@ static int group_desc_scan_and_fix(ext2_filsys fs, ext2fs_block_bitmap bmap)
        blk_t blk, new_blk;
 
        for (i = 0; i < fs->group_desc_count; i++) {
-               blk = fs->group_desc[i].bg_block_bitmap;
+               blk = ext2fs_block_bitmap_loc(fs, i);
                if (ext2fs_test_block_bitmap2(bmap, blk)) {
                        new_blk = translate_block(blk);
                        if (!new_blk)
                                continue;
-                       fs->group_desc[i].bg_block_bitmap = new_blk;
+                       ext2fs_block_bitmap_loc_set(fs, i, new_blk);
                }
 
-               blk = fs->group_desc[i].bg_inode_bitmap;
+               blk = ext2fs_inode_bitmap_loc(fs, i);
                if (ext2fs_test_block_bitmap2(bmap, blk)) {
                        new_blk = translate_block(blk);
                        if (!new_blk)
                                continue;
-                       fs->group_desc[i].bg_inode_bitmap = new_blk;
+                       ext2fs_inode_bitmap_loc_set(fs, i, new_blk);
                }
        }
        return 0;
@@ -1284,7 +1284,7 @@ static int expand_inode_table(ext2_filsys fs, unsigned long new_ino_size)
        tmp_new_itable = new_itable;
 
        for (i = 0; i < fs->group_desc_count; i++) {
-               blk = fs->group_desc[i].bg_inode_table;
+               blk = ext2fs_inode_table_loc(fs, i);
                retval = io_channel_read_blk64(fs->io, blk,
                                fs->inode_blocks_per_group, old_itable);
                if (retval)
@@ -1345,8 +1345,8 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
                count++;
                if ((count == fs->super->s_blocks_per_group) ||
                    (blk == ext2fs_blocks_count(fs->super)-1)) {
-                       fs->group_desc[group++].bg_free_blocks_count =
-                               group_free;
+                       ext2fs_bg_free_blocks_count_set(fs, group++,
+                                                       group_free);
                        count = 0;
                        group_free = 0;
                }
@@ -1370,8 +1370,8 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
                count++;
                if ((count == fs->super->s_inodes_per_group) ||
                    (ino == fs->super->s_inodes_count)) {
-                       fs->group_desc[group++].bg_free_inodes_count =
-                               group_free;
+                       ext2fs_bg_free_inodes_count_set(fs, group++,
+                                                       group_free);
                        count = 0;
                        group_free = 0;
                }
index 1bb6ed7..fd85d90 100644 (file)
@@ -111,11 +111,11 @@ static void determine_fs_stride(ext2_filsys fs)
                has_sb = ext2fs_bg_has_super(fs, group);
                if (group == 0 || has_sb != prev_has_sb)
                        goto next;
-               b_stride = fs->group_desc[group].bg_block_bitmap -
-                       fs->group_desc[group-1].bg_block_bitmap -
+               b_stride = ext2fs_block_bitmap_loc(fs, group) -
+                       ext2fs_block_bitmap_loc(fs, group - 1) -
                        fs->super->s_blocks_per_group;
-               i_stride = fs->group_desc[group].bg_inode_bitmap -
-                       fs->group_desc[group-1].bg_inode_bitmap -
+               i_stride = ext2fs_inode_bitmap_loc(fs, group) -
+                       ext2fs_inode_bitmap_loc(fs, group - 1) -
                        fs->super->s_blocks_per_group;
                if (b_stride != i_stride ||
                    b_stride < 0)
index 6f828a8..d73b9f6 100644 (file)
@@ -133,9 +133,9 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                                new_fs->super->s_reserved_gdt_blocks;
 
                input.group = i;
-               input.block_bitmap = new_fs->group_desc[i].bg_block_bitmap;
-               input.inode_bitmap = new_fs->group_desc[i].bg_inode_bitmap;
-               input.inode_table = new_fs->group_desc[i].bg_inode_table;
+               input.block_bitmap = ext2fs_block_bitmap_loc(new_fs, i);
+               input.inode_bitmap = ext2fs_inode_bitmap_loc(new_fs, i);
+               input.inode_table = ext2fs_inode_table_loc(new_fs, i);
                input.blocks_count = sb->s_blocks_per_group;
                if (i == new_fs->group_desc_count-1) {
                        input.blocks_count = ext2fs_blocks_count(new_fs->super) -
@@ -155,9 +155,9 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
                printf("new group will reserve %d blocks\n",
                       input.reserved_blocks);
                printf("new group has %d free blocks\n",
-                      new_fs->group_desc[i].bg_free_blocks_count);
+                      ext2fs_bg_free_blocks_count(new_fs, i),
                printf("new group has %d free inodes (%d blocks)\n",
-                      new_fs->group_desc[i].bg_free_inodes_count,
+                      ext2fs_bg_free_inodes_count(new_fs, i),
                       new_fs->inode_blocks_per_group);
                printf("Adding group #%d\n", input.group);
 #endif
index 538c7b7..abab8f3 100644 (file)
@@ -54,15 +54,11 @@ static errcode_t fix_sb_journal_backup(ext2_filsys fs);
 /*
  * Some helper CPP macros
  */
-#define FS_BLOCK_BM(fs, i) ((fs)->group_desc[(i)].bg_block_bitmap)
-#define FS_INODE_BM(fs, i) ((fs)->group_desc[(i)].bg_inode_bitmap)
-#define FS_INODE_TB(fs, i) ((fs)->group_desc[(i)].bg_inode_table)
+#define IS_BLOCK_BM(fs, i, blk) ((blk) == ext2fs_block_bitmap_loc((fs),(i)))
+#define IS_INODE_BM(fs, i, blk) ((blk) == ext2fs_inode_bitmap_loc((fs),(i)))
 
-#define IS_BLOCK_BM(fs, i, blk) ((blk) == FS_BLOCK_BM((fs),(i)))
-#define IS_INODE_BM(fs, i, blk) ((blk) == FS_INODE_BM((fs),(i)))
-
-#define IS_INODE_TB(fs, i, blk) (((blk) >= FS_INODE_TB((fs), (i))) && \
-                                ((blk) < (FS_INODE_TB((fs), (i)) + \
+#define IS_INODE_TB(fs, i, blk) (((blk) >= ext2fs_inode_table_loc((fs), (i))) && \
+                                ((blk) < (ext2fs_inode_table_loc((fs), (i)) + \
                                           (fs)->inode_blocks_per_group)))
 
 #define META_OVERHEAD(fs) (2 + (fs)->inode_blocks_per_group)
@@ -222,10 +218,10 @@ static void fix_uninit_block_bitmaps(ext2_filsys fs)
                             (blk >= old_desc_blk) &&
                             (blk < old_desc_blk + old_desc_blocks)) ||
                            (new_desc_blk && (blk == new_desc_blk)) ||
-                           (blk == fs->group_desc[g].bg_block_bitmap) ||
-                           (blk == fs->group_desc[g].bg_inode_bitmap) ||
-                           (blk >= fs->group_desc[g].bg_inode_table &&
-                            (blk < fs->group_desc[g].bg_inode_table
+                           (blk == ext2fs_block_bitmap_loc(fs, g)) ||
+                           (blk == ext2fs_inode_bitmap_loc(fs, g)) ||
+                           (blk >= ext2fs_inode_table_loc(fs, g) &&
+                            (blk < ext2fs_inode_table_loc(fs, g)
                              + fs->inode_blocks_per_group)))
                                ext2fs_fast_mark_block_bitmap2(fs->block_map, blk);
                        else
@@ -442,7 +438,8 @@ retry:
                for (i = fs->group_desc_count;
                     i < old_fs->group_desc_count; i++) {
                        free_gdp_blocks(fs, reserve_blocks,
-                                       &old_fs->group_desc[i]);
+                                       ext2fs_group_desc(old_fs,
+                                               old_fs->group_desc, i));
                }
                retval = 0;
                goto errout;
@@ -465,7 +462,7 @@ retry:
        } else
                numblocks = fs->super->s_blocks_per_group;
        i = old_fs->group_desc_count - 1;
-       fs->group_desc[i].bg_free_blocks_count += (numblocks-old_numblocks);
+       ext2fs_bg_free_blocks_count_set(fs, i, ext2fs_bg_free_blocks_count(fs, i) + (numblocks - old_numblocks));
        ext2fs_group_desc_csum_set(fs, i);
 
        /*
@@ -495,7 +492,7 @@ retry:
                        fs->super->s_reserved_gdt_blocks;
        for (i = old_fs->group_desc_count;
             i < fs->group_desc_count; i++) {
-               memset(&fs->group_desc[i], 0,
+               memset(ext2fs_group_desc(fs, fs->group_desc, i), 0,
                       sizeof(struct ext2_group_desc));
                adjblocks = 0;
 
@@ -548,10 +545,10 @@ retry:
                             ext2fs_free_blocks_count(fs->super) - adjblocks);
                fs->super->s_free_inodes_count +=
                        fs->super->s_inodes_per_group;
-               fs->group_desc[i].bg_free_blocks_count = numblocks;
-               fs->group_desc[i].bg_free_inodes_count =
-                       fs->super->s_inodes_per_group;
-               fs->group_desc[i].bg_used_dirs_count = 0;
+               ext2fs_bg_free_blocks_count_set(fs, i, numblocks);
+               ext2fs_bg_free_inodes_count_set(fs, i,
+                                               fs->super->s_inodes_per_group);
+               ext2fs_bg_used_dirs_count_set(fs, i, 0);
                ext2fs_group_desc_csum_set(fs, i);
 
                retval = ext2fs_allocate_group_table(fs, i, 0);
@@ -647,7 +644,7 @@ static errcode_t adjust_superblock(ext2_resize_t rfs, blk_t new_size)
                 * Write out the new inode table
                 */
                retval = io_channel_write_blk64(fs->io,
-                                               fs->group_desc[i].bg_inode_table,
+                                               ext2fs_inode_table_loc(fs, i),
                                                fs->inode_blocks_per_group,
                                                rfs->itable_buf);
                if (retval) goto errout;
@@ -705,7 +702,7 @@ static errcode_t mark_table_blocks(ext2_filsys fs,
                /*
                 * Mark the blocks used for the inode table
                 */
-               for (j = 0, b = fs->group_desc[i].bg_inode_table;
+               for (j = 0, b = ext2fs_inode_table_loc(fs, i);
                     j < (unsigned int) fs->inode_blocks_per_group;
                     j++, b++)
                        ext2fs_mark_block_bitmap2(bmap, b);
@@ -714,13 +711,13 @@ static errcode_t mark_table_blocks(ext2_filsys fs,
                 * Mark block used for the block bitmap
                 */
                ext2fs_mark_block_bitmap2(bmap,
-                                        fs->group_desc[i].bg_block_bitmap);
+                                        ext2fs_block_bitmap_loc(fs, i));
 
                /*
                 * Mark block used for the inode bitmap
                 */
                ext2fs_mark_block_bitmap2(bmap,
-                                        fs->group_desc[i].bg_inode_bitmap);
+                                        ext2fs_inode_bitmap_loc(fs, i));
        }
        return 0;
 }
@@ -745,13 +742,13 @@ static void mark_fs_metablock(ext2_resize_t rfs,
         * mark it as a block to be moved.
         */
        if (IS_BLOCK_BM(fs, group, blk)) {
-               FS_BLOCK_BM(fs, group) = 0;
+               ext2fs_block_bitmap_loc_set(fs, group, 0);
                rfs->needed_blocks++;
        } else if (IS_INODE_BM(fs, group, blk)) {
-               FS_INODE_BM(fs, group) = 0;
+               ext2fs_inode_bitmap_loc_set(fs, group, 0);
                rfs->needed_blocks++;
        } else if (IS_INODE_TB(fs, group, blk)) {
-               FS_INODE_TB(fs, group) = 0;
+               ext2fs_inode_table_loc_set(fs, group, 0);
                rfs->needed_blocks++;
        } else if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
                                              EXT4_FEATURE_RO_COMPAT_GDT_CSUM) &&
@@ -901,23 +898,23 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                                                  group_blk + has_super);
                }
 
-               if (fs->group_desc[i].bg_inode_table &&
-                   fs->group_desc[i].bg_inode_bitmap &&
-                   fs->group_desc[i].bg_block_bitmap)
+               if (ext2fs_inode_table_loc(fs, i) &&
+                   ext2fs_inode_bitmap_loc(fs, i) &&
+                   ext2fs_block_bitmap_loc(fs, i))
                        goto next_group;
 
                /*
                 * Reserve the existing meta blocks that we know
                 * aren't to be moved.
                 */
-               if (fs->group_desc[i].bg_block_bitmap)
+               if (ext2fs_block_bitmap_loc(fs, i))
                        ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
-                                fs->group_desc[i].bg_block_bitmap);
-               if (fs->group_desc[i].bg_inode_bitmap)
+                                ext2fs_block_bitmap_loc(fs, i));
+               if (ext2fs_inode_bitmap_loc(fs, i))
                        ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
-                                fs->group_desc[i].bg_inode_bitmap);
-               if (fs->group_desc[i].bg_inode_table)
-                       for (blk = fs->group_desc[i].bg_inode_table, j=0;
+                                ext2fs_inode_bitmap_loc(fs, i));
+               if (ext2fs_inode_table_loc(fs, i))
+                       for (blk = ext2fs_inode_table_loc(fs, i), j=0;
                             j < fs->inode_blocks_per_group ; j++, blk++)
                                ext2fs_mark_block_bitmap2(rfs->reserve_blocks,
                                                         blk);
@@ -954,16 +951,16 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                 * For those structures that have changed, we need to
                 * do bookkeepping.
                 */
-               if (FS_BLOCK_BM(old_fs, i) !=
-                   (blk = FS_BLOCK_BM(fs, i))) {
+               if (ext2fs_block_bitmap_loc(old_fs, i) !=
+                   (blk = ext2fs_block_bitmap_loc(fs, i))) {
                        ext2fs_block_alloc_stats(fs, blk, +1);
                        if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
                            !ext2fs_test_block_bitmap2(meta_bmap, blk))
                                ext2fs_mark_block_bitmap2(rfs->move_blocks,
                                                         blk);
                }
-               if (FS_INODE_BM(old_fs, i) !=
-                   (blk = FS_INODE_BM(fs, i))) {
+               if (ext2fs_inode_bitmap_loc(old_fs, i) !=
+                   (blk = ext2fs_inode_bitmap_loc(fs, i))) {
                        ext2fs_block_alloc_stats(fs, blk, +1);
                        if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
                            !ext2fs_test_block_bitmap2(meta_bmap, blk))
@@ -978,7 +975,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                 * can't have the inode table be destroyed during the
                 * block relocation phase.
                 */
-               if (FS_INODE_TB(fs, i) == FS_INODE_TB(old_fs, i))
+               if (ext2fs_inode_table_loc(fs, i) == ext2fs_inode_table_loc(old_fs, i))
                        goto next_group; /* inode table not moved */
 
                rfs->needed_blocks += fs->inode_blocks_per_group;
@@ -988,7 +985,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                 * allocation bitmap, and move any blocks that might
                 * be necessary.
                 */
-               for (blk = fs->group_desc[i].bg_inode_table, j=0;
+               for (blk = ext2fs_inode_table_loc(fs, i), j=0;
                     j < fs->inode_blocks_per_group ; j++, blk++) {
                        ext2fs_block_alloc_stats(fs, blk, +1);
                        if (ext2fs_test_block_bitmap2(old_fs->block_map, blk) &&
@@ -1001,7 +998,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
                 * Make sure the old inode table is reserved in the
                 * block reservation bitmap.
                 */
-               for (blk = rfs->old_fs->group_desc[i].bg_inode_table, j=0;
+               for (blk = ext2fs_inode_table_loc(rfs->old_fs, i), j=0;
                     j < fs->inode_blocks_per_group ; j++, blk++)
                        ext2fs_mark_block_bitmap2(rfs->reserve_blocks, blk);
 
@@ -1608,8 +1605,8 @@ static errcode_t move_itables(ext2_resize_t rfs)
         */
        to_move = moved = 0;
        for (i=0; i < max_groups; i++)
-               if (rfs->old_fs->group_desc[i].bg_inode_table !=
-                   fs->group_desc[i].bg_inode_table)
+               if (ext2fs_inode_table_loc(rfs->old_fs, i) !=
+                   ext2fs_inode_table_loc(fs, i))
                        to_move++;
 
        if (to_move == 0)
@@ -1625,8 +1622,8 @@ static errcode_t move_itables(ext2_resize_t rfs)
        rfs->old_fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
 
        for (i=0; i < max_groups; i++) {
-               old_blk = rfs->old_fs->group_desc[i].bg_inode_table;
-               new_blk = fs->group_desc[i].bg_inode_table;
+               old_blk = ext2fs_inode_table_loc(rfs->old_fs, i);
+               new_blk = ext2fs_inode_table_loc(fs, i);
                diff = new_blk - old_blk;
 
 #ifdef RESIZE2FS_DEBUG
@@ -1679,11 +1676,11 @@ static errcode_t move_itables(ext2_resize_t rfs)
                                goto errout;
                }
 
-               for (blk = rfs->old_fs->group_desc[i].bg_inode_table, j=0;
+               for (blk = ext2fs_inode_table_loc(rfs->old_fs, i), j=0;
                     j < fs->inode_blocks_per_group ; j++, blk++)
                        ext2fs_block_alloc_stats(fs, blk, -1);
 
-               rfs->old_fs->group_desc[i].bg_inode_table = new_blk;
+               ext2fs_inode_table_loc_set(rfs->old_fs, i, new_blk);
                ext2fs_group_desc_csum_set(rfs->old_fs, i);
                ext2fs_mark_super_dirty(rfs->old_fs);
                ext2fs_flush(rfs->old_fs);
@@ -1807,10 +1804,10 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
                         (blk >= old_desc_blk) &&
                         (blk < old_desc_blk + old_desc_blocks))) ||
                       ((new_desc_blk && (blk == new_desc_blk))) ||
-                      (blk == fs->group_desc[group].bg_block_bitmap) ||
-                      (blk == fs->group_desc[group].bg_inode_bitmap) ||
-                      ((blk >= fs->group_desc[group].bg_inode_table &&
-                        (blk < fs->group_desc[group].bg_inode_table
+                      (blk == ext2fs_block_bitmap_loc(fs, group)) ||
+                      (blk == ext2fs_inode_bitmap_loc(fs, group)) ||
+                      ((blk >= ext2fs_inode_table_loc(fs, group) &&
+                        (blk < ext2fs_inode_table_loc(fs, group)
                          + fs->inode_blocks_per_group))))) ||
                    (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk))) {
                        group_free++;
@@ -1819,8 +1816,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
                count++;
                if ((count == fs->super->s_blocks_per_group) ||
                    (blk == ext2fs_blocks_count(fs->super)-1)) {
-                       fs->group_desc[group].bg_free_blocks_count =
-                               group_free;
+                       ext2fs_bg_free_blocks_count_set(fs, group, group_free);
                        ext2fs_group_desc_csum_set(fs, group);
                        group++;
                        count = 0;
@@ -1859,8 +1855,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
                count++;
                if ((count == fs->super->s_inodes_per_group) ||
                    (ino == fs->super->s_inodes_count)) {
-                       fs->group_desc[group].bg_free_inodes_count =
-                               group_free;
+                       ext2fs_bg_free_inodes_count_set(fs, group, group_free);
                        ext2fs_group_desc_csum_set(fs, group);
                        group++;
                        count = 0;