All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Tulak <jtulak@redhat.com>
To: linux-xfs@vger.kernel.org
Cc: Jan Tulak <jtulak@redhat.com>
Subject: [PATCH 22/22] mkfs: prevent multiple specifications of a single option
Date: Wed, 15 Mar 2017 17:00:17 +0100	[thread overview]
Message-ID: <20170315160017.27805-23-jtulak@redhat.com> (raw)
In-Reply-To: <20170315160017.27805-1-jtulak@redhat.com>

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 <jtulak@redhat.com>
---
 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;
 }
-- 
2.11.0


  parent reply	other threads:[~2017-03-15 16:01 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-15 15:59 [PATCH 00/22] mkfs.xfs: Make stronger conflict checks Jan Tulak
2017-03-15 15:59 ` [PATCH 01/22] mkfs: remove intermediate getstr followed by getnum Jan Tulak
2017-03-16 22:59   ` Eric Sandeen
2017-04-05 13:00     ` Jan Tulak
2017-04-05 14:05       ` Eric Sandeen
2017-03-15 15:59 ` [PATCH 02/22] mkfs: merge tables for opts parsing into one table Jan Tulak
2017-03-15 15:59 ` [PATCH 03/22] mkfs: extend opt_params with a value field Jan Tulak
2017-03-15 15:59 ` [PATCH 04/22] mkfs: change conflicts array into a table capable of cross-option addressing Jan Tulak
2017-03-16 17:02   ` Eric Sandeen
2017-03-16 17:21     ` Jan Tulak
2017-03-16 17:41       ` Eric Sandeen
2017-03-16 17:47         ` Jan Tulak
2017-03-15 16:00 ` [PATCH 05/22] mkfs: add a check for conflicting values Jan Tulak
2017-03-25  0:36   ` Eric Sandeen
2017-03-29 14:58     ` Jan Tulak
2017-03-15 16:00 ` [PATCH 06/22] mkfs: add cross-section conflict checks Jan Tulak
2017-03-25  0:31   ` Eric Sandeen
2017-03-29 14:57     ` Jan Tulak
2017-03-15 16:00 ` [PATCH 07/22] mkfs: Move opts related #define to one place Jan Tulak
2017-03-16 23:25   ` Luis R. Rodriguez
2017-03-17 12:11     ` Jan Tulak
2017-03-15 16:00 ` [PATCH 08/22] mkfs: move conflicts into the table Jan Tulak
2017-03-16 18:04   ` Eric Sandeen
2017-03-16 18:39   ` Eric Sandeen
2017-03-16 18:45     ` Darrick J. Wong
2017-03-24 23:53   ` Eric Sandeen
2017-03-29 14:57     ` Jan Tulak
2017-03-15 16:00 ` [PATCH 09/22] mkfs: change conflict checks to utilize the new conflict structure Jan Tulak
2017-03-15 16:00 ` [PATCH 10/22] mkfs: change when to mark an option as seen Jan Tulak
2017-03-15 16:00 ` [PATCH 11/22] mkfs: add test_default_value into conflict struct Jan Tulak
2017-03-25  0:09   ` Eric Sandeen
2017-03-29 14:57     ` Jan Tulak
2017-03-29 16:33       ` Jan Tulak
2017-03-31  1:40         ` Luis R. Rodriguez
2017-03-31  7:35           ` Jan Tulak
2017-03-15 16:00 ` [PATCH 12/22] mkfs: expand conflicts declarations to named declaration Jan Tulak
2017-03-15 16:00 ` [PATCH 13/22] mkfs: remove zeroed items from conflicts declaration Jan Tulak
2017-03-15 16:00 ` [PATCH 14/22] mkfs: rename defaultval to flagval in opts Jan Tulak
2017-03-16 23:20   ` Luis R. Rodriguez
2017-03-17 12:06     ` Jan Tulak
2017-03-15 16:00 ` [PATCH 15/22] mkfs: replace SUBOPT_NEEDS_VAL for a flag Jan Tulak
2017-03-15 16:00 ` [PATCH 16/22] mkfs: Change all value fields in opt structures into unions Jan Tulak
2017-03-15 16:00 ` [PATCH 17/22] mkfs: use old variables as pointers to the new opts struct values Jan Tulak
2017-03-17  0:48   ` Eric Sandeen
2017-03-15 16:00 ` [PATCH 18/22] mkfs: prevent sector/blocksize to be specified as a number of blocks Jan Tulak
2017-03-15 16:00 ` [PATCH 19/22] mkfs: subopt flags should be saved as bool Jan Tulak
2017-03-15 16:00 ` [PATCH 20/22] mkfs: move uuid empty string test to getstr() Jan Tulak
2017-03-15 16:00 ` [PATCH 21/22] mkfs: remove duplicit checks Jan Tulak
2017-03-15 16:00 ` Jan Tulak [this message]
2017-03-16 17:19 ` [PATCH 00/22] mkfs.xfs: Make stronger conflict checks Eric Sandeen
2017-03-16 17:23   ` Jan Tulak
2017-03-16 23:38 ` Luis R. Rodriguez
2017-03-16 23:47   ` Eric Sandeen
2017-03-17 12:57     ` Jan Tulak
2017-03-18  7:08       ` Dave Chinner
2017-03-17 12:20   ` Jan Tulak
  -- strict thread matches above, loose matches on Subject: below --
2016-12-07 13:27 [RFC PATCH " Jan Tulak
2016-12-07 13:27 ` [PATCH 22/22] mkfs: prevent multiple specifications of a single option Jan Tulak
2017-01-16 14:18   ` Bill O'Donnell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170315160017.27805-23-jtulak@redhat.com \
    --to=jtulak@redhat.com \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.