lib: modules: Change XXX_init interface from XXX_init(void) to XXX_init(TALLOC_CTX *)
[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, 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_get_dos_attributes(struct vfs_handle_struct *handle,
805                                 struct smb_filename *smb_fname,
806                                 uint32_t *dosmode)
807 {
808         return SMB_VFS_NEXT_GET_DOS_ATTRIBUTES(handle,
809                                 smb_fname,
810                                 dosmode);
811 }
812
813 static NTSTATUS skel_fget_dos_attributes(struct vfs_handle_struct *handle,
814                                 struct files_struct *fsp,
815                                 uint32_t *dosmode)
816 {
817         return SMB_VFS_NEXT_FGET_DOS_ATTRIBUTES(handle,
818                                 fsp,
819                                 dosmode);
820 }
821
822 static NTSTATUS skel_set_dos_attributes(struct vfs_handle_struct *handle,
823                                 const struct smb_filename *smb_fname,
824                                 uint32_t dosmode)
825 {
826         return SMB_VFS_NEXT_SET_DOS_ATTRIBUTES(handle,
827                                 smb_fname,
828                                 dosmode);
829 }
830
831 static NTSTATUS skel_fset_dos_attributes(struct vfs_handle_struct *handle,
832                                 struct files_struct *fsp,
833                                 uint32_t dosmode)
834 {
835         return SMB_VFS_NEXT_FSET_DOS_ATTRIBUTES(handle,
836                                 fsp,
837                                 dosmode);
838 }
839
840 static NTSTATUS skel_fget_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
841                                  uint32_t security_info,
842                                  TALLOC_CTX *mem_ctx,
843                                  struct security_descriptor **ppdesc)
844 {
845         return SMB_VFS_NEXT_FGET_NT_ACL(handle, fsp, security_info, mem_ctx,
846                                         ppdesc);
847 }
848
849 static NTSTATUS skel_get_nt_acl(vfs_handle_struct *handle,
850                                 const struct smb_filename *smb_fname,
851                                 uint32_t security_info,
852                                 TALLOC_CTX *mem_ctx,
853                                 struct security_descriptor **ppdesc)
854 {
855         return SMB_VFS_NEXT_GET_NT_ACL(handle,
856                                 smb_fname,
857                                 security_info,
858                                 mem_ctx,
859                                 ppdesc);
860 }
861
862 static NTSTATUS skel_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp,
863                                  uint32_t security_info_sent,
864                                  const struct security_descriptor *psd)
865 {
866         return SMB_VFS_NEXT_FSET_NT_ACL(handle, fsp, security_info_sent, psd);
867 }
868
869 static int skel_chmod_acl(vfs_handle_struct *handle,
870                         const struct smb_filename *smb_fname,
871                         mode_t mode)
872 {
873         return SMB_VFS_NEXT_CHMOD_ACL(handle, smb_fname, mode);
874 }
875
876 static int skel_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp,
877                            mode_t mode)
878 {
879         return SMB_VFS_NEXT_FCHMOD_ACL(handle, fsp, mode);
880 }
881
882 static SMB_ACL_T skel_sys_acl_get_file(vfs_handle_struct *handle,
883                                        const char *path_p,
884                                        SMB_ACL_TYPE_T type,
885                                        TALLOC_CTX *mem_ctx)
886 {
887         return SMB_VFS_NEXT_SYS_ACL_GET_FILE(handle, path_p, type, mem_ctx);
888 }
889
890 static SMB_ACL_T skel_sys_acl_get_fd(vfs_handle_struct *handle,
891                                      files_struct *fsp, TALLOC_CTX *mem_ctx)
892 {
893         return SMB_VFS_NEXT_SYS_ACL_GET_FD(handle, fsp, mem_ctx);
894 }
895
896 static int skel_sys_acl_blob_get_file(vfs_handle_struct *handle,
897                                       const char *path_p, TALLOC_CTX *mem_ctx,
898                                       char **blob_description, DATA_BLOB *blob)
899 {
900         return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FILE(handle, path_p, mem_ctx,
901                                                   blob_description, blob);
902 }
903
904 static int skel_sys_acl_blob_get_fd(vfs_handle_struct *handle,
905                                     files_struct *fsp, TALLOC_CTX *mem_ctx,
906                                     char **blob_description, DATA_BLOB *blob)
907 {
908         return SMB_VFS_NEXT_SYS_ACL_BLOB_GET_FD(handle, fsp, mem_ctx,
909                                                 blob_description, blob);
910 }
911
912 static int skel_sys_acl_set_file(vfs_handle_struct *handle, const char *name,
913                                  SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
914 {
915         return SMB_VFS_NEXT_SYS_ACL_SET_FILE(handle, name, acltype, theacl);
916 }
917
918 static int skel_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
919                                SMB_ACL_T theacl)
920 {
921         return SMB_VFS_NEXT_SYS_ACL_SET_FD(handle, fsp, theacl);
922 }
923
924 static int skel_sys_acl_delete_def_file(vfs_handle_struct *handle,
925                                         const char *path)
926 {
927         return SMB_VFS_NEXT_SYS_ACL_DELETE_DEF_FILE(handle, path);
928 }
929
930 static ssize_t skel_getxattr(vfs_handle_struct *handle, const char *path,
931                              const char *name, void *value, size_t size)
932 {
933         return SMB_VFS_NEXT_GETXATTR(handle, path, name, value, size);
934 }
935
936 static ssize_t skel_fgetxattr(vfs_handle_struct *handle,
937                               struct files_struct *fsp, const char *name,
938                               void *value, size_t size)
939 {
940         return SMB_VFS_NEXT_FGETXATTR(handle, fsp, name, value, size);
941 }
942
943 static ssize_t skel_listxattr(vfs_handle_struct *handle, const char *path,
944                               char *list, size_t size)
945 {
946         return SMB_VFS_NEXT_LISTXATTR(handle, path, list, size);
947 }
948
949 static ssize_t skel_flistxattr(vfs_handle_struct *handle,
950                                struct files_struct *fsp, char *list,
951                                size_t size)
952 {
953         return SMB_VFS_NEXT_FLISTXATTR(handle, fsp, list, size);
954 }
955
956 static int skel_removexattr(vfs_handle_struct *handle, const char *path,
957                             const char *name)
958 {
959         return SMB_VFS_NEXT_REMOVEXATTR(handle, path, name);
960 }
961
962 static int skel_fremovexattr(vfs_handle_struct *handle,
963                              struct files_struct *fsp, const char *name)
964 {
965         return SMB_VFS_NEXT_FREMOVEXATTR(handle, fsp, name);
966 }
967
968 static int skel_setxattr(vfs_handle_struct *handle, const char *path,
969                          const char *name, const void *value, size_t size,
970                          int flags)
971 {
972         return SMB_VFS_NEXT_SETXATTR(handle, path, name, value, size, flags);
973 }
974
975 static int skel_fsetxattr(vfs_handle_struct *handle, struct files_struct *fsp,
976                           const char *name, const void *value, size_t size,
977                           int flags)
978 {
979         return SMB_VFS_NEXT_FSETXATTR(handle, fsp, name, value, size, flags);
980 }
981
982 static bool skel_aio_force(struct vfs_handle_struct *handle,
983                            struct files_struct *fsp)
984 {
985         return SMB_VFS_NEXT_AIO_FORCE(handle, fsp);
986 }
987
988 /* VFS operations structure */
989
990 struct vfs_fn_pointers skel_transparent_fns = {
991         /* Disk operations */
992
993         .connect_fn = skel_connect,
994         .disconnect_fn = skel_disconnect,
995         .disk_free_fn = skel_disk_free,
996         .get_quota_fn = skel_get_quota,
997         .set_quota_fn = skel_set_quota,
998         .get_shadow_copy_data_fn = skel_get_shadow_copy_data,
999         .statvfs_fn = skel_statvfs,
1000         .fs_capabilities_fn = skel_fs_capabilities,
1001         .get_dfs_referrals_fn = skel_get_dfs_referrals,
1002         .snap_check_path_fn = skel_snap_check_path,
1003         .snap_create_fn = skel_snap_create,
1004         .snap_delete_fn = skel_snap_delete,
1005
1006         /* Directory operations */
1007
1008         .opendir_fn = skel_opendir,
1009         .fdopendir_fn = skel_fdopendir,
1010         .readdir_fn = skel_readdir,
1011         .seekdir_fn = skel_seekdir,
1012         .telldir_fn = skel_telldir,
1013         .rewind_dir_fn = skel_rewind_dir,
1014         .mkdir_fn = skel_mkdir,
1015         .rmdir_fn = skel_rmdir,
1016         .closedir_fn = skel_closedir,
1017         .init_search_op_fn = skel_init_search_op,
1018
1019         /* File operations */
1020
1021         .open_fn = skel_open,
1022         .create_file_fn = skel_create_file,
1023         .close_fn = skel_close_fn,
1024         .read_fn = skel_vfs_read,
1025         .pread_fn = skel_pread,
1026         .pread_send_fn = skel_pread_send,
1027         .pread_recv_fn = skel_pread_recv,
1028         .write_fn = skel_write,
1029         .pwrite_fn = skel_pwrite,
1030         .pwrite_send_fn = skel_pwrite_send,
1031         .pwrite_recv_fn = skel_pwrite_recv,
1032         .lseek_fn = skel_lseek,
1033         .sendfile_fn = skel_sendfile,
1034         .recvfile_fn = skel_recvfile,
1035         .rename_fn = skel_rename,
1036         .fsync_fn = skel_fsync,
1037         .fsync_send_fn = skel_fsync_send,
1038         .fsync_recv_fn = skel_fsync_recv,
1039         .stat_fn = skel_stat,
1040         .fstat_fn = skel_fstat,
1041         .lstat_fn = skel_lstat,
1042         .get_alloc_size_fn = skel_get_alloc_size,
1043         .unlink_fn = skel_unlink,
1044         .chmod_fn = skel_chmod,
1045         .fchmod_fn = skel_fchmod,
1046         .chown_fn = skel_chown,
1047         .fchown_fn = skel_fchown,
1048         .lchown_fn = skel_lchown,
1049         .chdir_fn = skel_chdir,
1050         .getwd_fn = skel_getwd,
1051         .ntimes_fn = skel_ntimes,
1052         .ftruncate_fn = skel_ftruncate,
1053         .fallocate_fn = skel_fallocate,
1054         .lock_fn = skel_lock,
1055         .kernel_flock_fn = skel_kernel_flock,
1056         .linux_setlease_fn = skel_linux_setlease,
1057         .getlock_fn = skel_getlock,
1058         .symlink_fn = skel_symlink,
1059         .readlink_fn = skel_vfs_readlink,
1060         .link_fn = skel_link,
1061         .mknod_fn = skel_mknod,
1062         .realpath_fn = skel_realpath,
1063         .chflags_fn = skel_chflags,
1064         .file_id_create_fn = skel_file_id_create,
1065         .copy_chunk_send_fn = skel_copy_chunk_send,
1066         .copy_chunk_recv_fn = skel_copy_chunk_recv,
1067         .get_compression_fn = skel_get_compression,
1068         .set_compression_fn = skel_set_compression,
1069
1070         .streaminfo_fn = skel_streaminfo,
1071         .get_real_filename_fn = skel_get_real_filename,
1072         .connectpath_fn = skel_connectpath,
1073         .brl_lock_windows_fn = skel_brl_lock_windows,
1074         .brl_unlock_windows_fn = skel_brl_unlock_windows,
1075         .brl_cancel_windows_fn = skel_brl_cancel_windows,
1076         .strict_lock_fn = skel_strict_lock,
1077         .strict_unlock_fn = skel_strict_unlock,
1078         .translate_name_fn = skel_translate_name,
1079         .fsctl_fn = skel_fsctl,
1080         .readdir_attr_fn = skel_readdir_attr,
1081
1082         /* DOS attributes. */
1083         .get_dos_attributes_fn = skel_get_dos_attributes,
1084         .fget_dos_attributes_fn = skel_fget_dos_attributes,
1085         .set_dos_attributes_fn = skel_set_dos_attributes,
1086         .fset_dos_attributes_fn = skel_fset_dos_attributes,
1087
1088         /* NT ACL operations. */
1089
1090         .fget_nt_acl_fn = skel_fget_nt_acl,
1091         .get_nt_acl_fn = skel_get_nt_acl,
1092         .fset_nt_acl_fn = skel_fset_nt_acl,
1093
1094         /* POSIX ACL operations. */
1095
1096         .chmod_acl_fn = skel_chmod_acl,
1097         .fchmod_acl_fn = skel_fchmod_acl,
1098
1099         .sys_acl_get_file_fn = skel_sys_acl_get_file,
1100         .sys_acl_get_fd_fn = skel_sys_acl_get_fd,
1101         .sys_acl_blob_get_file_fn = skel_sys_acl_blob_get_file,
1102         .sys_acl_blob_get_fd_fn = skel_sys_acl_blob_get_fd,
1103         .sys_acl_set_file_fn = skel_sys_acl_set_file,
1104         .sys_acl_set_fd_fn = skel_sys_acl_set_fd,
1105         .sys_acl_delete_def_file_fn = skel_sys_acl_delete_def_file,
1106
1107         /* EA operations. */
1108         .getxattr_fn = skel_getxattr,
1109         .fgetxattr_fn = skel_fgetxattr,
1110         .listxattr_fn = skel_listxattr,
1111         .flistxattr_fn = skel_flistxattr,
1112         .removexattr_fn = skel_removexattr,
1113         .fremovexattr_fn = skel_fremovexattr,
1114         .setxattr_fn = skel_setxattr,
1115         .fsetxattr_fn = skel_fsetxattr,
1116
1117         /* aio operations */
1118         .aio_force_fn = skel_aio_force,
1119 };
1120
1121 static_decl_vfs;
1122 NTSTATUS vfs_skel_transparent_init(TALLOC_CTX *ctx)
1123 {
1124         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "skel_transparent",
1125                                 &skel_transparent_fns);
1126 }