2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 this implements most of the POSIX NTVFS backend
24 This is the default backend
28 #include "vfs_posix.h"
32 setup config options for a posix share
34 static void pvfs_setup_options(struct pvfs_state *pvfs)
36 int snum = pvfs->tcon->service;
39 if (lp_map_hidden(snum)) pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
40 if (lp_map_archive(snum)) pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
41 if (lp_map_system(snum)) pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
42 if (lp_readonly(snum)) pvfs->flags |= PVFS_FLAG_READONLY;
43 if (lp_strict_sync(snum)) pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
44 if (lp_strict_locking(snum)) pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
45 if (lp_ci_filesystem(snum)) pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
47 if (lp_parm_bool(snum, "posix", "fakeoplocks", False)) {
48 pvfs->flags |= PVFS_FLAG_FAKE_OPLOCKS;
51 #if HAVE_XATTR_SUPPORT
52 if (lp_parm_bool(snum, "posix", "xattr", True)) pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
55 pvfs->sharing_violation_delay = lp_parm_int(snum, "posix", "sharedelay", 1000000);
57 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
60 FS_ATTR_CASE_SENSITIVE_SEARCH |
61 FS_ATTR_CASE_PRESERVED_NAMES |
62 FS_ATTR_UNICODE_ON_DISK |
65 /* allow xattrs to be stored in a external tdb */
66 eadb = lp_parm_string(snum, "posix", "eadb");
68 pvfs->ea_db = tdb_wrap_open(pvfs, eadb, 50000,
69 TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
70 if (pvfs->ea_db != NULL) {
71 pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
73 DEBUG(0,("Failed to open eadb '%s' - %s\n",
74 eadb, strerror(errno)));
75 pvfs->flags &= ~PVFS_FLAG_XATTR_ENABLE;
79 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
80 pvfs->fs_attribs |= FS_ATTR_NAMED_STREAMS;
82 if (pvfs->flags & PVFS_FLAG_XATTR_ENABLE) {
83 pvfs->fs_attribs |= FS_ATTR_PERSISTANT_ACLS;
89 connect to a share - used when a tree_connect operation comes
90 in. For a disk based backend we needs to ensure that the base
91 directory exists (tho it doesn't need to be accessible by the user,
94 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
95 struct smbsrv_request *req, const char *sharename)
97 struct smbsrv_tcon *tcon = req->tcon;
98 struct pvfs_state *pvfs;
100 char *base_directory;
103 pvfs = talloc_zero_p(tcon, struct pvfs_state);
105 return NT_STATUS_NO_MEMORY;
108 /* for simplicity of path construction, remove any trailing slash now */
109 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
110 trim_string(base_directory, NULL, "/");
113 pvfs->base_directory = base_directory;
115 /* the directory must exist. Note that we deliberately don't
116 check that it is readable */
117 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
118 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
119 pvfs->base_directory, sharename));
120 return NT_STATUS_BAD_NETWORK_NAME;
123 tcon->fs_type = talloc_strdup(tcon, "NTFS");
124 tcon->dev_type = talloc_strdup(tcon, "A:");
126 ntvfs->private_data = pvfs;
128 pvfs->brl_context = brl_init(pvfs,
129 pvfs->tcon->smb_conn->connection->server_id,
131 pvfs->tcon->smb_conn->connection->messaging_ctx);
132 if (pvfs->brl_context == NULL) {
133 return NT_STATUS_INTERNAL_DB_CORRUPTION;
136 pvfs->odb_context = odb_init(pvfs,
137 pvfs->tcon->smb_conn->connection->server_id,
138 pvfs->tcon->smb_conn->connection->messaging_ctx);
139 if (pvfs->odb_context == NULL) {
140 return NT_STATUS_INTERNAL_DB_CORRUPTION;
143 pvfs->sidmap = sidmap_open(pvfs);
144 if (pvfs->sidmap == NULL) {
145 return NT_STATUS_INTERNAL_DB_CORRUPTION;
148 /* allocate the fnum id -> ptr tree */
149 pvfs->idtree_fnum = idr_init(pvfs);
150 if (pvfs->idtree_fnum == NULL) {
151 return NT_STATUS_NO_MEMORY;
154 /* allocate the search handle -> ptr tree */
155 pvfs->idtree_search = idr_init(pvfs);
156 if (pvfs->idtree_search == NULL) {
157 return NT_STATUS_NO_MEMORY;
160 status = pvfs_mangle_init(pvfs);
161 if (!NT_STATUS_IS_OK(status)) {
165 pvfs_setup_options(pvfs);
168 /* who had the stupid idea to generate a signal on a large
169 file write instead of just failing it!? */
170 BlockSignals(True, SIGXFSZ);
177 disconnect from a share
179 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
180 struct smbsrv_tcon *tcon)
186 check if a directory exists
188 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
189 struct smbsrv_request *req, struct smb_chkpath *cp)
191 struct pvfs_state *pvfs = ntvfs->private_data;
192 struct pvfs_filename *name;
195 /* resolve the cifs name to a posix name */
196 status = pvfs_resolve_name(pvfs, req, cp->in.path, 0, &name);
197 if (!NT_STATUS_IS_OK(status)) {
202 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
205 if (!S_ISDIR(name->st.st_mode)) {
206 return NT_STATUS_NOT_A_DIRECTORY;
215 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
216 struct smbsrv_request *req, struct smb_copy *cp)
218 DEBUG(0,("pvfs_copy not implemented\n"));
219 return NT_STATUS_NOT_SUPPORTED;
223 return print queue info
225 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
226 struct smbsrv_request *req, union smb_lpq *lpq)
228 return NT_STATUS_NOT_SUPPORTED;
231 /* SMBtrans - not used on file shares */
232 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
233 struct smbsrv_request *req, struct smb_trans2 *trans2)
235 return NT_STATUS_ACCESS_DENIED;
239 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
241 NTSTATUS ntvfs_posix_init(void)
244 struct ntvfs_ops ops;
248 ops.type = NTVFS_DISK;
250 /* fill in all the operations */
251 ops.connect = pvfs_connect;
252 ops.disconnect = pvfs_disconnect;
253 ops.unlink = pvfs_unlink;
254 ops.chkpath = pvfs_chkpath;
255 ops.qpathinfo = pvfs_qpathinfo;
256 ops.setpathinfo = pvfs_setpathinfo;
257 ops.openfile = pvfs_open;
258 ops.mkdir = pvfs_mkdir;
259 ops.rmdir = pvfs_rmdir;
260 ops.rename = pvfs_rename;
261 ops.copy = pvfs_copy;
262 ops.ioctl = pvfs_ioctl;
263 ops.read = pvfs_read;
264 ops.write = pvfs_write;
265 ops.seek = pvfs_seek;
266 ops.flush = pvfs_flush;
267 ops.close = pvfs_close;
268 ops.exit = pvfs_exit;
269 ops.lock = pvfs_lock;
270 ops.setfileinfo = pvfs_setfileinfo;
271 ops.qfileinfo = pvfs_qfileinfo;
272 ops.fsinfo = pvfs_fsinfo;
274 ops.search_first = pvfs_search_first;
275 ops.search_next = pvfs_search_next;
276 ops.search_close = pvfs_search_close;
277 ops.trans = pvfs_trans;
278 ops.logoff = pvfs_logoff;
279 ops.async_setup = pvfs_async_setup;
280 ops.cancel = pvfs_cancel;
282 /* register ourselves with the NTVFS subsystem. We register
283 under the name 'default' as we wish to be the default
284 backend, and also register as 'posix' */
285 ops.name = "default";
286 ret = ntvfs_register(&ops);
289 ret = ntvfs_register(&ops);
291 if (!NT_STATUS_IS_OK(ret)) {
292 DEBUG(0,("Failed to register POSIX backend!\n"));