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.28 by pajs, Thu Oct 9 15:22:59 2003 UTC vs.
Revision 1.34 by ats, Sun Oct 19 12:04:05 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 + #define VALID_FS_TYPES {"ufs", "mfs", "ffs"}
54 + #endif
55 + #ifdef FREEBSD
56   #include <sys/dkstat.h>
57   #include <devstat.h>
50 #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 + #endif
64 +
65   #define START_VAL 1
66  
67   char *copy_string(char *orig_ptr, const char *newtext){
# Line 97 | Line 110 | disk_stat_t *get_disk_stats(int *entries){
110          struct mntent *mp;
111          struct statfs fs;
112   #endif
113 < #ifdef FREEBSD
113 > #ifdef ALLBSD
114          int nummnt;
115          struct statfs *mp;
116   #endif
# Line 110 | Line 123 | disk_stat_t *get_disk_stats(int *entries){
123                  watermark=START_VAL;
124                  init_disk_stat(0, watermark-1, disk_stats);
125          }
126 < #ifdef FREEBSD
126 > #ifdef ALLBSD
127          nummnt=getmntinfo(&mp , MNT_LOCAL);
128          if (nummnt<=0){
129                  return NULL;
# Line 174 | Line 187 | disk_stat_t *get_disk_stats(int *entries){
187                          }
188  
189                          disk_ptr=disk_stats+num_disks;
190 < #ifdef FREEBSD
190 > #ifdef ALLBSD
191                          if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->f_mntfromname))==NULL){
192                                  return NULL;
193                          }
# Line 333 | Line 346 | diskio_stat_t *get_diskio_stats(int *entries){
346          long sel_gen;
347          struct devstat *dev_ptr;
348   #endif
349 + #ifdef NETBSD
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));
341                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
423          if ((devstat_getdevs(NULL, &stats)) < 0) return NULL;
424 <        /* Not aware of a get all devices, so i said 999. If we ever                                                                           * find a machine with more than 999 disks, then i'll change                                                                           * this number :)                                                                                                                      */
424 >        /* Not aware of a get all devices, so i said 999. If we ever
425 >         * find a machine with more than 999 disks, then i'll change
426 >         * this number :)
427 >         */
428          if (devstat_selectdevs(&dev_sel, &n_selected, &n_selections, &sel_gen, stats.dinfo->generation, stats.dinfo->devices, stats.dinfo->numdevs, NULL, 0, NULL, 0, DS_SELECT_ONLY, 999, 1) < 0) return NULL;
429   #else
430          if ((getdevs(&stats)) < 0) return NULL;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines