ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/disk_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/disk_stats.c (file contents):
Revision 1.50 by ats, Wed Jan 21 23:46:54 2004 UTC vs.
Revision 1.51 by tdb, Thu Feb 12 23:04:52 2004 UTC

# Line 67 | Line 67
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>
# Line 360 | Line 360 | diskio_stat_t *get_diskio_stats(int *entries){
360   #endif
361   #ifdef NETBSD
362          struct disk_sysctl *stats;
363 + #endif
364 + #ifdef OPENBSD
365 +        struct diskstats *stats;
366 + #endif
367 + #ifdef NETBSD
368 + #define MIBSIZE 3
369 + #endif
370 + #ifdef OPENBSD
371 + #define MIBSIZE 2
372 + #endif
373 + #if defined(NETBSD) || defined(OPENBSD)
374          int num_disks, i;
375 <        int mib[3];
375 >        int mib[MIBSIZE];
376          size_t size;
377   #endif
378  
379          num_diskio=0;
380  
381 < #ifdef NETBSD
381 > #if defined(NETBSD) || defined(OPENBSD)
382          mib[0] = CTL_HW;
383          mib[1] = HW_DISKSTATS;
384 + #ifdef NETBSD
385          mib[2] = sizeof(struct disk_sysctl);
386 + #endif
387  
388 <        if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
388 >        if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) {
389                  return NULL;
390          }
391 +
392 + #ifdef NETBSD
393          num_disks = size / sizeof(struct disk_sysctl);
394 + #else
395 +        num_disks = size / sizeof(struct diskstats);
396 + #endif
397  
398          stats = malloc(size);
399          if (stats == NULL) {
400                  return NULL;
401          }
402  
403 <        if (sysctl(mib, 3, stats, &size, NULL, 0) < 0) {
403 >        if (sysctl(mib, MIBSIZE, stats, &size, NULL, 0) < 0) {
404                  return NULL;
405          }
406  
407          for (i = 0; i < num_disks; i++) {
408                  u_int64_t rbytes, wbytes;
409  
410 + #ifdef NETBSD
411   #ifdef HAVE_DK_RBYTES
412                  rbytes = stats[i].dk_rbytes;
413                  wbytes = stats[i].dk_wbytes;
# Line 396 | Line 415 | diskio_stat_t *get_diskio_stats(int *entries){
415                  /* Before 1.7, NetBSD merged reads and writes. */
416                  rbytes = wbytes = stats[i].dk_bytes;
417   #endif
418 + #else
419 +                rbytes = wbytes = stats[i].ds_bytes;
420 + #endif
421  
422                  /* Don't keep stats for disks that have never been used. */
423                  if (rbytes == 0 && wbytes == 0) {
# Line 415 | Line 437 | diskio_stat_t *get_diskio_stats(int *entries){
437                  if (diskio_stats_ptr->disk_name != NULL) {
438                          free(diskio_stats_ptr->disk_name);
439                  }
440 + #ifdef NETBSD
441                  diskio_stats_ptr->disk_name = strdup(stats[i].dk_name);
442 + #else
443 +                asprintf((&diskio_stats_ptr->disk_name), "%s%d", "disk", i);
444 + #endif
445                  diskio_stats_ptr->systime = time(NULL);
446          
447                  num_diskio++;  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines