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.65 by tdb, Wed Apr 7 14:53:40 2004 UTC vs.
Revision 1.68 by tdb, Thu Apr 8 14:30:43 2004 UTC

# Line 128 | Line 128 | sg_fs_stats *sg_get_fs_stats(int *entries){
128   #ifdef ALLBSD
129          nummnt=getmntinfo(&mp , MNT_LOCAL);
130          if (nummnt<=0){
131 +                sg_set_error(SG_ERROR_GETMNTINFO, NULL);
132                  return NULL;
133          }
134          for(;nummnt--; mp++){
# Line 136 | Line 137 | sg_fs_stats *sg_get_fs_stats(int *entries){
137  
138   #if defined(LINUX) || defined(CYGWIN)
139          if ((f=setmntent("/etc/mtab", "r" ))==NULL){
140 +                sg_set_error(SG_ERROR_SETMNTENT, NULL);
141                  return NULL;
142          }
143  
# Line 149 | Line 151 | sg_fs_stats *sg_get_fs_stats(int *entries){
151  
152   #ifdef SOLARIS
153          if ((f=fopen("/etc/mnttab", "r" ))==NULL){
154 +                sg_set_error(SG_ERROR_OPEN, "/etc/mnttab");
155                  return NULL;
156          }
157          while((getmntent(f, &mp)) == 0){
# Line 250 | Line 253 | sg_fs_stats *sg_get_fs_stats(int *entries){
253  
254   }
255  
256 + int sg_fs_compare_device_name(const void *va, const void *vb) {
257 +        const sg_fs_stats *a = (const sg_fs_stats *)va;
258 +        const sg_fs_stats *b = (const sg_fs_stats *)vb;
259 +
260 +        return strcmp(a->device_name, b->device_name);
261 + }
262 +
263 + int sg_fs_compare_mnt_point(const void *va, const void *vb) {
264 +        const sg_fs_stats *a = (const sg_fs_stats *)va;
265 +        const sg_fs_stats *b = (const sg_fs_stats *)vb;
266 +
267 +        return strcmp(a->mnt_point, b->mnt_point);
268 + }
269 +
270   static void diskio_stat_init(sg_disk_io_stats *d) {
271          d->disk_name = NULL;
272   }
# Line 327 | Line 344 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
344  
345          size = sizeof(diskcount);
346          if (sysctl(mib, MIBSIZE, &diskcount, &size, NULL, 0) < 0) {
347 +                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKCOUNT");
348                  return NULL;
349          }
350  
# Line 334 | Line 352 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
352          mib[1] = HW_DISKNAMES;
353  
354          if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) {
355 +                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES");
356                  return NULL;
357          }
358  
# Line 343 | Line 362 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
362          }
363  
364          if (sysctl(mib, MIBSIZE, disknames, &size, NULL, 0) < 0) {
365 +                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKNAMES");
366                  return NULL;
367          }
368  
# Line 361 | Line 381 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
381   #endif
382  
383          if (sysctl(mib, MIBSIZE, NULL, &size, NULL, 0) < 0) {
384 +                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS");
385                  return NULL;
386          }
387  
# Line 376 | Line 397 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
397          }
398  
399          if (sysctl(mib, MIBSIZE, stats, &size, NULL, 0) < 0) {
400 +                sg_set_error(SG_ERROR_SYSCTL, "CTL_HW.HW_DISKSTATS");
401                  return NULL;
402          }
403  
# Line 435 | Line 457 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
457                  stats_init = 1;
458          }
459   #ifdef FREEBSD5
460 <        if ((devstat_getdevs(NULL, &stats)) < 0) return NULL;
460 >        if ((devstat_getdevs(NULL, &stats)) < 0) {
461 >                sg_set_error(SG_ERROR_DEVSTAT_GETDEVS, NULL);
462 >                return NULL;
463 >        }
464          /* Not aware of a get all devices, so i said 999. If we ever
465           * find a machine with more than 999 disks, then i'll change
466           * this number :)
467           */
468 <        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;
468 >        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) {
469 >                sg_set_error(SG_ERROR_DEVSTAT_SELECTDEVS, NULL);
470 >                return NULL;
471 >        }
472   #else
473 <        if ((getdevs(&stats)) < 0) return NULL;
473 >        if ((getdevs(&stats)) < 0) {
474 >                sg_set_error(SG_ERROR_DEVSTAT_GETDEVS, NULL);
475 >                return NULL;
476 >        }
477          /* Not aware of a get all devices, so i said 999. If we ever
478           * find a machine with more than 999 disks, then i'll change
479           * this number :)
480           */
481 <        if (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;
481 >        if (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) {
482 >                sg_set_error(SG_ERROR_DEVSTAT_SELECTDEVS, NULL);
483 >                return NULL;
484 >        }
485   #endif
486  
487          for(counter=0;counter<stats.dinfo->numdevs;counter++){
# Line 477 | Line 511 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
511   #endif
512                  if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name);
513                  if (asprintf((&diskio_stats_ptr->disk_name), "%s%d", dev_ptr->device_name, dev_ptr->unit_number) == -1) {
514 +                        sg_set_error(SG_ERROR_ASPRINTF, NULL);
515                          return NULL;
516                  }
517                  diskio_stats_ptr->systime=time(NULL);
# Line 488 | Line 523 | sg_disk_io_stats *sg_get_disk_io_stats(int *entries){
523   #endif
524   #ifdef SOLARIS
525          if ((kc = kstat_open()) == NULL) {
526 +                sg_set_error(SG_ERROR_KSTAT_OPEN, NULL);
527                  return NULL;
528          }
529  
# Line 656 | Line 692 | out:
692   #endif
693  
694   #ifdef CYGWIN
695 +        sg_set_error(SG_ERROR_UNSUPPORTED, "Cygwin");
696          return NULL;
697   #endif
698  
# Line 726 | Line 763 | sg_disk_io_stats *sg_get_disk_io_stats_diff(int *entri
763  
764          *entries = diff_count;
765          return diff;
766 + }
767 +
768 + int sg_disk_io_compare_name(const void *va, const void *vb) {
769 +        const sg_disk_io_stats *a = (const sg_disk_io_stats *)va;
770 +        const sg_disk_io_stats *b = (const sg_disk_io_stats *)vb;
771 +
772 +        return strcmp(a->disk_name, b->disk_name);
773   }
774  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines