25 |
|
#include <stdio.h> |
26 |
|
#include <stdlib.h> |
27 |
|
#include <string.h> |
28 |
+ |
#include <time.h> |
29 |
|
#include "statgrab.h" |
30 |
|
|
31 |
|
#ifdef SOLARIS |
35 |
|
#define VALID_FS_TYPES {"ufs", "tmpfs"} |
36 |
|
#endif |
37 |
|
|
38 |
< |
#ifdef LINUX |
38 |
< |
#include <time.h> |
39 |
< |
#include <sys/vfs.h> |
38 |
> |
#if defined(LINUX) || defined(CYGWIN) |
39 |
|
#include <mntent.h> |
40 |
+ |
#include <sys/vfs.h> |
41 |
|
#include "tools.h" |
42 |
+ |
#endif |
43 |
+ |
|
44 |
+ |
#ifdef LINUX |
45 |
|
#define VALID_FS_TYPES {"adfs", "affs", "befs", "bfs", "efs", "ext2", \ |
46 |
|
"ext3", "vxfs", "hfs", "hfsplus", "hpfs", "jffs", \ |
47 |
|
"jffs2", "minix", "msdos", "ntfs", "qnx4", "ramfs", \ |
49 |
|
"umsdos", "vfat", "xfs", "jfs"} |
50 |
|
#endif |
51 |
|
|
52 |
+ |
#ifdef CYGWIN |
53 |
+ |
#define VALID_FS_TYPES {"user"} |
54 |
+ |
#endif |
55 |
+ |
|
56 |
|
#ifdef ALLBSD |
57 |
|
#include <sys/param.h> |
58 |
|
#include <sys/ucred.h> |
106 |
|
char *fs_types[] = VALID_FS_TYPES; |
107 |
|
int x, valid_type; |
108 |
|
int num_disks=0; |
109 |
< |
#if defined(LINUX) || defined (SOLARIS) |
109 |
> |
#if defined(LINUX) || defined (SOLARIS) || defined(CYGWIN) |
110 |
|
FILE *f; |
111 |
|
#endif |
112 |
|
|
116 |
|
struct mnttab mp; |
117 |
|
struct statvfs fs; |
118 |
|
#endif |
119 |
< |
#ifdef LINUX |
119 |
> |
#if defined(LINUX) || defined(CYGWIN) |
120 |
|
struct mntent *mp; |
121 |
|
struct statfs fs; |
122 |
|
#endif |
148 |
|
} |
149 |
|
#endif |
150 |
|
|
151 |
< |
#ifdef LINUX |
151 |
> |
#if defined(LINUX) || defined(CYGWIN) |
152 |
|
if ((f=setmntent("/etc/mtab", "r" ))==NULL){ |
153 |
|
return NULL; |
154 |
|
} |
219 |
|
/* Freebsd doesn't have a "available" inodes */ |
220 |
|
disk_ptr->used_inodes=disk_ptr->total_inodes-disk_ptr->free_inodes; |
221 |
|
#endif |
222 |
< |
#ifdef LINUX |
222 |
> |
#if defined(LINUX) || defined(CYGWIN) |
223 |
|
if((disk_ptr->device_name=copy_string(disk_ptr->device_name, mp->mnt_fsname))==NULL){ |
224 |
|
return NULL; |
225 |
|
} |
273 |
|
|
274 |
|
*entries=num_disks; |
275 |
|
|
276 |
< |
/* If this fails, there is very little i can do about it, so i'll ignore it :) */ |
277 |
< |
#if defined(LINUX) || defined(SOLARIS) |
276 |
> |
/* If this fails, there is very little i can do about it, so |
277 |
> |
I'll ignore it :) */ |
278 |
> |
#if defined(LINUX) || defined(CYGWIN) |
279 |
> |
endmntent(f); |
280 |
> |
#endif |
281 |
> |
#if defined(SOLARIS) |
282 |
|
fclose(f); |
283 |
|
#endif |
284 |
|
|
333 |
|
diskio_stat_t *get_diskio_stats(int *entries){ |
334 |
|
|
335 |
|
static int sizeof_diskio_stats=0; |
336 |
+ |
#ifndef LINUX |
337 |
|
diskio_stat_t *diskio_stats_ptr; |
338 |
+ |
#endif |
339 |
|
|
340 |
|
#ifdef SOLARIS |
341 |
|
kstat_ctl_t *kc; |
346 |
|
FILE *f; |
347 |
|
char *line_ptr; |
348 |
|
int major, minor; |
336 |
– |
char dev_letter; |
349 |
|
int has_pp_stats = 1; |
350 |
|
static partition *parts = NULL; |
351 |
|
static int alloc_parts = 0; |
352 |
|
int i, n; |
353 |
|
time_t now; |
354 |
+ |
const char *format; |
355 |
|
#endif |
356 |
|
#ifdef FREEBSD |
357 |
|
static struct statinfo stats; |
524 |
|
n = 0; |
525 |
|
|
526 |
|
/* Read /proc/partitions to find what devices exist. Recent 2.4 kernels |
527 |
< |
have statistics in here too, so we can use those directly. */ |
527 |
> |
have statistics in here too, so we can use those directly. |
528 |
> |
2.6 kernels have /proc/diskstats instead with almost (but not quite) |
529 |
> |
the same format. */ |
530 |
|
|
531 |
< |
f = fopen("/proc/partitions", "r"); |
531 |
> |
f = fopen("/proc/diskstats", "r"); |
532 |
> |
format = " %d %d %19s %*d %*d %lld %*d %*d %*d %lld"; |
533 |
> |
if (f == NULL) { |
534 |
> |
f = fopen("/proc/partitions", "r"); |
535 |
> |
format = " %d %d %*d %19s %*d %*d %lld %*d %*d %*d %lld"; |
536 |
> |
} |
537 |
|
if (f == NULL) goto out; |
538 |
|
now = time(NULL); |
539 |
|
|
542 |
|
char *s; |
543 |
|
long long rsect, wsect; |
544 |
|
|
545 |
< |
int nr = sscanf(line_ptr, |
526 |
< |
" %d %d %*d %19s %*d %*d %lld %*d %*d %*d %lld", |
545 |
> |
int nr = sscanf(line_ptr, format, |
546 |
|
&major, &minor, name, &rsect, &wsect); |
547 |
|
if (nr < 3) continue; |
529 |
– |
if (nr < 5) { |
530 |
– |
has_pp_stats = 0; |
531 |
– |
rsect = 0; |
532 |
– |
wsect = 0; |
533 |
– |
} |
548 |
|
|
549 |
|
/* Skip device names ending in numbers, since they're |
550 |
|
partitions. */ |
552 |
|
while (*s != '\0') s++; |
553 |
|
--s; |
554 |
|
if (*s >= '0' && *s <= '9') continue; |
555 |
+ |
|
556 |
+ |
if (nr < 5) { |
557 |
+ |
has_pp_stats = 0; |
558 |
+ |
rsect = 0; |
559 |
+ |
wsect = 0; |
560 |
+ |
} |
561 |
|
|
562 |
|
diskio_stats = diskio_stat_malloc(n + 1, &sizeof_diskio_stats, |
563 |
|
diskio_stats); |