--- projects/libstatgrab/src/libstatgrab/swap_stats.c 2004/02/14 00:04:12 1.14 +++ projects/libstatgrab/src/libstatgrab/swap_stats.c 2004/02/14 19:03:35 1.15 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * - * $Id: swap_stats.c,v 1.14 2004/02/14 00:04:12 ats Exp $ + * $Id: swap_stats.c,v 1.15 2004/02/14 19:03:35 tdb Exp $ */ #ifdef HAVE_CONFIG_H @@ -37,10 +37,16 @@ #include #endif #ifdef FREEBSD +#ifdef FREEBSD5 +#include +#include +#include +#else #include #include #include #endif +#endif #if defined(NETBSD) || defined(OPENBSD) #include #include @@ -61,10 +67,16 @@ swap_stat_t *get_swap_stats(){ unsigned long long value; #endif #ifdef FREEBSD - struct kvm_swap swapinfo; int pagesize; +#ifdef FREEBSD5 + struct xswdev xsw; + int mib[16], n; + size_t mibsize, size; +#else + struct kvm_swap swapinfo; kvm_t *kvmd; #endif +#endif #if defined(NETBSD) || defined(OPENBSD) struct uvmexp *uvm; #endif @@ -102,17 +114,45 @@ swap_stat_t *get_swap_stats(){ swap_stat.used = swap_stat.total - swap_stat.free; #endif #ifdef FREEBSD + pagesize=getpagesize(); + +#ifdef FREEBSD5 + swap_stat.total = 0; + swap_stat.used = 0; + + mibsize = sizeof mib / sizeof mib[0]; + if (sysctlnametomib("vm.swap_info", mib, &mibsize) < 0) { + return NULL; + } + for (n = 0; ; ++n) { + mib[mibsize] = n; + size = sizeof xsw; + if (sysctl(mib, mibsize + 1, &xsw, &size, NULL, NULL) < 0) { + break; + } + if (xsw.xsw_version != XSWDEV_VERSION) { + return NULL; + } + swap_stat.total += (long long) xsw.xsw_nblks; + swap_stat.used += (long long) xsw.xsw_used; + } + if (errno != ENOENT) { + return NULL; + } +#else if((kvmd = get_kvm()) == NULL){ return NULL; } if ((kvm_getswapinfo(kvmd, &swapinfo, 1,0)) == -1){ return NULL; } - pagesize=getpagesize(); - swap_stat.total= (long long)swapinfo.ksw_total * (long long)pagesize; - swap_stat.used = (long long)swapinfo.ksw_used * (long long)pagesize; - swap_stat.free = swap_stat.total-swap_stat.used; + swap_stat.total = (long long)swapinfo.ksw_total; + swap_stat.used = (long long)swapinfo.ksw_used; +#endif + swap_stat.total *= pagesize; + swap_stat.used *= pagesize; + swap_stat.free = swap_stat.total - swap_stat.used; #endif #if defined(NETBSD) || defined(OPENBSD) if ((uvm = get_uvmexp()) == NULL) {