changeset 4736:6789961fe02e HEAD

Added support for statvfs(), which is what the newer BSDs use.
author Timo Sirainen <tss@iki.fi>
date Fri, 03 Nov 2006 16:05:21 +0200
parents 186dcdb5ec68
children fd0d7e9e0e72
files configure.in src/lib/mountpoint.c
diffstat 2 files changed, 45 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Fri Nov 03 15:21:42 2006 +0200
+++ b/configure.in	Fri Nov 03 16:05:21 2006 +0200
@@ -1144,6 +1144,40 @@
   AC_MSG_RESULT(no)
 ])
 
+dnl * Check if statvfs() can be used to find out block device for files
+AC_MSG_CHECKING([if statvfs.f_mntfromname exists])
+AC_TRY_COMPILE([
+  #include <sys/types.h>
+  #include <sys/statvfs.h>
+], [
+  struct statvfs buf;
+  char *p = buf.f_mntfromname;
+
+  statvfs(".", &buf);
+], [
+  AC_DEFINE(HAVE_STATVFS_MNTFROMNAME,, Define if you have statvfs.f_mntfromname)
+  AC_MSG_RESULT(yes)
+], [
+  AC_MSG_RESULT(no)
+])
+
+dnl * Check if statvfs() can be used to find out block device for files
+AC_MSG_CHECKING([if statvfs.f_mntfromname exists])
+AC_TRY_COMPILE([
+  #include <sys/types.h>
+  #include <sys/statvfs.h>
+], [
+  struct statvfs buf;
+  char *p = buf.f_mntfromname;
+
+  statvfs(".", &buf);
+], [
+  AC_DEFINE(HAVE_STATVFS_MNTFROMNAME,, Define if you have statvfs.f_mntfromname)
+  AC_MSG_RESULT(yes)
+], [
+  AC_MSG_RESULT(no)
+])
+
 dnl * Check if statfs() can be used to find out block device for files
 AC_MSG_CHECKING([if statfs.f_mntfromname exists])
 AC_TRY_COMPILE([
--- a/src/lib/mountpoint.c	Fri Nov 03 15:21:42 2006 +0200
+++ b/src/lib/mountpoint.c	Fri Nov 03 16:05:21 2006 +0200
@@ -5,9 +5,14 @@
 
 #include <sys/stat.h>
 
-#ifdef HAVE_STATFS_MNTFROMNAME
-#  include <sys/param.h> /* BSDs */
+#ifdef HAVE_STATVFS_MNTFROMNAME
+#  include <sys/statvfs.h> /* NetBSD 3.0+, FreeBSD 5.0+ */
+#  define STATVFS_STR "statvfs"
+#elif HAVE_STATFS_MNTFROMNAME
+#  include <sys/param.h> /* Older BSDs */
 #  include <sys/mount.h>
+#  define statvfs statfs
+#  define STATVFS_STR "statfs"
 #elif defined(HAVE_MNTENT_H)
 #  include <stdio.h>
 #  include <mntent.h> /* Linux */
@@ -38,16 +43,16 @@
 	memset(point_r, 0, sizeof(*point_r));
 	errno = ENOSYS;
 	return -1;
-#elif defined (HAVE_STATFS_MNTFROMNAME)
+#elif defined (HAVE_STATFS_MNTFROMNAME) || defined(HAVE_STATVFS_MNTFROMNAME)
 	/* BSDs */
-	struct statfs buf;
+	struct statvfs buf;
 
 	memset(point_r, 0, sizeof(*point_r));
-	if (statfs(path, &buf) < 0) {
+	if (statvfs(path, &buf) < 0) {
 		if (errno == ENOENT)
 			return 0;
 
-		i_error("statfs(%s) failed: %m", path);
+		i_error(STATVFS_STR"(%s) failed: %m", path);
 		return -1;
 	}