s3: smbd: Change open_streams_for_delete() to take a struct smb_filename *.
[samba.git] / source3 / smbd / vfs.c
index 2be6c54a8812c52ffad854b9f21eeb3a31de7843..a1154aee784d6b242534429a6b0207a59393b459 100644 (file)
 #include "system/filesys.h"
 #include "smbd/smbd.h"
 #include "smbd/globals.h"
-#include "memcache.h"
+#include "../lib/util/memcache.h"
 #include "transfer_file.h"
 #include "ntioctl.h"
+#include "lib/util/tevent_unix.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
 
 static_decl_vfs;
 
+struct vfs_fsp_data {
+    struct vfs_fsp_data *next;
+    struct vfs_handle_struct *owner;
+    void (*destroy)(void *p_data);
+    void *_dummy_;
+    /* NOTE: This structure contains four pointers so that we can guarantee
+     * that the end of the structure is always both 4-byte and 8-byte aligned.
+     */
+};
+
 struct vfs_init_function_entry {
        char *name;
        struct vfs_init_function_entry *prev, *next;
@@ -211,7 +222,7 @@ bool vfs_init_custom(connection_struct *conn, const char *vfs_object)
  be refactored if it becomes more widely used.
 ******************************************************************/
 
-#define EXT_DATA_AREA(e) ((uint8 *)(e) + sizeof(struct vfs_fsp_data))
+#define EXT_DATA_AREA(e) ((uint8_t *)(e) + sizeof(struct vfs_fsp_data))
 
 void *vfs_add_fsp_extension_notype(vfs_handle_struct *handle,
                                   files_struct *fsp, size_t ext_size,
@@ -261,6 +272,23 @@ void vfs_remove_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
        }
 }
 
+void vfs_remove_all_fsp_extensions(files_struct *fsp)
+{
+       struct vfs_fsp_data *curr;
+       struct vfs_fsp_data *next;
+
+       for (curr = fsp->vfs_extension; curr; curr = next) {
+
+               next = curr->next;
+               fsp->vfs_extension = next;
+
+               if (curr->destroy) {
+                       curr->destroy(EXT_DATA_AREA(curr));
+               }
+               TALLOC_FREE(curr);
+       }
+}
+
 void *vfs_memctx_fsp_extension(vfs_handle_struct *handle, files_struct *fsp)
 {
        struct vfs_fsp_data *head;
@@ -300,6 +328,12 @@ bool smbd_vfs_init(connection_struct *conn)
 
        /* Normal share - initialise with disk access functions */
        vfs_init_default(conn);
+
+       /* No need to load vfs modules for printer connections */
+       if (conn->printer) {
+               return True;
+       }
+
        vfs_objects = lp_vfs_objects(SNUM(conn));
 
        /* Override VFS functions if 'vfs object' was not specified*/
@@ -359,28 +393,6 @@ ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count)
        return (ssize_t)total;
 }
 
-ssize_t vfs_pread_data(files_struct *fsp, char *buf,
-                size_t byte_count, off_t offset)
-{
-       size_t total=0;
-
-       while (total < byte_count)
-       {
-               ssize_t ret = SMB_VFS_PREAD(fsp, buf + total,
-                                       byte_count - total, offset + total);
-
-               if (ret == 0) return total;
-               if (ret == -1) {
-                       if (errno == EINTR)
-                               continue;
-                       else
-                               return -1;
-               }
-               total += ret;
-       }
-       return (ssize_t)total;
-}
-
 /****************************************************************************
  Write data to a fd on the vfs.
 ****************************************************************************/
@@ -394,14 +406,25 @@ ssize_t vfs_write_data(struct smb_request *req,
        ssize_t ret;
 
        if (req && req->unread_bytes) {
+               int sockfd = req->xconn->transport.sock;
+               int old_flags;
                SMB_ASSERT(req->unread_bytes == N);
                /* VFS_RECVFILE must drain the socket
                 * before returning. */
                req->unread_bytes = 0;
-               return SMB_VFS_RECVFILE(req->sconn->sock,
+               /* Ensure the socket is blocking. */
+               old_flags = fcntl(sockfd, F_GETFL, 0);
+               if (set_blocking(sockfd, true) == -1) {
+                       return (ssize_t)-1;
+               }
+               ret = SMB_VFS_RECVFILE(sockfd,
                                        fsp,
                                        (off_t)-1,
                                        N);
+               if (fcntl(sockfd, F_SETFL, old_flags) == -1) {
+                       return (ssize_t)-1;
+               }
+               return ret;
        }
 
        while (total < N) {
@@ -427,14 +450,52 @@ ssize_t vfs_pwrite_data(struct smb_request *req,
        ssize_t ret;
 
        if (req && req->unread_bytes) {
+               int sockfd = req->xconn->transport.sock;
                SMB_ASSERT(req->unread_bytes == N);
                /* VFS_RECVFILE must drain the socket
                 * before returning. */
                req->unread_bytes = 0;
-               return SMB_VFS_RECVFILE(req->sconn->sock,
-                                       fsp,
-                                       offset,
-                                       N);
+               /*
+                * Leave the socket non-blocking and
+                * use SMB_VFS_RECVFILE. If it returns
+                * EAGAIN || EWOULDBLOCK temporarily set
+                * the socket blocking and retry
+                * the RECVFILE.
+                */
+               while (total < N) {
+                       ret = SMB_VFS_RECVFILE(sockfd,
+                                               fsp,
+                                               offset + total,
+                                               N - total);
+                       if (ret == 0 || (ret == -1 &&
+                                        (errno == EAGAIN ||
+                                         errno == EWOULDBLOCK))) {
+                               int old_flags;
+                               /* Ensure the socket is blocking. */
+                               old_flags = fcntl(sockfd, F_GETFL, 0);
+                               if (set_blocking(sockfd, true) == -1) {
+                                       return (ssize_t)-1;
+                               }
+                               ret = SMB_VFS_RECVFILE(sockfd,
+                                                       fsp,
+                                                       offset + total,
+                                                       N - total);
+                               if (fcntl(sockfd, F_SETFL, old_flags) == -1) {
+                                       return (ssize_t)-1;
+                               }
+                               if (ret == -1) {
+                                       return (ssize_t)-1;
+                               }
+                               total += ret;
+                               return (ssize_t)total;
+                       }
+                       /* Any other error case. */
+                       if (ret == -1) {
+                               return ret;
+                       }
+                       total += ret;
+               }
+               return (ssize_t)total;
        }
 
        while (total < N) {
@@ -495,7 +556,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
 
                contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_SHRINK);
 
-               flush_write_cache(fsp, SIZECHANGE_FLUSH);
+               flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
                if ((ret = SMB_VFS_FTRUNCATE(fsp, (off_t)len)) != -1) {
                        set_filelen_write_cache(fsp, len);
                }
@@ -505,16 +566,18 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
                return ret;
        }
 
-       if (!lp_strict_allocate(SNUM(fsp->conn)))
-               return 0;
-
        /* Grow - we need to test if we have enough space. */
 
        contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_ALLOC_GROW);
 
-       /* See if we have a syscall that will allocate beyond end-of-file
-          without changing EOF. */
-       ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_KEEP_SIZE, 0, len);
+       if (lp_strict_allocate(SNUM(fsp->conn))) {
+               /* See if we have a syscall that will allocate beyond
+                  end-of-file without changing EOF. */
+               ret = SMB_VFS_FALLOCATE(fsp, VFS_FALLOCATE_FL_KEEP_SIZE,
+                                       0, len);
+       } else {
+               ret = 0;
+       }
 
        contend_level2_oplocks_end(fsp, LEVEL2_CONTEND_ALLOC_GROW);
 
@@ -524,9 +587,13 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len)
                return 0;
        }
 
