build: Remove sys_open wrapper
[sfrench/samba-autobuild/.git] / source3 / modules / vfs_default.c
index bb01f9858817f21ec732226baa2b0f35a7388ba6..615c0296b4683344c7e66abb257c2dc16f16ec9c 100644 (file)
 */
 
 #include "includes.h"
+#include "system/time.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
+#include "ntioctl.h"
+#include "smbprofile.h"
+#include "../libcli/security/security.h"
+#include "passdb/lookup_sid.h"
+#include "source3/include/msdfs.h"
+#include "librpc/gen_ndr/ndr_dfsblobs.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_VFS
@@ -79,7 +88,10 @@ static int vfswrap_set_quota(struct vfs_handle_struct *handle,  enum SMB_QUOTA_T
 #endif
 }
 
-static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle, struct files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, bool labels)
+static int vfswrap_get_shadow_copy_data(struct vfs_handle_struct *handle,
+                                       struct files_struct *fsp,
+                                       struct shadow_copy_data *shadow_copy_data,
+                                       bool labels)
 {
        errno = ENOSYS;
        return -1;  /* Not implemented. */
@@ -90,15 +102,243 @@ static int vfswrap_statvfs(struct vfs_handle_struct *handle,  const char *path,
        return sys_statvfs(path, statbuf);
 }
 
-static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle)
+static uint32_t vfswrap_fs_capabilities(struct vfs_handle_struct *handle,
+               enum timestamp_set_resolution *p_ts_res)
 {
-#if defined(DARWINOS)
+       connection_struct *conn = handle->conn;
+       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);
-       sys_statvfs(handle->conn->connectpath, &statbuf);
-       return statbuf.FsCapabilities;
+       ret = sys_statvfs(conn->connectpath, &statbuf);
+       if (ret == 0) {
+               caps = statbuf.FsCapabilities;
+       }
+
+       *p_ts_res = TIMESTAMP_SET_SECONDS;
+
+       /* 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)) {
+               return caps;
+       }
+
+       ret = SMB_VFS_STAT(conn, smb_fname_cpath);
+       if (ret == -1) {
+               TALLOC_FREE(smb_fname_cpath);
+               return caps;
+       }
+
+       if (smb_fname_cpath->st.st_ex_mtime.tv_nsec ||
+                       smb_fname_cpath->st.st_ex_atime.tv_nsec ||
+                       smb_fname_cpath->st.st_ex_ctime.tv_nsec) {
+               /* If any of the normal UNIX directory timestamps
+                * have a non-zero tv_nsec component assume
+                * we might be able to set sub-second timestamps.
+                * See what filetime set primitives we have.
+                */
+#if defined(HAVE_UTIMENSAT)
+               *p_ts_res = TIMESTAMP_SET_NT_OR_BETTER;
+#elif defined(HAVE_UTIMES)
+               /* utimes allows msec timestamps to be set. */
+               *p_ts_res = TIMESTAMP_SET_MSEC;
+#elif defined(HAVE_UTIME)
+               /* utime only allows sec timestamps to be set. */
+               *p_ts_res = TIMESTAMP_SET_SECONDS;
 #endif
