s3: VFS: Change SMB_VFS_SYS_ACL_GET_FILE to use const struct smb_filename * instead...
[samba.git] / source3 / modules / vfs_default.c
index 3081f6e06812d7af87e13686396bcf8f78ff77ac..c3de3d7572d2f05510bfc283f776d70c78c655ad 100644 (file)
 #include "source3/include/msdfs.h"
 #include "librpc/gen_ndr/ndr_dfsblobs.h"
 #include "lib/util/tevent_unix.h"
-#include "lib/asys/asys.h"
+#include "lib/util/tevent_ntstatus.h"
+#include "lib/util/sys_rw.h"
+#include "lib/pthreadpool/pthreadpool_tevent.h"
+#include "librpc/gen_ndr/ndr_ioctl.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
@@ -41,7 +44,7 @@
    is sure to try and execute them.  These stubs are used to prevent
    this possibility. */
 
-static int vfswrap_connect(vfs_handle_struct *handle,  const char *service, const char *user)
+static int vfswrap_connect(vfs_handle_struct *handle, const char *service, const char *user)
 {
     return 0;    /* Return >= 0 for success */
 }
@@ -52,22 +55,27 @@ static void vfswrap_disconnect(vfs_handle_struct *handle)
 
 /* Disk operations */
 
-static uint64_t vfswrap_disk_free(vfs_handle_struct *handle,  const char *path, bool small_query, uint64_t *bsize,
-                              uint64_t *dfree, uint64_t *dsize)
+static uint64_t vfswrap_disk_free(vfs_handle_struct *handle, const char *path,
+                                 uint64_t *bsize, uint64_t *dfree,
+                                 uint64_t *dsize)
 {
-       uint64_t result;
+       if (sys_fsusage(path, dfree, dsize) != 0) {
+               return (uint64_t)-1;
+       }
 
-       result = sys_disk_free(handle->conn, path, small_query, bsize, dfree, dsize);
-       return result;
+       *bsize = 512;
+       return *dfree / 2;
 }
 
