1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
--- sysinfo.c.orig Tue Oct 6 16:21:18 1998
+++ sysinfo.c Fri Sep 16 10:30:05 2005
@@ -13,7 +13,9 @@
#include <sys/ioctl_compat.h> /* XXX NTTYDISC is too well hidden */
#include <sys/tty.h>
#include <sys/conf.h>
+#if __FreeBSD_version < 400000
#include <sys/rlist.h>
+#endif
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <err.h>
@@ -34,8 +36,14 @@
#include <sys/time.h>
#include <sys/mount.h>
#include <nfs/rpcv2.h>
+#if __FreeBSD_version >= 500000
+#include <nfs/nfsproto.h>
+#include <nfsclient/nfs.h>
+#include <nfsserver/nfs.h>
+#else
#include <nfs/nfsv2.h>
#include <nfs/nfs.h>
+#endif
#include <osreldate.h>
#include <fcntl.h>
@@ -95,6 +103,9 @@
#endif /* HAVE_DEVSTAT */
static struct nfsstats nfsstats;
+#if __FreeBSD_version >= 500000
+static struct nfsrvstats nfsrvstats;
+#endif
static struct _nfsStats {
int nfsServer, nfsClient;
} nfsStats, old_nfsStats;
@@ -102,6 +113,7 @@
struct nlist nl[] = {
#define X_CP_TIME 0
{ "_cp_time" },
+#if __FreeBSD_version < 400000
#define VM_SWAPLIST 1
{ "_swaplist" },/* list of free swap areas */
#define VM_SWDEVT 2
@@ -129,6 +141,33 @@
#define X_DKXFER 12
{ "_dk_xfer" },
#endif
+#else /* __FreeBSD_version < 400000 */
+#define VM_DMMAX 1
+ { "_dmmax" }, /* maximum size of a swap block */
+#define V_MOUNTLIST 2
+ { "_mountlist" }, /* address of head of mount list. */
+#define V_NUMV 3
+ { "_numvnodes" },
+#define FNL_NFILE 4
+/* nfiles changes name to openfiles in FreeBSD 6,
+ and also for a short period of time in RELENG_5 */
+#if (__FreeBSD_version > 600000) || ((__FreeBSD_version >= 503101) && (__FreeBSD_version < 503105))
+ {"_openfiles"},
+#else
+ {"_nfiles"},
+#endif
+#define FNL_MAXFILE 5
+ {"_maxfiles"},
+#define NLMANDATORY FNL_MAXFILE /* names up to here are mandatory */
+#define X_CNT 6
+ { "_cnt" }, /* struct vmmeter cnt */
+#define N_IFNET 7
+ { "_ifnet" },
+#ifndef HAVE_DEVSTAT
+#define X_DKXFER 8
+ { "_dk_xfer" },
+#endif
+#endif /* __FreeBSD_version < 400000 */
{ "" },
};
@@ -238,6 +277,14 @@
int pkt_in_out;
int total_xfers=0;
int mib[3], size;
+#if __FreeBSD_version >= 500000
+ int rvsize;
+ struct xvfsconf vfc;
+#else
+#if (__FreeBSD_version >= 300004)
+ struct vfsconf vfc;
+#endif
+#endif // #if __FreeBSD_version >= 500000
/* NPROCS=0, CPU */
if (cpuflag) {
@@ -356,19 +403,39 @@
for (i=0; i<10; i++)
states[i] = 0;
size = sizeof(nfsstats);
+#if __FreeBSD_version >= 500000
+ rvsize = sizeof(nfsrvstats);
+#endif
#if (__FreeBSD_version < 199512)
mib[0] = CTL_FS;
#else
mib[0] = CTL_VFS;
#endif
-#if (__FreeBSD_version >= 300003) /* ?? */
- mib[1] = MNT_EXPORTED;
+#if (__FreeBSD_version >= 300004)
+ if (getvfsbyname("nfs", &vfc) < 0)
+ /* no NFS in the kernel */
+ goto nfs_out;
+ mib[1] = vfc.vfc_typenum;
#else
- mib[1] = MNT_NFS;
+ mib[1] = MOUNT_NFS;
#endif
mib[2] = NFS_NFSSTATS;
+#if __FreeBSD_version >= 500000
+ if (sysctl( mib, 3, &nfsstats, &size, NULL, 0) < 0) {
+ return;
+ }
+ else {
+ size_t len = 3;
+ sysctlnametomib("vfs.nfsrv", mib, &len);
+ mib[2] = NFS_NFSRVSTATS;
+ }
+ if (sysctl( mib, 3, &nfsrvstats, &rvsize, NULL, 0) < 0) {
+ return;
+ }
+#else
if (sysctl( mib, 3, &nfsstats, &size, NULL, 0) < 0)
goto nfs_out;
+#endif
else {
old_nfsStats = nfsStats;
@@ -395,6 +462,22 @@
#else
nfsstats.rpccnt[NFSPROC_READDIR];
#endif
+#if __FreeBSD_version >= 500000
+ nfsStats.nfsServer = nfsrvstats.srvrpccnt[NFSPROC_GETATTR] +
+ nfsrvstats.srvrpccnt[NFSPROC_SETATTR] +
+ nfsrvstats.srvrpccnt[NFSPROC_LOOKUP] +
+ nfsrvstats.srvrpccnt[NFSPROC_READLINK] +
+ nfsrvstats.srvrpccnt[NFSPROC_READ] +
+ nfsrvstats.srvrpccnt[NFSPROC_WRITE] +
+ nfsrvstats.srvrpccnt[NFSPROC_CREATE] +
+ nfsrvstats.srvrpccnt[NFSPROC_REMOVE] +
+ nfsrvstats.srvrpccnt[NFSPROC_RENAME] +
+ nfsrvstats.srvrpccnt[NFSPROC_LINK] +
+ nfsrvstats.srvrpccnt[NFSPROC_SYMLINK] +
+ nfsrvstats.srvrpccnt[NFSPROC_MKDIR] +
+ nfsrvstats.srvrpccnt[NFSPROC_RMDIR] +
+ nfsrvstats.srvrpccnt[NFSPROC_READDIR];
+#else
nfsStats.nfsServer = nfsstats.srvrpccnt[NFSPROC_GETATTR] +
nfsstats.srvrpccnt[NFSPROC_SETATTR] +
nfsstats.srvrpccnt[NFSPROC_LOOKUP] +
@@ -418,6 +501,7 @@
#else
nfsstats.srvrpccnt[NFSPROC_READDIR];
#endif
+#endif // #if __FreeBSD_version >= 500000
}
scale_bar(250, nfsStats.nfsClient-old_nfsStats.nfsClient, 25, states, 0);
draw_bar(nfsflag-1, states, 10);
@@ -428,7 +512,7 @@
}
nfs_out:
-}
+;}
/* swapmode is derived from freebsd's pstat source ...
@@ -438,6 +522,21 @@
void
swapmode(int *used, int *avail)
{
+#if __FreeBSD_version >= 400000
+ /* based on swapmode from /usr/src/usr.bin/top/machine.c */
+ int n;
+ struct kvm_swap swapary[1];
+
+ n = kvm_getswapinfo(kd, swapary, 1, 0);
+ if (n < 0) {
+ *avail = *used = 0;
+ return;
+ }
+
+ *avail = swapary[0].ksw_total - swapary[0].ksw_used;
+ *used = swapary[0].ksw_used;
+ return;
+#else
char *header;
int hlen, nswap, nswdev, dmmax;
int i, div, nfree, npfree;
@@ -546,6 +645,7 @@
*used = *avail - nfree;
free(sw);
free(perdev);
+#endif /* __FreeBSD_version >= 400000 */
}
/*
@@ -623,13 +723,21 @@
* Make sure that the userland devstat version matches the kernel
* devstat version.
*/
+#if __FreeBSD_version >= 500000
+ if (devstat_checkversion(kd) < 0) {
+#else
if (checkversion() < 0) {
+#endif
nodisk++;
return;
}
/* find out how many devices we have */
+#if __FreeBSD_version >= 500000
+ if ((num_devices = devstat_getnumdevs(kd)) < 0) {
+#else
if ((num_devices = getnumdevs()) < 0) {
+#endif
nodisk++;
return;
}
@@ -644,7 +752,11 @@
* changed here, since it almost certainly has. We only look for
* errors.
*/
+#if __FreeBSD_version >= 500000
+ if (devstat_getdevs(NULL,&cur) == -1) {
+#else
if (getdevs(&cur) == -1) {
+#endif
nodisk++;
return;
}
@@ -656,7 +768,11 @@
/* only interested in disks */
matches = NULL;
+#if __FreeBSD_version >= 500000
+ if (devstat_buildmatch("da", &matches, &num_matches) != 0) {
+#else
if (buildmatch("da", &matches, &num_matches) != 0) {
+#endif
nodisk++;
return;
}
@@ -671,7 +787,11 @@
* device list has changed, so we don't look for return values of 0
* or 1. If we get back -1, though, there is an error.
*/
+#if __FreeBSD_version >= 500000
+ if (devstat_selectdevs(&dev_select, &num_selected,
+#else
if (selectdevs(&dev_select, &num_selected,
+#endif
&num_selections, &select_generation,
generation, cur.dinfo->devices, num_devices,
matches, num_matches,
@@ -697,7 +817,11 @@
* the selection process again, in case a device that we
* were previously displaying has gone away.
*/
+#if __FreeBSD_version >= 500000
+ switch (devstat_getdevs(NULL,&cur)) {
+#else
switch (getdevs(&cur)) {
+#endif
case -1:
return (0);
case 1: {
@@ -705,7 +829,11 @@
num_devices = cur.dinfo->numdevs;
generation = cur.dinfo->generation;
+#if __FreeBSD_version >= 500000
+ retval = devstat_selectdevs(&dev_select, &num_selected,
+#else
retval = selectdevs(&dev_select, &num_selected,
+#endif
&num_selections, &select_generation,
generation, cur.dinfo->devices,
num_devices, matches, num_matches,
@@ -729,14 +857,22 @@
* Calculate elapsed time up front, since it's the same for all
* devices.
*/
+#if __FreeBSD_version >= 500000
+ busy_seconds = cur.snap_time - last.snap_time;
+#else
busy_seconds = compute_etime(cur.busy_time, last.busy_time);
+#endif
/* this is the first time thru so just copy cur to last */
if (last.dinfo->numdevs == 0) {
tmp_dinfo = last.dinfo;
last.dinfo = cur.dinfo;
cur.dinfo = tmp_dinfo;
+#if __FreeBSD_version >= 500000
+ last.snap_time = cur.snap_time;
+#else
last.busy_time = cur.busy_time;
+#endif
return (0);
}
@@ -764,7 +900,11 @@
last.dinfo = cur.dinfo;
cur.dinfo = tmp_dinfo;
+#if __FreeBSD_version >= 500000
+ last.snap_time = cur.snap_time;
+#else
last.busy_time = cur.busy_time;
+#endif
} else
/* no disks found ? */
|