From: Volker Lendecke Date: Tue, 13 Jan 2026 21:06:06 +0000 (+0100) Subject: smbd: Factor out handling of dfree command into a separate function X-Git-Tag: tdb-1.4.15~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f6d5b79d536aa50951c3efa8326e32391c30f2f;p=thirdparty%2Fsamba.git smbd: Factor out handling of dfree command into a separate function Will enable code simplifications with early returns Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/smbd/dfree.c b/source3/smbd/dfree.c index cdfeedfaddc..1becfcc5dc3 100644 --- a/source3/smbd/dfree.c +++ b/source3/smbd/dfree.c @@ -51,29 +51,17 @@ static void disk_norm(uint64_t *bsize, uint64_t *dfree, uint64_t *dsize) Return number of 1K blocks available on a path and total number. ****************************************************************************/ -static uint64_t sys_disk_free(connection_struct *conn, - struct smb_filename *fname, - uint64_t *bsize, - uint64_t *dfree, - uint64_t *dsize) +static bool handle_dfree_command(connection_struct *conn, + struct smb_filename *fname, + uint64_t *bsize, + uint64_t *dfree, + uint64_t *dsize) { const struct loadparm_substitution *lp_sub = loadparm_s3_global_substitution(); - uint64_t dfree_retval; - uint64_t dfree_q = 0; - uint64_t bsize_q = 0; - uint64_t dsize_q = 0; const char *dfree_command; - static bool dfree_broken = false; char *path = fname->base_name; - (*dfree) = (*dsize) = 0; - (*bsize) = 512; - - /* - * If external disk calculation specified, use it. - */ - dfree_command = lp_dfree_command(talloc_tos(), lp_sub, SNUM(conn)); if (dfree_command && *dfree_command) { const char *p; @@ -84,7 +72,7 @@ static uint64_t sys_disk_free(connection_struct *conn, str_list_add_printf(&argl, "%s", dfree_command); str_list_add_printf(&argl, "%s", path); if (argl == NULL) { - return (uint64_t)-1; + return false; } DBG_NOTICE("Running command '%s %s'\n", @@ -122,12 +110,38 @@ static uint64_t sys_disk_free(connection_struct *conn, if (!*dfree) *dfree = 1024; - goto dfree_done; + return true; } DBG_ERR("file_lines_load() failed for " "command '%s %s'. Error was : %s\n", dfree_command, path, strerror(errno)); } + return false; +} + +static uint64_t sys_disk_free(connection_struct *conn, + struct smb_filename *fname, + uint64_t *bsize, + uint64_t *dfree, + uint64_t *dsize) +{ + uint64_t dfree_retval; + uint64_t dfree_q = 0; + uint64_t bsize_q = 0; + uint64_t dsize_q = 0; + static bool dfree_broken = false; + bool ok; + + (*dfree) = (*dsize) = 0; + (*bsize) = 512; + + /* + * If external disk calculation specified, use it. + */ + ok = handle_dfree_command(conn, fname, bsize, dfree, dsize); + if (ok) { + goto dfree_done; + } if (SMB_VFS_DISK_FREE(conn, fname, bsize, dfree, dsize) == (uint64_t)-1) {