1 |
|
/* |
2 |
|
* i-scream central monitoring system |
3 |
< |
* http://www.i-scream.org.uk |
4 |
< |
* Copyright (C) 2000-2002 i-scream |
3 |
> |
* http://www.i-scream.org |
4 |
> |
* Copyright (C) 2000-2003 i-scream |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or |
7 |
|
* modify it under the terms of the GNU General Public License |
32 |
|
#include <stdio.h> |
33 |
|
#include "tools.h" |
34 |
|
#endif |
35 |
+ |
#ifdef FREEBSD |
36 |
+ |
#include <unistd.h> |
37 |
+ |
#include <sys/types.h> |
38 |
+ |
#include <fcntl.h> |
39 |
+ |
#include <kvm.h> |
40 |
+ |
#endif |
41 |
|
|
42 |
|
swap_stat_t *get_swap_stats(){ |
43 |
|
|
51 |
|
FILE *f; |
52 |
|
char *line_ptr; |
53 |
|
#endif |
54 |
+ |
#ifdef FREEBSD |
55 |
+ |
struct kvm_swap swapinfo; |
56 |
+ |
int pagesize; |
57 |
+ |
kvm_t *kvmd = NULL; |
58 |
+ |
#endif |
59 |
|
|
60 |
|
#ifdef SOLARIS |
61 |
|
if((pagesize=sysconf(_SC_PAGESIZE)) == -1){ |
82 |
|
} |
83 |
|
fclose(f); |
84 |
|
#endif |
85 |
+ |
#ifdef FREEBSD |
86 |
+ |
if((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL){ |
87 |
+ |
return NULL; |
88 |
+ |
} |
89 |
+ |
if ((kvm_getswapinfo(kvmd, &swapinfo, 1,0)) == -1){ |
90 |
+ |
return NULL; |
91 |
+ |
} |
92 |
+ |
pagesize=getpagesize(); |
93 |
|
|
94 |
+ |
swap_stat.total= (long long)swapinfo.ksw_total * (long long)pagesize; |
95 |
+ |
swap_stat.used = (long long)swapinfo.ksw_used * (long long)pagesize; |
96 |
+ |
swap_stat.free = swap_stat.total-swap_stat.used; |
97 |
+ |
|
98 |
+ |
kvm_close(kvmd); |
99 |
+ |
#endif |
100 |
|
return &swap_stat; |
101 |
|
|
102 |
|
} |