reuse feature_table in print_sb_state() for cleanup.

Signed-off-by: Chao Yu <c...@kernel.org>
---
v3:
- fix a bug in feature_map()
 fsck/mount.c      | 56 +++++++++++++----------------------------------
 include/f2fs_fs.h | 52 +++++++++++++++++++++++++++++--------------
 2 files changed, 50 insertions(+), 58 deletions(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index ea38b14..18c5e2b 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..229b2aa 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1811,35 +1811,53 @@ 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++) {
+               if (!p->settable)
+                       continue;
+               if (strcmp(p->name, feature))
+                       continue;
+               break;
+       }
        return p->mask;
 }
 
+static inline char *feature_name(struct feature *table, u32 mask)
+{
+       struct feature *p;
+       for (p = table; p->name; p++) {
+               if (p->mask != mask)
+                       continue;
+               break;
+       }
+       return p->name;
+}
+
 static inline int set_feature_bits(struct feature *table, char *features)
 {
        u32 mask = feature_map(table, features);
-- 
2.40.1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

Reply via email to