Skip to content

Commit

Permalink
f2fs-tools: reuse feature_table to clean up print_sb_state()
Browse files Browse the repository at this point in the history
reuse feature_table in print_sb_state() for cleanup.

Signed-off-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
chaseyu authored and Jaegeuk Kim committed May 30, 2023
1 parent 4c1fd35 commit 92cc5ed
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 58 deletions.
56 changes: 15 additions & 41 deletions fsck/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 < MAX_NR_FEATURE; 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);
Expand Down
54 changes: 37 additions & 17 deletions include/f2fs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ enum {
#define F2FS_FEATURE_COMPRESSION 0x2000
#define F2FS_FEATURE_RO 0x4000

#define MAX_NR_FEATURE 32

#define MAX_VOLUME_NAME 512

/*
Expand Down Expand Up @@ -1811,35 +1813,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);
Expand Down

0 comments on commit 92cc5ed

Please sign in to comment.