-       return FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
+
+               DEBUG(10,("vfswrap_fs_capabilities: timestamp "
+                       "resolution of %s "
+                       "available on share %s, directory %s\n",
+                       *p_ts_res == TIMESTAMP_SET_MSEC ? "msec" : "sec",
+                       lp_servicename(conn->params->service),
+                       conn->connectpath ));
+       }
+       TALLOC_FREE(smb_fname_cpath);
+       return caps;
+}
+
+static NTSTATUS vfswrap_get_dfs_referrals(struct vfs_handle_struct *handle,
+                                         struct dfs_GetDFSReferral *r)
+{
+       struct junction_map *junction = NULL;
+       int consumedcnt = 0;
+       bool self_referral = false;
+       char *pathnamep = NULL;
+       char *local_dfs_path = NULL;
+       NTSTATUS status;
+       int i;
+       uint16_t max_referral_level = r->in.req.max_referral_level;
+
+       if (DEBUGLVL(10)) {
+               NDR_PRINT_IN_DEBUG(dfs_GetDFSReferral, r);
+       }
+
+       /* get the junction entry */
+       if (r->in.req.servername == NULL) {
+               return NT_STATUS_NOT_FOUND;
+       }
+
+       /*
+        * Trim pathname sent by client so it begins with only one backslash.
+        * Two backslashes confuse some dfs clients
+        */
+
+       local_dfs_path = talloc_strdup(r, r->in.req.servername);
+       if (local_dfs_path == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+       pathnamep = local_dfs_path;
+       while (IS_DIRECTORY_SEP(pathnamep[0]) &&
+              IS_DIRECTORY_SEP(pathnamep[1])) {
+               pathnamep++;
+       }
+
+       junction = talloc_zero(r, struct junction_map);
+       if (junction == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       /* The following call can change cwd. */
+       status = get_referred_path(r, pathnamep, handle->conn->sconn,
+                                  junction, &consumedcnt, &self_referral);
+       if (!NT_STATUS_IS_OK(status)) {
+               vfs_ChDir(handle->conn, handle->conn->connectpath);
+               return status;
+       }
+       vfs_ChDir(handle->conn, handle->conn->connectpath);
+
+       if (!self_referral) {
+               pathnamep[consumedcnt] = '\0';
+
+               if (DEBUGLVL(3)) {
+                       dbgtext("setup_dfs_referral: Path %s to "
+                               "alternate path(s):",
+                               pathnamep);
+                       for (i=0; i < junction->referral_count; i++) {
+                               dbgtext(" %s",
+                               junction->referral_list[i].alternate_path);
+                       }
+                       dbgtext(".\n");
+               }
+       }
+
+       if (r->in.req.max_referral_level <= 2) {
+               max_referral_level = 2;
+       }
+       if (r->in.req.max_referral_level >= 3) {
+               max_referral_level = 3;
+       }
+
+       r->out.resp = talloc_zero(r, struct dfs_referral_resp);
+       if (r->out.resp == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       r->out.resp->path_consumed = strlen_m(pathnamep) * 2;
+       r->out.resp->nb_referrals = junction->referral_count;
+
+       r->out.resp->header_flags = DFS_HEADER_FLAG_STORAGE_SVR;
+       if (self_referral) {
+               r->out.resp->header_flags |= DFS_HEADER_FLAG_REFERAL_SVR;
+       }
+
+       r->out.resp->referral_entries = talloc_zero_array(r,
+                               struct dfs_referral_type,
+                               r->out.resp->nb_referrals);
+       if (r->out.resp->referral_entries == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       switch (max_referral_level) {
+       case 2:
+               for(i=0; i < junction->referral_count; i++) {
+                       struct referral *ref = &junction->referral_list[i];
+                       TALLOC_CTX *mem_ctx = r->out.resp->referral_entries;
+                       struct dfs_referral_type *t =
+                               &r->out.resp->referral_entries[i];
+                       struct dfs_referral_v2 *v2 = &t->referral.v2;
+
+                       t->version = 2;
+                       v2->size = VERSION2_REFERRAL_SIZE;
+                       if (self_referral) {
+                               v2->server_type = DFS_SERVER_ROOT;
+                       } else {
+                               v2->server_type = DFS_SERVER_NON_ROOT;
+                       }
+                       v2->entry_flags = 0;
+                       v2->proximity = ref->proximity;
+                       v2->ttl = ref->ttl;
+                       v2->DFS_path = talloc_strdup(mem_ctx, pathnamep);
+                       if (v2->DFS_path == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+                       v2->DFS_alt_path = talloc_strdup(mem_ctx, pathnamep);
+                       if (v2->DFS_alt_path == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+                       v2->netw_address = talloc_strdup(mem_ctx,
+                                                        ref->alternate_path);
+                       if (v2->netw_address == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+               }
+
+               break;
+       case 3:
+               for(i=0; i < junction->referral_count; i++) {
+                       struct referral *ref = &junction->referral_list[i];
+                       TALLOC_CTX *mem_ctx = r->out.resp->referral_entries;
+                       struct dfs_referral_type *t =
+                               &r->out.resp->referral_entries[i];
+                       struct dfs_referral_v3 *v3 = &t->referral.v3;
+                       struct dfs_normal_referral *r1 = &v3->referrals.r1;
+
+                       t->version = 3;
+                       v3->size = VERSION3_REFERRAL_SIZE;
+                       if (self_referral) {
+                               v3->server_type = DFS_SERVER_ROOT;
+                       } else {
+                               v3->server_type = DFS_SERVER_NON_ROOT;
+                       }
+                       v3->entry_flags = 0;
+                       v3->ttl = ref->ttl;
+                       r1->DFS_path = talloc_strdup(mem_ctx, pathnamep);
+                       if (r1->DFS_path == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+                       r1->DFS_alt_path = talloc_strdup(mem_ctx, pathnamep);
+                       if (r1->DFS_alt_path == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+                       r1->netw_address = talloc_strdup(mem_ctx,
+                                                        ref->alternate_path);
+                       if (r1->netw_address == NULL) {
+                               return NT_STATUS_NO_MEMORY;
+                       }
+               }
+               break;
+       default:
+               DEBUG(0,("setup_dfs_referral: Invalid dfs referral "
+                       "version: %d\n",
+                       max_referral_level));
+               return NT_STATUS_INVALID_LEVEL;
+       }
+
+       if (DEBUGLVL(10)) {
+               NDR_PRINT_OUT_DEBUG(dfs_GetDFSReferral, r);
+       }
+
+       return NT_STATUS_OK;
 }
 
 /* Directory operations */
@@ -113,6 +353,20 @@ static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle,  const char *f
        return result;
 }
 
+static SMB_STRUCT_DIR *vfswrap_fdopendir(vfs_handle_struct *handle,
+                       files_struct *fsp,
+                       const char *mask,
+                       uint32 attr)
+{
+       SMB_STRUCT_DIR *result;
+
+       START_PROFILE(syscall_fdopendir);
+       result = sys_fdopendir(fsp->fh->fd);
+       END_PROFILE(syscall_fdopendir);
+       return result;
+}
+
+
 static SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle,
                                          SMB_STRUCT_DIR *dirp,
                                          SMB_STRUCT_STAT *sbuf)
@@ -163,7 +417,7 @@ static int vfswrap_mkdir(vfs_handle_struct *handle,  const char *path, mode_t mo
        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;
+               mode = (0777 & lp_dir_mask(SNUM(handle->conn)));
 
        TALLOC_FREE(parent);
 
@@ -214,13 +468,21 @@ static void vfswrap_init_search_op(vfs_handle_struct *handle,
 
 /* File operations */
 
-static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
-       files_struct *fsp, int flags, mode_t mode)
+static int vfswrap_open(vfs_handle_struct *handle,
+                       struct smb_filename *smb_fname,
+                       files_struct *fsp, int flags, mode_t mode)
 {
-       int result;
+       int result = -1;
 
        START_PROFILE(syscall_open);
-       result = sys_open(fname, flags, mode);
+
+       if (smb_fname->stream_name) {
+               errno = ENOENT;
+               goto out;
+       }
+
+       result = open(smb_fname->base_name, flags, mode);
+ out:
        END_PROFILE(syscall_open);
        return result;
 }
@@ -228,8 +490,7 @@ static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
 static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
                                    struct smb_request *req,
                                    uint16_t root_dir_fid,
-                                   const char *fname,
-                                   uint32_t create_file_flags,
+                                   struct smb_filename *smb_fname,
                                    uint32_t access_mask,
                                    uint32_t share_access,
                                    uint32_t create_disposition,
@@ -237,18 +498,19 @@ static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
                                    uint32_t file_attributes,
                                    uint32_t oplock_request,
                                    uint64_t allocation_size,
+                                   uint32_t private_flags,
                                    struct security_descriptor *sd,
                                    struct ea_list *ea_list,
                                    files_struct **result,
-                                   int *pinfo,
-                                   SMB_STRUCT_STAT *psbuf)
+                                   int *pinfo)
 {
-       return create_file_default(handle->conn, req, root_dir_fid, fname,
-                                  create_file_flags, access_mask, share_access,
+       return create_file_default(handle->conn, req, root_dir_fid, smb_fname,
+                                  access_mask, share_access,
                                   create_disposition, create_options,
                                   file_attributes, oplock_request,
-                                  allocation_size, sd, ea_list, result, pinfo,
-                                  psbuf);
+                                  allocation_size, private_flags,
+                                  sd, ea_list, result,
+                                  pinfo);
 }
 
 static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp)
@@ -372,7 +634,7 @@ static SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, SMB
 
        /* Cope with 'stat' file opens. */
        if (fsp->fh->fd != -1)
-               result = sys_lseek(fsp->fh->fd, offset, whence);
+               result = lseek(fsp->fh->fd, offset, whence);
 
        /*
         * We want to maintain the fiction that we can seek
@@ -415,106 +677,22 @@ static ssize_t vfswrap_recvfile(vfs_handle_struct *handle,
        return result;
 }
 
-/*********************************************************
- For rename across filesystems Patch from Warren Birnbaum
- <warrenb@hpcvscdp.cv.hp.com>
-**********************************************************/
-
-static int copy_reg(const char *source, const char *dest)
+static int vfswrap_rename(vfs_handle_struct *handle,
+                         const struct smb_filename *smb_fname_src,
+                         const struct smb_filename *smb_fname_dst)
 {
-       SMB_STRUCT_STAT source_stats;
-       int saved_errno;
-       int ifd = -1;
-       int ofd = -1;
-
-       if (sys_lstat (source, &source_stats) == -1)
-               return -1;
-
-       if (!S_ISREG (source_stats.st_mode))
-               return -1;
-
-       if((ifd = sys_open (source, O_RDONLY, 0)) < 0)
-               return -1;
-
-       if (unlink (dest) && errno != ENOENT)
-               return -1;
-
-#ifdef O_NOFOLLOW
-       if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW, 0600)) < 0 )
-#else
-       if((ofd = sys_open (dest, O_WRONLY | O_CREAT | O_TRUNC , 0600)) < 0 )
-#endif
-               goto err;
-
-       if (transfer_file(ifd, ofd, (size_t)-1) == -1)
-               goto err;
-
-       /*
-        * Try to preserve ownership.  For non-root it might fail, but that's ok.
-        * But root probably wants to know, e.g. if NFS disallows it.
-        */
-
-#ifdef HAVE_FCHOWN
-       if ((fchown(ofd, source_stats.st_uid, source_stats.st_gid) == -1) && (errno != EPERM))
-#else
-       if ((chown(dest, source_stats.st_uid, source_stats.st_gid) == -1) && (errno != EPERM))
-#endif
-               goto err;
-
-       /*
-        * fchown turns off set[ug]id bits for non-root,
-        * so do the chmod last.
-        */
-
-#if defined(HAVE_FCHMOD)
-       if (fchmod (ofd, source_stats.st_mode & 07777))
-#else
-       if (chmod (dest, source_stats.st_mode & 07777))
-#endif
-               goto err;
-
-       if (close (ifd) == -1)
-               goto err;
-
-       if (close (ofd) == -1)
-               return -1;
+       int result = -1;
 
-       /* Try to copy the old file's modtime and access time.  */
-       {
-               struct utimbuf tv;
+       START_PROFILE(syscall_rename);
 
-               tv.actime = source_stats.st_atime;
-               tv.modtime = source_stats.st_mtime;
-               utime(dest, &tv);
+       if (smb_fname_src->stream_name || smb_fname_dst->stream_name) {
+               errno = ENOENT;
+               goto out;
        }
 
-       if (unlink (source) == -1)
-               return -1;
-
-       return 0;
-
-  err:
-
-       saved_errno = errno;
-       if (ifd != -1)
-               close(ifd);
-       if (ofd != -1)
-               close(ofd);
-       errno = saved_errno;
-       return -1;
-}
-
-static int vfswrap_rename(vfs_handle_struct *handle,  const char *oldname, const char *newname)
-{
-       int result;
-
-       START_PROFILE(syscall_rename);
-       result = rename(oldname, newname);
-       if ((result == -1) && (errno == EXDEV)) {
-               /* Rename across filesystems needed. */
-               result = copy_reg(oldname, newname);
-       }
+       result = rename(smb_fname_src->base_name, smb_fname_dst->base_name);
 
+ out:
        END_PROFILE(syscall_rename);
        return result;
 }
@@ -533,12 +711,21 @@ static int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp)
 #endif
 }
 
-static int vfswrap_stat(vfs_handle_struct *handle,  const char *fname, SMB_STRUCT_STAT *sbuf)
+static int vfswrap_stat(vfs_handle_struct *handle,
+                       struct smb_filename *smb_fname)
 {
-       int result;
+       int result = -1;
 
        START_PROFILE(syscall_stat);
-       result = sys_stat(fname, sbuf);
+
+       if (smb_fname->stream_name) {
+               errno = ENOENT;
+               goto out;
+       }
+
+       result = sys_stat(smb_fname->base_name, &smb_fname->st,
+                         lp_fake_dir_create_times(SNUM(handle->conn)));
+ out:
        END_PROFILE(syscall_stat);
        return result;
 }
@@ -548,21 +735,372 @@ static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUC
        int result;
 
        START_PROFILE(syscall_fstat);
-       result = sys_fstat(fsp->fh->fd, sbuf);
+       result = sys_fstat(fsp->fh->fd,
+                          sbuf, lp_fake_dir_create_times(SNUM(handle->conn)));
        END_PROFILE(syscall_fstat);
        return result;
 }
 
