41 |
|
#include <sys/types.h> |
42 |
|
#include <kvm.h> |
43 |
|
#endif |
44 |
< |
#ifdef OPENBSD |
45 |
< |
#include <stdlib.h> |
44 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
45 |
|
#include <sys/param.h> |
47 |
– |
#include <sys/sysctl.h> |
46 |
|
#include <uvm/uvm.h> |
47 |
|
#endif |
48 |
|
|
67 |
|
#if defined(NETBSD) || defined(OPENBSD) |
68 |
|
struct uvmexp *uvm; |
69 |
|
#endif |
72 |
– |
#ifdef OPENBSD |
73 |
– |
int mib[2]; |
74 |
– |
size_t size; |
75 |
– |
#endif |
70 |
|
|
71 |
|
#ifdef SOLARIS |
72 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
113 |
|
swap_stat.used = (long long)swapinfo.ksw_used * (long long)pagesize; |
114 |
|
swap_stat.free = swap_stat.total-swap_stat.used; |
115 |
|
#endif |
116 |
< |
#ifdef NETBSD |
116 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
117 |
|
if ((uvm = get_uvmexp()) == NULL) { |
118 |
|
return NULL; |
119 |
|
} |
126 |
– |
#endif |
127 |
– |
#ifdef OPENBSD |
128 |
– |
mib[0] = CTL_VM; |
129 |
– |
mib[1] = VM_UVMEXP; |
120 |
|
|
131 |
– |
if (sysctl(mib, 2, NULL, &size, NULL, 0) < 0) { |
132 |
– |
return NULL; |
133 |
– |
} |
134 |
– |
|
135 |
– |
uvm = malloc(size); |
136 |
– |
if (uvm == NULL) { |
137 |
– |
return NULL; |
138 |
– |
} |
139 |
– |
|
140 |
– |
if (sysctl(mib, 2, uvm, &size, NULL, 0) < 0) { |
141 |
– |
return NULL; |
142 |
– |
} |
143 |
– |
#endif |
144 |
– |
|
145 |
– |
#if defined(NETBSD) || defined(OPENBSD) |
121 |
|
swap_stat.total = (long long)uvm->pagesize * (long long)uvm->swpages; |
122 |
|
swap_stat.used = (long long)uvm->pagesize * (long long)uvm->swpginuse; |
123 |
|
swap_stat.free = swap_stat.total - swap_stat.used; |
149 |
– |
#endif |
150 |
– |
|
151 |
– |
#ifdef OPENBSD |
152 |
– |
free(uvm); |
124 |
|
#endif |
125 |
|
|
126 |
|
return &swap_stat; |