From a29f73349a81fa8d418865b55b9a5a1ddddcfd44 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 1 Jun 2004 10:03:03 +0000 Subject: use statvfs if available. Should make it actually work, if not portable. 2004-06-01 Not Zed * 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. svn path=/trunk/; revision=26139 --- e-util/ChangeLog | 6 ++++++ e-util/e-fsutils.c | 25 +++++++++++++++++++------ 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 + + * 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 * 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 /* 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 /* linux interface */ +#ifdef HAVE_STATVFS +# ifdef HAVE_SYS_STATVFS_H +# include # endif +#else +#ifdef HAVE_STATFS # ifdef HAVE_SYS_PARAM_H # include /* bsd interface */ # endif @@ -40,6 +42,7 @@ # include # endif #endif +#endif #include #include @@ -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; -- cgit