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
|
$NetBSD: patch-df,v 1.3 2002/05/20 19:09:49 cjep Exp $
--- ksysguard/ksysguardd/FreeBSD/Memory.c.orig Sat Nov 10 18:17:04 2001
+++ ksysguard/ksysguardd/FreeBSD/Memory.c Mon Nov 26 12:00:04 2001
@@ -32,7 +32,12 @@
#include <sys/types.h>
#include <sys/vmmeter.h>
#include <unistd.h>
+/* Everything post 1.5.x uses uvm/uvm_* includes */
+#if __NetBSD_Version__ >= 105010000
+#include <uvm/uvm_param.h>
+#else
#include <vm/vm_param.h>
+#endif
#include "Command.h"
#include "Memory.h"
@@ -82,15 +87,25 @@
struct vmtotal p;
FILE *file;
char buf[256];
+ int rc;
+#ifndef __NetBSD__
struct kvm_swap kswap[16];
int i, swap_count, hlen, pagesize = getpagesize();
long blocksize;
+#endif
len = sizeof (Total);
+#ifdef __NetBSD__
+ mib[0] = CTL_HW;
+ mib[1] = HW_PHYSMEM;
+ sysctl(mib, sizeof(mib), &Total, &len, NULL, 0);
+#else
sysctlbyname("hw.physmem", &Total, &len, NULL, 0);
+#endif
Total /= 1024;
/* Borrowed from pstat */
+#ifndef __NetBSD__
swap_count = kvm_getswapinfo(kd, kswap, 16, SWIF_DEV_PREFIX);
getbsize(&hlen, &blocksize);
@@ -101,24 +116,42 @@
SUsed = CONVERT(kswap[0].ksw_used);
SFree = CONVERT(kswap[0].ksw_total - kswap[0].ksw_used);
}
+#endif
+#ifdef __NetBSD__
+ /* NetBSD doesn't know about vfs.bufspace */
+ Buffers = -1;
+#else
len = sizeof (Buffers);
if ((sysctlbyname("vfs.bufspace", &Buffers, &len, NULL, 0) == -1) || !len)
Buffers = 0; /* Doesn't work under FreeBSD v2.2.x */
+#endif
Buffers /= 1024;
+#ifdef __NetBSD__
+ /* NetBSD doesn't know about vm.stats */
+ Cached = -1;
+#else
len = sizeof (Cached);
if ((sysctlbyname("vm.stats.vm.v_cache_count", &Cached, &len, NULL, 0) == -1) || !len)
Cached = 0; /* Doesn't work under FreeBSD v2.2.x */
+#endif
Cached *= getpagesize() / 1024;
+#ifdef __NetBSD__
+ /* No idea where to get them right now.
+ * I don't want to start kmem-digging... */
+ MFree = -1;
+ Used = -1;
+#else
/* initializes the pointer to the vmmeter struct */
len = sizeof (p);
sysctlbyname("vm.vmmeter", &p, &len, NULL, 0);
MFree = p.t_free * getpagesize() / 1024;
Used = p.t_arm * getpagesize() / 1024 + Buffers + Cached;
+#endif
return 0;
}
|