$NetBSD: patch-dd,v 1.3 2002/08/25 19:23:45 jlam Exp $ --- ksysguard/ksysguardd/FreeBSD/Memory.c.orig Fri Sep 14 22:11:20 2001 +++ ksysguard/ksysguardd/FreeBSD/Memory.c Tue Aug 20 14:20:49 2002 @@ -32,7 +32,12 @@ #include #include #include +/* Everything post 1.5.x uses uvm/uvm_* includes */ +#if __NetBSD_Version__ >= 105010000 +#include +#else #include +#endif #include "Command.h" #include "Memory.h" @@ -77,6 +82,49 @@ exitMemory(void) int updateMemory(void) { +#ifdef __NetBSD__ +#define ARRLEN(X) (sizeof(X)/sizeof(X[0])) + long pagesize; /* using a long promotes the arithmetic */ + size_t len; + + { static int mib[]={ CTL_HW, HW_PHYSMEM }; + + len = sizeof(Total); + sysctl(mib, ARRLEN(mib), &Total, &len, NULL, 0); + Total >>= 10; + } + + { struct uvmexp x; + static int mib[] = { CTL_VM, VM_UVMEXP }; + + len = sizeof(x); + STotal = SUsed = SFree = -1; + pagesize = 1; + if (-1 < sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0)) { + pagesize = x.pagesize; + STotal = (pagesize*x.swpages) >> 10; + SUsed = (pagesize*x.swpginuse) >> 10; + SFree = STotal - SUsed; + } + } + + /* can't find NetBSD filesystem buffer info */ + Buffers = -1; + + /* NetBSD doesn't know about vm.stats */ + Cached = -1; + + { static int mib[]={ CTL_VM, VM_METER }; + struct vmtotal x; + + len = sizeof(x); + MFree = Used = -1; + if (sysctl(mib, ARRLEN(mib), &x, &len, NULL, 0) > -1) { + MFree = (x.t_free * pagesize) >> 10; + Used = (x.t_rm * pagesize) >> 10; + } + } +#else int mib[2]; size_t len; struct vmtotal p; @@ -119,6 +167,7 @@ updateMemory(void) sysctlbyname("vm.vmmeter", &p, &len, NULL, 0); MFree = p.t_free * getpagesize() / 1024; Used = p.t_arm * getpagesize() / 1024 + Buffers + Cached; +#endif return 0; }