From 84393e6acca5a6d8641e402fc8775b5bf4029a7b Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 19 Oct 2023 12:13:09 +0300 Subject: [PATCH 1/5] initial fs work (logging mostly) --- CMakeLists.txt | 7 +++++++ src/Core/PS4/HLE/LibKernel.cpp | 5 +++++ .../LibKernel/FileSystem/file_system.cpp | 13 +++++++++++++ .../Libraries/LibKernel/FileSystem/file_system.h | 7 +++++++ .../LibKernel/FileSystem/posix_file_system.cpp | 15 +++++++++++++++ .../LibKernel/FileSystem/posix_file_system.h | 6 ++++++ 6 files changed, 53 insertions(+) create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 1da14c4b..05d277e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,12 @@ set(SYSTEMSERVICE_SOURCES src/Emulator/HLE/Libraries/LibSystemService/system_ser src/Emulator/HLE/Libraries/LibSystemService/system_service.h ) +set(FILESYSTEM_SOURCES src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp + src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h + src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp + src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h +) + set(UTIL_SOURCES src/Emulator/Util/singleton.h ) @@ -53,6 +59,7 @@ add_executable(shadps4 ${USERSERVICE_SOURCES} ${PAD_SOURCES} ${SYSTEMSERVICE_SOURCES} + ${FILESYSTEM_SOURCES} ${UTIL_SOURCES} src/main.cpp src/types.h diff --git a/src/Core/PS4/HLE/LibKernel.cpp b/src/Core/PS4/HLE/LibKernel.cpp index 77fb3c71..81252174 100644 --- a/src/Core/PS4/HLE/LibKernel.cpp +++ b/src/Core/PS4/HLE/LibKernel.cpp @@ -10,6 +10,8 @@ #include "Kernel/event_queues.h" #include "Kernel/memory_management.h" #include "Libs.h" +#include "Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h" +#include "Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h" namespace HLE::Libs::LibKernel { @@ -44,6 +46,9 @@ void LibKernel_Register(SymbolsResolver* sym) { LIB_FUNCTION("Ou3iL1abvng", "libkernel", 1, "libkernel", 1, 1, stack_chk_fail); // time LIB_FUNCTION("-2IRUCO--PM", "libkernel", 1, "libkernel", 1, 1, sceKernelReadTsc); + // fs + LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, Emulator::HLE::Libraries::LibKernel::FileSystem::sceKernelOpen); + LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX::open); } }; // namespace HLE::Libs::LibKernel \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp new file mode 100644 index 00000000..cdf35595 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.cpp @@ -0,0 +1,13 @@ +#include "file_system.h" +#include +#include + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem { +constexpr bool log_file_fs = true; // disable it to disable logging + +int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { + LOG_INFO_IF(log_file_fs, "sceKernelOpen path = {} flags = {} mode = {}\n", path, log_hex_full(flags), log_hex_full(mode)); + return 0; +} + +} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h new file mode 100644 index 00000000..98f090f0 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h @@ -0,0 +1,7 @@ +#pragma once +#include + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem { +int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode); + +} \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp new file mode 100644 index 00000000..caa6fb43 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp @@ -0,0 +1,15 @@ +#include "posix_file_system.h" + +#include + +#include "file_system.h" + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX { +int PS4_SYSV_ABI open(const char* path, int flags, /* SceKernelMode*/ u16 mode) { + int result = sceKernelOpen(path, flags, mode); + if (result < 0) { + BREAKPOINT(); // posix calls different only for their return values + } + return result; +} +} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h new file mode 100644 index 00000000..cce1c6c0 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h @@ -0,0 +1,6 @@ +#pragma once +#include "types.h" + +namespace Emulator::HLE::Libraries::LibKernel::FileSystem::POSIX { +int PS4_SYSV_ABI open(const char *path, int flags, /* SceKernelMode*/ u16 mode); +} \ No newline at end of file From e3effe8c0aef3f31443c2e79196b97e0ffd8ea1a Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 19 Oct 2023 12:27:28 +0300 Subject: [PATCH 2/5] few libc (pow ,_Sin ) for ps4nes --- src/Core/PS4/HLE/LibC.cpp | 2 ++ src/Emulator/HLE/Libraries/LibC/libc.cpp | 5 +++++ src/Emulator/HLE/Libraries/LibC/libc.h | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/Core/PS4/HLE/LibC.cpp b/src/Core/PS4/HLE/LibC.cpp index 77cda914..4d591c39 100644 --- a/src/Core/PS4/HLE/LibC.cpp +++ b/src/Core/PS4/HLE/LibC.cpp @@ -84,6 +84,8 @@ void LibC_Register(SymbolsResolver* sym) { LIB_FUNCTION("QI-x0SL8jhw", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::acosf); LIB_FUNCTION("ZE6RNL+eLbk", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::tanf); LIB_FUNCTION("GZWjF-YIFFk", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::asinf); + LIB_FUNCTION("9LCjpWyQ5Zc", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::pow); + LIB_FUNCTION("cCXjU72Z0Ow", "libc", 1, "libc", 1, 1, Emulator::HLE::Libraries::LibC::_Sin); LIB_OBJ("P330P3dFF68", "libc", 1, "libc", 1, 1, &HLE::Libs::LibC::g_need_sceLibc); diff --git a/src/Emulator/HLE/Libraries/LibC/libc.cpp b/src/Emulator/HLE/Libraries/LibC/libc.cpp index bf0d9e61..ec531b4e 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc.cpp +++ b/src/Emulator/HLE/Libraries/LibC/libc.cpp @@ -55,4 +55,9 @@ float PS4_SYSV_ABI acosf(float num) { return std::acosf(num); } float PS4_SYSV_ABI tanf(float num) { return std::tanf(num); } float PS4_SYSV_ABI asinf(float num) { return std::asinf(num); } + +double PS4_SYSV_ABI pow(double base, double exponent) { return std::pow(base, exponent); } + +double PS4_SYSV_ABI _Sin(double x) { return std::sin(x); } + }; // namespace Emulator::HLE::Libraries::LibC \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibC/libc.h b/src/Emulator/HLE/Libraries/LibC/libc.h index 3047283b..1608612e 100644 --- a/src/Emulator/HLE/Libraries/LibC/libc.h +++ b/src/Emulator/HLE/Libraries/LibC/libc.h @@ -26,5 +26,7 @@ float PS4_SYSV_ABI atan2f(float y, float x); float PS4_SYSV_ABI acosf(float num); float PS4_SYSV_ABI tanf(float num); float PS4_SYSV_ABI asinf(float num); +double PS4_SYSV_ABI pow(double base, double exponent); +double PS4_SYSV_ABI _Sin(double x); } // namespace Emulator::HLE::Libraries::LibC \ No newline at end of file From 90d24c3a3c74f3afa4e28ae30214d7f34191ce40 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 19 Oct 2023 13:01:20 +0300 Subject: [PATCH 3/5] e_type ET_SCE_DYNAMIC seems to be valid as well --- src/Core/PS4/Loader/Elf.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/PS4/Loader/Elf.cpp b/src/Core/PS4/Loader/Elf.cpp index 04e2c654..d9112707 100644 --- a/src/Core/PS4/Loader/Elf.cpp +++ b/src/Core/PS4/Loader/Elf.cpp @@ -206,8 +206,8 @@ bool Elf::isElfFile() const { return false; } - if (m_elf_header->e_type != ET_SCE_DYNEXEC && m_elf_header->e_type != ET_SCE_DYNAMIC) { - printf("ERROR:e_type expected 0xFE10 OR 0xFE18 is (%04x)\n", m_elf_header->e_type); + if (m_elf_header->e_type != ET_SCE_DYNEXEC&& m_elf_header->e_type != ET_SCE_DYNAMIC&& m_elf_header->e_type != ET_SCE_EXEC) { + printf("ERROR:e_type expected 0xFE10 OR 0xFE18 OR 0xfe00 is (%04x)\n", m_elf_header->e_type); return false; } From eb307b9cd9510e675cc9325b3f092644c14fed5e Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 19 Oct 2023 17:02:49 +0300 Subject: [PATCH 4/5] draft fs design --- CMakeLists.txt | 5 ++- .../FileSystem/generic_file_system.h | 25 +++++++++++++++ .../LibKernel/FileSystem/meta_file_system.cpp | 20 ++++++++++++ .../LibKernel/FileSystem/meta_file_system.h | 32 +++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp create mode 100644 src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 05d277e6..7b872a8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,9 @@ set(FILESYSTEM_SOURCES src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_syst src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_system.h src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.cpp src/Emulator/HLE/Libraries/LibKernel/FileSystem/posix_file_system.h + src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h + src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h + src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp ) set(UTIL_SOURCES src/Emulator/Util/singleton.h @@ -95,7 +98,7 @@ add_executable(shadps4 src/Core/PS4/HLE/Kernel/cpu_management.cpp src/Core/PS4/HLE/Kernel/cpu_management.h - "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/Core/PS4/GPU/video_out_buffer.cpp" "src/Core/PS4/GPU/video_out_buffer.h" "src/Core/PS4/HLE/Graphics/graphics_render.cpp" "src/Core/PS4/HLE/Graphics/graphics_render.h" "src/Core/PS4/GPU/tile_manager.cpp" "src/Core/PS4/GPU/tile_manager.h" "src/version.h" "src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp" "src/Emulator/HLE/Libraries/LibSystemService/system_service.h") + "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/Core/PS4/HLE/Kernel/memory_management.cpp" "src/Core/PS4/HLE/Kernel/memory_management.h" "src/Core/PS4/GPU/gpu_memory.cpp" "src/Core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.h" "src/Core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/Core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/Core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/Core/PS4/GPU/video_out_buffer.cpp" "src/Core/PS4/GPU/video_out_buffer.h" "src/Core/PS4/HLE/Graphics/graphics_render.cpp" "src/Core/PS4/HLE/Graphics/graphics_render.h" "src/Core/PS4/GPU/tile_manager.cpp" "src/Core/PS4/GPU/tile_manager.h" "src/version.h" "src/Emulator/HLE/Libraries/LibSystemService/system_service.cpp" "src/Emulator/HLE/Libraries/LibSystemService/system_service.h" "src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h" "src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp") find_package(OpenGL REQUIRED) target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools) diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h new file mode 100644 index 00000000..c43f15a5 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h @@ -0,0 +1,25 @@ +#pragma once +#include + +#include + +namespace Emulator::Host::GenericFS { + +enum FileAccess { + FILEACCESS_READ = 0, + FILEACCESS_WRITE = 1, + FILEACCESS_READWRITE = 2 + +}; + +class GenericHandleAllocator { + public: + virtual u32 requestHandle() = 0; + virtual void releaseHandle(u32 handle) = 0; +}; + +class AbstractFileSystem { + virtual u32 openFile(std::string filename, FileAccess access) = 0; + virtual void closeFile(u32 handle) = 0; +}; +} // namespace Emulator::Host::GenericFS \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp new file mode 100644 index 00000000..bcf17192 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp @@ -0,0 +1,20 @@ +#include "meta_file_system.h" + +namespace Emulator::Host::GenericFS { + +void MetaFileSystem::mount(std::string prefix, AbstractFileSystem* system) {} + +void MetaFileSystem::unMount(AbstractFileSystem* system) {} + +void MetaFileSystem::unMountAll() {} + +bool MetaFileSystem::mapFilePath(std::string inpath, std::string* outpath, AbstractFileSystem** system) { return false; } + +void MetaFileSystem::releaseHandle(u32 handle) {} + +u32 MetaFileSystem::openFile(std::string filename, FileAccess access) { return u32(); } + +void MetaFileSystem::closeFile(u32 handle) {} + + +} // namespace Emulator::Host::GenericFS \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h new file mode 100644 index 00000000..17b959c9 --- /dev/null +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include +#include +#include "generic_file_system.h" + +namespace Emulator::Host::GenericFS { + +class MetaFileSystem : public GenericHandleAllocator, AbstractFileSystem { + struct System { + std::string prefix; + AbstractFileSystem *system; + }; + + u32 current; + std::vector fileSystems; + std::string currentDirectory; + + public: + MetaFileSystem() : current(0) {} + + void mount(std::string prefix, AbstractFileSystem *system); + void unMount(AbstractFileSystem *system); + void unMountAll(); + AbstractFileSystem *getHandleOwner(u32 handle); + bool mapFilePath(std::string inpath, std::string *outpath, AbstractFileSystem **system); + u32 requestHandle() { return ++current; } + void releaseHandle(u32 handle); + u32 openFile(std::string filename, FileAccess access); + void closeFile(u32 handle); +}; +} \ No newline at end of file From ec362948f458ac82db0cf184ff55530d2d04f53f Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Thu, 19 Oct 2023 17:52:49 +0300 Subject: [PATCH 5/5] more draft fs --- .../FileSystem/generic_file_system.h | 2 + .../LibKernel/FileSystem/meta_file_system.cpp | 44 ++++++++++++++++--- .../LibKernel/FileSystem/meta_file_system.h | 14 ++++-- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h index c43f15a5..424f1498 100644 --- a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/generic_file_system.h @@ -19,6 +19,8 @@ class GenericHandleAllocator { }; class AbstractFileSystem { + public: + virtual bool ownsHandle(u32 handle) = 0; virtual u32 openFile(std::string filename, FileAccess access) = 0; virtual void closeFile(u32 handle) = 0; }; diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp index bcf17192..9750ee51 100644 --- a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp @@ -2,19 +2,51 @@ namespace Emulator::Host::GenericFS { -void MetaFileSystem::mount(std::string prefix, AbstractFileSystem* system) {} +void MetaFileSystem::mount(std::string prefix, AbstractFileSystem* system) { + System x; + x.prefix = prefix; + x.system = system; + fileSystems.push_back(x); +} void MetaFileSystem::unMount(AbstractFileSystem* system) {} -void MetaFileSystem::unMountAll() {} +void MetaFileSystem::unMountAll() { fileSystems.clear(); } -bool MetaFileSystem::mapFilePath(std::string inpath, std::string* outpath, AbstractFileSystem** system) { return false; } +AbstractFileSystem* MetaFileSystem::getHandleOwner(u32 handle) { + for (u32 i = 0; i < fileSystems.size(); i++) { + if (fileSystems[i].system->ownsHandle(handle)) return fileSystems[i].system; // got it! + } + return nullptr; -void MetaFileSystem::releaseHandle(u32 handle) {} +} -u32 MetaFileSystem::openFile(std::string filename, FileAccess access) { return u32(); } +bool MetaFileSystem::mapFilePath(std::string inpath, std::string* outpath, AbstractFileSystem** system) { + for (unsigned int i = 0; i < fileSystems.size(); i++) { + int prefLen = fileSystems[i].prefix.size(); + if (fileSystems[i].prefix == inpath.substr(0, prefLen)) + { + *outpath = inpath.substr(prefLen); + *system = fileSystems[i].system; + return true; + } + } + return false; +} -void MetaFileSystem::closeFile(u32 handle) {} +u32 MetaFileSystem::openFile(std::string filename, FileAccess access) { + AbstractFileSystem* system; + std::string of; + if (mapFilePath(filename, &of, &system)) { + return system->openFile(of, access); + } + return 0; +} + +void MetaFileSystem::closeFile(u32 handle) { + AbstractFileSystem* sys = getHandleOwner(handle); + if (sys) sys->closeFile(handle); +} } // namespace Emulator::Host::GenericFS \ No newline at end of file diff --git a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h index 17b959c9..83b04744 100644 --- a/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h +++ b/src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h @@ -1,7 +1,9 @@ #pragma once #include + #include #include + #include "generic_file_system.h" namespace Emulator::Host::GenericFS { @@ -15,6 +17,7 @@ class MetaFileSystem : public GenericHandleAllocator, AbstractFileSystem { u32 current; std::vector fileSystems; std::string currentDirectory; + std::vector handler; public: MetaFileSystem() : current(0) {} @@ -24,9 +27,14 @@ class MetaFileSystem : public GenericHandleAllocator, AbstractFileSystem { void unMountAll(); AbstractFileSystem *getHandleOwner(u32 handle); bool mapFilePath(std::string inpath, std::string *outpath, AbstractFileSystem **system); - u32 requestHandle() { return ++current; } - void releaseHandle(u32 handle); + u32 requestHandle() { + handler.push_back(current); + current++; + return handler.back(); + } + void releaseHandle(u32 handle) { handler.erase(std::remove(handler.begin(), handler.end(), handle), handler.end()); } + bool ownsHandle(u32 handle) { return false; } u32 openFile(std::string filename, FileAccess access); void closeFile(u32 handle); }; -} \ No newline at end of file +} // namespace Emulator::Host::GenericFS \ No newline at end of file