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