2002-03-11 21:42:35 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2002 Poul-Henning Kamp
|
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Poul-Henning Kamp
|
|
|
|
* and NAI Labs, the Security Research Division of Network Associates, Inc.
|
|
|
|
* under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the
|
|
|
|
* DARPA CHATS research program.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. The names of the authors may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/sbuf.h>
|
|
|
|
#ifndef _KERNEL
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <err.h>
|
|
|
|
#else
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#endif
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
|
|
|
#include <geom/geom.h>
|
2002-03-26 22:07:38 +00:00
|
|
|
#include <geom/geom_int.h>
|
2002-03-11 21:42:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_confdot_consumer(struct sbuf *sb, struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
|
|
|
|
sbuf_printf(sb, "z%p [label=\"r%dw%de%d\\nbio #%d\"];\n",
|
|
|
|
cp, cp->acr, cp->acw, cp->ace, cp->biocount);
|
|
|
|
if (cp->provider)
|
|
|
|
sbuf_printf(sb, "z%p -> z%p;\n", cp, cp->provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_confdot_provider(struct sbuf *sb, struct g_provider *pp)
|
|
|
|
{
|
|
|
|
|
|
|
|
sbuf_printf(sb, "z%p [shape=hexagon,label=\"%s\\nr%dw%de%d\\nerr#%d\"];\n",
|
|
|
|
pp, pp->name, pp->acr, pp->acw, pp->ace, pp->error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_confdot_geom(struct sbuf *sb, struct g_geom *gp)
|
|
|
|
{
|
|
|
|
struct g_consumer *cp;
|
|
|
|
struct g_provider *pp;
|
|
|
|
|
|
|
|
sbuf_printf(sb, "z%p [shape=box,label=\"%s\\n%s\\nr#%d\"];\n",
|
2002-03-26 21:40:06 +00:00
|
|
|
gp, gp->class->name, gp->name, gp->rank);
|
2002-03-11 21:42:35 +00:00
|
|
|
LIST_FOREACH(cp, &gp->consumer, consumer) {
|
|
|
|
g_confdot_consumer(sb, cp);
|
|
|
|
sbuf_printf(sb, "z%p -> z%p;\n", gp, cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOREACH(pp, &gp->provider, provider) {
|
|
|
|
g_confdot_provider(sb, pp);
|
|
|
|
sbuf_printf(sb, "z%p -> z%p;\n", pp, gp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-26 21:40:06 +00:00
|
|
|
g_confdot_class(struct sbuf *sb, struct g_class *mp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp;
|
|
|
|
|
|
|
|
LIST_FOREACH(gp, &mp->geom, geom)
|
|
|
|
g_confdot_geom(sb, gp);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sbuf *
|
|
|
|
g_confdot(void)
|
|
|
|
{
|
2002-03-26 21:40:06 +00:00
|
|
|
struct g_class *mp;
|
2002-03-11 21:42:35 +00:00
|
|
|
struct sbuf *sb;
|
|
|
|
|
|
|
|
sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
|
|
|
|
sbuf_clear(sb);
|
|
|
|
sbuf_printf(sb, "digraph geom {\n");
|
2002-04-04 09:41:47 +00:00
|
|
|
LIST_FOREACH(mp, &g_classes, class)
|
2002-03-26 21:40:06 +00:00
|
|
|
g_confdot_class(sb, mp);
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, "};\n");
|
|
|
|
sbuf_finish(sb);
|
|
|
|
return (sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_conf_consumer(struct sbuf *sb, struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, "\t<consumer id=\"%p\">\n", cp);
|
|
|
|
sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", cp->geom);
|
|
|
|
if (cp->provider != NULL)
|
|
|
|
sbuf_printf(sb, "\t <provider ref=\"%p\"/>\n", cp->provider);
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
|
|
|
|
cp->acr, cp->acw, cp->ace);
|
|
|
|
if (cp->geom->dumpconf) {
|
|
|
|
sbuf_printf(sb, "\t <config>\n");
|
|
|
|
cp->geom->dumpconf(sb, "\t ", cp->geom, cp, NULL);
|
|
|
|
sbuf_printf(sb, "\t </config>\n");
|
|
|
|
}
|
|
|
|
sbuf_printf(sb, "\t</consumer>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_conf_provider(struct sbuf *sb, struct g_provider *pp)
|
|
|
|
{
|
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, "\t<provider id=\"%p\">\n", pp);
|
|
|
|
sbuf_printf(sb, "\t <geom ref=\"%p\"/>\n", pp->geom);
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, "\t <mode>r%dw%de%d</mode>\n",
|
|
|
|
pp->acr, pp->acw, pp->ace);
|
|
|
|
sbuf_printf(sb, "\t <name>%s</name>\n", pp->name);
|
|
|
|
if (pp->geom->dumpconf) {
|
|
|
|
sbuf_printf(sb, "\t <config>\n");
|
|
|
|
pp->geom->dumpconf(sb, "\t ", pp->geom, NULL, pp);
|
|
|
|
sbuf_printf(sb, "\t </config>\n");
|
|
|
|
}
|
|
|
|
sbuf_printf(sb, "\t</provider>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_conf_geom(struct sbuf *sb, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
|
|
|
|
{
|
|
|
|
struct g_consumer *cp2;
|
|
|
|
struct g_provider *pp2;
|
2002-05-21 20:33:49 +00:00
|
|
|
struct g_magicspace *gsp;
|
|
|
|
u_int u;
|
2002-03-11 21:42:35 +00:00
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, " <geom id=\"%p\">\n", gp);
|
|
|
|
sbuf_printf(sb, " <class ref=\"%p\"/>\n", gp->class);
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, " <name>%s</name>\n", gp->name);
|
|
|
|
sbuf_printf(sb, " <rank>%d</rank>\n", gp->rank);
|
2002-05-21 20:33:49 +00:00
|
|
|
if (gp->magicspaces) {
|
|
|
|
for (u = 0; u < gp->magicspaces->nmagic; u++) {
|
|
|
|
gsp = &gp->magicspaces->magicspace[u];
|
|
|
|
if (gsp->len == 0 || gsp->name == NULL)
|
|
|
|
continue;
|
|
|
|
sbuf_printf(sb, " <magicspace>\n");
|
|
|
|
sbuf_printf(sb, " <name>%.8s</name>\n",
|
|
|
|
gsp->name);
|
|
|
|
sbuf_printf(sb, " <offset>%lld</offset>\n",
|
|
|
|
(long long)gsp->offset);
|
|
|
|
sbuf_printf(sb, " <length>%u</length>\n",
|
|
|
|
gsp->len);
|
|
|
|
sbuf_printf(sb, " <flags>%u</flags>\n",
|
|
|
|
gsp->flags);
|
|
|
|
sbuf_printf(sb, " </magicspace>\n");
|
|
|
|
}
|
|
|
|
}
|
2002-03-11 21:42:35 +00:00
|
|
|
if (gp->dumpconf) {
|
|
|
|
sbuf_printf(sb, " <config>\n");
|
|
|
|
gp->dumpconf(sb, "\t", gp, NULL, NULL);
|
|
|
|
sbuf_printf(sb, " </config>\n");
|
|
|
|
}
|
|
|
|
LIST_FOREACH(cp2, &gp->consumer, consumer) {
|
|
|
|
if (cp != NULL && cp != cp2)
|
|
|
|
continue;
|
|
|
|
g_conf_consumer(sb, cp2);
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_FOREACH(pp2, &gp->provider, provider) {
|
|
|
|
if (pp != NULL && pp != pp2)
|
|
|
|
continue;
|
|
|
|
g_conf_provider(sb, pp2);
|
|
|
|
}
|
|
|
|
sbuf_printf(sb, " </geom>\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-03-26 21:40:06 +00:00
|
|
|
g_conf_class(struct sbuf *sb, struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
|
|
|
struct g_geom *gp2;
|
|
|
|
|
2002-04-24 21:02:28 +00:00
|
|
|
sbuf_printf(sb, " <class id=\"%p\">\n", mp);
|
2002-03-11 21:42:35 +00:00
|
|
|
sbuf_printf(sb, " <name>%s</name>\n", mp->name);
|
|
|
|
LIST_FOREACH(gp2, &mp->geom, geom) {
|
|
|
|
if (gp != NULL && gp != gp2)
|
|
|
|
continue;
|
|
|
|
g_conf_geom(sb, gp2, pp, cp);
|
|
|
|
}
|
2002-03-26 21:40:06 +00:00
|
|
|
sbuf_printf(sb, " </class>\n");
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sbuf *
|
2002-03-26 21:40:06 +00:00
|
|
|
g_conf_specific(struct g_class *mp, struct g_geom *gp, struct g_provider *pp, struct g_consumer *cp)
|
2002-03-11 21:42:35 +00:00
|
|
|
{
|
2002-03-26 21:40:06 +00:00
|
|
|
struct g_class *mp2;
|
2002-03-11 21:42:35 +00:00
|
|
|
struct sbuf *sb;
|
|
|
|
|
|
|
|
sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
|
|
|
|
sbuf_clear(sb);
|
|
|
|
sbuf_printf(sb, "<mesh>\n");
|
2002-04-19 09:21:27 +00:00
|
|
|
#ifndef _KERNEL
|
|
|
|
sbuf_printf(sb, " <FreeBSD>%cFreeBSD%c</FreeBSD>\n", '$', '$');
|
|
|
|
#endif
|
2002-04-04 09:41:47 +00:00
|
|
|
LIST_FOREACH(mp2, &g_classes, class) {
|
2002-03-11 21:42:35 +00:00
|
|
|
if (mp != NULL && mp != mp2)
|
|
|
|
continue;
|
2002-03-26 21:40:06 +00:00
|
|
|
g_conf_class(sb, mp2, gp, pp, cp);
|
2002-03-11 21:42:35 +00:00
|
|
|
}
|
|
|
|
sbuf_printf(sb, "</mesh>\n");
|
|
|
|
sbuf_finish(sb);
|
|
|
|
return (sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sbuf *
|
|
|
|
g_conf()
|
|
|
|
{
|
|
|
|
|
|
|
|
return (g_conf_specific(NULL, NULL, NULL, NULL));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
g_trace(int level, char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
struct sbuf *sb;
|
|
|
|
|
2002-04-23 11:48:45 +00:00
|
|
|
g_sanity(NULL);
|
2002-03-11 21:42:35 +00:00
|
|
|
if (!(g_debugflags & level))
|
|
|
|
return;
|
|
|
|
va_start(ap, fmt);
|
|
|
|
mtx_lock(&Giant);
|
|
|
|
sb = sbuf_new(NULL, NULL, 0, SBUF_AUTOEXTEND);
|
|
|
|
sbuf_vprintf(sb, fmt, ap);
|
|
|
|
sbuf_finish(sb);
|
|
|
|
mtx_unlock(&Giant);
|
|
|
|
printf("%s\n", sbuf_data(sb));
|
|
|
|
sbuf_delete(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_hexdump(void *ptr, int length)
|
|
|
|
{
|
|
|
|
int i, j, k;
|
|
|
|
unsigned char *cp;
|
|
|
|
|
|
|
|
cp = ptr;
|
|
|
|
for (i = 0; i < length; i+= 16) {
|
|
|
|
printf("%04x ", i);
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
k = i + j;
|
|
|
|
if (k < length)
|
|
|
|
printf(" %02x", cp[k]);
|
|
|
|
else
|
|
|
|
printf(" ");
|
|
|
|
}
|
|
|
|
printf(" |");
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
k = i + j;
|
|
|
|
if (k >= length)
|
|
|
|
printf(" ");
|
|
|
|
else if (cp[k] >= ' ' && cp[k] <= '~')
|
|
|
|
printf("%c", cp[k]);
|
|
|
|
else
|
|
|
|
printf(".");
|
|
|
|
}
|
|
|
|
printf("|\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|