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