Implemented a linux-only fsusage sysdeps.

svn path=/trunk/; revision=2683
This commit is contained in:
Benoît Dejean
2007-10-17 20:53:53 +00:00
parent f5bbc36a91
commit 8674e92349
3 changed files with 46 additions and 10 deletions

View File

@@ -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)
])

View File

@@ -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)

View File

@@ -1,6 +1,7 @@
#include <config.h>
#include <glibtop.h>
#include <glibtop/fsusage.h>
#include <glibtop/error.h>
#include "glibtop_private.h"
@@ -10,15 +11,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <linux/kdev_t.h>
#include <sys/statvfs.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
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);
}