btrfs-progs: unify argc min/max checking
We don't want to modify argc. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
6398ed78f9
commit
358807cc33
|
@ -450,8 +450,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
set_argv0(argv);
|
||||
argc = argc - optind;
|
||||
if (check_argc_min(argc, 1)) {
|
||||
if (check_argc_min(argc - optind, 1)) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -3165,9 +3165,8 @@ int main(int argc, char *argv[])
|
|||
return c != GETOPT_VAL_HELP;
|
||||
}
|
||||
}
|
||||
argc = argc - optind;
|
||||
set_argv0(argv);
|
||||
if (check_argc_exact(argc, 1)) {
|
||||
if (check_argc_exact(argc - optind, 1)) {
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -1142,8 +1142,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
set_argv0(argv);
|
||||
argc = argc - optind;
|
||||
if (check_argc_min(argc, 1))
|
||||
if (check_argc_min(argc - optind, 1))
|
||||
print_usage(1);
|
||||
dev = argv[optind];
|
||||
|
||||
|
|
|
@ -185,8 +185,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
set_argv0(argv);
|
||||
argc = argc - optind;
|
||||
if (check_argc_min(argc, 1)) {
|
||||
if (check_argc_min(argc - optind, 1)) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -428,8 +428,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
set_argv0(argv);
|
||||
argc = argc - optind;
|
||||
if (check_argc_min(argc, 1)) {
|
||||
if (check_argc_min(argc - optind, 1)) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
|
|
@ -2735,12 +2735,11 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
argc = argc - optind;
|
||||
set_argv0(argv);
|
||||
if (check_argc_min(argc, 2))
|
||||
if (check_argc_min(argc - optind, 2))
|
||||
print_usage(1);
|
||||
|
||||
dev_cnt = argc - 1;
|
||||
dev_cnt = argc - optind - 1;
|
||||
|
||||
if (create) {
|
||||
if (old_restore) {
|
||||
|
|
|
@ -248,8 +248,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
set_argv0(argv);
|
||||
argc = argc - optind;
|
||||
if (check_argc_min(argc, 1))
|
||||
if (check_argc_min(argc - optind, 1))
|
||||
print_usage();
|
||||
if (logical == 0)
|
||||
print_usage();
|
||||
|
|
|
@ -65,9 +65,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
set_argv0(argv);
|
||||
argc = argc - optind;
|
||||
|
||||
if (check_argc_exact(argc, 1))
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
print_usage();
|
||||
|
||||
if (bytenr == 0) {
|
||||
|
|
|
@ -39,23 +39,23 @@ int main(int argc, char **argv)
|
|||
int ret;
|
||||
|
||||
set_argv0(argv);
|
||||
if (check_argc_exact(argc, 2))
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
print_usage();
|
||||
|
||||
radix_tree_init();
|
||||
|
||||
printf("WARNING: this utility is deprecated, please use 'btrfs rescue zero-log'\n\n");
|
||||
|
||||
if ((ret = check_mounted(argv[1])) < 0) {
|
||||
if ((ret = check_mounted(argv[optind])) < 0) {
|
||||
fprintf(stderr, "ERROR: could not check mount status: %s\n", strerror(-ret));
|
||||
goto out;
|
||||
} else if (ret) {
|
||||
fprintf(stderr, "ERROR: %s is currently mounted\n", argv[1]);
|
||||
fprintf(stderr, "ERROR: %s is currently mounted\n", argv[optind]);
|
||||
ret = -EBUSY;
|
||||
goto out;
|
||||
}
|
||||
|
||||
root = open_ctree(argv[1], 0, OPEN_CTREE_WRITES | OPEN_CTREE_PARTIAL);
|
||||
root = open_ctree(argv[optind], 0, OPEN_CTREE_WRITES | OPEN_CTREE_PARTIAL);
|
||||
if (!root) {
|
||||
fprintf(stderr, "ERROR: cannot open ctree\n");
|
||||
return 1;
|
||||
|
@ -63,7 +63,7 @@ int main(int argc, char **argv)
|
|||
|
||||
sb = root->fs_info->super_copy;
|
||||
printf("Clearing log on %s, previous log_root %llu, level %u\n",
|
||||
argv[1],
|
||||
argv[optind],
|
||||
(unsigned long long)btrfs_super_log_root(sb),
|
||||
(unsigned)btrfs_super_log_root_level(sb));
|
||||
trans = btrfs_start_transaction(root, 1);
|
||||
|
|
|
@ -442,9 +442,8 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
set_argv0(argv);
|
||||
argc = argc - optind;
|
||||
device = argv[optind];
|
||||
if (check_argc_exact(argc, 1)) {
|
||||
if (check_argc_exact(argc - optind, 1)) {
|
||||
print_usage();
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -9579,9 +9579,8 @@ int cmd_check(int argc, char **argv)
|
|||
break;
|
||||
}
|
||||
}
|
||||
argc = argc - optind;
|
||||
|
||||
if (check_argc_exact(argc, 1))
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
usage(cmd_check_usage);
|
||||
|
||||
if (ctx.progress_enabled) {
|
||||
|
|
|
@ -246,10 +246,10 @@ static int cmd_device_scan(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
if (all && check_argc_max(argc, 2))
|
||||
if (all && check_argc_max(argc - optind, 1))
|
||||
usage(cmd_device_scan_usage);
|
||||
|
||||
if (all || argc == 1) {
|
||||
if (all || argc - optind == 1) {
|
||||
printf("Scanning for Btrfs filesystems\n");
|
||||
ret = btrfs_scan_lblkid();
|
||||
error_on(ret, "error %d while scanning", ret);
|
||||
|
@ -372,8 +372,7 @@ static int cmd_device_stats(int argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
argc = argc - optind;
|
||||
if (check_argc_exact(argc, 1))
|
||||
if (check_argc_exact(argc - optind, 1))
|
||||
usage(cmd_device_stats_usage);
|
||||
|
||||
dev_path = argv[optind];
|
||||
|
|
Loading…
Reference in New Issue