summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoît Dejean <bdejean@src.gnome.org>2004-07-17 12:04:09 +0000
committerBenoît Dejean <bdejean@src.gnome.org>2004-07-17 12:04:09 +0000
commite5a855db7c639d1e7431c054767046c92f9cf144 (patch)
treeda293cb0fd66fbc4492e64adfedce68bb740c242
parentbfc14a192537818ab4bd89602a80fd22cb90d3b1 (diff)
downloadlibgtop-e5a855db7c639d1e7431c054767046c92f9cf144.tar.gz
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.
-rw-r--r--sysdeps/common/ChangeLog7
-rw-r--r--sysdeps/common/fsusage.c36
-rw-r--r--sysdeps/common/mountlist.c49
3 files changed, 60 insertions, 32 deletions
diff --git a/sysdeps/common/ChangeLog b/sysdeps/common/ChangeLog
index b033f93a..3326f39a 100644
--- a/sysdeps/common/ChangeLog
+++ b/sysdeps/common/ChangeLog
@@ -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>
* Makefile.am:
diff --git a/sysdeps/common/fsusage.c b/sysdeps/common/fsusage.c
index 76bfffe3..6963581f 100644
--- a/sysdeps/common/fsusage.c
+++ b/sysdeps/common/fsusage.c
@@ -109,6 +109,40 @@ static const unsigned long _glibtop_sysdeps_fsusage =
+ (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
glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
const char *path)
@@ -117,6 +151,8 @@ glibtop_get_fsusage_s (glibtop *server, glibtop_fsusage *buf,
memset (buf, 0, sizeof (glibtop_fsusage));
+ _glibtop_get_fsusage_read_write(server, buf, path);
+
#ifdef STAT_STATFS3_OSF1
struct statfs fsd;
diff --git a/sysdeps/common/mountlist.c b/sysdeps/common/mountlist.c
index a5ea88cb..736748da 100644
--- a/sysdeps/common/mountlist.c
+++ b/sysdeps/common/mountlist.c
@@ -96,7 +96,7 @@ static struct mount_entry *read_filesystem_list (gboolean need_fs_type);
#if defined (MOUNTED_GETMNTINFO) && !defined (__NetBSD__) && !defined (__OpenBSD__)
-static char *
+static const char *
fstype_to_string (short t)
{
switch (t)
@@ -192,7 +192,7 @@ fstype_to_string (short t)
#endif /* MOUNTED_GETMNTINFO */
#ifdef MOUNTED_VMOUNT /* AIX. */
-static char *
+static const char *
fstype_to_string (int t)
{
struct vfs_ent *e;
@@ -553,7 +553,9 @@ glibtop_mountentry *
glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
{
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);
@@ -561,37 +563,21 @@ glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
/* Read filesystem list. */
- entries = read_filesystem_list (TRUE);
-
- if (entries == NULL)
+ if((entries = read_filesystem_list (TRUE)) == 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) {
if(all_fs || !ignore_mount_entry(cur)) {
- /* add a new glibtop_mountentry,
- resize mount_list if needed */
-
- if(buf->number == allocated) {
- allocated *= 2;
- mount_list = g_renew(glibtop_mountentry,
- mount_list, allocated);
- }
-
- e = &mount_list[buf->number];
+ /* add a new glibtop_mountentry */
+ glibtop_mountentry 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;
+ 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++;
+ g_array_append_val(mount_array, e);
}
/* free current mount_entry and move to the next */
@@ -602,10 +588,9 @@ glibtop_get_mountlist_s (glibtop *server, glibtop_mountlist *buf, int all_fs)
g_free(cur);
}
- buf->size = sizeof (glibtop_mountentry);
- buf->total = buf->number * buf->size;
- /* trim mount_list */
- mount_list = g_renew(glibtop_mountentry, mount_list, buf->number);
+ buf->size = sizeof (glibtop_mountentry);
+ buf->number = mount_array->len;
+ buf->total = buf->number * buf->size;
- return mount_list;
+ return (glibtop_mountentry*) g_array_free(mount_array, FALSE);
}