From 0936618a799918422012036aecbf7a2b0ee32354 Mon Sep 17 00:00:00 2001 From: Sebastien GODARD Date: Sun, 22 Jun 2014 16:09:18 +0200 Subject: [PATCH] Use statvfs() instead of statfs() system call Use statvfs() system call instead of statfs() to get filesystems statistics with sar since: 1) statfs() has been deprecated by the LSB (useful only to get fs type which is not needed here), 2) statvfs() better handles large file sizes. Signed-off-by: Sebastien GODARD --- count.c | 6 +++--- rd_stats.c | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/count.c b/count.c index 426af31..ceca3f5 100644 --- a/count.c +++ b/count.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include "common.h" @@ -463,7 +463,7 @@ int get_filesystem_nr(void) FILE *fp; char line[256], fs_name[MAX_FS_LEN], mountp[128]; int fs = 0; - struct statfs buf; + struct statvfs buf; if ((fp = fopen(MTAB, "r")) == NULL) /* File non-existent */ @@ -480,7 +480,7 @@ int get_filesystem_nr(void) oct2chr(mountp); /* Check that total size is not null */ - if (statfs(mountp, &buf) < 0) + if (statvfs(mountp, &buf) < 0) continue; if (buf.f_blocks) { diff --git a/rd_stats.c b/rd_stats.c index 6ea549c..899671d 100644 --- a/rd_stats.c +++ b/rd_stats.c @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include "common.h" @@ -2015,7 +2015,7 @@ void read_filesystem(struct stats_filesystem *st_filesystem, int nbr) char line[256], fs_name[MAX_FS_LEN], mountp[128]; int fs = 0; struct stats_filesystem *st_filesystem_i; - struct statfs buf; + struct statvfs buf; if ((fp = fopen(MTAB, "r")) == NULL) return; @@ -2029,13 +2029,13 @@ void read_filesystem(struct stats_filesystem *st_filesystem, int nbr) /* Replace octal codes */ oct2chr(mountp); - if ((statfs(mountp, &buf) < 0) || (!buf.f_blocks)) + if ((statvfs(mountp, &buf) < 0) || (!buf.f_blocks)) continue; st_filesystem_i = st_filesystem + fs++; - st_filesystem_i->f_blocks = buf.f_blocks * buf.f_bsize; - st_filesystem_i->f_bfree = buf.f_bfree * buf.f_bsize; - st_filesystem_i->f_bavail = buf.f_bavail * buf.f_bsize; + st_filesystem_i->f_blocks = buf.f_blocks * buf.f_frsize; + st_filesystem_i->f_bfree = buf.f_bfree * buf.f_frsize; + st_filesystem_i->f_bavail = buf.f_bavail * buf.f_frsize; st_filesystem_i->f_files = buf.f_files; st_filesystem_i->f_ffree = buf.f_ffree; strcpy(st_filesystem_i->fs_name, fs_name); -- 2.40.0