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
27 #include "include/includes.h"
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 pvfs->sharing_violation_delay = 1000000;
48 delay = lp_parm_int(snum, "posix", "sharedelay");
50 pvfs->sharing_violation_delay = delay;
53 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
58 connect to a share - used when a tree_connect operation comes
59 in. For a disk based backend we needs to ensure that the base
60 directory exists (tho it doesn't need to be accessible by the user,
63 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
64 struct smbsrv_request *req, const char *sharename)
66 struct smbsrv_tcon *tcon = req->tcon;
67 struct pvfs_state *pvfs;
72 pvfs = talloc_zero_p(tcon, struct pvfs_state);
74 return NT_STATUS_NO_MEMORY;
77 /* for simplicity of path construction, remove any trailing slash now */
78 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
79 trim_string(base_directory, NULL, "/");
82 pvfs->base_directory = base_directory;
84 /* the directory must exist. Note that we deliberately don't
85 check that it is readable */
86 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
87 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
88 pvfs->base_directory, sharename));
89 return NT_STATUS_BAD_NETWORK_NAME;
92 tcon->fs_type = talloc_strdup(tcon, "NTFS");
93 tcon->dev_type = talloc_strdup(tcon, "A:");
95 ntvfs->private_data = pvfs;
97 pvfs->brl_context = brl_init(pvfs,
98 pvfs->tcon->smb_conn->connection->server_id,
100 pvfs->tcon->smb_conn->connection->messaging_ctx);
101 if (pvfs->brl_context == NULL) {
102 return NT_STATUS_INTERNAL_DB_CORRUPTION;
105 pvfs->odb_context = odb_init(pvfs,
106 pvfs->tcon->smb_conn->connection->server_id,
108 pvfs->tcon->smb_conn->connection->messaging_ctx);
109 if (pvfs->odb_context == NULL) {
110 return NT_STATUS_INTERNAL_DB_CORRUPTION;
113 /* allocate the fnum id -> ptr tree */
114 pvfs->idtree_fnum = idr_init(pvfs);
115 if (pvfs->idtree_fnum == NULL) {
116 return NT_STATUS_NO_MEMORY;
119 /* allocate the search handle -> ptr tree */
120 pvfs->idtree_search = idr_init(pvfs);
121 if (pvfs->idtree_search == NULL) {
122 return NT_STATUS_NO_MEMORY;
125 status = pvfs_mangle_init(pvfs);
126 if (!NT_STATUS_IS_OK(status)) {
130 pvfs_setup_options(pvfs);
133 /* who had the stupid idea to generate a signal on a large
134 file write instead of just failing it!? */
135 BlockSignals(True, SIGXFSZ);
142 disconnect from a share
144 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
145 struct smbsrv_tcon *tcon)
151 check if a directory exists
153 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
154 struct smbsrv_request *req, struct smb_chkpath *cp)
156 struct pvfs_state *pvfs = ntvfs->private_data;
157 struct pvfs_filename *name;
160 /* resolve the cifs name to a posix name */
161 status = pvfs_resolve_name(pvfs, req, cp->in.path,
162 PVFS_RESOLVE_NO_WILDCARD, &name);
163 if (!NT_STATUS_IS_OK(status)) {
168 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
171 if (!S_ISDIR(name->st.st_mode)) {
172 return NT_STATUS_NOT_A_DIRECTORY;
181 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
182 struct smbsrv_request *req, struct smb_copy *cp)
184 DEBUG(0,("pvfs_copy not implemented\n"));
185 return NT_STATUS_NOT_SUPPORTED;
189 return print queue info
191 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
192 struct smbsrv_request *req, union smb_lpq *lpq)
194 return NT_STATUS_NOT_SUPPORTED;
197 /* SMBtrans - not used on file shares */
198 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
199 struct smbsrv_request *req, struct smb_trans2 *trans2)
201 return NT_STATUS_ACCESS_DENIED;
205 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
207 NTSTATUS ntvfs_posix_init(void)
210 struct ntvfs_ops ops;
214 ops.type = NTVFS_DISK;
216 /* fill in all the operations */
217 ops.connect = pvfs_connect;
218 ops.disconnect = pvfs_disconnect;
219 ops.unlink = pvfs_unlink;
220 ops.chkpath = pvfs_chkpath;
221 ops.qpathinfo = pvfs_qpathinfo;
222 ops.setpathinfo = pvfs_setpathinfo;
223 ops.openfile = pvfs_open;
224 ops.mkdir = pvfs_mkdir;
225 ops.rmdir = pvfs_rmdir;
226 ops.rename = pvfs_rename;
227 ops.copy = pvfs_copy;
228 ops.ioctl = pvfs_ioctl;
229 ops.read = pvfs_read;
230 ops.write = pvfs_write;
231 ops.seek = pvfs_seek;
232 ops.flush = pvfs_flush;
233 ops.close = pvfs_close;
234 ops.exit = pvfs_exit;
235 ops.lock = pvfs_lock;
236 ops.setfileinfo = pvfs_setfileinfo;
237 ops.qfileinfo = pvfs_qfileinfo;
238 ops.fsinfo = pvfs_fsinfo;
240 ops.search_first = pvfs_search_first;
241 ops.search_next = pvfs_search_next;
242 ops.search_close = pvfs_search_close;
243 ops.trans = pvfs_trans;
244 ops.logoff = pvfs_logoff;
245 ops.async_setup = pvfs_async_setup;
246 ops.cancel = pvfs_cancel;
248 /* register ourselves with the NTVFS subsystem. We register
249 under the name 'default' as we wish to be the default
250 backend, and also register as 'posix' */
251 ops.name = "default";
252 ret = register_backend("ntvfs", &ops);
255 ret = register_backend("ntvfs", &ops);
257 if (!NT_STATUS_IS_OK(ret)) {
258 DEBUG(0,("Failed to register POSIX backend!\n"));