From d37bff58ca4b4f6e5d41772c4c466a8642e516ce Mon Sep 17 00:00:00 2001 From: Aurora Wright Date: Mon, 28 Aug 2017 03:04:20 +0200 Subject: [PATCH] Fix diskio/filewrite --- stage2/arm9/source/fatfs/diskio.c | 12 ++++++------ stage2/arm9/source/fs.c | 20 ++++++++------------ stage2/arm9/source/fs.h | 1 - 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/stage2/arm9/source/fatfs/diskio.c b/stage2/arm9/source/fatfs/diskio.c index 63a6a10..e0735ea 100644 --- a/stage2/arm9/source/fatfs/diskio.c +++ b/stage2/arm9/source/fatfs/diskio.c @@ -41,8 +41,8 @@ DSTATUS disk_initialize ( if(sdmmcInitResult == 4) sdmmcInitResult = sdmmc_sdcard_init(); - return ((pdrv == SDCARD && !(sdmmcInitResult & 2)) || - (pdrv == CTRNAND && !(sdmmcInitResult & 1) && !ctrNandInit())) ? 0 : STA_NOINIT; + return ((pdrv == SDCARD && !(sdmmcInitResult & 2)) || + (pdrv == CTRNAND && !(sdmmcInitResult & 1) && !ctrNandInit())) ? 0 : STA_NOINIT; } @@ -61,8 +61,8 @@ DRESULT disk_read ( UINT count /* Number of sectors to read */ ) { - return ((pdrv == SDCARD && !sdmmc_sdcard_readsectors(sector, count, buff)) || - (pdrv == CTRNAND && !ctrNandRead(sector, count, buff))) ? RES_OK : RES_PARERR; + return ((pdrv == SDCARD && !sdmmc_sdcard_readsectors(sector, count, buff)) || + (pdrv == CTRNAND && !ctrNandRead(sector, count, buff))) ? RES_OK : RES_PARERR; } @@ -83,7 +83,7 @@ DRESULT disk_write ( UINT count /* Number of sectors to write */ ) { - return (pdrv == SDCARD && !sdmmc_sdcard_writesectors(sector, count, buff)) ? RES_OK : RES_PARERR; + return (pdrv == SDCARD && (*(vu16 *)(SDMMC_BASE + REG_SDSTATUS0) & TMIO_STAT0_WRPROTECT) != 0 && !sdmmc_sdcard_writesectors(sector, count, buff)) ? RES_OK : RES_PARERR; } #endif @@ -103,6 +103,6 @@ DRESULT disk_ioctl ( void *buff /* Buffer to send/receive control data */ ) { - return RES_PARERR; + return cmd == CTRL_SYNC ? RES_OK : RES_PARERR; } #endif diff --git a/stage2/arm9/source/fs.c b/stage2/arm9/source/fs.c index 85960c1..9b3d7ab 100644 --- a/stage2/arm9/source/fs.c +++ b/stage2/arm9/source/fs.c @@ -3,7 +3,7 @@ */ #include "fs.h" -#include +#include "memory.h" #include "fatfs/ff.h" static FATFS fs; @@ -41,17 +41,18 @@ u32 fileRead(void *dest, const char *path, u32 size, u32 maxSize) bool fileWrite(const void *buffer, const char *path, u32 size) { FIL file; + FRESULT result; switch(f_open(&file, path, FA_WRITE | FA_OPEN_ALWAYS)) { case FR_OK: { unsigned int written; - f_write(&file, buffer, size, &written); - f_truncate(&file); - f_close(&file); + result = f_write(&file, buffer, size, &written); + if(result == FR_OK) result = f_truncate(&file); + result |= f_close(&file); - return (u32)written == size; + return result == FR_OK && (u32)written == size; } case FR_NO_PATH: for(u32 i = 1; path[i] != 0; i++) @@ -60,16 +61,11 @@ bool fileWrite(const void *buffer, const char *path, u32 size) char folder[i + 1]; memcpy(folder, path, i); folder[i] = 0; - f_mkdir(folder); + result = f_mkdir(folder); } - return fileWrite(buffer, path, size); + return result == FR_OK && fileWrite(buffer, path, size); default: return false; } } - -bool fileDelete(const char *path) -{ - return f_unlink(path) == FR_OK; -} diff --git a/stage2/arm9/source/fs.h b/stage2/arm9/source/fs.h index 2280934..667f958 100644 --- a/stage2/arm9/source/fs.h +++ b/stage2/arm9/source/fs.h @@ -11,4 +11,3 @@ void unmountSd(void); bool mountCtrNand(void); u32 fileRead(void *dest, const char *path, u32 size, u32 maxSize); bool fileWrite(const void *buffer, const char *path, u32 size); -bool fileDelete(const char *path);