From: Philip Homburg Date: Fri, 5 Aug 2005 14:20:05 +0000 (+0000) Subject: Added dp8390 to /usr/etc/rc. Renamed get_mon_prm.c to env_get_prm.c. X-Git-Tag: v3.1.0~424 X-Git-Url: http://zhaoyanbai.com/repos/jquery-3.1.1.min.js?a=commitdiff_plain;h=473317e571ef846ba6a7fe3426102370641eed3b;p=minix.git Added dp8390 to /usr/etc/rc. Renamed get_mon_prm.c to env_get_prm.c. Add env_setargs call for access to argc/argv. --- diff --git a/drivers/dp8390/dp8390.c b/drivers/dp8390/dp8390.c index 393ea8951..02acde614 100644 --- a/drivers/dp8390/dp8390.c +++ b/drivers/dp8390/dp8390.c @@ -62,8 +62,6 @@ static dpeth_t de_table[DE_PORT_NR]; static u16_t eth_ign_proto; -static int arg_c; -static char **arg_v; /* Configuration */ typedef struct dp_conf @@ -175,8 +173,7 @@ int main(int argc, char *argv[]) dpeth_t *dep; long v; - arg_c= argc; - arg_v= argv; + env_setargs(argc, argv); for (i= 0, dep= de_table; ide_pci= env_prefix_x(arg_c, arg_v, envvar, "pci"))) + if (!(dep->de_pci= env_prefix(envvar, "pci"))) continue; /* no PCI config */ v= 0; - (void) env_parse_x(arg_c, arg_v, envvar, envfmt, 1, &v, 0, 255); + (void) env_parse(envvar, envfmt, 1, &v, 0, 255); dep->de_pcibus= v; v= 0; - (void) env_parse_x(arg_c, arg_v, envvar, envfmt, 2, &v, 0, 255); + (void) env_parse(envvar, envfmt, 2, &v, 0, 255); dep->de_pcidev= v; v= 0; - (void) env_parse_x(arg_c, arg_v, envvar, envfmt, 3, &v, 0, 255); + (void) env_parse(envvar, envfmt, 3, &v, 0, 255); dep->de_pcifunc= v; } @@ -826,8 +822,7 @@ dpeth_t *dep; for (i= 0; i < 6; i++) { v= dep->de_address.ea_addr[i]; - if (env_parse_x(arg_c, arg_v, - eakey, eafmt, i, &v, 0x00L, 0xFFL) != EP_SET) + if (env_parse(eakey, eafmt, i, &v, 0x00L, 0xFFL) != EP_SET) { break; } @@ -1748,8 +1743,7 @@ dp_conf_t *dcp; /* Get the default settings and modify them from the environment. */ dep->de_mode= DEM_SINK; v= dcp->dpc_port; - switch (env_parse_x(arg_c, arg_v, - dcp->dpc_envvar, dpc_fmt, 0, &v, 0x0000L, 0xFFFFL)) { + switch (env_parse(dcp->dpc_envvar, dpc_fmt, 0, &v, 0x0000L, 0xFFFFL)) { case EP_OFF: dep->de_mode= DEM_DISABLED; break; @@ -1762,18 +1756,16 @@ dp_conf_t *dcp; dep->de_base_port= v; v= dcp->dpc_irq | DEI_DEFAULT; - (void) env_parse_x(arg_c, arg_v, dcp->dpc_envvar, dpc_fmt, 1, &v, 0L, + (void) env_parse(dcp->dpc_envvar, dpc_fmt, 1, &v, 0L, (long) NR_IRQ_VECTORS - 1); dep->de_irq= v; v= dcp->dpc_mem; - (void) env_parse_x(arg_c, arg_v, - dcp->dpc_envvar, dpc_fmt, 2, &v, 0L, 0xFFFFFL); + (void) env_parse(dcp->dpc_envvar, dpc_fmt, 2, &v, 0L, 0xFFFFFL); dep->de_linmem= v; v= 0; - (void) env_parse_x(arg_c, arg_v, - dcp->dpc_envvar, dpc_fmt, 3, &v, 0x2000L, 0x8000L); + (void) env_parse(dcp->dpc_envvar, dpc_fmt, 3, &v, 0x2000L, 0x8000L); dep->de_ramsize= v; } diff --git a/etc/usr/rc b/etc/usr/rc index 87d9ff47e..13ab0bc9c 100644 --- a/etc/usr/rc +++ b/etc/usr/rc @@ -92,7 +92,7 @@ start) fi # start only network drivers that are in use - for driver in rtl8139 fxp dpeth + for driver in rtl8139 fxp dpeth dp8390 do if grep " $driver " /etc/inet.conf > /dev/null then diff --git a/include/minix/sysutil.h b/include/minix/sysutil.h index 564193ef4..f755a3b5b 100644 --- a/include/minix/sysutil.h +++ b/include/minix/sysutil.h @@ -29,16 +29,12 @@ #define EP_SET 3 /* var = 1:2:3 (nonblank field) */ #define EP_EGETKENV 4 /* sys_getkenv() failed ... */ -_PROTOTYPE( int get_mon_param, (char *key, char *value, int max_size) ); +_PROTOTYPE( void env_setargs, (int argc, char *argv[]) ); +_PROTOTYPE( int env_get_param, (char *key, char *value, int max_size) ); _PROTOTYPE( int env_prefix, (char *env, char *prefix) ); -_PROTOTYPE( int env_prefix_x, (int argc, char *argv[], - char *env, char *prefix) ); _PROTOTYPE( void env_panic, (char *key) ); _PROTOTYPE( int env_parse, (char *env, char *fmt, int field, long *param, long min, long max) ); -_PROTOTYPE( int env_parse_x, (int argc, char *argv[], char *env, - char *fmt, int field, long *param, long min, long max) ); - #define fkey_map(fkeys, sfkeys) fkey_ctl(FKEY_MAP, (fkeys), (sfkeys)) #define fkey_unmap(fkeys, sfkeys) fkey_ctl(FKEY_UNMAP, (fkeys), (sfkeys)) diff --git a/lib/sysutil/Makefile b/lib/sysutil/Makefile index 61189679a..2a894cd1f 100644 --- a/lib/sysutil/Makefile +++ b/lib/sysutil/Makefile @@ -12,7 +12,7 @@ OBJECTS = \ $(LIBUTILS)(kputc.o) \ $(LIBUTILS)(tickdelay.o) \ $(LIBUTILS)(getuptime.o) \ - $(LIBUTILS)(get_mon_prm.o) \ + $(LIBUTILS)(env_get_prm.o) \ $(LIBUTILS)(env_parse.o) \ $(LIBUTILS)(env_panic.o) \ $(LIBUTILS)(env_prefix.o) \ @@ -41,8 +41,8 @@ $(LIBUTILS)(getuptime.o): getuptime.c $(LIBUTILS)(tickdelay.o): tickdelay.c $(CC1) tickdelay.c -$(LIBUTILS)(get_mon_prm.o): get_mon_prm.c - $(CC1) get_mon_prm.c +$(LIBUTILS)(env_get_prm.o): env_get_prm.c + $(CC1) env_get_prm.c $(LIBUTILS)(env_parse.o): env_parse.c $(CC1) env_parse.c diff --git a/lib/sysutil/env_get_prm.c b/lib/sysutil/env_get_prm.c new file mode 100644 index 000000000..1d5a8710c --- /dev/null +++ b/lib/sysutil/env_get_prm.c @@ -0,0 +1,97 @@ +#include "sysutil.h" +#include +#include + +PRIVATE int argc = 0; +PRIVATE char **argv = NULL; + +FORWARD _PROTOTYPE( char *find_key, (const char *params, const char *key)); + +/*===========================================================================* + * env_setargs * + *===========================================================================*/ +PUBLIC void env_setargs(arg_c, arg_v) +int arg_c; +char *arg_v[]; +{ + argc= arg_c; + argv= arg_v; +} + +/*===========================================================================* + * env_get_param * + *===========================================================================*/ +PUBLIC int env_get_param(key, value, max_len) +char *key; /* which key to look up */ +char *value; /* where to store value */ +int max_len; /* maximum length of value */ +{ + message m; + static char mon_params[128*sizeof(char *)]; /* copy parameters here */ + char *key_value; + int i, s, keylen; + + if (key == NULL) + return EINVAL; + + keylen= strlen(key); + for (i= 1; i EP_BUF_SIZE) + return(E2BIG); + strcpy(value, key_value); + return OK; + } + + /* Get copy of boot monitor parameters. */ + m.m_type = SYS_GETINFO; + m.I_REQUEST = GET_MONPARAMS; + m.I_PROC_NR = SELF; + m.I_VAL_LEN = sizeof(mon_params); + m.I_VAL_PTR = mon_params; + if ((s=_taskcall(SYSTASK, SYS_GETINFO, &m)) != OK) { + printf("SYS_GETINFO: %d (size %u)\n", s, sizeof(mon_params)); + return(s); + } + + /* We got a copy, now search requested key. */ + if ((key_value = find_key(mon_params, key)) == NULL) + return(ESRCH); + + /* Value found, make the actual copy (as far as possible). */ + strncpy(value, key_value, max_len); + + /* See if it fits in the client's buffer. */ + if ((strlen(key_value)+1) > max_len) return(E2BIG); + return(OK); +} + + +/*==========================================================================* + * find_key * + *==========================================================================*/ +PRIVATE char *find_key(params,name) +const char *params; +const char *name; +{ + register const char *namep; + register char *envp; + + for (envp = (char *) params; *envp != 0;) { + for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++) + ; + if (*namep == '\0' && *envp == '=') + return(envp + 1); + while (*envp++ != 0) + ; + } + return(NULL); +} + diff --git a/lib/sysutil/env_panic.c b/lib/sysutil/env_panic.c index 76d503714..eb2aa11cb 100644 --- a/lib/sysutil/env_panic.c +++ b/lib/sysutil/env_panic.c @@ -9,7 +9,7 @@ char *key; /* environment variable whose value is bogus */ { static char value[EP_BUF_SIZE] = ""; int s; - if ((s=get_mon_param(key, value, sizeof(value))) == 0) { + if ((s=env_get_param(key, value, sizeof(value))) == 0) { if (s != ESRCH) /* only error allowed */ printf("WARNING: get_mon_param() failed in env_panic(): %d\n", s); } diff --git a/lib/sysutil/env_parse.c b/lib/sysutil/env_parse.c index fd9f59393..a7a876e31 100644 --- a/lib/sysutil/env_parse.c +++ b/lib/sysutil/env_parse.c @@ -12,21 +12,6 @@ char *fmt; /* template to parse it with */ int field; /* field number of value to return */ long *param; /* address of parameter to get */ long min, max; /* minimum and maximum values for the parameter */ -{ - return env_parse_x(0, NULL, env, fmt, field, param, min, max); -} - -/*=========================================================================* - * env_parse_x * - *=========================================================================*/ -PUBLIC int env_parse_x(argc, argv, env, fmt, field, param, min, max) -int argc; -char *argv[]; -char *env; /* environment variable to inspect */ -char *fmt; /* template to parse it with */ -int field; /* field number of value to return */ -long *param; /* address of parameter to get */ -long min, max; /* minimum and maximum values for the parameter */ { /* Parse an environment variable setting, something like "DPETH0=300:3". * Panic if the parsing fails. Return EP_UNSET if the environment variable @@ -46,25 +31,7 @@ long min, max; /* minimum and maximum values for the parameter */ long newpar; int s, i, radix, r, keylen; - keylen= strlen(env); - for (i= 0; i EP_BUF_SIZE) - { - printf("WARNING: env_parse() failed: argument too long\n"); - return(EP_EGETKENV); - } - strcpy(value, val); - } - - if (i >= argc && (s=get_mon_param(env, value, sizeof(value))) != 0) { + if ((s=env_get_param(env, value, sizeof(value))) != 0) { if (s == ESRCH) return(EP_UNSET); /* only error allowed */ printf("WARNING: get_mon_param() failed in env_parse(): %d\n",s); return(EP_EGETKENV); diff --git a/lib/sysutil/env_prefix.c b/lib/sysutil/env_prefix.c index 9f1e0deb9..b660255ca 100644 --- a/lib/sysutil/env_prefix.c +++ b/lib/sysutil/env_prefix.c @@ -8,19 +8,6 @@ PUBLIC int env_prefix(env, prefix) char *env; /* environment variable to inspect */ char *prefix; /* prefix to test for */ -{ - return env_prefix_x(0, NULL, env, prefix); -} - - -/*=========================================================================* - * env_prefix_x * - *=========================================================================*/ -PUBLIC int env_prefix_x(argc, argv, env, prefix) -int argc; -char *argv[]; -char *env; /* environment variable to inspect */ -char *prefix; /* prefix to test for */ { /* An environment setting may be prefixed by a word, usually "pci". * Return TRUE if a given prefix is used. @@ -31,26 +18,7 @@ char *prefix; /* prefix to test for */ char *val; size_t n; - keylen= strlen(env); - for (i= 0; i EP_BUF_SIZE) - { - printf("WARNING: env_parse() failed: argument too long\n"); - return(EP_EGETKENV); - } - strcpy(value, val); - } - - if (i >= argc && (s = get_mon_param(env, value, sizeof(value))) != 0) { + if ((s = env_get_param(env, value, sizeof(value))) != 0) { if (s != ESRCH) /* only error allowed */ printf("WARNING: get_mon_param() failed in env_prefix(): %d\n", s); } diff --git a/lib/sysutil/get_mon_prm.c b/lib/sysutil/get_mon_prm.c deleted file mode 100644 index 4f0489cc6..000000000 --- a/lib/sysutil/get_mon_prm.c +++ /dev/null @@ -1,67 +0,0 @@ -#include "sysutil.h" -#include -#include - -FORWARD _PROTOTYPE( char *find_key, (const char *params, const char *key)); - -/*===========================================================================* - * get_mon_param * - *===========================================================================*/ -PUBLIC int get_mon_param(key, value, max_len) -char *key; /* which key to look up */ -char *value; /* where to store value */ -int max_len; /* maximum length of value */ -{ - message m; - static char mon_params[128*sizeof(char *)]; /* copy parameters here */ - char *key_value; - int s; - - if (key != NULL) { - /* Get copy of boot monitor parameters. */ - m.m_type = SYS_GETINFO; - m.I_REQUEST = GET_MONPARAMS; - m.I_PROC_NR = SELF; - m.I_VAL_LEN = sizeof(mon_params); - m.I_VAL_PTR = mon_params; - if ((s=_taskcall(SYSTASK, SYS_GETINFO, &m)) != OK) { - printf("SYS_GETINFO: %d (size %u)\n", s, sizeof(mon_params)); - return(s); - } - - /* We got a copy, now search requested key. */ - if ((key_value = find_key(mon_params, key)) == NULL) - return(ESRCH); - - /* Value found, make the actual copy (as far as possible). */ - strncpy(value, key_value, max_len); - - /* See if it fits in the client's buffer. */ - if ((strlen(key_value)+1) > max_len) return(E2BIG); - return(OK); - } - return(EINVAL); -} - - -/*==========================================================================* - * find_key * - *==========================================================================*/ -PRIVATE char *find_key(params,name) -const char *params; -const char *name; -{ - register const char *namep; - register char *envp; - - for (envp = (char *) params; *envp != 0;) { - for (namep = name; *namep != 0 && *namep == *envp; namep++, envp++) - ; - if (*namep == '\0' && *envp == '=') - return(envp + 1); - while (*envp++ != 0) - ; - } - return(NULL); -} -