For btrfs-image,
dump may not come with option '-o'
-r may not come with option '-c', '-s', '-w', dev_cnt != 1
-m may not come with dev_cnt < 2
All of the above should be regarded as invalid combinations,
and the usage will show up.
Signed-off-by: Gui Hecheng <guihc.fnst@xxxxxxxxxxxxxx>
---
changelog
v1->v2: add error messages for each case
v2->v3: add missing judgements
---
btrfs-image.c | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/btrfs-image.c b/btrfs-image.c
index db5d193..9e5b8b3 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2462,6 +2462,7 @@ int main(int argc, char *argv[])
int ret;
int sanitize = 0;
int dev_cnt = 0;
+ int usage_error = 0;
FILE *out;
while (1) {
@@ -2500,15 +2501,30 @@ int main(int argc, char *argv[])
}
}
- if ((old_restore) && create)
- print_usage();
-
argc = argc - optind;
dev_cnt = argc - 1;
- if (multi_devices && dev_cnt < 2)
- print_usage();
- if (!multi_devices && dev_cnt != 1)
+ if (create) {
+ if (old_restore) {
+ fprintf(stderr, "Usage error: create and restore cannot be used at the same time\n");
+ usage_error++;
+ }
+ } else {
+ if (walk_trees || sanitize || compress_level) {
+ fprintf(stderr, "Usage error: use -w, -s, -c options for restore makes no sense\n");
+ usage_error++;
+ }
+ if (multi_devices && dev_cnt < 2) {
+ fprintf(stderr, "Usage error: not enough devices specified for -m option\n");
+ usage_error++;
+ }
+ if (!multi_devices && dev_cnt != 1) {
+ fprintf(stderr, "Usage error: accepts only 1 device without -m option\n");
+ usage_error++;
+ }
+ }
+
+ if (usage_error)
print_usage();
source = argv[optind];
--
1.8.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html