summaryrefslogtreecommitdiff
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
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>
-rw-r--r--cmds-balance.c18
-rw-r--r--cmds-device.c20
-rw-r--r--cmds-filesystem.c31
-rw-r--r--cmds-inspect.c21
-rw-r--r--cmds-property.c6
-rw-r--r--cmds-qgroup.c35
-rw-r--r--cmds-quota.c14
-rw-r--r--cmds-rescue.c2
-rw-r--r--cmds-scrub.c6
-rw-r--r--cmds-subvolume.c20
10 files changed, 122 insertions, 51 deletions
diff --git a/cmds-balance.c b/cmds-balance.c
index e0d10aa..33f91e4 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -612,10 +612,12 @@ static int cmd_balance_pause(int argc, char **argv)
int e;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_balance_pause_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_balance_pause_usage);
- path = argv[1];
+ path = argv[optind];
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
@@ -651,10 +653,12 @@ static int cmd_balance_cancel(int argc, char **argv)
int e;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_balance_cancel_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_balance_cancel_usage);
- path = argv[1];
+ path = argv[optind];
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
@@ -691,10 +695,12 @@ static int cmd_balance_resume(int argc, char **argv)
int ret;
int e;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_balance_resume_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_balance_resume_usage);
- path = argv[1];
+ path = argv[optind];
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
diff --git a/cmds-device.c b/cmds-device.c
index 50c1c5d..ee999a0 100644
--- a/cmds-device.c
+++ b/cmds-device.c
@@ -146,7 +146,9 @@ static int _cmd_device_remove(int argc, char **argv,
int i, fdmnt, ret = 0;
DIR *dirstream = NULL;
- if (check_argc_min(argc, 3))
+ clean_args_no_options(argc, argv, usagestr);
+
+ if (check_argc_min(argc - optind, 2))
usage(usagestr);
mntpnt = argv[argc - 1];
@@ -155,7 +157,7 @@ static int _cmd_device_remove(int argc, char **argv,
if (fdmnt < 0)
return 1;
- for(i=1 ; i < argc - 1; i++ ){
+ for(i = optind; i < argc - 1; i++) {
struct btrfs_ioctl_vol_args arg;
int res;
@@ -297,7 +299,9 @@ static int cmd_device_ready(int argc, char **argv)
int ret;
char *path;
- if (check_argc_min(argc, 2))
+ clean_args_no_options(argc, argv, cmd_device_ready_usage);
+
+ if (check_argc_min(argc - optind, 1))
usage(cmd_device_ready_usage);
fd = open("/dev/btrfs-control", O_RDWR);
@@ -306,10 +310,10 @@ static int cmd_device_ready(int argc, char **argv)
return 1;
}
- path = canonicalize_path(argv[argc - 1]);
+ path = canonicalize_path(argv[optind]);
if (!path) {
error("could not canonicalize pathname '%s': %s",
- argv[argc - 1], strerror(errno));
+ argv[optind], strerror(errno));
ret = 1;
goto out;
}
@@ -493,10 +497,12 @@ static int cmd_device_usage(int argc, char **argv)
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
- if (check_argc_min(argc, 2) || argv[1][0] == '-')
+ clean_args_no_options(argc, argv, cmd_device_usage_usage);
+
+ if (check_argc_min(argc - optind, 1))
usage(cmd_device_usage_usage);
- for (i = 1; i < argc; i++) {
+ for (i = optind; i < argc; i++) {
int fd;
DIR *dirstream = NULL;
diff --git a/cmds-filesystem.c b/cmds-filesystem.c
index 9e5ccab..ea66f8a 100644
--- a/cmds-filesystem.c
+++ b/cmds-filesystem.c
@@ -197,10 +197,12 @@ static int cmd_filesystem_df(int argc, char **argv)
unit_mode = get_unit_mode_from_arg(&argc, argv, 1);
- if (argc != 2 || argv[1][0] == '-')
+ clean_args_no_options(argc, argv, cmd_filesystem_df_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_filesystem_df_usage);
- path = argv[1];
+ path = argv[optind];
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
@@ -918,10 +920,12 @@ static int cmd_filesystem_sync(int argc, char **argv)
char *path;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_filesystem_sync_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_filesystem_sync_usage);
- path = argv[1];
+ path = argv[optind];
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
@@ -1178,11 +1182,13 @@ static int cmd_filesystem_resize(int argc, char **argv)
DIR *dirstream = NULL;
struct stat st;
- if (check_argc_exact(argc, 3))
+ clean_args_no_options(argc, argv, cmd_filesystem_resize_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_filesystem_resize_usage);
- amount = argv[1];
- path = argv[2];
+ amount = argv[optind];
+ path = argv[optind + 1];
len = strlen(amount);
if (len == 0 || len >= BTRFS_VOL_NAME_MAX) {
@@ -1247,16 +1253,19 @@ static const char * const cmd_filesystem_label_usage[] = {
static int cmd_filesystem_label(int argc, char **argv)
{
- if (check_argc_min(argc, 2) || check_argc_max(argc, 3))
+ clean_args_no_options(argc, argv, cmd_filesystem_label_usage);
+
+ if (check_argc_min(argc - optind, 2) ||
+ check_argc_max(argc - optind, 3))
usage(cmd_filesystem_label_usage);
- if (argc > 2) {
- return set_label(argv[1], argv[2]);
+ if (argc - optind > 2) {
+ return set_label(argv[optind], argv[optind + 1]);
} else {
char label[BTRFS_LABEL_SIZE];
int ret;
- ret = get_label(argv[1], label);
+ ret = get_label(argv[optind], label);
if (!ret)
fprintf(stdout, "%s\n", label);
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;
}
diff --git a/cmds-property.c b/cmds-property.c
index b7b2484..5b4da26 100644
--- a/cmds-property.c
+++ b/cmds-property.c
@@ -379,6 +379,8 @@ static int cmd_property_get(int argc, char **argv)
char *name = NULL;
int types = 0;
+ clean_args_no_options(argc, argv, cmd_property_get_usage);
+
if (check_argc_min(argc, 2) || check_argc_max(argc, 5))
usage(cmd_property_get_usage);
@@ -413,6 +415,8 @@ static int cmd_property_set(int argc, char **argv)
char *value = NULL;
int types = 0;
+ clean_args_no_options(argc, argv, cmd_property_set_usage);
+
if (check_argc_min(argc, 4) || check_argc_max(argc, 6))
usage(cmd_property_set_usage);
@@ -442,6 +446,8 @@ static int cmd_property_list(int argc, char **argv)
char *object = NULL;
int types = 0;
+ clean_args_no_options(argc, argv, cmd_property_list_usage);
+
if (check_argc_min(argc, 2) || check_argc_max(argc, 4))
usage(cmd_property_list_usage);
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index db5ee21..80b2d55 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -120,16 +120,17 @@ static int qgroup_create(int create, int argc, char **argv)
int ret = 0;
int fd;
int e;
- char *path = argv[2];
+ char *path;
struct btrfs_ioctl_qgroup_create_args args;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 3))
+ if (check_argc_exact(argc - optind, 3))
return -1;
memset(&args, 0, sizeof(args));
args.create = create;
- args.qgroupid = parse_qgroupid(argv[1]);
+ args.qgroupid = parse_qgroupid(argv[optind]);
+ path = argv[optind + 1];
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
@@ -207,7 +208,12 @@ static const char * const cmd_qgroup_assign_usage[] = {
static int cmd_qgroup_assign(int argc, char **argv)
{
- int ret = qgroup_assign(1, argc, argv);
+ int ret;
+
+ clean_args_no_options(argc, argv, cmd_qgroup_assign_usage);
+
+ ret = qgroup_assign(1, argc, argv);
+
if (ret < 0)
usage(cmd_qgroup_assign_usage);
return ret;
@@ -221,7 +227,12 @@ static const char * const cmd_qgroup_remove_usage[] = {
static int cmd_qgroup_remove(int argc, char **argv)
{
- int ret = qgroup_assign(0, argc, argv);
+ int ret;
+
+ clean_args_no_options(argc, argv, cmd_qgroup_remove_usage);
+
+ ret = qgroup_assign(0, argc, argv);
+
if (ret < 0)
usage(cmd_qgroup_remove_usage);
return ret;
@@ -235,7 +246,12 @@ static const char * const cmd_qgroup_create_usage[] = {
static int cmd_qgroup_create(int argc, char **argv)
{
- int ret = qgroup_create(1, argc, argv);
+ int ret;
+
+ clean_args_no_options(argc, argv, cmd_qgroup_create_usage);
+
+ ret = qgroup_create(1, argc, argv);
+
if (ret < 0)
usage(cmd_qgroup_create_usage);
return ret;
@@ -249,7 +265,12 @@ static const char * const cmd_qgroup_destroy_usage[] = {
static int cmd_qgroup_destroy(int argc, char **argv)
{
- int ret = qgroup_create(0, argc, argv);
+ int ret;
+
+ clean_args_no_options(argc, argv, cmd_qgroup_destroy_usage);
+
+ ret = qgroup_create(0, argc, argv);
+
if (ret < 0)
usage(cmd_qgroup_destroy_usage);
return ret;
diff --git a/cmds-quota.c b/cmds-quota.c
index 34b8dac..568482f 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -70,7 +70,12 @@ static const char * const cmd_quota_enable_usage[] = {
static int cmd_quota_enable(int argc, char **argv)
{
- int ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
+ int ret;
+
+ clean_args_no_options(argc, argv, cmd_quota_enable_usage);
+
+ ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv);
+
if (ret < 0)
usage(cmd_quota_enable_usage);
return ret;
@@ -84,7 +89,12 @@ static const char * const cmd_quota_disable_usage[] = {
static int cmd_quota_disable(int argc, char **argv)
{
- int ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv);
+ int ret;
+
+ clean_args_no_options(argc, argv, cmd_quota_disable_usage);
+
+ ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv);
+
if (ret < 0)
usage(cmd_quota_disable_usage);
return ret;
diff --git a/cmds-rescue.c b/cmds-rescue.c
index 9895425..cacb144 100644
--- a/cmds-rescue.c
+++ b/cmds-rescue.c
@@ -165,6 +165,8 @@ static int cmd_rescue_zero_log(int argc, char **argv)
char *devname;
int ret;
+ clean_args_no_options(argc, argv, cmd_rescue_zero_log_usage);
+
if (check_argc_exact(argc, 2))
usage(cmd_rescue_zero_log_usage);
diff --git a/cmds-scrub.c b/cmds-scrub.c
index da614f2..de7005c 100644
--- a/cmds-scrub.c
+++ b/cmds-scrub.c
@@ -1591,10 +1591,12 @@ static int cmd_scrub_cancel(int argc, char **argv)
int fdmnt = -1;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_scrub_cancel_usage);
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_scrub_cancel_usage);
- path = argv[1];
+ path = argv[optind];
fdmnt = open_path_or_dev_mnt(path, &dirstream, 1);
if (fdmnt < 0) {
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index 9d9b0af..02e1dec 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -788,7 +788,9 @@ static int cmd_subvol_get_default(int argc, char **argv)
u64 default_id;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 2))
+ clean_args_no_options(argc, argv, cmd_subvol_get_default_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_subvol_get_default_usage);
subvol = argv[1];
@@ -850,11 +852,13 @@ static int cmd_subvol_set_default(int argc, char **argv)
char *subvolid;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 3))
+ clean_args_no_options(argc, argv, cmd_subvol_set_default_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_subvol_set_default_usage);
- subvolid = argv[1];
- path = argv[2];
+ subvolid = argv[optind];
+ path = argv[optind + 1];
objectid = arg_strtou64(subvolid);
@@ -887,11 +891,13 @@ static int cmd_subvol_find_new(int argc, char **argv)
u64 last_gen;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 3))
+ clean_args_no_options(argc, argv, cmd_subvol_find_new_usage);
+
+ if (check_argc_exact(argc - optind, 2))
usage(cmd_subvol_find_new_usage);
- subvol = argv[1];
- last_gen = arg_strtou64(argv[2]);
+ subvol = argv[optind];
+ last_gen = arg_strtou64(argv[optind + 1]);
ret = test_issubvolume(subvol);
if (ret < 0) {