[BACK]Return to disks.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / systat

Annotation of src/usr.bin/systat/disks.c, Revision 1.2

1.2     ! niklas      1: /*     $OpenBSD$       */
        !             2: /*     $NetBSD: disks.c,v 1.3 1996/03/15 22:19:23 ragge Exp $  */
1.1       deraadt     3:
                      4: /*-
                      5:  * Copyright (c) 1980, 1992, 1993
                      6:  *     The Regents of the University of California.  All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *     This product includes software developed by the University of
                     19:  *     California, Berkeley and its contributors.
                     20:  * 4. Neither the name of the University nor the names of its contributors
                     21:  *    may be used to endorse or promote products derived from this software
                     22:  *    without specific prior written permission.
                     23:  *
                     24:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     25:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     26:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     27:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     28:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     29:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     30:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     31:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     32:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     33:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     34:  * SUCH DAMAGE.
                     35:  */
                     36:
                     37: #ifndef lint
                     38: #if 0
                     39: static char sccsid[] = "@(#)disks.c    8.1 (Berkeley) 6/6/93";
1.2     ! niklas     40: static char rcsid[] = "$NetBSD: disks.c,v 1.3 1996/03/15 22:19:23 ragge Exp $";
1.1       deraadt    41: #endif
1.2     ! niklas     42: static char rcsid[] = "$OpenBSD$";
1.1       deraadt    43: #endif /* not lint */
                     44:
                     45: #include <sys/types.h>
                     46: #include <sys/buf.h>
                     47:
                     48: #include <nlist.h>
                     49: #include <ctype.h>
                     50: #include <paths.h>
                     51: #include <string.h>
                     52: #include <stdlib.h>
                     53: #include "systat.h"
                     54: #include "extern.h"
                     55:
                     56: static void dkselect __P((char *, int, int []));
                     57: static int read_names __P((void));
                     58:
                     59: static struct nlist namelist[] = {
                     60: #define        X_DK_NDRIVE     0
                     61:        { "_dk_ndrive" },
                     62: #define        X_DK_WPMS       1
                     63:        { "_dk_wpms" },
                     64: #ifdef sun
                     65: #define        X_MBDINIT       (X_DK_WPMS+1)
                     66:        { "_mbdinit" },
                     67: #endif
                     68: #ifdef tahoe
                     69: #define        X_VBDINIT       (X_DK_WPMS+1)
                     70:        { "_vbdinit" },
                     71: #endif
                     72: #if defined(hp300) || defined(luna68k)
                     73: #define X_HPDINIT       (X_DK_WPMS+1)
                     74:         { "_hp_dinit" },
                     75: #endif
                     76: #ifdef mips
                     77: #define X_SCSI_DINIT   (X_DK_WPMS+1)
                     78:        { "_scsi_dinit" },
                     79: #endif
                     80:        { "" },
                     81: };
                     82:
                     83: float *dk_mspw;
                     84: int dk_ndrive, *dk_select;
                     85: char **dr_name;
                     86:
                     87: #include "names.c"                                     /* XXX */
                     88:
                     89: int
                     90: dkinit()
                     91: {
                     92:        register int i;
                     93:        register char *cp;
                     94:        static int once = 0;
                     95:        static char buf[1024];
                     96:
                     97:        if (once)
                     98:                return(1);
                     99:
                    100:        if (kvm_nlist(kd, namelist)) {
                    101:                nlisterr(namelist);
                    102:                return(0);
                    103:        }
                    104:        if (namelist[X_DK_NDRIVE].n_value == 0) {
                    105:                error("dk_ndrive undefined in kernel");
                    106:                return(0);
                    107:        }
                    108:        NREAD(X_DK_NDRIVE, &dk_ndrive, LONG);
                    109:        if (dk_ndrive <= 0) {
                    110:                error("dk_ndrive=%d according to %s", dk_ndrive, _PATH_UNIX);
                    111:                return(0);
                    112:        }
                    113:        dk_mspw = (float *)calloc(dk_ndrive, sizeof (float));
                    114:        {
                    115:                long *wpms = (long *)calloc(dk_ndrive, sizeof(long));
                    116:                KREAD(NPTR(X_DK_WPMS), wpms, dk_ndrive * sizeof (long));
                    117:                for (i = 0; i < dk_ndrive; i++)
                    118:                        *(dk_mspw + i) = (*(wpms + i) == 0)? 0.0:
                    119:                                         (float) 1.0 / *(wpms + i);
                    120:                free(wpms);
                    121:        }
                    122:        dr_name = (char **)calloc(dk_ndrive, sizeof (char *));
                    123:        dk_select = (int *)calloc(dk_ndrive, sizeof (int));
                    124:        for (cp = buf, i = 0; i < dk_ndrive; i++) {
                    125:                dr_name[i] = cp;
                    126:                sprintf(dr_name[i], "dk%d", i);
                    127:                cp += strlen(dr_name[i]) + 1;
                    128:                if (dk_mspw[i] != 0.0)
                    129:                        dk_select[i] = 1;
                    130:        }
                    131:        if (!read_names()) {
                    132:                free(dr_name);
                    133:                free(dk_select);
                    134:                free(dk_mspw);
                    135:                return(0);
                    136:        }
                    137:        once = 1;
                    138:        return(1);
                    139: }
                    140:
                    141: int
                    142: dkcmd(cmd, args)
                    143:        char *cmd, *args;
                    144: {
                    145:        if (prefix(cmd, "display") || prefix(cmd, "add")) {
                    146:                dkselect(args, 1, dk_select);
                    147:                return (1);
                    148:        }
                    149:        if (prefix(cmd, "ignore") || prefix(cmd, "delete")) {
                    150:                dkselect(args, 0, dk_select);
                    151:                return (1);
                    152:        }
                    153:        if (prefix(cmd, "drives")) {
                    154:                register int i;
                    155:
                    156:                move(CMDLINE, 0); clrtoeol();
                    157:                for (i = 0; i < dk_ndrive; i++)
                    158:                        if (dk_mspw[i] != 0.0)
                    159:                                printw("%s ", dr_name[i]);
                    160:                return (1);
                    161:        }
                    162:        return (0);
                    163: }
                    164:
                    165: static void
                    166: dkselect(args, truefalse, selections)
                    167:        char *args;
                    168:        int truefalse, selections[];
                    169: {
                    170:        register char *cp;
                    171:        register int i;
                    172:        char *index();
                    173:
                    174:        cp = index(args, '\n');
                    175:        if (cp)
                    176:                *cp = '\0';
                    177:        for (;;) {
                    178:                for (cp = args; *cp && isspace(*cp); cp++)
                    179:                        ;
                    180:                args = cp;
                    181:                for (; *cp && !isspace(*cp); cp++)
                    182:                        ;
                    183:                if (*cp)
                    184:                        *cp++ = '\0';
                    185:                if (cp - args == 0)
                    186:                        break;
                    187:                for (i = 0; i < dk_ndrive; i++)
                    188:                        if (strcmp(args, dr_name[i]) == 0) {
                    189:                                if (dk_mspw[i] != 0.0)
                    190:                                        selections[i] = truefalse;
                    191:                                else
                    192:                                        error("%s: drive not configured",
                    193:                                            dr_name[i]);
                    194:                                break;
                    195:                        }
                    196:                if (i >= dk_ndrive)
                    197:                        error("%s: unknown drive", args);
                    198:                args = cp;
                    199:        }
                    200: }