home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.bin / vmstat / names.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-26  |  4.7 KB  |  162 lines

  1. /*-
  2.  * Copyright (c) 1991 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  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.
  20.  *
  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
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)names.c    5.2 (Berkeley) 6/4/91
  34.  */
  35.  
  36. #if !defined(hp300) && !defined(tahoe) && !defined(vax)
  37. char *defdrives[] = { 0 };
  38. #endif
  39.  
  40. #ifdef hp300
  41. #include <hp300/dev/device.h>
  42.  
  43. char *defdrives[] = { "sd0", "sd1", "sd2", "rd0", "rd1", "rd2", 0 };
  44.  
  45. void
  46. read_names()
  47. {
  48.     register char *p;
  49.     register u_long hp;
  50.     static char buf[BUFSIZ];
  51.     struct hp_device hdev;
  52.     struct driver hdrv;
  53.     char name[10];
  54.  
  55.     hp = nl[X_HPDINIT].n_value;
  56.     if (hp == 0) {
  57.         (void) fprintf(stderr,
  58.             "vmstat: disk init info not in namelist\n");
  59.         exit(1);
  60.     }
  61.     p = buf;
  62.     for (;; hp += sizeof hdev) {
  63.         (void)kvm_read((void *)hp, &hdev, sizeof hdev);
  64.         if (hdev.hp_driver == 0)
  65.             break;
  66.         if (hdev.hp_dk < 0 || hdev.hp_alive == 0 ||
  67.             hdev.hp_cdriver == 0)
  68.             continue;
  69.         (void)kvm_read(hdev.hp_driver, &hdrv, sizeof hdrv);
  70.         (void)kvm_read(hdrv.d_name, name, sizeof name);
  71.         dr_name[hdev.hp_dk] = p;
  72.         p += sprintf(p, "%s%d", name, hdev.hp_unit) + 1;
  73.     }
  74. }
  75. #endif /* hp300 */
  76.  
  77. #ifdef tahoe
  78. #include <tahoe/vba/vbavar.h>
  79.  
  80. char *defdrives[] = { "dk0", "dk1", "dk2", 0 };
  81.  
  82. void
  83. read_names()
  84. {
  85.     register char *p;
  86.     struct vba_device udev, *up;
  87.     struct vba_driver udrv;
  88.     char name[10];
  89.     static char buf[BUFSIZ];
  90.  
  91.     up = (struct vba_device *) nl[X_VBDINIT].n_value;
  92.     if (up == 0) {
  93.         (void) fprintf(stderr,
  94.             "vmstat: disk init info not in namelist\n");
  95.         exit(1);
  96.     }
  97.     p = buf;
  98.     for (;; up += sizeof udev) {
  99.         (void)kvm_read(up, &udev, sizeof udev);
  100.         if (udev.ui_driver == 0)
  101.             break;
  102.         if (udev.ui_dk < 0 || udev.ui_alive == 0)
  103.             continue;
  104.         (void)kvm_read(udev.ui_driver, &udrv, sizeof udrv);
  105.         (void)kvm_read(udrv.ud_dname, name, sizeof name);
  106.         dr_name[udev.ui_dk] = p;
  107.         p += sprintf(p, "%s%d", name, udev.ui_unit);
  108.     }
  109. }
  110. #endif /* tahoe */
  111.  
  112. #ifdef vax
  113. #include <vax/uba/ubavar.h>
  114. #include <vax/mba/mbavar.h>
  115.  
  116. char *defdrives[] = { "hp0", "hp1", "hp2", 0 };
  117.  
  118. void
  119. read_names()
  120. {
  121.     register char *p;
  122.     unsigned long mp, up;
  123.     struct mba_device mdev;
  124.     struct mba_driver mdrv;
  125.     struct uba_device udev;
  126.     struct uba_driver udrv;
  127.     char name[10];
  128.     static char buf[BUFSIZ];
  129.  
  130.     mp = nl[X_MBDINIT].n_value;
  131.     up = nl[X_UBDINIT].n_value;
  132.     if (mp == 0 && up == 0) {
  133.         (void) fprintf(stderr,
  134.             "vmstat: disk init info not in namelist\n");
  135.         exit(1);
  136.     }
  137.     p = buf;
  138.     if (mp) for (;; mp += sizeof mdev) {
  139.         (void)kvm_read(mp, &mdev, sizeof mdev);
  140.         if (mdev.mi_driver == 0)
  141.             break;
  142.         if (mdev.mi_dk < 0 || mdev.mi_alive == 0)
  143.             continue;
  144.         (void)kvm_read(mdev.mi_driver, &mdrv, sizeof mdrv);
  145.         (void)kvm_read(mdrv.md_dname, name, sizeof name);
  146.         dr_name[mdev.mi_dk] = p;
  147.         p += sprintf(p, "%s%d", name, mdev.mi_unit);
  148.     }
  149.     if (up) for (;; up += sizeof udev) {
  150.         (void)kvm_read(up, &udev, sizeof udev);
  151.         if (udev.ui_driver == 0)
  152.             break;
  153.         if (udev.ui_dk < 0 || udev.ui_alive == 0)
  154.             continue;
  155.         (void)kvm_read(udev.ui_driver, &udrv, sizeof udrv);
  156.         (void)kvm_read(udrv.ud_dname, name, sizeof name);
  157.         dr_name[udev.ui_dk] = p;
  158.         p += sprintf(p, "%s%d", name, udev.ui_unit);
  159.     }
  160. }
  161. #endif /* vax */
  162.