summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValerie Aurora Henson <vaurora@redhat.com>2009-09-07 20:46:34 -0400
committerTheodore Ts'o <tytso@mit.edu>2009-09-07 20:46:34 -0400
commit4efbac6fed75c29d3d5f1b676b932754653a2ac5 (patch)
treeb5abaa3d97e473970064e649d9ed6f661b447a22
parenta63745e81cbb476b90c75ca3ca60b9ba4be95cae (diff)
downloade2fsprogs-4efbac6fed75c29d3d5f1b676b932754653a2ac5.tar.gz
Convert uses of super->s_*_blocks_count to ext2fs_*_blocks_count()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: Nick Dokos <nicholas.dokos@hp.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--debugfs/debugfs.c6
-rw-r--r--debugfs/logdump.c2
-rw-r--r--debugfs/lsdel.c2
-rw-r--r--debugfs/unused.c2
-rw-r--r--e2fsck/badblocks.c6
-rw-r--r--e2fsck/journal.c4
-rw-r--r--e2fsck/pass1.c24
-rw-r--r--e2fsck/pass2.c4
-rw-r--r--e2fsck/pass5.c22
-rw-r--r--e2fsck/super.c24
-rw-r--r--e2fsck/unix.c15
-rw-r--r--ext2ed/init.c11
-rw-r--r--ext2ed/super_com.c6
-rw-r--r--lib/ext2fs/alloc.c6
-rw-r--r--lib/ext2fs/alloc_sb.c4
-rw-r--r--lib/ext2fs/alloc_stats.c2
-rw-r--r--lib/ext2fs/alloc_tables.c6
-rw-r--r--lib/ext2fs/bb_inode.c2
-rw-r--r--lib/ext2fs/block.c6
-rw-r--r--lib/ext2fs/bmove.c2
-rw-r--r--lib/ext2fs/check_desc.c4
-rw-r--r--lib/ext2fs/closefs.c6
-rw-r--r--lib/ext2fs/csum.c2
-rw-r--r--lib/ext2fs/ext_attr.c2
-rw-r--r--lib/ext2fs/icount.c2
-rw-r--r--lib/ext2fs/initialize.c35
-rw-r--r--lib/ext2fs/mkjournal.c2
-rw-r--r--lib/ext2fs/openfs.c18
-rw-r--r--lib/ext2fs/rw_bitmaps.c6
-rw-r--r--lib/ext2fs/tst_badblocks.c2
-rw-r--r--misc/Makefile.in2
-rw-r--r--misc/e2freefrag.c10
-rw-r--r--misc/e2image.c2
-rw-r--r--misc/findsuper.c15
-rw-r--r--misc/mke2fs.c84
-rw-r--r--misc/tune2fs.c32
-rw-r--r--misc/util.c4
-rw-r--r--resize/main.c2
-rw-r--r--resize/online.c13
-rw-r--r--resize/resize2fs.c106
-rw-r--r--tests/progs/test_icount.c2
41 files changed, 260 insertions, 247 deletions
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 24aa664b..2d640f2c 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -256,8 +256,8 @@ void do_init_filesys(int argc, char **argv)
return;
memset(&param, 0, sizeof(struct ext2_super_block));
- param.s_blocks_count = parse_ulong(argv[2], argv[0],
- "blocks count", &err);
+ ext2fs_blocks_count_set(&param, parse_ulong(argv[2], argv[0],
+ "blocks count", &err));
if (err)
return;
retval = ext2fs_initialize(argv[1], 0, &param,
@@ -906,7 +906,7 @@ void do_dump_extents(int argc, char *argv[])
current_fs->blocksize) + 1;
if (logical_width < 5)
logical_width = 5;
- physical_width = int_log10(current_fs->super->s_blocks_count) + 1;
+ physical_width = int_log10(ext2fs_blocks_count(current_fs->super)) + 1;
if (physical_width < 5)
physical_width = 5;
diff --git a/debugfs/logdump.c b/debugfs/logdump.c
index 9a7108a6..971d2b34 100644
--- a/debugfs/logdump.c
+++ b/debugfs/logdump.c
@@ -368,7 +368,7 @@ static void dump_journal(char *cmdname, FILE *out_file,
fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
fprintf(out_file, "\tblocksize=%d\n", blocksize);
fprintf(out_file, "\tjournal data size %lu\n",
- (unsigned long) sb->s_blocks_count);
+ (unsigned long) ext2fs_blocks_count(sb));
}
}
diff --git a/debugfs/lsdel.c b/debugfs/lsdel.c
index 074fd165..7d9a74c4 100644
--- a/debugfs/lsdel.c
+++ b/debugfs/lsdel.c
@@ -59,7 +59,7 @@ static int lsdel_proc(ext2_filsys fs,
lsd->num_blocks++;
if (*block_nr < fs->super->s_first_data_block ||
- *block_nr >= fs->super->s_blocks_count) {
+ *block_nr >= ext2fs_blocks_count(fs->super)) {
lsd->bad_blocks++;
return BLOCK_ABORT;
}
diff --git a/debugfs/unused.c b/debugfs/unused.c
index 601b065b..598d08b3 100644
--- a/debugfs/unused.c
+++ b/debugfs/unused.c
@@ -36,7 +36,7 @@ void do_dump_unused(int argc EXT2FS_ATTR((unused)), char **argv)
return;
for (blk=current_fs->super->s_first_data_block;
- blk < current_fs->super->s_blocks_count; blk++) {
+ blk < ext2fs_blocks_count(current_fs->super); blk++) {
if (ext2fs_test_block_bitmap2(current_fs->block_map,blk))
continue;
retval = io_channel_read_blk64(current_fs->io, blk, 1, buf);
diff --git a/e2fsck/badblocks.c b/e2fsck/badblocks.c
index 87c69953..fa183b85 100644
--- a/e2fsck/badblocks.c
+++ b/e2fsck/badblocks.c
@@ -72,10 +72,10 @@ void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
goto fatal;
}
} else {
- sprintf(buf, "badblocks -b %d -X %s%s%s %d", fs->blocksize,
+ sprintf(buf, "badblocks -b %d -X %s%s%s %llu", fs->blocksize,
(ctx->options & E2F_OPT_PREEN) ? "" : "-s ",
(ctx->options & E2F_OPT_WRITECHECK) ? "-n " : "",
- fs->device_name, fs->super->s_blocks_count-1);
+ fs->device_name, ext2fs_blocks_count(fs->super)-1);
f = popen(buf, "r");
if (!f) {
com_err("read_bad_blocks_file", errno,
@@ -125,7 +125,7 @@ static int check_bb_inode_blocks(ext2_filsys fs,
/*
* If the block number is outrageous, clear it and ignore it.
*/
- if (*block_nr >= fs->super->s_blocks_count ||
+ if (*block_nr >= ext2fs_blocks_count(fs->super) ||
*block_nr < fs->super->s_first_data_block) {
printf(_("Warning: illegal block %u found in bad block inode. "
"Cleared.\n"), *block_nr);
diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index 7e30ea57..ffb1723e 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -215,7 +215,7 @@ static int process_journal_block(ext2_filsys fs,
p = (struct process_block_struct *) priv_data;
if (blk < fs->super->s_first_data_block ||
- blk >= fs->super->s_blocks_count)
+ blk >= ext2fs_blocks_count(fs->super))
return BLOCK_ABORT;
if (blockcnt >= 0)
@@ -409,7 +409,7 @@ static errcode_t e2fsck_get_journal(e2fsck_t ctx, journal_t **ret_journal)
goto errout;
}
- journal->j_maxlen = jsuper.s_blocks_count;
+ journal->j_maxlen = ext2fs_blocks_count(&jsuper);
start++;
}
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index c12e5f81..45ec11e0 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -191,7 +191,7 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
(extent.e_lblk != 0) ||
(extent.e_len != 1) ||
(extent.e_pblk < fs->super->s_first_data_block) ||
- (extent.e_pblk >= fs->super->s_blocks_count))
+ (extent.e_pblk >= ext2fs_blocks_count(fs->super)))
goto exit_extent;
i = 1;
exit_extent:
@@ -204,7 +204,7 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, ext2_ino_t ino,
if ((inode->i_size >= fs->blocksize) ||
(blocks != fs->blocksize >> 9) ||
(inode->i_block[0] < fs->super->s_first_data_block) ||
- (inode->i_block[0] >= fs->super->s_blocks_count))
+ (inode->i_block[0] >= ext2fs_blocks_count(fs->super)))
return 0;
for (i = 1; i < EXT2_N_BLOCKS; i++)
@@ -418,7 +418,7 @@ static void check_is_really_dir(e2fsck_t ctx, struct problem_context *pctx,
not_device++;
if (blk < ctx->fs->super->s_first_data_block ||
- blk >= ctx->fs->super->s_blocks_count ||
+ blk >= ext2fs_blocks_count(ctx->fs->super) ||
ext2fs_fast_test_block_bitmap2(ctx->block_found_map, blk))
return; /* Invalid block, can't be dir */
}
@@ -1382,7 +1382,7 @@ static int check_ext_attr(e2fsck_t ctx, struct problem_context *pctx,
*/
if (!(fs->super->s_feature_compat & EXT2_FEATURE_COMPAT_EXT_ATTR) ||
(blk < fs->super->s_first_data_block) ||
- (blk >= fs->super->s_blocks_count)) {
+ (blk >= ext2fs_blocks_count(fs->super))) {
mark_inode_bad(ctx, ino);
return 0;
}
@@ -1558,7 +1558,7 @@ static int handle_htree(e2fsck_t ctx, struct problem_context *pctx,
if ((pctx->errcode) ||
(blk == 0) ||
(blk < fs->super->s_first_data_block) ||
- (blk >= fs->super->s_blocks_count)) {
+ (blk >= ext2fs_blocks_count(fs->super))) {
if (fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
return 1;
else
@@ -1645,13 +1645,13 @@ static void scan_extent_node(e2fsck_t ctx, struct problem_context *pctx,
problem = 0;
if (extent.e_pblk < ctx->fs->super->s_first_data_block ||
- extent.e_pblk >= ctx->fs->super->s_blocks_count)
+ extent.e_pblk >= ext2fs_blocks_count(ctx->fs->super))
problem = PR_1_EXTENT_BAD_START_BLK;
else if (extent.e_lblk < start_block)
problem = PR_1_OUT_OF_ORDER_EXTENTS;
else if (is_leaf &&
(extent.e_pblk + extent.e_len) >
- ctx->fs->super->s_blocks_count)
+ ext2fs_blocks_count(ctx->fs->super))
problem = PR_1_EXTENT_ENDS_BEYOND;
if (problem) {
@@ -2008,8 +2008,8 @@ static char *describe_illegal_block(ext2_filsys fs, blk_t block)
if (block < super) {
sprintf(problem, "< FIRSTBLOCK (%u)", super);
return(problem);
- } else if (block >= fs->super->s_blocks_count) {
- sprintf(problem, "> BLOCKS (%u)", fs->super->s_blocks_count);
+ } else if (block >= ext2fs_blocks_count(fs->super)) {
+ sprintf(problem, "> BLOCKS (%u)", ext2fs_blocks_count(fs->super));
return(problem);
}
for (i = 0; i < fs->group_desc_count; i++) {
@@ -2153,7 +2153,7 @@ static int process_block(ext2_filsys fs,
problem = PR_1_TOOBIG_SYMLINK;
if (blk < fs->super->s_first_data_block ||
- blk >= fs->super->s_blocks_count)
+ blk >= ext2fs_blocks_count(fs->super))
problem = PR_1_ILLEGAL_BLOCK_NUM;
if (problem) {
@@ -2241,7 +2241,7 @@ static int process_bad_block(ext2_filsys fs,
pctx->blkcount = blockcnt;
if ((blk < fs->super->s_first_data_block) ||
- (blk >= fs->super->s_blocks_count)) {
+ (blk >= ext2fs_blocks_count(fs->super))) {
if (fix_problem(ctx, PR_1_BB_ILLEGAL_BLOCK_NUM, pctx)) {
*block_nr = 0;
return BLOCK_CHANGED;
@@ -2415,7 +2415,7 @@ static void new_table_block(e2fsck_t ctx, blk_t first_block, int group,
if (is_flexbg && (pctx.errcode == EXT2_ET_BLOCK_ALLOC_FAIL))
pctx.errcode = ext2fs_get_free_blocks2(fs,
fs->super->s_first_data_block,
- fs->super->s_blocks_count,
+ ext2fs_blocks_count(fs->super),
num, ctx->block_found_map, new_block);
if (pctx.errcode) {
pctx.num = num;
diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index 51b7fad4..067a9c71 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -1165,7 +1165,7 @@ static int deallocate_inode_block(ext2_filsys fs,
if (HOLE_BLKADDR(*block_nr))
return 0;
if ((*block_nr < fs->super->s_first_data_block) ||
- (*block_nr >= fs->super->s_blocks_count))
+ (*block_nr >= ext2fs_blocks_count(fs->super)))
return 0;
ext2fs_unmark_block_bitmap2(ctx->block_found_map, *block_nr);
ext2fs_block_alloc_stats(fs, *block_nr, -1);
@@ -1365,7 +1365,7 @@ extern int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,
if (ext2fs_file_acl_block(&inode) &&
((ext2fs_file_acl_block(&inode) < fs->super->s_first_data_block) ||
- (ext2fs_file_acl_block(&inode) >= fs->super->s_blocks_count))) {
+ (ext2fs_file_acl_block(&inode) >= ext2fs_blocks_count(fs->super)))) {
if (fix_problem(ctx, PR_2_FILE_ACL_BAD, &pctx)) {
ext2fs_file_acl_block_set(&inode, 0);
inode_modified++;
diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
index c27989ab..be5a2412 100644
--- a/e2fsck/pass5.c
+++ b/e2fsck/pass5.c
@@ -127,11 +127,11 @@ static void check_block_bitmaps(e2fsck_t ctx)
if ((fs->super->s_first_data_block <
ext2fs_get_block_bitmap_start2(ctx->block_found_map)) ||
- (fs->super->s_blocks_count-1 >
+ (ext2fs_blocks_count(fs->super)-1 >
ext2fs_get_block_bitmap_end2(ctx->block_found_map))) {
pctx.num = 1;
pctx.blk = fs->super->s_first_data_block;
- pctx.blk2 = fs->super->s_blocks_count -1;
+ pctx.blk2 = ext2fs_blocks_count(fs->super) -1;
pctx.ino = ext2fs_get_block_bitmap_start2(ctx->block_found_map);
pctx.ino2 = ext2fs_get_block_bitmap_end2(ctx->block_found_map);
fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
@@ -142,11 +142,11 @@ static void check_block_bitmaps(e2fsck_t ctx)
if ((fs->super->s_first_data_block <
ext2fs_get_block_bitmap_start2(fs->block_map)) ||
- (fs->super->s_blocks_count-1 >
+ (ext2fs_blocks_count(fs->super)-1 >
ext2fs_get_block_bitmap_end2(fs->block_map))) {
pctx.num = 2;
pctx.blk = fs->super->s_first_data_block;
- pctx.blk2 = fs->super->s_blocks_count -1;
+ pctx.blk2 = ext2fs_blocks_count(fs->super) -1;
pctx.ino = ext2fs_get_block_bitmap_start2(fs->block_map);
pctx.ino2 = ext2fs_get_block_bitmap_end2(fs->block_map);
fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
@@ -165,7 +165,7 @@ redo_counts:
(ext2fs_bg_flag_test(fs, group, EXT2_BG_BLOCK_UNINIT)))
skip_group++;
for (i = fs->super->s_first_data_block;
- i < fs->super->s_blocks_count;
+ i < ext2fs_blocks_count(fs->super);
i++) {
actual = ext2fs_fast_test_block_bitmap2(ctx->block_found_map, i);
@@ -190,7 +190,7 @@ redo_counts:
cmp_block = fs->super->s_blocks_per_group;
if (group == (int)fs->group_desc_count - 1)
cmp_block =
- fs->super->s_blocks_count %
+ ext2fs_blocks_count(fs->super) %
fs->super->s_blocks_per_group;
}
@@ -289,7 +289,7 @@ redo_counts:
}
blocks ++;
if ((blocks == fs->super->s_blocks_per_group) ||
- (i == fs->super->s_blocks_count-1)) {
+ (i == ext2fs_blocks_count(fs->super)-1)) {
free_array[group] = group_free;
group ++;
blocks = 0;
@@ -300,7 +300,7 @@ redo_counts:
fs->group_desc_count*2))
goto errout;
if (csum_flag &&
- (i != fs->super->s_blocks_count-1) &&
+ (i != ext2fs_blocks_count(fs->super)-1) &&
ext2fs_bg_flag_test(fs, group,
EXT2_BG_BLOCK_UNINIT))
skip_group++;
@@ -350,13 +350,13 @@ redo_counts:
ext2fs_unmark_valid(fs);
}
}
- if (free_blocks != fs->super->s_free_blocks_count) {
+ if (free_blocks != ext2fs_free_blocks_count(fs->super)) {
pctx.group = 0;
- pctx.blk = fs->super->s_free_blocks_count;
+ pctx.blk = ext2fs_free_blocks_count(fs->super);
pctx.blk2 = free_blocks;
if (fix_problem(ctx, PR_5_FREE_BLOCK_COUNT, &pctx)) {
- fs->super->s_free_blocks_count = free_blocks;
+ ext2fs_free_blocks_count_set(fs->super, free_blocks);
ext2fs_mark_super_dirty(fs);
} else
ext2fs_unmark_valid(fs);
diff --git a/e2fsck/super.c b/e2fsck/super.c
index 6b08688a..593b38ba 100644
--- a/e2fsck/super.c
+++ b/e2fsck/super.c
@@ -77,7 +77,7 @@ static int release_inode_block(ext2_filsys fs,
return 0;
if ((blk < fs->super->s_first_data_block) ||
- (blk >= fs->super->s_blocks_count)) {
+ (blk >= ext2fs_blocks_count(fs->super))) {
fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, pctx);
return_abort:
pb->abort = 1;
@@ -376,7 +376,7 @@ void check_resize_inode(e2fsck_t ctx)
if ((i < EXT2_N_BLOCKS) || !blk || !inode.i_links_count ||
!(inode.i_mode & LINUX_S_IFREG) ||
(blk < fs->super->s_first_data_block ||
- blk >= fs->super->s_blocks_count)) {
+ blk >= ext2fs_blocks_count(fs->super))) {
resize_inode_invalid:
if (fix_problem(ctx, PR_0_RESIZE_INODE_INVALID, &pctx)) {
memset(&inode, 0, sizeof(inode));
@@ -495,10 +495,10 @@ void check_super_block(e2fsck_t ctx)
*/
check_super_value(ctx, "inodes_count", sb->s_inodes_count,
MIN_CHECK, 1, 0);
- check_super_value(ctx, "blocks_count", sb->s_blocks_count,
+ check_super_value(ctx, "blocks_count", ext2fs_blocks_count(sb),
MIN_CHECK, 1, 0);
check_super_value(ctx, "first_data_block", sb->s_first_data_block,
- MAX_CHECK, 0, sb->s_blocks_count);
+ MAX_CHECK, 0, ext2fs_blocks_count(sb));
check_super_value(ctx, "log_block_size", sb->s_log_block_size,
MIN_CHECK | MAX_CHECK, 0,
EXT2_MAX_BLOCK_LOG_SIZE - EXT2_MIN_BLOCK_LOG_SIZE);
@@ -511,8 +511,8 @@ void check_super_block(e2fsck_t ctx)
MIN_CHECK | MAX_CHECK, 8, bpg_max);
check_super_value(ctx, "inodes_per_group", sb->s_inodes_per_group,
MIN_CHECK | MAX_CHECK, inodes_per_block, ipg_max);
- check_super_value(ctx, "r_blocks_count", sb->s_r_blocks_count,
- MAX_CHECK, 0, sb->s_blocks_count / 2);
+ check_super_value(ctx, "r_blocks_count", ext2fs_r_blocks_count(sb),
+ MAX_CHECK, 0, ext2fs_blocks_count(sb) / 2);
check_super_value(ctx, "reserved_gdt_blocks",
sb->s_reserved_gdt_blocks, MAX_CHECK, 0,
fs->blocksize/4);
@@ -533,8 +533,8 @@ void check_super_block(e2fsck_t ctx)
}
if ((ctx->flags & E2F_FLAG_GOT_DEVSIZE) &&
- (ctx->num_blocks < sb->s_blocks_count)) {
- pctx.blk = sb->s_blocks_count;
+ (ctx->num_blocks < ext2fs_blocks_count(sb))) {
+ pctx.blk = ext2fs_blocks_count(sb);
pctx.blk2 = ctx->num_blocks;
if (fix_problem(ctx, PR_0_FS_SIZE_WRONG, &pctx)) {
ctx->flags |= E2F_FLAG_ABORT;
@@ -583,7 +583,7 @@ void check_super_block(e2fsck_t ctx)
* Verify the group descriptors....
*/
first_block = sb->s_first_data_block;
- last_block = sb->s_blocks_count-1;
+ last_block = ext2fs_blocks_count(sb)-1;
csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
@@ -702,18 +702,18 @@ void check_super_block(e2fsck_t ctx)
* inodes; if the filesystem is not unmounted cleanly, the
* global counts may not be accurate.
*/
- if ((free_blocks != sb->s_free_blocks_count) ||
+ if ((free_blocks != ext2fs_free_blocks_count(sb)) ||
(free_inodes != sb->s_free_inodes_count)) {
if (ctx->options & E2F_OPT_READONLY)
ext2fs_unmark_valid(fs);
else {
- sb->s_free_blocks_count = free_blocks;
+ ext2fs_free_blocks_count_set(sb, free_blocks);
sb->s_free_inodes_count = free_inodes;
ext2fs_mark_super_dirty(fs);
}
}
- if ((sb->s_free_blocks_count > sb->s_blocks_count) ||
+ if ((ext2fs_free_blocks_count(sb) > ext2fs_blocks_count(sb)) ||
(sb->s_free_inodes_count > sb->s_inodes_count))
ext2fs_unmark_valid(fs);
diff --git a/e2fsck/unix.c b/e2fsck/unix.c
index 9d08f43f..e6296028 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -113,9 +113,9 @@ static void show_stats(e2fsck_t ctx)
inodes = fs->super->s_inodes_count;
inodes_used = (fs->super->s_inodes_count -
fs->super->s_free_inodes_count);
- blocks = fs->super->s_blocks_count;
- blocks_used = (fs->super->s_blocks_count -
- fs->super->s_free_blocks_count);
+ blocks = ext2fs_blocks_count(fs->super);
+ blocks_used = (ext2fs_blocks_count(fs->super) -
+ ext2fs_free_blocks_count(fs->super));
frag_percent_file = (10000 * ctx->fs_fragmented) / inodes_used;
frag_percent_file = (frag_percent_file + 5) / 10;
@@ -339,11 +339,12 @@ static void check_if_skip(e2fsck_t ctx)
fputs(_(", check forced.\n"), stdout);
return;
}
- printf(_("%s: clean, %u/%u files, %u/%u blocks"), ctx->device_name,
+ printf(_("%s: clean, %u/%u files, %llu/%llu blocks"), ctx->device_name,
fs->super->s_inodes_count - fs->super->s_free_inodes_count,
fs->super->s_inodes_count,
- fs->super->s_blocks_count - fs->super->s_free_blocks_count,
- fs->super->s_blocks_count);
+ ext2fs_blocks_count(fs->super) -
+ ext2fs_free_blocks_count(fs->super),
+ ext2fs_blocks_count(fs->super));
next_check = 100000;
if (fs->super->s_max_mnt_count > 0) {
next_check = fs->super->s_max_mnt_count - fs->super->s_mnt_count;
@@ -1331,7 +1332,7 @@ print_unsupp_features:
if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
if (journal_size < 1024)
- journal_size = ext2fs_default_journal_size(fs->super->s_blocks_count);
+ journal_size = ext2fs_default_journal_size(ext2fs_blocks_count(fs->super));
if (journal_size < 0) {
fs->super->s_feature_compat &=
~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
diff --git a/ext2ed/init.c b/ext2ed/init.c
index 41c2a398..3815ab56 100644
--- a/ext2ed/init.c
+++ b/ext2ed/init.c
@@ -370,13 +370,6 @@ void add_user_command (struct struct_commands *ptr,char *name,char *description,
ptr->callback [num]=callback;
}
-static unsigned int div_ceil(unsigned int a, unsigned int b)
-{
- if (!a)
- return 0;
- return ((a - 1) / b) + 1;
-}
-
int set_file_system_info (void)
{
@@ -422,13 +415,13 @@ int set_file_system_info (void)
file_system_info.first_group_desc_offset=2*EXT2_MIN_BLOCK_SIZE;
else
file_system_info.first_group_desc_offset=file_system_info.block_size;
- file_system_info.groups_count = div_ceil(sb->s_blocks_count,
+ file_system_info.groups_count = ext2fs_div64_ceil(ext2fs_blocks_count(sb),
sb->s_blocks_per_group);
file_system_info.inodes_per_block=file_system_info.block_size/sizeof (struct ext2_inode);
file_system_info.blocks_per_group=sb->s_inodes_per_group/file_system_info.inodes_per_block;
file_system_info.no_blocks_in_group=sb->s_blocks_per_group;
- file_system_info.file_system_size=(sb->s_blocks_count-1)*file_system_info.block_size;
+ file_system_info.file_system_size=(ext2fs_blocks_count(sb)-1)*file_system_info.block_size;
}
else {
diff --git a/ext2ed/super_com.c b/ext2ed/super_com.c
index 3d30070b..57953ab6 100644
--- a/ext2ed/super_com.c
+++ b/ext2ed/super_com.c
@@ -29,9 +29,9 @@ void type_ext2_super_block___show (char *command_line)
show (command_line);
- if (super->s_blocks_count != 0) {
- wmove (show_pad,2,40);wprintw (show_pad,"%2.2f%%",100*(float) super->s_r_blocks_count/ (float) super->s_blocks_count);
- wmove (show_pad,3,40);wprintw (show_pad,"%2.2f%%",100*(float) super->s_free_blocks_count/ (float) super->s_blocks_count);
+ if (ext2fs_blocks_count(super) != 0) {
+ wmove (show_pad,2,40);wprintw (show_pad,"%2.2f%%",100*(float) ext2fs_r_blocks_count(super)/ (float) ext2fs_blocks_count(super));
+ wmove (show_pad,3,40);wprintw (show_pad,"%2.2f%%",100*(float) ext2fs_free_blocks_count(super)/ (float) ext2fs_blocks_count(super));
}
if (super->s_inodes_count != 0) {
diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c
index 2c38bc9e..24ab05bb 100644
--- a/lib/ext2fs/alloc.c
+++ b/lib/ext2fs/alloc.c
@@ -157,7 +157,7 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal,
map = fs->block_map;
if (!map)
return EXT2_ET_NO_BLOCK_BITMAP;
- if (!goal || (goal >= fs->super->s_blocks_count))
+ if (!goal || (goal >= ext2fs_blocks_count(fs->super)))
goal = fs->super->s_first_data_block;
i = goal;
check_block_uninit(fs, map,
@@ -175,7 +175,7 @@ errcode_t ext2fs_new_block2(ext2_filsys fs, blk64_t goal,
return 0;
}
i++;
- if (i >= fs->super->s_blocks_count)
+ if (i >= ext2fs_blocks_count(fs->super))
i = fs->super->s_first_data_block;
} while (i != goal);
return EXT2_ET_BLOCK_ALLOC_FAIL;
@@ -269,7 +269,7 @@ errcode_t ext2fs_get_free_blocks2(ext2_filsys fs, blk64_t start, blk64_t finish,
if (!num)
num = 1;
do {
- if (b+num-1 > fs->super->s_blocks_count)
+ if (b+num-1 > ext2fs_blocks_count(fs->super))
b = fs->super->s_first_data_block;
if (ext2fs_fast_test_block_bitmap_range2(map, b, num)) {
*ret = b;
diff --git a/lib/ext2fs/alloc_sb.c b/lib/ext2fs/alloc_sb.c
index 8bb88275..37f21404 100644
--- a/lib/ext2fs/alloc_sb.c
+++ b/lib/ext2fs/alloc_sb.c
@@ -64,7 +64,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
if (fs->super->s_reserved_gdt_blocks && fs->block_map == bmap)
ext2fs_bg_flag_clear(fs, group, EXT2_BG_BLOCK_UNINIT);
for (j=0; j < old_desc_blocks; j++)
- if (old_desc_blk + j < fs->super->s_blocks_count)
+ if (old_desc_blk + j < ext2fs_blocks_count(fs->super))
ext2fs_mark_block_bitmap2(bmap,
old_desc_blk + j);
}
@@ -72,7 +72,7 @@ int ext2fs_reserve_super_and_bgd(ext2_filsys fs,
ext2fs_mark_block_bitmap2(bmap, new_desc_blk);
if (group == fs->group_desc_count-1) {
- num_blocks = (fs->super->s_blocks_count -
+ num_blocks = (ext2fs_blocks_count(fs->super) -
fs->super->s_first_data_block) %
fs->super->s_blocks_per_group;
if (!num_blocks)
diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c
index 9180b5c5..0ea06ab2 100644
--- a/lib/ext2fs/alloc_stats.c
+++ b/lib/ext2fs/alloc_stats.c
@@ -66,7 +66,7 @@ void ext2fs_block_alloc_stats2(ext2_filsys fs, blk64_t blk, int inuse)
int group = ext2fs_group_of_blk2(fs, blk);
#ifndef OMIT_COM_ERR
- if (blk >= fs->super->s_blocks_count) {
+ if (blk >= ext2fs_blocks_count(fs->super)) {
com_err("ext2fs_block_alloc_stats", 0,
"Illegal block number: %lu", (unsigned long) blk);
return;
diff --git a/lib/ext2fs/alloc_tables.c b/lib/ext2fs/alloc_tables.c
index 952bbcc7..94aeedae 100644
--- a/lib/ext2fs/alloc_tables.c
+++ b/lib/ext2fs/alloc_tables.c
@@ -142,7 +142,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
if (flexbg_size) {
dgrp_t gr = ext2fs_group_of_blk(fs, new_blk);
fs->group_desc[gr].bg_free_blocks_count--;
- fs->super->s_free_blocks_count--;
+ ext2fs_free_blocks_count_add(fs->super, -1);
ext2fs_bg_flag_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
ext2fs_group_desc_csum_set(fs, gr);
}
@@ -170,7 +170,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
if (flexbg_size) {
dgrp_t gr = ext2fs_group_of_blk(fs, new_blk);
fs->group_desc[gr].bg_free_blocks_count--;
- fs->super->s_free_blocks_count--;
+ ext2fs_free_blocks_count_add(fs->super, -1);
ext2fs_bg_flag_clear(fs, gr, EXT2_BG_BLOCK_UNINIT);
ext2fs_group_desc_csum_set(fs, gr);
}
@@ -204,7 +204,7 @@ errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
if (flexbg_size) {
dgrp_t gr = ext2fs_group_of_blk(fs, blk);
fs->group_desc[gr].bg_free_blocks_count--;
- fs->super->s_free_blocks_count--;
+ ext2fs_free_blocks_count_add(fs->super, -1);
ext2fs_bg_flag_clear(fs, gr,
EXT2_BG_BLOCK_UNINIT);
ext2fs_group_desc_csum_set(fs, gr);
diff --git a/lib/ext2fs/bb_inode.c b/lib/ext2fs/bb_inode.c
index bbebf6f0..f5a093dc 100644
--- a/lib/ext2fs/bb_inode.c
+++ b/lib/ext2fs/bb_inode.c
@@ -166,7 +166,7 @@ static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
/*
* If the block number is outrageous, clear it and ignore it.
*/
- if (*block_nr >= fs->super->s_blocks_count ||
+ if (*block_nr >= ext2fs_blocks_count(fs->super) ||
*block_nr < fs->super->s_first_data_block) {
*block_nr = 0;
return BLOCK_CHANGED;
diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c
index fc76ff20..ea3786df 100644
--- a/lib/ext2fs/block.c
+++ b/lib/ext2fs/block.c
@@ -78,7 +78,7 @@ static int block_iterate_ind(blk_t *ind_block, blk_t ref_block,
ctx->bcount += limit;
return ret;
}
- if (*ind_block >= ctx->fs->super->s_blocks_count ||
+ if (*ind_block >= ext2fs_blocks_count(ctx->fs->super) ||
*ind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_IND_BLOCK;
ret |= BLOCK_ERROR;
@@ -166,7 +166,7 @@ static int block_iterate_dind(blk_t *dind_block, blk_t ref_block,
ctx->bcount += limit*limit;
return ret;
}
- if (*dind_block >= ctx->fs->super->s_blocks_count ||
+ if (*dind_block >= ext2fs_blocks_count(ctx->fs->super) ||
*dind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_DIND_BLOCK;
ret |= BLOCK_ERROR;
@@ -252,7 +252,7 @@ static int block_iterate_tind(blk_t *tind_block, blk_t ref_block,
ctx->bcount += limit*limit*limit;
return ret;
}
- if (*tind_block >= ctx->fs->super->s_blocks_count ||
+ if (*tind_block >= ext2fs_blocks_count(ctx->fs->super) ||
*tind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_TIND_BLOCK;
ret |= BLOCK_ERROR;
diff --git a/lib/ext2fs/bmove.c b/lib/ext2fs/bmove.c
index 49839c63..b2f7cecd 100644
--- a/lib/ext2fs/bmove.c
+++ b/lib/ext2fs/bmove.c
@@ -50,7 +50,7 @@ static int process_block(ext2_filsys fs, blk_t *block_nr,
*/
if (ext2fs_test_block_bitmap2(pb->reserve, block)) {
do {
- if (++block >= fs->super->s_blocks_count)
+ if (++block >= ext2fs_blocks_count(fs->super))
block = fs->super->s_first_data_block;
if (block == orig) {
pb->error = EXT2_ET_BLOCK_ALLOC_FAIL;
diff --git a/lib/ext2fs/check_desc.c b/lib/ext2fs/check_desc.c
index 99b1ae4f..3ce38e68 100644
--- a/lib/ext2fs/check_desc.c
+++ b/lib/ext2fs/check_desc.c
@@ -35,7 +35,7 @@ errcode_t ext2fs_check_desc(ext2_filsys fs)
errcode_t retval;
dgrp_t i;
blk_t first_block = fs->super->s_first_data_block;
- blk_t last_block = fs->super->s_blocks_count-1;
+ blk_t last_block = ext2fs_blocks_count(fs->super)-1;
blk_t blk, b;
int j;
@@ -54,7 +54,7 @@ errcode_t ext2fs_check_desc(ext2_filsys fs)
first_block = ext2fs_group_first_block(fs, i);
last_block = ext2fs_group_last_block(fs, i);
if (i == (fs->group_desc_count - 1))
- last_block = fs->super->s_blocks_count-1;
+ last_block = ext2fs_blocks_count(fs->super)-1;
}
/*
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 613908b4..c505f006 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -151,9 +151,9 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,
&ret_used_blks);
if (group == fs->group_desc_count-1) {
- numblocks = (fs->super->s_blocks_count -
- fs->super->s_first_data_block) %
- fs->super->s_blocks_per_group;
+ numblocks = (ext2fs_blocks_count(fs->super) -
+ (blk64_t) fs->super->s_first_data_block) %
+ (blk64_t) fs->super->s_blocks_per_group;
if (!numblocks)
numblocks = fs->super->s_blocks_per_group;
} else
diff --git a/lib/ext2fs/csum.c b/lib/ext2fs/csum.c
index 39a99e4d..dca42a0f 100644
--- a/lib/ext2fs/csum.c
+++ b/lib/ext2fs/csum.c
@@ -183,7 +183,7 @@ int main(int argc, char **argv)
__u16 csum1, csum2, csum_known = 0xd3a4;
memset(&param, 0, sizeof(param));
- param.s_blocks_count = 32768;
+ ext2fs_blocks_count_set(&param, 32768);
retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, &param,
test_io_manager, &fs);
diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c
index b1025e29..9ba37b2e 100644
--- a/lib/ext2fs/ext_attr.c
+++ b/lib/ext2fs/ext_attr.c
@@ -117,7 +117,7 @@ errcode_t ext2fs_adjust_ea_refcount2(ext2_filsys fs, blk64_t blk,
struct ext2_ext_attr_header *header;
char *buf = 0;
- if ((blk >= fs->super->s_blocks_count) ||
+ if ((blk >= ext2fs_blocks_count(fs->super)) ||
(blk < fs->super->s_first_data_block))
return EXT2_ET_BAD_EA_BLOCK_NUM;
diff --git a/lib/ext2fs/icount.c b/lib/ext2fs/icount.c
index 52039304..bf80eb1b 100644
--- a/lib/ext2fs/icount.c
+++ b/lib/ext2fs/icount.c
@@ -744,7 +744,7 @@ static void setup(void)
initialize_ext2_error_table();
memset(&param, 0, sizeof(param));
- param.s_blocks_count = 12000;
+ ext2fs_blocks_count_set(&param, 12000);
retval = ext2fs_initialize("test fs", EXT2_FLAG_64BITS, &param,
test_io_manager, &test_fs);
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 73c4fec4..edcdd72e 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -75,8 +75,8 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs)
/* We set it at 1024x the current filesystem size, or
* the upper block count limit (2^32), whichever is lower.
*/
- if (sb->s_blocks_count < max_blocks / 1024)
- max_blocks = sb->s_blocks_count * 1024;
+ if (ext2fs_blocks_count(sb) < max_blocks / 1024)
+ max_blocks = ext2fs_blocks_count(sb) * 1024;
rsv_groups = ext2fs_div_ceil(max_blocks - sb->s_first_data_block, bpg);
rsv_gdb = ext2fs_div_ceil(rsv_groups, gdpb) - fs->desc_blocks;
if (rsv_gdb > EXT2_ADDR_PER_BLOCK(sb))
@@ -108,7 +108,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
char *buf = 0;
char c;
- if (!param || !param->s_blocks_count)
+ if (!param || !ext2fs_blocks_count(param))
return EXT2_ET_INVALID_ARGUMENT;
retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs);
@@ -200,9 +200,9 @@ errcode_t ext2fs_initialize(const char *name, int flags,
super->s_blocks_per_group = EXT2_MAX_BLOCKS_PER_GROUP(super);
super->s_frags_per_group = super->s_blocks_per_group * frags_per_block;
- super->s_blocks_count = param->s_blocks_count;
- super->s_r_blocks_count = param->s_r_blocks_count;
- if (super->s_r_blocks_count >= param->s_blocks_count) {
+ ext2fs_blocks_count_set(super, ext2fs_blocks_count(param));
+ ext2fs_r_blocks_count_set(super, ext2fs_r_blocks_count(param));
+ if (ext2fs_r_blocks_count(super) >= ext2fs_blocks_count(param)) {
retval = EXT2_ET_INVALID_ARGUMENT;
goto cleanup;
}
@@ -219,9 +219,9 @@ errcode_t ext2fs_initialize(const char *name, int flags,
}
retry:
- fs->group_desc_count = ext2fs_div_ceil(super->s_blocks_count -
- super->s_first_data_block,
- EXT2_BLOCKS_PER_GROUP(super));
+ fs->group_desc_count = (blk_t) ext2fs_div64_ceil(
+ ext2fs_blocks_count(super) - super->s_first_data_block,
+ EXT2_BLOCKS_PER_GROUP(super));
if (fs->group_desc_count == 0) {
retval = EXT2_ET_TOOSMALL;
goto cleanup;
@@ -230,7 +230,7 @@ retry:
EXT2_DESC_PER_BLOCK(super));
i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize;
- set_field(s_inodes_count, super->s_blocks_count / i);
+ set_field(s_inodes_count, ext2fs_blocks_count(super) / i);
/*
* Make sure we have at least EXT2_FIRST_INO + 1 inodes, so
@@ -250,7 +250,8 @@ retry:
if (super->s_blocks_per_group >= 256) {
/* Try again with slightly different parameters */
super->s_blocks_per_group -= 8;
- super->s_blocks_count = param->s_blocks_count;
+ ext2fs_blocks_count_set(super,
+ ext2fs_blocks_count(param));
super->s_frags_per_group = super->s_blocks_per_group *
frags_per_block;
goto retry;
@@ -338,14 +339,16 @@ ipg_retry:
overhead = (int) (2 + fs->inode_blocks_per_group);
if (ext2fs_bg_has_super(fs, fs->group_desc_count - 1))
overhead += 1 + fs->desc_blocks + super->s_reserved_gdt_blocks;
- rem = ((super->s_blocks_count - super->s_first_data_block) %
+ rem = ((ext2fs_blocks_count(super) - super->s_first_data_block) %
super->s_blocks_per_group);
if ((fs->group_desc_count == 1) && rem && (rem < overhead)) {
retval = EXT2_ET_TOOSMALL;
goto cleanup;
}
if (rem && (rem < overhead+50)) {
- super->s_blocks_count -= rem;
+ ext2fs_blocks_count_set(super, ext2fs_blocks_count(super) -
+ rem);
+
goto retry;
}
@@ -391,7 +394,7 @@ ipg_retry:
* superblock and group descriptors (the inode tables and
* bitmaps will be accounted for when allocated).
*/
- super->s_free_blocks_count = 0;
+ ext2fs_free_blocks_count_set(super, 0);
csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
for (i = 0; i < fs->group_desc_count; i++) {
@@ -413,7 +416,9 @@ ipg_retry:
if (fs->super->s_log_groups_per_flex)
numblocks += 2 + fs->inode_blocks_per_group;
- super->s_free_blocks_count += numblocks;
+ 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;
diff --git a/lib/ext2fs/mkjournal.c b/lib/ext2fs/mkjournal.c
index 7c5668de..6ba11747 100644
--- a/lib/ext2fs/mkjournal.c
+++ b/lib/ext2fs/mkjournal.c
@@ -321,7 +321,7 @@ static errcode_t write_journal_inode(ext2_filsys fs, ext2_ino_t journal_ino,
* the filesystem. Pick a group that has the largest number
* of free blocks.
*/
- group = ext2fs_group_of_blk(fs, (fs->super->s_blocks_count -
+ group = ext2fs_group_of_blk(fs, (ext2fs_blocks_count(fs->super) -
fs->super->s_first_data_block) / 2);
log_flex = 1 << fs->super->s_log_groups_per_flex;
if (fs->super->s_log_groups_per_flex && (group > log_flex)) {
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 2d78290a..8b486176 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -54,7 +54,7 @@ blk64_t ext2fs_descriptor_block_loc2(ext2_filsys fs, blk64_t group_block,
*/
if (group_block != fs->super->s_first_data_block &&
((ret_blk + fs->super->s_blocks_per_group) <
- fs->super->s_blocks_count))
+ ext2fs_blocks_count(fs->super)))
ret_blk += fs->super->s_blocks_per_group;
return ret_blk;
}
@@ -288,18 +288,18 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(fs->super) ||
fs->inode_blocks_per_group > EXT2_MAX_INODES_PER_GROUP(fs->super) ||
EXT2_DESC_PER_BLOCK(fs->super) == 0 ||
- fs->super->s_first_data_block >= fs->super->s_blocks_count) {
+ fs->super->s_first_data_block >= ext2fs_blocks_count(fs->super)) {
retval = EXT2_ET_CORRUPT_SUPERBLOCK;
goto cleanup;
}
- fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
- fs->super->s_first_data_block,
- blocks_per_group);
- if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) !=
- fs->super->s_inodes_count) {
- retval = EXT2_ET_CORRUPT_SUPERBLOCK;
+ fs->group_desc_count = ext2fs_div64_ceil(ext2fs_blocks_count(fs->super) -
+ fs->super->s_first_data_block,
+ blocks_per_group);
+ if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) !=
+ fs->super->s_inodes_count) {
+ retval = EXT2_ET_CORRUPT_SUPERBLOCK;
goto cleanup;
- }
+ }
fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
EXT2_DESC_PER_BLOCK(fs->super));
retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c
index a1006186..7878be61 100644
--- a/lib/ext2fs/rw_bitmaps.c
+++ b/lib/ext2fs/rw_bitmaps.c
@@ -81,9 +81,9 @@ static errcode_t write_bitmaps(ext2_filsys fs, int do_inode, int do_block)
if (i == fs->group_desc_count - 1) {
/* Force bitmap padding for the last group */
- nbits = ((fs->super->s_blocks_count
- - fs->super->s_first_data_block)
- % EXT2_BLOCKS_PER_GROUP(fs->super));
+ nbits = ((ext2fs_blocks_count(fs->super)
+ - (__u64) fs->super->s_first_data_block)
+ % (__u64) EXT2_BLOCKS_PER_GROUP(fs->super));
if (nbits)
for (j = nbits; j < fs->blocksize * 8; j++)
ext2fs_set_bit(j, block_buf);
diff --git a/lib/ext2fs/tst_badblocks.c b/lib/ext2fs/tst_badblocks.c
index 358da209..72b14b7a 100644
--- a/lib/ext2fs/tst_badblocks.c
+++ b/lib/ext2fs/tst_badblocks.c
@@ -227,7 +227,7 @@ int file_test_invalid(badblocks_list bb)
fs->super = malloc(SUPERBLOCK_SIZE);
memset(fs->super, 0, SUPERBLOCK_SIZE);
fs->super->s_first_data_block = 1;
- fs->super->s_blocks_count = 100;
+ ext2fs_blocks_count_set(fs->super, 100);
f = tmpfile();
if (!f) {
diff --git a/misc/Makefile.in b/misc/Makefile.in
index edcab83f..123922ff 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -127,7 +127,7 @@ profile.o:
findsuper: findsuper.o
$(E) " LD $@"
- $(Q) $(CC) $(ALL_LDFLAGS) -o findsuper findsuper.o
+ $(Q) $(CC) $(ALL_LDFLAGS) -o findsuper findsuper.o $(LIBS)
partinfo: partinfo.o
$(E) " LD $@"
diff --git a/misc/e2freefrag.c b/misc/e2freefrag.c
index 7e6abe1d..edbe0bb0 100644
--- a/misc/e2freefrag.c
+++ b/misc/e2freefrag.c
@@ -91,7 +91,7 @@ void update_chunk_stats(struct chunk_info *info, unsigned long chunk_size)
void scan_block_bitmap(ext2_filsys fs, struct chunk_info *info)
{
- unsigned long long blocks_count = fs->super->s_blocks_count;
+ unsigned long long blocks_count = ext2fs_blocks_count(fs->super);
unsigned long long chunks = (blocks_count + info->blks_in_chunk) >>
(info->chunkbits - info->blocksize_bits);
unsigned long long chunk_num;
@@ -149,15 +149,15 @@ errcode_t get_chunk_info(ext2_filsys fs, struct chunk_info *info)
scan_block_bitmap(fs, info);
- printf("Total blocks: %u\nFree blocks: %u (%0.1f%%)\n",
- fs->super->s_blocks_count, fs->super->s_free_blocks_count,
+ printf("Total blocks: %llu\nFree blocks: %u (%0.1f%%)\n",
+ ext2fs_blocks_count(fs->super), fs->super->s_free_blocks_count,
(double)fs->super->s_free_blocks_count * 100 /
- fs->super->s_blocks_count);
+ ext2fs_blocks_count(fs->super));
if (info->chunkbytes) {
printf("\nChunksize: %lu bytes (%u blocks)\n",
info->chunkbytes, info->blks_in_chunk);
- total_chunks = (fs->super->s_blocks_count +
+ total_chunks = (ext2fs_blocks_count(fs->super) +
info->blks_in_chunk) >>
(info->chunkbits - info->blocksize_bits);
printf("Total chunks: %lu\nFree chunks: %lu (%0.1f%%)\n",
diff --git a/misc/e2image.c b/misc/e2image.c
index abbf6410..3802c993 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -421,7 +421,7 @@ static void output_meta_data_blocks(ext2_filsys fs, int fd)
exit(1);
}
memset(zero_buf, 0, fs->blocksize);
- for (blk = 0; blk < fs->super->s_blocks_count; blk++) {
+ for (blk = 0; blk < ext2fs_blocks_count(fs->super); blk++) {
if ((blk >= fs->super->s_first_data_block) &&
ext2fs_test_block_bitmap2(meta_block_map, blk)) {
retval = io_channel_read_blk64(fs->io, blk, 1, buf);
diff --git a/misc/findsuper.c b/misc/findsuper.c
index fbc28a37..e793e3b1 100644
--- a/misc/findsuper.c
+++ b/misc/findsuper.c
@@ -92,6 +92,7 @@
#include <time.h>
#include "ext2fs/ext2_fs.h"
+#include "ext2fs/ext2fs.h"
#include "nls-enable.h"
#undef DEBUG
@@ -215,12 +216,14 @@ int main(int argc, char *argv[])
continue;
if (ext2.s_log_block_size > 6)
WHY("log block size > 6 (%u)\n", ext2.s_log_block_size);
- if (ext2.s_r_blocks_count > ext2.s_blocks_count)
+ if (ext2fs_r_blocks_count(&ext2) > ext2fs_blocks_count(&ext2))
WHY("r_blocks_count > blocks_count (%u > %u)\n",
- ext2.s_r_blocks_count, ext2.s_blocks_count);
- if (ext2.s_free_blocks_count > ext2.s_blocks_count)
+ ext2fs_r_blocks_count(&ext2),
+ ext2fs_blocks_count(&ext2));
+ if (ext2fs_free_blocks_count(&ext2) > ext2fs_blocks_count(&ext2))
WHY("free_blocks_count > blocks_count\n (%u > %u)\n",
- ext2.s_free_blocks_count, ext2.s_blocks_count);
+ ext2fs_free_blocks_count(&ext2),
+ ext2fs_blocks_count(&ext2));
if (ext2.s_free_inodes_count > ext2.s_inodes_count)
WHY("free_inodes_count > inodes_count (%u > %u)\n",
ext2.s_free_inodes_count, ext2.s_inodes_count);
@@ -246,9 +249,9 @@ int main(int argc, char *argv[])
printf("\r%11Lu %11Lu%s %11Lu%s %9u %5Lu %4u%s %s %02x%02x%02x%02x %s\n",
sk, sk - ext2.s_block_group_nr * grpsize - sb_offset,
jnl_copy ? "*":" ",
- sk + ext2.s_blocks_count * bsize -
+ sk + ext2fs_blocks_count(&ext2) * bsize -
ext2.s_block_group_nr * grpsize - sb_offset,
- jnl_copy ? "*" : " ", ext2.s_blocks_count, bsize,
+ jnl_copy ? "*" : " ", ext2fs_blocks_count(&ext2), bsize,
ext2.s_block_group_nr, jnl_copy ? "*" : " ", s,
ext2.s_uuid[0], ext2.s_uuid[1],
ext2.s_uuid[2], ext2.s_uuid[3], ext2.s_volume_name);
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 7287181e..cd97b93f 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -201,9 +201,9 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
errcode_t retval;
char buf[1024];
- sprintf(buf, "badblocks -b %d -X %s%s%s %u", fs->blocksize,
+ sprintf(buf, "badblocks -b %d -X %s%s%s %llu", fs->blocksize,
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
- fs->device_name, fs->super->s_blocks_count-1);
+ fs->device_name, ext2fs_blocks_count(fs->super)-1);
if (verbose)
printf(_("Running command: %s\n"), buf);
f = popen(buf, "r");
@@ -275,7 +275,7 @@ _("Warning: the backup superblock/group descriptors at block %u contain\n"
group = ext2fs_group_of_blk(fs, group_block+j);
fs->group_desc[group].bg_free_blocks_count++;
ext2fs_group_desc_csum_set(fs, group);
- fs->super->s_free_blocks_count++;
+ ext2fs_free_blocks_count_add(fs->super, 1);
}
}
group_block += fs->super->s_blocks_per_group;
@@ -492,7 +492,7 @@ static void create_journal_dev(ext2_filsys fs)
int c, count, err_count;
retval = ext2fs_create_journal_superblock(fs,
- fs->super->s_blocks_count, 0, &buf);
+ ext2fs_blocks_count(fs->super), 0, &buf);
if (retval) {
com_err("create_journal_dev", retval,
_("while initializing journal superblock"));
@@ -502,7 +502,7 @@ static void create_journal_dev(ext2_filsys fs)
_("Zeroing journal device: "),
ext2fs_blocks_count(fs->super));
blk = 0;
- count = fs->super->s_blocks_count;
+ count = ext2fs_blocks_count(fs->super);
while (count > 0) {
if (count > 1024)
c = 1024;
@@ -542,9 +542,9 @@ static void show_stats(ext2_filsys fs)
dgrp_t i;
int need, col_left;
- if (fs_param.s_blocks_count != s->s_blocks_count)
- fprintf(stderr, _("warning: %u blocks unused.\n\n"),
- fs_param.s_blocks_count - s->s_blocks_count);
+ if (ext2fs_blocks_count(&fs_param) != ext2fs_blocks_count(s))
+ fprintf(stderr, _("warning: %llu blocks unused.\n\n"),
+ ext2fs_blocks_count(&fs_param) - ext2fs_blocks_count(s));
memset(buf, 0, sizeof(buf));
strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
@@ -558,11 +558,11 @@ static void show_stats(ext2_filsys fs)
s->s_log_block_size);
printf(_("Fragment size=%u (log=%u)\n"), fs->fragsize,
s->s_log_frag_size);
- printf(_("%u inodes, %u blocks\n"), s->s_inodes_count,
- s->s_blocks_count);
- printf(_("%u blocks (%2.2f%%) reserved for the super user\n"),
- s->s_r_blocks_count,
- 100.0 * s->s_r_blocks_count / s->s_blocks_count);
+ printf(_("%u inodes, %llu blocks\n"), s->s_inodes_count,
+ ext2fs_blocks_count(s));
+ printf(_("%llu blocks (%2.2f%%) reserved for the super user\n"),
+ ext2fs_r_blocks_count(s),
+ 100.0 * ext2fs_r_blocks_count(s) / ext2fs_blocks_count(s));
printf(_("First data block=%u\n"), s->s_first_data_block);
if (s->s_reserved_gdt_blocks)
printf(_("Maximum filesystem blocks=%lu\n"),
@@ -702,7 +702,7 @@ static void parse_extended_opts(struct ext2_super_block *param,
r_usage++;
continue;
}
- if (resize <= param->s_blocks_count) {
+ if (resize <= ext2fs_blocks_count(param)) {
fprintf(stderr,
_("The resize maximum must be greater "
"than the filesystem size.\n"));
@@ -715,8 +715,8 @@ static void parse_extended_opts(struct ext2_super_block *param,
if (!bpg)
bpg = blocksize * 8;
gdpb = EXT2_DESC_PER_BLOCK(param);
- group_desc_count =
- ext2fs_div_ceil(param->s_blocks_count, bpg);
+ group_desc_count = (__u32) ext2fs_div64_ceil(
+ ext2fs_blocks_count(param), bpg);
desc_blocks = (group_desc_count +
gdpb - 1) / gdpb;
rsv_groups = ext2fs_div_ceil(resize, bpg);
@@ -931,9 +931,9 @@ static char **parse_fs_type(const char *fs_type,
}
meg = (1024 * 1024) / EXT2_BLOCK_SIZE(fs_param);
- if (fs_param->s_blocks_count < 3 * meg)
+ if (ext2fs_blocks_count(fs_param) < 3 * meg)
size_type = "floppy";
- else if (fs_param->s_blocks_count < 512 * meg)
+ else if (ext2fs_blocks_count(fs_param) < 512 * meg)
size_type = "small";
else
size_type = "default";
@@ -1352,9 +1352,9 @@ static void PRS(int argc, char *argv[])
blocksize, sys_page_size);
}
if (optind < argc) {
- fs_param.s_blocks_count = parse_num_blocks(argv[optind++],
- fs_param.s_log_block_size);
- if (!fs_param.s_blocks_count) {
+ ext2fs_blocks_count_set(&fs_param, parse_num_blocks(argv[optind++],
+ fs_param.s_log_block_size));
+ if (!ext2fs_blocks_count(&fs_param)) {
com_err(program_name, 0, _("invalid blocks count - %s"),
argv[optind - 1]);
exit(1);
@@ -1369,8 +1369,8 @@ static void PRS(int argc, char *argv[])
fs_param.s_log_frag_size = fs_param.s_log_block_size;
- if (noaction && fs_param.s_blocks_count) {
- dev_size = fs_param.s_blocks_count;
+ if (noaction && ext2fs_blocks_count(&fs_param)) {
+ dev_size = ext2fs_blocks_count(&fs_param);
retval = 0;
} else {
retry:
@@ -1414,7 +1414,7 @@ get_size_failure:
exit(1);
}
got_size:
- if (!fs_param.s_blocks_count) {
+ if (!ext2fs_blocks_count(&fs_param)) {
if (retval == EXT2_ET_UNIMPLEMENTED) {
com_err(program_name, 0,
_("Couldn't determine device size; you "
@@ -1434,13 +1434,16 @@ got_size:
));
exit(1);
}
- fs_param.s_blocks_count = dev_size;
- if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param))
- fs_param.s_blocks_count &= ~((sys_page_size /
- EXT2_BLOCK_SIZE(&fs_param))-1);
- }
+ ext2fs_blocks_count_set(&fs_param, dev_size);
+ if (sys_page_size > EXT2_BLOCK_SIZE(&fs_param)) {
+ blk64_t tmp = ext2fs_blocks_count(&fs_param);
- } else if (!force && (fs_param.s_blocks_count > dev_size)) {
+ tmp &= ~((blk64_t) ((sys_page_size /
+ EXT2_BLOCK_SIZE(&fs_param))-1));
+ ext2fs_blocks_count_set(&fs_param, tmp);
+ }
+ }
+ } else if (!force && (ext2fs_blocks_count(&fs_param) > dev_size)) {
com_err(program_name, 0,
_("Filesystem larger than apparent device size."));
proceed_question();
@@ -1564,7 +1567,9 @@ got_size:
if ((blocksize < 0) && (use_bsize < (-blocksize)))
use_bsize = -blocksize;
blocksize = use_bsize;
- fs_param.s_blocks_count /= blocksize / 1024;
+ ext2fs_blocks_count_set(&fs_param,
+ ext2fs_blocks_count(&fs_param) /
+ (blocksize / 1024));
}
if (inode_ratio == 0) {
@@ -1647,7 +1652,7 @@ got_size:
/* Make sure number of inodes specified will fit in 32 bits */
if (num_inodes == 0) {
unsigned long long n;
- n = (unsigned long long) fs_param.s_blocks_count * blocksize / inode_ratio;
+ n = ext2fs_blocks_count(&fs_param) * blocksize / inode_ratio;
if (n > ~0U) {
com_err(program_name, 0,
_("too many inodes (%llu), raise inode ratio?"), n);
@@ -1663,29 +1668,28 @@ got_size:
* Calculate number of inodes based on the inode ratio
*/
fs_param.s_inodes_count = num_inodes ? num_inodes :
- ((__u64) fs_param.s_blocks_count * blocksize)
- / inode_ratio;
+ (ext2fs_blocks_count(&fs_param) * blocksize) / inode_ratio;
if ((((long long)fs_param.s_inodes_count) *
(inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE)) >=
- (((long long)fs_param.s_blocks_count) *
+ ((ext2fs_blocks_count(&fs_param)) *
EXT2_BLOCK_SIZE(&fs_param))) {
com_err(program_name, 0, _("inode_size (%u) * inodes_count "
"(%u) too big for a\n\t"
- "filesystem with %lu blocks, "
+ "filesystem with %llu blocks, "
"specify higher inode_ratio (-i)\n\t"
"or lower inode count (-N).\n"),
inode_size ? inode_size : EXT2_GOOD_OLD_INODE_SIZE,
fs_param.s_inodes_count,
- (unsigned long) fs_param.s_blocks_count);
+ (unsigned long long) ext2fs_blocks_count(&fs_param));
exit(1);
}
/*
* Calculate number of blocks to reserve
*/
- fs_param.s_r_blocks_count = (unsigned int) (reserved_ratio *
- fs_param.s_blocks_count / 100.0);
+ ext2fs_r_blocks_count_set(&fs_param, reserved_ratio *
+ ext2fs_blocks_count(&fs_param) / 100.0);
}
static int should_do_undo(const char *name)
@@ -1975,7 +1979,7 @@ int main (int argc, char *argv[])
} else {
/* rsv must be a power of two (64kB is MD RAID sb alignment) */
unsigned int rsv = 65536 / fs->blocksize;
- unsigned long blocks = fs->super->s_blocks_count;
+ unsigned long blocks = ext2fs_blocks_count(fs->super);
unsigned long start;
blk_t ret_blk;
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 6da5c072..8daf6324 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -69,7 +69,8 @@ static int I_flag;
static time_t last_check_time;
static int print_label;
static int max_mount_count, mount_count, mount_flags;
-static unsigned long interval, reserved_blocks;
+static unsigned long interval;
+static blk64_t reserved_blocks;
static double reserved_ratio;
static unsigned long resgid, resuid;
static unsigned short errors;
@@ -262,7 +263,7 @@ static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr,
group = ext2fs_group_of_blk(fs, block);
fs->group_desc[group].bg_free_blocks_count++;
ext2fs_group_desc_csum_set(fs, group);
- fs->super->s_free_blocks_count++;
+ ext2fs_free_blocks_count_add(fs->super, 1);
return 0;
}
@@ -1008,7 +1009,7 @@ static int get_move_bitmaps(ext2_filsys fs, int new_ino_blks_per_grp,
}
ext2fs_badblocks_list_free(bb_list);
- if (needed_blocks > fs->super->s_free_blocks_count)
+ if (needed_blocks > ext2fs_free_blocks_count(fs->super))
return ENOSPC;
return 0;
@@ -1055,7 +1056,7 @@ static int move_block(ext2_filsys fs, ext2fs_block_bitmap bmap)
return retval;
for (new_blk = blk = fs->super->s_first_data_block;
- blk < fs->super->s_blocks_count; blk++) {
+ blk < ext2fs_blocks_count(fs->super); blk++) {
if (!ext2fs_test_block_bitmap2(bmap, blk))
continue;
@@ -1336,21 +1337,21 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
* First calculate the block statistics
*/
for (blk = fs->super->s_first_data_block;
- blk < fs->super->s_blocks_count; blk++) {
+ blk < ext2fs_blocks_count(fs->super); blk++) {
if (!ext2fs_fast_test_block_bitmap2(fs->block_map, blk)) {
group_free++;
total_free++;
}
count++;
if ((count == fs->super->s_blocks_per_group) ||
- (blk == fs->super->s_blocks_count-1)) {
+ (blk == ext2fs_blocks_count(fs->super)-1)) {
fs->group_desc[group++].bg_free_blocks_count =
group_free;
count = 0;
group_free = 0;
}
}
- fs->super->s_free_blocks_count = total_free;
+ ext2fs_free_blocks_count_set(fs->super, total_free);
/*
* Next, calculate the inode statistics
@@ -1658,23 +1659,22 @@ retry_open:
interval);
}
if (m_flag) {
- sb->s_r_blocks_count = (unsigned int) (reserved_ratio *
- sb->s_blocks_count / 100.0);
+ ext2fs_r_blocks_count_set(sb, reserved_ratio *
+ ext2fs_blocks_count(sb) / 100.0);
ext2fs_mark_super_dirty(fs);
- printf(_("Setting reserved blocks percentage to %g%% "
- "(%u blocks)\n"),
- reserved_ratio, sb->s_r_blocks_count);
+ printf (_("Setting reserved blocks percentage to %g%% (%llu blocks)\n"),
+ reserved_ratio, ext2fs_r_blocks_count(sb));
}
if (r_flag) {
- if (reserved_blocks >= sb->s_blocks_count/2) {
+ if (reserved_blocks >= ext2fs_blocks_count(sb)/2) {
com_err(program_name, 0,
- _("reserved blocks count is too big (%lu)"),
+ _("reserved blocks count is too big (%llu)"),
reserved_blocks);
exit(1);
}
- sb->s_r_blocks_count = reserved_blocks;
+ ext2fs_r_blocks_count_set(sb, reserved_blocks);
ext2fs_mark_super_dirty(fs);
- printf(_("Setting reserved blocks count to %lu\n"),
+ printf(_("Setting reserved blocks count to %llu\n"),
reserved_blocks);
}
if (s_flag == 1) {
diff --git a/misc/util.c b/misc/util.c
index 837d60fc..b8a3cac9 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -253,7 +253,7 @@ unsigned int figure_journal_size(int size, ext2_filsys fs)
{
int j_blocks;
- j_blocks = ext2fs_default_journal_size(fs->super->s_blocks_count);
+ j_blocks = ext2fs_default_journal_size(ext2fs_blocks_count(fs->super));
if (j_blocks < 0) {
fputs(_("\nFilesystem too small for a journal\n"), stderr);
return 0;
@@ -269,7 +269,7 @@ unsigned int figure_journal_size(int size, ext2_filsys fs)
j_blocks);
exit(1);
}
- if ((unsigned) j_blocks > fs->super->s_free_blocks_count / 2) {
+ if ((unsigned) j_blocks > ext2fs_free_blocks_count(fs->super) / 2) {
fputs(_("\nJournal size too big for filesystem.\n"),
stderr);
exit(1);
diff --git a/resize/main.c b/resize/main.c
index 220c192e..1bb6ed7b 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -429,7 +429,7 @@ int main (int argc, char ** argv)
fs->blocksize / 1024, new_size);
exit(1);
}
- if (new_size == fs->super->s_blocks_count) {
+ if (new_size == ext2fs_blocks_count(fs->super)) {
fprintf(stderr, _("The filesystem is already %u blocks "
"long. Nothing to do!\n\n"), new_size);
exit(0);
diff --git a/resize/online.c b/resize/online.c
index 4bc54513..6f828a8a 100644
--- a/resize/online.c
+++ b/resize/online.c
@@ -37,9 +37,9 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
printf(_("Filesystem at %s is mounted on %s; "
"on-line resizing required\n"), fs->device_name, mtpt);
- if (*new_size < sb->s_blocks_count) {
- printf(_("On-line shrinking from %u to %u not supported.\n"),
- sb->s_blocks_count, *new_size);
+ if (*new_size < ext2fs_blocks_count(sb)) {
+ printf(_("On-line shrinking from %llu to %u not supported.\n"),
+ ext2fs_blocks_count(sb), *new_size);
exit(1);
}
@@ -69,7 +69,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
exit(1);
}
- size=sb->s_blocks_count;
+ size=ext2fs_blocks_count(sb);
if (ioctl(fd, EXT2_IOC_GROUP_EXTEND, &size)) {
if (errno == EPERM)
com_err(program_name, 0,
@@ -83,7 +83,8 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
exit(1);
}
- percent = (sb->s_r_blocks_count * 100.0) / sb->s_blocks_count;
+ percent = (ext2fs_r_blocks_count(sb) * 100.0) /
+ ext2fs_blocks_count(sb);
retval = ext2fs_read_bitmaps(fs);
if (retval)
@@ -137,7 +138,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
input.inode_table = new_fs->group_desc[i].bg_inode_table;
input.blocks_count = sb->s_blocks_per_group;
if (i == new_fs->group_desc_count-1) {
- input.blocks_count = new_fs->super->s_blocks_count -
+ input.blocks_count = ext2fs_blocks_count(new_fs->super) -
sb->s_first_data_block -
(i * sb->s_blocks_per_group);
}
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 2883af5e..5a1eb2a8 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -115,7 +115,7 @@ errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
ext2fs_bg_flag_clear(rfs->new_fs, rfs->new_fs->group_desc_count - 1,
EXT2_BG_BLOCK_UNINIT);
- *new_size = rfs->new_fs->super->s_blocks_count;
+ *new_size = ext2fs_blocks_count(rfs->new_fs->super);
retval = blocks_to_move(rfs);
if (retval)
@@ -123,9 +123,9 @@ errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
#ifdef RESIZE2FS_DEBUG
if (rfs->flags & RESIZE_DEBUG_BMOVE)
- printf("Number of free blocks: %u/%u, Needed: %d\n",
- rfs->old_fs->super->s_free_blocks_count,
- rfs->new_fs->super->s_free_blocks_count,
+ printf("Number of free blocks: %llu/%llu, Needed: %d\n",
+ ext2fs_free_blocks_count(rfs->old_fs->super),
+ ext2fs_free_blocks_count(rfs->new_fs->super),
rfs->needed_blocks);
#endif
@@ -215,7 +215,7 @@ static void fix_uninit_block_bitmaps(ext2_filsys fs)
fs->super->s_reserved_gdt_blocks;
for (i=0; i < fs->super->s_blocks_per_group; i++, blk++) {
- if (blk >= fs->super->s_blocks_count)
+ if (blk >= ext2fs_blocks_count(fs->super))
break;
if ((blk == super_blk) ||
(old_desc_blk && old_desc_blocks &&
@@ -258,26 +258,26 @@ static void free_gdp_blocks(ext2_filsys fs,
int j;
if (gdp->bg_block_bitmap &&
- (gdp->bg_block_bitmap < fs->super->s_blocks_count)) {
+ (gdp->bg_block_bitmap < ext2fs_blocks_count(fs->super))) {
ext2fs_block_alloc_stats(fs, gdp->bg_block_bitmap, -1);
ext2fs_mark_block_bitmap2(reserve_blocks,
gdp->bg_block_bitmap);
}
if (gdp->bg_inode_bitmap &&
- (gdp->bg_inode_bitmap < fs->super->s_blocks_count)) {
+ (gdp->bg_inode_bitmap < ext2fs_blocks_count(fs->super))) {
ext2fs_block_alloc_stats(fs, gdp->bg_inode_bitmap, -1);
ext2fs_mark_block_bitmap2(reserve_blocks,
gdp->bg_inode_bitmap);
}
if (gdp->bg_inode_table == 0 ||
- (gdp->bg_inode_table >= fs->super->s_blocks_count))
+ (gdp->bg_inode_table >= ext2fs_blocks_count(fs->super)))
return;
for (blk = gdp->bg_inode_table, j = 0;
j < fs->inode_blocks_per_group; j++, blk++) {
- if (blk >= fs->super->s_blocks_count)
+ if (blk >= ext2fs_blocks_count(fs->super))
break;
ext2fs_block_alloc_stats(fs, blk, -1);
ext2fs_mark_block_bitmap2(reserve_blocks, blk);
@@ -306,10 +306,10 @@ errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs,
unsigned long long new_inodes; /* u64 to check for overflow */
double percent;
- fs->super->s_blocks_count = new_size;
+ ext2fs_blocks_count_set(fs->super, new_size);
retry:
- fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
+ fs->group_desc_count = ext2fs_div64_ceil(ext2fs_blocks_count(fs->super) -
fs->super->s_first_data_block,
EXT2_BLOCKS_PER_GROUP(fs->super));
if (fs->group_desc_count == 0)
@@ -334,12 +334,13 @@ retry:
* necessary data structures. If not, we need to get rid of
* it.
*/
- rem = (fs->super->s_blocks_count - fs->super->s_first_data_block) %
+ rem = (ext2fs_blocks_count(fs->super) - fs->super->s_first_data_block) %
fs->super->s_blocks_per_group;
if ((fs->group_desc_count == 1) && rem && (rem < overhead))
return EXT2_ET_TOOSMALL;
if (rem && (rem < overhead+50)) {
- fs->super->s_blocks_count -= rem;
+ ext2fs_blocks_count_set(fs->super,
+ ext2fs_blocks_count(fs->super) - rem);
goto retry;
}
/*
@@ -357,21 +358,24 @@ retry:
/*
* Adjust the number of free blocks
*/
- blk = old_fs->super->s_blocks_count;
- if (blk > fs->super->s_blocks_count)
- fs->super->s_free_blocks_count -=
- (blk - fs->super->s_blocks_count);
+ blk = ext2fs_blocks_count(old_fs->super);
+ if (blk > ext2fs_blocks_count(fs->super))
+ ext2fs_free_blocks_count_set(fs->super,
+ ext2fs_free_blocks_count(fs->super) -
+ (blk - ext2fs_blocks_count(fs->super)));
else
- fs->super->s_free_blocks_count +=
- (fs->super->s_blocks_count - blk);
+ ext2fs_free_blocks_count_set(fs->super,
+ ext2fs_free_blocks_count(fs->super) +
+ (ext2fs_blocks_count(fs->super) - blk));
/*
* Adjust the number of reserved blocks
*/
- percent = (old_fs->super->s_r_blocks_count * 100.0) /
- old_fs->super->s_blocks_count;
- fs->super->s_r_blocks_count = (unsigned int) (percent *
- fs->super->s_blocks_count / 100.0);
+ percent = (ext2fs_r_blocks_count(old_fs->super) * 100.0) /
+ ext2fs_blocks_count(old_fs->super);
+ ext2fs_r_blocks_count_set(fs->super,
+ (percent * ext2fs_blocks_count(fs->super) /
+ 100.0));
/*
* Adjust the bitmaps for size
@@ -384,7 +388,7 @@ retry:
real_end = ((EXT2_BLOCKS_PER_GROUP(fs->super)
* fs->group_desc_count)) - 1 +
fs->super->s_first_data_block;
- retval = ext2fs_resize_block_bitmap2(fs->super->s_blocks_count-1,
+ retval = ext2fs_resize_block_bitmap2(ext2fs_blocks_count(fs->super)-1,
real_end, fs->block_map);
if (retval) goto errout;
@@ -447,13 +451,13 @@ retry:
/*
* Fix the count of the last (old) block group
*/
- old_numblocks = (old_fs->super->s_blocks_count -
+ old_numblocks = (ext2fs_blocks_count(old_fs->super) -
old_fs->super->s_first_data_block) %
old_fs->super->s_blocks_per_group;
if (!old_numblocks)
old_numblocks = old_fs->super->s_blocks_per_group;
if (old_fs->group_desc_count == fs->group_desc_count) {
- numblocks = (fs->super->s_blocks_count -
+ numblocks = (ext2fs_blocks_count(fs->super) -
fs->super->s_first_data_block) %
fs->super->s_blocks_per_group;
if (!numblocks)
@@ -500,7 +504,7 @@ retry:
ext2fs_bg_flag_set(fs, i, EXT2_BG_INODE_UNINIT | EXT2_BG_INODE_ZEROED)
;
if (i == fs->group_desc_count-1) {
- numblocks = (fs->super->s_blocks_count -
+ numblocks = (ext2fs_blocks_count(fs->super) -
fs->super->s_first_data_block) %
fs->super->s_blocks_per_group;
if (!numblocks)
@@ -541,7 +545,8 @@ retry:
adjblocks += 2 + fs->inode_blocks_per_group;
numblocks -= adjblocks;
- fs->super->s_free_blocks_count -= adjblocks;
+ ext2fs_free_blocks_count_set(fs->super,
+ 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;
@@ -784,7 +789,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
fs = rfs->new_fs;
old_fs = rfs->old_fs;
- if (old_fs->super->s_blocks_count > fs->super->s_blocks_count)
+ if (ext2fs_blocks_count(old_fs->super) > ext2fs_blocks_count(fs->super))
fs = rfs->old_fs;
retval = ext2fs_allocate_block_bitmap(fs, _("blocks to be moved"),
@@ -807,8 +812,8 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
* If we're shrinking the filesystem, we need to move all of
* the blocks that don't fit any more
*/
- for (blk = fs->super->s_blocks_count;
- blk < old_fs->super->s_blocks_count; blk++) {
+ for (blk = ext2fs_blocks_count(fs->super);
+ blk < ext2fs_blocks_count(old_fs->super); blk++) {
g = ext2fs_group_of_blk(fs, blk);
if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
EXT4_FEATURE_RO_COMPAT_GDT_CSUM) &&
@@ -1036,9 +1041,9 @@ static void init_block_alloc(ext2_resize_t rfs)
rfs->new_blk = rfs->new_fs->super->s_first_data_block;
#if 0
/* HACK for testing */
- if (rfs->new_fs->super->s_blocks_count >
- rfs->old_fs->super->s_blocks_count)
- rfs->new_blk = rfs->old_fs->super->s_blocks_count;
+ if (ext2fs_blocks_count(rfs->new_fs->super) >
+ ext2fs_blocks_count(rfs->old_fs->super))
+ rfs->new_blk = ext2fs_blocks_count(rfs->old_fs->super);
#endif
}
@@ -1047,7 +1052,7 @@ static blk_t get_new_block(ext2_resize_t rfs)
ext2_filsys fs = rfs->new_fs;
while (1) {
- if (rfs->new_blk >= fs->super->s_blocks_count) {
+ if (rfs->new_blk >= ext2fs_blocks_count(fs->super)) {
if (rfs->alloc_state == DESPERATION)
return 0;
@@ -1064,7 +1069,7 @@ static blk_t get_new_block(ext2_resize_t rfs)
ext2fs_test_block_bitmap2(rfs->reserve_blocks,
rfs->new_blk) ||
((rfs->alloc_state == AVOID_OLD) &&
- (rfs->new_blk < rfs->old_fs->super->s_blocks_count) &&
+ (rfs->new_blk < ext2fs_blocks_count(rfs->old_fs->super)) &&
ext2fs_test_block_bitmap2(rfs->old_fs->block_map,
rfs->new_blk))) {
rfs->new_blk++;
@@ -1132,7 +1137,7 @@ static errcode_t block_mover(ext2_resize_t rfs)
to_move = moved = 0;
init_block_alloc(rfs);
for (blk = old_fs->super->s_first_data_block;
- blk < old_fs->super->s_blocks_count; blk++) {
+ blk < ext2fs_blocks_count(old_fs->super); blk++) {
if (!ext2fs_test_block_bitmap2(old_fs->block_map, blk))
continue;
if (!ext2fs_test_block_bitmap2(rfs->move_blocks, blk))
@@ -1326,10 +1331,10 @@ static errcode_t inode_scan_and_fix(ext2_resize_t rfs)
* is larger. We need to do this to avoid catching an error
* by the block iterator routines
*/
- orig_size = rfs->old_fs->super->s_blocks_count;
- if (orig_size < rfs->new_fs->super->s_blocks_count)
- rfs->old_fs->super->s_blocks_count =
- rfs->new_fs->super->s_blocks_count;
+ orig_size = ext2fs_blocks_count(rfs->old_fs->super);
+ if (orig_size < ext2fs_blocks_count(rfs->new_fs->super))
+ ext2fs_blocks_count_set(rfs->old_fs->super,
+ ext2fs_blocks_count(rfs->new_fs->super));
retval = ext2fs_open_inode_scan(rfs->old_fs, 0, &scan);
if (retval) goto errout;
@@ -1437,7 +1442,7 @@ static errcode_t inode_scan_and_fix(ext2_resize_t rfs)
io_channel_flush(rfs->old_fs->io);
errout:
- rfs->old_fs->super->s_blocks_count = orig_size;
+ ext2fs_blocks_count_set(rfs->old_fs->super, orig_size);
if (rfs->bmap) {
ext2fs_free_extent_table(rfs->bmap);
rfs->bmap = 0;
@@ -1796,7 +1801,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
old_desc_blocks = fs->desc_blocks +
fs->super->s_reserved_gdt_blocks;
for (blk = fs->super->s_first_data_block;
- blk < fs->super->s_blocks_count; blk++) {
+ blk < ext2fs_blocks_count(fs->super); blk++) {
if ((uninit &&
!((blk == super_blk) ||
((old_desc_blk && old_desc_blocks &&
@@ -1814,7 +1819,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
}
count++;
if ((count == fs->super->s_blocks_per_group) ||
- (blk == fs->super->s_blocks_count-1)) {
+ (blk == ext2fs_blocks_count(fs->super)-1)) {
fs->group_desc[group].bg_free_blocks_count =
group_free;
ext2fs_group_desc_csum_set(fs, group);
@@ -1834,7 +1839,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
fs->super->s_reserved_gdt_blocks;
}
}
- fs->super->s_free_blocks_count = total_free;
+ ext2fs_free_blocks_count_set(fs->super, total_free);
/*
* Next, calculate the inode statistics
@@ -1925,8 +1930,8 @@ blk_t calculate_minimum_resize_size(ext2_filsys fs)
}
/* calculate how many blocks are needed for data */
- data_needed = fs->super->s_blocks_count -
- fs->super->s_free_blocks_count;
+ data_needed = ext2fs_blocks_count(fs->super) -
+ ext2fs_free_blocks_count(fs->super);
data_needed -= SUPER_OVERHEAD(fs) * num_of_superblocks;
data_needed -= META_OVERHEAD(fs) * fs->group_desc_count;
@@ -2056,15 +2061,16 @@ blk_t calculate_minimum_resize_size(ext2_filsys fs)
* If at this point we've already added up more "needed" than
* the current size, just return current size as minimum.
*/
- if (blks_needed >= fs->super->s_blocks_count)
- return fs->super->s_blocks_count;
+ if (blks_needed >= ext2fs_blocks_count(fs->super))
+ return ext2fs_blocks_count(fs->super);
/*
* We need to reserve a few extra blocks if extents are
* enabled, in case we need to grow the extent tree. The more
* we shrink the file system, the more space we need.
*/
if (fs->super->s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)
- blks_needed += (fs->super->s_blocks_count - blks_needed)/500;
+ blks_needed += (ext2fs_blocks_count(fs->super) -
+ blks_needed)/500;
return blks_needed;
}
diff --git a/tests/progs/test_icount.c b/tests/progs/test_icount.c
index aa9b9321..777a8123 100644
--- a/tests/progs/test_icount.c
+++ b/tests/progs/test_icount.c
@@ -308,7 +308,7 @@ int main(int argc, char **argv)
* Create a sample filesystem structure
*/
memset(&param, 0, sizeof(struct ext2_super_block));
- param.s_blocks_count = 80000;
+ ext2fs_blocks_count_set(&param, 80000);
param.s_inodes_count = 20000;
retval = ext2fs_initialize("/dev/null", 0, &param,
unix_io_manager, &test_fs);