VFS: Modify chown to take a const struct smb_filename * instead of const char *
[kai/samba-autobuild/.git] / source3 / modules / vfs_default.c
index 5d0966e18a84985a7f9da609816e520b9fc82935..604ee4519b71bead7e9552b8bbfb3276f1288586 100644 (file)
@@ -58,19 +58,23 @@ static uint64_t vfswrap_disk_free(vfs_handle_struct *handle, const char *path,
                                  uint64_t *bsize, uint64_t *dfree,
                                  uint64_t *dsize)
 {
-       uint64_t result;
+       if (sys_fsusage(path, dfree, dsize) != 0) {
+               return (uint64_t)-1;
+       }
 
-       result = sys_disk_free(handle->conn, path, bsize, dfree, dsize);
-       return result;
+       *bsize = 512;
+       return *dfree / 2;
 }
 
-static int vfswrap_get_quota(struct vfs_handle_struct *handle, enum SMB_QUOTA_TYPE qtype, unid_t id, SMB_DISK_QUOTA *qt)
+static int vfswrap_get_quota(struct vfs_handle_struct *handle, const char *path,
+                            enum SMB_QUOTA_TYPE qtype, unid_t id,
+                            SMB_DISK_QUOTA *qt)
 {
 #ifdef HAVE_SYS_QUOTAS
        int result;
 
        START_PROFILE(syscall_get_quota);
-       result = sys_get_quota(handle->conn->connectpath, qtype, id, qt);
+       result = sys_get_quota(path, qtype, id, qt);
        END_PROFILE(syscall_get_quota);
        return result;
 #else
@@ -371,12 +375,15 @@ static NTSTATUS vfswrap_snap_delete(struct vfs_handle_struct *handle,
 
 /* Directory operations */
 
-static DIR *vfswrap_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32_t attr)
+static DIR *vfswrap_opendir(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               const char *mask,
+                               uint32_t attr)
 {
        DIR *result;
 
        START_PROFILE(syscall_opendir);
-       result = opendir(fname);
+       result = opendir(smb_fname->base_name);
        END_PROFILE(syscall_opendir);
        return result;
 }
@@ -461,10 +468,13 @@ static void vfswrap_rewinddir(vfs_handle_struct *handle, DIR *dirp)
        END_PROFILE(syscall_rewinddir);
 }
 
-static int vfswrap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int vfswrap_mkdir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
        bool has_dacl = False;
+       const char *path = smb_fname->base_name;
        char *parent = NULL;
 
        START_PROFILE(syscall_mkdir);
@@ -488,20 +498,23 @@ static int vfswrap_mkdir(vfs_handle_struct *handle, const char *path, mode_t mod
                 * mess up any inherited ACL bits that were set. JRA.
                 */
                int saved_errno = errno; /* We may get ENOSYS */
-               if ((SMB_VFS_CHMOD_ACL(handle->conn, path, mode) == -1) && (errno == ENOSYS))
+               if ((SMB_VFS_CHMOD_ACL(handle->conn, smb_fname, mode) == -1) &&
+                               (errno == ENOSYS)) {
                        errno = saved_errno;
+               }
        }
 
        END_PROFILE(syscall_mkdir);
        return result;
 }
 
-static int vfswrap_rmdir(vfs_handle_struct *handle, const char *path)
+static int vfswrap_rmdir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname)
 {
        int result;
 
        START_PROFILE(syscall_rmdir);
-       result = rmdir(path);
+       result = rmdir(smb_fname->base_name);
        END_PROFILE(syscall_rmdir);
        return result;
 }