-static int vfswrap_get_quota(struct vfs_handle_struct *handle,  enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
+static int vfswrap_get_quota(struct vfs_handle_struct *handle, const char *path,
+                            enum SMB_QUOTA_TYPE qtype, unid_t id,
+                            SMB_DISK_QUOTA *qt)
 {
 #ifdef HAVE_SYS_QUOTAS
        int result;
 
        START_PROFILE(syscall_get_quota);
-       result = sys_get_quota(handle->conn->connectpath, qtype, id, qt);
+       result = sys_get_quota(path, qtype, id, qt);
        END_PROFILE(syscall_get_quota);
        return result;
 #else
@@ -76,7 +84,7 @@ static int vfswrap_get_quota(struct vfs_handle_struct *handle,  enum SMB_QUOTA_T
 #endif
 }
 
-static int vfswrap_set_quota(struct vfs_handle_struct *handle,  enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
+static int vfswrap_set_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
 {
 #ifdef HAVE_SYS_QUOTAS
        int result;
@@ -100,7 +108,7 @@ static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle,
        return -1;  /* Not implemented. */
 }
 
-static int vfswrap_statvfs(struct vfs_handle_struct *handle,  const char *path, vfs_statvfs_struct *statbuf)
+static int vfswrap_statvfs(struct vfs_handle_struct *handle, const char *path, vfs_statvfs_struct *statbuf)
 {
        return sys_statvfs(path, statbuf);
 }
@@ -112,7 +120,6 @@ static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle,
        uint32_t caps = FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
        struct smb_filename *smb_fname_cpath = NULL;
        struct vfs_statvfs_struct statbuf;
-       NTSTATUS status;
        int ret;
 
        ZERO_STRUCT(statbuf);
@@ -126,12 +133,9 @@ static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle,
        /* Work out what timestamp resolution we can
         * use when setting a timestamp. */
 
-       status = create_synthetic_smb_fname(talloc_tos(),
-                               conn->connectpath,
-                               NULL,
-                               NULL,
-                               &smb_fname_cpath);
-       if (!NT_STATUS_IS_OK(status)) {
+       smb_fname_cpath = synthetic_smb_fname(talloc_tos(), conn->connectpath,
+                                             NULL, NULL, 0);
+       if (smb_fname_cpath == NULL) {
                return caps;
        }
 
@@ -213,6 +217,8 @@ static NTSTATUS vfswrap_get_dfs_referrals(struct vfs_handle_struct *handle,
 
        /* The following call can change cwd. */
        status = get_referred_path(r, pathnamep,
+                                  handle->conn->sconn->remote_address,
+                                  handle->conn->sconn->local_address,
                                   !handle->conn->sconn->using_smb2,
                                   junction, &consumedcnt, &self_referral);
        if (!NT_STATUS_IS_OK(status)) {
@@ -225,8 +231,7 @@ static NTSTATUS vfswrap_get_dfs_referrals(struct vfs_handle_struct *handle,
                pathnamep[consumedcnt] = '\0';
 
                if (DEBUGLVL(3)) {
-                       dbgtext("setup_dfs_referral: Path %s to "
-                               "alternate path(s):",
+                       dbgtext("Path %s to alternate path(s):",
                                pathnamep);
                        for (i=0; i < junction->referral_count; i++) {
                                dbgtext(" %s",
@@ -332,8 +337,7 @@ static NTSTATUS vfswrap_get_dfs_referrals(struct vfs_handle_struct *handle,
                }
                break;
        default:
-               DEBUG(0,("setup_dfs_referral: Invalid dfs referral "
-                       "version: %d\n",
+               DEBUG(0,("Invalid dfs referral version: %d\n",
                        max_referral_level));
                return NT_STATUS_INVALID_LEVEL;
        }
@@ -345,14 +349,44 @@ static NTSTATUS vfswrap_get_dfs_referrals(struct vfs_handle_struct *handle,
        return NT_STATUS_OK;
 }
 
+static NTSTATUS vfswrap_snap_check_path(struct vfs_handle_struct *handle,
+                                       TALLOC_CTX *mem_ctx,
+                                       const char *service_path,
+                                       char **base_volume)
+{
+       return NT_STATUS_NOT_SUPPORTED;
+}
+
+static NTSTATUS vfswrap_snap_create(struct vfs_handle_struct *handle,
+                                   TALLOC_CTX *mem_ctx,
+                                   const char *base_volume,
+                                   time_t *tstamp,
+                                   bool rw,
+                                   char **base_path,
+                                   char **snap_path)
+{
+       return NT_STATUS_NOT_SUPPORTED;
+}
+
+static NTSTATUS vfswrap_snap_delete(struct vfs_handle_struct *handle,
+                                   TALLOC_CTX *mem_ctx,
+                                   char *base_path,
+                                   char *snap_path)
+{
+       return NT_STATUS_NOT_SUPPORTED;
+}
+
 /* Directory operations */
 
-static DIR *vfswrap_opendir(vfs_handle_struct *handle,  const char *fname, const char *mask, uint32 attr)
+static DIR *vfswrap_opendir(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               const char *mask,
+                               uint32_t attr)
 {
        DIR *result;
 
        START_PROFILE(syscall_opendir);
-       result = opendir(fname);
+       result = opendir(smb_fname->base_name);
        END_PROFILE(syscall_opendir);
        return result;
 }
@@ -360,7 +394,7 @@ static DIR *vfswrap_opendir(vfs_handle_struct *handle,  const char *fname, const
 static DIR *vfswrap_fdopendir(vfs_handle_struct *handle,
                        files_struct *fsp,
                        const char *mask,
-                       uint32 attr)
+                       uint32_t attr)
 {
        DIR *result;
 
@@ -379,22 +413,56 @@ static struct dirent *vfswrap_readdir(vfs_handle_struct *handle,
 
        START_PROFILE(syscall_readdir);
        result = readdir(dirp);
-       /* Default Posix readdir() does not give us stat info.
-        * Set to invalid to indicate we didn't return this info. */
-       if (sbuf)
-               SET_STAT_INVALID(*sbuf);
        END_PROFILE(syscall_readdir);
+       if (sbuf) {
+               /* Default Posix readdir() does not give us stat info.
+                * Set to invalid to indicate we didn't return this info. */
+               SET_STAT_INVALID(*sbuf);
+#if defined(HAVE_DIRFD) && defined(HAVE_FSTATAT)
+               if (result != NULL) {
+                       /* See if we can efficiently return this. */
+                       struct stat st;
+                       int flags = AT_SYMLINK_NOFOLLOW;
+                       int ret = fstatat(dirfd(dirp),
+                                       result->d_name,
+                                       &st,
+                                       flags);
+                       /*
+                        * As this is an optimization,
+                        * ignore it if we stat'ed a
+                        * symlink. Make the caller
+                        * do it again as we don't
+                        * know if they wanted the link
+                        * info, or its target info.
+                        */
+                       if ((ret == 0) && (!S_ISLNK(st.st_mode))) {
+                               init_stat_ex_from_stat(sbuf,
+                                       &st,
+                                       lp_fake_directory_create_times(
+                                               SNUM(handle->conn)));
+                       }
+               }
+#endif
+       }
        return result;
 }
 
-static void vfswrap_seekdir(vfs_handle_struct *handle,  DIR *dirp, long offset)
+static NTSTATUS vfswrap_readdir_attr(struct vfs_handle_struct *handle,
+                                    const struct smb_filename *fname,
+                                    TALLOC_CTX *mem_ctx,
+                                    struct readdir_attr_data **attr_data)
+{
+       return NT_STATUS_NOT_SUPPORTED;
+}
+
+static void vfswrap_seekdir(vfs_handle_struct *handle, DIR *dirp, long offset)
 {
        START_PROFILE(syscall_seekdir);
        seekdir(dirp, offset);
        END_PROFILE(syscall_seekdir);
 }
 
-static long vfswrap_telldir(vfs_handle_struct *handle,  DIR *dirp)
+static long vfswrap_telldir(vfs_handle_struct *handle, DIR *dirp)
 {
        long result;
        START_PROFILE(syscall_telldir);
@@ -403,25 +471,29 @@ static long vfswrap_telldir(vfs_handle_struct *handle,  DIR *dirp)
        return result;
 }
 
-static void vfswrap_rewinddir(vfs_handle_struct *handle,  DIR *dirp)
+static void vfswrap_rewinddir(vfs_handle_struct *handle, DIR *dirp)
 {
        START_PROFILE(syscall_rewinddir);
        rewinddir(dirp);
        END_PROFILE(syscall_rewinddir);
 }
 
-static int vfswrap_mkdir(vfs_handle_struct *handle,  const char *path, mode_t mode)
+static int vfswrap_mkdir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
        bool has_dacl = False;
+       const char *path = smb_fname->base_name;
        char *parent = NULL;
 
        START_PROFILE(syscall_mkdir);
 
        if (lp_inherit_acls(SNUM(handle->conn))
            && parent_dirname(talloc_tos(), path, &parent, NULL)
-           && (has_dacl = directory_has_default_acl(handle->conn, parent)))
-               mode = (0777 & lp_dir_mask(SNUM(handle->conn)));
+           && (has_dacl = directory_has_default_acl(handle->conn, parent))) {
+               mode = (0777 & lp_directory_mask(SNUM(handle->conn)));
+       }
 
        TALLOC_FREE(parent);
 
@@ -436,25 +508,28 @@ static int vfswrap_mkdir(vfs_handle_struct *handle,  const char *path, mode_t mo
                 * mess up any inherited ACL bits that were set. JRA.
                 */
                int saved_errno = errno; /* We may get ENOSYS */
-               if ((SMB_VFS_CHMOD_ACL(handle->conn, path, mode) == -1) && (errno == ENOSYS))
+               if ((SMB_VFS_CHMOD_ACL(handle->conn, smb_fname, mode) == -1) &&
+                               (errno == ENOSYS)) {
                        errno = saved_errno;
+               }
        }
 
        END_PROFILE(syscall_mkdir);
        return result;
 }
 
-static int vfswrap_rmdir(vfs_handle_struct *handle,  const char *path)
+static int vfswrap_rmdir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
 {
        int result;
 
        START_PROFILE(syscall_rmdir);
-       result = rmdir(path);
+       result = rmdir(smb_fname->base_name);
        END_PROFILE(syscall_rmdir);
        return result;
 }
 
-static int vfswrap_closedir(vfs_handle_struct *handle,  DIR *dirp)
+static int vfswrap_closedir(vfs_handle_struct *handle, DIR *dirp)
 {
        int result;
 
@@ -501,20 +576,23 @@ static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
                                    uint32_t create_options,
                                    uint32_t file_attributes,
                                    uint32_t oplock_request,
+                                   struct smb2_lease *lease,
                                    uint64_t allocation_size,
                                    uint32_t private_flags,
                                    struct security_descriptor *sd,
                                    struct ea_list *ea_list,
                                    files_struct **result,
-                                   int *pinfo)
+                                   int *pinfo,
+                                   const struct smb2_create_blobs *in_context_blobs,
+                                   struct smb2_create_blobs *out_context_blobs)
 {
        return create_file_default(handle->conn, req, root_dir_fid, smb_fname,
                                   access_mask, share_access,
                                   create_disposition, create_options,
-                                  file_attributes, oplock_request,
+                                  file_attributes, oplock_request, lease,
                                   allocation_size, private_flags,
                                   sd, ea_list, result,
-                                  pinfo);
+                                  pinfo, in_context_blobs, out_context_blobs);
 }
 
 static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp)
@@ -533,7 +611,7 @@ static ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, void *
 
        START_PROFILE_BYTES(syscall_read, n);
        result = sys_read(fsp->fh->fd, data, n);
-       END_PROFILE(syscall_read);
+       END_PROFILE_BYTES(syscall_read);
        return result;
 }
 
@@ -545,7 +623,7 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void
 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
        START_PROFILE_BYTES(syscall_pread, n);
        result = sys_pread(fsp->fh->fd, data, n, offset);
-       END_PROFILE(syscall_pread);
+       END_PROFILE_BYTES(syscall_pread);
 
        if (result == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be seeked (sought?) on. */
@@ -587,7 +665,7 @@ static ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, const
 
        START_PROFILE_BYTES(syscall_write, n);
        result = sys_write(fsp->fh->fd, data, n);
-       END_PROFILE(syscall_write);
+       END_PROFILE_BYTES(syscall_write);
        return result;
 }
 
@@ -599,7 +677,7 @@ static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, cons
 #if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)
        START_PROFILE_BYTES(syscall_pwrite, n);
        result = sys_pwrite(fsp->fh->fd, data, n, offset);
-       END_PROFILE(syscall_pwrite);
+       END_PROFILE_BYTES(syscall_pwrite);
 
        if (result == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be sought on. */
@@ -630,48 +708,33 @@ static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, cons
        return result;
 }
 
-static void vfswrap_asys_finished(struct tevent_context *ev,
-                                 struct tevent_fd *fde,
-                                 uint16_t flags, void *p);
-
-static bool vfswrap_init_asys_ctx(struct smbXsrv_connection *conn)
+static int vfswrap_init_pool(struct smbd_server_connection *conn)
 {
        int ret;
 
-       if (conn->asys_ctx != NULL) {
-               return true;
-       }
-       ret = asys_context_init(&conn->asys_ctx, aio_pending_size);
-       if (ret != 0) {
-               DEBUG(1, ("asys_context_init failed: %s\n", strerror(ret)));
-               return false;
-       }
-       conn->asys_fde = tevent_add_fd(conn->ev_ctx, conn,
-                                      asys_signalfd(conn->asys_ctx),
-                                      TEVENT_FD_READ,
-                                      vfswrap_asys_finished,
-                                      conn->asys_ctx);
-       if (conn->asys_fde == NULL) {
-               DEBUG(1, ("tevent_add_fd failed\n"));
-               asys_context_destroy(conn->asys_ctx);
-               conn->asys_ctx = NULL;
-               return false;
+       if (conn->pool != NULL) {
+               return 0;
        }
-       return true;
+
+       ret = pthreadpool_tevent_init(conn, lp_aio_max_threads(),
+                                     &conn->pool);
+       return ret;
 }
 
-struct vfswrap_asys_state {
-       struct asys_context *asys_ctx;
-       struct tevent_req *req;
+struct vfswrap_pread_state {
        ssize_t ret;
        int err;
+       int fd;
+       void *buf;
+       size_t count;
+       off_t offset;
+
+       struct vfs_aio_state vfs_aio_state;
+       SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
 };
 
-static int vfswrap_asys_state_destructor(struct vfswrap_asys_state *s)
-{
-       asys_cancel(s->asys_ctx, s->req);
-       return 0;
-}
+static void vfs_pread_do(void *private_data);
+static void vfs_pread_done(struct tevent_req *subreq);
 
 static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
                                             TALLOC_CTX *mem_ctx,
@@ -680,31 +743,115 @@ static struct tevent_req *vfswrap_pread_send(struct vfs_handle_struct *handle,
                                             void *data,
                                             size_t n, off_t offset)
 {
-       struct tevent_req *req;
-       struct vfswrap_asys_state *state;
+       struct tevent_req *req, *subreq;
+       struct vfswrap_pread_state *state;
        int ret;
 
-       req = tevent_req_create(mem_ctx, &state, struct vfswrap_asys_state);
+       req = tevent_req_create(mem_ctx, &state, struct vfswrap_pread_state);
        if (req == NULL) {
                return NULL;
        }
-       if (!vfswrap_init_asys_ctx(handle->conn->sconn->conn)) {
-               tevent_req_oom(req);
+
+       ret = vfswrap_init_pool(handle->conn->sconn);
+       if (tevent_req_error(req, ret)) {
                return tevent_req_post(req, ev);
        }
-       state->asys_ctx = handle->conn->sconn->conn->asys_ctx;
-       state->req = req;
 
-       ret = asys_pread(state->asys_ctx, fsp->fh->fd, data, n, offset, req);
-       if (ret != 0) {
-               tevent_req_error(req, ret);
+       state->ret = -1;
+       state->fd = fsp->fh->fd;
+       state->buf = data;
+       state->count = n;
+       state->offset = offset;
+
+       SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pread, profile_p,
+                                    state->profile_bytes, n);
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
+
+       subreq = pthreadpool_tevent_job_send(
+               state, ev, handle->conn->sconn->pool,
+               vfs_pread_do, state);
+       if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
-       talloc_set_destructor(state, vfswrap_asys_state_destructor);
+       tevent_req_set_callback(subreq, vfs_pread_done, req);
 
        return req;
 }
 
+static void vfs_pread_do(void *private_data)
+{
+       struct vfswrap_pread_state *state = talloc_get_type_abort(
+               private_data, struct vfswrap_pread_state);
+       struct timespec start_time;
+       struct timespec end_time;
+
+       SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
+
+       PROFILE_TIMESTAMP(&start_time);
+
+       do {
+               state->ret = pread(state->fd, state->buf, state->count,
+                                  state->offset);
+       } while ((state->ret == -1) && (errno == EINTR));
+
+       state->err = errno;
+
+       PROFILE_TIMESTAMP(&end_time);
+
+       state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
+
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
+}
+
+static void vfs_pread_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+#ifdef WITH_PROFILE
+       struct vfswrap_pread_state *state = tevent_req_data(
+               req, struct vfswrap_pread_state);
+#endif
+       int ret;
+
+       ret = pthreadpool_tevent_job_recv(subreq);
+       TALLOC_FREE(subreq);
+       SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
+       if (tevent_req_error(req, ret)) {
+               return;
+       }
+
+       tevent_req_done(req);
+}
+
+static ssize_t vfswrap_pread_recv(struct tevent_req *req,
+                                 struct vfs_aio_state *vfs_aio_state)
+{
+       struct vfswrap_pread_state *state = tevent_req_data(
+               req, struct vfswrap_pread_state);
+
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
+               return -1;
+       }
+
+       *vfs_aio_state = state->vfs_aio_state;
+       return state->ret;
+}
+
+struct vfswrap_pwrite_state {
+       ssize_t ret;
+       int err;
+       int fd;
+       const void *buf;
+       size_t count;
+       off_t offset;
+
+       struct vfs_aio_state vfs_aio_state;
+       SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
+};
+
+static void vfs_pwrite_do(void *private_data);
+static void vfs_pwrite_done(struct tevent_req *subreq);
+
 static struct tevent_req *vfswrap_pwrite_send(struct vfs_handle_struct *handle,
                                              TALLOC_CTX *mem_ctx,
                                              struct tevent_context *ev,
@@ -712,118 +859,198 @@ static struct tevent_req *vfswrap_pwrite_send(struct vfs_handle_struct *handle,
                                              const void *data,
                                              size_t n, off_t offset)
 {
-       struct tevent_req *req;
-       struct vfswrap_asys_state *state;
+       struct tevent_req *req, *subreq;
+       struct vfswrap_pwrite_state *state;
        int ret;
 
-       req = tevent_req_create(mem_ctx, &state, struct vfswrap_asys_state);
+       req = tevent_req_create(mem_ctx, &state, struct vfswrap_pwrite_state);
        if (req == NULL) {
                return NULL;
        }
-       if (!vfswrap_init_asys_ctx(handle->conn->sconn->conn)) {
-               tevent_req_oom(req);
+
+       ret = vfswrap_init_pool(handle->conn->sconn);
+       if (tevent_req_error(req, ret)) {
                return tevent_req_post(req, ev);
        }
-       state->asys_ctx = handle->conn->sconn->conn->asys_ctx;
-       state->req = req;
 
-       ret = asys_pwrite(state->asys_ctx, fsp->fh->fd, data, n, offset, req);
-       if (ret != 0) {
-               tevent_req_error(req, ret);
+       state->ret = -1;
+       state->fd = fsp->fh->fd;
+       state->buf = data;
+       state->count = n;
+       state->offset = offset;
+
+       SMBPROFILE_BYTES_ASYNC_START(syscall_asys_pwrite, profile_p,
+                                    state->profile_bytes, n);
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
+
+       subreq = pthreadpool_tevent_job_send(
+               state, ev, handle->conn->sconn->pool,
+               vfs_pwrite_do, state);
+       if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
-       talloc_set_destructor(state, vfswrap_asys_state_destructor);
+       tevent_req_set_callback(subreq, vfs_pwrite_done, req);
 
        return req;
 }
 
+static void vfs_pwrite_do(void *private_data)
+{
+       struct vfswrap_pwrite_state *state = talloc_get_type_abort(
+               private_data, struct vfswrap_pwrite_state);
+       struct timespec start_time;
+       struct timespec end_time;
+
+       SMBPROFILE_BYTES_ASYNC_SET_BUSY(state->profile_bytes);
+
+       PROFILE_TIMESTAMP(&start_time);
+
+       do {
+               state->ret = pwrite(state->fd, state->buf, state->count,
+                                  state->offset);
+       } while ((state->ret == -1) && (errno == EINTR));
+
+       state->err = errno;
+
+       PROFILE_TIMESTAMP(&end_time);
+
+       state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
+
+       SMBPROFILE_BYTES_ASYNC_SET_IDLE(state->profile_bytes);
+}
+
+static void vfs_pwrite_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+#ifdef WITH_PROFILE
+       struct vfswrap_pwrite_state *state = tevent_req_data(
+               req, struct vfswrap_pwrite_state);
+#endif
+       int ret;
+
+       ret = pthreadpool_tevent_job_recv(subreq);
+       TALLOC_FREE(subreq);
+       SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
+       if (tevent_req_error(req, ret)) {
+               return;
+       }
+
+       tevent_req_done(req);
+}
+
+static ssize_t vfswrap_pwrite_recv(struct tevent_req *req,
+                                  struct vfs_aio_state *vfs_aio_state)
+{
+       struct vfswrap_pwrite_state *state = tevent_req_data(
+               req, struct vfswrap_pwrite_state);
+
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
+               return -1;
+       }
+
+       *vfs_aio_state = state->vfs_aio_state;
+       return state->ret;
+}
+
+struct vfswrap_fsync_state {
+       ssize_t ret;
+       int err;
+       int fd;
+
+       struct vfs_aio_state vfs_aio_state;
+       SMBPROFILE_BASIC_ASYNC_STATE(profile_basic);
+};
+
+static void vfs_fsync_do(void *private_data);
+static void vfs_fsync_done(struct tevent_req *subreq);
+
 static struct tevent_req *vfswrap_fsync_send(struct vfs_handle_struct *handle,
                                             TALLOC_CTX *mem_ctx,
                                             struct tevent_context *ev,
                                             struct files_struct *fsp)
 {
-       struct tevent_req *req;
-       struct vfswrap_asys_state *state;
+       struct tevent_req *req, *subreq;
+       struct vfswrap_fsync_state *state;
        int ret;
 
-       req = tevent_req_create(mem_ctx, &state, struct vfswrap_asys_state);
+       req = tevent_req_create(mem_ctx, &state, struct vfswrap_fsync_state);
        if (req == NULL) {
                return NULL;
        }
-       if (!vfswrap_init_asys_ctx(handle->conn->sconn->conn)) {
-               tevent_req_oom(req);
+
+       ret = vfswrap_init_pool(handle->conn->sconn);
+       if (tevent_req_error(req, ret)) {
                return tevent_req_post(req, ev);
        }
-       state->asys_ctx = handle->conn->sconn->conn->asys_ctx;
-       state->req = req;
 
-       ret = asys_fsync(state->asys_ctx, fsp->fh->fd, req);
-       if (ret != 0) {
-               tevent_req_error(req, ret);
+       state->ret = -1;
+       state->fd = fsp->fh->fd;
+
+       SMBPROFILE_BASIC_ASYNC_START(syscall_asys_fsync, profile_p,
+                                    state->profile_basic);
+
+       subreq = pthreadpool_tevent_job_send(
+               state, ev, handle->conn->sconn->pool, vfs_fsync_do, state);
+       if (tevent_req_nomem(subreq, req)) {
                return tevent_req_post(req, ev);
        }
-       talloc_set_destructor(state, vfswrap_asys_state_destructor);
+       tevent_req_set_callback(subreq, vfs_fsync_done, req);
 
        return req;
 }
 
-static void vfswrap_asys_finished(struct tevent_context *ev,
-                                       struct tevent_fd *fde,
-                                       uint16_t flags, void *p)
+static void vfs_fsync_do(void *private_data)
 {
-       struct asys_context *asys_ctx = (struct asys_context *)p;
-       struct tevent_req *req;
-       struct vfswrap_asys_state *state;
-       int res;
-       ssize_t ret;
-       int err;
-       void *private_data;
+       struct vfswrap_fsync_state *state = talloc_get_type_abort(
+               private_data, struct vfswrap_fsync_state);
+       struct timespec start_time;
+       struct timespec end_time;
 
-       if ((flags & TEVENT_FD_READ) == 0) {
-               return;
-       }
+       PROFILE_TIMESTAMP(&start_time);
 
-       res = asys_result(asys_ctx, &ret, &err, &private_data);
-       if (res == ECANCELED) {
-               return;
-       }
+       do {
+               state->ret = fsync(state->fd);
+       } while ((state->ret == -1) && (errno == EINTR));
 
-       if (res != 0) {
-               DEBUG(1, ("asys_result returned %s\n", strerror(res)));
-               return;
-       }
+       state->err = errno;
 
-       req = talloc_get_type_abort(private_data, struct tevent_req);
-       state = tevent_req_data(req, struct vfswrap_asys_state);
+       PROFILE_TIMESTAMP(&end_time);
 
-       talloc_set_destructor(state, NULL);
-
-       state->ret = ret;
-       state->err = err;
-       tevent_req_done(req);
+       state->vfs_aio_state.duration = nsec_time_diff(&end_time, &start_time);
 }
 
-static ssize_t vfswrap_asys_ssize_t_recv(struct tevent_req *req, int *err)
+static void vfs_fsync_done(struct tevent_req *subreq)
 {
-       struct vfswrap_asys_state *state = tevent_req_data(
-               req, struct vfswrap_asys_state);
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+#ifdef WITH_PROFILE
+       struct vfswrap_fsync_state *state = tevent_req_data(
+               req, struct vfswrap_fsync_state);
+#endif
+       int ret;
 
-       if (tevent_req_is_unix_error(req, err)) {
-               return -1;
+       ret = pthreadpool_tevent_job_recv(subreq);
+       TALLOC_FREE(subreq);
+       SMBPROFILE_BASIC_ASYNC_END(state->profile_basic);
+       if (tevent_req_error(req, ret)) {
+               return;
        }
-       *err = state->err;
-       return state->ret;
+
+       tevent_req_done(req);
 }
 
-static int vfswrap_asys_int_recv(struct tevent_req *req, int *err)
+static int vfswrap_fsync_recv(struct tevent_req *req,
+                             struct vfs_aio_state *vfs_aio_state)
 {
-       struct vfswrap_asys_state *state = tevent_req_data(
-               req, struct vfswrap_asys_state);
+       struct vfswrap_fsync_state *state = tevent_req_data(
+               req, struct vfswrap_fsync_state);
 
-       if (tevent_req_is_unix_error(req, err)) {
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
                return -1;
        }
-       *err = state->err;
+
+       *vfs_aio_state = state->vfs_aio_state;
        return state->ret;
 }
 
@@ -860,7 +1087,7 @@ static ssize_t vfswrap_sendfile(vfs_handle_struct *handle, int tofd, files_struc
 
        START_PROFILE_BYTES(syscall_sendfile, n);
        result = sys_sendfile(tofd, fromfsp->fh->fd, hdr, offset, n);
-       END_PROFILE(syscall_sendfile);
+       END_PROFILE_BYTES(syscall_sendfile);
        return result;
 }
 
@@ -874,7 +1101,7 @@ static ssize_t vfswrap_recvfile(vfs_handle_struct *handle,
 
        START_PROFILE_BYTES(syscall_recvfile, n);
        result = sys_recvfile(fromfd, tofsp->fh->fd, offset, n);
-       END_PROFILE(syscall_recvfile);
+       END_PROFILE_BYTES(syscall_recvfile);
        return result;
 }
 
@@ -925,7 +1152,7 @@ static int vfswrap_stat(vfs_handle_struct *handle,
        }
 
        result = sys_stat(smb_fname->base_name, &smb_fname->st,
-                         lp_fake_dir_create_times(SNUM(handle->conn)));
+                         lp_fake_directory_create_times(SNUM(handle->conn)));
  out:
        END_PROFILE(syscall_stat);
        return result;
@@ -937,7 +1164,7 @@ static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUC
 
        START_PROFILE(syscall_fstat);
        result = sys_fstat(fsp->fh->fd,
-                          sbuf, lp_fake_dir_create_times(SNUM(handle->conn)));
+                          sbuf, lp_fake_directory_create_times(SNUM(handle->conn)));
        END_PROFILE(syscall_fstat);
        return result;
 }
@@ -955,7 +1182,7 @@ static int vfswrap_lstat(vfs_handle_struct *handle,
        }
 
        result = sys_lstat(smb_fname->base_name, &smb_fname->st,
-                          lp_fake_dir_create_times(SNUM(handle->conn)));
+                          lp_fake_directory_create_times(SNUM(handle->conn)));
  out:
        END_PROFILE(syscall_lstat);
        return result;
@@ -979,7 +1206,7 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                              struct files_struct *fsp,
                              TALLOC_CTX *ctx,
                              uint32_t function,
-                             uint16_t req_flags,  /* Needed for UNICODE ... */
+                             uint16_t req_flags, /* Needed for UNICODE ... */
                              const uint8_t *_in_data,
                              uint32_t in_len,
                              uint8_t **_out_data,
@@ -988,22 +1215,22 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
 {
        const char *in_data = (const char *)_in_data;
        char **out_data = (char **)_out_data;
+       NTSTATUS status;
 
        switch (function) {
        case FSCTL_SET_SPARSE:
        {
                bool set_sparse = true;
-               NTSTATUS status;
 
                if (in_len >= 1 && in_data[0] == 0) {
                        set_sparse = false;
                }
 
                status = file_set_sparse(handle->conn, fsp, set_sparse);
-               
+
                DEBUG(NT_STATUS_IS_OK(status) ? 10 : 9,
                      ("FSCTL_SET_SPARSE: fname[%s] set[%u] - %s\n",
-                      smb_fname_str_dbg(fsp->fsp_name), set_sparse, 
+                      smb_fname_str_dbg(fsp->fsp_name), set_sparse,
                       nt_errstr(status)));
 
                return status;
@@ -1021,7 +1248,8 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on %s\n",
                          fsp_fnum_dbg(fsp)));
 
-               *out_len = (max_out_len >= 64) ? 64 : max_out_len;
+               *out_len = MIN(max_out_len, 64);
+
                /* Hmmm, will this cause problems if less data asked for? */
                return_data = talloc_array(ctx, char, 64);
                if (return_data == NULL) {
@@ -1032,6 +1260,7 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                push_file_id_16(return_data, &fsp->file_id);
                memcpy(return_data+16,create_volume_objectid(fsp->conn,objid),16);
                push_file_id_16(return_data+32, &fsp->file_id);
+               memset(return_data+48, 0, 16);
                *out_data = return_data;
                return NT_STATUS_OK;
        }
@@ -1066,8 +1295,8 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                 */
                struct shadow_copy_data *shadow_data = NULL;
                bool labels = False;
-               uint32 labels_data_count = 0;
-               uint32 i;
+               uint32_t labels_data_count = 0;
+               uint32_t i;
                char *cur_pdata = NULL;
 
                if (max_out_len < 16) {
@@ -1090,25 +1319,32 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                 * Call the VFS routine to actually do the work.
                 */
                if (SMB_VFS_GET_SHADOW_COPY_DATA(fsp, shadow_data, labels)!=0) {
-                       TALLOC_FREE(shadow_data);
-                       if (errno == ENOSYS) {
-                               DEBUG(5,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, not supported.\n", 
-                                       fsp->conn->connectpath));
-                               return NT_STATUS_NOT_SUPPORTED;
+                       int log_lev = 0;
+                       if (errno == 0) {
+                               /* broken module didn't set errno on error */
+                               status = NT_STATUS_UNSUCCESSFUL;
                        } else {
-                               DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n", 
-                                       fsp->conn->connectpath));
-                               return NT_STATUS_UNSUCCESSFUL;
+                               status = map_nt_error_from_unix(errno);
+                               if (NT_STATUS_EQUAL(status,
+                                                   NT_STATUS_NOT_SUPPORTED)) {
+                                       log_lev = 5;
+                               }
                        }
+                       DEBUG(log_lev, ("FSCTL_GET_SHADOW_COPY_DATA: "
+                                       "connectpath %s, failed - %s.\n",
+                                       fsp->conn->connectpath,
+                                       nt_errstr(status)));
+                       TALLOC_FREE(shadow_data);
+                       return status;
                }
 
-               labels_data_count = (shadow_data->num_volumes * 2 * 
+               labels_data_count = (shadow_data->num_volumes * 2 *
                                        sizeof(SHADOW_COPY_LABEL)) + 2;
 
                if (!labels) {
                        *out_len = 16;
                } else {
-                       *out_len = 12 + labels_data_count + 4;
+                       *out_len = 12 + labels_data_count;
                }
 
                if (max_out_len < *out_len) {
@@ -1118,7 +1354,7 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                        return NT_STATUS_BUFFER_TOO_SMALL;
                }
 
-               cur_pdata = talloc_array(ctx, char, *out_len);
+               cur_pdata = talloc_zero_array(ctx, char, *out_len);
                if (cur_pdata == NULL) {
                        TALLOC_FREE(shadow_data);
                        return NT_STATUS_NO_MEMORY;
@@ -1135,7 +1371,7 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                }
 
                /* needed_data_count 4 bytes */
-               SIVAL(cur_pdata, 8, labels_data_count + 4);
+               SIVAL(cur_pdata, 8, labels_data_count);
 
                cur_pdata += 12;
 
@@ -1143,10 +1379,16 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                          shadow_data->num_volumes, fsp_str_dbg(fsp)));
                if (labels && shadow_data->labels) {
                        for (i=0; i<shadow_data->num_volumes; i++) {
-                               srvstr_push(cur_pdata, req_flags,
+                               size_t len = 0;
+                               status = srvstr_push(cur_pdata, req_flags,
                                            cur_pdata, shadow_data->labels[i],
                                            2 * sizeof(SHADOW_COPY_LABEL),
-                                           STR_UNICODE|STR_TERMINATE);
+                                           STR_UNICODE|STR_TERMINATE, &len);
+                               if (!NT_STATUS_IS_OK(status)) {
+                                       TALLOC_FREE(*out_data);
+                                       TALLOC_FREE(shadow_data);
+                                       return status;
+                               }
                                cur_pdata += 2 * sizeof(SHADOW_COPY_LABEL);
                                DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
                        }
@@ -1182,7 +1424,7 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                /* unknown 4 bytes: this is not the length of the sid :-(  */
                /*unknown = IVAL(pdata,0);*/
 
-               if (!sid_parse(in_data + 4, sid_len, &sid)) {
+               if (!sid_parse(_in_data + 4, sid_len, &sid)) {
                        return NT_STATUS_INVALID_PARAMETER;
                }
                DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
@@ -1227,7 +1469,6 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
                 * and SEEK_DATA/SEEK_HOLE on Solaris is needed to make
                 * this FSCTL correct for sparse files.
                 */
-               NTSTATUS status;
                uint64_t offset, length;
                char *out_data_tmp = NULL;
 
@@ -1292,7 +1533,7 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
        }
 
        default:
-               /* 
+               /*
                 * Only print once ... unfortunately there could be lots of
                 * different FSCTLs that are called.
                 */
@@ -1306,6 +1547,350 @@ static NTSTATUS vfswrap_fsctl(struct vfs_handle_struct *handle,
        return NT_STATUS_NOT_SUPPORTED;
 }
 
+static bool vfswrap_is_offline(struct vfs_handle_struct *handle,
+                              const struct smb_filename *fname,
+                              SMB_STRUCT_STAT *sbuf);
+
+static NTSTATUS vfswrap_get_dos_attributes(struct vfs_handle_struct *handle,
+                                          struct smb_filename *smb_fname,
+                                          uint32_t *dosmode)
+{
+       bool offline;
+
+       offline = vfswrap_is_offline(handle, smb_fname, &smb_fname->st);
+       if (offline) {
+               *dosmode |= FILE_ATTRIBUTE_OFFLINE;
+       }
+
+       return get_ea_dos_attribute(handle->conn, smb_fname, dosmode);
+}
+
+static NTSTATUS vfswrap_fget_dos_attributes(struct vfs_handle_struct *handle,
+                                           struct files_struct *fsp,
+                                           uint32_t *dosmode)
+{
+       bool offline;
+
+       offline = vfswrap_is_offline(handle, fsp->fsp_name, &fsp->fsp_name->st);
+       if (offline) {
+               *dosmode |= FILE_ATTRIBUTE_OFFLINE;
+       }
+
+       return get_ea_dos_attribute(handle->conn, fsp->fsp_name, dosmode);
+}
+
+static NTSTATUS vfswrap_set_dos_attributes(struct vfs_handle_struct *handle,
+                                          const struct smb_filename *smb_fname,
+                                          uint32_t dosmode)
+{
+       return set_ea_dos_attribute(handle->conn, smb_fname, dosmode);
+}
+
+static NTSTATUS vfswrap_fset_dos_attributes(struct vfs_handle_struct *handle,
+                                           struct files_struct *fsp,
+                                           uint32_t dosmode)
+{
+       return set_ea_dos_attribute(handle->conn, fsp->fsp_name, dosmode);
+}
+
+struct vfs_cc_state {
+       struct tevent_context *ev;
+       uint8_t *buf;
+       bool read_lck_locked;
+       struct lock_struct read_lck;
+       bool write_lck_locked;
+       struct lock_struct write_lck;
+       struct files_struct *src_fsp;
+       off_t src_off;
+       struct files_struct *dst_fsp;
+       off_t dst_off;
+       off_t to_copy;
+       off_t remaining;
+       size_t next_io_size;
+       uint32_t flags;
+};
+
+static NTSTATUS copy_chunk_loop(struct tevent_req *req);
+
+static struct tevent_req *vfswrap_copy_chunk_send(struct vfs_handle_struct *handle,
+                                                 TALLOC_CTX *mem_ctx,
+                                                 struct tevent_context *ev,
+                                                 struct files_struct *src_fsp,
+                                                 off_t src_off,
+                                                 struct files_struct *dest_fsp,
+                                                 off_t dest_off,
+                                                 off_t to_copy,
+                                                 uint32_t flags)
+{
+       struct tevent_req *req;
+       struct vfs_cc_state *state = NULL;
+       size_t num = MIN(to_copy, COPYCHUNK_MAX_TOTAL_LEN);
+       NTSTATUS status;
+
+       DBG_DEBUG("server side copy chunk of length %" PRIu64 "\n", to_copy);
+
+       req = tevent_req_create(mem_ctx, &state, struct vfs_cc_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       if (flags & ~VFS_COPY_CHUNK_FL_MASK_ALL) {
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+
+       if (flags & VFS_COPY_CHUNK_FL_MUST_CLONE) {
+               DEBUG(10, ("COW clones not supported by vfs_default\n"));
+               tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
+               return tevent_req_post(req, ev);
+       }
+
+       *state = (struct vfs_cc_state) {
+               .ev = ev,
+               .src_fsp = src_fsp,
+               .src_off = src_off,
+               .dst_fsp = dest_fsp,
+               .dst_off = dest_off,
+               .to_copy = to_copy,
+               .remaining = to_copy,
+               .flags = flags,
+       };
+       state->buf = talloc_array(state, uint8_t, num);
+       if (tevent_req_nomem(state->buf, req)) {
+               return tevent_req_post(req, ev);
+       }
+
+       status = vfs_stat_fsp(src_fsp);
+       if (tevent_req_nterror(req, status)) {
+               return tevent_req_post(req, ev);
+       }
+
+       if (src_fsp->fsp_name->st.st_ex_size < src_off + num) {
+               /*
+                * [MS-SMB2] 3.3.5.15.6 Handling a Server-Side Data Copy Request
+                *   If the SourceOffset or SourceOffset + Length extends beyond
+                *   the end of file, the server SHOULD<240> treat this as a
+                *   STATUS_END_OF_FILE error.
+                * ...
+                *   <240> Section 3.3.5.15.6: Windows servers will return
+                *   STATUS_INVALID_VIEW_SIZE instead of STATUS_END_OF_FILE.
+                */
+               tevent_req_nterror(req, NT_STATUS_INVALID_VIEW_SIZE);
+               return tevent_req_post(req, ev);
+       }
+
+       if (src_fsp->op == NULL) {
+               tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
+               return tevent_req_post(req, ev);
+       }
+
+       if (dest_fsp->op == NULL) {
+               tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
+               return tevent_req_post(req, ev);
+       }
+
+       status = copy_chunk_loop(req);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return tevent_req_post(req, ev);
+       }
+
+       return req;
+}
+
+static void vfswrap_copy_chunk_read_done(struct tevent_req *subreq);
+
+static NTSTATUS copy_chunk_loop(struct tevent_req *req)
+{
+       struct vfs_cc_state *state = tevent_req_data(req, struct vfs_cc_state);
+       struct tevent_req *subreq = NULL;
+       bool ok;
+
+       state->next_io_size = MIN(state->remaining, talloc_array_length(state->buf));
+
+       if (!(state->flags & VFS_COPY_CHUNK_FL_IGNORE_LOCKS)) {
+               init_strict_lock_struct(state->src_fsp,
+                               state->src_fsp->op->global->open_persistent_id,
+                                       state->src_off,
+                                       state->next_io_size,
+                                       READ_LOCK,
+                                       &state->read_lck);
+
+               ok = SMB_VFS_STRICT_LOCK(state->src_fsp->conn,
+                                        state->src_fsp,
+                                        &state->read_lck);
+               if (!ok) {
+                       return NT_STATUS_FILE_LOCK_CONFLICT;
+               }
+       }
+
+       subreq = SMB_VFS_PREAD_SEND(state,
+                                   state->src_fsp->conn->sconn->ev_ctx,
+                                   state->src_fsp,
+                                   state->buf,
+                                   state->next_io_size,
+                                   state->src_off);
+       if (subreq == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       tevent_req_set_callback(subreq, vfswrap_copy_chunk_read_done, req);
+
+       return NT_STATUS_OK;
+}
+
+static void vfswrap_copy_chunk_write_done(struct tevent_req *subreq);
+
+static void vfswrap_copy_chunk_read_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct vfs_cc_state *state = tevent_req_data(req, struct vfs_cc_state);
+       struct vfs_aio_state aio_state;
+       ssize_t nread;
+       bool ok;
+
+       if (!(state->flags & VFS_COPY_CHUNK_FL_IGNORE_LOCKS)) {
+               SMB_VFS_STRICT_UNLOCK(state->src_fsp->conn,
+                                     state->src_fsp,
+                                     &state->read_lck);
+               ZERO_STRUCT(state->read_lck);
+       }
+
+       nread = SMB_VFS_PREAD_RECV(subreq, &aio_state);
+       TALLOC_FREE(subreq);
+       if (nread == -1) {
+               DBG_ERR("read failed: %s\n", strerror(errno));
+               tevent_req_nterror(req, map_nt_error_from_unix(aio_state.error));
+               return;
+       }
+       if (nread != state->next_io_size) {
+               DBG_ERR("Short read, only %zd of %zu\n",
+                       nread, state->next_io_size);
+               tevent_req_nterror(req, NT_STATUS_IO_DEVICE_ERROR);
+               return;
+       }
+
+       state->src_off += nread;
+
+       if (!(state->flags & VFS_COPY_CHUNK_FL_IGNORE_LOCKS)) {
+               init_strict_lock_struct(state->dst_fsp,
+                               state->dst_fsp->op->global->open_persistent_id,
+                                       state->dst_off,
+                                       state->next_io_size,
+                                       WRITE_LOCK,
+                                       &state->write_lck);
+
+               ok = SMB_VFS_STRICT_LOCK(state->dst_fsp->conn,
+                                        state->dst_fsp,
+                                        &state->write_lck);
+               if (!ok) {
+                       tevent_req_nterror(req, NT_STATUS_FILE_LOCK_CONFLICT);
+                       return;
+               }
+       }
+
+       subreq = SMB_VFS_PWRITE_SEND(state,
+                                    state->ev,
+                                    state->dst_fsp,
+                                    state->buf,
+                                    state->next_io_size,
+                                    state->dst_off);
+       if (subreq == NULL) {
+               tevent_req_nterror(req, NT_STATUS_NO_MEMORY);
+               return;
+       }
+       tevent_req_set_callback(subreq, vfswrap_copy_chunk_write_done, req);
+}
+
+static void vfswrap_copy_chunk_write_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct vfs_cc_state *state = tevent_req_data(req, struct vfs_cc_state);
+       struct vfs_aio_state aio_state;
+       ssize_t nwritten;
+       NTSTATUS status;
+
+       if (!(state->flags & VFS_COPY_CHUNK_FL_IGNORE_LOCKS)) {
+               SMB_VFS_STRICT_UNLOCK(state->dst_fsp->conn,
+                                     state->dst_fsp,
+                                     &state->write_lck);
+               ZERO_STRUCT(state->write_lck);
+       }
+
+       nwritten = SMB_VFS_PWRITE_RECV(subreq, &aio_state);
+       TALLOC_FREE(subreq);
+       if (nwritten == -1) {
+               DBG_ERR("write failed: %s\n", strerror(errno));
+               tevent_req_nterror(req, map_nt_error_from_unix(aio_state.error));
+               return;
+       }
+       if (nwritten != state->next_io_size) {
+               DBG_ERR("Short write, only %zd of %zu\n", nwritten, state->next_io_size);
+               tevent_req_nterror(req, NT_STATUS_IO_DEVICE_ERROR);
+               return;
+       }
+
+       state->dst_off += nwritten;
+
+       if (state->remaining < nwritten) {
+               /* Paranoia check */
+               tevent_req_nterror(req, NT_STATUS_INTERNAL_ERROR);
+               return;
+       }
+       state->remaining -= nwritten;
+       if (state->remaining == 0) {
+               tevent_req_done(req);
+               return;
+       }
+
+       status = copy_chunk_loop(req);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+
+       return;
+}
+
+static NTSTATUS vfswrap_copy_chunk_recv(struct vfs_handle_struct *handle,
+                                       struct tevent_req *req,
+                                       off_t *copied)
+{
+       struct vfs_cc_state *state = tevent_req_data(req, struct vfs_cc_state);
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               DBG_DEBUG("copy chunk failed: %s\n", nt_errstr(status));
+               *copied = 0;
+               tevent_req_received(req);
+               return status;
+       }
+
+       *copied = state->to_copy;
+       DBG_DEBUG("copy chunk copied %lu\n", (unsigned long)*copied);
+       tevent_req_received(req);
+
+       return NT_STATUS_OK;
+}
+
+static NTSTATUS vfswrap_get_compression(struct vfs_handle_struct *handle,
+                                       TALLOC_CTX *mem_ctx,
+                                       struct files_struct *fsp,
+                                       struct smb_filename *smb_fname,
+                                       uint16_t *_compression_fmt)
+{
+       return NT_STATUS_INVALID_DEVICE_REQUEST;
+}
+
+static NTSTATUS vfswrap_set_compression(struct vfs_handle_struct *handle,
+                                       TALLOC_CTX *mem_ctx,
+                                       struct files_struct *fsp,
+                                       uint16_t compression_fmt)
+{
+       return NT_STATUS_INVALID_DEVICE_REQUEST;
+}
+
 /********************************************************************
  Given a stat buffer return the allocated size on disk, taking into
  account sparse files.
@@ -1338,6 +1923,18 @@ static uint64_t vfswrap_get_alloc_size(vfs_handle_struct *handle,
 #else
 #error SIZEOF_BLKCNT_T_NOT_A_SUPPORTED_VALUE
 #endif
+       if (result == 0) {
+               /*
+                * Some file systems do not allocate a block for very
+                * small files. But for non-empty file should report a
+                * positive size.
+                */
+
+               uint64_t filesize = get_file_size_stat(sbuf);
+               if (filesize > 0) {
+                       result = MIN((uint64_t)STAT_ST_BLOCKSIZE, filesize);
+               }
+       }
 #else
        result = get_file_size_stat(sbuf);
 #endif
@@ -1370,7 +1967,9 @@ static int vfswrap_unlink(vfs_handle_struct *handle,
        return result;
 }
 
-static int vfswrap_chmod(vfs_handle_struct *handle,  const char *path, mode_t mode)
+static int vfswrap_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
 
@@ -1385,7 +1984,10 @@ static int vfswrap_chmod(vfs_handle_struct *handle,  const char *path, mode_t mo
 
        {
                int saved_errno = errno; /* We might get ENOSYS */
-               if ((result = SMB_VFS_CHMOD_ACL(handle->conn, path, mode)) == 0) {
+               result = SMB_VFS_CHMOD_ACL(handle->conn,
+                               smb_fname,
+                               mode);
+               if (result == 0) {
                        END_PROFILE(syscall_chmod);
                        return result;
                }
@@ -1393,7 +1995,7 @@ static int vfswrap_chmod(vfs_handle_struct *handle,  const char *path, mode_t mo
                errno = saved_errno;
        }
 
-       result = chmod(path, mode);
+       result = chmod(smb_fname->base_name, mode);
        END_PROFILE(syscall_chmod);
        return result;
 }
@@ -1431,12 +2033,15 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t m
        return result;
 }
 
-static int vfswrap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
+static int vfswrap_chown(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uid_t uid,
+                       gid_t gid)
 {
        int result;
 
        START_PROFILE(syscall_chown);
-       result = chown(path, uid, gid);
+       result = chown(smb_fname->base_name, uid, gid);
        END_PROFILE(syscall_chown);
        return result;
 }
@@ -1456,17 +2061,20 @@ static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, uid_t ui
 #endif
 }
 
-static int vfswrap_lchown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
+static int vfswrap_lchown(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uid_t uid,
+                       gid_t gid)
 {
        int result;
 
        START_PROFILE(syscall_lchown);
-       result = lchown(path, uid, gid);
+       result = lchown(smb_fname->base_name, uid, gid);
        END_PROFILE(syscall_lchown);
        return result;
 }
 
-static int vfswrap_chdir(vfs_handle_struct *handle,  const char *path)
+static int vfswrap_chdir(vfs_handle_struct *handle, const char *path)
 {
        int result;
 
@@ -1613,22 +2221,19 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
           emulation is being done by the libc (like on AIX with JFS1). In that
           case we do our own emulation. fallocate implementations can
           return ENOTSUP or EINVAL in cases like that. */
-       ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_EXTEND_SIZE,
-                               pst->st_ex_size, space_to_write);
-       if (ret == ENOSPC) {
-               errno = ENOSPC;
+       ret = SMB_VFS_FALLOCATE(fsp, 0, pst->st_ex_size, space_to_write);
+       if (ret == -1 && errno == ENOSPC) {
                return -1;
        }
        if (ret == 0) {
                return 0;
        }
        DEBUG(10,("strict_allocate_ftruncate: SMB_VFS_FALLOCATE failed with "
-               "error %d. Falling back to slow manual allocation\n", ret));
+               "error %d. Falling back to slow manual allocation\n", errno));
 
        /* available disk space is enough or not? */
-       space_avail = get_dfree_info(fsp->conn,
-                                    fsp->fsp_name->base_name, false,
-                                    &bsize,&dfree,&dsize);
+       space_avail =
+           get_dfree_info(fsp->conn, fsp->fsp_name, &bsize, &dfree, &dsize);
        /* space_avail is 1k blocks */
        if (space_avail == (uint64_t)-1 ||
                        ((uint64_t)space_to_write/1024 > space_avail) ) {
@@ -1639,8 +2244,7 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
        /* Write out the real space on disk. */
        ret = vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
        if (ret != 0) {
-               errno = ret;
-               ret = -1;
+               return -1;
        }
 
        return 0;
@@ -1668,8 +2272,6 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, off_t
           ftruncate extend but ext2 can. */
 
        result = ftruncate(fsp->fh->fd, len);
-       if (result == 0)
-               goto done;
 
        /* According to W. R. Stevens advanced UNIX prog. Pure 4.3 BSD cannot
           extend a file with ftruncate. Provide alternate implementation
@@ -1683,6 +2285,12 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, off_t
        if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
+
+       /* We need to update the files_struct after successful ftruncate */
+       if (result == 0) {
+               goto done;
+       }
+
        pst = &fsp->fsp_name->st;
 
 #ifdef S_ISFIFO
@@ -1716,20 +2324,27 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, off_t
 
 static int vfswrap_fallocate(vfs_handle_struct *handle,
                        files_struct *fsp,
-                       enum vfs_fallocate_mode mode,
+                       uint32_t mode,
                        off_t offset,
                        off_t len)
 {
        int result;
 
        START_PROFILE(syscall_fallocate);
-       if (mode == VFS_FALLOCATE_EXTEND_SIZE) {
+       if (mode == 0) {
                result = sys_posix_fallocate(fsp->fh->fd, offset, len);
-       } else if (mode == VFS_FALLOCATE_KEEP_SIZE) {
-               result = sys_fallocate(fsp->fh->fd, mode, offset, len);
+               /*
+                * posix_fallocate returns 0 on success, errno on error
+                * and doesn't set errno. Make it behave like fallocate()
+                * which returns -1, and sets errno on failure.
+                */
+               if (result != 0) {
+                       errno = result;
+                       result = -1;
+               }
        } else {
-               errno = EINVAL;
-               result = -1;
+               /* sys_fallocate handles filtering of unsupported mode flags */
+               result = sys_fallocate(fsp->fh->fd, mode, offset, len);
        }
        END_PROFILE(syscall_fallocate);
        return result;
@@ -1740,13 +2355,21 @@ static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, o
        bool result;
 
        START_PROFILE(syscall_fcntl_lock);
+
+       if (fsp->use_ofd_locks || !lp_parm_bool(SNUM(fsp->conn),
+                                               "smbd",
+                                               "force process locks",
+                                               false)) {
+               op = map_process_lock_to_ofd_lock(op, &fsp->use_ofd_locks);
+       }
+
        result =  fcntl_lock(fsp->fh->fd, op, offset, count, type);
        END_PROFILE(syscall_fcntl_lock);
        return result;
 }
 
 static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
-                               uint32 share_mode, uint32 access_mask)
+                               uint32_t share_mode, uint32_t access_mask)
 {
        START_PROFILE(syscall_kernel_flock);
        kernel_flock(fsp->fh->fd, share_mode, access_mask);
@@ -1757,9 +2380,18 @@ static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
 static bool vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, off_t *poffset, off_t *pcount, int *ptype, pid_t *ppid)
 {
        bool result;
+       int op = F_GETLK;
 
        START_PROFILE(syscall_fcntl_getlock);
-       result =  fcntl_getlock(fsp->fh->fd, poffset, pcount, ptype, ppid);
+
+       if (fsp->use_ofd_locks || !lp_parm_bool(SNUM(fsp->conn),
+                                               "smbd",
+                                               "force process locks",
+                                               false)) {
+               op = map_process_lock_to_ofd_lock(op, &fsp->use_ofd_locks);
+       }
+
+       result = fcntl_getlock(fsp->fh->fd, op, poffset, pcount, ptype, ppid);
        END_PROFILE(syscall_fcntl_getlock);
        return result;
 }
@@ -1780,7 +2412,7 @@ static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
        return result;
 }
 
-static int vfswrap_symlink(vfs_handle_struct *handle,  const char *oldpath, const char *newpath)
+static int vfswrap_symlink(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
 {
        int result;
 
@@ -1790,7 +2422,7 @@ static int vfswrap_symlink(vfs_handle_struct *handle,  const char *oldpath, cons
        return result;
 }
 
-static int vfswrap_readlink(vfs_handle_struct *handle,  const char *path, char *buf, size_t bufsiz)
+static int vfswrap_readlink(vfs_handle_struct *handle, const char *path, char *buf, size_t bufsiz)
 {
        int result;
 
@@ -1800,7 +2432,7 @@ static int vfswrap_readlink(vfs_handle_struct *handle,  const char *path, char *
        return result;
 }
 
-static int vfswrap_link(vfs_handle_struct *handle,  const char *oldpath, const char *newpath)
+static int vfswrap_link(vfs_handle_struct *handle, const char *oldpath, const char *newpath)
 {
        int result;
 
@@ -1810,7 +2442,7 @@ static int vfswrap_link(vfs_handle_struct *handle,  const char *oldpath, const c
        return result;
 }
 
-static int vfswrap_mknod(vfs_handle_struct *handle,  const char *pathname, mode_t mode, SMB_DEV_T dev)
+static int vfswrap_mknod(vfs_handle_struct *handle, const char *pathname, mode_t mode, SMB_DEV_T dev)
 {
        int result;
 
@@ -1820,59 +2452,16 @@ static int vfswrap_mknod(vfs_handle_struct *handle,  const char *pathname, mode_
        return result;
 }
 
-static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path)
+static char *vfswrap_realpath(vfs_handle_struct *handle, const char *path)
 {
        char *result;
 
        START_PROFILE(syscall_realpath);
-#ifdef REALPATH_TAKES_NULL
-       result = realpath(path, NULL);
-#else
-       result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
-       if (result) {
-               char *resolved_path = realpath(path, result);
-               if (!resolved_path) {
-                       SAFE_FREE(result);
-               } else {
-                       /* SMB_ASSERT(result == resolved_path) ? */
-                       result = resolved_path;
-               }
-       }
-#endif
+       result = sys_realpath(path);
        END_PROFILE(syscall_realpath);
        return result;
 }
 
-static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle,
-                                    struct sys_notify_context *ctx,
-                                    const char *path,
-                                    uint32_t *filter,
-                                    uint32_t *subdir_filter,
-                                    void (*callback)(struct sys_notify_context *ctx, 
-                                                     void *private_data,
-                                                     struct notify_event *ev),
-                                    void *private_data, void *handle)
-{
-       /*
-        * So far inotify is the only supported default notify mechanism. If
-        * another platform like the the BSD's or a proprietary Unix comes
-        * along and wants another default, we can play the same trick we
-        * played with Posix ACLs.
-        *
-        * Until that is the case, hard-code inotify here.
-        */
-#ifdef HAVE_INOTIFY
-       if (lp_kernel_change_notify(vfs_handle->conn->params)) {
-               return inotify_watch(ctx, path, filter, subdir_filter,
-                                    callback, private_data, handle);
-       }
-#endif
-       /*
-        * Do nothing, leave everything to notify_internal.c
-        */
-       return NT_STATUS_OK;
-}
-
 static int vfswrap_chflags(vfs_handle_struct *handle, const char *path,
                           unsigned int flags)
 {
@@ -1902,7 +2491,7 @@ static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle,
 
 static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
                                   struct files_struct *fsp,
-                                  const char *fname,
+                                  const struct smb_filename *smb_fname,
                                   TALLOC_CTX *mem_ctx,
                                   unsigned int *pnum_streams,
                                   struct stream_struct **pstreams)
@@ -1922,17 +2511,19 @@ static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
                ret = SMB_VFS_FSTAT(fsp, &sbuf);
        }
        else {
-               struct smb_filename smb_fname;
+               struct smb_filename smb_fname_cp;
 
-               ZERO_STRUCT(smb_fname);
-               smb_fname.base_name = discard_const_p(char, fname);
+               ZERO_STRUCT(smb_fname_cp);
+               smb_fname_cp.base_name = discard_const_p(char,
+                                       smb_fname->base_name);
+               smb_fname_cp.flags = smb_fname->flags;
 
-               if (lp_posix_pathnames()) {
-                       ret = SMB_VFS_LSTAT(handle->conn, &smb_fname);
+               if (smb_fname_cp.flags & SMB_FILENAME_POSIX_PATH) {
+                       ret = SMB_VFS_LSTAT(handle->conn, &smb_fname_cp);
                } else {
-                       ret = SMB_VFS_STAT(handle->conn, &smb_fname);
+                       ret = SMB_VFS_STAT(handle->conn, &smb_fname_cp);
                }
-               sbuf = smb_fname.st;
+               sbuf = smb_fname_cp.st;
        }
 
        if (ret == -1) {
@@ -1984,8 +2575,7 @@ static const char *vfswrap_connectpath(struct vfs_handle_struct *handle,
 static NTSTATUS vfswrap_brl_lock_windows(struct vfs_handle_struct *handle,
                                         struct byte_range_lock *br_lck,
                                         struct lock_struct *plock,
-                                        bool blocking_lock,
-                                        struct blocking_lock_record *blr)
+                                        bool blocking_lock)
 {
        SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
 
@@ -2005,8 +2595,7 @@ static bool vfswrap_brl_unlock_windows(struct vfs_handle_struct *handle,
 
 static bool vfswrap_brl_cancel_windows(struct vfs_handle_struct *handle,
                                       struct byte_range_lock *br_lck,
-                                      struct lock_struct *plock,
-                                      struct blocking_lock_record *blr)
+                                      struct lock_struct *plock)
 {
        SMB_ASSERT(plock->lock_flav == WINDOWS_LOCK);
 
@@ -2038,7 +2627,7 @@ static void vfswrap_strict_unlock(struct vfs_handle_struct *handle,
 
 static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
                                    files_struct *fsp,
-                                   uint32 security_info,
+                                   uint32_t security_info,
                                    TALLOC_CTX *mem_ctx,
                                    struct security_descriptor **ppdesc)
 {
@@ -2052,21 +2641,24 @@ static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
 }
 
 static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
-                                  const char *name,
-                                  uint32 security_info,
+                                  const struct smb_filename *smb_fname,
+                                  uint32_t security_info,
                                   TALLOC_CTX *mem_ctx,
                                   struct security_descriptor **ppdesc)
 {
        NTSTATUS result;
 
        START_PROFILE(get_nt_acl);
-       result = posix_get_nt_acl(handle->conn, name, security_info,
-                                 mem_ctx, ppdesc);
+       result = posix_get_nt_acl(handle->conn,
+                               smb_fname,
+                               security_info,
+                               mem_ctx,
+                               ppdesc);
        END_PROFILE(get_nt_acl);
        return result;
 }
 
-static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
+static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32_t security_info_sent, const struct security_descriptor *psd)
 {
        NTSTATUS result;
 
@@ -2085,7 +2677,9 @@ static NTSTATUS vfswrap_audit_file(struct vfs_handle_struct *handle,
        return NT_STATUS_OK; /* Nothing to do here ... */
 }
 
-static int vfswrap_chmod_acl(vfs_handle_struct *handle,  const char *name, mode_t mode)
+static int vfswrap_chmod_acl(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               mode_t mode)
 {
 #ifdef HAVE_NO_ACL
        errno = ENOSYS;
@@ -2094,7 +2688,7 @@ static int vfswrap_chmod_acl(vfs_handle_struct *handle,  const char *name, mode_
        int result;
 
        START_PROFILE(chmod_acl);
-       result = chmod_acl(handle->conn, name, mode);
+       result = chmod_acl(handle->conn, smb_fname, mode);
        END_PROFILE(chmod_acl);
        return result;
 #endif
@@ -2116,11 +2710,11 @@ static int vfswrap_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, mode
 }
 
 static SMB_ACL_T vfswrap_sys_acl_get_file(vfs_handle_struct *handle,
-                                         const char *path_p,
+                                         const struct smb_filename *smb_fname,
                                          SMB_ACL_TYPE_T type,
                                          TALLOC_CTX *mem_ctx)
 {
-       return sys_acl_get_file(handle, path_p, type, mem_ctx);
+       return sys_acl_get_file(handle, smb_fname, type, mem_ctx);
 }
 
 static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle,
@@ -2130,7 +2724,7 @@ static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle,
        return sys_acl_get_fd(handle, fsp, mem_ctx);
 }
 
-static int vfswrap_sys_acl_set_file(vfs_handle_struct *handle,  const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
+static int vfswrap_sys_acl_set_file(vfs_handle_struct *handle, const char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl)
 {
        return sys_acl_set_file(handle, name, acltype, theacl);
 }
@@ -2140,9 +2734,10 @@ static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp,
        return sys_acl_set_fd(handle, fsp, theacl);
 }
 
-static int vfswrap_sys_acl_delete_def_file(vfs_handle_struct *handle,  const char *path)
+static int vfswrap_sys_acl_delete_def_file(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
 {
-       return sys_acl_delete_def_file(handle, path);
+       return sys_acl_delete_def_file(handle, smb_fname);
 }
 
 /****************************************************************
@@ -2226,16 +2821,6 @@ static bool vfswrap_is_offline(struct vfs_handle_struct *handle,
        return offline;
 }
 
-static int vfswrap_set_offline(struct vfs_handle_struct *handle,
-                              const struct smb_filename *fname)
-{
-       /* We don't know how to set offline bit by default, needs to be overriden in the vfs modules */
-#if defined(ENOTSUP)
-       errno = ENOTSUP;
-#endif
-       return -1;
-}
-
 static NTSTATUS vfswrap_durable_cookie(struct vfs_handle_struct *handle,
                                       struct files_struct *fsp,
                                       TALLOC_CTX *mem_ctx,
@@ -2279,12 +2864,16 @@ static struct vfs_fn_pointers vfs_default_fns = {
        .statvfs_fn = vfswrap_statvfs,
        .fs_capabilities_fn = vfswrap_fs_capabilities,
        .get_dfs_referrals_fn = vfswrap_get_dfs_referrals,
+       .snap_check_path_fn = vfswrap_snap_check_path,
+       .snap_create_fn = vfswrap_snap_create,
+       .snap_delete_fn = vfswrap_snap_delete,
 
        /* Directory operations */
 
        .opendir_fn = vfswrap_opendir,
        .fdopendir_fn = vfswrap_fdopendir,
        .readdir_fn = vfswrap_readdir,
+       .readdir_attr_fn = vfswrap_readdir_attr,
        .seekdir_fn = vfswrap_seekdir,
        .telldir_fn = vfswrap_telldir,
        .rewind_dir_fn = vfswrap_rewinddir,
@@ -2301,18 +2890,18 @@ static struct vfs_fn_pointers vfs_default_fns = {
        .read_fn = vfswrap_read,
        .pread_fn = vfswrap_pread,
        .pread_send_fn = vfswrap_pread_send,
-       .pread_recv_fn = vfswrap_asys_ssize_t_recv,
+       .pread_recv_fn = vfswrap_pread_recv,
        .write_fn = vfswrap_write,
        .pwrite_fn = vfswrap_pwrite,
        .pwrite_send_fn = vfswrap_pwrite_send,
-       .pwrite_recv_fn = vfswrap_asys_ssize_t_recv,
+       .pwrite_recv_fn = vfswrap_pwrite_recv,
        .lseek_fn = vfswrap_lseek,
        .sendfile_fn = vfswrap_sendfile,
        .recvfile_fn = vfswrap_recvfile,
        .rename_fn = vfswrap_rename,
        .fsync_fn = vfswrap_fsync,
        .fsync_send_fn = vfswrap_fsync_send,
-       .fsync_recv_fn = vfswrap_asys_int_recv,
+       .fsync_recv_fn = vfswrap_fsync_recv,
        .stat_fn = vfswrap_stat,
        .fstat_fn = vfswrap_fstat,
        .lstat_fn = vfswrap_lstat,
@@ -2337,7 +2926,6 @@ static struct vfs_fn_pointers vfs_default_fns = {
        .link_fn = vfswrap_link,
        .mknod_fn = vfswrap_mknod,
        .realpath_fn = vfswrap_realpath,
-       .notify_watch_fn = vfswrap_notify_watch,
        .chflags_fn = vfswrap_chflags,
        .file_id_create_fn = vfswrap_file_id_create,
        .streaminfo_fn = vfswrap_streaminfo,
@@ -2350,6 +2938,14 @@ static struct vfs_fn_pointers vfs_default_fns = {
        .strict_unlock_fn = vfswrap_strict_unlock,
        .translate_name_fn = vfswrap_translate_name,
        .fsctl_fn = vfswrap_fsctl,
+       .set_dos_attributes_fn = vfswrap_set_dos_attributes,
+       .fset_dos_attributes_fn = vfswrap_fset_dos_attributes,
+       .get_dos_attributes_fn = vfswrap_get_dos_attributes,
+       .fget_dos_attributes_fn = vfswrap_fget_dos_attributes,
+       .copy_chunk_send_fn = vfswrap_copy_chunk_send,
+       .copy_chunk_recv_fn = vfswrap_copy_chunk_recv,
+       .get_compression_fn = vfswrap_get_compression,
+       .set_compression_fn = vfswrap_set_compression,
 
        /* NT ACL operations. */
 
@@ -2384,18 +2980,14 @@ static struct vfs_fn_pointers vfs_default_fns = {
        /* aio operations */
        .aio_force_fn = vfswrap_aio_force,
 
-       /* offline operations */
-       .is_offline_fn = vfswrap_is_offline,
-       .set_offline_fn = vfswrap_set_offline,
-
        /* durable handle operations */
        .durable_cookie_fn = vfswrap_durable_cookie,
        .durable_disconnect_fn = vfswrap_durable_disconnect,
        .durable_reconnect_fn = vfswrap_durable_reconnect,
 };
 
-NTSTATUS vfs_default_init(void);
-NTSTATUS vfs_default_init(void)
+NTSTATUS vfs_default_init(TALLOC_CTX *);
+NTSTATUS vfs_default_init(TALLOC_CTX *ctx)
 {
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
                                DEFAULT_VFS_MODULE_NAME, &vfs_default_fns);