1 |
|
#include <stdlib.h> |
2 |
|
#include <stdio.h> |
3 |
< |
#include <ukcprog.h> |
3 |
> |
#include "ukcprog.h" |
4 |
|
#include <string.h> |
5 |
|
|
6 |
|
#ifdef SOLARIS |
36 |
|
system_disks_t *sd=NULL; |
37 |
|
system_disks_t *sd_ptr=sd; |
38 |
|
int counter=0; |
39 |
+ |
char *xml_disk_stats; |
40 |
|
#ifdef SOLARIS |
41 |
|
struct mnttab mp; |
42 |
|
struct statvfs df; |
63 |
|
continue; |
64 |
|
} |
65 |
|
if((((strcmp(mp.mnt_fstype,"ufs"))==0) || (strcmp(mp.mnt_fstype,"tmpfs")) ==0)){ |
66 |
< |
sd_ptr=malloc(sizeof(system_disks_t)); |
67 |
< |
sd_ptr->disk=malloc(sizeof(disk_stat_t)); |
68 |
< |
sd_ptr->disk->device_name=strdup(mp.mnt_special); |
69 |
< |
sd_ptr->disk->mnt_point=strdup(mp.mnt_mountp); |
66 |
> |
if((sd_ptr=malloc(sizeof(system_disks_t))) == NULL){ |
67 |
> |
errf("malloc failed (%m)"); |
68 |
> |
return NULL; |
69 |
> |
} |
70 |
> |
if((sd_ptr->disk=malloc(sizeof(disk_stat_t))) == NULL){ |
71 |
> |
errf("malloc failed (%m)"); |
72 |
> |
return NULL; |
73 |
> |
} |
74 |
> |
if((sd_ptr->disk->device_name=strdup(mp.mnt_special)) == NULL) { |
75 |
> |
errf("strdup failed (%m)"); |
76 |
> |
return NULL; |
77 |
> |
} |
78 |
> |
if((sd_ptr->disk->mnt_point=strdup(mp.mnt_mountp)) == NULL){ |
79 |
> |
errf("strdup failed (%m)"); |
80 |
> |
return NULL; |
81 |
> |
} |
82 |
|
sd_ptr->disk->size=((df.f_frsize/1024) * df.f_blocks); |
83 |
|
sd_ptr->disk->used=(((df.f_frsize/1024) * df.f_blocks) -((df.f_frsize/1024) * df.f_bfree)); |
84 |
|
sd_ptr->disk->avail=(df.f_frsize/1024) * df.f_bavail; |
104 |
|
} |
105 |
|
|
106 |
|
if((((strcmp(mp->mnt_type, MNTTYPE_NFS))==0) || (strcmp(mp->mnt_type,MNTTYPE_IGNORE)) ==0)) continue; |
107 |
< |
sd_ptr=malloc(sizeof(system_disks_t)); |
108 |
< |
sd_ptr->disk=malloc(sizeof(disk_stat_t)); |
109 |
< |
sd_ptr->disk->device_name=strdup(mp->mnt_fsname); |
110 |
< |
sd_ptr->disk->mnt_point=strdup(mp->mnt_dir); |
107 |
> |
if((sd_ptr=malloc(sizeof(system_disks_t))) == NULL){ |
108 |
> |
errf("malloc failed (%m)"); |
109 |
> |
return NULL; |
110 |
> |
} |
111 |
> |
if((sd_ptr->disk=malloc(sizeof(disk_stat_t))) == NULL){ |
112 |
> |
errf("malloc failed (%m)"); |
113 |
> |
return NULL; |
114 |
> |
} |
115 |
> |
if((sd_ptr->disk->device_name=strdup(mp->mnt_fsname)) == NULL){ |
116 |
> |
errf("strdup failed (%m)"); |
117 |
> |
return NULL; |
118 |
> |
} |
119 |
> |
if((sd_ptr->disk->mnt_point=strdup(mp->mnt_dir)) == NULL){ |
120 |
> |
errf("strdup failed (%m)"); |
121 |
> |
return NULL; |
122 |
> |
} |
123 |
|
sd_ptr->disk->size=((df.f_bsize/1024) * df.f_blocks); |
124 |
|
sd_ptr->disk->used=((df.f_bsize/1024) * df.f_blocks) -((df.f_bsize/1024) * df.f_bfree); |
125 |
|
sd_ptr->disk->avail=((df.f_bsize/1024) * df.f_bavail); |
136 |
|
return NULL; |
137 |
|
} |
138 |
|
|
139 |
< |
for(;counter<nummnt;counter++){ |
140 |
< |
sd_ptr=malloc(sizeof(system_disks_t)); |
141 |
< |
sd_ptr->disk=malloc(sizeof(disk_stat_t)); |
142 |
< |
sd_ptr->disk->device_name=strdup(mp->f_mntfromname); |
143 |
< |
sd_ptr->disk->mnt_point=strdup(mp->f_mntonname); |
139 |
> |
for(counter=0;counter<nummnt;counter++){ |
140 |
> |
if((sd_ptr=malloc(sizeof(system_disks_t))) == NULL){ |
141 |
> |
errf("malloc failed (%m)"); |
142 |
> |
return NULL; |
143 |
> |
} |
144 |
> |
if((sd_ptr->disk=malloc(sizeof(disk_stat_t))) == NULL){ |
145 |
> |
errf("malloc failed (%m)"); |
146 |
> |
return NULL; |
147 |
> |
} |
148 |
> |
if((sd_ptr->disk->device_name=strdup(mp->f_mntfromname))==NULL){ |
149 |
> |
errf("strdup failed (%m)"); |
150 |
> |
return NULL; |
151 |
> |
} |
152 |
> |
if((sd_ptr->disk->mnt_point=strdup(mp->f_mntonname))==NULL){ |
153 |
> |
errf("strdup failed (%m)"); |
154 |
> |
return NULL; |
155 |
> |
} |
156 |
|
sd_ptr->disk->size=((mp->f_bsize/1024) * mp->f_blocks); |
157 |
|
sd_ptr->disk->used=((mp->f_bsize/1024) * mp->f_blocks) -((mp->f_bsize/1024) * mp->f_bfree); |
158 |
|
sd_ptr->disk->avail=((mp->f_bsize/1024) * mp->f_bavail); |
166 |
|
|
167 |
|
|
168 |
|
sd_ptr=sd; |
169 |
+ |
xml_disk_stats=strdup("<disk>"); |
170 |
+ |
|
171 |
|
while(sd_ptr!=NULL){ |
172 |
< |
printf("%s\n", sd_ptr->disk->device_name); |
173 |
< |
printf("%s\n", sd_ptr->disk->mnt_point); |
174 |
< |
printf("%ld\n", sd_ptr->disk->size); |
175 |
< |
printf("%ld\n", sd_ptr->disk->used); |
137 |
< |
printf("%ld\n", sd_ptr->disk->avail); |
138 |
< |
|
172 |
> |
if((xml_disk_stats=strf("%s<p%d name=\"%s\" mount=\"%s\" kbytes=\"%ld\" used=\"%ld\" avail=\"%ld\" totalinodes=\"%ld\" freeinodes=\"%ld\"></p%d>", xml_disk_stats, counter, sd_ptr->disk->device_name, sd_ptr->disk->mnt_point, sd_ptr->disk->size, sd_ptr->disk->used, sd_ptr->disk->avail, sd_ptr->disk->t_inodes, sd_ptr->disk->f_inodes, counter)) == NULL){ |
173 |
> |
errf("strf failed (%m)"); |
174 |
> |
return NULL; |
175 |
> |
} |
176 |
|
sd_ptr=sd_ptr->next_disk; |
177 |
|
counter++; |
178 |
|
} |
179 |
|
|
180 |
< |
return "jibble"; |
180 |
> |
xml_disk_stats=strf("%s</disk>",xml_disk_stats); |
181 |
> |
|
182 |
> |
return xml_disk_stats; |
183 |
|
} |
184 |
|
|
146 |
– |
int main(){ |
147 |
– |
printf("%s",get_disk_stats()); |
148 |
– |
exit(0); |
149 |
– |
} |
150 |
– |
|
151 |
– |
|
152 |
– |
|