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