diff --git a/libgtop-sysdeps.m4 b/libgtop-sysdeps.m4 index a9dc7636..0dffa642 100644 --- a/libgtop-sysdeps.m4 +++ b/libgtop-sysdeps.m4 @@ -67,6 +67,7 @@ AC_DEFUN([GNOME_LIBGTOP_SYSDEPS],[ libgtop_have_sysinfo=yes libgtop_need_server=no libgtop_sysdeps_private_mountlist=yes + libgtop_sysdeps_private_fsusage=yes ;; netbsd*|openbsd*|bsdi*) libgtop_sysdeps_dir=bsd @@ -320,5 +321,6 @@ main (void) AM_CONDITIONAL(NEED_LIBGTOP, test x$libgtop_need_server = xyes) AM_CONDITIONAL(LIBGTOP_SYSDEPS_PRIVATE_MOUNTLIST, test x$libgtop_sysdeps_private_mountlist = xyes) + AM_CONDITIONAL(LIBGTOP_SYSDEPS_PRIVATE_FSUSAGE, test x$libgtop_sysdeps_private_fsusage = xyes) ]) diff --git a/sysdeps/common/Makefile.am b/sysdeps/common/Makefile.am index 13e6e2c0..43cb9e3c 100644 --- a/sysdeps/common/Makefile.am +++ b/sysdeps/common/Makefile.am @@ -4,7 +4,6 @@ INCLUDES = @INCLUDES@ noinst_LTLIBRARIES = libgtop_common-2.0.la libgtop_suid_common-2.0.la libgtop_common_2_0_la_SOURCES = error.c gnuslib.c \ - fsusage.c \ procargs.c \ default.c @@ -12,6 +11,10 @@ if !LIBGTOP_SYSDEPS_PRIVATE_MOUNTLIST libgtop_common_2_0_la_SOURCES += mountlist.c endif +if !LIBGTOP_SYSDEPS_PRIVATE_FSUSAGE + libgtop_common_2_0_la_SOURCES += fsusage.c +endif + # libgtop_common_2_0_la_LDFLAGS = $(LT_VERSION_INFO) libgtop_common_2_0_la_LIBADD = $(LIBGTOP_EXTRA_LIBS) diff --git a/sysdeps/linux/fsusage.c b/sysdeps/linux/fsusage.c index d66fcc5e..c6bff2e4 100644 --- a/sysdeps/linux/fsusage.c +++ b/sysdeps/linux/fsusage.c @@ -1,6 +1,7 @@ #include #include #include +#include #include "glibtop_private.h" @@ -10,15 +11,11 @@ #include #include #include - +#include #include #include #include -void -_glibtop_linux_get_fsusage_read_write(glibtop *server, - glibtop_fsusage *buf, - const char *path); /* * Linux 2.6.x @@ -127,10 +124,8 @@ static void linux_2_4_0(glibtop *server, glibtop_fsusage *buf, const char *path) } -void -_glibtop_linux_get_fsusage_read_write(glibtop *server, - glibtop_fsusage *buf, - const char *path) +static void +get_fsusage_read_write(glibtop *server, glibtop_fsusage *buf, const char *path) { if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0)) { @@ -141,3 +136,39 @@ _glibtop_linux_get_fsusage_read_write(glibtop *server, linux_2_4_0(server, buf, path); } } + + +/* the following comes from sysdeps/common/mountlist.c if copyright matters... + */ + +static const unsigned long _glibtop_sysdeps_fsusage = +(1L << GLIBTOP_FSUSAGE_BLOCKS) + (1L << GLIBTOP_FSUSAGE_BFREE) ++ (1L << GLIBTOP_FSUSAGE_BAVAIL) + (1L << GLIBTOP_FSUSAGE_FILES) ++ (1L << GLIBTOP_FSUSAGE_FFREE) + (1L << GLIBTOP_FSUSAGE_BLOCK_SIZE); + + + +void +glibtop_get_fsusage_s(glibtop *server, glibtop_fsusage *buf, const char *path) +{ + struct statvfs fsd; + + glibtop_init_r(&server, 0, 0); + memset(buf, 0, sizeof(glibtop_fsusage)); + + if (statvfs(path, &fsd) < 0) { + glibtop_warn_r(server, "statvfs '%s' failed", path); + return; + } + + buf->blocks = fsd.f_blocks; + buf->bfree = fsd.f_bfree; + buf->bavail = (fsd.f_bavail > fsd.f_bfree) ? 0 : fsd.f_bavail; + buf->files = fsd.f_files; + buf->ffree = fsd.f_ffree; + buf->block_size = fsd.f_bsize; + buf->flags = _glibtop_sysdeps_fsusage; + + /* setting additional flags is delegated */ + get_fsusage_read_write(server, buf, path); +}