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.31 by ats, Sun Oct 19 02:03:02 2003 UTC vs.
Revision 1.34 by ats, Sun Oct 19 12:04:05 2003 UTC

# Line 39 | Line 39
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 ALLBSD
# Line 52 | Line 56
56   #include <sys/dkstat.h>
57   #include <devstat.h>
58   #endif
59 + #ifdef NETBSD
60 + #include <sys/param.h>
61 + #include <sys/sysctl.h>
62 + #include <sys/disk.h>
63 + #endif
64  
65   #define START_VAL 1
66  
# Line 338 | Line 347 | diskio_stat_t *get_diskio_stats(int *entries){
347          struct devstat *dev_ptr;
348   #endif
349   #ifdef NETBSD
350 <        /* FIXME get_diskio_stats NYI on NetBSD.
351 <         * See vmstat/dkstats.c in NetBSD source for examples.
352 <         */
350 >        struct disk_sysctl *stats;
351 >        int num_disks, i;
352 >        int mib[3];
353 >        size_t size;
354   #endif
355 +
356          num_diskio=0;
357  
358 + #ifdef NETBSD
359 +        mib[0] = CTL_HW;
360 +        mib[1] = HW_DISKSTATS;
361 +        mib[2] = sizeof(struct disk_sysctl);
362 +
363 +        if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) {
364 +                return NULL;
365 +        }
366 +        num_disks = size / sizeof(struct disk_sysctl);
367 +
368 +        stats = malloc(size);
369 +        if (stats == NULL) {
370 +                return NULL;
371 +        }
372 +
373 +        if (sysctl(mib, 3, stats, &size, NULL, 0) < 0) {
374 +                return NULL;
375 +        }
376 +
377 +        for (i = 0; i < num_disks; i++) {
378 +                u_int64_t rbytes, wbytes;
379 +
380 + #ifdef HAVE_DK_RBYTES
381 +                rbytes = stats[i].dk_rbytes;
382 +                wbytes = stats[i].dk_wbytes;
383 + #else
384 +                /* Before 1.6.1, NetBSD merged reads and writes. */
385 +                rbytes = wbytes = stats[i].dk_bytes;
386 + #endif
387 +
388 +                /* Don't keep stats for disks that have never been used. */
389 +                if (rbytes == 0 && wbytes == 0) {
390 +                        continue;
391 +                }
392 +
393 +                diskio_stats = diskio_stat_malloc(num_diskio + 1,
394 +                                                  &sizeof_diskio_stats,
395 +                                                  diskio_stats);
396 +                if (diskio_stats == NULL) {
397 +                        return NULL;
398 +                }
399 +                diskio_stats_ptr = diskio_stats + num_diskio;
400 +                
401 +                diskio_stats_ptr->read_bytes = rbytes;
402 +                diskio_stats_ptr->write_bytes = wbytes;
403 +                if (diskio_stats_ptr->disk_name != NULL) {
404 +                        free(diskio_stats_ptr->disk_name);
405 +                }
406 +                diskio_stats_ptr->disk_name = strdup(stats[i].dk_name);
407 +                diskio_stats_ptr->systime = time(NULL);
408 +        
409 +                num_diskio++;  
410 +        }
411 +
412 +        free(stats);
413 + #endif
414 +
415   #ifdef FREEBSD
416          if (!stats_init) {
417                  stats.dinfo=malloc(sizeof(struct devinfo));
350                bzero(stats.dinfo, sizeof(struct devinfo));
418                  if(stats.dinfo==NULL) return NULL;
419 +                bzero(stats.dinfo, sizeof(struct devinfo));
420                  stats_init = 1;
421          }
422   #ifdef FREEBSD5

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines