s3: OneFS bulk directory enumeration support
[ira/wip.git] / source3 / modules / vfs_default.c
index 3251c56061adeb4d3dfbcf7fa0fdaf18315605c2..4b123ab03ed56b858a40935fd189dd8c7d484d43 100644 (file)
@@ -40,10 +40,10 @@ static void vfswrap_disconnect(vfs_handle_struct *handle)
 
 /* Disk operations */
 
-static SMB_BIG_UINT vfswrap_disk_free(vfs_handle_struct *handle,  const char *path, bool small_query, SMB_BIG_UINT *bsize,
-                              SMB_BIG_UINT *dfree, SMB_BIG_UINT *dsize)
+static uint64_t vfswrap_disk_free(vfs_handle_struct *handle,  const char *path, bool small_query, uint64_t *bsize,
+                              uint64_t *dfree, uint64_t *dsize)
 {
-       SMB_BIG_UINT result;
+       uint64_t result;
 
        result = sys_disk_free(handle->conn, path, small_query, bsize, dfree, dsize);
        return result;
@@ -90,6 +90,17 @@ 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)
+{
+#if defined(DARWINOS)
+       struct vfs_statvfs_struct statbuf;
+       ZERO_STRUCT(statbuf);
+       sys_statvfs(handle->conn->connectpath, &statbuf);
+       return statbuf.FsCapabilities;
+#endif
+       return FILE_CASE_SENSITIVE_SEARCH | FILE_CASE_PRESERVED_NAMES;
+}
+
 /* Directory operations */
 
 static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle,  const char *fname, const char *mask, uint32 attr)
@@ -102,12 +113,18 @@ static SMB_STRUCT_DIR *vfswrap_opendir(vfs_handle_struct *handle,  const char *f
        return result;
 }
 
-static SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle,  SMB_STRUCT_DIR *dirp)
+static SMB_STRUCT_DIRENT *vfswrap_readdir(vfs_handle_struct *handle,
+                                         SMB_STRUCT_DIR *dirp,
+                                         SMB_STRUCT_STAT *sbuf)
 {
        SMB_STRUCT_DIRENT *result;
 
        START_PROFILE(syscall_readdir);
        result = sys_readdir(dirp);
+       /* Default Posix readdir() does not give us stat info.
+        * Set to invalid to indicate we didn't return this info. */
+       if (sbuf)
+               SET_STAT_INVALID(*sbuf);
        END_PROFILE(syscall_readdir);
        return result;
 }
@@ -139,12 +156,17 @@ static int vfswrap_mkdir(vfs_handle_struct *handle,  const char *path, mode_t mo
 {
        int result;
        bool has_dacl = False;
+       char *parent = NULL;
 
        START_PROFILE(syscall_mkdir);
 
-       if (lp_inherit_acls(SNUM(handle->conn)) && (has_dacl = directory_has_default_acl(handle->conn, parent_dirname(path))))
+       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;
 
+       TALLOC_FREE(parent);
+
        result = mkdir(path, mode);
 
        if (result == 0 && !has_dacl) {
@@ -184,6 +206,12 @@ static int vfswrap_closedir(vfs_handle_struct *handle,  SMB_STRUCT_DIR *dirp)
        return result;
 }
 
+static void vfswrap_init_search_op(vfs_handle_struct *handle,
+                                  SMB_STRUCT_DIR *dirp)
+{
+       /* Default behavior is a NOOP */
+}
+
 /* File operations */
 
 static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
@@ -197,40 +225,65 @@ static int vfswrap_open(vfs_handle_struct *handle,  const char *fname,
        return result;
 }
 
-static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
+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,
+                                   uint32_t access_mask,
+                                   uint32_t share_access,
+                                   uint32_t create_disposition,
+                                   uint32_t create_options,
+                                   uint32_t file_attributes,
+                                   uint32_t oplock_request,
+                                   uint64_t allocation_size,
+                                   struct security_descriptor *sd,
+                                   struct ea_list *ea_list,
+                                   files_struct **result,
+                                   int *pinfo,
+                                   SMB_STRUCT_STAT *psbuf)
+{
+       return create_file_default(handle->conn, req, root_dir_fid, fname,
+                                  create_file_flags, access_mask, share_access,
+                                  create_disposition, create_options,
+                                  file_attributes, oplock_request,
+                                  allocation_size, sd, ea_list, result, pinfo,
+                                  psbuf);
+}
+
+static int vfswrap_close(vfs_handle_struct *handle, files_struct *fsp)
 {
        int result;
 
        START_PROFILE(syscall_close);
-
-       result = close(fd);
+       result = fd_close_posix(fsp);
        END_PROFILE(syscall_close);
        return result;
 }
 
-static ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data, size_t n)
+static ssize_t vfswrap_read(vfs_handle_struct *handle, files_struct *fsp, void *data, size_t n)
 {
        ssize_t result;
 
        START_PROFILE_BYTES(syscall_read, n);
-       result = sys_read(fd, data, n);
+       result = sys_read(fsp->fh->fd, data, n);
        END_PROFILE(syscall_read);
        return result;
 }
 
