From 94b3f884a28dab87d7a1369923bd4a30fe43af15 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 21 May 2009 14:25:46 -0700 Subject: [PATCH 1/3] (SIGAR-148) add generic sigar_statvfs built with LFS flags --- include/sigar_util.h | 4 ++++ src/sigar_fileinfo.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/include/sigar_util.h b/include/sigar_util.h index b81196c2..258f1257 100644 --- a/include/sigar_util.h +++ b/include/sigar_util.h @@ -120,6 +120,10 @@ int sigar_procfs_args_get(sigar_t *sigar, sigar_pid_t pid, int sigar_mem_calc_ram(sigar_t *sigar, sigar_mem_t *mem); +int sigar_statvfs(sigar_t *sigar, + const char *dirname, + sigar_file_system_usage_t *fsusage); + double sigar_file_system_usage_calc_used(sigar_t *sigar, sigar_file_system_usage_t *fs); diff --git a/src/sigar_fileinfo.c b/src/sigar_fileinfo.c index 5cb10c9d..a7567459 100644 --- a/src/sigar_fileinfo.c +++ b/src/sigar_fileinfo.c @@ -61,6 +61,40 @@ # endif #endif +#include "sigar.h" + +#ifndef WIN32 +#include +#include + +#define SIGAR_FS_BLOCKS_TO_BYTES(val, bsize) ((val * bsize) >> 1) + +int sigar_statvfs(sigar_t *sigar, + const char *dirname, + sigar_file_system_usage_t *fsusage) +{ + struct statvfs buf; + sigar_uint64_t val, bsize; + + if (statvfs(dirname, &buf) != 0) { + return errno; + } + + bsize = buf.f_frsize / 512; + val = buf.f_blocks; + fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); + val = buf.f_bfree; + fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); + val = buf.f_bavail; + fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); + fsusage->used = fsusage->total - fsusage->free; + fsusage->files = buf.f_files; + fsusage->free_files = buf.f_ffree; + + return SIGAR_OK; +} +#endif + /* * whittled down version of apr/file_info/{unix,win32}/filestat.c * to fillin sigar_fileattrs_t From b53121d071a071765df3dd7c2420d5f5fd3e3007 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 21 May 2009 14:26:29 -0700 Subject: [PATCH 2/3] (SIGAR-148) use sigar_statvfs --- src/os/solaris/solaris_sigar.c | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index ad856eb1..bd867223 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -1352,8 +1352,6 @@ int sigar_file_system_list_get(sigar_t *sigar, return SIGAR_OK; } -#include - typedef struct { char device[PATH_MAX]; char name[8]; @@ -1716,29 +1714,16 @@ int sigar_disk_usage_get(sigar_t *sigar, const char *name, return status; } -#define SIGAR_FS_BLOCKS_TO_BYTES(val, bsize) ((val * bsize) >> 1) - int sigar_file_system_usage_get(sigar_t *sigar, const char *dirname, sigar_file_system_usage_t *fsusage) { - struct statvfs buf; - sigar_uint64_t val, bsize; + int status = sigar_statvfs(sigar, dirname, fsusage); - if (statvfs(dirname, &buf) != 0) { - return errno; + if (status != SIGAR_OK) { + return status; } - bsize = buf.f_frsize / 512; - val = buf.f_blocks; - fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); - val = buf.f_bfree; - fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); - val = buf.f_bavail; - fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); - fsusage->used = fsusage->total - fsusage->free; - fsusage->files = buf.f_files; - fsusage->free_files = buf.f_ffree; fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage); sigar_disk_usage_get(sigar, dirname, &fsusage->disk); From 376409a403d9b5402e3bcd420070217d8f43cf18 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 21 May 2009 14:26:34 -0700 Subject: [PATCH 3/3] (SIGAR-148) use sigar_statvfs --- src/os/linux/linux_sigar.c | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index ce0f36dc..2f232ae1 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -1058,7 +1058,6 @@ int sigar_thread_cpu_get(sigar_t *sigar, } #include -#include int sigar_os_fs_type_get(sigar_file_system_t *fsp) { @@ -1458,31 +1457,16 @@ int sigar_disk_usage_get(sigar_t *sigar, const char *name, return status; } -#include - -#define SIGAR_FS_BLOCKS_TO_BYTES(val, bsize) ((val * bsize) >> 1) - int sigar_file_system_usage_get(sigar_t *sigar, const char *dirname, sigar_file_system_usage_t *fsusage) { - struct statfs buf; - sigar_uint64_t val, bsize; - - if (statfs(dirname, &buf) != 0) { - return errno; + int status = sigar_statvfs(sigar, dirname, fsusage); + + if (status != SIGAR_OK) { + return status; } - bsize = buf.f_bsize / 512; - val = buf.f_blocks; - fsusage->total = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); - val = buf.f_bfree; - fsusage->free = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); - val = buf.f_bavail; - fsusage->avail = SIGAR_FS_BLOCKS_TO_BYTES(val, bsize); - fsusage->used = fsusage->total - fsusage->free; - fsusage->files = buf.f_files; - fsusage->free_files = buf.f_ffree; fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage); (void)sigar_disk_usage_get(sigar, dirname, &fsusage->disk);