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 |
26 |
|
#include <stdio.h> |
27 |
|
#include <stdlib.h> |
28 |
|
#include <string.h> |
29 |
+ |
#include <time.h> |
30 |
|
#include "statgrab.h" |
31 |
|
|
32 |
|
#ifdef SOLARIS |
36 |
|
#define VALID_FS_TYPES {"ufs", "tmpfs"} |
37 |
|
#endif |
38 |
|
|
39 |
< |
#ifdef LINUX |
38 |
< |
#include <time.h> |
39 |
< |
#include <sys/vfs.h> |
39 |
> |
#if defined(LINUX) || defined(CYGWIN) |
40 |
|
#include <mntent.h> |
41 |
+ |
#include <sys/vfs.h> |
42 |
|
#include "tools.h" |
43 |
< |
#ifdef CYGWIN |
44 |
< |
#define VALID_FS_TYPES {"user"} |
45 |
< |
#else |
43 |
> |
#endif |
44 |
> |
|
45 |
> |
#ifdef LINUX |
46 |
|
#define VALID_FS_TYPES {"adfs", "affs", "befs", "bfs", "efs", "ext2", \ |
47 |
|
"ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \ |
48 |
|
"jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \ |
49 |
|
"rootfs", "reiserfs", "sysv", "v7", "udf", "ufs", \ |
50 |
|
"umsdos", "vfat", "xfs", "jfs"} |
51 |
|
#endif |
52 |
+ |
|
53 |
+ |
#ifdef CYGWIN |
54 |
+ |
#define VALID_FS_TYPES {"user"} |
55 |
|
#endif |
56 |
|
|
57 |
|
#ifdef ALLBSD |
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; |
104 |
< |
int x, valid_type; |
119 |
> |
int valid_type; |
120 |
|
int num_disks=0; |
121 |
< |
#if defined(LINUX) || defined (SOLARIS) |
121 |
> |
#if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN) |
122 |
|
FILE *f; |
123 |
|
#endif |
124 |
|
|
128 |
|
struct mnttab mp; |
129 |
|
struct statvfs fs; |
130 |
|
#endif |
131 |
< |
#ifdef LINUX |
131 |
> |
#if defined(LINUX) || defined(CYGWIN) |
132 |
|
struct mntent *mp; |
133 |
|
struct statfs fs; |
134 |
|
#endif |
151 |
|
return NULL; |
152 |
|
} |
153 |
|
for(;nummnt--; mp++){ |
154 |
< |
valid_type=0; |
140 |
< |
for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){ |
141 |
< |
if(strcmp(mp->f_fstypename, fs_types[x]) ==0){ |
142 |
< |
valid_type=1; |
143 |
< |
break; |
144 |
< |
} |
145 |
< |
} |
154 |
> |
valid_type = is_valid_fs_type(mp->f_fstypename); |
155 |
|
#endif |
156 |
|
|
157 |
< |
#ifdef LINUX |
157 |
> |
#if defined(LINUX) || defined(CYGWIN) |
158 |
|
if ((f=setmntent("/etc/mtab", "r" ))==NULL){ |
159 |
|
return NULL; |
160 |
|
} |
164 |
|
continue; |
165 |
|
} |
166 |
|
|
167 |
< |
valid_type=0; |
159 |
< |
for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){ |
160 |
< |
if(strcmp(mp->mnt_type, fs_types[x]) ==0){ |
161 |
< |
valid_type=1; |
162 |
< |
break; |
163 |
< |
} |
164 |
< |
} |
167 |
> |
valid_type = is_valid_fs_type(mp->mnt_type); |
168 |
|
#endif |
169 |
|
|
170 |
|
#ifdef SOLARIS |
175 |
|
if ((statvfs(mp.mnt_mountp, &fs)) !=0){ |
176 |
|
continue; |
177 |
|
} |
178 |
< |
valid_type=0; |
176 |
< |
for(x=0;x<((sizeof(fs_types))/(sizeof(char*)));x++){ |
177 |
< |
if(strcmp(mp.mnt_fstype, fs_types[x]) ==0){ |
178 |
< |
valid_type=1; |
179 |
< |
break; |
180 |
< |
} |
181 |
< |
} |
178 |
> |
valid_type = is_valid_fs_type(mp.mnt_fstype); |
179 |
|
#endif |
180 |
|
|
181 |
|
if(valid_type){ |
213 |
|
/* Freebsd doesn't have a "available" inodes */ |
214 |
|
disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes; |
215 |
|
#endif |
216 |
< |
#ifdef LINUX |
216 |
> |
#if defined(LINUX) || defined(CYGWIN) |
217 |
|
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->mnt_fsname))==NULL){ |
218 |
|
return NULL; |
219 |
|
} |
269 |
|
|
270 |
|
/* If this fails, there is very little i can do about it, so |
271 |
|
I'll ignore it :) */ |
272 |
< |
#if defined(LINUX) |
272 |
> |
#if defined(LINUX) || defined(CYGWIN) |
273 |
|
endmntent(f); |
274 |
|
#endif |
275 |
|
#if defined(SOLARIS) |
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 |
|
} |
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; |
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; |
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++){ |