-static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, int fd, void *data,
+static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void *data,
                        size_t n, SMB_OFF_T offset)
 {
        ssize_t result;
 
 #if defined(HAVE_PREAD) || defined(HAVE_PREAD64)
        START_PROFILE_BYTES(syscall_pread, n);
-       result = sys_pread(fd, data, n, offset);
+       result = sys_pread(fsp->fh->fd, data, n, offset);
        END_PROFILE(syscall_pread);
 
        if (result == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be seeked (sought?) on. */
-               result = SMB_VFS_READ(fsp, fd, data, n);
+               result = SMB_VFS_READ(fsp, data, n);
                fsp->fh->pos = 0;
        }
 
@@ -238,23 +291,23 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, int f
        SMB_OFF_T   curr;
        int lerrno;
 
-       curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR);
+       curr = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
        if (curr == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be seeked (sought?) on. */
-               result = SMB_VFS_READ(fsp, fd, data, n);
+               result = SMB_VFS_READ(fsp, data, n);
                fsp->fh->pos = 0;
                return result;
        }
 
-       if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) {
+       if (SMB_VFS_LSEEK(fsp, offset, SEEK_SET) == -1) {
                return -1;
        }
 
        errno = 0;
-       result = SMB_VFS_READ(fsp, fd, data, n);
+       result = SMB_VFS_READ(fsp, data, n);
        lerrno = errno;
 
-       SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET);
+       SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
        errno = lerrno;
 
 #endif /* HAVE_PREAD */
@@ -262,48 +315,48 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, int f
        return result;
 }
 
-static ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, int fd, const void *data, size_t n)
+static ssize_t vfswrap_write(vfs_handle_struct *handle, files_struct *fsp, const void *data, size_t n)
 {
        ssize_t result;
 
        START_PROFILE_BYTES(syscall_write, n);
-       result = sys_write(fd, data, n);
+       result = sys_write(fsp->fh->fd, data, n);
        END_PROFILE(syscall_write);
        return result;
 }
 
