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.51 by tdb, Thu Feb 12 23:04:52 2004 UTC vs.
Revision 1.54 by ats, Fri Mar 19 23:44:30 2004 UTC

# Line 61 | Line 61
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", \
# Line 349 | Line 349 | diskio_stat_t *get_diskio_stats(int *entries){
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;
# Line 362 | Line 362 | diskio_stat_t *get_diskio_stats(int *entries){
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
# Line 378 | Line 381 | diskio_stat_t *get_diskio_stats(int *entries){
381  
382          num_diskio=0;
383  
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;
# Line 440 | Line 475 | diskio_stat_t *get_diskio_stats(int *entries){
475   #ifdef NETBSD
476                  diskio_stats_ptr->disk_name = strdup(stats[i].dk_name);
477   #else
478 <                asprintf((&diskio_stats_ptr->disk_name), "%s%d", "disk", i);
478 >                diskio_stats_ptr->disk_name = strdup(dk_name[i]);
479   #endif
480                  diskio_stats_ptr->systime = time(NULL);
481          
# Line 448 | Line 483 | diskio_stat_t *get_diskio_stats(int *entries){
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;
# Line 551 | Line 590 | diskio_stat_t *get_diskio_stats(int *entries){
590             the same format. */
591  
592          f = fopen("/proc/diskstats", "r");
593 <        format = " %d %d %19s %*d %*d %lld %*d %*d %*d %lld";
593 >        format = " %d %d %99s %*d %*d %lld %*d %*d %*d %lld";
594          if (f == NULL) {
595                  f = fopen("/proc/partitions", "r");
596 <                format = " %d %d %*d %19s %*d %*d %lld %*d %*d %*d %lld";
596 >                format = " %d %d %*d %99s %*d %*d %lld %*d %*d %*d %lld";
597          }
598          if (f == NULL) goto out;
599          now = time(NULL);
600  
601          while ((line_ptr = f_read_line(f, "")) != NULL) {
602 <                char name[20];
602 >                char name[100];
603                  char *s;
604                  long long rsect, wsect;
605  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines