From 40ea11d7785e3b4d7fedc86c90eba7e873531d87 Mon Sep 17 00:00:00 2001 From: d0k3 Date: Mon, 14 Mar 2016 17:22:53 +0100 Subject: [PATCH] Fix copying files to the root path --- source/fatfs/ffconf.h | 4 ++-- source/fs.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/source/fatfs/ffconf.h b/source/fatfs/ffconf.h index cc64648..64a99c9 100644 --- a/source/fatfs/ffconf.h +++ b/source/fatfs/ffconf.h @@ -127,7 +127,7 @@ / When _LFN_UNICODE is 0, this option has no effect. */ -#define _FS_RPATH 1 +#define _FS_RPATH 0 /* This option configures relative path feature. / / 0: Disable relative path feature and remove related functions. @@ -146,7 +146,7 @@ #define _STR_VOLUME_ID 0 -#define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3" +#define _VOLUME_STRS "SDCARD","CTRNAND_S","TWLN_S","TWLP_S","CTRNAND_E","TWLN_E","TWLP_E" // <--- improve(!!!) /* _STR_VOLUME_ID option switches string volume ID feature. / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive / number in the path name. _VOLUME_STRS defines the drive ID strings for each diff --git a/source/fs.c b/source/fs.c index 3ebb205..2549592 100644 --- a/source/fs.c +++ b/source/fs.c @@ -136,8 +136,11 @@ bool PathCopyWorker(char* dest, char* orig, bool overwrite) { bool ret = false; - if (f_stat(dest, &fno) != FR_OK) return false; // destination directory does not exist - if (!(fno.fattrib & AM_DIR)) return false; // destination is not a directory (must be at this point) + if (f_stat(dest, &fno) != FR_OK) { // is root or destination does not exist + DIR tmp_dir; // check if root + if (f_opendir(&tmp_dir, dest) != FR_OK) return false; + f_closedir(&tmp_dir); + } else if (!(fno.fattrib & AM_DIR)) return false; // destination is not a directory (must be at this point) if (f_stat(orig, &fno) != FR_OK) return false; // origin does not exist // build full destination path (on top of destination directory) @@ -150,8 +153,10 @@ bool PathCopyWorker(char* dest, char* orig, bool overwrite) { // check if destination is part of or equal origin if (strncmp(dest, orig, strnlen(orig, 255)) == 0) { - if ((dest[strnlen(orig, 255)] == '/') || (dest[strnlen(orig, 255)] == '\0')) + if ((dest[strnlen(orig, 255)] == '/') || (dest[strnlen(orig, 255)] == '\0')) { + ShowPrompt(false, "Error: Destination is part of origin"); return false; + } } // check if destination exists