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