mirror of
https://github.com/Ryuzaki-MrL/savemii.git
synced 2026-04-25 07:22:28 -05:00
clang-format
This commit is contained in:
parent
004d405c4e
commit
db63c4452e
|
|
@ -6,15 +6,15 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/* Definitions of physical drive number for each drive */
|
||||
#define DEV_SD 0
|
||||
#define DEV_USB_EXT 1
|
||||
#define DEV_SD 0
|
||||
#define DEV_USB_EXT 1
|
||||
|
||||
#define DEV_SD_NAME "sd"
|
||||
#define DEV_SD_NAME "sd"
|
||||
#define DEV_USB_EXT_NAME "extusb"
|
||||
|
||||
#define SD_PATH "/dev/sdcard01"
|
||||
#define USB_EXT1_PATH "/dev/usb01"
|
||||
#define USB_EXT2_PATH "/dev/usb02"
|
||||
#define SD_PATH "/dev/sdcard01"
|
||||
#define USB_EXT1_PATH "/dev/usb01"
|
||||
#define USB_EXT2_PATH "/dev/usb02"
|
||||
|
||||
extern int deviceFds[FF_VOLUMES];
|
||||
extern const char *devicePaths[FF_VOLUMES];
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@
|
|||
/* storage control modules to the FatFs module with a defined API. */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#include "ff.h" /* Obtains integer types */
|
||||
#include "diskio.h" /* Declarations of disk functions */
|
||||
#include "diskio.h" /* Declarations of disk functions */
|
||||
#include "ff.h" /* Obtains integer types */
|
||||
#include "ffcache.h"
|
||||
|
||||
|
||||
|
|
@ -18,20 +18,20 @@
|
|||
|
||||
#if USE_RAMDISK == 0
|
||||
|
||||
#include <coreinit/filesystem.h>
|
||||
#include <coreinit/debug.h>
|
||||
#include <stdlib.h>
|
||||
#include <mocha/mocha.h>
|
||||
#include <mocha/fsa.h>
|
||||
#include <coreinit/filesystem.h>
|
||||
#include <coreinit/filesystem_fsa.h>
|
||||
#include <mocha/fsa.h>
|
||||
#include <mocha/mocha.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Some state has to be kept for the mounting of the devices. The cleanup is done by fat32.cpp.
|
||||
const char* fatDevPaths[FF_VOLUMES] = {"/dev/sdcard01", "/dev/usb01", "/dev/usb02"};
|
||||
const char *fatDevPaths[FF_VOLUMES] = {"/dev/sdcard01", "/dev/usb01", "/dev/usb02"};
|
||||
bool fatMounted[FF_VOLUMES] = {false, false, false};
|
||||
FSAClientHandle fatClients[FF_VOLUMES] = {};
|
||||
IOSHandle fatHandles[FF_VOLUMES] = {-1, -1, -1};
|
||||
const WORD fatSectorSizes[FF_VOLUMES] = {512, 512, 512};
|
||||
WORD fatCacheSizes[FF_VOLUMES] = {32*8*4*4, 32*8*4*8, 32*8*4};
|
||||
WORD fatCacheSizes[FF_VOLUMES] = {32 * 8 * 4 * 4, 32 * 8 * 4 * 8, 32 * 8 * 4};
|
||||
|
||||
|
||||
DSTATUS wiiu_mountDrive(BYTE pdrv) {
|
||||
|
|
@ -58,13 +58,13 @@ DSTATUS wiiu_unmountDrive(BYTE pdrv) {
|
|||
}
|
||||
|
||||
|
||||
FSError wiiu_readSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, BYTE* outputBuff) {
|
||||
FSError wiiu_readSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, BYTE *outputBuff) {
|
||||
FSError status = FSAEx_RawReadEx(fatClients[pdrv], outputBuff, fatSectorSizes[pdrv], sectorCount, sectorIdx, fatHandles[pdrv]);
|
||||
//OSReport("[CacheRead] buff=%x, idx=%u, cnt=%u; ret=%d\n", (void*)outputBuff, sectorIdx, sectorCount, status);
|
||||
return status;
|
||||
}
|
||||
|
||||
FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BYTE* inputBuff) {
|
||||
FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BYTE *inputBuff) {
|
||||
FSError status = FSAEx_RawWriteEx(fatClients[pdrv], inputBuff, fatSectorSizes[pdrv], sectorCount, sectorIdx, fatHandles[pdrv]);
|
||||
//OSReport("[CacheWrite] buff=%x, idx=%u, cnt=%u; ret=%d\n", (void*)inputBuff, sectorIdx, sectorCount, status);
|
||||
return status;
|
||||
|
|
@ -75,36 +75,33 @@ FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BY
|
|||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS disk_status(
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES)
|
||||
return STA_NOINIT;
|
||||
if (!fatMounted[pdrv]) {
|
||||
return STA_NOINIT;
|
||||
}
|
||||
uint8_t* headerBuff = aligned_alloc(0x40, fatSectorSizes[pdrv]);
|
||||
uint8_t *headerBuff = aligned_alloc(0x40, fatSectorSizes[pdrv]);
|
||||
FSError status = FSAEx_RawReadEx(fatClients[pdrv], headerBuff, fatSectorSizes[pdrv], 1, 0, fatHandles[pdrv]);
|
||||
free(headerBuff);
|
||||
|
||||
if (status != FS_ERROR_OK) OSReport("Non-zero status while getting disk status %d\n", status);
|
||||
if (status == FS_ERROR_WRITE_PROTECTED) return STA_PROTECT;
|
||||
if (status == FS_ERROR_MEDIA_NOT_READY) return STA_NODISK;
|
||||
if (status != FS_ERROR_OK) return STA_NOINIT;
|
||||
if (status != FS_ERROR_OK) return STA_NOINIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Initialize a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS disk_initialize(
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return STA_NOINIT;
|
||||
if (fatMounted[pdrv]) return STA_NOINIT;
|
||||
// todo: Support drives with non-512 sector sizes
|
||||
|
|
@ -116,10 +113,9 @@ DSTATUS disk_initialize (
|
|||
/* Shutdown a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_shutdown (
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS disk_shutdown(
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return STA_NOINIT;
|
||||
ffcache_shutdown(pdrv);
|
||||
if (!fatMounted[pdrv]) return STA_NOINIT;
|
||||
|
|
@ -127,18 +123,16 @@ DSTATUS disk_shutdown (
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
DRESULT disk_read(
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
|
|
@ -147,20 +141,18 @@ DRESULT disk_read (
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if FF_FS_READONLY == 0
|
||||
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
DRESULT disk_write(
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
|
|
@ -175,12 +167,11 @@ DRESULT disk_write (
|
|||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive number (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT disk_ioctl(
|
||||
BYTE pdrv, /* Physical drive number (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_ERROR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
|
|
@ -196,25 +187,25 @@ DRESULT disk_ioctl (
|
|||
return RES_OK;
|
||||
}
|
||||
case SET_CACHE_COUNT: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested changing the cache size to %d", *((WORD*)buff));
|
||||
fatCacheSizes[pdrv] = *((WORD*)buff);
|
||||
DEBUG_OSReport("[disk_ioctl] Requested changing the cache size to %d", *((WORD *) buff));
|
||||
fatCacheSizes[pdrv] = *((WORD *) buff);
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_SECTOR_COUNT: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested sector count!");
|
||||
// FSADeviceInfo deviceInfo = {};
|
||||
// if (FSAGetDeviceInfo(fatClients[pdrv], fatDevPaths[pdrv], &deviceInfo) != FS_ERROR_OK) return RES_ERROR;
|
||||
// *(LBA_t*)buff = deviceInfo.deviceSizeInSectors;
|
||||
// FSADeviceInfo deviceInfo = {};
|
||||
// if (FSAGetDeviceInfo(fatClients[pdrv], fatDevPaths[pdrv], &deviceInfo) != FS_ERROR_OK) return RES_ERROR;
|
||||
// *(LBA_t*)buff = deviceInfo.deviceSizeInSectors;
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_SECTOR_SIZE: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested sector size which is currently %d!", fatSectorSizes[pdrv]);
|
||||
*(WORD*)buff = (WORD)fatSectorSizes[pdrv];
|
||||
*(WORD *) buff = (WORD) fatSectorSizes[pdrv];
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_BLOCK_SIZE: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested block size which is unknown!");
|
||||
*(WORD*)buff = 1;
|
||||
*(WORD *) buff = 1;
|
||||
return RES_OK;
|
||||
}
|
||||
case CTRL_TRIM: {
|
||||
|
|
@ -225,7 +216,7 @@ DRESULT disk_ioctl (
|
|||
return RES_PARERR;
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
DWORD get_fattime() {
|
||||
|
|
@ -242,25 +233,25 @@ DWORD get_fattime() {
|
|||
#else
|
||||
|
||||
|
||||
#include <coreinit/filesystem.h>
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/filesystem.h>
|
||||
#include <memory.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
// Some state has to be kept for the mounting of the devices. The cleanup is done by fat32.cpp.
|
||||
bool fatMounted[FF_VOLUMES] = {false};
|
||||
|
||||
#define SPLIT_TOTAL_SIZE 10737418240
|
||||
#define SPLIT_TOTAL_SIZE_SECTORS (SPLIT_TOTAL_SIZE/512)
|
||||
#define SPLIT_IMAGE_COUNT 5
|
||||
#define SPLIT_IMAGE_SIZE_SECTORS (SPLIT_TOTAL_SIZE/SPLIT_IMAGE_COUNT/512)
|
||||
#define SPLIT_TOTAL_SIZE 10737418240
|
||||
#define SPLIT_TOTAL_SIZE_SECTORS (SPLIT_TOTAL_SIZE / 512)
|
||||
#define SPLIT_IMAGE_COUNT 5
|
||||
#define SPLIT_IMAGE_SIZE_SECTORS (SPLIT_TOTAL_SIZE / SPLIT_IMAGE_COUNT / 512)
|
||||
|
||||
FSFileHandle fatHandles[FF_VOLUMES][SPLIT_IMAGE_COUNT];
|
||||
const WORD fatSectorSizes[FF_VOLUMES] = {512};
|
||||
WORD fatCacheSizes[FF_VOLUMES] = {32*8*4};
|
||||
WORD fatCacheSizes[FF_VOLUMES] = {32 * 8 * 4};
|
||||
|
||||
FSClient* client;
|
||||
FSClient *client;
|
||||
FSCmdBlock fsCmd;
|
||||
|
||||
char sMountPath[0x80];
|
||||
|
|
@ -276,7 +267,7 @@ DSTATUS wiiu_mountDrive(BYTE pdrv) {
|
|||
FSMount(client, &fsCmd, &mountSource, sMountPath, sizeof(sMountPath), FS_ERROR_FLAG_ALL);
|
||||
|
||||
// Check raw disk image
|
||||
for (uint8_t i=0; i<SPLIT_IMAGE_COUNT; i++) {
|
||||
for (uint8_t i = 0; i < SPLIT_IMAGE_COUNT; i++) {
|
||||
char name[255];
|
||||
snprintf(name, 254, "%s/split%u.img", sMountPath, i);
|
||||
FSStatus result = FSOpenFile(client, &fsCmd, name, "r+", &fatHandles[pdrv][i], FS_ERROR_FLAG_ALL);
|
||||
|
|
@ -291,7 +282,7 @@ DSTATUS wiiu_mountDrive(BYTE pdrv) {
|
|||
}
|
||||
|
||||
DSTATUS wiiu_unmountDrive(BYTE pdrv) {
|
||||
for (uint8_t i=0; i<SPLIT_IMAGE_COUNT; i++) {
|
||||
for (uint8_t i = 0; i < SPLIT_IMAGE_COUNT; i++) {
|
||||
FSCloseFile(client, &fsCmd, fatHandles[pdrv][i], FS_ERROR_FLAG_ALL);
|
||||
}
|
||||
FSDelClient(client, 0);
|
||||
|
|
@ -301,9 +292,9 @@ DSTATUS wiiu_unmountDrive(BYTE pdrv) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
FSError wiiu_readSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, BYTE* outputBuff) {
|
||||
void* tempBuff = aligned_alloc(0x40, 1*fatSectorSizes[pdrv]);
|
||||
for (uint32_t i=0; i<sectorCount; i++) {
|
||||
FSError wiiu_readSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, BYTE *outputBuff) {
|
||||
void *tempBuff = aligned_alloc(0x40, 1 * fatSectorSizes[pdrv]);
|
||||
for (uint32_t i = 0; i < sectorCount; i++) {
|
||||
LBA_t currSectorIdx = sectorIdx + i;
|
||||
uint32_t fileIdx = 0;
|
||||
if (currSectorIdx != 0) {
|
||||
|
|
@ -311,17 +302,17 @@ FSError wiiu_readSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, BYTE* out
|
|||
currSectorIdx = currSectorIdx % SPLIT_IMAGE_SIZE_SECTORS;
|
||||
}
|
||||
|
||||
FSStatus status = FSReadFileWithPos(client, &fsCmd, tempBuff, 1*fatSectorSizes[pdrv], 1, currSectorIdx*fatSectorSizes[pdrv], fatHandles[pdrv][fileIdx], 0, FS_ERROR_FLAG_ALL);
|
||||
memcpy(outputBuff+(i*fatSectorSizes[pdrv]), tempBuff, 1*fatSectorSizes[pdrv]);
|
||||
FSStatus status = FSReadFileWithPos(client, &fsCmd, tempBuff, 1 * fatSectorSizes[pdrv], 1, currSectorIdx * fatSectorSizes[pdrv], fatHandles[pdrv][fileIdx], 0, FS_ERROR_FLAG_ALL);
|
||||
memcpy(outputBuff + (i * fatSectorSizes[pdrv]), tempBuff, 1 * fatSectorSizes[pdrv]);
|
||||
//DEBUG_OSReport("[CacheRead] buff=%x, idx=%u -> relativeIdx=%u, cnt=%u; ret=%d", (void*)outputBuff, sectorIdx, currSectorIdx, sectorCount, status);
|
||||
}
|
||||
free(tempBuff);
|
||||
return FS_ERROR_OK;
|
||||
}
|
||||
|
||||
FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BYTE* inputBuff) {
|
||||
void* tempBuff = aligned_alloc(0x40, 1*fatSectorSizes[pdrv]);
|
||||
for (uint32_t i=0; i<sectorCount; i++) {
|
||||
FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BYTE *inputBuff) {
|
||||
void *tempBuff = aligned_alloc(0x40, 1 * fatSectorSizes[pdrv]);
|
||||
for (uint32_t i = 0; i < sectorCount; i++) {
|
||||
LBA_t currSectorIdx = sectorIdx + i;
|
||||
uint32_t fileIdx = 0;
|
||||
if (currSectorIdx != 0) {
|
||||
|
|
@ -329,8 +320,8 @@ FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BY
|
|||
currSectorIdx = currSectorIdx % SPLIT_IMAGE_SIZE_SECTORS;
|
||||
}
|
||||
|
||||
memcpy(tempBuff, ((void*)inputBuff)+(i*fatSectorSizes[pdrv]), 1*fatSectorSizes[pdrv]);
|
||||
FSStatus status = FSWriteFileWithPos(client, &fsCmd, tempBuff, 1*fatSectorSizes[pdrv], 1, currSectorIdx*fatSectorSizes[pdrv], fatHandles[pdrv][fileIdx], 0, FS_ERROR_FLAG_ALL);
|
||||
memcpy(tempBuff, ((void *) inputBuff) + (i * fatSectorSizes[pdrv]), 1 * fatSectorSizes[pdrv]);
|
||||
FSStatus status = FSWriteFileWithPos(client, &fsCmd, tempBuff, 1 * fatSectorSizes[pdrv], 1, currSectorIdx * fatSectorSizes[pdrv], fatHandles[pdrv][fileIdx], 0, FS_ERROR_FLAG_ALL);
|
||||
//DEBUG_OSReport("[CacheWrite] buff=%x, idx=%u -> relativeIdx=%u, cnt=%u; ret=%d", (void*)inputBuff, sectorIdx, currSectorIdx, sectorCount, status);
|
||||
}
|
||||
free(tempBuff);
|
||||
|
|
@ -342,35 +333,32 @@ FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BY
|
|||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_status (
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS disk_status(
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES)
|
||||
return STA_NOINIT;
|
||||
if (!fatMounted[pdrv]) {
|
||||
return STA_NOINIT;
|
||||
}
|
||||
// uint8_t* headerBuff = aligned_alloc(0x40, fatSectorSizes[pdrv]);
|
||||
// FSError status = FSAEx_RawReadEx(fatClients[pdrv], headerBuff, fatSectorSizes[pdrv], 1, 0, fatHandles[pdrv]);
|
||||
// free(headerBuff);
|
||||
// if (status != FS_ERROR_OK) OSReport("Non-zero status while getting disk status %d\n", status);
|
||||
// if (status == FS_ERROR_WRITE_PROTECTED) return STA_PROTECT;
|
||||
// if (status == FS_ERROR_MEDIA_NOT_READY) return STA_NODISK;
|
||||
// if (status != FS_ERROR_OK) return STA_NOINIT;
|
||||
// uint8_t* headerBuff = aligned_alloc(0x40, fatSectorSizes[pdrv]);
|
||||
// FSError status = FSAEx_RawReadEx(fatClients[pdrv], headerBuff, fatSectorSizes[pdrv], 1, 0, fatHandles[pdrv]);
|
||||
// free(headerBuff);
|
||||
// if (status != FS_ERROR_OK) OSReport("Non-zero status while getting disk status %d\n", status);
|
||||
// if (status == FS_ERROR_WRITE_PROTECTED) return STA_PROTECT;
|
||||
// if (status == FS_ERROR_MEDIA_NOT_READY) return STA_NODISK;
|
||||
// if (status != FS_ERROR_OK) return STA_NOINIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Initialize a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_initialize (
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS disk_initialize(
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES)
|
||||
return STA_NOINIT;
|
||||
if (fatMounted[pdrv])
|
||||
|
|
@ -384,10 +372,9 @@ DSTATUS disk_initialize (
|
|||
/* Shutdown a Drive */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DSTATUS disk_shutdown (
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
)
|
||||
{
|
||||
DSTATUS disk_shutdown(
|
||||
BYTE pdrv /* Physical drive number to identify the drive */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES)
|
||||
return STA_NOINIT;
|
||||
ffcache_shutdown(pdrv);
|
||||
|
|
@ -397,18 +384,16 @@ DSTATUS disk_shutdown (
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Read Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_read (
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
)
|
||||
{
|
||||
DRESULT disk_read(
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
BYTE *buff, /* Data buffer to store read data */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to read */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
|
|
@ -417,20 +402,18 @@ DRESULT disk_read (
|
|||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Write Sector(s) */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#if FF_FS_READONLY == 0
|
||||
|
||||
DRESULT disk_write (
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
)
|
||||
{
|
||||
DRESULT disk_write(
|
||||
BYTE pdrv, /* Physical drive number to identify the drive */
|
||||
const BYTE *buff, /* Data to be written */
|
||||
LBA_t sector, /* Start sector in LBA */
|
||||
UINT count /* Number of sectors to write */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
|
|
@ -445,48 +428,47 @@ DRESULT disk_write (
|
|||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
DRESULT disk_ioctl (
|
||||
BYTE pdrv, /* Physical drive number (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
)
|
||||
{
|
||||
DRESULT disk_ioctl(
|
||||
BYTE pdrv, /* Physical drive number (0..) */
|
||||
BYTE cmd, /* Control code */
|
||||
void *buff /* Buffer to send/receive control data */
|
||||
) {
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_ERROR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
switch (cmd) {
|
||||
case CTRL_SYNC: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested a sync, flushing currently cached sectors!");
|
||||
for (uint8_t i=0; i<SPLIT_IMAGE_COUNT; i++) {
|
||||
for (uint8_t i = 0; i < SPLIT_IMAGE_COUNT; i++) {
|
||||
FSFlushFile(client, &fsCmd, fatHandles[pdrv][i], FS_ERROR_FLAG_ALL);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
case CTRL_FORCE_SYNC: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested a forced sync, flushing currently cached sectors!");
|
||||
for (uint8_t i=0; i<SPLIT_IMAGE_COUNT; i++) {
|
||||
for (uint8_t i = 0; i < SPLIT_IMAGE_COUNT; i++) {
|
||||
FSFlushFile(client, &fsCmd, fatHandles[pdrv][i], FS_ERROR_FLAG_ALL);
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
case SET_CACHE_COUNT: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested changing the cache size to %d", *((WORD*)buff));
|
||||
fatCacheSizes[pdrv] = *((WORD*)buff);
|
||||
DEBUG_OSReport("[disk_ioctl] Requested changing the cache size to %d", *((WORD *) buff));
|
||||
fatCacheSizes[pdrv] = *((WORD *) buff);
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_SECTOR_COUNT: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested sector count!");
|
||||
*(LBA_t*)buff = SPLIT_TOTAL_SIZE_SECTORS;
|
||||
*(LBA_t *) buff = SPLIT_TOTAL_SIZE_SECTORS;
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_SECTOR_SIZE: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested sector size which is currently %d!", fatSectorSizes[pdrv]);
|
||||
*(WORD*)buff = (WORD)fatSectorSizes[pdrv];
|
||||
*(WORD *) buff = (WORD) fatSectorSizes[pdrv];
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_BLOCK_SIZE: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested block size which is unknown!");
|
||||
*(WORD*)buff = 1;
|
||||
*(WORD *) buff = 1;
|
||||
return RES_OK;
|
||||
}
|
||||
case CTRL_TRIM: {
|
||||
|
|
|
|||
|
|
@ -11,78 +11,78 @@ extern "C" {
|
|||
|
||||
#include <coreinit/filesystem_fsa.h>
|
||||
|
||||
#define DEV_SD_REF 0
|
||||
#define DEV_USB01_REF 1
|
||||
#define DEV_USB02_REF 2
|
||||
#define DEV_SD_REF 0
|
||||
#define DEV_USB01_REF 1
|
||||
#define DEV_USB02_REF 2
|
||||
|
||||
extern bool fatMounted[FF_VOLUMES];
|
||||
extern const char* VolumeStr[FF_VOLUMES];
|
||||
extern const char *VolumeStr[FF_VOLUMES];
|
||||
|
||||
/* Status of Disk Functions */
|
||||
typedef BYTE DSTATUS;
|
||||
typedef BYTE DSTATUS;
|
||||
|
||||
/* Results of Disk Functions */
|
||||
typedef enum {
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
RES_OK = 0, /* 0: Successful */
|
||||
RES_ERROR, /* 1: R/W Error */
|
||||
RES_WRPRT, /* 2: Write Protected */
|
||||
RES_NOTRDY, /* 3: Not Ready */
|
||||
RES_PARERR /* 4: Invalid Parameter */
|
||||
} DRESULT;
|
||||
|
||||
/*---------------------------------------*/
|
||||
/* Prototypes for disk control functions */
|
||||
|
||||
FSError wiiu_readSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, BYTE* outputBuff);
|
||||
FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BYTE* inputBuff);
|
||||
FSError wiiu_readSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, BYTE *outputBuff);
|
||||
FSError wiiu_writeSectors(BYTE pdrv, LBA_t sectorIdx, UINT sectorCount, const BYTE *inputBuff);
|
||||
|
||||
|
||||
DSTATUS disk_initialize (BYTE pdrv);
|
||||
DSTATUS disk_shutdown (BYTE pdrv);
|
||||
DSTATUS disk_status (BYTE pdrv);
|
||||
DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
|
||||
DSTATUS disk_initialize(BYTE pdrv);
|
||||
DSTATUS disk_shutdown(BYTE pdrv);
|
||||
DSTATUS disk_status(BYTE pdrv);
|
||||
DRESULT disk_read(BYTE pdrv, BYTE *buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_write(BYTE pdrv, const BYTE *buff, LBA_t sector, UINT count);
|
||||
DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void *buff);
|
||||
|
||||
|
||||
/* Disk Status Bits (DSTATUS) */
|
||||
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
#define STA_NOINIT 0x01 /* Drive not initialized */
|
||||
#define STA_NODISK 0x02 /* No medium in the drive */
|
||||
#define STA_PROTECT 0x04 /* Write protected */
|
||||
|
||||
|
||||
/* Command code for disk_ioctrl function */
|
||||
|
||||
/* Generic command (Used by FatFs) */
|
||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
|
||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||
#define SET_CACHE_COUNT 69
|
||||
#define CTRL_FORCE_SYNC 70
|
||||
#define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */
|
||||
#define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */
|
||||
#define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */
|
||||
#define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */
|
||||
#define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */
|
||||
#define SET_CACHE_COUNT 69
|
||||
#define CTRL_FORCE_SYNC 70
|
||||
|
||||
/* Generic command (Not used by FatFs) */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||
#define CTRL_EJECT 7 /* Eject media */
|
||||
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||
#define CTRL_POWER 5 /* Get/Set power status */
|
||||
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
|
||||
#define CTRL_EJECT 7 /* Eject media */
|
||||
#define CTRL_FORMAT 8 /* Create physical format on the media */
|
||||
|
||||
/* MMC/SDC specific ioctl command */
|
||||
#define MMC_GET_TYPE 10 /* Get card type */
|
||||
#define MMC_GET_CSD 11 /* Get CSD */
|
||||
#define MMC_GET_CID 12 /* Get CID */
|
||||
#define MMC_GET_OCR 13 /* Get OCR */
|
||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
|
||||
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
|
||||
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
|
||||
#define MMC_GET_TYPE 10 /* Get card type */
|
||||
#define MMC_GET_CSD 11 /* Get CSD */
|
||||
#define MMC_GET_CID 12 /* Get CID */
|
||||
#define MMC_GET_OCR 13 /* Get OCR */
|
||||
#define MMC_GET_SDSTAT 14 /* Get SD status */
|
||||
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
|
||||
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
|
||||
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
|
||||
|
||||
/* ATA/CF specific ioctl command */
|
||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||
#define ATA_GET_MODEL 21 /* Get model name */
|
||||
#define ATA_GET_SN 22 /* Get serial number */
|
||||
#define ATA_GET_REV 20 /* Get F/W revision */
|
||||
#define ATA_GET_MODEL 21 /* Get model name */
|
||||
#define ATA_GET_SN 22 /* Get serial number */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
#include <sys/iosupport.h>
|
||||
#include "extusb_devoptab.h"
|
||||
#include "../devices.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/iosupport.h>
|
||||
#include <whb/log.h>
|
||||
#include <whb/log_console.h>
|
||||
#include "../devices.h"
|
||||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
@ -13,34 +13,34 @@ extern "C" {
|
|||
|
||||
static devoptab_t
|
||||
extusb_fs_devoptab =
|
||||
{
|
||||
.name = "sd",
|
||||
.structSize = sizeof(__extusb_fs_file_t),
|
||||
.open_r = __extusb_fs_open,
|
||||
.close_r = __extusb_fs_close,
|
||||
.write_r = __extusb_fs_write,
|
||||
.read_r = __extusb_fs_read,
|
||||
.seek_r = __extusb_fs_seek,
|
||||
.fstat_r = __extusb_fs_fstat,
|
||||
.stat_r = __extusb_fs_stat,
|
||||
.link_r = __extusb_fs_link,
|
||||
.unlink_r = __extusb_fs_unlink,
|
||||
.chdir_r = __extusb_fs_chdir,
|
||||
.rename_r = __extusb_fs_rename,
|
||||
.mkdir_r = __extusb_fs_mkdir,
|
||||
.dirStateSize = sizeof(__extusb_fs_dir_t),
|
||||
.diropen_r = __extusb_fs_diropen,
|
||||
.dirreset_r = __extusb_fs_dirreset,
|
||||
.dirnext_r = __extusb_fs_dirnext,
|
||||
.dirclose_r = __extusb_fs_dirclose,
|
||||
.statvfs_r = __extusb_fs_statvfs,
|
||||
.ftruncate_r = __extusb_fs_ftruncate,
|
||||
.fsync_r = __extusb_fs_fsync,
|
||||
.deviceData = NULL,
|
||||
.chmod_r = __extusb_fs_chmod,
|
||||
.fchmod_r = __extusb_fs_fchmod,
|
||||
.rmdir_r = __extusb_fs_rmdir,
|
||||
};
|
||||
{
|
||||
.name = "sd",
|
||||
.structSize = sizeof(__extusb_fs_file_t),
|
||||
.open_r = __extusb_fs_open,
|
||||
.close_r = __extusb_fs_close,
|
||||
.write_r = __extusb_fs_write,
|
||||
.read_r = __extusb_fs_read,
|
||||
.seek_r = __extusb_fs_seek,
|
||||
.fstat_r = __extusb_fs_fstat,
|
||||
.stat_r = __extusb_fs_stat,
|
||||
.link_r = __extusb_fs_link,
|
||||
.unlink_r = __extusb_fs_unlink,
|
||||
.chdir_r = __extusb_fs_chdir,
|
||||
.rename_r = __extusb_fs_rename,
|
||||
.mkdir_r = __extusb_fs_mkdir,
|
||||
.dirStateSize = sizeof(__extusb_fs_dir_t),
|
||||
.diropen_r = __extusb_fs_diropen,
|
||||
.dirreset_r = __extusb_fs_dirreset,
|
||||
.dirnext_r = __extusb_fs_dirnext,
|
||||
.dirclose_r = __extusb_fs_dirclose,
|
||||
.statvfs_r = __extusb_fs_statvfs,
|
||||
.ftruncate_r = __extusb_fs_ftruncate,
|
||||
.fsync_r = __extusb_fs_fsync,
|
||||
.deviceData = NULL,
|
||||
.chmod_r = __extusb_fs_chmod,
|
||||
.fchmod_r = __extusb_fs_fchmod,
|
||||
.rmdir_r = __extusb_fs_rmdir,
|
||||
};
|
||||
|
||||
static BOOL extusb_fs_initialised = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,16 +2,16 @@
|
|||
|
||||
#include <coreinit/filesystem.h>
|
||||
|
||||
#include "../ff.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/iosupport.h>
|
||||
#include <sys/param.h>
|
||||
#include <unistd.h>
|
||||
#include "../ff.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_chdir(struct _reent *r,
|
||||
const char *path) {
|
||||
int __extusb_fs_chdir(struct _reent *r,
|
||||
const char *path) {
|
||||
if (!path) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
#include <sys/stat.h>
|
||||
#include "extusb_devoptab.h"
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_chmod(struct _reent *r,
|
||||
const char *path,
|
||||
mode_t mode) {
|
||||
int __extusb_fs_chmod(struct _reent *r,
|
||||
const char *path,
|
||||
mode_t mode) {
|
||||
if (!path) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_dirclose(struct _reent *r,
|
||||
DIR_ITER *dirState) {
|
||||
int __extusb_fs_dirclose(struct _reent *r,
|
||||
DIR_ITER *dirState) {
|
||||
|
||||
if (!dirState) {
|
||||
r->_errno = EINVAL;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_dirnext(struct _reent *r,
|
||||
DIR_ITER *dirState,
|
||||
char *filename,
|
||||
struct stat *filestat) {
|
||||
int __extusb_fs_dirnext(struct _reent *r,
|
||||
DIR_ITER *dirState,
|
||||
char *filename,
|
||||
struct stat *filestat) {
|
||||
if (!dirState || !filename || !filestat) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_dirreset(struct _reent *r,
|
||||
DIR_ITER *dirState) {
|
||||
int __extusb_fs_dirreset(struct _reent *r,
|
||||
DIR_ITER *dirState) {
|
||||
if (!dirState) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_fchmod(struct _reent *r,
|
||||
void *fd,
|
||||
mode_t mode) {
|
||||
int __extusb_fs_fchmod(struct _reent *r,
|
||||
void *fd,
|
||||
mode_t mode) {
|
||||
if (!fd) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_fstat(struct _reent *r,
|
||||
void *fd,
|
||||
struct stat *st) {
|
||||
int __extusb_fs_fstat(struct _reent *r,
|
||||
void *fd,
|
||||
struct stat *st) {
|
||||
if (!fd || !st) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_fsync(struct _reent *r,
|
||||
void *fd) {
|
||||
int __extusb_fs_fsync(struct _reent *r,
|
||||
void *fd) {
|
||||
if (!fd) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_link(struct _reent *r,
|
||||
const char *existing,
|
||||
const char *newLink) {
|
||||
int __extusb_fs_link(struct _reent *r,
|
||||
const char *existing,
|
||||
const char *newLink) {
|
||||
r->_errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_mkdir(struct _reent *r,
|
||||
const char *path,
|
||||
int mode) {
|
||||
int __extusb_fs_mkdir(struct _reent *r,
|
||||
const char *path,
|
||||
int mode) {
|
||||
char *fixedPath;
|
||||
|
||||
if (!path) {
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_rename(struct _reent *r,
|
||||
const char *oldName,
|
||||
const char *newName) {
|
||||
int __extusb_fs_rename(struct _reent *r,
|
||||
const char *oldName,
|
||||
const char *newName) {
|
||||
char *fixedOldPath, *fixedNewPath;
|
||||
|
||||
if (!oldName || !newName) {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_rmdir(struct _reent *r,
|
||||
const char *name) {
|
||||
int __extusb_fs_rmdir(struct _reent *r,
|
||||
const char *name) {
|
||||
if (!name) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
off_t
|
||||
__extusb_fs_seek(struct _reent *r,
|
||||
void *fd,
|
||||
off_t pos,
|
||||
int whence) {
|
||||
uint64_t offset;;
|
||||
off_t __extusb_fs_seek(struct _reent *r,
|
||||
void *fd,
|
||||
off_t pos,
|
||||
int whence) {
|
||||
uint64_t offset;
|
||||
;
|
||||
|
||||
if (!fd) {
|
||||
r->_errno = EINVAL;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_stat(struct _reent *r,
|
||||
const char *path,
|
||||
struct stat *st) {
|
||||
int __extusb_fs_stat(struct _reent *r,
|
||||
const char *path,
|
||||
struct stat *st) {
|
||||
if (!path || !st) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_statvfs(struct _reent *r,
|
||||
const char *path,
|
||||
struct statvfs *buf) {
|
||||
int __extusb_fs_statvfs(struct _reent *r,
|
||||
const char *path,
|
||||
struct statvfs *buf) {
|
||||
//TODO: look up in FATFS struct
|
||||
r->_errno = ENOSYS;
|
||||
return -1;
|
||||
|
|
|
|||
|
|
@ -4,10 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_ftruncate(struct _reent *r,
|
||||
void *fd,
|
||||
off_t len) {
|
||||
int __extusb_fs_ftruncate(struct _reent *r,
|
||||
void *fd,
|
||||
off_t len) {
|
||||
// Make sure length is non-negative
|
||||
if (!fd || len < 0) {
|
||||
r->_errno = EINVAL;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_unlink(struct _reent *r,
|
||||
const char *name) {
|
||||
int __extusb_fs_unlink(struct _reent *r,
|
||||
const char *name) {
|
||||
char *fixedPath;
|
||||
|
||||
if (!name) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "extusb_devoptab.h"
|
||||
#include "../devices.h"
|
||||
#include "extusb_devoptab.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -1,14 +1,13 @@
|
|||
#include <time.h>
|
||||
#include "extusb_devoptab.h"
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_utimes(struct _reent *r,
|
||||
const char *filename,
|
||||
const struct timeval times[2]) {
|
||||
int __extusb_fs_utimes(struct _reent *r,
|
||||
const char *filename,
|
||||
const struct timeval times[2]) {
|
||||
if (!filename) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
|
|
|
|||
10520
src/fatfs/ff.c
10520
src/fatfs/ff.c
File diff suppressed because it is too large
Load Diff
408
src/fatfs/ff.h
408
src/fatfs/ff.h
|
|
@ -20,13 +20,13 @@
|
|||
|
||||
|
||||
#ifndef FF_DEFINED
|
||||
#define FF_DEFINED 86631 /* Revision ID */
|
||||
#define FF_DEFINED 86631 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
|
||||
#if FF_DEFINED != FFCONF_DEF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
|
|
@ -35,7 +35,7 @@ extern "C" {
|
|||
|
||||
/* Integer types used for FatFs API */
|
||||
|
||||
#if defined(_WIN32) /* Windows VC++ (for development only) */
|
||||
#if defined(_WIN32) /* Windows VC++ (for development only) */
|
||||
#define FF_INTDEF 2
|
||||
#include <windows.h>
|
||||
typedef unsigned __int64 QWORD;
|
||||
|
|
@ -43,23 +43,23 @@ typedef unsigned __int64 QWORD;
|
|||
#define isnan(v) _isnan(v)
|
||||
#define isinf(v) (!_finite(v))
|
||||
|
||||
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
||||
#elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */
|
||||
#define FF_INTDEF 2
|
||||
#include <stdint.h>
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||
typedef WORD WCHAR; /* UTF-16 character type */
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef uint16_t WORD; /* 16-bit unsigned integer */
|
||||
typedef uint32_t DWORD; /* 32-bit unsigned integer */
|
||||
typedef uint64_t QWORD; /* 64-bit unsigned integer */
|
||||
typedef WORD WCHAR; /* UTF-16 character type */
|
||||
|
||||
#else /* Earlier than C99 */
|
||||
#else /* Earlier than C99 */
|
||||
#define FF_INTDEF 1
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef unsigned short WORD; /* 16-bit unsigned integer */
|
||||
typedef unsigned long DWORD; /* 32-bit unsigned integer */
|
||||
typedef WORD WCHAR; /* UTF-16 character type */
|
||||
typedef unsigned int UINT; /* int must be 16-bit or 32-bit */
|
||||
typedef unsigned char BYTE; /* char must be 8-bit */
|
||||
typedef unsigned short WORD; /* 16-bit unsigned integer */
|
||||
typedef unsigned long DWORD; /* 32-bit unsigned integer */
|
||||
typedef WORD WCHAR; /* UTF-16 character type */
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -84,337 +84,323 @@ typedef DWORD LBA_t;
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
/* Type of path name strings on FatFs API (TCHAR) */
|
||||
|
||||
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
||||
#if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */
|
||||
typedef WCHAR TCHAR;
|
||||
#define _T(x) L ## x
|
||||
#define _TEXT(x) L ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
|
||||
#define _T(x) L##x
|
||||
#define _TEXT(x) L##x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) u8 ## x
|
||||
#define _TEXT(x) u8 ## x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
|
||||
#define _T(x) u8##x
|
||||
#define _TEXT(x) u8##x
|
||||
#elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */
|
||||
typedef DWORD TCHAR;
|
||||
#define _T(x) U ## x
|
||||
#define _TEXT(x) U ## x
|
||||
#define _T(x) U##x
|
||||
#define _TEXT(x) U##x
|
||||
#elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3)
|
||||
#error Wrong FF_LFN_UNICODE setting
|
||||
#else /* ANSI/OEM code in SBCS/DBCS */
|
||||
#else /* ANSI/OEM code in SBCS/DBCS */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
|
||||
extern PARTITION VolToPart[]; /* Volume - Partition mapping table */
|
||||
#endif
|
||||
|
||||
#if FF_STR_VOLUME_ID
|
||||
#ifndef FF_VOLUME_STRS
|
||||
extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||
extern const char *VolumeStr[FF_VOLUMES]; /* User defied volume ID */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Filesystem object structure (FATFS) */
|
||||
|
||||
typedef struct {
|
||||
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||
BYTE pdrv; /* Associated physical drive */
|
||||
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD signature; /* Stored Wii U drive signature */
|
||||
WORD id; /* Volume mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
WORD csize; /* Cluster size [sectors] */
|
||||
BYTE fs_type; /* Filesystem type (0:not mounted) */
|
||||
BYTE pdrv; /* Associated physical drive */
|
||||
BYTE n_fats; /* Number of FATs (1 or 2) */
|
||||
BYTE wflag; /* win[] flag (b0:dirty) */
|
||||
BYTE fsi_flag; /* FSINFO flags (b7:disabled, b0:dirty) */
|
||||
WORD signature; /* Stored Wii U drive signature */
|
||||
WORD id; /* Volume mount ID */
|
||||
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
|
||||
WORD csize; /* Cluster size [sectors] */
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if FF_USE_LFN
|
||||
WCHAR* lfnbuf; /* LFN working buffer */
|
||||
WCHAR *lfnbuf; /* LFN working buffer */
|
||||
#endif
|
||||
#if FF_FS_EXFAT
|
||||
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
||||
BYTE *dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
||||
#endif
|
||||
#if FF_FS_REENTRANT
|
||||
FF_SYNC_t sobj; /* Identifier of sync object */
|
||||
FF_SYNC_t sobj; /* Identifier of sync object */
|
||||
#endif
|
||||
#if !FF_FS_READONLY
|
||||
DWORD last_clst; /* Last allocated cluster */
|
||||
DWORD free_clst; /* Number of free clusters */
|
||||
DWORD last_clst; /* Last allocated cluster */
|
||||
DWORD free_clst; /* Number of free clusters */
|
||||
#endif
|
||||
#if FF_FS_RPATH
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
DWORD scannedDir; /* Which directory is currently cached, which can be utilized using f_chdir only */
|
||||
DWORD cdir; /* Current directory start cluster (0:root) */
|
||||
DWORD scannedDir; /* Which directory is currently cached, which can be utilized using f_chdir only */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
|
||||
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
|
||||
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
|
||||
DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */
|
||||
DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */
|
||||
DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */
|
||||
#endif
|
||||
#endif
|
||||
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||
DWORD fsize; /* Size of an FAT [sectors] */
|
||||
LBA_t volbase; /* Volume base sector */
|
||||
LBA_t fatbase; /* FAT base sector */
|
||||
LBA_t dirbase; /* Root directory base sector/cluster */
|
||||
LBA_t database; /* Data base sector */
|
||||
DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */
|
||||
DWORD fsize; /* Size of an FAT [sectors] */
|
||||
LBA_t volbase; /* Volume base sector */
|
||||
LBA_t fatbase; /* FAT base sector */
|
||||
LBA_t dirbase; /* Root directory base sector/cluster */
|
||||
LBA_t database; /* Data base sector */
|
||||
#if FF_FS_EXFAT
|
||||
LBA_t bitbase; /* Allocation bitmap base sector */
|
||||
LBA_t bitbase; /* Allocation bitmap base sector */
|
||||
#endif
|
||||
LBA_t winsect; /* Current sector appearing in the win[] */
|
||||
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
LBA_t winsect; /* Current sector appearing in the win[] */
|
||||
BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */
|
||||
} FATFS;
|
||||
|
||||
|
||||
|
||||
/* Object ID and allocation information (FFOBJID) */
|
||||
|
||||
typedef struct {
|
||||
FATFS* fs; /* Pointer to the hosting volume of this object */
|
||||
WORD id; /* Hosting volume mount ID */
|
||||
BYTE attr; /* Object attribute */
|
||||
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
||||
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
||||
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
||||
FATFS *fs; /* Pointer to the hosting volume of this object */
|
||||
WORD id; /* Hosting volume mount ID */
|
||||
BYTE attr; /* Object attribute */
|
||||
BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */
|
||||
DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */
|
||||
FSIZE_t objsize; /* Object size (valid when sclust != 0) */
|
||||
#if FF_FS_EXFAT
|
||||
DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
|
||||
DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
|
||||
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
|
||||
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
|
||||
DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
|
||||
DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */
|
||||
DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */
|
||||
DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */
|
||||
DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */
|
||||
DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */
|
||||
#endif
|
||||
#if FF_FS_LOCK
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */
|
||||
#endif
|
||||
} FFOBJID;
|
||||
|
||||
|
||||
|
||||
/* File object structure (FIL) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
|
||||
BYTE flag; /* File status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||
LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */
|
||||
BYTE flag; /* File status flags */
|
||||
BYTE err; /* Abort flag (error code) */
|
||||
FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */
|
||||
DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */
|
||||
LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */
|
||||
#if !FF_FS_READONLY
|
||||
LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||
BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||
LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */
|
||||
BYTE *dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
|
||||
#endif
|
||||
#if FF_USE_FASTSEEK
|
||||
DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
|
||||
DWORD *cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */
|
||||
#endif
|
||||
#if !FF_FS_TINY
|
||||
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
|
||||
BYTE buf[FF_MAX_SS]; /* File private data read/write window */
|
||||
#endif
|
||||
} FIL;
|
||||
|
||||
|
||||
|
||||
/* Directory object structure (DIR_FAT) */
|
||||
|
||||
typedef struct {
|
||||
FFOBJID obj; /* Object identifier */
|
||||
DWORD dptr; /* Current read/write offset */
|
||||
DWORD clust; /* Current cluster */
|
||||
LBA_t sect; /* Current sector (0:Read operation has terminated) */
|
||||
BYTE* dir; /* Pointer to the directory item in the win[] */
|
||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
FFOBJID obj; /* Object identifier */
|
||||
DWORD dptr; /* Current read/write offset */
|
||||
DWORD clust; /* Current cluster */
|
||||
LBA_t sect; /* Current sector (0:Read operation has terminated) */
|
||||
BYTE *dir; /* Pointer to the directory item in the win[] */
|
||||
BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */
|
||||
#if FF_USE_LFN
|
||||
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
|
||||
DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */
|
||||
#endif
|
||||
#if FF_USE_FIND
|
||||
const TCHAR* pat; /* Pointer to the name matching pattern */
|
||||
const TCHAR *pat; /* Pointer to the name matching pattern */
|
||||
#endif
|
||||
} DIR_FAT;
|
||||
|
||||
|
||||
|
||||
/* File information structure (FILINFO) */
|
||||
|
||||
typedef struct {
|
||||
FSIZE_t fsize; /* File size */
|
||||
WORD fdate; /* Modified date */
|
||||
WORD ftime; /* Modified time */
|
||||
BYTE fattrib; /* File attribute */
|
||||
FSIZE_t fsize; /* File size */
|
||||
WORD fdate; /* Modified date */
|
||||
WORD ftime; /* Modified time */
|
||||
BYTE fattrib; /* File attribute */
|
||||
#if FF_USE_LFN
|
||||
TCHAR altname[FF_SFN_BUF + 1];/* Altenative file name */
|
||||
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
||||
TCHAR altname[FF_SFN_BUF + 1]; /* Altenative file name */
|
||||
TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */
|
||||
#else
|
||||
TCHAR fname[12 + 1]; /* File name */
|
||||
TCHAR fname[12 + 1]; /* File name */
|
||||
#endif
|
||||
} FILINFO;
|
||||
|
||||
|
||||
|
||||
/* Format parameter structure (MKFS_PARM) */
|
||||
|
||||
typedef struct {
|
||||
BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
|
||||
BYTE n_fat; /* Number of FATs */
|
||||
UINT align; /* Data area alignment (sector) */
|
||||
UINT n_root; /* Number of root directory entries */
|
||||
DWORD au_size; /* Cluster size (byte) */
|
||||
BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */
|
||||
BYTE n_fat; /* Number of FATs */
|
||||
UINT align; /* Data area alignment (sector) */
|
||||
UINT n_root; /* Number of root directory entries */
|
||||
DWORD au_size; /* Cluster size (byte) */
|
||||
} MKFS_PARM;
|
||||
|
||||
|
||||
|
||||
/* File function return code (FRESULT) */
|
||||
|
||||
typedef enum {
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
FR_OK = 0, /* (0) Succeeded */
|
||||
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
||||
FR_INT_ERR, /* (2) Assertion failed */
|
||||
FR_NOT_READY, /* (3) The physical drive cannot work */
|
||||
FR_NO_FILE, /* (4) Could not find the file */
|
||||
FR_NO_PATH, /* (5) Could not find the path */
|
||||
FR_INVALID_NAME, /* (6) The path name format is invalid */
|
||||
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
||||
FR_EXIST, /* (8) Access denied due to prohibited access */
|
||||
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
||||
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
||||
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
||||
FR_NOT_ENABLED, /* (12) The volume has no work area */
|
||||
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
||||
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
||||
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
||||
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
||||
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
||||
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
||||
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||
} FRESULT;
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* FatFs module application interface */
|
||||
|
||||
FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close (FIL* fp); /* Close an open file object */
|
||||
FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */
|
||||
FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */
|
||||
FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate (FIL* fp); /* Truncate the file */
|
||||
FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir (DIR_FAT* dp, const TCHAR* path); /* Open a directory */
|
||||
FRESULT f_closedir (DIR_FAT* dp); /* Close an open directory */
|
||||
FRESULT f_readdir (DIR_FAT* dp, FILINFO* fno); /* Read a directory item */
|
||||
FRESULT f_findfirst (DIR_FAT* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */
|
||||
FRESULT f_findnext (DIR_FAT* dp, FILINFO* fno); /* Find next file */
|
||||
FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */
|
||||
FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */
|
||||
FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir (const TCHAR* path); /* Change current directory */
|
||||
FRESULT f_chdrive (const TCHAR* path); /* Change current drive */
|
||||
FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */
|
||||
FRESULT f_setlabel (const TCHAR* label); /* Set volume label */
|
||||
FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */
|
||||
FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
|
||||
FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */
|
||||
FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */
|
||||
FRESULT f_setcp (WORD cp); /* Set current code page */
|
||||
int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */
|
||||
int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */
|
||||
int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */
|
||||
TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */
|
||||
FRESULT f_open(FIL *fp, const TCHAR *path, BYTE mode); /* Open or create a file */
|
||||
FRESULT f_close(FIL *fp); /* Close an open file object */
|
||||
FRESULT f_read(FIL *fp, void *buff, UINT btr, UINT *br); /* Read data from the file */
|
||||
FRESULT f_write(FIL *fp, const void *buff, UINT btw, UINT *bw); /* Write data to the file */
|
||||
FRESULT f_lseek(FIL *fp, FSIZE_t ofs); /* Move file pointer of the file object */
|
||||
FRESULT f_truncate(FIL *fp); /* Truncate the file */
|
||||
FRESULT f_sync(FIL *fp); /* Flush cached data of the writing file */
|
||||
FRESULT f_opendir(DIR_FAT *dp, const TCHAR *path); /* Open a directory */
|
||||
FRESULT f_closedir(DIR_FAT *dp); /* Close an open directory */
|
||||
FRESULT f_readdir(DIR_FAT *dp, FILINFO *fno); /* Read a directory item */
|
||||
FRESULT f_findfirst(DIR_FAT *dp, FILINFO *fno, const TCHAR *path, const TCHAR *pattern); /* Find first file */
|
||||
FRESULT f_findnext(DIR_FAT *dp, FILINFO *fno); /* Find next file */
|
||||
FRESULT f_mkdir(const TCHAR *path); /* Create a sub directory */
|
||||
FRESULT f_unlink(const TCHAR *path); /* Delete an existing file or directory */
|
||||
FRESULT f_rename(const TCHAR *path_old, const TCHAR *path_new); /* Rename/Move a file or directory */
|
||||
FRESULT f_stat(const TCHAR *path, FILINFO *fno); /* Get file status */
|
||||
FRESULT f_chmod(const TCHAR *path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */
|
||||
FRESULT f_utime(const TCHAR *path, const FILINFO *fno); /* Change timestamp of a file/dir */
|
||||
FRESULT f_chdir(const TCHAR *path); /* Change current directory */
|
||||
FRESULT f_chdrive(const TCHAR *path); /* Change current drive */
|
||||
FRESULT f_getcwd(TCHAR *buff, UINT len); /* Get current directory */
|
||||
FRESULT f_getfree(const TCHAR *path, DWORD *nclst, FATFS **fatfs); /* Get number of free clusters on the drive */
|
||||
FRESULT f_getlabel(const TCHAR *path, TCHAR *label, DWORD *vsn); /* Get volume label */
|
||||
FRESULT f_setlabel(const TCHAR *label); /* Set volume label */
|
||||
FRESULT f_forward(FIL *fp, UINT (*func)(const BYTE *, UINT), UINT btf, UINT *bf); /* Forward data to the stream */
|
||||
FRESULT f_expand(FIL *fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */
|
||||
FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt); /* Mount/Unmount a logical drive */
|
||||
FRESULT f_mkfs(const TCHAR *path, const MKFS_PARM *opt, void *work, UINT len); /* Create a FAT volume */
|
||||
FRESULT f_fdisk(BYTE pdrv, const LBA_t ptbl[], void *work); /* Divide a physical drive into some partitions */
|
||||
FRESULT f_setcp(WORD cp); /* Set current code page */
|
||||
int f_putc(TCHAR c, FIL *fp); /* Put a character to the file */
|
||||
int f_puts(const TCHAR *str, FIL *cp); /* Put a string to the file */
|
||||
int f_printf(FIL *fp, const TCHAR *str, ...); /* Put a formatted string to the file */
|
||||
TCHAR *f_gets(TCHAR *buff, int len, FIL *fp); /* Get a string from the file */
|
||||
|
||||
#define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize))
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->obj.objsize)
|
||||
#define f_rewind(fp) f_lseek((fp), 0)
|
||||
#define f_eof(fp) ((int) ((fp)->fptr == (fp)->obj.objsize))
|
||||
#define f_error(fp) ((fp)->err)
|
||||
#define f_tell(fp) ((fp)->fptr)
|
||||
#define f_size(fp) ((fp)->obj.objsize)
|
||||
#define f_rewind(fp) f_lseek((fp), 0)
|
||||
#define f_rewinddir(dp) f_readdir((dp), 0)
|
||||
#define f_rmdir(path) f_unlink(path)
|
||||
#define f_rmdir(path) f_unlink(path)
|
||||
#define f_unmount(path) f_mount(0, path, 0)
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !FF_FS_READONLY && !FF_FS_NORTC
|
||||
DWORD get_fattime (void);
|
||||
DWORD get_fattime(void);
|
||||
#endif
|
||||
|
||||
/* LFN support functions */
|
||||
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
||||
WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
||||
WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
||||
DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
|
||||
#if FF_USE_LFN >= 1 /* Code conversion (defined in unicode.c) */
|
||||
WCHAR ff_oem2uni(WCHAR oem, WORD cp); /* OEM code to Unicode conversion */
|
||||
WCHAR ff_uni2oem(DWORD uni, WORD cp); /* Unicode to OEM code conversion */
|
||||
DWORD ff_wtoupper(DWORD uni); /* Unicode upper-case conversion */
|
||||
#endif
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
void* ff_memalloc (UINT msize); /* Allocate memory block */
|
||||
void ff_memfree (void* mblock); /* Free memory block */
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
void *ff_memalloc(UINT msize); /* Allocate memory block */
|
||||
void ff_memfree(void *mblock); /* Free memory block */
|
||||
#endif
|
||||
|
||||
/* Sync functions */
|
||||
#if FF_FS_REENTRANT
|
||||
int ff_cre_syncobj (BYTE vol, FF_SYNC_t* sobj); /* Create a sync object */
|
||||
int ff_req_grant (FF_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant (FF_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj (FF_SYNC_t sobj); /* Delete a sync object */
|
||||
int ff_cre_syncobj(BYTE vol, FF_SYNC_t *sobj); /* Create a sync object */
|
||||
int ff_req_grant(FF_SYNC_t sobj); /* Lock sync object */
|
||||
void ff_rel_grant(FF_SYNC_t sobj); /* Unlock sync object */
|
||||
int ff_del_syncobj(FF_SYNC_t sobj); /* Delete a sync object */
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Flags and offset address */
|
||||
|
||||
|
||||
/* File access mode and open method flags (3rd argument of f_open) */
|
||||
#define FA_READ 0x01
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA_OPEN_APPEND 0x30
|
||||
#define FA_READ 0x01
|
||||
#define FA_WRITE 0x02
|
||||
#define FA_OPEN_EXISTING 0x00
|
||||
#define FA_CREATE_NEW 0x04
|
||||
#define FA_CREATE_ALWAYS 0x08
|
||||
#define FA_OPEN_ALWAYS 0x10
|
||||
#define FA_OPEN_APPEND 0x30
|
||||
|
||||
/* Fast seek controls (2nd argument of f_lseek) */
|
||||
#define CREATE_LINKMAP ((FSIZE_t)0 - 1)
|
||||
#define CREATE_LINKMAP ((FSIZE_t) 0 - 1)
|
||||
|
||||
/* Format options (2nd argument of f_mkfs) */
|
||||
#define FM_FAT 0x01
|
||||
#define FM_FAT32 0x02
|
||||
#define FM_EXFAT 0x04
|
||||
#define FM_ANY 0x07
|
||||
#define FM_SFD 0x08
|
||||
#define FM_FAT 0x01
|
||||
#define FM_FAT32 0x02
|
||||
#define FM_EXFAT 0x04
|
||||
#define FM_ANY 0x07
|
||||
#define FM_SFD 0x08
|
||||
|
||||
/* Filesystem type (FATFS.fs_type) */
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
#define FS_EXFAT 4
|
||||
#define FS_FAT12 1
|
||||
#define FS_FAT16 2
|
||||
#define FS_FAT32 3
|
||||
#define FS_EXFAT 4
|
||||
|
||||
/* File attribute bits for directory entry (FILINFO.fattrib) */
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
#define AM_RDO 0x01 /* Read only */
|
||||
#define AM_HID 0x02 /* Hidden */
|
||||
#define AM_SYS 0x04 /* System */
|
||||
#define AM_DIR 0x10 /* Directory */
|
||||
#define AM_ARC 0x20 /* Archive */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
#include "ffcache.h"
|
||||
|
||||
#include <mocha/fsa.h>
|
||||
#include <memory.h>
|
||||
#include <coreinit/debug.h>
|
||||
#include <map>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
#include <unordered_map>
|
||||
#include <array>
|
||||
#include <coreinit/debug.h>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory.h>
|
||||
#include <mocha/fsa.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <chrono>
|
||||
#include <mutex>
|
||||
|
|
@ -19,8 +19,8 @@
|
|||
struct sectorCache {
|
||||
LBA_t sectorIdx = std::numeric_limits<LBA_t>::max();
|
||||
bool dirty = false;
|
||||
BYTE* buffer = nullptr;
|
||||
std::list<sectorCache*>::iterator it;
|
||||
BYTE *buffer = nullptr;
|
||||
std::list<sectorCache *>::iterator it;
|
||||
};
|
||||
|
||||
sectorCache emptySector = {};
|
||||
|
|
@ -30,11 +30,11 @@ struct driveCache {
|
|||
BYTE pdrv = 0;
|
||||
uint32_t sectorSize = 0;
|
||||
uint32_t sectorCount = 0;
|
||||
BYTE* sectorsBuffer = nullptr;
|
||||
BYTE *sectorsBuffer = nullptr;
|
||||
|
||||
std::vector<sectorCache*> freeSectors;
|
||||
std::list<sectorCache*> lruSectors;
|
||||
std::unordered_map<LBA_t, sectorCache*> cachedSectors;
|
||||
std::vector<sectorCache *> freeSectors;
|
||||
std::list<sectorCache *> lruSectors;
|
||||
std::unordered_map<LBA_t, sectorCache *> cachedSectors;
|
||||
|
||||
std::unordered_map<std::string, dirCache> cachedDirSFNs;
|
||||
std::unordered_map<std::u16string, dirCache> cachedDirLFNs;
|
||||
|
|
@ -42,48 +42,48 @@ struct driveCache {
|
|||
DWORD lastDirTable = 0xFFFFFFFF;
|
||||
DWORD cachedDirLastAllocatedIdx = 0;
|
||||
|
||||
sectorCache* activeCacheWindow = &emptySector;
|
||||
sectorCache *activeCacheWindow = &emptySector;
|
||||
};
|
||||
|
||||
std::array<driveCache, FF_VOLUMES> fatCaches;
|
||||
|
||||
static void cache_addLRUEntry(driveCache* cache, sectorCache *ptr) {
|
||||
static void cache_addLRUEntry(driveCache *cache, sectorCache *ptr) {
|
||||
ptr->it = cache->lruSectors.emplace(cache->lruSectors.end(), ptr);
|
||||
}
|
||||
|
||||
static sectorCache* cache_getLRUEntry(driveCache* cache) {
|
||||
static sectorCache *cache_getLRUEntry(driveCache *cache) {
|
||||
return cache->lruSectors.front();
|
||||
}
|
||||
|
||||
static void cache_makeMRU(driveCache* cache, sectorCache *ptr) {
|
||||
static void cache_makeMRU(driveCache *cache, sectorCache *ptr) {
|
||||
cache->lruSectors.splice(cache->lruSectors.end(), cache->lruSectors, ptr->it);
|
||||
}
|
||||
|
||||
static sectorCache* cache_getFreeSector(driveCache* cache) {
|
||||
static sectorCache *cache_getFreeSector(driveCache *cache) {
|
||||
if (cache->freeSectors.empty())
|
||||
return nullptr;
|
||||
|
||||
sectorCache* cached = cache->freeSectors.back();
|
||||
cache->freeSectors.resize(cache->freeSectors.size()-1);
|
||||
sectorCache *cached = cache->freeSectors.back();
|
||||
cache->freeSectors.resize(cache->freeSectors.size() - 1);
|
||||
return cached;
|
||||
}
|
||||
|
||||
static sectorCache* cache_getCachedSector(driveCache* cache, LBA_t sectorIdx) {
|
||||
static sectorCache *cache_getCachedSector(driveCache *cache, LBA_t sectorIdx) {
|
||||
if (auto it = cache->cachedSectors.find(sectorIdx); it != cache->cachedSectors.end())
|
||||
return it->second;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static uint32_t cache_getUncachedSectorCount(driveCache* cache, LBA_t sectorIdx, UINT maxSectorCount) {
|
||||
for (uint32_t i=0; i<maxSectorCount; i++) {
|
||||
if (cache_getCachedSector(cache, sectorIdx+i) != nullptr) {
|
||||
static uint32_t cache_getUncachedSectorCount(driveCache *cache, LBA_t sectorIdx, UINT maxSectorCount) {
|
||||
for (uint32_t i = 0; i < maxSectorCount; i++) {
|
||||
if (cache_getCachedSector(cache, sectorIdx + i) != nullptr) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return maxSectorCount;
|
||||
}
|
||||
|
||||
static DRESULT cache_doRawRead(driveCache* cache, LBA_t sectorIdx, UINT sectorCount, BYTE* outputBuff) {
|
||||
static DRESULT cache_doRawRead(driveCache *cache, LBA_t sectorIdx, UINT sectorCount, BYTE *outputBuff) {
|
||||
FSError res = wiiu_readSectors(cache->pdrv, sectorIdx, sectorCount, outputBuff);
|
||||
if (res == FS_ERROR_MEDIA_NOT_READY) {
|
||||
return RES_NOTRDY;
|
||||
|
|
@ -94,7 +94,7 @@ static DRESULT cache_doRawRead(driveCache* cache, LBA_t sectorIdx, UINT sectorCo
|
|||
return RES_OK;
|
||||
}
|
||||
|
||||
static DRESULT cache_doRawWrite(driveCache* cache, LBA_t sectorIdx, UINT sectorCount, const BYTE* inputBuff) {
|
||||
static DRESULT cache_doRawWrite(driveCache *cache, LBA_t sectorIdx, UINT sectorCount, const BYTE *inputBuff) {
|
||||
FSError res = wiiu_writeSectors(cache->pdrv, sectorIdx, sectorCount, inputBuff);
|
||||
if (res == FS_ERROR_MEDIA_NOT_READY) {
|
||||
return RES_NOTRDY;
|
||||
|
|
@ -105,10 +105,10 @@ static DRESULT cache_doRawWrite(driveCache* cache, LBA_t sectorIdx, UINT sectorC
|
|||
return RES_OK;
|
||||
}
|
||||
|
||||
static uint32_t cache_getFlushableRange(driveCache* cache, LBA_t sectorIdx) {
|
||||
static uint32_t cache_getFlushableRange(driveCache *cache, LBA_t sectorIdx) {
|
||||
uint32_t maxFlushableSectorCount = 512 < cache->sectorCount ? 512 : cache->sectorCount;
|
||||
for (uint32_t i=0; i<maxFlushableSectorCount; i++) {
|
||||
auto ptr = cache_getCachedSector(cache, sectorIdx+i);
|
||||
for (uint32_t i = 0; i < maxFlushableSectorCount; i++) {
|
||||
auto ptr = cache_getCachedSector(cache, sectorIdx + i);
|
||||
if (ptr == nullptr || !ptr->dirty) {
|
||||
return i;
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ static uint32_t cache_getFlushableRange(driveCache* cache, LBA_t sectorIdx) {
|
|||
return maxFlushableSectorCount;
|
||||
}
|
||||
|
||||
static void cache_flushSectorRange(driveCache* cache, sectorCache* sector) {
|
||||
static void cache_flushSectorRange(driveCache *cache, sectorCache *sector) {
|
||||
if (!sector->dirty)
|
||||
return;
|
||||
|
||||
|
|
@ -127,10 +127,10 @@ static void cache_flushSectorRange(driveCache* cache, sectorCache* sector) {
|
|||
}
|
||||
//OSReport("[ffcache] Flushed %u offset with %u count!\n", sector->sectorIdx, count);
|
||||
|
||||
BYTE* alignedBuffer = (BYTE*)aligned_alloc(0x40, count*cache->sectorSize);
|
||||
for (uint32_t i=0; i<count; i++) {
|
||||
auto writeSector = cache_getCachedSector(cache, sector->sectorIdx+i);
|
||||
memcpy(alignedBuffer+(i*cache->sectorSize), writeSector->buffer, cache->sectorSize);
|
||||
BYTE *alignedBuffer = (BYTE *) aligned_alloc(0x40, count * cache->sectorSize);
|
||||
for (uint32_t i = 0; i < count; i++) {
|
||||
auto writeSector = cache_getCachedSector(cache, sector->sectorIdx + i);
|
||||
memcpy(alignedBuffer + (i * cache->sectorSize), writeSector->buffer, cache->sectorSize);
|
||||
writeSector->dirty = false;
|
||||
}
|
||||
cache_doRawWrite(cache, sector->sectorIdx, count, alignedBuffer);
|
||||
|
|
@ -147,7 +147,7 @@ static void cache_flushSectorRange(driveCache* cache, sectorCache* sector) {
|
|||
// }
|
||||
//}
|
||||
|
||||
static sectorCache* cache_getNewUncachedSector(driveCache* cache, LBA_t sectorIdx) {
|
||||
static sectorCache *cache_getNewUncachedSector(driveCache *cache, LBA_t sectorIdx) {
|
||||
auto newSector = cache_getFreeSector(cache);
|
||||
if (newSector != nullptr) {
|
||||
newSector->sectorIdx = sectorIdx;
|
||||
|
|
@ -168,36 +168,36 @@ static sectorCache* cache_getNewUncachedSector(driveCache* cache, LBA_t sectorId
|
|||
return newSector;
|
||||
}
|
||||
|
||||
static void cache_writeSectors(driveCache* cache, LBA_t sectorIdx, UINT sectorCount, const BYTE* inputBuff) {
|
||||
for (uint32_t i=0; i<sectorCount; i++) {
|
||||
auto ptr = cache_getCachedSector(cache, sectorIdx+i);
|
||||
static void cache_writeSectors(driveCache *cache, LBA_t sectorIdx, UINT sectorCount, const BYTE *inputBuff) {
|
||||
for (uint32_t i = 0; i < sectorCount; i++) {
|
||||
auto ptr = cache_getCachedSector(cache, sectorIdx + i);
|
||||
if (ptr == nullptr)
|
||||
ptr = cache_getNewUncachedSector(cache, sectorIdx+i);
|
||||
memcpy(ptr->buffer, inputBuff+(i*cache->sectorSize), cache->sectorSize);
|
||||
ptr = cache_getNewUncachedSector(cache, sectorIdx + i);
|
||||
memcpy(ptr->buffer, inputBuff + (i * cache->sectorSize), cache->sectorSize);
|
||||
ptr->dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
static void cache_readSectors(driveCache* cache, LBA_t sectorIdx, UINT sectorCount, BYTE* outputBuff) {
|
||||
for (uint32_t i=0; i<sectorCount; i++) {
|
||||
sectorCache* ptr = cache_getCachedSector(cache, sectorIdx+i);
|
||||
static void cache_readSectors(driveCache *cache, LBA_t sectorIdx, UINT sectorCount, BYTE *outputBuff) {
|
||||
for (uint32_t i = 0; i < sectorCount; i++) {
|
||||
sectorCache *ptr = cache_getCachedSector(cache, sectorIdx + i);
|
||||
if (ptr != nullptr) {
|
||||
if (outputBuff != nullptr)
|
||||
memcpy(outputBuff+(i*cache->sectorSize), ptr->buffer, cache->sectorSize);
|
||||
memcpy(outputBuff + (i * cache->sectorSize), ptr->buffer, cache->sectorSize);
|
||||
cache_makeMRU(cache, ptr);
|
||||
continue;
|
||||
}
|
||||
uint32_t readRange = cache_getUncachedSectorCount(cache, sectorIdx+i, sectorCount-i);
|
||||
BYTE* alignedBuffer = (BYTE*)aligned_alloc(0x40, (sectorCount-i)*cache->sectorSize);
|
||||
cache_doRawRead(cache, sectorIdx+i, sectorCount-i, alignedBuffer);
|
||||
for (uint32_t f=i; f<i+readRange; f++) {
|
||||
sectorCache* newPtr = cache_getNewUncachedSector(cache, sectorIdx+f);
|
||||
memcpy(newPtr->buffer, alignedBuffer+((f-i)*cache->sectorSize), cache->sectorSize);
|
||||
uint32_t readRange = cache_getUncachedSectorCount(cache, sectorIdx + i, sectorCount - i);
|
||||
BYTE *alignedBuffer = (BYTE *) aligned_alloc(0x40, (sectorCount - i) * cache->sectorSize);
|
||||
cache_doRawRead(cache, sectorIdx + i, sectorCount - i, alignedBuffer);
|
||||
for (uint32_t f = i; f < i + readRange; f++) {
|
||||
sectorCache *newPtr = cache_getNewUncachedSector(cache, sectorIdx + f);
|
||||
memcpy(newPtr->buffer, alignedBuffer + ((f - i) * cache->sectorSize), cache->sectorSize);
|
||||
if (outputBuff != nullptr)
|
||||
memcpy(outputBuff+(i*cache->sectorSize), newPtr->buffer, cache->sectorSize);
|
||||
memcpy(outputBuff + (i * cache->sectorSize), newPtr->buffer, cache->sectorSize);
|
||||
}
|
||||
free(alignedBuffer);
|
||||
i += (readRange-1);
|
||||
i += (readRange - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -221,9 +221,9 @@ DRESULT ffcache_initialize(BYTE pdrv, DWORD sectorByteSize, DWORD sectorCount) {
|
|||
fatCaches[pdrv].lruSectors.clear();
|
||||
|
||||
// Initialize sectors with sector index far outside possible range to prevent them from being used
|
||||
fatCaches[pdrv].sectorsBuffer = (BYTE*)aligned_alloc(0x40, fatCaches[pdrv].sectorCount*fatCaches[pdrv].sectorSize);
|
||||
for (uint32_t i=0; i<sectorCount; i++) {
|
||||
fatCaches[pdrv].freeSectors.emplace_back(new sectorCache{.buffer = fatCaches[pdrv].sectorsBuffer+(i*fatCaches[pdrv].sectorSize)});
|
||||
fatCaches[pdrv].sectorsBuffer = (BYTE *) aligned_alloc(0x40, fatCaches[pdrv].sectorCount * fatCaches[pdrv].sectorSize);
|
||||
for (uint32_t i = 0; i < sectorCount; i++) {
|
||||
fatCaches[pdrv].freeSectors.emplace_back(new sectorCache{.buffer = fatCaches[pdrv].sectorsBuffer + (i * fatCaches[pdrv].sectorSize)});
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
|
@ -234,7 +234,7 @@ DRESULT ffcache_flushSectors(BYTE pdrv) {
|
|||
return RES_ERROR;
|
||||
|
||||
while (!cache->lruSectors.empty()) {
|
||||
sectorCache* sector = cache->lruSectors.front();
|
||||
sectorCache *sector = cache->lruSectors.front();
|
||||
cache_flushSectorRange(cache, sector);
|
||||
cache->cachedSectors.erase(sector->sectorIdx);
|
||||
cache->freeSectors.emplace_back(sector);
|
||||
|
|
@ -251,7 +251,7 @@ void ffcache_shutdown(BYTE pdrv) {
|
|||
// Delete all sectors
|
||||
ffcache_flushSectors(pdrv);
|
||||
while (!cache->freeSectors.empty()) {
|
||||
sectorCache* sector = cache->freeSectors.back();
|
||||
sectorCache *sector = cache->freeSectors.back();
|
||||
cache_flushSectorRange(cache, sector);
|
||||
cache->freeSectors.pop_back();
|
||||
delete sector;
|
||||
|
|
@ -281,20 +281,18 @@ DRESULT ffcache_writeSectors(BYTE pdrv, LBA_t sectorOffset, UINT sectorCount, co
|
|||
return RES_OK;
|
||||
}
|
||||
|
||||
BYTE* ffcache_getSector(BYTE pdrv, LBA_t sectorOffset) {
|
||||
driveCache* cache = &fatCaches[pdrv];
|
||||
sectorCache* sector = nullptr;
|
||||
BYTE *ffcache_getSector(BYTE pdrv, LBA_t sectorOffset) {
|
||||
driveCache *cache = &fatCaches[pdrv];
|
||||
sectorCache *sector = nullptr;
|
||||
if (fatCaches[pdrv].activeCacheWindow->sectorIdx == sectorOffset) {
|
||||
sector = fatCaches[pdrv].activeCacheWindow;
|
||||
cache_makeMRU(&fatCaches[pdrv], sector);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sector = cache_getCachedSector(cache, sectorOffset);
|
||||
if (sector == nullptr) {
|
||||
sector = cache_getNewUncachedSector(cache, sectorOffset);
|
||||
cache_doRawRead(cache, sectorOffset, 1, sector->buffer);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cache_makeMRU(&fatCaches[pdrv], sector);
|
||||
}
|
||||
fatCaches[pdrv].activeCacheWindow = sector;
|
||||
|
|
@ -304,15 +302,14 @@ BYTE* ffcache_getSector(BYTE pdrv, LBA_t sectorOffset) {
|
|||
}
|
||||
|
||||
|
||||
dirCache* dirCache_createSFN(BYTE pdrv, DIR_FAT* cache) {
|
||||
dirCache *dirCache_createSFN(BYTE pdrv, DIR_FAT *cache) {
|
||||
std::string keySFN(cache->fn, cache->fn + 11);
|
||||
DEBUG_OSReport("[dirCache] Added SFN for %.011s for cwd in %u with sect=%u, clust=%u, dptr=%u, blk_ofs=%u", keySFN.c_str(), cache->obj.sclust, cache->sect, cache->clust, cache->blk_ofs);
|
||||
auto [it, inserted] = fatCaches[pdrv].cachedDirSFNs.emplace(keySFN, dirCache{
|
||||
.cluster = cache->clust,
|
||||
.sectorOffset = cache->sect,
|
||||
.dirIdx = cache->dptr,
|
||||
.lfnStartDirIdx = cache->blk_ofs
|
||||
});
|
||||
.cluster = cache->clust,
|
||||
.sectorOffset = cache->sect,
|
||||
.dirIdx = cache->dptr,
|
||||
.lfnStartDirIdx = cache->blk_ofs});
|
||||
if (!inserted) {
|
||||
DEBUG_OSReport("Tried inserting shortname %.011s twice?!", cache->fn);
|
||||
OSSleepTicks(OSSecondsToTicks(3));
|
||||
|
|
@ -320,29 +317,28 @@ dirCache* dirCache_createSFN(BYTE pdrv, DIR_FAT* cache) {
|
|||
return &it->second;
|
||||
}
|
||||
|
||||
dirCache* dirCache_findSFN(BYTE pdrv, BYTE* sfnWithoutStatus) {
|
||||
auto it = fatCaches[pdrv].cachedDirSFNs.find(std::string(sfnWithoutStatus, sfnWithoutStatus+11));
|
||||
dirCache *dirCache_findSFN(BYTE pdrv, BYTE *sfnWithoutStatus) {
|
||||
auto it = fatCaches[pdrv].cachedDirSFNs.find(std::string(sfnWithoutStatus, sfnWithoutStatus + 11));
|
||||
if (it == fatCaches[pdrv].cachedDirSFNs.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
dirCache* dirCache_createLFN(BYTE pdrv, const WCHAR* fullName, DIR_FAT* cache) {
|
||||
std::u16string utf16KeyName((char16_t*)fullName);
|
||||
dirCache *dirCache_createLFN(BYTE pdrv, const WCHAR *fullName, DIR_FAT *cache) {
|
||||
std::u16string utf16KeyName((char16_t *) fullName);
|
||||
#if USE_DEBUG_STUBS
|
||||
std::string str;
|
||||
std::transform(utf16KeyName.begin(), utf16KeyName.end(), std::back_inserter(str), [](wchar_t c) {
|
||||
return (char)c;
|
||||
return (char) c;
|
||||
});
|
||||
DEBUG_OSReport("[dirCache] Added LFN for %.030s for cwd in %u with sect=%u, clust=%u, dptr=%u, blk_ofs=%u", str.c_str(), cache->obj.sclust, cache->sect, cache->clust, cache->blk_ofs);
|
||||
#endif
|
||||
auto [it, inserted] = fatCaches[pdrv].cachedDirLFNs.emplace(utf16KeyName, dirCache{
|
||||
.cluster = cache->clust,
|
||||
.sectorOffset = cache->sect,
|
||||
.dirIdx = cache->dptr,
|
||||
.lfnStartDirIdx = cache->blk_ofs
|
||||
});
|
||||
.cluster = cache->clust,
|
||||
.sectorOffset = cache->sect,
|
||||
.dirIdx = cache->dptr,
|
||||
.lfnStartDirIdx = cache->blk_ofs});
|
||||
#if USE_DEBUG_STUBS
|
||||
if (!inserted) {
|
||||
DEBUG_OSReport("Tried inserting shortname %.030s twice?!", str.c_str());
|
||||
|
|
@ -352,8 +348,8 @@ dirCache* dirCache_createLFN(BYTE pdrv, const WCHAR* fullName, DIR_FAT* cache) {
|
|||
return &it->second;
|
||||
}
|
||||
|
||||
dirCache* dirCache_findLFN(BYTE pdrv, const WCHAR* fullName) {
|
||||
auto it = fatCaches[pdrv].cachedDirLFNs.find((char16_t*)fullName);
|
||||
dirCache *dirCache_findLFN(BYTE pdrv, const WCHAR *fullName) {
|
||||
auto it = fatCaches[pdrv].cachedDirLFNs.find((char16_t *) fullName);
|
||||
if (it == fatCaches[pdrv].cachedDirLFNs.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -361,9 +357,6 @@ dirCache* dirCache_findLFN(BYTE pdrv, const WCHAR* fullName) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void dirCache_clear(BYTE pdrv) {
|
||||
DEBUG_OSReport("Clear dirCache!");
|
||||
fatCaches[pdrv].cachedDirLastAllocatedIdx = 0;
|
||||
|
|
@ -373,7 +366,6 @@ void dirCache_clear(BYTE pdrv) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
void dirCache_setLastAllocatedIdx(BYTE pdrv, DWORD lastIdx, DWORD lastDirTable) {
|
||||
if (lastDirTable == fatCaches[pdrv].lastDirTable) {
|
||||
if (lastIdx <= fatCaches[pdrv].cachedDirLastAllocatedIdx) {
|
||||
|
|
@ -381,8 +373,7 @@ void dirCache_setLastAllocatedIdx(BYTE pdrv, DWORD lastIdx, DWORD lastDirTable)
|
|||
//OSFatal("HOW CAN THE INDEX BE SMALLER?!\n");
|
||||
}
|
||||
fatCaches[pdrv].cachedDirLastAllocatedIdx = lastIdx;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fatCaches[pdrv].lastDirTable = lastDirTable;
|
||||
fatCaches[pdrv].cachedDirLastAllocatedIdx = 0;
|
||||
}
|
||||
|
|
@ -395,7 +386,7 @@ DWORD dirCache_getLastClusterIdx(BYTE pdrv, DWORD currDirTableIdx) {
|
|||
|
||||
|
||||
std::mutex _mutex;
|
||||
std::unordered_map<const char*, double> segmentTimes;
|
||||
std::unordered_map<const char *, double> segmentTimes;
|
||||
|
||||
uint64_t cache_getTime() {
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
|
|
@ -405,18 +396,18 @@ uint64_t profile_startSegment() {
|
|||
return cache_getTime();
|
||||
}
|
||||
|
||||
void profile_endSegment(const char* segmentName, uint64_t startTime) {
|
||||
void profile_endSegment(const char *segmentName, uint64_t startTime) {
|
||||
std::scoped_lock<std::mutex> lck(_mutex);
|
||||
double timeSpent = (double)(cache_getTime() - startTime);
|
||||
double timeSpent = (double) (cache_getTime() - startTime);
|
||||
segmentTimes[segmentName] += timeSpent;
|
||||
}
|
||||
|
||||
void profile_incrementCounter(const char* segmentName) {
|
||||
void profile_incrementCounter(const char *segmentName) {
|
||||
std::scoped_lock<std::mutex> lck(_mutex);
|
||||
segmentTimes[segmentName] += 1.0f;
|
||||
}
|
||||
|
||||
double profile_getSegment(const char* segmentName) {
|
||||
double profile_getSegment(const char *segmentName) {
|
||||
std::scoped_lock<std::mutex> lck(_mutex);
|
||||
double ret = segmentTimes[segmentName];
|
||||
segmentTimes[segmentName] = 0;
|
||||
|
|
@ -424,7 +415,6 @@ double profile_getSegment(const char* segmentName) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ff.h"
|
||||
#include "diskio.h"
|
||||
#include "ff.h"
|
||||
|
||||
DRESULT ffcache_initialize(BYTE pdrv, DWORD sectorByteSize, DWORD sectorCount);
|
||||
void ffcache_shutdown(BYTE pdrv);
|
||||
|
|
@ -15,21 +15,21 @@ DRESULT ffcache_readSectors(BYTE pdrv, LBA_t sectorOffset, UINT sectorCount, BYT
|
|||
DRESULT ffcache_writeSectors(BYTE pdrv, LBA_t sectorOffset, UINT sectorCount, const BYTE *bufferIn);
|
||||
DRESULT ffcache_flushSectors(BYTE pdrv);
|
||||
uint64_t cache_getTime();
|
||||
BYTE* ffcache_getSector(BYTE pdrv, LBA_t sectorOffset);
|
||||
BYTE *ffcache_getSector(BYTE pdrv, LBA_t sectorOffset);
|
||||
|
||||
typedef struct dirCache {
|
||||
DWORD cluster; // Which cluster this directory is located at
|
||||
LBA_t sectorOffset;
|
||||
DWORD dirIdx; // Offset from cluster start for this specific dir entry (cluster being a chain of file entries)
|
||||
DWORD lfnStartDirIdx;
|
||||
DWORD cluster; // Which cluster this directory is located at
|
||||
LBA_t sectorOffset;
|
||||
DWORD dirIdx; // Offset from cluster start for this specific dir entry (cluster being a chain of file entries)
|
||||
DWORD lfnStartDirIdx;
|
||||
} dirCache;
|
||||
|
||||
|
||||
dirCache* dirCache_createSFN(BYTE pdrv, DIR_FAT* cache);
|
||||
dirCache* dirCache_findSFN(BYTE pdrv, BYTE* sfnWithoutStatus);
|
||||
dirCache *dirCache_createSFN(BYTE pdrv, DIR_FAT *cache);
|
||||
dirCache *dirCache_findSFN(BYTE pdrv, BYTE *sfnWithoutStatus);
|
||||
|
||||
dirCache* dirCache_createLFN(BYTE pdrv, const WCHAR* fullName, DIR_FAT* cache);
|
||||
dirCache* dirCache_findLFN(BYTE pdrv, const WCHAR* fullName);
|
||||
dirCache *dirCache_createLFN(BYTE pdrv, const WCHAR *fullName, DIR_FAT *cache);
|
||||
dirCache *dirCache_findLFN(BYTE pdrv, const WCHAR *fullName);
|
||||
|
||||
void dirCache_setLastAllocatedIdx(BYTE pdrv, DWORD lastIdx, DWORD lastDirTable);
|
||||
DWORD dirCache_getLastClusterIdx(BYTE pdrv, DWORD currDirTableIdx);
|
||||
|
|
@ -37,22 +37,30 @@ void dirCache_clear(BYTE pdrv);
|
|||
|
||||
|
||||
#if USE_DEBUG_STUBS
|
||||
#define DEBUG_OSReport(fmt, args...) OSReport(fmt "\n", ## args)
|
||||
#define DEBUG_OSReport(fmt, args...) OSReport(fmt "\n", ##args)
|
||||
#else
|
||||
#define DEBUG_OSReport(fmt, args...) do {} while (false)
|
||||
#define DEBUG_OSReport(fmt, args...) \
|
||||
do { \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
uint64_t profile_startSegment();
|
||||
void profile_incrementCounter(const char* segmentName);
|
||||
void profile_endSegment(const char* segmentName, uint64_t startTime);
|
||||
void profile_incrementCounter(const char *segmentName);
|
||||
void profile_endSegment(const char *segmentName, uint64_t startTime);
|
||||
#if USE_DEBUG_STUBS
|
||||
#define DEBUG_profile_startSegment(sectionName) uint64_t sectionName##Time = profile_startSegment();
|
||||
#define DEBUG_profile_endSegment(sectionName) profile_endSegment( #sectionName "Time" , sectionName##Time );
|
||||
#define DEBUG_profile_incrementCounter(counterName) profile_incrementCounter( #counterName );
|
||||
#define DEBUG_profile_startSegment(sectionName) uint64_t sectionName##Time = profile_startSegment();
|
||||
#define DEBUG_profile_endSegment(sectionName) profile_endSegment(#sectionName "Time", sectionName##Time);
|
||||
#define DEBUG_profile_incrementCounter(counterName) profile_incrementCounter(#counterName);
|
||||
#else
|
||||
#define DEBUG_profile_startSegment(sectionName) do {} while (false)
|
||||
#define DEBUG_profile_endSegment(sectionName) do {} while (false)
|
||||
#define DEBUG_profile_incrementCounter(counterName) do {} while (false)
|
||||
#define DEBUG_profile_startSegment(sectionName) \
|
||||
do { \
|
||||
} while (false)
|
||||
#define DEBUG_profile_endSegment(sectionName) \
|
||||
do { \
|
||||
} while (false)
|
||||
#define DEBUG_profile_incrementCounter(counterName) \
|
||||
do { \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,20 @@
|
|||
/ FatFs Functional Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FFCONF_DEF 86631 /* Revision ID */
|
||||
#define FFCONF_DEF 86631 /* Revision ID */
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Function Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_FS_READONLY 0
|
||||
#define FF_FS_READONLY 0
|
||||
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
|
||||
/ Read-only configuration removes writing API functions, f_write(), f_sync(),
|
||||
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
|
||||
/ and optional writing functions as well. */
|
||||
|
||||
|
||||
#define FF_FS_MINIMIZE 0
|
||||
#define FF_FS_MINIMIZE 0
|
||||
/* This option defines minimization level to remove some basic API functions.
|
||||
/
|
||||
/ 0: Basic functions are fully enabled.
|
||||
|
|
@ -25,41 +25,41 @@
|
|||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
|
||||
#define FF_USE_FIND 0
|
||||
#define FF_USE_FIND 0
|
||||
/* This option switches filtered directory read functions, f_findfirst() and
|
||||
/ f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */
|
||||
|
||||
|
||||
#define FF_USE_MKFS 0
|
||||
#define FF_USE_MKFS 0
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_FASTSEEK 0
|
||||
#define FF_USE_FASTSEEK 0
|
||||
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_EXPAND 1
|
||||
#define FF_USE_EXPAND 1
|
||||
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_CHMOD 1
|
||||
#define FF_USE_CHMOD 1
|
||||
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
|
||||
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
|
||||
|
||||
|
||||
#define FF_USE_LABEL 1
|
||||
#define FF_USE_LABEL 1
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_FORWARD 0
|
||||
#define FF_USE_FORWARD 0
|
||||
/* This option switches f_forward() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_STRFUNC 0
|
||||
#define FF_PRINT_LLI 0
|
||||
#define FF_PRINT_FLOAT 0
|
||||
#define FF_STRF_ENCODE 0
|
||||
#define FF_USE_STRFUNC 0
|
||||
#define FF_PRINT_LLI 0
|
||||
#define FF_PRINT_FLOAT 0
|
||||
#define FF_STRF_ENCODE 0
|
||||
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
|
||||
/ f_printf().
|
||||
/
|
||||
|
|
@ -84,7 +84,7 @@
|
|||
/ Locale and Namespace Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_CODE_PAGE 932
|
||||
#define FF_CODE_PAGE 932
|
||||
/* This option specifies the OEM code page to be used on the target system.
|
||||
/ Incorrect code page setting can cause a file open failure.
|
||||
/
|
||||
|
|
@ -113,8 +113,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#define FF_USE_LFN 2
|
||||
#define FF_MAX_LFN 255
|
||||
#define FF_USE_LFN 2
|
||||
#define FF_MAX_LFN 255
|
||||
/* The FF_USE_LFN switches the support for LFN (long file name).
|
||||
/
|
||||
/ 0: Disable LFN. FF_MAX_LFN has no effect.
|
||||
|
|
@ -133,7 +133,7 @@
|
|||
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
|
||||
|
||||
|
||||
#define FF_LFN_UNICODE 0
|
||||
#define FF_LFN_UNICODE 0
|
||||
/* This option switches the character encoding on the API when LFN is enabled.
|
||||
/
|
||||
/ 0: ANSI/OEM in current CP (TCHAR = char)
|
||||
|
|
@ -145,15 +145,15 @@
|
|||
/ When LFN is not enabled, this option has no effect. */
|
||||
|
||||
|
||||
#define FF_LFN_BUF 255
|
||||
#define FF_SFN_BUF 12
|
||||
#define FF_LFN_BUF 255
|
||||
#define FF_SFN_BUF 12
|
||||
/* This set of options defines size of file name members in the FILINFO structure
|
||||
/ which is used to read out directory items. These values should be sufficient for
|
||||
/ the file names to read. The maximum possible length of the read file name depends
|
||||
/ on character encoding. When LFN is not enabled, these options have no effect. */
|
||||
|
||||
|
||||
#define FF_FS_RPATH 1
|
||||
#define FF_FS_RPATH 1
|
||||
/* This option configures support for relative path.
|
||||
/
|
||||
/ 0: Disable relative path and remove related functions.
|
||||
|
|
@ -167,14 +167,14 @@
|
|||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#if USE_RAMDISK == 1
|
||||
#define FF_VOLUMES 1
|
||||
#define FF_VOLUMES 1
|
||||
#else
|
||||
#define FF_VOLUMES 3
|
||||
#define FF_VOLUMES 3
|
||||
#endif
|
||||
/* Number of volumes (logical drives) to be used. (1-10) */
|
||||
|
||||
|
||||
#define FF_STR_VOLUME_ID 0
|
||||
#define FF_STR_VOLUME_ID 0
|
||||
// #define FF_VOLUME_STRS "sdcard01","usb01","usb02"
|
||||
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
|
||||
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
|
||||
|
|
@ -188,7 +188,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#define FF_MULTI_PARTITION 0
|
||||
#define FF_MULTI_PARTITION 0
|
||||
/* This option switches support for multiple volumes on the physical drive.
|
||||
/ By default (0), each logical drive number is bound to the same physical drive
|
||||
/ number and only an FAT volume found on the physical drive will be mounted.
|
||||
|
|
@ -197,8 +197,8 @@
|
|||
/ funciton will be available. */
|
||||
|
||||
|
||||
#define FF_MIN_SS 512
|
||||
#define FF_MAX_SS 512
|
||||
#define FF_MIN_SS 512
|
||||
#define FF_MAX_SS 512
|
||||
/* This set of options configures the range of sector size to be supported. (512,
|
||||
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
|
||||
/ harddisk, but a larger value may be required for on-board flash memory and some
|
||||
|
|
@ -207,44 +207,43 @@
|
|||
/ GET_SECTOR_SIZE command. */
|
||||
|
||||
|
||||
#define FF_LBA64 0
|
||||
#define FF_LBA64 0
|
||||
/* This option switches support for 64-bit LBA. (0:Disable or 1:Enable)
|
||||
/ To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */
|
||||
|
||||
|
||||
#define FF_MIN_GPT 0x10000000
|
||||
#define FF_MIN_GPT 0x10000000
|
||||
/* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and
|
||||
/ f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */
|
||||
|
||||
|
||||
#define FF_USE_TRIM 0
|
||||
#define FF_USE_TRIM 0
|
||||
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
|
||||
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
|
||||
/ disk_ioctl() function. */
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ System Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FF_FS_TINY 0
|
||||
#define FF_FS_TINY 0
|
||||
/* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
|
||||
/ At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes.
|
||||
/ Instead of private sector buffer eliminated from the file object, common sector
|
||||
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */
|
||||
|
||||
|
||||
#define FF_FS_EXFAT 0
|
||||
#define FF_FS_EXFAT 0
|
||||
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
|
||||
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
|
||||
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
|
||||
|
||||
|
||||
#define FF_FS_NORTC 0
|
||||
#define FF_NORTC_MON 1
|
||||
#define FF_NORTC_MDAY 1
|
||||
#define FF_NORTC_YEAR 2020
|
||||
#define FF_FS_NORTC 0
|
||||
#define FF_NORTC_MON 1
|
||||
#define FF_NORTC_MDAY 1
|
||||
#define FF_NORTC_YEAR 2020
|
||||
/* The option FF_FS_NORTC switches timestamp functiton. If the system does not have
|
||||
/ any RTC function or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable
|
||||
/ the timestamp function. Every object modified by FatFs will have a fixed timestamp
|
||||
|
|
@ -255,7 +254,7 @@
|
|||
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
|
||||
|
||||
|
||||
#define FF_FS_NOFSINFO 0
|
||||
#define FF_FS_NOFSINFO 0
|
||||
/* If you need to know correct free space on the FAT32 volume, set bit 0 of this
|
||||
/ option, and f_getfree() function at first time after volume mount will force
|
||||
/ a full FAT scan. Bit 1 controls the use of last allocated cluster number.
|
||||
|
|
@ -267,7 +266,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#define FF_FS_LOCK 0
|
||||
#define FF_FS_LOCK 0
|
||||
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
|
||||
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
|
||||
/ is 1.
|
||||
|
|
@ -280,9 +279,9 @@
|
|||
|
||||
|
||||
/* #include <somertos.h> // O/S definitions */
|
||||
#define FF_FS_REENTRANT 0
|
||||
#define FF_FS_TIMEOUT 1000
|
||||
#define FF_SYNC_t HANDLE
|
||||
#define FF_FS_REENTRANT 0
|
||||
#define FF_FS_TIMEOUT 1000
|
||||
#define FF_SYNC_t HANDLE
|
||||
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
|
||||
/ module itself. Note that regardless of this option, file access to different
|
||||
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
|
||||
|
|
@ -301,5 +300,4 @@
|
|||
/ included somewhere in the scope of ff.h. */
|
||||
|
||||
|
||||
|
||||
/*--- End of configuration options ---*/
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
#include "ff.h"
|
||||
|
||||
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate a memory block */
|
||||
|
|
@ -15,11 +15,10 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
|
||||
void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */
|
||||
UINT msize /* Number of bytes to allocate */
|
||||
)
|
||||
{
|
||||
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||
void *ff_memalloc( /* Returns pointer to the allocated memory block (null if not enough core) */
|
||||
UINT msize /* Number of bytes to allocate */
|
||||
) {
|
||||
return malloc(msize); /* Allocate a new memory block with POSIX API */
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -27,18 +26,16 @@ void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if no
|
|||
/* Free a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
void ff_memfree (
|
||||
void* mblock /* Pointer to the memory block to free (nothing to do if null) */
|
||||
)
|
||||
{
|
||||
free(mblock); /* Free the memory block with POSIX API */
|
||||
void ff_memfree(
|
||||
void *mblock /* Pointer to the memory block to free (nothing to do if null) */
|
||||
) {
|
||||
free(mblock); /* Free the memory block with POSIX API */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if FF_FS_REENTRANT /* Mutal exclusion */
|
||||
#if FF_FS_REENTRANT /* Mutal exclusion */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Create a Synchronization Object */
|
||||
|
|
@ -51,32 +48,31 @@ void ff_memfree (
|
|||
//const osMutexDef_t Mutex[FF_VOLUMES]; /* Table of CMSIS-RTOS mutex */
|
||||
|
||||
|
||||
int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object */
|
||||
BYTE vol, /* Corresponding volume (logical drive number) */
|
||||
FF_SYNC_t* sobj /* Pointer to return the created sync object */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
*sobj = CreateMutex(NULL, FALSE, NULL);
|
||||
return (int)(*sobj != INVALID_HANDLE_VALUE);
|
||||
int ff_cre_syncobj( /* 1:Function succeeded, 0:Could not create the sync object */
|
||||
BYTE vol, /* Corresponding volume (logical drive number) */
|
||||
FF_SYNC_t *sobj /* Pointer to return the created sync object */
|
||||
) {
|
||||
/* Win32 */
|
||||
*sobj = CreateMutex(NULL, FALSE, NULL);
|
||||
return (int) (*sobj != INVALID_HANDLE_VALUE);
|
||||
|
||||
/* uITRON */
|
||||
// T_CSEM csem = {TA_TPRI,1,1};
|
||||
// *sobj = acre_sem(&csem);
|
||||
// return (int)(*sobj > 0);
|
||||
/* uITRON */
|
||||
// T_CSEM csem = {TA_TPRI,1,1};
|
||||
// *sobj = acre_sem(&csem);
|
||||
// return (int)(*sobj > 0);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// *sobj = OSMutexCreate(0, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// *sobj = OSMutexCreate(0, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// *sobj = xSemaphoreCreateMutex();
|
||||
// return (int)(*sobj != NULL);
|
||||
/* FreeRTOS */
|
||||
// *sobj = xSemaphoreCreateMutex();
|
||||
// return (int)(*sobj != NULL);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// *sobj = osMutexCreate(&Mutex[vol]);
|
||||
// return (int)(*sobj != NULL);
|
||||
/* CMSIS-RTOS */
|
||||
// *sobj = osMutexCreate(&Mutex[vol]);
|
||||
// return (int)(*sobj != NULL);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -88,27 +84,26 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object
|
|||
/ the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error */
|
||||
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)CloseHandle(sobj);
|
||||
int ff_del_syncobj( /* 1:Function succeeded, 0:Could not delete due to an error */
|
||||
FF_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
|
||||
) {
|
||||
/* Win32 */
|
||||
return (int) CloseHandle(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(del_sem(sobj) == E_OK);
|
||||
/* uITRON */
|
||||
// return (int)(del_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err);
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// vSemaphoreDelete(sobj);
|
||||
// return 1;
|
||||
/* FreeRTOS */
|
||||
// vSemaphoreDelete(sobj);
|
||||
// return 1;
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexDelete(sobj) == osOK);
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexDelete(sobj) == osOK);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -119,26 +114,25 @@ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error
|
|||
/ When a 0 is returned, the file function fails with FR_TIMEOUT.
|
||||
*/
|
||||
|
||||
int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a grant */
|
||||
FF_SYNC_t sobj /* Sync object to wait */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
return (int)(WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
|
||||
int ff_req_grant( /* 1:Got a grant to access the volume, 0:Could not get a grant */
|
||||
FF_SYNC_t sobj /* Sync object to wait */
|
||||
) {
|
||||
/* Win32 */
|
||||
return (int) (WaitForSingleObject(sobj, FF_FS_TIMEOUT) == WAIT_OBJECT_0);
|
||||
|
||||
/* uITRON */
|
||||
// return (int)(wai_sem(sobj) == E_OK);
|
||||
/* uITRON */
|
||||
// return (int)(wai_sem(sobj) == E_OK);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
/* uC/OS-II */
|
||||
// OS_ERR err;
|
||||
// OSMutexPend(sobj, FF_FS_TIMEOUT, &err));
|
||||
// return (int)(err == OS_NO_ERR);
|
||||
|
||||
/* FreeRTOS */
|
||||
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
|
||||
/* FreeRTOS */
|
||||
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -148,25 +142,23 @@ int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a gran
|
|||
/* This function is called on leaving file functions to unlock the volume.
|
||||
*/
|
||||
|
||||
void ff_rel_grant (
|
||||
FF_SYNC_t sobj /* Sync object to be signaled */
|
||||
)
|
||||
{
|
||||
/* Win32 */
|
||||
ReleaseMutex(sobj);
|
||||
void ff_rel_grant(
|
||||
FF_SYNC_t sobj /* Sync object to be signaled */
|
||||
) {
|
||||
/* Win32 */
|
||||
ReleaseMutex(sobj);
|
||||
|
||||
/* uITRON */
|
||||
// sig_sem(sobj);
|
||||
/* uITRON */
|
||||
// sig_sem(sobj);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OSMutexPost(sobj);
|
||||
/* uC/OS-II */
|
||||
// OSMutexPost(sobj);
|
||||
|
||||
/* FreeRTOS */
|
||||
// xSemaphoreGive(sobj);
|
||||
/* FreeRTOS */
|
||||
// xSemaphoreGive(sobj);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// osMutexRelease(sobj);
|
||||
/* CMSIS-RTOS */
|
||||
// osMutexRelease(sobj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
30877
src/fatfs/ffunicode.c
30877
src/fatfs/ffunicode.c
File diff suppressed because it is too large
Load Diff
|
|
@ -35,11 +35,11 @@ static bool buffersInitialized = false;
|
|||
std::string newlibtoFSA(std::string path) {
|
||||
if (path.rfind("storage_slccmpt01:", 0) == 0) {
|
||||
replace(path, "storage_slccmpt01:", "/vol/storage_slccmpt01");
|
||||
} else if(path.rfind("storage_mlc01:", 0) == 0) {
|
||||
} else if (path.rfind("storage_mlc01:", 0) == 0) {
|
||||
replace(path, "storage_mlc01:", "/vol/storage_mlc01");
|
||||
} else if(path.rfind("storage_usb01:", 0) == 0) {
|
||||
} else if (path.rfind("storage_usb01:", 0) == 0) {
|
||||
replace(path, "storage_usb01:", "/vol/storage_usb01");
|
||||
} else if(path.rfind("storage_usb02:", 0) == 0) {
|
||||
} else if (path.rfind("storage_usb02:", 0) == 0) {
|
||||
replace(path, "storage_usb02:", "/vol/storage_usb02");
|
||||
}
|
||||
return path;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user