Implemented a linux-only fsusage sysdeps.
svn path=/trunk/; revision=2683
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user