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
, const char *path
,
31 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
34 static uint64_t dfq_load_param(int snum
, const char *path
, const char *section
,
35 const char *param
, uint64_t def_val
)
40 talloc_asprintf(talloc_tos(), "%s/%s/%s", section
, param
, path
);
45 ret
= (uint64_t)lp_parm_ulonglong(snum
, "fake_dfq", option
,
46 (unsigned long long)def_val
);
53 static uint64_t dfq_disk_free(vfs_handle_struct
*handle
, const char *path
,
54 uint64_t *bsize
, uint64_t *dfree
, uint64_t *dsize
)
57 int snum
= SNUM(handle
->conn
);
58 uint64_t dfq_bsize
= 0;
61 /* look up the params based on real path to be resilient
62 * to refactoring of path<->realpath
64 rpath
= SMB_VFS_NEXT_REALPATH(handle
, path
);
66 dfq_bsize
= dfq_load_param(snum
, rpath
, "df", "block size", 0);
70 return SMB_VFS_NEXT_DISK_FREE(handle
, path
, bsize
, dfree
,
75 *dfree
= dfq_load_param(snum
, rpath
, "df", "disk free", 0);
76 *dsize
= dfq_load_param(snum
, rpath
, "df", "disk size", 0);
78 if ((*bsize
) < 1024) {
79 free_1k
= (*dfree
) / (1024 / (*bsize
));
81 free_1k
= ((*bsize
) / 1024) * (*dfree
);
88 static int dfq_get_quota(struct vfs_handle_struct
*handle
, const char *path
,
89 enum SMB_QUOTA_TYPE qtype
, unid_t id
,
95 int snum
= SNUM(handle
->conn
);
99 rpath
= SMB_VFS_NEXT_REALPATH(handle
, path
);
105 case SMB_USER_QUOTA_TYPE
:
106 section
= talloc_asprintf(talloc_tos(), "u%llu",
107 (unsigned long long)id
.uid
);
109 case SMB_GROUP_QUOTA_TYPE
:
110 section
= talloc_asprintf(talloc_tos(), "g%llu",
111 (unsigned long long)id
.gid
);
113 case SMB_USER_FS_QUOTA_TYPE
:
114 section
= talloc_strdup(talloc_tos(), "udflt");
116 case SMB_GROUP_FS_QUOTA_TYPE
:
117 section
= talloc_strdup(talloc_tos(), "gdflt");
123 if (section
== NULL
) {
127 bsize
= dfq_load_param(snum
, rpath
, section
, "block size", 4096);
132 if (dfq_load_param(snum
, rpath
, section
, "err", 0) != 0) {
138 if (dfq_load_param(snum
, rpath
, section
, "nosys", 0) != 0) {
147 qt
->hardlimit
= dfq_load_param(snum
, rpath
, section
, "hard limit", 0);
148 qt
->softlimit
= dfq_load_param(snum
, rpath
, section
, "soft limit", 0);
149 qt
->curblocks
= dfq_load_param(snum
, rpath
, section
, "cur blocks", 0);
151 dfq_load_param(snum
, rpath
, section
, "inode hard limit", 0);
153 dfq_load_param(snum
, rpath
, section
, "inode soft limit", 0);
154 qt
->curinodes
= dfq_load_param(snum
, rpath
, section
, "cur inodes", 0);
155 qt
->qflags
= dfq_load_param(snum
, rpath
, section
, "qflags", QUOTAS_DENY_DISK
);
160 rc
= SMB_VFS_NEXT_GET_QUOTA(handle
, path
, qtype
, id
, qt
);
164 TALLOC_FREE(section
);
170 struct vfs_fn_pointers vfs_fake_dfq_fns
= {
171 /* Disk operations */
173 .disk_free_fn
= dfq_disk_free
,
174 .get_quota_fn
= dfq_get_quota
,
178 NTSTATUS
vfs_fake_dfq_init(void)
180 return smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "fake_dfq",