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;
38 if (lp_map_hidden(snum)) pvfs->flags |= PVFS_FLAG_MAP_HIDDEN;
39 if (lp_map_archive(snum)) pvfs->flags |= PVFS_FLAG_MAP_ARCHIVE;
40 if (lp_map_system(snum)) pvfs->flags |= PVFS_FLAG_MAP_SYSTEM;
41 if (lp_readonly(snum)) pvfs->flags |= PVFS_FLAG_READONLY;
42 if (lp_strict_sync(snum)) pvfs->flags |= PVFS_FLAG_STRICT_SYNC;
43 if (lp_strict_locking(snum)) pvfs->flags |= PVFS_FLAG_STRICT_LOCKING;
44 if (lp_ci_filesystem(snum)) pvfs->flags |= PVFS_FLAG_CI_FILESYSTEM;
46 pvfs->share_name = talloc_strdup(pvfs, lp_servicename(snum));
51 connect to a share - used when a tree_connect operation comes
52 in. For a disk based backend we needs to ensure that the base
53 directory exists (tho it doesn't need to be accessible by the user,
56 static NTSTATUS pvfs_connect(struct ntvfs_module_context *ntvfs,
57 struct smbsrv_request *req, const char *sharename)
59 struct smbsrv_tcon *tcon = req->tcon;
60 struct pvfs_state *pvfs;
65 pvfs = talloc_zero_p(tcon, struct pvfs_state);
67 return NT_STATUS_NO_MEMORY;
70 /* for simplicity of path construction, remove any trailing slash now */
71 base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
72 trim_string(base_directory, NULL, "/");
75 pvfs->base_directory = base_directory;
77 /* the directory must exist. Note that we deliberately don't
78 check that it is readable */
79 if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
80 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n",
81 pvfs->base_directory, sharename));
82 return NT_STATUS_BAD_NETWORK_NAME;
85 tcon->fs_type = talloc_strdup(tcon, "NTFS");
86 tcon->dev_type = talloc_strdup(tcon, "A:");
88 ntvfs->private_data = pvfs;
90 pvfs->brl_context = brl_init(pvfs,
91 pvfs->tcon->smb_conn->connection->server_id,
93 pvfs->tcon->smb_conn->connection->messaging_ctx);
94 if (pvfs->brl_context == NULL) {
95 return NT_STATUS_INTERNAL_DB_CORRUPTION;
98 pvfs->odb_context = odb_init(pvfs,
99 pvfs->tcon->smb_conn->connection->server_id,
101 pvfs->tcon->smb_conn->connection->messaging_ctx);
102 if (pvfs->odb_context == NULL) {
103 return NT_STATUS_INTERNAL_DB_CORRUPTION;
106 /* allocate the fnum id -> ptr tree */
107 pvfs->idtree_fnum = idr_init(pvfs);
108 if (pvfs->idtree_fnum == NULL) {
109 return NT_STATUS_NO_MEMORY;
112 /* allocate the search handle -> ptr tree */
113 pvfs->idtree_search = idr_init(pvfs);
114 if (pvfs->idtree_search == NULL) {
115 return NT_STATUS_NO_MEMORY;
118 status = pvfs_mangle_init(pvfs);
119 if (!NT_STATUS_IS_OK(status)) {
123 pvfs_setup_options(pvfs);
126 /* who had the stupid idea to generate a signal on a large
127 file write instead of just failing it!? */
128 BlockSignals(True, SIGXFSZ);
135 disconnect from a share
137 static NTSTATUS pvfs_disconnect(struct ntvfs_module_context *ntvfs,
138 struct smbsrv_tcon *tcon)
144 check if a directory exists
146 static NTSTATUS pvfs_chkpath(struct ntvfs_module_context *ntvfs,
147 struct smbsrv_request *req, struct smb_chkpath *cp)
149 struct pvfs_state *pvfs = ntvfs->private_data;
150 struct pvfs_filename *name;
153 /* resolve the cifs name to a posix name */
154 status = pvfs_resolve_name(pvfs, req, cp->in.path,
155 PVFS_RESOLVE_NO_WILDCARD, &name);
156 if (!NT_STATUS_IS_OK(status)) {
161 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
164 if (!S_ISDIR(name->st.st_mode)) {
165 return NT_STATUS_NOT_A_DIRECTORY;
174 static NTSTATUS pvfs_copy(struct ntvfs_module_context *ntvfs,
175 struct smbsrv_request *req, struct smb_copy *cp)
177 DEBUG(0,("pvfs_copy not implemented\n"));
178 return NT_STATUS_NOT_SUPPORTED;
182 return print queue info
184 static NTSTATUS pvfs_lpq(struct ntvfs_module_context *ntvfs,
185 struct smbsrv_request *req, union smb_lpq *lpq)
187 return NT_STATUS_NOT_SUPPORTED;
190 /* SMBtrans - not used on file shares */
191 static NTSTATUS pvfs_trans(struct ntvfs_module_context *ntvfs,
192 struct smbsrv_request *req, struct smb_trans2 *trans2)
194 return NT_STATUS_ACCESS_DENIED;
198 initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
200 NTSTATUS ntvfs_posix_init(void)
203 struct ntvfs_ops ops;
207 ops.type = NTVFS_DISK;
209 /* fill in all the operations */
210 ops.connect = pvfs_connect;
211 ops.disconnect = pvfs_disconnect;
212 ops.unlink = pvfs_unlink;
213 ops.chkpath = pvfs_chkpath;
214 ops.qpathinfo = pvfs_qpathinfo;
215 ops.setpathinfo = pvfs_setpathinfo;
216 ops.openfile = pvfs_open;
217 ops.mkdir = pvfs_mkdir;
218 ops.rmdir = pvfs_rmdir;
219 ops.rename = pvfs_rename;
220 ops.copy = pvfs_copy;
221 ops.ioctl = pvfs_ioctl;
222 ops.read = pvfs_read;
223 ops.write = pvfs_write;
224 ops.seek = pvfs_seek;
225 ops.flush = pvfs_flush;
226 ops.close = pvfs_close;
227 ops.exit = pvfs_exit;
228 ops.lock = pvfs_lock;
229 ops.setfileinfo = pvfs_setfileinfo;
230 ops.qfileinfo = pvfs_qfileinfo;
231 ops.fsinfo = pvfs_fsinfo;
233 ops.search_first = pvfs_search_first;
234 ops.search_next = pvfs_search_next;
235 ops.search_close = pvfs_search_close;
236 ops.trans = pvfs_trans;
237 ops.logoff = pvfs_logoff;
238 ops.async_setup = pvfs_async_setup;
240 /* register ourselves with the NTVFS subsystem. We register
241 under the name 'default' as we wish to be the default
242 backend, and also register as 'posix' */
243 ops.name = "default";
244 ret = register_backend("ntvfs", &ops);
247 ret = register_backend("ntvfs", &ops);
249 if (!NT_STATUS_IS_OK(ret)) {
250 DEBUG(0,("Failed to register POSIX backend!\n"));