RPXLoadingModule/src/FSWrapper.h

160 lines
6.4 KiB
C
Raw Normal View History

2021-01-01 01:39:28 +01:00
#pragma once
#include <cstdint>
#include <dirent.h>
#include <functional>
#include <coreinit/filesystem.h>
#include <coreinit/mutex.h>
typedef struct dirMagic {
uint32_t handle{};
DIR *dir{};
bool in_use{};
char path[256]{};
OSMutex *mutex{};
2022-01-26 23:20:21 +01:00
FSDirectoryEntry *readResult = nullptr;
int readResultCapacity = 0;
int readResultNumberOfEntries = 0;
FSDirectoryHandle realDirHandle = 0;
2021-01-01 01:39:28 +01:00
} dirMagic_t;
typedef struct fileMagic {
uint32_t handle;
bool in_use;
int fd;
OSMutex *mutex;
} fileMagic_t;
#define ERROR_FLAG_MASK (0xFFFF0000)
#define FORCE_REAL_FUNC_MAGIC (0x42420000)
#define FORCE_REAL_FUNC_WITH_FULL_ERRORS (FORCE_REAL_FUNC_MAGIC | 0x0000FFFF)
#define HANDLE_INDICATOR_MASK 0xFFFFFF00
2021-01-01 01:39:28 +01:00
#define HANDLE_INDICATOR_MASK 0xFFFFFF00
#define HANDLE_MASK (0x000000FF)
#define DIR_HANDLE_MAGIC 0x30000000
#define FILE_HANDLE_MAGIC 0x30000100
#define FILE_HANDLES_LENGTH 64
#define DIR_HANDLES_LENGTH 64
#define FS_STATUS_USE_REAL_OS (FSStatus) 0xFFFF0000
extern dirMagic_t dir_handles[DIR_HANDLES_LENGTH];
extern fileMagic_t file_handles[FILE_HANDLES_LENGTH];
FSStatus FSOpenDirWrapper(char *path,
FSDirectoryHandle *handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(char *)> &fallback_function,
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSReadDirWrapper(FSDirectoryHandle handle,
FSDirectoryEntry *entry,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSCloseDirWrapper(FSDirectoryHandle handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSRewindDirWrapper(FSDirectoryHandle handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSMakeDirWrapper(char *path,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(char *)> &fallback_function,
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSOpenFileWrapper(char *path,
const char *mode,
FSFileHandle *handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(char *)> &fallback_function,
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSCloseFileWrapper(FSFileHandle handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSGetStatWrapper(char *path,
FSStat *stats,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(char *)> &fallback_function,
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSGetStatFileWrapper(FSFileHandle handle,
FSStat *stats,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSReadFileWrapper(void *buffer,
uint32_t size,
uint32_t count,
FSFileHandle handle,
uint32_t unk1,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSReadFileWithPosWrapper(void *buffer,
uint32_t size,
uint32_t count,
uint32_t pos,
FSFileHandle handle,
int32_t unk1,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSSetPosFileWrapper(FSFileHandle handle,
uint32_t pos,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSGetPosFileWrapper(FSFileHandle handle,
uint32_t *pos,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSIsEofWrapper(FSFileHandle handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSTruncateFileWrapper(FSFileHandle handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSWriteFileWrapper(uint8_t *buffer,
uint32_t size,
uint32_t count,
FSFileHandle handle,
uint32_t unk1,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSRemoveWrapper(char *path,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(char *)> &fallback_function,
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSRenameWrapper(char *oldPath,
char *newPath,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(char *, char *)> &fallback_function,
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
FSStatus FSFlushFileWrapper(FSFileHandle handle,
FSErrorFlag errorMask,
2021-09-28 20:04:55 +02:00
const std::function<FSStatus(FSStatus)> &result_handler);
2021-01-01 01:39:28 +01:00
int32_t getNewDirHandleIndex();
int32_t getNewFileHandleIndex();
bool isValidDirHandle(int32_t handle);
bool isValidFileHandle(int32_t handle);