Compare commits
6 Commits
LIBGTOP_2_
...
LIBGTOP_2_
Author | SHA1 | Date | |
---|---|---|---|
|
91b7ae4b11 | ||
|
ce23ce407c | ||
|
7f779e078d | ||
|
229eab1213 | ||
|
791e0dd859 | ||
|
f63973eac5 |
6
NEWS
6
NEWS
@@ -1,3 +1,9 @@
|
||||
23 June 2008: Overview of changes in 2.23.4
|
||||
===========================================
|
||||
* linux:
|
||||
- Fixed and improved glibtop_get_fsusage with kernel >= 2.6.25.
|
||||
Closes #539360.
|
||||
|
||||
24 May 2008: Overview of changes in 2.23.2
|
||||
==========================================
|
||||
* glibtop_get_proc_open_files API can also lists IPv6 TCP sockets.
|
||||
|
@@ -4,7 +4,7 @@ dnl
|
||||
|
||||
m4_define([libgtop_major_version], [2])
|
||||
m4_define([libgtop_minor_version], [23])
|
||||
m4_define([libgtop_micro_version], [2])
|
||||
m4_define([libgtop_micro_version], [4])
|
||||
m4_define([libgtop_version], [libgtop_major_version.libgtop_minor_version.libgtop_micro_version])
|
||||
|
||||
dnl increment if the interface has additions, changes, removals.
|
||||
|
@@ -15,35 +15,43 @@ static void print_fsusage(const char *mountpoint)
|
||||
|
||||
glibtop_get_fsusage(&buf, mountpoint);
|
||||
|
||||
printf("%-20s %-10llu %-10llu %-10llu %.1f\n",
|
||||
printf("%-30s %10llu %10llu %10llu %5.1f %10llu %10llu\n",
|
||||
mountpoint,
|
||||
buf.blocks * buf.block_size >> 20,
|
||||
(buf.blocks - buf.bavail) * buf.block_size >> 20,
|
||||
buf.bavail * buf.block_size >> 20,
|
||||
(buf.blocks - buf.bavail) * 100.0 / buf.blocks
|
||||
(buf.blocks - buf.bavail) * 100.0 / (buf.blocks ? buf.blocks : 1.0),
|
||||
buf.read,
|
||||
buf.write
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glibtop_mountlist buf;
|
||||
glibtop_mountentry *entries;
|
||||
size_t i;
|
||||
|
||||
glibtop_init();
|
||||
|
||||
printf("%-20s %-10s %-10s %-10s %-10s\n",
|
||||
"Filesystem", "Size", "Used", "Avail", "Use%");
|
||||
printf("%-30s %10s %10s %10s %5s %10s %10s\n",
|
||||
"Filesystem", "Size", "Used", "Avail", "Use%", "Read", "Write");
|
||||
|
||||
entries = glibtop_get_mountlist(&buf, TRUE);
|
||||
if (argc > 1) {
|
||||
while (*++argv)
|
||||
print_fsusage(*argv);
|
||||
} else {
|
||||
glibtop_mountentry *entries;
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < buf.number; ++i)
|
||||
{
|
||||
print_fsusage(entries[i].mountdir);
|
||||
}
|
||||
entries = glibtop_get_mountlist(&buf, TRUE);
|
||||
|
||||
g_free(entries);
|
||||
for(i = 0; i < buf.number; ++i)
|
||||
{
|
||||
print_fsusage(entries[i].mountdir);
|
||||
}
|
||||
|
||||
g_free(entries);
|
||||
}
|
||||
|
||||
glibtop_close();
|
||||
|
||||
|
@@ -1,3 +1,7 @@
|
||||
2008-06-11 Djihed Afifi <djihed@gmail.com>
|
||||
|
||||
* ar.po: Updated Arabic Translation by Khaled Hosny.
|
||||
|
||||
2008-05-22 Djihed Afifi <djihed@gmail.com>
|
||||
|
||||
* ar.po: Updated Arabic Translation by Khaled Hosny.
|
||||
|
@@ -15,6 +15,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <mntent.h>
|
||||
|
||||
|
||||
/*
|
||||
@@ -25,66 +26,102 @@
|
||||
|
||||
|
||||
|
||||
static char *
|
||||
get_partition(const char *mountpoint)
|
||||
static gboolean
|
||||
get_device(glibtop* server, const char *mountpoint,
|
||||
char* device, size_t device_size)
|
||||
{
|
||||
FILE *partitions;
|
||||
char *name = NULL;
|
||||
char line[1024];
|
||||
struct stat statb;
|
||||
const struct mntent *mnt;
|
||||
FILE *fp;
|
||||
gboolean found = FALSE;
|
||||
|
||||
if(stat(mountpoint, &statb) == -1)
|
||||
return NULL;
|
||||
|
||||
if((partitions = fopen("/proc/partitions", "r")) == NULL)
|
||||
return NULL;
|
||||
|
||||
while(fgets(line, sizeof line, partitions))
|
||||
{
|
||||
unsigned major, minor;
|
||||
char dev[32];
|
||||
|
||||
if(sscanf(line, "%u %u %*u %31s", &major, &minor, dev) != 3)
|
||||
continue;
|
||||
|
||||
if(MKDEV(major, minor) != statb.st_dev)
|
||||
continue;
|
||||
|
||||
name = g_strdup(dev);
|
||||
break;
|
||||
if (!(fp = setmntent(MOUNTED, "r"))) {
|
||||
glibtop_warn_io_r(server, "Could not open %s", MOUNTED);
|
||||
goto out;
|
||||
}
|
||||
|
||||
fclose(partitions);
|
||||
return name;
|
||||
while ((mnt = getmntent(fp)))
|
||||
{
|
||||
if (!strcmp(mountpoint, mnt->mnt_dir)) {
|
||||
if (!strncmp(mnt->mnt_fsname, "/dev/", 5)) {
|
||||
g_strlcpy(device, mnt->mnt_fsname + 5, device_size);
|
||||
found = TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
endmntent(fp);
|
||||
out:
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
get_sys_path(const char *device, char **stat_path, const char **parse_format)
|
||||
/*
|
||||
TRUE if device is like "hda3" and then set prefix to "hda".
|
||||
*/
|
||||
static gboolean
|
||||
is_partition(const char* device, char* prefix, size_t prefix_size)
|
||||
{
|
||||
if(g_str_has_prefix(device, "hd") || g_str_has_prefix(device, "sd"))
|
||||
{
|
||||
char *prefix;
|
||||
char *path;
|
||||
size_t offset;
|
||||
g_strlcpy(prefix, device, prefix_size);
|
||||
|
||||
offset = strcspn(device, "0123456789");
|
||||
for ( ; *prefix; prefix++) {
|
||||
if (isdigit(*prefix)) {
|
||||
*prefix = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
prefix = g_strdup(device);
|
||||
prefix [offset] = '\0';
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
path = g_strdup_printf("/sys/block/%s/%s/stat",
|
||||
prefix, device);
|
||||
|
||||
g_free(prefix);
|
||||
/*
|
||||
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.
|
||||
|
||||
*stat_path = path;
|
||||
*parse_format = "%*llu %llu %*llu %llu";
|
||||
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(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";
|
||||
|
||||
char prefix[32];
|
||||
|
||||
if (is_partition(device, prefix, sizeof prefix)) {
|
||||
|
||||
*stat_path = g_strdup_printf("/sys/block/%s/%s/stat",
|
||||
prefix, device);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,17 +129,16 @@ get_sys_path(const char *device, char **stat_path, const char **parse_format)
|
||||
|
||||
static void linux_2_6_0(glibtop *server, glibtop_fsusage *buf, const char *path)
|
||||
{
|
||||
char *device;
|
||||
char *filename;
|
||||
const char *format;
|
||||
int ret;
|
||||
char buffer[BUFSIZ];
|
||||
char device[64];
|
||||
|
||||
device = get_partition(path);
|
||||
if(!device) return;
|
||||
if (!get_device(server, path, device, sizeof device))
|
||||
return;
|
||||
|
||||
get_sys_path(device, &filename, &format);
|
||||
g_free(device);
|
||||
get_sys_path(server, device, &filename, &format);
|
||||
|
||||
ret = try_file_to_buffer(buffer, sizeof buffer, filename);
|
||||
|
||||
|
Reference in New Issue
Block a user