diff --git a/include/fs.h b/include/fs.h
index d925d3c..ac2f4c6 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -21,7 +21,7 @@
#include "types.h"
#include "fatfs/ff.h"
-
+#define FS_MAX_DEVICES (2)
#define FS_MAX_DRIVES (FF_VOLUMES)
#define FS_DRIVE_NAMES FF_VOLUME_STRS
@@ -32,6 +32,12 @@
typedef enum
{
+ FS_DEVICE_SDMC = 0,
+ FS_DEVICE_NAND = 1
+} FsDevice;
+
+typedef enum
+{
FS_DRIVE_SDMC = 0,
FS_DRIVE_TWLN = 1,
FS_DRIVE_TWLP = 2,
@@ -51,11 +57,14 @@
typedef FILINFO FsFileInfo;
+typedef s32 DevHandle;
s32 fMount(FsDrive drive);
s32 fUnmount(FsDrive drive);
s32 fGetFree(FsDrive drive, u64 *size);
+s32 fPrepareRawAccess(FsDevice dev);
+s32 fFinalizeRawAccess(DevHandle handle);
s32 fOpen(const char *const path, FsOpenMode mode);
s32 fRead(s32 handle, void *const buf, u32 size);
s32 fWrite(s32 handle, const void *const buf, u32 size);
diff --git a/source/arm9/fs.c b/source/arm9/fs.c
index fb57749..71ca67f 100644
--- a/source/arm9/fs.c
+++ b/source/arm9/fs.c
@@ -16,6 +16,7 @@
* along with this program. If not, see .
*/
+#include
#include "types.h"
#include "fs.h"
#include "fatfs/ff.h"
@@ -33,6 +34,8 @@
static bool dStatTable[FS_MAX_DIRS] = {0};
static u32 dHandles = 0;
+static bool devStatTable[FS_MAX_DEVICES] = {0};
+static bool fsStatBackupTable[FS_MAX_DRIVES] = {0};
s32 fMount(FsDrive drive)
@@ -79,6 +82,49 @@
else return -res;
}
+s32 fPrepareRawAccess(FsDevice dev)
+{
+ if((u32)dev >= FS_MAX_DEVICES) return -30;
+ if(devStatTable[dev]) return -31;
+
+ if(dev != FS_DEVICE_NAND)
+ return -31;
+
+ memcpy(fsStatBackupTable, fsStatTable, sizeof(fsStatTable));
+
+ switch(dev)
+ {
+ case FS_DEVICE_SDMC:
+ fUnmount(FS_DRIVE_SDMC);
+ break;
+ case FS_DEVICE_NAND:
+ fUnmount(FS_DRIVE_TWLN);
+ fUnmount(FS_DRIVE_TWLP);
+ fUnmount(FS_DRIVE_NAND);
+ break;
+ default:
+ return -30; //panic();
+ }
+
+ devStatTable[dev] = true;
+
+ return FR_OK;
+}
+
+s32 fFinalizeRawAccess(DevHandle handle)
+{
+ if(handle != FR_OK) return -30;
+ if(!devStatTable[FS_DEVICE_NAND]) return -31;
+
+ for(u32 drive = 0; drive < FS_MAX_DRIVES; drive++)
+ {
+ if(fsStatBackupTable[drive])
+ fMount(drive);
+ }
+
+ return FR_OK;
+}
+
static s32 findUnusedFileSlot(void)
{
if(fHandles >= FS_MAX_FILES) return -1;
@@ -285,3 +331,5 @@
if(res == FR_OK) return res;
else return -res;
}
+
+