initial fs design

This commit is contained in:
wheremyfoodat 2023-10-20 07:51:20 +03:00 committed by georgemoralis
parent e9d2d37aae
commit fda578a625
6 changed files with 91 additions and 120 deletions

View File

@ -51,6 +51,8 @@ set(FILESYSTEM_SOURCES src/Emulator/HLE/Libraries/LibKernel/FileSystem/file_syst
set(HOST_SOURCES src/Emulator/Host/controller.cpp set(HOST_SOURCES src/Emulator/Host/controller.cpp
src/Emulator/Host/controller.h src/Emulator/Host/controller.h
src/Emulator/Host/fs.cpp
src/Emulator/Host/fs.h
) )
set(UTIL_SOURCES src/Emulator/Util/singleton.h set(UTIL_SOURCES src/Emulator/Util/singleton.h
@ -98,7 +100,7 @@ add_executable(shadps4
src/Core/PS4/HLE/Kernel/cpu_management.cpp src/Core/PS4/HLE/Kernel/cpu_management.cpp
src/Core/PS4/HLE/Kernel/cpu_management.h 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/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.h" "src/Emulator/HLE/Libraries/LibKernel/FileSystem/meta_file_system.cpp") "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")
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools) target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools)

View File

@ -1,27 +0,0 @@
#pragma once
#include <types.h>
#include <string>
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 {
public:
virtual bool ownsHandle(u32 handle) = 0;
virtual u32 openFile(std::string filename, FileAccess access) = 0;
virtual void closeFile(u32 handle) = 0;
};
} // namespace Emulator::Host::GenericFS

View File

@ -1,52 +0,0 @@
#include "meta_file_system.h"
namespace Emulator::Host::GenericFS {
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() { fileSystems.clear(); }
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;
}
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;
}
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

View File

@ -1,40 +0,0 @@
#pragma once
#include <types.h>
#include <string>
#include <vector>
#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<System> fileSystems;
std::string currentDirectory;
std::vector<u32> handler;
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() {
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);
};
} // namespace Emulator::Host::GenericFS

3
src/Emulator/Host/fs.cpp Normal file
View File

@ -0,0 +1,3 @@
#include "fs.h"
namespace Emulator::Host::Fs {}

85
src/Emulator/Host/fs.h Normal file
View File

@ -0,0 +1,85 @@
#pragma once
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <filesystem>
#include <optional>
#include <vector>
#include <types.h>
#include "Lib/Threads.h"
namespace Emulator::Host::Fs {
struct File {
bool valid = false; // Το descriptor ειναι οντως ανοιχτο;
FILE* file; // File handle του αρχειο
std::filesystem::path path; // Path του στο host FS
File() : valid(true) {}
};
class HandleTable {
std::vector<File> files;
u32 openFileCount = 0; // Ποσα descriptors εχουμε ανοιχτα;
public:
static constexpr u32 MAX_FILE_DESCRIPTORS = 65536;
HandleTable() {
files.reserve(128); // Κανουμε reserve χωρο για μερικα αρχεια για να αποφυγουμε allocations
reset();
}
void reset() {
for (auto& f : files) {
if (f.valid) {
// Κανουμε fclose το αρχειο και ο,τι αλλο ειναι να γινει
}
}
files.clear();
openFileCount = 0;
}
// Επιστρεφει handle για να δημιουργησουμε νεο αρχείο
std::optional<u32> createHandle() {
if (openFileCount >= MAX_FILE_DESCRIPTORS) {
// Δεν μπορουμε να ανοιξουμε αλλα descriptors, εχουμε βαρεσει το max
return std::nullopt;
}
// Μπορουμε σιγουρα να δημιουργησουμε handle, οποτε αυξανουμε το handle count
openFileCount += 1;
// Κοιταμε αν κανενα απτα files στο vector ειναι ελευθερο για να το κανουμε reuse
for (size_t i = 0; i < files.size(); i++) {
// Βρηκαμε ελευθερο αρχειο, επιστρεφουμε το index του
if (!files[i].valid) {
return i;
}
}
// Δεν υπαρχει ελευθερο στο vector αλλα δεν εχουμε εξαντλησει το cap, οποτε μεγαλωνουμε το vector
// Και επιστρεφουμε το index του καινουργιου
u32 handle = files.size();
files.push_back(File());
return handle;
}
void freeHandle(u32 handle) {
if (handle >= files.size()) {
// Στανταρ invalid
printf("POUTSA\n");
return;
}
if (files[handle].valid) {
// Παλι κανουμε fclose και πιπες και το μαρκαρουμε για reuse
files[handle].valid = false;
// Μειον ενα ανοιχτο αρχειο
openFileCount -= 1;
}
}
};
}