r14456: don't access the smbsrv_tcon inside the ntvfs modules
[samba.git] / source4 / ntvfs / ntvfs.h
1 /* 
2    Unix SMB/CIFS implementation.
3    NTVFS structures and defines
4    Copyright (C) Andrew Tridgell                        2003
5    Copyright (C) Stefan Metzmacher                      2004
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 /* modules can use the following to determine if the interface has changed */
23 /* version 1 -> 0 - make module stacking easier -- metze */
24 #define NTVFS_INTERFACE_VERSION 0
25
26 struct ntvfs_module_context;
27
28 #define ntvfs_request smbsrv_request
29
30 /* each backend has to be one one of the following 3 basic types. In
31  * earlier versions of Samba backends needed to handle all types, now
32  * we implement them separately. */
33 enum ntvfs_type {NTVFS_DISK, NTVFS_PRINT, NTVFS_IPC};
34
35 /* the ntvfs operations structure - contains function pointers to 
36    the backend implementations of each operation */
37 struct ntvfs_ops {
38         const char *name;
39         enum ntvfs_type type;
40
41         /* initial setup */
42         NTSTATUS (*connect)(struct ntvfs_module_context *ntvfs,
43                             struct ntvfs_request *req,
44                             const char *sharename);
45         NTSTATUS (*disconnect)(struct ntvfs_module_context *ntvfs);
46
47         /* async_setup - called when a backend is processing a async request */
48         NTSTATUS (*async_setup)(struct ntvfs_module_context *ntvfs,
49                                 struct ntvfs_request *req,
50                                 void *private);
51
52         /* filesystem operations */
53         NTSTATUS (*fsinfo)(struct ntvfs_module_context *ntvfs,
54                            struct ntvfs_request *req,
55                            union smb_fsinfo *fs);
56
57         /* path operations */
58         NTSTATUS (*unlink)(struct ntvfs_module_context *ntvfs,
59                            struct ntvfs_request *req,
60                            union smb_unlink *unl);
61         NTSTATUS (*chkpath)(struct ntvfs_module_context *ntvfs,
62                             struct ntvfs_request *req,
63                             union smb_chkpath *cp);
64         NTSTATUS (*qpathinfo)(struct ntvfs_module_context *ntvfs,
65                               struct ntvfs_request *req,
66                               union smb_fileinfo *st);
67         NTSTATUS (*setpathinfo)(struct ntvfs_module_context *ntvfs,
68                                 struct ntvfs_request *req,
69                                 union smb_setfileinfo *st);
70         NTSTATUS (*mkdir)(struct ntvfs_module_context *ntvfs,
71                           struct ntvfs_request *req,
72                           union smb_mkdir *md);
73         NTSTATUS (*rmdir)(struct ntvfs_module_context *ntvfs,
74                           struct ntvfs_request *req,
75                           struct smb_rmdir *rd);
76         NTSTATUS (*rename)(struct ntvfs_module_context *ntvfs,
77                            struct ntvfs_request *req,
78                            union smb_rename *ren);
79         NTSTATUS (*copy)(struct ntvfs_module_context *ntvfs,
80                          struct ntvfs_request *req,
81                          struct smb_copy *cp);
82         NTSTATUS (*open)(struct ntvfs_module_context *ntvfs,
83                          struct ntvfs_request *req,
84                          union smb_open *oi);
85
86         /* directory search */
87         NTSTATUS (*search_first)(struct ntvfs_module_context *ntvfs,
88                                  struct ntvfs_request *req,
89                                  union smb_search_first *io, void *private,
90                                  BOOL (*callback)(void *private, union smb_search_data *file));
91         NTSTATUS (*search_next)(struct ntvfs_module_context *ntvfs,
92                                 struct ntvfs_request *req,
93                                 union smb_search_next *io, void *private,
94                                 BOOL (*callback)(void *private, union smb_search_data *file));
95         NTSTATUS (*search_close)(struct ntvfs_module_context *ntvfs,
96                                  struct ntvfs_request *req,
97                                  union smb_search_close *io);
98
99         /* operations on open files */
100         NTSTATUS (*ioctl)(struct ntvfs_module_context *ntvfs,
101                           struct ntvfs_request *req,
102                           union smb_ioctl *io);
103         NTSTATUS (*read)(struct ntvfs_module_context *ntvfs,
104                          struct ntvfs_request *req,
105                          union smb_read *io);
106         NTSTATUS (*write)(struct ntvfs_module_context *ntvfs,
107                           struct ntvfs_request *req,
108                           union smb_write *io);
109         NTSTATUS (*seek)(struct ntvfs_module_context *ntvfs,
110                          struct ntvfs_request *req,
111                          union smb_seek *io);
112         NTSTATUS (*flush)(struct ntvfs_module_context *ntvfs,
113                           struct ntvfs_request *req,
114                           union smb_flush *flush);
115         NTSTATUS (*lock)(struct ntvfs_module_context *ntvfs,
116                          struct ntvfs_request *req,
117                          union smb_lock *lck);
118         NTSTATUS (*qfileinfo)(struct ntvfs_module_context *ntvfs,
119                               struct ntvfs_request *req,
120                               union smb_fileinfo *info);
121         NTSTATUS (*setfileinfo)(struct ntvfs_module_context *ntvfs,
122                                 struct ntvfs_request *req,
123                                 union smb_setfileinfo *info);
124         NTSTATUS (*close)(struct ntvfs_module_context *ntvfs,
125                           struct ntvfs_request *req,
126                           union smb_close *io);
127
128         /* trans interface - used by IPC backend for pipes and RAP calls */
129         NTSTATUS (*trans)(struct ntvfs_module_context *ntvfs,
130                           struct ntvfs_request *req,
131                           struct smb_trans2 *trans);
132
133         /* trans2 interface - only used by CIFS backend to prover complete passthru for testing */
134         NTSTATUS (*trans2)(struct ntvfs_module_context *ntvfs,
135                            struct ntvfs_request *req,
136                            struct smb_trans2 *trans2);
137
138         /* change notify request */
139         NTSTATUS (*notify)(struct ntvfs_module_context *ntvfs,
140                            struct ntvfs_request *req,
141                            union smb_notify *info);
142
143         /* cancel - cancels any pending async request */
144         NTSTATUS (*cancel)(struct ntvfs_module_context *ntvfs,
145                            struct ntvfs_request *req);
146
147         /* printing specific operations */
148         NTSTATUS (*lpq)(struct ntvfs_module_context *ntvfs, 
149                         struct ntvfs_request *req,
150                         union smb_lpq *lpq);
151
152         /* logoff - called when a vuid is closed */
153         NTSTATUS (*logoff)(struct ntvfs_module_context *ntvfs,
154                            struct ntvfs_request *req);
155         NTSTATUS (*exit)(struct ntvfs_module_context *ntvfs,
156                          struct ntvfs_request *req);
157 };
158
159 struct ntvfs_module_context {
160         struct ntvfs_module_context *prev, *next;
161         struct ntvfs_context *ctx;
162         int depth;
163         const struct ntvfs_ops *ops;
164         void *private_data;
165 };
166
167 struct ntvfs_context {
168         enum ntvfs_type type;
169
170         /* the reported filesystem type */
171         char *fs_type;
172
173         /* the reported device type */
174         char *dev_type;
175
176         enum protocol_types protocol;
177
178         /* 
179          * linked list of module contexts
180          */
181         struct ntvfs_module_context *modules;
182
183         struct {
184                 int snum;
185         } config;
186
187         uint32_t server_id;
188         struct event_context *event_ctx;
189         struct messaging_context *msg_ctx;
190
191         struct {
192                 void *private_data;
193                 NTSTATUS (*handler)(void *private_data, uint16_t fnum, uint8_t level);
194         } oplock;
195 };
196
197
198 /* a set of flags to control handling of request structures */
199 #define NTVFS_ASYNC_STATE_ASYNC     (1<<1) /* the backend will answer this one later */
200 #define NTVFS_ASYNC_STATE_MAY_ASYNC (1<<2) /* the backend is allowed to answer async */
201
202 /* the ntvfs_async_state structure allows backend functions to 
203    delay replying to requests. To use this, the front end must
204    set send_fn to a function to be called by the backend
205    when the reply is finally ready to be sent. The backend
206    must set status to the status it wants in the
207    reply. The backend must set the NTVFS_ASYNC_STATE_ASYNC
208    control_flag on the request to indicate that it wishes to
209    delay the reply
210
211    If NTVFS_ASYNC_STATE_MAY_ASYNC is not set then the backend cannot
212    ask for a delayed reply for this request
213
214    note that the private_data pointer is private to the layer which alloced this struct
215 */
216 struct ntvfs_async_state {
217         struct ntvfs_async_state *prev, *next;
218         /* the async handling infos */
219         uint_t state;
220         void *private_data;
221         void (*send_fn)(struct ntvfs_request *);
222         NTSTATUS status;
223
224         /* the passthru module's per session private data */
225         struct ntvfs_module_context *ntvfs;
226 };
227
228 /* this structure is used by backends to determine the size of some critical types */
229 struct ntvfs_critical_sizes {
230         int interface_version;
231         int sizeof_ntvfs_critical_sizes;
232         int sizeof_ntvfs_context;
233         int sizeof_ntvfs_module_context;
234         int sizeof_ntvfs_ops;
235         int sizeof_ntvfs_async_state;
236         int sizeof_ntvfs_request;
237 };
238
239 struct messaging_context;
240
241 #include "ntvfs/ntvfs_proto.h"