+       if (ret == -1 && errno == ENOSPC) {
+               return -1;
+       }
+
        len -= fsp->fsp_name->st.st_ex_size;
        len /= 1024; /* Len is now number of 1k blocks needed. */
-       space_avail = get_dfree_info(conn, fsp->fsp_name->base_name, false,
+       space_avail = get_dfree_info(conn, fsp->fsp_name->base_name,
                                     &bsize, &dfree, &dsize);
        if (space_avail == (uint64_t)-1) {
                return -1;
@@ -559,7 +626,7 @@ int vfs_set_filelen(files_struct *fsp, off_t len)
 
        DEBUG(10,("vfs_set_filelen: ftruncate %s to len %.0f\n",
                  fsp_str_dbg(fsp), (double)len));
-       flush_write_cache(fsp, SIZECHANGE_FLUSH);
+       flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
        if ((ret = SMB_VFS_FTRUNCATE(fsp, len)) != -1) {
                set_filelen_write_cache(fsp, len);
                notify_fname(fsp->conn, NOTIFY_ACTION_MODIFIED,
@@ -578,7 +645,7 @@ int vfs_set_filelen(files_struct *fsp, off_t len)
  fails. Needs to be outside of the default version of SMB_VFS_FALLOCATE
  as this is also called from the default SMB_VFS_FTRUNCATE code.
  Always extends the file size.
- Returns 0 on success, errno on failure.
+ Returns 0 on success, -1 on failure.
 ****************************************************************************/
 
 #define SPARSE_BUF_WRITE_SIZE (32*1024)
@@ -592,7 +659,7 @@ int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len)
                sparse_buf = SMB_CALLOC_ARRAY(char, SPARSE_BUF_WRITE_SIZE);
                if (!sparse_buf) {
                        errno = ENOMEM;
-                       return ENOMEM;
+                       return -1;
                }
        }
 
@@ -601,10 +668,12 @@ int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len)
 
                pwrite_ret = SMB_VFS_PWRITE(fsp, sparse_buf, curr_write_size, offset + total);
                if (pwrite_ret == -1) {
+                       int saved_errno = errno;
                        DEBUG(10,("vfs_slow_fallocate: SMB_VFS_PWRITE for file "
                                  "%s failed with error %s\n",
-                                 fsp_str_dbg(fsp), strerror(errno)));
-                       return errno;
+                                 fsp_str_dbg(fsp), strerror(saved_errno)));
+                       errno = saved_errno;
+                       return -1;
                }
                total += pwrite_ret;
        }
@@ -648,7 +717,7 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
 
        contend_level2_oplocks_begin(fsp, LEVEL2_CONTEND_FILL_SPARSE);
 
-       flush_write_cache(fsp, SIZECHANGE_FLUSH);
+       flush_write_cache(fsp, SAMBA_SIZECHANGE_FLUSH);
 
        offset = fsp->fsp_name->st.st_ex_size;
        num_to_write = len - fsp->fsp_name->st.st_ex_size;
@@ -660,11 +729,8 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
                 * 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,
-                               offset, num_to_write);
-               if (ret == ENOSPC) {
-                       errno = ENOSPC;
-                       ret = -1;
+               ret = SMB_VFS_FALLOCATE(fsp, 0, offset, num_to_write);
+               if (ret == -1 && errno == ENOSPC) {
                        goto out;
                }
                if (ret == 0) {
@@ -675,10 +741,6 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
        }
 
        ret = vfs_slow_fallocate(fsp, offset, num_to_write);
-       if (ret != 0) {
-               errno = ret;
-               ret = -1;
-       }
 
  out:
 
@@ -694,24 +756,24 @@ int vfs_fill_sparse(files_struct *fsp, off_t len)
  Transfer some data (n bytes) between two file_struct's.
 ****************************************************************************/
 
-static ssize_t vfs_read_fn(void *file, void *buf, size_t len)
+static ssize_t vfs_pread_fn(void *file, void *buf, size_t len, off_t offset)
 {
        struct files_struct *fsp = (struct files_struct *)file;
 
-       return SMB_VFS_READ(fsp, buf, len);
+       return SMB_VFS_PREAD(fsp, buf, len, offset);
 }
 
-static ssize_t vfs_write_fn(void *file, const void *buf, size_t len)
+static ssize_t vfs_pwrite_fn(void *file, const void *buf, size_t len, off_t offset)
 {
        struct files_struct *fsp = (struct files_struct *)file;
 
-       return SMB_VFS_WRITE(fsp, buf, len);
+       return SMB_VFS_PWRITE(fsp, buf, len, offset);
 }
 
 off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n)
 {
        return transfer_file_internal((void *)in, (void *)out, n,
-                                     vfs_read_fn, vfs_write_fn);
+                                     vfs_pread_fn, vfs_pwrite_fn);
 }
 
 /*******************************************************************
@@ -765,26 +827,34 @@ const char *vfs_readdirname(connection_struct *conn, void *p,
 
 int vfs_ChDir(connection_struct *conn, const char *path)
 {
-       int res;
+       int ret;
 
        if (!LastDir) {
                LastDir = SMB_STRDUP("");
        }
 
-       if (strcsequal(path,"."))
-               return(0);
+       if (ISDOT(path)) {
+               return 0;
+       }
 
-       if (*path == '/' && strcsequal(LastDir,path))
-               return(0);
+       if (*path == '/' && strcsequal(LastDir,path)) {
+               return 0;
+       }
 
        DEBUG(4,("vfs_ChDir to %s\n",path));
 
-       res = SMB_VFS_CHDIR(conn,path);
-       if (!res) {
+       ret = SMB_VFS_CHDIR(conn,path);
+       if (ret == 0) {
+               /* Global cache. */
                SAFE_FREE(LastDir);
                LastDir = SMB_STRDUP(path);
+
+               /* conn cache. */
+               TALLOC_FREE(conn->cwd);
+               conn->cwd = vfs_GetWd(conn, conn);
+               DEBUG(4,("vfs_ChDir got %s\n",conn->cwd));
        }
-       return(res);
+       return ret;
 }
 
 /*******************************************************************
@@ -801,16 +871,14 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
        struct file_id key;
        struct smb_filename *smb_fname_dot = NULL;
        struct smb_filename *smb_fname_full = NULL;
-       NTSTATUS status;
 
        if (!lp_getwd_cache()) {
                goto nocache;
        }
 
-       status = create_synthetic_smb_fname(ctx, ".", NULL, NULL,
-                                           &smb_fname_dot);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = map_errno_from_nt_status(status);
+       smb_fname_dot = synthetic_smb_fname(ctx, ".", NULL, NULL);
+       if (smb_fname_dot == NULL) {
+               errno = ENOMEM;
                goto out;
        }
 
@@ -835,10 +903,10 @@ char *vfs_GetWd(TALLOC_CTX *ctx, connection_struct *conn)
        SMB_ASSERT((cache_value.length > 0)
                   && (cache_value.data[cache_value.length-1] == '\0'));
 
-       status = create_synthetic_smb_fname(ctx, (char *)cache_value.data,
-                                           NULL, NULL, &smb_fname_full);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = map_errno_from_nt_status(status);
+       smb_fname_full = synthetic_smb_fname(ctx, (char *)cache_value.data,
+                                            NULL, NULL);
+       if (smb_fname_full == NULL) {
+               errno = ENOMEM;
                goto out;
        }
 
@@ -976,10 +1044,9 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
                resolved_name));
 
        /* Now check the stat value is the same. */