-static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, int fd, const void *data,
+static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, const void *data,
                        size_t n, SMB_OFF_T offset)
 {
        ssize_t result;
 
 #if defined(HAVE_PWRITE) || defined(HAVE_PRWITE64)
        START_PROFILE_BYTES(syscall_pwrite, n);
-       result = sys_pwrite(fd, data, n, offset);
+       result = sys_pwrite(fsp->fh->fd, data, n, offset);
        END_PROFILE(syscall_pwrite);
 
        if (result == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be sought on. */
-               result = SMB_VFS_WRITE(fsp, fd, data, n);
+               result = SMB_VFS_WRITE(fsp, data, n);
        }
 
 #else /* HAVE_PWRITE */
        SMB_OFF_T   curr;
        int         lerrno;
 
-       curr = SMB_VFS_LSEEK(fsp, fd, 0, SEEK_CUR);
+       curr = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
        if (curr == -1) {
                return -1;
        }
 
-       if (SMB_VFS_LSEEK(fsp, fd, offset, SEEK_SET) == -1) {
+       if (SMB_VFS_LSEEK(fsp, offset, SEEK_SET) == -1) {
                return -1;
        }
 
-       result = SMB_VFS_WRITE(fsp, fd, data, n);
+       result = SMB_VFS_WRITE(fsp, data, n);
        lerrno = errno;
 
-       SMB_VFS_LSEEK(fsp, fd, curr, SEEK_SET);
+       SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
        errno = lerrno;
 
 #endif /* HAVE_PWRITE */
@@ -311,15 +364,15 @@ static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, int
        return result;
 }
 
-static SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, int filedes, SMB_OFF_T offset, int whence)
+static SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T offset, int whence)
 {
        SMB_OFF_T result = 0;
 
        START_PROFILE(syscall_lseek);
 
        /* Cope with 'stat' file opens. */
-       if (filedes != -1)
-               result = sys_lseek(filedes, offset, whence);
+       if (fsp->fh->fd != -1)
+               result = sys_lseek(fsp->fh->fd, offset, whence);
 
        /*
         * We want to maintain the fiction that we can seek
@@ -337,28 +390,27 @@ static SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, int
        return result;
 }
 
-static ssize_t vfswrap_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fsp, int fromfd, const DATA_BLOB *hdr,
+static ssize_t vfswrap_sendfile(vfs_handle_struct *handle, int tofd, files_struct *fromfsp, const DATA_BLOB *hdr,
                        SMB_OFF_T offset, size_t n)
 {
        ssize_t result;
 
        START_PROFILE_BYTES(syscall_sendfile, n);
-       result = sys_sendfile(tofd, fromfd, hdr, offset, n);
+       result = sys_sendfile(tofd, fromfsp->fh->fd, hdr, offset, n);
        END_PROFILE(syscall_sendfile);
        return result;
 }
 
 static ssize_t vfswrap_recvfile(vfs_handle_struct *handle,
                        int fromfd,
-                       files_struct *fsp,
-                       int tofd,
+                       files_struct *tofsp,
                        SMB_OFF_T offset,
                        size_t n)
 {
        ssize_t result;
 
        START_PROFILE_BYTES(syscall_recvfile, n);
-       result = sys_recvfile(fromfd, tofd, offset, n);
+       result = sys_recvfile(fromfd, tofsp->fh->fd, offset, n);
        END_PROFILE(syscall_recvfile);
        return result;
 }
@@ -458,7 +510,7 @@ static int vfswrap_rename(vfs_handle_struct *handle,  const char *oldname, const
 
        START_PROFILE(syscall_rename);
        result = rename(oldname, newname);
-       if (errno == EXDEV) {
+       if ((result == -1) && (errno == EXDEV)) {
                /* Rename across filesystems needed. */
                result = copy_reg(oldname, newname);
        }
@@ -467,13 +519,13 @@ static int vfswrap_rename(vfs_handle_struct *handle,  const char *oldname, const
        return result;
 }
 
-static int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp, int fd)
+static int vfswrap_fsync(vfs_handle_struct *handle, files_struct *fsp)
 {
 #ifdef HAVE_FSYNC
        int result;
 
        START_PROFILE(syscall_fsync);
-       result = fsync(fd);
+       result = fsync(fsp->fh->fd);
        END_PROFILE(syscall_fsync);
        return result;
 #else
@@ -491,12 +543,12 @@ static int vfswrap_stat(vfs_handle_struct *handle,  const char *fname, SMB_STRUC
        return result;
 }
 
-static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_STRUCT_STAT *sbuf)
+static int vfswrap_fstat(vfs_handle_struct *handle, files_struct *fsp, SMB_STRUCT_STAT *sbuf)
 {
        int result;
 
        START_PROFILE(syscall_fstat);
-       result = sys_fstat(fd, sbuf);
+       result = sys_fstat(fsp->fh->fd, sbuf);
        END_PROFILE(syscall_fstat);
        return result;
 }
@@ -511,6 +563,39 @@ int vfswrap_lstat(vfs_handle_struct *handle,  const char *path, SMB_STRUCT_STAT
        return result;
 }
 
