Home | History | Annotate | Line # | Download | only in config
lint.c revision 1.16.4.1
      1  1.16.4.1  perseant /*	$NetBSD: lint.c,v 1.16.4.1 2025/08/02 05:58:25 perseant Exp $	*/
      2       1.1      cube 
      3       1.1      cube /*
      4       1.3      cube  *  Copyright (c) 2007 The NetBSD Foundation.
      5       1.1      cube  *  All rights reserved.
      6       1.1      cube  *
      7       1.1      cube  *  Redistribution and use in source and binary forms, with or without
      8       1.1      cube  *  modification, are permitted provided that the following conditions
      9       1.1      cube  *  are met:
     10       1.1      cube  *  1. Redistributions of source code must retain the above copyright
     11       1.1      cube  *     notice, this list of conditions and the following disclaimer.
     12       1.1      cube  *  2. Redistributions in binary form must reproduce the above copyright
     13       1.1      cube  *     notice, this list of conditions and the following disclaimer in the
     14       1.1      cube  *     documentation and/or other materials provided with the distribution.
     15       1.1      cube  *
     16       1.1      cube  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17       1.1      cube  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18       1.1      cube  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19       1.1      cube  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20       1.1      cube  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21       1.1      cube  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22       1.1      cube  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23       1.1      cube  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24       1.1      cube  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25       1.1      cube  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26       1.1      cube  *  POSSIBILITY OF SUCH DAMAGE.
     27       1.1      cube  */
     28       1.1      cube 
     29       1.1      cube #if HAVE_NBTOOL_CONFIG_H
     30       1.1      cube #include "nbtool_config.h"
     31       1.1      cube #endif
     32       1.1      cube 
     33      1.15  christos #include <sys/cdefs.h>
     34  1.16.4.1  perseant __RCSID("$NetBSD: lint.c,v 1.16.4.1 2025/08/02 05:58:25 perseant Exp $");
     35      1.15  christos 
     36      1.12  dholland #include <assert.h>
     37       1.1      cube #include <stdlib.h>
     38       1.1      cube 
     39       1.1      cube #include "defs.h"
     40       1.1      cube 
     41       1.1      cube void
     42      1.14      matt emit_params(void)
     43       1.1      cube {
     44       1.1      cube 
     45       1.1      cube 	printf("version\t%d\n", CONFIG_VERSION);
     46       1.1      cube 	printf("ident\t\"LINT_%s\"\n", conffile);
     47       1.1      cube 	printf("maxusers\t%d\n", defmaxusers);
     48       1.4      cube 	printf("config netbsdlint root on ?\n");
     49       1.1      cube 	printf("\n");
     50       1.1      cube }
     51       1.1      cube 
     52       1.1      cube enum opt_types {
     53       1.1      cube 	OT_FLAG,
     54       1.1      cube 	OT_PARAM,
     55       1.1      cube 	OT_FS
     56       1.1      cube };
     57       1.1      cube 
     58       1.1      cube static struct opt_type {
     59       1.1      cube 	enum opt_types ot_type;
     60       1.1      cube 	const char *ot_name;
     61       1.1      cube 	struct hashtab **ot_ht;
     62       1.1      cube } opt_types[] = {
     63       1.1      cube 	{ OT_FLAG, "options", &opttab },
     64       1.1      cube 	{ OT_PARAM, "options", &opttab },
     65       1.1      cube 	{ OT_FS, "file-system", &fsopttab },
     66       1.1      cube };
     67       1.1      cube 
     68       1.1      cube static int
     69      1.12  dholland do_emit_option(const char *name, struct defoptlist *dl, void *v)
     70       1.1      cube {
     71       1.1      cube 	const struct opt_type *ot = v;
     72      1.12  dholland 	const char *value;
     73       1.1      cube 
     74      1.12  dholland 	if (dl->dl_obsolete)
     75       1.1      cube 		return 0;
     76       1.1      cube 
     77       1.1      cube 	if (ht_lookup(*(ot->ot_ht), name))
     78       1.1      cube 		return 0;
     79       1.1      cube 
     80      1.12  dholland 	printf("%s\t%s", ot->ot_name, dl->dl_name);
     81       1.3      cube 	if (ot->ot_type == OT_PARAM) {
     82      1.12  dholland 		struct defoptlist *dl2 = dlhash_lookup(defoptlint, dl->dl_name);
     83      1.16  christos 		if (dl2 != NULL) {
     84      1.16  christos 			assert(dl2 == dl);
     85      1.12  dholland 			value = dl2->dl_lintvalue;
     86      1.16  christos 		} else
     87      1.12  dholland 			value = dl->dl_value;
     88      1.12  dholland 		printf("=\"%s\"", value ? value : "1");
     89       1.3      cube 	}
     90       1.1      cube 	printf("\n");
     91       1.1      cube 
     92       1.1      cube 	return 1;
     93       1.1      cube }
     94      1.12  dholland 
     95      1.12  dholland /*
     96      1.12  dholland  * Same as do_emit_option but for filesystem definitions, which now
     97      1.12  dholland  * have a different data type. XXX these should probably be unified
     98      1.12  dholland  * again.
     99      1.12  dholland  */
    100      1.12  dholland static int
    101      1.12  dholland do_emit_fs(const char *name, struct nvlist *nv, void *v)
    102      1.12  dholland {
    103      1.12  dholland 	const struct opt_type *ot = v;
    104      1.12  dholland 
    105      1.12  dholland 	if (ht_lookup(*(ot->ot_ht), name))
    106      1.12  dholland 		return 0;
    107      1.12  dholland 
    108      1.12  dholland 	assert(ot->ot_type != OT_PARAM);
    109      1.12  dholland 	printf("%s\t%s\n", ot->ot_name, nv->nv_name);
    110      1.12  dholland 
    111      1.12  dholland 	return 1;
    112      1.12  dholland }
    113       1.1      cube 
    114       1.1      cube void
    115      1.11  dholland emit_options(void)
    116       1.1      cube {
    117       1.1      cube 
    118      1.12  dholland 	(void)dlhash_enumerate(defflagtab, do_emit_option, &opt_types[0]);
    119       1.1      cube 	printf("\n");
    120      1.12  dholland 	(void)dlhash_enumerate(defparamtab, do_emit_option, &opt_types[1]);
    121       1.1      cube 	printf("\n");
    122      1.12  dholland 	(void)nvhash_enumerate(deffstab, do_emit_fs, &opt_types[2]);
    123       1.1      cube 	printf("\n");
    124       1.1      cube }
    125       1.1      cube 
    126       1.1      cube static void
    127       1.1      cube do_emit_instances(struct devbase *d, struct attr *at)
    128       1.1      cube {
    129      1.10  dholland 	struct nvlist *nv1;
    130      1.10  dholland 	struct loclist *ll;
    131       1.9  dholland 	struct attrlist *al;
    132       1.1      cube 	struct attr *a;
    133       1.1      cube 	struct deva *da;
    134       1.1      cube 
    135       1.4      cube 	/*
    136       1.4      cube 	 * d_isdef is used to check whether a deva has been seen or not,
    137       1.4      cube 	 * for there are devices that can be their own ancestor (e.g.
    138       1.4      cube 	 * uhub, pci).
    139       1.4      cube 	 */
    140       1.4      cube 
    141       1.1      cube 	if (at != NULL) {
    142       1.1      cube 		for (da = d->d_ahead; da != NULL; da = da->d_bsame)
    143       1.1      cube 			if (onlist(da->d_atlist, at))
    144       1.1      cube 				break;
    145       1.1      cube 		if (da == NULL)
    146       1.1      cube 			panic("do_emit_instances: no deva found for %s at %s",
    147       1.1      cube 			    d->d_name, at->a_name);
    148       1.1      cube 
    149       1.1      cube 		if (da->d_isdef > 1)
    150       1.1      cube 			return;
    151       1.1      cube 		da->d_isdef = 2;
    152       1.1      cube 	}
    153       1.1      cube 
    154       1.8      cube 	if (at == NULL && !d->d_ispseudo && d->d_ihead == NULL)
    155       1.1      cube 		printf("%s0\tat\troot\n", d->d_name);
    156       1.8      cube 	else if (at != NULL && !d->d_ispseudo && da->d_ihead == NULL) {
    157       1.1      cube 		printf("%s0\tat\t%s?", d->d_name, at->a_name);
    158       1.1      cube 
    159      1.10  dholland 		for (ll = at->a_locs; ll != NULL; ll = ll->ll_next) {
    160      1.10  dholland 			if (ll->ll_num == 0)
    161      1.10  dholland 				printf(" %s %c", ll->ll_name,
    162      1.10  dholland 				    ll->ll_string ? '?' : '0');
    163       1.1      cube 		}
    164       1.1      cube 
    165       1.1      cube 		printf("\n");
    166       1.1      cube 	}
    167       1.1      cube 
    168       1.4      cube 	/*
    169       1.4      cube 	 * Children attachments are found the same way as in the orphan
    170       1.4      cube 	 * detection code in main.c.
    171       1.4      cube 	 */
    172       1.9  dholland 	for (al = d->d_attrs; al != NULL; al = al->al_next) {
    173       1.9  dholland 		a = al->al_this;
    174       1.1      cube 		for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
    175       1.1      cube 			do_emit_instances(nv1->nv_ptr, a);
    176       1.1      cube 	}
    177       1.1      cube }
    178       1.1      cube 
    179       1.1      cube /* ARGSUSED */
    180       1.1      cube static int
    181       1.1      cube emit_root_instance(const char *name, void *value, void *v)
    182       1.1      cube {
    183       1.1      cube 
    184       1.1      cube 	do_emit_instances((struct devbase *)value, NULL);
    185       1.1      cube 
    186       1.1      cube 	return 1;
    187       1.1      cube }
    188       1.1      cube 
    189       1.2      cube /* ARGSUSED */
    190       1.2      cube static int
    191       1.2      cube emit_pseudo_instance(const char *name, void *value, void *v)
    192       1.2      cube {
    193       1.2      cube 	struct devbase *d = value;
    194       1.2      cube 
    195       1.8      cube 	if (d->d_ispseudo && d->d_ihead == NULL)
    196       1.2      cube 		printf("pseudo-device\t%s\n", d->d_name);
    197       1.2      cube 	return 0;
    198       1.2      cube }
    199       1.2      cube 
    200       1.1      cube void
    201      1.14      matt emit_instances(void)
    202       1.1      cube {
    203       1.1      cube 
    204       1.1      cube 	(void)ht_enumerate(devroottab, emit_root_instance, NULL);
    205       1.2      cube 	printf("\n");
    206       1.2      cube 	(void)ht_enumerate(devbasetab, emit_pseudo_instance, NULL);
    207       1.1      cube }
    208