-int vfswrap_lstat(vfs_handle_struct *handle,  const char *path, SMB_STRUCT_STAT *sbuf)
+static int vfswrap_lstat(vfs_handle_struct *handle,
+                        struct smb_filename *smb_fname)
 {
-       int result;
+       int result = -1;
 
        START_PROFILE(syscall_lstat);
-       result = sys_lstat(path, sbuf);
+
+       if (smb_fname->stream_name) {
+               errno = ENOENT;
+               goto out;
+       }
+
+       result = sys_lstat(smb_fname->base_name, &smb_fname->st,
+                          lp_fake_dir_create_times(SNUM(handle->conn)));
+ out:
        END_PROFILE(syscall_lstat);
        return result;
 }
 
+static NTSTATUS vfswrap_translate_name(struct vfs_handle_struct *handle,
+                                      const char *name,
+                                      enum vfs_translate_direction direction,
+                                      TALLOC_CTX *mem_ctx,
+                                      char **mapped_name)
+{
+       return NT_STATUS_NONE_MAPPED;
+}
+
+/*
+ * Implement the default fsctl operation.
+ */
+static bool vfswrap_logged_ioctl_message = false;
+
+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 ... */
+                             const uint8_t *_in_data,
+                             uint32_t in_len,
+                             uint8_t **_out_data,
+                             uint32_t max_out_len,
+                             uint32_t *out_len)
+{
+       const char *in_data = (const char *)_in_data;
+       char **out_data = (char **)_out_data;
+
+       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, 
+                      nt_errstr(status)));
+
+               return status;
+       }
+
+       case FSCTL_CREATE_OR_GET_OBJECT_ID:
+       {
+               unsigned char objid[16];
+               char *return_data = NULL;
+
+               /* This should return the object-id on this file.
+                * I think I'll make this be the inode+dev. JRA.
+                */
+
+               DEBUG(10,("FSCTL_CREATE_OR_GET_OBJECT_ID: called on FID[0x%04X]\n",fsp->fnum));
+
+               *out_len = (max_out_len >= 64) ? 64 : max_out_len;
+               /* Hmmm, will this cause problems if less data asked for? */
+               return_data = talloc_array(ctx, char, 64);
+               if (return_data == NULL) {
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               /* For backwards compatibility only store the dev/inode. */
+               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);
+               *out_data = return_data;
+               return NT_STATUS_OK;
+       }
+
+       case FSCTL_GET_REPARSE_POINT:
+       {
+               /* Fail it with STATUS_NOT_A_REPARSE_POINT */
+               DEBUG(10, ("FSCTL_GET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp->fnum));
+               return NT_STATUS_NOT_A_REPARSE_POINT;
+       }
+
+       case FSCTL_SET_REPARSE_POINT:
+       {
+               /* Fail it with STATUS_NOT_A_REPARSE_POINT */
+               DEBUG(10, ("FSCTL_SET_REPARSE_POINT: called on FID[0x%04X] Status: NOT_IMPLEMENTED\n", fsp->fnum));
+               return NT_STATUS_NOT_A_REPARSE_POINT;
+       }
+
+       case FSCTL_GET_SHADOW_COPY_DATA:
+       {
+               /*
+                * This is called to retrieve the number of Shadow Copies (a.k.a. snapshots)
+                * and return their volume names.  If max_data_count is 16, then it is just
+                * asking for the number of volumes and length of the combined names.
+                *
+                * pdata is the data allocated by our caller, but that uses
+                * total_data_count (which is 0 in our case) rather than max_data_count.
+                * Allocate the correct amount and return the pointer to let
+                * it be deallocated when we return.
+                */
+               struct shadow_copy_data *shadow_data = NULL;
+               bool labels = False;
+               uint32 labels_data_count = 0;
+               uint32 i;
+               char *cur_pdata = NULL;
+
+               if (max_out_len < 16) {
+                       DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) < 16 is invalid!\n",
+                               max_out_len));
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
+
+               if (max_out_len > 16) {
+                       labels = True;
+               }
+
+               shadow_data = talloc_zero(ctx, struct shadow_copy_data);
+               if (shadow_data == NULL) {
+                       DEBUG(0,("TALLOC_ZERO() failed!\n"));
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               /*
+                * 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;
+                       } else {
+                               DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: connectpath %s, failed.\n", 
+                                       fsp->conn->connectpath));
+                               return NT_STATUS_UNSUCCESSFUL;
+                       }
+               }
+
+               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;
+               }
+
+               if (max_out_len < *out_len) {
+                       DEBUG(0,("FSCTL_GET_SHADOW_COPY_DATA: max_data_count(%u) too small (%u) bytes needed!\n",
+                               max_out_len, *out_len));
+                       TALLOC_FREE(shadow_data);
+                       return NT_STATUS_BUFFER_TOO_SMALL;
+               }
+
+               cur_pdata = talloc_array(ctx, char, *out_len);
+               if (cur_pdata == NULL) {
+                       TALLOC_FREE(shadow_data);
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               *out_data = cur_pdata;
+
+               /* num_volumes 4 bytes */
+               SIVAL(cur_pdata, 0, shadow_data->num_volumes);
+
+               if (labels) {
+                       /* num_labels 4 bytes */
+                       SIVAL(cur_pdata, 4, shadow_data->num_volumes);
+               }
+
+               /* needed_data_count 4 bytes */
+               SIVAL(cur_pdata, 8, labels_data_count + 4);
+
+               cur_pdata += 12;
+
+               DEBUG(10,("FSCTL_GET_SHADOW_COPY_DATA: %u volumes for path[%s].\n",
+                         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,
+                                           cur_pdata, shadow_data->labels[i],
+                                           2 * sizeof(SHADOW_COPY_LABEL),
+                                           STR_UNICODE|STR_TERMINATE);
+                               cur_pdata += 2 * sizeof(SHADOW_COPY_LABEL);
+                               DEBUGADD(10,("Label[%u]: '%s'\n",i,shadow_data->labels[i]));
+                       }
+               }
+
+               TALLOC_FREE(shadow_data);
+
+               return NT_STATUS_OK;
+       }
+
+       case FSCTL_FIND_FILES_BY_SID:
+       {
+               /* pretend this succeeded -
+                *
+                * we have to send back a list with all files owned by this SID
+                *
+                * but I have to check that --metze
+                */
+               struct dom_sid sid;
+               uid_t uid;
+               size_t sid_len;
+
+               DEBUG(10,("FSCTL_FIND_FILES_BY_SID: called on FID[0x%04X]\n", fsp->fnum));
+
+               if (in_len < 8) {
+                       /* NT_STATUS_BUFFER_TOO_SMALL maybe? */
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
+
+               sid_len = MIN(in_len - 4,SID_MAX_SIZE);
+
+               /* unknown 4 bytes: this is not the length of the sid :-(  */
+               /*unknown = IVAL(pdata,0);*/
+
+               if (!sid_parse(in_data + 4, sid_len, &sid)) {
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
+               DEBUGADD(10, ("for SID: %s\n", sid_string_dbg(&sid)));
+
+               if (!sid_to_uid(&sid, &uid)) {
+                       DEBUG(0,("sid_to_uid: failed, sid[%s] sid_len[%lu]\n",
+                                sid_string_dbg(&sid),
+                                (unsigned long)sid_len));
+                       uid = (-1);
+               }
+
+               /* we can take a look at the find source :-)
+                *
+                * find ./ -uid $uid  -name '*'   is what we need here
+                *
+                *
+                * and send 4bytes len and then NULL terminated unicode strings
+                * for each file
+                *
+                * but I don't know how to deal with the paged results
+                * (maybe we can hang the result anywhere in the fsp struct)
+                *
+                * but I don't know how to deal with the paged results
+                * (maybe we can hang the result anywhere in the fsp struct)
+                *
+                * we don't send all files at once
+                * and at the next we should *not* start from the beginning,
+                * so we have to cache the result
+                *
+                * --metze
+                */
+
+               /* this works for now... */
+               return NT_STATUS_OK;
+       }
+
+       case FSCTL_QUERY_ALLOCATED_RANGES:
+       {
+               /* FIXME: This is just a dummy reply, telling that all of the
+                * file is allocated. MKS cp needs that.
+                * Adding the real allocated ranges via FIEMAP on Linux
+                * 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;
+
+               if (in_len != 16) {
+                       DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: data_count(%u) != 16 is invalid!\n",
+                               in_len));
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
+
+               if (max_out_len < 16) {
+                       DEBUG(0,("FSCTL_QUERY_ALLOCATED_RANGES: max_out_len (%u) < 16 is invalid!\n",
+                               max_out_len));
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
+
+               offset = BVAL(in_data,0);
+               length = BVAL(in_data,8);
+
+               if (offset + length < offset) {
+                       /* No 64-bit integer wrap. */
+                       return NT_STATUS_INVALID_PARAMETER;
+               }
+
+               /* Shouldn't this be SMB_VFS_STAT ... ? */
+               status = vfs_stat_fsp(fsp);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return status;
+               }
+
+               *out_len = 16;
+               out_data_tmp = talloc_array(ctx, char, *out_len);
+               if (out_data_tmp == NULL) {
+                       DEBUG(10, ("unable to allocate memory for response\n"));
+                       return NT_STATUS_NO_MEMORY;
+               }
+
+               if (offset > fsp->fsp_name->st.st_ex_size ||
+                               fsp->fsp_name->st.st_ex_size == 0 ||
+                               length == 0) {
+                       memset(out_data_tmp, 0, *out_len);
+               } else {
+                       uint64_t end = offset + length;
+                       end = MIN(end, fsp->fsp_name->st.st_ex_size);
+                       SBVAL(out_data_tmp, 0, 0);
+                       SBVAL(out_data_tmp, 8, end);
+               }
+
+               *out_data = out_data_tmp;
+
+               return NT_STATUS_OK;
+       }
+
+       case FSCTL_IS_VOLUME_DIRTY:
+       {
+               DEBUG(10,("FSCTL_IS_VOLUME_DIRTY: called on FID[0x%04X] "
+                         "(but not implemented)\n", fsp->fnum));
+               /*
+                * http://msdn.microsoft.com/en-us/library/cc232128%28PROT.10%29.aspx
+                * says we have to respond with NT_STATUS_INVALID_PARAMETER
+                */
+               return NT_STATUS_INVALID_PARAMETER;
+       }
+
+       default:
+               /* 
+                * Only print once ... unfortunately there could be lots of
+                * different FSCTLs that are called.
+                */
+               if (!vfswrap_logged_ioctl_message) {
+                       vfswrap_logged_ioctl_message = true;
+                       DEBUG(2, ("%s (0x%x): Currently not implemented.\n",
+                       __func__, function));
+               }
+       }
+
+       return NT_STATUS_NOT_SUPPORTED;
+}
+
 /********************************************************************
  Given a stat buffer return the allocated size on disk, taking into
  account sparse files.
@@ -575,13 +1113,13 @@ static uint64_t vfswrap_get_alloc_size(vfs_handle_struct *handle,
 
        START_PROFILE(syscall_get_alloc_size);
 
-       if(S_ISDIR(sbuf->st_mode)) {
+       if(S_ISDIR(sbuf->st_ex_mode)) {
                result = 0;
                goto out;
        }
 
 #if defined(HAVE_STAT_ST_BLOCKS) && defined(STAT_ST_BLOCKSIZE)
-       result = (uint64_t)STAT_ST_BLOCKSIZE * (uint64_t)sbuf->st_blocks;
+       result = (uint64_t)STAT_ST_BLOCKSIZE * (uint64_t)sbuf->st_ex_blocks;
 #else
        result = get_file_size_stat(sbuf);
 #endif
@@ -596,12 +1134,20 @@ static uint64_t vfswrap_get_alloc_size(vfs_handle_struct *handle,
        return result;
 }
 
-static int vfswrap_unlink(vfs_handle_struct *handle,  const char *path)
+static int vfswrap_unlink(vfs_handle_struct *handle,
+                         const struct smb_filename *smb_fname)
 {
-       int result;
+       int result = -1;
 
        START_PROFILE(syscall_unlink);
-       result = unlink(path);
+
+       if (smb_fname->stream_name) {
+               errno = ENOENT;
+               goto out;
+       }
+       result = unlink(smb_fname->base_name);
+
+ out:
        END_PROFILE(syscall_unlink);
        return result;
 }
@@ -712,12 +1258,12 @@ static int vfswrap_chdir(vfs_handle_struct *handle,  const char *path)
        return result;
 }
 
-static char *vfswrap_getwd(vfs_handle_struct *handle,  char *path)
+static char *vfswrap_getwd(vfs_handle_struct *handle)
 {
        char *result;
 
        START_PROFILE(syscall_getwd);
-       result = sys_getwd(path);
+       result = sys_getwd();
        END_PROFILE(syscall_getwd);
        return result;
 }
@@ -727,34 +1273,85 @@ static char *vfswrap_getwd(vfs_handle_struct *handle,  char *path)
  system will support.
 **********************************************************************/
 
