From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from cn.fujitsu.com ([59.151.112.132]:53492 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751014AbaFXC5M (ORCPT ); Mon, 23 Jun 2014 22:57:12 -0400 Message-ID: <1403578314.6694.2.camel@localhost.localdomain> Subject: Re: [PATCH v2 2/4] btrfs-progs: deal with invalid option combinations for btrfs-image From: Gui Hecheng To: CC: Date: Tue, 24 Jun 2014 10:51:54 +0800 In-Reply-To: <1403577393-6096-1-git-send-email-guihc.fnst@cn.fujitsu.com> References: <20140623141214.GF1553@twin.jikos.cz> <1403577393-6096-1-git-send-email-guihc.fnst@cn.fujitsu.com> Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org List-ID: On Tue, 2014-06-24 at 10:36 +0800, Gui Hecheng wrote: > 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 > --- > changelog > v1->v2: add error messages for each case > --- > btrfs-image.c | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > > diff --git a/btrfs-image.c b/btrfs-image.c > index db5d193..c18dff1 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,26 @@ 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) { > + usage_error = old_restore; > + fprintf(stderr, "Usage error: create and restore cannot be used at the same time\n"); > + } else { > + usage_error = walk_trees || sanitize || compress_level; > + fprintf(stderr, "Usage error: use -w, -s, -c options for restore makes no sense\n"); > + > + if (multi_devices) { > + usage_error = usage_error || (dev_cnt < 2); > + fprintf(stderr, "Usage error: not enough devices specified for -m option\n"); > + } else { > + usage_error = usage_error || (dev_cnt != 1); > + fprintf(stderr, "Usage error: accepts only 1 device without -m option\n"); > + } > + } > + > + if (usage_error) > print_usage(); > > source = argv[optind]; Ah, sorry, I forget about the if() judgement, please *ignore* this one.