1 |
#include <stdlib.h> |
2 |
#include <stdio.h> |
3 |
#include <ukcprog.h> |
4 |
#include <strings.h> |
5 |
|
6 |
#ifdef SOLARIS |
7 |
#include <sys/mnttab.h> |
8 |
#include <sys/types.h> |
9 |
#include <sys/statvfs.h> |
10 |
#endif |
11 |
|
12 |
typedef struct { |
13 |
char *device_name; |
14 |
char *mnt_point; |
15 |
long size; |
16 |
long used; |
17 |
long avail; |
18 |
long t_inodes; |
19 |
long f_inodes; |
20 |
}disk_stat_t; |
21 |
|
22 |
typedef struct system_disks_t{ |
23 |
disk_stat_t *disk; |
24 |
struct system_disks_t *next_disk; |
25 |
}system_disks_t; |
26 |
|
27 |
char *disk_stats(){ |
28 |
system_disks_t *sd=NULL; |
29 |
system_disks_t *sd_ptr=sd; |
30 |
FILE *f; |
31 |
int counter=0; |
32 |
#ifdef SOLARIS |
33 |
struct mnttab mp; |
34 |
struct statvfs df; |
35 |
#endif |
36 |
#ifdef LINUX |
37 |
struct mntent *mp; |
38 |
struct statfs df; |
39 |
#endif |
40 |
#ifdef FREEBSD |
41 |
int nummnt; |
42 |
struct statfs *mp; |
43 |
#endif |
44 |
|
45 |
#ifdef SOLARIS |
46 |
if ((f=fopen("/etc/mnttab", "r" ))==NULL){ |
47 |
errf("Failed to open mounts (%m)"); |
48 |
return NULL; |
49 |
} |
50 |
while((getmntent(f, &mp)) == 0){ |
51 |
if ((statvfs(mp.mnt_mountp, &df)) !=0){ |
52 |
errf("Failed to gets fs stats (%m)"); |
53 |
continue; |
54 |
} |
55 |
if((((strcmp(mp.mnt_fstype,"ufs"))==0) || (strcmp(mp.mnt_fstype,"tmpfs")) ==0)){ |
56 |
sd_ptr=malloc(sizeof(system_disks_t)); |
57 |
sd_ptr->disk=malloc(sizeof(disk_stat_t)); |
58 |
sd_ptr->disk->device_name=strdup(mp.mnt_special); |
59 |
sd_ptr->disk->mnt_point=strdup(mp.mnt_mountp); |
60 |
sd_ptr->disk->size=((df.f_frsize/1024) * df.f_blocks); |
61 |
sd_ptr->disk->used=(((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree)); |
62 |
sd_ptr->disk->avail=(df.f_frsize/1024) * df.f_bavail; |
63 |
sd_ptr->disk->t_inodes=df.f_files; |
64 |
sd_ptr->disk->f_inodes=df.f_ffree; |
65 |
sd_ptr->next_disk=sd; |
66 |
sd=sd_ptr; |
67 |
} |
68 |
|
69 |
} |
70 |
|
71 |
#endif |
72 |
sd_ptr=sd; |
73 |
while(sd_ptr!=NULL){ |
74 |
printf("%s\n", sd_ptr->disk->device_name); |
75 |
printf("%s\n", sd_ptr->disk->mnt_point); |
76 |
printf("%ld\n", sd_ptr->disk->size); |
77 |
printf("%ld\n", sd_ptr->disk->used); |
78 |
printf("%ld\n", sd_ptr->disk->avail); |
79 |
|
80 |
sd_ptr=sd_ptr->next_disk; |
81 |
} |
82 |
|
83 |
return "jibble"; |
84 |
} |
85 |
|
86 |
int main(){ |
87 |
printf("%s",disk_stats()); |
88 |
exit(0); |
89 |
} |
90 |
|
91 |
|
92 |
|