-static int vfswrap_ntimes(vfs_handle_struct *handle, const char *path,
+static int vfswrap_ntimes(vfs_handle_struct *handle,
+                         const struct smb_filename *smb_fname,
                          struct smb_file_time *ft)
 {
-       int result;
+       int result = -1;
 
        START_PROFILE(syscall_ntimes);
+
+       if (smb_fname->stream_name) {
+               errno = ENOENT;
+               goto out;
+       }
+
+       if (ft != NULL) {
+               if (null_timespec(ft->atime)) {
+                       ft->atime= smb_fname->st.st_ex_atime;
+               }
+
+               if (null_timespec(ft->mtime)) {
+                       ft->mtime = smb_fname->st.st_ex_mtime;
+               }
+
+               if (!null_timespec(ft->create_time)) {
+                       set_create_timespec_ea(handle->conn,
+                                              smb_fname,
+                                              ft->create_time);
+               }
+
+               if ((timespec_compare(&ft->atime,
+                                     &smb_fname->st.st_ex_atime) == 0) &&
+                   (timespec_compare(&ft->mtime,
+                                     &smb_fname->st.st_ex_mtime) == 0)) {
+                       return 0;
+               }
+       }
+
+#if defined(HAVE_UTIMENSAT)
+       if (ft != NULL) {
+               struct timespec ts[2];
+               ts[0] = ft->atime;
+               ts[1] = ft->mtime;
+               result = utimensat(AT_FDCWD, smb_fname->base_name, ts, 0);
+       } else {
+               result = utimensat(AT_FDCWD, smb_fname->base_name, NULL, 0);
+       }
+       if (!((result == -1) && (errno == ENOSYS))) {
+               goto out;
+       }
+#endif
 #if defined(HAVE_UTIMES)
        if (ft != NULL) {
                struct timeval tv[2];
                tv[0] = convert_timespec_to_timeval(ft->atime);
                tv[1] = convert_timespec_to_timeval(ft->mtime);
-               result = utimes(path, tv);
+               result = utimes(smb_fname->base_name, tv);
        } else {
-               result = utimes(path, NULL);
+               result = utimes(smb_fname->base_name, NULL);
        }
-#elif defined(HAVE_UTIME)
+       if (!((result == -1) && (errno == ENOSYS))) {
+               goto out;
+       }
+#endif
+#if defined(HAVE_UTIME)
        if (ft != NULL) {
                struct utimbuf times;
                times.actime = convert_timespec_to_time_t(ft->atime);
                times.modtime = convert_timespec_to_time_t(ft->mtime);
-               result = utime(path, &times);
+               result = utime(smb_fname->base_name, &times);
        } else {
-               result = utime(path, NULL);
+               result = utime(smb_fname->base_name, NULL);
        }
-#else
+       if (!((result == -1) && (errno == ENOSYS))) {
+               goto out;
+       }
+#endif
        errno = ENOSYS;
        result = -1;
-#endif
+
+ out:
        END_PROFILE(syscall_ntimes);
        return result;
 }
@@ -766,137 +1363,131 @@ static int vfswrap_ntimes(vfs_handle_struct *handle, const char *path,
 
 static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len)
 {
-       SMB_STRUCT_STAT st;
-       SMB_OFF_T currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
-       unsigned char zero_space[4096];
        SMB_OFF_T space_to_write;
+       uint64_t space_avail;
+       uint64_t bsize,dfree,dsize;
+       int ret;
+       NTSTATUS status;
+       SMB_STRUCT_STAT *pst;
 
-       if (currpos == -1)
-               return -1;
-
-       if (SMB_VFS_FSTAT(fsp, &st) == -1)
+       status = vfs_stat_fsp(fsp);
+       if (!NT_STATUS_IS_OK(status)) {
                return -1;
-
-       space_to_write = len - st.st_size;
+       }
+       pst = &fsp->fsp_name->st;
 
 #ifdef S_ISFIFO
-       if (S_ISFIFO(st.st_mode))
+       if (S_ISFIFO(pst->st_ex_mode))
                return 0;
 #endif
 
-       if (st.st_size == len)
+       if (pst->st_ex_size == len)
                return 0;
 
        /* Shrink - just ftruncate. */
-       if (st.st_size > len)
-               return sys_ftruncate(fsp->fh->fd, len);
+       if (pst->st_ex_size > len)
+               return ftruncate(fsp->fh->fd, len);
+
+       space_to_write = len - pst->st_ex_size;
+
+       /* for allocation try fallocate first. This can fail on some
+          platforms e.g. when the filesystem doesn't support it and no
+          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;
+               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));
 
        /* available disk space is enough or not? */
-       if (lp_strict_allocate(SNUM(fsp->conn))){
-               uint64_t space_avail;
-               uint64_t bsize,dfree,dsize;
-
-               space_avail = get_dfree_info(fsp->conn,fsp->fsp_name,false,&bsize,&dfree,&dsize);
-               /* space_avail is 1k blocks */
-               if (space_avail == (uint64_t)-1 ||
-                               ((uint64_t)space_to_write/1024 > space_avail) ) {
-                       errno = ENOSPC;
-                       return -1;
-               }
+       space_avail = get_dfree_info(fsp->conn,
+                                    fsp->fsp_name->base_name, false,
+                                    &bsize,&dfree,&dsize);
+       /* space_avail is 1k blocks */
+       if (space_avail == (uint64_t)-1 ||
+                       ((uint64_t)space_to_write/1024 > space_avail) ) {
+               errno = ENOSPC;
+               return -1;
        }
 
        /* Write out the real space on disk. */
-       if (SMB_VFS_LSEEK(fsp, st.st_size, SEEK_SET) != st.st_size)
-               return -1;
-
-       space_to_write = len - st.st_size;
-
-       memset(zero_space, '\0', sizeof(zero_space));
-       while ( space_to_write > 0) {
-               SMB_OFF_T retlen;
-               SMB_OFF_T current_len_to_write = MIN(sizeof(zero_space),space_to_write);
-
-               retlen = SMB_VFS_WRITE(fsp,(char *)zero_space,current_len_to_write);
-               if (retlen <= 0)
-                       return -1;
-
-               space_to_write -= retlen;
+       ret = vfs_slow_fallocate(fsp, pst->st_ex_size, space_to_write);
+       if (ret != 0) {
+               errno = ret;
+               ret = -1;
        }
 
-       /* Seek to where we were */
-       if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
-               return -1;
-
        return 0;
 }
 
 static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len)
 {
        int result = -1;
-       SMB_STRUCT_STAT st;
+       SMB_STRUCT_STAT *pst;
+       NTSTATUS status;
        char c = 0;
-       SMB_OFF_T currpos;
 
        START_PROFILE(syscall_ftruncate);
 
-       if (lp_strict_allocate(SNUM(fsp->conn))) {
+       if (lp_strict_allocate(SNUM(fsp->conn)) && !fsp->is_sparse) {
                result = strict_allocate_ftruncate(handle, fsp, len);
                END_PROFILE(syscall_ftruncate);
                return result;
        }
 
        /* we used to just check HAVE_FTRUNCATE_EXTEND and only use
-          sys_ftruncate if the system supports it. Then I discovered that
+          ftruncate if the system supports it. Then I discovered that
           you can have some filesystems that support ftruncate
           expansion and some that don't! On Linux fat can't do
           ftruncate extend but ext2 can. */
 
-       result = sys_ftruncate(fsp->fh->fd, len);
+       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
           for this */
-       currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
-       if (currpos == -1) {
-               goto done;
-       }
 
        /* Do an fstat to see if the file is longer than the requested
           size in which case the ftruncate above should have
           succeeded or shorter, in which case seek to len - 1 and
           write 1 byte of zero */
-       if (SMB_VFS_FSTAT(fsp, &st) == -1) {
+       status = vfs_stat_fsp(fsp);
+       if (!NT_STATUS_IS_OK(status)) {
                goto done;
        }
+       pst = &fsp->fsp_name->st;
 
 #ifdef S_ISFIFO
-       if (S_ISFIFO(st.st_mode)) {
+       if (S_ISFIFO(pst->st_ex_mode)) {
                result = 0;
                goto done;
        }
 #endif
 
-       if (st.st_size == len) {
+       if (pst->st_ex_size == len) {
                result = 0;
                goto done;
        }
 
-       if (st.st_size > len) {
-               /* the sys_ftruncate should have worked */
+       if (pst->st_ex_size > len) {
+               /* the ftruncate should have worked */
                goto done;
        }
 
-       if (SMB_VFS_LSEEK(fsp, len-1, SEEK_SET) != len -1)
-               goto done;
-
-       if (SMB_VFS_WRITE(fsp, &c, 1)!=1)
+       if (SMB_VFS_PWRITE(fsp, &c, 1, len-1)!=1) {
                goto done;
+       }
 
-       /* Seek to where we were */
-       if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
-               goto done;
        result = 0;
 
   done:
@@ -905,6 +1496,27 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_O
        return result;
 }
 
+static int vfswrap_fallocate(vfs_handle_struct *handle,
+                       files_struct *fsp,
+                       enum vfs_fallocate_mode mode,
+                       SMB_OFF_T offset,
+                       SMB_OFF_T len)
+{
+       int result;
+
+       START_PROFILE(syscall_fallocate);
+       if (mode == VFS_FALLOCATE_EXTEND_SIZE) {
+               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);
+       } else {
+               errno = EINVAL;
+               result = -1;
+       }
+       END_PROFILE(syscall_fallocate);
+       return result;
+}
+
 static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
 {
        bool result;
@@ -916,10 +1528,10 @@ static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int op, S
 }
 
 static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
-                               uint32 share_mode)
+                               uint32 share_mode, uint32 access_mask)
 {
        START_PROFILE(syscall_kernel_flock);
-       kernel_flock(fsp->fh->fd, share_mode);
+       kernel_flock(fsp->fh->fd, share_mode, access_mask);
        END_PROFILE(syscall_kernel_flock);
        return 0;
 }
@@ -995,19 +1607,34 @@ 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, char *resolved_path)
+static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path)
 {
        char *result;
 
        START_PROFILE(syscall_realpath);
-       result = realpath(path, resolved_path);
+#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
        END_PROFILE(syscall_realpath);
        return result;
 }
 
 static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle,
                                     struct sys_notify_context *ctx,
-                                    struct notify_entry *e,
+                                    const char *path,
+                                    uint32_t *filter,
+                                    uint32_t *subdir_filter,
                                     void (*callback)(struct sys_notify_context *ctx, 
                                                      void *private_data,
                                                      struct notify_event *ev),
@@ -1022,8 +1649,9 @@ static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle,
         * Until that is the case, hard-code inotify here.
         */
 #ifdef HAVE_INOTIFY
-       if (lp_kernel_change_notify(ctx->conn->params)) {
-               return inotify_watch(ctx, e, callback, private_data, handle);
+       if (lp_kernel_change_notify(vfs_handle->conn->params)) {
+               return inotify_watch(ctx, path, filter, subdir_filter,
+                                    callback, private_data, handle);
        }
 #endif
        /*
@@ -1032,7 +1660,8 @@ static NTSTATUS vfswrap_notify_watch(vfs_handle_struct *vfs_handle,
        return NT_STATUS_OK;
 }
 
-static int vfswrap_chflags(vfs_handle_struct *handle, const char *path, int flags)
+static int vfswrap_chflags(vfs_handle_struct *handle, const char *path,
+                          unsigned int flags)
 {
 #ifdef HAVE_CHFLAGS
        return chflags(path, flags);
@@ -1043,7 +1672,7 @@ static int vfswrap_chflags(vfs_handle_struct *handle, const char *path, int flag
 }
 
 static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle,
-                                            SMB_STRUCT_STAT *sbuf)
+                                            const SMB_STRUCT_STAT *sbuf)
 {
        struct file_id key;
 
@@ -1051,8 +1680,8 @@ static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle,
         * blob */
        ZERO_STRUCT(key);
 
-       key.devid = sbuf->st_dev;
-       key.inode = sbuf->st_ino;
+       key.devid = sbuf->st_ex_dev;
+       key.inode = sbuf->st_ex_ino;
        /* key.extid is unused by default. */
 
        return key;
@@ -1066,8 +1695,7 @@ static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
                                   struct stream_struct **pstreams)
 {
        SMB_STRUCT_STAT sbuf;
-       unsigned int num_streams = 0;
-       struct stream_struct *streams = NULL;
+       struct stream_struct *tmp_streams = NULL;
        int ret;
 
        if ((fsp != NULL) && (fsp->is_directory)) {
@@ -1081,36 +1709,42 @@ static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
                ret = SMB_VFS_FSTAT(fsp, &sbuf);
        }
        else {
-               ret = SMB_VFS_STAT(handle->conn, fname, &sbuf);
+               struct smb_filename smb_fname;
+
+               ZERO_STRUCT(smb_fname);
+               smb_fname.base_name = discard_const_p(char, fname);
+
+               if (lp_posix_pathnames()) {
+                       ret = SMB_VFS_LSTAT(handle->conn, &smb_fname);
+               } else {
+                       ret = SMB_VFS_STAT(handle->conn, &smb_fname);
+               }
+               sbuf = smb_fname.st;
        }
 
        if (ret == -1) {
                return map_nt_error_from_unix(errno);
        }
 
-       if (S_ISDIR(sbuf.st_mode)) {
+       if (S_ISDIR(sbuf.st_ex_mode)) {
                goto done;
        }
 
-       streams = talloc(mem_ctx, struct stream_struct);
-
-       if (streams == NULL) {
+       tmp_streams = talloc_realloc(mem_ctx, *pstreams, struct stream_struct,
+                                       (*pnum_streams) + 1);
+       if (tmp_streams == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
-
-       streams->size = sbuf.st_size;
-       streams->alloc_size = SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp, &sbuf);
-
-       streams->name = talloc_strdup(streams, "::$DATA");
-       if (streams->name == NULL) {
-               TALLOC_FREE(streams);
+       tmp_streams[*pnum_streams].name = talloc_strdup(tmp_streams, "::$DATA");
+       if (tmp_streams[*pnum_streams].name == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
+       tmp_streams[*pnum_streams].size = sbuf.st_ex_size;
+       tmp_streams[*pnum_streams].alloc_size = SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp, &sbuf);
 
-       num_streams = 1;
+       *pnum_streams += 1;
+       *pstreams = tmp_streams;
  done:
-       *pnum_streams = num_streams;
-       *pstreams = streams;
        return NT_STATUS_OK;
 }
 
@@ -1120,8 +1754,18 @@ static int vfswrap_get_real_filename(struct vfs_handle_struct *handle,
                                     TALLOC_CTX *mem_ctx,
                                     char **found_name)
 {
-       return get_real_filename(handle->conn, path, name, mem_ctx,
-                                found_name);
+       /*
+        * Don't fall back to get_real_filename so callers can differentiate
+        * between a full directory scan and an actual case-insensitive stat.
+        */
+       errno = EOPNOTSUPP;
+       return -1;
+}
+
+static const char *vfswrap_connectpath(struct vfs_handle_struct *handle,
+                                      const char *fname)
+{
+       return handle->conn->connectpath;
 }
 
 static NTSTATUS vfswrap_brl_lock_windows(struct vfs_handle_struct *handle,
@@ -1181,7 +1825,8 @@ 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, SEC_DESC **ppdesc)
+                                   uint32 security_info,
+                                   struct security_descriptor **ppdesc)
 {
        NTSTATUS result;
 
@@ -1193,7 +1838,8 @@ 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, SEC_DESC **ppdesc)
+                                  uint32 security_info,
+                                  struct security_descriptor **ppdesc)
 {
        NTSTATUS result;
 
@@ -1203,7 +1849,7 @@ static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
        return result;
 }
 
-static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
+static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const struct security_descriptor *psd)
 {
        NTSTATUS result;
 
@@ -1377,12 +2023,12 @@ static ssize_t vfswrap_listxattr(struct vfs_handle_struct *handle, const char *p
        return sys_listxattr(path, list, size);
 }
 
-ssize_t vfswrap_llistxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
+static ssize_t vfswrap_llistxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
 {
        return sys_llistxattr(path, list, size);
 }
 
-ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
+static ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
 {
        return sys_flistxattr(fsp->fh->fd, list, size);
 }
@@ -1419,12 +2065,32 @@ static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_stru
 
 static int vfswrap_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
 {
-       return sys_aio_read(aiocb);
+       int ret;
+       /*
+        * aio_read must be done as root, because in the glibc aio
+        * implementation the helper thread needs to be able to send a signal
+        * to the main thread, even when it has done a seteuid() to a
+        * different user.
+        */
+       become_root();
+       ret = sys_aio_read(aiocb);
+       unbecome_root();
+       return ret;
 }
 
 static int vfswrap_aio_write(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
 {
-       return sys_aio_write(aiocb);
+       int ret;
+       /*
+        * aio_write must be done as root, because in the glibc aio
+        * implementation the helper thread needs to be able to send a signal
+        * to the main thread, even when it has done a seteuid() to a
+        * different user.
+        */
+       become_root();
+       ret = sys_aio_write(aiocb);
+       unbecome_root();
+       return ret;
 }
 
 static ssize_t vfswrap_aio_return(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
@@ -1457,9 +2123,15 @@ static bool vfswrap_aio_force(struct vfs_handle_struct *handle, struct files_str
        return false;
 }
 
-static bool vfswrap_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
+static bool vfswrap_is_offline(struct vfs_handle_struct *handle,
+                              const struct smb_filename *fname,
+                              SMB_STRUCT_STAT *sbuf)
 {
-       if (ISDOT(path) || ISDOTDOT(path)) {
+       NTSTATUS status;
+       char *path;
+       bool offline = false;
+
+        if (ISDOT(fname->base_name) || ISDOTDOT(fname->base_name)) {
                return false;
        }
 
@@ -1470,10 +2142,21 @@ static bool vfswrap_is_offline(struct vfs_handle_struct *handle, const char *pat
                return false;
        }
 
-       return (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
+        status = get_full_smb_filename(talloc_tos(), fname, &path);
+        if (!NT_STATUS_IS_OK(status)) {
+                errno = map_errno_from_nt_status(status);
+                return false;
+        }
+
+       offline = (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
+
+       TALLOC_FREE(path);
+
+       return offline;
 }
 
-static int vfswrap_set_offline(struct vfs_handle_struct *handle, const char *path)
+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)
@@ -1482,268 +2165,152 @@ static int vfswrap_set_offline(struct vfs_handle_struct *handle, const char *pat
        return -1;
 }
 
-static vfs_op_tuple vfs_default_ops[] = {
-
+static struct vfs_fn_pointers vfs_default_fns = {
        /* Disk operations */
 
-       {SMB_VFS_OP(vfswrap_connect),   SMB_VFS_OP_CONNECT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_disconnect),        SMB_VFS_OP_DISCONNECT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_disk_free), SMB_VFS_OP_DISK_FREE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_get_quota), SMB_VFS_OP_GET_QUOTA,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_set_quota), SMB_VFS_OP_SET_QUOTA,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_get_shadow_copy_data), SMB_VFS_OP_GET_SHADOW_COPY_DATA,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_statvfs),   SMB_VFS_OP_STATVFS,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fs_capabilities), SMB_VFS_OP_FS_CAPABILITIES,
-        SMB_VFS_LAYER_OPAQUE},
+       .connect_fn = vfswrap_connect,
+       .disconnect_fn = vfswrap_disconnect,
+       .disk_free_fn = vfswrap_disk_free,
+       .get_quota_fn = vfswrap_get_quota,
+       .set_quota_fn = vfswrap_set_quota,
+       .get_shadow_copy_data_fn = vfswrap_get_shadow_copy_data,
+       .statvfs_fn = vfswrap_statvfs,
+       .fs_capabilities_fn = vfswrap_fs_capabilities,
+       .get_dfs_referrals_fn = vfswrap_get_dfs_referrals,
 
        /* Directory operations */
 
-       {SMB_VFS_OP(vfswrap_opendir),   SMB_VFS_OP_OPENDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_readdir),   SMB_VFS_OP_READDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_seekdir),   SMB_VFS_OP_SEEKDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_telldir),   SMB_VFS_OP_TELLDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_rewinddir), SMB_VFS_OP_REWINDDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_mkdir),     SMB_VFS_OP_MKDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_rmdir),     SMB_VFS_OP_RMDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_closedir),  SMB_VFS_OP_CLOSEDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_init_search_op), SMB_VFS_OP_INIT_SEARCH_OP,
-        SMB_VFS_LAYER_OPAQUE},
+       .opendir_fn = vfswrap_opendir,
+       .fdopendir_fn = vfswrap_fdopendir,
+       .readdir_fn = vfswrap_readdir,
+       .seekdir_fn = vfswrap_seekdir,
+       .telldir_fn = vfswrap_telldir,
+       .rewind_dir_fn = vfswrap_rewinddir,
+       .mkdir_fn = vfswrap_mkdir,
+       .rmdir_fn = vfswrap_rmdir,
+       .closedir_fn = vfswrap_closedir,
+       .init_search_op_fn = vfswrap_init_search_op,
 
        /* File operations */
 
