fsck.f2fs: fix bad notice of missing device
authorKinglong Mee <kinglongmee@gmail.com>
Fri, 17 Mar 2017 13:55:50 +0000 (21:55 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sun, 19 Mar 2017 22:45:21 +0000 (18:45 -0400)
The following messages is better than before.

Before,
# fsck.f2fs -d 1
    Error: Need argument for -d

Now,
# fsck.f2fs -d 1
Info: Debug level = 1
        Error: Device not specified

Signed-off-by: Kinglong Mee <kinglongmee@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/main.c

index ab0884c..fe127ec 100644 (file)
@@ -114,8 +114,6 @@ void f2fs_parse_options(int argc, char *argv[])
                MSG(0, "\tError: Device not specified\n");
                error_out(prog);
        }
-       c.devices[0].path = strdup(argv[argc - 1]);
-       argv[argc-- - 1] = 0;
 
        if (!strcmp("fsck.f2fs", prog)) {
                const char *option_string = ":ad:fp:t";
@@ -372,7 +370,14 @@ void f2fs_parse_options(int argc, char *argv[])
                                break;
                }
        }
-       if (argc > optind) {
+
+       if (optind >= argc) {
+               MSG(0, "\tError: Device not specified\n");
+               error_out(prog);
+       }
+
+       c.devices[0].path = strdup(argv[optind]);
+       if (argc > (optind + 1)) {
                c.dbg_lv = 0;
                err = EUNKNOWN_ARG;
        }