Message ID | 20230526061129.2999437-2-chao@kernel.org (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [f2fs-dev,1/2] f2fs-tools: fix to le32 type variable correctly | expand |
On 05/26, Chao Yu wrote: > Signed-off-by: Chao Yu <chao@kernel.org> > --- > fsck/mount.c | 56 +++++++++++++---------------------------------- > include/f2fs_fs.h | 42 +++++++++++++++++++++-------------- > 2 files changed, 41 insertions(+), 57 deletions(-) > > diff --git a/fsck/mount.c b/fsck/mount.c > index 70e8b46..60ad493 100644 > --- a/fsck/mount.c > +++ b/fsck/mount.c > @@ -599,54 +599,28 @@ void print_cp_state(u32 flag) > MSG(0, "\n"); > } > > +extern struct feature feature_table[]; > void print_sb_state(struct f2fs_super_block *sb) > { > unsigned int f = get_sb(feature); > + char *name; > int i; > > MSG(0, "Info: superblock features = %x : ", f); > - if (f & F2FS_FEATURE_ENCRYPT) { > - MSG(0, "%s", " encrypt"); > - } > - if (f & F2FS_FEATURE_VERITY) { > - MSG(0, "%s", " verity"); > - } > - if (f & F2FS_FEATURE_BLKZONED) { > - MSG(0, "%s", " blkzoned"); > - } > - if (f & F2FS_FEATURE_EXTRA_ATTR) { > - MSG(0, "%s", " extra_attr"); > - } > - if (f & F2FS_FEATURE_PRJQUOTA) { > - MSG(0, "%s", " project_quota"); > - } > - if (f & F2FS_FEATURE_INODE_CHKSUM) { > - MSG(0, "%s", " inode_checksum"); > - } > - if (f & F2FS_FEATURE_FLEXIBLE_INLINE_XATTR) { > - MSG(0, "%s", " flexible_inline_xattr"); > - } > - if (f & F2FS_FEATURE_QUOTA_INO) { > - MSG(0, "%s", " quota_ino"); > - } > - if (f & F2FS_FEATURE_INODE_CRTIME) { > - MSG(0, "%s", " inode_crtime"); > - } > - if (f & F2FS_FEATURE_LOST_FOUND) { > - MSG(0, "%s", " lost_found"); > - } > - if (f & F2FS_FEATURE_SB_CHKSUM) { > - MSG(0, "%s", " sb_checksum"); > - } > - if (f & F2FS_FEATURE_CASEFOLD) { > - MSG(0, "%s", " casefold"); > - } > - if (f & F2FS_FEATURE_COMPRESSION) { > - MSG(0, "%s", " compression"); > - } > - if (f & F2FS_FEATURE_RO) { > - MSG(0, "%s", " ro"); > + > + for (i = 0; i < 32; i++) { Need to add a definition for 32? > + unsigned int bit = 1 << i; > + > + if (!(f & bit)) > + continue; > + > + name = feature_name(feature_table, bit); > + if (!name) > + continue; > + > + MSG(0, " %s", name); > } > + > MSG(0, "\n"); > MSG(0, "Info: superblock encrypt level = %d, salt = ", > sb->encryption_level); > diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h > index 9d35b42..a97c974 100644 > --- a/include/f2fs_fs.h > +++ b/include/f2fs_fs.h > @@ -1811,35 +1811,45 @@ static inline void f2fs_init_inode(struct f2fs_super_block *sb, > > struct feature { > char *name; > - u32 mask; > + u32 mask; > + u32 settable; > }; > > #define INIT_FEATURE_TABLE \ > struct feature feature_table[] = { \ > - { "encrypt", F2FS_FEATURE_ENCRYPT }, \ > - { "extra_attr", F2FS_FEATURE_EXTRA_ATTR }, \ > - { "project_quota", F2FS_FEATURE_PRJQUOTA }, \ > - { "inode_checksum", F2FS_FEATURE_INODE_CHKSUM }, \ > - { "flexible_inline_xattr", F2FS_FEATURE_FLEXIBLE_INLINE_XATTR },\ > - { "quota", F2FS_FEATURE_QUOTA_INO }, \ > - { "inode_crtime", F2FS_FEATURE_INODE_CRTIME }, \ > - { "lost_found", F2FS_FEATURE_LOST_FOUND }, \ > - { "verity", F2FS_FEATURE_VERITY }, /* reserved */ \ > - { "sb_checksum", F2FS_FEATURE_SB_CHKSUM }, \ > - { "casefold", F2FS_FEATURE_CASEFOLD }, \ > - { "compression", F2FS_FEATURE_COMPRESSION }, \ > - { "ro", F2FS_FEATURE_RO}, \ > - { NULL, 0x0}, \ > + { "encrypt", F2FS_FEATURE_ENCRYPT, 1}, \ > + { "blkzoned", F2FS_FEATURE_BLKZONED, 0}, \ > + { "extra_attr", F2FS_FEATURE_EXTRA_ATTR, 1}, \ > + { "project_quota", F2FS_FEATURE_PRJQUOTA, 1}, \ > + { "inode_checksum", F2FS_FEATURE_INODE_CHKSUM, 1}, \ > + { "flexible_inline_xattr", F2FS_FEATURE_FLEXIBLE_INLINE_XATTR,1}, \ > + { "quota", F2FS_FEATURE_QUOTA_INO, 1}, \ > + { "inode_crtime", F2FS_FEATURE_INODE_CRTIME, 1}, \ > + { "lost_found", F2FS_FEATURE_LOST_FOUND, 1}, \ > + { "verity", F2FS_FEATURE_VERITY, 1}, \ > + { "sb_checksum", F2FS_FEATURE_SB_CHKSUM, 1}, \ > + { "casefold", F2FS_FEATURE_CASEFOLD, 1}, \ > + { "compression", F2FS_FEATURE_COMPRESSION, 1}, \ > + { "ro", F2FS_FEATURE_RO, 1}, \ > + { NULL, 0x0, 0}, \ > }; > > static inline u32 feature_map(struct feature *table, char *feature) > { > struct feature *p; > - for (p = table; p->name && strcmp(p->name, feature); p++) > + for (p = table; p->name && p->settable && strcmp(p->name, feature); p++) > ; > return p->mask; > } > > +static inline char *feature_name(struct feature *table, u32 mask) > +{ > + struct feature *p; > + for (p = table; p->name && p->mask != mask; p++) > + ; > + return p->name; > +} > + > static inline int set_feature_bits(struct feature *table, char *features) > { > u32 mask = feature_map(table, features); > -- > 2.40.1
On 2023/5/27 0:25, Jaegeuk Kim wrote: > On 05/26, Chao Yu wrote: >> Signed-off-by: Chao Yu <chao@kernel.org> >> --- >> fsck/mount.c | 56 +++++++++++++---------------------------------- >> include/f2fs_fs.h | 42 +++++++++++++++++++++-------------- >> 2 files changed, 41 insertions(+), 57 deletions(-) >> >> diff --git a/fsck/mount.c b/fsck/mount.c >> index 70e8b46..60ad493 100644 >> --- a/fsck/mount.c >> +++ b/fsck/mount.c >> @@ -599,54 +599,28 @@ void print_cp_state(u32 flag) >> MSG(0, "\n"); >> } >> >> +extern struct feature feature_table[]; >> void print_sb_state(struct f2fs_super_block *sb) >> { >> unsigned int f = get_sb(feature); >> + char *name; >> int i; >> >> MSG(0, "Info: superblock features = %x : ", f); >> - if (f & F2FS_FEATURE_ENCRYPT) { >> - MSG(0, "%s", " encrypt"); >> - } >> - if (f & F2FS_FEATURE_VERITY) { >> - MSG(0, "%s", " verity"); >> - } >> - if (f & F2FS_FEATURE_BLKZONED) { >> - MSG(0, "%s", " blkzoned"); >> - } >> - if (f & F2FS_FEATURE_EXTRA_ATTR) { >> - MSG(0, "%s", " extra_attr"); >> - } >> - if (f & F2FS_FEATURE_PRJQUOTA) { >> - MSG(0, "%s", " project_quota"); >> - } >> - if (f & F2FS_FEATURE_INODE_CHKSUM) { >> - MSG(0, "%s", " inode_checksum"); >> - } >> - if (f & F2FS_FEATURE_FLEXIBLE_INLINE_XATTR) { >> - MSG(0, "%s", " flexible_inline_xattr"); >> - } >> - if (f & F2FS_FEATURE_QUOTA_INO) { >> - MSG(0, "%s", " quota_ino"); >> - } >> - if (f & F2FS_FEATURE_INODE_CRTIME) { >> - MSG(0, "%s", " inode_crtime"); >> - } >> - if (f & F2FS_FEATURE_LOST_FOUND) { >> - MSG(0, "%s", " lost_found"); >> - } >> - if (f & F2FS_FEATURE_SB_CHKSUM) { >> - MSG(0, "%s", " sb_checksum"); >> - } >> - if (f & F2FS_FEATURE_CASEFOLD) { >> - MSG(0, "%s", " casefold"); >> - } >> - if (f & F2FS_FEATURE_COMPRESSION) { >> - MSG(0, "%s", " compression"); >> - } >> - if (f & F2FS_FEATURE_RO) { >> - MSG(0, "%s", " ro"); >> + >> + for (i = 0; i < 32; i++) { > > Need to add a definition for 32? Agree and fixed. Thanks, > >> + unsigned int bit = 1 << i; >> + >> + if (!(f & bit)) >> + continue; >> + >> + name = feature_name(feature_table, bit); >> + if (!name) >> + continue; >> + >> + MSG(0, " %s", name); >> } >> + >> MSG(0, "\n"); >> MSG(0, "Info: superblock encrypt level = %d, salt = ", >> sb->encryption_level); >> diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h >> index 9d35b42..a97c974 100644 >> --- a/include/f2fs_fs.h >> +++ b/include/f2fs_fs.h >> @@ -1811,35 +1811,45 @@ static inline void f2fs_init_inode(struct f2fs_super_block *sb, >> >> struct feature { >> char *name; >> - u32 mask; >> + u32 mask; >> + u32 settable; >> }; >> >> #define INIT_FEATURE_TABLE \ >> struct feature feature_table[] = { \ >> - { "encrypt", F2FS_FEATURE_ENCRYPT }, \ >> - { "extra_attr", F2FS_FEATURE_EXTRA_ATTR }, \ >> - { "project_quota", F2FS_FEATURE_PRJQUOTA }, \ >> - { "inode_checksum", F2FS_FEATURE_INODE_CHKSUM }, \ >> - { "flexible_inline_xattr", F2FS_FEATURE_FLEXIBLE_INLINE_XATTR },\ >> - { "quota", F2FS_FEATURE_QUOTA_INO }, \ >> - { "inode_crtime", F2FS_FEATURE_INODE_CRTIME }, \ >> - { "lost_found", F2FS_FEATURE_LOST_FOUND }, \ >> - { "verity", F2FS_FEATURE_VERITY }, /* reserved */ \ >> - { "sb_checksum", F2FS_FEATURE_SB_CHKSUM }, \ >> - { "casefold", F2FS_FEATURE_CASEFOLD }, \ >> - { "compression", F2FS_FEATURE_COMPRESSION }, \ >> - { "ro", F2FS_FEATURE_RO}, \ >> - { NULL, 0x0}, \ >> + { "encrypt", F2FS_FEATURE_ENCRYPT, 1}, \ >> + { "blkzoned", F2FS_FEATURE_BLKZONED, 0}, \ >> + { "extra_attr", F2FS_FEATURE_EXTRA_ATTR, 1}, \ >> + { "project_quota", F2FS_FEATURE_PRJQUOTA, 1}, \ >> + { "inode_checksum", F2FS_FEATURE_INODE_CHKSUM, 1}, \ >> + { "flexible_inline_xattr", F2FS_FEATURE_FLEXIBLE_INLINE_XATTR,1}, \ >> + { "quota", F2FS_FEATURE_QUOTA_INO, 1}, \ >> + { "inode_crtime", F2FS_FEATURE_INODE_CRTIME, 1}, \ >> + { "lost_found", F2FS_FEATURE_LOST_FOUND, 1}, \ >> + { "verity", F2FS_FEATURE_VERITY, 1}, \ >> + { "sb_checksum", F2FS_FEATURE_SB_CHKSUM, 1}, \ >> + { "casefold", F2FS_FEATURE_CASEFOLD, 1}, \ >> + { "compression", F2FS_FEATURE_COMPRESSION, 1}, \ >> + { "ro", F2FS_FEATURE_RO, 1}, \ >> + { NULL, 0x0, 0}, \ >> }; >> >> static inline u32 feature_map(struct feature *table, char *feature) >> { >> struct feature *p; >> - for (p = table; p->name && strcmp(p->name, feature); p++) >> + for (p = table; p->name && p->settable && strcmp(p->name, feature); p++) >> ; >> return p->mask; >> } >> >> +static inline char *feature_name(struct feature *table, u32 mask) >> +{ >> + struct feature *p; >> + for (p = table; p->name && p->mask != mask; p++) >> + ; >> + return p->name; >> +} >> + >> static inline int set_feature_bits(struct feature *table, char *features) >> { >> u32 mask = feature_map(table, features); >> -- >> 2.40.1
diff --git a/fsck/mount.c b/fsck/mount.c index 70e8b46..60ad493 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -599,54 +599,28 @@ void print_cp_state(u32 flag) MSG(0, "\n"); } +extern struct feature feature_table[]; void print_sb_state(struct f2fs_super_block *sb) { unsigned int f = get_sb(feature); + char *name; int i; MSG(0, "Info: superblock features = %x : ", f); - if (f & F2FS_FEATURE_ENCRYPT) { - MSG(0, "%s", " encrypt"); - } - if (f & F2FS_FEATURE_VERITY) { - MSG(0, "%s", " verity"); - } - if (f & F2FS_FEATURE_BLKZONED) { - MSG(0, "%s", " blkzoned"); - } - if (f & F2FS_FEATURE_EXTRA_ATTR) { - MSG(0, "%s", " extra_attr"); - } - if (f & F2FS_FEATURE_PRJQUOTA) { - MSG(0, "%s", " project_quota"); - } - if (f & F2FS_FEATURE_INODE_CHKSUM) { - MSG(0, "%s", " inode_checksum"); - } - if (f & F2FS_FEATURE_FLEXIBLE_INLINE_XATTR) { - MSG(0, "%s", " flexible_inline_xattr"); - } - if (f & F2FS_FEATURE_QUOTA_INO) { - MSG(0, "%s", " quota_ino"); - } - if (f & F2FS_FEATURE_INODE_CRTIME) { - MSG(0, "%s", " inode_crtime"); - } - if (f & F2FS_FEATURE_LOST_FOUND) { - MSG(0, "%s", " lost_found"); - } - if (f & F2FS_FEATURE_SB_CHKSUM) { - MSG(0, "%s", " sb_checksum"); - } - if (f & F2FS_FEATURE_CASEFOLD) { - MSG(0, "%s", " casefold"); - } - if (f & F2FS_FEATURE_COMPRESSION) { - MSG(0, "%s", " compression"); - } - if (f & F2FS_FEATURE_RO) { - MSG(0, "%s", " ro"); + + for (i = 0; i < 32; i++) { + unsigned int bit = 1 << i; + + if (!(f & bit)) + continue; + + name = feature_name(feature_table, bit); + if (!name) + continue; + + MSG(0, " %s", name); } + MSG(0, "\n"); MSG(0, "Info: superblock encrypt level = %d, salt = ", sb->encryption_level); diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 9d35b42..a97c974 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1811,35 +1811,45 @@ static inline void f2fs_init_inode(struct f2fs_super_block *sb, struct feature { char *name; - u32 mask; + u32 mask; + u32 settable; }; #define INIT_FEATURE_TABLE \ struct feature feature_table[] = { \ - { "encrypt", F2FS_FEATURE_ENCRYPT }, \ - { "extra_attr", F2FS_FEATURE_EXTRA_ATTR }, \ - { "project_quota", F2FS_FEATURE_PRJQUOTA }, \ - { "inode_checksum", F2FS_FEATURE_INODE_CHKSUM }, \ - { "flexible_inline_xattr", F2FS_FEATURE_FLEXIBLE_INLINE_XATTR },\ - { "quota", F2FS_FEATURE_QUOTA_INO }, \ - { "inode_crtime", F2FS_FEATURE_INODE_CRTIME }, \ - { "lost_found", F2FS_FEATURE_LOST_FOUND }, \ - { "verity", F2FS_FEATURE_VERITY }, /* reserved */ \ - { "sb_checksum", F2FS_FEATURE_SB_CHKSUM }, \ - { "casefold", F2FS_FEATURE_CASEFOLD }, \ - { "compression", F2FS_FEATURE_COMPRESSION }, \ - { "ro", F2FS_FEATURE_RO}, \ - { NULL, 0x0}, \ + { "encrypt", F2FS_FEATURE_ENCRYPT, 1}, \ + { "blkzoned", F2FS_FEATURE_BLKZONED, 0}, \ + { "extra_attr", F2FS_FEATURE_EXTRA_ATTR, 1}, \ + { "project_quota", F2FS_FEATURE_PRJQUOTA, 1}, \ + { "inode_checksum", F2FS_FEATURE_INODE_CHKSUM, 1}, \ + { "flexible_inline_xattr", F2FS_FEATURE_FLEXIBLE_INLINE_XATTR,1}, \ + { "quota", F2FS_FEATURE_QUOTA_INO, 1}, \ + { "inode_crtime", F2FS_FEATURE_INODE_CRTIME, 1}, \ + { "lost_found", F2FS_FEATURE_LOST_FOUND, 1}, \ + { "verity", F2FS_FEATURE_VERITY, 1}, \ + { "sb_checksum", F2FS_FEATURE_SB_CHKSUM, 1}, \ + { "casefold", F2FS_FEATURE_CASEFOLD, 1}, \ + { "compression", F2FS_FEATURE_COMPRESSION, 1}, \ + { "ro", F2FS_FEATURE_RO, 1}, \ + { NULL, 0x0, 0}, \ }; static inline u32 feature_map(struct feature *table, char *feature) { struct feature *p; - for (p = table; p->name && strcmp(p->name, feature); p++) + for (p = table; p->name && p->settable && strcmp(p->name, feature); p++) ; return p->mask; } +static inline char *feature_name(struct feature *table, u32 mask) +{ + struct feature *p; + for (p = table; p->name && p->mask != mask; p++) + ; + return p->name; +} + static inline int set_feature_bits(struct feature *table, char *features) { u32 mask = feature_map(table, features);
Signed-off-by: Chao Yu <chao@kernel.org> --- fsck/mount.c | 56 +++++++++++++---------------------------------- include/f2fs_fs.h | 42 +++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 57 deletions(-)