-       {SMB_VFS_OP(vfswrap_open),      SMB_VFS_OP_OPEN,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_create_file),       SMB_VFS_OP_CREATE_FILE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_close),     SMB_VFS_OP_CLOSE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_read),      SMB_VFS_OP_READ,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_pread),     SMB_VFS_OP_PREAD,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_write),     SMB_VFS_OP_WRITE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_pwrite),    SMB_VFS_OP_PWRITE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_lseek),     SMB_VFS_OP_LSEEK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sendfile),  SMB_VFS_OP_SENDFILE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_recvfile),  SMB_VFS_OP_RECVFILE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_rename),    SMB_VFS_OP_RENAME,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fsync),     SMB_VFS_OP_FSYNC,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_stat),      SMB_VFS_OP_STAT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fstat),     SMB_VFS_OP_FSTAT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_lstat),     SMB_VFS_OP_LSTAT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_get_alloc_size),    SMB_VFS_OP_GET_ALLOC_SIZE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_unlink),    SMB_VFS_OP_UNLINK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_chmod),     SMB_VFS_OP_CHMOD,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fchmod),    SMB_VFS_OP_FCHMOD,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_chown),     SMB_VFS_OP_CHOWN,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fchown),    SMB_VFS_OP_FCHOWN,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_lchown),    SMB_VFS_OP_LCHOWN,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_chdir),     SMB_VFS_OP_CHDIR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_getwd),     SMB_VFS_OP_GETWD,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_ntimes),    SMB_VFS_OP_NTIMES,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_ftruncate), SMB_VFS_OP_FTRUNCATE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_lock),      SMB_VFS_OP_LOCK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_kernel_flock),      SMB_VFS_OP_KERNEL_FLOCK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_linux_setlease),    SMB_VFS_OP_LINUX_SETLEASE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_getlock),   SMB_VFS_OP_GETLOCK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_symlink),   SMB_VFS_OP_SYMLINK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_readlink),  SMB_VFS_OP_READLINK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_link),      SMB_VFS_OP_LINK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_mknod),     SMB_VFS_OP_MKNOD,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_realpath),  SMB_VFS_OP_REALPATH,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_notify_watch),      SMB_VFS_OP_NOTIFY_WATCH,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_chflags),   SMB_VFS_OP_CHFLAGS,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_file_id_create),    SMB_VFS_OP_FILE_ID_CREATE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_streaminfo),        SMB_VFS_OP_STREAMINFO,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_get_real_filename), SMB_VFS_OP_GET_REAL_FILENAME,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_brl_lock_windows),  SMB_VFS_OP_BRL_LOCK_WINDOWS,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_brl_unlock_windows),SMB_VFS_OP_BRL_UNLOCK_WINDOWS,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_brl_cancel_windows),SMB_VFS_OP_BRL_CANCEL_WINDOWS,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_strict_lock),       SMB_VFS_OP_STRICT_LOCK,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_strict_unlock),     SMB_VFS_OP_STRICT_UNLOCK,
-        SMB_VFS_LAYER_OPAQUE},
+       .open_fn = vfswrap_open,
+       .create_file_fn = vfswrap_create_file,
+       .close_fn = vfswrap_close,
+       .read_fn = vfswrap_read,
+       .pread_fn = vfswrap_pread,
+       .write_fn = vfswrap_write,
+       .pwrite_fn = vfswrap_pwrite,
+       .lseek_fn = vfswrap_lseek,
+       .sendfile_fn = vfswrap_sendfile,
+       .recvfile_fn = vfswrap_recvfile,
+       .rename_fn = vfswrap_rename,
+       .fsync_fn = vfswrap_fsync,
+       .stat_fn = vfswrap_stat,
+       .fstat_fn = vfswrap_fstat,
+       .lstat_fn = vfswrap_lstat,
+       .get_alloc_size_fn = vfswrap_get_alloc_size,
+       .unlink_fn = vfswrap_unlink,
+       .chmod_fn = vfswrap_chmod,
+       .fchmod_fn = vfswrap_fchmod,
+       .chown_fn = vfswrap_chown,
+       .fchown_fn = vfswrap_fchown,
+       .lchown_fn = vfswrap_lchown,
+       .chdir_fn = vfswrap_chdir,
+       .getwd_fn = vfswrap_getwd,
+       .ntimes_fn = vfswrap_ntimes,
+       .ftruncate_fn = vfswrap_ftruncate,
+       .fallocate_fn = vfswrap_fallocate,
+       .lock_fn = vfswrap_lock,
+       .kernel_flock_fn = vfswrap_kernel_flock,
+       .linux_setlease_fn = vfswrap_linux_setlease,
+       .getlock_fn = vfswrap_getlock,
+       .symlink_fn = vfswrap_symlink,
+       .readlink_fn = vfswrap_readlink,
+       .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,
+       .get_real_filename_fn = vfswrap_get_real_filename,
+       .connectpath_fn = vfswrap_connectpath,
+       .brl_lock_windows_fn = vfswrap_brl_lock_windows,
+       .brl_unlock_windows_fn = vfswrap_brl_unlock_windows,
+       .brl_cancel_windows_fn = vfswrap_brl_cancel_windows,
+       .strict_lock_fn = vfswrap_strict_lock,
+       .strict_unlock_fn = vfswrap_strict_unlock,
+       .translate_name_fn = vfswrap_translate_name,
+       .fsctl_fn = vfswrap_fsctl,
 
        /* NT ACL operations. */
 
