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