From patchwork Wed Mar 15 16:00:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Tulak X-Patchwork-Id: 9626025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F38C1604CC for ; Wed, 15 Mar 2017 16:01:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E68FC28452 for ; Wed, 15 Mar 2017 16:01:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB2EC28643; Wed, 15 Mar 2017 16:01:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8520228452 for ; Wed, 15 Mar 2017 16:01:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752220AbdCOQBc (ORCPT ); Wed, 15 Mar 2017 12:01:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51016 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754133AbdCOQBD (ORCPT ); Wed, 15 Mar 2017 12:01:03 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 666DF80F93 for ; Wed, 15 Mar 2017 16:01:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 666DF80F93 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jtulak@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 666DF80F93 Received: from honza-mbp.redhat.com (ovpn-204-198.brq.redhat.com [10.40.204.198]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2FG0b8g031509; Wed, 15 Mar 2017 12:01:02 -0400 From: Jan Tulak To: linux-xfs@vger.kernel.org Cc: Jan Tulak Subject: [PATCH 22/22] mkfs: prevent multiple specifications of a single option Date: Wed, 15 Mar 2017 17:00:17 +0100 Message-Id: <20170315160017.27805-23-jtulak@redhat.com> In-Reply-To: <20170315160017.27805-1-jtulak@redhat.com> References: <20170315160017.27805-1-jtulak@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 15 Mar 2017 16:01:03 +0000 (UTC) Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Because things like -l size=40M,size=50M are clearly wrong and should not pass. However, in two cases, we do not know if the option is a string or number - thus the few more lines with can_respec flag. Signed-off-by: Jan Tulak --- mkfs/xfs_mkfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index dfb5e300..a472b92c 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -432,6 +432,10 @@ test_uvalue_num(enum e_type a_type, union u_value a, long long b) { * Set to true if, when user specifies the option, she has to specify * a value too. That is, if needs_val is true, then it is not possible to * use the subopt as a flag. + * + * can_respec OPTIONAL + * If true, then there can come one getnum() after a getstr() call for this + * option. */ struct opt_params { int index; @@ -458,6 +462,7 @@ struct opt_params { union u_value value; enum e_type type; bool needs_val; + bool can_respec; } subopt_params[MAX_SUBOPTS]; } opts[MAX_OPTS] = { { @@ -876,6 +881,7 @@ struct opt_params { .maxval.i = 2, .needs_val = true, .type = INT, + .can_respec = true, }, { .index = L_SUNIT, .conflicts = { {.opt = OPT_L, @@ -1008,6 +1014,7 @@ struct opt_params { .maxval.i = 2, .needs_val = true, .type = INT, + .can_respec = true, }, { .index = N_FTYPE, .conflicts = { {.opt = OPT_M, @@ -2020,6 +2027,22 @@ getnum( struct subopt_param *sp = &opts->subopt_params[index]; long long c; + if (sp->seen){ + /* If the option has respec flag, it is possible to do ONE + * getnum call even with sp->seen == 1. Do this by disabling + * the respec flag - this time we can continue, but if getnum + * gets called once more, we will fail. + */ + if (sp->can_respec){ + sp->can_respec = false; + } else { + fprintf(stderr, + _("You can't use an option multiple times: -%c %s\n"), + opts->name, opts->subopts[index]); + usage(); + } + } + /* empty strings might just return a default value */ if (!str || *str == '\0') { if (sp->needs_val) @@ -2132,6 +2155,12 @@ getstr( /* empty strings for string options are not valid */ if (!str || *str == '\0') reqval(opts->name, (char **)opts->subopts, index); + if (opts->subopt_params[index].seen){ + fprintf(stderr, + _("You can't use an option multiple times: -%c %s\n"), + opts->name, opts->subopts[index]); + usage(); + } opts->subopt_params[index].seen = true; return str; }