vfs_commit: print warning when no fsync support is there
[sfrench/samba-autobuild/.git] / source3 / modules / onefs_streams.c
index 91917eef44de395a15c06aa94d371f98e624fc5c..fa65b519966136515e6412d621e1036d927cec09 100644 (file)
 
 #include <sys/isi_enc.h>
 
-/*
- * OneFS stores streams without the explicit :$DATA at the end, so this strips
- * it off.  All onefs_stream functions must call through this instead of
- * split_ntfs_stream_name directly.
- */
-NTSTATUS onefs_split_ntfs_stream_name(TALLOC_CTX *mem_ctx, const char *fname,
-                                     char **pbase, char **pstream)
-{
-       NTSTATUS status;
-       char *stream;
-
-       status = split_ntfs_stream_name(mem_ctx, fname, pbase, pstream);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-
-       /* Default $DATA stream.  */
-       if (pstream == NULL || *pstream == NULL) {
-               return NT_STATUS_OK;
-       }
-
-       /* Strip off the $DATA. */
-       stream = strrchr_m(*pstream, ':');
-       SMB_ASSERT(stream);
-       stream[0] = '\0';
-
-       return NT_STATUS_OK;
-}
-
 NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
                                     const struct smb_filename *smb_fname_in,
                                     struct smb_filename **smb_fname_out)
@@ -84,6 +55,9 @@ NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
                /* Strip off the :$DATA if one exists. */
                str_tmp = strrchr_m(stream_name, ':');
                if (str_tmp) {
+                       if (StrCaseCmp(str_tmp, ":$DATA") != 0) {
+                               return NT_STATUS_INVALID_PARAMETER;
+                       }
                        str_tmp[0] = '\0';
                }
        }
@@ -97,26 +71,14 @@ NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
                                            stream_name, &smb_fname_in->st,
                                            smb_fname_out);
        TALLOC_FREE(stream_name);
-       return status;
-}
-
-int onefs_is_stream(const char *path, char **pbase, char **pstream,
-                   bool *is_stream)
-{
-       (*is_stream) = is_ntfs_stream_name(path);
 
-       if (!(*is_stream)) {
-               return 0;
-       }
-
-       if (!NT_STATUS_IS_OK(onefs_split_ntfs_stream_name(talloc_tos(), path,
-                                                         pbase, pstream))) {
-               DEBUG(10, ("onefs_split_ntfs_stream_name failed\n"));
-               errno = ENOMEM;
-               return -1;
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(5, ("Failed to prep stream name for %s: %s\n",
+                         *smb_fname_out ?
+                         smb_fname_str_dbg(*smb_fname_out) : "NULL",
+                         nt_errstr(status)));
        }
-
-       return 0;
+       return status;
 }
 
 int onefs_close(vfs_handle_struct *handle, struct files_struct *fsp)
@@ -141,6 +103,9 @@ static int get_stream_dir_fd(connection_struct *conn, const char *base,
        int dir_fd;
        int saved_errno;
 
+       DEBUG(10, ("Getting stream directory fd: %s (%d)\n", base,
+                  base_fdp ? *base_fdp : -1));
+
        /* If a valid base_fdp was given, use it. */
        if (base_fdp && *base_fdp >= 0) {
                base_fd = *base_fdp;
@@ -160,6 +125,8 @@ static int get_stream_dir_fd(connection_struct *conn, const char *base,
                                                0,
                                                NULL);
                if (base_fd < 0) {
+                       DEBUG(5, ("Failed getting base fd: %s\n",
+                                 strerror(errno)));
                        return -1;
                }
        }
@@ -192,6 +159,11 @@ static int get_stream_dir_fd(connection_struct *conn, const char *base,
                *base_fdp = base_fd;
        }
 
+       if (dir_fd < 0) {
+               DEBUG(5, ("Failed getting stream directory fd: %s\n",
+                         strerror(errno)));
+       }
+
        return dir_fd;
 }
 
@@ -218,6 +190,9 @@ int onefs_rename(vfs_handle_struct *handle,
        /* For now don't allow renames from or to the default stream. */
        if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
            is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
+               DEBUG(3, ("Unable to rename to/from a default stream: %s -> "
+                         "%s\n", smb_fname_str_dbg(smb_fname_src),
+                         smb_fname_str_dbg(smb_fname_dst)));
                errno = ENOSYS;
                goto done;
        }
@@ -356,6 +331,9 @@ static int stat_stream(struct connection_struct *conn, const char *base,
        /* Stat the stream. */
        ret = onefs_sys_fstat_at(dir_fd, stream, sbuf, flags);
        if (ret != -1) {
+               DEBUG(10, ("stat of stream '%s' failed: %s\n", stream,
+                          strerror(errno)));
+       } else {
                /* Now stat the base file and merge the results. */
                ret = onefs_sys_fstat(base_fd, &base_sbuf);
                if (ret != -1) {
@@ -424,7 +402,7 @@ int onefs_fstat(vfs_handle_struct *handle, struct files_struct *fsp,
                }
        }
 
-       onefs_adjust_stat_time(handle->conn, fsp->fsp_name, sbuf);
+       onefs_adjust_stat_time(handle->conn, fsp->fsp_name->base_name, sbuf);
        return ret;
 }
 
@@ -463,14 +441,12 @@ int onefs_lstat(vfs_handle_struct *handle, struct smb_filename *smb_fname)
 }
 
 int onefs_unlink(vfs_handle_struct *handle,
-                 const struct smb_filename *smb_fname)
+                const struct smb_filename *smb_fname)
 {
        struct smb_filename *smb_fname_onefs = NULL;
        int ret;
-       bool is_stream;
-       char *base = NULL;
-       char *stream = NULL;
        int dir_fd, saved_errno;
+       NTSTATUS status;
 
        /* Not a stream. */
        if (!is_ntfs_stream_smb_fname(smb_fname)) {
@@ -520,10 +496,6 @@ int onefs_vtimes_streams(vfs_handle_struct *handle,
 
        START_PROFILE(syscall_ntimes);
 
-       ret = onefs_is_stream(fname, &base, &stream, &is_stream);
-       if (ret)
-               return ret;
-
        if (!is_ntfs_stream_smb_fname(smb_fname)) {
                ret = vtimes(smb_fname->base_name, times, flags);
                return ret;
@@ -654,7 +626,11 @@ static NTSTATUS walk_onefs_streams(connection_struct *conn, files_struct *fsp,
 
        fake_fs.conn = conn;
        fake_fs.fh = &fake_fh;
-       fake_fs.fsp_name = SMB_STRDUP(fname);
+       status = create_synthetic_smb_fname(talloc_tos(), fname, NULL, NULL,
+                                           &fake_fs.fsp_name);
+       if (!NT_STATUS_IS_OK(status)) {
+               goto out;
+       }
 
        /* Iterate over the streams in the ADS directory. */
        while ((dp = SMB_VFS_READDIR(conn, dirp, NULL)) != NULL) {
@@ -721,7 +697,7 @@ out:
                close(base_fd);
        }
 
-       SAFE_FREE(fake_fs.fsp_name);
+       TALLOC_FREE(fake_fs.fsp_name);
        return status;
 }