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