Started implementation of read, write. Code should be splitted into arch

* fsusage.c: (glibtop_get_fsusage_s): Started implementation of read, write.
	Code should be splitted into arch specific files.

	* mountlist.c: (glibtop_get_mountlist_s): glibify. Used GArray.
This commit is contained in:
Benoît Dejean
2004-07-17 12:04:09 +00:00
parent bfc14a1925
commit e5a855db7c
3 changed files with 60 additions and 32 deletions

View File

@@ -1,3 +1,10 @@
2004-07-17 Benoît Dejean <tazforever@dlfp.org>
* fsusage.c: (glibtop_get_fsusage_s): Started implementation of read, write.
Code should be splitted into arch specific files.
* mountlist.c: (glibtop_get_mountlist_s): glibify. Used GArray.
2004-07-07 Benoît Dejean <tazforever@dlfp.org> 2004-07-07 Benoît Dejean <tazforever@dlfp.org>
* Makefile.am: * Makefile.am:

View File

@@ -109,6 +109,40 @@ static const unsigned long _glibtop_sysdeps_fsusage =
+ (1L << GLIBTOP_FSUSAGE_FFREE) + (1L << GLIBTOP_FSUSAGE_BLOCK_SIZE); + (1L << GLIBTOP_FSUSAGE_FFREE) + (1L << GLIBTOP_FSUSAGE_BLOCK_SIZE);
/*
* _glibtop_get_fsusage_read_write
* New function to retrieve total read and write
*
* Each arch should have its own function()
* and the proper #define. This is more readable than one single
* function full of #something where everything is mixed.
* These functions are private.
*
* void _glibtop_<arch>_get_fsusage_read_write(glibtop*server,
* glibtop_fsusage *buf,
* const char *path);
*
* TODO: split this file properly, is possible
*/
#ifdef linux
void _glibtop_linux_get_fsusage_read_write(glibtop *server,
glibtop_fsusage *buf,
const char *path);
#define _glibtop_get_fsusage_read_write(S, B, P) \
_glibtop_linux_get_fsusage_read_write(S, B, P)
#else /* default fallback */
#define _glibtop_get_fsusage_read_write(S, B, P) ((void)0)
#endif
/* end _glibtop_get_fsusage_read_write */
void void
glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf, glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
const char *path) const char *path)
@@ -117,6 +151,8 @@ glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
memset (buf, 0, sizeof (glibtop_fsusage)); memset (buf, 0, sizeof (glibtop_fsusage));
_glibtop_get_fsusage_read_write(server, buf, path);
#ifdef STAT_STATFS3_OSF1 #ifdef STAT_STATFS3_OSF1
struct statfs fsd; struct statfs fsd;

View File

@@ -96,7 +96,7 @@ static struct mount_entry *read_filesystem_list (gboolean need_fs_type);
#if defined (MOUNTED_GETMNTINFO) && !defined (__NetBSD__) && !defined (__OpenBSD__) #if defined (MOUNTED_GETMNTINFO) && !defined (__NetBSD__) && !defined (__OpenBSD__)
static char * static const char *
fstype_to_string (short t) fstype_to_string (short t)
{ {
switch (t) switch (t)
@@ -192,7 +192,7 @@ fstype_to_string (short t)
#endif /* MOUNTED_GETMNTINFO */ #endif /* MOUNTED_GETMNTINFO */
#ifdef MOUNTED_VMOUNT /* AIX. */ #ifdef MOUNTED_VMOUNT /* AIX. */
static char * static const char *
fstype_to_string (int t) fstype_to_string (int t)
{ {
struct vfs_ent *e; struct vfs_ent *e;
@@ -553,7 +553,9 @@ glibtop_mountentry *
glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs) glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
{ {
struct mount_entry *entries, *cur, *next; struct mount_entry *entries, *cur, *next;
glibtop_mountentry *mount_list, *e;
GArray *mount_array = g_array_new(FALSE, FALSE,
sizeof(glibtop_mountentry));
glibtop_init_r (&server, 0, 0); glibtop_init_r (&server, 0, 0);
@@ -561,37 +563,21 @@ glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
/* Read filesystem list. */ /* Read filesystem list. */
entries = read_filesystem_list (TRUE); if((entries = read_filesystem_list (TRUE)) == NULL)
if (entries == NULL)
return NULL; return NULL;
buf->number = 0;
gsize allocated = 16; /* magic */
mount_list = g_new(glibtop_mountentry, allocated);
for (cur = &entries[0]; cur != NULL; cur = next) { for (cur = &entries[0]; cur != NULL; cur = next) {
if(all_fs || !ignore_mount_entry(cur)) { if(all_fs || !ignore_mount_entry(cur)) {
/* add a new glibtop_mountentry, /* add a new glibtop_mountentry */
resize mount_list if needed */ glibtop_mountentry e;
if(buf->number == allocated) { g_strlcpy(e.devname, cur->me_devname, sizeof e.devname);
allocated *= 2; g_strlcpy(e.mountdir, cur->me_mountdir, sizeof e.mountdir);
mount_list = g_renew(glibtop_mountentry, g_strlcpy(e.type, cur->me_type, sizeof e.type);
mount_list, allocated); e.dev = cur->me_dev;
}
e = &mount_list[buf->number]; g_array_append_val(mount_array, e);
g_strlcpy(e->devname, cur->me_devname, sizeof e->devname);
g_strlcpy(e->mountdir, cur->me_mountdir, sizeof e->mountdir);
g_strlcpy(e->type, cur->me_type, sizeof e->type);
e->dev = cur->me_dev;
buf->number++;
} }
/* free current mount_entry and move to the next */ /* free current mount_entry and move to the next */
@@ -603,9 +589,8 @@ glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
} }
buf->size = sizeof (glibtop_mountentry); buf->size = sizeof (glibtop_mountentry);
buf->number = mount_array->len;
buf->total = buf->number * buf->size; buf->total = buf->number * buf->size;
/* trim mount_list */
mount_list = g_renew(glibtop_mountentry, mount_list, buf->number);
return mount_list; return (glibtop_mountentry*) g_array_free(mount_array, FALSE);
} }