42 |
|
#define VALID_FS_TYPES {"ext2", "ext3", "xfs", "reiserfs", "vfat", "tmpfs"} |
43 |
|
#endif |
44 |
|
|
45 |
+ |
#ifdef FREEBSD |
46 |
+ |
#include <sys/param.h> |
47 |
+ |
#include <sys/ucred.h> |
48 |
+ |
#include <sys/mount.h> |
49 |
+ |
#define VALID_FS_TYPES {"ufs", "mfs"} |
50 |
+ |
#endif |
51 |
|
#define START_VAL 1 |
52 |
|
|
53 |
|
char *copy_string(char *orig_ptr, const char *newtext){ |
82 |
|
char *fs_types[] = VALID_FS_TYPES; |
83 |
|
int x, valid_type; |
84 |
|
int num_disks=0; |
85 |
+ |
#if defined(LINUX) || defined (SOLARIS) |
86 |
|
FILE *f; |
87 |
+ |
#endif |
88 |
|
|
89 |
|
disk_stat_t *disk_ptr; |
90 |
|
|
96 |
|
struct mntent *mp; |
97 |
|
struct statfs fs; |
98 |
|
#endif |
99 |
+ |
#ifdef FREEBSD |
100 |
+ |
int nummnt; |
101 |
+ |
struct statfs *mp; |
102 |
+ |
#endif |
103 |
|
|
104 |
|
if(watermark==-1){ |
105 |
|
disk_stats=malloc(START_VAL * sizeof(disk_stat_t)); |
109 |
|
watermark=START_VAL; |
110 |
|
init_disk_stat(0, watermark-1, disk_stats); |
111 |
|
} |
112 |
+ |
#ifdef FREEBSD |
113 |
+ |
nummnt=getmntinfo(&mp , MNT_LOCAL); |
114 |
+ |
if (nummnt<=0){ |
115 |
+ |
return NULL; |
116 |
+ |
} |
117 |
+ |
for(;nummnt--; mp++){ |
118 |
+ |
valid_type=0; |
119 |
+ |
for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){ |
120 |
+ |
if(strcmp(mp->f_fstypename, fs_types[x]) ==0){ |
121 |
+ |
valid_type=1; |
122 |
+ |
break; |
123 |
+ |
} |
124 |
+ |
} |
125 |
+ |
#endif |
126 |
+ |
|
127 |
|
#ifdef LINUX |
128 |
|
if ((f=setmntent("/etc/mtab", "r" ))==NULL){ |
129 |
|
return NULL; |
173 |
|
} |
174 |
|
|
175 |
|
disk_ptr=disk_stats+num_disks; |
176 |
+ |
#ifdef FREEBSD |
177 |
+ |
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->f_mntfromname))==NULL){ |
178 |
+ |
return NULL; |
179 |
+ |
} |
180 |
+ |
|
181 |
+ |
if((disk_ptr->fs_type=copy_string(disk_ptr->fs_type, mp->f_fstypename))==NULL){ |
182 |
+ |
return NULL; |
183 |
+ |
} |
184 |
+ |
|
185 |
+ |
if((disk_ptr->mnt_point=copy_string(disk_ptr->mnt_point, mp->f_mntonname))==NULL){ |
186 |
+ |
return NULL; |
187 |
+ |
} |
188 |
+ |
|
189 |
+ |
disk_ptr->size = (long long)mp->f_bsize * (long long) mp->f_blocks; |
190 |
+ |
disk_ptr->avail = (long long)mp->f_bsize * (long long) mp->f_bavail; |
191 |
+ |
disk_ptr->used = (disk_ptr->size) - ((long long)mp->f_bsize * (long long)mp->f_bfree); |
192 |
+ |
|
193 |
+ |
disk_ptr->total_inodes=(long long)mp->f_files; |
194 |
+ |
disk_ptr->free_inodes=(long long)mp->f_ffree; |
195 |
+ |
/* Freebsd doesn't have a "available" inodes */ |
196 |
+ |
disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes; |
197 |
+ |
#endif |
198 |
|
#ifdef LINUX |
199 |
|
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->mnt_fsname))==NULL){ |
200 |
|
return NULL; |
250 |
|
*entries=num_disks; |
251 |
|
|
252 |
|
/* If this fails, there is very little i can do about it, so i'll ignore it :) */ |
253 |
+ |
#if defined(LINUX) || defined(SOLARIS) |
254 |
|
fclose(f); |
255 |
+ |
#endif |
256 |
|
|
257 |
|
return disk_stats; |
258 |
|
|
424 |
|
diskio_stats_ptr->systime=time(NULL); |
425 |
|
num_diskio++; |
426 |
|
} |
427 |
+ |
|
428 |
|
fclose(f); |
429 |
|
|
430 |
|
#endif |