s3: VFS: Change SMB_VFS_REMOVEXATTR to use const struct smb_filename * instead of...
[sfrench/samba-autobuild/.git] / source3 / include / vfs.h
1 /* 
2    Unix SMB/CIFS implementation.
3    VFS structures and parameters
4    Copyright (C) Jeremy Allison                         1999-2005
5    Copyright (C) Tim Potter                             1999
6    Copyright (C) Alexander Bokovoy                      2002-2005
7    Copyright (C) Stefan (metze) Metzmacher              2003
8    Copyright (C) Volker Lendecke                        2009
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23    This work was sponsored by Optifacio Software Services, Inc.
24 */
25
26 #ifndef _VFS_H
27 #define _VFS_H
28
29 /* Avoid conflict with an AIX include file */
30
31 #ifdef vfs_ops
32 #undef vfs_ops
33 #endif
34
35 /*
36  * As we're now (thanks Andrew ! :-) using file_structs and connection
37  * structs in the vfs - then anyone writing a vfs must include includes.h...
38  */
39
40 /*
41  * This next constant specifies the version number of the VFS interface
42  * this smbd will load. Increment this if *ANY* changes are made to the
43  * vfs_ops below. JRA.
44  *
45  * If you change anything here, please also update modules/vfs_full_audit.c.
46  * VL.
47  */
48
49 /* Changed to version 2 for CIFS UNIX extensions (mknod and link added). JRA. */
50 /* Changed to version 3 for POSIX acl extensions. JRA. */
51 /* Changed to version 4 for cascaded VFS interface. Alexander Bokovoy. */
52 /* Changed to version 5 for sendfile addition. JRA. */
53 /* Changed to version 6 for the new module system, fixed cascading and quota functions. --metze */
54 /* Changed to version 7 to include the get_nt_acl info parameter. JRA. */
55 /* Changed to version 8 includes EA calls. JRA. */
56 /* Changed to version 9 to include the get_shadow_data call. --metze */
57 /* Changed to version 10 to include pread/pwrite calls. */
58 /* Changed to version 11 to include seekdir/telldir/rewinddir calls. JRA */
59 /* Changed to version 12 to add mask and attributes to opendir(). JRA 
60    Also include aio calls. JRA. */
61 /* Changed to version 13 as the internal structure of files_struct has changed. JRA */
62 /* Changed to version 14 as we had to change DIR to SMB_STRUCT_DIR. JRA */
63 /* Changed to version 15 as we added the statvfs call. JRA */
64 /* Changed to version 16 as we added the getlock call. JRA */
65 /* Changed to version 17 as we removed redundant connection_struct parameters. --jpeach */
66 /* Changed to version 18 to add fsp parameter to the open call -- jpeach 
67    Also include kernel_flock call - jmcd */
68 /* Changed to version 19, kernel change notify has been merged 
69    Also included linux setlease call - jmcd */
70 /* Changed to version 20, use ntimes call instead of utime (greater
71  * timestamp resolition. JRA. */
72 /* Changed to version21 to add chflags operation -- jpeach */
73 /* Changed to version22 to add lchown operation -- jra */
74 /* Leave at 22 - not yet released. But change set_nt_acl to return an NTSTATUS. jra. */
75 /* Leave at 22 - not yet released. Add file_id_create operation. --metze */
76 /* Leave at 22 - not yet released. Change all BOOL parameters (int) to bool. jra. */
77 /* Leave at 22 - not yet released. Added recvfile. */
78 /* Leave at 22 - not yet released. Change get_nt_acl to return NTSTATUS - vl */
79 /* Leave at 22 - not yet released. Change get_nt_acl to *not* take a
80  * files_struct. - obnox.*/
81 /* Leave at 22 - not yet released. Remove parameter fd from fget_nt_acl. - obnox */
82 /* Leave at 22 - not yet released. Remove parameter fd from gset_nt_acl. - obnox */
83 /* Leave at 22 - not yet released. Remove parameter fd from pread. - obnox */
84 /* Leave at 22 - not yet released. Remove parameter fd from pwrite. - obnox */
85 /* Leave at 22 - not yet released. Remove parameter fd from lseek. - obnox */
86 /* Leave at 22 - not yet released. Remove parameter fd from fsync. - obnox */
87 /* Leave at 22 - not yet released. Remove parameter fd from fstat. - obnox */
88 /* Leave at 22 - not yet released. Remove parameter fd from fchmod. - obnox */
89 /* Leave at 22 - not yet released. Remove parameter fd from fchown. - obnox */
90 /* Leave at 22 - not yet released. Remove parameter fd from ftruncate. - obnox */
91 /* Leave at 22 - not yet released. Remove parameter fd from lock. - obnox */
92 /* Leave at 22 - not yet released. Remove parameter fd from kernel_flock. - obnox */
93 /* Leave at 22 - not yet released. Remove parameter fd from linux_setlease. - obnox */
94 /* Leave at 22 - not yet released. Remove parameter fd from getlock. - obnox */
95 /* Leave at 22 - not yet released. Remove parameter fd from sys_acl_get_fd. - obnox */
96 /* Leave at 22 - not yet released. Remove parameter fd from fchmod_acl. - obnox */
97 /* Leave at 22 - not yet released. Remove parameter fd from sys_acl_set_fd. - obnox */
98 /* Leave at 22 - not yet released. Remove parameter fd from fgetxattr. - obnox */
99 /* Leave at 22 - not yet released. Remove parameter fd from flistxattr. - obnox */
100 /* Leave at 22 - not yet released. Remove parameter fd from fremovexattr. - obnox */
101 /* Leave at 22 - not yet released. Remove parameter fd from fsetxattr. - obnox */
102 /* Leave at 22 - not yet released. Remove parameter fd from aio_cancel. - obnox */
103 /* Leave at 22 - not yet released. Remove parameter fd from read. - obnox */
104 /* Leave at 22 - not yet released. Remove parameter fd from write. - obnox */
105 /* Leave at 22 - not yet released. Remove parameter fromfd from sendfile. - obnox */
106 /* Leave at 22 - not yet released. Remove parameter fromfd from recvfile. - obnox */
107 /* Leave at 22 - not yet released. Additional change: add operations for offline files -- ab */
108 /* Leave at 22 - not yet released. Add the streaminfo call. -- jpeach, vl */
109 /* Leave at 22 - not yet released. Remove parameter fd from close_fn. - obnox */
110 /* Changed to version 23 - remove set_nt_acl call. This can only be done via an
111    open handle. JRA. */
112 /* Changed to version 24 - make security descriptor const in fset_nt_acl. JRA. */
113 /* Changed to version 25 - Jelmer's change from SMB_BIG_UINT to uint64_t. */
114 /* Leave at 25 - not yet released. Add create_file call. -- tprouty. */
115 /* Leave at 25 - not yet released. Add create time to ntimes. -- tstecher. */
116 /* Leave at 25 - not yet released. Add get_alloc_size call. -- tprouty. */
117 /* Leave at 25 - not yet released. Add SMB_STRUCT_STAT to readdir. - sdann */
118 /* Leave at 25 - not yet released. Add init_search_op call. - sdann */
119 /* Leave at 25 - not yet released. Add locking calls. -- zkirsch. */
120 /* Leave at 25 - not yet released. Add strict locking calls. -- drichards. */
121 /* Changed to version 26 - Plumb struct smb_filename to SMB_VFS_CREATE_FILE,
122                            SMB_VFS_OPEN, SMB_VFS_STAT, SMB_VFS_LSTAT,
123                            SMB_VFS_RENAME, SMB_VFS_UNLINK, SMB_VFS_NTIMES.  */
124 /* Changed to version 27 - not yet released. Added enum timestamp_set_resolution
125  *                         return to fs_capabilities call. JRA. */
126 /* Leave at 27 - not yet released. Add translate_name VFS call to convert
127                  UNIX names to Windows supported names -- asrinivasan. */
128 /* Changed to version 28 - Add private_flags uint32_t to CREATE call. */
129 /* Leave at 28 - not yet released. Change realpath to assume NULL and return a
130                  malloc'ed path. JRA. */
131 /* Leave at 28 - not yet released. Move posix_fallocate into the VFS
132                 where it belongs. JRA. */
133 /* Leave at 28 - not yet released. Rename posix_fallocate to fallocate
134                 to split out the two possible uses. JRA. */
135 /* Leave at 28 - not yet released. Add fdopendir. JRA. */
136 /* Leave at 28 - not yet released. Rename open function to open_fn. - gd */
137 /* Leave at 28 - not yet released. Make getwd function always return malloced memory. JRA. */
138 /* Bump to version 29 - Samba 3.6.0 will ship with interface version 28. */
139 /* Leave at 29 - not yet releases. Add fsctl. Richard Sharpe */
140 /* Leave at 29 - not yet released. add SMB_VFS_GET_DFS_REFERRAL() - metze */
141 /* Leave at 29 - not yet released. Remove l{list,get,set,remove}xattr - abartlet */
142 /* Leave at 29 - not yet released. move to plain off_t - abartlet */
143 /* Leave at 29 - not yet released. Remove sys_acl functions other than set and get - abartlet */
144 /* Leave at 29 - not yet released. Added backup_intent bool to files_struct - JRA */
145 /* Leave at 29 - not yet released. Add durable handle functions - metze/obnox */
146 /* Leave at 29 - not yet released. Added sys_acl_blob_get_file and sys_acl_blob_get_fd */
147 /* Bump to version 30 - Samba 4.0.0 will ship with interface version 30 */
148 /* Leave at 30 - not yet released. Added conn->cwd to save vfs_GetWd() calls. */
149 /* Leave at 30 - not yet released. Changed sys_acl_blob_get_file interface to remove type */
150 /* Bump to version 31 - Samba 4.1.0 will ship with interface version 31 */
151 /* Leave at 31 - not yet released. Make struct vuid_cache_entry in
152                 connection_struct a pointer. */
153 /* Leave at 31 - not yet released. Add share_access to vuid_cache_entry. */
154 /* Leave at 31 - not yet released. add SMB_VFS_COPY_CHUNK() */
155 /* Leave at 31 - not yet released. Remove the unused
156                 fsp->pending_break_messages array */
157 /* Leave at 31 - not yet released. add SMB_VFS_[GET/SET]_COMPRESSION() */
158
159 /* Bump to version 32 - Samba 4.2 will ship with that. */
160 /* Version 32 - Add "lease" to CREATE_FILE operation */
161 /* Version 32 - Add "lease" to struct files_struct */
162 /* Version 32 - Add SMB_VFS_READDIR_ATTR() */
163 /* Version 32 - Add in and out create context blobs to create_file */
164 /* Version 32 - Remove unnecessary SMB_VFS_DISK_FREE() small_query parameter */
165 /* Bump to version 33 - Samba 4.3 will ship with that. */
166 /* Version 33 - change fallocate mode flags param from enum->uint32_t */
167 /* Version 33 - Add snapshot create/delete calls */
168 /* Version 33 - Add OS X SMB2 AAPL copyfile extension flag to fsp */
169 /* Version 33 - Remove notify_watch_fn */
170 /* Bump to version 34 - Samba 4.4 will ship with that */
171 /* Version 34 - Remove bool posix_open, add uint64_t posix_flags */
172 /* Version 34 - Added bool posix_pathnames to struct smb_request */
173 /* Bump to version 35 - Samba 4.5 will ship with that */
174 /* Version 35 - Change get_nt_acl_fn from const char *, to
175                 const struct smb_filename * */
176 /* Version 35 - Change mkdir from const char *, to
177                 const struct smb_filename * */
178 /* Version 35 - Change rmdir from const char *, to
179                 const struct smb_filename * */
180 /* Version 35 - Change opendir from const char *, to
181                 const struct smb_filename * */
182 /* Version 35 - Wrap aio async funtions args in a struct vfs_aio_state */
183 /* Version 35 - Change chmod from const char *, to
184                 const struct smb_filename * */
185 /* Version 35 - Change chmod_acl from const char *, to
186                 const struct smb_filename * */
187 /* Version 35 - Change chown from const char *, to
188                 const struct smb_filename * */
189 /* Version 35 - Change lchown from const char *, to
190                 const struct smb_filename * */
191 /* Version 35 - Change streaminfo from const char *, to
192                 const struct smb_filename * */
193 /* Version 35 - Add uint32_t flags to struct smb_filename */
194 /* Version 35 - Add get/set/fget/fset dos attribute functions. */
195 /* Version 35 - Add bool use_ofd_locks to struct files_struct */
196 /* Bump to version 36 - Samba 4.6 will ship with that */
197 /* Version 36 - Remove is_offline and set_offline */
198 /* Version 37 - Module init functions now take a TALLOC_CTX * parameter. */
199 /* Version 37 - Add vfs_copy_chunk_flags for DUP_EXTENTS_TO_FILE */
200 /* Version 37 - Change sys_acl_delete_def_file from const char *
201                 to const struct smb_filename * */
202 /* Version 37 - Change sys_acl_get_file from const char *
203                 to const struct smb_filename * */
204 /* Version 37 - Change sys_acl_blob_get_file from const char *
205                 to const struct smb_filename * */
206 /* Version 37 - Change sys_acl_set_file from const char *
207                 to const struct smb_filename * */
208 /* Version 37 - Change listxattr from const char *
209                 to const struct smb_filename * */
210 /* Version 37 - Change removexattr from const char *
211                 to const struct smb_filename * */
212
213 #define SMB_VFS_INTERFACE_VERSION 37
214
215 /*
216     All intercepted VFS operations must be declared as static functions inside module source
217     in order to keep smbd namespace unpolluted. See source of audit, extd_audit, fake_perms and recycle
218     example VFS modules for more details.
219 */
220
221 /* VFS operations structure */
222
223 struct vfs_handle_struct;
224 struct connection_struct;
225 struct files_struct;
226 struct security_descriptor;
227 struct vfs_statvfs_struct;
228 struct smb_request;
229 struct ea_list;
230 struct smb_file_time;
231 struct blocking_lock_record;
232 struct smb_filename;
233 struct dfs_GetDFSReferral;
234
235 typedef union unid_t {
236         uid_t uid;
237         gid_t gid;
238 } unid_t;
239
240 struct fd_handle {
241         size_t ref_count;
242         int fd;
243         uint64_t position_information;
244         off_t pos;
245         uint32_t private_options;       /* NT Create options, but we only look at
246                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_DOS and
247                                  * NTCREATEX_OPTIONS_PRIVATE_DENY_FCB and
248                                  * NTCREATEX_OPTIONS_PRIVATE_DELETE_ON_CLOSE
249                                  * for print files *only*, where
250                                  * DELETE_ON_CLOSE is not stored in the share
251                                  * mode database.
252                                  */
253         unsigned long gen_id;
254 };
255
256 struct fsp_lease {
257         size_t ref_count;
258         struct smbd_server_connection *sconn;
259         struct tevent_timer *timeout;
260         struct smb2_lease lease;
261 };
262
263 typedef struct files_struct {
264         struct files_struct *next, *prev;
265         uint64_t fnum;
266         struct smbXsrv_open *op;
267         struct connection_struct *conn;
268         struct fd_handle *fh;
269         unsigned int num_smb_operations;
270         struct file_id file_id;
271         uint64_t initial_allocation_size; /* Faked up initial allocation on disk. */
272         uint16_t file_pid;
273         uint64_t vuid; /* SMB2 compat */
274         struct write_cache *wcp;
275         struct timeval open_time;
276         uint32_t access_mask;           /* NTCreateX access bits (FILE_READ_DATA etc.) */
277         uint32_t share_access;          /* NTCreateX share constants (FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE). */
278
279         bool kernel_share_modes_taken;
280
281         bool update_write_time_triggered;
282         struct tevent_timer *update_write_time_event;
283         bool update_write_time_on_close;
284         struct timespec close_write_time;
285         bool write_time_forced;
286
287         int oplock_type;
288         struct fsp_lease *lease;
289         int sent_oplock_break;
290         struct tevent_timer *oplock_timeout;
291         struct lock_struct last_lock_failure;
292         int current_lock_count; /* Count the number of outstanding locks and pending locks. */
293
294         bool can_lock;
295         bool can_read;
296         bool can_write;
297         bool modified;
298         bool is_directory;
299         bool aio_write_behind;
300         bool initial_delete_on_close; /* Only set at NTCreateX if file was created. */
301         bool delete_on_close;
302         uint64_t posix_flags;
303         bool is_sparse;
304         bool backup_intent; /* Handle was successfully opened with backup intent
305                                 and opener has privilege to do so. */
306         bool aapl_copyfile_supported;
307         bool use_ofd_locks; /* Are we using open file description locks ? */
308         struct smb_filename *fsp_name;
309         uint32_t name_hash;             /* Jenkins hash of full pathname. */
310         uint64_t mid;                   /* Mid of the operation that created us. */
311
312         struct vfs_fsp_data *vfs_extension;
313         struct fake_file_handle *fake_file_handle;
314
315         struct notify_change_buf *notify;
316
317         struct files_struct *base_fsp; /* placeholder for delete on close */
318
319         /*
320          * Read-only cached brlock record, thrown away when the
321          * brlock.tdb seqnum changes. This avoids fetching data from
322          * the brlock.tdb on every read/write call.
323          */
324         int brlock_seqnum;
325         struct byte_range_lock *brlock_rec;
326
327         struct dptr_struct *dptr;
328
329         /* if not NULL, means this is a print file */
330         struct print_file_data *print_file;
331
332         unsigned num_aio_requests;
333         struct tevent_req **aio_requests;
334
335         /*
336          * If a close request comes in while we still have aio_requests
337          * around, we need to hold back the close. When all aio_requests are
338          * done, the aio completion routines need tevent_wait_done() on
339          * this. A bit ugly, but before we have close_file() fully async
340          * possibly the simplest approach. Thanks, Jeremy for the idea.
341          */
342         struct tevent_req *deferred_close;
343 } files_struct;
344
345 #define FSP_POSIX_FLAGS_OPEN            0x01
346 #define FSP_POSIX_FLAGS_RENAME          0x02
347 #define FSP_POSIX_FLAGS_PATHNAMES       0x04
348
349 #define FSP_POSIX_FLAGS_ALL                     \
350         (FSP_POSIX_FLAGS_OPEN |                 \
351          FSP_POSIX_FLAGS_PATHNAMES |            \
352          FSP_POSIX_FLAGS_RENAME)
353
354 struct vuid_cache_entry {
355         struct auth_session_info *session_info;
356         uint64_t vuid; /* SMB2 compat */
357         bool read_only;
358         uint32_t share_access;
359 };
360
361 struct vuid_cache {
362         unsigned int next_entry;
363         struct vuid_cache_entry array[VUID_CACHE_SIZE];
364 };
365
366 typedef struct {
367         char *name;
368         bool is_wild;
369 } name_compare_entry;
370
371 struct dfree_cached_info {
372         time_t last_dfree_time;
373         uint64_t dfree_ret;
374         uint64_t bsize;
375         uint64_t dfree;
376         uint64_t dsize;
377 };
378
379 struct share_params {
380         int service;
381 };
382
383 typedef struct connection_struct {
384         struct connection_struct *next, *prev;
385         struct smbd_server_connection *sconn; /* can be NULL */
386         struct smbXsrv_tcon *tcon; /* can be NULL */
387         uint32_t cnum; /* an index passed over the wire */
388         struct share_params *params;
389         bool force_user;
390         struct vuid_cache *vuid_cache;
391         bool printer;
392         bool ipc;
393         bool read_only; /* Attributes for the current user of the share. */
394         uint32_t share_access;
395         /* Does this filesystem honor
396            sub second timestamps on files
397            and directories when setting time ? */
398         enum timestamp_set_resolution ts_res;
399         char *connectpath;
400         char *origpath;
401         char *cwd; /* Working directory. */
402
403         struct vfs_handle_struct *vfs_handles;          /* for the new plugins */
404
405         /*
406          * This represents the user information on this connection. Depending
407          * on the vuid using this tid, this might change per SMB request.
408          */
409         struct auth_session_info *session_info;
410
411         /*
412          * If the "force group" parameter is set, this is the primary gid that
413          * may be used in the users token, depending on the vuid using this tid.
414          */
415         gid_t force_group_gid;
416
417         uint64_t vuid; /* vuid of user who *opened* this connection, or UID_FIELD_INVALID */
418
419         time_t lastused;
420         time_t lastused_count;
421         int num_files_open;
422         unsigned int num_smb_operations; /* Count of smb operations on this tree. */
423         int encrypt_level;
424         bool encrypted_tid;
425
426         /* Semantics requested by the client or forced by the server config. */
427         bool case_sensitive;
428         bool case_preserve;
429         bool short_case_preserve;
430
431         /* Semantics provided by the underlying filesystem. */
432         int fs_capabilities;
433         /* Device number of the directory of the share mount.
434            Used to ensure unique FileIndex returns. */
435         SMB_DEV_T base_share_dev;
436
437         name_compare_entry *hide_list; /* Per-share list of files to return as hidden. */
438         name_compare_entry *veto_list; /* Per-share list of files to veto (never show). */
439         name_compare_entry *veto_oplock_list; /* Per-share list of files to refuse oplocks on. */       
440         name_compare_entry *aio_write_behind_list; /* Per-share list of files to use aio write behind on. */       
441         struct dfree_cached_info *dfree_info;
442         struct trans_state *pending_trans;
443
444         struct rpc_pipe_client *spoolss_pipe;
445
446 } connection_struct;
447
448 struct smbd_smb2_request;
449 struct privilege_paths;
450
451 struct smb_request {
452         uint8_t cmd;
453         uint16_t flags2;
454         uint16_t smbpid;
455         uint64_t mid; /* For compatibility with SMB2. */
456         uint32_t seqnum;
457         uint64_t vuid; /* For compatibility with SMB2. */
458         uint32_t tid;
459         uint8_t  wct;
460         const uint16_t *vwv;
461         uint16_t buflen;
462         const uint8_t *buf;
463         const uint8_t *inbuf;
464
465         /*
466          * Async handling in the main smb processing loop is directed by
467          * outbuf: reply_xxx routines indicate sync behaviour by putting their
468          * reply into "outbuf". If they leave it as NULL, they take care of it
469          * themselves, possibly later.
470          *
471          * If async handling is wanted, the reply_xxx routine must make sure
472          * that it talloc_move()s the smb_req somewhere else.
473          */
474         uint8_t *outbuf;
475
476         size_t unread_bytes;
477         bool encrypted;
478         connection_struct *conn;
479         struct smbd_server_connection *sconn;
480         struct smbXsrv_connection *xconn;
481         struct smb_perfcount_data pcd;
482
483         /*
484          * Chained request handling
485          */
486         struct files_struct *chain_fsp;
487
488         /*
489          * state information for async smb handling
490          */
491         void *async_priv;
492
493         /*
494          * Back pointer to smb2 request.
495          */
496         struct smbd_smb2_request *smb2req;
497
498         /*
499          * Pathnames used if request done
500          * under privilege.
501          */
502         struct privilege_paths *priv_paths;
503
504         /*
505          * Request list for chained requests, we're part of it.
506          */
507         struct smb_request **chain;
508
509         struct timeval request_time;
510
511         bool posix_pathnames;
512 };
513
514 /*
515  * Info about an alternate data stream
516  */
517
518 struct stream_struct {
519         off_t size;
520         off_t alloc_size;
521         char *name;
522 };
523
524 /* time info */
525 struct smb_file_time {
526         struct timespec mtime;
527         struct timespec atime;
528         struct timespec ctime;
529         struct timespec create_time;
530 };
531
532 /*
533  * smb_filename
534  */
535 struct smb_filename {
536         char *base_name;
537         char *stream_name;
538         char *original_lcomp;
539         uint32_t flags;
540         SMB_STRUCT_STAT st;
541 };
542
543 /*
544  * smb_filename flags. Define in terms of the FSP_POSIX_FLAGS_XX
545  * to keep the numeric values consistent.
546  */
547
548 #define SMB_FILENAME_POSIX_PATH         FSP_POSIX_FLAGS_PATHNAMES
549
550 #define VFS_FIND(__fn__) while (handle->fns->__fn__##_fn==NULL) { \
551                                 handle = handle->next; \
552                          }
553
554 enum vfs_translate_direction {
555         vfs_translate_to_unix = 0,
556         vfs_translate_to_windows
557 };
558
559 enum vfs_fallocate_flags {
560         VFS_FALLOCATE_FL_KEEP_SIZE              = 0x0001,
561         VFS_FALLOCATE_FL_PUNCH_HOLE             = 0x0002,
562 };
563
564 /*
565  * @VFS_COPY_CHUNK_FL_MUST_CLONE: indicates that copy_chunk_send_fn() copy must
566  *                                be handled as a COW clone, AKA reflink.
567  * @VFS_COPY_CHUNK_FL_MASK_ALL: all valid copychunk flags.
568  */
569 enum vfs_copy_chunk_flags {
570         VFS_COPY_CHUNK_FL_MUST_CLONE            = 0x0001,
571         VFS_COPY_CHUNK_FL_IGNORE_LOCKS          = 0x0002,
572
573         VFS_COPY_CHUNK_FL_MASK_ALL              =
574                                         (VFS_COPY_CHUNK_FL_MUST_CLONE
575                                          | VFS_COPY_CHUNK_FL_IGNORE_LOCKS),
576 };
577
578 struct vfs_aio_state {
579         int error;
580         uint64_t duration;
581 };
582
583 /*
584     Available VFS operations. These values must be in sync with vfs_ops struct
585     (struct vfs_fn_pointers and struct vfs_handle_pointers inside of struct vfs_ops).
586     In particular, if new operations are added to vfs_ops, appropriate constants
587     should be added to vfs_op_type so that order of them kept same as in vfs_ops.
588 */
589 struct shadow_copy_data;
590
591 struct vfs_fn_pointers {
592         /* Disk operations */
593
594         int (*connect_fn)(struct vfs_handle_struct *handle, const char *service, const char *user);
595         void (*disconnect_fn)(struct vfs_handle_struct *handle);
596         uint64_t (*disk_free_fn)(struct vfs_handle_struct *handle, const char *path, uint64_t *bsize,
597                               uint64_t *dfree, uint64_t *dsize);
598         int (*get_quota_fn)(struct vfs_handle_struct *handle, const char *path,
599                             enum SMB_QUOTA_TYPE qtype, unid_t id,
600                             SMB_DISK_QUOTA *qt);
601         int (*set_quota_fn)(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt);
602         int (*get_shadow_copy_data_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, struct shadow_copy_data *shadow_copy_data, bool labels);
603         int (*statvfs_fn)(struct vfs_handle_struct *handle, const char *path, struct vfs_statvfs_struct *statbuf);
604         uint32_t (*fs_capabilities_fn)(struct vfs_handle_struct *handle, enum timestamp_set_resolution *p_ts_res);
605
606         /*
607          * Note: that "struct dfs_GetDFSReferral *r"
608          * needs to be a valid TALLOC_CTX
609          */
610         NTSTATUS (*get_dfs_referrals_fn)(struct vfs_handle_struct *handle,
611                                          struct dfs_GetDFSReferral *r);
612
613         /* Directory operations */
614
615         DIR *(*opendir_fn)(struct vfs_handle_struct *handle,
616                                         const struct smb_filename *smb_fname,
617                                         const char *mask,
618                                         uint32_t attributes);
619         DIR *(*fdopendir_fn)(struct vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32_t attributes);
620         struct dirent *(*readdir_fn)(struct vfs_handle_struct *handle,
621                                          DIR *dirp,
622                                          SMB_STRUCT_STAT *sbuf);
623         void (*seekdir_fn)(struct vfs_handle_struct *handle, DIR *dirp, long offset);
624         long (*telldir_fn)(struct vfs_handle_struct *handle, DIR *dirp);
625         void (*rewind_dir_fn)(struct vfs_handle_struct *handle, DIR *dirp);
626         int (*mkdir_fn)(struct vfs_handle_struct *handle,
627                         const struct smb_filename *smb_fname,
628                         mode_t mode);
629         int (*rmdir_fn)(struct vfs_handle_struct *handle,
630                         const struct smb_filename *smb_fname);
631         int (*closedir_fn)(struct vfs_handle_struct *handle, DIR *dir);
632         void (*init_search_op_fn)(struct vfs_handle_struct *handle, DIR *dirp);
633
634         /* File operations */
635
636         int (*open_fn)(struct vfs_handle_struct *handle,
637                        struct smb_filename *smb_fname, files_struct *fsp,
638                        int flags, mode_t mode);
639         NTSTATUS (*create_file_fn)(struct vfs_handle_struct *handle,
640                                    struct smb_request *req,
641                                    uint16_t root_dir_fid,
642                                    struct smb_filename *smb_fname,
643                                    uint32_t access_mask,
644                                    uint32_t share_access,
645                                    uint32_t create_disposition,
646                                    uint32_t create_options,
647                                    uint32_t file_attributes,
648                                    uint32_t oplock_request,
649                                    struct smb2_lease *lease,
650                                    uint64_t allocation_size,
651                                    uint32_t private_flags,
652                                    struct security_descriptor *sd,
653                                    struct ea_list *ea_list,
654                                    files_struct **result,
655                                    int *pinfo,
656                                    const struct smb2_create_blobs *in_context_blobs,
657                                    struct smb2_create_blobs *out_context_blobs);
658         int (*close_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp);
659         ssize_t (*read_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, void *data, size_t n);
660         ssize_t (*pread_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, void *data, size_t n, off_t offset);
661         struct tevent_req *(*pread_send_fn)(struct vfs_handle_struct *handle,
662                                             TALLOC_CTX *mem_ctx,
663                                             struct tevent_context *ev,
664                                             struct files_struct *fsp,
665                                             void *data,
666                                             size_t n, off_t offset);
667         ssize_t (*pread_recv_fn)(struct tevent_req *req, struct vfs_aio_state *state);
668         ssize_t (*write_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const void *data, size_t n);
669         ssize_t (*pwrite_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const void *data, size_t n, off_t offset);
670         struct tevent_req *(*pwrite_send_fn)(struct vfs_handle_struct *handle,
671                                              TALLOC_CTX *mem_ctx,
672                                              struct tevent_context *ev,
673                                              struct files_struct *fsp,
674                                              const void *data,
675                                              size_t n, off_t offset);
676         ssize_t (*pwrite_recv_fn)(struct tevent_req *req, struct vfs_aio_state *state);
677         off_t (*lseek_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t offset, int whence);
678         ssize_t (*sendfile_fn)(struct vfs_handle_struct *handle, int tofd, files_struct *fromfsp, const DATA_BLOB *header, off_t offset, size_t count);
679         ssize_t (*recvfile_fn)(struct vfs_handle_struct *handle, int fromfd, files_struct *tofsp, off_t offset, size_t count);
680         int (*rename_fn)(struct vfs_handle_struct *handle,
681                          const struct smb_filename *smb_fname_src,
682                          const struct smb_filename *smb_fname_dst);
683         int (*fsync_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp);
684         struct tevent_req *(*fsync_send_fn)(struct vfs_handle_struct *handle,
685                                             TALLOC_CTX *mem_ctx,
686                                             struct tevent_context *ev,
687                                             struct files_struct *fsp);
688         int (*fsync_recv_fn)(struct tevent_req *req, struct vfs_aio_state *state);
689         int (*stat_fn)(struct vfs_handle_struct *handle, struct smb_filename *smb_fname);
690         int (*fstat_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_STAT *sbuf);
691         int (*lstat_fn)(struct vfs_handle_struct *handle, struct smb_filename *smb_filename);
692         uint64_t (*get_alloc_size_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const SMB_STRUCT_STAT *sbuf);
693         int (*unlink_fn)(struct vfs_handle_struct *handle,
694                          const struct smb_filename *smb_fname);
695         int (*chmod_fn)(struct vfs_handle_struct *handle,
696                         const struct smb_filename *smb_fname,
697                         mode_t mode);
698         int (*fchmod_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, mode_t mode);
699         int (*chown_fn)(struct vfs_handle_struct *handle,
700                         const struct smb_filename *smb_fname,
701                         uid_t uid,
702                         gid_t gid);
703         int (*fchown_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, uid_t uid, gid_t gid);
704         int (*lchown_fn)(struct vfs_handle_struct *handle,
705                         const struct smb_filename *smb_fname,
706                         uid_t uid,
707                         gid_t gid);
708         int (*chdir_fn)(struct vfs_handle_struct *handle, const char *path);
709         char *(*getwd_fn)(struct vfs_handle_struct *handle);
710         int (*ntimes_fn)(struct vfs_handle_struct *handle,
711                          const struct smb_filename *smb_fname,
712                          struct smb_file_time *ft);
713         int (*ftruncate_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t offset);
714         int (*fallocate_fn)(struct vfs_handle_struct *handle,
715                             struct files_struct *fsp,
716                             uint32_t mode,
717                             off_t offset,
718                             off_t len);
719         bool (*lock_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, int op, off_t offset, off_t count, int type);
720         int (*kernel_flock_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp,
721                                uint32_t share_mode, uint32_t access_mask);
722         int (*linux_setlease_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, int leasetype);
723         bool (*getlock_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid);
724         int (*symlink_fn)(struct vfs_handle_struct *handle, const char *oldpath, const char *newpath);
725         int (*readlink_fn)(struct vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz);
726         int (*link_fn)(struct vfs_handle_struct *handle, const char *oldpath, const char *newpath);
727         int (*mknod_fn)(struct vfs_handle_struct *handle, const char *path, mode_t mode, SMB_DEV_T dev);
728         char *(*realpath_fn)(struct vfs_handle_struct *handle, const char *path);
729         int (*chflags_fn)(struct vfs_handle_struct *handle, const char *path, unsigned int flags);
730         struct file_id (*file_id_create_fn)(struct vfs_handle_struct *handle,
731                                             const SMB_STRUCT_STAT *sbuf);
732         struct tevent_req *(*copy_chunk_send_fn)(struct vfs_handle_struct *handle,
733                                                  TALLOC_CTX *mem_ctx,
734                                                  struct tevent_context *ev,
735                                                  struct files_struct *src_fsp,
736                                                  off_t src_off,
737                                                  struct files_struct *dest_fsp,
738                                                  off_t dest_off,
739                                                  off_t to_copy,
740                                                  uint32_t flags);
741         NTSTATUS (*copy_chunk_recv_fn)(struct vfs_handle_struct *handle,
742                                        struct tevent_req *req,
743                                        off_t *copied);
744         NTSTATUS (*get_compression_fn)(struct vfs_handle_struct *handle,
745                                        TALLOC_CTX *mem_ctx,
746                                        struct files_struct *fsp,
747                                        struct smb_filename *smb_fname,
748                                        uint16_t *_compression_fmt);
749         NTSTATUS (*set_compression_fn)(struct vfs_handle_struct *handle,
750                                        TALLOC_CTX *mem_ctx,
751                                        struct files_struct *fsp,
752                                        uint16_t compression_fmt);
753         NTSTATUS (*snap_check_path_fn)(struct vfs_handle_struct *handle,
754                                        TALLOC_CTX *mem_ctx,
755                                        const char *service_path,
756                                        char **base_volume);
757         NTSTATUS (*snap_create_fn)(struct vfs_handle_struct *handle,
758                                    TALLOC_CTX *mem_ctx,
759                                    const char *base_volume,
760                                    time_t *tstamp,
761                                    bool rw,
762                                    char **base_path,
763                                    char **snap_path);
764         NTSTATUS (*snap_delete_fn)(struct vfs_handle_struct *handle,
765                                    TALLOC_CTX *mem_ctx,
766                                    char *base_path,
767                                    char *snap_path);
768
769         NTSTATUS (*streaminfo_fn)(struct vfs_handle_struct *handle,
770                                   struct files_struct *fsp,
771                                   const struct smb_filename *smb_fname,
772                                   TALLOC_CTX *mem_ctx,
773                                   unsigned int *num_streams,
774                                   struct stream_struct **streams);
775
776         int (*get_real_filename_fn)(struct vfs_handle_struct *handle,
777                                     const char *path,
778                                     const char *name,
779                                     TALLOC_CTX *mem_ctx,
780                                     char **found_name);
781
782         const char *(*connectpath_fn)(struct vfs_handle_struct *handle,
783                                       const char *filename);
784
785         NTSTATUS (*brl_lock_windows_fn)(struct vfs_handle_struct *handle,
786                                         struct byte_range_lock *br_lck,
787                                         struct lock_struct *plock,
788                                         bool blocking_lock);
789
790         bool (*brl_unlock_windows_fn)(struct vfs_handle_struct *handle,
791                                       struct messaging_context *msg_ctx,
792                                       struct byte_range_lock *br_lck,
793                                       const struct lock_struct *plock);
794
795         bool (*brl_cancel_windows_fn)(struct vfs_handle_struct *handle,
796                                       struct byte_range_lock *br_lck,
797                                       struct lock_struct *plock);
798
799         bool (*strict_lock_fn)(struct vfs_handle_struct *handle,
800                                struct files_struct *fsp,
801                                struct lock_struct *plock);
802
803         void (*strict_unlock_fn)(struct vfs_handle_struct *handle,
804                                  struct files_struct *fsp,
805                                  struct lock_struct *plock);
806
807         NTSTATUS (*translate_name_fn)(struct vfs_handle_struct *handle,
808                                       const char *name,
809                                       enum vfs_translate_direction direction,
810                                       TALLOC_CTX *mem_ctx,
811                                       char **mapped_name);
812
813         NTSTATUS (*fsctl_fn)(struct vfs_handle_struct *handle,
814                              struct files_struct *fsp,
815                              TALLOC_CTX *ctx,
816                              uint32_t function,
817                              uint16_t req_flags,
818                              const uint8_t *_in_data,
819                              uint32_t in_len,
820                              uint8_t **_out_data,
821                              uint32_t max_out_len,
822                              uint32_t *out_len); 
823
824         NTSTATUS (*get_dos_attributes_fn)(struct vfs_handle_struct *handle,
825                                           struct smb_filename *smb_fname,
826                                           uint32_t *dosmode);
827
828         NTSTATUS (*fget_dos_attributes_fn)(struct vfs_handle_struct *handle,
829                                            struct files_struct *fsp,
830                                            uint32_t *dosmode);
831
832         NTSTATUS (*set_dos_attributes_fn)(struct vfs_handle_struct *handle,
833                                           const struct smb_filename *smb_fname,
834                                           uint32_t dosmode);
835
836         NTSTATUS (*fset_dos_attributes_fn)(struct vfs_handle_struct *hande,
837                                            struct files_struct *fsp,
838                                            uint32_t dosmode);
839
840         /* NT ACL operations. */
841
842         NTSTATUS (*fget_nt_acl_fn)(struct vfs_handle_struct *handle,
843                                    struct files_struct *fsp,
844                                    uint32_t security_info,
845                                    TALLOC_CTX *mem_ctx,
846                                    struct security_descriptor **ppdesc);
847         NTSTATUS (*get_nt_acl_fn)(struct vfs_handle_struct *handle,
848                                   const struct smb_filename *smb_fname,
849                                   uint32_t security_info,
850                                    TALLOC_CTX *mem_ctx,
851                                   struct security_descriptor **ppdesc);
852         NTSTATUS (*fset_nt_acl_fn)(struct vfs_handle_struct *handle,
853                                    struct files_struct *fsp,
854                                    uint32_t security_info_sent,
855                                    const struct security_descriptor *psd);
856
857         NTSTATUS (*audit_file_fn)(struct vfs_handle_struct *handle,
858                                   struct smb_filename *file,
859                                   struct security_acl *sacl,
860                                   uint32_t access_requested,
861                                   uint32_t access_denied);
862
863         /* POSIX ACL operations. */
864
865         int (*chmod_acl_fn)(struct vfs_handle_struct *handle,
866                                         const struct smb_filename *smb_fname,
867                                         mode_t mode);
868         int (*fchmod_acl_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, mode_t mode);
869
870         SMB_ACL_T (*sys_acl_get_file_fn)(struct vfs_handle_struct *handle,
871                                          const struct smb_filename *smb_fname,
872                                          SMB_ACL_TYPE_T type,
873                                          TALLOC_CTX *mem_ctx);
874         SMB_ACL_T (*sys_acl_get_fd_fn)(struct vfs_handle_struct *handle,
875                                        struct files_struct *fsp,
876                                        TALLOC_CTX *mem_ctx);
877         int (*sys_acl_blob_get_file_fn)(struct vfs_handle_struct *handle,
878                                         const struct smb_filename *smb_fname,
879                                         TALLOC_CTX *mem_ctx,
880                                         char **blob_description,
881                                         DATA_BLOB *blob);
882         int (*sys_acl_blob_get_fd_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp,
883                                       TALLOC_CTX *mem_ctx, char **blob_description,
884                                       DATA_BLOB *blob);
885         int (*sys_acl_set_file_fn)(struct vfs_handle_struct *handle,
886                                         const struct smb_filename *smb_fname,
887                                         SMB_ACL_TYPE_T acltype,
888                                         SMB_ACL_T theacl);
889         int (*sys_acl_set_fd_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_ACL_T theacl);
890         int (*sys_acl_delete_def_file_fn)(struct vfs_handle_struct *handle,
891                                         const struct smb_filename *smb_fname);
892
893         /* EA operations. */
894         ssize_t (*getxattr_fn)(struct vfs_handle_struct *handle,const char *path, const char *name, void *value, size_t size);
895         ssize_t (*fgetxattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, void *value, size_t size);
896         ssize_t (*listxattr_fn)(struct vfs_handle_struct *handle,
897                                         const struct smb_filename *smb_fname,
898                                         char *list,
899                                         size_t size);
900         ssize_t (*flistxattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size);
901         int (*removexattr_fn)(struct vfs_handle_struct *handle,
902                                         const struct smb_filename *smb_fname,
903                                         const char *name);
904         int (*fremovexattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name);
905         int (*setxattr_fn)(struct vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags);
906         int (*fsetxattr_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, const void *value, size_t size, int flags);
907
908         /* aio operations */
909         bool (*aio_force_fn)(struct vfs_handle_struct *handle, struct files_struct *fsp);
910
911         /* durable handle operations */
912         NTSTATUS (*durable_cookie_fn)(struct vfs_handle_struct *handle,
913                                       struct files_struct *fsp,
914                                       TALLOC_CTX *mem_ctx,
915                                       DATA_BLOB *cookie);
916         NTSTATUS (*durable_disconnect_fn)(struct vfs_handle_struct *handle,
917                                           struct files_struct *fsp,
918                                           const DATA_BLOB old_cookie,
919                                           TALLOC_CTX *mem_ctx,
920                                           DATA_BLOB *new_cookie);
921         NTSTATUS (*durable_reconnect_fn)(struct vfs_handle_struct *handle,
922                                          struct smb_request *smb1req,
923                                          struct smbXsrv_open *op,
924                                          const DATA_BLOB old_cookie,
925                                          TALLOC_CTX *mem_ctx,
926                                          struct files_struct **fsp,
927                                          DATA_BLOB *new_cookie);
928
929         NTSTATUS (*readdir_attr_fn)(struct vfs_handle_struct *handle,
930                                     const struct smb_filename *fname,
931                                     TALLOC_CTX *mem_ctx,
932                                     struct readdir_attr_data **attr_data);
933 };
934
935 /*
936     VFS operation description. Each VFS module registers an array of vfs_op_tuple to VFS subsystem,
937     which describes all operations this module is willing to intercept.
938     VFS subsystem initializes then the conn->vfs_ops and conn->vfs_opaque_ops structs
939     using this information.
940 */
941
942 typedef struct vfs_handle_struct {
943         struct vfs_handle_struct  *next, *prev;
944         const char *param;
945         struct connection_struct *conn;
946         const struct vfs_fn_pointers *fns;
947         void *data;
948         void (*free_data)(void **data);
949 } vfs_handle_struct;
950
951
952 typedef struct vfs_statvfs_struct {
953         /* For undefined recommended transfer size return -1 in that field */
954         uint32_t OptimalTransferSize;  /* bsize on some os, iosize on other os */
955         uint32_t BlockSize;
956
957         /*
958          The next three fields are in terms of the block size.
959          (above). If block size is unknown, 4096 would be a
960          reasonable block size for a server to report.
961          Note that returning the blocks/blocksavail removes need
962          to make a second call (to QFSInfo level 0x103 to get this info.
963          UserBlockAvail is typically less than or equal to BlocksAvail,
964          if no distinction is made return the same value in each.
965         */
966
967         uint64_t TotalBlocks;
968         uint64_t BlocksAvail;       /* bfree */
969         uint64_t UserBlocksAvail;   /* bavail */
970
971         /* For undefined Node fields or FSID return -1 */
972         uint64_t TotalFileNodes;
973         uint64_t FreeFileNodes;
974         uint64_t FsIdentifier;   /* fsid */
975         /* NB Namelen comes from FILE_SYSTEM_ATTRIBUTE_INFO call */
976         /* NB flags can come from FILE_SYSTEM_DEVICE_INFO call   */
977
978         int FsCapabilities;
979 } vfs_statvfs_struct;
980
981 /* Add a new FSP extension of the given type. Returns a pointer to the
982  * extenstion data.
983  */
984 #define VFS_ADD_FSP_EXTENSION(handle, fsp, type, destroy_fn)            \
985     vfs_add_fsp_extension_notype(handle, (fsp), sizeof(type), (destroy_fn))
986
987 /* Return a pointer to the existing FSP extension data. */
988 #define VFS_FETCH_FSP_EXTENSION(handle, fsp) \
989     vfs_fetch_fsp_extension(handle, (fsp))
990
991 /* Return the talloc context associated with an FSP extension. */
992 #define VFS_MEMCTX_FSP_EXTENSION(handle, fsp) \
993     vfs_memctx_fsp_extension(handle, (fsp))
994
995 /* Remove and destroy an FSP extension. */
996 #define VFS_REMOVE_FSP_EXTENSION(handle, fsp) \
997     vfs_remove_fsp_extension((handle), (fsp))
998
999 #define SMB_VFS_HANDLE_GET_DATA(handle, datap, type, ret) { \
1000         if (!(handle)||((datap=(type *)(handle)->data)==NULL)) { \
1001                 DEBUG(0,("%s() failed to get vfs_handle->data!\n",__FUNCTION__)); \
1002                 ret; \
1003         } \
1004 }
1005
1006 #define SMB_VFS_HANDLE_SET_DATA(handle, datap, free_fn, type, ret) { \
1007         if (!(handle)) { \
1008                 DEBUG(0,("%s() failed to set handle->data!\n",__FUNCTION__)); \
1009                 ret; \
1010         } else { \
1011                 if ((handle)->free_data) { \
1012                         (handle)->free_data(&(handle)->data); \
1013                 } \
1014                 (handle)->data = (void *)datap; \
1015                 (handle)->free_data = free_fn; \
1016         } \
1017 }
1018
1019 #define SMB_VFS_HANDLE_FREE_DATA(handle) { \
1020         if ((handle) && (handle)->free_data) { \
1021                 (handle)->free_data(&(handle)->data); \
1022         } \
1023 }
1024
1025 /* Check whether module-specific data handle was already allocated or not */
1026 #define SMB_VFS_HANDLE_TEST_DATA(handle)  ( !(handle) || !(handle)->data ? False : True )
1027
1028 #define SMB_VFS_OP(x) ((void *) x)
1029
1030 #define DEFAULT_VFS_MODULE_NAME "/[Default VFS]/"
1031
1032 #include "vfs_macros.h"
1033
1034 int smb_vfs_call_connect(struct vfs_handle_struct *handle,
1035                          const char *service, const char *user);
1036 void smb_vfs_call_disconnect(struct vfs_handle_struct *handle);
1037 uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
1038                                 const char *path, uint64_t *bsize,
1039                                 uint64_t *dfree, uint64_t *dsize);
1040 int smb_vfs_call_get_quota(struct vfs_handle_struct *handle, const char *path,
1041                            enum SMB_QUOTA_TYPE qtype, unid_t id,
1042                            SMB_DISK_QUOTA *qt);
1043 int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
1044                            enum SMB_QUOTA_TYPE qtype, unid_t id,
1045                            SMB_DISK_QUOTA *qt);
1046 int smb_vfs_call_get_shadow_copy_data(struct vfs_handle_struct *handle,
1047                                       struct files_struct *fsp,
1048                                       struct shadow_copy_data *shadow_copy_data,
1049                                       bool labels);
1050 int smb_vfs_call_statvfs(struct vfs_handle_struct *handle, const char *path,
1051                          struct vfs_statvfs_struct *statbuf);
1052 uint32_t smb_vfs_call_fs_capabilities(struct vfs_handle_struct *handle,
1053                                       enum timestamp_set_resolution *p_ts_res);
1054 /*
1055  * Note: that "struct dfs_GetDFSReferral *r" needs to be a valid TALLOC_CTX
1056  */
1057 NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
1058                                         struct dfs_GetDFSReferral *r);
1059 DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
1060                         const struct smb_filename *smb_fname,
1061                         const char *mask,
1062                         uint32_t attributes);
1063 DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
1064                                         struct files_struct *fsp,
1065                                         const char *mask,
1066                                         uint32_t attributes);
1067 struct dirent *smb_vfs_call_readdir(struct vfs_handle_struct *handle,
1068                                         DIR *dirp,
1069                                         SMB_STRUCT_STAT *sbuf);
1070 void smb_vfs_call_seekdir(struct vfs_handle_struct *handle,
1071                           DIR *dirp, long offset);
1072 long smb_vfs_call_telldir(struct vfs_handle_struct *handle,
1073                           DIR *dirp);
1074 void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
1075                              DIR *dirp);
1076 int smb_vfs_call_mkdir(struct vfs_handle_struct *handle,
1077                         const struct smb_filename *smb_fname,
1078                         mode_t mode);
1079 int smb_vfs_call_rmdir(struct vfs_handle_struct *handle,
1080                         const struct smb_filename *smb_fname);
1081 int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
1082                           DIR *dir);
1083 void smb_vfs_call_init_search_op(struct vfs_handle_struct *handle,
1084                                  DIR *dirp);
1085 int smb_vfs_call_open(struct vfs_handle_struct *handle,
1086                       struct smb_filename *smb_fname, struct files_struct *fsp,
1087                       int flags, mode_t mode);
1088 NTSTATUS smb_vfs_call_create_file(struct vfs_handle_struct *handle,
1089                                   struct smb_request *req,
1090                                   uint16_t root_dir_fid,
1091                                   struct smb_filename *smb_fname,
1092                                   uint32_t access_mask,
1093                                   uint32_t share_access,
1094                                   uint32_t create_disposition,
1095                                   uint32_t create_options,
1096                                   uint32_t file_attributes,
1097                                   uint32_t oplock_request,
1098                                   struct smb2_lease *lease,
1099                                   uint64_t allocation_size,
1100                                   uint32_t private_flags,
1101                                   struct security_descriptor *sd,
1102                                   struct ea_list *ea_list,
1103                                   files_struct **result,
1104                                   int *pinfo,
1105                                   const struct smb2_create_blobs *in_context_blobs,
1106                                   struct smb2_create_blobs *out_context_blobs);
1107 int smb_vfs_call_close(struct vfs_handle_struct *handle,
1108                        struct files_struct *fsp);
1109 ssize_t smb_vfs_call_read(struct vfs_handle_struct *handle,
1110                           struct files_struct *fsp, void *data, size_t n);
1111 ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
1112                            struct files_struct *fsp, void *data, size_t n,
1113                            off_t offset);
1114 struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle,
1115                                            TALLOC_CTX *mem_ctx,
1116                                            struct tevent_context *ev,
1117                                            struct files_struct *fsp,
1118                                            void *data,
1119                                            size_t n, off_t offset);
1120 ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req, struct vfs_aio_state *state);
1121
1122 ssize_t smb_vfs_call_write(struct vfs_handle_struct *handle,
1123                            struct files_struct *fsp, const void *data,
1124                            size_t n);
1125 ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
1126                             struct files_struct *fsp, const void *data,
1127                             size_t n, off_t offset);
1128 struct tevent_req *smb_vfs_call_pwrite_send(struct vfs_handle_struct *handle,
1129                                             TALLOC_CTX *mem_ctx,
1130                                             struct tevent_context *ev,
1131                                             struct files_struct *fsp,
1132                                             const void *data,
1133                                             size_t n, off_t offset);
1134 ssize_t SMB_VFS_PWRITE_RECV(struct tevent_req *req, struct vfs_aio_state *state);
1135
1136 off_t smb_vfs_call_lseek(struct vfs_handle_struct *handle,
1137                              struct files_struct *fsp, off_t offset,
1138                              int whence);
1139 ssize_t smb_vfs_call_sendfile(struct vfs_handle_struct *handle, int tofd,
1140                               files_struct *fromfsp, const DATA_BLOB *header,
1141                               off_t offset, size_t count);
1142 ssize_t smb_vfs_call_recvfile(struct vfs_handle_struct *handle, int fromfd,
1143                               files_struct *tofsp, off_t offset,
1144                               size_t count);
1145 int smb_vfs_call_rename(struct vfs_handle_struct *handle,
1146                         const struct smb_filename *smb_fname_src,
1147                         const struct smb_filename *smb_fname_dst);
1148 int smb_vfs_call_fsync(struct vfs_handle_struct *handle,
1149                        struct files_struct *fsp);
1150
1151 struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle,
1152                                            TALLOC_CTX *mem_ctx,
1153                                            struct tevent_context *ev,
1154                                            struct files_struct *fsp);
1155 int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *state);
1156
1157 int smb_vfs_call_stat(struct vfs_handle_struct *handle,
1158                       struct smb_filename *smb_fname);
1159 int smb_vfs_call_fstat(struct vfs_handle_struct *handle,
1160                        struct files_struct *fsp, SMB_STRUCT_STAT *sbuf);
1161 int smb_vfs_call_lstat(struct vfs_handle_struct *handle,
1162                        struct smb_filename *smb_filename);
1163 uint64_t smb_vfs_call_get_alloc_size(struct vfs_handle_struct *handle,
1164                                      struct files_struct *fsp,
1165                                      const SMB_STRUCT_STAT *sbuf);
1166 int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
1167                         const struct smb_filename *smb_fname);
1168 int smb_vfs_call_chmod(struct vfs_handle_struct *handle,
1169                         const struct smb_filename *smb_fname,
1170                         mode_t mode);
1171 int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
1172                         struct files_struct *fsp, mode_t mode);
1173 int smb_vfs_call_chown(struct vfs_handle_struct *handle,
1174                         const struct smb_filename *smb_fname,
1175                         uid_t uid,
1176                         gid_t gid);
1177 int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
1178                         struct files_struct *fsp, uid_t uid, gid_t gid);
1179 int smb_vfs_call_lchown(struct vfs_handle_struct *handle,
1180                         const struct smb_filename *smb_fname,
1181                         uid_t uid,
1182                         gid_t gid);
1183 int smb_vfs_call_chdir(struct vfs_handle_struct *handle, const char *path);
1184 char *smb_vfs_call_getwd(struct vfs_handle_struct *handle);
1185 int smb_vfs_call_ntimes(struct vfs_handle_struct *handle,
1186                         const struct smb_filename *smb_fname,
1187                         struct smb_file_time *ft);
1188 int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle,
1189                            struct files_struct *fsp, off_t offset);
1190 int smb_vfs_call_fallocate(struct vfs_handle_struct *handle,
1191                            struct files_struct *fsp,
1192                            uint32_t mode,
1193                            off_t offset,
1194                            off_t len);
1195 bool smb_vfs_call_lock(struct vfs_handle_struct *handle,
1196                        struct files_struct *fsp, int op, off_t offset,
1197                        off_t count, int type);
1198 int smb_vfs_call_kernel_flock(struct vfs_handle_struct *handle,
1199                               struct files_struct *fsp, uint32_t share_mode,
1200                               uint32_t access_mask);
1201 int smb_vfs_call_linux_setlease(struct vfs_handle_struct *handle,
1202                                 struct files_struct *fsp, int leasetype);
1203 bool smb_vfs_call_getlock(struct vfs_handle_struct *handle,
1204                           struct files_struct *fsp, off_t *poffset,
1205                           off_t *pcount, int *ptype, pid_t *ppid);
1206 int smb_vfs_call_symlink(struct vfs_handle_struct *handle, const char *oldpath,
1207                          const char *newpath);
1208 int smb_vfs_call_readlink(struct vfs_handle_struct *handle,
1209                           const char *path, char *buf, size_t bufsiz);
1210 int smb_vfs_call_link(struct vfs_handle_struct *handle, const char *oldpath,
1211                       const char *newpath);
1212 int smb_vfs_call_mknod(struct vfs_handle_struct *handle, const char *path,
1213                        mode_t mode, SMB_DEV_T dev);
1214 char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path);
1215 int smb_vfs_call_chflags(struct vfs_handle_struct *handle, const char *path,
1216                          unsigned int flags);
1217 struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
1218                                            const SMB_STRUCT_STAT *sbuf);
1219 NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle,
1220                                  struct files_struct *fsp,
1221                                  const struct smb_filename *smb_fname,
1222                                  TALLOC_CTX *mem_ctx,
1223                                  unsigned int *num_streams,
1224                                  struct stream_struct **streams);
1225 int smb_vfs_call_get_real_filename(struct vfs_handle_struct *handle,
1226                                    const char *path, const char *name,
1227                                    TALLOC_CTX *mem_ctx, char **found_name);
1228 const char *smb_vfs_call_connectpath(struct vfs_handle_struct *handle,
1229                                      const char *filename);
1230 NTSTATUS smb_vfs_call_brl_lock_windows(struct vfs_handle_struct *handle,
1231                                        struct byte_range_lock *br_lck,
1232                                        struct lock_struct *plock,
1233                                        bool blocking_lock);
1234 bool smb_vfs_call_brl_unlock_windows(struct vfs_handle_struct *handle,
1235                                      struct messaging_context *msg_ctx,
1236                                      struct byte_range_lock *br_lck,
1237                                      const struct lock_struct *plock);
1238 bool smb_vfs_call_brl_cancel_windows(struct vfs_handle_struct *handle,
1239                                      struct byte_range_lock *br_lck,
1240                                      struct lock_struct *plock);
1241 bool smb_vfs_call_strict_lock(struct vfs_handle_struct *handle,
1242                               struct files_struct *fsp,
1243                               struct lock_struct *plock);
1244 void smb_vfs_call_strict_unlock(struct vfs_handle_struct *handle,
1245                                 struct files_struct *fsp,
1246                                 struct lock_struct *plock);
1247 NTSTATUS smb_vfs_call_translate_name(struct vfs_handle_struct *handle,
1248                                      const char *name,
1249                                      enum vfs_translate_direction direction,
1250                                      TALLOC_CTX *mem_ctx,
1251                                      char **mapped_name);
1252 NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle,
1253                             struct files_struct *fsp,
1254                             TALLOC_CTX *ctx,
1255                             uint32_t function,
1256                             uint16_t req_flags,
1257                             const uint8_t *_in_data,
1258                             uint32_t in_len,
1259                             uint8_t **_out_data,
1260                             uint32_t max_out_len,
1261                             uint32_t *out_len);
1262 NTSTATUS smb_vfs_call_get_dos_attributes(struct vfs_handle_struct *handle,
1263                                          struct smb_filename *smb_fname,
1264                                          uint32_t *dosmode);
1265 NTSTATUS smb_vfs_call_fget_dos_attributes(struct vfs_handle_struct *handle,
1266                                           struct files_struct *fsp,
1267                                           uint32_t *dosmode);
1268 NTSTATUS smb_vfs_call_set_dos_attributes(struct vfs_handle_struct *handle,
1269                                          const struct smb_filename *smb_fname,
1270                                          uint32_t dosmode);
1271 NTSTATUS smb_vfs_call_fset_dos_attributes(struct vfs_handle_struct *handle,
1272                                           struct files_struct *fsp,
1273                                           uint32_t dosmode);
1274 struct tevent_req *smb_vfs_call_copy_chunk_send(struct vfs_handle_struct *handle,
1275                                                 TALLOC_CTX *mem_ctx,
1276                                                 struct tevent_context *ev,
1277                                                 struct files_struct *src_fsp,
1278                                                 off_t src_off,
1279                                                 struct files_struct *dest_fsp,
1280                                                 off_t dest_off,
1281                                                 off_t num,
1282                                                 uint32_t flags);
1283 NTSTATUS smb_vfs_call_copy_chunk_recv(struct vfs_handle_struct *handle,
1284                                       struct tevent_req *req,
1285                                       off_t *copied);
1286 NTSTATUS smb_vfs_call_get_compression(struct vfs_handle_struct *handle,
1287                                       TALLOC_CTX *mem_ctx,
1288                                       struct files_struct *fsp,
1289                                       struct smb_filename *smb_fname,
1290                                       uint16_t *_compression_fmt);
1291 NTSTATUS smb_vfs_call_set_compression(struct vfs_handle_struct *handle,
1292                                       TALLOC_CTX *mem_ctx,
1293                                       struct files_struct *fsp,
1294                                       uint16_t compression_fmt);
1295 NTSTATUS smb_vfs_call_snap_check_path(vfs_handle_struct *handle,
1296                                       TALLOC_CTX *mem_ctx,
1297                                       const char *service_path,
1298                                       char **base_volume);
1299 NTSTATUS smb_vfs_call_snap_create(struct vfs_handle_struct *handle,
1300                                   TALLOC_CTX *mem_ctx,
1301                                   const char *base_volume,
1302                                   time_t *tstamp,
1303                                   bool rw,
1304                                   char **base_path,
1305                                   char **snap_path);
1306 NTSTATUS smb_vfs_call_snap_delete(struct vfs_handle_struct *handle,
1307                                   TALLOC_CTX *mem_ctx,
1308                                   char *base_path,
1309                                   char *snap_path);
1310 NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
1311                                   struct files_struct *fsp,
1312                                   uint32_t security_info,
1313                                   TALLOC_CTX *mem_ctx,
1314                                   struct security_descriptor **ppdesc);
1315 NTSTATUS smb_vfs_call_get_nt_acl(struct vfs_handle_struct *handle,
1316                                  const struct smb_filename *smb_fname,
1317                                  uint32_t security_info,
1318                                  TALLOC_CTX *mem_ctx,
1319                                  struct security_descriptor **ppdesc);
1320 NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
1321                                   struct files_struct *fsp,
1322                                   uint32_t security_info_sent,
1323                                   const struct security_descriptor *psd);
1324 NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle,
1325                                  struct smb_filename *file,
1326                                  struct security_acl *sacl,
1327                                  uint32_t access_requested,
1328                                  uint32_t access_denied);
1329 int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle,
1330                                 const struct smb_filename *file,
1331                                 mode_t mode);
1332 int smb_vfs_call_fchmod_acl(struct vfs_handle_struct *handle,
1333                             struct files_struct *fsp, mode_t mode);
1334 SMB_ACL_T smb_vfs_call_sys_acl_get_file(struct vfs_handle_struct *handle,
1335                                         const struct smb_filename *smb_fname,
1336                                         SMB_ACL_TYPE_T type,
1337                                         TALLOC_CTX *mem_ctx);
1338 SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
1339                                       struct files_struct *fsp,
1340                                       TALLOC_CTX *mem_ctx);
1341 int smb_vfs_call_sys_acl_blob_get_file(struct vfs_handle_struct *handle,
1342                                        const struct smb_filename *smb_fname,
1343                                        TALLOC_CTX *mem_ctx,
1344                                        char **blob_description,
1345                                        DATA_BLOB *blob);
1346 int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct *handle,
1347                                      struct files_struct *fsp,  
1348                                      TALLOC_CTX *mem_ctx,
1349                                      char **blob_description,
1350                                      DATA_BLOB *blob);
1351 int smb_vfs_call_sys_acl_set_file(struct vfs_handle_struct *handle,
1352                                 const struct smb_filename *smb_fname,
1353                                 SMB_ACL_TYPE_T acltype,
1354                                 SMB_ACL_T theacl);
1355 int smb_vfs_call_sys_acl_set_fd(struct vfs_handle_struct *handle,
1356                                 struct files_struct *fsp, SMB_ACL_T theacl);
1357 int smb_vfs_call_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
1358                                 const struct smb_filename *smb_fname);
1359 ssize_t smb_vfs_call_getxattr(struct vfs_handle_struct *handle,
1360                               const char *path, const char *name, void *value,
1361                               size_t size);
1362 ssize_t smb_vfs_call_fgetxattr(struct vfs_handle_struct *handle,
1363                                struct files_struct *fsp, const char *name,
1364                                void *value, size_t size);
1365 ssize_t smb_vfs_call_listxattr(struct vfs_handle_struct *handle,
1366                                 const struct smb_filename *smb_fname,
1367                                 char *list,
1368                                 size_t size);
1369 ssize_t smb_vfs_call_llistxattr(struct vfs_handle_struct *handle,
1370                                 const char *path, char *list, size_t size);
1371 ssize_t smb_vfs_call_flistxattr(struct vfs_handle_struct *handle,
1372                                 struct files_struct *fsp, char *list,
1373                                 size_t size);
1374 int smb_vfs_call_removexattr(struct vfs_handle_struct *handle,
1375                                 const struct smb_filename *smb_fname,
1376                                 const char *name);
1377 int smb_vfs_call_fremovexattr(struct vfs_handle_struct *handle,
1378                               struct files_struct *fsp, const char *name);
1379 int smb_vfs_call_setxattr(struct vfs_handle_struct *handle, const char *path,
1380                           const char *name, const void *value, size_t size,
1381                           int flags);
1382 int smb_vfs_call_lsetxattr(struct vfs_handle_struct *handle, const char *path,
1383                            const char *name, const void *value, size_t size,
1384                            int flags);
1385 int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
1386                            struct files_struct *fsp, const char *name,
1387                            const void *value, size_t size, int flags);
1388 bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle,
1389                             struct files_struct *fsp);
1390 bool smb_vfs_call_is_offline(struct vfs_handle_struct *handle,
1391                              const struct smb_filename *fname,
1392                              SMB_STRUCT_STAT *sbuf);
1393 int smb_vfs_call_set_offline(struct vfs_handle_struct *handle,
1394                              const struct smb_filename *fname);
1395 NTSTATUS smb_vfs_call_durable_cookie(struct vfs_handle_struct *handle,
1396                                      struct files_struct *fsp,
1397                                      TALLOC_CTX *mem_ctx,
1398                                      DATA_BLOB *cookie);
1399 NTSTATUS smb_vfs_call_durable_disconnect(struct vfs_handle_struct *handle,
1400                                          struct files_struct *fsp,
1401                                          const DATA_BLOB old_cookie,
1402                                          TALLOC_CTX *mem_ctx,
1403                                          DATA_BLOB *new_cookie);
1404 NTSTATUS smb_vfs_call_durable_reconnect(struct vfs_handle_struct *handle,
1405                                         struct smb_request *smb1req,
1406                                         struct smbXsrv_open *op,
1407                                         const DATA_BLOB old_cookie,
1408                                         TALLOC_CTX *mem_ctx,
1409                                         struct files_struct **fsp,
1410                                         DATA_BLOB *new_cookie);
1411 NTSTATUS smb_vfs_call_readdir_attr(struct vfs_handle_struct *handle,
1412                                    const struct smb_filename *fname,
1413                                    TALLOC_CTX *mem_ctx,
1414                                    struct readdir_attr_data **attr_data);
1415
1416 NTSTATUS smb_register_vfs(int version, const char *name,
1417                           const struct vfs_fn_pointers *fns);
1418 void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
1419                                    files_struct *fsp, size_t ext_size,
1420                                    void (*destroy_fn)(void *p_data));
1421 void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp);
1422 void vfs_remove_all_fsp_extensions(struct files_struct *fsp);
1423 void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, files_struct *fsp);
1424 void *vfs_fetch_fsp_extension(vfs_handle_struct *handle, files_struct *fsp);
1425
1426 void smb_vfs_assert_all_fns(const struct vfs_fn_pointers* fns,
1427                             const char *module);
1428
1429 #endif /* _VFS_H */