2 * Copyright (c) 1980, 1992, 1993
3 * The Regents of the University of California. All rights reserved.
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.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 static char sccsid[] = "@(#)disks.c 8.1 (Berkeley) 6/6/93";
38 #include <sys/param.h>
39 #include <sys/types.h>
41 #include <sys/dkstat.h>
51 static void dkselect __P((char *, int, int []));
52 static int read_names __P((void));
54 static struct nlist namelist[] = {
59 #if defined(hp300) || defined(luna68k)
60 #define X_HPDINIT (X_DK_WPMS+1)
64 #define X_DK_NAMES (X_DK_WPMS+1)
68 #define X_SCSI_DINIT (X_DK_WPMS+1)
72 #define X_MBDINIT (X_DK_WPMS+1)
76 #define X_VBDINIT (X_DK_WPMS+1)
80 #define X_MBDINIT (X_DK_WPMS+1)
82 #define X_UBDINIT (X_DK_WPMS+2)
89 int dk_ndrive, *dk_select;
92 #include "names.c" /* XXX */
100 static char buf[1024];
105 if (kvm_nlist(kd, namelist)) {
109 if (namelist[X_DK_NDRIVE].n_value == 0) {
110 error("dk_ndrive undefined in kernel");
113 NREAD(X_DK_NDRIVE, &dk_ndrive, sizeof(dk_ndrive));
114 if (dk_ndrive <= 0) {
115 error("dk_ndrive=%d according to %s", dk_ndrive, getbootfile());
118 dk_mspw = (float *)calloc(dk_ndrive, sizeof (float));
120 long *wpms = (long *)calloc(dk_ndrive, sizeof(long));
121 KREAD(NPTR(X_DK_WPMS), wpms, dk_ndrive * sizeof (long));
122 for (i = 0; i < dk_ndrive; i++)
123 *(dk_mspw + i) = (*(wpms + i) == 0)? 0.0:
124 (float) 1.0 / *(wpms + i);
127 dr_name = (char **)calloc(dk_ndrive, sizeof (char *));
128 dk_select = (int *)calloc(dk_ndrive, sizeof (int));
129 for (cp = buf, i = 0; i < dk_ndrive; i++) {
131 snprintf(cp, sizeof(buf) - (cp - buf), "dk%d", i);
132 cp += strlen(cp) + 1;
133 if (cp > buf + sizeof(buf))
134 errx(1, "buf too small in dkinit, aborting");
135 if (dk_mspw[i] != 0.0)
152 if (prefix(cmd, "display") || prefix(cmd, "add")) {
153 dkselect(args, 1, dk_select);
156 if (prefix(cmd, "ignore") || prefix(cmd, "delete")) {
157 dkselect(args, 0, dk_select);
160 if (prefix(cmd, "drives")) {
163 move(CMDLINE, 0); clrtoeol();
164 for (i = 0; i < dk_ndrive; i++)
165 if (dk_mspw[i] != 0.0)
166 printw("%s ", dr_name[i]);
173 dkselect(args, truefalse, selections)
175 int truefalse, selections[];
181 cp = index(args, '\n');
185 for (cp = args; *cp && isspace(*cp); cp++)
188 for (; *cp && !isspace(*cp); cp++)
194 for (i = 0; i < dk_ndrive; i++)
195 if (strcmp(args, dr_name[i]) == 0) {
196 if (dk_mspw[i] != 0.0)
197 selections[i] = truefalse;
199 error("%s: drive not configured",
204 error("%s: unknown drive", args);