]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Factor out handling of dfree command into a separate function
authorVolker Lendecke <vl@samba.org>
Tue, 13 Jan 2026 21:06:06 +0000 (22:06 +0100)
committerVolker Lendecke <vl@samba.org>
Tue, 20 Jan 2026 11:53:34 +0000 (11:53 +0000)
Will enable code simplifications with early returns

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

index cdfeedfaddc1de12a8d87a0489c729228a627aaa..1becfcc5dc3b97497cfd59224b313989afbcc0ba 100644 (file)
@@ -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) {