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