-       {SMB_VFS_OP(vfswrap_fget_nt_acl),       SMB_VFS_OP_FGET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_get_nt_acl),        SMB_VFS_OP_GET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fset_nt_acl),       SMB_VFS_OP_FSET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
+       .fget_nt_acl_fn = vfswrap_fget_nt_acl,
+       .get_nt_acl_fn = vfswrap_get_nt_acl,
+       .fset_nt_acl_fn = vfswrap_fset_nt_acl,
 
        /* POSIX ACL operations. */
 
-       {SMB_VFS_OP(vfswrap_chmod_acl), SMB_VFS_OP_CHMOD_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fchmod_acl),        SMB_VFS_OP_FCHMOD_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_get_entry), SMB_VFS_OP_SYS_ACL_GET_ENTRY,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_get_tag_type),      SMB_VFS_OP_SYS_ACL_GET_TAG_TYPE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_get_permset),       SMB_VFS_OP_SYS_ACL_GET_PERMSET,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_get_qualifier),     SMB_VFS_OP_SYS_ACL_GET_QUALIFIER,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_get_file),  SMB_VFS_OP_SYS_ACL_GET_FILE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_get_fd),    SMB_VFS_OP_SYS_ACL_GET_FD,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_clear_perms),       SMB_VFS_OP_SYS_ACL_CLEAR_PERMS,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_add_perm),  SMB_VFS_OP_SYS_ACL_ADD_PERM,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_to_text),   SMB_VFS_OP_SYS_ACL_TO_TEXT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_init),      SMB_VFS_OP_SYS_ACL_INIT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_create_entry),      SMB_VFS_OP_SYS_ACL_CREATE_ENTRY,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_set_tag_type),      SMB_VFS_OP_SYS_ACL_SET_TAG_TYPE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_set_qualifier),     SMB_VFS_OP_SYS_ACL_SET_QUALIFIER,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_set_permset),       SMB_VFS_OP_SYS_ACL_SET_PERMSET,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_valid),     SMB_VFS_OP_SYS_ACL_VALID,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_set_file),  SMB_VFS_OP_SYS_ACL_SET_FILE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_set_fd),    SMB_VFS_OP_SYS_ACL_SET_FD,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_delete_def_file),   SMB_VFS_OP_SYS_ACL_DELETE_DEF_FILE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_get_perm),  SMB_VFS_OP_SYS_ACL_GET_PERM,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_free_text), SMB_VFS_OP_SYS_ACL_FREE_TEXT,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_free_acl),  SMB_VFS_OP_SYS_ACL_FREE_ACL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_sys_acl_free_qualifier),    SMB_VFS_OP_SYS_ACL_FREE_QUALIFIER,
-        SMB_VFS_LAYER_OPAQUE},
+       .chmod_acl_fn = vfswrap_chmod_acl,
+       .fchmod_acl_fn = vfswrap_fchmod_acl,
+
+       .sys_acl_get_entry_fn = vfswrap_sys_acl_get_entry,
+       .sys_acl_get_tag_type_fn = vfswrap_sys_acl_get_tag_type,
+       .sys_acl_get_permset_fn = vfswrap_sys_acl_get_permset,
+       .sys_acl_get_qualifier_fn = vfswrap_sys_acl_get_qualifier,
+       .sys_acl_get_file_fn = vfswrap_sys_acl_get_file,
+       .sys_acl_get_fd_fn = vfswrap_sys_acl_get_fd,
+       .sys_acl_clear_perms_fn = vfswrap_sys_acl_clear_perms,
+       .sys_acl_add_perm_fn = vfswrap_sys_acl_add_perm,
+       .sys_acl_to_text_fn = vfswrap_sys_acl_to_text,
+       .sys_acl_init_fn = vfswrap_sys_acl_init,
+       .sys_acl_create_entry_fn = vfswrap_sys_acl_create_entry,
+       .sys_acl_set_tag_type_fn = vfswrap_sys_acl_set_tag_type,
+       .sys_acl_set_qualifier_fn = vfswrap_sys_acl_set_qualifier,
+       .sys_acl_set_permset_fn = vfswrap_sys_acl_set_permset,
+       .sys_acl_valid_fn = vfswrap_sys_acl_valid,
+       .sys_acl_set_file_fn = vfswrap_sys_acl_set_file,
+       .sys_acl_set_fd_fn = vfswrap_sys_acl_set_fd,
+       .sys_acl_delete_def_file_fn = vfswrap_sys_acl_delete_def_file,
+       .sys_acl_get_perm_fn = vfswrap_sys_acl_get_perm,
+       .sys_acl_free_text_fn = vfswrap_sys_acl_free_text,
+       .sys_acl_free_acl_fn = vfswrap_sys_acl_free_acl,
+       .sys_acl_free_qualifier_fn = vfswrap_sys_acl_free_qualifier,
 
        /* EA operations. */
