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