Home | History | Annotate | Line # | Download | only in config
      1  1.36  riastrad /*	$NetBSD: mkioconf.c,v 1.36 2024/04/05 00:43:42 riastradh Exp $	*/
      2   1.1   thorpej 
      3   1.1   thorpej /*
      4   1.1   thorpej  * Copyright (c) 1992, 1993
      5   1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
      6   1.1   thorpej  *
      7   1.1   thorpej  * This software was developed by the Computer Systems Engineering group
      8   1.1   thorpej  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9   1.1   thorpej  * contributed to Berkeley.
     10   1.1   thorpej  *
     11   1.1   thorpej  * All advertising materials mentioning features or use of this software
     12   1.1   thorpej  * must display the following acknowledgement:
     13   1.1   thorpej  *	This product includes software developed by the University of
     14   1.1   thorpej  *	California, Lawrence Berkeley Laboratories.
     15   1.1   thorpej  *
     16   1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     17   1.1   thorpej  * modification, are permitted provided that the following conditions
     18   1.1   thorpej  * are met:
     19   1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     20   1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     21   1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     22   1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     23   1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     24   1.1   thorpej  * 3. Neither the name of the University nor the names of its contributors
     25   1.1   thorpej  *    may be used to endorse or promote products derived from this software
     26   1.1   thorpej  *    without specific prior written permission.
     27   1.1   thorpej  *
     28   1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     29   1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     30   1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     31   1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     32   1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33   1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34   1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35   1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     36   1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     37   1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     38   1.1   thorpej  * SUCH DAMAGE.
     39   1.1   thorpej  *
     40   1.1   thorpej  *	from: @(#)mkioconf.c	8.1 (Berkeley) 6/6/93
     41   1.1   thorpej  */
     42   1.1   thorpej 
     43   1.1   thorpej #if HAVE_NBTOOL_CONFIG_H
     44   1.1   thorpej #include "nbtool_config.h"
     45   1.1   thorpej #endif
     46   1.1   thorpej 
     47  1.22  christos #include <sys/cdefs.h>
     48  1.36  riastrad __RCSID("$NetBSD: mkioconf.c,v 1.36 2024/04/05 00:43:42 riastradh Exp $");
     49  1.22  christos 
     50   1.1   thorpej #include <sys/param.h>
     51   1.8       dsl #include <err.h>
     52   1.1   thorpej #include <errno.h>
     53   1.1   thorpej #include <stdio.h>
     54   1.1   thorpej #include <stdlib.h>
     55   1.1   thorpej #include <string.h>
     56   1.1   thorpej #include "defs.h"
     57   1.1   thorpej 
     58   1.1   thorpej /*
     59   1.1   thorpej  * Make ioconf.c.
     60   1.1   thorpej  */
     61   1.3  drochner static int cf_locators_print(const char *, void *, void *);
     62   1.1   thorpej static int cforder(const void *, const void *);
     63   1.8       dsl static void emitcfdata(FILE *);
     64   1.8       dsl static void emitcfdrivers(FILE *);
     65   1.8       dsl static void emitexterns(FILE *);
     66   1.8       dsl static void emitcfattachinit(FILE *);
     67   1.8       dsl static void emithdr(FILE *);
     68   1.8       dsl static void emitloc(FILE *);
     69   1.8       dsl static void emitpseudo(FILE *);
     70   1.8       dsl static void emitparents(FILE *);
     71   1.8       dsl static void emitroots(FILE *);
     72   1.8       dsl static void emitname2blk(FILE *);
     73   1.1   thorpej 
     74   1.1   thorpej #define	SEP(pos, max)	(((u_int)(pos) % (max)) == 0 ? "\n\t" : " ")
     75   1.1   thorpej 
     76   1.1   thorpej #define ARRNAME(n, l) (strchr((n), ARRCHR) && strncmp((n), (l), strlen((l))) == 0)
     77   1.1   thorpej 
     78   1.1   thorpej /*
     79   1.1   thorpej  * NEWLINE can only be used in the emitXXX functions.
     80   1.1   thorpej  * In most cases it can be subsumed into an fprintf.
     81   1.1   thorpej  */
     82   1.8       dsl #define	NEWLINE		putc('\n', fp)
     83   1.1   thorpej 
     84   1.1   thorpej int
     85   1.1   thorpej mkioconf(void)
     86   1.1   thorpej {
     87   1.1   thorpej 	FILE *fp;
     88   1.1   thorpej 
     89   1.1   thorpej 	qsort(packed, npacked, sizeof *packed, cforder);
     90   1.1   thorpej 	if ((fp = fopen("ioconf.c.tmp", "w")) == NULL) {
     91   1.9  christos 		warn("cannot write ioconf.c");
     92  1.32  uebayasi 		return (1);
     93   1.1   thorpej 	}
     94   1.8       dsl 
     95  1.29  christos 	fprintf(fp, "#include \"ioconf.h\"\n");
     96  1.33     pooka 	if (ioconfname)
     97  1.33     pooka 		fprintf(fp, "#define IOCONF %s\n", ioconfname);
     98  1.29  christos 
     99  1.16     pooka 	emithdr(fp);
    100  1.16     pooka 	emitcfdrivers(fp);
    101  1.16     pooka 	emitexterns(fp);
    102  1.16     pooka 	emitloc(fp);
    103  1.16     pooka 	emitparents(fp);
    104  1.16     pooka 	emitcfdata(fp);
    105  1.17     pooka 	emitcfattachinit(fp);
    106  1.16     pooka 
    107  1.15     pooka 	if (ioconfname == NULL) {
    108  1.15     pooka 		emitroots(fp);
    109  1.15     pooka 		emitpseudo(fp);
    110  1.15     pooka 		if (!do_devsw)
    111  1.15     pooka 			emitname2blk(fp);
    112  1.15     pooka 	}
    113   1.8       dsl 
    114   1.8       dsl 	fflush(fp);
    115   1.8       dsl 	if (ferror(fp)) {
    116   1.9  christos 		warn("error writing ioconf.c");
    117   1.1   thorpej 		(void)fclose(fp);
    118   1.9  christos #if 0
    119   1.9  christos 		(void)unlink("ioconf.c.tmp");
    120   1.9  christos #endif
    121  1.32  uebayasi 		return (1);
    122   1.1   thorpej 	}
    123   1.8       dsl 
    124   1.1   thorpej 	(void)fclose(fp);
    125   1.1   thorpej 	if (moveifchanged("ioconf.c.tmp", "ioconf.c") != 0) {
    126   1.9  christos 		warn("error renaming ioconf.c");
    127  1.32  uebayasi 		return (1);
    128   1.1   thorpej 	}
    129   1.1   thorpej 	return (0);
    130   1.1   thorpej }
    131   1.1   thorpej 
    132   1.1   thorpej static int
    133   1.1   thorpej cforder(const void *a, const void *b)
    134   1.1   thorpej {
    135   1.1   thorpej 	int n1, n2;
    136   1.1   thorpej 
    137  1.14     lukem 	n1 = (*(const struct devi * const *)a)->i_cfindex;
    138  1.14     lukem 	n2 = (*(const struct devi * const *)b)->i_cfindex;
    139  1.36  riastrad 	if (n1 < n2)
    140  1.36  riastrad 		return -1;
    141  1.36  riastrad 	else if (n1 > n2)
    142  1.36  riastrad 		return +1;
    143  1.36  riastrad 	else
    144  1.36  riastrad 		abort();	/* no ties possible */
    145   1.1   thorpej }
    146   1.1   thorpej 
    147   1.8       dsl static void
    148   1.1   thorpej emithdr(FILE *ofp)
    149   1.1   thorpej {
    150   1.1   thorpej 	FILE *ifp;
    151  1.22  christos 	size_t n;
    152   1.1   thorpej 	char ifnbuf[200], buf[BUFSIZ];
    153   1.1   thorpej 	char *ifn;
    154   1.1   thorpej 
    155  1.10     lukem 	autogen_comment(ofp, "ioconf.c");
    156   1.1   thorpej 
    157  1.30  uebayasi 	(void)snprintf(ifnbuf, sizeof(ifnbuf), "%s/arch/%s/conf/ioconf.incl.%s",
    158  1.30  uebayasi 	    srcdir,
    159  1.19  nakayama 	    machine ? machine : "(null)", machine ? machine : "(null)");
    160  1.30  uebayasi 	ifn = ifnbuf;
    161   1.1   thorpej 	if ((ifp = fopen(ifn, "r")) != NULL) {
    162   1.1   thorpej 		while ((n = fread(buf, 1, sizeof(buf), ifp)) > 0)
    163   1.9  christos 			(void)fwrite(buf, 1, n, ofp);
    164   1.8       dsl 		if (ferror(ifp))
    165   1.8       dsl 			err(EXIT_FAILURE, "error reading %s", ifn);
    166   1.1   thorpej 		(void)fclose(ifp);
    167   1.1   thorpej 	} else {
    168   1.8       dsl 		fputs("#include <sys/param.h>\n"
    169   1.8       dsl 			"#include <sys/conf.h>\n"
    170   1.8       dsl 			"#include <sys/device.h>\n"
    171   1.8       dsl 			"#include <sys/mount.h>\n", ofp);
    172   1.1   thorpej 	}
    173   1.1   thorpej }
    174   1.1   thorpej 
    175   1.3  drochner /*
    176   1.3  drochner  * Emit an initialized array of character strings describing this
    177   1.3  drochner  * attribute's locators.
    178   1.3  drochner  */
    179   1.3  drochner static int
    180   1.3  drochner cf_locators_print(const char *name, void *value, void *arg)
    181   1.3  drochner {
    182   1.3  drochner 	struct attr *a;
    183  1.21  dholland 	struct loclist *ll;
    184   1.3  drochner 	FILE *fp = arg;
    185   1.3  drochner 
    186   1.3  drochner 	a = value;
    187   1.6  drochner 	if (!a->a_iattr)
    188   1.6  drochner 		return (0);
    189  1.23  uebayasi 	if (ht_lookup(selecttab, name) == NULL)
    190  1.23  uebayasi 		return (0);
    191   1.6  drochner 
    192   1.3  drochner 	if (a->a_locs) {
    193   1.8       dsl 		fprintf(fp,
    194   1.3  drochner 		    "static const struct cfiattrdata %scf_iattrdata = {\n",
    195   1.8       dsl 			    name);
    196  1.24  uebayasi 		fprintf(fp, "\t\"%s\", %d, {\n", name, a->a_loclen);
    197  1.21  dholland 		for (ll = a->a_locs; ll; ll = ll->ll_next)
    198  1.12  uebayasi 			fprintf(fp, "\t\t{ \"%s\", \"%s\", %s },\n",
    199  1.21  dholland 				ll->ll_name,
    200  1.21  dholland 				(ll->ll_string ? ll->ll_string : "NULL"),
    201  1.21  dholland 				(ll->ll_string ? ll->ll_string : "0"));
    202   1.8       dsl 		fprintf(fp, "\t}\n};\n");
    203   1.8       dsl 	} else {
    204   1.8       dsl 		fprintf(fp,
    205   1.8       dsl 		    "static const struct cfiattrdata %scf_iattrdata = {\n"
    206   1.8       dsl 		    "\t\"%s\", 0, {\n\t\t{ NULL, NULL, 0 },\n\t}\n};\n",
    207   1.8       dsl 		    name, name);
    208   1.8       dsl 	}
    209   1.8       dsl 
    210   1.3  drochner 	return 0;
    211   1.3  drochner }
    212   1.3  drochner 
    213   1.8       dsl static void
    214   1.1   thorpej emitcfdrivers(FILE *fp)
    215   1.1   thorpej {
    216   1.1   thorpej 	struct devbase *d;
    217  1.20  dholland 	struct attrlist *al;
    218   1.1   thorpej 	struct attr *a;
    219   1.1   thorpej 	int has_iattrs;
    220   1.1   thorpej 
    221   1.1   thorpej 	NEWLINE;
    222   1.8       dsl 	ht_enumerate(attrtab, cf_locators_print, fp);
    223   1.3  drochner 
    224   1.3  drochner 	NEWLINE;
    225   1.1   thorpej 	TAILQ_FOREACH(d, &allbases, d_next) {
    226   1.1   thorpej 		if (!devbase_has_instances(d, WILD))
    227   1.1   thorpej 			continue;
    228   1.1   thorpej 		has_iattrs = 0;
    229  1.20  dholland 		for (al = d->d_attrs; al != NULL; al = al->al_next) {
    230  1.20  dholland 			a = al->al_this;
    231   1.1   thorpej 			if (a->a_iattr == 0)
    232   1.1   thorpej 				continue;
    233   1.8       dsl 			if (has_iattrs == 0)
    234   1.8       dsl 				fprintf(fp,
    235   1.3  drochner 			    	    "static const struct cfiattrdata * const %s_attrs[] = { ",
    236   1.8       dsl 			    	    d->d_name);
    237   1.1   thorpej 			has_iattrs = 1;
    238   1.8       dsl 			fprintf(fp, "&%scf_iattrdata, ", a->a_name);
    239   1.1   thorpej 		}
    240   1.8       dsl 		if (has_iattrs)
    241   1.8       dsl 			fprintf(fp, "NULL };\n");
    242   1.8       dsl 		fprintf(fp, "CFDRIVER_DECL(%s, %s, ", d->d_name, /* ) */
    243   1.1   thorpej 		    d->d_classattr != NULL ? d->d_classattr->a_devclass
    244   1.8       dsl 					   : "DV_DULL");
    245   1.8       dsl 		if (has_iattrs)
    246   1.8       dsl 			fprintf(fp, "%s_attrs", d->d_name);
    247   1.8       dsl 		else
    248   1.8       dsl 			fprintf(fp, "NULL");
    249   1.8       dsl 		fprintf(fp, /* ( */ ");\n\n");
    250   1.1   thorpej 	}
    251   1.1   thorpej 
    252   1.1   thorpej 	NEWLINE;
    253  1.15     pooka 
    254  1.17     pooka 	fprintf(fp,
    255  1.17     pooka 	    "%sstruct cfdriver * const cfdriver_%s_%s[] = {\n",
    256  1.17     pooka 	    ioconfname ? "static " : "",
    257  1.18     pooka 	    ioconfname ? "ioconf" : "list",
    258  1.17     pooka 	    ioconfname ? ioconfname : "initial");
    259  1.15     pooka 
    260   1.1   thorpej 	TAILQ_FOREACH(d, &allbases, d_next) {
    261   1.1   thorpej 		if (!devbase_has_instances(d, WILD))
    262   1.1   thorpej 			continue;
    263   1.8       dsl 		fprintf(fp, "\t&%s_cd,\n", d->d_name);
    264   1.1   thorpej 	}
    265   1.8       dsl 	fprintf(fp, "\tNULL\n};\n");
    266   1.1   thorpej }
    267   1.1   thorpej 
    268   1.8       dsl static void
    269   1.1   thorpej emitexterns(FILE *fp)
    270   1.1   thorpej {
    271   1.1   thorpej 	struct deva *da;
    272   1.1   thorpej 
    273   1.1   thorpej 	NEWLINE;
    274   1.1   thorpej 	TAILQ_FOREACH(da, &alldevas, d_next) {
    275   1.1   thorpej 		if (!deva_has_instances(da, WILD))
    276   1.1   thorpej 			continue;
    277   1.8       dsl 		fprintf(fp, "extern struct cfattach %s_ca;\n",
    278   1.8       dsl 			    da->d_name);
    279   1.1   thorpej 	}
    280   1.1   thorpej }
    281   1.1   thorpej 
    282   1.8       dsl static void
    283   1.1   thorpej emitcfattachinit(FILE *fp)
    284   1.1   thorpej {
    285   1.1   thorpej 	struct devbase *d;
    286   1.1   thorpej 	struct deva *da;
    287   1.1   thorpej 
    288   1.1   thorpej 	NEWLINE;
    289   1.1   thorpej 	TAILQ_FOREACH(d, &allbases, d_next) {
    290   1.1   thorpej 		if (!devbase_has_instances(d, WILD))
    291   1.1   thorpej 			continue;
    292   1.1   thorpej 		if (d->d_ahead == NULL)
    293   1.1   thorpej 			continue;
    294   1.1   thorpej 
    295   1.8       dsl 		fprintf(fp,
    296   1.8       dsl 		    "static struct cfattach * const %s_cfattachinit[] = {\n\t",
    297   1.8       dsl 			    d->d_name);
    298   1.1   thorpej 		for (da = d->d_ahead; da != NULL; da = da->d_bsame) {
    299   1.1   thorpej 			if (!deva_has_instances(da, WILD))
    300   1.1   thorpej 				continue;
    301   1.8       dsl 			fprintf(fp, "&%s_ca, ", da->d_name);
    302   1.1   thorpej 		}
    303   1.8       dsl 		fprintf(fp, "NULL\n};\n");
    304   1.1   thorpej 	}
    305   1.1   thorpej 
    306   1.1   thorpej 	NEWLINE;
    307  1.17     pooka 	fprintf(fp, "%sconst struct cfattachinit cfattach%s%s[] = {\n",
    308  1.17     pooka 	    ioconfname ? "static " : "",
    309  1.18     pooka 	    ioconfname ? "_ioconf_" : "init",
    310  1.17     pooka 	    ioconfname ? ioconfname : "");
    311   1.1   thorpej 
    312   1.1   thorpej 	TAILQ_FOREACH(d, &allbases, d_next) {
    313   1.1   thorpej 		if (!devbase_has_instances(d, WILD))
    314   1.1   thorpej 			continue;
    315   1.1   thorpej 		if (d->d_ahead == NULL)
    316   1.1   thorpej 			continue;
    317   1.1   thorpej 
    318   1.8       dsl 		fprintf(fp, "\t{ \"%s\", %s_cfattachinit },\n",
    319   1.8       dsl 			    d->d_name, d->d_name);
    320   1.1   thorpej 	}
    321   1.1   thorpej 
    322   1.8       dsl 	fprintf(fp, "\t{ NULL, NULL }\n};\n");
    323   1.1   thorpej }
    324   1.1   thorpej 
    325   1.8       dsl static void
    326   1.1   thorpej emitloc(FILE *fp)
    327   1.1   thorpej {
    328   1.1   thorpej 	int i;
    329   1.1   thorpej 
    330   1.1   thorpej 	if (locators.used != 0) {
    331   1.8       dsl 		fprintf(fp, "\n/* locators */\n"
    332   1.8       dsl 			"static int loc[%d] = {", locators.used);
    333   1.1   thorpej 		for (i = 0; i < locators.used; i++)
    334   1.8       dsl 			fprintf(fp, "%s%s,", SEP(i, 8), locators.vec[i]);
    335   1.8       dsl 		fprintf(fp, "\n};\n");
    336   1.1   thorpej 	}
    337   1.1   thorpej }
    338   1.1   thorpej 
    339   1.1   thorpej /*
    340   1.1   thorpej  * Emit static parent data.
    341   1.1   thorpej  */
    342   1.8       dsl static void
    343   1.1   thorpej emitparents(FILE *fp)
    344   1.1   thorpej {
    345   1.1   thorpej 	struct pspec *p;
    346  1.34  christos 	int inst = -1;
    347   1.1   thorpej 
    348   1.1   thorpej 	NEWLINE;
    349   1.1   thorpej 	TAILQ_FOREACH(p, &allpspecs, p_list) {
    350   1.5      cube 		if (p->p_devs == NULL || p->p_active != DEVI_ACTIVE)
    351   1.1   thorpej 			continue;
    352  1.35  christos 		if (inst >= p->p_inst)
    353  1.34  christos 			continue;
    354  1.34  christos 		inst = p->p_inst;
    355   1.8       dsl 		fprintf(fp,
    356   1.8       dsl 		    "static const struct cfparent pspec%d = {\n", p->p_inst);
    357   1.8       dsl 		fprintf(fp, "\t\"%s\", ", p->p_iattr->a_name);
    358   1.1   thorpej 		if (p->p_atdev != NULL) {
    359   1.8       dsl 			fprintf(fp, "\"%s\", ", p->p_atdev->d_name);
    360   1.8       dsl 			if (p->p_atunit == WILD)
    361   1.8       dsl 				fprintf(fp, "DVUNIT_ANY");
    362   1.8       dsl 			else
    363   1.8       dsl 				fprintf(fp, "%d", p->p_atunit);
    364   1.8       dsl 		} else
    365   1.8       dsl 			fprintf(fp, "NULL, 0");
    366   1.8       dsl 		fprintf(fp, "\n};\n");
    367   1.1   thorpej 	}
    368   1.1   thorpej }
    369   1.1   thorpej 
    370   1.1   thorpej /*
    371   1.1   thorpej  * Emit the cfdata array.
    372   1.1   thorpej  */
    373   1.8       dsl static void
    374   1.1   thorpej emitcfdata(FILE *fp)
    375   1.1   thorpej {
    376   1.1   thorpej 	struct devi **p, *i;
    377   1.1   thorpej 	struct pspec *ps;
    378   1.1   thorpej 	int unit, v;
    379   1.1   thorpej 	const char *state, *basename, *attachment;
    380  1.21  dholland 	struct loclist *ll;
    381   1.1   thorpej 	struct attr *a;
    382  1.14     lukem 	const char *loc;
    383   1.1   thorpej 	char locbuf[20];
    384   1.1   thorpej 	const char *lastname = "";
    385   1.1   thorpej 
    386   1.8       dsl 	fprintf(fp, "\n"
    387   1.8       dsl 		"#define NORM FSTATE_NOTFOUND\n"
    388   1.8       dsl 		"#define STAR FSTATE_STAR\n"
    389   1.8       dsl 		"\n"
    390  1.17     pooka 		"%sstruct cfdata cfdata%s%s[] = {\n"
    391   1.8       dsl 		"    /* driver           attachment    unit state "
    392  1.25  uebayasi 		"     loc   flags  pspec */\n",
    393  1.17     pooka 		    ioconfname ? "static " : "",
    394  1.18     pooka 		    ioconfname ? "_ioconf_" : "",
    395  1.15     pooka 		    ioconfname ? ioconfname : "");
    396   1.1   thorpej 	for (p = packed; (i = *p) != NULL; p++) {
    397   1.1   thorpej 		/* the description */
    398   1.8       dsl 		fprintf(fp, "/*%3d: %s at ", i->i_cfindex, i->i_name);
    399   1.1   thorpej 		if ((ps = i->i_pspec) != NULL) {
    400   1.1   thorpej 			if (ps->p_atdev != NULL &&
    401   1.1   thorpej 			    ps->p_atunit != WILD) {
    402   1.8       dsl 				fprintf(fp, "%s%d", ps->p_atdev->d_name,
    403   1.8       dsl 					    ps->p_atunit);
    404   1.1   thorpej 			} else if (ps->p_atdev != NULL) {
    405   1.8       dsl 				fprintf(fp, "%s?", ps->p_atdev->d_name);
    406   1.1   thorpej 			} else {
    407   1.8       dsl 				fprintf(fp, "%s?", ps->p_iattr->a_name);
    408   1.1   thorpej 			}
    409   1.1   thorpej 
    410   1.1   thorpej 			a = ps->p_iattr;
    411  1.21  dholland 			for (ll = a->a_locs, v = 0; ll != NULL;
    412  1.21  dholland 			     ll = ll->ll_next, v++) {
    413  1.21  dholland 				if (ARRNAME(ll->ll_name, lastname)) {
    414   1.8       dsl 					fprintf(fp, " %s %s",
    415  1.21  dholland 					    ll->ll_name, i->i_locs[v]);
    416   1.1   thorpej 				} else {
    417   1.8       dsl 					fprintf(fp, " %s %s",
    418  1.21  dholland 						    ll->ll_name,
    419   1.8       dsl 						    i->i_locs[v]);
    420  1.21  dholland 					lastname = ll->ll_name;
    421   1.1   thorpej 				}
    422   1.1   thorpej 			}
    423   1.1   thorpej 		} else {
    424   1.1   thorpej 			a = NULL;
    425   1.8       dsl 			fputs("root", fp);
    426   1.1   thorpej 		}
    427   1.1   thorpej 
    428   1.8       dsl 		fputs(" */\n", fp);
    429   1.1   thorpej 
    430   1.1   thorpej 		/* then the actual defining line */
    431   1.1   thorpej 		basename = i->i_base->d_name;
    432   1.1   thorpej 		attachment = i->i_atdeva->d_name;
    433   1.1   thorpej 		if (i->i_unit == STAR) {
    434   1.1   thorpej 			unit = i->i_base->d_umax;
    435   1.1   thorpej 			state = "STAR";
    436   1.1   thorpej 		} else {
    437   1.1   thorpej 			unit = i->i_unit;
    438   1.1   thorpej 			state = "NORM";
    439   1.1   thorpej 		}
    440   1.1   thorpej 		if (i->i_locoff >= 0) {
    441   1.1   thorpej 			(void)snprintf(locbuf, sizeof(locbuf), "loc+%3d",
    442   1.1   thorpej 			    i->i_locoff);
    443   1.1   thorpej 			loc = locbuf;
    444   1.1   thorpej 		} else
    445  1.26  uebayasi 			loc = "NULL";
    446  1.12  uebayasi 		fprintf(fp, "    { \"%s\",%s\"%s\",%s%2d, %s, %7s, %#6x, ",
    447  1.25  uebayasi 			    basename, strlen(basename) < 7 ? "\t\t"
    448   1.1   thorpej 			    				   : "\t",
    449   1.1   thorpej 			    attachment, strlen(attachment) < 5 ? "\t\t"
    450   1.1   thorpej 			    				       : "\t",
    451   1.8       dsl 			    unit, state, loc, i->i_cfflags);
    452   1.8       dsl 		if (ps != NULL)
    453  1.12  uebayasi 			fprintf(fp, "&pspec%d },\n", ps->p_inst);
    454   1.8       dsl 		else
    455  1.12  uebayasi 			fputs("NULL },\n", fp);
    456   1.8       dsl 	}
    457  1.12  uebayasi 	fprintf(fp, "    { %s,%s%s,%s%2d, %s, %7s, %#6x, %s }\n};\n",
    458  1.25  uebayasi 	    "NULL", "\t\t", "NULL", "\t\t", 0, "   0", "NULL", 0, "NULL");
    459   1.1   thorpej }
    460   1.1   thorpej 
    461   1.1   thorpej /*
    462   1.1   thorpej  * Emit the table of potential roots.
    463   1.1   thorpej  */
    464   1.8       dsl static void
    465   1.1   thorpej emitroots(FILE *fp)
    466   1.1   thorpej {
    467   1.1   thorpej 	struct devi **p, *i;
    468   1.1   thorpej 
    469   1.8       dsl 	fputs("\nconst short cfroots[] = {\n", fp);
    470   1.1   thorpej 	for (p = packed; (i = *p) != NULL; p++) {
    471   1.1   thorpej 		if (i->i_at != NULL)
    472   1.1   thorpej 			continue;
    473   1.1   thorpej 		if (i->i_unit != 0 &&
    474   1.1   thorpej 		    (i->i_unit != STAR || i->i_base->d_umax != 0))
    475   1.9  christos 			warnx("warning: `%s at root' is not unit 0", i->i_name);
    476   1.8       dsl 		fprintf(fp, "\t%2d /* %s */,\n",
    477   1.8       dsl 		    i->i_cfindex, i->i_name);
    478   1.1   thorpej 	}
    479   1.8       dsl 	fputs("\t-1\n};\n", fp);
    480   1.1   thorpej }
    481   1.1   thorpej 
    482   1.1   thorpej /*
    483   1.1   thorpej  * Emit pseudo-device initialization.
    484   1.1   thorpej  */
    485   1.8       dsl static void
    486   1.1   thorpej emitpseudo(FILE *fp)
    487   1.1   thorpej {
    488   1.1   thorpej 	struct devi *i;
    489   1.1   thorpej 	struct devbase *d;
    490   1.1   thorpej 
    491   1.8       dsl 	fputs("\n/* pseudo-devices */\n", fp);
    492  1.27  uebayasi 	fputs("\nconst struct pdevinit pdevinit[] = {\n", fp);
    493   1.1   thorpej 	TAILQ_FOREACH(i, &allpseudo, i_next) {
    494   1.1   thorpej 		d = i->i_base;
    495   1.8       dsl 		fprintf(fp, "\t{ %sattach, %d },\n",
    496   1.8       dsl 		    d->d_name, d->d_umax);
    497   1.1   thorpej 	}
    498   1.8       dsl 	fputs("\t{ 0, 0 }\n};\n", fp);
    499   1.1   thorpej }
    500   1.1   thorpej 
    501   1.1   thorpej /*
    502   1.1   thorpej  * Emit name to major block number table.
    503   1.1   thorpej  */
    504   1.8       dsl void
    505   1.1   thorpej emitname2blk(FILE *fp)
    506   1.1   thorpej {
    507   1.1   thorpej 	struct devbase *dev;
    508   1.1   thorpej 
    509   1.8       dsl 	fputs("\n/* device name to major block number */\n", fp);
    510   1.1   thorpej 
    511   1.8       dsl 	fprintf(fp, "struct devnametobdevmaj dev_name2blk[] = {\n");
    512   1.1   thorpej 
    513   1.1   thorpej 	TAILQ_FOREACH(dev, &allbases, d_next) {
    514  1.13  drochner 		if (dev->d_major == NODEVMAJOR)
    515   1.1   thorpej 			continue;
    516   1.1   thorpej 
    517  1.13  drochner 		fprintf(fp, "\t{ \"%s\", %d },\n",
    518  1.13  drochner 			    dev->d_name, dev->d_major);
    519   1.1   thorpej 	}
    520   1.8       dsl 	fprintf(fp, "\t{ NULL, 0 }\n};\n");
    521   1.1   thorpej }
    522