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.40 by ats, Mon Nov 10 23:25:45 2003 UTC vs.
Revision 1.47 by ats, Sat Jan 10 16:25:51 2004 UTC

# Line 98 | Line 98 | void init_disk_stat(int start, int end, disk_stat_t *d
98          }
99   }
100  
101 + int is_valid_fs_type(const char *type) {
102 +        const char *types[] = VALID_FS_TYPES;
103 +        int i;
104 +
105 +        for (i = 0; i < (sizeof types / sizeof *types); i++) {
106 +                if (strcmp(types[i], type) == 0) {
107 +                        return 1;
108 +                }
109 +        }
110 +        return 0;
111 + }
112 +
113   disk_stat_t *get_disk_stats(int *entries){
114  
115          static disk_stat_t *disk_stats;
116          static int watermark=-1;
117  
118 <        char *fs_types[] = VALID_FS_TYPES;
107 <        int x, valid_type;
118 >        int valid_type;
119          int num_disks=0;
120   #if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN)
121          FILE *f;
# Line 139 | Line 150 | disk_stat_t *get_disk_stats(int *entries){
150                  return NULL;
151          }
152          for(;nummnt--; mp++){
153 <                valid_type=0;
143 <                for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){
144 <                        if(strcmp(mp->f_fstypename, fs_types[x]) ==0){
145 <                                valid_type=1;
146 <                                break;
147 <                        }
148 <                }
153 >                valid_type = is_valid_fs_type(mp->f_fstypename);
154   #endif
155  
156   #if defined(LINUX) || defined(CYGWIN)
# Line 158 | Line 163 | disk_stat_t *get_disk_stats(int *entries){
163                          continue;
164                  }      
165  
166 <                valid_type=0;
162 <                for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){
163 <                        if(strcmp(mp->mnt_type, fs_types[x]) ==0){
164 <                                valid_type=1;
165 <                                break;
166 <                        }
167 <                }
166 >                valid_type = is_valid_fs_type(mp->mnt_type);
167   #endif
168  
169   #ifdef SOLARIS
# Line 175 | Line 174 | disk_stat_t *get_disk_stats(int *entries){
174                  if ((statvfs(mp.mnt_mountp, &fs)) !=0){
175                          continue;
176                  }
177 <                valid_type=0;
179 <                for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){
180 <                        if(strcmp(mp.mnt_fstype, fs_types[x]) ==0){
181 <                                valid_type=1;
182 <                                break;
183 <                        }
184 <                }
177 >                valid_type = is_valid_fs_type(mp.mnt_fstype);
178   #endif
179  
180                  if(valid_type){
# Line 510 | Line 503 | diskio_stat_t *get_diskio_stats(int *entries){
503  
504                          if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name);
505  
506 <                        diskio_stats_ptr->disk_name=strdup(ksp->ks_name);
506 >                        diskio_stats_ptr->disk_name=strdup((char *) get_svr_from_bsd(ksp->ks_name));
507                          diskio_stats_ptr->systime=time(NULL);
508                          num_diskio++;
509                  }
# Line 583 | Line 576 | diskio_stat_t *get_diskio_stats(int *entries){
576                  n++;
577          }
578  
579 +        fclose(f);
580 +        f = NULL;
581 +
582          if (!has_pp_stats) {
583 <                /* This is an older kernel without stats in /proc/partitions.
584 <                   Read what we can from /proc/stat instead. */
583 >                /* This is an older kernel where /proc/partitions doesn't
584 >                   contain stats. Read what we can from /proc/stat instead, and
585 >                   fill in the appropriate bits of the list allocated above. */
586  
587                  f = fopen("/proc/stat", "r");
588                  if (f == NULL) goto out;
# Line 652 | Line 649 | diskio_stat_t *get_diskio_stats(int *entries){
649          num_diskio = n;
650   out:
651          if (f != NULL) fclose(f);
652 + #endif
653  
654 + #ifdef CYGWIN
655 +        return NULL;
656   #endif
657 +
658          *entries=num_diskio;
659  
660          return diskio_stats;
# Line 693 | Line 694 | diskio_stat_t *get_diskio_stats_diff(int *entries){
694          }
695  
696          diskio_stats_ptr=get_diskio_stats(&disks);
697 +        if (diskio_stats_ptr == NULL) {
698 +                return NULL;
699 +        }
700          diskio_stats_diff_ptr=diskio_stats_diff;
701  
702          for(x=0;x<sizeof_diskio_stats_diff;x++){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines