35 |
|
#endif |
36 |
|
|
37 |
|
#ifdef LINUX |
38 |
+ |
#include <time.h> |
39 |
|
#include <sys/vfs.h> |
40 |
|
#include <mntent.h> |
41 |
|
#include "tools.h" |
42 |
< |
#define VALID_FS_TYPES {"ext2", "ext3", "xfs", "reiserfs", "vfat", "tmpfs"} |
42 |
> |
#define VALID_FS_TYPES {"adfs", "affs", "befs", "bfs", "efs", "ext2", \ |
43 |
> |
"ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \ |
44 |
> |
"jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \ |
45 |
> |
"rootfs", "reiserfs", "sysv", "v7", "udf", "ufs", \ |
46 |
> |
"umsdos", "vfat", "xfs", "jfs"} |
47 |
|
#endif |
48 |
|
|
49 |
< |
#ifdef FREEBSD |
49 |
> |
#ifdef ALLBSD |
50 |
|
#include <sys/param.h> |
51 |
|
#include <sys/ucred.h> |
52 |
|
#include <sys/mount.h> |
53 |
+ |
#endif |
54 |
+ |
#ifdef FREEBSD |
55 |
|
#include <sys/dkstat.h> |
56 |
|
#include <devstat.h> |
57 |
|
#define VALID_FS_TYPES {"ufs", "mfs"} |
58 |
|
#endif |
59 |
+ |
#ifdef NETBSD |
60 |
+ |
#include <sys/param.h> |
61 |
+ |
#include <sys/sysctl.h> |
62 |
+ |
#include <sys/disk.h> |
63 |
+ |
#define VALID_FS_TYPES {"ffs", "mfs", "msdos", "lfs", "adosfs", "ext2fs", \ |
64 |
+ |
"ntfs"} |
65 |
+ |
#endif |
66 |
+ |
|
67 |
|
#define START_VAL 1 |
68 |
|
|
69 |
|
char *copy_string(char *orig_ptr, const char *newtext){ |
112 |
|
struct mntent *mp; |
113 |
|
struct statfs fs; |
114 |
|
#endif |
115 |
< |
#ifdef FREEBSD |
115 |
> |
#ifdef ALLBSD |
116 |
|
int nummnt; |
117 |
|
struct statfs *mp; |
118 |
|
#endif |
125 |
|
watermark=START_VAL; |
126 |
|
init_disk_stat(0, watermark-1, disk_stats); |
127 |
|
} |
128 |
< |
#ifdef FREEBSD |
128 |
> |
#ifdef ALLBSD |
129 |
|
nummnt=getmntinfo(&mp , MNT_LOCAL); |
130 |
|
if (nummnt<=0){ |
131 |
|
return NULL; |
189 |
|
} |
190 |
|
|
191 |
|
disk_ptr=disk_stats+num_disks; |
192 |
< |
#ifdef FREEBSD |
192 |
> |
#ifdef ALLBSD |
193 |
|
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->f_mntfromname))==NULL){ |
194 |
|
return NULL; |
195 |
|
} |
348 |
|
long sel_gen; |
349 |
|
struct devstat *dev_ptr; |
350 |
|
#endif |
351 |
+ |
#ifdef NETBSD |
352 |
+ |
struct disk_sysctl *stats; |
353 |
+ |
int num_disks, i; |
354 |
+ |
int mib[3]; |
355 |
+ |
size_t size; |
356 |
+ |
#endif |
357 |
+ |
|
358 |
|
num_diskio=0; |
359 |
|
|
360 |
+ |
#ifdef NETBSD |
361 |
+ |
mib[0] = CTL_HW; |
362 |
+ |
mib[1] = HW_DISKSTATS; |
363 |
+ |
mib[2] = sizeof(struct disk_sysctl); |
364 |
+ |
|
365 |
+ |
if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) { |
366 |
+ |
return NULL; |
367 |
+ |
} |
368 |
+ |
num_disks = size / sizeof(struct disk_sysctl); |
369 |
+ |
|
370 |
+ |
stats = malloc(size); |
371 |
+ |
if (stats == NULL) { |
372 |
+ |
return NULL; |
373 |
+ |
} |
374 |
+ |
|
375 |
+ |
if (sysctl(mib, 3, stats, &size, NULL, 0) < 0) { |
376 |
+ |
return NULL; |
377 |
+ |
} |
378 |
+ |
|
379 |
+ |
for (i = 0; i < num_disks; i++) { |
380 |
+ |
u_int64_t rbytes, wbytes; |
381 |
+ |
|
382 |
+ |
#ifdef HAVE_DK_RBYTES |
383 |
+ |
rbytes = stats[i].dk_rbytes; |
384 |
+ |
wbytes = stats[i].dk_wbytes; |
385 |
+ |
#else |
386 |
+ |
/* Before 1.6.1, NetBSD merged reads and writes. */ |
387 |
+ |
rbytes = wbytes = stats[i].dk_bytes; |
388 |
+ |
#endif |
389 |
+ |
|
390 |
+ |
/* Don't keep stats for disks that have never been used. */ |
391 |
+ |
if (rbytes == 0 && wbytes == 0) { |
392 |
+ |
continue; |
393 |
+ |
} |
394 |
+ |
|
395 |
+ |
diskio_stats = diskio_stat_malloc(num_diskio + 1, |
396 |
+ |
&sizeof_diskio_stats, |
397 |
+ |
diskio_stats); |
398 |
+ |
if (diskio_stats == NULL) { |
399 |
+ |
return NULL; |
400 |
+ |
} |
401 |
+ |
diskio_stats_ptr = diskio_stats + num_diskio; |
402 |
+ |
|
403 |
+ |
diskio_stats_ptr->read_bytes = rbytes; |
404 |
+ |
diskio_stats_ptr->write_bytes = wbytes; |
405 |
+ |
if (diskio_stats_ptr->disk_name != NULL) { |
406 |
+ |
free(diskio_stats_ptr->disk_name); |
407 |
+ |
} |
408 |
+ |
diskio_stats_ptr->disk_name = strdup(stats[i].dk_name); |
409 |
+ |
diskio_stats_ptr->systime = time(NULL); |
410 |
+ |
|
411 |
+ |
num_diskio++; |
412 |
+ |
} |
413 |
+ |
|
414 |
+ |
free(stats); |
415 |
+ |
#endif |
416 |
+ |
|
417 |
|
#ifdef FREEBSD |
418 |
|
if (!stats_init) { |
419 |
|
stats.dinfo=malloc(sizeof(struct devinfo)); |
420 |
|
if(stats.dinfo==NULL) return NULL; |
421 |
+ |
bzero(stats.dinfo, sizeof(struct devinfo)); |
422 |
|
stats_init = 1; |
423 |
|
} |
424 |
+ |
#ifdef FREEBSD5 |
425 |
+ |
if ((devstat_getdevs(NULL, &stats)) < 0) return NULL; |
426 |
+ |
/* Not aware of a get all devices, so i said 999. If we ever |
427 |
+ |
* find a machine with more than 999 disks, then i'll change |
428 |
+ |
* this number :) |
429 |
+ |
*/ |
430 |
+ |
if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL; |
431 |
+ |
#else |
432 |
|
if ((getdevs(&stats)) < 0) return NULL; |
433 |
|
/* Not aware of a get all devices, so i said 999. If we ever |
434 |
|
* find a machine with more than 999 disks, then i'll change |
435 |
|
* this number :) |
436 |
|
*/ |
437 |
|
if (selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL; |
438 |
+ |
#endif |
439 |
|
|
440 |
|
for(counter=0;counter<stats.dinfo->numdevs;counter++){ |
441 |
|
dev_ptr=&stats.dinfo->devices[dev_sel[counter].position]; |
444 |
|
* devices.. like mem, proc.. and also doesn't report floppy |
445 |
|
* drives etc unless they are doing stuff :) |
446 |
|
*/ |
447 |
+ |
#ifdef FREEBSD5 |
448 |
+ |
if((dev_ptr->bytes[DEVSTAT_READ]==0) && (dev_ptr->bytes[DEVSTAT_WRITE]==0)) continue; |
449 |
+ |
#else |
450 |
|
if((dev_ptr->bytes_read==0) && (dev_ptr->bytes_written==0)) continue; |
451 |
+ |
#endif |
452 |
|
if((diskio_stats=diskio_stat_malloc(num_diskio+1, &sizeof_diskio_stats, diskio_stats))==NULL){ |
453 |
|
return NULL; |
454 |
|
} |
455 |
|
diskio_stats_ptr=diskio_stats+num_diskio; |
456 |
< |
|
456 |
> |
|
457 |
> |
#ifdef FREEBSD5 |
458 |
> |
diskio_stats_ptr->read_bytes=dev_ptr->bytes[DEVSTAT_READ]; |
459 |
> |
diskio_stats_ptr->write_bytes=dev_ptr->bytes[DEVSTAT_WRITE]; |
460 |
> |
#else |
461 |
|
diskio_stats_ptr->read_bytes=dev_ptr->bytes_read; |
462 |
|
diskio_stats_ptr->write_bytes=dev_ptr->bytes_written; |
463 |
+ |
#endif |
464 |
|
if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name); |
465 |
|
asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number); |
466 |
|
diskio_stats_ptr->systime=time(NULL); |
468 |
|
num_diskio++; |
469 |
|
} |
470 |
|
free(dev_sel); |
373 |
– |
free(stats.dinfo); |
471 |
|
|
472 |
|
#endif |
473 |
|
#ifdef SOLARIS |