fs mount points and handles

This commit is contained in:
georgemoralis 2023-11-06 08:32:27 +02:00
parent a01e057632
commit bfbe67bc42
5 changed files with 117 additions and 4 deletions

View File

@ -59,6 +59,8 @@ set(SYSTEMSERVICE_SOURCES src/core/hle/libraries/libsystemservice/system_service
set(FILESYSTEM_SOURCES src/core/hle/libraries/libkernel/file_system.cpp
src/core/hle/libraries/libkernel/file_system.h
src/core/file_sys/fs.cpp
src/core/file_sys/fs.h
)
set(HOST_SOURCES src/Emulator/Host/controller.cpp

66
src/core/file_sys/fs.cpp Normal file
View File

@ -0,0 +1,66 @@
#include "fs.h"
#include <algorithm>
namespace Core::FileSys {
void MntPoints::mount(const std::string& host_folder, const std::string& guest_folder) {
std::unique_lock lock{m_mutex};
MntPair pair;
pair.host_path = host_folder;
pair.guest_path = guest_folder;
m_mnt_pairs.push_back(pair);
}
void MntPoints::unmount(const std::string& path) {} // TODO!
void MntPoints::unmountAll() {
std::unique_lock lock{m_mutex};
m_mnt_pairs.clear();
}
std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
std::unique_lock lock{m_mutex};
for (auto& pair : m_mnt_pairs) {
if (pair.guest_path.starts_with(guest_directory)) {
return pair.host_path + guest_directory;
}
}
// hack for relative path , get app0 and assuming it goes from there
for (auto& pair : m_mnt_pairs) {
if (pair.guest_path.starts_with("/app0")) {
std::replace(pair.host_path.begin(), pair.host_path.end(), '\\', '/');
return pair.host_path + guest_directory;
}
}
return "";
}
int HandleTable::createHandle() {
std::unique_lock lock{m_mutex};
auto* file = new File{};
file->isDirectory = false;
file->isOpened = false;
int existingFilesNum = m_files.size();
// TODO when i close a file m_files probably have a open pos , so we can fill this
m_files.push_back(file);
return existingFilesNum - 1;
}
void HandleTable::deleteHandle(int d) {
std::unique_lock lock{m_mutex};
delete m_files.at(d);
m_files[d] = nullptr;
}
File* HandleTable::getFile(int d) {
std::unique_lock lock{m_mutex};
return m_files.at(d);
}
File* HandleTable::getFile(const std::string& real_name) {
std::unique_lock lock{m_mutex};
for (auto* file : m_files) {
if (file != nullptr && file->m_real_name == real_name) {
return file;
}
}
return nullptr;
}
} // namespace Core::FileSys

45
src/core/file_sys/fs.h Normal file
View File

@ -0,0 +1,45 @@
#pragma once
#include <mutex>
#include <string>
#include <vector>
namespace Core::FileSys {
class MntPoints {
public:
struct MntPair {
std::string host_path;
std::string guest_path; // e.g /app0/
};
MntPoints() {}
virtual ~MntPoints() {}
void mount(const std::string& host_folder, const std::string& guest_folder);
void unmount(const std::string& path);
void unmountAll();
std::string getHostDirectory(const std::string& guest_directory);
private:
std::vector<MntPair> m_mnt_pairs;
std::mutex m_mutex;
};
struct File {
std::atomic_bool isOpened;
std::atomic_bool isDirectory;
std::string m_real_name;
};
class HandleTable {
HandleTable() {}
virtual ~HandleTable() {}
int createHandle();
void deleteHandle(int d);
File* getFile(int d);
File* getFile(const std::string& real_name);
private:
std::vector<File*> m_files;
std::mutex m_mutex;
};
} // namespace Core::FileSys

View File

@ -12,7 +12,7 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
return 0;
}
int PS4_SYSV_ABI open(const char* path, int flags, /* SceKernelMode*/ u16 mode) {
int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode) {
LOG_INFO_IF(log_file_fs, "posix open redirect to sceKernelOpen\n");
int result = sceKernelOpen(path, flags, mode);
if (result < 0) {
@ -23,7 +23,7 @@ int PS4_SYSV_ABI open(const char* path, int flags, /* SceKernelMode*/ u16 mode)
void fileSystemSymbolsRegister(Loader::SymbolsResolver* sym) {
LIB_FUNCTION("1G3lF1Gg1k8", "libkernel", 1, "libkernel", 1, 1, sceKernelOpen);
LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, open);
LIB_FUNCTION("wuCroIGjt2g", "libScePosix", 1, "libkernel", 1, 1, posix_open);
}
} // namespace Core::Libraries::LibKernel

View File

@ -10,7 +10,7 @@ namespace Core::Libraries::LibKernel {
int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode);
int PS4_SYSV_ABI open(const char *path, int flags, /* SceKernelMode*/ u16 mode);
int PS4_SYSV_ABI posix_open(const char *path, int flags, /* SceKernelMode*/ u16 mode);
void fileSystemSymbolsRegister(Loader::SymbolsResolver *sym);