diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/config/config.h | 15 | ||||
-rw-r--r-- | usr.sbin/config/config.y | 366 | ||||
-rw-r--r-- | usr.sbin/config/configvers.h | 4 | ||||
-rw-r--r-- | usr.sbin/config/lang.l | 8 | ||||
-rw-r--r-- | usr.sbin/config/main.c | 28 | ||||
-rw-r--r-- | usr.sbin/config/mkmakefile.c | 35 | ||||
-rw-r--r-- | usr.sbin/config/mkswapconf.c | 203 |
7 files changed, 45 insertions, 614 deletions
diff --git a/usr.sbin/config/config.h b/usr.sbin/config/config.h index d7f009b..f9f2d2c 100644 --- a/usr.sbin/config/config.h +++ b/usr.sbin/config/config.h @@ -57,25 +57,15 @@ struct file_list { * root device, etc. for system specifications */ union { - struct { /* when swap specification */ - dev_t fuw_swapdev; - int fuw_swapsize; - int fuw_swapflag; - } fuw; struct { /* when system specification */ - dev_t fus_rootdev; - dev_t fus_dumpdev; + char * fus_rootdev; } fus; struct { /* when component dev specification */ dev_t fup_compdev; int fup_compinfo; } fup; } fun; -#define f_swapdev fun.fuw.fuw_swapdev -#define f_swapsize fun.fuw.fuw_swapsize -#define f_swapflag fun.fuw.fuw_swapflag #define f_rootdev fun.fus.fus_rootdev -#define f_dumpdev fun.fus.fus_dumpdev #define f_compdev fun.fup.fup_compdev #define f_compinfo fun.fup.fup_compinfo }; @@ -183,8 +173,6 @@ char *get_quoted_word __P((FILE *)); char *path __P((char *)); char *raisestr __P((char *)); void moveifchanged __P((const char *, const char *)); -dev_t nametodev __P((char *, int, int, char)); -char *devtoname __P((dev_t)); void init_dev __P((struct device *)); void newbus_ioconf __P((void)); int yyparse __P((void)); @@ -207,7 +195,6 @@ extern int profiling; extern int debugging; extern int maxusers; -extern u_int loadaddress; extern int old_config_present; /* Old config/build directory still there */ diff --git a/usr.sbin/config/config.y b/usr.sbin/config/config.y index 8959e6c..eaa9346 100644 --- a/usr.sbin/config/config.y +++ b/usr.sbin/config/config.y @@ -6,13 +6,11 @@ %token AND %token ANY -%token ARGS %token AT %token BIO %token BUS %token CAM %token COMMA -%token CONFIG %token CONFLICTS %token CONTROLLER %token CPU @@ -21,7 +19,6 @@ %token DISK %token DRIVE %token DRQ -%token DUMPS %token EQUALS %token FLAGS %token IDENT @@ -36,18 +33,15 @@ %token MINUS %token NET %token NEXUS -%token ON %token OPTIONS %token MAKEOPTIONS %token PORT %token PRIORITY %token PSEUDO_DEVICE -%token ROOT %token SEMICOLON %token SEQUENTIAL %token SIZE %token SLAVE -%token SWAP %token TARGET %token TTY %token TRACE @@ -62,10 +56,6 @@ %type <str> Opt_value %type <str> Dev %type <str> device_name -%type <val> major_minor -%type <val> root_device_spec root_device_specs -%type <val> dump_device_spec -%type <file> swap_device_spec %{ @@ -104,9 +94,6 @@ * @(#)config.y 8.1 (Berkeley) 6/6/93 */ -#include <sys/disklabel.h> -#include <sys/diskslice.h> - #include <ctype.h> #include <err.h> #include <stdio.h> @@ -120,7 +107,7 @@ static struct device *curp = 0; struct device *dtab; char *ident; int yyline; -struct file_list *ftab, *conf_list, **confp, *comp_list, **compp; +struct file_list *ftab, *conf_list, **confp; char errbuf[80]; int maxusers; int do_trace; @@ -129,12 +116,8 @@ int seen_scbus; #define ns(s) strdup(s) -static int alreadychecked __P((dev_t, dev_t[], dev_t *)); -static void deverror __P((char *, char *)); -static int finddev __P((dev_t)); static struct device *connect __P((char *, int)); static struct device *huhcon __P((char *)); -static dev_t *verifyswap __P((struct file_list *, dev_t *, dev_t *)); static void yyerror __P((char *s)); @@ -142,7 +125,6 @@ static void yyerror __P((char *s)); %% Configuration: Many_specs - = { verifysystemspecs(); } ; Many_specs: @@ -193,155 +175,9 @@ Config_spec: | IDENT ID = { ident = $2; } | - System_spec - | MAXUSERS NUMBER = { maxusers = $2; }; -System_spec: - System_id System_parameter_list - = { checksystemspec(*confp); } - ; - -System_id: - CONFIG Save_id - = { mkconf($2); } - ; - -System_parameter_list: - System_parameter_list System_parameter - | System_parameter - ; - -System_parameter: - addr_spec - | swap_spec - | root_spec - | dump_spec - | arg_spec - ; - -addr_spec: - AT NUMBER - = { loadaddress = $2; } - ; - -swap_spec: - SWAP optional_on swap_device_list - = { yyerror("swap specification obsolete, ignored"); } - ; - -swap_device_list: - swap_device_list AND swap_device - | swap_device - ; - -swap_device: - swap_device_spec optional_size optional_sflag - ; - -swap_device_spec: - device_name - = { - struct file_list *fl = newflist(SWAPSPEC); - - if (eq($1, "generic")) - fl->f_fn = $1; - else { - fl->f_swapdev = nametodev($1, 0, - COMPATIBILITY_SLICE, 'b'); - fl->f_fn = devtoname(fl->f_swapdev); - } - $$ = fl; - } - | major_minor - = { - struct file_list *fl = newflist(SWAPSPEC); - - fl->f_swapdev = $1; - fl->f_fn = devtoname($1); - $$ = fl; - } - ; - -root_spec: - ROOT optional_on root_device_specs - = { - struct file_list *fl = *confp; - - if (fl && fl->f_rootdev != NODEV) - yyerror("extraneous root device specification"); - else - fl->f_rootdev = $3; - } - ; - -root_device_specs: - root_device_spec AND root_device_specs - = { - warnx("extraneous root devices ignored"); - $$ = $1; - } - | root_device_spec - ; - -root_device_spec: - device_name - = { $$ = nametodev($1, 0, COMPATIBILITY_SLICE, 'a'); } - | major_minor - ; - -dump_spec: - DUMPS optional_on dump_device_spec - = { - struct file_list *fl = *confp; - - if (fl && fl->f_dumpdev != NODEV) - yyerror("extraneous dump device specification"); - else - fl->f_dumpdev = $3; - } - - ; - -dump_device_spec: - device_name - = { $$ = nametodev($1, 0, COMPATIBILITY_SLICE, 'b'); } - | major_minor - ; - -arg_spec: - ARGS optional_on arg_device_spec - = { yyerror("arg device specification obsolete, ignored"); } - ; - -arg_device_spec: - device_name - | major_minor - ; - -major_minor: - MAJOR NUMBER MINOR NUMBER - = { $$ = makedev($2, $4); } - ; - -optional_on: - ON - | /* empty */ - ; - -optional_size: - SIZE NUMBER - = { yyerror("`size nnn' swap spec obsolete"); } - | /* empty */ - ; - -optional_sflag: - SEQUENTIAL - = { yyerror("`sequential' swap spec obsolete"); } - | /* empty */ - ; - device_name: Save_id = { $$ = $1; } @@ -611,28 +447,6 @@ newdev(dp) curp = np; } -/* - * note that a configuration should be made - */ -static void -mkconf(sysname) - char *sysname; -{ - register struct file_list *fl, **flp; - - fl = (struct file_list *) malloc(sizeof *fl); - memset(fl, 0, sizeof(*fl)); - fl->f_type = SYSTEMSPEC; - fl->f_needs = sysname; - fl->f_rootdev = NODEV; - fl->f_dumpdev = NODEV; - fl->f_fn = 0; - fl->f_next = 0; - for (flp = confp; *flp; flp = &(*flp)->f_next) - ; - *flp = fl; - confp = flp; -} static struct file_list * newflist(ftype) @@ -643,55 +457,12 @@ newflist(ftype) fl->f_type = ftype; fl->f_next = 0; - fl->f_swapdev = NODEV; - fl->f_swapsize = 0; fl->f_needs = 0; fl->f_fn = 0; return (fl); } /* - * Add a swap device to the system's configuration - */ -static void -mkswap(system, fl, size, flag) - struct file_list *system, *fl; - int size, flag; -{ - register struct file_list **flp; - - if (system == 0 || system->f_type != SYSTEMSPEC) { - yyerror("\"swap\" spec precedes \"config\" specification"); - return; - } - if (size < 0) { - yyerror("illegal swap partition size"); - return; - } - /* - * Append swap description to the end of the list. - */ - flp = &system->f_next; - for (; *flp && (*flp)->f_type == SWAPSPEC; flp = &(*flp)->f_next) - ; - fl->f_next = *flp; - *flp = fl; - fl->f_swapsize = size; - fl->f_swapflag = flag; - /* - * If first swap device for this system, - * set up f_fn field to insure swap - * files are created with unique names. - */ - if (system->f_fn) - return; - if (eq(fl->f_fn, "generic")) - system->f_fn = ns(fl->f_fn); - else - system->f_fn = ns(system->f_needs); -} - -/* * find the pointer to connect to the given device and number. * returns 0 if no such device and prints an error message */ @@ -841,140 +612,5 @@ checksystemspec(fl) } swap = fl->f_next; generic = swap && swap->f_type == SWAPSPEC && eq(swap->f_fn, "generic"); - if (fl->f_rootdev == NODEV && !generic) { - yyerror("no root device specified"); - exit(1); - } - /* - * Default swap area to be in 'b' partition of root's - * device. If root specified to be other than on 'a' - * partition, give warning, something probably amiss. - */ - if (swap == 0 || swap->f_type != SWAPSPEC) { - dev_t dev; - - swap = newflist(SWAPSPEC); - dev = fl->f_rootdev; - if (dkpart(dev) != 0) { - (void) snprintf(buf, sizeof(buf), -"Warning, swap defaulted to 'b' partition with root on '%c' partition", - dkpart(dev) + 'a'); - yyerror(buf); - } - swap->f_swapdev = dkmodpart(dev, SWAP_PART); - swap->f_fn = devtoname(swap->f_swapdev); - mkswap(fl, swap, 0); - } - /* - * Make sure a generic swap isn't specified, along with - * other stuff (user must really be confused). - */ - if (generic) { - if (fl->f_rootdev != NODEV) - yyerror("root device specified with generic swap"); - if (fl->f_dumpdev != NODEV) - yyerror("dump device specified with generic swap"); - return; - } - /* - * Warn if dump device is not a swap area. - */ - if (fl->f_dumpdev != NODEV && fl->f_dumpdev != swap->f_swapdev) { - struct file_list *p = swap->f_next; - - for (; p && p->f_type == SWAPSPEC; p = p->f_next) - if (fl->f_dumpdev == p->f_swapdev) - return; - (void) snprintf(buf, sizeof(buf), - "Warning: dump device is not a swap partition"); - yyerror(buf); - } } -/* - * Verify all devices specified in the system specification - * are present in the device specifications. - */ -static void -verifysystemspecs() -{ - register struct file_list *fl; - dev_t checked[50]; - register dev_t *pchecked = checked; - - for (fl = conf_list; fl; fl = fl->f_next) { - if (fl->f_type != SYSTEMSPEC) - continue; - if (!finddev(fl->f_rootdev)) - deverror(fl->f_needs, "root"); - *pchecked++ = fl->f_rootdev; - pchecked = verifyswap(fl->f_next, checked, pchecked); - if (!alreadychecked(fl->f_dumpdev, checked, pchecked)) { - if (!finddev(fl->f_dumpdev)) - deverror(fl->f_needs, "dump"); - *pchecked++ = fl->f_dumpdev; - } - } -} - -/* - * Do as above, but for swap devices. - */ -static dev_t * -verifyswap(fl, checked, pchecked) - register struct file_list *fl; - dev_t checked[]; - register dev_t *pchecked; -{ - - for (;fl && fl->f_type == SWAPSPEC; fl = fl->f_next) { - if (eq(fl->f_fn, "generic")) - continue; - if (alreadychecked(fl->f_swapdev, checked, pchecked)) - continue; - if (!finddev(fl->f_swapdev)) - warnx("swap device %s not configured", fl->f_fn); - *pchecked++ = fl->f_swapdev; - } - return (pchecked); -} - -/* - * Has a device already been checked - * for its existence in the configuration? - */ -static int -alreadychecked(dev, list, last) - dev_t dev, list[]; - register dev_t *last; -{ - register dev_t *p; - - for (p = list; p < last; p++) - if (dkmodpart(*p, 0) != dkmodpart(dev, 0)) - return (1); - return (0); -} - -static void -deverror(systemname, devtype) - char *systemname, *devtype; -{ - - warnx("%s: %s device not configured", systemname, devtype); -} - -/* - * Look for the device in the list of - * configured hardware devices. Must - * take into account stuff wildcarded. - */ -/*ARGSUSED*/ -static int -finddev(dev) - dev_t dev; -{ - - /* punt on this right now */ - return (1); -} diff --git a/usr.sbin/config/configvers.h b/usr.sbin/config/configvers.h index 0714c59..f55d5e2 100644 --- a/usr.sbin/config/configvers.h +++ b/usr.sbin/config/configvers.h @@ -6,6 +6,6 @@ * The numbering scheme is inspired by the sys/conf/newvers.sh RELDATE * and <osreldate.h> system. * - * $Id: configvers.h,v 1.12 1999/04/16 21:28:10 peter Exp $ + * $Id: configvers.h,v 1.13 1999/04/24 21:38:48 peter Exp $ */ -#define CONFIGVERS 400014 +#define CONFIGVERS 400015 diff --git a/usr.sbin/config/lang.l b/usr.sbin/config/lang.l index 3e47f5e..f1061f6 100644 --- a/usr.sbin/config/lang.l +++ b/usr.sbin/config/lang.l @@ -52,13 +52,11 @@ struct kt { int kt_val; } key_words[] = { { "and", AND }, - { "args", ARGS }, { "at", AT }, { "bio", BIO }, /* XXX going away */ { "bus", BUS }, { "cam", CAM }, /* XXX going away */ { "conflicts", CONFLICTS }, - { "config", CONFIG }, { "controller", CONTROLLER }, { "cpu", CPU }, { "device", DEVICE }, @@ -66,7 +64,6 @@ struct kt { { "disk", DISK }, { "drive", DRIVE }, { "drq", DRQ }, - { "dumps", DUMPS }, { "flags", FLAGS }, { "ident", IDENT }, { "iomem", IOMEM }, @@ -80,16 +77,13 @@ struct kt { { "minor", MINOR }, { "net", NET }, /* XXX going away */ { "nexus", NEXUS }, - { "on", ON }, { "options", OPTIONS }, { "port", PORT }, { "priority", PRIORITY }, { "pseudo-device",PSEUDO_DEVICE }, - { "root", ROOT }, { "sequential", SEQUENTIAL }, { "size", SIZE }, { "slave", SLAVE }, - { "swap", SWAP }, { "tape", DEVICE }, { "target", TARGET }, { "tty", TTY }, /* XXX going away */ @@ -128,7 +122,7 @@ ID [A-Za-z_][-A-Za-z_0-9]* if ((i = kw_lookup(yytext)) == -1) REJECT; if (i == CONTROLLER || i == DEVICE || i == DISK || - i == PSEUDO_DEVICE || i == AT || i == ON) + i == PSEUDO_DEVICE || i == AT) BEGIN NONUM; tprintf("(%s) ", yytext); return i; diff --git a/usr.sbin/config/main.c b/usr.sbin/config/main.c index 3f7e106..7088c08 100644 --- a/usr.sbin/config/main.c +++ b/usr.sbin/config/main.c @@ -42,7 +42,7 @@ static const char copyright[] = static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: main.c,v 1.31 1999/04/18 13:36:29 peter Exp $"; + "$Id: main.c,v 1.32 1999/04/24 18:59:19 peter Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -70,12 +70,33 @@ static int no_config_clobber = TRUE; int old_config_present; int debugging; int profiling; -u_int loadaddress; static void usage __P((void)); static void configfile __P((void)); /* + * note that a configuration should be made + */ +static void +mkconf(sysname) + char *sysname; +{ + register struct file_list *fl, **flp; + + fl = (struct file_list *) malloc(sizeof *fl); + memset(fl, 0, sizeof(*fl)); + fl->f_type = SYSTEMSPEC; + fl->f_needs = sysname; + fl->f_rootdev = 0; + fl->f_fn = 0; + fl->f_next = 0; + for (flp = confp; *flp; flp = &(*flp)->f_next) + ; + *flp = fl; + confp = flp; +} + +/* * Config builds a set of files for building a UNIX * system given a description of the desired system. */ @@ -143,10 +164,9 @@ main(argc, argv) else old_config_present = 1; - loadaddress = -1; dtab = NULL; confp = &conf_list; - compp = &comp_list; + mkconf("kernel"); if (yyparse()) exit(3); switch (machine) { diff --git a/usr.sbin/config/mkmakefile.c b/usr.sbin/config/mkmakefile.c index e1dfa2b..c0cd35d 100644 --- a/usr.sbin/config/mkmakefile.c +++ b/usr.sbin/config/mkmakefile.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)mkmakefile.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: mkmakefile.c,v 1.40 1999/04/19 13:53:07 peter Exp $"; + "$Id: mkmakefile.c,v 1.41 1999/04/24 18:59:19 peter Exp $"; #endif /* not lint */ /* @@ -73,7 +73,6 @@ static const char rcsid[] = static struct file_list *fcur; static char *tail __P((char *)); -static void do_swapspec __P((FILE *, char *)); static void do_clean __P((FILE *)); static void do_load __P((FILE *)); static void do_rules __P((FILE *)); @@ -178,9 +177,6 @@ makefile() } } fprintf(ofp, "\n"); - if (loadaddress != -1) { - fprintf(ofp, "LOAD_ADDRESS=%X\n", loadaddress); - } for (op = mkopt; op; op = op->op_next) fprintf(ofp, "%s=%s\n", op->op_name, op->op_value); if (debugging) @@ -569,7 +565,7 @@ do_objs(fp) for (fl = conf_list; fl; fl = fl->f_next) { if (fl->f_type != SWAPSPEC) continue; - (void) snprintf(swapname, sizeof(swapname), "swap%s.c", fl->f_fn); + (void) snprintf(swapname, sizeof(swapname), "swapkernel.c"); if (eq(sp, swapname)) goto cont; } @@ -618,16 +614,12 @@ do_cfiles(fp) } for (fl = conf_list; fl; fl = fl->f_next) if (fl->f_type == SYSTEMSPEC) { - (void) snprintf(swapname, sizeof(swapname), "swap%s.c", fl->f_fn); + (void) snprintf(swapname, sizeof(swapname), "swapkernel.c"); if ((len = 3 + strlen(swapname)) + lpos > 72) { lpos = 8; fputs("\\\n\t", fp); } - if (eq(fl->f_fn, "generic")) - fprintf(fp, "$S/%s/%s/%s ", - machinename, machinename, swapname); - else - fprintf(fp, "%s ", swapname); + fprintf(fp, "%s ", swapname); lpos += len + 1; } if (lpos != 8) @@ -823,33 +815,18 @@ do_systemspec(f, fl, first) { fprintf(f, "KERNEL=\t%s\n", fl->f_needs); - fprintf(f, "${FULLKERNEL}: ${SYSTEM_DEP} swap%s.o", fl->f_fn); + fprintf(f, "${FULLKERNEL}: ${SYSTEM_DEP}"); if (first) fprintf(f, " vers.o"); fprintf(f, "\n\t${SYSTEM_LD_HEAD}\n"); - fprintf(f, "\t${SYSTEM_LD} swap%s.o\n", fl->f_fn); + fprintf(f, "\t${SYSTEM_LD}\n", fl->f_fn); fprintf(f, "\t${SYSTEM_LD_TAIL}\n\n"); - do_swapspec(f, fl->f_fn); for (fl = fl->f_next; fl; fl = fl->f_next) if (fl->f_type != SWAPSPEC) break; return (fl); } -static void -do_swapspec(f, name) - FILE *f; - register char *name; -{ - - if (!eq(name, "generic")) - fprintf(f, "swap%s.o: swap%s.c\n", name, name); - else - fprintf(f, "swapgeneric.o: $S/%s/%s/swapgeneric.c\n", - machinename, machinename); - fprintf(f, "\t${NORMAL_C}\n\n"); -} - char * raisestr(str) register char *str; diff --git a/usr.sbin/config/mkswapconf.c b/usr.sbin/config/mkswapconf.c index 255cbf6..7095f04 100644 --- a/usr.sbin/config/mkswapconf.c +++ b/usr.sbin/config/mkswapconf.c @@ -36,7 +36,7 @@ static char sccsid[] = "@(#)mkswapconf.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$Id: mkswapconf.c,v 1.18 1999/04/18 13:36:29 peter Exp $"; + "$Id: mkswapconf.c,v 1.19 1999/04/24 18:59:19 peter Exp $"; #endif /* not lint */ /* @@ -45,23 +45,19 @@ static const char rcsid[] = #include <err.h> #include <unistd.h> -#include <sys/disklabel.h> -#include <sys/diskslice.h> - #include <ctype.h> #include <stdio.h> #include <string.h> #include "config.h" -#define ns(s) strdup(s) - -static void initdevtable __P((void)); -static struct file_list *do_swap __P((struct file_list *)); - void swapconf() { + FILE *fp; + char newswapname[80]; + char swapname[80]; + register struct file_list *swap; register struct file_list *fl; fl = conf_list; @@ -70,199 +66,20 @@ swapconf() fl = fl->f_next; continue; } - fl = do_swap(fl); + break; } -} - -static struct file_list * -do_swap(fl) - register struct file_list *fl; -{ - FILE *fp; - char newswapname[80]; - char swapname[80]; - register struct file_list *swap; - if (eq(fl->f_fn, "generic")) { - fl = fl->f_next; - return (fl->f_next); - } - (void) snprintf(swapname, sizeof(swapname), "swap%s.c", fl->f_fn); - (void) snprintf(newswapname, sizeof(newswapname), "swap%s.c.new", fl->f_fn); + (void) snprintf(swapname, sizeof(swapname), "swapkernel.c"); + (void) snprintf(newswapname, sizeof(newswapname), "swapkernel.c.new"); fp = fopen(path(newswapname), "w"); if (fp == 0) err(1, "%s", path(newswapname)); fprintf(fp, "#include <sys/param.h>\n"); fprintf(fp, "#include <sys/conf.h>\n"); fprintf(fp, "\n"); - /* - * If there aren't any swap devices - * specified, just return, the error - * has already been noted. - */ - swap = fl->f_next; - if (swap == 0 || swap->f_type != SWAPSPEC) { - (void) unlink(path(newswapname)); - fclose(fp); - return (swap); - } - fprintf(fp, "dev_t\trootdev = makedev(%d, 0x%08x);\t\t/* %s */\n", - major(fl->f_rootdev), minor(fl->f_rootdev), - devtoname(fl->f_rootdev)); - if (fl->f_dumpdev != NODEV) { - fprintf(fp, "dev_t\tdumpdev = makedev(%d, 0x%08x);\t\t/* %s */\n", - major(fl->f_dumpdev), minor(fl->f_dumpdev), - devtoname(fl->f_dumpdev)); - } else { - fprintf(fp, "dev_t\tdumpdev = NODEV;\t\t\t/* unconfigured */\n"); - } + fprintf(fp, "char\t*rootdevname = \"%s\";\n", fl->f_rootdev); fclose(fp); moveifchanged(path(newswapname), path(swapname)); - return (swap); -} - -static int devtablenotread = 1; -static struct devdescription { - char *dev_name; - int dev_major; - struct devdescription *dev_next; -} *devtable; - -/* - * Given a device name specification figure out: - * major device number - * partition - * device name - * unit number - * This is a hack, but the system still thinks in - * terms of major/minor instead of string names. - */ -dev_t -nametodev(name, defunit, defslice, defpartition) - char *name; - int defunit; - int defslice; - char defpartition; -{ - char *cp, partition; - int unit, slice; - register struct devdescription *dp; - - cp = name; - if (cp == 0) - errx(1, "internal error, nametodev"); - while (*cp && !isdigit(*cp)) - cp++; - unit = *cp ? atoi(cp) : defunit; - if (unit < 0 || unit > 31) { - warnx( - "%s: invalid device specification, unit out of range", name); - unit = defunit; /* carry on more checking */ - } - if (*cp) { - *cp++ = '\0'; - while (*cp && isdigit(*cp)) - cp++; - } - slice = defslice; - if (*cp == 's') { - ++cp; - if (*cp) { - slice = atoi(cp); - if (slice < 0 || slice >= MAX_SLICES - 1) { - warnx( - "%s: invalid device specification, slice out of range", - cp); - slice = defslice; - } - if (slice != COMPATIBILITY_SLICE) - slice++; - *cp++ = '\0'; - while (*cp && isdigit(*cp)) - cp++; - } - } - partition = *cp ? *cp : defpartition; - if (partition < 'a' || partition > 'h') { - warnx("%c: invalid device specification, bad partition", *cp); - partition = defpartition; /* carry on */ - } - if (devtablenotread) - initdevtable(); - for (dp = devtable; dp; dp = dp->dev_next) - if (eq(name, dp->dev_name)) - break; - if (dp == 0) { - warnx("%s: unknown device", name); - return (NODEV); - } - return (makedev(dp->dev_major, - dkmakeminor(unit, slice, partition - 'a'))); -} - -char * -devtoname(dev) - dev_t dev; -{ - char buf[80]; - register struct devdescription *dp; - int part; - char partname[2]; - int slice; - char slicename[32]; - - if (devtablenotread) - initdevtable(); - for (dp = devtable; dp; dp = dp->dev_next) - if (major(dev) == dp->dev_major) - break; - if (dp == 0) - dp = devtable; - part = dkpart(dev); - slice = dkslice(dev); - slicename[0] = partname[0] = '\0'; - if (slice != WHOLE_DISK_SLICE || part != RAW_PART) { - partname[0] = 'a' + part; - partname[1] = '\0'; - if (slice != COMPATIBILITY_SLICE) - snprintf(slicename, sizeof(slicename), "s%d", slice - 1); - } - (void) snprintf(buf, sizeof(buf), "%s%d%s%s", dp->dev_name, - dkunit(dev), slicename, partname); - return (ns(buf)); + return; } -static void -initdevtable() -{ - char linebuf[256]; - char buf[BUFSIZ]; - int maj; - register struct devdescription **dp = &devtable; - FILE *fp; - - (void) snprintf(buf, sizeof(buf), "../conf/devices.%s", machinename); - fp = fopen(buf, "r"); - if (fp == NULL) - errx(1, "can't open %s", buf); - while(fgets(linebuf,256,fp)) { - /*******************************\ - * Allow a comment * - \*******************************/ - if(linebuf[0] == '#') continue; - - if (sscanf(linebuf, "%s\t%d\n", buf, &maj) == 2) { - *dp = (struct devdescription *)malloc(sizeof (**dp)); - memset(*dp, 0, sizeof(**dp)); - (*dp)->dev_name = ns(buf); - (*dp)->dev_major = maj; - dp = &(*dp)->dev_next; - } else { - fprintf(stderr,"illegal line in devices file\n"); - break; - } - } - *dp = 0; - fclose(fp); - devtablenotread = 0; -} |