-       status = create_synthetic_smb_fname(talloc_tos(), ".",
-                                       NULL, NULL,
-                                       &smb_fname_cwd);
-       if (!NT_STATUS_IS_OK(status)) {
+       smb_fname_cwd = synthetic_smb_fname(talloc_tos(), ".", NULL, NULL);
+       if (smb_fname_cwd == NULL) {
+               status = NT_STATUS_NO_MEMORY;
                goto err;
        }
 
@@ -1009,15 +1076,32 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
        }
 
        rootdir_len = strlen(conn_rootdir);
-       if (strncmp(conn_rootdir, resolved_name, rootdir_len) != 0) {
-               DEBUG(2, ("check_reduced_name_with_privilege: Bad access "
-                       "attempt: %s is a symlink outside the "
-                       "share path\n",
-                       dir_name));
-               DEBUGADD(2, ("conn_rootdir =%s\n", conn_rootdir));
-               DEBUGADD(2, ("resolved_name=%s\n", resolved_name));
-               status = NT_STATUS_ACCESS_DENIED;
-               goto err;
+
+       /*
+        * In the case of rootdir_len == 1, we know that conn_rootdir is
+        * "/", and we also know that resolved_name starts with a slash.
+        * So, in this corner case, resolved_name is automatically a
+        * sub-directory of the conn_rootdir. Thus we can skip the string
+        * comparison and the next character checks (which are even
+        * wrong in this case).
+        */
+       if (rootdir_len != 1) {
+               bool matched;
+
+               matched = (strncmp(conn_rootdir, resolved_name,
+                               rootdir_len) == 0);
+
+               if (!matched || (resolved_name[rootdir_len] != '/' &&
+                                resolved_name[rootdir_len] != '\0')) {
+                       DEBUG(2, ("check_reduced_name_with_privilege: Bad "
+                               "access attempt: %s is a symlink outside the "
+                               "share path\n",
+                               dir_name));
+                       DEBUGADD(2, ("conn_rootdir =%s\n", conn_rootdir));
+                       DEBUGADD(2, ("resolved_name=%s\n", resolved_name));
+                       status = NT_STATUS_ACCESS_DENIED;
+                       goto err;
+               }
        }
 
        /* Now ensure that the last component either doesn't
@@ -1058,6 +1142,7 @@ NTSTATUS check_reduced_name_with_privilege(connection_struct *conn,
        if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(priv_paths);
        }
+       TALLOC_FREE(dir_name);
        return status;
 }
 
@@ -1072,7 +1157,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
        bool allow_symlinks = true;
        bool allow_widelinks = false;
 
-       DEBUG(3,("check_reduced_name [%s] [%s]\n", fname, conn->connectpath));
+       DBG_DEBUG("check_reduced_name [%s] [%s]\n", fname, conn->connectpath);
 
        resolved_name = SMB_VFS_REALPATH(conn,fname);
 
@@ -1142,7 +1227,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
        }
 
        allow_widelinks = lp_widelinks(SNUM(conn));
-       allow_symlinks = lp_symlinks(SNUM(conn));
+       allow_symlinks = lp_follow_symlinks(SNUM(conn));
 
        /* Common widelinks and symlinks checks. */
        if (!allow_widelinks || !allow_symlinks) {
@@ -1158,15 +1243,33 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                }
 
                rootdir_len = strlen(conn_rootdir);
-               if (strncmp(conn_rootdir, resolved_name,
-                               rootdir_len) != 0) {
-                       DEBUG(2, ("check_reduced_name: Bad access "
-                               "attempt: %s is a symlink outside the "
-                               "share path\n", fname));
-                       DEBUGADD(2, ("conn_rootdir =%s\n", conn_rootdir));
-                       DEBUGADD(2, ("resolved_name=%s\n", resolved_name));
-                       SAFE_FREE(resolved_name);
-                       return NT_STATUS_ACCESS_DENIED;
+
+               /*
+                * In the case of rootdir_len == 1, we know that
+                * conn_rootdir is "/", and we also know that
+                * resolved_name starts with a slash.  So, in this
+                * corner case, resolved_name is automatically a
+                * sub-directory of the conn_rootdir. Thus we can skip
+                * the string comparison and the next character checks
+                * (which are even wrong in this case).
+                */
+               if (rootdir_len != 1) {
+                       bool matched;
+
+                       matched = (strncmp(conn_rootdir, resolved_name,
+                                       rootdir_len) == 0);
+                       if (!matched || (resolved_name[rootdir_len] != '/' &&
+                                        resolved_name[rootdir_len] != '\0')) {
+                               DEBUG(2, ("check_reduced_name: Bad access "
+                                       "attempt: %s is a symlink outside the "
+                                       "share path\n", fname));
+                               DEBUGADD(2, ("conn_rootdir =%s\n",
+                                            conn_rootdir));
+                               DEBUGADD(2, ("resolved_name=%s\n",
+                                            resolved_name));
+                               SAFE_FREE(resolved_name);
+                               return NT_STATUS_ACCESS_DENIED;
+                       }
                }
 
                /* Extra checks if all symlinks are disallowed. */
@@ -1191,8 +1294,8 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
                        p++;
                        if (strcmp(fname, p)!=0) {
                                DEBUG(2, ("check_reduced_name: Bad access "
-                                       "attempt: %s is a symlink\n",
-                                       fname));
+                                       "attempt: %s is a symlink to %s\n",
+                                         fname, p));
                                SAFE_FREE(resolved_name);
                                return NT_STATUS_ACCESS_DENIED;
                        }
@@ -1201,8 +1304,7 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
 
   out:
 
-       DEBUG(3,("check_reduced_name: %s reduced to %s\n", fname,
-                resolved_name));
+       DBG_INFO("%s reduced to %s\n", fname, resolved_name);
        SAFE_FREE(resolved_name);
        return NT_STATUS_OK;
 }
@@ -1210,59 +1312,26 @@ NTSTATUS check_reduced_name(connection_struct *conn, const char *fname)
 /**
  * XXX: This is temporary and there should be no callers of this once
  * smb_filename is plumbed through all path based operations.
+ *
+ * Called when we know stream name parsing has already been done.
  */
