s3: VFS: Change SMB_VFS_SYS_ACL_DELETE_DEF_FILE to use const struct smb_filename...
[sfrench/samba-autobuild/.git] / examples / VFS / skel_transparent.c
1 /* 
2  * Skeleton VFS module.  Implements passthrough operation of all VFS
3  * calls to disk functions.
4  *
5  * Copyright (C) Tim Potter, 1999-2000
6  * Copyright (C) Alexander Bokovoy, 2002
7  * Copyright (C) Stefan (metze) Metzmacher, 2003
8  * Copyright (C) Jeremy Allison 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
24 #include "../source3/include/includes.h"
25 #include "lib/util/tevent_unix.h"
26 #include "lib/util/tevent_ntstatus.h"
27
28 /* PLEASE,PLEASE READ THE VFS MODULES CHAPTER OF THE 
29    SAMBA DEVELOPERS GUIDE!!!!!!
30  */
31
32 /* If you take this file as template for your module
33  * please make sure that you remove all skel_XXX() functions you don't
34  * want to implement!! The passthrough operations are not
35  * neccessary in a real module.
36  *
37  * --metze
38  */
39
40 static int skel_connect(vfs_handle_struct *handle, const char *service,
41                         const char *user)
42 {
43         return SMB_VFS_NEXT_CONNECT(handle, service, user);
44 }
45
46 static void skel_disconnect(vfs_handle_struct *handle)
47 {
48         SMB_VFS_NEXT_DISCONNECT(handle);
49 }
50
51 static uint64_t skel_disk_free(vfs_handle_struct *handle, const char *path,
52                                uint64_t *bsize,
53                                uint64_t *dfree, uint64_t *dsize)
54 {
55         return SMB_VFS_NEXT_DISK_FREE(handle, path, bsize, dfree, dsize);
56 }
57
58 static int skel_get_quota(vfs_handle_struct *handle, const char *path,
59                           enum SMB_QUOTA_TYPE qtype, unid_t id,
60                           SMB_DISK_QUOTA *dq)
61 {
62         return SMB_VFS_NEXT_GET_QUOTA(handle, path, qtype, id, dq);
63 }
64
65 static int skel_set_quota(vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype,
66                           unid_t id, SMB_DISK_QUOTA *dq)
67 {
68         return SMB_VFS_NEXT_SET_QUOTA(handle, qtype, id, dq);
69 }
70
71 static int skel_get_shadow_copy_data(vfs_handle_struct *handle,
72                                      files_struct *fsp,
73                                      struct shadow_copy_data *shadow_copy_data,
74                                      bool labels)
75 {
76         return SMB_VFS_NEXT_GET_SHADOW_COPY_DATA(handle, fsp, shadow_copy_data,
77                                                  labels);
78 }
79
80 static int skel_statvfs(struct vfs_handle_struct *handle, const char *path,
81                         struct vfs_statvfs_struct *statbuf)
82 {
83         return SMB_VFS_NEXT_STATVFS(handle, path, statbuf);
84 }
85
86 static uint32_t skel_fs_capabilities(struct vfs_handle_struct *handle,
87                                      enum timestamp_set_resolution *p_ts_res)
88 {
89         return SMB_VFS_NEXT_FS_CAPABILITIES(handle, p_ts_res);
90 }
91
92 static NTSTATUS skel_get_dfs_referrals(struct vfs_handle_struct *handle,
93                                        struct dfs_GetDFSReferral *r)
94 {
95         return SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
96 }
97
98 static DIR *skel_opendir(vfs_handle_struct *handle,
99                         const struct smb_filename *smb_fname,
100                         const char *mask,
101                         uint32_t attr)
102 {
103         return SMB_VFS_NEXT_OPENDIR(handle, smb_fname, mask, attr);
104 }
105
106 static NTSTATUS skel_snap_check_path(struct vfs_handle_struct *handle,
107                                      TALLOC_CTX *mem_ctx,
108                                      const char *service_path,
109                                      char **base_volume)
110 {
111         return SMB_VFS_NEXT_SNAP_CHECK_PATH(handle, mem_ctx, service_path,
112                                             base_volume);
113 }
114
115 static NTSTATUS skel_snap_create(struct vfs_handle_struct *handle,
116                                  TALLOC_CTX *mem_ctx,
117                                  const char *base_volume,
118                                  time_t *tstamp,
119                                  bool rw,
120                                  char **base_path,
121                                  char **snap_path)
122 {
123         return SMB_VFS_NEXT_SNAP_CREATE(handle, mem_ctx, base_volume, tstamp,
124                                         rw, base_path, snap_path);
125 }
126
127 static NTSTATUS skel_snap_delete(struct vfs_handle_struct *handle,
128                                  TALLOC_CTX *mem_ctx,
129                                  char *base_path,
130                                  char *snap_path)
131 {
132         return SMB_VFS_NEXT_SNAP_DELETE(handle, mem_ctx, base_path, snap_path);
133 }
134
135 static DIR *skel_fdopendir(vfs_handle_struct *handle, files_struct *fsp,
136                            const char *mask, uint32_t attr)
137 {
138         return SMB_VFS_NEXT_FDOPENDIR(handle, fsp, mask, attr);
139 }
140
141 static struct dirent *skel_readdir(vfs_handle_struct *handle,
142                                    DIR *dirp, SMB_STRUCT_STAT *sbuf)
143 {
144         return SMB_VFS_NEXT_READDIR(handle, dirp, sbuf);
145 }
146
147 static void skel_seekdir(vfs_handle_struct *handle, DIR *dirp, long offset)
148 {
149         SMB_VFS_NEXT_SEEKDIR(handle, dirp, offset);
150 }
151
152 static long skel_telldir(vfs_handle_struct *handle, DIR *dirp)
153 {
154         return SMB_VFS_NEXT_TELLDIR(handle, dirp);
155 }
156
157 static void skel_rewind_dir(vfs_handle_struct *handle, DIR *dirp)
158 {
159         SMB_VFS_NEXT_REWINDDIR(handle, dirp);
160 }
161
162 static int skel_mkdir(vfs_handle_struct *handle,
163                 const struct smb_filename *smb_fname,
164                 mode_t mode)
165 {
166         return SMB_VFS_NEXT_MKDIR(handle, smb_fname, mode);
167 }
168
169 static int skel_rmdir(vfs_handle_struct *handle,
170                 const struct smb_filename *smb_fname)
171 {
172         return SMB_VFS_NEXT_RMDIR(handle, smb_fname);
173 }
174
175 static int skel_closedir(vfs_handle_struct *handle, DIR *dir)
176 {
177         return SMB_VFS_NEXT_CLOSEDIR(handle, dir);
178 }
179
180 static void skel_init_search_op(struct vfs_handle_struct *handle, DIR *dirp)
181 {
182         SMB_VFS_NEXT_INIT_SEARCH_OP(handle, dirp);
183 }
184
185 static int skel_open(vfs_handle_struct *handle, struct smb_filename *smb_fname,
186                      files_struct *fsp, int flags, mode_t mode)
187 {
188         return SMB_VFS_NEXT_OPEN(handle, smb_fname, fsp, flags, mode);
189 }
190
191 static NTSTATUS skel_create_file(struct vfs_handle_struct *handle,
192                                  struct smb_request *req,
193                                  uint16_t root_dir_fid,
194                                  struct smb_filename *smb_fname,
195                                  uint32_t access_mask,
196                                  uint32_t share_access,
197                                  uint32_t create_disposition,
198                                  uint32_t create_options,
199                                  uint32_t file_attributes,
200                                  uint32_t oplock_request,
201                                  struct smb2_lease *lease,
202                                  uint64_t allocation_size,
203                                  uint32_t private_flags,
204                                  struct security_descriptor *sd,
205                                  struct ea_list *ea_list,
206                                  files_struct ** result, int *pinfo,
207                                  const struct smb2_create_blobs *in_context_blobs,
208                                  struct smb2_create_blobs *out_context_blobs)
209 {
210         return SMB_VFS_NEXT_CREATE_FILE(handle,
211                                         req,
212                                         root_dir_fid,
213                                         smb_fname,
214                                         access_mask,
215                                         share_access,
216                                         create_disposition,
217                                         create_options,
218                                         file_attributes,
219                                         oplock_request,
220                                         lease,
221                                         allocation_size,
222                                         private_flags,
223                                         sd, ea_list, result, pinfo,
224                                         in_context_blobs, out_context_blobs);
225 }
226
227 static int skel_close_fn(vfs_handle_struct *handle, files_struct *fsp)
228 {
229         return SMB_VFS_NEXT_CLOSE(handle, fsp);
230 }
231
232 static ssize_t skel_vfs_read(vfs_handle_struct *handle, files_struct *fsp,
233                              void *data, size_t n)
234 {
235         return SMB_VFS_NEXT_READ(handle, fsp, data, n);
236 }
237
238 static ssize_t skel_pread(vfs_handle_struct *handle, files_struct *fsp,
239                           void *data, size_t n, off_t offset)
240 {
241         return SMB_VFS_NEXT_PREAD(handle, fsp, data, n, offset);
242 }
243
244 struct skel_pread_state {
245         ssize_t ret;
246         struct vfs_aio_state vfs_aio_state;
247 };
248
249 static void skel_pread_done(struct tevent_req *subreq);
250
251 static struct tevent_req *skel_pread_send(struct vfs_handle_struct *handle,
252                                           TALLOC_CTX *mem_ctx,
253                                           struct tevent_context *ev,
254                                           struct files_struct *fsp,
255                                           void *data, size_t n, off_t offset)
256 {
257         struct tevent_req *req, *subreq;
258         struct skel_pread_state *state;
259
260         req = tevent_req_create(mem_ctx, &state, struct skel_pread_state);
261         if (req == NULL) {
262                 return NULL;
263         }
264         subreq = SMB_VFS_NEXT_PREAD_SEND(state, ev, handle, fsp, data,
265                                          n, offset);
266         if (tevent_req_nomem(subreq, req)) {
267                 return tevent_req_post(req, ev);
268         }
269         tevent_req_set_callback(subreq, skel_pread_done, req);
270         return req;
271 }
272
273 static void skel_pread_done(struct tevent_req *subreq)
274 {
275         struct tevent_req *req =
276             tevent_req_callback_data(subreq, struct tevent_req);
277         struct skel_pread_state *state =
278             tevent_req_data(req, struct skel_pread_state);
279
280         state->ret = SMB_VFS_PREAD_RECV(subreq, &state->vfs_aio_state);
281         TALLOC_FREE(subreq);
282         tevent_req_done(req);
283 }
284
285 static ssize_t skel_pread_recv(struct tevent_req *req,
286                                struct vfs_aio_state *vfs_aio_state)
287 {
288         struct skel_pread_state *state =
289             tevent_req_data(req, struct skel_pread_state);
290
291         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
292                 return -1;
293         }
294         *vfs_aio_state = state->vfs_aio_state;
295         return state->ret;
296 }
297
298 static ssize_t skel_write(vfs_handle_struct *handle, files_struct *fsp,
299                           const void *data, size_t n)
300 {
301         return SMB_VFS_NEXT_WRITE(handle, fsp, data, n);
302 }
303
304 static ssize_t skel_pwrite(vfs_handle_struct *handle, files_struct *fsp,
305                            const void *data, size_t n, off_t offset)
306 {
307         return SMB_VFS_NEXT_PWRITE(handle, fsp, data, n, offset);
308 }
309
310 struct skel_pwrite_state {
311         ssize_t ret;
312         struct vfs_aio_state vfs_aio_state;
313 };
314
315 static void skel_pwrite_done(struct tevent_req *subreq);
316
317 static struct tevent_req *skel_pwrite_send(struct vfs_handle_struct *handle,
318                                            TALLOC_CTX *mem_ctx,
319                                            struct tevent_context *ev,
320                                            struct files_struct *fsp,
321                                            const void *data,
322                                            size_t n, off_t offset)
323 {
324         struct tevent_req *req, *subreq;
325         struct skel_pwrite_state *state;
326
327         req = tevent_req_create(mem_ctx, &state, struct skel_pwrite_state);
328         if (req == NULL) {
329                 return NULL;
330         }
331         subreq = SMB_VFS_NEXT_PWRITE_SEND(state, ev, handle, fsp, data,
332                                           n, offset);
333         if (tevent_req_nomem(subreq, req)) {
334                 return tevent_req_post(req, ev);
335         }
336         tevent_req_set_callback(subreq, skel_pwrite_done, req);
337         return req;
338 }
339
340 static void skel_pwrite_done(struct tevent_req *subreq)
341 {
342         struct tevent_req *req =
343             tevent_req_callback_data(subreq, struct tevent_req);
344         struct skel_pwrite_state *state =
345             tevent_req_data(req, struct skel_pwrite_state);
346
347         state->ret = SMB_VFS_PWRITE_RECV(subreq, &state->vfs_aio_state);
348         TALLOC_FREE(subreq);
349         tevent_req_done(req);
350 }
351
352 static ssize_t skel_pwrite_recv(struct tevent_req *req,
353                                 struct vfs_aio_state *vfs_aio_state)
354 {
355         struct skel_pwrite_state *state =
356             tevent_req_data(req, struct skel_pwrite_state);
357
358         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
359                 return -1;
360         }
361         *vfs_aio_state = state->vfs_aio_state;
362         return state->ret;
363 }
364
365 static off_t skel_lseek(vfs_handle_struct *handle, files_struct *fsp,
366                         off_t offset, int whence)
367 {
368         return SMB_VFS_NEXT_LSEEK(handle, fsp, offset, whence);
369 }
370
371 static ssize_t skel_sendfile(vfs_handle_struct *handle, int tofd,
372                              files_struct *fromfsp, const DATA_BLOB *hdr,
373                              off_t offset, size_t n)
374 {
375         return SMB_VFS_NEXT_SENDFILE(handle, tofd, fromfsp, hdr, offset, n);
376 }
377
378 static ssize_t skel_recvfile(vfs_handle_struct *handle, int fromfd,
379                              files_struct *tofsp, off_t offset, size_t n)
380 {
381         return SMB_VFS_NEXT_RECVFILE(handle, fromfd, tofsp, offset, n);
382 }
383
384 static int skel_rename(vfs_handle_struct *handle,
385                        const struct smb_filename *smb_fname_src,
386                        const struct smb_filename *smb_fname_dst)
387 {
388         return SMB_VFS_NEXT_RENAME(handle, smb_fname_src, smb_fname_dst);
389 }
390
391 static int skel_fsync(vfs_handle_struct *handle, files_struct *fsp)
392 {
393         return SMB_VFS_NEXT_FSYNC(handle, fsp);
394 }
395
396 struct skel_fsync_state {
397         int ret;
398         struct vfs_aio_state vfs_aio_state;
399 };
400
401 static void skel_fsync_done(struct tevent_req *subreq);
402
403 static struct tevent_req *skel_fsync_send(struct vfs_handle_struct *handle,
404                                           TALLOC_CTX *mem_ctx,
405                                           struct tevent_context *ev,
406                                           struct files_struct *fsp)
407 {
408         struct tevent_req *req, *subreq;
409         struct skel_fsync_state *state;
410
411         req = tevent_req_create(mem_ctx, &state, struct skel_fsync_state);
412         if (req == NULL) {
413                 return NULL;
414         }
415         subreq = SMB_VFS_NEXT_FSYNC_SEND(state, ev, handle, fsp);
416         if (tevent_req_nomem(subreq, req)) {
417                 return tevent_req_post(req, ev);
418         }
419         tevent_req_set_callback(subreq, skel_fsync_done, req);
420         return req;
421 }
422
423 static void skel_fsync_done(struct tevent_req *subreq)
424 {
425         struct tevent_req *req =
426             tevent_req_callback_data(subreq, struct tevent_req);
427         struct skel_fsync_state *state =
428             tevent_req_data(req, struct skel_fsync_state);
429
430         state->ret = SMB_VFS_FSYNC_RECV(subreq, &state->vfs_aio_state);
431         TALLOC_FREE(subreq);
432         tevent_req_done(req);
433 }
434
435 static int skel_fsync_recv(struct tevent_req *req,
436                            struct vfs_aio_state *vfs_aio_state)
437 {
438         struct skel_fsync_state *state =
439             tevent_req_data(req, struct skel_fsync_state);
440
441         if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
442                 return -1;
443         }
444         *vfs_aio_state = state->vfs_aio_state;
445         return state->ret;
446 }
447
448 static int skel_stat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
449 {
450         return SMB_VFS_NEXT_STAT(handle, smb_fname);
451 }
452
453 static int skel_fstat(vfs_handle_struct *handle, files_struct *fsp,
454                       SMB_STRUCT_STAT *sbuf)
455 {
456         return SMB_VFS_NEXT_FSTAT(handle, fsp, sbuf);
457 }
458
459 static int skel_lstat(vfs_handle_struct *handle,
460                       struct smb_filename *smb_fname)
461 {
462         return SMB_VFS_NEXT_LSTAT(handle, smb_fname);
463 }
464
465 static uint64_t skel_get_alloc_size(struct vfs_handle_struct *handle,
466                                     struct files_struct *fsp,
467                                     const SMB_STRUCT_STAT *sbuf)
468 {
469         return SMB_VFS_NEXT_GET_ALLOC_SIZE(handle, fsp, sbuf);
470 }
471
472 static int skel_unlink(vfs_handle_struct *handle,
473                        const struct smb_filename *smb_fname)
474 {
475         return SMB_VFS_NEXT_UNLINK(handle, smb_fname);
476 }
477
478 static int skel_chmod(vfs_handle_struct *handle,
479                         const struct smb_filename *smb_fname,
480                         mode_t mode)
481 {
482         return SMB_VFS_NEXT_CHMOD(handle, smb_fname, mode);
483 }
484
485 static int skel_fchmod(vfs_handle_struct *handle, files_struct *fsp,
486                        mode_t mode)
487 {
488         return SMB_VFS_NEXT_FCHMOD(handle, fsp, mode);
489 }
490
491 static int skel_chown(vfs_handle_struct *handle,
492                         const struct smb_filename *smb_fname,
493                         uid_t uid,
494                         gid_t gid)
495 {
496         return SMB_VFS_NEXT_CHOWN(handle, smb_fname, uid, gid);
497 }
498
499 static int skel_fchown(vfs_handle_struct *handle, files_struct *fsp,
500                        uid_t uid, gid_t gid)
501 {
502         return SMB_VFS_NEXT_FCHOWN(handle, fsp, uid, gid);
503 }
504
505 static int skel_lchown(vfs_handle_struct *handle,
506                         const struct smb_filename *smb_fname,
507                         uid_t uid,
508                         gid_t gid)
509 {
510         return SMB_VFS_NEXT_LCHOWN(handle, smb_fname, uid, gid);
511 }
512
513 static int skel_chdir(vfs_handle_struct *handle, const char *path)
514 {
515         return SMB_VFS_NEXT_CHDIR(handle, path);
516 }
517
518 static char *skel_getwd(vfs_handle_struct *handle)
519 {
520         return SMB_VFS_NEXT_GETWD(handle);
521 }
522
523 static int skel_ntimes(vfs_handle_struct *handle,
524                        const struct smb_filename *smb_fname,
525                        struct smb_file_time *ft)
526 {
527         return SMB_VFS_NEXT_NTIMES(handle, smb_fname, ft);
528 }
529
530 static int skel_ftruncate(vfs_handle_struct *handle, files_struct *fsp,
531                           off_t offset)
532 {
533         return SMB_VFS_NEXT_FTRUNCATE(handle, fsp, offset);
534 }
535
536 static int skel_fallocate(vfs_handle_struct *handle, files_struct *fsp,
537                           uint32_t mode, off_t offset, off_t len)
538 {
539         return SMB_VFS_NEXT_FALLOCATE(handle, fsp, mode, offset, len);
540 }
541
542 static bool skel_lock(vfs_handle_struct *handle, files_struct *fsp, int op,
543                       off_t offset, off_t count, int type)
544 {
545         return SMB_VFS_NEXT_LOCK(handle, fsp, op, offset, count, type);
546 }
547
548 static int skel_kernel_flock(struct vfs_handle_struct *handle,
549                              struct files_struct *fsp, uint32_t share_mode,
550                              uint32_t access_mask)
551 {
552         return SMB_VFS_NEXT_KERNEL_FLOCK(handle, fsp, share_mode, access_mask);
553 }
554
555 static int skel_linux_setlease(struct vfs_handle_struct *handle,
556                                struct files_struct *fsp, int leasetype)
557 {
558         return SMB_VFS_NEXT_LINUX_SETLEASE(handle, fsp, leasetype);
559 }
560
561 static bool skel_getlock(vfs_handle_struct *handle, files_struct *fsp,
562                          off_t *poffset, off_t *pcount, int *ptype,
563                          pid_t *ppid)
564 {
565         return SMB_VFS_NEXT_GETLOCK(handle, fsp, poffset, pcount, ptype, ppid);
566 }
567
568 static int skel_symlink(vfs_handle_struct *handle, const char *oldpath,
569                         const char *newpath)
570 {
571         return SMB_VFS_NEXT_SYMLINK(handle, oldpath, newpath);
572 }
573
574 static int skel_vfs_readlink(vfs_handle_struct *handle, const char *path,
575                              char *buf, size_t bufsiz)
576 {
577         return SMB_VFS_NEXT_READLINK(handle, path, buf, bufsiz);
578 }
579
580 static int skel_link(vfs_handle_struct *handle, const char *oldpath,
581                      const char *newpath)
582 {
583         return SMB_VFS_NEXT_LINK(handle, oldpath, newpath);
584 }
585
586 static int skel_mknod(vfs_handle_struct *handle, const char *path, mode_t mode,
587                       SMB_DEV_T dev)
588 {
589         return SMB_VFS_NEXT_MKNOD(handle, path, mode, dev);
590 }
591
592 static char *skel_realpath(vfs_handle_struct *handle, const char *path)
593 {
594         return SMB_VFS_NEXT_REALPATH(handle, path);
595 }
596
597 static int skel_chflags(vfs_handle_struct *handle, const char *path,
598                         uint flags)
599 {
600         return SMB_VFS_NEXT_CHFLAGS(handle, path, flags);
601 }
602
603 static struct file_id skel_file_id_create(vfs_handle_struct *handle,
604                                           const SMB_STRUCT_STAT *sbuf)
605 {
606         return SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
607 }
608
609 struct skel_cc_state {
610         struct vfs_handle_struct *handle;
611         off_t copied;
612 };
613 static void skel_copy_chunk_done(struct tevent_req *subreq);
614
615 static struct tevent_req *skel_copy_chunk_send(struct vfs_handle_struct *handle,
616                                                TALLOC_CTX *mem_ctx,
617                                                struct tevent_context *ev,
618                                                struct files_struct *src_fsp,
619                                                off_t src_off,
620                                                struct files_struct *dest_fsp,
621                                                off_t dest_off,
622                                                off_t num,
623                                                uint32_t flags)
624 {
625         struct tevent_req *req;
626         struct tevent_req *subreq;
627         struct skel_cc_state *cc_state;
628
629         req = tevent_req_create(mem_ctx, &cc_state, struct skel_cc_state);
630         if (req == NULL) {
631                 return NULL;
632         }
633
634         cc_state->handle = handle;
635         subreq = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, cc_state, ev,
636                                               src_fsp, src_off,
637                                               dest_fsp, dest_off, num, flags);
638         if (tevent_req_nomem(subreq, req)) {
639                 return tevent_req_post(req, ev);
640         }
641
642         tevent_req_set_callback(subreq, skel_copy_chunk_done, req);
643         return req;
644 }
645
646 static void skel_copy_chunk_done(struct tevent_req *subreq)
647 {
648         struct tevent_req *req = tevent_req_callback_data(
649                 subreq, struct tevent_req);
650         struct skel_cc_state *cc_state
651                         = tevent_req_data(req, struct skel_cc_state);
652         NTSTATUS status;
653
654         status = SMB_VFS_NEXT_COPY_CHUNK_RECV(cc_state->handle,
655                                               subreq,
656                                               &cc_state->copied);
657         TALLOC_FREE(subreq);
658         if (tevent_req_nterror(req, status)) {
659                 return;
660         }
661         tevent_req_done(req);
662 }
663
664 static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
665                                      struct tevent_req *req,
666                                      off_t *copied)
667 {
668         struct skel_cc_state *cc_state
669                         = tevent_req_data(req, struct skel_cc_state);
670         NTSTATUS status;
671
672         *copied = cc_state->copied;
673         if (tevent_req_is_nterror(req, &status)) {
674                 tevent_req_received(req);
675                 return status;
676         }
677
678         tevent_req_received(req);
679         return NT_STATUS_OK;
680 }
681
682 static NTSTATUS skel_get_compression(struct vfs_handle_struct *handle,
683                                      TALLOC_CTX *mem_ctx,
684                                      struct files_struct *fsp,
685                                      struct smb_filename *smb_fname,
686                                      uint16_t *_compression_fmt)
687 {
688         return SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
689                                             _compression_fmt);
690 }
691
692 static NTSTATUS skel_set_compression(struct vfs_handle_struct *handle,
693                                      TALLOC_CTX *mem_ctx,
694                                      struct files_struct *fsp,
695                                      uint16_t compression_fmt)
696 {
697         return SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
698                                             compression_fmt);
699 }
700
701 static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle,
702                                 struct files_struct *fsp,
703                                 const struct smb_filename *smb_fname,
704                                 TALLOC_CTX *mem_ctx,
705                                 unsigned int *num_streams,
706                                 struct stream_struct **streams)
707 {
708         return SMB_VFS_NEXT_STREAMINFO(handle,
709                                 fsp,
710                                 smb_fname,
711                                 mem_ctx,
712                                 num_streams,
713                                 streams);
714 }
715
716 static int skel_get_real_filename(struct vfs_handle_struct *handle,
717                                   const char *path,
718                                   const char *name,
719                                   TALLOC_CTX *mem_ctx, char **found_name)
720 {
721         return SMB_VFS_NEXT_GET_REAL_FILENAME(handle,
722                                               path, name, mem_ctx, found_name);
723 }
724
725 static const char *skel_connectpath(struct vfs_handle_struct *handle,
726                                     const char *filename)
727 {
728         return SMB_VFS_NEXT_CONNECTPATH(handle, filename);
729 }
730
731 static NTSTATUS skel_brl_lock_windows(struct vfs_handle_struct *handle,
732                                       struct byte_range_lock *br_lck,
733                                       struct lock_struct *plock,
734                                       bool blocking_lock)
735 {
736         return SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle,
737                                              br_lck, plock, blocking_lock);
738 }
739
740 static bool skel_brl_unlock_windows(struct vfs_handle_struct *handle,
741                                     struct messaging_context *msg_ctx,
742                                     struct byte_range_lock *br_lck,
743                                     const struct lock_struct *plock)
744 {
745         return SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck, plock);
746 }
747
748 static bool skel_brl_cancel_windows(struct vfs_handle_struct *handle,
749                                     struct byte_range_lock *br_lck,
750                                     struct lock_struct *plock)
751 {
752         return SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
753 }
754
755 static bool skel_strict_lock(struct vfs_handle_struct *handle,
756                              struct files_struct *fsp,
757                              struct lock_struct *plock)
758 {
759         return SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
760 }
761
762 static void skel_strict_unlock(struct vfs_handle_struct *handle,
763                                struct files_struct *fsp,
764                                struct lock_struct *plock)
765 {
766         SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
767 }
768
769 static NTSTATUS skel_translate_name(struct vfs_handle_struct *handle,
770                                     const char *mapped_name,
771                                     enum vfs_translate_direction direction,
772                                     TALLOC_CTX *mem_ctx, char **pmapped_name)
773 {
774         return SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
775                                            mem_ctx, pmapped_name);
776 }
777
778 static NTSTATUS skel_fsctl(struct vfs_handle_struct *handle,
779                            struct files_struct *fsp,
780                            TALLOC_CTX *ctx,
781                            uint32_t function,
782                            uint16_t req_flags,  /* Needed for UNICODE ... */
783                            const uint8_t *_in_data,
784                            uint32_t in_len,
785                            uint8_t ** _out_data,
786                            uint32_t max_out_len, uint32_t *out_len)
787 {
788         return SMB_VFS_NEXT_FSCTL(handle,
789                                   fsp,
790                                   ctx,
791                                   function,
792                                   req_flags,
793                                   _in_data,
794                                   in_len, _out_data, max_out_len, out_len);
795 }
796
797 static NTSTATUS skel_readdir_attr(struct vfs_handle_struct *handle,
798                                   const struct smb_filename *fname,
799                                   TALLOC_CTX *mem_ctx,
800                                   struct readdir_attr_data **pattr_data)
801 {
802         return SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
803 }
804
805 static NTSTATUS skel_get_dos_attributes(struct vfs_handle_struct *handle,
806                                 struct smb_filename *smb_fname,
807                                 uint32_t *dosmode)
808 {
809         return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
810                                 smb_fname,
811                                 dosmode);
812 }
813
814 static NTSTATUS skel_fget_dos_attributes(struct vfs_handle_struct *handle,
815                                 struct files_struct *fsp,
816                                 uint32_t *dosmode)
817 {
818         return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
819                                 fsp,
820                                 dosmode);
821 }
822
823 static NTSTATUS skel_set_dos_attributes(struct vfs_handle_struct *handle,
824                                 const struct smb_filename *smb_fname,
825                                 uint32_t dosmode)
826 {
827         return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
828                                 smb_fname,
829                                 dosmode);
830 }
831
832 static NTSTATUS skel_fset_dos_attributes(struct vfs_handle_struct *handle,
833                                 struct files_struct *fsp,
834                                 uint32_t dosmode)
835 {
836         return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
837                                 fsp,
838                                 dosmode);
839 }
840
841 static NTSTATUS skel_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
842                                  uint32_t security_info,
843                                  TALLOC_CTX *mem_ctx,
844                                  struct security_descriptor **ppdesc)
845 {
846         return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, mem_ctx,
847                                         ppdesc);
848 }
849
850 static NTSTATUS skel_get_nt_acl(vfs_handle_struct *handle,
851                                 const struct smb_filename *smb_fname,
852                                 uint32_t security_info,
853                                 TALLOC_CTX *mem_ctx,
854                                 struct security_descriptor **ppdesc)
855 {
856         return SMB_VFS_NEXT_GET_NT_ACL(handle,
857                                 smb_fname,
858                                 security_info,
859                                 mem_ctx,
860                                 ppdesc);
861 }
862
863 static NTSTATUS skel_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
864                                  uint32_t security_info_sent,
865                                  const struct security_descriptor *psd)
866 {
867         return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
868 }
869
870 static int skel_chmod_acl(vfs_handle_struct *handle,
871                         const struct smb_filename *smb_fname,
872                         mode_t mode)
873 {
874         return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
875 }
876
877 static int skel_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
878                            mode_t mode)
879 {
880         return SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
881 }
882
883 static SMB_ACL_T skel_sys_acl_get_file(vfs_handle_struct *handle,
884                                        const char *path_p,
885                                        SMB_ACL_TYPE_T type,
886                                        TALLOC_CTX *mem_ctx)
887 {
888         return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
889 }
890
891 static SMB_ACL_T skel_sys_acl_get_fd(vfs_handle_struct *handle,
892                                      files_struct *fsp, TALLOC_CTX *mem_ctx)
893 {
894         return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
895 }
896
897 static int skel_sys_acl_blob_get_file(vfs_handle_struct *handle,
898                                       const char *path_p, TALLOC_CTX *mem_ctx,
899                                       char **blob_description, DATA_BLOB *blob)
900 {
901         return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx,
902                                                   blob_description, blob);
903 }
904
905 static int skel_sys_acl_blob_get_fd(vfs_handle_struct *handle,
906                                     files_struct *fsp, TALLOC_CTX *mem_ctx,
907                                     char **blob_description, DATA_BLOB *blob)
908 {
909         return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
910                                                 blob_description, blob);
911 }
912
913 static int skel_sys_acl_set_file(vfs_handle_struct *handle, const char *name,
914                                  SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
915 {
916         return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype, theacl);
917 }
918
919 static int skel_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
920                                SMB_ACL_T theacl)
921 {
922         return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
923 }
924
925 static int skel_sys_acl_delete_def_file(vfs_handle_struct *handle,
926                                         const struct smb_filename *smb_fname)
927 {
928         return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
929 }
930
931 static ssize_t skel_getxattr(vfs_handle_struct *handle, const char *path,
932                              const char *name, void *value, size_t size)
933 {
934         return SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
935 }
936
937 static ssize_t skel_fgetxattr(vfs_handle_struct *handle,
938                               struct files_struct *fsp, const char *name,
939                               void *value, size_t size)
940 {
941         return SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
942 }
943
944 static ssize_t skel_listxattr(vfs_handle_struct *handle, const char *path,
945                               char *list, size_t size)
946 {
947         return SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
948 }
949
950 static ssize_t skel_flistxattr(vfs_handle_struct *handle,
951                                struct files_struct *fsp, char *list,
952                                size_t size)
953 {
954         return SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
955 }
956
957 static int skel_removexattr(vfs_handle_struct *handle, const char *path,
958                             const char *name)
959 {
960         return SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
961 }
962
963 static int skel_fremovexattr(vfs_handle_struct *handle,
964                              struct files_struct *fsp, const char *name)
965 {
966         return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
967 }
968
969 static int skel_setxattr(vfs_handle_struct *handle, const char *path,
970                          const char *name, const void *value, size_t size,
971                          int flags)
972 {
973         return SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size, flags);
974 }
975
976 static int skel_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,
977                           const char *name, const void *value, size_t size,
978                           int flags)
979 {
980         return SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
981 }
982
983 static bool skel_aio_force(struct vfs_handle_struct *handle,
984                            struct files_struct *fsp)
985 {
986         return SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
987 }
988
989 /* VFS operations structure */
990
991 struct vfs_fn_pointers skel_transparent_fns = {
992         /* Disk operations */
993
994         .connect_fn = skel_connect,
995         .disconnect_fn = skel_disconnect,
996         .disk_free_fn = skel_disk_free,
997         .get_quota_fn = skel_get_quota,
998         .set_quota_fn = skel_set_quota,
999         .get_shadow_copy_data_fn = skel_get_shadow_copy_data,
1000         .statvfs_fn = skel_statvfs,
1001         .fs_capabilities_fn = skel_fs_capabilities,
1002         .get_dfs_referrals_fn = skel_get_dfs_referrals,
1003         .snap_check_path_fn = skel_snap_check_path,
1004         .snap_create_fn = skel_snap_create,
1005         .snap_delete_fn = skel_snap_delete,
1006
1007         /* Directory operations */
1008
1009         .opendir_fn = skel_opendir,
1010         .fdopendir_fn = skel_fdopendir,
1011         .readdir_fn = skel_readdir,
1012         .seekdir_fn = skel_seekdir,
1013         .telldir_fn = skel_telldir,
1014         .rewind_dir_fn = skel_rewind_dir,
1015         .mkdir_fn = skel_mkdir,
1016         .rmdir_fn = skel_rmdir,
1017         .closedir_fn = skel_closedir,
1018         .init_search_op_fn = skel_init_search_op,
1019
1020         /* File operations */
1021
1022         .open_fn = skel_open,
1023         .create_file_fn = skel_create_file,
1024         .close_fn = skel_close_fn,
1025         .read_fn = skel_vfs_read,
1026         .pread_fn = skel_pread,
1027         .pread_send_fn = skel_pread_send,
1028         .pread_recv_fn = skel_pread_recv,
1029         .write_fn = skel_write,
1030         .pwrite_fn = skel_pwrite,
1031         .pwrite_send_fn = skel_pwrite_send,
1032         .pwrite_recv_fn = skel_pwrite_recv,
1033         .lseek_fn = skel_lseek,
1034         .sendfile_fn = skel_sendfile,
1035         .recvfile_fn = skel_recvfile,
1036         .rename_fn = skel_rename,
1037         .fsync_fn = skel_fsync,
1038         .fsync_send_fn = skel_fsync_send,
1039         .fsync_recv_fn = skel_fsync_recv,
1040         .stat_fn = skel_stat,
1041         .fstat_fn = skel_fstat,
1042         .lstat_fn = skel_lstat,
1043         .get_alloc_size_fn = skel_get_alloc_size,
1044         .unlink_fn = skel_unlink,
1045         .chmod_fn = skel_chmod,
1046         .fchmod_fn = skel_fchmod,
1047         .chown_fn = skel_chown,
1048         .fchown_fn = skel_fchown,
1049         .lchown_fn = skel_lchown,
1050         .chdir_fn = skel_chdir,
1051         .getwd_fn = skel_getwd,
1052         .ntimes_fn = skel_ntimes,
1053         .ftruncate_fn = skel_ftruncate,
1054         .fallocate_fn = skel_fallocate,
1055         .lock_fn = skel_lock,
1056         .kernel_flock_fn = skel_kernel_flock,
1057         .linux_setlease_fn = skel_linux_setlease,
1058         .getlock_fn = skel_getlock,
1059         .symlink_fn = skel_symlink,
1060         .readlink_fn = skel_vfs_readlink,
1061         .link_fn = skel_link,
1062         .mknod_fn = skel_mknod,
1063         .realpath_fn = skel_realpath,
1064         .chflags_fn = skel_chflags,
1065         .file_id_create_fn = skel_file_id_create,
1066         .copy_chunk_send_fn = skel_copy_chunk_send,
1067         .copy_chunk_recv_fn = skel_copy_chunk_recv,
1068         .get_compression_fn = skel_get_compression,
1069         .set_compression_fn = skel_set_compression,
1070
1071         .streaminfo_fn = skel_streaminfo,
1072         .get_real_filename_fn = skel_get_real_filename,
1073         .connectpath_fn = skel_connectpath,
1074         .brl_lock_windows_fn = skel_brl_lock_windows,
1075         .brl_unlock_windows_fn = skel_brl_unlock_windows,
1076         .brl_cancel_windows_fn = skel_brl_cancel_windows,
1077         .strict_lock_fn = skel_strict_lock,
1078         .strict_unlock_fn = skel_strict_unlock,
1079         .translate_name_fn = skel_translate_name,
1080         .fsctl_fn = skel_fsctl,
1081         .readdir_attr_fn = skel_readdir_attr,
1082
1083         /* DOS attributes. */
1084         .get_dos_attributes_fn = skel_get_dos_attributes,
1085         .fget_dos_attributes_fn = skel_fget_dos_attributes,
1086         .set_dos_attributes_fn = skel_set_dos_attributes,
1087         .fset_dos_attributes_fn = skel_fset_dos_attributes,
1088
1089         /* NT ACL operations. */
1090
1091         .fget_nt_acl_fn = skel_fget_nt_acl,
1092         .get_nt_acl_fn = skel_get_nt_acl,
1093         .fset_nt_acl_fn = skel_fset_nt_acl,
1094
1095         /* POSIX ACL operations. */
1096
1097         .chmod_acl_fn = skel_chmod_acl,
1098         .fchmod_acl_fn = skel_fchmod_acl,
1099
1100         .sys_acl_get_file_fn = skel_sys_acl_get_file,
1101         .sys_acl_get_fd_fn = skel_sys_acl_get_fd,
1102         .sys_acl_blob_get_file_fn = skel_sys_acl_blob_get_file,
1103         .sys_acl_blob_get_fd_fn = skel_sys_acl_blob_get_fd,
1104         .sys_acl_set_file_fn = skel_sys_acl_set_file,
1105         .sys_acl_set_fd_fn = skel_sys_acl_set_fd,
1106         .sys_acl_delete_def_file_fn = skel_sys_acl_delete_def_file,
1107
1108         /* EA operations. */
1109         .getxattr_fn = skel_getxattr,
1110         .fgetxattr_fn = skel_fgetxattr,
1111         .listxattr_fn = skel_listxattr,
1112         .flistxattr_fn = skel_flistxattr,
1113         .removexattr_fn = skel_removexattr,
1114         .fremovexattr_fn = skel_fremovexattr,
1115         .setxattr_fn = skel_setxattr,
1116         .fsetxattr_fn = skel_fsetxattr,
1117
1118         /* aio operations */
1119         .aio_force_fn = skel_aio_force,
1120 };
1121
1122 static_decl_vfs;
1123 NTSTATUS vfs_skel_transparent_init(TALLOC_CTX *ctx)
1124 {
1125         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "skel_transparent",
1126                                 &skel_transparent_fns);
1127 }