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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines