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