-int vfs_stat_smb_fname(struct connection_struct *conn, const char *fname,
+int vfs_stat_smb_basename(struct connection_struct *conn, const char *fname,
                       SMB_STRUCT_STAT *psbuf)
 {
-       struct smb_filename *smb_fname = NULL;
-       NTSTATUS status;
+       struct smb_filename smb_fname = {
+                       .base_name = discard_const_p(char, fname)
+       };
        int ret;
 
-       status = create_synthetic_smb_fname_split(talloc_tos(), fname, NULL,
-                                                 &smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = map_errno_from_nt_status(status);
-               return -1;
-       }
-
        if (lp_posix_pathnames()) {
-               ret = SMB_VFS_LSTAT(conn, smb_fname);
+               ret = SMB_VFS_LSTAT(conn, &smb_fname);
        } else {
-               ret = SMB_VFS_STAT(conn, smb_fname);
-       }
-
-       if (ret != -1) {
-               *psbuf = smb_fname->st;
-       }
-
-       TALLOC_FREE(smb_fname);
-       return ret;
-}
-
-/**
- * XXX: This is temporary and there should be no callers of this once
- * smb_filename is plumbed through all path based operations.
- */
-int vfs_lstat_smb_fname(struct connection_struct *conn, const char *fname,
-                       SMB_STRUCT_STAT *psbuf)
-{
-       struct smb_filename *smb_fname = NULL;
-       NTSTATUS status;
-       int ret;
-
-       status = create_synthetic_smb_fname_split(talloc_tos(), fname, NULL,
-                                                 &smb_fname);
-       if (!NT_STATUS_IS_OK(status)) {
-               errno = map_errno_from_nt_status(status);
-               return -1;
+               ret = SMB_VFS_STAT(conn, &smb_fname);
        }
 
-       ret = SMB_VFS_LSTAT(conn, smb_fname);
        if (ret != -1) {
-               *psbuf = smb_fname->st;
+               *psbuf = smb_fname.st;
        }
-
-       TALLOC_FREE(smb_fname);
        return ret;
 }
 
@@ -1275,7 +1344,7 @@ NTSTATUS vfs_stat_fsp(files_struct *fsp)
        int ret;
 
        if(fsp->fh->fd == -1) {
-               if (fsp->posix_open) {
+               if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
                        ret = SMB_VFS_LSTAT(fsp->conn, fsp->fsp_name);
                } else {
                        ret = SMB_VFS_STAT(fsp->conn, fsp->fsp_name);
@@ -1296,14 +1365,19 @@ NTSTATUS vfs_stat_fsp(files_struct *fsp)
  */
 NTSTATUS vfs_streaminfo(connection_struct *conn,
                        struct files_struct *fsp,
-                       const char *fname,
+                       const struct smb_filename *smb_fname,
                        TALLOC_CTX *mem_ctx,
                        unsigned int *num_streams,
                        struct stream_struct **streams)
 {
        *num_streams = 0;
        *streams = NULL;
-       return SMB_VFS_STREAMINFO(conn, fsp, fname, mem_ctx, num_streams, streams);
+       return SMB_VFS_STREAMINFO(conn,
+                       fsp,
+                       smb_fname,
+                       mem_ctx,
+                       num_streams,
+                       streams);
 }
 
 /*
@@ -1328,21 +1402,19 @@ void smb_vfs_call_disconnect(struct vfs_handle_struct *handle)
 }
 
 uint64_t smb_vfs_call_disk_free(struct vfs_handle_struct *handle,
-                               const char *path, bool small_query,
-                               uint64_t *bsize, uint64_t *dfree,
-                               uint64_t *dsize)
+                               const char *path, uint64_t *bsize,
+                               uint64_t *dfree, uint64_t *dsize)
 {
        VFS_FIND(disk_free);
-       return handle->fns->disk_free_fn(handle, path, small_query, bsize, 
-                                        dfree, dsize);
+       return handle->fns->disk_free_fn(handle, path, bsize, dfree, dsize);
 }
 
-int smb_vfs_call_get_quota(struct vfs_handle_struct *handle,
+int smb_vfs_call_get_quota(struct vfs_handle_struct *handle, const char *path,
                           enum SMB_QUOTA_TYPE qtype, unid_t id,
                           SMB_DISK_QUOTA *qt)
 {
        VFS_FIND(get_quota);
-       return handle->fns->get_quota_fn(handle, qtype, id, qt);
+       return handle->fns->get_quota_fn(handle, path, qtype, id, qt);
 }
 
 int smb_vfs_call_set_quota(struct vfs_handle_struct *handle,
@@ -1385,17 +1457,18 @@ NTSTATUS smb_vfs_call_get_dfs_referrals(struct vfs_handle_struct *handle,
 }
 
 DIR *smb_vfs_call_opendir(struct vfs_handle_struct *handle,
-                                    const char *fname, const char *mask,
-                                    uint32 attributes)
+                                       const struct smb_filename *smb_fname,
+                                       const char *mask,
+                                       uint32_t attributes)
 {
        VFS_FIND(opendir);
-       return handle->fns->opendir_fn(handle, fname, mask, attributes);
+       return handle->fns->opendir_fn(handle, smb_fname, mask, attributes);
 }
 
 DIR *smb_vfs_call_fdopendir(struct vfs_handle_struct *handle,
                                        struct files_struct *fsp,
                                        const char *mask,
-                                       uint32 attributes)
+                                       uint32_t attributes)
 {
        VFS_FIND(fdopendir);
        return handle->fns->fdopendir_fn(handle, fsp, mask, attributes);
@@ -1430,17 +1503,19 @@ void smb_vfs_call_rewind_dir(struct vfs_handle_struct *handle,
        handle->fns->rewind_dir_fn(handle, dirp);
 }
 
-int smb_vfs_call_mkdir(struct vfs_handle_struct *handle, const char *path,
-                      mode_t mode)
+int smb_vfs_call_mkdir(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        VFS_FIND(mkdir);
-       return handle->fns->mkdir_fn(handle, path, mode);
+       return handle->fns->mkdir_fn(handle, smb_fname, mode);
 }
 
-int smb_vfs_call_rmdir(struct vfs_handle_struct *handle, const char *path)
+int smb_vfs_call_rmdir(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
 {
        VFS_FIND(rmdir);
-       return handle->fns->rmdir_fn(handle, path);
+       return handle->fns->rmdir_fn(handle, smb_fname);
 }
 
 int smb_vfs_call_closedir(struct vfs_handle_struct *handle,
@@ -1475,20 +1550,23 @@ NTSTATUS smb_vfs_call_create_file(struct 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)
 {
        VFS_FIND(create_file);
        return handle->fns->create_file_fn(
                handle, req, root_dir_fid, smb_fname, access_mask,
                share_access, create_disposition, create_options,
-               file_attributes, oplock_request, allocation_size,
+               file_attributes, oplock_request, lease, allocation_size,
                private_flags, sd, ea_list,
-               result, pinfo);
+               result, pinfo, in_context_blobs, out_context_blobs);
 }
 
 int smb_vfs_call_close(struct vfs_handle_struct *handle,
@@ -1513,6 +1591,70 @@ ssize_t smb_vfs_call_pread(struct vfs_handle_struct *handle,
        return handle->fns->pread_fn(handle, fsp, data, n, offset);
 }
 
+struct smb_vfs_call_pread_state {
+       ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
+       ssize_t retval;
+       struct vfs_aio_state vfs_aio_state;
+};
+
+static void smb_vfs_call_pread_done(struct tevent_req *subreq);
+
+struct tevent_req *smb_vfs_call_pread_send(struct vfs_handle_struct *handle,
+                                          TALLOC_CTX *mem_ctx,
+                                          struct tevent_context *ev,
+                                          struct files_struct *fsp,
+                                          void *data,
+                                          size_t n, off_t offset)
+{
+       struct tevent_req *req, *subreq;
+       struct smb_vfs_call_pread_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct smb_vfs_call_pread_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       VFS_FIND(pread_send);
+       state->recv_fn = handle->fns->pread_recv_fn;
+
+       subreq = handle->fns->pread_send_fn(handle, state, ev, fsp, data, n,
+                                           offset);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, smb_vfs_call_pread_done, req);
+       return req;
+}
+
+static void smb_vfs_call_pread_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct smb_vfs_call_pread_state *state = tevent_req_data(
+               req, struct smb_vfs_call_pread_state);
+
+       state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
+       TALLOC_FREE(subreq);
+       if (state->retval == -1) {
+               tevent_req_error(req, state->vfs_aio_state.error);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+ssize_t SMB_VFS_PREAD_RECV(struct tevent_req *req,
+                          struct vfs_aio_state *vfs_aio_state)
+{
+       struct smb_vfs_call_pread_state *state = tevent_req_data(
+               req, struct smb_vfs_call_pread_state);
+
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
+               return -1;
+       }
+       *vfs_aio_state = state->vfs_aio_state;
+       return state->retval;
+}
+
 ssize_t smb_vfs_call_write(struct vfs_handle_struct *handle,
                           struct files_struct *fsp, const void *data,
                           size_t n)
@@ -1529,6 +1671,70 @@ ssize_t smb_vfs_call_pwrite(struct vfs_handle_struct *handle,
        return handle->fns->pwrite_fn(handle, fsp, data, n, offset);
 }
 
+struct smb_vfs_call_pwrite_state {
+       ssize_t (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
+       ssize_t retval;
+       struct vfs_aio_state vfs_aio_state;
+};
+
+static void smb_vfs_call_pwrite_done(struct tevent_req *subreq);
+
+struct tevent_req *smb_vfs_call_pwrite_send(struct vfs_handle_struct *handle,
+                                           TALLOC_CTX *mem_ctx,
+                                           struct tevent_context *ev,
+                                           struct files_struct *fsp,
+                                           const void *data,
+                                           size_t n, off_t offset)
+{
+       struct tevent_req *req, *subreq;
+       struct smb_vfs_call_pwrite_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct smb_vfs_call_pwrite_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       VFS_FIND(pwrite_send);
+       state->recv_fn = handle->fns->pwrite_recv_fn;
+
+       subreq = handle->fns->pwrite_send_fn(handle, state, ev, fsp, data, n,
+                                            offset);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, smb_vfs_call_pwrite_done, req);
+       return req;
+}
+
+static void smb_vfs_call_pwrite_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct smb_vfs_call_pwrite_state *state = tevent_req_data(
+               req, struct smb_vfs_call_pwrite_state);
+
+       state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
+       TALLOC_FREE(subreq);
+       if (state->retval == -1) {
+               tevent_req_error(req, state->vfs_aio_state.error);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+ssize_t SMB_VFS_PWRITE_RECV(struct tevent_req *req,
+                           struct vfs_aio_state *vfs_aio_state)
+{
+       struct smb_vfs_call_pwrite_state *state = tevent_req_data(
+               req, struct smb_vfs_call_pwrite_state);
+
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
+               return -1;
+       }
+       *vfs_aio_state = state->vfs_aio_state;
+       return state->retval;
+}
+
 off_t smb_vfs_call_lseek(struct vfs_handle_struct *handle,
                             struct files_struct *fsp, off_t offset,
                             int whence)
@@ -1569,6 +1775,67 @@ int smb_vfs_call_fsync(struct vfs_handle_struct *handle,
        return handle->fns->fsync_fn(handle, fsp);
 }
 
+struct smb_vfs_call_fsync_state {
+       int (*recv_fn)(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state);
+       int retval;
+       struct vfs_aio_state vfs_aio_state;
+};
+
+static void smb_vfs_call_fsync_done(struct tevent_req *subreq);
+
+struct tevent_req *smb_vfs_call_fsync_send(struct vfs_handle_struct *handle,
+                                          TALLOC_CTX *mem_ctx,
+                                          struct tevent_context *ev,
+                                          struct files_struct *fsp)
+{
+       struct tevent_req *req, *subreq;
+       struct smb_vfs_call_fsync_state *state;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct smb_vfs_call_fsync_state);
+       if (req == NULL) {
+               return NULL;
+       }
+       VFS_FIND(fsync_send);
+       state->recv_fn = handle->fns->fsync_recv_fn;
+
+       subreq = handle->fns->fsync_send_fn(handle, state, ev, fsp);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, smb_vfs_call_fsync_done, req);
+       return req;
+}
+
+static void smb_vfs_call_fsync_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct smb_vfs_call_fsync_state *state = tevent_req_data(
+               req, struct smb_vfs_call_fsync_state);
+
+       state->retval = state->recv_fn(subreq, &state->vfs_aio_state);
+       TALLOC_FREE(subreq);
+       if (state->retval == -1) {
+               tevent_req_error(req, state->vfs_aio_state.error);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+int SMB_VFS_FSYNC_RECV(struct tevent_req *req, struct vfs_aio_state *vfs_aio_state)
+{
+       struct smb_vfs_call_fsync_state *state = tevent_req_data(
+               req, struct smb_vfs_call_fsync_state);
+
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
+               return -1;
+       }
+       *vfs_aio_state = state->vfs_aio_state;
+       return state->retval;
+}
+
+
 int smb_vfs_call_stat(struct vfs_handle_struct *handle,
                      struct smb_filename *smb_fname)
 {
@@ -1605,11 +1872,12 @@ int smb_vfs_call_unlink(struct vfs_handle_struct *handle,
        return handle->fns->unlink_fn(handle, smb_fname);
 }
 
-int smb_vfs_call_chmod(struct vfs_handle_struct *handle, const char *path,
-                      mode_t mode)
+int smb_vfs_call_chmod(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        VFS_FIND(chmod);
-       return handle->fns->chmod_fn(handle, path, mode);
+       return handle->fns->chmod_fn(handle, smb_fname, mode);
 }
 
 int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
@@ -1619,11 +1887,13 @@ int smb_vfs_call_fchmod(struct vfs_handle_struct *handle,
        return handle->fns->fchmod_fn(handle, fsp, mode);
 }
 
-int smb_vfs_call_chown(struct vfs_handle_struct *handle, const char *path,
-                      uid_t uid, gid_t gid)
+int smb_vfs_call_chown(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uid_t uid,
+                       gid_t gid)
 {
        VFS_FIND(chown);
-       return handle->fns->chown_fn(handle, path, uid, gid);
+       return handle->fns->chown_fn(handle, smb_fname, uid, gid);
 }
 
 int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
@@ -1633,20 +1903,19 @@ int smb_vfs_call_fchown(struct vfs_handle_struct *handle,
        return handle->fns->fchown_fn(handle, fsp, uid, gid);
 }
 
-int smb_vfs_call_lchown(struct vfs_handle_struct *handle, const char *path,
-                       uid_t uid, gid_t gid)
+int smb_vfs_call_lchown(struct vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uid_t uid,
+                       gid_t gid)
 {
        VFS_FIND(lchown);
-       return handle->fns->lchown_fn(handle, path, uid, gid);
+       return handle->fns->lchown_fn(handle, smb_fname, uid, gid);
 }
 
 NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
 {
        int ret;
        bool as_root = false;
-       const char *path;
-       char *saved_dir = NULL;
-       char *parent_dir = NULL;
        NTSTATUS status;
 
        if (fsp->fh->fd != -1) {
@@ -1669,8 +1938,10 @@ NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
                 * and always act using lchown to ensure we
                 * don't deref any symbolic links.
                 */
+               char *saved_dir = NULL;
+               char *parent_dir = NULL;
                const char *final_component = NULL;
-               struct smb_filename local_fname;
+               struct smb_filename *local_smb_fname = NULL;
 
                saved_dir = vfs_GetWd(talloc_tos(),fsp->conn);
                if (!saved_dir) {
@@ -1694,33 +1965,56 @@ NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
                        return map_nt_error_from_unix(errno);
                }
 
-               ZERO_STRUCT(local_fname);
-               local_fname.base_name = discard_const_p(char, final_component);
+               local_smb_fname = synthetic_smb_fname(talloc_tos(),
+                                       final_component,
+                                       NULL,
+                                       NULL);
+               if (local_smb_fname == NULL) {
+                       status = NT_STATUS_NO_MEMORY;
+                       goto out;
+               }
 
                /* Must use lstat here. */
-               ret = SMB_VFS_LSTAT(fsp->conn, &local_fname);
+               ret = SMB_VFS_LSTAT(fsp->conn, local_smb_fname);
                if (ret == -1) {
                        status = map_nt_error_from_unix(errno);
                        goto out;
                }
 
                /* Ensure it matches the fsp stat. */
-               if (!check_same_stat(&local_fname.st, &fsp->fsp_name->st)) {
+               if (!check_same_stat(&local_smb_fname->st,
+                               &fsp->fsp_name->st)) {
                         status = NT_STATUS_ACCESS_DENIED;
                        goto out;
                 }
-                path = final_component;
-        } else {
-                path = fsp->fsp_name->base_name;
-        }
 
-       if (fsp->posix_open || as_root) {
                ret = SMB_VFS_LCHOWN(fsp->conn,
-                       path,
+                       local_smb_fname,
+                       uid, gid);
+
+               if (ret == 0) {
+                       status = NT_STATUS_OK;
+               } else {
+                       status = map_nt_error_from_unix(errno);
+               }
+
+  out:
+
+               vfs_ChDir(fsp->conn,saved_dir);
+               TALLOC_FREE(local_smb_fname);
+               TALLOC_FREE(saved_dir);
+               TALLOC_FREE(parent_dir);
+
+               return status;
+       }
+
+       if (fsp->posix_flags & FSP_POSIX_FLAGS_OPEN) {
+               ret = SMB_VFS_LCHOWN(fsp->conn,
+                       fsp->fsp_name,
                        uid, gid);
        } else {
                ret = SMB_VFS_CHOWN(fsp->conn,
-                       path,
+                       fsp->fsp_name,
                        uid, gid);
        }
 
@@ -1729,14 +2023,6 @@ NTSTATUS vfs_chown_fsp(files_struct *fsp, uid_t uid, gid_t gid)
        } else {
                status = map_nt_error_from_unix(errno);
        }
-
-  out:
-
-       if (as_root) {
-               vfs_ChDir(fsp->conn,saved_dir);
-               TALLOC_FREE(saved_dir);
-               TALLOC_FREE(parent_dir);
-       }
        return status;
 }
 
@@ -1768,17 +2054,17 @@ int smb_vfs_call_ftruncate(struct vfs_handle_struct *handle,
 }
 
 int smb_vfs_call_fallocate(struct vfs_handle_struct *handle,
-                               struct files_struct *fsp,
-                               enum vfs_fallocate_mode mode,
-                               off_t offset,
-                               off_t len)
+                          struct files_struct *fsp,
+                          uint32_t mode,
+                          off_t offset,
+                          off_t len)
 {
        VFS_FIND(fallocate);
        return handle->fns->fallocate_fn(handle, fsp, mode, offset, len);
 }
 
 int smb_vfs_call_kernel_flock(struct vfs_handle_struct *handle,
-                             struct files_struct *fsp, uint32 share_mode,
+                             struct files_struct *fsp, uint32_t share_mode,
                              uint32_t access_mask)
 {
        VFS_FIND(kernel_flock);
@@ -1827,22 +2113,6 @@ char *smb_vfs_call_realpath(struct vfs_handle_struct *handle, const char *path)
        return handle->fns->realpath_fn(handle, path);
 }
 
