AromaBaseModule/source/sdrefcount/refcount.cpp

30 lines
1.2 KiB
C++
Raw Permalink Normal View History

2022-08-25 12:58:35 +02:00
#include "globals.h"
#include "logger.h"
#include "sd_function_replacements.h"
#include <coreinit/filesystem_fsa.h>
void initSDRefCount() {
FSAInit();
auto client = FSAAddClient(nullptr);
gSDMountRefCount = 0;
if (client > 0) {
auto res = FSAMount(client, "/dev/sdcard01", "/vol/external01", (FSAMountFlags) 0, nullptr, 0);
if (res == FS_ERROR_ALREADY_EXISTS) {
DEBUG_FUNCTION_LINE("SDCard is already mounted, set ref counter to 16");
gSDMountRefCount = 16;
} else {
DEBUG_FUNCTION_LINE("Set ref counter to 0");
FSAUnmount(client, "/vol/external01", FSA_UNMOUNT_FLAG_BIND_MOUNT);
}
FSADelClient(res);
}
DEBUG_FUNCTION_LINE("Patch SDRefCount functions");
for (uint32_t i = 0; i < sdrefcount_function_replacements_size; i++) {
bool wasPatched = false;
if (FunctionPatcher_AddFunctionPatch(&sdrefcount_function_replacements[i], nullptr, &wasPatched) != FUNCTION_PATCHER_RESULT_SUCCESS || !wasPatched) {
2022-08-25 12:58:35 +02:00
OSFatal("AromaBaseModule: Failed to patch function for sd ref counting");
}
}
DEBUG_FUNCTION_LINE("Patch SDRefCount functions finished");
}