2017-11-19 04:46:29 +03:00
|
|
|
/* $NetBSD: mkioconf.c,v 1.35 2017/11/19 01:46:29 christos Exp $ */
|
1996-03-03 20:21:25 +03:00
|
|
|
|
1996-03-17 09:29:19 +03:00
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed by the Computer Systems Engineering group
|
|
|
|
* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
|
|
|
|
* contributed to Berkeley.
|
|
|
|
*
|
|
|
|
* All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Lawrence Berkeley Laboratories.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
1995-04-28 10:54:58 +04:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
1993-03-21 12:45:37 +03:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
1995-04-28 10:54:58 +04:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-08-07 15:25:11 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1995-04-28 10:54:58 +04:00
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1995-04-28 10:54:58 +04:00
|
|
|
*
|
|
|
|
* from: @(#)mkioconf.c 8.1 (Berkeley) 6/6/93
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
|
|
|
|
2004-06-21 02:20:14 +04:00
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-10-29 20:14:50 +03:00
|
|
|
#include <sys/cdefs.h>
|
2017-11-19 04:46:29 +03:00
|
|
|
__RCSID("$NetBSD: mkioconf.c,v 1.35 2017/11/19 01:46:29 christos Exp $");
|
2014-10-29 20:14:50 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <sys/param.h>
|
2006-10-05 00:34:48 +04:00
|
|
|
#include <err.h>
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <errno.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdio.h>
|
1995-04-28 10:54:58 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-01-29 13:20:28 +03:00
|
|
|
#include "defs.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
1995-04-28 10:54:58 +04:00
|
|
|
* Make ioconf.c.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
2005-08-25 19:01:07 +04:00
|
|
|
static int cf_locators_print(const char *, void *, void *);
|
2000-10-02 23:48:34 +04:00
|
|
|
static int cforder(const void *, const void *);
|
2006-10-05 00:34:48 +04:00
|
|
|
static void emitcfdata(FILE *);
|
|
|
|
static void emitcfdrivers(FILE *);
|
|
|
|
static void emitexterns(FILE *);
|
|
|
|
static void emitcfattachinit(FILE *);
|
|
|
|
static void emithdr(FILE *);
|
|
|
|
static void emitloc(FILE *);
|
|
|
|
static void emitpseudo(FILE *);
|
|
|
|
static void emitparents(FILE *);
|
|
|
|
static void emitroots(FILE *);
|
|
|
|
static void emitname2blk(FILE *);
|
1993-11-23 10:45:06 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
#define SEP(pos, max) (((u_int)(pos) % (max)) == 0 ? "\n\t" : " ")
|
1994-06-24 18:22:08 +04:00
|
|
|
|
1999-01-21 16:10:08 +03:00
|
|
|
#define ARRNAME(n, l) (strchr((n), ARRCHR) && strncmp((n), (l), strlen((l))) == 0)
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* NEWLINE can only be used in the emitXXX functions.
|
|
|
|
* In most cases it can be subsumed into an fprintf.
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
#define NEWLINE putc('\n', fp)
|
1994-06-24 18:22:08 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
int
|
2000-10-02 23:48:34 +04:00
|
|
|
mkioconf(void)
|
1994-06-24 18:22:08 +04:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
FILE *fp;
|
1994-06-24 18:22:08 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
qsort(packed, npacked, sizeof *packed, cforder);
|
2002-02-13 02:20:11 +03:00
|
|
|
if ((fp = fopen("ioconf.c.tmp", "w")) == NULL) {
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("cannot write ioconf.c");
|
2015-09-03 16:53:36 +03:00
|
|
|
return (1);
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
|
2015-08-20 12:44:24 +03:00
|
|
|
fprintf(fp, "#include \"ioconf.h\"\n");
|
2015-11-12 17:38:21 +03:00
|
|
|
if (ioconfname)
|
|
|
|
fprintf(fp, "#define IOCONF %s\n", ioconfname);
|
2015-08-20 12:44:24 +03:00
|
|
|
|
2010-02-04 00:32:27 +03:00
|
|
|
emithdr(fp);
|
|
|
|
emitcfdrivers(fp);
|
|
|
|
emitexterns(fp);
|
|
|
|
emitloc(fp);
|
|
|
|
emitparents(fp);
|
|
|
|
emitcfdata(fp);
|
2010-03-25 22:39:05 +03:00
|
|
|
emitcfattachinit(fp);
|
2010-02-04 00:32:27 +03:00
|
|
|
|
2010-02-04 00:00:49 +03:00
|
|
|
if (ioconfname == NULL) {
|
|
|
|
emitroots(fp);
|
|
|
|
emitpseudo(fp);
|
|
|
|
if (!do_devsw)
|
|
|
|
emitname2blk(fp);
|
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
|
|
|
|
fflush(fp);
|
|
|
|
if (ferror(fp)) {
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("error writing ioconf.c");
|
1995-04-28 10:54:58 +04:00
|
|
|
(void)fclose(fp);
|
2007-01-14 02:47:36 +03:00
|
|
|
#if 0
|
|
|
|
(void)unlink("ioconf.c.tmp");
|
|
|
|
#endif
|
2015-09-03 16:53:36 +03:00
|
|
|
return (1);
|
1994-06-24 18:22:08 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
(void)fclose(fp);
|
2002-02-13 02:20:11 +03:00
|
|
|
if (moveifchanged("ioconf.c.tmp", "ioconf.c") != 0) {
|
2007-01-14 02:47:36 +03:00
|
|
|
warn("error renaming ioconf.c");
|
2015-09-03 16:53:36 +03:00
|
|
|
return (1);
|
2002-02-13 02:20:11 +03:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
return (0);
|
1993-11-23 10:45:06 +03:00
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
static int
|
2000-10-02 23:48:34 +04:00
|
|
|
cforder(const void *a, const void *b)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
int n1, n2;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2009-04-11 16:41:10 +04:00
|
|
|
n1 = (*(const struct devi * const *)a)->i_cfindex;
|
|
|
|
n2 = (*(const struct devi * const *)b)->i_cfindex;
|
1995-04-28 10:54:58 +04:00
|
|
|
return (n1 - n2);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emithdr(FILE *ofp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
FILE *ifp;
|
2014-10-29 20:14:50 +03:00
|
|
|
size_t n;
|
1999-09-24 08:48:37 +04:00
|
|
|
char ifnbuf[200], buf[BUFSIZ];
|
|
|
|
char *ifn;
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2007-12-12 03:03:33 +03:00
|
|
|
autogen_comment(ofp, "ioconf.c");
|
1999-09-24 08:48:37 +04:00
|
|
|
|
2015-08-28 06:55:15 +03:00
|
|
|
(void)snprintf(ifnbuf, sizeof(ifnbuf), "%s/arch/%s/conf/ioconf.incl.%s",
|
|
|
|
srcdir,
|
2011-03-03 17:53:01 +03:00
|
|
|
machine ? machine : "(null)", machine ? machine : "(null)");
|
2015-08-28 06:55:15 +03:00
|
|
|
ifn = ifnbuf;
|
1995-04-28 10:54:58 +04:00
|
|
|
if ((ifp = fopen(ifn, "r")) != NULL) {
|
|
|
|
while ((n = fread(buf, 1, sizeof(buf), ifp)) > 0)
|
2007-01-14 02:47:36 +03:00
|
|
|
(void)fwrite(buf, 1, n, ofp);
|
2006-10-05 00:34:48 +04:00
|
|
|
if (ferror(ifp))
|
|
|
|
err(EXIT_FAILURE, "error reading %s", ifn);
|
1995-04-28 10:54:58 +04:00
|
|
|
(void)fclose(ifp);
|
|
|
|
} else {
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("#include <sys/param.h>\n"
|
|
|
|
"#include <sys/conf.h>\n"
|
|
|
|
"#include <sys/device.h>\n"
|
|
|
|
"#include <sys/mount.h>\n", ofp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-25 19:01:07 +04:00
|
|
|
/*
|
|
|
|
* Emit an initialized array of character strings describing this
|
|
|
|
* attribute's locators.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
cf_locators_print(const char *name, void *value, void *arg)
|
|
|
|
{
|
|
|
|
struct attr *a;
|
2012-03-12 01:16:07 +04:00
|
|
|
struct loclist *ll;
|
2005-08-25 19:01:07 +04:00
|
|
|
FILE *fp = arg;
|
|
|
|
|
|
|
|
a = value;
|
2006-08-09 22:03:23 +04:00
|
|
|
if (!a->a_iattr)
|
|
|
|
return (0);
|
2014-10-31 20:43:55 +03:00
|
|
|
if (ht_lookup(selecttab, name) == NULL)
|
|
|
|
return (0);
|
2006-08-09 22:03:23 +04:00
|
|
|
|
2005-08-25 19:01:07 +04:00
|
|
|
if (a->a_locs) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp,
|
2005-08-25 19:01:07 +04:00
|
|
|
"static const struct cfiattrdata %scf_iattrdata = {\n",
|
2006-10-05 00:34:48 +04:00
|
|
|
name);
|
2014-10-31 20:58:02 +03:00
|
|
|
fprintf(fp, "\t\"%s\", %d, {\n", name, a->a_loclen);
|
2012-03-12 01:16:07 +04:00
|
|
|
for (ll = a->a_locs; ll; ll = ll->ll_next)
|
2009-01-16 12:43:41 +03:00
|
|
|
fprintf(fp, "\t\t{ \"%s\", \"%s\", %s },\n",
|
2012-03-12 01:16:07 +04:00
|
|
|
ll->ll_name,
|
|
|
|
(ll->ll_string ? ll->ll_string : "NULL"),
|
|
|
|
(ll->ll_string ? ll->ll_string : "0"));
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\t}\n};\n");
|
|
|
|
} else {
|
|
|
|
fprintf(fp,
|
|
|
|
"static const struct cfiattrdata %scf_iattrdata = {\n"
|
|
|
|
"\t\"%s\", 0, {\n\t\t{ NULL, NULL, 0 },\n\t}\n};\n",
|
|
|
|
name, name);
|
|
|
|
}
|
|
|
|
|
2005-08-25 19:01:07 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitcfdrivers(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct devbase *d;
|
2012-03-11 11:32:41 +04:00
|
|
|
struct attrlist *al;
|
2002-09-26 08:07:35 +04:00
|
|
|
struct attr *a;
|
|
|
|
int has_iattrs;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
2005-08-25 19:01:07 +04:00
|
|
|
NEWLINE;
|
2006-10-05 00:34:48 +04:00
|
|
|
ht_enumerate(attrtab, cf_locators_print, fp);
|
2005-08-25 19:01:07 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
NEWLINE;
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(d, &allbases, d_next) {
|
1996-03-17 05:08:22 +03:00
|
|
|
if (!devbase_has_instances(d, WILD))
|
1995-04-28 10:54:58 +04:00
|
|
|
continue;
|
2002-09-26 08:07:35 +04:00
|
|
|
has_iattrs = 0;
|
2012-03-11 11:32:41 +04:00
|
|
|
for (al = d->d_attrs; al != NULL; al = al->al_next) {
|
|
|
|
a = al->al_this;
|
2002-09-26 08:07:35 +04:00
|
|
|
if (a->a_iattr == 0)
|
|
|
|
continue;
|
2006-10-05 00:34:48 +04:00
|
|
|
if (has_iattrs == 0)
|
|
|
|
fprintf(fp,
|
2005-08-25 19:01:07 +04:00
|
|
|
"static const struct cfiattrdata * const %s_attrs[] = { ",
|
2006-10-05 00:34:48 +04:00
|
|
|
d->d_name);
|
2002-09-26 08:07:35 +04:00
|
|
|
has_iattrs = 1;
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "&%scf_iattrdata, ", a->a_name);
|
2002-09-26 08:07:35 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
if (has_iattrs)
|
|
|
|
fprintf(fp, "NULL };\n");
|
|
|
|
fprintf(fp, "CFDRIVER_DECL(%s, %s, ", d->d_name, /* ) */
|
2002-09-30 22:54:36 +04:00
|
|
|
d->d_classattr != NULL ? d->d_classattr->a_devclass
|
2006-10-05 00:34:48 +04:00
|
|
|
: "DV_DULL");
|
|
|
|
if (has_iattrs)
|
|
|
|
fprintf(fp, "%s_attrs", d->d_name);
|
|
|
|
else
|
|
|
|
fprintf(fp, "NULL");
|
|
|
|
fprintf(fp, /* ( */ ");\n\n");
|
1995-04-28 10:54:58 +04:00
|
|
|
}
|
2002-09-27 06:24:06 +04:00
|
|
|
|
|
|
|
NEWLINE;
|
2010-02-04 00:00:49 +03:00
|
|
|
|
2010-03-25 22:39:05 +03:00
|
|
|
fprintf(fp,
|
|
|
|
"%sstruct cfdriver * const cfdriver_%s_%s[] = {\n",
|
|
|
|
ioconfname ? "static " : "",
|
2010-03-26 18:51:17 +03:00
|
|
|
ioconfname ? "ioconf" : "list",
|
2010-03-25 22:39:05 +03:00
|
|
|
ioconfname ? ioconfname : "initial");
|
2010-02-04 00:00:49 +03:00
|
|
|
|
2002-09-27 06:24:06 +04:00
|
|
|
TAILQ_FOREACH(d, &allbases, d_next) {
|
|
|
|
if (!devbase_has_instances(d, WILD))
|
|
|
|
continue;
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\t&%s_cd,\n", d->d_name);
|
2002-09-27 06:24:06 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\tNULL\n};\n");
|
1998-01-12 10:37:40 +03:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitexterns(FILE *fp)
|
1998-01-12 10:37:40 +03:00
|
|
|
{
|
|
|
|
struct deva *da;
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
NEWLINE;
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(da, &alldevas, d_next) {
|
1996-03-17 05:08:22 +03:00
|
|
|
if (!deva_has_instances(da, WILD))
|
|
|
|
continue;
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "extern struct cfattach %s_ca;\n",
|
|
|
|
da->d_name);
|
1996-03-17 05:08:22 +03:00
|
|
|
}
|
2002-10-04 05:50:53 +04:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2002-10-04 05:50:53 +04:00
|
|
|
emitcfattachinit(FILE *fp)
|
|
|
|
{
|
|
|
|
struct devbase *d;
|
|
|
|
struct deva *da;
|
|
|
|
|
1996-03-17 05:08:22 +03:00
|
|
|
NEWLINE;
|
2002-10-04 05:50:53 +04:00
|
|
|
TAILQ_FOREACH(d, &allbases, d_next) {
|
|
|
|
if (!devbase_has_instances(d, WILD))
|
|
|
|
continue;
|
|
|
|
if (d->d_ahead == NULL)
|
|
|
|
continue;
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp,
|
|
|
|
"static struct cfattach * const %s_cfattachinit[] = {\n\t",
|
|
|
|
d->d_name);
|
2002-10-04 05:50:53 +04:00
|
|
|
for (da = d->d_ahead; da != NULL; da = da->d_bsame) {
|
|
|
|
if (!deva_has_instances(da, WILD))
|
|
|
|
continue;
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "&%s_ca, ", da->d_name);
|
2002-10-04 05:50:53 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "NULL\n};\n");
|
2002-10-04 05:50:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NEWLINE;
|
2010-03-25 22:39:05 +03:00
|
|
|
fprintf(fp, "%sconst struct cfattachinit cfattach%s%s[] = {\n",
|
|
|
|
ioconfname ? "static " : "",
|
2010-03-26 18:51:17 +03:00
|
|
|
ioconfname ? "_ioconf_" : "init",
|
2010-03-25 22:39:05 +03:00
|
|
|
ioconfname ? ioconfname : "");
|
2002-10-04 05:50:53 +04:00
|
|
|
|
|
|
|
TAILQ_FOREACH(d, &allbases, d_next) {
|
|
|
|
if (!devbase_has_instances(d, WILD))
|
|
|
|
continue;
|
|
|
|
if (d->d_ahead == NULL)
|
|
|
|
continue;
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\t{ \"%s\", %s_cfattachinit },\n",
|
|
|
|
d->d_name, d->d_name);
|
2002-10-04 05:50:53 +04:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\t{ NULL, NULL }\n};\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitloc(FILE *fp)
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
int i;
|
1993-06-06 08:14:01 +04:00
|
|
|
|
2001-01-18 10:09:47 +03:00
|
|
|
if (locators.used != 0) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\n/* locators */\n"
|
|
|
|
"static int loc[%d] = {", locators.used);
|
2001-01-18 10:09:47 +03:00
|
|
|
for (i = 0; i < locators.used; i++)
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "%s%s,", SEP(i, 8), locators.vec[i]);
|
|
|
|
fprintf(fp, "\n};\n");
|
2001-01-18 10:09:47 +03:00
|
|
|
}
|
1993-06-06 08:14:01 +04:00
|
|
|
}
|
1993-04-15 11:52:08 +04:00
|
|
|
|
1993-06-06 08:14:01 +04:00
|
|
|
/*
|
2002-09-26 08:07:35 +04:00
|
|
|
* Emit static parent data.
|
1993-06-06 08:14:01 +04:00
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2002-09-26 08:07:35 +04:00
|
|
|
emitparents(FILE *fp)
|
1993-09-16 01:15:19 +04:00
|
|
|
{
|
2002-09-26 08:07:35 +04:00
|
|
|
struct pspec *p;
|
2017-11-18 21:44:20 +03:00
|
|
|
int inst = -1;
|
1993-09-16 01:15:19 +04:00
|
|
|
|
2002-09-26 08:07:35 +04:00
|
|
|
NEWLINE;
|
|
|
|
TAILQ_FOREACH(p, &allpspecs, p_list) {
|
2005-10-02 03:30:37 +04:00
|
|
|
if (p->p_devs == NULL || p->p_active != DEVI_ACTIVE)
|
2002-09-26 08:07:35 +04:00
|
|
|
continue;
|
2017-11-19 04:46:29 +03:00
|
|
|
if (inst >= p->p_inst)
|
2017-11-18 21:44:20 +03:00
|
|
|
continue;
|
|
|
|
inst = p->p_inst;
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp,
|
|
|
|
"static const struct cfparent pspec%d = {\n", p->p_inst);
|
|
|
|
fprintf(fp, "\t\"%s\", ", p->p_iattr->a_name);
|
2002-09-26 08:07:35 +04:00
|
|
|
if (p->p_atdev != NULL) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\"%s\", ", p->p_atdev->d_name);
|
|
|
|
if (p->p_atunit == WILD)
|
|
|
|
fprintf(fp, "DVUNIT_ANY");
|
|
|
|
else
|
|
|
|
fprintf(fp, "%d", p->p_atunit);
|
|
|
|
} else
|
|
|
|
fprintf(fp, "NULL, 0");
|
|
|
|
fprintf(fp, "\n};\n");
|
2002-09-26 08:07:35 +04:00
|
|
|
}
|
1993-09-16 01:15:19 +04:00
|
|
|
}
|
1993-10-14 04:22:27 +03:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Emit the cfdata array.
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitcfdata(FILE *fp)
|
1993-10-14 04:22:27 +03:00
|
|
|
{
|
2002-09-26 08:07:35 +04:00
|
|
|
struct devi **p, *i;
|
|
|
|
struct pspec *ps;
|
1997-10-18 11:58:56 +04:00
|
|
|
int unit, v;
|
|
|
|
const char *state, *basename, *attachment;
|
2012-03-12 01:16:07 +04:00
|
|
|
struct loclist *ll;
|
1997-10-18 11:58:56 +04:00
|
|
|
struct attr *a;
|
2009-04-11 16:41:10 +04:00
|
|
|
const char *loc;
|
1995-04-28 10:54:58 +04:00
|
|
|
char locbuf[20];
|
1999-01-21 16:10:08 +03:00
|
|
|
const char *lastname = "";
|
1995-04-28 10:54:58 +04:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\n"
|
|
|
|
"#define NORM FSTATE_NOTFOUND\n"
|
|
|
|
"#define STAR FSTATE_STAR\n"
|
|
|
|
"\n"
|
2010-03-25 22:39:05 +03:00
|
|
|
"%sstruct cfdata cfdata%s%s[] = {\n"
|
2006-10-05 00:34:48 +04:00
|
|
|
" /* driver attachment unit state "
|
2014-10-31 21:26:06 +03:00
|
|
|
" loc flags pspec */\n",
|
2010-03-25 22:39:05 +03:00
|
|
|
ioconfname ? "static " : "",
|
2010-03-26 18:51:17 +03:00
|
|
|
ioconfname ? "_ioconf_" : "",
|
2010-02-04 00:00:49 +03:00
|
|
|
ioconfname ? ioconfname : "");
|
1995-04-28 10:54:58 +04:00
|
|
|
for (p = packed; (i = *p) != NULL; p++) {
|
|
|
|
/* the description */
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "/*%3d: %s at ", i->i_cfindex, i->i_name);
|
2002-09-26 08:07:35 +04:00
|
|
|
if ((ps = i->i_pspec) != NULL) {
|
|
|
|
if (ps->p_atdev != NULL &&
|
|
|
|
ps->p_atunit != WILD) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "%s%d", ps->p_atdev->d_name,
|
|
|
|
ps->p_atunit);
|
2002-09-26 08:07:35 +04:00
|
|
|
} else if (ps->p_atdev != NULL) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "%s?", ps->p_atdev->d_name);
|
1999-01-21 16:10:08 +03:00
|
|
|
} else {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "%s?", ps->p_iattr->a_name);
|
1999-01-21 16:10:08 +03:00
|
|
|
}
|
2002-09-26 08:07:35 +04:00
|
|
|
|
|
|
|
a = ps->p_iattr;
|
2012-03-12 01:16:07 +04:00
|
|
|
for (ll = a->a_locs, v = 0; ll != NULL;
|
|
|
|
ll = ll->ll_next, v++) {
|
|
|
|
if (ARRNAME(ll->ll_name, lastname)) {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, " %s %s",
|
2012-03-12 01:16:07 +04:00
|
|
|
ll->ll_name, i->i_locs[v]);
|
2002-09-26 08:07:35 +04:00
|
|
|
} else {
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, " %s %s",
|
2012-03-12 01:16:07 +04:00
|
|
|
ll->ll_name,
|
2006-10-05 00:34:48 +04:00
|
|
|
i->i_locs[v]);
|
2012-03-12 01:16:07 +04:00
|
|
|
lastname = ll->ll_name;
|
2002-09-26 08:07:35 +04:00
|
|
|
}
|
|
|
|
}
|
2002-09-27 01:07:49 +04:00
|
|
|
} else {
|
|
|
|
a = NULL;
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("root", fp);
|
2002-09-27 01:07:49 +04:00
|
|
|
}
|
2002-09-26 08:07:35 +04:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs(" */\n", fp);
|
1995-04-28 10:54:58 +04:00
|
|
|
|
|
|
|
/* then the actual defining line */
|
|
|
|
basename = i->i_base->d_name;
|
1996-03-17 05:08:22 +03:00
|
|
|
attachment = i->i_atdeva->d_name;
|
1995-04-28 10:54:58 +04:00
|
|
|
if (i->i_unit == STAR) {
|
|
|
|
unit = i->i_base->d_umax;
|
|
|
|
state = "STAR";
|
|
|
|
} else {
|
|
|
|
unit = i->i_unit;
|
|
|
|
state = "NORM";
|
1993-10-14 04:22:27 +03:00
|
|
|
}
|
1995-04-28 10:54:58 +04:00
|
|
|
if (i->i_locoff >= 0) {
|
2003-07-13 16:39:08 +04:00
|
|
|
(void)snprintf(locbuf, sizeof(locbuf), "loc+%3d",
|
|
|
|
i->i_locoff);
|
1995-04-28 10:54:58 +04:00
|
|
|
loc = locbuf;
|
|
|
|
} else
|
2014-11-01 09:20:24 +03:00
|
|
|
loc = "NULL";
|
2009-01-16 12:43:41 +03:00
|
|
|
fprintf(fp, " { \"%s\",%s\"%s\",%s%2d, %s, %7s, %#6x, ",
|
2014-10-31 21:26:06 +03:00
|
|
|
basename, strlen(basename) < 7 ? "\t\t"
|
2002-09-27 06:24:06 +04:00
|
|
|
: "\t",
|
2002-10-04 05:50:53 +04:00
|
|
|
attachment, strlen(attachment) < 5 ? "\t\t"
|
2002-09-26 08:07:35 +04:00
|
|
|
: "\t",
|
2006-10-05 00:34:48 +04:00
|
|
|
unit, state, loc, i->i_cfflags);
|
|
|
|
if (ps != NULL)
|
2009-01-16 12:43:41 +03:00
|
|
|
fprintf(fp, "&pspec%d },\n", ps->p_inst);
|
2006-10-05 00:34:48 +04:00
|
|
|
else
|
2009-01-16 12:43:41 +03:00
|
|
|
fputs("NULL },\n", fp);
|
1993-10-14 04:22:27 +03:00
|
|
|
}
|
2009-01-16 12:43:41 +03:00
|
|
|
fprintf(fp, " { %s,%s%s,%s%2d, %s, %7s, %#6x, %s }\n};\n",
|
2014-10-31 21:26:06 +03:00
|
|
|
"NULL", "\t\t", "NULL", "\t\t", 0, " 0", "NULL", 0, "NULL");
|
1993-10-14 04:22:27 +03:00
|
|
|
}
|
1993-09-16 01:15:19 +04:00
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Emit the table of potential roots.
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitroots(FILE *fp)
|
1994-02-01 05:07:11 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct devi **p, *i;
|
1994-02-01 05:07:11 +03:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("\nconst short cfroots[] = {\n", fp);
|
1995-04-28 10:54:58 +04:00
|
|
|
for (p = packed; (i = *p) != NULL; p++) {
|
|
|
|
if (i->i_at != NULL)
|
1994-02-01 05:07:11 +03:00
|
|
|
continue;
|
1995-04-28 10:54:58 +04:00
|
|
|
if (i->i_unit != 0 &&
|
|
|
|
(i->i_unit != STAR || i->i_base->d_umax != 0))
|
2007-01-14 02:47:36 +03:00
|
|
|
warnx("warning: `%s at root' is not unit 0", i->i_name);
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\t%2d /* %s */,\n",
|
|
|
|
i->i_cfindex, i->i_name);
|
1994-02-01 05:07:11 +03:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("\t-1\n};\n", fp);
|
1994-02-01 05:07:11 +03:00
|
|
|
}
|
|
|
|
|
1995-04-28 10:54:58 +04:00
|
|
|
/*
|
|
|
|
* Emit pseudo-device initialization.
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
static void
|
2000-10-02 23:48:34 +04:00
|
|
|
emitpseudo(FILE *fp)
|
1994-02-01 05:07:11 +03:00
|
|
|
{
|
1997-10-18 11:58:56 +04:00
|
|
|
struct devi *i;
|
|
|
|
struct devbase *d;
|
1994-02-01 05:07:11 +03:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("\n/* pseudo-devices */\n", fp);
|
2014-11-01 10:26:11 +03:00
|
|
|
fputs("\nconst struct pdevinit pdevinit[] = {\n", fp);
|
2002-06-05 14:56:17 +04:00
|
|
|
TAILQ_FOREACH(i, &allpseudo, i_next) {
|
1995-04-28 10:54:58 +04:00
|
|
|
d = i->i_base;
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\t{ %sattach, %d },\n",
|
|
|
|
d->d_name, d->d_umax);
|
1994-02-01 05:07:11 +03:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("\t{ 0, 0 }\n};\n", fp);
|
1994-02-01 05:07:11 +03:00
|
|
|
}
|
1998-02-18 10:00:27 +03:00
|
|
|
|
2002-09-11 10:20:09 +04:00
|
|
|
/*
|
|
|
|
* Emit name to major block number table.
|
|
|
|
*/
|
2006-10-05 00:34:48 +04:00
|
|
|
void
|
2002-09-11 10:20:09 +04:00
|
|
|
emitname2blk(FILE *fp)
|
|
|
|
{
|
|
|
|
struct devbase *dev;
|
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fputs("\n/* device name to major block number */\n", fp);
|
2002-09-11 10:20:09 +04:00
|
|
|
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "struct devnametobdevmaj dev_name2blk[] = {\n");
|
2002-09-11 10:20:09 +04:00
|
|
|
|
|
|
|
TAILQ_FOREACH(dev, &allbases, d_next) {
|
2009-01-20 21:20:47 +03:00
|
|
|
if (dev->d_major == NODEVMAJOR)
|
2002-09-11 10:20:09 +04:00
|
|
|
continue;
|
|
|
|
|
2009-01-20 21:20:47 +03:00
|
|
|
fprintf(fp, "\t{ \"%s\", %d },\n",
|
|
|
|
dev->d_name, dev->d_major);
|
2002-09-11 10:20:09 +04:00
|
|
|
}
|
2006-10-05 00:34:48 +04:00
|
|
|
fprintf(fp, "\t{ NULL, 0 }\n};\n");
|
2002-09-11 10:20:09 +04:00
|
|
|
}
|