From: Volker Lendecke Date: Fri, 23 Jan 2026 17:52:00 +0000 (+0100) Subject: smbserver: Convert callers of sys_fsusage to sys_statvfs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=268f02773363ea80122166a95f3748c1fe76b34c;p=thirdparty%2Fsamba.git smbserver: Convert callers of sys_fsusage to sys_statvfs Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 629750b2cfd..03080e62799 100644 --- a/source3/modules/vfs_default.c +++ b/source3/modules/vfs_default.c @@ -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; diff --git a/source3/modules/vfs_gpfs.c b/source3/modules/vfs_gpfs.c index aa297cfe0d8..882d4056965 100644 --- a/source3/modules/vfs_gpfs.c +++ b/source3/modules/vfs_gpfs.c @@ -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 #include @@ -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", diff --git a/source3/printing/printing.c b/source3/printing/printing.c index 3afc3733983..d92ebd04a55 100644 --- a/source3/printing/printing.c +++ b/source3/printing/printing.c @@ -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; + } } } diff --git a/source4/ntvfs/posix/pvfs_fsinfo.c b/source4/ntvfs/posix/pvfs_fsinfo.c index c355c19b300..378773f34d3 100644 --- a/source4/ntvfs/posix/pvfs_fsinfo.c +++ b/source4/ntvfs/posix/pvfs_fsinfo.c @@ -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; } diff --git a/source4/ntvfs/simple/vfs_simple.c b/source4/ntvfs/simple/vfs_simple.c index 794f06d3e06..6df1c7703ed 100644 --- a/source4/ntvfs/simple/vfs_simple.c +++ b/source4/ntvfs/simple/vfs_simple.c @@ -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) {