summaryrefslogtreecommitdiffstats
path: root/utils/mount/parse_opt.c
diff options
context:
space:
mode:
authorChuck Lever <chuck.lever@oracle.com>2009-01-27 17:41:02 -0500
committerSteve Dickson <steved@redhat.com>2009-01-27 17:41:02 -0500
commit0dcb83a870926de215307472676096056dabc9b0 (patch)
tree4db3b268848ec4bf0e334d4777de2c5bc259bc80 /utils/mount/parse_opt.c
parent29ac873f9024c8fcbca38ab09ba54cda3765b746 (diff)
downloadnfs-utils-0dcb83a870926de215307472676096056dabc9b0.tar.gz
nfs-utils-0dcb83a870926de215307472676096056dabc9b0.tar.xz
nfs-utils-0dcb83a870926de215307472676096056dabc9b0.zip
text-based mount command: make po_rightmost() work for N options
Sometimes we need to choose the rightmost option among multiple different mount options. For example, we want to find the rightmost of "proto," "tcp," and "udp". Or, the rightmost of "vers," "nfsvers," "v2," and "v3". Update po_rightmost() to choose among N options instead of just two. Signed-off-by: Steve Dickson <steved@redhat.com>
Diffstat (limited to 'utils/mount/parse_opt.c')
-rw-r--r--utils/mount/parse_opt.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/utils/mount/parse_opt.c b/utils/mount/parse_opt.c
index f61d0dd..4934508 100644
--- a/utils/mount/parse_opt.c
+++ b/utils/mount/parse_opt.c
@@ -421,34 +421,38 @@ po_found_t po_get_numeric(struct mount_options *options, char *keyword, long *va
#endif /* HAVE_STRTOL */
/**
- * po_rightmost - determine the relative position of two options
+ * po_rightmost - determine the relative position of several options
* @options: pointer to mount options
- * @key1: pointer to a C string containing an option keyword
- * @key2: pointer to a C string containing another option keyword
+ * @keys: pointer to an array of C strings containing option keywords
+ *
+ * This function can be used to determine which of several similar
+ * options will be the one to take effect.
*
* The kernel parses the mount option string from left to right.
* If an option is specified more than once (for example, "intr"
* and "nointr", the rightmost option is the last to be parsed,
* and it therefore takes precedence over previous similar options.
*
- * This function can be used to determine which of two similar
- * options will be the one to take effect.
+ * This can also distinguish among multiple synonymous options, such
+ * as "proto=," "udp" and "tcp."
+ *
+ * Returns the index into @keys of the option that is rightmost.
+ * If none of the options are present, returns zero.
*/
-po_rightmost_t po_rightmost(struct mount_options *options,
- char *key1, char *key2)
+unsigned int po_rightmost(struct mount_options *options, const char *keys[])
{
struct mount_option *option;
+ unsigned int i;
if (options) {
for (option = options->tail; option; option = option->prev) {
- if (key2 && strcmp(option->keyword, key2) == 0)
- return PO_KEY2_RIGHTMOST;
- if (key1 && strcmp(option->keyword, key1) == 0)
- return PO_KEY1_RIGHTMOST;
+ for (i = 0; keys[i] != NULL; i++)
+ if (strcmp(option->keyword, keys[i]) == 0)
+ return i;
}
}
- return PO_NEITHER_FOUND;
+ return 0;
}
/**