Home | History | Annotate | Line # | Download | only in config
      1  1.109  riastrad /*	$NetBSD: defs.h,v 1.109 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: @(#)config.h	8.1 (Berkeley) 6/6/93
     41    1.1   thorpej  */
     42    1.1   thorpej 
     43    1.1   thorpej /*
     44    1.1   thorpej  * defs.h:  Global definitions for "config"
     45    1.1   thorpej  */
     46    1.1   thorpej 
     47    1.1   thorpej #if HAVE_NBTOOL_CONFIG_H
     48    1.1   thorpej #include "nbtool_config.h"
     49    1.1   thorpej #endif
     50    1.1   thorpej 
     51    1.1   thorpej #include <sys/types.h>
     52    1.1   thorpej #include <sys/param.h>
     53    1.1   thorpej #include <sys/queue.h>
     54    1.1   thorpej 
     55    1.1   thorpej #if !defined(MAKE_BOOTSTRAP) && defined(BSD)
     56    1.1   thorpej #include <sys/cdefs.h>
     57    1.1   thorpej #include <paths.h>
     58    1.1   thorpej #endif
     59    1.1   thorpej 
     60    1.1   thorpej #include <stdio.h>
     61    1.1   thorpej #include <stdlib.h>
     62    1.1   thorpej #include <unistd.h>
     63    1.1   thorpej 
     64    1.1   thorpej /* These are really for MAKE_BOOTSTRAP but harmless. */
     65    1.1   thorpej #ifndef __dead
     66    1.1   thorpej #define __dead
     67    1.1   thorpej #endif
     68   1.36  dholland #ifndef __printflike
     69   1.36  dholland #define __printflike(a, b)
     70   1.36  dholland #endif
     71    1.1   thorpej #ifndef _PATH_DEVNULL
     72    1.1   thorpej #define _PATH_DEVNULL "/dev/null"
     73    1.1   thorpej #endif
     74    1.1   thorpej 
     75    1.1   thorpej #ifdef	MAKE_BOOTSTRAP
     76    1.1   thorpej #undef	dev_t
     77   1.27  drochner #undef	devmajor_t
     78   1.27  drochner #undef	devminor_t
     79    1.1   thorpej #undef	NODEV
     80   1.27  drochner #undef	NODEVMAJOR
     81    1.1   thorpej #undef	major
     82    1.1   thorpej #undef	minor
     83    1.1   thorpej #undef	makedev
     84   1.27  drochner #define	dev_t		unsigned int	/* XXX: assumes int is 32 bits */
     85    1.1   thorpej #define	NODEV		((dev_t)-1)
     86   1.27  drochner #define devmajor_t	int
     87   1.27  drochner #define devminor_t	int
     88   1.27  drochner #define NODEVMAJOR	(-1)
     89   1.27  drochner #define major(x)        ((devmajor_t)((((x) & 0x000fff00) >>  8)))
     90   1.27  drochner #define minor(x)        ((devminor_t)((((x) & 0xfff00000) >> 12) | \
     91    1.1   thorpej 			       (((x) & 0x000000ff) >>  0)))
     92   1.95  christos #define makedev(x,y)    ((dev_t)((((dev_t)(x) <<  8) & 0x000fff00U) | \
     93   1.95  christos                                  (((dev_t)(y) << 12) & 0xfff00000U) | \
     94   1.95  christos                                  (((dev_t)(y) <<  0) & 0x000000ffU)))
     95    1.1   thorpej #define __attribute__(x)
     96    1.1   thorpej #endif	/* MAKE_BOOTSTRAP */
     97    1.1   thorpej 
     98    1.1   thorpej #undef setprogname
     99    1.1   thorpej #undef getprogname
    100    1.1   thorpej extern const char *progname;
    101    1.1   thorpej #define	setprogname(s)	((void)(progname = (s)))
    102    1.1   thorpej #define	getprogname()	(progname)
    103    1.1   thorpej 
    104    1.1   thorpej #define ARRCHR '#'
    105    1.1   thorpej 
    106    1.1   thorpej /*
    107    1.8      cube  * The next two lines define the current version of the config(1) binary,
    108    1.8      cube  * and the minimum version of the configuration files it supports.
    109    1.8      cube  */
    110  1.108   thorpej #define CONFIG_VERSION		20240118
    111    1.8      cube #define CONFIG_MINVERSION	0
    112    1.8      cube 
    113  1.105  christos struct where {
    114  1.105  christos 	const char *w_srcfile;		/* file name where we are defined */
    115  1.105  christos 	u_short	w_srcline;		/* line number where we are defined */
    116  1.105  christos };
    117    1.8      cube /*
    118    1.1   thorpej  * Name/value lists.  Values can be strings or pointers and/or can carry
    119    1.1   thorpej  * integers.  The names can be NULL, resulting in simple value lists.
    120    1.1   thorpej  */
    121    1.1   thorpej struct nvlist {
    122   1.14       dsl 	struct nvlist	*nv_next;
    123   1.14       dsl 	const char	*nv_name;
    124   1.14       dsl 	const char	*nv_str;
    125   1.14       dsl 	void		*nv_ptr;
    126   1.26  christos 	long long	nv_num;
    127   1.14       dsl 	int		nv_ifunit;		/* XXX XXX XXX */
    128   1.14       dsl 	int		nv_flags;
    129    1.1   thorpej #define	NV_DEPENDED	1
    130  1.105  christos 	struct where	nv_where;
    131    1.1   thorpej };
    132    1.1   thorpej 
    133    1.1   thorpej /*
    134    1.1   thorpej  * Kernel configurations.
    135    1.1   thorpej  */
    136    1.1   thorpej struct config {
    137    1.1   thorpej 	TAILQ_ENTRY(config) cf_next;
    138    1.1   thorpej 	const char *cf_name;		/* "netbsd" */
    139    1.1   thorpej 	const char *cf_fstype;		/* file system type */
    140    1.1   thorpej 	struct	nvlist *cf_root;	/* "root on ra0a" */
    141    1.1   thorpej 	struct	nvlist *cf_dump;	/* "dumps on ra0b" */
    142  1.105  christos 	struct where	cf_where;
    143    1.1   thorpej };
    144    1.1   thorpej 
    145    1.1   thorpej /*
    146   1.42  dholland  * Option definition list
    147   1.42  dholland  */
    148   1.42  dholland struct defoptlist {
    149   1.42  dholland 	struct defoptlist *dl_next;
    150   1.42  dholland 	const char *dl_name;
    151   1.42  dholland 	const char *dl_value;
    152   1.42  dholland 	const char *dl_lintvalue;
    153   1.42  dholland 	int dl_obsolete;
    154  1.107   thorpej 	int dl_mkvar;
    155   1.42  dholland 	struct nvlist *dl_depends;
    156  1.105  christos 	struct where	dl_where;
    157   1.42  dholland };
    158   1.42  dholland 
    159   1.76  uebayasi struct files;
    160   1.76  uebayasi TAILQ_HEAD(filelist, files);
    161   1.76  uebayasi 
    162   1.61  uebayasi struct module {
    163   1.61  uebayasi 	const char		*m_name;
    164   1.61  uebayasi #if 1
    165   1.61  uebayasi 	struct attrlist		*m_deps;
    166   1.61  uebayasi #else
    167   1.61  uebayasi 	struct attrlist		*m_attrs;
    168   1.61  uebayasi 	struct modulelist	*m_deps;
    169   1.61  uebayasi #endif
    170   1.61  uebayasi 	int			m_expanding;
    171   1.76  uebayasi 	struct filelist		m_files;
    172   1.63  uebayasi 	int			m_weight;
    173   1.61  uebayasi };
    174   1.61  uebayasi 
    175   1.42  dholland /*
    176    1.1   thorpej  * Attributes.  These come in three flavors: "plain", "device class,"
    177    1.1   thorpej  * and "interface".  Plain attributes (e.g., "ether") simply serve
    178    1.1   thorpej  * to pull in files.  Device class attributes are like plain
    179    1.1   thorpej  * attributes, but additionally specify a device class (e.g., the
    180    1.1   thorpej  * "disk" device class attribute specifies that devices with the
    181    1.1   thorpej  * attribute belong to the "DV_DISK" class) and are mutually exclusive.
    182    1.1   thorpej  * Interface attributes (e.g., "scsi") carry three lists: locators,
    183    1.1   thorpej  * child devices, and references.  The locators are those things
    184    1.1   thorpej  * that must be specified in order to configure a device instance
    185    1.1   thorpej  * using this attribute (e.g., "tg0 at scsi0").  The a_devs field
    186    1.1   thorpej  * lists child devices that can connect here (e.g., "tg"s), while
    187    1.1   thorpej  * the a_refs are parents that carry the attribute (e.g., actual
    188    1.1   thorpej  * SCSI host adapter drivers such as the SPARC "esp").
    189    1.1   thorpej  */
    190    1.1   thorpej struct attr {
    191   1.61  uebayasi 	/* XXX */
    192   1.61  uebayasi 	struct module a_m;
    193   1.61  uebayasi #define	a_name		a_m.m_name
    194   1.61  uebayasi #define	a_deps		a_m.m_deps
    195   1.61  uebayasi #define	a_expanding	a_m.m_expanding
    196   1.61  uebayasi #define	a_files		a_m.m_files
    197   1.63  uebayasi #define	a_weight	a_m.m_weight
    198   1.54  uebayasi 
    199   1.54  uebayasi 	/* "interface attribute" */
    200   1.98  christos 	uint8_t	a_iattr;		/* true => allows children */
    201   1.98  christos 	uint8_t a_deselected;		/* deselected */
    202   1.40  dholland 	struct	loclist *a_locs;	/* locators required */
    203    1.1   thorpej 	int	a_loclen;		/* length of above list */
    204    1.1   thorpej 	struct	nvlist *a_devs;		/* children */
    205    1.1   thorpej 	struct	nvlist *a_refs;		/* parents */
    206   1.54  uebayasi 
    207   1.54  uebayasi 	/* "device class" */
    208   1.54  uebayasi 	const char *a_devclass;		/* device class described */
    209  1.105  christos 	struct where a_where;
    210  1.109  riastrad 
    211  1.109  riastrad 	size_t	a_idx;			/* index to break sorting ties */
    212    1.1   thorpej };
    213    1.1   thorpej 
    214    1.1   thorpej /*
    215   1.38  dholland  * List of attributes.
    216   1.38  dholland  */
    217   1.38  dholland struct attrlist {
    218   1.38  dholland 	struct attrlist *al_next;
    219   1.38  dholland 	struct attr *al_this;
    220   1.38  dholland };
    221   1.38  dholland 
    222   1.38  dholland /*
    223   1.40  dholland  * List of locators. (Either definitions or uses...)
    224   1.40  dholland  *
    225   1.40  dholland  * XXX it would be nice if someone could clarify wtf ll_string and ll_num
    226   1.40  dholland  * are actually holding. (This stuff was previously stored in a very ad
    227   1.40  dholland  * hoc fashion, and the code is far from clear.)
    228   1.40  dholland  */
    229   1.40  dholland struct loclist {
    230   1.40  dholland 	const char *ll_name;
    231   1.40  dholland 	const char *ll_string;
    232   1.40  dholland 	long long ll_num;
    233   1.40  dholland 	struct loclist *ll_next;
    234   1.40  dholland };
    235   1.40  dholland 
    236   1.40  dholland /*
    237    1.1   thorpej  * Parent specification.  Multiple device instances may share a
    238    1.1   thorpej  * given parent spec.  Parent specs are emitted only if there are
    239    1.1   thorpej  * device instances which actually reference it.
    240    1.1   thorpej  */
    241    1.1   thorpej struct pspec {
    242    1.1   thorpej 	TAILQ_ENTRY(pspec) p_list;	/* link on parent spec list */
    243    1.1   thorpej 	struct	attr *p_iattr;		/* interface attribute of parent */
    244    1.1   thorpej 	struct	devbase *p_atdev;	/* optional parent device base */
    245    1.1   thorpej 	int	p_atunit;		/* optional parent device unit */
    246    1.1   thorpej 	struct	nvlist *p_devs;		/* children using it */
    247    1.1   thorpej 	int	p_inst;			/* parent spec instance */
    248    1.3      cube 	int	p_active;		/* parent spec is actively used */
    249  1.102  christos 	int	p_ref;			/* refcount */
    250    1.1   thorpej };
    251    1.1   thorpej 
    252    1.1   thorpej /*
    253    1.1   thorpej  * The "base" part (struct devbase) of a device ("uba", "sd"; but not
    254    1.1   thorpej  * "uba2" or "sd0").  It may be found "at" one or more attributes,
    255    1.1   thorpej  * including "at root" (this is represented by a NULL attribute), as
    256    1.1   thorpej  * specified by the device attachments (struct deva).
    257    1.1   thorpej  *
    258    1.1   thorpej  * Each device may also export attributes.  If any provide an output
    259    1.1   thorpej  * interface (e.g., "esp" provides "scsi"), other devices (e.g.,
    260    1.1   thorpej  * "tg"s) can be found at instances of this one (e.g., "esp"s).
    261    1.1   thorpej  * Such a connection must provide locators as specified by that
    262    1.1   thorpej  * interface attribute (e.g., "target").  The base device can
    263    1.1   thorpej  * export both output (aka `interface') attributes, as well as
    264    1.1   thorpej  * import input (`plain') attributes.  Device attachments may
    265    1.1   thorpej  * only import input attributes; it makes no sense to have a
    266    1.1   thorpej  * specific attachment export a new interface to other devices.
    267    1.1   thorpej  *
    268    1.1   thorpej  * Each base carries a list of instances (via d_ihead).  Note that this
    269    1.1   thorpej  * list "skips over" aliases; those must be found through the instances
    270    1.1   thorpej  * themselves.  Each base also carries a list of possible attachments,
    271    1.1   thorpej  * each of which specify a set of devices that the device can attach
    272    1.1   thorpej  * to, as well as the device instances that are actually using that
    273    1.1   thorpej  * attachment.
    274    1.1   thorpej  */
    275    1.1   thorpej struct devbase {
    276    1.1   thorpej 	const char *d_name;		/* e.g., "sd" */
    277    1.1   thorpej 	TAILQ_ENTRY(devbase) d_next;
    278  1.100  christos 	int 	d_level;
    279  1.100  christos 	struct devbase *d_levelparent;
    280    1.1   thorpej 	int	d_isdef;		/* set once properly defined */
    281    1.1   thorpej 	int	d_ispseudo;		/* is a pseudo-device */
    282   1.27  drochner 	devmajor_t d_major;		/* used for "root on sd0", e.g. */
    283   1.38  dholland 	struct	attrlist *d_attrs;	/* attributes, if any */
    284    1.1   thorpej 	int	d_umax;			/* highest unit number + 1 */
    285    1.1   thorpej 	struct	devi *d_ihead;		/* first instance, if any */
    286    1.1   thorpej 	struct	devi **d_ipp;		/* used for tacking on more instances */
    287    1.1   thorpej 	struct	deva *d_ahead;		/* first attachment, if any */
    288    1.1   thorpej 	struct	deva **d_app;		/* used for tacking on attachments */
    289    1.1   thorpej 	struct	attr *d_classattr;	/* device class attribute (if any) */
    290  1.105  christos 	struct	where d_where;
    291    1.1   thorpej };
    292    1.1   thorpej 
    293    1.1   thorpej struct deva {
    294    1.1   thorpej 	const char *d_name;		/* name of attachment, e.g. "com_isa" */
    295    1.1   thorpej 	TAILQ_ENTRY(deva) d_next;	/* list of all instances */
    296    1.1   thorpej 	struct	deva *d_bsame;		/* list on same base */
    297    1.1   thorpej 	int	d_isdef;		/* set once properly defined */
    298    1.1   thorpej 	struct	devbase *d_devbase;	/* the base device */
    299    1.1   thorpej 	struct	nvlist *d_atlist;	/* e.g., "at tg" (attr list) */
    300   1.38  dholland 	struct	attrlist *d_attrs;	/* attributes, if any */
    301    1.1   thorpej 	struct	devi *d_ihead;		/* first instance, if any */
    302    1.1   thorpej 	struct	devi **d_ipp;		/* used for tacking on more instances */
    303  1.105  christos 	struct	where d_where;
    304    1.1   thorpej };
    305    1.1   thorpej 
    306    1.1   thorpej /*
    307    1.1   thorpej  * An "instance" of a device.  The same instance may be listed more
    308    1.1   thorpej  * than once, e.g., "xx0 at isa? port FOO" + "xx0 at isa? port BAR".
    309    1.1   thorpej  *
    310    1.1   thorpej  * After everything has been read in and verified, the devi's are
    311    1.1   thorpej  * "packed" to collect all the information needed to generate ioconf.c.
    312    1.1   thorpej  * In particular, we try to collapse multiple aliases into a single entry.
    313    1.1   thorpej  * We then assign each "primary" (non-collapsed) instance a cfdata index.
    314    1.1   thorpej  * Note that there may still be aliases among these.
    315    1.1   thorpej  */
    316    1.1   thorpej struct devi {
    317    1.1   thorpej 	/* created while parsing config file */
    318    1.1   thorpej 	const char *i_name;	/* e.g., "sd0" */
    319    1.1   thorpej 	int	i_unit;		/* unit from name, e.g., 0 */
    320    1.1   thorpej 	struct	devbase *i_base;/* e.g., pointer to "sd" base */
    321    1.1   thorpej 	TAILQ_ENTRY(devi) i_next; /* list of all instances */
    322    1.1   thorpej 	struct	devi *i_bsame;	/* list on same base */
    323    1.1   thorpej 	struct	devi *i_asame;	/* list on same base attachment */
    324    1.1   thorpej 	struct	devi *i_alias;	/* other aliases of this instance */
    325    1.1   thorpej 	const char *i_at;	/* where this is "at" (NULL if at root) */
    326    1.1   thorpej 	struct	pspec *i_pspec;	/* parent spec (NULL if at root) */
    327    1.1   thorpej 	struct	deva *i_atdeva;
    328    1.1   thorpej 	const char **i_locs;	/* locators (as given by pspec's iattr) */
    329    1.1   thorpej 	int	i_cfflags;	/* flags from config line */
    330    1.7      cube 	int	i_level;	/* position between negated instances */
    331    1.4      cube 	int	i_active;
    332    1.4      cube #define	DEVI_ORPHAN	0	/* instance has no active parent */
    333    1.4      cube #define	DEVI_ACTIVE	1	/* instance has an active parent */
    334    1.4      cube #define	DEVI_IGNORED	2	/* instance's parent has been removed */
    335    1.6      cube #define DEVI_BROKEN	3	/* instance is broken (syntax error) */
    336   1.33     pooka 	int	i_pseudoroot;	/* instance is pseudoroot */
    337    1.1   thorpej 
    338    1.1   thorpej 	/* created during packing or ioconf.c generation */
    339    1.1   thorpej 	short	i_collapsed;	/* set => this alias no longer needed */
    340   1.59  christos 	u_short	i_cfindex;	/* our index in cfdata */
    341   1.59  christos 	int	i_locoff;	/* offset in locators.vec */
    342  1.105  christos 	struct	where i_where;
    343    1.1   thorpej };
    344    1.1   thorpej /* special units */
    345    1.1   thorpej #define	STAR	(-1)		/* unit number for, e.g., "sd*" */
    346    1.1   thorpej #define	WILD	(-2)		/* unit number for, e.g., "sd?" */
    347    1.1   thorpej 
    348    1.1   thorpej /*
    349   1.77  uebayasi  * Files (*.c, *.S, or *.o).  This structure defines the common fields
    350    1.9       erh  * between the two.
    351    1.9       erh  */
    352    1.1   thorpej struct files {
    353   1.77  uebayasi 	TAILQ_ENTRY(files) fi_next;
    354   1.79  uebayasi 	TAILQ_ENTRY(files) fi_snext;	/* per-suffix list */
    355  1.105  christos 	struct	where fi_where;
    356   1.79  uebayasi 	u_char fi_flags;	/* as below */
    357   1.77  uebayasi 	const char *fi_tail;	/* name, i.e., strrchr(fi_path, '/') + 1 */
    358   1.77  uebayasi 	const char *fi_base;	/* tail minus ".c" (or whatever) */
    359   1.80  uebayasi 	const char *fi_dir;	/* path to file */
    360   1.77  uebayasi 	const char *fi_path;	/* full file path */
    361   1.77  uebayasi 	const char *fi_prefix;	/* any file prefix */
    362   1.81  uebayasi 	const char *fi_buildprefix;	/* prefix in builddir */
    363   1.77  uebayasi 	int fi_suffix;		/* single char suffix */
    364   1.77  uebayasi 	size_t fi_len;		/* path string length */
    365   1.77  uebayasi 	struct condexpr *fi_optx; /* options expression */
    366   1.77  uebayasi 	struct nvlist *fi_optf; /* flattened version of above, if needed */
    367   1.79  uebayasi 	const char *fi_mkrule;	/* special make rule, if any */
    368   1.77  uebayasi 	struct attr *fi_attr;	/* owner attr */
    369   1.93  uebayasi 	int fi_order;		/* score of order in ${ALLFILES} */
    370   1.77  uebayasi 	TAILQ_ENTRY(files) fi_anext;	/* next file in attr */
    371    1.9       erh };
    372    1.9       erh 
    373    1.1   thorpej /* flags */
    374    1.1   thorpej #define	FI_SEL		0x01	/* selected */
    375    1.1   thorpej #define	FI_NEEDSCOUNT	0x02	/* needs-count */
    376    1.1   thorpej #define	FI_NEEDSFLAG	0x04	/* needs-flag */
    377    1.1   thorpej #define	FI_HIDDEN	0x08	/* obscured by other(s), base names overlap */
    378    1.1   thorpej 
    379   1.93  uebayasi extern size_t nselfiles;
    380   1.93  uebayasi extern struct files **selfiles;
    381   1.93  uebayasi 
    382    1.1   thorpej /*
    383   1.39  dholland  * Condition expressions.
    384   1.39  dholland  */
    385   1.39  dholland 
    386   1.39  dholland enum condexpr_types {
    387   1.39  dholland 	CX_ATOM,
    388   1.39  dholland 	CX_NOT,
    389   1.39  dholland 	CX_AND,
    390   1.39  dholland 	CX_OR,
    391   1.39  dholland };
    392   1.39  dholland struct condexpr {
    393   1.39  dholland 	enum condexpr_types cx_type;
    394   1.39  dholland 	union {
    395   1.39  dholland 		const char *atom;
    396   1.39  dholland 		struct condexpr *not;
    397   1.39  dholland 		struct {
    398   1.39  dholland 			struct condexpr *left;
    399   1.39  dholland 			struct condexpr *right;
    400   1.39  dholland 		} and, or;
    401   1.39  dholland 	} cx_u;
    402   1.39  dholland };
    403   1.39  dholland #define cx_atom	cx_u.atom
    404   1.39  dholland #define cx_not	cx_u.not
    405   1.39  dholland #define cx_and	cx_u.and
    406   1.39  dholland #define cx_or	cx_u.or
    407    1.1   thorpej 
    408    1.1   thorpej /*
    409    1.1   thorpej  * File/object prefixes.  These are arranged in a stack, and affect
    410    1.1   thorpej  * the behavior of the source path.
    411    1.1   thorpej  */
    412   1.81  uebayasi 
    413   1.81  uebayasi struct prefix;
    414   1.81  uebayasi SLIST_HEAD(prefixlist, prefix);
    415   1.81  uebayasi 
    416    1.1   thorpej struct prefix {
    417    1.1   thorpej 	SLIST_ENTRY(prefix)	pf_next;	/* next prefix in stack */
    418    1.1   thorpej 	const char		*pf_prefix;	/* the actual prefix */
    419    1.1   thorpej };
    420    1.1   thorpej 
    421    1.1   thorpej /*
    422    1.1   thorpej  * Device major informations.
    423    1.1   thorpej  */
    424    1.1   thorpej struct devm {
    425    1.1   thorpej 	TAILQ_ENTRY(devm) dm_next;
    426    1.1   thorpej 	const char	*dm_name;	/* [bc]devsw name */
    427   1.27  drochner 	devmajor_t	dm_cmajor;	/* character major */
    428   1.27  drochner 	devmajor_t	dm_bmajor;	/* block major */
    429   1.39  dholland 	struct condexpr	*dm_opts;	/* options */
    430   1.35     pooka 	struct nvlist	*dm_devnodes;	/* information on /dev nodes */
    431  1.105  christos 	struct where dm_where;
    432    1.1   thorpej };
    433    1.1   thorpej 
    434    1.1   thorpej /*
    435    1.1   thorpej  * Hash tables look up name=value pairs.  The pointer value of the name
    436    1.1   thorpej  * is assumed to be constant forever; this can be arranged by interning
    437    1.1   thorpej  * the name.  (This is fairly convenient since our lexer does this for
    438    1.1   thorpej  * all identifier-like strings---it has to save them anyway, lest yacc's
    439    1.1   thorpej  * look-ahead wipe out the current one.)
    440    1.1   thorpej  */
    441    1.1   thorpej struct hashtab;
    442    1.1   thorpej 
    443  1.106     joerg extern int lkmmode;
    444  1.106     joerg extern const char *conffile;		/* source file, e.g., "GENERIC.sparc" */
    445  1.106     joerg extern const char *machine;		/* machine type, e.g., "sparc" or "sun3" */
    446  1.106     joerg extern const char *machinearch;	/* machine arch, e.g., "sparc" or "m68k" */
    447  1.106     joerg extern struct	nvlist *machinesubarches;
    448    1.1   thorpej 				/* machine subarches, e.g., "sun68k" or "hpc" */
    449  1.106     joerg extern const char *ioconfname;		/* ioconf name, mutually exclusive to machine */
    450  1.106     joerg extern const char *srcdir;		/* path to source directory (rel. to build) */
    451  1.106     joerg extern const char *builddir;		/* path to build directory */
    452  1.106     joerg extern const char *defbuilddir;	/* default build directory */
    453  1.106     joerg extern const char *ident;		/* kernel "ident"ification string */
    454  1.106     joerg extern int	errors;			/* counts calls to error() */
    455  1.106     joerg extern int	minmaxusers;		/* minimum "maxusers" parameter */
    456  1.106     joerg extern int	defmaxusers;		/* default "maxusers" parameter */
    457  1.106     joerg extern int	maxmaxusers;		/* default "maxusers" parameter */
    458  1.106     joerg extern int	maxusers;		/* configuration's "maxusers" parameter */
    459  1.106     joerg extern int	maxpartitions;		/* configuration's "maxpartitions" parameter */
    460  1.106     joerg extern int	version;		/* version of the configuration file */
    461  1.106     joerg extern struct	nvlist *options;	/* options */
    462  1.106     joerg extern struct	nvlist *fsoptions;	/* filesystems */
    463  1.106     joerg extern struct	nvlist *mkoptions;	/* makeoptions */
    464  1.106     joerg extern struct	nvlist *appmkoptions;	/* appending mkoptions */
    465  1.106     joerg extern struct	nvlist *condmkoptions;	/* conditional makeoption table */
    466  1.106     joerg extern struct	hashtab *devbasetab;	/* devbase lookup */
    467  1.106     joerg extern struct	hashtab *devroottab;	/* attach at root lookup */
    468  1.106     joerg extern struct	hashtab *devatab;	/* devbase attachment lookup */
    469  1.106     joerg extern struct	hashtab *devitab;	/* device instance lookup */
    470  1.106     joerg extern struct	hashtab *deaddevitab;	/* removed instances lookup */
    471  1.106     joerg extern struct	hashtab *selecttab;	/* selects things that are "optional foo" */
    472  1.106     joerg extern struct	hashtab *needcnttab;	/* retains names marked "needs-count" */
    473  1.106     joerg extern struct	hashtab *opttab;	/* table of configured options */
    474  1.106     joerg extern struct	hashtab *fsopttab;	/* table of configured file systems */
    475  1.106     joerg extern struct	dlhash *defopttab;	/* options that have been "defopt"'d */
    476  1.106     joerg extern struct	dlhash *defflagtab;	/* options that have been "defflag"'d */
    477  1.106     joerg extern struct	dlhash *defparamtab;	/* options that have been "defparam"'d */
    478  1.106     joerg extern struct	dlhash *defoptlint;	/* lint values for options */
    479  1.106     joerg extern struct	nvhash *deffstab;	/* defined file systems */
    480  1.106     joerg extern struct	dlhash *optfiletab;	/* "defopt"'d option .h files */
    481  1.106     joerg extern struct	hashtab *attrtab;	/* attributes (locators, etc.) */
    482  1.106     joerg extern struct	hashtab *attrdeptab;	/* attribute dependencies */
    483  1.106     joerg extern struct	hashtab *bdevmtab;	/* block devm lookup */
    484  1.106     joerg extern struct	hashtab *cdevmtab;	/* character devm lookup */
    485  1.106     joerg 
    486  1.106     joerg TAILQ_HEAD(devbasetq, devbase);
    487  1.106     joerg TAILQ_HEAD(devatq, deva);
    488  1.106     joerg TAILQ_HEAD(conftq, config);
    489  1.106     joerg TAILQ_HEAD(devitq, devi);
    490  1.106     joerg TAILQ_HEAD(devmtq, devm);
    491  1.106     joerg TAILQ_HEAD(pspectq, pspec);
    492  1.106     joerg 
    493  1.106     joerg extern struct devbasetq allbases;	/* list of all devbase structures */
    494  1.106     joerg extern struct devatq alldevas;		/* list of all devbase attachments */
    495  1.106     joerg extern struct conftq allcf;		/* list of configured kernels */
    496  1.106     joerg extern struct devitq alldevi,		/* list of all instances */
    497  1.106     joerg 		     allpseudo;		/* list of all pseudo-devices */
    498  1.106     joerg extern struct devmtq alldevms;		/* list of all device-majors */
    499  1.106     joerg extern struct pspectq allpspecs;	/* list of all parent specs */
    500  1.106     joerg extern int	ndevi;			/* number of devi's (before packing) */
    501  1.106     joerg extern int	npspecs;		/* number of parent specs */
    502  1.106     joerg extern devmajor_t maxbdevm;		/* max number of block major */
    503  1.106     joerg extern devmajor_t maxcdevm;		/* max number of character major */
    504  1.106     joerg extern int	do_devsw;		/* 0 if pre-devsw config */
    505  1.106     joerg extern int	oktopackage;		/* 0 before setmachine() */
    506  1.106     joerg extern int	devilevel;		/* used for devi->i_level */
    507  1.106     joerg 
    508  1.106     joerg extern struct filelist		allfiles;	/* list of all kernel source files */
    509  1.106     joerg extern struct filelist		allcfiles;	/* list of all .c files */
    510  1.106     joerg extern struct filelist		allsfiles;	/* list of all .S files */
    511  1.106     joerg extern struct filelist		allofiles;	/* list of all .o files */
    512  1.106     joerg 
    513  1.106     joerg extern struct prefixlist	prefixes,	/* prefix stack */
    514  1.106     joerg 				allprefixes;	/* all prefixes used
    515  1.106     joerg 						 * (after popped) */
    516  1.106     joerg extern struct prefixlist	buildprefixes,	/* build prefix stack */
    517  1.106     joerg 				allbuildprefixes;/* all build prefixes used
    518  1.106     joerg 						  * (after popped) */
    519    1.1   thorpej 
    520   1.50  uebayasi extern struct attr allattr;
    521  1.106     joerg extern struct devi **packed;	/* arrayified table for packed devi's */
    522  1.106     joerg extern size_t npacked;		/* size of packed table, <= ndevi */
    523    1.1   thorpej 
    524  1.106     joerg extern struct locators {			/* loc[] table for config */
    525    1.1   thorpej 	const char **vec;
    526    1.1   thorpej 	int	used;
    527    1.1   thorpej } locators;
    528    1.1   thorpej 
    529    1.1   thorpej struct numconst {
    530    1.1   thorpej 	int64_t	val;
    531    1.1   thorpej 	int fmt;
    532    1.1   thorpej };
    533    1.1   thorpej 
    534    1.1   thorpej /* files.c */
    535    1.1   thorpej void	initfiles(void);
    536    1.1   thorpej void	checkfiles(void);
    537    1.1   thorpej int	fixfiles(void);		/* finalize */
    538    1.1   thorpej int	fixdevsw(void);
    539   1.67  uebayasi void	addfile(const char *, struct condexpr *, u_char, const char *);
    540   1.39  dholland int	expr_eval(struct condexpr *, int (*)(const char *, void *), void *);
    541    1.1   thorpej 
    542    1.1   thorpej /* hash.c */
    543    1.1   thorpej struct	hashtab *ht_new(void);
    544   1.16  christos void	ht_free(struct hashtab *);
    545   1.57  uebayasi int	ht_insrep2(struct hashtab *, const char *, const char *, void *, int);
    546    1.1   thorpej int	ht_insrep(struct hashtab *, const char *, void *, int);
    547   1.57  uebayasi #define	ht_insert2(ht, nam1, nam2, val) ht_insrep2(ht, nam1, nam2, val, 0)
    548    1.1   thorpej #define	ht_insert(ht, nam, val) ht_insrep(ht, nam, val, 0)
    549    1.1   thorpej #define	ht_replace(ht, nam, val) ht_insrep(ht, nam, val, 1)
    550   1.57  uebayasi int	ht_remove2(struct hashtab *, const char *, const char *);
    551    1.1   thorpej int	ht_remove(struct hashtab *, const char *);
    552   1.57  uebayasi void	*ht_lookup2(struct hashtab *, const char *, const char *);
    553    1.1   thorpej void	*ht_lookup(struct hashtab *, const char *);
    554    1.1   thorpej void	initintern(void);
    555    1.1   thorpej const char *intern(const char *);
    556   1.57  uebayasi typedef int (*ht_callback2)(const char *, const char *, void *, void *);
    557    1.1   thorpej typedef int (*ht_callback)(const char *, void *, void *);
    558   1.57  uebayasi int	ht_enumerate2(struct hashtab *, ht_callback2, void *);
    559    1.1   thorpej int	ht_enumerate(struct hashtab *, ht_callback, void *);
    560    1.1   thorpej 
    561   1.41  dholland /* typed hash, named struct HT, whose type is string -> struct VT */
    562   1.41  dholland #define DECLHASH(HT, VT) \
    563   1.41  dholland 	struct HT;							\
    564   1.41  dholland 	struct HT *HT##_create(void);					\
    565   1.41  dholland 	int HT##_insert(struct HT *, const char *, struct VT *);	\
    566   1.41  dholland 	int HT##_replace(struct HT *, const char *, struct VT *);	\
    567   1.41  dholland 	int HT##_remove(struct HT *, const char *);			\
    568   1.41  dholland 	struct VT *HT##_lookup(struct HT *, const char *);		\
    569   1.41  dholland 	int HT##_enumerate(struct HT *,					\
    570   1.41  dholland 			int (*)(const char *, struct VT *, void *),	\
    571   1.41  dholland 			void *)
    572   1.41  dholland DECLHASH(nvhash, nvlist);
    573   1.42  dholland DECLHASH(dlhash, defoptlist);
    574   1.41  dholland 
    575   1.17      cube /* lint.c */
    576   1.17      cube void	emit_instances(void);
    577   1.17      cube void	emit_options(void);
    578   1.17      cube void	emit_params(void);
    579   1.17      cube 
    580    1.1   thorpej /* main.c */
    581   1.62  uebayasi extern	int Mflag;
    582   1.83  uebayasi extern	int Sflag;
    583    1.1   thorpej void	addoption(const char *, const char *);
    584    1.1   thorpej void	addfsoption(const char *);
    585    1.1   thorpej void	addmkoption(const char *, const char *);
    586    1.1   thorpej void	appendmkoption(const char *, const char *);
    587   1.39  dholland void	appendcondmkoption(struct condexpr *, const char *, const char *);
    588   1.32     pooka void	deffilesystem(struct nvlist *, struct nvlist *);
    589   1.42  dholland void	defoption(const char *, struct defoptlist *, struct nvlist *);
    590   1.42  dholland void	defflag(const char *, struct defoptlist *, struct nvlist *, int);
    591   1.42  dholland void	defparam(const char *, struct defoptlist *, struct nvlist *, int);
    592   1.96  christos void	deloption(const char *, int);
    593   1.96  christos void	delfsoption(const char *, int);
    594   1.96  christos void	delmkoption(const char *, int);
    595    1.1   thorpej int	devbase_has_instances(struct devbase *, int);
    596  1.105  christos struct where *find_declared_option(const char *);
    597  1.107   thorpej struct defoptlist *find_declared_option_option(const char *name);
    598    1.1   thorpej int	deva_has_instances(struct deva *, int);
    599    1.1   thorpej void	setupdirs(void);
    600   1.74  uebayasi void	fixmaxusers(void);
    601   1.71  uebayasi void	fixmkoption(void);
    602  1.107   thorpej void	mkflagvar(struct defoptlist *);
    603   1.29      cube const char *strtolower(const char *);
    604    1.1   thorpej 
    605    1.1   thorpej /* tests on option types */
    606   1.41  dholland #define OPT_FSOPT(n)	(nvhash_lookup(deffstab, (n)) != NULL)
    607   1.42  dholland #define OPT_DEFOPT(n)	(dlhash_lookup(defopttab, (n)) != NULL)
    608   1.42  dholland #define OPT_DEFFLAG(n)	(dlhash_lookup(defflagtab, (n)) != NULL)
    609   1.42  dholland #define OPT_DEFPARAM(n)	(dlhash_lookup(defparamtab, (n)) != NULL)
    610   1.42  dholland #define OPT_OBSOLETE(n)	(dlhash_lookup(obsopttab, (n)) != NULL)
    611  1.105  christos #define DEFINED_OPTION(n) (find_declared_option((n)))
    612    1.1   thorpej 
    613    1.1   thorpej /* main.c */
    614    1.1   thorpej void	logconfig_include(FILE *, const char *);
    615    1.1   thorpej 
    616    1.1   thorpej /* mkdevsw.c */
    617    1.1   thorpej int	mkdevsw(void);
    618    1.1   thorpej 
    619    1.1   thorpej /* mkheaders.c */
    620    1.1   thorpej int	mkheaders(void);
    621    1.1   thorpej int	moveifchanged(const char *, const char *);
    622   1.31     pooka int	emitlocs(void);
    623   1.34     pooka int	emitioconfh(void);
    624    1.1   thorpej 
    625    1.1   thorpej /* mkioconf.c */
    626    1.1   thorpej int	mkioconf(void);
    627    1.1   thorpej 
    628    1.1   thorpej /* mkmakefile.c */
    629    1.1   thorpej int	mkmakefile(void);
    630    1.1   thorpej 
    631    1.1   thorpej /* mkswap.c */
    632    1.1   thorpej int	mkswap(void);
    633    1.1   thorpej 
    634    1.1   thorpej /* pack.c */
    635    1.1   thorpej void	pack(void);
    636    1.1   thorpej 
    637    1.1   thorpej /* scan.l */
    638   1.59  christos u_short	currentline(void);
    639    1.1   thorpej int	firstfile(const char *);
    640    1.1   thorpej void	package(const char *);
    641    1.1   thorpej int	include(const char *, int, int, int);
    642   1.93  uebayasi extern int includedepth;
    643    1.1   thorpej 
    644    1.1   thorpej /* sem.c, other than for yacc actions */
    645    1.1   thorpej void	initsem(void);
    646   1.17      cube int	onlist(struct nvlist *, void *);
    647    1.1   thorpej 
    648    1.1   thorpej /* util.c */
    649    1.1   thorpej void	prefix_push(const char *);
    650    1.1   thorpej void	prefix_pop(void);
    651   1.81  uebayasi void	buildprefix_push(const char *);
    652   1.81  uebayasi void	buildprefix_pop(void);
    653    1.1   thorpej char	*sourcepath(const char *);
    654   1.47  uebayasi extern	int dflag;
    655   1.47  uebayasi #define	CFGDBG(n, ...) \
    656   1.47  uebayasi 	do { if ((dflag) >= (n)) cfgdbg(__VA_ARGS__); } while (0)
    657   1.47  uebayasi void	cfgdbg(const char *, ...)			/* debug info */
    658   1.47  uebayasi      __printflike(1, 2);
    659   1.20  christos void	cfgwarn(const char *, ...)			/* immediate warns */
    660   1.36  dholland      __printflike(1, 2);
    661   1.20  christos void	cfgxwarn(const char *, int, const char *, ...)	/* delayed warns */
    662   1.36  dholland      __printflike(3, 4);
    663   1.20  christos void	cfgerror(const char *, ...)			/* immediate errs */
    664   1.36  dholland      __printflike(1, 2);
    665   1.20  christos void	cfgxerror(const char *, int, const char *, ...)	/* delayed errs */
    666   1.36  dholland      __printflike(3, 4);
    667    1.1   thorpej __dead void panic(const char *, ...)
    668   1.36  dholland      __printflike(1, 2);
    669   1.26  christos struct nvlist *newnv(const char *, const char *, void *, long long, struct nvlist *);
    670    1.1   thorpej void	nvfree(struct nvlist *);
    671    1.1   thorpej void	nvfreel(struct nvlist *);
    672   1.19      cube struct nvlist *nvcat(struct nvlist *, struct nvlist *);
    673   1.22     lukem void	autogen_comment(FILE *, const char *);
    674   1.42  dholland struct defoptlist *defoptlist_create(const char *, const char *, const char *);
    675   1.42  dholland void defoptlist_destroy(struct defoptlist *);
    676   1.42  dholland struct defoptlist *defoptlist_append(struct defoptlist *, struct defoptlist *);
    677   1.38  dholland struct attrlist *attrlist_create(void);
    678   1.38  dholland struct attrlist *attrlist_cons(struct attrlist *, struct attr *);
    679   1.38  dholland void attrlist_destroy(struct attrlist *);
    680   1.38  dholland void attrlist_destroyall(struct attrlist *);
    681   1.40  dholland struct loclist *loclist_create(const char *, const char *, long long);
    682   1.40  dholland void loclist_destroy(struct loclist *);
    683   1.39  dholland struct condexpr *condexpr_create(enum condexpr_types);
    684   1.39  dholland void condexpr_destroy(struct condexpr *);
    685    1.1   thorpej 
    686    1.1   thorpej /* liby */
    687    1.1   thorpej void	yyerror(const char *);
    688    1.1   thorpej int	yylex(void);
    689