-
-       {SMB_VFS_OP(vfswrap_getxattr),  SMB_VFS_OP_GETXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_lgetxattr), SMB_VFS_OP_LGETXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fgetxattr), SMB_VFS_OP_FGETXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_listxattr), SMB_VFS_OP_LISTXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_llistxattr),        SMB_VFS_OP_LLISTXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_flistxattr),        SMB_VFS_OP_FLISTXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_removexattr),       SMB_VFS_OP_REMOVEXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_lremovexattr),      SMB_VFS_OP_LREMOVEXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fremovexattr),      SMB_VFS_OP_FREMOVEXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_setxattr),  SMB_VFS_OP_SETXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_lsetxattr), SMB_VFS_OP_LSETXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_fsetxattr), SMB_VFS_OP_FSETXATTR,
-        SMB_VFS_LAYER_OPAQUE},
-
-       {SMB_VFS_OP(vfswrap_aio_read),  SMB_VFS_OP_AIO_READ,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_aio_write), SMB_VFS_OP_AIO_WRITE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_aio_return),        SMB_VFS_OP_AIO_RETURN,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_aio_cancel), SMB_VFS_OP_AIO_CANCEL,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_aio_error), SMB_VFS_OP_AIO_ERROR,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_aio_fsync), SMB_VFS_OP_AIO_FSYNC,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_aio_suspend),SMB_VFS_OP_AIO_SUSPEND,
-        SMB_VFS_LAYER_OPAQUE},
-
-       {SMB_VFS_OP(vfswrap_aio_force), SMB_VFS_OP_AIO_FORCE,
-        SMB_VFS_LAYER_OPAQUE},
-
-       {SMB_VFS_OP(vfswrap_is_offline),SMB_VFS_OP_IS_OFFLINE,
-        SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_set_offline),SMB_VFS_OP_SET_OFFLINE,
-        SMB_VFS_LAYER_OPAQUE},
-
-       /* Finish VFS operations definition */
-
-       {SMB_VFS_OP(NULL),              SMB_VFS_OP_NOOP,
-        SMB_VFS_LAYER_NOOP}
+       .getxattr_fn = vfswrap_getxattr,
+       .lgetxattr_fn = vfswrap_lgetxattr,
+       .fgetxattr_fn = vfswrap_fgetxattr,
+       .listxattr_fn = vfswrap_listxattr,
+       .llistxattr_fn = vfswrap_llistxattr,
+       .flistxattr_fn = vfswrap_flistxattr,
+       .removexattr_fn = vfswrap_removexattr,
+       .lremovexattr_fn = vfswrap_lremovexattr,
+       .fremovexattr_fn = vfswrap_fremovexattr,
+       .setxattr_fn = vfswrap_setxattr,
+       .lsetxattr_fn = vfswrap_lsetxattr,
+       .fsetxattr_fn = vfswrap_fsetxattr,
+
+       /* aio operations */
+       .aio_read_fn = vfswrap_aio_read,
+       .aio_write_fn = vfswrap_aio_write,
+       .aio_return_fn = vfswrap_aio_return,
+       .aio_cancel_fn = vfswrap_aio_cancel,
+       .aio_error_fn = vfswrap_aio_error,
+       .aio_fsync_fn = vfswrap_aio_fsync,
+       .aio_suspend_fn = vfswrap_aio_suspend,
+       .aio_force_fn = vfswrap_aio_force,
+
+       /* offline operations */
+       .is_offline_fn = vfswrap_is_offline,
+       .set_offline_fn = vfswrap_set_offline
 };
 
 NTSTATUS vfs_default_init(void);
 NTSTATUS vfs_default_init(void)
 {
-       unsigned int needed = SMB_VFS_OP_LAST + 1; /* convert from index to count */
-
-       if (ARRAY_SIZE(vfs_default_ops) != needed) {
-               DEBUG(0, ("%s: %u ops registered, but %u ops are required\n",
-                       DEFAULT_VFS_MODULE_NAME, (unsigned int)ARRAY_SIZE(vfs_default_ops), needed));
-               smb_panic("operation(s) missing from default VFS module");
-       }
-
        return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,
-                               DEFAULT_VFS_MODULE_NAME, vfs_default_ops);
+                               DEFAULT_VFS_MODULE_NAME, &vfs_default_fns);
 }
+
+