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

Comparing projects/libstatgrab/src/libstatgrab/disk_stats.c (file contents):
Revision 1.8 by pajs, Sat Mar 1 02:41:54 2003 UTC vs.
Revision 1.9 by pajs, Tue Mar 4 12:55:14 2003 UTC

# Line 23 | Line 23
23   #endif
24  
25   #include <stdlib.h>
26 #include <stdio.h>
26   #include <string.h>
27   #include "statgrab.h"
28  
29   #ifdef SOLARIS
30 + #include <stdio.h>
31   #include <sys/mnttab.h>
32   #include <sys/statvfs.h>
33   #include <kstat.h>
34   #define VALID_FS_TYPES {"ufs", "tmpfs"}
35   #endif
36  
37 + #ifdef LINUX
38 + #include <stdio.h>
39 + #include <sys/vfs.h>
40 + #include <mntent.h>
41 + #define VALID_FS_TYPES {"ext2", "ext3", "xfs", "reiserfs", "vfat", "tmpfs"}
42 + #endif
43 +
44   #define START_VAL 1
45  
46   char *copy_string(char *orig_ptr, const char *newtext){
# Line 67 | Line 74 | disk_stat_t *get_disk_stats(int *entries){
74  
75          char *fs_types[] = VALID_FS_TYPES;
76          int x, valid_type;
70
77          int num_disks=0;
72        struct mnttab mp;
73        struct statvfs fs;
78          FILE *f;
79  
80          disk_stat_t *disk_ptr;
81  
82 + #ifdef SOLARIS
83 +        struct mnttab *mp;
84 +        struct statvfs fs;
85 + #endif
86 + #ifdef LINUX
87 +        struct mntent *mp;
88 +        struct statfs fs;
89 + #endif
90 +
91          if(watermark==-1){
92                  disk_stats=malloc(START_VAL * sizeof(disk_stat_t));
93                  if(disk_stats==NULL){
# Line 83 | Line 96 | disk_stat_t *get_disk_stats(int *entries){
96                  watermark=START_VAL;
97                  init_disk_stat(0, watermark-1, disk_stats);
98          }
99 + #ifdef LINUX
100 +        if ((f=setmntent("/etc/mtab", "r" ))==NULL){
101 +                return NULL;
102 +        }
103  
104 +        while((mp=getmntent(f))){
105 +                if((statfs(mp->mnt_dir, &fs)) !=0){
106 +                        continue;
107 +                }      
108  
109 +                valid_type=0;
110 +                for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){
111 +                        if(strcmp(mp->mnt_type, fs_types[x]) ==0){
112 +                                valid_type=1;
113 +                                break;
114 +                        }
115 +                }
116 + #endif
117 +
118 + #ifdef SOLARIS
119          if ((f=fopen("/etc/mnttab", "r" ))==NULL){
120                  return NULL;
121          }
# Line 92 | Line 123 | disk_stat_t *get_disk_stats(int *entries){
123                  if ((statvfs(mp.mnt_mountp, &fs)) !=0){
124                          continue;
125                  }
95
126                  valid_type=0;
127                  for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){
128                          if(strcmp(mp.mnt_fstype, fs_types[x]) ==0){
# Line 100 | Line 130 | disk_stat_t *get_disk_stats(int *entries){
130                                  break;
131                          }
132                  }
133 + #endif
134  
135                  if(valid_type){
136                          if(num_disks>watermark-1){
# Line 114 | Line 145 | disk_stat_t *get_disk_stats(int *entries){
145                          }
146  
147                          disk_ptr=disk_stats+num_disks;
148 <        
148 > #ifdef LINUX
149 >                        if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->mnt_fsname))==NULL){
150 >                                return NULL;
151 >                        }
152 >                                
153 >                        if((disk_ptr->fs_type=copy_string(disk_ptr->fs_type, mp->mnt_type))==NULL){    
154 >                                return NULL;
155 >                        }
156 >
157 >                        if((disk_ptr->mnt_point=copy_string(disk_ptr->mnt_point, mp->mnt_dir))==NULL){
158 >                                return NULL;
159 >                        }
160 >                        disk_ptr->size = (long long)fs.f_bsize * (long long)fs.f_blocks;
161 >                        disk_ptr->avail = (long long)fs.f_bsize * (long long)fs.f_bavail;
162 >                        disk_ptr->used = (disk_ptr->size) - ((long long)fs.f_bsize * (long long)fs.f_bfree);
163 >
164 >                        disk_ptr->total_inodes=(long long)fs.f_files;
165 >                        disk_ptr->free_inodes=(long long)fs.f_ffree;
166 >                        /* Linux doesn't have a "available" inodes */
167 >                        disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes;
168 > #endif
169 >
170 > #ifdef SOLARIS
171                          /* Memory leak in event of realloc failing */
172                          /* Maybe make this char[bigenough] and do strncpy's and put a null in the end?
173 <                           Downside is its a bit hungry for a lot of mounts, as MNT_MAX_SIZE woul prob be upwards
174 <                           of a k each */
173 >                         * Downside is its a bit hungry for a lot of mounts, as MNT_MAX_SIZE would prob
174 >                         * be upwards of a k each
175 >                         */
176                          if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp.mnt_special))==NULL){
177                                  return NULL;
178                          }
# Line 138 | Line 192 | disk_stat_t *get_disk_stats(int *entries){
192                          disk_ptr->total_inodes=(long long)fs.f_files;
193                          disk_ptr->used_inodes=disk_ptr->total_inodes - (long long)fs.f_ffree;
194                          disk_ptr->free_inodes=(long long)fs.f_favail;
195 <
195 > #endif
196                          num_disks++;
197                  }
198          }
# Line 151 | Line 205 | disk_stat_t *get_disk_stats(int *entries){
205          return disk_stats;
206  
207   }
208 <
208 > #ifdef SOLARIS
209   void diskio_stat_init(int start, int end, diskio_stat_t *diskio_stats){
210  
211          for(diskio_stats+=start; start<end; start++){
# Line 303 | Line 357 | diskio_stat_t *get_diskio_stats_diff(int *entries){
357          *entries=sizeof_diskio_stats_diff;
358          return diskio_stats_diff;
359   }
360 + #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines