2 * Fake Disk-Free and Quota VFS module. Implements passthrough operation
3 * of all VFS calls, except for "disk free" and "get quota" which
4 * are handled by reading a text file named ".dfq" in the current directory.
6 * This module is intended for testing purposes.
8 * Copyright (C) Uri Simchoni, 2016
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "smbd/smbd.h"
28 #define DBGC_CLASS DBGC_VFS
30 static int dfq_get_quota(struct vfs_handle_struct *handle,
31 const struct smb_filename *smb_fname,
32 enum SMB_QUOTA_TYPE qtype,
36 static uint64_t dfq_load_param(int snum, const char *path, const char *section,
37 const char *param, uint64_t def_val)
42 talloc_asprintf(talloc_tos(), "%s/%s/%s", section, param, path);
47 ret = (uint64_t)lp_parm_ulonglong(snum, "fake_dfq", option,
48 (unsigned long long)def_val);
55 static uint64_t dfq_disk_free(vfs_handle_struct *handle,
56 const struct smb_filename *smb_fname,
62 int snum = SNUM(handle->conn);
63 uint64_t dfq_bsize = 0;
66 /* look up the params based on real path to be resilient
67 * to refactoring of path<->realpath
69 rpath = SMB_VFS_NEXT_REALPATH(handle, smb_fname->base_name);
71 dfq_bsize = dfq_load_param(snum, rpath, "df", "block size", 0);
75 return SMB_VFS_NEXT_DISK_FREE(handle, smb_fname, bsize, dfree,
80 *dfree = dfq_load_param(snum, rpath, "df", "disk free", 0);
81 *dsize = dfq_load_param(snum, rpath, "df", "disk size", 0);
83 if ((*bsize) < 1024) {
84 free_1k = (*dfree) / (1024 / (*bsize));
86 free_1k = ((*bsize) / 1024) * (*dfree);
93 static int dfq_get_quota(struct vfs_handle_struct *handle,
94 const struct smb_filename *smb_fname,
95 enum SMB_QUOTA_TYPE qtype,
101 char *section = NULL;
102 int snum = SNUM(handle->conn);
106 rpath = SMB_VFS_NEXT_REALPATH(handle, smb_fname->base_name);
112 case SMB_USER_QUOTA_TYPE:
113 section = talloc_asprintf(talloc_tos(), "u%llu",
114 (unsigned long long)id.uid);
116 case SMB_GROUP_QUOTA_TYPE:
117 section = talloc_asprintf(talloc_tos(), "g%llu",
118 (unsigned long long)id.gid);
120 case SMB_USER_FS_QUOTA_TYPE:
121 section = talloc_strdup(talloc_tos(), "udflt");
123 case SMB_GROUP_FS_QUOTA_TYPE:
124 section = talloc_strdup(talloc_tos(), "gdflt");
130 if (section == NULL) {
134 bsize = dfq_load_param(snum, rpath, section, "block size", 4096);
139 if (dfq_load_param(snum, rpath, section, "err", 0) != 0) {
145 if (dfq_load_param(snum, rpath, section, "nosys", 0) != 0) {
154 qt->hardlimit = dfq_load_param(snum, rpath, section, "hard limit", 0);
155 qt->softlimit = dfq_load_param(snum, rpath, section, "soft limit", 0);
156 qt->curblocks = dfq_load_param(snum, rpath, section, "cur blocks", 0);
158 dfq_load_param(snum, rpath, section, "inode hard limit", 0);
160 dfq_load_param(snum, rpath, section, "inode soft limit", 0);
161 qt->curinodes = dfq_load_param(snum, rpath, section, "cur inodes", 0);
162 qt->qflags = dfq_load_param(snum, rpath, section, "qflags", QUOTAS_DENY_DISK);
167 rc = SMB_VFS_NEXT_GET_QUOTA(handle, smb_fname, qtype, id, qt);
171 TALLOC_FREE(section);
177 struct vfs_fn_pointers vfs_fake_dfq_fns = {
178 /* Disk operations */
180 .disk_free_fn = dfq_disk_free,
181 .get_quota_fn = dfq_get_quota,
185 NTSTATUS vfs_fake_dfq_init(TALLOC_CTX *ctx)
187 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "fake_dfq",