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.48 by tdb, Fri Jan 16 15:54:54 2004 UTC

# Line 1 | Line 1
1 < /*
1 > /*
2   * i-scream central monitoring system
3   * http://www.i-scream.org
4 < * Copyright (C) 2000-2003 i-scream
4 > * Copyright (C) 2000-2004 i-scream
5   *
6 < * This program is free software; you can redistribute it and/or
7 < * modify it under the terms of the GNU General Public License
8 < * as published by the Free Software Foundation; either version 2
9 < * of the License, or (at your option) any later version.
6 > * This library is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public
8 > * License as published by the Free Software Foundation; either
9 > * version 2.1 of the License, or (at your option) any later version.
10   *
11 < * This program is distributed in the hope that it will be useful,
11 > * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 < * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 < * GNU General Public License for more details.
13 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 > * Lesser General Public License for more details.
15   *
16 < * You should have received a copy of the GNU General Public License
17 < * along with this program; if not, write to the Free Software
18 < * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 > * You should have received a copy of the GNU Lesser General Public
17 > * License along with this library; if not, write to the Free Software
18 > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 > * 02111-1307 USA
20   */
21  
22   #ifdef HAVE_CONFIG_H
# Line 98 | Line 99 | void init_disk_stat(int start, int end, disk_stat_t *d
99          }
100   }
101  
102 + int is_valid_fs_type(const char *type) {
103 +        const char *types[] = VALID_FS_TYPES;
104 +        int i;
105 +
106 +        for (i = 0; i < (sizeof types / sizeof *types); i++) {
107 +                if (strcmp(types[i], type) == 0) {
108 +                        return 1;
109 +                }
110 +        }
111 +        return 0;
112 + }
113 +
114   disk_stat_t *get_disk_stats(int *entries){
115  
116          static disk_stat_t *disk_stats;
117          static int watermark=-1;
118  
119 <        char *fs_types[] = VALID_FS_TYPES;
107 <        int x, valid_type;
119 >        int valid_type;
120          int num_disks=0;
121   #if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN)
122          FILE *f;
# Line 139 | Line 151 | disk_stat_t *get_disk_stats(int *entries){
151                  return NULL;
152          }
153          for(;nummnt--; mp++){
154 <                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 <                }
154 >                valid_type = is_valid_fs_type(mp->f_fstypename);
155   #endif
156  
157   #if defined(LINUX) || defined(CYGWIN)
# Line 158 | Line 164 | disk_stat_t *get_disk_stats(int *entries){
164                          continue;
165                  }      
166  
167 <                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 <                }
167 >                valid_type = is_valid_fs_type(mp->mnt_type);
168   #endif
169  
170   #ifdef SOLARIS
# Line 175 | Line 175 | disk_stat_t *get_disk_stats(int *entries){
175                  if ((statvfs(mp.mnt_mountp, &fs)) !=0){
176                          continue;
177                  }
178 <                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 <                }
178 >                valid_type = is_valid_fs_type(mp.mnt_fstype);
179   #endif
180  
181                  if(valid_type){
# Line 510 | Line 504 | diskio_stat_t *get_diskio_stats(int *entries){
504  
505                          if(diskio_stats_ptr->disk_name!=NULL) free(diskio_stats_ptr->disk_name);
506  
507 <                        diskio_stats_ptr->disk_name=strdup(ksp->ks_name);
507 >                        diskio_stats_ptr->disk_name=strdup((char *) get_svr_from_bsd(ksp->ks_name));
508                          diskio_stats_ptr->systime=time(NULL);
509                          num_diskio++;
510                  }
# Line 583 | Line 577 | diskio_stat_t *get_diskio_stats(int *entries){
577                  n++;
578          }
579  
580 +        fclose(f);
581 +        f = NULL;
582 +
583          if (!has_pp_stats) {
584 <                /* This is an older kernel without stats in /proc/partitions.
585 <                   Read what we can from /proc/stat instead. */
584 >                /* This is an older kernel where /proc/partitions doesn't
585 >                   contain stats. Read what we can from /proc/stat instead, and
586 >                   fill in the appropriate bits of the list allocated above. */
587  
588                  f = fopen("/proc/stat", "r");
589                  if (f == NULL) goto out;
# Line 652 | Line 650 | diskio_stat_t *get_diskio_stats(int *entries){
650          num_diskio = n;
651   out:
652          if (f != NULL) fclose(f);
653 + #endif
654  
655 + #ifdef CYGWIN
656 +        return NULL;
657   #endif
658 +
659          *entries=num_diskio;
660  
661          return diskio_stats;
# Line 693 | Line 695 | diskio_stat_t *get_diskio_stats_diff(int *entries){
695          }
696  
697          diskio_stats_ptr=get_diskio_stats(&disks);
698 +        if (diskio_stats_ptr == NULL) {
699 +                return NULL;
700 +        }
701          diskio_stats_diff_ptr=diskio_stats_diff;
702  
703          for(x=0;x<sizeof_diskio_stats_diff;x++){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines