1 |
|
#include <stdlib.h> |
2 |
|
#include <stdio.h> |
3 |
|
#include <ukcprog.h> |
4 |
< |
#include <strings.h> |
4 |
> |
#include <string.h> |
5 |
|
|
6 |
|
#ifdef SOLARIS |
7 |
|
#include <sys/mnttab.h> |
8 |
|
#include <sys/types.h> |
9 |
|
#include <sys/statvfs.h> |
10 |
|
#endif |
11 |
< |
|
11 |
> |
#ifdef LINUX |
12 |
> |
#include <mntent.h> |
13 |
> |
#include <sys/vfs.h> |
14 |
> |
#endif |
15 |
> |
#ifdef FREEBSD |
16 |
> |
#include <sys/param.h> |
17 |
> |
#include <sys/ucred.h> |
18 |
> |
#include <sys/mount.h> |
19 |
> |
#endif |
20 |
|
typedef struct { |
21 |
|
char *device_name; |
22 |
|
char *mnt_point; |
32 |
|
struct system_disks_t *next_disk; |
33 |
|
}system_disks_t; |
34 |
|
|
35 |
< |
char *disk_stats(){ |
35 |
> |
char *get_disk_stats(){ |
36 |
|
system_disks_t *sd=NULL; |
37 |
|
system_disks_t *sd_ptr=sd; |
38 |
|
FILE *f; |
77 |
|
} |
78 |
|
|
79 |
|
#endif |
80 |
+ |
#ifdef linux |
81 |
+ |
if ((f=fopen("/etc/mtab", "r" ))==NULL){ |
82 |
+ |
errf("Failed to open mounts (%m)"); |
83 |
+ |
return NULL; |
84 |
+ |
} |
85 |
+ |
|
86 |
+ |
while((mp=getmntent(f))){ |
87 |
+ |
if ((statfs(mp->mnt_dir, &df)) !=0){ |
88 |
+ |
errf("Failed to gets fs stats (%m)"); |
89 |
+ |
continue; |
90 |
+ |
} |
91 |
+ |
|
92 |
+ |
if((((strcmp(mp->mnt_type, MNTTYPE_NFS))==0) || (strcmp(mp->mnt_type,MNTTYPE_IGNORE)) ==0)) continue; |
93 |
+ |
sd_ptr=malloc(sizeof(system_disks_t)); |
94 |
+ |
sd_ptr->disk=malloc(sizeof(disk_stat_t)); |
95 |
+ |
sd_ptr->disk->device_name=strdup(mp->mnt_fsname); |
96 |
+ |
sd_ptr->disk->mnt_point=strdup(mp->mnt_dir); |
97 |
+ |
sd_ptr->disk->size=((df.f_bsize/1024) * df.f_blocks); |
98 |
+ |
sd_ptr->disk->used=((df.f_bsize/1024) * df.f_blocks) -((df.f_bsize/1024) * df.f_bfree); |
99 |
+ |
sd_ptr->disk->avail=((df.f_bsize/1024) * df.f_bavail); |
100 |
+ |
sd_ptr->disk->t_inodes=df.f_files; |
101 |
+ |
sd_ptr->disk->f_inodes=df.f_ffree; |
102 |
+ |
sd_ptr->next_disk=sd; |
103 |
+ |
sd=sd_ptr; |
104 |
+ |
} |
105 |
+ |
#endif |
106 |
+ |
#ifdef FREEBSD |
107 |
+ |
nummnt=getmntinfo(&mp , MNT_LOCAL); |
108 |
+ |
if (nummnt<=0){ |
109 |
+ |
errf("Failed to get disk stats (%m)"); |
110 |
+ |
return NULL; |
111 |
+ |
} |
112 |
+ |
|
113 |
+ |
for(;counter<nummnt;counter++){ |
114 |
+ |
sd_ptr=malloc(sizeof(system_disks_t)); |
115 |
+ |
sd_ptr->disk=malloc(sizeof(disk_stat_t)); |
116 |
+ |
sd_ptr->disk->device_name=strdup(mp->f_mntfromname); |
117 |
+ |
sd_ptr->disk->mnt_point=strdup(mp->f_mntonname); |
118 |
+ |
sd_ptr->disk->size=((mp->f_bsize/1024) * mp->f_blocks); |
119 |
+ |
sd_ptr->disk->used=((mp->f_bsize/1024) * mp->f_blocks) -((mp->f_bsize/1024) * mp->f_bfree); |
120 |
+ |
sd_ptr->disk->avail=((mp->f_bsize/1024) * mp->f_bavail); |
121 |
+ |
sd_ptr->disk->t_inodes=mp->f_files; |
122 |
+ |
sd_ptr->disk->f_inodes=mp->f_ffree; |
123 |
+ |
sd_ptr->next_disk=sd; |
124 |
+ |
sd=sd_ptr; |
125 |
+ |
} |
126 |
+ |
#endif |
127 |
+ |
|
128 |
+ |
|
129 |
|
sd_ptr=sd; |
130 |
|
while(sd_ptr!=NULL){ |
131 |
|
printf("%s\n", sd_ptr->disk->device_name); |
135 |
|
printf("%ld\n", sd_ptr->disk->avail); |
136 |
|
|
137 |
|
sd_ptr=sd_ptr->next_disk; |
138 |
+ |
counter++; |
139 |
|
} |
140 |
|
|
141 |
|
return "jibble"; |
142 |
|
} |
143 |
|
|
144 |
|
int main(){ |
145 |
< |
printf("%s",disk_stats()); |
145 |
> |
printf("%s",get_disk_stats()); |
146 |
|
exit(0); |
147 |
|
} |
148 |
|
|