lint.c revision 1.9 1 /* $NetBSD: lint.c,v 1.9 2012/03/11 07:32:41 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 *nv, *nv1;
105 struct attrlist *al;
106 struct attr *a;
107 struct deva *da;
108
109 /*
110 * d_isdef is used to check whether a deva has been seen or not,
111 * for there are devices that can be their own ancestor (e.g.
112 * uhub, pci).
113 */
114
115 if (at != NULL) {
116 for (da = d->d_ahead; da != NULL; da = da->d_bsame)
117 if (onlist(da->d_atlist, at))
118 break;
119 if (da == NULL)
120 panic("do_emit_instances: no deva found for %s at %s",
121 d->d_name, at->a_name);
122
123 if (da->d_isdef > 1)
124 return;
125 da->d_isdef = 2;
126 }
127
128 if (at == NULL && !d->d_ispseudo && d->d_ihead == NULL)
129 printf("%s0\tat\troot\n", d->d_name);
130 else if (at != NULL && !d->d_ispseudo && da->d_ihead == NULL) {
131 printf("%s0\tat\t%s?", d->d_name, at->a_name);
132
133 for (nv = at->a_locs; nv != NULL; nv = nv->nv_next) {
134 if (nv->nv_num == 0)
135 printf(" %s %c", nv->nv_name,
136 nv->nv_str ? '?' : '0');
137 }
138
139 printf("\n");
140 }
141
142 /*
143 * Children attachments are found the same way as in the orphan
144 * detection code in main.c.
145 */
146 for (al = d->d_attrs; al != NULL; al = al->al_next) {
147 a = al->al_this;
148 for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
149 do_emit_instances(nv1->nv_ptr, a);
150 }
151 }
152
153 /* ARGSUSED */
154 static int
155 emit_root_instance(const char *name, void *value, void *v)
156 {
157
158 do_emit_instances((struct devbase *)value, NULL);
159
160 return 1;
161 }
162
163 /* ARGSUSED */
164 static int
165 emit_pseudo_instance(const char *name, void *value, void *v)
166 {
167 struct devbase *d = value;
168
169 if (d->d_ispseudo && d->d_ihead == NULL)
170 printf("pseudo-device\t%s\n", d->d_name);
171 return 0;
172 }
173
174 void
175 emit_instances()
176 {
177
178 (void)ht_enumerate(devroottab, emit_root_instance, NULL);
179 printf("\n");
180 (void)ht_enumerate(devbasetab, emit_pseudo_instance, NULL);
181 }
182