mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [CFT] [5/15] autofs4 options parsing
@ 2003-09-05 18:55 Randy.Dunlap
  0 siblings, 0 replies; only message in thread
From: Randy.Dunlap @ 2003-09-05 18:55 UTC (permalink / raw)
  To: lkml; +Cc: fsdev


diff -Naurp -X /home/rddunlap/doc/dontdiff-osdl linux-260-test4-pv/fs/autofs4/inode.c linux-260-test4-fs/fs/autofs4/inode.c
--- linux-260-test4-pv/fs/autofs4/inode.c	2003-08-22 16:58:08.000000000 -0700
+++ linux-260-test4-fs/fs/autofs4/inode.c	2003-08-27 11:19:07.000000000 -0700
@@ -14,6 +14,7 @@
 #include <linux/slab.h>
 #include <linux/file.h>
 #include <linux/pagemap.h>
+#include <linux/parser.h>
 #include <asm/bitops.h>
 #include "autofs_i.h"
 #include <linux/module.h>
@@ -94,10 +95,23 @@ static struct super_operations autofs4_s
 	.statfs		= simple_statfs,
 };
 
+enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto};
+
+static match_table_t tokens = {
+	{Opt_fd, "fd=%d"},
+	{Opt_uid, "uid=%d"},
+	{Opt_gid, "gid=%d"},
+	{Opt_pgrp, "pgrp=%d"},
+	{Opt_minproto, "minproto=%d"},
+	{Opt_maxproto, "maxproto=%d"},
+	{Opt_err, NULL}
+};
+
 static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
 			 pid_t *pgrp, int *minproto, int *maxproto)
 {
-	char *this_char, *value;
+	char *p;
+	substring_t args[MAX_OPT_ARGS];
 	
 	*uid = current->uid;
 	*gid = current->gid;
@@ -108,55 +122,37 @@ static int parse_options(char *options, 
 
 	*pipefd = -1;
 
-	if ( !options ) return 1;
-	while ((this_char = strsep(&options,",")) != NULL) {
-		if (!*this_char)
+	if (!options)
+		return 1;
+
+	while ((p = strsep(&options, ",")) != NULL) {
+		int token;
+		if (!*p)
 			continue;
-		if ((value = strchr(this_char,'=')) != NULL)
-			*value++ = 0;
-		if (!strcmp(this_char,"fd")) {
-			if (!value || !*value)
-				return 1;
-			*pipefd = simple_strtoul(value,&value,0);
-			if (*value)
-				return 1;
-		}
-		else if (!strcmp(this_char,"uid")) {
-			if (!value || !*value)
-				return 1;
-			*uid = simple_strtoul(value,&value,0);
-			if (*value)
-				return 1;
-		}
-		else if (!strcmp(this_char,"gid")) {
-			if (!value || !*value)
-				return 1;
-			*gid = simple_strtoul(value,&value,0);
-			if (*value)
-				return 1;
-		}
-		else if (!strcmp(this_char,"pgrp")) {
-			if (!value || !*value)
-				return 1;
-			*pgrp = simple_strtoul(value,&value,0);
-			if (*value)
-				return 1;
-		}
-		else if (!strcmp(this_char,"minproto")) {
-			if (!value || !*value)
-				return 1;
-			*minproto = simple_strtoul(value,&value,0);
-			if (*value)
-				return 1;
-		}
-		else if (!strcmp(this_char,"maxproto")) {
-			if (!value || !*value)
-				return 1;
-			*maxproto = simple_strtoul(value,&value,0);
-			if (*value)
+
+		token = match_token(p, tokens, args);
+		switch (token) {
+			case Opt_fd:
+				*pipefd = match_int(args);
+				break;
+			case Opt_uid:
+				*uid = match_int(args);
+				break;
+			case Opt_gid:
+				*gid = match_int(args);
+				break;
+			case Opt_pgrp:
+				*pgrp = match_int(args);
+				break;
+			case Opt_minproto:
+				*minproto = match_int(args);
+				break;
+			case Opt_maxproto:
+				*maxproto = match_int(args);
+				break;
+			default:
 				return 1;
 		}
-		else break;
 	}
 	return (*pipefd < 0);
 }


--
~Randy

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-09-05 19:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-05 18:55 [CFT] [5/15] autofs4 options parsing Randy.Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®