summaryrefslogtreecommitdiff
path: root/cmds-inspect.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-03-01 16:02:08 +0100
committerDavid Sterba <dsterba@suse.com>2016-03-14 13:42:47 +0100
commitbabe94e4817aca45aef409b7a21bc47e51cda6ff (patch)
treea00641b956754d6bd002bb23c6b8e3d3a18b8740 /cmds-inspect.c
parentc27640938de1506e0a02f7f928a00886d5da616a (diff)
btrfs-progs: add getopt stubs where needed
Commands that do not take any options do not use getopt, which means the standard option separator "--" does not work. Update all command handlers that need it, argv needs to be referenced using the optind that is correctly pointed after the separator. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'cmds-inspect.c')
-rw-r--r--cmds-inspect.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/cmds-inspect.c b/cmds-inspect.c
index 176f836..dbc6656 100644
--- a/cmds-inspect.c
+++ b/cmds-inspect.c
@@ -268,22 +268,24 @@ static int cmd_inspect_subvolid_resolve(int argc, char **argv)
char path[PATH_MAX];
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 3))
+ clean_args_no_options(argc, argv, cmd_inspect_subvolid_resolve_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_inspect_subvolid_resolve_usage);
- fd = btrfs_open_dir(argv[2], &dirstream, 1);
+ fd = btrfs_open_dir(argv[optind], &dirstream, 1);
if (fd < 0) {
ret = -ENOENT;
goto out;
}
- subvol_id = arg_strtou64(argv[1]);
+ subvol_id = arg_strtou64(argv[optind]);
ret = btrfs_subvolid_resolve(fd, path, sizeof(path), subvol_id);
if (ret) {
fprintf(stderr,
- "%s: btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n",
- argv[0], (unsigned long long)subvol_id, ret);
+ "btrfs_subvolid_resolve(subvol_id %llu) failed with ret=%d\n",
+ (unsigned long long)subvol_id, ret);
goto out;
}
@@ -308,10 +310,12 @@ static int cmd_inspect_rootid(int argc, char **argv)
u64 rootid;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_inspect_rootid_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_inspect_rootid_usage);
- fd = btrfs_open_dir(argv[1], &dirstream, 1);
+ fd = btrfs_open_dir(argv[optind], &dirstream, 1);
if (fd < 0) {
ret = -ENOENT;
goto out;
@@ -319,8 +323,7 @@ static int cmd_inspect_rootid(int argc, char **argv)
ret = lookup_ino_rootid(fd, &rootid);
if (ret) {
- fprintf(stderr, "%s: rootid failed with ret=%d\n",
- argv[0], ret);
+ fprintf(stderr, "rootid failed with ret=%d\n", ret);
goto out;
}