fusee_cpp: implement emummc/system partition mounting

This commit is contained in:
Michael Scire 2021-08-31 22:51:51 -07:00 committed by SciresM
parent 8560713a60
commit 2f7012cbc6
15 changed files with 1009 additions and 18 deletions

View file

@ -24,8 +24,10 @@ namespace ams::fs {
constexpr size_t MaxFiles = 8;
constinit bool g_is_sd_mounted = false;
constinit bool g_is_sys_mounted = false;
alignas(0x10) constinit FATFS g_sd_fs = {};
alignas(0x10) constinit FATFS g_sys_fs = {};
alignas(0x10) constinit FIL g_files[MaxFiles] = {};
constinit bool g_files_opened[MaxFiles] = {};
@ -104,16 +106,40 @@ namespace ams::fs {
bool MountSdCard() {
AMS_ASSERT(!g_is_sd_mounted);
g_is_sd_mounted = f_mount(std::addressof(g_sd_fs), "sdmc", 1) == FR_OK;
g_is_sd_mounted = f_mount(std::addressof(g_sd_fs), "sdmc:", 1) == FR_OK;
return g_is_sd_mounted;
}
void UnmountSdCard() {
AMS_ASSERT(g_is_sd_mounted);
f_unmount("");
f_unmount("sdmc:");
g_is_sd_mounted = false;
}
bool MountSystem() {
AMS_ASSERT(!g_is_sys_mounted);
g_is_sys_mounted = f_mount(std::addressof(g_sys_fs), "sys:", 1) == FR_OK;
return g_is_sys_mounted;
}
void UnmountSystem() {
AMS_ASSERT(g_is_sys_mounted);
f_unmount("sys:");
g_is_sys_mounted = false;
}
Result GetEntryType(DirectoryEntryType *out_entry_type, bool *out_archive, const char *path) {
/* Get the file info. */
FILINFO info;
R_TRY(TranslateFatFsError(f_stat(path, std::addressof(info))));
/* Handle the file. */
*out_entry_type = (info.fattrib & AM_DIR) ? DirectoryEntryType_Directory : DirectoryEntryType_File;
*out_archive = (info.fattrib & AM_ARC);
return ResultSuccess();
}
Result CreateFile(const char *path, s64 size) {
/* Create the file. */
FIL fp;