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 |
+ |
#define VALID_FS_TYPES {"ufs", "mfs", "ffs"} |
54 |
+ |
#endif |
55 |
+ |
#ifdef FREEBSD |
56 |
|
#include <sys/dkstat.h> |
57 |
|
#include <devstat.h> |
50 |
– |
#define VALID_FS_TYPES {"ufs", "mfs"} |
58 |
|
#endif |
59 |
+ |
|
60 |
|
#define START_VAL 1 |
61 |
|
|
62 |
|
char *copy_string(char *orig_ptr, const char *newtext){ |
105 |
|
struct mntent *mp; |
106 |
|
struct statfs fs; |
107 |
|
#endif |
108 |
< |
#ifdef FREEBSD |
108 |
> |
#ifdef ALLBSD |
109 |
|
int nummnt; |
110 |
|
struct statfs *mp; |
111 |
|
#endif |
118 |
|
watermark=START_VAL; |
119 |
|
init_disk_stat(0, watermark-1, disk_stats); |
120 |
|
} |
121 |
< |
#ifdef FREEBSD |
121 |
> |
#ifdef ALLBSD |
122 |
|
nummnt=getmntinfo(&mp , MNT_LOCAL); |
123 |
|
if (nummnt<=0){ |
124 |
|
return NULL; |
182 |
|
} |
183 |
|
|
184 |
|
disk_ptr=disk_stats+num_disks; |
185 |
< |
#ifdef FREEBSD |
185 |
> |
#ifdef ALLBSD |
186 |
|
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->f_mntfromname))==NULL){ |
187 |
|
return NULL; |
188 |
|
} |
333 |
|
time_t now; |
334 |
|
#endif |
335 |
|
#ifdef FREEBSD |
336 |
< |
struct statinfo stats; |
336 |
> |
static struct statinfo stats; |
337 |
> |
static int stats_init = 0; |
338 |
|
int counter; |
339 |
|
struct device_selection *dev_sel = NULL; |
340 |
|
int n_selected, n_selections; |
341 |
|
long sel_gen; |
342 |
|
struct devstat *dev_ptr; |
343 |
|
#endif |
344 |
+ |
#ifdef NETBSD |
345 |
+ |
/* FIXME get_diskio_stats NYI on NetBSD. |
346 |
+ |
* See vmstat/dkstats.c in NetBSD source for examples. |
347 |
+ |
*/ |
348 |
+ |
#endif |
349 |
|
num_diskio=0; |
350 |
|
|
351 |
|
#ifdef FREEBSD |
352 |
< |
stats.dinfo=malloc(sizeof(struct devinfo)); |
353 |
< |
if(stats.dinfo==NULL) return NULL; |
352 |
> |
if (!stats_init) { |
353 |
> |
stats.dinfo=malloc(sizeof(struct devinfo)); |
354 |
> |
if(stats.dinfo==NULL) return NULL; |
355 |
> |
bzero(stats.dinfo, sizeof(struct devinfo)); |
356 |
> |
stats_init = 1; |
357 |
> |
} |
358 |
> |
#ifdef FREEBSD5 |
359 |
> |
if ((devstat_getdevs(NULL, &stats)) < 0) return NULL; |
360 |
> |
/* Not aware of a get all devices, so i said 999. If we ever |
361 |
> |
* find a machine with more than 999 disks, then i'll change |
362 |
> |
* this number :) |
363 |
> |
*/ |
364 |
> |
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; |
365 |
> |
#else |
366 |
|
if ((getdevs(&stats)) < 0) return NULL; |
367 |
|
/* Not aware of a get all devices, so i said 999. If we ever |
368 |
|
* find a machine with more than 999 disks, then i'll change |
369 |
|
* this number :) |
370 |
|
*/ |
371 |
|
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; |
372 |
+ |
#endif |
373 |
|
|
374 |
|
for(counter=0;counter<stats.dinfo->numdevs;counter++){ |
375 |
|
dev_ptr=&stats.dinfo->devices[dev_sel[counter].position]; |
378 |
|
* devices.. like mem, proc.. and also doesn't report floppy |
379 |
|
* drives etc unless they are doing stuff :) |
380 |
|
*/ |
381 |
+ |
#ifdef FREEBSD5 |
382 |
+ |
if((dev_ptr->bytes[DEVSTAT_READ]==0) && (dev_ptr->bytes[DEVSTAT_WRITE]==0)) continue; |
383 |
+ |
#else |
384 |
|
if((dev_ptr->bytes_read==0) && (dev_ptr->bytes_written==0)) continue; |
385 |
+ |
#endif |
386 |
|
if((diskio_stats=diskio_stat_malloc(num_diskio+1, &sizeof_diskio_stats, diskio_stats))==NULL){ |
387 |
|
return NULL; |
388 |
|
} |
389 |
|
diskio_stats_ptr=diskio_stats+num_diskio; |
390 |
< |
|
390 |
> |
|
391 |
> |
#ifdef FREEBSD5 |
392 |
> |
diskio_stats_ptr->read_bytes=dev_ptr->bytes[DEVSTAT_READ]; |
393 |
> |
diskio_stats_ptr->write_bytes=dev_ptr->bytes[DEVSTAT_WRITE]; |
394 |
> |
#else |
395 |
|
diskio_stats_ptr->read_bytes=dev_ptr->bytes_read; |
396 |
|
diskio_stats_ptr->write_bytes=dev_ptr->bytes_written; |
397 |
+ |
#endif |
398 |
|
if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name); |
399 |
|
asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number); |
400 |
|
diskio_stats_ptr->systime=time(NULL); |
402 |
|
num_diskio++; |
403 |
|
} |
404 |
|
free(dev_sel); |
369 |
– |
free(stats.dinfo); |
405 |
|
|
406 |
|
#endif |
407 |
|
#ifdef SOLARIS |