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.72 by ats, Sun Jul 18 21:30:11 2004 UTC vs.
Revision 1.73 by tdb, Mon Nov 1 18:30:17 2004 UTC

# Line 76 | Line 76
76                          "ntfs"}
77   #endif
78  
79 + #ifdef HPUX
80 + #include <sys/param.h>
81 + #include <sys/pstat.h>
82 + #include <sys/types.h>
83 + #include <sys/stat.h>
84 + #include <sys/vfs.h>
85 + #include <mntent.h>
86 + #include <dirent.h>
87 + #include <stdio.h>
88 + #include <time.h>
89 + #define VALID_FS_TYPES {"vxfs", "hfs"}
90 + #endif
91 +
92   static void disk_stat_init(sg_fs_stats *d) {
93          d->device_name = NULL;
94          d->fs_type = NULL;
# Line 106 | Line 119 | sg_fs_stats *sg_get_fs_stats(int *entries){
119  
120          int valid_type;
121          int num_disks=0;
122 < #if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN)
122 > #if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN) || defined(HPUX)
123          FILE *f;
124   #endif
125  
# Line 116 | Line 129 | sg_fs_stats *sg_get_fs_stats(int *entries){
129          struct mnttab mp;
130          struct statvfs fs;
131   #endif
132 < #if defined(LINUX) || defined(CYGWIN)
132 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
133          struct mntent *mp;
134          struct statfs fs;
135   #endif
# Line 139 | Line 152 | sg_fs_stats *sg_get_fs_stats(int *entries){
152                  valid_type = is_valid_fs_type(mp->f_fstypename);
153   #endif
154  
155 < #if defined(LINUX) || defined(CYGWIN)
155 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
156 > #ifdef MNT_MNTTAB
157 >        if ((f=setmntent(MNT_MNTTAB, "r" ))==NULL){
158 > #else
159          if ((f=setmntent("/etc/mtab", "r" ))==NULL){
160 + #endif
161                  sg_set_error(SG_ERROR_SETMNTENT, NULL);
162                  return NULL;
163          }
# Line 191 | Line 208 | sg_fs_stats *sg_get_fs_stats(int *entries){
208                          /* Freebsd doesn't have a "available" inodes */
209                          disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes;
210   #endif
211 < #if defined(LINUX) || defined(CYGWIN)
211 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
212                          if (sg_update_string(&disk_ptr->device_name, mp->mnt_fsname) < 0) {
213                                  return NULL;
214                          }
# Line 246 | Line 263 | sg_fs_stats *sg_get_fs_stats(int *entries){
263  
264          /* If this fails, there is very little i can do about it, so
265             I'll ignore it :) */
266 < #if defined(LINUX) || defined(CYGWIN)
266 > #if defined(LINUX) || defined(CYGWIN) || defined(HPUX)
267          endmntent(f);
268   #endif
269   #if defined(SOLARIS)
# Line 295 | Line 312 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
312          sg_disk_io_stats *diskio_stats_ptr;
313   #endif
314  
315 + #ifdef HPUX
316 +        long long rbytes = 0, wbytes = 0;
317 +        struct dirent *dinfo = NULL;
318 +        struct stat lstatinfo;
319 +        struct pst_diskinfo pstat_diskinfo;
320 +        char fullpathbuf[1024] = {0};
321 +        dev_t diskid;
322 +        DIR *dh = NULL;
323 +        int disknum = 0;
324 + #endif
325   #ifdef SOLARIS
326          kstat_ctl_t *kc;
327          kstat_t *ksp;
# Line 342 | Line 369 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
369  
370          num_diskio=0;
371  
372 + #ifdef HPUX
373 +
374 +        /* The "128" here is arbitrary, it can be increased to any number
375 +           at the expense of only more system calls to pstat(). */
376 +        for (disknum = 0; disknum < 128; disknum++) {
377 +                if (pstat_getdisk(&pstat_diskinfo, sizeof(pstat_diskinfo), 1, disknum) == -1) {
378 +                        break;
379 +                }
380 +
381 +                if (pstat_diskinfo.psd_idx != disknum) {
382 +                        continue;
383 +                }
384 +
385 +                /* Skip "disabled" disks.. */
386 +                if (pstat_diskinfo.psd_status == 0) {
387 +                        continue;
388 +                }
389 +
390 +                /* We can't seperate the reads from the writes, we'll
391 +                   just give half to each. */
392 +                rbytes = wbytes = (pstat_diskinfo.psd_dkwds * 64);
393 +
394 +                /* Skip unused disks. */
395 +                if (rbytes == 0 && wbytes == 0) {
396 +                        continue;
397 +                }
398 +
399 +                if (VECTOR_RESIZE(diskio_stats, num_diskio + 1) < 0) {
400 +                        return NULL;
401 +                }
402 +
403 +                diskio_stats_ptr = diskio_stats + num_diskio;
404 +
405 +                diskio_stats_ptr->read_bytes = rbytes;
406 +                diskio_stats_ptr->write_bytes = wbytes;
407 +
408 +                diskio_stats_ptr->systime = time(NULL);
409 +
410 +                num_diskio++;
411 +
412 +                if (diskio_stats_ptr->disk_name == NULL) {
413 +                        dh = opendir("/dev/dsk");
414 +                        if (dh == NULL) {
415 +                                continue;
416 +                        }
417 +
418 +                        diskid = (pstat_diskinfo.psd_dev.psd_major << 24) | pstat_diskinfo.psd_dev.psd_minor;
419 +                        while (1) {
420 +                                dinfo = readdir(dh);
421 +                                if (dinfo == NULL) {
422 +                                        break;
423 +                                }
424 +                                snprintf(fullpathbuf, sizeof(fullpathbuf), "/dev/dsk/%s", dinfo->d_name);
425 +                                if (lstat(fullpathbuf, &lstatinfo) < 0) {
426 +                                        continue;
427 +                                }
428 +
429 +                                if (lstatinfo.st_rdev == diskid) {
430 +                                        if (sg_update_string(&diskio_stats_ptr->disk_name, dinfo->d_name) < 0) {
431 +                                                return NULL;
432 +                                        }
433 +                                        break;
434 +                                }
435 +                        }
436 +                        closedir(dh);
437 +
438 +                        if (diskio_stats_ptr->disk_name == NULL) {
439 +                                if (sg_update_string(&diskio_stats_ptr->disk_name, pstat_diskinfo.psd_hw_path.psh_name) < 0) {
440 +                                        return NULL;
441 +                                }
442 +                        }
443 +                }
444 +        }
445 + #endif
446   #ifdef OPENBSD
447          mib[0] = CTL_HW;
448          mib[1] = HW_DISKCOUNT;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines