f2fs-tools: introduce new option V to show version
authorSheng Yong <shengyong1@huawei.com>
Tue, 10 Apr 2018 03:28:19 +0000 (11:28 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 14 Jul 2018 05:46:00 +0000 (22:46 -0700)
This patch introduces a new option -V to show the version of f2fs tools
and exit after that.

Signed-off-by: Sheng Yong <shengyong1@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/main.c
include/f2fs_fs.h
mkfs/f2fs_format_main.c

index bbf82c3..ca3b789 100644 (file)
@@ -58,6 +58,7 @@ void fsck_usage()
        MSG(0, "  -t show directory tree\n");
        MSG(0, "  -q preserve quota limits\n");
        MSG(0, "  -y fix all the time\n");
+       MSG(0, "  -V print the version number and exit\n");
        MSG(0, "  --dry-run do not really fix corruptions\n");
        exit(1);
 }
@@ -73,6 +74,7 @@ void dump_usage()
        MSG(0, "  -S sparse_mode\n");
        MSG(0, "  -a [SSA dump segno from #1~#2 (decimal), for all 0~-1]\n");
        MSG(0, "  -b blk_addr (in 4KB)\n");
+       MSG(0, "  -V print the version number and exit\n");
 
        exit(1);
 }
@@ -87,6 +89,7 @@ void defrag_usage()
        MSG(0, "  -l length [default:512 (2MB)]\n");
        MSG(0, "  -t target block address [default: main_blkaddr + 2MB]\n");
        MSG(0, "  -i set direction as shrink [default: expand]\n");
+       MSG(0, "  -V print the version number and exit\n");
        exit(1);
 }
 
@@ -96,6 +99,7 @@ void resize_usage()
        MSG(0, "[options]:\n");
        MSG(0, "  -d debug level [default:0]\n");
        MSG(0, "  -t target sectors [default: device size]\n");
+       MSG(0, "  -V print the version number and exit\n");
        exit(1);
 }
 
@@ -111,6 +115,7 @@ void sload_usage()
        MSG(0, "  -t mount point [prefix of target fs path, default:/]\n");
        MSG(0, "  -T timestamp\n");
        MSG(0, "  -d debug level [default:0]\n");
+       MSG(0, "  -V print the version number and exit\n");
        exit(1);
 }
 
