2012-03-12 07:04:56 +04:00
|
|
|
/* $NetBSD: lint.c,v 1.13 2012/03/12 03:04:56 dholland Exp $ */
|
2007-01-08 19:08:08 +03:00
|
|
|
|
|
|
|
/*
|
2007-01-09 16:03:47 +03:00
|
|
|
* Copyright (c) 2007 The NetBSD Foundation.
|
2007-01-08 19:08:08 +03:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if HAVE_NBTOOL_CONFIG_H
|
|
|
|
#include "nbtool_config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-03-12 06:58:55 +04:00
|
|
|
#include <assert.h>
|
2007-01-08 19:08:08 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
|
|
|
|
void
|
|
|
|
emit_params()
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("version\t%d\n", CONFIG_VERSION);
|
|
|
|
printf("ident\t\"LINT_%s\"\n", conffile);
|
|
|
|
printf("maxusers\t%d\n", defmaxusers);
|
2007-01-10 18:17:43 +03:00
|
|
|
printf("config netbsdlint root on ?\n");
|
2007-01-08 19:08:08 +03:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
enum opt_types {
|
|
|
|
OT_FLAG,
|
|
|
|
OT_PARAM,
|
|
|
|
OT_FS
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct opt_type {
|
|
|
|
enum opt_types ot_type;
|
|
|
|
const char *ot_name;
|
|
|
|
struct hashtab **ot_ht;
|
|
|
|
} opt_types[] = {
|
|
|
|
{ OT_FLAG, "options", &opttab },
|
|
|
|
{ OT_PARAM, "options", &opttab },
|
|
|
|
{ OT_FS, "file-system", &fsopttab },
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
2012-03-12 06:58:55 +04:00
|
|
|
do_emit_option(const char *name, struct defoptlist *dl, void *v)
|
2007-01-08 19:08:08 +03:00
|
|
|
{
|
|
|
|
const struct opt_type *ot = v;
|
2012-03-12 06:58:55 +04:00
|
|
|
const char *value;
|
2007-01-08 19:08:08 +03:00
|
|
|
|
2012-03-12 06:58:55 +04:00
|
|
|
if (dl->dl_obsolete)
|
2007-01-08 19:08:08 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (ht_lookup(*(ot->ot_ht), name))
|
|
|
|
return 0;
|
|
|
|
|
2012-03-12 06:58:55 +04:00
|
|
|
printf("%s\t%s", ot->ot_name, dl->dl_name);
|
2007-01-09 16:03:47 +03:00
|
|
|
if (ot->ot_type == OT_PARAM) {
|
2012-03-12 06:58:55 +04:00
|
|
|
struct defoptlist *dl2 = dlhash_lookup(defoptlint, dl->dl_name);
|
|
|
|
if (dl2 != NULL)
|
|
|
|
value = dl2->dl_lintvalue;
|
|
|
|
else
|
|
|
|
value = dl->dl_value;
|
|
|
|
assert(dl2 == dl);
|
|
|
|
printf("=\"%s\"", value ? value : "1");
|
2007-01-09 16:03:47 +03:00
|
|
|
}
|
2007-01-08 19:08:08 +03:00
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2012-03-12 06:58:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Same as do_emit_option but for filesystem definitions, which now
|
|
|
|
* have a different data type. XXX these should probably be unified
|
|
|
|
* again.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
do_emit_fs(const char *name, struct nvlist *nv, void *v)
|
|
|
|
{
|
|
|
|
const struct opt_type *ot = v;
|
|
|
|
|
|
|
|
if (ht_lookup(*(ot->ot_ht), name))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
assert(ot->ot_type != OT_PARAM);
|
|
|
|
printf("%s\t%s\n", ot->ot_name, nv->nv_name);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2007-01-08 19:08:08 +03:00
|
|
|
|
|
|
|
|
|
|
|
void
|
2012-03-12 04:20:30 +04:00
|
|
|
emit_options(void)
|
2007-01-08 19:08:08 +03:00
|
|
|
{
|
|
|
|
|
2012-03-12 06:58:55 +04:00
|
|
|
(void)dlhash_enumerate(defflagtab, do_emit_option, &opt_types[0]);
|
2007-01-08 19:08:08 +03:00
|
|
|
printf("\n");
|
2012-03-12 06:58:55 +04:00
|
|
|
(void)dlhash_enumerate(defparamtab, do_emit_option, &opt_types[1]);
|
2007-01-08 19:08:08 +03:00
|
|
|
printf("\n");
|
2012-03-12 06:58:55 +04:00
|
|
|
(void)nvhash_enumerate(deffstab, do_emit_fs, &opt_types[2]);
|
2007-01-08 19:08:08 +03:00
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_emit_instances(struct devbase *d, struct attr *at)
|
|
|
|
{
|
2012-03-12 01:16:07 +04:00
|
|
|
struct nvlist *nv1;
|
|
|
|
struct loclist *ll;
|
2012-03-11 11:32:41 +04:00
|
|
|
struct attrlist *al;
|
2007-01-08 19:08:08 +03:00
|
|
|
struct attr *a;
|
|
|
|
struct deva *da;
|
|
|
|
|
2007-01-10 18:17:43 +03:00
|
|
|
/*
|
|
|
|
* d_isdef is used to check whether a deva has been seen or not,
|
|
|
|
* for there are devices that can be their own ancestor (e.g.
|
|
|
|
* uhub, pci).
|
|
|
|
*/
|
|
|
|
|
2007-01-08 19:08:08 +03:00
|
|
|
if (at != NULL) {
|
|
|
|
for (da = d->d_ahead; da != NULL; da = da->d_bsame)
|
|
|
|
if (onlist(da->d_atlist, at))
|
|
|
|
break;
|
|
|
|
if (da == NULL)
|
|
|
|
panic("do_emit_instances: no deva found for %s at %s",
|
|
|
|
d->d_name, at->a_name);
|
|
|
|
|
|
|
|
if (da->d_isdef > 1)
|
|
|
|
return;
|
|
|
|
da->d_isdef = 2;
|
|
|
|
}
|
|
|
|
|
2009-08-31 01:07:41 +04:00
|
|
|
if (at == NULL && !d->d_ispseudo && d->d_ihead == NULL)
|
2007-01-08 19:08:08 +03:00
|
|
|
printf("%s0\tat\troot\n", d->d_name);
|
2009-08-31 01:07:41 +04:00
|
|
|
else if (at != NULL && !d->d_ispseudo && da->d_ihead == NULL) {
|
2007-01-08 19:08:08 +03:00
|
|
|
printf("%s0\tat\t%s?", d->d_name, at->a_name);
|
|
|
|
|
2012-03-12 01:16:07 +04:00
|
|
|
for (ll = at->a_locs; ll != NULL; ll = ll->ll_next) {
|
|
|
|
if (ll->ll_num == 0)
|
|
|
|
printf(" %s %c", ll->ll_name,
|
|
|
|
ll->ll_string ? '?' : '0');
|
2007-01-08 19:08:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
2007-01-10 18:17:43 +03:00
|
|
|
/*
|
|
|
|
* Children attachments are found the same way as in the orphan
|
|
|
|
* detection code in main.c.
|
|
|
|
*/
|
2012-03-11 11:32:41 +04:00
|
|
|
for (al = d->d_attrs; al != NULL; al = al->al_next) {
|
|
|
|
a = al->al_this;
|
2007-01-08 19:08:08 +03:00
|
|
|
for (nv1 = a->a_devs; nv1 != NULL; nv1 = nv1->nv_next)
|
|
|
|
do_emit_instances(nv1->nv_ptr, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
emit_root_instance(const char *name, void *value, void *v)
|
|
|
|
{
|
|
|
|
|
|
|
|
do_emit_instances((struct devbase *)value, NULL);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2007-01-08 21:08:24 +03:00
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
emit_pseudo_instance(const char *name, void *value, void *v)
|
|
|
|
{
|
|
|
|
struct devbase *d = value;
|
|
|
|
|
2009-08-31 01:07:41 +04:00
|
|
|
if (d->d_ispseudo && d->d_ihead == NULL)
|
2007-01-08 21:08:24 +03:00
|
|
|
printf("pseudo-device\t%s\n", d->d_name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-08 19:08:08 +03:00
|
|
|
void
|
|
|
|
emit_instances()
|
|
|
|
{
|
|
|
|
|
|
|
|
(void)ht_enumerate(devroottab, emit_root_instance, NULL);
|
2007-01-08 21:08:24 +03:00
|
|
|
printf("\n");
|
|
|
|
(void)ht_enumerate(devbasetab, emit_pseudo_instance, NULL);
|
2007-01-08 19:08:08 +03:00
|
|
|
}
|