+NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
+ const struct smb_filename *smb_fname_in,
+ struct smb_filename **smb_fname_out)
+{
+ char *stream_name = NULL;
+ NTSTATUS status;
+
+ /*
+ * Only attempt to strip off the trailing :$DATA if there is an actual
+ * stream there. If it is the default stream, the smb_fname_out will
+ * just have a NULL stream so the base file is opened.
+ */
+ if (smb_fname_in->stream_name &&
+ !is_ntfs_default_stream_smb_fname(smb_fname_in)) {
+ char *str_tmp = smb_fname_in->stream_name;
+
+ /* First strip off the leading ':' */
+ if (str_tmp[0] == ':') {
+ str_tmp++;
+ }
+
+ /* Create a new copy of the stream_name. */
+ stream_name = talloc_strdup(ctx, str_tmp);
+ if (stream_name == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ /* Strip off the :$DATA if one exists. */
+ str_tmp = strrchr_m(stream_name, ':');
+ if (str_tmp) {
+ str_tmp[0] = '\0';
+ }
+ }
+
+ /*
+ * If there was a stream that wasn't the default stream the leading
+ * colon and trailing :$DATA has now been stripped off. Create a new
+ * smb_filename to pass back.
+ */
+ status = create_synthetic_smb_fname(ctx, smb_fname_in->base_name,
+ stream_name, &smb_fname_in->st,
+ smb_fname_out);
+ TALLOC_FREE(stream_name);
+ return status;
+}
+