fsck.f2fs: add "-l" to show the layout information
authorJaegeuk Kim <jaegeuk@kernel.org>
Sun, 23 May 2021 21:23:06 +0000 (14:23 -0700)
committerJaegeuk Kim <jaegeuk@kernel.org>
Wed, 26 May 2021 14:43:28 +0000 (07:43 -0700)
This patch add an option to print out superblock and checkpoint only.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/main.c
fsck/mount.c
include/f2fs_fs.h

index f42ab0c..904b09c 100644 (file)
@@ -71,6 +71,7 @@ void fsck_usage()
        MSG(0, "  -d debug level [default:0]\n");
        MSG(0, "  -f check/fix entire partition\n");
        MSG(0, "  -g add default options\n");
+       MSG(0, "  -l show superblock/checkpoint\n");
        MSG(0, "  -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
        MSG(0, "  -p preen mode [default:0 the same as -a [0|1]]\n");
        MSG(0, "  -S sparse_mode\n");
@@ -226,7 +227,7 @@ void f2fs_parse_options(int argc, char *argv[])
        }
 
        if (!strcmp("fsck.f2fs", prog)) {
-               const char *option_string = ":aC:c:m:d:fg:O:p:q:StyV";
+               const char *option_string = ":aC:c:m:d:fg:lO:p:q:StyV";
                int opt = 0, val;
                char *token;
                struct option long_opt[] = {
@@ -273,6 +274,9 @@ void f2fs_parse_options(int argc, char *argv[])
                                if (!strcmp(optarg, "android"))
                                        c.defset = CONF_ANDROID;
                                break;
+                       case 'l':
+                               c.layout = 1;
+                               break;
                        case 'O':
                                if (parse_feature(feature_table, optarg))
                                        fsck_usage();
index cc140a3..f7763c9 100644 (file)
@@ -369,11 +369,16 @@ static void DISP_label(u_int16_t *name)
        char buffer[MAX_VOLUME_NAME];
 
        utf16_to_utf8(buffer, name, MAX_VOLUME_NAME, MAX_VOLUME_NAME);
-       printf("%-30s" "\t\t[%s]\n", "volum_name", buffer);
+       if (c.layout)
+               printf("%-30s %s\n", "Filesystem volume name:", buffer);
+       else
+               printf("%-30s" "\t\t[%s]\n", "volum_name", buffer);
 }
 
 void print_raw_sb_info(struct f2fs_super_block *sb)
 {
+       if (c.layout)
+               goto printout;
        if (!c.dbg_lv)
                return;
 
@@ -381,7 +386,7 @@ void print_raw_sb_info(struct f2fs_super_block *sb)
        printf("+--------------------------------------------------------+\n");
        printf("| Super block                                            |\n");
        printf("+--------------------------------------------------------+\n");
-
+printout:
        DISP_u32(sb, magic);
        DISP_u32(sb, major_ver);
 
@@ -427,6 +432,8 @@ void print_ckpt_info(struct f2fs_sb_info *sbi)
 {
        struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
 
+       if (c.layout)
+               goto printout;
        if (!c.dbg_lv)
                return;
 
@@ -434,7 +441,7 @@ void print_ckpt_info(struct f2fs_sb_info *sbi)
        printf("+--------------------------------------------------------+\n");
        printf("| Checkpoint                                             |\n");
        printf("+--------------------------------------------------------+\n");
-
+printout:
        DISP_u64(cp, checkpoint_ver);
        DISP_u64(cp, user_block_count);
        DISP_u64(cp, valid_block_count);
@@ -3535,6 +3542,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
                if (get_cp(ckpt_flags) & CP_QUOTA_NEED_FSCK_FLAG)
                        c.fix_on = 1;
        }
+       if (c.layout)
+               return 1;
 
        if (tune_sb_features(sbi))
                return -1;
index 5d49ed1..66547a3 100644 (file)
@@ -240,14 +240,14 @@ static inline uint64_t bswap_64(uint64_t val)
 
 #define MSG(n, fmt, ...)                                               \
        do {                                                            \
-               if (c.dbg_lv >= n) {                                    \
+               if (c.dbg_lv >= n && !c.layout) {                       \
                        printf(fmt, ##__VA_ARGS__);                     \
                }                                                       \
        } while (0)
 
 #define DBG(n, fmt, ...)                                               \
        do {                                                            \
-               if (c.dbg_lv >= n) {                                    \
+               if (c.dbg_lv >= n && !c.layout) {                       \
                        printf("[%s:%4d] " fmt,                         \
                                __func__, __LINE__, ##__VA_ARGS__);     \
                }                                                       \
@@ -262,7 +262,11 @@ static inline uint64_t bswap_64(uint64_t val)
 #define DISP_u16(ptr, member)                                          \
        do {                                                            \
                assert(sizeof((ptr)->member) == 2);                     \
-               printf("%-30s" "\t\t[0x%8x : %u]\n",                    \
+               if (c.layout)                                           \
+                       printf("%-30s %u\n",                            \
+                       #member":", le16_to_cpu(((ptr)->member)));      \
+               else                                                    \
+                       printf("%-30s" "\t\t[0x%8x : %u]\n",            \
                        #member, le16_to_cpu(((ptr)->member)),          \
                        le16_to_cpu(((ptr)->member)));                  \
        } while (0)
@@ -270,7 +274,11 @@ static inline uint64_t bswap_64(uint64_t val)
 #define DISP_u32(ptr, member)                                          \
        do {                                                            \
                assert(sizeof((ptr)->member) <= 4);                     \
-               printf("%-30s" "\t\t[0x%8x : %u]\n",                    \
+               if (c.layout)                                           \
+                       printf("%-30s %u\n",                            \
+                       #member":", le32_to_cpu(((ptr)->member)));      \
+               else                                                    \
+                       printf("%-30s" "\t\t[0x%8x : %u]\n",            \
                        #member, le32_to_cpu(((ptr)->member)),          \
                        le32_to_cpu(((ptr)->member)));                  \
        } while (0)
@@ -278,14 +286,23 @@ static inline uint64_t bswap_64(uint64_t val)
 #define DISP_u64(ptr, member)                                          \
        do {                                                            \
                assert(sizeof((ptr)->member) == 8);                     \
-               printf("%-30s" "\t\t[0x%8llx : %llu]\n",                \
+               if (c.layout)                                           \
+                       printf("%-30s %llu\n",                          \
+                       #member":", le64_to_cpu(((ptr)->member)));      \
+               else                                                    \
+                       printf("%-30s" "\t\t[0x%8llx : %llu]\n",        \
                        #member, le64_to_cpu(((ptr)->member)),          \
                        le64_to_cpu(((ptr)->member)));                  \
        } while (0)
 
 #define DISP_utf(ptr, member)                                          \
        do {                                                            \
-               printf("%-30s" "\t\t[%s]\n", #member, ((ptr)->member)); \
+               if (c.layout)                                           \
+                       printf("%-30s %s\n", #member":",                \
+                                       ((ptr)->member));               \
+               else                                                    \
+                       printf("%-30s" "\t\t[%s]\n", #member,           \
+                                       ((ptr)->member));               \
        } while (0)
 
 /* Display to buffer */
@@ -472,6 +489,7 @@ struct f2fs_configuration {
        int bug_nat_bits;
        int alloc_failed;
        int auto_fix;
+       int layout;
        int quota_fix;
        int preen_mode;
        int ro;