/
osdFileSystem.c
37 lines (30 loc) · 1.05 KB
/
osdFileSystem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* File system statistics
* Autor: Dirk Zimoch (PSI)
*/
#define _ISOC99_SOURCE /* for fmin() */
#include <math.h>
#include <sys/statvfs.h>
#include <errno.h>
#include <stdio.h>
#include <devIocStats.h>
int devIocStatsGetFileSystemUsage(fsInfo *pval) {
struct statvfs stat;
if (statvfs(pval->path, &stat) != 0)
return errno;
/*
printf("\n%s\n", pval->path);
printf("block size %lu\n", stat.f_bsize);
printf("fragment size %lu\n", stat.f_frsize);
printf("total fragments %lu\n", stat.f_blocks);
printf("free fragments %lu\n", stat.f_bfree);
printf("available fragments %lu\n", stat.f_bavail);
printf("total inodes %lu\n", stat.f_files);
printf("free inodes %lu\n", stat.f_ffree);
printf("available inodes %lu\n", stat.f_favail);
*/
pval->fsUsage = 100*(1-fmin(
(double)stat.f_bavail/(double)stat.f_blocks,
(double)stat.f_favail/(double)stat.f_files));
pval->fsFreeBytes = (double)stat.f_bavail*(double)stat.f_frsize;
return 0;
}