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;
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);
}
}
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;
"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);
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,
/*
* 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,
/*
* 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));
}
}
}
}
/* 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;
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;
/*
} 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 {
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++;
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,
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);
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;
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,
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;
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);
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);
}
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);
(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
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. */
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);
}
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);
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)
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);
}
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)
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);
* 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 *
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);
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;
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);
/*
* 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;
/*
* 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;
/*
* 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;
}
#else
super_shadow = fs->super;
- group_shadow = fs->group_desc;
+ group_shadow = ext2fs_group_desc(fs, fs->group_desc, 0);
#endif
/*
__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);
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,
{
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;
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,
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;
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)
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);
};
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) {
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) {
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;
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;
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;
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)
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);
}
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;
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)) *
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);
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)) *
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;
}
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);
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;
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) +
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);
}
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;
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);
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);
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;
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))
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))
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) &&
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 "),
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,
/*
* 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);
/*
* 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));
}
}
}
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);
}
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));
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;
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++) {
{
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;
}
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;
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)
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;
}
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;
}
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)
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) -
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
/*
* 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)
(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
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;
} 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);
/*
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;
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);
* 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;
/*
* 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);
* 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;
}
* 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) &&
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);
* 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))
* 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;
* 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) &&
* 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);
*/
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)
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
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);
(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++;
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;
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;