Skip to content

Commit

Permalink
Fix diskio/filewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraWright committed Aug 28, 2017
1 parent f5e90ac commit d37bff5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
12 changes: 6 additions & 6 deletions stage2/arm9/source/fatfs/diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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;
}


Expand All @@ -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

Expand All @@ -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
20 changes: 8 additions & 12 deletions stage2/arm9/source/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

#include "fs.h"
#include <string.h>
#include "memory.h"
#include "fatfs/ff.h"

static FATFS fs;
Expand Down Expand Up @@ -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++)
Expand All @@ -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;
}
1 change: 0 additions & 1 deletion stage2/arm9/source/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit d37bff5

Please sign in to comment.