2022-04-14 22:41:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "IFSWrapper.h"
|
2022-09-10 21:24:58 +02:00
|
|
|
#include "utils/logger.h"
|
|
|
|
#include <coreinit/core.h>
|
2022-04-14 22:41:41 +02:00
|
|
|
#include <coreinit/filesystem.h>
|
2022-08-09 00:28:29 +02:00
|
|
|
#include <coreinit/filesystem_fsa.h>
|
2022-04-14 22:41:41 +02:00
|
|
|
#include <functional>
|
|
|
|
#include <mutex>
|
|
|
|
#include <romfs_dev.h>
|
|
|
|
#include <string>
|
|
|
|
|
2022-09-10 21:24:58 +02:00
|
|
|
struct FSIOThreadData {
|
|
|
|
OSThread *thread;
|
|
|
|
void *stack;
|
|
|
|
OSMessageQueue queue;
|
|
|
|
OSMessage messages[0x10];
|
|
|
|
bool setup;
|
|
|
|
char threadName[0x50];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct AsyncParamFS {
|
|
|
|
FSClient *client;
|
|
|
|
FSCmdBlock *block;
|
|
|
|
FSErrorFlag errorMask;
|
|
|
|
FSAsyncData asyncData;
|
|
|
|
IOSAsyncCallbackFn callback;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum FSShimSyncType {
|
|
|
|
FS_SHIM_TYPE_SYNC = 1,
|
|
|
|
FS_SHIM_TYPE_ASYNC = 2
|
|
|
|
} FSShimSyncType;
|
|
|
|
|
|
|
|
typedef enum FSShimApiType {
|
|
|
|
FS_SHIM_API_FS = 1,
|
|
|
|
FS_SHIM_API_FSA = 2
|
|
|
|
} FSShimApiType;
|
|
|
|
|
|
|
|
struct FSShimWrapper {
|
|
|
|
FSAShimBuffer *shim;
|
|
|
|
AsyncParamFS asyncFS;
|
|
|
|
FSShimSyncType sync;
|
|
|
|
FSShimApiType api;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FSShimWrapperMessage {
|
|
|
|
FSShimWrapper *param;
|
|
|
|
OSMessageQueue messageQueue;
|
|
|
|
OSMessage messages[0x1];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define FS_IO_QUEUE_COMMAND_STOP 0x13371337
|
|
|
|
#define FS_IO_QUEUE_COMMAND_PROCESS_FS_COMMAND 0x42424242
|
|
|
|
#define FS_IO_QUEUE_SYNC_RESULT 0x43434343
|
|
|
|
|
|
|
|
extern bool gThreadsRunning;
|
|
|
|
extern FSIOThreadData gThreadData[3];
|
2022-04-14 22:41:41 +02:00
|
|
|
extern std::mutex fsLayerMutex;
|
2022-04-29 13:34:04 +02:00
|
|
|
extern std::vector<std::unique_ptr<IFSWrapper>> fsLayers;
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-09-10 21:24:58 +02:00
|
|
|
#define fsaShimPrepareRequestReadFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, uint8_t * buffer, uint32_t size, uint32_t count, uint32_t pos, FSFileHandle handle, FSAReadFlag readFlags))(0x101C400 + 0x436cc))
|
|
|
|
#define fsaShimPrepareRequestWriteFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const uint8_t *buffer, uint32_t size, uint32_t count, uint32_t pos, FSFileHandle handle, FSAWriteFlag writeFlags))(0x101C400 + 0x437f4))
|
|
|
|
#define fsaShimPrepareRequestOpenFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *path, const char *mode, FSMode createMode, FSOpenFileFlags openFlag, uint32_t preallocSize))(0x101C400 + 0x43588))
|
|
|
|
#define fsaShimPrepareRequestCloseFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSFileHandle handle))(0x101C400 + 0x43a00))
|
|
|
|
#define fsaShimPrepareRequestStatFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSFileHandle handle))(0x101C400 + 0x43998))
|
|
|
|
#define fsaShimPrepareRequestQueryInfo ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *path, FSAQueryInfoType type))(0x101C400 + 0x44118))
|
|
|
|
#define fsaShimPrepareRequestSetPos ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSFileHandle handle, FSAFilePosition position))(0x101C400 + 0x43930))
|
|
|
|
#define fsaShimPrepareRequestGetPos ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSFileHandle handle))(0x101C400 + 0x438fc))
|
|
|
|
#define fsaShimPrepareRequestIsEof ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSFileHandle handle))(0x101C400 + 0x43964))
|
|
|
|
#define fsaShimPrepareRequestTruncate ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSFileHandle handle))(0x101C400 + 0x43a34))
|
|
|
|
#define fsaShimPrepareRequestRemove ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *))(0x101C400 + 0x43aa8))
|
|
|
|
#define fsaShimPrepareRequestRename ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *, const char *))(0x101C400 + 0x43bc0))
|
|
|
|
#define fsaShimPrepareRequestFlushFile ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSFileHandle handle))(0x101C400 + 0x439cc))
|
|
|
|
#define fsaShimPrepareRequestChangeMode ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *path, FSMode mode, FSMode modeMask))(0x101C400 + 0x43ff4))
|
|
|
|
|
|
|
|
#define fsaShimPrepareRequestOpenDir ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *path))(0x101C400 + 0x43458))
|
|
|
|
#define fsaShimPrepareRequestReadDir ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSDirectoryHandle handle))(0x101C400 + 0x434ec))
|
|
|
|
#define fsaShimPrepareRequestCloseDir ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSDirectoryHandle handle))(0x101C400 + 0x43554))
|
|
|
|
#define fsaShimPrepareRequestRewindDir ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, FSDirectoryHandle handle))(0x101C400 + 0x43520))
|
|
|
|
#define fsaShimPrepareRequestMakeDir ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *path, FSMode mode))(0x101C400 + 0x43314))
|
|
|
|
#define fsaShimPrepareRequestChangeDir ((FSError(*)(FSAShimBuffer * shim, IOSHandle clientHandle, const char *path))(0x101C400 + 0x43258))
|
|
|
|
|
|
|
|
#define fsaDecodeFsaStatusToFsStatus ((FSStatus(*)(FSError))(0x101C400 + 0x4b148))
|
|
|
|
#define fsClientHandleFatalError ((void (*)(FSClientBody *, uint32_t))(0x101C400 + 0x4b34c))
|
|
|
|
#define fsClientHandleFatalErrorAndBlock ((void (*)(FSClientBody *, uint32_t))(0x101C400 + 0x4cc20))
|
|
|
|
|
|
|
|
extern "C" FSError __FSAShimDecodeIosErrorToFsaStatus(IOSHandle handle, IOSError err);
|
|
|
|
|
|
|
|
bool sendMessageToThread(FSShimWrapperMessage *param);
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
void clearFSLayer();
|
|
|
|
|
2022-09-10 21:24:58 +02:00
|
|
|
FSError doForLayer(FSShimWrapper *param);
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-09-10 21:24:58 +02:00
|
|
|
FSError processShimBufferForFS(FSShimWrapper *param);
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-09-10 21:24:58 +02:00
|
|
|
FSError processShimBufferForFSA(FSShimWrapper *param);
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
FSCmdBlockBody *fsCmdBlockGetBody(FSCmdBlock *cmdBlock);
|
|
|
|
|
|
|
|
FSClientBody *fsClientGetBody(FSClient *client);
|
|
|
|
|
2022-09-10 21:24:58 +02:00
|
|
|
FSStatus handleAsyncResult(FSClient *client, FSCmdBlock *block, FSAsyncData *asyncData, FSStatus status);
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
int64_t readIntoBuffer(int32_t handle, void *buffer, size_t size, size_t count);
|
|
|
|
|
2022-09-10 21:24:58 +02:00
|
|
|
int64_t writeFromBuffer(int32_t handle, const void *buffer, size_t size, size_t count);
|
|
|
|
|
|
|
|
void startFSIOThreads();
|
|
|
|
void stopFSIOThreads();
|