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