f3adae3978fada2cfa69993b0e9527cc22150cce
[samba.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,
587                         const struct smb_filename *smb_fname,
588                         mode_t mode,
589                         SMB_DEV_T dev)
590 {
591         return SMB_VFS_NEXT_MKNOD(handle, smb_fname, mode, dev);
592 }
593
594 static char *skel_realpath(vfs_handle_struct *handle, const char *path)
595 {
596         return SMB_VFS_NEXT_REALPATH(handle, path);
597 }
598
599 static int skel_chflags(vfs_handle_struct *handle,
600                         const struct smb_filename *smb_fname,
601                         uint flags)
602 {
603         return SMB_VFS_NEXT_CHFLAGS(handle, smb_fname, flags);
604 }
605
606 static struct file_id skel_file_id_create(vfs_handle_struct *handle,
607                                           const SMB_STRUCT_STAT *sbuf)
608 {
609         return SMB_VFS_NEXT_FILE_ID_CREATE(handle, sbuf);
610 }
611
612 struct skel_cc_state {
613         struct vfs_handle_struct *handle;
614         off_t copied;
615 };
616 static void skel_copy_chunk_done(struct tevent_req *subreq);
617
618 static struct tevent_req *skel_copy_chunk_send(struct vfs_handle_struct *handle,
619                                                TALLOC_CTX *mem_ctx,
620                                                struct tevent_context *ev,
621                                                struct files_struct *src_fsp,
622                                                off_t src_off,
623                                                struct files_struct *dest_fsp,
624                                                off_t dest_off,
625                                                off_t num,
626                                                uint32_t flags)
627 {
628         struct tevent_req *req;
629         struct tevent_req *subreq;
630         struct skel_cc_state *cc_state;
631
632         req = tevent_req_create(mem_ctx, &cc_state, struct skel_cc_state);
633         if (req == NULL) {
634                 return NULL;
635         }
636
637         cc_state->handle = handle;
638         subreq = SMB_VFS_NEXT_COPY_CHUNK_SEND(handle, cc_state, ev,
639                                               src_fsp, src_off,
640                                               dest_fsp, dest_off, num, flags);
641         if (tevent_req_nomem(subreq, req)) {
642                 return tevent_req_post(req, ev);
643         }
644
645         tevent_req_set_callback(subreq, skel_copy_chunk_done, req);
646         return req;
647 }
648
649 static void skel_copy_chunk_done(struct tevent_req *subreq)
650 {
651         struct tevent_req *req = tevent_req_callback_data(
652                 subreq, struct tevent_req);
653         struct skel_cc_state *cc_state
654                         = tevent_req_data(req, struct skel_cc_state);
655         NTSTATUS status;
656
657         status = SMB_VFS_NEXT_COPY_CHUNK_RECV(cc_state->handle,
658                                               subreq,
659                                               &cc_state->copied);
660         TALLOC_FREE(subreq);
661         if (tevent_req_nterror(req, status)) {
662                 return;
663         }
664         tevent_req_done(req);
665 }
666
667 static NTSTATUS skel_copy_chunk_recv(struct vfs_handle_struct *handle,
668                                      struct tevent_req *req,
669                                      off_t *copied)
670 {
671         struct skel_cc_state *cc_state
672                         = tevent_req_data(req, struct skel_cc_state);
673         NTSTATUS status;
674
675         *copied = cc_state->copied;
676         if (tevent_req_is_nterror(req, &status)) {
677                 tevent_req_received(req);
678                 return status;
679         }
680
681         tevent_req_received(req);
682         return NT_STATUS_OK;
683 }
684
685 static NTSTATUS skel_get_compression(struct vfs_handle_struct *handle,
686                                      TALLOC_CTX *mem_ctx,
687                                      struct files_struct *fsp,
688                                      struct smb_filename *smb_fname,
689                                      uint16_t *_compression_fmt)
690 {
691         return SMB_VFS_NEXT_GET_COMPRESSION(handle, mem_ctx, fsp, smb_fname,
692                                             _compression_fmt);
693 }
694
695 static NTSTATUS skel_set_compression(struct vfs_handle_struct *handle,
696                                      TALLOC_CTX *mem_ctx,
697                                      struct files_struct *fsp,
698                                      uint16_t compression_fmt)
699 {
700         return SMB_VFS_NEXT_SET_COMPRESSION(handle, mem_ctx, fsp,
701                                             compression_fmt);
702 }
703
704 static NTSTATUS skel_streaminfo(struct vfs_handle_struct *handle,
705                                 struct files_struct *fsp,
706                                 const struct smb_filename *smb_fname,
707                                 TALLOC_CTX *mem_ctx,
708                                 unsigned int *num_streams,
709                                 struct stream_struct **streams)
710 {
711         return SMB_VFS_NEXT_STREAMINFO(handle,
712                                 fsp,
713                                 smb_fname,
714                                 mem_ctx,
715                                 num_streams,
716                                 streams);
717 }
718
719 static int skel_get_real_filename(struct vfs_handle_struct *handle,
720                                   const char *path,
721                                   const char *name,
722                                   TALLOC_CTX *mem_ctx, char **found_name)
723 {
724         return SMB_VFS_NEXT_GET_REAL_FILENAME(handle,
725                                               path, name, mem_ctx, found_name);
726 }
727
728 static const char *skel_connectpath(struct vfs_handle_struct *handle,
729                                     const char *filename)
730 {
731         return SMB_VFS_NEXT_CONNECTPATH(handle, filename);
732 }
733
734 static NTSTATUS skel_brl_lock_windows(struct vfs_handle_struct *handle,
735                                       struct byte_range_lock *br_lck,
736                                       struct lock_struct *plock,
737                                       bool blocking_lock)
738 {
739         return SMB_VFS_NEXT_BRL_LOCK_WINDOWS(handle,
740                                              br_lck, plock, blocking_lock);
741 }
742
743 static bool skel_brl_unlock_windows(struct vfs_handle_struct *handle,
744                                     struct messaging_context *msg_ctx,
745                                     struct byte_range_lock *br_lck,
746                                     const struct lock_struct *plock)
747 {
748         return SMB_VFS_NEXT_BRL_UNLOCK_WINDOWS(handle, msg_ctx, br_lck, plock);
749 }
750
751 static bool skel_brl_cancel_windows(struct vfs_handle_struct *handle,
752                                     struct byte_range_lock *br_lck,
753                                     struct lock_struct *plock)
754 {
755         return SMB_VFS_NEXT_BRL_CANCEL_WINDOWS(handle, br_lck, plock);
756 }
757
758 static bool skel_strict_lock(struct vfs_handle_struct *handle,
759                              struct files_struct *fsp,
760                              struct lock_struct *plock)
761 {
762         return SMB_VFS_NEXT_STRICT_LOCK(handle, fsp, plock);
763 }
764
765 static void skel_strict_unlock(struct vfs_handle_struct *handle,
766                                struct files_struct *fsp,
767                                struct lock_struct *plock)
768 {
769         SMB_VFS_NEXT_STRICT_UNLOCK(handle, fsp, plock);
770 }
771
772 static NTSTATUS skel_translate_name(struct vfs_handle_struct *handle,
773                                     const char *mapped_name,
774                                     enum vfs_translate_direction direction,
775                                     TALLOC_CTX *mem_ctx, char **pmapped_name)
776 {
777         return SMB_VFS_NEXT_TRANSLATE_NAME(handle, mapped_name, direction,
778                                            mem_ctx, pmapped_name);
779 }
780
781 static NTSTATUS skel_fsctl(struct vfs_handle_struct *handle,
782                            struct files_struct *fsp,
783                            TALLOC_CTX *ctx,
784                            uint32_t function,
785                            uint16_t req_flags,  /* Needed for UNICODE ... */
786                            const uint8_t *_in_data,
787                            uint32_t in_len,
788                            uint8_t ** _out_data,
789                            uint32_t max_out_len, uint32_t *out_len)
790 {
791         return SMB_VFS_NEXT_FSCTL(handle,
792                                   fsp,
793                                   ctx,
794                                   function,
795                                   req_flags,
796                                   _in_data,
797                                   in_len, _out_data, max_out_len, out_len);
798 }
799
800 static NTSTATUS skel_readdir_attr(struct vfs_handle_struct *handle,
801                                   const struct smb_filename *fname,
802                                   TALLOC_CTX *mem_ctx,
803                                   struct readdir_attr_data **pattr_data)
804 {
805         return SMB_VFS_NEXT_READDIR_ATTR(handle, fname, mem_ctx, pattr_data);
806 }
807
808 static NTSTATUS skel_get_dos_attributes(struct vfs_handle_struct *handle,
809                                 struct smb_filename *smb_fname,
810                                 uint32_t *dosmode)
811 {
812         return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
813                                 smb_fname,
814                                 dosmode);
815 }
816
817 static NTSTATUS skel_fget_dos_attributes(struct vfs_handle_struct *handle,
818                                 struct files_struct *fsp,
819                                 uint32_t *dosmode)
820 {
821         return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
822                                 fsp,
823                                 dosmode);
824 }
825
826 static NTSTATUS skel_set_dos_attributes(struct vfs_handle_struct *handle,
827                                 const struct smb_filename *smb_fname,
828                                 uint32_t dosmode)
829 {
830         return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
831                                 smb_fname,
832                                 dosmode);
833 }
834
835 static NTSTATUS skel_fset_dos_attributes(struct vfs_handle_struct *handle,
836                                 struct files_struct *fsp,
837                                 uint32_t dosmode)
838 {
839         return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
840                                 fsp,
841                                 dosmode);
842 }
843
844 static NTSTATUS skel_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
845                                  uint32_t security_info,
846                                  TALLOC_CTX *mem_ctx,
847                                  struct security_descriptor **ppdesc)
848 {
849         return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, mem_ctx,
850                                         ppdesc);
851 }
852
853 static NTSTATUS skel_get_nt_acl(vfs_handle_struct *handle,
854                                 const struct smb_filename *smb_fname,
855                                 uint32_t security_info,
856                                 TALLOC_CTX *mem_ctx,
857                                 struct security_descriptor **ppdesc)
858 {
859         return SMB_VFS_NEXT_GET_NT_ACL(handle,
860                                 smb_fname,
861                                 security_info,
862                                 mem_ctx,
863                                 ppdesc);
864 }
865
866 static NTSTATUS skel_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
867                                  uint32_t security_info_sent,
868                                  const struct security_descriptor *psd)
869 {
870         return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
871 }
872
873 static int skel_chmod_acl(vfs_handle_struct *handle,
874                         const struct smb_filename *smb_fname,
875                         mode_t mode)
876 {
877         return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
878 }
879
880 static int skel_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
881                            mode_t mode)
882 {
883         return SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
884 }
885
886 static SMB_ACL_T skel_sys_acl_get_file(vfs_handle_struct *handle,
887                                        const struct smb_filename *smb_fname,
888                                        SMB_ACL_TYPE_T type,
889                                        TALLOC_CTX *mem_ctx)
890 {
891         return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, smb_fname, type, mem_ctx);
892 }
893
894 static SMB_ACL_T skel_sys_acl_get_fd(vfs_handle_struct *handle,
895                                      files_struct *fsp, TALLOC_CTX *mem_ctx)
896 {
897         return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
898 }
899
900 static int skel_sys_acl_blob_get_file(vfs_handle_struct *handle,
901                                 const struct smb_filename *smb_fname,
902                                 TALLOC_CTX *mem_ctx,
903                                 char **blob_description,
904                                 DATA_BLOB *blob)
905 {
906         return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, smb_fname, mem_ctx,
907                                                   blob_description, blob);
908 }
909
910 static int skel_sys_acl_blob_get_fd(vfs_handle_struct *handle,
911                                     files_struct *fsp, TALLOC_CTX *mem_ctx,
912                                     char **blob_description, DATA_BLOB *blob)
913 {
914         return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
915                                                 blob_description, blob);
916 }
917
918 static int skel_sys_acl_set_file(vfs_handle_struct *handle,
919                                 const struct smb_filename *smb_fname,
920                                 SMB_ACL_TYPE_T acltype,
921                                 SMB_ACL_T theacl)
922 {
923         return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, smb_fname,
924                         acltype, theacl);
925 }
926
927 static int skel_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
928                                SMB_ACL_T theacl)
929 {
930         return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
931 }
932
933 static int skel_sys_acl_delete_def_file(vfs_handle_struct *handle,
934                                         const struct smb_filename *smb_fname)
935 {
936         return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, smb_fname);
937 }
938
939 static ssize_t skel_getxattr(vfs_handle_struct *handle,
940                                 const struct smb_filename *smb_fname,
941                                 const char *name,
942                                 void *value,
943                                 size_t size)
944 {
945         return SMB_VFS_NEXT_GETXATTR(handle, smb_fname, name, value, size);
946 }
947
948 static ssize_t skel_fgetxattr(vfs_handle_struct *handle,
949                               struct files_struct *fsp, const char *name,
950                               void *value, size_t size)
951 {
952         return SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
953 }
954
955 static ssize_t skel_listxattr(vfs_handle_struct *handle,
956                                 const struct smb_filename *smb_fname,
957                                 char *list,
958                                 size_t size)
959 {
960         return SMB_VFS_NEXT_LISTXATTR(handle, smb_fname, list, size);
961 }
962
963 static ssize_t skel_flistxattr(vfs_handle_struct *handle,
964                                struct files_struct *fsp, char *list,
965                                size_t size)
966 {
967         return SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
968 }
969
970 static int skel_removexattr(vfs_handle_struct *handle,
971                         const struct smb_filename *smb_fname,
972                         const char *name)
973 {
974         return SMB_VFS_NEXT_REMOVEXATTR(handle, smb_fname, name);
975 }
976
977 static int skel_fremovexattr(vfs_handle_struct *handle,
978                              struct files_struct *fsp, const char *name)
979 {
980         return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
981 }
982
983 static int skel_setxattr(vfs_handle_struct *handle,
984                         const struct smb_filename *smb_fname,
985                         const char *name,
986                         const void *value,
987                         size_t size,
988                         int flags)
989 {
990         return SMB_VFS_NEXT_SETXATTR(handle, smb_fname,
991                         name, value, size, flags);
992 }
993
994 static int skel_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,
995                           const char *name, const void *value, size_t size,
996                           int flags)
997 {
998         return SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
999 }
1000
1001 static bool skel_aio_force(struct vfs_handle_struct *handle,
1002                            struct files_struct *fsp)
1003 {
1004         return SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
1005 }
1006
1007 /* VFS operations structure */
1008
1009 struct vfs_fn_pointers skel_transparent_fns = {
1010         /* Disk operations */
1011
1012         .connect_fn = skel_connect,
1013         .disconnect_fn = skel_disconnect,
1014         .disk_free_fn = skel_disk_free,
1015         .get_quota_fn = skel_get_quota,
1016         .set_quota_fn = skel_set_quota,
1017         .get_shadow_copy_data_fn = skel_get_shadow_copy_data,
1018         .statvfs_fn = skel_statvfs,
1019         .fs_capabilities_fn = skel_fs_capabilities,
1020         .get_dfs_referrals_fn = skel_get_dfs_referrals,
1021         .snap_check_path_fn = skel_snap_check_path,
1022         .snap_create_fn = skel_snap_create,
1023         .snap_delete_fn = skel_snap_delete,
1024
1025         /* Directory operations */
1026
1027         .opendir_fn = skel_opendir,
1028         .fdopendir_fn = skel_fdopendir,
1029         .readdir_fn = skel_readdir,
1030         .seekdir_fn = skel_seekdir,
1031         .telldir_fn = skel_telldir,
1032         .rewind_dir_fn = skel_rewind_dir,
1033         .mkdir_fn = skel_mkdir,
1034         .rmdir_fn = skel_rmdir,
1035         .closedir_fn = skel_closedir,
1036         .init_search_op_fn = skel_init_search_op,
1037
1038         /* File operations */
1039
1040         .open_fn = skel_open,
1041         .create_file_fn = skel_create_file,
1042         .close_fn = skel_close_fn,
1043         .read_fn = skel_vfs_read,
1044         .pread_fn = skel_pread,
1045         .pread_send_fn = skel_pread_send,
1046         .pread_recv_fn = skel_pread_recv,
1047         .write_fn = skel_write,
1048         .pwrite_fn = skel_pwrite,
1049         .pwrite_send_fn = skel_pwrite_send,
1050         .pwrite_recv_fn = skel_pwrite_recv,
1051         .lseek_fn = skel_lseek,
1052         .sendfile_fn = skel_sendfile,
1053         .recvfile_fn = skel_recvfile,
1054         .rename_fn = skel_rename,
1055         .fsync_fn = skel_fsync,
1056         .fsync_send_fn = skel_fsync_send,
1057         .fsync_recv_fn = skel_fsync_recv,
1058         .stat_fn = skel_stat,
1059         .fstat_fn = skel_fstat,
1060         .lstat_fn = skel_lstat,
1061         .get_alloc_size_fn = skel_get_alloc_size,
1062         .unlink_fn = skel_unlink,
1063         .chmod_fn = skel_chmod,
1064         .fchmod_fn = skel_fchmod,
1065         .chown_fn = skel_chown,
1066         .fchown_fn = skel_fchown,
1067         .lchown_fn = skel_lchown,
1068         .chdir_fn = skel_chdir,
1069         .getwd_fn = skel_getwd,
1070         .ntimes_fn = skel_ntimes,
1071         .ftruncate_fn = skel_ftruncate,
1072         .fallocate_fn = skel_fallocate,
1073         .lock_fn = skel_lock,
1074         .kernel_flock_fn = skel_kernel_flock,
1075         .linux_setlease_fn = skel_linux_setlease,
1076         .getlock_fn = skel_getlock,
1077         .symlink_fn = skel_symlink,
1078         .readlink_fn = skel_vfs_readlink,
1079         .link_fn = skel_link,
1080         .mknod_fn = skel_mknod,
1081         .realpath_fn = skel_realpath,
1082         .chflags_fn = skel_chflags,
1083         .file_id_create_fn = skel_file_id_create,
1084         .copy_chunk_send_fn = skel_copy_chunk_send,
1085         .copy_chunk_recv_fn = skel_copy_chunk_recv,
1086         .get_compression_fn = skel_get_compression,
1087         .set_compression_fn = skel_set_compression,
1088
1089         .streaminfo_fn = skel_streaminfo,
1090         .get_real_filename_fn = skel_get_real_filename,
1091         .connectpath_fn = skel_connectpath,
1092         .brl_lock_windows_fn = skel_brl_lock_windows,
1093         .brl_unlock_windows_fn = skel_brl_unlock_windows,
1094         .brl_cancel_windows_fn = skel_brl_cancel_windows,
1095         .strict_lock_fn = skel_strict_lock,
1096         .strict_unlock_fn = skel_strict_unlock,
1097         .translate_name_fn = skel_translate_name,
1098         .fsctl_fn = skel_fsctl,
1099         .readdir_attr_fn = skel_readdir_attr,
1100
1101         /* DOS attributes. */
1102         .get_dos_attributes_fn = skel_get_dos_attributes,
1103         .fget_dos_attributes_fn = skel_fget_dos_attributes,
1104         .set_dos_attributes_fn = skel_set_dos_attributes,
1105         .fset_dos_attributes_fn = skel_fset_dos_attributes,
1106
1107         /* NT ACL operations. */
1108
1109         .fget_nt_acl_fn = skel_fget_nt_acl,
1110         .get_nt_acl_fn = skel_get_nt_acl,
1111         .fset_nt_acl_fn = skel_fset_nt_acl,
1112
1113         /* POSIX ACL operations. */
1114
1115         .chmod_acl_fn = skel_chmod_acl,
1116         .fchmod_acl_fn = skel_fchmod_acl,
1117
1118         .sys_acl_get_file_fn = skel_sys_acl_get_file,
1119         .sys_acl_get_fd_fn = skel_sys_acl_get_fd,
1120         .sys_acl_blob_get_file_fn = skel_sys_acl_blob_get_file,
1121         .sys_acl_blob_get_fd_fn = skel_sys_acl_blob_get_fd,
1122         .sys_acl_set_file_fn = skel_sys_acl_set_file,
1123         .sys_acl_set_fd_fn = skel_sys_acl_set_fd,
1124         .sys_acl_delete_def_file_fn = skel_sys_acl_delete_def_file,
1125
1126         /* EA operations. */
1127         .getxattr_fn = skel_getxattr,
1128         .fgetxattr_fn = skel_fgetxattr,
1129         .listxattr_fn = skel_listxattr,
1130         .flistxattr_fn = skel_flistxattr,
1131         .removexattr_fn = skel_removexattr,
1132         .fremovexattr_fn = skel_fremovexattr,
1133         .setxattr_fn = skel_setxattr,
1134         .fsetxattr_fn = skel_fsetxattr,
1135
1136         /* aio operations */
1137         .aio_force_fn = skel_aio_force,
1138 };
1139
1140 static_decl_vfs;
1141 NTSTATUS vfs_skel_transparent_init(TALLOC_CTX *ctx)
1142 {
1143         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "skel_transparent",
1144                                 &skel_transparent_fns);
1145 }