]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbserver: Convert callers of sys_fsusage to sys_statvfs
authorVolker Lendecke <vl@samba.org>
Fri, 23 Jan 2026 17:52:00 +0000 (18:52 +0100)
committerAnoop C S <anoopcs@samba.org>
Sun, 15 Feb 2026 10:42:34 +0000 (10:42 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/modules/vfs_default.c
source3/modules/vfs_gpfs.c
source3/printing/printing.c
source4/ntvfs/posix/pvfs_fsinfo.c
source4/ntvfs/simple/vfs_simple.c

index 629750b2cfd999571ec47fb1fdc7952f553446c8..03080e62799f5ab44dab84f26888a90630e85fbd 100644 (file)
@@ -105,10 +105,14 @@ static uint64_t vfswrap_disk_free(vfs_handle_struct *handle,
                                  uint64_t *dsize)
 {
        const struct smb_filename *smb_fname = fsp->fsp_name;
+       struct vfs_statvfs_struct statvfsbuf;
+       int ret;
 
-       if (sys_fsusage(smb_fname->base_name, dfree, dsize) != 0) {
+       ret = sys_statvfs(smb_fname->base_name, &statvfsbuf);
+       if (ret != 0) {
                return (uint64_t)-1;
        }
+       statvfs2fsusage(&statvfsbuf, dfree, dsize);
 
        *bsize = 512;
        return *dfree / 2;
index aa297cfe0d8871faea841cae660338ff9276bb7d..882d40569659ced7ae3486bd003191f83a81f3d6 100644 (file)
@@ -32,6 +32,7 @@
 #include "lib/util/tevent_unix.h"
 #include "lib/pthreadpool/pthreadpool_tevent.h"
 #include "lib/util/gpfswrap.h"
+#include "lib/util/statvfs.h"
 
 #include <gnutls/gnutls.h>
 #include <gnutls/crypto.h>
@@ -2321,6 +2322,7 @@ static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle,
        struct security_unix_token *utok;
        struct gpfs_quotaInfo qi_user = { 0 }, qi_group = { 0 };
        struct gpfs_config_data *config;
+       struct vfs_statvfs_struct statvfsbuf;
        int err;
        time_t cur_time;
 
@@ -2331,14 +2333,16 @@ static uint64_t vfs_gpfs_disk_free(vfs_handle_struct *handle,
                        handle, fsp, bsize, dfree, dsize);
        }
 
-       err = sys_fsusage(smb_fname->base_name, dfree, dsize);
+       err = sys_statvfs(smb_fname->base_name, &statvfsbuf);
        if (err) {
                DEBUG (0, ("Could not get fs usage, errno %d\n", errno));
                return SMB_VFS_NEXT_DISK_FREE(
                        handle, fsp, bsize, dfree, dsize);
        }
 
-       /* sys_fsusage returns units of 512 bytes */
+       statvfs2fsusage(&statvfsbuf, dfree, dsize);
+
+       /* statvfs2fsusage returns units of 512 bytes */
        *bsize = 512;
 
        DEBUG(10, ("fs dfree %llu, dsize %llu\n",
index 3afc373398353299db039fbb0f336b8166917ba9..d92ebd04a552e06d71af5c7575714a57d4259a15 100644 (file)
@@ -42,6 +42,7 @@
 #include "lib/global_contexts.h"
 #include "source3/printing/rap_jobid.h"
 #include "source3/lib/substitute.h"
+#include "lib/util/statvfs.h"
 
 #define CACHE_LAST_SCAN_TIME "CACHE"
 #define MSG_PENDING_TIME "MSG_PENDING"
@@ -2559,8 +2560,6 @@ static WERROR print_job_checks(const struct auth_session_info *server_info,
        const char *sharename = lp_const_servicename(snum);
        const struct loadparm_substitution *lp_sub =
                loadparm_s3_global_substitution();
-       uint64_t dspace, dsize;
-       uint64_t minspace;
        int ret;
 
        if (!W_ERROR_IS_OK(print_access_check(server_info, msg_ctx, snum,
@@ -2578,12 +2577,19 @@ static WERROR print_job_checks(const struct auth_session_info *server_info,
 
        /* see if we have sufficient disk space */
        if (lp_min_print_space(snum)) {
-               minspace = lp_min_print_space(snum);
-               ret = sys_fsusage(lp_path(talloc_tos(), lp_sub, snum), &dspace, &dsize);
-               if (ret == 0 && dspace < 2*minspace) {
-                       DEBUG(3, ("print_job_checks: "
-                                 "disk space check failed.\n"));
-                       return WERR_NO_SPOOL_SPACE;
+               struct vfs_statvfs_struct buf;
+               uint64_t minspace = lp_min_print_space(snum);
+
+               ret = sys_statvfs(lp_path(talloc_tos(), lp_sub, snum), &buf);
+               if (ret == 0) {
+                       uint64_t dspace, dsize;
+
+                       statvfs2fsusage(&buf, &dspace, &dsize);
+
+                       if (dspace < 2 * minspace) {
+                               DBG_NOTICE("disk space check failed.\n");
+                               return WERR_NO_SPOOL_SPACE;
+                       }
                }
        }
 
index c355c19b3000efcd5c85dd766dd2044630f3ac6a..378773f34d33e87e2b70f1299bf3fae1b74a6340 100644 (file)
@@ -23,6 +23,7 @@
 #include "vfs_posix.h"
 #include "librpc/gen_ndr/xattr.h"
 #include "librpc/ndr/libndr.h"
+#include "lib/util/statvfs.h"
 
 /* We use libblkid out of e2fsprogs to identify UUID of a volume */
 #ifdef HAVE_LIBBLKID
@@ -92,17 +93,24 @@ NTSTATUS pvfs_fsinfo(struct ntvfs_module_context *ntvfs,
        struct stat st;
        const uint16_t block_size = 512;
 
-       /* only some levels need the expensive sys_fsusage() call */
+       /* only some levels need the expensive sys_statvfs() call */
        switch (fs->generic.level) {
        case RAW_QFS_DSKATTR:
        case RAW_QFS_ALLOCATION:
        case RAW_QFS_SIZE_INFO:
        case RAW_QFS_SIZE_INFORMATION:
-       case RAW_QFS_FULL_SIZE_INFORMATION:
-               if (sys_fsusage(pvfs->base_directory, &blocks_free, &blocks_total) == -1) {
+       case RAW_QFS_FULL_SIZE_INFORMATION: {
+               struct vfs_statvfs_struct statvfsbuf;
+               int ret;
+
+               ret = sys_statvfs(pvfs->base_directory, &statvfsbuf);
+               if (ret == -1) {
                        return pvfs_map_errno(pvfs, errno);
                }
+               statvfs2fsusage(&statvfsbuf, &blocks_free, &blocks_total);
+
                break;
+       }
        default:
                break;
        }
index 794f06d3e06e612d8cdbc39a31dbe2e7a18f431b..6df1c7703eddabc6a0de95bada9899fdeb19737b 100644 (file)
@@ -33,6 +33,7 @@
 #include "../lib/util/dlinklist.h"
 #include "ntvfs/ntvfs.h"
 #include "ntvfs/simple/proto.h"
+#include "lib/util/statvfs.h"
 
 #ifndef O_DIRECTORY
 #define O_DIRECTORY 0
@@ -781,18 +782,23 @@ static NTSTATUS svfs_fsinfo(struct ntvfs_module_context *ntvfs,
                            struct ntvfs_request *req, union smb_fsinfo *fs)
 {
        struct svfs_private *p = ntvfs->private_data;
+       struct vfs_statvfs_struct statvfsbuf;
        struct stat st;
+       int ret;
 
        if (fs->generic.level != RAW_QFS_GENERIC) {
                return ntvfs_map_fsinfo(ntvfs, req, fs);
        }
 
-       if (sys_fsusage(p->connectpath,
-                       &fs->generic.out.blocks_free, 
-                       &fs->generic.out.blocks_total) == -1) {
+       ret = sys_statvfs(p->connectpath, &statvfsbuf);
+       if (ret == -1) {
                return map_nt_error_from_unix_common(errno);
        }
 
+       statvfs2fsusage(&statvfsbuf,
+                       &fs->generic.out.blocks_free,
+                       &fs->generic.out.blocks_total);
+
        fs->generic.out.block_size = 512;
 
        if (stat(p->connectpath, &st) != 0) {