+/********************************************************************
+ Given a stat buffer return the allocated size on disk, taking into
+ account sparse files.
+********************************************************************/
+static uint64_t vfswrap_get_alloc_size(vfs_handle_struct *handle,
+                                      struct files_struct *fsp,
+                                      const SMB_STRUCT_STAT *sbuf)
+{
+       uint64_t result;
+
+       START_PROFILE(syscall_get_alloc_size);
+
+       if(S_ISDIR(sbuf->st_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;
+#else
+       result = get_file_size_stat(sbuf);
+#endif
+
+       if (fsp && fsp->initial_allocation_size)
+               result = MAX(result,fsp->initial_allocation_size);
+
+       result = smb_roundup(handle->conn, result);
+
+ out:
+       END_PROFILE(syscall_get_alloc_size);
+       return result;
+}
+
 static int vfswrap_unlink(vfs_handle_struct *handle,  const char *path)
 {
        int result;
@@ -549,7 +634,7 @@ static int vfswrap_chmod(vfs_handle_struct *handle,  const char *path, mode_t mo
        return result;
 }
 
-static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode)
+static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
 {
        int result;
 
@@ -563,7 +648,7 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd,
 
        {
                int saved_errno = errno; /* We might get ENOSYS */
-               if ((result = SMB_VFS_FCHMOD_ACL(fsp, fd, mode)) == 0) {
+               if ((result = SMB_VFS_FCHMOD_ACL(fsp, mode)) == 0) {
                        END_PROFILE(syscall_fchmod);
                        return result;
                }
@@ -572,7 +657,7 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, int fd,
        }
 
 #if defined(HAVE_FCHMOD)
-       result = fchmod(fd, mode);
+       result = fchmod(fsp->fh->fd, mode);
 #else
        result = -1;
        errno = ENOSYS;
@@ -587,18 +672,18 @@ static int vfswrap_chown(vfs_handle_struct *handle, const char *path, uid_t uid,
        int result;
 
        START_PROFILE(syscall_chown);
-       result = sys_chown(path, uid, gid);
+       result = chown(path, uid, gid);
        END_PROFILE(syscall_chown);
        return result;
 }
 
-static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, int fd, uid_t uid, gid_t gid)
+static int vfswrap_fchown(vfs_handle_struct *handle, files_struct *fsp, uid_t uid, gid_t gid)
 {
 #ifdef HAVE_FCHOWN
        int result;
 
        START_PROFILE(syscall_fchown);
-       result = fchown(fd, uid, gid);
+       result = fchown(fsp->fh->fd, uid, gid);
        END_PROFILE(syscall_fchown);
        return result;
 #else
@@ -612,7 +697,7 @@ static int vfswrap_lchown(vfs_handle_struct *handle, const char *path, uid_t uid
        int result;
 
        START_PROFILE(syscall_lchown);
-       result = sys_lchown(path, uid, gid);
+       result = lchown(path, uid, gid);
        END_PROFILE(syscall_lchown);
        return result;
 }
@@ -642,24 +727,29 @@ static char *vfswrap_getwd(vfs_handle_struct *handle,  char *path)
  system will support.
 **********************************************************************/
 
-static int vfswrap_ntimes(vfs_handle_struct *handle, const char *path, const struct timespec ts[2])
+static int vfswrap_ntimes(vfs_handle_struct *handle, const char *path,
+                         struct smb_file_time *ft)
 {
        int result;
 
        START_PROFILE(syscall_ntimes);
 #if defined(HAVE_UTIMES)
-       {
+       if (ft != NULL) {
                struct timeval tv[2];
-               tv[0] = convert_timespec_to_timeval(ts[0]);
-               tv[1] = convert_timespec_to_timeval(ts[1]);
+               tv[0] = convert_timespec_to_timeval(ft->atime);
+               tv[1] = convert_timespec_to_timeval(ft->mtime);
                result = utimes(path, tv);
+       } else {
+               result = utimes(path, NULL);
        }
 #elif defined(HAVE_UTIME)
-       {
+       if (ft != NULL) {
                struct utimbuf times;
-               times.actime = convert_timespec_to_time_t(ts[0]);
-               times.modtime = convert_timespec_to_time_t(ts[1]);
-               result = utime(path, times);
+               times.actime = convert_timespec_to_time_t(ft->atime);
+               times.modtime = convert_timespec_to_time_t(ft->mtime);
+               result = utime(path, &times);
+       } else {
+               result = utime(path, NULL);
        }
 #else
        errno = ENOSYS;
@@ -674,17 +764,17 @@ static int vfswrap_ntimes(vfs_handle_struct *handle, const char *path, const str
  allocate is set.
 **********************************************************************/
 
-static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T len)
+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, fd, 0, SEEK_CUR);
+       SMB_OFF_T currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
        unsigned char zero_space[4096];
        SMB_OFF_T space_to_write;
 
        if (currpos == -1)
                return -1;
 
-       if (SMB_VFS_FSTAT(fsp, fd, &st) == -1)
+       if (SMB_VFS_FSTAT(fsp, &st) == -1)
                return -1;
 
        space_to_write = len - st.st_size;
@@ -699,10 +789,24 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
 
        /* Shrink - just ftruncate. */
        if (st.st_size > len)
-               return sys_ftruncate(fd, len);
+               return sys_ftruncate(fsp->fh->fd, len);
+
+       /* 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;
+               }
+       }
 
        /* Write out the real space on disk. */
-       if (SMB_VFS_LSEEK(fsp, fd, st.st_size, SEEK_SET) != st.st_size)
+       if (SMB_VFS_LSEEK(fsp, st.st_size, SEEK_SET) != st.st_size)
                return -1;
 
        space_to_write = len - st.st_size;
@@ -712,7 +816,7 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
                SMB_OFF_T retlen;
                SMB_OFF_T current_len_to_write = MIN(sizeof(zero_space),space_to_write);
 
-               retlen = SMB_VFS_WRITE(fsp,fsp->fh->fd,(char *)zero_space,current_len_to_write);
+               retlen = SMB_VFS_WRITE(fsp,(char *)zero_space,current_len_to_write);
                if (retlen <= 0)
                        return -1;
 
@@ -720,13 +824,13 @@ static int strict_allocate_ftruncate(vfs_handle_struct *handle, files_struct *fs
        }
 
        /* Seek to where we were */
-       if (SMB_VFS_LSEEK(fsp, fd, currpos, SEEK_SET) != currpos)
+       if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
                return -1;
 
        return 0;
 }
 
-static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T len)
+static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T len)
 {
        int result = -1;
        SMB_STRUCT_STAT st;
@@ -736,7 +840,7 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int f
        START_PROFILE(syscall_ftruncate);
 
        if (lp_strict_allocate(SNUM(fsp->conn))) {
-               result = strict_allocate_ftruncate(handle, fsp, fd, len);
+               result = strict_allocate_ftruncate(handle, fsp, len);
                END_PROFILE(syscall_ftruncate);
                return result;
        }
@@ -747,14 +851,14 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int f
           expansion and some that don't! On Linux fat can't do
           ftruncate extend but ext2 can. */
 
-       result = sys_ftruncate(fd, len);
+       result = sys_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, fd, 0, SEEK_CUR);
+       currpos = SMB_VFS_LSEEK(fsp, 0, SEEK_CUR);
        if (currpos == -1) {
                goto done;
        }
@@ -763,7 +867,7 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int f
           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, fd, &st) == -1) {
+       if (SMB_VFS_FSTAT(fsp, &st) == -1) {
                goto done;
        }
 
@@ -784,14 +888,14 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int f
                goto done;
        }
 
-       if (SMB_VFS_LSEEK(fsp, fd, len-1, SEEK_SET) != len -1)
+       if (SMB_VFS_LSEEK(fsp, len-1, SEEK_SET) != len -1)
                goto done;
 
-       if (SMB_VFS_WRITE(fsp, fd, &c, 1)!=1)
+       if (SMB_VFS_WRITE(fsp, &c, 1)!=1)
                goto done;
 
        /* Seek to where we were */
-       if (SMB_VFS_LSEEK(fsp, fd, currpos, SEEK_SET) != currpos)
+       if (SMB_VFS_LSEEK(fsp, currpos, SEEK_SET) != currpos)
                goto done;
        result = 0;
 
@@ -801,36 +905,36 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, int f
        return result;
 }
 
