2007-08-30 13:26:34

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 0/8][e2fsprogs] 64-bit block number support - first part

This is a series of 8 patches that prepares for the 64-bit block number support in e2fsprogs:
- change a few variable types to blk_t type to support 64-bit block numbers in a next step,

- introduce a new option to mkfs to build ext4 filesystems with larger group descriptor sizes,

- introduce helper functions, similar to those existing in the ext4 kernel code, to access 64-bit block counters split in two 32-bit words.

Code compiled and "make check" passed.

The patchset is composed of the following patches:
1/8 : use existing function ext2fs_group_first_block()
This function will be change in a next step to support 64-bit block numbers.
This patch will allow to make the change in a single place.

2/8 : convert block number definition to blk_t

3/8 : add new -D <desc-size> option to mkfs

4/8 : add new macro to get descriptor number

5/8 : add new inline functions to get blocks counters
6/8 : change access to the filesystem blocks counter
7/8 : change access to the reserved blocks counter
8/8 : change access to the free blocks counter

Regards
Valerie


2007-08-30 13:26:57

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 7/8][e2fsprogs] change access to the reserved blocks counter


From: Valerie Clement <[email protected]>

This patch replaces all references to super->s_r_blocks_count by
ext2_r_blocks_count(super) in preparation for 64-bit support.

Signed-off-by: Valerie Clement <[email protected]>
---

e2fsck/super.c | 2 +-
lib/ext2fs/initialize.c | 4 ++--
misc/mke2fs.c | 8 ++++----
misc/tune2fs.c | 8 ++++----
resize/online.c | 3 ++-
5 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/e2fsck/super.c b/e2fsck/super.c
index d2693db..f7e4e89 100644
--- a/e2fsck/super.c
+++ b/e2fsck/super.c
@@ -507,7 +507,7 @@ 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,
+ check_super_value(ctx, "r_blocks_count", ext2_r_blocks_count(sb),
MAX_CHECK, 0, ext2_blocks_count(sb) / 2);
check_super_value(ctx, "reserved_gdt_blocks",
sb->s_reserved_gdt_blocks, MAX_CHECK, 0,
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index cb68191..6969745 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -188,8 +188,8 @@ errcode_t ext2fs_initialize(const char *name, int flags,
super->s_frags_per_group = super->s_blocks_per_group * frags_per_block;

ext2_blocks_count_set(super, ext2_blocks_count(param));
- super->s_r_blocks_count = param->s_r_blocks_count;
- if (super->s_r_blocks_count >= ext2_blocks_count(param)) {
+ ext2_r_blocks_count_set(super, ext2_r_blocks_count(param));
+ if (ext2_r_blocks_count(super) >= ext2_blocks_count(param)) {
retval = EXT2_ET_INVALID_ARGUMENT;
goto cleanup;
}
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 021625a..074c985 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -687,8 +687,8 @@ static void show_stats(ext2_filsys fs)
printf(_("%u inodes, %u blocks\n"), s->s_inodes_count,
ext2_blocks_count(s));
printf(_("%u blocks (%2.2f%%) reserved for the super user\n"),
- s->s_r_blocks_count,
- 100.0 * s->s_r_blocks_count / ext2_blocks_count(s));
+ ext2_r_blocks_count(s),
+ 100.0 * ext2_r_blocks_count(s) / ext2_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"),
@@ -1547,8 +1547,8 @@ static void PRS(int argc, char *argv[])
/*
* Calculate number of blocks to reserve
*/
- fs_param.s_r_blocks_count = e2p_percent(reserved_ratio,
- ext2_blocks_count(&fs_param));
+ ext2_r_blocks_count_set(&fs_param, e2p_percent(reserved_ratio,
+ ext2_blocks_count(&fs_param)));
}

int main (int argc, char *argv[])
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 5eaa252..2d3e3c0 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -825,11 +825,11 @@ int main (int argc, char ** argv)
printf (_("Setting interval between checks to %lu seconds\n"), interval);
}
if (m_flag) {
- sb->s_r_blocks_count = e2p_percent(reserved_ratio,
- ext2_blocks_count(sb));
+ ext2_r_blocks_count_set(sb,
+ e2p_percent(reserved_ratio, ext2_blocks_count(sb)));
ext2fs_mark_super_dirty(fs);
printf (_("Setting reserved blocks percentage to %g%% (%u blocks)\n"),
- reserved_ratio, sb->s_r_blocks_count);
+ reserved_ratio, ext2_r_blocks_count(sb));
}
if (r_flag) {
if (reserved_blocks >= ext2_blocks_count(sb) / 2) {
@@ -838,7 +838,7 @@ int main (int argc, char ** argv)
reserved_blocks);
exit (1);
}
- sb->s_r_blocks_count = reserved_blocks;
+ ext2_r_blocks_count_set(sb, reserved_blocks);
ext2fs_mark_super_dirty(fs);
printf (_("Setting reserved blocks count to %lu\n"),
reserved_blocks);
diff --git a/resize/online.c b/resize/online.c
index ebc4ff9..f5bc0c0 100644
--- a/resize/online.c
+++ b/resize/online.c
@@ -79,7 +79,8 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
exit(1);
}

- r_frac = ext2fs_div_ceil(100 * sb->s_r_blocks_count, ext2_blocks_count(sb));
+ r_frac = ext2fs_div_ceil(100 * ext2_r_blocks_count(sb),
+ ext2_blocks_count(sb));

retval = ext2fs_read_bitmaps(fs);
if (retval)

2007-08-30 13:26:56

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 8/8][e2fsprogs] change access to the free blocks counter


From: Valerie Clement <[email protected]>

This patch replaces all references to super->s_free_blocks_count by
ext2_free_blocks_count(super) in preparation for 64-bit support.

Signed-off-by: Valerie Clement <[email protected]>
---

e2fsck/pass5.c | 6 +++---
e2fsck/super.c | 6 +++---
e2fsck/unix.c | 4 ++--
lib/ext2fs/alloc_stats.c | 3 ++-
lib/ext2fs/initialize.c | 5 +++--
misc/mke2fs.c | 6 ++++--
misc/tune2fs.c | 3 ++-
misc/util.c | 3 ++-
resize/resize2fs.c | 19 +++++++++++--------
9 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
index 7e3f5ee..40612e2 100644
--- a/e2fsck/pass5.c
+++ b/e2fsck/pass5.c
@@ -291,13 +291,13 @@ redo_counts:
ext2fs_unmark_valid(fs);
}
}
- if (free_blocks != fs->super->s_free_blocks_count) {
+ if (free_blocks != ext2_free_blocks_count(fs->super)) {
pctx.group = 0;
- pctx.blk = fs->super->s_free_blocks_count;
+ pctx.blk = ext2_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;
+ ext2_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 f7e4e89..5501ba9 100644
--- a/e2fsck/super.c
+++ b/e2fsck/super.c
@@ -630,18 +630,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 != ext2_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;
+ ext2_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 > ext2_blocks_count(sb)) ||
+ if ((ext2_free_blocks_count(sb) > ext2_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 610712f..42037a4 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -112,7 +112,7 @@ static void show_stats(e2fsck_t ctx)
fs->super->s_free_inodes_count);
blocks = ext2_blocks_count(fs->super);
blocks_used = (ext2_blocks_count(fs->super) -
- fs->super->s_free_blocks_count);
+ ext2_free_blocks_count(fs->super));

frag_percent = (10000 * ctx->fs_fragmented) / inodes_used;
frag_percent = (frag_percent + 5) / 10;
@@ -302,7 +302,7 @@ static void check_if_skip(e2fsck_t ctx)
printf(_("%s: clean, %u/%u files, %u/%u blocks"), ctx->device_name,
fs->super->s_inodes_count - fs->super->s_free_inodes_count,
fs->super->s_inodes_count,
- ext2_blocks_count(fs->super) - fs->super->s_free_blocks_count,
+ ext2_blocks_count(fs->super) - ext2_free_blocks_count(fs->super),
ext2_blocks_count(fs->super));
next_check = 100000;
if (fs->super->s_max_mnt_count > 0) {
diff --git a/lib/ext2fs/alloc_stats.c b/lib/ext2fs/alloc_stats.c
index 4088f7b..8b0b964 100644
--- a/lib/ext2fs/alloc_stats.c
+++ b/lib/ext2fs/alloc_stats.c
@@ -46,7 +46,8 @@ void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse)
else
ext2fs_unmark_block_bitmap(fs->block_map, blk);
fs->group_desc[group].bg_free_blocks_count -= inuse;
- fs->super->s_free_blocks_count -= inuse;
+ ext2_free_blocks_count_set(fs->super,
+ ext2_free_blocks_count(fs->super) - inuse);
ext2fs_mark_super_dirty(fs);
ext2fs_mark_bb_dirty(fs);
}
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 6969745..19fbaa9 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -366,11 +366,12 @@ ipg_retry:
* inode table have not been allocated (and in fact won't be
* by this routine), they are accounted for nevertheless.
*/
- super->s_free_blocks_count = 0;
+ ext2_free_blocks_count_set(super, 0ULL);
for (i = 0; i < fs->group_desc_count; i++) {
numblocks = ext2fs_reserve_super_and_bgd(fs, i, fs->block_map);

- super->s_free_blocks_count += numblocks;
+ ext2_free_blocks_count_set(super,
+ ext2_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/misc/mke2fs.c b/misc/mke2fs.c
index 074c985..a4ee998 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -263,7 +263,8 @@ _("Warning: the backup superblock/group descriptors at block %u contain\n"
group_bad++;
group = ext2fs_group_of_blk(fs, group_block+j);
fs->group_desc[group].bg_free_blocks_count++;
- fs->super->s_free_blocks_count++;
+ ext2_free_blocks_count_set(fs->super,
+ ext2_free_blocks_count(fs->super) + 1);
}
}
group_block += fs->super->s_blocks_per_group;
@@ -468,7 +469,8 @@ static void setup_lazy_bg(ext2_filsys fs)
if (bg->bg_free_blocks_count == blks) {
bg->bg_free_blocks_count = 0;
bg->bg_flags |= EXT2_BG_BLOCK_UNINIT;
- sb->s_free_blocks_count -= blks;
+ ext2_free_blocks_count_set(sb,
+ ext2_free_blocks_count(sb) - blks);
}
}
}
diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 2d3e3c0..a65129f 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -213,7 +213,8 @@ static int release_blocks_proc(ext2_filsys fs, blk_t *blocknr,
ext2fs_unmark_block_bitmap(fs->block_map,block);
group = ext2fs_group_of_blk(fs, block);
fs->group_desc[group].bg_free_blocks_count++;
- fs->super->s_free_blocks_count++;
+ ext2_free_blocks_count_set(fs->super,
+ ext2_free_blocks_count(fs->super) + 1);
return 0;
}