@@ -563,22 +576,6 @@ static NTSTATUS vfswrap_create_file(vfs_handle_struct *handle,
                                    const struct smb2_create_blobs *in_context_blobs,
                                    struct smb2_create_blobs *out_context_blobs)
 {
-       struct smb2_create_blob *svhdx = NULL;
-
-       /*
-        * It might be empty ... and smb2_create_blob_find does not handle that
-        */
-       if (in_context_blobs) {
-               svhdx = smb2_create_blob_find(in_context_blobs,
-                                             SVHDX_OPEN_DEVICE_CONTEXT);
-       }
-
-       if (svhdx != NULL) {
-               /* SharedVHD is not yet supported */
-               DEBUG(10, ("Shared VHD not yet supported, INVALID_DEVICE_REQUEST\n"));
-               return NT_STATUS_INVALID_DEVICE_REQUEST;
-       }
-
        return create_file_default(handle->conn, req, root_dir_fid, smb_fname,
                                   access_mask, share_access,
                                   create_disposition, create_options,
@@ -716,7 +713,7 @@ static bool vfswrap_init_asys_ctx(struct smbd_server_connection *conn)
                return true;
        }
 
-       ret = asys_context_init(&ctx, get_aio_pending_size());
+       ret = asys_context_init(&ctx, lp_aio_max_threads());
        if (ret != 0) {
                DEBUG(1, ("asys_context_init failed: %s\n", strerror(ret)));
                return false;
@@ -750,7 +747,7 @@ struct vfswrap_asys_state {
        struct asys_context *asys_ctx;
        struct tevent_req *req;
        ssize_t ret;
-       int err;
+       struct vfs_aio_state vfs_aio_state;
        SMBPROFILE_BASIC_ASYNC_STATE(profile_basic);
        SMBPROFILE_BYTES_ASYNC_STATE(profile_bytes);
 };
@@ -866,14 +863,14 @@ static void vfswrap_asys_finished(struct tevent_context *ev,
                                        uint16_t flags, void *p)
 {
        struct asys_context *asys_ctx = (struct asys_context *)p;
-       struct asys_result results[outstanding_aio_calls];
+       struct asys_result results[get_outstanding_aio_calls()];
        int i, ret;
 
        if ((flags & TEVENT_FD_READ) == 0) {
                return;
        }
 
-       ret = asys_results(asys_ctx, results, outstanding_aio_calls);
+       ret = asys_results(asys_ctx, results, get_outstanding_aio_calls());
        if (ret < 0) {
                DEBUG(1, ("asys_results returned %s\n", strerror(-ret)));
                return;
@@ -897,33 +894,36 @@ static void vfswrap_asys_finished(struct tevent_context *ev,
                SMBPROFILE_BASIC_ASYNC_END(state->profile_basic);
                SMBPROFILE_BYTES_ASYNC_END(state->profile_bytes);
                state->ret = result->ret;
-               state->err = result->err;
+               state->vfs_aio_state.error = result->err;
+               state->vfs_aio_state.duration = result->duration;
                tevent_req_defer_callback(req, ev);
                tevent_req_done(req);
        }
 }
 
-static ssize_t vfswrap_asys_ssize_t_recv(struct tevent_req *req, int *err)
+static ssize_t vfswrap_asys_ssize_t_recv(struct tevent_req *req,
+                                        struct vfs_aio_state *vfs_aio_state)
 {
        struct vfswrap_asys_state *state = tevent_req_data(
                req, struct vfswrap_asys_state);
 
-       if (tevent_req_is_unix_error(req, err)) {
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
                return -1;
        }
-       *err = state->err;
+       *vfs_aio_state = state->vfs_aio_state;
        return state->ret;
 }
 
-static int vfswrap_asys_int_recv(struct tevent_req *req, int *err)
+static int vfswrap_asys_int_recv(struct tevent_req *req,
+                                struct vfs_aio_state *vfs_aio_state)
 {
        struct vfswrap_asys_state *state = tevent_req_data(
                req, struct vfswrap_asys_state);
 
-       if (tevent_req_is_unix_error(req, err)) {
+       if (tevent_req_is_unix_error(req, &vfs_aio_state->error)) {
                return -1;
        }
-       *err = state->err;
+       *vfs_aio_state = state->vfs_aio_state;
        return state->ret;
 }
 
@@ -1678,7 +1678,9 @@ static int vfswrap_unlink(vfs_handle_struct *handle,
        return result;
 }
 
-static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mode)
+static int vfswrap_chmod(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       mode_t mode)
 {
        int result;
 
@@ -1693,7 +1695,10 @@ static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mod
 
        {
                int saved_errno = errno; /* We might get ENOSYS */
-               if ((result = SMB_VFS_CHMOD_ACL(handle->conn, path, mode)) == 0) {
+               result = SMB_VFS_CHMOD_ACL(handle->conn,
+                               smb_fname,
+                               mode);
+               if (result == 0) {
                        END_PROFILE(syscall_chmod);
                        return result;
                }
@@ -1701,7 +1706,7 @@ static int vfswrap_chmod(vfs_handle_struct *handle, const char *path, mode_t mod
                errno = saved_errno;
        }
 
-       result = chmod(path, mode);
+       result = chmod(smb_fname->base_name, mode);
        END_PROFILE(syscall_chmod);
        return result;
 }
@@ -1739,12 +1744,15 @@ static int vfswrap_fchmod(vfs_handle_struct *handle, files_struct *fsp, mode_t m
        return result;
 }
 
-static int vfswrap_chown(vfs_handle_struct *handle, const char *path, uid_t uid, gid_t gid)
+static int vfswrap_chown(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       uid_t uid,
+                       gid_t gid)
 {
        int result;
 
        START_PROFILE(syscall_chown);
-       result = chown(path, uid, gid);
+       result = chown(smb_fname->base_name, uid, gid);
        END_PROFILE(syscall_chown);
        return result;
 }
@@ -2141,20 +2149,7 @@ static char *vfswrap_realpath(vfs_handle_struct *handle, const char *path)
        char *result;
 
        START_PROFILE(syscall_realpath);
-#ifdef REALPATH_TAKES_NULL
-       result = realpath(path, NULL);
-#else
-       result = SMB_MALLOC_ARRAY(char, PATH_MAX+1);
-       if (result) {
-               char *resolved_path = realpath(path, result);
-               if (!resolved_path) {
-                       SAFE_FREE(result);
-               } else {
-                       /* SMB_ASSERT(result == resolved_path) ? */
-                       result = resolved_path;
-               }
-       }
-#endif
+       result = sys_realpath(path);
        END_PROFILE(syscall_realpath);
        return result;
 }
@@ -2336,7 +2331,7 @@ static NTSTATUS vfswrap_fget_nt_acl(vfs_handle_struct *handle,
 }
 
 static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
-                                  const char *name,
+                                  const struct smb_filename *smb_fname,
                                   uint32_t security_info,
                                   TALLOC_CTX *mem_ctx,
                                   struct security_descriptor **ppdesc)
@@ -2344,8 +2339,11 @@ static NTSTATUS vfswrap_get_nt_acl(vfs_handle_struct *handle,
        NTSTATUS result;
 
        START_PROFILE(get_nt_acl);
-       result = posix_get_nt_acl(handle->conn, name, security_info,
-                                 mem_ctx, ppdesc);
+       result = posix_get_nt_acl(handle->conn,
+                               smb_fname->base_name,
+                               security_info,
+                               mem_ctx,
+                               ppdesc);
        END_PROFILE(get_nt_acl);
        return result;
 }
@@ -2369,7 +2367,9 @@ static NTSTATUS vfswrap_audit_file(struct vfs_handle_struct *handle,
        return NT_STATUS_OK; /* Nothing to do here ... */
 }
 
-static int vfswrap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t mode)
+static int vfswrap_chmod_acl(vfs_handle_struct *handle,
+                               const struct smb_filename *smb_fname,
+                               mode_t mode)
 {
 #ifdef HAVE_NO_ACL
        errno = ENOSYS;
@@ -2378,7 +2378,7 @@ static int vfswrap_chmod_acl(vfs_handle_struct *handle, const char *name, mode_t
        int result;
 
        START_PROFILE(chmod_acl);
-       result = chmod_acl(handle->conn, name, mode);
+       result = chmod_acl(handle->conn, smb_fname->base_name, mode);
        END_PROFILE(chmod_acl);
        return result;
 #endif