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