xref: /original-bsd/usr.bin/vmstat/names.c (revision a1c2194a)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)names.c	5.2 (Berkeley) 06/04/91
8  */
9 
10 #if !defined(hp300) && !defined(tahoe) && !defined(vax)
11 char *defdrives[] = { 0 };
12 #endif
13 
14 #ifdef hp300
15 #include <hp300/dev/device.h>
16 
17 char *defdrives[] = { "sd0", "sd1", "sd2", "rd0", "rd1", "rd2", 0 };
18 
19 void
20 read_names()
21 {
22 	register char *p;
23 	register u_long hp;
24 	static char buf[BUFSIZ];
25 	struct hp_device hdev;
26 	struct driver hdrv;
27 	char name[10];
28 
29 	hp = nl[X_HPDINIT].n_value;
30 	if (hp == 0) {
31 		(void) fprintf(stderr,
32 		    "vmstat: disk init info not in namelist\n");
33 		exit(1);
34 	}
35 	p = buf;
36 	for (;; hp += sizeof hdev) {
37 		(void)kvm_read((void *)hp, &hdev, sizeof hdev);
38 		if (hdev.hp_driver == 0)
39 			break;
40 		if (hdev.hp_dk < 0 || hdev.hp_alive == 0 ||
41 		    hdev.hp_cdriver == 0)
42 			continue;
43 		(void)kvm_read(hdev.hp_driver, &hdrv, sizeof hdrv);
44 		(void)kvm_read(hdrv.d_name, name, sizeof name);
45 		dr_name[hdev.hp_dk] = p;
46 		p += sprintf(p, "%s%d", name, hdev.hp_unit) + 1;
47 	}
48 }
49 #endif /* hp300 */
50 
51 #ifdef tahoe
52 #include <tahoe/vba/vbavar.h>
53 
54 char *defdrives[] = { "dk0", "dk1", "dk2", 0 };
55 
56 void
57 read_names()
58 {
59 	register char *p;
60 	struct vba_device udev, *up;
61 	struct vba_driver udrv;
62 	char name[10];
63 	static char buf[BUFSIZ];
64 
65 	up = (struct vba_device *) nl[X_VBDINIT].n_value;
66 	if (up == 0) {
67 		(void) fprintf(stderr,
68 		    "vmstat: disk init info not in namelist\n");
69 		exit(1);
70 	}
71 	p = buf;
72 	for (;; up += sizeof udev) {
73 		(void)kvm_read(up, &udev, sizeof udev);
74 		if (udev.ui_driver == 0)
75 			break;
76 		if (udev.ui_dk < 0 || udev.ui_alive == 0)
77 			continue;
78 		(void)kvm_read(udev.ui_driver, &udrv, sizeof udrv);
79 		(void)kvm_read(udrv.ud_dname, name, sizeof name);
80 		dr_name[udev.ui_dk] = p;
81 		p += sprintf(p, "%s%d", name, udev.ui_unit);
82 	}
83 }
84 #endif /* tahoe */
85 
86 #ifdef vax
87 #include <vax/uba/ubavar.h>
88 #include <vax/mba/mbavar.h>
89 
90 char *defdrives[] = { "hp0", "hp1", "hp2", 0 };
91 
92 void
93 read_names()
94 {
95 	register char *p;
96 	unsigned long mp, up;
97 	struct mba_device mdev;
98 	struct mba_driver mdrv;
99 	struct uba_device udev;
100 	struct uba_driver udrv;
101 	char name[10];
102 	static char buf[BUFSIZ];
103 
104 	mp = nl[X_MBDINIT].n_value;
105 	up = nl[X_UBDINIT].n_value;
106 	if (mp == 0 && up == 0) {
107 		(void) fprintf(stderr,
108 		    "vmstat: disk init info not in namelist\n");
109 		exit(1);
110 	}
111 	p = buf;
112 	if (mp) for (;; mp += sizeof mdev) {
113 		(void)kvm_read(mp, &mdev, sizeof mdev);
114 		if (mdev.mi_driver == 0)
115 			break;
116 		if (mdev.mi_dk < 0 || mdev.mi_alive == 0)
117 			continue;
118 		(void)kvm_read(mdev.mi_driver, &mdrv, sizeof mdrv);
119 		(void)kvm_read(mdrv.md_dname, name, sizeof name);
120 		dr_name[mdev.mi_dk] = p;
121 		p += sprintf(p, "%s%d", name, mdev.mi_unit);
122 	}
123 	if (up) for (;; up += sizeof udev) {
124 		(void)kvm_read(up, &udev, sizeof udev);
125 		if (udev.ui_driver == 0)
126 			break;
127 		if (udev.ui_dk < 0 || udev.ui_alive == 0)
128 			continue;
129 		(void)kvm_read(udev.ui_driver, &udrv, sizeof udrv);
130 		(void)kvm_read(udrv.ud_dname, name, sizeof name);
131 		dr_name[udev.ui_dk] = p;
132 		p += sprintf(p, "%s%d", name, udev.ui_unit);
133 	}
134 }
135 #endif /* vax */
136