[PATCH] final support for MODULE_PARAM as kernel commandline

Richard Guenther (zxmpm11@student.uni-tuebingen.de)
Sun, 12 Sep 1999 12:02:53 +0200 (METDST)


Hi!

This is the final version of the patch that allows compiled
in modules which use MODULE_PARAM get their parameters from
the kernel command line. The code has been cleaned up wrt.
formatting and 's' support is there (as far as the kernel
command line allows).

Please apply (well its sent to Alan, as Linus is not here...).

Richard.

--
Richard Guenther <richard.guenther@student.uni-tuebingen.de>
PGP: 2E829319 - 2F 83 FC 93 E9 E4 19 E2 93 7A 32 42 45 37 23 57
WWW: http://www.anatom.uni-tuebingen.de/~richi/

--- linux-2.3.16/lib/Makefile.original Sat Sep 11 15:45:57 1999 +++ linux-2.3.16/lib/Makefile Sat Sep 11 16:29:13 1999 @@ -7,6 +7,6 @@ # L_TARGET := lib.a -L_OBJS := errno.o ctype.o string.o vsprintf.o +L_OBJS := errno.o ctype.o string.o vsprintf.o parse.o include $(TOPDIR)/Rules.make --- linux-2.3.16/lib/parse.c.original Sat Sep 11 16:28:05 1999 +++ linux-2.3.16/lib/parse.c Sat Sep 11 20:07:59 1999 @@ -0,0 +1,97 @@ +/* + * linux/lib/parse.c + * + * (C) Richard Guenther <richard.guenther@student.uni-tuebingen.de> + * + * Heavily based on parts of modutil's insmod.c which is + * + * Copyright 1996, 1997 Linux International. + * + * New implementation contributed by Richard Henderson <rth@tamu.edu> + * Based on original work by Bjorn Eckwall <bj0rn@blox.se> + * + * This file is part of the Linux modutils. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <linux/kernel.h> +#include <linux/ctype.h> +#include <linux/string.h> + +/* parse module parameters like insmod */ +int parse_parameters(void *var, char *type, char *str) +{ + char *p, t; + long min, max, val, cnt; + + p = type; + if (isdigit(*p)) { + min = simple_strtoul(p, &p, 0); + if (*p == '-') + max = simple_strtoul(p+1, &p, 0); + else + max = min; + } else + min = max = 1; + t = *p; + + p = str; + cnt = 0; + do { + if (*p == ',') { + p++; + cnt++; + continue; + } + switch (t) { + case 'b': + val = simple_strtol(p, &p, 0); + ((char *)var)[cnt] = (char)val; + break; + case 'h': + val = simple_strtol(p, &p, 0); + ((short *)var)[cnt] = (short)val; + break; + case 'i': + val = simple_strtol(p, &p, 0); + ((int *)var)[cnt] = (int)val; + break; + case 'l': + val = simple_strtol(p, &p, 0); + ((long *)var)[cnt] = (long)val; + break; + case 's': + /* complex quoting is not possible, as parse_options() + * just searches for ' ', so we can safely just leech + * the whole string (multiple strings are impossible, too) + * - where do we check for overflows?? */ + strcpy((char *)var, p); + break; + default: + printk(KERN_INFO "error in parsing arguments \"%s\" using format %s\n", str, type); + return 0; + } + if (*p == ',') + p++; + cnt++; + } while (*p && cnt < max); + + return 1; +} + + + + --- linux-2.3.16/include/linux/module.h.original Sat Sep 11 15:04:03 1999 +++ linux-2.3.16/include/linux/module.h Sat Sep 11 16:08:09 1999 @@ -8,6 +8,7 @@ #define _LINUX_MODULE_H #include <linux/config.h> +#include <linux/init.h> #ifdef __GENKSYMS__ # define _set_ver(sym) sym @@ -207,11 +208,17 @@ #endif #else /* MODULE */ - +extern int parse_parameters(void *var, char *type, char *str); #define MODULE_AUTHOR(name) #define MODULE_DESCRIPTION(desc) #define MODULE_SUPPORTED_DEVICE(name) -#define MODULE_PARM(var,type) +#define MODULE_PARM(var,type) \ +static char *modparm##var##_setup_type __initdata = type;\ +static int __init modparm##var##_setup(char *str)\ +{\ + return parse_parameters(var, modparm##var##_setup_type, str);\ +}\ +__setup(#var "=", modparm##var##_setup); #define MODULE_PARM_DESC(var,desc) #ifndef __GENKSYMS__

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/