diff --git a/misc/util.c b/misc/util.c
index 8fe505a..435396b 100644
--- a/misc/util.c
+++ b/misc/util.c
@@ -269,7 +269,8 @@ 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 > ext2_free_blocks_count(fs->super) / 2)
+ {
fputs(_("\nJournal size too big for filesystem.\n"),
stderr);
exit(1);
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 6c37f77..ebd66d2 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -109,8 +109,8 @@ 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,
+ ext2_free_blocks_count(rfs->old_fs->super),
+ ext2_free_blocks_count(rfs->new_fs->super),
rfs->needed_blocks);
#endif

@@ -242,11 +242,13 @@ retry:
*/
blk = ext2_blocks_count(old_fs->super);
if (blk > ext2_blocks_count(fs->super))
- fs->super->s_free_blocks_count -=
- (blk - ext2_blocks_count(fs->super));
+ ext2_free_blocks_count_set(fs->super,
+ ext2_free_blocks_count(fs->super) -
+ (blk - ext2_blocks_count(fs->super)));
else
- fs->super->s_free_blocks_count +=
- (ext2_blocks_count(fs->super) - blk);
+ ext2_free_blocks_count_set(fs->super,
+ ext2_free_blocks_count(fs->super) +
+ (ext2_blocks_count(fs->super) - blk));

/*
* Adjust the number of reserved blocks
@@ -407,7 +409,8 @@ retry:
adjblocks += 2 + fs->inode_blocks_per_group;

numblocks -= adjblocks;
- fs->super->s_free_blocks_count -= adjblocks;
+ ext2_free_blocks_count_set(fs->super,
+ ext2_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;
@@ -1580,7 +1583,7 @@ static errcode_t ext2fs_calculate_summary_stats(ext2_filsys fs)
group_free = 0;
}
}
- fs->super->s_free_blocks_count = total_free;
+ ext2_free_blocks_count_set(fs->super, total_free);

/*
* Next, calculate the inode statistics

2007-08-30 13:26:49

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 5/8][e2fsprogs] add new inline functions to get blocks counters


From: Valerie Clement <[email protected]>

In preparation for 64-bit support, this patch introduces new inline functions
to get block counts in the on-disk superblock.

If the EXT4_FEATURE_INCOMPAT_64BIT flag is not set, the functions return the
low 32 bits of block counters.

Changes from the previous version:
Replace macros definition by inline functions because some previous macros
evaluate their argument more than once.

Signed-off-by: Valerie Clement <[email protected]>
---

lib/ext2fs/ext2fs.h | 72 +++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 3aa9c8f..b60318c 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1011,6 +1011,13 @@ extern blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group);
extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
struct ext2_inode *inode);
extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
+extern blk_t ext2_blocks_count(struct ext2_super_block *super);
+extern blk_t ext2_r_blocks_count(struct ext2_super_block *super);
+extern blk_t ext2_free_blocks_count(struct ext2_super_block *super);
+extern void ext2_blocks_count_set(struct ext2_super_block *super, blk_t blk);
+extern void ext2_r_blocks_count_set(struct ext2_super_block *super, blk_t blk);
+extern void ext2_free_blocks_count_set(struct ext2_super_block *super,
+ blk_t blk);

/*
* The actual inlined functions definitions themselves...
@@ -1184,17 +1191,6 @@ _INLINE_ blk_t ext2fs_group_first_block(ext2_filsys fs, dgrp_t group)
(group * fs->super->s_blocks_per_group);
}

-/*
- * Return the last block (inclusive) in a group
- */
-_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
-{
- return (group == fs->group_desc_count - 1 ?
- fs->super->s_blocks_count - 1 :
- ext2fs_group_first_block(fs, group) +
- (fs->super->s_blocks_per_group - 1));
-}
-
_INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
struct ext2_inode *inode)
{
@@ -1211,6 +1207,60 @@ _INLINE_ unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b)
return 0;
return ((a - 1) / b) + 1;
}
+
+_INLINE_ blk_t ext2_blocks_count(struct ext2_super_block *super)
+{
+ return super->s_blocks_count +
+ (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+ (__u64)super->s_blocks_count_hi << 32 : 0);
+}
+
+_INLINE_ blk_t ext2_r_blocks_count(struct ext2_super_block *super)
+{
+ return super->s_r_blocks_count +
+ (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+ (__u64)super->s_r_blocks_count_hi << 32 : 0);
+}
+
+_INLINE_ blk_t ext2_free_blocks_count(struct ext2_super_block *super)
+{
+ return super->s_free_blocks_count +
+ (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT ?
+ (__u64)super->s_free_blocks_hi << 32 : 0);
+}
+
+_INLINE_ void ext2_blocks_count_set(struct ext2_super_block *super, blk_t blk)
+{
+ super->s_blocks_count = blk;
+ if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
+ super->s_blocks_count_hi = (__u64) blk >> 32;
+}
+
+_INLINE_ void ext2_r_blocks_count_set(struct ext2_super_block *super, blk_t blk)
+{
+ super->s_r_blocks_count = blk;
+ if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
+ super->s_r_blocks_count_hi = (__u64) blk >> 32;
+}
+
+_INLINE_ void ext2_free_blocks_count_set(struct ext2_super_block *super,
+ blk_t blk)
+{
+ super->s_free_blocks_count = blk;
+ if (super->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT)
+ super->s_free_blocks_hi = (__u64) blk >> 32;
+}
+
+/*
+ * Return the last block (inclusive) in a group
+ */
+_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
+{
+ return (group == fs->group_desc_count - 1 ?
+ fs->super->s_blocks_count - 1 :
+ ext2fs_group_first_block(fs, group) +
+ (fs->super->s_blocks_per_group - 1));
+}
#undef _INLINE_
#endif


2007-08-30 13:26:37

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 1/8][e2fsprogs] use existing function ext2fs_group_first_block()


From: Valerie Clement <[email protected]>

Replace piece of code by call to the existing function,
i.e. ext2fs_group_first_block().

Signed-off-by: Valerie Clement <[email protected]>
---

lib/ext2fs/closefs.c | 3 +--
lib/ext2fs/openfs.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 474e00e..f780e80 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -57,8 +57,7 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,
int numblocks, has_super;
int old_desc_blocks;

- group_block = fs->super->s_first_data_block +
- (group * fs->super->s_blocks_per_group);
+ group_block = ext2fs_group_first_block(fs, group);

if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 55cc077..8a369c3 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -42,8 +42,7 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
bg = (fs->blocksize / sizeof (struct ext2_group_desc)) * i;
if (ext2fs_bg_has_super(fs, bg))
has_super = 1;
- ret_blk = (fs->super->s_first_data_block + has_super +
- (bg * fs->super->s_blocks_per_group));
+ ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
/*
* If group_block is not the normal value, we're trying to use
* the backup group descriptors and superblock --- so use the

2007-08-30 13:26:52

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 6/8][e2fsprogs] change access to the filesystem blocks counter


From: Valerie Clement <[email protected]>

This patch replaces all references to super->s_blocks_count by
ext2_blocks_count(super) in preparation for 64-bit support.

Signed-off-by: Valerie Clement <[email protected]>
---

debugfs/debugfs.c | 4 +--
debugfs/logdump.c | 2 +
debugfs/lsdel.c | 2 +
debugfs/set_fields.c | 1 +
debugfs/unused.c | 2 +
e2fsck/badblocks.c | 4 +--
e2fsck/journal.c | 4 +--
e2fsck/pass1.c | 16 ++++++-----
e2fsck/pass2.c | 4 +--
e2fsck/pass5.c | 14 +++++-----
e2fsck/super.c | 16 ++++++-----
e2fsck/unix.c | 10 ++++---
lib/ext2fs/alloc.c | 6 ++--
lib/ext2fs/bb_inode.c | 2 +
lib/ext2fs/bitmaps.c | 2 +
lib/ext2fs/block.c | 6 ++--
lib/ext2fs/bmove.c | 2 +
lib/ext2fs/closefs.c | 2 +
lib/ext2fs/ext2fs.h | 2 +
lib/ext2fs/ext_attr.c | 2 +
lib/ext2fs/initialize.c | 20 +++++++-------
lib/ext2fs/openfs.c | 4 +--
lib/ext2fs/read_bb.c | 2 +
lib/ext2fs/read_bb_file.c | 2 +
lib/ext2fs/rw_bitmaps.c | 2 +
lib/ext2fs/tst_badblocks.c | 2 +
lib/ext2fs/tst_iscan.c | 2 +
misc/e2image.c | 2 +
misc/mke2fs.c | 56 +++++++++++++++++++++-------------------
misc/tune2fs.c | 4 +--
misc/util.c | 2 +
resize/main.c | 2 +
resize/online.c | 10 ++++---
resize/resize2fs.c | 62 ++++++++++++++++++++++----------------------
tests/progs/test_icount.c | 2 +
35 files changed, 140 insertions(+), 137 deletions(-)

diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c
index 190c4b7..4a3aa0e 100644
--- a/debugfs/debugfs.c
+++ b/debugfs/debugfs.c
@@ -233,8 +233,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);
+ ext2_blocks_count_set(&param, parse_ulong(argv[2], argv[0],
+ "blocks count", &err));
if (err)
return;
retval = ext2fs_initialize(argv[1], 0, &param,
diff --git a/debugfs/logdump.c b/debugfs/logdump.c
index 773d84e..50f6ac5 100644
--- a/debugfs/logdump.c
+++ b/debugfs/logdump.c
@@ -366,7 +366,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",
- sb->s_blocks_count);
+ ext2_blocks_count(sb));
}
}

diff --git a/debugfs/lsdel.c b/debugfs/lsdel.c
index 3dc32a7..f320331 100644
--- a/debugfs/lsdel.c
+++ b/debugfs/lsdel.c
@@ -57,7 +57,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 >= ext2_blocks_count(fs->super)) {
lsd->bad_blocks++;
return BLOCK_ABORT;
}
diff --git a/debugfs/set_fields.c b/debugfs/set_fields.c
index 9ff7f8c..9c23524 100644
--- a/debugfs/set_fields.c
+++ b/debugfs/set_fields.c
@@ -114,6 +114,7 @@ static struct field_set_info super_fields[] = {
{ "mkfs_time", &set_sb.s_mkfs_time, 4, parse_time },
{ "jnl_blocks", &set_sb.s_jnl_blocks[0], 4, parse_uint, FLAG_ARRAY,
17 },
+ { "blocks_count_hi", &set_sb.s_blocks_count_hi, 4, parse_uint },
{ "flags", &set_sb.s_flags, 4, parse_uint },
{ 0, 0, 0, 0 }
};
diff --git a/debugfs/unused.c b/debugfs/unused.c
index 0eee8e6..d94e528 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 < ext2_blocks_count(current_fs->super); blk++) {
if (ext2fs_test_block_bitmap(current_fs->block_map,blk))
continue;
retval = io_channel_read_blk(current_fs->io, blk, 1, buf);
diff --git a/e2fsck/badblocks.c b/e2fsck/badblocks.c
index 36dc208..49fde35 100644
--- a/e2fsck/badblocks.c
+++ b/e2fsck/badblocks.c
@@ -75,7 +75,7 @@ void read_bad_blocks_file(e2fsck_t ctx, const char *bad_blocks_file,
sprintf(buf, "badblocks -b %d -X %s%s%s %d", 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, ext2_blocks_count(fs->super) - 1);
f = popen(buf, "r");
if (!f) {
com_err("read_bad_blocks_file", errno,
@@ -124,7 +124,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 >= ext2_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 756bbcb..8b2b2a9 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -209,7 +209,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 >= ext2_blocks_count(fs->super))
return BLOCK_ABORT;

if (blockcnt >= 0)
@@ -403,7 +403,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 = ext2_blocks_count(&jsuper);
start++;
}

diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
index ceb9c7f..e053630 100644
--- a/e2fsck/pass1.c
+++ b/e2fsck/pass1.c
@@ -179,7 +179,7 @@ int e2fsck_pass1_check_symlink(ext2_filsys fs, struct ext2_inode *inode,
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] >= ext2_blocks_count(fs->super)))
return 0;

for (i = 1; i < EXT2_N_BLOCKS; i++)
@@ -392,7 +392,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 >= ext2_blocks_count(ctx->fs->super) ||
ext2fs_fast_test_block_bitmap(ctx->block_found_map, blk))
return; /* Invalid block, can't be dir */
}
@@ -1274,7 +1274,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 >= ext2_blocks_count(fs->super))) {
mark_inode_bad(ctx, ino);
return 0;
}
@@ -1434,7 +1434,7 @@ static int handle_htree(e2fsck_t ctx, struct problem_context *pctx,
blk = inode->i_block[0];
if (((blk == 0) ||
(blk < fs->super->s_first_data_block) ||
- (blk >= fs->super->s_blocks_count)) &&
+ (blk >= ext2_blocks_count(fs->super))) &&
fix_problem(ctx, PR_1_HTREE_BADROOT, pctx))
return 1;