@@ -160,7 +165,7 @@ void f2fs_parse_options(int argc, char *argv[])
        }
 
        if (!strcmp("fsck.f2fs", prog)) {
-               const char *option_string = ":ad:fp:q:Sty";
+               const char *option_string = ":ad:fp:q:StyV";
                int opt = 0;
                struct option long_opt[] = {
                        {"dry-run", no_argument, 0, 1},
@@ -240,6 +245,9 @@ void f2fs_parse_options(int argc, char *argv[])
                                        break;
                                }
                                break;
+                       case 'V':
+                               show_version(prog);
+                               exit(0);
                        case '?':
                                option = optopt;
                        default:
@@ -250,7 +258,7 @@ void f2fs_parse_options(int argc, char *argv[])
                                break;
                }
        } else if (!strcmp("dump.f2fs", prog)) {
-               const char *option_string = "d:i:n:s:Sa:b:";
+               const char *option_string = "d:i:n:s:Sa:b:V";
                static struct dump_option dump_opt = {
                        .nid = 0,       /* default root ino */
                        .start_nat = -1,
@@ -310,6 +318,9 @@ void f2fs_parse_options(int argc, char *argv[])
                                        ret = sscanf(optarg, "%x",
                                                        &dump_opt.blk_addr);
                                break;
+                       case 'V':
+                               show_version(prog);
+                               exit(0);
                        default:
                                err = EUNKNOWN_OPT;
                                break;
@@ -321,7 +332,7 @@ void f2fs_parse_options(int argc, char *argv[])
 
                c.private = &dump_opt;
        } else if (!strcmp("defrag.f2fs", prog)) {
-               const char *option_string = "d:s:Sl:t:i";
+               const char *option_string = "d:s:Sl:t:iV";
 
                c.func = DEFRAG;
                while ((option = getopt(argc, argv, option_string)) != EOF) {
@@ -367,6 +378,9 @@ void f2fs_parse_options(int argc, char *argv[])
                        case 'i':
                                c.defrag_shrink = 1;
                                break;
+                       case 'V':
+                               show_version(prog);
+                               exit(0);
                        default:
                                err = EUNKNOWN_OPT;
                                break;
@@ -376,7 +390,7 @@ void f2fs_parse_options(int argc, char *argv[])
                                break;
                }
        } else if (!strcmp("resize.f2fs", prog)) {
-               const char *option_string = "d:t:";
+               const char *option_string = "d:t:V";
 
                c.func = RESIZE;
                while ((option = getopt(argc, argv, option_string)) != EOF) {
@@ -400,6 +414,9 @@ void f2fs_parse_options(int argc, char *argv[])
                                        ret = sscanf(optarg, "%"PRIx64"",
                                                        &c.target_sectors);
                                break;
+                       case 'V':
+                               show_version(prog);
+                               exit(0);
                        default:
                                err = EUNKNOWN_OPT;
                                break;
@@ -409,7 +426,7 @@ void f2fs_parse_options(int argc, char *argv[])
                                break;
                }
        } else if (!strcmp("sload.f2fs", prog)) {
-               const char *option_string = "C:d:f:p:s:St:T:";
+               const char *option_string = "C:d:f:p:s:St:T:V";
 #ifdef HAVE_LIBSELINUX
                int max_nr_opt = (int)sizeof(c.seopt_file) /
                        sizeof(c.seopt_file[0]);
@@ -467,6 +484,9 @@ void f2fs_parse_options(int argc, char *argv[])
                        case 'T':
                                c.fixed_time = strtoul(optarg, &p, 0);
                                break;
+                       case 'V':
+                               show_version(prog);
+                               exit(0);
                        default:
                                err = EUNKNOWN_OPT;
                                break;
index 0a42ba1..543f4ba 100644 (file)
@@ -12,6 +12,7 @@
 #ifndef __F2FS_FS_H__
 #define __F2FS_FS_H__
 
+#include <stdio.h>
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -1298,4 +1299,9 @@ static inline int is_qf_ino(struct f2fs_super_block *sb, nid_t ino)
        return 0;
 }
 
+static inline void show_version(const char *prog)
+{
+       MSG(0, "%s %s (%s)\n", prog, F2FS_TOOLS_VERSION, F2FS_TOOLS_DATE);
+}
+
 #endif /*__F2FS_FS_H */
index a6e4474..fb8da79 100644 (file)
@@ -58,6 +58,7 @@ static void mkfs_usage()
        MSG(0, "  -t 0: nodiscard, 1: discard [default:1]\n");
        MSG(0, "  -w wanted sector size\n");
        MSG(0, "  -z # of sections per zone [default:1]\n");
+       MSG(0, "  -V print the version number and exit\n");
        MSG(0, "sectors: number of sectors. [default: determined by device size]\n");
        exit(1);
 }
@@ -136,7 +137,7 @@ static void parse_feature(const char *features)
 
 static void f2fs_parse_options(int argc, char *argv[])
 {
-       static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:fw:";
+       static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:fw:V";
        int32_t option=0;
 
        while ((option = getopt(argc,argv,option_string)) != EOF) {
@@ -209,6 +210,9 @@ static void f2fs_parse_options(int argc, char *argv[])
                case 'w':
                        c.wanted_sector_size = atoi(optarg);
                        break;
+               case 'V':
+                       show_version("mkfs.f2fs");
+                       exit(0);
                default:
                        MSG(0, "\tError: Unknown option %c\n",option);
                        mkfs_usage();