From 9aae957919df6397ab8db9bbc1dd6cdc7565f589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Fri, 24 Sep 2004 12:59:29 +0000 Subject: [PATCH] ../configure.in Added new example, just like 'df'. * .cvsignore: * Makefile.am: * ../configure.in * df.c: (print_fsusage), (main): Added new example, just like 'df'. --- configure.in | 2 +- examples/.cvsignore | 3 +++ examples/ChangeLog | 7 +++++++ examples/Makefile.am | 13 +++++++++++-- examples/df.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 examples/df.c diff --git a/configure.in b/configure.in index 5e8003a6..2a71714b 100644 --- a/configure.in +++ b/configure.in @@ -123,7 +123,7 @@ else fi if test "x$enable_static" != xno; then - static_targets="first_static second_static mountlist_static procmap_static netload_static sysdeps_static timings_static $smp_static_examples pprint_static procargs_static" + static_targets="first_static second_static mountlist_static procmap_static netload_static sysdeps_static timings_static $smp_static_examples pprint_static procargs_static df_static" else static_targets="" fi diff --git a/examples/.cvsignore b/examples/.cvsignore index 8dcb874c..eb80d17f 100644 --- a/examples/.cvsignore +++ b/examples/.cvsignore @@ -18,3 +18,6 @@ pprint pprint_static procargs procargs_static +df +df_static + diff --git a/examples/ChangeLog b/examples/ChangeLog index e62ffaa7..6bbaeb2f 100644 --- a/examples/ChangeLog +++ b/examples/ChangeLog @@ -1,3 +1,10 @@ +2004-09-24 Benoît Dejean + + * .cvsignore: + * Makefile.am: + * ../configure.in + * df.c: (print_fsusage), (main): Added new example, just like 'df'. + 2004-09-22 Benoît Dejean * pprint.c: (main): Disable pprint_get_msg_limits() because it can fail. diff --git a/examples/Makefile.am b/examples/Makefile.am index 49133396..b68175c0 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -6,7 +6,7 @@ INCLUDES = @INCLUDES@ DEFS = @DEFS@ -noinst_PROGRAMS = first second pprint procargs \ +noinst_PROGRAMS = first second pprint procargs df \ mountlist procmap netload sysdeps timings \ @static_targets@ @smp_examples@ @@ -14,7 +14,8 @@ EXTRA_PROGRAMS = first_static second_static \ mountlist_static procmap_static \ third third_static smp smp_static \ netload_static sysdeps_static \ - timings_static pprint_static procargs_static + timings_static pprint_static procargs_static \ + df_static first_SOURCES = first.c first_LDADD = $(top_builddir)/lib/libgtop-2.0.la @@ -100,3 +101,11 @@ procargs_static_SOURCES = $(procargs_SOURCES) procargs_static_LDADD = $(procargs_LDADD) procargs_static_LDFLAGS = -static + +df_SOURCES = df.c +df_LDADD = $(top_builddir)/lib/libgtop-2.0.la + +df_static_SOURCES = $(df_SOURCES) +df_static_LDADD = $(df_LDADD) +df_static_LDFLAGS = -static + diff --git a/examples/df.c b/examples/df.c new file mode 100644 index 00000000..a590ace2 --- /dev/null +++ b/examples/df.c @@ -0,0 +1,45 @@ +#include + +#include +#include + +#include + + +static void print_fsusage(const char *mountpoint) +{ + glibtop_fsusage buf; + + glibtop_get_fsusage(&buf, mountpoint); + + printf("%-20s %-10llu %-10llu %-10llu %.1f\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 + ); +} + + +int main() +{ + glibtop_mountlist buf; + glibtop_mountentry *entries; + size_t i; + + + printf("%-20s %-10s %-10s %-10s %-10s\n", + "Filesystem", "Size", "Used", "Avail", "Use%"); + + entries = glibtop_get_mountlist(&buf, FALSE); + + for(i = 0; i < buf.number; ++i) + { + print_fsusage(entries[i].mountdir); + } + + g_free(entries); + + return 0; +}