-NTSTATUS smb_vfs_call_notify_watch(struct vfs_handle_struct *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_p)
-{
-       VFS_FIND(notify_watch);
-       return handle->fns->notify_watch_fn(handle, ctx, path,
-                                           filter, subdir_filter, callback,
-                                           private_data, handle_p);
-}
-
 int smb_vfs_call_chflags(struct vfs_handle_struct *handle, const char *path,
                         unsigned int flags)
 {
@@ -1859,13 +2129,13 @@ struct file_id smb_vfs_call_file_id_create(struct vfs_handle_struct *handle,
 
 NTSTATUS smb_vfs_call_streaminfo(struct vfs_handle_struct *handle,
                                 struct files_struct *fsp,
-                                const char *fname,
+                                const struct smb_filename *smb_fname,
                                 TALLOC_CTX *mem_ctx,
                                 unsigned int *num_streams,
                                 struct stream_struct **streams)
 {
        VFS_FIND(streaminfo);
-       return handle->fns->streaminfo_fn(handle, fsp, fname, mem_ctx,
+       return handle->fns->streaminfo_fn(handle, fsp, smb_fname, mem_ctx,
                                          num_streams, streams);
 }
 
@@ -1924,33 +2194,115 @@ NTSTATUS smb_vfs_call_fsctl(struct vfs_handle_struct *handle,
                            uint32_t *out_len)
 {
        VFS_FIND(fsctl);
-       return handle->fns->fsctl_fn(handle, fsp, ctx, function, req_flags, 
-                                    in_data, in_len, out_data, max_out_len, 
+       return handle->fns->fsctl_fn(handle, fsp, ctx, function, req_flags,
+                                    in_data, in_len, out_data, max_out_len,
                                     out_len);
 }
 
+struct tevent_req *smb_vfs_call_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 num)
+{
+       VFS_FIND(copy_chunk_send);
+       return handle->fns->copy_chunk_send_fn(handle, mem_ctx, ev, src_fsp,
+                                              src_off, dest_fsp, dest_off, num);
+}
+
+NTSTATUS smb_vfs_call_copy_chunk_recv(struct vfs_handle_struct *handle,
+                                     struct tevent_req *req,
+                                     off_t *copied)
+{
+       VFS_FIND(copy_chunk_recv);
+       return handle->fns->copy_chunk_recv_fn(handle, req, copied);
+}
+
+NTSTATUS smb_vfs_call_get_compression(vfs_handle_struct *handle,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct files_struct *fsp,
+                                     struct smb_filename *smb_fname,
+                                     uint16_t *_compression_fmt)
+{
+       VFS_FIND(get_compression);
+       return handle->fns->get_compression_fn(handle, mem_ctx, fsp, smb_fname,
+                                              _compression_fmt);
+}
+
+NTSTATUS smb_vfs_call_set_compression(vfs_handle_struct *handle,
+                                     TALLOC_CTX *mem_ctx,
+                                     struct files_struct *fsp,
+                                     uint16_t compression_fmt)
+{
+       VFS_FIND(set_compression);
+       return handle->fns->set_compression_fn(handle, mem_ctx, fsp,
+                                              compression_fmt);
+}
+
+NTSTATUS smb_vfs_call_snap_check_path(vfs_handle_struct *handle,
+                                     TALLOC_CTX *mem_ctx,
+                                     const char *service_path,
+                                     char **base_volume)
+{
+       VFS_FIND(snap_check_path);
+       return handle->fns->snap_check_path_fn(handle, mem_ctx, service_path,
+                                              base_volume);
+}
+
+NTSTATUS smb_vfs_call_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)
+{
+       VFS_FIND(snap_create);
+       return handle->fns->snap_create_fn(handle, mem_ctx, base_volume, tstamp,
+                                          rw, base_path, snap_path);
+}
+
+NTSTATUS smb_vfs_call_snap_delete(struct vfs_handle_struct *handle,
+                                 TALLOC_CTX *mem_ctx,
+                                 char *base_path,
+                                 char *snap_path)
+{
+       VFS_FIND(snap_delete);
+       return handle->fns->snap_delete_fn(handle, mem_ctx, base_path,
+                                          snap_path);
+}
+
 NTSTATUS smb_vfs_call_fget_nt_acl(struct vfs_handle_struct *handle,
                                  struct files_struct *fsp,
-                                 uint32 security_info,
+                                 uint32_t security_info,
+                                 TALLOC_CTX *mem_ctx,
                                  struct security_descriptor **ppdesc)
 {
        VFS_FIND(fget_nt_acl);
        return handle->fns->fget_nt_acl_fn(handle, fsp, security_info,
-                                          ppdesc);
+                                          mem_ctx, ppdesc);
 }
 
 NTSTATUS smb_vfs_call_get_nt_acl(struct 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)
 {
        VFS_FIND(get_nt_acl);
-       return handle->fns->get_nt_acl_fn(handle, name, security_info, ppdesc);
+       return handle->fns->get_nt_acl_fn(handle,
+                               smb_fname,
+                               security_info,
+                               mem_ctx,
+                               ppdesc);
 }
 
 NTSTATUS smb_vfs_call_fset_nt_acl(struct vfs_handle_struct *handle,
                                  struct files_struct *fsp,
-                                 uint32 security_info_sent,
+                                 uint32_t security_info_sent,
                                  const struct security_descriptor *psd)
 {
        VFS_FIND(fset_nt_acl);
@@ -1972,11 +2324,12 @@ NTSTATUS smb_vfs_call_audit_file(struct vfs_handle_struct *handle,
                                          access_denied);
 }
 
-int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle, const char *name,
-                          mode_t mode)
+int smb_vfs_call_chmod_acl(struct vfs_handle_struct *handle,
+               const struct smb_filename *smb_fname,
+               mode_t mode)
 {
        VFS_FIND(chmod_acl);
-       return handle->fns->chmod_acl_fn(handle, name, mode);
+       return handle->fns->chmod_acl_fn(handle, smb_fname, mode);
 }
 
 int smb_vfs_call_fchmod_acl(struct vfs_handle_struct *handle,
@@ -1986,118 +2339,41 @@ int smb_vfs_call_fchmod_acl(struct vfs_handle_struct *handle,
        return handle->fns->fchmod_acl_fn(handle, fsp, mode);
 }
 
-int smb_vfs_call_sys_acl_get_entry(struct vfs_handle_struct *handle,
-                                  SMB_ACL_T theacl, int entry_id,
-                                  SMB_ACL_ENTRY_T *entry_p)
-{
-       VFS_FIND(sys_acl_get_entry);
-       return handle->fns->sys_acl_get_entry_fn(handle, theacl, entry_id,
-                                                entry_p);
-}
-
-int smb_vfs_call_sys_acl_get_tag_type(struct vfs_handle_struct *handle,
-                                     SMB_ACL_ENTRY_T entry_d,
-                                     SMB_ACL_TAG_T *tag_type_p)
-{
-       VFS_FIND(sys_acl_get_tag_type);
-       return handle->fns->sys_acl_get_tag_type_fn(handle, entry_d, 
-                                                   tag_type_p);
-}
-
-int smb_vfs_call_sys_acl_get_permset(struct vfs_handle_struct *handle,
-                                    SMB_ACL_ENTRY_T entry_d,
-                                    SMB_ACL_PERMSET_T *permset_p)
-{
-       VFS_FIND(sys_acl_get_permset);
-       return handle->fns->sys_acl_get_permset_fn(handle, entry_d, permset_p);
-}
-
-void * smb_vfs_call_sys_acl_get_qualifier(struct vfs_handle_struct *handle,
-                                         SMB_ACL_ENTRY_T entry_d)
-{
-       VFS_FIND(sys_acl_get_qualifier);
-       return handle->fns->sys_acl_get_qualifier_fn(handle, entry_d);
-}
-
 SMB_ACL_T smb_vfs_call_sys_acl_get_file(struct vfs_handle_struct *handle,
                                        const char *path_p,
-                                       SMB_ACL_TYPE_T type)
+                                       SMB_ACL_TYPE_T type,
+                                       TALLOC_CTX *mem_ctx)
 {
        VFS_FIND(sys_acl_get_file);
-       return handle->fns->sys_acl_get_file_fn(handle, path_p, type);
+       return handle->fns->sys_acl_get_file_fn(handle, path_p, type, mem_ctx);
 }
 
 SMB_ACL_T smb_vfs_call_sys_acl_get_fd(struct vfs_handle_struct *handle,
-                                     struct files_struct *fsp)
+                                     struct files_struct *fsp,
+                                     TALLOC_CTX *mem_ctx)
 {
        VFS_FIND(sys_acl_get_fd);
-       return handle->fns->sys_acl_get_fd_fn(handle, fsp);
-}
-
-int smb_vfs_call_sys_acl_clear_perms(struct vfs_handle_struct *handle,
-                                    SMB_ACL_PERMSET_T permset)
-{
-       VFS_FIND(sys_acl_clear_perms);
-       return handle->fns->sys_acl_clear_perms_fn(handle, permset);
-}
-
-int smb_vfs_call_sys_acl_add_perm(struct vfs_handle_struct *handle,
-                                 SMB_ACL_PERMSET_T permset,
-                                 SMB_ACL_PERM_T perm)
-{
-       VFS_FIND(sys_acl_add_perm);
-       return handle->fns->sys_acl_add_perm_fn(handle, permset, perm);
-}
-
-char * smb_vfs_call_sys_acl_to_text(struct vfs_handle_struct *handle,
-                                   SMB_ACL_T theacl, ssize_t *plen)
-{
-       VFS_FIND(sys_acl_to_text);
-       return handle->fns->sys_acl_to_text_fn(handle, theacl, plen);
+       return handle->fns->sys_acl_get_fd_fn(handle, fsp, mem_ctx);
 }
 