-static bool vfswrap_lock(vfs_handle_struct *handle, files_struct *fsp, int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type)
+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;
 
        START_PROFILE(syscall_fcntl_lock);
-       result =  fcntl_lock(fd, op, offset, count, type);
+       result =  fcntl_lock(fsp->fh->fd, op, offset, count, type);
        END_PROFILE(syscall_fcntl_lock);
        return result;
 }
 
-static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp, int fd,
+static int vfswrap_kernel_flock(vfs_handle_struct *handle, files_struct *fsp,
                                uint32 share_mode)
 {
        START_PROFILE(syscall_kernel_flock);
-       kernel_flock(fd, share_mode);
+       kernel_flock(fsp->fh->fd, share_mode);
        END_PROFILE(syscall_kernel_flock);
        return 0;
 }
 
-static bool vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
+static bool vfswrap_getlock(vfs_handle_struct *handle, files_struct *fsp, SMB_OFF_T *poffset, SMB_OFF_T *pcount, int *ptype, pid_t *ppid)
 {
        bool result;
 
        START_PROFILE(syscall_fcntl_getlock);
-       result =  fcntl_getlock(fd, poffset, pcount, ptype, ppid);
+       result =  fcntl_getlock(fsp->fh->fd, poffset, pcount, ptype, ppid);
        END_PROFILE(syscall_fcntl_getlock);
        return result;
 }
 
