]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Factor out initializing vfs_statvfs_struct from system info
authorVolker Lendecke <vl@samba.org>
Sun, 23 Nov 2025 06:52:46 +0000 (07:52 +0100)
committerAnoop C S <anoopcs@samba.org>
Sun, 15 Feb 2026 10:42:33 +0000 (10:42 +0000)
Patch is a bit confusing due to all the #ifdefs, but it's just some
code shuffling to prepare for the next patch.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/smbd/statvfs.c

index 9002e5a10ee48b89c475bd74c25c934e9edb9393..064c6ac02f8d27b5bed0616d988c54eb64d5a82a 100644 (file)
@@ -77,79 +77,84 @@ static int darwin_fs_capabilities(const char * path)
 #endif /* DARWINOS */
 
 #if defined(BSD_STYLE_STATVFS)
-static int bsd_statvfs(const char *path, struct vfs_statvfs_struct *statbuf)
-{
-       struct statfs sbuf;
-       int ret;
-
-       ret = statfs(path, &sbuf);
-       if (ret != 0) {
-               return ret;
-       }
 
-       statbuf->OptimalTransferSize = sbuf.f_iosize;
-       statbuf->BlockSize = sbuf.f_bsize;
-       statbuf->TotalBlocks = sbuf.f_blocks;
-       statbuf->BlocksAvail = sbuf.f_bfree;
-       statbuf->UserBlocksAvail = sbuf.f_bavail;
-       statbuf->TotalFileNodes = sbuf.f_files;
-       statbuf->FreeFileNodes = sbuf.f_ffree;
-       statbuf->FsIdentifier =
-               (((uint64_t) sbuf.f_fsid.val[0] << 32) & 0xffffffff00000000LL) |
-               (uint64_t) sbuf.f_fsid.val[1];
+static void bsd_init_statvfs(const struct statvfs *src,
+                            struct vfs_statvfs_struct *dst)
+{
+       dst->OptimalTransferSize = src->f_iosize;
+       dst->BlockSize = src->f_bsize;
+       dst->TotalBlocks = src->f_blocks;
+       dst->BlocksAvail = src->f_bfree;
+       dst->UserBlocksAvail = src->f_bavail;
+       dst->TotalFileNodes = src->f_files;
+       dst->FreeFileNodes = src->f_ffree;
+       dst->FsIdentifier = (((uint64_t)src->f_fsid.val[0] << 32) &
+                            0xffffffff00000000LL) |
+                           (uint64_t)src->f_fsid.val[1];
 #ifdef DARWINOS
-       statbuf->FsCapabilities = darwin_fs_capabilities(sbuf.f_mntonname);
+       dst->FsCapabilities = darwin_fs_capabilities(src->f_mntonname);
 #else
        /* Try to extrapolate some of the fs flags into the
         * capabilities
         */
-       statbuf->FsCapabilities =
-               FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
+       dst->FsCapabilities = FILE_CASE_SENSITIVE_SEARCH |
+                             FILE_CASE_PRESERVED_NAMES;
 #ifdef MNT_ACLS
-       if (sbuf.f_flags & MNT_ACLS)
-               statbuf->FsCapabilities |= FILE_PERSISTENT_ACLS;
+       if (src->f_flags & MNT_ACLS) {
+               dst->FsCapabilities |= FILE_PERSISTENT_ACLS;
+       }
 #endif
 #endif
-       if (sbuf.f_flags & MNT_QUOTA)
-               statbuf->FsCapabilities |= FILE_VOLUME_QUOTAS;
-       if (sbuf.f_flags & MNT_RDONLY)
-               statbuf->FsCapabilities |= FILE_READ_ONLY_VOLUME;
-
-       return 0;
+       if (src->f_flags & MNT_QUOTA) {
+               dst->FsCapabilities |= FILE_VOLUME_QUOTAS;
+       }
+       if (src->f_flags & MNT_RDONLY) {
+               dst->FsCapabilities |= FILE_READ_ONLY_VOLUME;
+       }
 }
-#elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
-static int posix_statvfs(const char *path, struct vfs_statvfs_struct *statbuf)
+
+static int bsd_statvfs(const char *path, struct vfs_statvfs_struct *statbuf)
 {
-       struct statvfs statvfs_buf;
+       struct statfs sbuf;
        int ret;
 
-       ret = statvfs(path, &statvfs_buf);
-
+       ret = statfs(path, &sbuf);
        if (ret != 0) {
                return ret;
        }
 
+       bsd_init_statvfs(&sbuf, statbuf);
+
+       return 0;
+}
+#elif defined(STAT_STATVFS) && defined(HAVE_FSID_INT)
+
+static void posix_init_statvfs(const struct statvfs *src,
+                              struct vfs_statvfs_struct *dst)
+{
        /* statvfs bsize is not the statfs bsize, the naming is terrible,
         * see bug 11810 */
-       statbuf->OptimalTransferSize = statvfs_buf.f_bsize;
-       statbuf->BlockSize = statvfs_buf.f_frsize;
-       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;
+       dst->OptimalTransferSize = src->f_bsize;
+       dst->BlockSize = src->f_frsize;
+       dst->TotalBlocks = src->f_blocks;
+       dst->BlocksAvail = src->f_bfree;
+       dst->UserBlocksAvail = src->f_bavail;
+       dst->TotalFileNodes = src->f_files;
+       dst->FreeFileNodes = src->f_ffree;
+       dst->FsIdentifier = src->f_fsid;
        /* Try to extrapolate some of the fs flags into the
         * capabilities
         */
-       statbuf->FsCapabilities =
-               FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
+       dst->FsCapabilities = FILE_CASE_SENSITIVE_SEARCH |
+                             FILE_CASE_PRESERVED_NAMES;
 #ifdef ST_QUOTA
-       if (statvfs_buf.f_flag & ST_QUOTA)
-               statbuf->FsCapabilities |= FILE_VOLUME_QUOTAS;
+       if (src->f_flag & ST_QUOTA) {
+               dst->FsCapabilities |= FILE_VOLUME_QUOTAS;
+       }
 #endif
-       if (statvfs_buf.f_flag & ST_RDONLY)
-               statbuf->FsCapabilities |= FILE_READ_ONLY_VOLUME;
+       if (src->f_flag & ST_RDONLY) {
+               dst->FsCapabilities |= FILE_READ_ONLY_VOLUME;
+       }
 
 #if defined(HAVE_FALLOC_FL_PUNCH_HOLE) && defined(HAVE_LSEEK_HOLE_DATA)
        /*
@@ -157,8 +162,23 @@ static int posix_statvfs(const char *path, struct vfs_statvfs_struct *statbuf)
         * deallocate blocks, and SEEK_HOLE / SEEK_DATA can be used
         * to provide QUERY_ALLOCATED_RANGES information.
         */
-       statbuf->FsCapabilities |= FILE_SUPPORTS_SPARSE_FILES;
+       dst->FsCapabilities |= FILE_SUPPORTS_SPARSE_FILES;
 #endif
+}
+
+static int posix_statvfs(const char *path, struct vfs_statvfs_struct *statbuf)
+{
+       struct statvfs statvfs_buf;
+       int ret;
+
+       ret = statvfs(path, &statvfs_buf);
+
+       if (ret != 0) {
+               return ret;
+       }
+
+       posix_init_statvfs(&statvfs_buf, statbuf);
+
        return 0;
 }
 #endif