2 * Copyright (c) 1999 Andrzej Bialecki <abial@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * $FreeBSD: src/release/sysinstall/kget.c,v 1.14.2.1 2000/07/14 10:21:32 jhb Exp $
27 * $DragonFly: src/release/sysinstall/Attic/kget.c,v 1.2 2003/06/17 04:27:21 dillon Exp $
39 #include "sysinstall.h"
40 #include <sys/sysctl.h>
41 #include <machine/uc_device.h>
46 int len, i, bytes_written = 0;
48 char *mib1 = "machdep.uc_devlist";
54 /* create the output file; if we end up not writing to it, we'll
56 fout = fopen(out, "w");
58 msgDebug("kget: Unable to open %s for writing.\n", out);
62 /* We use sysctlbyname, because the oid is unknown (OID_AUTO) */
63 /* get the buffer size */
64 i = sysctlbyname(mib1, NULL, &len, NULL, NULL);
66 msgDebug("kget: error buffer sizing\n");
70 msgDebug("kget: mib1 has length of %d\n", len);
73 buf = (char *)alloca(len * sizeof(char));
74 i = sysctlbyname(mib1, buf, &len, NULL, NULL);
76 msgDebug("kget: error retrieving data\n");
83 id = (struct uc_device *)(buf + i);
84 p = (buf + i + sizeof(struct uc_device));
86 if (!id->id_enabled) {
87 bytes_written += fprintf(fout, "di %s%d\n", name, id->id_unit);
90 bytes_written += fprintf(fout, "en %s%d\n", name, id->id_unit);
91 if (id->id_iobase > 0) {
92 bytes_written += fprintf(fout, "po %s%d %#x\n",
93 name, id->id_unit, id->id_iobase);
96 bytes_written += fprintf(fout, "ir %s%d %d\n", name,
97 id->id_unit, ffs(id->id_irq) - 1);
100 bytes_written += fprintf(fout, "dr %s%d %d\n", name,
101 id->id_unit, id->id_drq);
103 if (id->id_maddr > 0) {
104 bytes_written += fprintf(fout, "iom %s%d %#x\n", name,
105 id->id_unit, (u_int)id->id_maddr);
107 if (id->id_msize > 0) {
108 bytes_written += fprintf(fout, "ios %s%d %d\n", name,
109 id->id_unit, id->id_msize);
111 bytes_written += fprintf(fout, "f %s%d %#x\n", name,
112 id->id_unit, id->id_flags);
114 i += sizeof(struct uc_device) + 8;
119 fprintf(fout, "q\n");