-static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp, int fd,
+static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
                                int leasetype)
 {
        int result = -1;
@@ -839,11 +943,11 @@ static int vfswrap_linux_setlease(vfs_handle_struct *handle, files_struct *fsp,
 
 #ifdef HAVE_KERNEL_OPLOCKS_LINUX
        /* first set the signal handler */
-       if(linux_set_lease_sighandler(fd) == -1) {
+       if(linux_set_lease_sighandler(fsp->fh->fd) == -1) {
                return -1;
        }
 
-       result = linux_setlease(fd, leasetype);
+       result = linux_setlease(fsp->fh->fd, leasetype);
 #else
        errno = ENOSYS;
 #endif
@@ -856,7 +960,7 @@ static int vfswrap_symlink(vfs_handle_struct *handle,  const char *oldpath, cons
        int result;
 
        START_PROFILE(syscall_symlink);
-       result = sys_symlink(oldpath, newpath);
+       result = symlink(oldpath, newpath);
        END_PROFILE(syscall_symlink);
        return result;
 }
@@ -866,7 +970,7 @@ static int vfswrap_readlink(vfs_handle_struct *handle,  const char *path, char *
        int result;
 
        START_PROFILE(syscall_readlink);
-       result = sys_readlink(path, buf, bufsiz);
+       result = readlink(path, buf, bufsiz);
        END_PROFILE(syscall_readlink);
        return result;
 }
@@ -876,7 +980,7 @@ static int vfswrap_link(vfs_handle_struct *handle,  const char *oldpath, const c
        int result;
 
        START_PROFILE(syscall_link);
-       result = sys_link(oldpath, newpath);
+       result = link(oldpath, newpath);
        END_PROFILE(syscall_link);
        return result;
 }
@@ -896,7 +1000,7 @@ static char *vfswrap_realpath(vfs_handle_struct *handle,  const char *path, char
        char *result;
 
        START_PROFILE(syscall_realpath);
-       result = sys_realpath(path, resolved_path);
+       result = realpath(path, resolved_path);
        END_PROFILE(syscall_realpath);
        return result;
 }
@@ -943,6 +1047,72 @@ static struct file_id vfswrap_file_id_create(struct vfs_handle_struct *handle, S
        return file_id_create_dev(dev, inode);
 }
 
+static NTSTATUS vfswrap_streaminfo(vfs_handle_struct *handle,
+                                  struct files_struct *fsp,
+                                  const char *fname,
+                                  TALLOC_CTX *mem_ctx,
+                                  unsigned int *pnum_streams,
+                                  struct stream_struct **pstreams)
+{
+       SMB_STRUCT_STAT sbuf;
+       unsigned int num_streams = 0;
+       struct stream_struct *streams = NULL;
+       int ret;
+
+       if ((fsp != NULL) && (fsp->is_directory)) {
+               /*
+                * No default streams on directories
+                */
+               goto done;
+       }
+
+       if ((fsp != NULL) && (fsp->fh->fd != -1)) {
+               ret = SMB_VFS_FSTAT(fsp, &sbuf);
+       }
+       else {
+               ret = SMB_VFS_STAT(handle->conn, fname, &sbuf);
+       }
+
+       if (ret == -1) {
+               return map_nt_error_from_unix(errno);
+       }
+
+       if (S_ISDIR(sbuf.st_mode)) {
+               goto done;
+       }
+
+       streams = talloc(mem_ctx, struct stream_struct);
+
+       if (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);
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       num_streams = 1;
+ done:
+       *pnum_streams = num_streams;
+       *pstreams = streams;
+       return NT_STATUS_OK;
+}
+
+static int vfswrap_get_real_filename(struct vfs_handle_struct *handle,
+                                    const char *path,
+                                    const char *name,
+                                    TALLOC_CTX *mem_ctx,
+                                    char **found_name)
+{
+       return get_real_filename(handle->conn, path, name, mem_ctx,
+                                found_name);
+}
+
 static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
                                    files_struct *fsp,
                                    uint32 security_info, SEC_DESC **ppdesc)
@@ -967,7 +1137,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, SEC_DESC *psd)
+static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp, uint32 security_info_sent, const SEC_DESC *psd)
 {
        NTSTATUS result;
 
@@ -977,16 +1147,6 @@ static NTSTATUS vfswrap_fset_nt_acl(vfs_handle_struct *handle, files_struct *fsp
        return result;
 }
 
-static NTSTATUS vfswrap_set_nt_acl(vfs_handle_struct *handle, files_struct *fsp, const char *name, uint32 security_info_sent, SEC_DESC *psd)
-{
-       NTSTATUS result;
-
-       START_PROFILE(set_nt_acl);
-       result = set_nt_acl(fsp, security_info_sent, psd);
-       END_PROFILE(set_nt_acl);
-       return result;
-}
-
 static int vfswrap_chmod_acl(vfs_handle_struct *handle,  const char *name, mode_t mode)
 {
 #ifdef HAVE_NO_ACL
@@ -1002,7 +1162,7 @@ static int vfswrap_chmod_acl(vfs_handle_struct *handle,  const char *name, mode_
 #endif
 }
 
-static int vfswrap_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int fd, mode_t mode)
+static int vfswrap_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, mode_t mode)
 {
 #ifdef HAVE_NO_ACL
        errno = ENOSYS;
@@ -1011,7 +1171,7 @@ static int vfswrap_fchmod_acl(vfs_handle_struct *handle, files_struct *fsp, int
        int result;
 
        START_PROFILE(fchmod_acl);
-       result = fchmod_acl(fsp, fd, mode);
+       result = fchmod_acl(fsp, mode);
        END_PROFILE(fchmod_acl);
        return result;
 #endif
@@ -1042,9 +1202,9 @@ static SMB_ACL_T vfswrap_sys_acl_get_file(vfs_handle_struct *handle,  const char
        return sys_acl_get_file(handle, path_p, type);
 }
 
-static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp, int fd)
+static SMB_ACL_T vfswrap_sys_acl_get_fd(vfs_handle_struct *handle, files_struct *fsp)
 {
-       return sys_acl_get_fd(handle, fsp, fd);
+       return sys_acl_get_fd(handle, fsp);
 }
 
 static int vfswrap_sys_acl_clear_perms(vfs_handle_struct *handle,  SMB_ACL_PERMSET_T permset)
@@ -1097,9 +1257,9 @@ static int vfswrap_sys_acl_set_file(vfs_handle_struct *handle,  const char *name
        return sys_acl_set_file(handle, name, acltype, theacl);
 }
 
-static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, int fd, SMB_ACL_T theacl)
+static int vfswrap_sys_acl_set_fd(vfs_handle_struct *handle, files_struct *fsp, SMB_ACL_T theacl)
 {
-       return sys_acl_set_fd(handle, fsp, fd, theacl);
+       return sys_acl_set_fd(handle, fsp, theacl);
 }
 
 static int vfswrap_sys_acl_delete_def_file(vfs_handle_struct *handle,  const char *path)
