ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/swap_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/swap_stats.c (file contents):
Revision 1.3 by pajs, Fri Mar 7 15:43:14 2003 UTC vs.
Revision 1.4 by pajs, Fri Apr 4 11:45:55 2003 UTC

# Line 32 | Line 32
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  
# Line 45 | Line 51 | swap_stat_t *get_swap_stats(){
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){
# Line 71 | Line 82 | swap_stat_t *get_swap_stats(){
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines