61 |
|
#include <sys/ucred.h> |
62 |
|
#include <sys/mount.h> |
63 |
|
#endif |
64 |
< |
#ifdef FREEBSD |
64 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
65 |
|
#include <sys/dkstat.h> |
66 |
|
#include <devstat.h> |
67 |
|
#define VALID_FS_TYPES {"hpfs", "msdosfs", "ntfs", "udf", "ext2fs", \ |
68 |
|
"ufs", "mfs"} |
69 |
|
#endif |
70 |
< |
#ifdef NETBSD |
70 |
> |
#if defined(NETBSD) || defined(OPENBSD) |
71 |
|
#include <sys/param.h> |
72 |
|
#include <sys/sysctl.h> |
73 |
|
#include <sys/disk.h> |
349 |
|
time_t now; |
350 |
|
const char *format; |
351 |
|
#endif |
352 |
< |
#ifdef FREEBSD |
352 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
353 |
|
static struct statinfo stats; |
354 |
|
static int stats_init = 0; |
355 |
|
int counter; |
360 |
|
#endif |
361 |
|
#ifdef NETBSD |
362 |
|
struct disk_sysctl *stats; |
363 |
+ |
#endif |
364 |
+ |
#ifdef OPENBSD |
365 |
+ |
int diskcount; |
366 |
+ |
char *disknames, *name, *bufpp; |
367 |
+ |
char **dk_name; |
368 |
+ |
struct diskstats *stats; |
369 |
+ |
#endif |
370 |
+ |
#ifdef NETBSD |
371 |
+ |
#define MIBSIZE 3 |
372 |
+ |
#endif |
373 |
+ |
#ifdef OPENBSD |
374 |
+ |
#define MIBSIZE 2 |
375 |
+ |
#endif |
376 |
+ |
#if defined(NETBSD) || defined(OPENBSD) |
377 |
|
int num_disks, i; |
378 |
< |
int mib[3]; |
378 |
> |
int mib[MIBSIZE]; |
379 |
|
size_t size; |
380 |
|
#endif |
381 |
|
|
382 |
|
num_diskio=0; |
383 |
|
|
384 |
< |
#ifdef NETBSD |
384 |
> |
#ifdef OPENBSD |
385 |
|
mib[0] = CTL_HW; |
386 |
+ |
mib[1] = HW_DISKCOUNT; |
387 |
+ |
|
388 |
+ |
size = sizeof(diskcount); |
389 |
+ |
if (sysctl(mib, MIBSIZE, &diskcount, &size, NULL, 0) < 0) { |
390 |
+ |
return NULL; |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
mib[0] = CTL_HW; |
394 |
+ |
mib[1] = HW_DISKNAMES; |
395 |
+ |
|
396 |
+ |
if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) { |
397 |
+ |
return NULL; |
398 |
+ |
} |
399 |
+ |
|
400 |
+ |
disknames = malloc(size); |
401 |
+ |
if (disknames == NULL) { |
402 |
+ |
return NULL; |
403 |
+ |
} |
404 |
+ |
|
405 |
+ |
if (sysctl(mib, MIBSIZE, disknames, &size, NULL, 0) < 0) { |
406 |
+ |
return NULL; |
407 |
+ |
} |
408 |
+ |
|
409 |
+ |
dk_name = calloc(diskcount, sizeof(char *)); |
410 |
+ |
bufpp = disknames; |
411 |
+ |
for (i = 0; i < diskcount && (name = strsep(&bufpp, ",")) != NULL; i++) { |
412 |
+ |
dk_name[i] = name; |
413 |
+ |
} |
414 |
+ |
#endif |
415 |
+ |
|
416 |
+ |
#if defined(NETBSD) || defined(OPENBSD) |
417 |
+ |
mib[0] = CTL_HW; |
418 |
|
mib[1] = HW_DISKSTATS; |
419 |
+ |
#ifdef NETBSD |
420 |
|
mib[2] = sizeof(struct disk_sysctl); |
421 |
+ |
#endif |
422 |
|
|
423 |
< |
if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) { |
423 |
> |
if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) { |
424 |
|
return NULL; |
425 |
|
} |
426 |
+ |
|
427 |
+ |
#ifdef NETBSD |
428 |
|
num_disks = size / sizeof(struct disk_sysctl); |
429 |
+ |
#else |
430 |
+ |
num_disks = size / sizeof(struct diskstats); |
431 |
+ |
#endif |
432 |
|
|
433 |
|
stats = malloc(size); |
434 |
|
if (stats == NULL) { |
435 |
|
return NULL; |
436 |
|
} |
437 |
|
|
438 |
< |
if (sysctl(mib, 3, stats, &size, NULL, 0) < 0) { |
438 |
> |
if (sysctl(mib, MIBSIZE, stats, &size, NULL, 0) < 0) { |
439 |
|
return NULL; |
440 |
|
} |
441 |
|
|
442 |
|
for (i = 0; i < num_disks; i++) { |
443 |
|
u_int64_t rbytes, wbytes; |
444 |
|
|
445 |
+ |
#ifdef NETBSD |
446 |
|
#ifdef HAVE_DK_RBYTES |
447 |
|
rbytes = stats[i].dk_rbytes; |
448 |
|
wbytes = stats[i].dk_wbytes; |
450 |
|
/* Before 1.7, NetBSD merged reads and writes. */ |
451 |
|
rbytes = wbytes = stats[i].dk_bytes; |
452 |
|
#endif |
453 |
+ |
#else |
454 |
+ |
rbytes = wbytes = stats[i].ds_bytes; |
455 |
+ |
#endif |
456 |
|
|
457 |
|
/* Don't keep stats for disks that have never been used. */ |
458 |
|
if (rbytes == 0 && wbytes == 0) { |
472 |
|
if (diskio_stats_ptr->disk_name != NULL) { |
473 |
|
free(diskio_stats_ptr->disk_name); |
474 |
|
} |
475 |
+ |
#ifdef NETBSD |
476 |
|
diskio_stats_ptr->disk_name = strdup(stats[i].dk_name); |
477 |
+ |
#else |
478 |
+ |
diskio_stats_ptr->disk_name = strdup(dk_name[i]); |
479 |
+ |
#endif |
480 |
|
diskio_stats_ptr->systime = time(NULL); |
481 |
|
|
482 |
|
num_diskio++; |
483 |
|
} |
484 |
|
|
485 |
|
free(stats); |
486 |
+ |
#ifdef OPENBSD |
487 |
+ |
free(dk_name); |
488 |
+ |
free(disknames); |
489 |
|
#endif |
490 |
+ |
#endif |
491 |
|
|
492 |
< |
#ifdef FREEBSD |
492 |
> |
#if defined(FREEBSD) || defined(DFBSD) |
493 |
|
if (!stats_init) { |
494 |
|
stats.dinfo=malloc(sizeof(struct devinfo)); |
495 |
|
if(stats.dinfo==NULL) return NULL; |