From patchwork Tue Jun 24 03:16:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 4406191 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2590ABEEAA for ; Tue, 24 Jun 2014 03:21:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 23AD32018E for ; Tue, 24 Jun 2014 03:21:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 227BD2017A for ; Tue, 24 Jun 2014 03:21:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751101AbaFXDVg (ORCPT ); Mon, 23 Jun 2014 23:21:36 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:50319 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750827AbaFXDVf (ORCPT ); Mon, 23 Jun 2014 23:21:35 -0400 X-IronPort-AV: E=Sophos;i="5.00,766,1396972800"; d="scan'208";a="32328784" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 24 Jun 2014 11:18:53 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s5O3LWdd019100; Tue, 24 Jun 2014 11:21:32 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Tue, 24 Jun 2014 11:21:38 +0800 From: Gui Hecheng To: CC: , Gui Hecheng Subject: [PATCH v3 2/4] btrfs-progs: deal with invalid option combinations for btrfs-image Date: Tue, 24 Jun 2014 11:16:12 +0800 Message-ID: <1403579772-7795-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <20140623141214.GF1553@twin.jikos.cz> References: <20140623141214.GF1553@twin.jikos.cz> MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 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];