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){ |
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){ |
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 |
|
} |
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){ |
130 |
|
break; |
131 |
|
} |
132 |
|
} |
133 |
+ |
#endif |
134 |
|
|
135 |
|
if(valid_type){ |
136 |
|
if(num_disks>watermark-1){ |
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 |
|
} |
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 |
|
} |
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++){ |
357 |
|
*entries=sizeof_diskio_stats_diff; |
358 |
|
return diskio_stats_diff; |
359 |
|
} |
360 |
+ |
#endif |