41 |
|
#include <sys/types.h> |
42 |
|
#include <kvm.h> |
43 |
|
#endif |
44 |
+ |
#ifdef OPENBSD |
45 |
+ |
#include <stdlib.h> |
46 |
+ |
#include <sys/param.h> |
47 |
+ |
#include <sys/sysctl.h> |
48 |
+ |
#include <uvm/uvm.h> |
49 |
+ |
#endif |
50 |
|
|
51 |
|
swap_stat_t *get_swap_stats(){ |
52 |
|
|
66 |
|
int pagesize; |
67 |
|
kvm_t *kvmd; |
68 |
|
#endif |
69 |
< |
#ifdef NETBSD |
69 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
70 |
|
struct uvmexp *uvm; |
71 |
|
#endif |
72 |
+ |
#ifdef OPENBSD |
73 |
+ |
int mib[2]; |
74 |
+ |
size_t size; |
75 |
+ |
#endif |
76 |
|
|
77 |
|
#ifdef SOLARIS |
78 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
123 |
|
if ((uvm = get_uvmexp()) == NULL) { |
124 |
|
return NULL; |
125 |
|
} |
126 |
+ |
#endif |
127 |
+ |
#ifdef OPENBSD |
128 |
+ |
mib[0] = CTL_VM; |
129 |
+ |
mib[1] = VM_UVMEXP; |
130 |
|
|
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) |
146 |
|
swap_stat.total = (long long)uvm->pagesize * (long long)uvm->swpages; |
147 |
|
swap_stat.used = (long long)uvm->pagesize * (long long)uvm->swpginuse; |
148 |
|
swap_stat.free = swap_stat.total - swap_stat.used; |
149 |
|
#endif |
150 |
+ |
|
151 |
+ |
#ifdef OPENBSD |
152 |
+ |
free(uvm); |
153 |
+ |
#endif |
154 |
+ |
|
155 |
|
return &swap_stat; |
156 |
|
|
157 |
|
} |