@@ -1141,9 +1301,9 @@ static ssize_t vfswrap_lgetxattr(struct vfs_handle_struct *handle,const char *pa
        return sys_lgetxattr(path, name, value, size);
 }
 
-static ssize_t vfswrap_fgetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, void *value, size_t size)
+static ssize_t vfswrap_fgetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, void *value, size_t size)
 {
-       return sys_fgetxattr(fd, name, value, size);
+       return sys_fgetxattr(fsp->fh->fd, name, value, size);
 }
 
 static ssize_t vfswrap_listxattr(struct vfs_handle_struct *handle, const char *path, char *list, size_t size)
@@ -1156,9 +1316,9 @@ ssize_t vfswrap_llistxattr(struct vfs_handle_struct *handle, const char *path, c
        return sys_llistxattr(path, list, size);
 }
 
-ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, char *list, size_t size)
+ssize_t vfswrap_flistxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, char *list, size_t size)
 {
-       return sys_flistxattr(fd, list, size);
+       return sys_flistxattr(fsp->fh->fd, list, size);
 }
 
 static int vfswrap_removexattr(struct vfs_handle_struct *handle, const char *path, const char *name)
@@ -1171,9 +1331,9 @@ static int vfswrap_lremovexattr(struct vfs_handle_struct *handle, const char *pa
        return sys_lremovexattr(path, name);
 }
 
