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 HAVE_XATTR_SUPPORT
48 if (lp_parm_bool(snum, "posix", "xattr", True)) pvfs->flags |= PVFS_FLAG_XATTR_ENABLE;
51 pvfs->sharing_violation_delay = 1000000;
52 delay = lp_parm_int(snum, "posix", "sharedelay");
54 pvfs->sharing_violation_delay = delay;
57 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
62 connect to a share - used when a tree_connect operation comes
63 in. For a disk based backend we needs to ensure that the base
64 directory exists (tho it doesn't need to be accessible by the user,
67 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
68 struct smbsrv_request *req, const char *sharename)
70 struct smbsrv_tcon *tcon = req->tcon;
71 struct pvfs_state *pvfs;
76 pvfs = talloc_zero_p(tcon, struct pvfs_state);
78 return NT_STATUS_NO_MEMORY;
81 /* for simplicity of path construction, remove any trailing slash now */
82 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
83 trim_string(base_directory, NULL, "/");
86 pvfs->base_directory = base_directory;
88 /* the directory must exist. Note that we deliberately don't
89 check that it is readable */
90 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
91 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
92 pvfs->base_directory, sharename));
93 return NT_STATUS_BAD_NETWORK_NAME;
96 tcon->fs_type = talloc_strdup(tcon, "NTFS");
97 tcon->dev_type = talloc_strdup(tcon, "A:");
99 ntvfs->private_data = pvfs;
101 pvfs->brl_context = brl_init(pvfs,
102 pvfs->tcon->smb_conn->connection->server_id,
104 pvfs->tcon->smb_conn->connection->messaging_ctx);
105 if (pvfs->brl_context == NULL) {
106 return NT_STATUS_INTERNAL_DB_CORRUPTION;
109 pvfs->odb_context = odb_init(pvfs,
110 pvfs->tcon->smb_conn->connection->server_id,
112 pvfs->tcon->smb_conn->connection->messaging_ctx);
113 if (pvfs->odb_context == NULL) {
114 return NT_STATUS_INTERNAL_DB_CORRUPTION;
117 /* allocate the fnum id -> ptr tree */
118 pvfs->idtree_fnum = idr_init(pvfs);
119 if (pvfs->idtree_fnum == NULL) {
120 return NT_STATUS_NO_MEMORY;
123 /* allocate the search handle -> ptr tree */
124 pvfs->idtree_search = idr_init(pvfs);
125 if (pvfs->idtree_search == NULL) {
126 return NT_STATUS_NO_MEMORY;
129 status = pvfs_mangle_init(pvfs);
130 if (!NT_STATUS_IS_OK(status)) {
134 pvfs_setup_options(pvfs);
137 /* who had the stupid idea to generate a signal on a large
138 file write instead of just failing it!? */
139 BlockSignals(True, SIGXFSZ);
146 disconnect from a share
148 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
149 struct smbsrv_tcon *tcon)
155 check if a directory exists
157 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
158 struct smbsrv_request *req, struct smb_chkpath *cp)
160 struct pvfs_state *pvfs = ntvfs->private_data;
161 struct pvfs_filename *name;
164 /* resolve the cifs name to a posix name */
165 status = pvfs_resolve_name(pvfs, req, cp->in.path,
166 PVFS_RESOLVE_NO_WILDCARD, &name);
167 if (!NT_STATUS_IS_OK(status)) {
172 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
175 if (!S_ISDIR(name->st.st_mode)) {
176 return NT_STATUS_NOT_A_DIRECTORY;
185 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
186 struct smbsrv_request *req, struct smb_copy *cp)
188 DEBUG(0,("pvfs_copy not implemented\n"));
189 return NT_STATUS_NOT_SUPPORTED;
193 return print queue info
195 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
196 struct smbsrv_request *req, union smb_lpq *lpq)
198 return NT_STATUS_NOT_SUPPORTED;
201 /* SMBtrans - not used on file shares */
202 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
203 struct smbsrv_request *req, struct smb_trans2 *trans2)
205 return NT_STATUS_ACCESS_DENIED;
209 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
211 NTSTATUS ntvfs_posix_init(void)
214 struct ntvfs_ops ops;
218 ops.type = NTVFS_DISK;
220 /* fill in all the operations */
221 ops.connect = pvfs_connect;
222 ops.disconnect = pvfs_disconnect;
223 ops.unlink = pvfs_unlink;
224 ops.chkpath = pvfs_chkpath;
225 ops.qpathinfo = pvfs_qpathinfo;
226 ops.setpathinfo = pvfs_setpathinfo;
227 ops.openfile = pvfs_open;
228 ops.mkdir = pvfs_mkdir;
229 ops.rmdir = pvfs_rmdir;
230 ops.rename = pvfs_rename;
231 ops.copy = pvfs_copy;
232 ops.ioctl = pvfs_ioctl;
233 ops.read = pvfs_read;
234 ops.write = pvfs_write;
235 ops.seek = pvfs_seek;
236 ops.flush = pvfs_flush;
237 ops.close = pvfs_close;
238 ops.exit = pvfs_exit;
239 ops.lock = pvfs_lock;
240 ops.setfileinfo = pvfs_setfileinfo;
241 ops.qfileinfo = pvfs_qfileinfo;
242 ops.fsinfo = pvfs_fsinfo;
244 ops.search_first = pvfs_search_first;
245 ops.search_next = pvfs_search_next;
246 ops.search_close = pvfs_search_close;
247 ops.trans = pvfs_trans;
248 ops.logoff = pvfs_logoff;
249 ops.async_setup = pvfs_async_setup;
250 ops.cancel = pvfs_cancel;
252 /* register ourselves with the NTVFS subsystem. We register
253 under the name 'default' as we wish to be the default
254 backend, and also register as 'posix' */
255 ops.name = "default";
256 ret = register_backend("ntvfs", &ops);
259 ret = register_backend("ntvfs", &ops);
261 if (!NT_STATUS_IS_OK(ret)) {
262 DEBUG(0,("Failed to register POSIX backend!\n"));