$OpenBSD: patch-sysdeps_openbsd_fsusage_c,v 1.3 2014/02/03 13:56:38 ajacoutot Exp $

RM at next release.

--- sysdeps/openbsd/fsusage.c.orig	Sat Jul 27 14:40:23 2013
+++ sysdeps/openbsd/fsusage.c	Mon Feb  3 14:53:26 2014
@@ -2,13 +2,4 @@
 
 #include <config.h>
-
-/*
- * statvfs is lacking various members which are present in statfs,
- * like f_(a)syncreads and f_(a)syncwrites. So eventhough we have
- * statvfs, undef it here untill those members are added.
- */
-#undef HAVE_SYS_STATVFS_H
-#undef STAT_STATVFS
-
 #include <glibtop.h>
 #include <glibtop/error.h>
@@ -21,9 +12,6 @@
 #include <unistd.h>
 #include <sys/param.h>
-#if defined (HAVE_SYS_STATVFS_H)
-#include <sys/statvfs.h>
-#else
 #include <sys/mount.h>
-#endif
+#include <sys/statvfs.h>
 
 #include <stdio.h>
@@ -31,33 +19,49 @@
 #include <stdlib.h>
 
-void
-_glibtop_openbsd_get_fsusage_read_write(glibtop *server,
-				      glibtop_fsusage *buf,
-				      const char *path);
+static const unsigned long _glibtop_sysdeps_fsusage =
+(1L << GLIBTOP_FSUSAGE_BLOCKS) + (1L << GLIBTOP_FSUSAGE_BFREE)
++ (1L << GLIBTOP_FSUSAGE_BAVAIL) + (1L << GLIBTOP_FSUSAGE_FILES)
++ (1L << GLIBTOP_FSUSAGE_FFREE) + (1L << GLIBTOP_FSUSAGE_BLOCK_SIZE);
 
+static void
+_glibtop_get_fsusage_read_write (glibtop *server, glibtop_fsusage *buf, const char *path)
+{
+        int result;
+        struct statfs sfs;
+
+        result = statfs (path, &sfs);
+
+        if (result == -1) {
+                glibtop_warn_io_r (server, "statfs");
+                return;
+        }
+
+        buf->read = sfs.f_syncreads + sfs.f_asyncreads;
+        buf->write = sfs.f_syncwrites + sfs.f_asyncwrites;
+        buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE);
+}
+
 void
-_glibtop_openbsd_get_fsusage_read_write(glibtop *server,
-				      glibtop_fsusage *buf,
-				      const char *path)
+glibtop_get_fsusage_s(glibtop *server, glibtop_fsusage *buf, const char *path)
 {
-	int result;
-#if defined (STAT_STATVFS)
-	struct statvfs sfs;
-#else
-	struct statfs sfs;
-#endif
+	struct statvfs fsd;
 
-#if defined (STAT_STATVFS)
-	result = statvfs (path, &sfs);
-#else
-	result = statfs (path, &sfs);
-#endif
+	glibtop_init_r (&server, 0, 0);
 
-	if (result == -1) {
+	memset (buf, 0, sizeof (glibtop_fsusage));
+
+	if (statvfs (path, &fsd) < 0)
 		return;
-	}
 
-	buf->read = sfs.f_syncreads + sfs.f_asyncreads;
-	buf->write = sfs.f_syncwrites + sfs.f_asyncwrites;
-	buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE);
+	buf->block_size = fsd.f_frsize;
+	buf->blocks = fsd.f_blocks;
+	buf->bfree  = fsd.f_bfree;
+	buf->bavail = (fsd.f_bavail > fsd.f_bfree) ? 0 : fsd.f_bavail;
+	buf->files  = fsd.f_files;
+	buf->ffree  = fsd.f_ffree;
+
+	buf->flags = _glibtop_sysdeps_fsusage;
+
+	_glibtop_get_fsusage_read_write(server, buf, path);
 }
+
