public inbox for linux-nfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Coddington <bcodding@redhat.com>
To: linux-nfs@vger.kernel.org
Subject: [PATCH 3/6] mount.nfs: parse options - add helper po_contains_prefix
Date: Tue, 18 Nov 2014 09:06:41 -0500	[thread overview]
Message-ID: <3210f38d54929658120ef91c5f951e04ad63fdc7.1416319371.git.bcodding@redhat.com> (raw)
In-Reply-To: <cover.1416319371.git.bcodding@redhat.com>
In-Reply-To: <cover.1416319371.git.bcodding@redhat.com>

The version options (v2,v4,v4.2) may increase in the future, but they have
a predictable prefix.  Add a parse option helper to locate and return these
options by prefix so that a future increment of version does not require the
addition of strings to a search table.

Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
 utils/mount/parse_opt.c |   24 ++++++++++++++++++++++++
 utils/mount/parse_opt.h |    2 ++
 2 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
index 342e210..7ba61c4 100644
--- a/utils/mount/parse_opt.c
+++ b/utils/mount/parse_opt.c
@@ -410,6 +410,30 @@ po_found_t po_contains(struct mount_options *options, char *keyword)
 }
 
 /**
+ * po_contains_prefix - check for presence of an option matching a prefix
+ * @options: pointer to mount options
+ * @prefix: pointer to prefix to match against a keyword
+ * @keyword: pointer to a C string containing the option keyword if found
+ *
+ * On success, *keyword contains the pointer of the matching option's keyword.
+ */
+po_found_t po_contains_prefix(struct mount_options *options,
+								const char *prefix, char **keyword)
+{
+	struct mount_option *option;
+
+	if (options && prefix) {
+		for (option = options->head; option; option = option->next)
+			if (strncmp(option->keyword, prefix, strlen(prefix)) == 0) {
+				*keyword = option->keyword;
+				return PO_FOUND;
+			}
+	}
+
+	return PO_NOT_FOUND;
+}
+
+/**
  * po_get - return the value of the rightmost instance of an option
  * @options: pointer to mount options
  * @keyword: pointer to a C string containing option keyword for which to search
diff --git a/utils/mount/parse_opt.h b/utils/mount/parse_opt.h
index 5037207..0745e0f 100644
--- a/utils/mount/parse_opt.h
+++ b/utils/mount/parse_opt.h
@@ -45,6 +45,8 @@ po_return_t		po_join(struct mount_options *, char **);
 
 po_return_t		po_append(struct mount_options *, char *);
 po_found_t		po_contains(struct mount_options *, char *);
+po_found_t		po_contains_prefix(struct mount_options *options,
+						const char *prefix, char **keyword);
 char *			po_get(struct mount_options *, char *);
 po_found_t		po_get_numeric(struct mount_options *,
 					char *, long *);
-- 
1.7.1


  parent reply	other threads:[~2014-11-18 14:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-18 14:06 [PATCH v2 0/6] mount.nfs default version Benjamin Coddington
2014-11-18 14:06 ` [PATCH 1/6] mount.nfs: default enable mount config file (nfsmount.conf) Benjamin Coddington
2014-11-18 14:06 ` [PATCH 2/6] mount.nfs: fix a comment typo in parse options Benjamin Coddington
2014-11-18 14:06 ` Benjamin Coddington [this message]
2014-11-18 14:06 ` [PATCH 4/6] mount.nfs: Add struct nfs_version and generalize version parsing Benjamin Coddington
2014-11-18 14:06 ` [PATCH 5/6] nfsmount.conf: Always parse versions Benjamin Coddington
2014-11-18 14:06 ` [PATCH 6/6] mount.nfs: configurable minor version defaults Benjamin Coddington
2015-01-28 21:29 ` [PATCH v2 0/6] mount.nfs default version Steve Dickson

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=3210f38d54929658120ef91c5f951e04ad63fdc7.1416319371.git.bcodding@redhat.com \
    --to=bcodding@redhat.com \
    --cc=linux-nfs@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox