if (opts.inode != -1)
inode = ntfs_inode_open(vol, opts.inode);
- else
+ else {
+#ifdef HAVE_WINDOWS_H
+ char *unix_name;
+
+ unix_name = ntfs_utils_unix_path(opts.file);
+ if (unix_name) {
+ inode = ntfs_pathname_to_inode(vol, NULL,
+ unix_name);
+ free(unix_name);
+ } else
+ inode = (ntfs_inode*)NULL;
+#else
inode = ntfs_pathname_to_inode(vol, NULL, opts.file);
+#endif
+ }
if (!inode) {
ntfs_log_perror("ERROR: Couldn't open inode");
s64 br, bw;
ntfschar *attr_name;
int attr_name_len = 0;
+#ifdef HAVE_WINDOWS_H
+ char *unix_name;
+#endif
ntfs_log_set_handler(ntfs_log_handler_stderr);
goto close_src;
}
out = ntfs_inode_open(vol, inode_num);
- } else
+ } else {
+#ifdef HAVE_WINDOWS_H
+ unix_name = ntfs_utils_unix_path(opts.dest_file);
+ if (unix_name) {
+ out = ntfs_pathname_to_inode(vol, NULL, unix_name);
+ } else
+ out = (ntfs_inode*)NULL;
+#else
out = ntfs_pathname_to_inode(vol, NULL, opts.dest_file);
+#endif
+ }
if (!out) {
/* Copy the file if the dest_file's parent dir can be opened. */
char *parent_dirname;
ntfs_inode *ni;
char *dirname_last_whack;
+#ifdef HAVE_WINDOWS_H
+ filename = basename(unix_name);
+ parent_dirname = strdup(unix_name);
+#else
filename = basename(opts.dest_file);
parent_dirname = strdup(opts.dest_file);
+#endif
if (!parent_dirname) {
ntfs_log_perror("strdup() failed");
goto close_src;
ntfs_inode_close(out);
goto close_src;
}
+#ifdef HAVE_WINDOWS_H
+ strcpy(overwrite_filename, unix_name);
+#else
strcpy(overwrite_filename, opts.dest_file);
- if (opts.dest_file[dest_dirname_len - 1] != '/') {
+#endif
+ if (overwrite_filename[dest_dirname_len - 1] != '/') {
strcat(overwrite_filename, "/");
}
strcat(overwrite_filename, filename);
/* Open the specified inode. */
#ifdef HAVE_WINDOWS_H
- unix_name = (char*)malloc(strlen(file_name) + 1);
+ unix_name = ntfs_utils_unix_path(file_name);
if (unix_name) {
- int i;
- for (i=0; file_name[i]; i++)
- if (file_name[i] == '\\')
- unix_name[i] = '/';
- else
- unix_name[i] = file_name[i];
- unix_name[i] = 0;
ni = ntfs_pathname_to_inode(vol, NULL, unix_name);
free(unix_name);
} else
ntfs_inode *inode;
/* obtain the inode */
if (opts.filename) {
+#ifdef HAVE_WINDOWS_H
+ char *unix_name;
+
+ unix_name = ntfs_utils_unix_path(opts.filename);
+ if (unix_name) {
+ inode = ntfs_pathname_to_inode(vol, NULL,
+ unix_name);
+ free(unix_name);
+ } else
+ inode = (ntfs_inode*)NULL;
+#else
inode = ntfs_pathname_to_inode(vol, NULL,
opts.filename);
+#endif
} else {
inode = ntfs_inode_open(vol, MK_MREF(opts.inode, 0));
}
return (out);
}
+/*
+ * Translate paths to files submitted from Windows
+ *
+ * Translate Windows directory separators to Unix ones
+ *
+ * Returns the translated path, to be freed by caller
+ * NULL if there was an error, with errno set
+ */
+
+char *ntfs_utils_unix_path(const char *in)
+{
+ char *out;
+ int i;
+
+ out = strdup(in);
+ if (out) {
+ for (i=0; in[i]; i++)
+ if (in[i] == '\\')
+ out[i] = '/';
+ } else
+ errno = ENOMEM;
+ return (out);
+}
+
#endif
*/
#define MAX_FMT 1536
char *ntfs_utils_reformat(char *out, int sz, const char *fmt);
+char *ntfs_utils_unix_path(const char *in);
#define ntfs_log_redirect(fn,fi,li,le,d,fmt, args...) \
do { char buf[MAX_FMT]; ntfs_log_redirect(fn,fi,li,le,d, \
ntfs_utils_reformat(buf,MAX_FMT,fmt), args); } while (0)