@@ -1646,8 +1646,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 >= ext2_blocks_count(fs->super)) {
+ sprintf(problem, "> BLOCKS (%u)", ext2_blocks_count(fs->super));
return(problem);
}
for (i = 0; i < fs->group_desc_count; i++) {
@@ -1774,7 +1774,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 >= ext2_blocks_count(fs->super))
problem = PR_1_ILLEGAL_BLOCK_NUM;

if (problem) {
@@ -1862,7 +1862,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 >= ext2_blocks_count(fs->super))) {
if (fix_problem(ctx, PR_1_BB_ILLEGAL_BLOCK_NUM, pctx)) {
*block_nr = 0;
return BLOCK_CHANGED;
diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c
index 7f7635f..3343d9e 100644
--- a/e2fsck/pass2.c
+++ b/e2fsck/pass2.c
@@ -1092,7 +1092,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 >= ext2_blocks_count(fs->super)))
return 0;
ext2fs_unmark_block_bitmap(ctx->block_found_map, *block_nr);
ext2fs_block_alloc_stats(fs, *block_nr, -1);
@@ -1292,7 +1292,7 @@ extern int e2fsck_process_bad_inode(e2fsck_t ctx, ext2_ino_t dir,

if (inode.i_file_acl &&
((inode.i_file_acl < fs->super->s_first_data_block) ||
- (inode.i_file_acl >= fs->super->s_blocks_count))) {
+ (inode.i_file_acl >= ext2_blocks_count(fs->super)))) {
if (fix_problem(ctx, PR_2_FILE_ACL_BAD, &pctx)) {
inode.i_file_acl = 0;
inode_modified++;
diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
index 8e3794d..7e3f5ee 100644
--- a/e2fsck/pass5.c
+++ b/e2fsck/pass5.c
@@ -130,11 +130,11 @@ static void check_block_bitmaps(e2fsck_t ctx)

if ((fs->super->s_first_data_block <
ext2fs_get_block_bitmap_start(ctx->block_found_map)) ||
- (fs->super->s_blocks_count-1 >
+ (ext2_blocks_count(fs->super) - 1 >
ext2fs_get_block_bitmap_end(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 = ext2_blocks_count(fs->super) -1;
pctx.ino = ext2fs_get_block_bitmap_start(ctx->block_found_map);
pctx.ino2 = ext2fs_get_block_bitmap_end(ctx->block_found_map);
fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
@@ -145,11 +145,11 @@ static void check_block_bitmaps(e2fsck_t ctx)

if ((fs->super->s_first_data_block <
ext2fs_get_block_bitmap_start(fs->block_map)) ||
- (fs->super->s_blocks_count-1 >
+ (ext2_blocks_count(fs->super) - 1 >
ext2fs_get_block_bitmap_end(fs->block_map))) {
pctx.num = 2;
pctx.blk = fs->super->s_first_data_block;
- pctx.blk2 = fs->super->s_blocks_count -1;
+ pctx.blk2 = ext2_blocks_count(fs->super) - 1;
pctx.ino = ext2fs_get_block_bitmap_start(fs->block_map);
pctx.ino2 = ext2fs_get_block_bitmap_end(fs->block_map);
fix_problem(ctx, PR_5_BMAP_ENDPOINTS, &pctx);
@@ -170,7 +170,7 @@ redo_counts:
skip_group++;
super = fs->super->s_first_data_block;
for (i = fs->super->s_first_data_block;
- i < fs->super->s_blocks_count;
+ i < ext2_blocks_count(fs->super);
i++) {
actual = ext2fs_fast_test_block_bitmap(ctx->block_found_map, i);

@@ -230,7 +230,7 @@ redo_counts:
}
blocks ++;
if ((blocks == fs->super->s_blocks_per_group) ||
- (i == fs->super->s_blocks_count-1)) {
+ (i == ext2_blocks_count(fs->super) - 1)) {
free_array[group] = group_free;
group ++;
blocks = 0;
@@ -242,7 +242,7 @@ redo_counts:
fs->group_desc_count*2))
goto errout;
if (lazy_bg &&
- (i != fs->super->s_blocks_count-1) &&
+ (i != ext2_blocks_count(fs->super) - 1) &&
(fs->group_desc[group].bg_flags &
EXT2_BG_BLOCK_UNINIT))
skip_group++;
diff --git a/e2fsck/super.c b/e2fsck/super.c
index a91f37e..d2693db 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 >= ext2_blocks_count(fs->super))) {
fix_problem(ctx, PR_0_ORPHAN_ILLEGAL_BLOCK_NUM, pctx);
return_abort:
pb->abort = 1;
@@ -375,7 +375,7 @@ static 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 >= ext2_blocks_count(fs->super))) {
resize_inode_invalid:
if (fix_problem(ctx, PR_0_RESIZE_INODE_INVALID, &pctx)) {
memset(&inode, 0, sizeof(inode));
@@ -491,10 +491,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", ext2_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, ext2_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);
@@ -508,7 +508,7 @@ void check_super_block(e2fsck_t ctx)
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);
+ MAX_CHECK, 0, ext2_blocks_count(sb) / 2);
check_super_value(ctx, "reserved_gdt_blocks",
sb->s_reserved_gdt_blocks, MAX_CHECK, 0,
fs->blocksize/4);
@@ -525,8 +525,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 < ext2_blocks_count(sb))) {
+ pctx.blk = ext2_blocks_count(sb);
pctx.blk2 = ctx->num_blocks;
if (fix_problem(ctx, PR_0_FS_SIZE_WRONG, &pctx)) {
ctx->flags |= E2F_FLAG_ABORT;
@@ -641,7 +641,7 @@ void check_super_block(e2fsck_t ctx)
}
}

- if ((sb->s_free_blocks_count > sb->s_blocks_count) ||
+ if ((sb->s_free_blocks_count > ext2_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 ad68c4b..610712f 100644
--- a/e2fsck/unix.c
+++ b/e2fsck/unix.c
@@ -110,8 +110,8 @@ 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 -
+ blocks = ext2_blocks_count(fs->super);
+ blocks_used = (ext2_blocks_count(fs->super) -
fs->super->s_free_blocks_count);

frag_percent = (10000 * ctx->fs_fragmented) / inodes_used;
@@ -302,8 +302,8 @@ static void check_if_skip(e2fsck_t ctx)
printf(_("%s: clean, %u/%u files, %u/%u 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);
+ ext2_blocks_count(fs->super) - fs->super->s_free_blocks_count,
+ ext2_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;
@@ -1215,7 +1215,7 @@ restart:
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(ext2_blocks_count(fs->super));
if (journal_size < 0) {
fs->super->s_feature_compat &=
~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
diff --git a/lib/ext2fs/alloc.c b/lib/ext2fs/alloc.c
index 7385123..e3ea8e0 100644
--- a/lib/ext2fs/alloc.c
+++ b/lib/ext2fs/alloc.c
@@ -84,7 +84,7 @@ errcode_t ext2fs_new_block(ext2_filsys fs, blk_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 >= ext2_blocks_count(fs->super)))
goal = fs->super->s_first_data_block;
i = goal;
do {
@@ -93,7 +93,7 @@ errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
return 0;
}
i++;
- if (i >= fs->super->s_blocks_count)
+ if (i >= ext2_blocks_count(fs->super))
i = fs->super->s_first_data_block;
} while (i != goal);
return EXT2_ET_BLOCK_ALLOC_FAIL;
@@ -160,7 +160,7 @@ errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish,
if (!num)
num = 1;
do {
- if (b+num-1 > fs->super->s_blocks_count)
+ if (b+num-1 > ext2_blocks_count(fs->super))
b = fs->super->s_first_data_block;
if (ext2fs_fast_test_block_bitmap_range(map, b, num)) {
*ret = b;
diff --git a/lib/ext2fs/bb_inode.c b/lib/ext2fs/bb_inode.c
index 97a5608..0d252ea 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 >= ext2_blocks_count(fs->super) ||
*block_nr < fs->super->s_first_data_block) {
*block_nr = 0;
return BLOCK_CHANGED;
diff --git a/lib/ext2fs/bitmaps.c b/lib/ext2fs/bitmaps.c
index b033fa3..0427225 100644
--- a/lib/ext2fs/bitmaps.c
+++ b/lib/ext2fs/bitmaps.c
@@ -78,7 +78,7 @@ errcode_t ext2fs_allocate_block_bitmap(ext2_filsys fs,
fs->write_bitmaps = ext2fs_write_bitmaps;

start = fs->super->s_first_data_block;
- end = fs->super->s_blocks_count-1;
+ end = ext2_blocks_count(fs->super) - 1;
real_end = (EXT2_BLOCKS_PER_GROUP(fs->super)
* fs->group_desc_count)-1 + start;

diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c
index 7685680..91cdd28 100644
--- a/lib/ext2fs/block.c
+++ b/lib/ext2fs/block.c
@@ -53,7 +53,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 >= ext2_blocks_count(ctx->fs->super) ||
*ind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_IND_BLOCK;
ret |= BLOCK_ERROR;
@@ -127,7 +127,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 >= ext2_blocks_count(ctx->fs->super) ||
*dind_block < ctx->fs->super->s_first_data_block) {
ctx->errcode = EXT2_ET_BAD_DIND_BLOCK;
ret |= BLOCK_ERROR;
@@ -203,7 +203,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 >= ext2_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 9946c46..ec200f8 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_bitmap(pb->reserve, block)) {
do {
- if (++block >= fs->super->s_blocks_count)
+ if (++block >= ext2_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/closefs.c b/lib/ext2fs/closefs.c
index da95b54..f1cbe4e 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -66,7 +66,7 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,
fs->desc_blocks + fs->super->s_reserved_gdt_blocks;

if (group == fs->group_desc_count-1) {
- numblocks = (fs->super->s_blocks_count -
+ numblocks = (ext2_blocks_count(fs->super) -
fs->super->s_first_data_block) %
fs->super->s_blocks_per_group;
if (!numblocks)
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index b60318c..6c4ec69 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -1257,7 +1257,7 @@ _INLINE_ void ext2_free_blocks_count_set(struct ext2_super_block *super,
_INLINE_ blk_t ext2fs_group_last_block(ext2_filsys fs, dgrp_t group)
{
return (group == fs->group_desc_count - 1 ?
- fs->super->s_blocks_count - 1 :
+ ext2_blocks_count(fs->super) - 1 :
ext2fs_group_first_block(fs, group) +
(fs->super->s_blocks_per_group - 1));
}
diff --git a/lib/ext2fs/ext_attr.c b/lib/ext2fs/ext_attr.c
index 08211c3..5bced12 100644
--- a/lib/ext2fs/ext_attr.c
+++ b/lib/ext2fs/ext_attr.c
@@ -74,7 +74,7 @@ errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
struct ext2_ext_attr_header *header;
char *buf = 0;

- if ((blk >= fs->super->s_blocks_count) ||
+ if ((blk >= ext2_blocks_count(fs->super)) ||
(blk < fs->super->s_first_data_block))
return EXT2_ET_BAD_EA_BLOCK_NUM;

diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index f5bff1e..cb68191 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 (ext2_blocks_count(sb) < max_blocks / 1024)
+ max_blocks = ext2_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))
@@ -107,7 +107,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
char *buf;
char c;

- if (!param || !param->s_blocks_count)
+ if (!param || !ext2_blocks_count(param))
return EXT2_ET_INVALID_ARGUMENT;

retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs);
@@ -187,9 +187,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;
+ ext2_blocks_count_set(super, ext2_blocks_count(param));
super->s_r_blocks_count = param->s_r_blocks_count;
- if (super->s_r_blocks_count >= param->s_blocks_count) {
+ if (super->s_r_blocks_count >= ext2_blocks_count(param)) {
retval = EXT2_ET_INVALID_ARGUMENT;
goto cleanup;
}
@@ -206,7 +206,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
}

retry:
- fs->group_desc_count = ext2fs_div_ceil(super->s_blocks_count -
+ fs->group_desc_count = ext2fs_div_ceil(ext2_blocks_count(super) -
super->s_first_data_block,
EXT2_BLOCKS_PER_GROUP(super));
if (fs->group_desc_count == 0) {
@@ -217,7 +217,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, ext2_blocks_count(super) / i);

/*
* Make sure we have at least EXT2_FIRST_INO + 1 inodes, so
@@ -237,7 +237,7 @@ 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;
+ ext2_blocks_count_set(super, ext2_blocks_count(param));
super->s_frags_per_group = super->s_blocks_per_group *
frags_per_block;
goto retry;
@@ -321,12 +321,12 @@ 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 = ((ext2_blocks_count(super) - super->s_first_data_block) %
super->s_blocks_per_group);
if ((fs->group_desc_count == 1) && rem && (rem < overhead))
return EXT2_ET_TOOSMALL;
if (rem && (rem < overhead+50)) {
- super->s_blocks_count -= rem;
+ ext2_blocks_count_set(super, ext2_blocks_count(super) - rem);
goto retry;
}

diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 73ab088..4f2585b 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -53,7 +53,7 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
*/
if (group_block != fs->super->s_first_data_block &&
((ret_blk + fs->super->s_blocks_per_group) <
- fs->super->s_blocks_count))
+ ext2_blocks_count(fs->super)))
ret_blk += fs->super->s_blocks_per_group;
return ret_blk;
}
@@ -270,7 +270,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
retval = EXT2_ET_CORRUPT_SUPERBLOCK;
goto cleanup;
}
- fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
+ fs->group_desc_count = ext2fs_div_ceil(ext2_blocks_count(fs->super) -
fs->super->s_first_data_block,
blocks_per_group);
fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
diff --git a/lib/ext2fs/read_bb.c b/lib/ext2fs/read_bb.c
index c717adc..0841232 100644
--- a/lib/ext2fs/read_bb.c
+++ b/lib/ext2fs/read_bb.c
@@ -49,7 +49,7 @@ static int mark_bad_block(ext2_filsys fs, blk_t *block_nr,
return 0;

if ((*block_nr < fs->super->s_first_data_block) ||
- (*block_nr >= fs->super->s_blocks_count))
+ (*block_nr >= ext2_blocks_count(fs->super)))
return 0; /* Ignore illegal blocks */

rb->err = ext2fs_badblocks_list_add(rb->bb_list, *block_nr);
diff --git a/lib/ext2fs/read_bb_file.c b/lib/ext2fs/read_bb_file.c
index 2ac71f4..b2cb5d3 100644
--- a/lib/ext2fs/read_bb_file.c
+++ b/lib/ext2fs/read_bb_file.c
@@ -59,7 +59,7 @@ errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
continue;
if (fs &&
((blockno < fs->super->s_first_data_block) ||
- (blockno >= fs->super->s_blocks_count))) {
+ (blockno >= ext2_blocks_count(fs->super)))) {
if (invalid)
(invalid)(fs, blockno, buf, priv_data);
continue;
diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c
index 603b590..1c2c756 100644
--- a/lib/ext2fs/rw_bitmaps.c
+++ b/lib/ext2fs/rw_bitmaps.c
@@ -103,7 +103,7 @@ 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
+ nbits = ((ext2_blocks_count(fs->super)
- fs->super->s_first_data_block)
% EXT2_BLOCKS_PER_GROUP(fs->super));
if (nbits)
diff --git a/lib/ext2fs/tst_badblocks.c b/lib/ext2fs/tst_badblocks.c
index 2453f47..abb5dc8 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;
+ ext2_blocks_count_set(fs->super, 100);

f = tmpfile();
if (!f) {
diff --git a/lib/ext2fs/tst_iscan.c b/lib/ext2fs/tst_iscan.c
index d7fdc12..df16355 100644
--- a/lib/ext2fs/tst_iscan.c
+++ b/lib/ext2fs/tst_iscan.c
@@ -71,7 +71,7 @@ static void setup(void)
initialize_ext2_error_table();

memset(&param, 0, sizeof(param));
- param.s_blocks_count = 12000;
+ ext2_blocks_count_set(&param, 12000);


test_io_cb_read_blk = test_read_blk;
diff --git a/misc/e2image.c b/misc/e2image.c
index dd13cea..74772c7 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -411,7 +411,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 < ext2_blocks_count(fs->super); blk++) {
if ((blk >= fs->super->s_first_data_block) &&
ext2fs_test_block_bitmap(meta_block_map, blk)) {
retval = io_channel_read_blk(fs->io, blk, 1, buf);
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 3dc5e18..021625a 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -192,7 +192,7 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list)

sprintf(buf, "badblocks -b %d -X %s%s%s %u", fs->blocksize,
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
- fs->device_name, fs->super->s_blocks_count-1);
+ fs->device_name, ext2_blocks_count(fs->super) - 1);
if (verbose)
printf(_("Running command: %s\n"), buf);
f = popen(buf, "r");
@@ -626,7 +626,7 @@ static void create_journal_dev(ext2_filsys fs)
int count;

retval = ext2fs_create_journal_superblock(fs,
- fs->super->s_blocks_count, 0, &buf);
+ ext2_blocks_count(fs->super), 0, &buf);
if (retval) {
com_err("create_journal_dev", retval,
_("while initializing journal superblock"));
@@ -636,9 +636,9 @@ static void create_journal_dev(ext2_filsys fs)
memset(&progress, 0, sizeof(progress));
else
progress_init(&progress, _("Zeroing journal device: "),
- fs->super->s_blocks_count);
+ ext2_blocks_count(fs->super));

- retval = zero_blocks(fs, 0, fs->super->s_blocks_count,
+ retval = zero_blocks(fs, 0, ext2_blocks_count(fs->super),
&progress, &blk, &count);
if (retval) {
com_err("create_journal_dev", retval,
@@ -668,9 +668,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)
+ if (ext2_blocks_count(&fs_param) != ext2_blocks_count(s))
fprintf(stderr, _("warning: %u blocks unused.\n\n"),
- fs_param.s_blocks_count - s->s_blocks_count);
+ ext2_blocks_count(&fs_param) - ext2_blocks_count(s));

memset(buf, 0, sizeof(buf));
strncpy(buf, s->s_volume_name, sizeof(s->s_volume_name));
@@ -685,10 +685,10 @@ static void show_stats(ext2_filsys fs)
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);
+ ext2_blocks_count(s));
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);
+ 100.0 * s->s_r_blocks_count / ext2_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"),
@@ -813,7 +813,7 @@ static void parse_extended_opts(struct ext2_super_block *param,
r_usage++;
continue;
}
- if (resize <= param->s_blocks_count) {
+ if (resize <= ext2_blocks_count(param)) {
fprintf(stderr,
_("The resize maximum must be greater "
"than the filesystem size.\n"));
@@ -827,7 +827,7 @@ static void parse_extended_opts(struct ext2_super_block *param,
bpg = blocksize * 8;
gdpb = EXT2_DESC_PER_BLOCK(param);
group_desc_count =
- ext2fs_div_ceil(param->s_blocks_count, bpg);
+ ext2fs_div_ceil(ext2_blocks_count(param), bpg);
desc_blocks = (group_desc_count +
gdpb - 1) / gdpb;
rsv_groups = ext2fs_div_ceil(resize, bpg);
@@ -1221,9 +1221,10 @@ 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) {
+ ext2_blocks_count_set(&fs_param,
+ parse_num_blocks(argv[optind++],
+ fs_param.s_log_block_size));
+ if (!ext2_blocks_count(&fs_param)) {
com_err(program_name, 0, _("invalid blocks count - %s"),
argv[optind - 1]);
exit(1);
@@ -1238,8 +1239,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 && ext2_blocks_count(&fs_param)) {
+ dev_size = ext2_blocks_count(&fs_param);
retval = 0;
} else {
retry:
@@ -1260,7 +1261,7 @@ static void PRS(int argc, char *argv[])
_("while trying to determine filesystem size"));
exit(1);
}
- if (!fs_param.s_blocks_count) {
+ if (!ext2_blocks_count(&fs_param)) {
if (retval == EXT2_ET_UNIMPLEMENTED) {
com_err(program_name, 0,
_("Couldn't determine device size; you "
@@ -1280,20 +1281,20 @@ static void PRS(int argc, char *argv[])
));
exit(1);
}
- fs_param.s_blocks_count = dev_size;
+ ext2_blocks_count_set(&fs_param, 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);
}

- } else if (!force && (fs_param.s_blocks_count > dev_size)) {
+ } else if (!force && (ext2_blocks_count(&fs_param) > dev_size)) {
com_err(program_name, 0,
_("Filesystem larger than apparent device size."));
proceed_question();
}

if (!fs_type) {
- int megs = (__u64)fs_param.s_blocks_count *
+ int megs = ext2_blocks_count(&fs_param) *
(EXT2_BLOCK_SIZE(&fs_param) / 1024) / 1024;

if (fs_param.s_feature_incompat &
@@ -1405,7 +1406,8 @@ static void PRS(int argc, char *argv[])
if ((blocksize < 0) && (use_bsize < (-blocksize)))
use_bsize = -blocksize;
blocksize = use_bsize;
- fs_param.s_blocks_count /= blocksize / 1024;
+ ext2_blocks_count_set(&fs_param,
+ ext2_blocks_count(&fs_param) / (blocksize / 1024));
}

if (inode_ratio == 0) {
@@ -1467,7 +1469,7 @@ static void PRS(int argc, char *argv[])
}


- if (!force && fs_param.s_blocks_count >= ((unsigned) 1 << 31)) {
+ if (!force && ext2_blocks_count(&fs_param) >= ((unsigned) 1 << 31)) {
com_err(program_name, 0,
_("Filesystem too large. No more than 2**31-1 blocks\n"
"\t (8TB using a blocksize of 4k) are currently supported."));
@@ -1508,7 +1510,7 @@ static void PRS(int argc, char *argv[])
/* 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 = (unsigned long long) ext2_blocks_count(&fs_param) * blocksize / inode_ratio;
if (n > ~0U) {
com_err(program_name, 0,
_("too many inodes (%llu), raise inode ratio?"), n);
@@ -1524,12 +1526,12 @@ static void PRS(int argc, char *argv[])
* 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)
+ ((__u64) ext2_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) *
+ (((long long)ext2_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"
@@ -1538,7 +1540,7 @@ static void PRS(int argc, char *argv[])
"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) ext2_blocks_count(&fs_param));
exit(1);
}

@@ -1546,7 +1548,7 @@ static void PRS(int argc, char *argv[])
* Calculate number of blocks to reserve
*/
fs_param.s_r_blocks_count = e2p_percent(reserved_ratio,
- fs_param.s_blocks_count);
+ ext2_blocks_count(&fs_param));
}

int main (int argc, char *argv[])
@@ -1677,7 +1679,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 = ext2_blocks_count(fs->super);
unsigned long start;
blk_t ret_blk;

diff --git a/misc/tune2fs.c b/misc/tune2fs.c
index 833b994..5eaa252 100644
--- a/misc/tune2fs.c
+++ b/misc/tune2fs.c
@@ -826,13 +826,13 @@ int main (int argc, char ** argv)
}
if (m_flag) {
sb->s_r_blocks_count = e2p_percent(reserved_ratio,
- sb->s_blocks_count);
+ ext2_blocks_count(sb));
ext2fs_mark_super_dirty(fs);
printf (_("Setting reserved blocks percentage to %g%% (%u blocks)\n"),
reserved_ratio, sb->s_r_blocks_count);
}
if (r_flag) {
- if (reserved_blocks >= sb->s_blocks_count/2) {
+ if (reserved_blocks >= ext2_blocks_count(sb) / 2) {
com_err (program_name, 0,
_("reserved blocks count is too big (%lu)"),
reserved_blocks);
diff --git a/misc/util.c b/misc/util.c
index 6a4c40c..8fe505a 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(ext2_blocks_count(fs->super));
if (j_blocks < 0) {
fputs(_("\nFilesystem too small for a journal\n"), stderr);
return 0;
diff --git a/resize/main.c b/resize/main.c
index 7db4ebc..a7e0190 100644
--- a/resize/main.c
+++ b/resize/main.c
@@ -380,7 +380,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 == ext2_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 36b3185..ebc4ff9 100644
--- a/resize/online.c
+++ b/resize/online.c
@@ -33,9 +33,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) {
+ if (*new_size < ext2_blocks_count(sb)) {
printf(_("On-line shrinking from %u to %u not supported.\n"),
- sb->s_blocks_count, *new_size);
+ ext2_blocks_count(sb), *new_size);
exit(1);
}

@@ -65,7 +65,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
exit(1);
}

- size=sb->s_blocks_count;
+ size = ext2_blocks_count(sb);
if (ioctl(fd, EXT2_IOC_GROUP_EXTEND, &size)) {
if (errno == EPERM)
com_err(program_name, 0,
@@ -79,7 +79,7 @@ errcode_t online_resize_fs(ext2_filsys fs, const char *mtpt,
exit(1);
}

- r_frac = ext2fs_div_ceil(100 * sb->s_r_blocks_count, sb->s_blocks_count);
+ r_frac = ext2fs_div_ceil(100 * sb->s_r_blocks_count, ext2_blocks_count(sb));

retval = ext2fs_read_bitmaps(fs);
if (retval)
@@ -122,7 +122,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 = ext2_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 12bdd89..6c37f77 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -100,7 +100,7 @@ errcode_t resize_fs(ext2_filsys fs, blk_t *new_size, int flags,
if (retval)
goto errout;

- *new_size = rfs->new_fs->super->s_blocks_count;
+ *new_size = ext2_blocks_count(rfs->new_fs->super);

retval = blocks_to_move(rfs);
if (retval)
@@ -189,10 +189,10 @@ errcode_t adjust_fs_info(ext2_filsys fs, ext2_filsys old_fs, blk_t new_size)
int has_super;
unsigned long long new_inodes; /* u64 to check for overflow */

- fs->super->s_blocks_count = new_size;
+ ext2_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_div_ceil(ext2_blocks_count(fs->super) -
fs->super->s_first_data_block,
EXT2_BLOCKS_PER_GROUP(fs->super));
if (fs->group_desc_count == 0)
@@ -217,12 +217,12 @@ 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 = (ext2_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;
+ ext2_blocks_count_set(fs->super, ext2_blocks_count(fs->super) - rem);
goto retry;
}
/*
@@ -240,21 +240,21 @@ retry:
/*
* Adjust the number of free blocks
*/
- blk = old_fs->super->s_blocks_count;
- if (blk > fs->super->s_blocks_count)
+ blk = ext2_blocks_count(old_fs->super);
+ if (blk > ext2_blocks_count(fs->super))
fs->super->s_free_blocks_count -=
- (blk - fs->super->s_blocks_count);
+ (blk - ext2_blocks_count(fs->super));
else
fs->super->s_free_blocks_count +=
- (fs->super->s_blocks_count - blk);
+ (ext2_blocks_count(fs->super) - blk);

/*
* Adjust the number of reserved blocks
*/
blk = (__u64)old_fs->super->s_r_blocks_count * 100 /
- old_fs->super->s_blocks_count;
+ ext2_blocks_count(old_fs->super);
fs->super->s_r_blocks_count = e2p_percent(blk,
- fs->super->s_blocks_count);
+ ext2_blocks_count(fs->super));

/*
* Adjust the bitmaps for size
@@ -267,7 +267,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_bitmap(fs->super->s_blocks_count-1,
+ retval = ext2fs_resize_block_bitmap(ext2_blocks_count(fs->super) - 1,
real_end, fs->block_map);

if (retval) goto errout;
@@ -324,13 +324,13 @@ retry:
/*
* Fix the count of the last (old) block group
*/
- old_numblocks = (old_fs->super->s_blocks_count -
+ old_numblocks = (ext2_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 = (ext2_blocks_count(fs->super) -
fs->super->s_first_data_block) %
fs->super->s_blocks_per_group;
if (!numblocks)
@@ -370,7 +370,7 @@ retry:
adjblocks = 0;

if (i == fs->group_desc_count-1) {
- numblocks = (fs->super->s_blocks_count -
+ numblocks = (ext2_blocks_count(fs->super) -
fs->super->s_first_data_block) %
fs->super->s_blocks_per_group;
if (!numblocks)
@@ -635,7 +635,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 (ext2_blocks_count(old_fs->super) > ext2_blocks_count(fs->super))
fs = rfs->old_fs;

retval = ext2fs_allocate_block_bitmap(fs, _("reserved blocks"),
@@ -663,8 +663,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 = ext2_blocks_count(fs->super);
+ blk < ext2_blocks_count(old_fs->super); blk++) {
if (ext2fs_test_block_bitmap(old_fs->block_map, blk) &&
!ext2fs_test_block_bitmap(meta_bmap, blk)) {
ext2fs_mark_block_bitmap(rfs->move_blocks, blk);
@@ -861,9 +861,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 (ext2_blocks_count(rfs->new_fs->super) >
+ ext2_blocks_count(rfs->old_fs->super))
+ rfs->new_blk = ext2_blocks_count(rfs->old_fs->super);
#endif
}

@@ -872,7 +872,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 >= ext2_blocks_count(fs->super)) {
if (rfs->alloc_state == DESPERATION)
return 0;

@@ -889,7 +889,7 @@ static blk_t get_new_block(ext2_resize_t rfs)
ext2fs_test_block_bitmap(rfs->reserve_blocks,
rfs->new_blk) ||
((rfs->alloc_state == AVOID_OLD) &&
- (rfs->new_blk < rfs->old_fs->super->s_blocks_count) &&
+ (rfs->new_blk < ext2_blocks_count(rfs->old_fs->super)) &&
ext2fs_test_block_bitmap(rfs->old_fs->block_map,
rfs->new_blk))) {
rfs->new_blk++;
@@ -933,7 +933,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 < ext2_blocks_count(old_fs->super); blk++) {
if (!ext2fs_test_block_bitmap(old_fs->block_map, blk))
continue;
if (!ext2fs_test_block_bitmap(rfs->move_blocks, blk))
@@ -1127,10 +1127,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 = ext2_blocks_count(rfs->old_fs->super);
+ if (orig_size < ext2_blocks_count(rfs->new_fs->super))
+ ext2_blocks_count_set(rfs->old_fs->super,
+ ext2_blocks_count(rfs->new_fs->super));

retval = ext2fs_open_inode_scan(rfs->old_fs, 0, &scan);
if (retval) goto errout;
@@ -1239,7 +1239,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;
+ ext2_blocks_count_set(rfs->old_fs->super, orig_size);
if (rfs->bmap) {
ext2fs_free_extent_table(rfs->bmap);
rfs->bmap = 0;
@@ -1566,14 +1566,14 @@ 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 < ext2_blocks_count(fs->super); blk++) {
if (!ext2fs_fast_test_block_bitmap(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 == ext2_blocks_count(fs->super) - 1)) {
fs->group_desc[group++].bg_free_blocks_count =
group_free;
count = 0;
diff --git a/tests/progs/test_icount.c b/tests/progs/test_icount.c
index 026779f..21efe4f 100644
--- a/tests/progs/test_icount.c
+++ b/tests/progs/test_icount.c
@@ -307,7 +307,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;
+ ext2_blocks_count_set(&param, 80000);
param.s_inodes_count = 20000;
retval = ext2fs_initialize("/dev/null", 0, &param,
unix_io_manager, &test_fs);

2007-08-30 13:26:42

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 4/8][e2fsprogs] add new macro to get descriptor number


From: Valerie Clement <[email protected]>

This patch introduces a new macro EXT2_DESC_PER_BLOCK to calculate the number
of group descriptors per block as two different structures are now defined,
ext4_group_desc structure for ext4 filesystems and ext2_group_desc structure
for older filesystems.

Signed-off-by: Valerie Clement <[email protected]>
---

lib/ext2fs/closefs.c | 2 +-
lib/ext2fs/ext2_fs.h | 2 +-
lib/ext2fs/initialize.c | 2 +-
lib/ext2fs/openfs.c | 4 ++--
misc/mke2fs.c | 5 ++---
resize/resize2fs.c | 7 +++----
6 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index efbb727..da95b54 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -80,7 +80,7 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,
super_blk = group_block;
numblocks--;
}
- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
meta_bg = group / meta_bg_size;

if (!(fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) ||
diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
index f6e8b36..3941c38 100644
--- a/lib/ext2fs/ext2_fs.h
+++ b/lib/ext2fs/ext2_fs.h
@@ -234,7 +234,7 @@ struct ext2_dx_countlimit {
#define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
#define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
#else
-#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
+#define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_DESC_SIZE(s))
#endif

/*
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index ee7af93..f5bff1e 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -67,7 +67,7 @@ static unsigned int calc_reserved_gdt_blocks(ext2_filsys fs)
{
struct ext2_super_block *sb = fs->super;
unsigned long bpg = sb->s_blocks_per_group;
- unsigned int gdpb = fs->blocksize / sizeof(struct ext2_group_desc);
+ unsigned int gdpb = EXT2_DESC_PER_BLOCK(sb);
unsigned long max_blocks = 0xffffffff;
unsigned long rsv_groups;
unsigned int rsv_gdb;
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 8a369c3..73ab088 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -39,7 +39,7 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
(i < fs->super->s_first_meta_bg))
return (group_block + i + 1);

- bg = (fs->blocksize / sizeof (struct ext2_group_desc)) * i;
+ bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
if (ext2fs_bg_has_super(fs, bg))
has_super = 1;
ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
@@ -282,7 +282,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options,
if (!group_block)
group_block = fs->super->s_first_data_block;
dest = (char *) fs->group_desc;
- groups_per_block = fs->blocksize / sizeof(struct ext2_group_desc);
+ groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
for (i=0 ; i < fs->desc_blocks; i++) {
blk = ext2fs_descriptor_block_loc(fs, group_block, i);
retval = io_channel_read_blk(fs->io, blk, 1, dest);
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 115eef9..3dc5e18 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -693,8 +693,7 @@ static void show_stats(ext2_filsys fs)
if (s->s_reserved_gdt_blocks)
printf(_("Maximum filesystem blocks=%lu\n"),
(s->s_reserved_gdt_blocks + fs->desc_blocks) *
- (fs->blocksize / sizeof(struct ext2_group_desc)) *
- s->s_blocks_per_group);
+ EXT2_DESC_PER_BLOCK(s) * s->s_blocks_per_group);
if (fs->group_desc_count > 1)
printf(_("%u block groups\n"), fs->group_desc_count);
else
@@ -826,7 +825,7 @@ static void parse_extended_opts(struct ext2_super_block *param,
bpg = param->s_blocks_per_group;
if (!bpg)
bpg = blocksize * 8;
- gdpb = blocksize / sizeof(struct ext2_group_desc);
+ gdpb = EXT2_DESC_PER_BLOCK(param);
group_desc_count =
ext2fs_div_ceil(param->s_blocks_count, bpg);
desc_blocks = (group_desc_count +
diff --git a/resize/resize2fs.c b/resize/resize2fs.c
index 0d6a082..12bdd89 100644
--- a/resize/resize2fs.c
+++ b/resize/resize2fs.c
@@ -383,8 +383,7 @@ retry:
ext2fs_mark_block_bitmap(fs->block_map, group_block);
adjblocks++;
}
- meta_bg_size = (fs->blocksize /
- sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
meta_bg = i / meta_bg_size;
if (!(fs->super->s_feature_incompat &
EXT2_FEATURE_INCOMPAT_META_BG) ||
@@ -550,7 +549,7 @@ static errcode_t mark_table_blocks(ext2_filsys fs,
unsigned long meta_bg_size;
unsigned int old_desc_blocks;

- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
else
@@ -717,7 +716,7 @@ static errcode_t blocks_to_move(ext2_resize_t rfs)
* If we're increasing the number of descriptor blocks, life
* gets interesting....
*/
- meta_bg_size = (fs->blocksize / sizeof (struct ext2_group_desc));
+ meta_bg_size = EXT2_DESC_PER_BLOCK(fs->super);
for (i = 0; i < max_groups; i++) {
has_super = ext2fs_bg_has_super(fs, i);
if (has_super)

2007-08-30 13:26:40

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 3/8][e2fsprogs] add new -D <desc-size> option to mkfs


From: Valerie Clement <[email protected]>

This patch adds a new option -D <descriptor-size> to mkfs to allow creating
ext4 filesystems with larger group descriptor size.

By default, the group descriptor size is 32 bytes.
To support 64-bit physical block numbers and thus to be able to use filesystems
> 16TB, the group descriptor size must be increased to 64 bytes.

Use mkfs -t ext4 -D 64 to create an ext4 filesystem with 64-byte group
descriptor size. This set the EXT4_FEATURE_INCOMPAT_64BIT flag on device.

The descriptor size is limited to a power-of-two value and to the block size.

Signed-off-by: Valerie Clement <[email protected]>
---

lib/ext2fs/ext2_fs.h | 7 +++++++
lib/ext2fs/initialize.c | 1 +
misc/mke2fs.c | 33 +++++++++++++++++++++++++++++++--
3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
index a316665..f6e8b36 100644
--- a/lib/ext2fs/ext2_fs.h
+++ b/lib/ext2fs/ext2_fs.h
@@ -217,6 +217,13 @@ struct ext2_dx_countlimit {
/*
* Macro-instructions used to manage group descriptors
*/
+#define EXT2_MIN_DESC_SIZE 32
+#define EXT2_MIN_DESC_SIZE_64BIT 64
+#define EXT2_MAX_DESC_SIZE EXT2_MIN_BLOCK_SIZE
+#define EXT2_DESC_SIZE(s) \
+ ((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? \
+ (s)->s_desc_size : EXT2_MIN_DESC_SIZE)
+
#define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
#define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
index 16e9eaa..ee7af93 100644
--- a/lib/ext2fs/initialize.c
+++ b/lib/ext2fs/initialize.c
@@ -149,6 +149,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,

set_field(s_log_block_size, 0); /* default blocksize: 1024 bytes */
set_field(s_log_frag_size, 0); /* default fragsize: 1024 bytes */
+ set_field(s_desc_size, 0);
set_field(s_first_data_block, super->s_log_block_size ? 0 : 1);
set_field(s_max_mnt_count, EXT2_DFL_MAX_MNT_COUNT);
set_field(s_errors, EXT2_ERRORS_DEFAULT);
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 4a6cace..115eef9 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -96,7 +96,7 @@ static void usage(void)
{
fprintf(stderr, _("Usage: %s [-c|-t|-l filename] [-b block-size] "
"[-f fragment-size]\n\t[-i bytes-per-inode] [-I inode-size] "
- "[-j] [-J journal-options]\n"
+ "[-D descriptor-size] [-j] [-J journal-options]\n"
"\t[-N number-of-inodes] [-m reserved-blocks-percentage] "
"[-o creator-os]\n\t[-g blocks-per-group] [-L volume-label] "
"[-M last-mounted-directory]\n\t[-O feature[,...]] "
@@ -911,6 +911,7 @@ static void PRS(int argc, char *argv[])
int blocksize = 0;
int inode_ratio = 0;
int inode_size = 0;
+ int desc_size = 0;
double reserved_ratio = 5.0;
int sector_size = 0;
int show_version_only = 0;
@@ -993,7 +994,7 @@ static void PRS(int argc, char *argv[])
}

while ((c = getopt (argc, argv,
- "b:cf:g:i:jl:m:no:qr:s:tvE:FI:J:L:M:N:O:R:ST:V")) != EOF) {
+ "b:cf:g:i:jl:m:no:qr:s:tvD:E:FI:J:L:M:N:O:R:ST:V")) != EOF) {
switch (c) {
case 'b':
blocksize = strtol(optarg, &tmp, 0);
@@ -1110,6 +1111,14 @@ static void PRS(int argc, char *argv[])
exit(1);
}
break;
+ case 'D':
+ desc_size = strtoul(optarg, &tmp, 0);
+ if (*tmp) {
+ com_err(program_name, 0,
+ _("invalid descriptor size - %s"), optarg);
+ exit(1);
+ }
+ break;
case 'v':
verbose = 1;
break;
@@ -1439,6 +1448,26 @@ static void PRS(int argc, char *argv[])
}
}

+ if (desc_size) {
+ if (desc_size < EXT2_MIN_DESC_SIZE ||
+ desc_size > EXT2_BLOCK_SIZE(&fs_param) ||
+ desc_size & (desc_size -1)) {
+ com_err(program_name, 0,
+ _("invalid descriptor size %d (min %d/max %d)"),
+ desc_size, EXT2_MIN_DESC_SIZE,
+ blocksize);
+ exit(1);
+ }
+ if (desc_size != EXT2_MIN_DESC_SIZE)
+ fprintf(stderr, _("Warning: %d-byte descriptors not "
+ "usable on older systems\n"),
+ desc_size);
+ fs_param.s_desc_size = desc_size;
+ if (desc_size > EXT2_MIN_DESC_SIZE)
+ fs_param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT;
+ }
+
+
if (!force && fs_param.s_blocks_count >= ((unsigned) 1 << 31)) {
com_err(program_name, 0,
_("Filesystem too large. No more than 2**31-1 blocks\n"

2007-08-30 13:26:40

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 2/8][e2fsprogs] convert block number definition to blk_t


From: Valerie Clement <[email protected]>

This patch converts a few __u32 or unsigned int block number definitions to
blk_t type. Conversions are necessary to prepare the 64-bit porting.

Signed-off-by: Valerie Clement <[email protected]>
---

debugfs/logdump.c | 10 +++++-----
e2fsck/pass5.c | 4 ++--
e2fsck/super.c | 3 ++-
lib/ext2fs/closefs.c | 4 ++--
lib/ext2fs/ext2fs.h | 2 +-
5 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/debugfs/logdump.c b/debugfs/logdump.c
index 2bf67b5..773d84e 100644
--- a/debugfs/logdump.c
+++ b/debugfs/logdump.c
@@ -36,11 +36,11 @@ extern char *optarg;

enum journal_location {JOURNAL_IS_INTERNAL, JOURNAL_IS_EXTERNAL};

-#define ANY_BLOCK ((unsigned int) -1)
+#define ANY_BLOCK ((blk_t) -1)

int dump_all, dump_contents, dump_descriptors;
-unsigned int block_to_dump, group_to_dump, bitmap_to_dump;
-unsigned int inode_block_to_dump, inode_offset_to_dump, bitmap_to_dump;
+blk_t block_to_dump, bitmap_to_dump, inode_block_to_dump;
+unsigned int group_to_dump, inode_offset_to_dump;
ext2_ino_t inode_to_dump;

struct journal_source
@@ -365,8 +365,8 @@ static void dump_journal(char *cmdname, FILE *out_file,
if (dump_all) {
fprintf(out_file, "\tuuid=%s\n", jsb_buffer);
fprintf(out_file, "\tblocksize=%d\n", blocksize);
- fprintf(out_file, "\tjournal data size %ld\n",
- (long) sb->s_blocks_count);
+ fprintf(out_file, "\tjournal data size %lu\n",
+ sb->s_blocks_count);
}
}

diff --git a/e2fsck/pass5.c b/e2fsck/pass5.c
index 53248b0..8e3794d 100644
--- a/e2fsck/pass5.c
+++ b/e2fsck/pass5.c
@@ -114,8 +114,8 @@ static void check_block_bitmaps(e2fsck_t ctx)
blk_t i, super;
int *free_array;
int group = 0;
- unsigned int blocks = 0;
- unsigned int free_blocks = 0;
+ blk_t blocks = 0;
+ blk_t free_blocks = 0;
int group_free = 0;
int actual, bitmap;
struct problem_context pctx;
diff --git a/e2fsck/super.c b/e2fsck/super.c
index 00a131c..a91f37e 100644
--- a/e2fsck/super.c
+++ b/e2fsck/super.c
@@ -466,7 +466,8 @@ void check_super_block(e2fsck_t ctx)
dgrp_t i;
blk_t should_be;
struct problem_context pctx;
- __u32 free_blocks = 0, free_inodes = 0;
+ blk_t free_blocks = 0;
+ ino_t free_inodes = 0;

inodes_per_block = EXT2_INODES_PER_BLOCK(fs->super);
ipg_max = inodes_per_block * (blocks_per_group - 4);
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index f780e80..efbb727 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -54,8 +54,8 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,
{
blk_t group_block, super_blk = 0, old_desc_blk = 0, new_desc_blk = 0;
unsigned int meta_bg, meta_bg_size;
- int numblocks, has_super;
- int old_desc_blocks;
+ blk_t numblocks, old_desc_blocks;
+ int has_super;

group_block = ext2fs_group_first_block(fs, group);

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 20c63c0..3aa9c8f 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -415,7 +415,7 @@ typedef struct ext2_icount *ext2_icount_t;
/*
* For ext2 compression support
*/
-#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) 0xffffffff)
+#define EXT2FS_COMPRESSED_BLKADDR ((blk_t) -1)
#define HOLE_BLKADDR(_b) ((_b) == 0 || (_b) == EXT2FS_COMPRESSED_BLKADDR)

/*

2007-08-30 14:02:23

by Valerie Clement

[permalink] [raw]
Subject: [PATCH 1/8][e2fsprogs] use existing function ext2fs_group_first_block()


From: Valerie Clement <[email protected]>

Replace piece of code by call to the existing function,
i.e. ext2fs_group_first_block().

Signed-off-by: Valerie Clement <[email protected]>
---

lib/ext2fs/closefs.c | 3 +--
lib/ext2fs/openfs.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 474e00e..f780e80 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -57,8 +57,7 @@ int ext2fs_super_and_bgd_loc(ext2_filsys fs,
int numblocks, has_super;
int old_desc_blocks;

- group_block = fs->super->s_first_data_block +
- (group * fs->super->s_blocks_per_group);
+ group_block = ext2fs_group_first_block(fs, group);

if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
old_desc_blocks = fs->super->s_first_meta_bg;
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index 55cc077..8a369c3 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -42,8 +42,7 @@ blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
bg = (fs->blocksize / sizeof (struct ext2_group_desc)) * i;
if (ext2fs_bg_has_super(fs, bg))
has_super = 1;
- ret_blk = (fs->super->s_first_data_block + has_super +
- (bg * fs->super->s_blocks_per_group));
+ ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
/*
* If group_block is not the normal value, we're trying to use
* the backup group descriptors and superblock --- so use the

2007-08-30 14:12:14

by Andreas Dilger

[permalink] [raw]
Subject: Re: [PATCH 3/8][e2fsprogs] add new -D <desc-size> option to mkfs

On Aug 30, 2007 17:37 +0200, Valerie Clement wrote:
> @@ -1439,6 +1448,26 @@ static void PRS(int argc, char *argv[])
> + if (desc_size < EXT2_MIN_DESC_SIZE ||
> + desc_size > EXT2_BLOCK_SIZE(&fs_param) ||

Should this be EXT2_MAX_DESC_SIZE?

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.

2007-08-30 19:12:18

by Mingming Cao

[permalink] [raw]
Subject: Re: [PATCH 3/8][e2fsprogs] add new -D <desc-size> option to mkfs

On Thu, 2007-08-30 at 17:37 +0200, Valerie Clement wrote:
> From: Valerie Clement <[email protected]>
>
> This patch adds a new option -D <descriptor-size> to mkfs to allow creating
> ext4 filesystems with larger group descriptor size.
>
> By default, the group descriptor size is 32 bytes.
> To support 64-bit physical block numbers and thus to be able to use filesystems
> > 16TB, the group descriptor size must be increased to 64 bytes.
>

Could you explain a bit more why we need this option? It seems to me we
could make the block group descriptor size to 64bytes whenever creating
a ext4 filesystem by default. Is there any case we need to create ext4
with old 32 bytes block group descriptors?

> Use mkfs -t ext4 -D 64 to create an ext4 filesystem with 64-byte group
> descriptor size. This set the EXT4_FEATURE_INCOMPAT_64BIT flag on device.
>
> The descriptor size is limited to a power-of-two value and to the block size.
>
> Signed-off-by: Valerie Clement <[email protected]>
> ---
>
> lib/ext2fs/ext2_fs.h | 7 +++++++
> lib/ext2fs/initialize.c | 1 +
> misc/mke2fs.c | 33 +++++++++++++++++++++++++++++++--
> 3 files changed, 39 insertions(+), 2 deletions(-)
>
> diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h
> index a316665..f6e8b36 100644
> --- a/lib/ext2fs/ext2_fs.h
> +++ b/lib/ext2fs/ext2_fs.h
> @@ -217,6 +217,13 @@ struct ext2_dx_countlimit {
> /*
> * Macro-instructions used to manage group descriptors
> */
> +#define EXT2_MIN_DESC_SIZE 32
> +#define EXT2_MIN_DESC_SIZE_64BIT 64
> +#define EXT2_MAX_DESC_SIZE EXT2_MIN_BLOCK_SIZE
> +#define EXT2_DESC_SIZE(s) \
> + ((EXT2_SB(s)->s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) ? \
> + (s)->s_desc_size : EXT2_MIN_DESC_SIZE)
> +
> #define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
> #define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
> #define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))
> diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c
> index 16e9eaa..ee7af93 100644
> --- a/lib/ext2fs/initialize.c
> +++ b/lib/ext2fs/initialize.c
> @@ -149,6 +149,7 @@ errcode_t ext2fs_initialize(const char *name, int flags,
>
> set_field(s_log_block_size, 0); /* default blocksize: 1024 bytes */
> set_field(s_log_frag_size, 0); /* default fragsize: 1024 bytes */
> + set_field(s_desc_size, 0);
> set_field(s_first_data_block, super->s_log_block_size ? 0 : 1);
> set_field(s_max_mnt_count, EXT2_DFL_MAX_MNT_COUNT);
> set_field(s_errors, EXT2_ERRORS_DEFAULT);
> diff --git a/misc/mke2fs.c b/misc/mke2fs.c
> index 4a6cace..115eef9 100644
> --- a/misc/mke2fs.c
> +++ b/misc/mke2fs.c
> @@ -96,7 +96,7 @@ static void usage(void)
> {
> fprintf(stderr, _("Usage: %s [-c|-t|-l filename] [-b block-size] "
> "[-f fragment-size]\n\t[-i bytes-per-inode] [-I inode-size] "
> - "[-j] [-J journal-options]\n"
> + "[-D descriptor-size] [-j] [-J journal-options]\n"
> "\t[-N number-of-inodes] [-m reserved-blocks-percentage] "
> "[-o creator-os]\n\t[-g blocks-per-group] [-L volume-label] "
> "[-M last-mounted-directory]\n\t[-O feature[,...]] "
> @@ -911,6 +911,7 @@ static void PRS(int argc, char *argv[])
> int blocksize = 0;
> int inode_ratio = 0;
> int inode_size = 0;
> + int desc_size = 0;
> double reserved_ratio = 5.0;
> int sector_size = 0;
> int show_version_only = 0;
> @@ -993,7 +994,7 @@ static void PRS(int argc, char *argv[])
> }
>
> while ((c = getopt (argc, argv,
> - "b:cf:g:i:jl:m:no:qr:s:tvE:FI:J:L:M:N:O:R:ST:V")) != EOF) {
> + "b:cf:g:i:jl:m:no:qr:s:tvD:E:FI:J:L:M:N:O:R:ST:V")) != EOF) {
> switch (c) {
> case 'b':
> blocksize = strtol(optarg, &tmp, 0);
> @@ -1110,6 +1111,14 @@ static void PRS(int argc, char *argv[])
> exit(1);
> }
> break;
> + case 'D':
> + desc_size = strtoul(optarg, &tmp, 0);
> + if (*tmp) {
> + com_err(program_name, 0,
> + _("invalid descriptor size - %s"), optarg);
> + exit(1);
> + }
> + break;
> case 'v':
> verbose = 1;
> break;
> @@ -1439,6 +1448,26 @@ static void PRS(int argc, char *argv[])
> }
> }
>
> + if (desc_size) {
> + if (desc_size < EXT2_MIN_DESC_SIZE ||
> + desc_size > EXT2_BLOCK_SIZE(&fs_param) ||
> + desc_size & (desc_size -1)) {
> + com_err(program_name, 0,
> + _("invalid descriptor size %d (min %d/max %d)"),
> + desc_size, EXT2_MIN_DESC_SIZE,
> + blocksize);
> + exit(1);
> + }
> + if (desc_size != EXT2_MIN_DESC_SIZE)
> + fprintf(stderr, _("Warning: %d-byte descriptors not "
> + "usable on older systems\n"),
> + desc_size);
> + fs_param.s_desc_size = desc_size;
> + if (desc_size > EXT2_MIN_DESC_SIZE)
> + fs_param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT;
> + }
> +
> +
> if (!force && fs_param.s_blocks_count >= ((unsigned) 1 << 31)) {
> com_err(program_name, 0,
> _("Filesystem too large. No more than 2**31-1 blocks\n"
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2007-08-30 20:51:22

by Andreas Dilger

[permalink] [raw]
Subject: Re: [PATCH 3/8][e2fsprogs] add new -D <desc-size> option to mkfs

On Aug 30, 2007 12:12 -0700, Mingming Cao wrote:
> On Thu, 2007-08-30 at 17:37 +0200, Valerie Clement wrote:
> > This patch adds a new option -D <descriptor-size> to mkfs to allow creating
> > ext4 filesystems with larger group descriptor size.
> >
> > By default, the group descriptor size is 32 bytes.
> > To support 64-bit physical block numbers and thus to be able to use filesystems
> > > 16TB, the group descriptor size must be increased to 64 bytes.
>
> Could you explain a bit more why we need this option? It seems to me we
> could make the block group descriptor size to 64bytes whenever creating
> a ext4 filesystem by default. Is there any case we need to create ext4
> with old 32 bytes block group descriptors?

Because we will only have a single tool "mke2fs", and it should be able
to format filesystems for all kernels. Also, it may be desirable to
make the descriptor larger for whatever reason (e.g. testing some new
feature).

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.

2007-09-01 00:24:47

by Mingming Cao

[permalink] [raw]
Subject: Re: [PATCH 3/8][e2fsprogs] add new -D <desc-size> option to mkfs

On Thu, 2007-08-30 at 14:51 -0600, Andreas Dilger wrote:
> On Aug 30, 2007 12:12 -0700, Mingming Cao wrote:
> > On Thu, 2007-08-30 at 17:37 +0200, Valerie Clement wrote:
> > > This patch adds a new option -D <descriptor-size> to mkfs to allow creating
> > > ext4 filesystems with larger group descriptor size.
> > >
> > > By default, the group descriptor size is 32 bytes.
> > > To support 64-bit physical block numbers and thus to be able to use filesystems
> > > > 16TB, the group descriptor size must be increased to 64 bytes.
> >
> > Could you explain a bit more why we need this option? It seems to me we
> > could make the block group descriptor size to 64bytes whenever creating
> > a ext4 filesystem by default. Is there any case we need to create ext4
> > with old 32 bytes block group descriptors?
>
> Because we will only have a single tool "mke2fs", and it should be able
> to format filesystems for all kernels.

I agree. I was wondering why not make the 64bytes block group descriptor
for ext4 as default. So by default we don't need to specify the size
when creating ext4 fs.

> Also, it may be desirable to
> make the descriptor larger for whatever reason (e.g. testing some new
> feature).
>
Okay, that could be useful for ext4. Don't feel ext2/3 needs that
option.

Regards,

Mingming

2007-09-04 06:29:00

by Andreas Dilger

[permalink] [raw]
Subject: Re: [PATCH 3/8][e2fsprogs] add new -D <desc-size> option to mkfs

On Aug 31, 2007 17:25 -0700, Mingming Cao wrote:
> On Thu, 2007-08-30 at 14:51 -0600, Andreas Dilger wrote:
> > we will only have a single tool "mke2fs", and it should be able
> > to format filesystems for all kernels.
>
> I agree. I was wondering why not make the 64bytes block group descriptor
> for ext4 as default. So by default we don't need to specify the size
> when creating ext4 fs.

Sure, this can be the default for ext4 (as with all the other ext4 features
like INCOMPAT_64BIT INCOMPAT_EXTENTS, UNINIT_GROUPS, etc).

> > Also, it may be desirable to make the descriptor larger for whatever
> > reason (e.g. testing some new feature).
> >
> Okay, that could be useful for ext4. Don't feel ext2/3 needs that option.

It can't hurt anything. At worst it means INCOMPAT_64BIT is enabled at
mke2fs time and the mount will immediately fail with ext2/ext3. Users
shouldn't mess with options they don't understand.

Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.

2007-10-14 20:30:36

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 0/8][e2fsprogs] 64-bit block number support - first part

Hi Valerie,

My apologies not having the time to review your patches until now.

On Thu, Aug 30, 2007 at 05:28:35PM +0200, Valerie Clement wrote:
> This is a series of 8 patches that prepares for the 64-bit block number support in e2fsprogs:

In general, could people please use a fill column of 72 when sending
e-mail messages, writing C code, and writing git commit logs? It
makes life easier for people who still use 80 column screens, and it
is the kernel standard. Thanks!

> - change a few variable types to blk_t type to support 64-bit block
> numbers in a next step,

It's good to clean this up, but this presumes that blk_t is going to
change to a 64-bit type. I'd much rather *add* a blk64_t, and keep
blk_t at 32 bits. This patch series in a number of places makes the
presumption that blk_t will change size --- in particular when it
creates new interfaces that returns 64-bits through a blk_t. Please
don't do that.

> - introduce helper functions, similar to those existing in the ext4 kernel code, to access 64-bit block counters split in two 32-bit words.

These are the ones....

- Ted

2007-10-14 22:53:31

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 1/8][e2fsprogs] use existing function ext2fs_group_first_block()

The subject line (i.e, the git one-line summary) was too generic; when
people look at the repository via gitk, "use existing function
ext2fs_group_first_block()" doesn't really give any context. I
replaced the description with the following and I accepted it into the
git tree.

libext2fs: use ext2fs_group_first_block() instead of open-coded equivalent

Use ext2fs_group_first_block() instead of the open-coded equivalent in
ext2fs_super_and_bgd_loc() and ext2fs_descriptor_block_loc().

Signed-off-by: Valerie Clement <[email protected]>
Signed-off-by: "Theodore Ts'o" <[email protected]>

- Ted

2007-10-15 01:03:06

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 2/8][e2fsprogs] convert block number definition to blk_t

On Thu, Aug 30, 2007 at 05:33:40PM +0200, Valerie Clement wrote:
>
> From: Valerie Clement <[email protected]>
>
> This patch converts a few __u32 or unsigned int block number definitions to
> blk_t type. Conversions are necessary to prepare the 64-bit porting.
>
> Signed-off-by: Valerie Clement <[email protected]>

Applied with the following description:

Use blk_t type instead of unsigned int or __u32

Signed-off-by: Valerie Clement <[email protected]>
Signed-off-by: "Theodore Ts'o" <[email protected]>

- Ted

2007-10-15 01:51:41

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 3/8][e2fsprogs] add new -D <desc-size> option to mkfs

On Thu, Aug 30, 2007 at 05:37:01PM +0200, Valerie Clement wrote:
>
> From: Valerie Clement <[email protected]>
>
> This patch adds a new option -D <descriptor-size> to mkfs to allow creating
> ext4 filesystems with larger group descriptor size.

The patch is missing a man page update.

In addition, the descriptor size is something that should be
configurable via mke2fs.conf, via the [defaults] and [fs_types]
stanza. (And don't forget to update the mke2fs.conf man page.)

- Ted

2007-10-15 02:09:40

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 4/8][e2fsprogs] add new macro to get descriptor number

On Thu, Aug 30, 2007 at 05:38:13PM +0200, Valerie Clement wrote:
>
> From: Valerie Clement <[email protected]>
>
> This patch introduces a new macro EXT2_DESC_PER_BLOCK to calculate the number
> of group descriptors per block as two different structures are now defined,
> ext4_group_desc structure for ext4 filesystems and ext2_group_desc structure
> for older filesystems.
>
> Signed-off-by: Valerie Clement <[email protected]>

Applied with minor changes take into account that I haven't applied
patch 3/8 yet.

- Ted

2007-10-17 14:14:12

by Valerie Clement

[permalink] [raw]
Subject: Re: [PATCH 0/8][e2fsprogs] 64-bit block number support - first part

Theodore Tso wrote:
> It's good to clean this up, but this presumes that blk_t is going to
> change to a 64-bit type. I'd much rather *add* a blk64_t, and keep
> blk_t at 32 bits. This patch series in a number of places makes the
> presumption that blk_t will change size --- in particular when it
> creates new interfaces that returns 64-bits through a blk_t. Please
> don't do that.

Does it mean that we'll have to duplicate all of the structures
containing fields of type blk_t (like process_block_struct,
e2fsck_struct, ext2_inode_cache, ...) and also duplicate most of
the code for the functions which use variables of type blk_t?

Val?rie

2007-10-17 14:53:31

by Ted Ts'o

[permalink] [raw]
Subject: Re: [PATCH 0/8][e2fsprogs] 64-bit block number support - first part

On Wed, Oct 17, 2007 at 04:13:50PM +0200, Valerie Clement wrote:
> Theodore Tso wrote:
>> It's good to clean this up, but this presumes that blk_t is going to
>> change to a 64-bit type. I'd much rather *add* a blk64_t, and keep
>> blk_t at 32 bits. This patch series in a number of places makes the
>> presumption that blk_t will change size --- in particular when it
>> creates new interfaces that returns 64-bits through a blk_t. Please
>> don't do that.
>
> Does it mean that we'll have to duplicate all of the structures
> containing fields of type blk_t (like process_block_struct,
> e2fsck_struct, ext2_inode_cache, ...) and also duplicate most of
> the code for the functions which use variables of type blk_t?

process_block_struct and e2fsck_struct are e2fsck specific structures,
so they don't have to be duplicated; the concern is libext2fs ABI
compatibility.

As far as ext2_inode_cache, you will note that the structure is
defined in ext2fsP.h, so it's not visible to outside callers. The
ext2fsP.h file was created specifically to allow internal
implementation changes without breaking the ABI, because structures in
ext2fsP.h aren't part of the published interface.

If there are functions where we can show that none of the users of
libext2fs library are calling it, by surveying all known apps that
link against libext2fs (both in e2fsprogs and external to e2fsprogs),
then there is another alternative. If we know that it's most likely
only being used as an internal helper functions by libext2fs, and the
only reason it wasn't declared static was because it was being used
from another .c file, we could use a linker script to hide the
internal functions using ELF symbol versions, so that applications
would never see those functions. It won't work for the static
library, so it's not full proof, but if we at the same time use a
function prefix like ext2fs__ with two underscores, it'll probably be
good enough. This would be the equivalent of removing a function from
the library (as far as outside callers are concerned), so we would
have to do our own due diligence before we could proceed, but it would
be possible.

- Ted