mirror of
https://github.com/Ryuzaki-MrL/savemii.git
synced 2026-04-25 15:41:31 -05:00
commit
03fb0ebba4
|
|
@ -8,7 +8,7 @@ public:
|
|||
Date(uint32_t high, uint32_t low, uint8_t s) : highID(high),
|
||||
lowID(low),
|
||||
slot(s),
|
||||
path(stringFormat("sd:/wiiu/backups/%08x%08x/%u/savemiiMeta.json", highID, lowID, slot)) {
|
||||
path(stringFormat("/vol/external01/wiiu/backups/%08x%08x/%u/savemiiMeta.json", highID, lowID, slot)) {
|
||||
}
|
||||
std::string get();
|
||||
bool set(std::string date);
|
||||
|
|
|
|||
|
|
@ -1,24 +0,0 @@
|
|||
FatFs License
|
||||
|
||||
FatFs has being developped as a personal project of the author, ChaN. It is free from the code anyone else wrote at current release. Following code block shows a copy of the FatFs license document that heading the source files.
|
||||
|
||||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT Filesystem Module Rx.xx /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 20xx, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
/ that the following condition is met:
|
||||
/
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
Therefore FatFs license is one of the BSD-style licenses, but there is a significant feature. FatFs is mainly intended for embedded systems. In order to extend the usability for commercial products, the redistributions of FatFs in binary form, such as embedded code, binary library and any forms without source code, do not need to include about FatFs in the documentations. This is equivalent to the 1-clause BSD license. Of course FatFs is compatible with the most of open source software licenses include GNU GPL. When you redistribute the FatFs source code with changes or create a fork, the license can also be changed to GNU GPL, BSD-style license or any open source software license that not conflict with FatFs license.
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#include "devices.h"
|
||||
#include "ffconf.h"
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int deviceFds[FF_VOLUMES] = {-1, -1};
|
||||
const char *devicePaths[FF_VOLUMES] = {NULL, NULL};
|
||||
|
||||
const char *get_fat_usb_path() {
|
||||
return devicePaths[DEV_USB_EXT];
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
#include "ffconf.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Definitions of physical drive number for each drive */
|
||||
#define DEV_SD 0
|
||||
#define DEV_USB_EXT 1
|
||||
|
||||
#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"
|
||||
|
||||
extern int deviceFds[FF_VOLUMES];
|
||||
extern const char *devicePaths[FF_VOLUMES];
|
||||
|
||||
const char *get_fat_usb_path();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,514 +0,0 @@
|
|||
/*-----------------------------------------------------------------------*/
|
||||
/* Low level disk I/O module SKELETON for FatFs (C)ChaN, 2019 */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* If a working storage control module is available, it should be */
|
||||
/* attached to the FatFs via a glue function rather than modifying it. */
|
||||
/* This is an example of glue functions to attach various existing */
|
||||
/* 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 "ffcache.h"
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Internal Wii U Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
#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_fsa.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"};
|
||||
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};
|
||||
|
||||
|
||||
DSTATUS wiiu_mountDrive(BYTE pdrv) {
|
||||
// Create and open raw device
|
||||
fatClients[pdrv] = FSAAddClient(NULL);
|
||||
Mocha_UnlockFSClientEx(fatClients[pdrv]);
|
||||
|
||||
FSError res = FSAEx_RawOpenEx(fatClients[pdrv], fatDevPaths[pdrv], &fatHandles[pdrv]);
|
||||
if (res < 0) {
|
||||
OSReport("Couldn't open %d with error %d\n", pdrv, res);
|
||||
FSADelClient(fatClients[pdrv]);
|
||||
return STA_NODISK;
|
||||
}
|
||||
OSReport("Mounted %d drive\n", pdrv);
|
||||
fatMounted[pdrv] = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
DSTATUS wiiu_unmountDrive(BYTE pdrv) {
|
||||
FSAEx_RawCloseEx(fatClients[pdrv], fatHandles[pdrv]);
|
||||
FSADelClient(fatClients[pdrv]);
|
||||
fatMounted[pdrv] = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
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 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;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Initialize a 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
|
||||
ffcache_initialize(pdrv, fatSectorSizes[pdrv], fatCacheSizes[pdrv]);
|
||||
return wiiu_mountDrive(pdrv);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Shutdown a 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;
|
||||
return wiiu_unmountDrive(pdrv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* 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 */
|
||||
)
|
||||
{
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
//return wiiu_readSectors(pdrv, sector, count, buff) == FS_ERROR_OK ? RES_OK : RES_ERROR;
|
||||
return ffcache_readSectors(pdrv, sector, count, buff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* 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 */
|
||||
)
|
||||
{
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
//return wiiu_writeSectors(pdrv, sector, count, buff) == FS_ERROR_OK ? RES_OK : RES_ERROR;
|
||||
return ffcache_writeSectors(pdrv, sector, count, buff);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
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 cached sectors!");
|
||||
//return ffcache_flushSectors(pdrv);
|
||||
return RES_OK;
|
||||
}
|
||||
case CTRL_FORCE_SYNC: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested a forced sync, flushing cached sectors!");
|
||||
//return ffcache_flushSectors(pdrv);
|
||||
return RES_OK;
|
||||
}
|
||||
case SET_CACHE_COUNT: {
|
||||
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;
|
||||
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];
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_BLOCK_SIZE: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested block size which is unknown!");
|
||||
*(WORD*)buff = 1;
|
||||
return RES_OK;
|
||||
}
|
||||
case CTRL_TRIM: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested trim!");
|
||||
return RES_OK;
|
||||
}
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
DWORD get_fattime() {
|
||||
OSCalendarTime output;
|
||||
OSTicksToCalendarTime(OSGetTime(), &output);
|
||||
return (DWORD) (output.tm_year - 1980) << 25 |
|
||||
(DWORD) (output.tm_mon + 1) << 21 |
|
||||
(DWORD) output.tm_mday << 16 |
|
||||
(DWORD) output.tm_hour << 11 |
|
||||
(DWORD) output.tm_min << 5 |
|
||||
(DWORD) output.tm_sec >> 1;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
|
||||
#include <coreinit/filesystem.h>
|
||||
#include <coreinit/debug.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)
|
||||
|
||||
FSFileHandle fatHandles[FF_VOLUMES][SPLIT_IMAGE_COUNT];
|
||||
const WORD fatSectorSizes[FF_VOLUMES] = {512};
|
||||
WORD fatCacheSizes[FF_VOLUMES] = {32*8*4};
|
||||
|
||||
FSClient* client;
|
||||
FSCmdBlock fsCmd;
|
||||
|
||||
char sMountPath[0x80];
|
||||
|
||||
DSTATUS wiiu_mountDrive(BYTE pdrv) {
|
||||
client = aligned_alloc(0x20, sizeof(FSClient));
|
||||
FSAddClient(client, 0);
|
||||
FSInitCmdBlock(&fsCmd);
|
||||
|
||||
FSMountSource mountSource;
|
||||
FSGetMountSource(client, &fsCmd, FS_MOUNT_SOURCE_SD, &mountSource, -1);
|
||||
|
||||
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++) {
|
||||
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);
|
||||
OSReport("Opened disk image %s with size of with result %d!\n", name, result);
|
||||
if (result != FS_STATUS_OK) {
|
||||
FSDelClient(client, 0);
|
||||
return STA_NOINIT;
|
||||
}
|
||||
}
|
||||
fatMounted[pdrv] = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
DSTATUS wiiu_unmountDrive(BYTE pdrv) {
|
||||
for (uint8_t i=0; i<SPLIT_IMAGE_COUNT; i++) {
|
||||
FSCloseFile(client, &fsCmd, fatHandles[pdrv][i], FS_ERROR_FLAG_ALL);
|
||||
}
|
||||
FSDelClient(client, 0);
|
||||
free(client);
|
||||
|
||||
fatMounted[pdrv] = false;
|
||||
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++) {
|
||||
LBA_t currSectorIdx = sectorIdx + i;
|
||||
uint32_t fileIdx = 0;
|
||||
if (currSectorIdx != 0) {
|
||||
fileIdx = currSectorIdx / SPLIT_IMAGE_SIZE_SECTORS;
|
||||
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]);
|
||||
//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++) {
|
||||
LBA_t currSectorIdx = sectorIdx + i;
|
||||
uint32_t fileIdx = 0;
|
||||
if (currSectorIdx != 0) {
|
||||
fileIdx = currSectorIdx / SPLIT_IMAGE_SIZE_SECTORS;
|
||||
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);
|
||||
//DEBUG_OSReport("[CacheWrite] buff=%x, idx=%u -> relativeIdx=%u, cnt=%u; ret=%d", (void*)inputBuff, sectorIdx, currSectorIdx, sectorCount, status);
|
||||
}
|
||||
free(tempBuff);
|
||||
return FS_ERROR_OK;
|
||||
}
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Get Drive Status */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
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;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Initialize a 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: Get sector size instead of hard-coding it
|
||||
ffcache_initialize(pdrv, fatSectorSizes[pdrv], fatCacheSizes[pdrv]);
|
||||
return wiiu_mountDrive(pdrv);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Shutdown a 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;
|
||||
return wiiu_unmountDrive(pdrv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* 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 */
|
||||
)
|
||||
{
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
return wiiu_readSectors(pdrv, sector, count, buff) == FS_ERROR_OK ? RES_OK : RES_ERROR;
|
||||
//return ffcache_readSectors(pdrv, sector, count, buff);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* 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 */
|
||||
)
|
||||
{
|
||||
if (pdrv < 0 || pdrv >= FF_VOLUMES) return RES_PARERR;
|
||||
if (!fatMounted[pdrv]) return RES_NOTRDY;
|
||||
|
||||
return wiiu_writeSectors(pdrv, sector, count, buff) == FS_ERROR_OK ? RES_OK : RES_ERROR;
|
||||
//return ffcache_writeSectors(pdrv, sector, count, buff);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
/* Miscellaneous Functions */
|
||||
/*-----------------------------------------------------------------------*/
|
||||
|
||||
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++) {
|
||||
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++) {
|
||||
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);
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_SECTOR_COUNT: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested sector count!");
|
||||
*(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];
|
||||
return RES_OK;
|
||||
}
|
||||
case GET_BLOCK_SIZE: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested block size which is unknown!");
|
||||
*(WORD*)buff = 1;
|
||||
return RES_OK;
|
||||
}
|
||||
case CTRL_TRIM: {
|
||||
DEBUG_OSReport("[disk_ioctl] Requested trim!");
|
||||
//return RES_OK;
|
||||
}
|
||||
default:
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
return RES_PARERR;
|
||||
}
|
||||
|
||||
DWORD get_fattime() {
|
||||
OSCalendarTime output;
|
||||
OSTicksToCalendarTime(OSGetTime(), &output);
|
||||
return (DWORD) (output.tm_year - 1980) << 25 |
|
||||
(DWORD) (output.tm_mon + 1) << 21 |
|
||||
(DWORD) output.tm_mday << 16 |
|
||||
(DWORD) output.tm_hour << 11 |
|
||||
(DWORD) output.tm_min << 5 |
|
||||
(DWORD) output.tm_sec >> 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
/*-----------------------------------------------------------------------/
|
||||
/ Low level disk interface modlue include file (C)ChaN, 2019 /
|
||||
/-----------------------------------------------------------------------*/
|
||||
|
||||
#ifndef _DISKIO_DEFINED
|
||||
#define _DISKIO_DEFINED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <coreinit/filesystem_fsa.h>
|
||||
|
||||
#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];
|
||||
|
||||
/* Status of Disk Functions */
|
||||
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 */
|
||||
} 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);
|
||||
|
||||
|
||||
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 */
|
||||
|
||||
|
||||
/* 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
|
||||
|
||||
/* 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 */
|
||||
|
||||
/* 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 */
|
||||
|
||||
/* 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 */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,157 +0,0 @@
|
|||
#include <sys/iosupport.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <whb/log.h>
|
||||
#include <whb/log_console.h>
|
||||
#include "../devices.h"
|
||||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
static BOOL extusb_fs_initialised = false;
|
||||
|
||||
int init_extusb_devoptab() {
|
||||
if (extusb_fs_initialised) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extusb_fs_devoptab.deviceData = memalign(0x40, sizeof(FATFS));
|
||||
if (extusb_fs_devoptab.deviceData == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *mountPath = memalign(0x40, 256);
|
||||
sprintf(mountPath, "%d:", DEV_SD);
|
||||
|
||||
int dev = AddDevice(&extusb_fs_devoptab);
|
||||
if (dev != -1) {
|
||||
setDefaultDevice(dev);
|
||||
|
||||
// Mount the external USB drive
|
||||
FRESULT fr = f_mount(extusb_fs_devoptab.deviceData, mountPath, 1);
|
||||
|
||||
if (fr != FR_OK) {
|
||||
free(extusb_fs_devoptab.deviceData);
|
||||
extusb_fs_devoptab.deviceData = NULL;
|
||||
return fr;
|
||||
}
|
||||
// chdir to external USB root for general use
|
||||
chdir("sd:/");
|
||||
extusb_fs_initialised = true;
|
||||
} else {
|
||||
f_unmount(mountPath);
|
||||
free(extusb_fs_devoptab.deviceData);
|
||||
extusb_fs_devoptab.deviceData = NULL;
|
||||
return dev;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fini_extusb_devoptab() {
|
||||
if (!extusb_fs_initialised) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rc = RemoveDevice(extusb_fs_devoptab.name);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
char *mountPath = memalign(0x40, 256);
|
||||
sprintf(mountPath, "%d:", DEV_SD);
|
||||
rc = f_unmount(mountPath);
|
||||
if (rc != FR_OK) {
|
||||
return rc;
|
||||
}
|
||||
free(extusb_fs_devoptab.deviceData);
|
||||
extusb_fs_devoptab.deviceData = NULL;
|
||||
extusb_fs_initialised = false;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
const char *translate_fatfs_error(FRESULT fr) {
|
||||
switch (fr) {
|
||||
case FR_OK:
|
||||
return "(0) OK";
|
||||
case FR_DISK_ERR:
|
||||
return "(1) A hard error occurred in the low level disk I/O layer";
|
||||
case FR_INT_ERR:
|
||||
return "(2) Assertion failed";
|
||||
case FR_NOT_READY:
|
||||
return "(3) The physical drive cannot work";
|
||||
case FR_NO_FILE:
|
||||
return "(4) Could not find the file";
|
||||
case FR_NO_PATH:
|
||||
return "(5) Could not find the path";
|
||||
case FR_INVALID_NAME:
|
||||
return "(6) The path name format is invalid";
|
||||
case FR_DENIED:
|
||||
return "(7) Access denied due to prohibited access or directory full";
|
||||
case FR_EXIST:
|
||||
return "(8) Access denied due to prohibited access";
|
||||
case FR_INVALID_OBJECT:
|
||||
return "(9) The file/directory object is invalid";
|
||||
case FR_WRITE_PROTECTED:
|
||||
return "(10) The physical drive is write protected";
|
||||
case FR_INVALID_DRIVE:
|
||||
return "(11) The logical drive number is invalid";
|
||||
case FR_NOT_ENABLED:
|
||||
return "(12) The volume has no work area";
|
||||
case FR_NO_FILESYSTEM:
|
||||
return "(13) There is no valid FAT volume";
|
||||
case FR_MKFS_ABORTED:
|
||||
return "(14) The f_mkfs() aborted due to any problem";
|
||||
case FR_TIMEOUT:
|
||||
return "(15) Could not get a grant to access the volume within defined period";
|
||||
case FR_LOCKED:
|
||||
return "(16) The operation is rejected according to the file sharing policy";
|
||||
case FR_NOT_ENOUGH_CORE:
|
||||
return "(17) LFN working buffer could not be allocated";
|
||||
case FR_TOO_MANY_OPEN_FILES:
|
||||
return "(18) Number of open files > FF_FS_LOCK";
|
||||
case FR_INVALID_PARAMETER:
|
||||
return "(19) Given parameter is invalid";
|
||||
default:
|
||||
return "Unknown error";
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,114 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <coreinit/filesystem.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.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" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Open file struct
|
||||
*/
|
||||
typedef struct {
|
||||
//! FS handle
|
||||
FIL fp;
|
||||
|
||||
char *path;
|
||||
|
||||
//! Flags used in open(2)
|
||||
int flags;
|
||||
|
||||
//! Current file offset
|
||||
uint32_t offset;
|
||||
} __extusb_fs_file_t;
|
||||
|
||||
|
||||
/**
|
||||
* Open directory struct
|
||||
*/
|
||||
typedef struct {
|
||||
//! FS handle
|
||||
DIR_FAT dp;
|
||||
|
||||
//! Temporary storage for reading entries
|
||||
FILINFO entry_data;
|
||||
} __extusb_fs_dir_t;
|
||||
|
||||
int init_extusb_devoptab();
|
||||
int fini_extusb_devoptab();
|
||||
const char *translate_fatfs_error(FRESULT fr);
|
||||
|
||||
int __extusb_fs_open(struct _reent *r, void *fileStruct, const char *path,
|
||||
int flags, int mode);
|
||||
|
||||
int __extusb_fs_close(struct _reent *r, void *fd);
|
||||
|
||||
ssize_t __extusb_fs_write(struct _reent *r, void *fd, const char *ptr,
|
||||
size_t len);
|
||||
|
||||
ssize_t __extusb_fs_read(struct _reent *r, void *fd, char *ptr, size_t len);
|
||||
|
||||
off_t __extusb_fs_seek(struct _reent *r, void *fd, off_t pos, int dir);
|
||||
|
||||
int __extusb_fs_fstat(struct _reent *r, void *fd, struct stat *st);
|
||||
|
||||
int __extusb_fs_stat(struct _reent *r, const char *file, struct stat *st);
|
||||
|
||||
int __extusb_fs_link(struct _reent *r, const char *existing,
|
||||
const char *newLink);
|
||||
|
||||
int __extusb_fs_unlink(struct _reent *r, const char *name);
|
||||
|
||||
int __extusb_fs_chdir(struct _reent *r, const char *name);
|
||||
|
||||
int __extusb_fs_rename(struct _reent *r, const char *oldName,
|
||||
const char *newName);
|
||||
|
||||
int __extusb_fs_mkdir(struct _reent *r, const char *path, int mode);
|
||||
|
||||
DIR_ITER *__extusb_fs_diropen(struct _reent *r, DIR_ITER *dirState,
|
||||
const char *path);
|
||||
|
||||
int __extusb_fs_dirreset(struct _reent *r, DIR_ITER *dirState);
|
||||
|
||||
int __extusb_fs_dirnext(struct _reent *r, DIR_ITER *dirState, char *filename,
|
||||
struct stat *filestat);
|
||||
|
||||
int __extusb_fs_dirclose(struct _reent *r, DIR_ITER *dirState);
|
||||
|
||||
int __extusb_fs_statvfs(struct _reent *r, const char *path,
|
||||
struct statvfs *buf);
|
||||
|
||||
int __extusb_fs_ftruncate(struct _reent *r, void *fd, off_t len);
|
||||
|
||||
int __extusb_fs_fsync(struct _reent *r, void *fd);
|
||||
|
||||
int __extusb_fs_chmod(struct _reent *r, const char *path, mode_t mode);
|
||||
|
||||
int __extusb_fs_fchmod(struct _reent *r, void *fd, mode_t mode);
|
||||
|
||||
int __extusb_fs_rmdir(struct _reent *r, const char *name);
|
||||
|
||||
// devoptab_fs_utils.c
|
||||
char *__extusb_fs_fixpath(struct _reent *r, const char *path);
|
||||
|
||||
int __extusb_fs_translate_error(FRESULT error);
|
||||
|
||||
time_t __extusb_fs_translate_time(WORD fdate, WORD ftime);
|
||||
|
||||
mode_t __extusb_fs_translate_mode(FILINFO fileStat);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_chdir(struct _reent *r,
|
||||
const char *path) {
|
||||
if (!path) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *fixedPath = __extusb_fs_fixpath(r, path);
|
||||
if (!fixedPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FRESULT fr = f_chdir(fixedPath);
|
||||
free(fixedPath);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#include <sys/stat.h>
|
||||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_chmod(struct _reent *r,
|
||||
const char *path,
|
||||
mode_t mode) {
|
||||
if (!path) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *fixedPath = __extusb_fs_fixpath(r, path);
|
||||
if (!fixedPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FRESULT fr;
|
||||
if (((mode & S_IWUSR) || (mode & S_IWGRP) || (mode & S_IWOTH)) == 0) {
|
||||
fr = f_chmod(fixedPath, 0, AM_RDO);
|
||||
} else {
|
||||
fr = f_chmod(fixedPath, AM_RDO, AM_RDO);
|
||||
}
|
||||
|
||||
free(fixedPath);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int __extusb_fs_close(struct _reent *r,
|
||||
void *fd) {
|
||||
if (!fd) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
FRESULT fr = f_close(&file->fp);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(file->path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_dirclose(struct _reent *r,
|
||||
DIR_ITER *dirState) {
|
||||
|
||||
if (!dirState) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_dir_t *dir = (__extusb_fs_dir_t *) (dirState->dirStruct);
|
||||
FRESULT fr = f_closedir(&dir->dp);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_dirnext(struct _reent *r,
|
||||
DIR_ITER *dirState,
|
||||
char *filename,
|
||||
struct stat *filestat) {
|
||||
if (!dirState || !filename || !filestat) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_dir_t *dir = (__extusb_fs_dir_t *) (dirState->dirStruct);
|
||||
memset(&dir->entry_data, 0, sizeof(dir->entry_data));
|
||||
FRESULT fr = f_readdir(&dir->dp, &dir->entry_data);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
if (dir->entry_data.fname[0] == 0) {
|
||||
r->_errno = ENOENT;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Fill in the stat info
|
||||
memset(filestat, 0, sizeof(struct stat));
|
||||
filestat->st_ino = 0;
|
||||
|
||||
if (dir->entry_data.fattrib & AM_DIR) {
|
||||
filestat->st_mode = S_IFDIR;
|
||||
} else {
|
||||
filestat->st_mode = S_IFREG;
|
||||
}
|
||||
|
||||
filestat->st_uid = 0;
|
||||
filestat->st_gid = 0;
|
||||
filestat->st_size = dir->entry_data.fsize;
|
||||
|
||||
memset(filename, 0, NAME_MAX);
|
||||
strcpy(filename, dir->entry_data.fname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DIR_ITER *
|
||||
__extusb_fs_diropen(struct _reent *r,
|
||||
DIR_ITER *dirState,
|
||||
const char *path) {
|
||||
if (!dirState || !path) {
|
||||
r->_errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *fixedPath = __extusb_fs_fixpath(r, path);
|
||||
if (!fixedPath) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__extusb_fs_dir_t *dir = (__extusb_fs_dir_t *) (dirState->dirStruct);
|
||||
FRESULT fr = f_opendir(&dir->dp, fixedPath);
|
||||
free(fixedPath);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return NULL;
|
||||
}
|
||||
memset(&dir->entry_data, 0, sizeof(dir->entry_data));
|
||||
return dirState;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_dirreset(struct _reent *r,
|
||||
DIR_ITER *dirState) {
|
||||
if (!dirState) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_dir_t *dir = (__extusb_fs_dir_t *) (dirState->dirStruct);
|
||||
FRESULT fr = f_rewinddir(&dir->dp);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_fchmod(struct _reent *r,
|
||||
void *fd,
|
||||
mode_t mode) {
|
||||
if (!fd) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
return __extusb_fs_chmod(r, file->path, mode);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_fstat(struct _reent *r,
|
||||
void *fd,
|
||||
struct stat *st) {
|
||||
if (!fd || !st) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
return __extusb_fs_stat(r, file->path, st);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_fsync(struct _reent *r,
|
||||
void *fd) {
|
||||
if (!fd) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
FRESULT fr = f_sync(&file->fp);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_link(struct _reent *r,
|
||||
const char *existing,
|
||||
const char *newLink) {
|
||||
r->_errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_mkdir(struct _reent *r,
|
||||
const char *path,
|
||||
int mode) {
|
||||
char *fixedPath;
|
||||
|
||||
if (!path) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fixedPath = __extusb_fs_fixpath(r, path);
|
||||
if (!fixedPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: Use mode to set directory attributes.
|
||||
FRESULT fr = f_mkdir(fixedPath);
|
||||
free(fixedPath);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,57 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int __extusb_fs_open(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) {
|
||||
if (!fileStruct || !path) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
BYTE fsMode;
|
||||
if (flags == 0) {
|
||||
fsMode = FA_READ;
|
||||
} else if (flags == 2) {
|
||||
fsMode = FA_READ | FA_WRITE;
|
||||
} else if (flags == 0x601) {
|
||||
fsMode = FA_CREATE_ALWAYS | FA_WRITE;
|
||||
} else if (flags == 0x602) {
|
||||
fsMode = FA_CREATE_ALWAYS | FA_WRITE | FA_READ;
|
||||
} else if (flags == 0x209) {
|
||||
fsMode = FA_OPEN_APPEND | FA_WRITE;
|
||||
} else if (flags == 0x20A) {
|
||||
fsMode = FA_OPEN_APPEND | FA_WRITE | FA_READ;
|
||||
} else {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *fixedPath = __extusb_fs_fixpath(r, path);
|
||||
if (!fixedPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FIL fp;
|
||||
FRESULT fr;
|
||||
|
||||
// Open the file
|
||||
fr = f_open(&fp, fixedPath, fsMode);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
free(fixedPath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fileStruct;
|
||||
file->fp = fp;
|
||||
file->flags = (flags & (O_ACCMODE | O_APPEND | O_SYNC));
|
||||
file->offset = 0;
|
||||
file->path = fixedPath;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ssize_t __extusb_fs_read(struct _reent *r, void *fd, char *ptr, size_t len) {
|
||||
if (!fd || !ptr) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check that the file was opened with read access
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
if ((file->flags & O_ACCMODE) == O_WRONLY) {
|
||||
r->_errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// cache-aligned, cache-line-sized
|
||||
__attribute__((aligned(0x40))) uint8_t alignedBuffer[0x40];
|
||||
|
||||
size_t bytesRead = 0;
|
||||
while (bytesRead < len) {
|
||||
// only use input buffer if cache-aligned and read size is a multiple of cache line size
|
||||
// otherwise read into alignedBuffer
|
||||
uint8_t *tmp = (uint8_t *) ptr;
|
||||
size_t size = len - bytesRead;
|
||||
|
||||
if ((uintptr_t) ptr & 0x3F) {
|
||||
// read partial cache-line front-end
|
||||
tmp = alignedBuffer;
|
||||
size = MIN(size, 0x40 - ((uintptr_t) ptr & 0x3F));
|
||||
} else if (size < 0x40) {
|
||||
// read partial cache-line back-end
|
||||
tmp = alignedBuffer;
|
||||
} else {
|
||||
// read whole cache lines
|
||||
size &= ~0x3F;
|
||||
}
|
||||
|
||||
UINT br;
|
||||
FRESULT fr = f_read(&file->fp, tmp, size, &br);
|
||||
|
||||
if (fr != FR_OK) {
|
||||
if (bytesRead != 0) {
|
||||
return (ssize_t) bytesRead; // error after partial read
|
||||
}
|
||||
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tmp == alignedBuffer) {
|
||||
memcpy(ptr, alignedBuffer, br);
|
||||
}
|
||||
|
||||
bytesRead += br;
|
||||
ptr += br;
|
||||
|
||||
if (br != size) {
|
||||
return (ssize_t) bytesRead; // partial read
|
||||
}
|
||||
}
|
||||
|
||||
return (ssize_t) bytesRead;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_rename(struct _reent *r,
|
||||
const char *oldName,
|
||||
const char *newName) {
|
||||
char *fixedOldPath, *fixedNewPath;
|
||||
|
||||
if (!oldName || !newName) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fixedOldPath = __extusb_fs_fixpath(r, oldName);
|
||||
if (!fixedOldPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
fixedNewPath = __extusb_fs_fixpath(r, newName);
|
||||
if (!fixedNewPath) {
|
||||
free(fixedOldPath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FRESULT fr = f_rename(fixedOldPath, fixedNewPath);
|
||||
free(fixedOldPath);
|
||||
free(fixedNewPath);
|
||||
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_rmdir(struct _reent *r,
|
||||
const char *name) {
|
||||
if (!name) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *fixedPath = __extusb_fs_fixpath(r, name);
|
||||
if (!fixedPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FRESULT fr = f_rmdir(fixedPath);
|
||||
free(fixedPath);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
off_t
|
||||
__extusb_fs_seek(struct _reent *r,
|
||||
void *fd,
|
||||
off_t pos,
|
||||
int whence) {
|
||||
uint64_t offset;;
|
||||
|
||||
if (!fd) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
FILINFO fno;
|
||||
FRESULT fr;
|
||||
|
||||
// Find the offset to see from
|
||||
switch (whence) {
|
||||
// Set absolute position; start offset is 0
|
||||
case SEEK_SET:
|
||||
offset = 0;
|
||||
break;
|
||||
|
||||
// Set position relative to the current position
|
||||
case SEEK_CUR:
|
||||
offset = file->offset;
|
||||
break;
|
||||
|
||||
// Set position relative to the end of the file
|
||||
case SEEK_END:
|
||||
fr = f_stat(file->path, &fno);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
offset = fno.fsize;
|
||||
break;
|
||||
|
||||
// An invalid option was provided
|
||||
default:
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO: A better check that prevents overflow.
|
||||
if (pos < 0 && offset < -pos) {
|
||||
// Don't allow seek to before the beginning of the file
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t old_offset = file->offset;
|
||||
file->offset = offset + pos;
|
||||
|
||||
fr = f_lseek(&file->fp, file->offset);
|
||||
if (fr != FR_OK) {
|
||||
// revert offset update on error.
|
||||
file->offset = old_offset;
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return file->offset;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_stat(struct _reent *r,
|
||||
const char *path,
|
||||
struct stat *st) {
|
||||
if (!path || !st) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *fixedPath = __extusb_fs_fixpath(r, path);
|
||||
if (!fixedPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILINFO fno;
|
||||
FRESULT fr = f_stat(fixedPath, &fno);
|
||||
if (fr != FR_OK) {
|
||||
free(fixedPath);
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
free(fixedPath);
|
||||
|
||||
memset(st, 0, sizeof(struct stat));
|
||||
|
||||
st->st_nlink = 1;
|
||||
|
||||
st->st_atime = __extusb_fs_translate_time(fno.fdate, fno.ftime);
|
||||
st->st_ctime = __extusb_fs_translate_time(fno.fdate, fno.ftime);
|
||||
st->st_mtime = __extusb_fs_translate_time(fno.fdate, fno.ftime);
|
||||
st->st_mode = __extusb_fs_translate_mode(fno);
|
||||
|
||||
if (!(fno.fattrib & AM_DIR)) {
|
||||
st->st_size = (off_t) fno.fsize;
|
||||
st->st_uid = 0;
|
||||
st->st_gid = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,18 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_statvfs(struct _reent *r,
|
||||
const char *path,
|
||||
struct statvfs *buf) {
|
||||
//TODO: look up in FATFS struct
|
||||
r->_errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
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;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Set the new file size
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
FRESULT fr = f_lseek(&file->fp, len);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fr = f_truncate(&file->fp);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_unlink(struct _reent *r,
|
||||
const char *name) {
|
||||
char *fixedPath;
|
||||
|
||||
if (!name) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
fixedPath = __extusb_fs_fixpath(r, name);
|
||||
if (!fixedPath) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FRESULT fr = f_unlink(fixedPath);
|
||||
free(fixedPath);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,110 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
#include "../devices.h"
|
||||
#include "stdio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
char *
|
||||
__extusb_fs_fixpath(struct _reent *r,
|
||||
const char *path) {
|
||||
char *p;
|
||||
char *fixedPath;
|
||||
|
||||
if (!path) {
|
||||
r->_errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p = strchr(path, ':') + 1;
|
||||
if (!strchr(path, ':')) {
|
||||
p = (char *) path;
|
||||
}
|
||||
|
||||
if (strlen(p) > FS_MAX_PATH) {
|
||||
r->_errno = ENAMETOOLONG;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fixedPath = (char *) memalign(0x40, FS_MAX_PATH + 1);
|
||||
if (!fixedPath) {
|
||||
r->_errno = ENOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sprintf(fixedPath, "%d:%s", DEV_SD, p);
|
||||
return fixedPath;
|
||||
}
|
||||
|
||||
int __extusb_fs_translate_error(FRESULT error) {
|
||||
switch ((int) error) {
|
||||
case FR_DISK_ERR:
|
||||
case FR_INT_ERR:
|
||||
case FR_NOT_READY:
|
||||
return EIO;
|
||||
case FR_NO_FILE:
|
||||
case FR_NO_PATH:
|
||||
case FR_INVALID_NAME:
|
||||
return ENOENT;
|
||||
case FR_DENIED:
|
||||
return EACCES;
|
||||
case FR_EXIST:
|
||||
return EEXIST;
|
||||
case FR_INVALID_OBJECT:
|
||||
return EBADF;
|
||||
case FR_WRITE_PROTECTED:
|
||||
return EROFS;
|
||||
case FR_INVALID_DRIVE:
|
||||
return ENODEV;
|
||||
case FR_NOT_ENABLED:
|
||||
return ENOMEM;
|
||||
case FR_NO_FILESYSTEM:
|
||||
return ENODEV;
|
||||
case FR_MKFS_ABORTED:
|
||||
return EINVAL;
|
||||
case FR_TIMEOUT:
|
||||
return EINTR;
|
||||
case FR_LOCKED:
|
||||
return EAGAIN;
|
||||
case FR_NOT_ENOUGH_CORE:
|
||||
return ENOMEM;
|
||||
case FR_TOO_MANY_OPEN_FILES:
|
||||
return EMFILE;
|
||||
case FR_INVALID_PARAMETER:
|
||||
return EINVAL;
|
||||
}
|
||||
return (int) error;
|
||||
}
|
||||
|
||||
time_t __extusb_fs_translate_time(WORD fdate, WORD ftime) {
|
||||
struct tm time;
|
||||
time.tm_year = fdate >> 9;
|
||||
time.tm_mon = (fdate >> 5) & 0b1111;
|
||||
time.tm_mday = fdate & 0b11111;
|
||||
time.tm_hour = ftime >> 11;
|
||||
time.tm_min = (ftime >> 5) & 0b111111;
|
||||
time.tm_sec = (ftime & 0b11111) * 2;
|
||||
return mktime(&time);
|
||||
}
|
||||
|
||||
mode_t __extusb_fs_translate_mode(FILINFO fileStat) {
|
||||
mode_t retMode = 0;
|
||||
|
||||
if ((fileStat.fattrib & AM_DIR) == AM_DIR) {
|
||||
retMode |= S_IFDIR;
|
||||
} else {
|
||||
retMode |= S_IFREG;
|
||||
}
|
||||
|
||||
mode_t flags = (FS_MODE_READ_OWNER | FS_MODE_READ_GROUP | FS_MODE_READ_OTHER) >> 2;
|
||||
if (fileStat.fattrib & AM_RDO) {
|
||||
flags |= (FS_MODE_WRITE_OWNER | FS_MODE_WRITE_GROUP | FS_MODE_WRITE_OTHER) >> 1;
|
||||
}
|
||||
flags |= FS_MODE_EXEC_OWNER | FS_MODE_EXEC_GROUP | FS_MODE_EXEC_OTHER;
|
||||
return retMode | flags;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
#include <time.h>
|
||||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int
|
||||
__extusb_fs_utimes(struct _reent *r,
|
||||
const char *filename,
|
||||
const struct timeval times[2]) {
|
||||
if (!filename) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILINFO fno;
|
||||
if (times == NULL) {
|
||||
DWORD time = get_fattime();
|
||||
fno.fdate = (WORD) (time >> 16);
|
||||
fno.ftime = (WORD) (time & 0xFFFF);
|
||||
} else {
|
||||
struct tm time;
|
||||
localtime_r(×[1].tv_sec, &time);
|
||||
fno.fdate = (WORD) (((time.tm_year - 1980) * 512U) | time.tm_mon * 32U | time.tm_mday);
|
||||
fno.ftime = (WORD) (time.tm_hour * 2048U | time.tm_min * 32U | time.tm_sec / 2U);
|
||||
}
|
||||
|
||||
FRESULT fr = f_utime(filename, &fno);
|
||||
if (fr != FR_OK) {
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
#include "extusb_devoptab.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
ssize_t __extusb_fs_write(struct _reent *r, void *fd, const char *ptr,
|
||||
size_t len) {
|
||||
if (!fd || !ptr) {
|
||||
r->_errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
__extusb_fs_file_t *file = (__extusb_fs_file_t *) fd;
|
||||
if ((file->flags & O_ACCMODE) == O_RDONLY) {
|
||||
r->_errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// cache-aligned, cache-line-sized
|
||||
__attribute__((aligned(0x40))) uint8_t alignedBuffer[0x40];
|
||||
|
||||
size_t bytesWritten = 0;
|
||||
while (bytesWritten < len) {
|
||||
// only use input buffer if cache-aligned and write size is a multiple of cache line size
|
||||
// otherwise write from alignedBuffer
|
||||
uint8_t *tmp = (uint8_t *) ptr;
|
||||
size_t size = len - bytesWritten;
|
||||
|
||||
if ((uintptr_t) ptr & 0x3F) {
|
||||
// write partial cache-line front-end
|
||||
tmp = alignedBuffer;
|
||||
size = MIN(size, 0x40 - ((uintptr_t) ptr & 0x3F));
|
||||
} else if (size < 0x40) {
|
||||
// write partial cache-line back-end
|
||||
tmp = alignedBuffer;
|
||||
} else {
|
||||
// write whole cache lines
|
||||
size &= ~0x3F;
|
||||
}
|
||||
|
||||
if (tmp == alignedBuffer) {
|
||||
memcpy(tmp, ptr, size);
|
||||
}
|
||||
|
||||
UINT bw;
|
||||
FRESULT fr = f_write(&file->fp, tmp, size, &bw);
|
||||
if (fr != FR_OK) {
|
||||
if (bytesWritten != 0) {
|
||||
return (ssize_t) bytesWritten; // error after partial write
|
||||
}
|
||||
|
||||
r->_errno = __extusb_fs_translate_error(fr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bytesWritten += bw;
|
||||
ptr += bw;
|
||||
|
||||
if (bw != size) {
|
||||
return (ssize_t) bytesWritten; // partial write
|
||||
}
|
||||
}
|
||||
|
||||
return (ssize_t) bytesWritten;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
7197
src/fatfs/ff.c
7197
src/fatfs/ff.c
File diff suppressed because it is too large
Load Diff
424
src/fatfs/ff.h
424
src/fatfs/ff.h
|
|
@ -1,424 +0,0 @@
|
|||
/*----------------------------------------------------------------------------/
|
||||
/ FatFs - Generic FAT Filesystem module R0.14b /
|
||||
/-----------------------------------------------------------------------------/
|
||||
/
|
||||
/ Copyright (C) 2021, ChaN, all right reserved.
|
||||
/
|
||||
/ FatFs module is an open source software. Redistribution and use of FatFs in
|
||||
/ source and binary forms, with or without modification, are permitted provided
|
||||
/ that the following condition is met:
|
||||
|
||||
/ 1. Redistributions of source code must retain the above copyright notice,
|
||||
/ this condition and the following disclaimer.
|
||||
/
|
||||
/ This software is provided by the copyright holder and contributors "AS IS"
|
||||
/ and any warranties related to this software are DISCLAIMED.
|
||||
/ The copyright owner or contributors be NOT LIABLE for any damages caused
|
||||
/ by use of this software.
|
||||
/
|
||||
/----------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#ifndef FF_DEFINED
|
||||
#define FF_DEFINED 86631 /* Revision ID */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ffconf.h" /* FatFs configuration options */
|
||||
|
||||
#if FF_DEFINED != FFCONF_DEF
|
||||
#error Wrong configuration file (ffconf.h).
|
||||
#endif
|
||||
|
||||
|
||||
/* Integer types used for FatFs API */
|
||||
|
||||
#if defined(_WIN32) /* Windows VC++ (for development only) */
|
||||
#define FF_INTDEF 2
|
||||
#include <windows.h>
|
||||
typedef unsigned __int64 QWORD;
|
||||
#include <float.h>
|
||||
#define isnan(v) _isnan(v)
|
||||
#define isinf(v) (!_finite(v))
|
||||
|
||||
#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 */
|
||||
|
||||
#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 */
|
||||
#endif
|
||||
|
||||
|
||||
/* Type of file size and LBA variables */
|
||||
|
||||
#if FF_FS_EXFAT
|
||||
#if FF_INTDEF != 2
|
||||
#error exFAT feature wants C99 or later
|
||||
#endif
|
||||
typedef QWORD FSIZE_t;
|
||||
#if FF_LBA64
|
||||
typedef QWORD LBA_t;
|
||||
#else
|
||||
typedef DWORD LBA_t;
|
||||
#endif
|
||||
#else
|
||||
#if FF_LBA64
|
||||
#error exFAT needs to be enabled when enable 64-bit LBA
|
||||
#endif
|
||||
typedef DWORD FSIZE_t;
|
||||
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 */
|
||||
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 */
|
||||
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 */
|
||||
typedef DWORD TCHAR;
|
||||
#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 */
|
||||
typedef char TCHAR;
|
||||
#define _T(x) x
|
||||
#define _TEXT(x) x
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Definitions of volume management */
|
||||
|
||||
#if FF_MULTI_PARTITION /* Multiple partition configuration */
|
||||
typedef struct {
|
||||
BYTE pd; /* Physical drive number */
|
||||
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
|
||||
} PARTITION;
|
||||
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 */
|
||||
#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] */
|
||||
#if FF_MAX_SS != FF_MIN_SS
|
||||
WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */
|
||||
#endif
|
||||
#if FF_USE_LFN
|
||||
WCHAR* lfnbuf; /* LFN working buffer */
|
||||
#endif
|
||||
#if FF_FS_EXFAT
|
||||
BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */
|
||||
#endif
|
||||
#if FF_FS_REENTRANT
|
||||
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 */
|
||||
#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 */
|
||||
#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) */
|
||||
#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 */
|
||||
#if FF_FS_EXFAT
|
||||
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) */
|
||||
} 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) */
|
||||
#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) */
|
||||
#endif
|
||||
#if FF_FS_LOCK
|
||||
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) */
|
||||
#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) */
|
||||
#endif
|
||||
#if FF_USE_FASTSEEK
|
||||
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 */
|
||||
#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]} */
|
||||
#if FF_USE_LFN
|
||||
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 */
|
||||
#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 */
|
||||
#if FF_USE_LFN
|
||||
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 */
|
||||
#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) */
|
||||
} 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 */
|
||||
} 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 */
|
||||
|
||||
#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_unmount(path) f_mount(0, path, 0)
|
||||
|
||||
|
||||
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
/* Additional user defined functions */
|
||||
|
||||
/* RTC function */
|
||||
#if !FF_FS_READONLY && !FF_FS_NORTC
|
||||
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 */
|
||||
#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 */
|
||||
#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 */
|
||||
#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
|
||||
|
||||
/* Fast seek controls (2nd argument of f_lseek) */
|
||||
#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
|
||||
|
||||
/* Filesystem type (FATFS.fs_type) */
|
||||
#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 */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FF_DEFINED */
|
||||
|
|
@ -1,430 +0,0 @@
|
|||
#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 <chrono>
|
||||
#include <mutex>
|
||||
|
||||
#include <log_freetype.h>
|
||||
|
||||
struct sectorCache {
|
||||
LBA_t sectorIdx = std::numeric_limits<LBA_t>::max();
|
||||
bool dirty = false;
|
||||
BYTE* buffer = nullptr;
|
||||
std::list<sectorCache*>::iterator it;
|
||||
};
|
||||
|
||||
sectorCache emptySector = {};
|
||||
|
||||
struct driveCache {
|
||||
bool initialized = false;
|
||||
BYTE pdrv = 0;
|
||||
uint32_t sectorSize = 0;
|
||||
uint32_t sectorCount = 0;
|
||||
BYTE* sectorsBuffer = nullptr;
|
||||
|
||||
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;
|
||||
|
||||
DWORD lastDirTable = 0xFFFFFFFF;
|
||||
DWORD cachedDirLastAllocatedIdx = 0;
|
||||
|
||||
sectorCache* activeCacheWindow = &emptySector;
|
||||
};
|
||||
|
||||
std::array<driveCache, FF_VOLUMES> fatCaches;
|
||||
|
||||
static void cache_addLRUEntry(driveCache* cache, sectorCache *ptr) {
|
||||
ptr->it = cache->lruSectors.emplace(cache->lruSectors.end(), ptr);
|
||||
}
|
||||
|
||||
static sectorCache* cache_getLRUEntry(driveCache* cache) {
|
||||
return cache->lruSectors.front();
|
||||
}
|
||||
|
||||
static void cache_makeMRU(driveCache* cache, sectorCache *ptr) {
|
||||
cache->lruSectors.splice(cache->lruSectors.end(), cache->lruSectors, ptr->it);
|
||||
}
|
||||
|
||||
static sectorCache* cache_getFreeSector(driveCache* cache) {
|
||||
if (cache->freeSectors.empty())
|
||||
return nullptr;
|
||||
|
||||
sectorCache* cached = cache->freeSectors.back();
|
||||
cache->freeSectors.resize(cache->freeSectors.size()-1);
|
||||
return cached;
|
||||
}
|
||||
|
||||
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) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return maxSectorCount;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (res != FS_ERROR_OK) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (res != FS_ERROR_OK) {
|
||||
return RES_ERROR;
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
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);
|
||||
if (ptr == nullptr || !ptr->dirty) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return maxFlushableSectorCount;
|
||||
}
|
||||
|
||||
static void cache_flushSectorRange(driveCache* cache, sectorCache* sector) {
|
||||
if (!sector->dirty)
|
||||
return;
|
||||
|
||||
auto count = cache_getFlushableRange(cache, sector->sectorIdx);
|
||||
if (count == 0) {
|
||||
OSFatal("[ffcache] There shouldn't be a zero here?!\n");
|
||||
return;
|
||||
}
|
||||
//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);
|
||||
writeSector->dirty = false;
|
||||
}
|
||||
cache_doRawWrite(cache, sector->sectorIdx, count, alignedBuffer);
|
||||
free(alignedBuffer);
|
||||
}
|
||||
|
||||
//static void cache_flushSingleSector(driveCache* cache, sectorCache* sector) {
|
||||
// if (sector->dirty) {
|
||||
// sector->dirty = false;
|
||||
// BYTE* alignedBuffer = (BYTE*)aligned_alloc(0x40, 1*cache->sectorSize);
|
||||
// memcpy(alignedBuffer, sector->buffer.data(), cache->sectorSize);
|
||||
// cache_doRawWrite(cache, sector->sectorIdx, 1, alignedBuffer);
|
||||
// free(alignedBuffer);
|
||||
// }
|
||||
//}
|
||||
|
||||
static sectorCache* cache_getNewUncachedSector(driveCache* cache, LBA_t sectorIdx) {
|
||||
auto newSector = cache_getFreeSector(cache);
|
||||
if (newSector != nullptr) {
|
||||
newSector->sectorIdx = sectorIdx;
|
||||
newSector->dirty = false;
|
||||
cache_addLRUEntry(cache, newSector);
|
||||
cache->cachedSectors.emplace(sectorIdx, newSector);
|
||||
return newSector;
|
||||
}
|
||||
|
||||
// Free oldest sector by replacing contents and moving it to the front
|
||||
newSector = cache_getLRUEntry(cache);
|
||||
cache_flushSectorRange(cache, newSector);
|
||||
cache->cachedSectors.erase(newSector->sectorIdx);
|
||||
newSector->sectorIdx = sectorIdx;
|
||||
newSector->dirty = false;
|
||||
cache_makeMRU(cache, newSector);
|
||||
cache->cachedSectors.emplace(sectorIdx, newSector);
|
||||
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);
|
||||
if (ptr == nullptr)
|
||||
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);
|
||||
if (ptr != nullptr) {
|
||||
if (outputBuff != nullptr)
|
||||
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);
|
||||
if (outputBuff != nullptr)
|
||||
memcpy(outputBuff+(i*cache->sectorSize), newPtr->buffer, cache->sectorSize);
|
||||
}
|
||||
free(alignedBuffer);
|
||||
i += (readRange-1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
DRESULT ffcache_initialize(BYTE pdrv, DWORD sectorByteSize, DWORD sectorCount) {
|
||||
if (fatCaches[pdrv].initialized)
|
||||
return RES_ERROR;
|
||||
|
||||
OSReport("[ffcache] Initializing cache...\n");
|
||||
|
||||
fatCaches[pdrv].initialized = true;
|
||||
fatCaches[pdrv].sectorSize = sectorByteSize;
|
||||
fatCaches[pdrv].sectorCount = sectorCount;
|
||||
fatCaches[pdrv].pdrv = pdrv;
|
||||
|
||||
fatCaches[pdrv].freeSectors.clear();
|
||||
fatCaches[pdrv].cachedSectors.clear();
|
||||
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)});
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
DRESULT ffcache_flushSectors(BYTE pdrv) {
|
||||
auto cache = &fatCaches[pdrv];
|
||||
if (!cache->initialized)
|
||||
return RES_ERROR;
|
||||
|
||||
while (!cache->lruSectors.empty()) {
|
||||
sectorCache* sector = cache->lruSectors.front();
|
||||
cache_flushSectorRange(cache, sector);
|
||||
cache->cachedSectors.erase(sector->sectorIdx);
|
||||
cache->freeSectors.emplace_back(sector);
|
||||
cache->lruSectors.pop_front();
|
||||
}
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
void ffcache_shutdown(BYTE pdrv) {
|
||||
auto cache = &fatCaches[pdrv];
|
||||
if (!fatCaches[pdrv].initialized)
|
||||
return;
|
||||
|
||||
// Delete all sectors
|
||||
ffcache_flushSectors(pdrv);
|
||||
while (!cache->freeSectors.empty()) {
|
||||
sectorCache* sector = cache->freeSectors.back();
|
||||
cache_flushSectorRange(cache, sector);
|
||||
cache->freeSectors.pop_back();
|
||||
delete sector;
|
||||
}
|
||||
|
||||
free(cache->sectorsBuffer);
|
||||
dirCache_clear(pdrv);
|
||||
OSReport("[ffcache] Clearing %d cachedSectors, %d freeSectors, %d lruSectors...\n", cache->cachedSectors.size(), cache->freeSectors.size(), cache->lruSectors.size());
|
||||
fatCaches[pdrv].initialized = false;
|
||||
}
|
||||
|
||||
DRESULT ffcache_readSectors(BYTE pdrv, LBA_t sectorOffset, UINT sectorCount, BYTE *bufferOut) {
|
||||
if (!fatCaches[pdrv].initialized)
|
||||
return RES_ERROR;
|
||||
|
||||
cache_readSectors(&fatCaches[pdrv], sectorOffset, sectorCount, bufferOut);
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
DRESULT ffcache_writeSectors(BYTE pdrv, LBA_t sectorOffset, UINT sectorCount, const BYTE *bufferIn) {
|
||||
if (!fatCaches[pdrv].initialized)
|
||||
return RES_ERROR;
|
||||
|
||||
cache_writeSectors(&fatCaches[pdrv], sectorOffset, sectorCount, bufferIn);
|
||||
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
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 {
|
||||
sector = cache_getCachedSector(cache, sectorOffset);
|
||||
if (sector == nullptr) {
|
||||
sector = cache_getNewUncachedSector(cache, sectorOffset);
|
||||
cache_doRawRead(cache, sectorOffset, 1, sector->buffer);
|
||||
}
|
||||
else {
|
||||
cache_makeMRU(&fatCaches[pdrv], sector);
|
||||
}
|
||||
fatCaches[pdrv].activeCacheWindow = sector;
|
||||
}
|
||||
sector->dirty = true;
|
||||
return sector->buffer;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
});
|
||||
if (!inserted) {
|
||||
DEBUG_OSReport("Tried inserting shortname %.011s twice?!", cache->fn);
|
||||
OSSleepTicks(OSSecondsToTicks(3));
|
||||
}
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
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);
|
||||
#if USE_DEBUG_STUBS
|
||||
std::string str;
|
||||
std::transform(utf16KeyName.begin(), utf16KeyName.end(), std::back_inserter(str), [](wchar_t 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
|
||||
});
|
||||
#if USE_DEBUG_STUBS
|
||||
if (!inserted) {
|
||||
DEBUG_OSReport("Tried inserting shortname %.030s twice?!", str.c_str());
|
||||
OSSleepTicks(OSSecondsToTicks(3));
|
||||
}
|
||||
#endif
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return &it->second;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void dirCache_clear(BYTE pdrv) {
|
||||
DEBUG_OSReport("Clear dirCache!");
|
||||
fatCaches[pdrv].cachedDirLastAllocatedIdx = 0;
|
||||
fatCaches[pdrv].lastDirTable = 0xFFFFFFFF;
|
||||
fatCaches[pdrv].cachedDirSFNs.clear();
|
||||
fatCaches[pdrv].cachedDirLFNs.clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void dirCache_setLastAllocatedIdx(BYTE pdrv, DWORD lastIdx, DWORD lastDirTable) {
|
||||
if (lastDirTable == fatCaches[pdrv].lastDirTable) {
|
||||
if (lastIdx <= fatCaches[pdrv].cachedDirLastAllocatedIdx) {
|
||||
DEBUG_OSReport("HOW CAN THE INDEX BE SMALLER?!");
|
||||
//OSFatal("HOW CAN THE INDEX BE SMALLER?!\n");
|
||||
}
|
||||
fatCaches[pdrv].cachedDirLastAllocatedIdx = lastIdx;
|
||||
}
|
||||
else {
|
||||
fatCaches[pdrv].lastDirTable = lastDirTable;
|
||||
fatCaches[pdrv].cachedDirLastAllocatedIdx = 0;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD dirCache_getLastClusterIdx(BYTE pdrv, DWORD currDirTableIdx) {
|
||||
if (currDirTableIdx != fatCaches[pdrv].lastDirTable) return 0;
|
||||
return fatCaches[pdrv].cachedDirLastAllocatedIdx;
|
||||
}
|
||||
|
||||
|
||||
std::mutex _mutex;
|
||||
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();
|
||||
}
|
||||
|
||||
uint64_t profile_startSegment() {
|
||||
return cache_getTime();
|
||||
}
|
||||
|
||||
void profile_endSegment(const char* segmentName, uint64_t startTime) {
|
||||
std::scoped_lock<std::mutex> lck(_mutex);
|
||||
double timeSpent = (double)(cache_getTime() - startTime);
|
||||
segmentTimes[segmentName] += timeSpent;
|
||||
}
|
||||
|
||||
void profile_incrementCounter(const char* segmentName) {
|
||||
std::scoped_lock<std::mutex> lck(_mutex);
|
||||
segmentTimes[segmentName] += 1.0f;
|
||||
}
|
||||
|
||||
double profile_getSegment(const char* segmentName) {
|
||||
std::scoped_lock<std::mutex> lck(_mutex);
|
||||
double ret = segmentTimes[segmentName];
|
||||
segmentTimes[segmentName] = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
#ifndef _FFCACHE_DEFINED
|
||||
#define _FFCACHE_DEFINED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "ff.h"
|
||||
#include "diskio.h"
|
||||
|
||||
DRESULT ffcache_initialize(BYTE pdrv, DWORD sectorByteSize, DWORD sectorCount);
|
||||
void ffcache_shutdown(BYTE pdrv);
|
||||
|
||||
DRESULT ffcache_readSectors(BYTE pdrv, LBA_t sectorOffset, UINT sectorCount, BYTE *bufferOut);
|
||||
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);
|
||||
|
||||
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;
|
||||
} dirCache;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
void dirCache_setLastAllocatedIdx(BYTE pdrv, DWORD lastIdx, DWORD lastDirTable);
|
||||
DWORD dirCache_getLastClusterIdx(BYTE pdrv, DWORD currDirTableIdx);
|
||||
void dirCache_clear(BYTE pdrv);
|
||||
|
||||
|
||||
#if USE_DEBUG_STUBS
|
||||
#define DEBUG_OSReport(fmt, args...) OSReport(fmt "\n", ## args)
|
||||
#else
|
||||
#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);
|
||||
#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 );
|
||||
#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)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _FFCACHE_DEFINED */
|
||||
|
|
@ -1,305 +0,0 @@
|
|||
/*---------------------------------------------------------------------------/
|
||||
/ FatFs Functional Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#define FFCONF_DEF 86631 /* Revision ID */
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Function Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#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
|
||||
/* This option defines minimization level to remove some basic API functions.
|
||||
/
|
||||
/ 0: Basic functions are fully enabled.
|
||||
/ 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename()
|
||||
/ are removed.
|
||||
/ 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
|
||||
/ 3: f_lseek() function is removed in addition to 2. */
|
||||
|
||||
|
||||
#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
|
||||
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_FASTSEEK 0
|
||||
/* This option switches fast seek function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#define FF_USE_EXPAND 1
|
||||
/* This option switches f_expand function. (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#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
|
||||
/* This option switches volume label functions, f_getlabel() and f_setlabel().
|
||||
/ (0:Disable or 1:Enable) */
|
||||
|
||||
|
||||
#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
|
||||
/* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and
|
||||
/ f_printf().
|
||||
/
|
||||
/ 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect.
|
||||
/ 1: Enable without LF-CRLF conversion.
|
||||
/ 2: Enable with LF-CRLF conversion.
|
||||
/
|
||||
/ FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2
|
||||
makes f_printf() support floating point argument. These features want C99 or later.
|
||||
/ When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character
|
||||
/ encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE
|
||||
/ to be read/written via those functions.
|
||||
/
|
||||
/ 0: ANSI/OEM in current CP
|
||||
/ 1: Unicode in UTF-16LE
|
||||
/ 2: Unicode in UTF-16BE
|
||||
/ 3: Unicode in UTF-8
|
||||
*/
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Locale and Namespace Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#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.
|
||||
/
|
||||
/ 437 - U.S.
|
||||
/ 720 - Arabic
|
||||
/ 737 - Greek
|
||||
/ 771 - KBL
|
||||
/ 775 - Baltic
|
||||
/ 850 - Latin 1
|
||||
/ 852 - Latin 2
|
||||
/ 855 - Cyrillic
|
||||
/ 857 - Turkish
|
||||
/ 860 - Portuguese
|
||||
/ 861 - Icelandic
|
||||
/ 862 - Hebrew
|
||||
/ 863 - Canadian French
|
||||
/ 864 - Arabic
|
||||
/ 865 - Nordic
|
||||
/ 866 - Russian
|
||||
/ 869 - Greek 2
|
||||
/ 932 - Japanese (DBCS)
|
||||
/ 936 - Simplified Chinese (DBCS)
|
||||
/ 949 - Korean (DBCS)
|
||||
/ 950 - Traditional Chinese (DBCS)
|
||||
/ 0 - Include all code pages above and configured by f_setcp()
|
||||
*/
|
||||
|
||||
|
||||
#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.
|
||||
/ 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
|
||||
/ 2: Enable LFN with dynamic working buffer on the STACK.
|
||||
/ 3: Enable LFN with dynamic working buffer on the HEAP.
|
||||
/
|
||||
/ To enable the LFN, ffunicode.c needs to be added to the project. The LFN function
|
||||
/ requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and
|
||||
/ additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled.
|
||||
/ The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can
|
||||
/ be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN
|
||||
/ specification.
|
||||
/ When use stack for the working buffer, take care on stack overflow. When use heap
|
||||
/ memory for the working buffer, memory management functions, ff_memalloc() and
|
||||
/ ff_memfree() exemplified in ffsystem.c, need to be added to the project. */
|
||||
|
||||
|
||||
#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)
|
||||
/ 1: Unicode in UTF-16 (TCHAR = WCHAR)
|
||||
/ 2: Unicode in UTF-8 (TCHAR = char)
|
||||
/ 3: Unicode in UTF-32 (TCHAR = DWORD)
|
||||
/
|
||||
/ Also behavior of string I/O functions will be affected by this option.
|
||||
/ When LFN is not enabled, this option has no effect. */
|
||||
|
||||
|
||||
#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
|
||||
/* This option configures support for relative path.
|
||||
/
|
||||
/ 0: Disable relative path and remove related functions.
|
||||
/ 1: Enable relative path. f_chdir() and f_chdrive() are available.
|
||||
/ 2: f_getcwd() function is available in addition to 1.
|
||||
*/
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------/
|
||||
/ Drive/Volume Configurations
|
||||
/---------------------------------------------------------------------------*/
|
||||
|
||||
#if USE_RAMDISK == 1
|
||||
#define FF_VOLUMES 1
|
||||
#else
|
||||
#define FF_VOLUMES 3
|
||||
#endif
|
||||
/* Number of volumes (logical drives) to be used. (1-10) */
|
||||
|
||||
|
||||
#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
|
||||
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
|
||||
/ logical drives. Number of items must not be less than FF_VOLUMES. Valid
|
||||
/ characters for the volume ID strings are A-Z, a-z and 0-9, however, they are
|
||||
/ compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is
|
||||
/ not defined, a user defined volume string table needs to be defined as:
|
||||
/
|
||||
/ const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",...
|
||||
*/
|
||||
|
||||
|
||||
#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.
|
||||
/ When this function is enabled (1), each logical drive number can be bound to
|
||||
/ arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk()
|
||||
/ funciton will be available. */
|
||||
|
||||
|
||||
#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
|
||||
/ type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured
|
||||
/ for variable sector size mode and disk_ioctl() function needs to implement
|
||||
/ GET_SECTOR_SIZE command. */
|
||||
|
||||
|
||||
#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
|
||||
/* 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
|
||||
/* 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
|
||||
/* 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
|
||||
/* 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
|
||||
/* 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
|
||||
/ defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time.
|
||||
/ To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be
|
||||
/ added to the project to read current time form real-time clock. FF_NORTC_MON,
|
||||
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
|
||||
/ These options have no effect in read-only configuration (FF_FS_READONLY = 1). */
|
||||
|
||||
|
||||
#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.
|
||||
/
|
||||
/ bit0=0: Use free cluster count in the FSINFO if available.
|
||||
/ bit0=1: Do not trust free cluster count in the FSINFO.
|
||||
/ bit1=0: Use last allocated cluster number in the FSINFO if available.
|
||||
/ bit1=1: Do not trust last allocated cluster number in the FSINFO.
|
||||
*/
|
||||
|
||||
|
||||
#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.
|
||||
/
|
||||
/ 0: Disable file lock function. To avoid volume corruption, application program
|
||||
/ should avoid illegal open, remove and rename to the open objects.
|
||||
/ >0: Enable file lock function. The value defines how many files/sub-directories
|
||||
/ can be opened simultaneously under file lock control. Note that the file
|
||||
/ lock control is independent of re-entrancy. */
|
||||
|
||||
|
||||
/* #include <somertos.h> // O/S definitions */
|
||||
#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()
|
||||
/ and f_fdisk() function, are always not re-entrant. Only file/directory access
|
||||
/ to the same volume is under control of this function.
|
||||
/
|
||||
/ 0: Disable re-entrancy. FF_FS_TIMEOUT and FF_SYNC_t have no effect.
|
||||
/ 1: Enable re-entrancy. Also user provided synchronization handlers,
|
||||
/ ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
|
||||
/ function, must be added to the project. Samples are available in
|
||||
/ option/syscall.c.
|
||||
/
|
||||
/ The FF_FS_TIMEOUT defines timeout period in unit of time tick.
|
||||
/ The FF_SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
|
||||
/ SemaphoreHandle_t and etc. A header file for O/S definitions needs to be
|
||||
/ included somewhere in the scope of ff.h. */
|
||||
|
||||
|
||||
|
||||
/*--- End of configuration options ---*/
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
/*------------------------------------------------------------------------*/
|
||||
/* Sample Code of OS Dependent Functions for FatFs */
|
||||
/* (C)ChaN, 2018 */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "ff.h"
|
||||
|
||||
|
||||
#if FF_USE_LFN == 3 /* Dynamic memory allocation */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Allocate a memory block */
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
#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 */
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* 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 */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if FF_FS_REENTRANT /* Mutal exclusion */
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Create a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to create a new
|
||||
/ synchronization object for the volume, such as semaphore and mutex.
|
||||
/ When a 0 is returned, the f_mount() function fails with FR_INT_ERR.
|
||||
*/
|
||||
|
||||
//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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* FreeRTOS */
|
||||
// *sobj = xSemaphoreCreateMutex();
|
||||
// return (int)(*sobj != NULL);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// *sobj = osMutexCreate(&Mutex[vol]);
|
||||
// return (int)(*sobj != NULL);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Delete a Synchronization Object */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called in f_mount() function to delete a synchronization
|
||||
/ object that created with ff_cre_syncobj() function. When a 0 is returned,
|
||||
/ 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* FreeRTOS */
|
||||
// vSemaphoreDelete(sobj);
|
||||
// return 1;
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexDelete(sobj) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Request Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* This function is called on entering file functions to lock the volume.
|
||||
/ 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* FreeRTOS */
|
||||
// return (int)(xSemaphoreTake(sobj, FF_FS_TIMEOUT) == pdTRUE);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// return (int)(osMutexWait(sobj, FF_FS_TIMEOUT) == osOK);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* Release Grant to Access the Volume */
|
||||
/*------------------------------------------------------------------------*/
|
||||
/* 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);
|
||||
|
||||
/* uITRON */
|
||||
// sig_sem(sobj);
|
||||
|
||||
/* uC/OS-II */
|
||||
// OSMutexPost(sobj);
|
||||
|
||||
/* FreeRTOS */
|
||||
// xSemaphoreGive(sobj);
|
||||
|
||||
/* CMSIS-RTOS */
|
||||
// osMutexRelease(sobj);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
15593
src/fatfs/ffunicode.c
15593
src/fatfs/ffunicode.c
File diff suppressed because it is too large
Load Diff
14
src/main.cpp
14
src/main.cpp
|
|
@ -111,7 +111,7 @@ static Title *loadWiiUTitles(int run) {
|
|||
int tNoSave = usable;
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
for (uint8_t a = 0; a < 2; a++) {
|
||||
std::string path = stringFormat("%s/usr/save/%08x", (i == 0) ? getUSB().c_str() : "storage_mlc01:", highIDs[a]);
|
||||
std::string path = stringFormat("%s/usr/save/%08x", (i == 0) ? getUSB().c_str() : "/vol/storage_mlc01", highIDs[a]);
|
||||
DIR *dir = opendir(path.c_str());
|
||||
if (dir != nullptr) {
|
||||
struct dirent *data;
|
||||
|
|
@ -119,9 +119,9 @@ static Title *loadWiiUTitles(int run) {
|
|||
if (data->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
path = stringFormat("%s/usr/save/%08x/%s/user", (i == 0) ? getUSB().c_str() : "storage_mlc01:", highIDs[a], data->d_name);
|
||||
path = stringFormat("%s/usr/save/%08x/%s/user", (i == 0) ? getUSB().c_str() : "/vol/storage_mlc01", highIDs[a], data->d_name);
|
||||
if (checkEntry(path.c_str()) == 2) {
|
||||
path = stringFormat("%s/usr/save/%08x/%s/meta/meta.xml", (i == 0) ? getUSB().c_str() : "storage_mlc01:", highIDs[a],
|
||||
path = stringFormat("%s/usr/save/%08x/%s/meta/meta.xml", (i == 0) ? getUSB().c_str() : "/vol/storage_mlc01", highIDs[a],
|
||||
data->d_name);
|
||||
if (checkEntry(path.c_str()) == 1) {
|
||||
for (int i = 0; i < usable; i++) {
|
||||
|
|
@ -150,7 +150,7 @@ static Title *loadWiiUTitles(int run) {
|
|||
|
||||
for (uint8_t a = 0; a < 2; a++) {
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
std::string path = stringFormat("%s/usr/save/%08x", (i == 0) ? getUSB().c_str() : "storage_mlc01:", highIDs[a]);
|
||||
std::string path = stringFormat("%s/usr/save/%08x", (i == 0) ? getUSB().c_str() : "/vol/storage_mlc01", highIDs[a]);
|
||||
DIR *dir = opendir(path.c_str());
|
||||
if (dir != nullptr) {
|
||||
struct dirent *data;
|
||||
|
|
@ -158,7 +158,7 @@ static Title *loadWiiUTitles(int run) {
|
|||
if (data->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
path = stringFormat("%s/usr/save/%08x/%s/meta/meta.xml", (i == 0) ? getUSB().c_str() : "storage_mlc01:", highIDs[a],
|
||||
path = stringFormat("%s/usr/save/%08x/%s/meta/meta.xml", (i == 0) ? getUSB().c_str() : "/vol/storage_mlc01", highIDs[a],
|
||||
data->d_name);
|
||||
if (checkEntry(path.c_str()) == 1) {
|
||||
saves[pos].highID = highIDs[a];
|
||||
|
|
@ -194,7 +194,7 @@ static Title *loadWiiUTitles(int run) {
|
|||
uint32_t lowID = saves[i].lowID;
|
||||
bool isTitleOnUSB = saves[i].dev == 0u;
|
||||
|
||||
const std::string path = stringFormat("%s/usr/%s/%08x/%08x/meta/meta.xml", isTitleOnUSB ? getUSB().c_str() : "storage_mlc01:",
|
||||
const std::string path = stringFormat("%s/usr/%s/%08x/%08x/meta/meta.xml", isTitleOnUSB ? getUSB().c_str() : "/vol/storage_mlc01",
|
||||
saves[i].found ? "title" : "save", highID, lowID);
|
||||
titles[wiiuTitlesCount].saveInit = !saves[i].found;
|
||||
|
||||
|
|
@ -954,7 +954,7 @@ int main() {
|
|||
}
|
||||
}
|
||||
std::string path = stringFormat("%s/usr/title/000%x/%x/code/fw.img",
|
||||
(titles[targ].isTitleOnUSB) ? getUSB().c_str() : "storage_mlc01:", titles[targ].highID,
|
||||
(titles[targ].isTitleOnUSB) ? getUSB().c_str() : "/vol/storage_mlc01", titles[targ].highID,
|
||||
titles[targ].lowID);
|
||||
if ((mode == WiiU) && (checkEntry(path.c_str()) != 0))
|
||||
if (!promptConfirm(ST_ERROR, gettext("vWii saves are in the vWii section. Continue?")))
|
||||
|
|
|
|||
110
src/savemng.cpp
110
src/savemng.cpp
|
|
@ -9,8 +9,6 @@
|
|||
#include <savemng.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "fatfs/extusb_devoptab/extusb_devoptab.h"
|
||||
|
||||
#define IO_MAX_FILE_BUFFER (1024 * 1024) // 1 MB
|
||||
|
||||
static char *p1;
|
||||
|
|
@ -32,18 +30,7 @@ static file_buffer buffers[16];
|
|||
static char *fileBuf[2];
|
||||
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) {
|
||||
replace(path, "storage_mlc01:", "/vol/storage_mlc01");
|
||||
} else if(path.rfind("storage_usb01:", 0) == 0) {
|
||||
replace(path, "storage_usb01:", "/vol/storage_usb01");
|
||||
} else if(path.rfind("storage_usb02:", 0) == 0) {
|
||||
replace(path, "storage_usb02:", "/vol/storage_usb02");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
extern "C" FSClient *__wut_devoptab_fs_client;
|
||||
|
||||
int checkEntry(const char *fPath) {
|
||||
struct stat st;
|
||||
|
|
@ -63,27 +50,20 @@ bool initFS() {
|
|||
if (ret)
|
||||
ret = Mocha_UnlockFSClientEx(handle) == MOCHA_RESULT_SUCCESS;
|
||||
if (ret) {
|
||||
Mocha_UnlockFSClient(__wut_devoptab_fs_client);
|
||||
Mocha_MountFS("storage_slccmpt01", nullptr, "/vol/storage_slccmpt01");
|
||||
Mocha_MountFS("storage_slccmpt01", "/dev/slccmpt01", "/vol/storage_slccmpt01");
|
||||
Mocha_MountFS("storage_mlc01", nullptr, "/vol/storage_mlc01");
|
||||
Mocha_MountFS("storage_usb01", nullptr, "/vol/storage_usb01");
|
||||
Mocha_MountFS("storage_usb02", nullptr, "/vol/storage_usb02");
|
||||
if (checkEntry("storage_usb01:/usr") == 2)
|
||||
usb = "storage_usb01:";
|
||||
else if (checkEntry("storage_usb02:/usr") == 2)
|
||||
usb = "storage_usb02:";
|
||||
init_extusb_devoptab();
|
||||
if (checkEntry("/vol/storage_usb01/usr") == 2)
|
||||
usb = "/vol/storage_usb01";
|
||||
else if (checkEntry("/vol/storage_usb02/usr") == 2)
|
||||
usb = "/vol/storage_usb02";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void deinitFS() {
|
||||
fini_extusb_devoptab();
|
||||
Mocha_UnmountFS("storage_slccmpt01");
|
||||
Mocha_UnmountFS("storage_mlc01");
|
||||
Mocha_UnmountFS("storage_usb01");
|
||||
Mocha_UnmountFS("storage_usb02");
|
||||
Mocha_DeInitLibrary();
|
||||
FSADelClient(handle);
|
||||
FSAShutdown();
|
||||
|
|
@ -160,9 +140,9 @@ int32_t loadTitleIcon(Title *title) {
|
|||
}
|
||||
} else {
|
||||
if (title->saveInit)
|
||||
path = stringFormat("%s/usr/save/%08x/%08x/meta/iconTex.tga", isUSB ? getUSB().c_str() : "storage_mlc01:", highID, lowID);
|
||||
path = stringFormat("%s/usr/save/%08x/%08x/meta/iconTex.tga", isUSB ? getUSB().c_str() : "/vol/storage_mlc01", highID, lowID);
|
||||
else
|
||||
path = stringFormat("%s/usr/title/%08x/%08x/meta/iconTex.tga", isUSB ? getUSB().c_str() : "storage_mlc01:", highID, lowID);
|
||||
path = stringFormat("%s/usr/title/%08x/%08x/meta/iconTex.tga", isUSB ? getUSB().c_str() : "/vol/storage_mlc01", highID, lowID);
|
||||
|
||||
return loadFile(path.c_str(), &title->iconBuf);
|
||||
}
|
||||
|
|
@ -199,7 +179,7 @@ static bool createFolder(const char *fPath) { //Adapted from mkdir_p made by Jon
|
|||
if (checkEntry(_path.c_str()) == 0) {
|
||||
if (mkdir(_path.c_str(), 0x660) == -1)
|
||||
return false;
|
||||
FSAChangeMode(handle, newlibtoFSA(_path).c_str(), (FSMode) 0x660);
|
||||
FSAChangeMode(handle, _path.c_str(), (FSMode) 0x660);
|
||||
}
|
||||
|
||||
*p = '/';
|
||||
|
|
@ -210,7 +190,7 @@ static bool createFolder(const char *fPath) { //Adapted from mkdir_p made by Jon
|
|||
if (checkEntry(_path.c_str()) == 0)
|
||||
if (mkdir(_path.c_str(), 0x660) == -1)
|
||||
return false;
|
||||
FSAChangeMode(handle, newlibtoFSA(_path).c_str(), (FSMode) 0x660);
|
||||
FSAChangeMode(handle, _path.c_str(), (FSMode) 0x660);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -411,7 +391,7 @@ void getAccountsSD(Title *title, uint8_t slot) {
|
|||
if (sdacc != nullptr)
|
||||
free(sdacc);
|
||||
|
||||
std::string path = stringFormat("sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
std::string path = stringFormat("/vol/external01/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
DIR *dir = opendir(path.c_str());
|
||||
if (dir != nullptr) {
|
||||
struct dirent *data;
|
||||
|
|
@ -523,7 +503,7 @@ static bool copyFile(std::string pPath, std::string oPath) {
|
|||
fclose(source);
|
||||
fclose(dest);
|
||||
|
||||
FSAChangeMode(handle, newlibtoFSA(oPath).c_str(), (FSMode) 0x660);
|
||||
FSAChangeMode(handle, oPath.c_str(), (FSMode) 0x660);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -534,7 +514,7 @@ static int copyDir(std::string pPath, std::string tPath) { // Source: ft2sd
|
|||
return -1;
|
||||
|
||||
mkdir(tPath.c_str(), 0x660);
|
||||
FSAChangeMode(handle, newlibtoFSA(tPath).c_str(), (FSMode) 0x660);
|
||||
FSAChangeMode(handle, tPath.c_str(), (FSMode) 0x660);
|
||||
auto *data = (dirent *) malloc(sizeof(dirent));
|
||||
|
||||
while ((data = readdir(dir)) != nullptr) {
|
||||
|
|
@ -547,7 +527,7 @@ static int copyDir(std::string pPath, std::string tPath) { // Source: ft2sd
|
|||
|
||||
if ((data->d_type & DT_DIR) != 0) {
|
||||
mkdir(targetPath.c_str(), 0x660);
|
||||
FSAChangeMode(handle, newlibtoFSA(targetPath).c_str(), (FSMode) 0x660);
|
||||
FSAChangeMode(handle, targetPath.c_str(), (FSMode) 0x660);
|
||||
if (copyDir(pPath + stringFormat("/%s", data->d_name), targetPath) != 0) {
|
||||
closedir(dir);
|
||||
return -2;
|
||||
|
|
@ -620,7 +600,7 @@ static std::string getUserID() { // Source: loadiine_gx2
|
|||
}
|
||||
|
||||
int getLoadiineGameSaveDir(char *out, const char *productCode, const char *longName, const uint32_t highID, const uint32_t lowID) {
|
||||
DIR *dir = opendir("sd:/wiiu/saves");
|
||||
DIR *dir = opendir("/vol/external01/wiiu/saves");
|
||||
|
||||
if (dir == nullptr)
|
||||
return -1;
|
||||
|
|
@ -628,7 +608,7 @@ int getLoadiineGameSaveDir(char *out, const char *productCode, const char *longN
|
|||
struct dirent *data;
|
||||
while ((data = readdir(dir)) != nullptr) {
|
||||
if (((data->d_type & DT_DIR) != 0) && ((strstr(data->d_name, productCode) != nullptr) || (strstr(data->d_name, stringFormat("%s [%08x%08x]", longName, highID, lowID).c_str()) != nullptr))) {
|
||||
sprintf(out, "sd:/wiiu/saves/%s", data->d_name);
|
||||
sprintf(out, "/vol/external01/wiiu/saves/%s", data->d_name);
|
||||
closedir(dir);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -684,9 +664,9 @@ static bool getLoadiineUserDir(char *out, const char *fullSavePath, const char *
|
|||
bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot) {
|
||||
std::string path;
|
||||
if (((highID & 0xFFFFFFF0) == 0x00010000) && (slot == 255))
|
||||
path = stringFormat("sd:/savegames/%08x%08x", highID, lowID);
|
||||
path = stringFormat("/vol/external01/savegames/%08x%08x", highID, lowID);
|
||||
else
|
||||
path = stringFormat("sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
path = stringFormat("/vol/external01/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
int ret = checkEntry(path.c_str());
|
||||
return ret <= 0;
|
||||
}
|
||||
|
|
@ -710,7 +690,7 @@ bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t s
|
|||
if (!isWii) {
|
||||
if (!inSD) {
|
||||
char path[PATH_SIZE];
|
||||
strcpy(path, (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save"));
|
||||
strcpy(path, (isUSB ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save"));
|
||||
if (user == 0) {
|
||||
sprintf(srcPath, "%s/%08x/%08x/%s/common", path, highID, lowID, "user");
|
||||
} else if (user == 0xFFFFFFFF) {
|
||||
|
|
@ -720,7 +700,7 @@ bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t s
|
|||
}
|
||||
} else {
|
||||
if (!iine) {
|
||||
sprintf(srcPath, "sd:/wiiu/backups/%08x%08x/%u/%08X", highID, lowID, slot, user);
|
||||
sprintf(srcPath, "/vol/external01/wiiu/backups/%08x%08x/%u/%08X", highID, lowID, slot, user);
|
||||
} else {
|
||||
if (getLoadiineGameSaveDir(srcPath, title->productCode, title->longName, title->highID, title->lowID) != 0) {
|
||||
return false;
|
||||
|
|
@ -742,7 +722,7 @@ bool hasAccountSave(Title *title, bool inSD, bool iine, uint32_t user, uint8_t s
|
|||
if (!inSD) {
|
||||
sprintf(srcPath, "storage_slccmpt01:/title/%08x/%08x/data", highID, lowID);
|
||||
} else {
|
||||
sprintf(srcPath, "sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
sprintf(srcPath, "/vol/external01/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
}
|
||||
}
|
||||
if (checkEntry(srcPath) == 2) {
|
||||
|
|
@ -764,11 +744,11 @@ bool hasCommonSave(Title *title, bool inSD, bool iine, uint8_t slot, int version
|
|||
std::string srcPath;
|
||||
if (!inSD) {
|
||||
char path[PATH_SIZE];
|
||||
strcpy(path, (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save"));
|
||||
strcpy(path, (isUSB ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save"));
|
||||
srcPath = stringFormat("%s/%08x/%08x/%s/common", path, highID, lowID, "user");
|
||||
} else {
|
||||
if (!iine) {
|
||||
srcPath = stringFormat("sd:/wiiu/backups/%08x%08x/%u/common", highID, lowID, slot);
|
||||
srcPath = stringFormat("/vol/external01/wiiu/backups/%08x%08x/%u/common", highID, lowID, slot);
|
||||
} else {
|
||||
if (getLoadiineGameSaveDir(srcPath.data(), title->productCode, title->longName, title->highID, title->lowID) != 0)
|
||||
return false;
|
||||
|
|
@ -799,8 +779,8 @@ void copySavedata(Title *title, Title *titleb, int8_t allusers, int8_t allusers_
|
|||
promptError(gettext("Backup done. Now copying Savedata."));
|
||||
}
|
||||
|
||||
std::string path = (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save");
|
||||
std::string pathb = (isUSBb ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save");
|
||||
std::string path = (isUSB ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save");
|
||||
std::string pathb = (isUSBb ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save");
|
||||
std::string srcPath = stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, "user");
|
||||
std::string dstPath = stringFormat("%s/%08x/%08x/%s", pathb.c_str(), highIDb, lowIDb, "user");
|
||||
createFolder(dstPath.c_str());
|
||||
|
|
@ -816,11 +796,11 @@ void copySavedata(Title *title, Title *titleb, int8_t allusers, int8_t allusers_
|
|||
|
||||
if (dstPath.rfind("storage_slccmpt01:", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_slccmpt01");
|
||||
} else if(dstPath.rfind("storage_mlc01:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_mlc01", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_mlc01");
|
||||
} else if(dstPath.rfind("storage_usb01:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_usb01", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_usb01");
|
||||
} else if(dstPath.rfind("storage_usb02:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_usb02", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_usb02");
|
||||
}
|
||||
}
|
||||
|
|
@ -848,9 +828,9 @@ void backupAllSave(Title *titles, int count, OSCalendarTime *date) {
|
|||
uint32_t lowID = titles[i].lowID;
|
||||
bool isUSB = titles[i].isTitleOnUSB;
|
||||
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
|
||||
const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save"));
|
||||
const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save"));
|
||||
std::string srcPath = stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, isWii ? "data" : "user");
|
||||
std::string dstPath = stringFormat("sd:/wiiu/backups/batch/%s/0/%08x%08x", datetime.c_str(), highID, lowID);
|
||||
std::string dstPath = stringFormat("/vol/external01/wiiu/backups/batch/%s/0/%08x%08x", datetime.c_str(), highID, lowID);
|
||||
|
||||
createFolder(dstPath.c_str());
|
||||
if (copyDir(srcPath, dstPath) != 0)
|
||||
|
|
@ -867,13 +847,13 @@ void backupSavedata(Title *title, uint8_t slot, int8_t allusers, bool common) {
|
|||
uint32_t lowID = title->lowID;
|
||||
bool isUSB = title->isTitleOnUSB;
|
||||
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
|
||||
const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save"));
|
||||
const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save"));
|
||||
std::string srcPath = stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, isWii ? "data" : "user");
|
||||
std::string dstPath;
|
||||
if (isWii && (slot == 255))
|
||||
dstPath = stringFormat("sd:/savegames/%08x%08x", highID, lowID);
|
||||
dstPath = stringFormat("/vol/external01/savegames/%08x%08x", highID, lowID);
|
||||
else
|
||||
dstPath = stringFormat("sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
dstPath = stringFormat("/vol/external01/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
createFolder(dstPath.c_str());
|
||||
|
||||
if ((allusers > -1) && !isWii) {
|
||||
|
|
@ -900,11 +880,11 @@ void backupSavedata(Title *title, uint8_t slot, int8_t allusers, bool common) {
|
|||
delete dateObj;
|
||||
if (dstPath.rfind("storage_slccmpt01:", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_slccmpt01");
|
||||
} else if(dstPath.rfind("storage_mlc01:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_mlc01", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_mlc01");
|
||||
} else if(dstPath.rfind("storage_usb01:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_usb01", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_usb01");
|
||||
} else if(dstPath.rfind("storage_usb02:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_usb02", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_usb02");
|
||||
}
|
||||
}
|
||||
|
|
@ -924,11 +904,11 @@ void restoreSavedata(Title *title, uint8_t slot, int8_t sdusers, int8_t allusers
|
|||
bool isUSB = title->isTitleOnUSB;
|
||||
bool isWii = ((highID & 0xFFFFFFF0) == 0x00010000);
|
||||
std::string srcPath;
|
||||
const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save"));
|
||||
const std::string path = (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save"));
|
||||
if (isWii && (slot == 255))
|
||||
srcPath = stringFormat("sd:/savegames/%08x%08x", highID, lowID);
|
||||
srcPath = stringFormat("/vol/external01/savegames/%08x%08x", highID, lowID);
|
||||
else
|
||||
srcPath = stringFormat("sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
srcPath = stringFormat("/vol/external01/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
|
||||
std::string dstPath = stringFormat("%s/%08x/%08x/%s", path.c_str(), highID, lowID, isWii ? "data" : "user");
|
||||
createFolder(dstPath.c_str());
|
||||
|
||||
|
|
@ -948,11 +928,11 @@ void restoreSavedata(Title *title, uint8_t slot, int8_t sdusers, int8_t allusers
|
|||
|
||||
if (dstPath.rfind("storage_slccmpt01:", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_slccmpt01");
|
||||
} else if(dstPath.rfind("storage_mlc01:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_mlc01", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_mlc01");
|
||||
} else if(dstPath.rfind("storage_usb01:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_usb01", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_usb01");
|
||||
} else if(dstPath.rfind("storage_usb02:", 0) == 0) {
|
||||
} else if(dstPath.rfind("/vol/storage_usb02", 0) == 0) {
|
||||
FSAFlushVolume(handle, "/vol/storage_usb02");
|
||||
}
|
||||
}
|
||||
|
|
@ -970,7 +950,7 @@ void wipeSavedata(Title *title, int8_t allusers, bool common) {
|
|||
char srcPath[PATH_SIZE];
|
||||
char origPath[PATH_SIZE];
|
||||
char path[PATH_SIZE];
|
||||
strcpy(path, (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "storage_mlc01:/usr/save")));
|
||||
strcpy(path, (isWii ? "storage_slccmpt01:/title" : (isUSB ? (getUSB() + "/usr/save").c_str() : "/vol/storage_mlc01/usr/save")));
|
||||
sprintf(srcPath, "%s/%08x/%08x/%s", path, highID, lowID, isWii ? "data" : "user");
|
||||
if ((allusers > -1) && !isWii) {
|
||||
uint32_t offset = strlen(srcPath);
|
||||
|
|
@ -1021,7 +1001,7 @@ void importFromLoadiine(Title *title, bool common, int version) {
|
|||
const char *usrPath = {getUserID().c_str()};
|
||||
uint32_t srcOffset = strlen(srcPath);
|
||||
getLoadiineUserDir(srcPath, srcPath, usrPath);
|
||||
sprintf(dstPath, "%s/usr/save/%08x/%08x/user", isUSB ? getUSB().c_str() : "storage_mlc01:", highID, lowID);
|
||||
sprintf(dstPath, "%s/usr/save/%08x/%08x/user", isUSB ? getUSB().c_str() : "/vol/storage_mlc01", highID, lowID);
|
||||
createFolder(dstPath);
|
||||
uint32_t dstOffset = strlen(dstPath);
|
||||
sprintf(dstPath + dstOffset, "/%s", usrPath);
|
||||
|
|
@ -1050,7 +1030,7 @@ void exportToLoadiine(Title *title, bool common, int version) {
|
|||
const char *usrPath = {getUserID().c_str()};
|
||||
uint32_t dstOffset = strlen(dstPath);
|
||||
getLoadiineUserDir(dstPath, dstPath, usrPath);
|
||||
sprintf(srcPath, "%s/usr/save/%08x/%08x/user", isUSB ? getUSB().c_str() : "storage_mlc01:", highID, lowID);
|
||||
sprintf(srcPath, "%s/usr/save/%08x/%08x/user", isUSB ? getUSB().c_str() : "/vol/storage_mlc01", highID, lowID);
|
||||
uint32_t srcOffset = strlen(srcPath);
|
||||
sprintf(srcPath + srcOffset, "/%s", usrPath);
|
||||
createFolder(dstPath);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user