Return number of 1K blocks available on a path and total number.
****************************************************************************/
-uint64_t sys_disk_free(connection_struct *conn, struct smb_filename *fname,
- uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
+static uint64_t sys_disk_free(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;
- const char *path = fname->base_name;
+ char *path = fname->base_name;
(*dfree) = (*dsize) = 0;
(*bsize) = 512;
* If external disk calculation specified, use it.
*/
- dfree_command = lp_dfree_command(talloc_tos(), SNUM(conn));
+ dfree_command = lp_dfree_command(talloc_tos(), lp_sub, SNUM(conn));
if (dfree_command && *dfree_command) {
const char *p;
char **lines = NULL;
- char *syscmd = NULL;
+ char **argl = NULL;
- syscmd = talloc_asprintf(talloc_tos(),
- "%s %s",
- dfree_command,
- path);
-
- if (!syscmd) {
+ argl = str_list_make_empty(talloc_tos());
+ str_list_add_printf(&argl, "%s", dfree_command);
+ str_list_add_printf(&argl, "%s", path);
+ if (argl == NULL) {
return (uint64_t)-1;
}
- DEBUG (3, ("disk_free: Running command '%s'\n", syscmd));
+ DBG_NOTICE("Running command '%s %s'\n",
+ dfree_command,
+ path);
+
+ lines = file_lines_ploadv(talloc_tos(), argl, NULL);
+
+ TALLOC_FREE(argl);
- lines = file_lines_pload(talloc_tos(), syscmd, NULL);
if (lines != NULL) {
char *line = lines[0];
goto dfree_done;
}
- DEBUG (0, ("disk_free: file_lines_load() failed for "
- "command '%s'. Error was : %s\n",
- syscmd, strerror(errno) ));
+ DBG_ERR("file_lines_load() failed for "
+ "command '%s %s'. Error was : %s\n",
+ dfree_command, path, strerror(errno));
}
if (SMB_VFS_DISK_FREE(conn, fname, bsize, dfree, dsize) ==
Depending on the file system layout and file system features, the free space
information can be different for different sub directories underneath a SMB
share. Store the cache information in memcache using the query path as the
- key to accomodate this.
+ key to accommodate this.
****************************************************************************/
+struct dfree_cached_info {
+ time_t last_dfree_time;
+ uint64_t dfree_ret;
+ uint64_t bsize;
+ uint64_t dfree;
+ uint64_t dsize;
+};
+
uint64_t get_dfree_info(connection_struct *conn, struct smb_filename *fname,
uint64_t *bsize, uint64_t *dfree, uint64_t *dsize)
{
TALLOC_FREE(to_free);
return dfree_ret;
}
+
+void flush_dfree_cache(void)
+{
+ memcache_flush(smbd_memcache(), DFREE_CACHE);
+}