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.29 by ats, Sat Oct 18 22:16:44 2003 UTC vs.
Revision 1.35 by ats, Sun Oct 19 21:06:55 2003 UTC

# Line 35 | Line 35
35   #endif
36  
37   #ifdef LINUX
38 + #include <time.h>
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 FREEBSD
49 > #ifdef ALLBSD
50   #include <sys/param.h>
51   #include <sys/ucred.h>
52   #include <sys/mount.h>
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  
69   char *copy_string(char *orig_ptr, const char *newtext){
# Line 97 | Line 112 | disk_stat_t *get_disk_stats(int *entries){
112          struct mntent *mp;
113          struct statfs fs;
114   #endif
115 < #ifdef FREEBSD
115 > #ifdef ALLBSD
116          int nummnt;
117          struct statfs *mp;
118   #endif
# Line 110 | Line 125 | disk_stat_t *get_disk_stats(int *entries){
125                  watermark=START_VAL;
126                  init_disk_stat(0, watermark-1, disk_stats);
127          }
128 < #ifdef FREEBSD
128 > #ifdef ALLBSD
129          nummnt=getmntinfo(&mp , MNT_LOCAL);
130          if (nummnt<=0){
131                  return NULL;
# Line 174 | Line 189 | disk_stat_t *get_disk_stats(int *entries){
189                          }
190  
191                          disk_ptr=disk_stats+num_disks;
192 < #ifdef FREEBSD
192 > #ifdef ALLBSD
193                          if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->f_mntfromname))==NULL){
194                                  return NULL;
195                          }
# Line 333 | Line 348 | diskio_stat_t *get_diskio_stats(int *entries){
348          long sel_gen;
349          struct devstat *dev_ptr;
350   #endif
351 + #ifdef NETBSD
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));
341                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