From d3d35e937f777019f1c8be311d5fd16ced62e8b2 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 1 Jul 2009 14:29:20 -0700 Subject: [PATCH 1/2] (SIGAR-148) use sigar_statvfs --- src/os/darwin/darwin_sigar.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index d18f317c..12fac276 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2202,23 +2202,12 @@ int sigar_file_system_usage_get(sigar_t *sigar, const char *dirname, sigar_file_system_usage_t *fsusage) { - struct sigar_statfs buf; - sigar_uint64_t val, bsize; + int status = sigar_statvfs(sigar, dirname, fsusage); - if (sigar_statfs(dirname, &buf) < 0) { - return errno; + 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); #if defined(__FreeBSD__) From 2b00bad1c1b9d5202be689b21868a33401ee84f1 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 1 Jul 2009 14:59:08 -0700 Subject: [PATCH 2/2] move FreeBSD sigar_disk_usage_get related code where it belongs --- src/os/darwin/darwin_sigar.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 12fac276..d254df33 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -2192,8 +2192,22 @@ int sigar_disk_usage_get(sigar_t *sigar, const char *name, IOObjectRelease(service); IOObjectRelease(parent); + return SIGAR_OK; +#elif defined(__FreeBSD__) + /* XXX incomplete */ + struct sigar_statfs buf; + + if (sigar_statfs(name, &buf) < 0) { + return errno; + } + + SIGAR_DISK_STATS_INIT(disk); + + disk->reads = buf.f_syncreads + buf.f_asyncreads; + disk->writes = buf.f_syncwrites + buf.f_asyncwrites; return SIGAR_OK; #else + SIGAR_DISK_STATS_INIT(disk); return SIGAR_ENOTIMPL; #endif } @@ -2210,17 +2224,7 @@ int sigar_file_system_usage_get(sigar_t *sigar, fsusage->use_percent = sigar_file_system_usage_calc_used(sigar, fsusage); -#if defined(__FreeBSD__) - fsusage->disk_reads = buf.f_syncreads + buf.f_asyncreads; - fsusage->disk_writes = buf.f_syncwrites + buf.f_asyncwrites; - fsusage->disk_read_bytes = SIGAR_FIELD_NOTIMPL; - fsusage->disk_write_bytes = SIGAR_FIELD_NOTIMPL; - fsusage->disk_queue = SIGAR_FIELD_NOTIMPL; -#elif defined(DARWIN) sigar_disk_usage_get(sigar, dirname, &fsusage->disk); -#else - SIGAR_DISK_STATS_INIT(&fsusage->disk); -#endif return SIGAR_OK; }