summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoît Dejean <bdejean@src.gnome.org>2008-06-22 09:31:41 +0000
committerBenoît Dejean <bdejean@src.gnome.org>2008-06-22 09:31:41 +0000
commit791e0dd85964dbfcce139e9ebfd5045b773c39d9 (patch)
treedc7200fe79a05e614b53b4abb81a9c71f432a09d
parentf63973eac5846371a9409953f1ddd5714d0eb283 (diff)
downloadlibgtop-791e0dd85964dbfcce139e9ebfd5045b773c39d9.tar.gz
Handle new /sys/block/.../stat format for linux >= 2.6.25.
Closes #539360. svn path=/trunk/; revision=2755
-rw-r--r--sysdeps/linux/fsusage.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/sysdeps/linux/fsusage.c b/sysdeps/linux/fsusage.c
index c6bff2e4..d6fae5a4 100644
--- a/sysdeps/linux/fsusage.c
+++ b/sysdeps/linux/fsusage.c
@@ -59,9 +59,35 @@ get_partition(const char *mountpoint)
}
+/*
+ Bug #539360.
+ /sys/.../stat format is partially defined in
+ linux/Documentation/block/stat.txt (looks outdated). Before linux
+ 2.5.25, /sys/block/%s/stat and /sys/block/%s/%s/stat were not the
+ same, but the following commit changed the latter to have the same
+ format and broke compatibility.
+
+ Commit 34e8beac92c27d292938065f8375842d2840767c
+ Author: Jerome Marchand <jmarchan@redhat.com>
+ Date: Fri Feb 8 11:04:55 2008 +0100
+
+ Enhanced partition statistics: sysfs
+
+ Reports enhanced partition statistics in sysfs.
+
+ Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
+
+ fs/partitions/check.c | 22 +++++++++++++++++++---
+ 1 files changed, 19 insertions(+), 3 deletions(-)
+
+ */
+
static void
-get_sys_path(const char *device, char **stat_path, const char **parse_format)
+get_sys_path(glibtop* server, const char *device, char **stat_path, const char **parse_format)
{
+ const char* linux_2_6_25_format = "%*llu %*llu %llu %*llu"
+ "%*llu %*llu %llu %*llu";
+
if(g_str_has_prefix(device, "hd") || g_str_has_prefix(device, "sd"))
{
char *prefix;
@@ -79,12 +105,18 @@ get_sys_path(const char *device, char **stat_path, const char **parse_format)
g_free(prefix);
*stat_path = path;
- *parse_format = "%*llu %llu %*llu %llu";
+ if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 25))
+ *parse_format = "%*llu %llu %*llu %llu";
+ else
+ *parse_format = linux_2_6_25_format;
}
else
{
*stat_path = g_strdup_printf("/sys/block/%s/stat", device);
- *parse_format = "%*llu %*llu %llu %*llu %*llu %*llu %llu";
+ if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 25))
+ *parse_format = "%*llu %*llu %llu %*llu %*llu %*llu %llu";
+ else
+ *parse_format = linux_2_6_25_format;
}
}
@@ -101,7 +133,7 @@ static void linux_2_6_0(glibtop *server, glibtop_fsusage *buf, const char *path)
device = get_partition(path);
if(!device) return;
- get_sys_path(device, &filename, &format);
+ get_sys_path(server, device, &filename, &format);
g_free(device);
ret = try_file_to_buffer(buffer, sizeof buffer, filename);