-static int vfswrap_fremovexattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name)
+static int vfswrap_fremovexattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name)
 {
-       return sys_fremovexattr(fd, name);
+       return sys_fremovexattr(fsp->fh->fd, name);
 }
 
 static int vfswrap_setxattr(struct vfs_handle_struct *handle, const char *path, const char *name, const void *value, size_t size, int flags)
@@ -1186,9 +1346,9 @@ static int vfswrap_lsetxattr(struct vfs_handle_struct *handle, const char *path,
        return sys_lsetxattr(path, name, value, size, flags);
 }
 
-static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp,int fd, const char *name, const void *value, size_t size, int flags)
+static int vfswrap_fsetxattr(struct vfs_handle_struct *handle, struct files_struct *fsp, const char *name, const void *value, size_t size, int flags)
 {
-       return sys_fsetxattr(fd, name, value, size, flags);
+       return sys_fsetxattr(fsp->fh->fd, name, value, size, flags);
 }
 
 static int vfswrap_aio_read(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
@@ -1206,9 +1366,9 @@ static ssize_t vfswrap_aio_return(struct vfs_handle_struct *handle, struct files
        return sys_aio_return(aiocb);
 }
 
-static int vfswrap_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, int fd, SMB_STRUCT_AIOCB *aiocb)
+static int vfswrap_aio_cancel(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
 {
-       return sys_aio_cancel(fd, aiocb);
+       return sys_aio_cancel(fsp->fh->fd, aiocb);
 }
 
 static int vfswrap_aio_error(struct vfs_handle_struct *handle, struct files_struct *fsp, SMB_STRUCT_AIOCB *aiocb)
@@ -1226,6 +1386,36 @@ static int vfswrap_aio_suspend(struct vfs_handle_struct *handle, struct files_st
        return sys_aio_suspend(aiocb, n, timeout);
 }
 
+static bool vfswrap_aio_force(struct vfs_handle_struct *handle, struct files_struct *fsp)
+{
+       return false;
+}
+
+static bool vfswrap_is_offline(struct vfs_handle_struct *handle, const char *path, SMB_STRUCT_STAT *sbuf)
+{
+       if (ISDOT(path) || ISDOTDOT(path)) {
+               return false;
+       }
+
+       if (!lp_dmapi_support(SNUM(handle->conn)) || !dmapi_have_session()) {
+#if defined(ENOTSUP)
+               errno = ENOTSUP;
+#endif
+               return false;
+       }
+
+       return (dmapi_file_flags(path) & FILE_ATTRIBUTE_OFFLINE) != 0;
+}
+
+static int vfswrap_set_offline(struct vfs_handle_struct *handle, const char *path)
+{
+       /* We don't know how to set offline bit by default, needs to be overriden in the vfs modules */
+#if defined(ENOTSUP)
+       errno = ENOTSUP;
+#endif
+       return -1;
+}
+
 static vfs_op_tuple vfs_default_ops[] = {
 
        /* Disk operations */
@@ -1244,6 +1434,8 @@ static vfs_op_tuple vfs_default_ops[] = {
         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},
 
        /* Directory operations */
 
@@ -1263,11 +1455,15 @@ static vfs_op_tuple vfs_default_ops[] = {
         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},
 
        /* 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,
@@ -1294,6 +1490,8 @@ static vfs_op_tuple vfs_default_ops[] = {
         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,
@@ -1338,6 +1536,10 @@ static vfs_op_tuple vfs_default_ops[] = {
         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},
 
        /* NT ACL operations. */
 
@@ -1347,8 +1549,6 @@ static vfs_op_tuple vfs_default_ops[] = {
         SMB_VFS_LAYER_OPAQUE},
        {SMB_VFS_OP(vfswrap_fset_nt_acl),       SMB_VFS_OP_FSET_NT_ACL,
         SMB_VFS_LAYER_OPAQUE},
-       {SMB_VFS_OP(vfswrap_set_nt_acl),        SMB_VFS_OP_SET_NT_ACL,
-        SMB_VFS_LAYER_OPAQUE},
 
        /* POSIX ACL operations. */
 
@@ -1443,6 +1643,14 @@ static vfs_op_tuple vfs_default_ops[] = {
        {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,