lint.c revision 1.12 1 /* $NetBSD: lint.c,v 1.12 2012/03/12 02:58:55 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 <assert.h>
34 #include <stdlib.h>
35
36 #include "defs.h"
37
38 void
39 emit_params()
40 {
41
42 printf("version\t%d\n", CONFIG_VERSION);
43 printf("ident\t\"LINT_%s\"\n", conffile);
44 printf("maxusers\t%d\n", defmaxusers);
45 printf("config netbsdlint root on ?\n");
46 printf("\n");
47 }
48
49 enum opt_types {
50 OT_FLAG,
51 OT_PARAM,
52 OT_FS
53 };
54
55 static struct opt_type {
56 enum opt_types ot_type;
57 const char *ot_name;
58 struct hashtab **ot_ht;
59 } opt_types[] = {
60 { OT_FLAG, "options", &opttab },
61 { OT_PARAM, "options", &opttab },
62 { OT_FS, "file-system", &fsopttab },
63 };
64
65 static int
66 do_emit_option(const char *name, struct defoptlist *dl, void *v)
67 {
68 const struct opt_type *ot = v;
69 const char *value;
70
71 if (dl->dl_obsolete)
72 return 0;
73
74 if (ht_lookup(*(ot->ot_ht), name))
75 return 0;
76
77 printf("%s\t%s", ot->ot_name, dl->dl_name);
78 if (ot->ot_type == OT_PARAM) {
79 struct defoptlist *dl2 = dlhash_lookup(defoptlint, dl->dl_name);
80 if (dl2 != NULL)
81 value = dl2->dl_lintvalue;
82 else
83 value = dl->dl_value;
84 assert(dl2 == dl);
85 printf("=\"%s\"", value ? value : "1");
86 }
87 printf("\n");
88
89 return 1;
90 }
91
92 /*
93 * Same as do_emit_option but for filesystem definitions, which now
94 * have a different data type. XXX these should probably be unified
95 * again.
96 */
97 static int
98 do_emit_fs(const char *name, struct nvlist *nv, void *v)
99 {
100 const struct opt_type *ot = v;
101
102 assert((nv->nv_flags & NV_OBSOLETE) == 0);
103
104 if (ht_lookup(*(ot->ot_ht), name))
105 return 0;
106
107 assert(ot->ot_type != OT_PARAM);
108 printf("%s\t%s\n", ot->ot_name, nv->nv_name);
109
110 return 1;
111 }
112
113
114 void
115 emit_options(void)
116 {
117
118 (void)dlhash_enumerate(defflagtab, do_emit_option, &opt_types[0]);
119 printf("\n");
120 (void)dlhash_enumerate(defparamtab, do_emit_option, &opt_types[1]);
121 printf("\n");
122 (void)nvhash_enumerate(deffstab, do_emit_fs, &opt_types[2]);
123 printf("\n");
124 }
125
126 static void
127 do_emit_instances(struct devbase *d, struct attr *at)
128 {
129 struct nvlist *nv1;
130 struct loclist *ll;
131 struct attrlist *al;
132 struct attr *a;
133 struct deva *da;
134
135 /*
136 * d_isdef is used to check whether a deva has been seen or not,
137 * for there are devices that can be their own ancestor (e.g.
138 * uhub, pci).
139 */
140
141 if (at != NULL) {
142 for (da = d->d_ahead; da != NULL; da = da->d_bsame)
143 if (onlist(da->d_atlist, at))
144 break;
145 if (da == NULL)
146 panic("do_emit_instances: no deva found for %s at %s",
147 d->d_name, at->a_name);
148
149 if (da->d_isdef > 1)
150 return;
151 da->d_isdef = 2;
152 }
153
154 if (at == NULL && !d->d_ispseudo && d->d_ihead == NULL)
155 printf("%s0\tat\troot\n", d->d_name);
156 else if (at != NULL && !d->d_ispseudo && da->d_ihead == NULL) {
157 printf("%s0\tat\t%s?", d->d_name, at->a_name);
158
159 for (ll = at->a_locs; ll != NULL; ll = ll->ll_next) {
160 if (ll->ll_num == 0)
161 printf(" %s %c", ll->ll_name,
162 ll->ll_string ? '?' : '0');
163 }
164
165 printf("\n");
166 }
167
168 /*
169 * Children attachments are found the same way as in the orphan
170 * detection code in main.c.
171 */
172 for (al = d->d_attrs; al != NULL; al = al->al_next) {
173 a = al->al_this;
174 for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
175 do_emit_instances(nv1->nv_ptr, a);
176 }
177 }
178
179 /* ARGSUSED */
180 static int
181 emit_root_instance(const char *name, void *value, void *v)
182 {
183
184 do_emit_instances((struct devbase *)value, NULL);
185
186 return 1;
187 }
188
189 /* ARGSUSED */
190 static int
191 emit_pseudo_instance(const char *name, void *value, void *v)
192 {
193 struct devbase *d = value;
194
195 if (d->d_ispseudo && d->d_ihead == NULL)
196 printf("pseudo-device\t%s\n", d->d_name);
197 return 0;
198 }
199
200 void
201 emit_instances()
202 {
203
204 (void)ht_enumerate(devroottab, emit_root_instance, NULL);
205 printf("\n");
206 (void)ht_enumerate(devbasetab, emit_pseudo_instance, NULL);
207 }
208