aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--e-util/ChangeLog6
-rw-r--r--e-util/e-fsutils.c25
2 files changed, 25 insertions, 6 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog
index d86523f096..33fe654c81 100644
--- a/e-util/ChangeLog
+++ b/e-util/ChangeLog
@@ -1,3 +1,9 @@
+2004-06-01 Not Zed <NotZed@Ximian.com>
+
+ * e-fsutils.c (e_fsutils_avail): use statvfs if available. Should
+ make it actually work, if not portable. This is for a bug but I
+ can't recall the number.
+
2004-05-27 Rodney Dawes <dobey@novell.com>
* Makefile.am (dist-hook): Require e-error-tool
diff --git a/e-util/e-fsutils.c b/e-util/e-fsutils.c
index d2c615124b..923dd5ec42 100644
--- a/e-util/e-fsutils.c
+++ b/e-util/e-fsutils.c
@@ -29,10 +29,12 @@
#include <dirent.h>
/* This isn't as portable as, say, the stuff in GNU coreutils. But I care not for OSF1. */
-#ifdef HAVE_STATFS
-# ifdef HAVE_SYS_VFS_H
-# include <sys/vfs.h> /* linux interface */
+#ifdef HAVE_STATVFS
+# ifdef HAVE_SYS_STATVFS_H
+# include <sys/statvfs.h>
# endif
+#else
+#ifdef HAVE_STATFS
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h> /* bsd interface */
# endif
@@ -40,6 +42,7 @@
# include <sys/mount.h>
# endif
#endif
+#endif
#include <errno.h>
#include <string.h>
@@ -128,14 +131,24 @@ fail:
long
e_fsutils_avail(const char *path)
{
-#ifdef HAVE_STATFS
+#if defined(HAVE_STATVFS)
+ struct statvfs stfs;
+
+ if (statvfs(path, &stfs) == -1)
+ return -1;
+
+ /* Assumes that frsize === power of 2 */
+ if (stfs.f_frsize >= 1024)
+ return stfs.f_bavail * (stfs.f_frsize / 1024);
+ else
+ return stfs.f_bavail / (1024 / stfs.f_frsize);
+#elif defined(HAVE_STATFS)
struct statfs stfs;
if (statfs(path, &stfs) == -1)
return -1;
- /* On linux at least, bavail is in 512 byte blocks */
- /* For BSD this isn't clear, it may be dependent on f_bsize, which on linux is rather, the page size! */
+ /* For BSD this isn't clear, it may be dependent on f_bsize */
return stfs.f_bavail / 2;
#else
errno = ENOSYS;