Remove redundant parameter fd from SMB_VFS_CLOSE().
[samba.git] / source3 / modules / vfs_default.c
index 97138bdacf041b3bc6317e347f9af433421a66cf..de801a20414263e1f01b66a6a49ba70552153cb2 100644 (file)
@@ -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)
@@ -197,23 +208,22 @@ 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 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;
 }
@@ -230,7 +240,7 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void
 
        if (result == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be seeked (sought?) on. */
-               result = SMB_VFS_READ(fsp, fsp->fh->fd, data, n);
+               result = SMB_VFS_READ(fsp, data, n);
                fsp->fh->pos = 0;
        }
 
@@ -241,7 +251,7 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void
        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, fsp->fh->fd, data, n);
+               result = SMB_VFS_READ(fsp, data, n);
                fsp->fh->pos = 0;
                return result;
        }
@@ -251,7 +261,7 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void
        }
 
        errno = 0;
-       result = SMB_VFS_READ(fsp, fsp->fh->fd, data, n);
+       result = SMB_VFS_READ(fsp, data, n);
        lerrno = errno;
 
        SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
@@ -262,12 +272,12 @@ static ssize_t vfswrap_pread(vfs_handle_struct *handle, files_struct *fsp, void
        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;
 }
@@ -284,7 +294,7 @@ static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, cons
 
        if (result == -1 && errno == ESPIPE) {
                /* Maintain the fiction that pipes can be sought on. */
-               result = SMB_VFS_WRITE(fsp, fsp->fh->fd, data, n);
+               result = SMB_VFS_WRITE(fsp, data, n);
        }
 
 #else /* HAVE_PWRITE */
@@ -300,7 +310,7 @@ static ssize_t vfswrap_pwrite(vfs_handle_struct *handle, files_struct *fsp, cons
                return -1;
        }
 
-       result = SMB_VFS_WRITE(fsp, fsp->fh->fd, data, n);
+       result = SMB_VFS_WRITE(fsp, data, n);
        lerrno = errno;
 
        SMB_VFS_LSEEK(fsp, curr, SEEK_SET);
@@ -337,28 +347,27 @@ static SMB_OFF_T vfswrap_lseek(vfs_handle_struct *handle, files_struct *fsp, SMB
        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 +467,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);
        }
@@ -712,7 +721,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;
 
@@ -787,7 +796,7 @@ static int vfswrap_ftruncate(vfs_handle_struct *handle, files_struct *fsp, SMB_O
        if (SMB_VFS_LSEEK(fsp, len-1, SEEK_SET) != len -1)
                goto done;
 
-       if (SMB_VFS_WRITE(fsp, fsp->fh->fd, &c, 1)!=1)
+       if (SMB_VFS_WRITE(fsp, &c, 1)!=1)
                goto done;
 
        /* Seek to where we were */
@@ -943,6 +952,62 @@ 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 = get_allocation_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 NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
                                    files_struct *fsp,
                                    uint32 security_info, SEC_DESC **ppdesc)
@@ -1226,6 +1291,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 +1339,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 */
 
@@ -1338,6 +1435,8 @@ 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},
 
        /* NT ACL operations. */
 
@@ -1443,6 +1542,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,