From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S265988AbTIETaf (ORCPT ); Fri, 5 Sep 2003 15:30:35 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S265852AbTIETQu (ORCPT ); Fri, 5 Sep 2003 15:16:50 -0400 Received: from fw.osdl.org ([65.172.181.6]:20369 "EHLO mail.osdl.org") by vger.kernel.org with ESMTP id S265771AbTIETKH (ORCPT ); Fri, 5 Sep 2003 15:10:07 -0400 Date: Fri, 5 Sep 2003 11:55:20 -0700 From: "Randy.Dunlap" To: lkml Cc: fsdev Subject: [CFT] [5/15] autofs4 options parsing Message-Id: <20030905115520.1d8a9ea7.rddunlap@osdl.org> Organization: OSDL X-Mailer: Sylpheed version 0.9.4 (GTK+ 1.2.10; i686-pc-linux-gnu) X-Face: +5V?h'hZQPB9kW Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org 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 #include #include +#include #include #include "autofs_i.h" #include @@ -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