-SMB_ACL_T smb_vfs_call_sys_acl_init(struct vfs_handle_struct *handle,
-                                   int count)
+int smb_vfs_call_sys_acl_blob_get_file(struct vfs_handle_struct *handle,
+                                      const char *path_p,
+                                      TALLOC_CTX *mem_ctx, 
+                                      char **blob_description,
+                                      DATA_BLOB *blob)
 {
-       VFS_FIND(sys_acl_init);
-       return handle->fns->sys_acl_init_fn(handle, count);
+       VFS_FIND(sys_acl_blob_get_file);
+       return handle->fns->sys_acl_blob_get_file_fn(handle, path_p, mem_ctx, blob_description, blob);
 }
 
-int smb_vfs_call_sys_acl_create_entry(struct vfs_handle_struct *handle,
-                                     SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry)
-{
-       VFS_FIND(sys_acl_create_entry);
-       return handle->fns->sys_acl_create_entry_fn(handle, pacl, pentry);
-}
-
-int smb_vfs_call_sys_acl_set_tag_type(struct vfs_handle_struct *handle,
-                                     SMB_ACL_ENTRY_T entry,
-                                     SMB_ACL_TAG_T tagtype)
-{
-       VFS_FIND(sys_acl_set_tag_type);
-       return handle->fns->sys_acl_set_tag_type_fn(handle, entry, tagtype);
-}
-
-int smb_vfs_call_sys_acl_set_qualifier(struct vfs_handle_struct *handle,
-                                      SMB_ACL_ENTRY_T entry, void *qual)
-{
-       VFS_FIND(sys_acl_set_qualifier);
-       return handle->fns->sys_acl_set_qualifier_fn(handle, entry, qual);
-}
-
-int smb_vfs_call_sys_acl_set_permset(struct vfs_handle_struct *handle,
-                                    SMB_ACL_ENTRY_T entry,
-                                    SMB_ACL_PERMSET_T permset)
-{
-       VFS_FIND(sys_acl_set_permset);
-       return handle->fns->sys_acl_set_permset_fn(handle, entry, permset);
-}
-
-int smb_vfs_call_sys_acl_valid(struct vfs_handle_struct *handle,
-                              SMB_ACL_T theacl)
+int smb_vfs_call_sys_acl_blob_get_fd(struct vfs_handle_struct *handle,
+                                    struct files_struct *fsp,
+                                    TALLOC_CTX *mem_ctx, 
+                                    char **blob_description,
+                                    DATA_BLOB *blob)
 {
-       VFS_FIND(sys_acl_valid);
-       return handle->fns->sys_acl_valid_fn(handle, theacl);
+       VFS_FIND(sys_acl_blob_get_fd);
+       return handle->fns->sys_acl_blob_get_fd_fn(handle, fsp, mem_ctx, blob_description, blob);
 }
 
 int smb_vfs_call_sys_acl_set_file(struct vfs_handle_struct *handle,
@@ -2122,36 +2398,6 @@ int smb_vfs_call_sys_acl_delete_def_file(struct vfs_handle_struct *handle,
        return handle->fns->sys_acl_delete_def_file_fn(handle, path);
 }
 
-int smb_vfs_call_sys_acl_get_perm(struct vfs_handle_struct *handle,
-                                 SMB_ACL_PERMSET_T permset,
-                                 SMB_ACL_PERM_T perm)
-{
-       VFS_FIND(sys_acl_get_perm);
-       return handle->fns->sys_acl_get_perm_fn(handle, permset, perm);
-}
-
-int smb_vfs_call_sys_acl_free_text(struct vfs_handle_struct *handle,
-                                  char *text)
-{
-       VFS_FIND(sys_acl_free_text);
-       return handle->fns->sys_acl_free_text_fn(handle, text);
-}
-
-int smb_vfs_call_sys_acl_free_acl(struct vfs_handle_struct *handle,
-                                 SMB_ACL_T posix_acl)
-{
-       VFS_FIND(sys_acl_free_acl);
-       return handle->fns->sys_acl_free_acl_fn(handle, posix_acl);
-}
-
-int smb_vfs_call_sys_acl_free_qualifier(struct vfs_handle_struct *handle,
-                                       void *qualifier, SMB_ACL_TAG_T tagtype)
-{
-       VFS_FIND(sys_acl_free_qualifier);
-       return handle->fns->sys_acl_free_qualifier_fn(handle, qualifier, 
-                                                     tagtype);
-}
-
 ssize_t smb_vfs_call_getxattr(struct vfs_handle_struct *handle,
                              const char *path, const char *name, void *value,
                              size_t size)
@@ -2213,60 +2459,6 @@ int smb_vfs_call_fsetxattr(struct vfs_handle_struct *handle,
        return handle->fns->fsetxattr_fn(handle, fsp, name, value, size, flags);
 }
 
-int smb_vfs_call_aio_read(struct vfs_handle_struct *handle,
-                         struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
-{
-       VFS_FIND(aio_read);
-       return handle->fns->aio_read_fn(handle, fsp, aiocb);
-}
-
-int smb_vfs_call_aio_write(struct vfs_handle_struct *handle,
-                          struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
-{
-       VFS_FIND(aio_write);
-       return handle->fns->aio_write_fn(handle, fsp, aiocb);
-}
-
-ssize_t smb_vfs_call_aio_return(struct vfs_handle_struct *handle,
-                               struct files_struct *fsp,
-                               SMB_STRUCT_AIOCB *aiocb)
-{
-       VFS_FIND(aio_return);
-       return handle->fns->aio_return_fn(handle, fsp, aiocb);
-}
-
-int smb_vfs_call_aio_cancel(struct vfs_handle_struct *handle,
-                           struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
-{
-       VFS_FIND(aio_cancel);
-       return handle->fns->aio_cancel_fn(handle, fsp, aiocb);
-}
-
-int smb_vfs_call_aio_error(struct vfs_handle_struct *handle,
-                          struct files_struct *fsp,
-                          SMB_STRUCT_AIOCB *aiocb)
-{
-       VFS_FIND(aio_error);
-       return handle->fns->aio_error_fn(handle, fsp, aiocb);
-}
-
-int smb_vfs_call_aio_fsync(struct vfs_handle_struct *handle,
-                          struct files_struct *fsp, int op,
-                          SMB_STRUCT_AIOCB *aiocb)
-{
-       VFS_FIND(aio_fsync);
-       return handle->fns->aio_fsync_fn(handle, fsp, op, aiocb);
-}
-
-int smb_vfs_call_aio_suspend(struct vfs_handle_struct *handle,
-                            struct files_struct *fsp,
-                            const SMB_STRUCT_AIOCB * const aiocb[], int n,
-                            const struct timespec *timeout)
-{
-       VFS_FIND(aio_suspend);
-       return handle->fns->aio_suspend_fn(handle, fsp, aiocb, n, timeout);
-}
-
 bool smb_vfs_call_aio_force(struct vfs_handle_struct *handle,
                            struct files_struct *fsp)
 {
@@ -2288,3 +2480,46 @@ int smb_vfs_call_set_offline(struct vfs_handle_struct *handle,
        VFS_FIND(set_offline);
        return handle->fns->set_offline_fn(handle, fname);
 }
+
+NTSTATUS smb_vfs_call_durable_cookie(struct vfs_handle_struct *handle,
+                                    struct files_struct *fsp,
+                                    TALLOC_CTX *mem_ctx,
+                                    DATA_BLOB *cookie)
+{
+       VFS_FIND(durable_cookie);
+       return handle->fns->durable_cookie_fn(handle, fsp, mem_ctx, cookie);
+}
+
+NTSTATUS smb_vfs_call_durable_disconnect(struct vfs_handle_struct *handle,
+                                        struct files_struct *fsp,
+                                        const DATA_BLOB old_cookie,
+                                        TALLOC_CTX *mem_ctx,
+                                        DATA_BLOB *new_cookie)
+{
+       VFS_FIND(durable_disconnect);
+       return handle->fns->durable_disconnect_fn(handle, fsp, old_cookie,
+                                                 mem_ctx, new_cookie);
+}
+
+NTSTATUS smb_vfs_call_durable_reconnect(struct vfs_handle_struct *handle,
+                                       struct smb_request *smb1req,
+                                       struct smbXsrv_open *op,
+                                       const DATA_BLOB old_cookie,
+                                       TALLOC_CTX *mem_ctx,
+                                       struct files_struct **fsp,
+                                       DATA_BLOB *new_cookie)
+{
+       VFS_FIND(durable_reconnect);
+       return handle->fns->durable_reconnect_fn(handle, smb1req, op,
+                                                old_cookie, mem_ctx, fsp,
+                                                new_cookie);
+}
+
+NTSTATUS smb_vfs_call_readdir_attr(struct vfs_handle_struct *handle,
+                                  const struct smb_filename *fname,
+                                  TALLOC_CTX *mem_ctx,
+                                  struct readdir_attr_data **attr_data)
+{
+       VFS_FIND(readdir_attr);
+       return handle->fns->readdir_attr_fn(handle, fname, mem_ctx, attr_data);
+}