s3: fine tune and clean up statvfs tests
[samba.git] / source3 / smbd / statvfs.c
index 5fc0afdd7987e9f3306fb1dd66df502fedcc41fa..918867f7aad4c8253247ee9298a1241158dde5c7 100644 (file)
 */
 
 #include "includes.h"
-
-#if defined(LINUX) && defined(HAVE_FSID_INT)
-static int linux_statvfs(const char *path, vfs_statvfs_struct *statbuf)
-{
-       struct statvfs statvfs_buf;
-       int result;
-
-       result = statvfs(path, &statvfs_buf);
-
-       if (!result) {
-               statbuf->OptimalTransferSize = statvfs_buf.f_frsize;
-               statbuf->BlockSize = statvfs_buf.f_bsize;
-               statbuf->TotalBlocks = statvfs_buf.f_blocks;
-               statbuf->BlocksAvail = statvfs_buf.f_bfree;
-               statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
-               statbuf->TotalFileNodes = statvfs_buf.f_files;
-               statbuf->FreeFileNodes = statvfs_buf.f_ffree;
-               statbuf->FsIdentifier = statvfs_buf.f_fsid;
-
-               /* Good defaults for Linux filesystems are case sensitive
-                * and case preserving.
-                */
-               statbuf->FsCapabilities =
-                   FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVING_NAMES;
-       }
-       return result;
-}
-#endif
+#include "system/filesys.h"
+#include "smbd/smbd.h"
 
 #if defined(DARWINOS)
 
@@ -118,25 +92,95 @@ static int darwin_statvfs(const char *path, vfs_statvfs_struct *statbuf)
        statbuf->UserBlocksAvail = sbuf.f_bavail;
        statbuf->TotalFileNodes = sbuf.f_files;
        statbuf->FreeFileNodes = sbuf.f_ffree;
-       statbuf->FsIdentifier = *(SMB_BIG_UINT *)(&sbuf.f_fsid); /* Ick. */
+       statbuf->FsIdentifier = *(uint64_t *)(&sbuf.f_fsid); /* Ick. */
        statbuf->FsCapabilities = darwin_fs_capabilities(sbuf.f_mntonname);
 
        return 0;
 }
+#elif defined(BSD_STYLE_STATVFS)
+static int bsd_statvfs(const char *path, vfs_statvfs_struct *statbuf)
+{
+       struct statfs statfs_buf;
+       int result;
+
+       result = statfs(path, &statfs_buf);
+       if (result != 0) {
+               return result;
+       }
+
+       statbuf->OptimalTransferSize = statfs_buf.f_iosize;
+       statbuf->BlockSize = statfs_buf.f_bsize;
+       statbuf->TotalBlocks = statfs_buf.f_blocks;
+       statbuf->BlocksAvail = statfs_buf.f_bfree;
+       statbuf->UserBlocksAvail = statfs_buf.f_bavail;
+       statbuf->TotalFileNodes = statfs_buf.f_files;
+       statbuf->FreeFileNodes = statfs_buf.f_ffree;
+       statbuf->FsIdentifier =
+               (((uint64_t) statfs_buf.f_fsid.val[0] << 32) & 0xffffffff00000000LL) |
+                   (uint64_t) statfs_buf.f_fsid.val[1];
+       /* Try to extrapolate some of the fs flags into the
+        * capabilities
+        */
+       statbuf->FsCapabilities =
+           FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
+#ifdef MNT_ACLS
+       if (statfs_buf.f_flags & MNT_ACLS)
+               statbuf->FsCapabilities |= FILE_PERSISTENT_ACLS;
+#endif
+       if (statfs_buf.f_flags & MNT_QUOTA)
+               statbuf->FsCapabilities |= FILE_VOLUME_QUOTAS;
+       if (statfs_buf.f_flags & MNT_RDONLY)
+               statbuf->FsCapabilities |= FILE_READ_ONLY_VOLUME;
+
+       return 0;
+}
+#elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
+static int linux_statvfs(const char *path, vfs_statvfs_struct *statbuf)
+{
+       struct statvfs statvfs_buf;
+       int result;
+
+       result = statvfs(path, &statvfs_buf);
+
+       if (!result) {
+               statbuf->OptimalTransferSize = statvfs_buf.f_frsize;
+               statbuf->BlockSize = statvfs_buf.f_bsize;
+               statbuf->TotalBlocks = statvfs_buf.f_blocks;
+               statbuf->BlocksAvail = statvfs_buf.f_bfree;
+               statbuf->UserBlocksAvail = statvfs_buf.f_bavail;
+               statbuf->TotalFileNodes = statvfs_buf.f_files;
+               statbuf->FreeFileNodes = statvfs_buf.f_ffree;
+               statbuf->FsIdentifier = statvfs_buf.f_fsid;
+               /* Try to extrapolate some of the fs flags into the
+                * capabilities
+                */
+               statbuf->FsCapabilities =
+                   FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
+#ifdef ST_QUOTA
+               if (statvfs_buf.f_flag & ST_QUOTA)
+                       statbuf->FsCapabilities |= FILE_VOLUME_QUOTAS;
+#endif
+               if (statvfs_buf.f_flag & ST_RDONLY)
+                       statbuf->FsCapabilities |= FILE_READ_ONLY_VOLUME;
+       }
+       return result;
+}
 #endif
 
 /* 
  sys_statvfs() is an abstraction layer over system-dependent statvfs()/statfs()
  for particular POSIX systems. Due to controversy of what is considered more important
  between LSB and FreeBSD/POSIX.1 (IEEE Std 1003.1-2001) we need to abstract the interface
- so that particular OS would use its preffered interface.
+ so that particular OS would use its prefered interface.
 */
 int sys_statvfs(const char *path, vfs_statvfs_struct *statbuf)
 {
-#if defined(LINUX) && defined(HAVE_FSID_INT)
-       return linux_statvfs(path, statbuf);
-#elif defined(DARWINOS)
+#if defined(DARWINOS)
        return darwin_statvfs(path, statbuf);
+#elif defined(BSD_STYLE_STATVFS)
+       return bsd_statvfs(path, statbuf);
+#elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
+       return linux_statvfs(path, statbuf);
 #else
        /* BB change this to return invalid level */
 #ifdef EOPNOTSUPP