37 |
|
#include <sys/mnttab.h> |
38 |
|
#include <sys/statvfs.h> |
39 |
|
#include <kstat.h> |
40 |
< |
#define VALID_FS_TYPES {"ufs", "tmpfs", "vxfs"} |
40 |
> |
#define VALID_FS_TYPES {"ufs", "tmpfs", "vxfs", "nfs"} |
41 |
|
#endif |
42 |
|
|
43 |
|
#if defined(LINUX) || defined(CYGWIN) |
87 |
|
#include <dirent.h> |
88 |
|
#include <stdio.h> |
89 |
|
#include <time.h> |
90 |
< |
#define VALID_FS_TYPES {"vxfs", "hfs"} |
90 |
> |
#define VALID_FS_TYPES {"vxfs", "hfs", "nfs"} |
91 |
|
#define DISK_BATCH 30 |
92 |
|
#endif |
93 |
|
|
94 |
+ |
#ifdef WIN32 |
95 |
+ |
#include "win32.h" |
96 |
+ |
/*#define VALID_FS_TYPES {"NTFS", "FAT", "FAT32"} unused*/ |
97 |
+ |
#define BUFSIZE 512 |
98 |
+ |
#endif |
99 |
+ |
|
100 |
|
#ifdef ALLBSD |
101 |
|
#define SG_MP_FSTYPENAME(mp) (mp)->f_fstypename |
102 |
|
#define SG_MP_DEVNAME(mp) (mp)->f_mntfromname |
149 |
|
free(d->mnt_point); |
150 |
|
} |
151 |
|
|
152 |
+ |
#ifndef WIN32 /* not used by WIN32, so stop compiler throwing warnings */ |
153 |
|
static int is_valid_fs_type(const char *type) { |
154 |
|
const char *types[] = VALID_FS_TYPES; |
155 |
|
int i; |
161 |
|
} |
162 |
|
return 0; |
163 |
|
} |
164 |
+ |
#endif |
165 |
|
|
166 |
|
sg_fs_stats *sg_get_fs_stats(int *entries){ |
167 |
|
VECTOR_DECLARE_STATIC(disk_stats, sg_fs_stats, 10, |
190 |
|
struct statfs *mp, **fs; |
191 |
|
#endif |
192 |
|
#endif |
193 |
+ |
#ifdef WIN32 |
194 |
+ |
char lp_buf[MAX_PATH]; |
195 |
+ |
char volume_name_buf[BUFSIZE]; |
196 |
+ |
char filesys_name_buf[BUFSIZE]; |
197 |
+ |
char drive[4] = " :\\"; |
198 |
+ |
char *p; |
199 |
+ |
lp_buf[0]='\0'; |
200 |
+ |
#endif |
201 |
|
|
202 |
|
#ifdef ALLBSD |
203 |
|
nummnt=getmntinfo(&mp, MNT_WAIT); |
236 |
|
} |
237 |
|
#endif |
238 |
|
|
239 |
+ |
#ifdef WIN32 |
240 |
+ |
if (!(GetLogicalDriveStrings(BUFSIZE-1, lp_buf))) { |
241 |
+ |
sg_set_error(SG_ERROR_GETMNTINFO, "GetLogicalDriveStrings"); |
242 |
+ |
return NULL; |
243 |
+ |
} |
244 |
+ |
p = lp_buf; |
245 |
+ |
do { |
246 |
+ |
// Copy drive letter to template string |
247 |
+ |
*drive = *p; |
248 |
+ |
// Only interested in harddrives. |
249 |
+ |
int drive_type = GetDriveType(drive); |
250 |
+ |
|
251 |
+ |
if(drive_type == DRIVE_FIXED) { |
252 |
+ |
#else |
253 |
|
if(is_valid_fs_type(SG_MP_FSTYPENAME(mp))){ |
254 |
+ |
#endif |
255 |
|
if (VECTOR_RESIZE(disk_stats, num_disks + 1) < 0) { |
256 |
|
return NULL; |
257 |
|
} |
258 |
|
disk_ptr=disk_stats+num_disks; |
259 |
|
|
260 |
+ |
#ifndef WIN32 |
261 |
|
/* Maybe make this char[bigenough] and do strncpy's and put a null in the end? |
262 |
|
* Downside is its a bit hungry for a lot of mounts, as MNT_MAX_SIZE would prob |
263 |
|
* be upwards of a k each |
275 |
|
disk_ptr->size = SG_FS_FRSIZE(fs) * SG_FS_BLOCKS(fs); |
276 |
|
disk_ptr->avail = SG_FS_FRSIZE(fs) * SG_FS_BAVAIL(fs); |
277 |
|
disk_ptr->used = (disk_ptr->size) - (SG_FS_FRSIZE(fs) * SG_FS_BFREE(fs)); |
278 |
< |
|
278 |
> |
|
279 |
|
disk_ptr->total_inodes = SG_FS_FILES(fs); |
280 |
|
disk_ptr->free_inodes = SG_FS_FFREE(fs); |
281 |
|
/* Linux, FreeBSD don't have a "available" inodes */ |
288 |
|
disk_ptr->free_blocks = SG_FS_BFREE(fs); |
289 |
|
disk_ptr->avail_blocks = SG_FS_BAVAIL(fs); |
290 |
|
disk_ptr->used_blocks = disk_ptr->total_blocks - disk_ptr->free_blocks; |
291 |
+ |
#else |
292 |
+ |
if(!GetVolumeInformation(drive, volume_name_buf, BUFSIZE, |
293 |
+ |
NULL, NULL, NULL, |
294 |
+ |
filesys_name_buf, BUFSIZE)) { |
295 |
+ |
sg_set_error_with_errno(SG_ERROR_DISKINFO, |
296 |
+ |
"GetVolumeInformation"); |
297 |
+ |
return NULL; |
298 |
+ |
} |
299 |
|
|
300 |
+ |
if (sg_update_string(&disk_ptr->device_name, |
301 |
+ |
volume_name_buf) < 0) { |
302 |
+ |
return NULL; |
303 |
+ |
} |
304 |
+ |
if (sg_update_string(&disk_ptr->fs_type, |
305 |
+ |
filesys_name_buf) < 0) { |
306 |
+ |
return NULL; |
307 |
+ |
} |
308 |
+ |
if (sg_update_string(&disk_ptr->mnt_point, |
309 |
+ |
drive) < 0) { |
310 |
+ |
return NULL; |
311 |
+ |
} |
312 |
+ |
if (!GetDiskFreeSpaceEx(drive, NULL, |
313 |
+ |
(PULARGE_INTEGER)&disk_ptr->size, |
314 |
+ |
(PULARGE_INTEGER)&disk_ptr->avail)) { |
315 |
+ |
sg_set_error_with_errno(SG_ERROR_DISKINFO, |
316 |
+ |
"GetDiskFreeSpaceEx"); |
317 |
+ |
return NULL; |
318 |
+ |
} |
319 |
+ |
disk_ptr->used = disk_ptr->size - disk_ptr->avail; |
320 |
+ |
disk_ptr->total_inodes = 0; |
321 |
+ |
disk_ptr->free_inodes = 0; |
322 |
+ |
disk_ptr->used_inodes = 0; |
323 |
+ |
disk_ptr->avail_inodes = 0; |
324 |
+ |
|
325 |
+ |
/* I dunno what to do with these... so have nothing */ |
326 |
+ |
disk_ptr->io_size = 0; |
327 |
+ |
disk_ptr->block_size = 0; |
328 |
+ |
disk_ptr->total_blocks = 0; |
329 |
+ |
disk_ptr->free_blocks = 0; |
330 |
+ |
disk_ptr->avail_blocks = 0; |
331 |
+ |
disk_ptr->used_blocks = 0; |
332 |
+ |
#endif |
333 |
|
num_disks++; |
334 |
|
} |
335 |
+ |
#ifdef WIN32 |
336 |
+ |
while(*p++); |
337 |
+ |
} while(*p); |
338 |
+ |
#else |
339 |
|
} |
340 |
+ |
#endif |
341 |
|
|
342 |
|
*entries=num_disks; |
343 |
|
|
449 |
|
int mib[MIBSIZE]; |
450 |
|
size_t size; |
451 |
|
#endif |
452 |
+ |
#ifdef WIN32 |
453 |
+ |
char *name; |
454 |
+ |
long long rbytes; |
455 |
+ |
long long wbytes; |
456 |
+ |
#endif |
457 |
|
|
458 |
|
num_diskio=0; |
459 |
|
|
851 |
|
f = fopen("/proc/stat", "r"); |
852 |
|
if (f == NULL) goto out; |
853 |
|
now = time(NULL); |
854 |
< |
|
854 |
> |
|
855 |
|
line_ptr = sg_f_read_line(f, "disk_io:"); |
856 |
|
if (line_ptr == NULL) goto out; |
857 |
< |
|
857 |
> |
|
858 |
|
while((line_ptr=strchr(line_ptr, ' '))!=NULL){ |
859 |
|
long long rsect, wsect; |
860 |
|
|
861 |
|
if (*++line_ptr == '\0') break; |
862 |
< |
|
862 |
> |
|
863 |
|
if((sscanf(line_ptr, |
864 |
|
"(%d,%d):(%*d, %*d, %lld, %*d, %lld)", |
865 |
|
&major, &minor, &rsect, &wsect)) != 4) { |
920 |
|
return NULL; |
921 |
|
#endif |
922 |
|
|
923 |
+ |
#ifdef WIN32 |
924 |
+ |
sg_set_error(SG_ERROR_NONE, NULL); |
925 |
+ |
|
926 |
+ |
while((name = get_diskio(num_diskio, &rbytes, &wbytes)) != NULL) { |
927 |
+ |
if (VECTOR_RESIZE(diskio_stats, num_diskio+1)) { |
928 |
+ |
return NULL; |
929 |
+ |
} |
930 |
+ |
|
931 |
+ |
diskio_stats_ptr = diskio_stats + num_diskio; |
932 |
+ |
|
933 |
+ |
if (sg_update_string(&diskio_stats_ptr->disk_name, name) < 0) { |
934 |
+ |
return NULL; |
935 |
+ |
} |
936 |
+ |
sg_update_string(&name, NULL); |
937 |
+ |
diskio_stats_ptr->read_bytes = rbytes; |
938 |
+ |
diskio_stats_ptr->write_bytes = wbytes; |
939 |
+ |
|
940 |
+ |
diskio_stats_ptr->systime = 0; |
941 |
+ |
|
942 |
+ |
num_diskio++; |
943 |
+ |
} |
944 |
+ |
#endif |
945 |
+ |
|
946 |
|
*entries=num_diskio; |
947 |
|
|
948 |
|
return diskio_stats; |
949 |
|
} |
950 |
|
|
951 |
|
sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entries){ |
952 |
+ |
#ifndef WIN32 |
953 |
|
VECTOR_DECLARE_STATIC(diff, sg_disk_io_stats, 1, |
954 |
|
diskio_stat_init, diskio_stat_destroy); |
955 |
|
sg_disk_io_stats *src = NULL, *dest; |
1011 |
|
|
1012 |
|
*entries = diff_count; |
1013 |
|
return diff; |
1014 |
+ |
#else /* WIN32 */ |
1015 |
+ |
return sg_get_disk_io_stats(entries); |
1016 |
+ |
#endif |
1017 |
|
} |
1018 |
|
|
1019 |
|
int sg_disk_io_compare_name(const void *va, const void *vb) { |