new ext4 group desc struct in e2fsprogs
RFC PATCH 1/12 new ext4 group desc struct in e2fsprogs
A different groups descriptor structure was introduced for ext4 filesystems. This patch handles that.
debugfs/debugfs.c | 9 +++++++++ debugfs/set_fields.c | 4 ++++ e2fsck/super.c | 4 ++++ lib/ext2fs/closefs.c | 5 +++++ lib/ext2fs/ext2fs.h | 8 ++++++++ lib/ext2fs/openfs.c | 7 ++++++- lib/ext2fs/swapfs.c | 4 ++++ misc/mke2fs.c | 4 ++++ resize/resize2fs.c | 2 +- 9 files changed, 45 insertions(+), 2 deletions(-)
lib/ext2fs/ext2fs.h +8 -0
@@ -213,7 +213,11 @@ struct struct_ext2_filsys {int fragsize;dgrp_t group_desc_count;unsigned long desc_blocks; +#ifdef _EXT4FS_ +struct ext4_group_desc * group_desc; +#else struct ext2_group_desc * group_desc; +#endif int inode_blocks_per_group;ext2fs_inode_bitmap inode_map;ext2fs_block_bitmap block_map;
@@ -1003,7 +1007,11 @@ extern errcode_t ext2fs_copy_bitmap(ext2extern void ext2fs_swap_ext_attr (char *to,char *from,int bufsize,int has_header);extern void ext2fs_swap_super (struct ext2_super_block * super); +#ifdef _EXT4FS_ +extern void ext2fs_swap_group_desc (struct ext4_group_desc *gdp); +#else extern void ext2fs_swap_group_desc (struct ext2_group_desc *gdp); +#endif extern void ext2fs_swap_extent_header (struct ext3_extent_header *eh);extern void ext2fs_swap_extent_index (struct ext3_extent_idx *ix);extern void ext2fs_swap_extent (struct ext3_extent *ex);
debugfs/set_fields.c +4 -0
@@ -31,7 +31,11 @@static struct ext2_super_block set_sb;static struct ext2_inode set_inode; +#ifdef _EXT4FS_ +static struct ext4_group_desc set_gd; +#else static struct ext2_group_desc set_gd; +#endif static ext2_ino_t set_ino;static int array_idx;
resize/resize2fs.c +1 -1
@@ -365,7 +365,7 @@ retry:for (i = old_fs->group_desc_count; i < fs->group_desc_count; i++) {memset (&fs->group_desc[i],0 , -sizeof (struct ext2_group_desc )); +sizeof (fs->group_desc[0 ])); adjblocks =0 ;if (i == fs->group_desc_count-1 ) {
misc/mke2fs.c +4 -0
@@ -449,7 +449,11 @@ static void setup_lazy_bg(ext2_filsys fsdgrp_t i;int blks;struct ext2_super_block *sb = fs->super; +#ifdef _EXT4FS_ +struct ext4_group_desc *bg = fs->group_desc; +#else struct ext2_group_desc *bg = fs->group_desc; +#endif if (EXT2_HAS_COMPAT_FEATURE (fs->super,EXT2_FEATURE_COMPAT_LAZY_BG )) {
debugfs/debugfs.c +9 -0
@@ -267,8 +267,13 @@ static void print_features(struct ext2_sfputs ("\n" , f); } +#ifdef _EXT4FS_ +static void print_bg_opts (struct ext4_group_desc *gdp,int mask, + const char *str, int *first, FILE *f) +#else static void print_bg_opts (struct ext2_group_desc *gdp,int mask, const char *str, int *first, FILE *f) +#endif {if (gdp->bg_flags & mask) {if (*first) {
@@ -284,7 +289,11 @@ void do_show_super_stats(int argc, char {dgrp_t i;FILE *out; +#ifdef _EXT4FS_ +struct ext4_group_desc *gdp; +#else struct ext2_group_desc *gdp; +#endif int c, header_only =0 ;int numdirs =0 , first;
e2fsck/super.c +4 -0
@@ -470,7 +470,11 @@ void check_super_block(e2fsck_t ctx)ext2_filsys fs = ctx->fs;blk_t first_block, last_block;struct ext2_super_block *sb = fs->super; +#ifdef _EXT4FS_ +struct ext4_group_desc *gd; +#else struct ext2_group_desc *gd; +#endif blk_t blocks_per_group = fs->super->s_blocks_per_group;blk_t bpg_max;int inodes_per_block;
lib/ext2fs/swapfs.c +4 -0
@@ -77,7 +77,11 @@ void ext2fs_swap_super(struct ext2_super } +#ifdef _EXT4FS_ +void ext2fs_swap_group_desc(struct ext4_group_desc *gdp) +#else void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) +#endif { gdp->bg_block_bitmap =ext2fs_swab32 (gdp->bg_block_bitmap); gdp->bg_inode_bitmap =ext2fs_swab32 (gdp->bg_inode_bitmap);
lib/ext2fs/openfs.c +6 -1
@@ -90,7 +90,6 @@ errcode_t ext2fs_open2(const char *name,int j, groups_per_block, blocks_per_group, io_flags;blk_t group_block, blk;char *dest, *cp; -struct ext2_group_desc *gdp;EXT2_CHECK_MAGIC (manager,EXT2_ET_MAGIC_IO_MANAGER );
@@ -289,7 +288,13 @@ errcode_t ext2fs_open2(const char *name, goto cleanup;#ifdef EXT2FS_ENABLE_SWAPFS if (fs->flags &EXT2_FLAG_SWAP_BYTES ) { +#ifdef _EXT4FS_ +struct ext4_group_desc *gdp; + gdp = (struct ext4_group_desc *) dest; +#else +struct ext2_group_desc *gdp; gdp = (struct ext2_group_desc *) dest; +#endif for (j=0 ; j < groups_per_block; j++)ext2fs_swap_group_desc (gdp++); }
lib/ext2fs/closefs.c +5 -0
@@ -209,8 +209,13 @@ errcode_t ext2fs_flush(ext2_filsys fs)errcode_t retval;unsigned long fs_state;struct ext2_super_block *super_shadow =0 ; +#ifdef _EXT4FS_ +struct ext4_group_desc *group_shadow =0 ; +struct ext4_group_desc *s, *t; +#else struct ext2_group_desc *group_shadow =0 ;struct ext2_group_desc *s, *t; +#endif char *group_ptr;int old_desc_blocks;
lib/ext2fs/ext2fs.h struct struct_ext2_filsys { · line 220
Quoted 9 lines · Valerie Clement
lib/ext2fs/ext2fs.h +4
-0@@ -213,7 +213,11 @@ struct struct_ext2_filsys {int fragsize;dgrp_t group_desc_count;unsigned long desc_blocks; +#ifdef _EXT4FS_ +struct ext4_group_desc * group_desc; +#else struct ext2_group_desc * group_desc; +#endif
The way similar changes were incorporated into e2fsprogs in the past (e.g. large inode support) is to pass an ext2_group_desc around and in places where access to the "large" part of the struct are needed this is typecast and conditional upon the appropriate superblock field or feature, as it is in the kernel. This also avoids the need to change the parameter everywhere.
This is important because even "ext4" filesystems may only have 32-byte group descriptors if they are formatted as ext3 and upgraded.
For large inodes, this is using "s_inode_size", and for the group descriptor it should use "s_desc_size" and INCOMPAT_64BIT.
lib/ext2fs/swapfs.c void ext2fs_swap_super(struct ext2_super · line 87
Quoted 10 lines
lib/ext2fs/swapfs.c +4
-0+#ifdef _EXT4FS_ +void ext2fs_swap_group_desc(struct ext4_group_desc *gdp) +#else void ext2fs_swap_group_desc(struct ext2_group_desc *gdp) +#endif { gdp->bg_block_bitmap =ext2fs_swab32 (gdp->bg_block_bitmap); gdp->bg_inode_bitmap =ext2fs_swab32 (gdp->bg_inode_bitmap);
This does not swap the new fields in the group descriptor. Swabbing the ext4_group_desc fields should also be conditional upon INCOMPAT_64BIT and s_desc_size > sizeof(struct ext2_group_desc).
Cheers, Andreas
--
Andreas Dilger
Principal Software Engineer
Cluster File Systems, Inc.
Quoted 18 lines · Andreas Dilger
lib/ext2fs/ext2fs.h struct struct_ext2_filsys { · line 220
Quoted 9 lines · Valerie Clement
lib/ext2fs/ext2fs.h +4
-0@@ -213,7 +213,11 @@ struct struct_ext2_filsys {int fragsize;dgrp_t group_desc_count;unsigned long desc_blocks; +#ifdef _EXT4FS_ +struct ext4_group_desc * group_desc; +#else struct ext2_group_desc * group_desc; +#endif The way similar changes were incorporated into e2fsprogs in the past (e.g. large inode support) is to pass an
ext2_group_descaround and in places where access to the "large" part of the struct are needed this is typecast and conditional upon the appropriate superblock field or feature, as it is in the kernel. This also avoids the need to change the parameter everywhere.
Quoted 6 lines
This is important because even "ext4" filesystems may only have 32-byte group descriptors if they are formatted as ext3 and upgraded.
For large inodes, this is using "
s_inode_size", and for the group descriptor it should use "s_desc_size" andINCOMPAT_64BIT.
Yes, I see the problem. I'll make the changes in this way. Thanks,
Valérie