forked from Mirrors/btrfs-progs
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>master
parent
c27640938d
commit
babe94e481
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
14
cmds-quota.c
14
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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue