r2251: forgot to add vfs_posix.h in my last commit
[metze/samba/wip.git] / source4 / ntvfs / posix / vfs_posix.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    POSIX NTVFS backend
5
6    Copyright (C) Andrew Tridgell 2004
7
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.
12    
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.
17    
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.
21 */
22 /*
23   this implements most of the POSIX NTVFS backend
24   This is the default backend
25 */
26
27 #include "include/includes.h"
28 #include "vfs_posix.h"
29
30
31 /*
32   connect to a share - used when a tree_connect operation comes
33   in. For a disk based backend we needs to ensure that the base
34   directory exists (tho it doesn't need to be accessible by the user,
35   that comes later)
36 */
37 static NTSTATUS pvfs_connect(struct smbsrv_request *req, const char *sharename)
38 {
39         struct smbsrv_tcon *tcon = req->tcon;
40         struct pvfs_state *pvfs;
41         struct stat st;
42
43         DEBUG(0,("WARNING: the posix vfs handler is incomplete - you probably want \"ntvfs handler = simple\"\n"));
44
45         pvfs = talloc_named(tcon, sizeof(struct pvfs_state), "pvfs_connect(%s)", sharename);
46         if (pvfs == NULL) {
47                 return NT_STATUS_NO_MEMORY;
48         }
49
50         pvfs->base_directory = talloc_strdup(pvfs, lp_pathname(tcon->service));
51
52         /* the directory must exist. Note that we deliberately don't
53            check that it is readable */
54         if (stat(pvfs->base_directory, &st) != 0 || !S_ISDIR(st.st_mode)) {
55                 DEBUG(0,("pvfs_connect: '%s' is not a directory, when connecting to [%s]\n", 
56                          pvfs->base_directory, sharename));
57                 return NT_STATUS_BAD_NETWORK_NAME;
58         }
59
60         tcon->fs_type = talloc_strdup(tcon, "NTFS");
61         tcon->dev_type = talloc_strdup(tcon, "A:");
62
63         return NT_STATUS_OK;
64 }
65
66 /*
67   disconnect from a share
68 */
69 static NTSTATUS pvfs_disconnect(struct smbsrv_tcon *tcon)
70 {
71         return NT_STATUS_OK;
72 }
73
74 /*
75   delete a file - the dirtype specifies the file types to include in the search. 
76   The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
77 */
78 static NTSTATUS pvfs_unlink(struct smbsrv_request *req, struct smb_unlink *unl)
79 {
80         return NT_STATUS_NOT_IMPLEMENTED;
81 }
82
83
84 /*
85   ioctl interface - we don't do any
86 */
87 static NTSTATUS pvfs_ioctl(struct smbsrv_request *req, union smb_ioctl *io)
88 {
89         return NT_STATUS_INVALID_PARAMETER;
90 }
91
92 /*
93   check if a directory exists
94 */
95 static NTSTATUS pvfs_chkpath(struct smbsrv_request *req, struct smb_chkpath *cp)
96 {
97         return NT_STATUS_NOT_IMPLEMENTED;
98 }
99
100 /*
101   return info on a pathname
102 */
103 static NTSTATUS pvfs_qpathinfo(struct smbsrv_request *req, union smb_fileinfo *info)
104 {
105         return NT_STATUS_NOT_IMPLEMENTED;
106 }
107
108 /*
109   query info on a open file
110 */
111 static NTSTATUS pvfs_qfileinfo(struct smbsrv_request *req, union smb_fileinfo *info)
112 {
113         return NT_STATUS_NOT_IMPLEMENTED;
114 }
115
116
117 /*
118   open a file
119 */
120 static NTSTATUS pvfs_open(struct smbsrv_request *req, union smb_open *io)
121 {
122         return NT_STATUS_NOT_IMPLEMENTED;
123 }
124
125 /*
126   create a directory
127 */
128 static NTSTATUS pvfs_mkdir(struct smbsrv_request *req, union smb_mkdir *md)
129 {
130         return NT_STATUS_NOT_IMPLEMENTED;
131 }
132
133 /*
134   remove a directory
135 */
136 static NTSTATUS pvfs_rmdir(struct smbsrv_request *req, struct smb_rmdir *rd)
137 {
138         return NT_STATUS_NOT_IMPLEMENTED;
139 }
140
141 /*
142   rename a set of files
143 */
144 static NTSTATUS pvfs_rename(struct smbsrv_request *req, union smb_rename *ren)
145 {
146         return NT_STATUS_NOT_IMPLEMENTED;
147 }
148
149 /*
150   copy a set of files
151 */
152 static NTSTATUS pvfs_copy(struct smbsrv_request *req, struct smb_copy *cp)
153 {
154         return NT_STATUS_NOT_SUPPORTED;
155 }
156
157 /*
158   read from a file
159 */
160 static NTSTATUS pvfs_read(struct smbsrv_request *req, union smb_read *rd)
161 {
162         return NT_STATUS_NOT_IMPLEMENTED;
163 }
164
165 /*
166   write to a file
167 */
168 static NTSTATUS pvfs_write(struct smbsrv_request *req, union smb_write *wr)
169 {
170         return NT_STATUS_NOT_IMPLEMENTED;
171 }
172
173 /*
174   seek in a file
175 */
176 static NTSTATUS pvfs_seek(struct smbsrv_request *req, struct smb_seek *io)
177 {
178         return NT_STATUS_NOT_SUPPORTED;
179 }
180
181 /*
182   flush a file
183 */
184 static NTSTATUS pvfs_flush(struct smbsrv_request *req, struct smb_flush *io)
185 {
186         return NT_STATUS_NOT_IMPLEMENTED;
187 }
188
189 /*
190   close a file
191 */
192 static NTSTATUS pvfs_close(struct smbsrv_request *req, union smb_close *io)
193 {
194         return NT_STATUS_NOT_IMPLEMENTED;
195 }
196
197 /*
198   exit - closing files?
199 */
200 static NTSTATUS pvfs_exit(struct smbsrv_request *req)
201 {
202         return NT_STATUS_NOT_SUPPORTED;
203 }
204
205 /*
206   lock a byte range
207 */
208 static NTSTATUS pvfs_lock(struct smbsrv_request *req, union smb_lock *lck)
209 {
210         return NT_STATUS_NOT_IMPLEMENTED;
211 }
212
213 /*
214   set info on a pathname
215 */
216 static NTSTATUS pvfs_setpathinfo(struct smbsrv_request *req, union smb_setfileinfo *st)
217 {
218         return NT_STATUS_NOT_SUPPORTED;
219 }
220
221 /*
222   set info on a open file
223 */
224 static NTSTATUS pvfs_setfileinfo(struct smbsrv_request *req, 
225                                  union smb_setfileinfo *info)
226 {
227         return NT_STATUS_NOT_IMPLEMENTED;
228 }
229
230
231 /*
232   return filesystem space info
233 */
234 static NTSTATUS pvfs_fsinfo(struct smbsrv_request *req, union smb_fsinfo *fs)
235 {
236         return NT_STATUS_NOT_IMPLEMENTED;
237 }
238
239 /*
240   return print queue info
241 */
242 static NTSTATUS pvfs_lpq(struct smbsrv_request *req, union smb_lpq *lpq)
243 {
244         return NT_STATUS_NOT_SUPPORTED;
245 }
246
247 /* 
248    list files in a directory matching a wildcard pattern
249 */
250 static NTSTATUS pvfs_search_first(struct smbsrv_request *req, union smb_search_first *io, 
251                                   void *search_private, 
252                                   BOOL (*callback)(void *, union smb_search_data *))
253 {
254         return NT_STATUS_NOT_IMPLEMENTED;
255 }
256
257 /* continue a search */
258 static NTSTATUS pvfs_search_next(struct smbsrv_request *req, union smb_search_next *io, 
259                                  void *search_private, 
260                                  BOOL (*callback)(void *, union smb_search_data *))
261 {
262         return NT_STATUS_NOT_IMPLEMENTED;
263 }
264
265 /* close a search */
266 static NTSTATUS pvfs_search_close(struct smbsrv_request *req, union smb_search_close *io)
267 {
268         return NT_STATUS_NOT_IMPLEMENTED;
269 }
270
271 /* SMBtrans - not used on file shares */
272 static NTSTATUS pvfs_trans(struct smbsrv_request *req, struct smb_trans2 *trans2)
273 {
274         return NT_STATUS_ACCESS_DENIED;
275 }
276
277 /*
278   initialialise the POSIX disk backend, registering ourselves with the ntvfs subsystem
279  */
280 NTSTATUS ntvfs_posix_init(void)
281 {
282         NTSTATUS ret;
283         struct ntvfs_ops ops;
284
285         ZERO_STRUCT(ops);
286
287         ops.name = "default";
288         ops.type = NTVFS_DISK;
289         
290         /* fill in all the operations */
291         ops.connect = pvfs_connect;
292         ops.disconnect = pvfs_disconnect;
293         ops.unlink = pvfs_unlink;
294         ops.chkpath = pvfs_chkpath;
295         ops.qpathinfo = pvfs_qpathinfo;
296         ops.setpathinfo = pvfs_setpathinfo;
297         ops.open = pvfs_open;
298         ops.mkdir = pvfs_mkdir;
299         ops.rmdir = pvfs_rmdir;
300         ops.rename = pvfs_rename;
301         ops.copy = pvfs_copy;
302         ops.ioctl = pvfs_ioctl;
303         ops.read = pvfs_read;
304         ops.write = pvfs_write;
305         ops.seek = pvfs_seek;
306         ops.flush = pvfs_flush; 
307         ops.close = pvfs_close;
308         ops.exit = pvfs_exit;
309         ops.lock = pvfs_lock;
310         ops.setfileinfo = pvfs_setfileinfo;
311         ops.qfileinfo = pvfs_qfileinfo;
312         ops.fsinfo = pvfs_fsinfo;
313         ops.lpq = pvfs_lpq;
314         ops.search_first = pvfs_search_first;
315         ops.search_next = pvfs_search_next;
316         ops.search_close = pvfs_search_close;
317         ops.trans = pvfs_trans;
318
319         /* register ourselves with the NTVFS subsystem. We register
320            under the name 'default' as we wish to be the default
321            backend, and also register as 'posix' */
322         ops.name = "posix";
323         ret = register_backend("ntvfs", &ops);
324
325         ret = register_backend("ntvfs", &ops);
326
327         if (!NT_STATUS_IS_OK(ret)) {
328                 DEBUG(0,("Failed to register POSIX backend!\n"));
329         }
330
331         return ret;
332 }