some fs work for openorbis (WIP)

This commit is contained in:
georgemoralis 2024-01-26 18:01:27 +02:00
parent 57ddf939d4
commit ff43fec76a
6 changed files with 225 additions and 6 deletions

View file

@ -4,6 +4,7 @@
#include <vector>
#include "common/fs_file.h"
#include <common/io_file.h>
namespace Core::FileSys {
@ -32,7 +33,7 @@ struct File {
std::atomic_bool isDirectory;
std::string m_host_name;
std::string m_guest_name;
Common::FS::File f;
IOFile f;
//std::vector<Common::FS::DirEntry> dirents;
u32 dirents_index;
std::mutex m_mutex;

View file

@ -2,6 +2,9 @@
#include "common/debug.h"
#include "core/hle/libraries/libkernel/file_system.h"
#include "core/hle/libraries/libs.h"
#include <core/file_sys/fs.h>
#include <common/singleton.h>
#include <core/hle/error_codes.h>
namespace Core::Libraries::LibKernel {
@ -9,10 +12,25 @@ 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 = {:#x} mode = {:#x}\n", path, flags, mode);
return 0;
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* mnt = Common::Singleton<Core::FileSys::MntPoints>::Instance();
// only open files support!
u32 handle = h->createHandle();
auto* file = h->getFile(handle);
file->m_guest_name = path;
file->m_host_name = mnt->getHostFile(file->m_guest_name);
bool result = file->f.open(file->m_host_name);
if (!result) {
h->deleteHandle(handle);
return SCE_KERNEL_ERROR_EACCES;
}
file->isOpened = true;
return handle;
}
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) {
@ -21,9 +39,25 @@ int PS4_SYSV_ABI open(const char* path, int flags, /* SceKernelMode*/ u16 mode)
return result;
}
size_t PS4_SYSV_ABI _readv(int d, const SceKernelIovec* iov, int iovcnt) {
auto* h = Common::Singleton<Core::FileSys::HandleTable>::Instance();
auto* file = h->getFile(d);
size_t total_read = 0;
file->m_mutex.lock();
for (int i = 0; i < iovcnt; i++) {
total_read += file->f.readBytes(iov[i].iov_base,iov[i].iov_len).second;
}
file->m_mutex.unlock();
return total_read;
}
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);
LIB_FUNCTION("+WRlkKjZvag", "libkernel", 1, "libkernel", 1, 1, _readv);
// openOrbis (to check if it is valid out of OpenOrbis
LIB_FUNCTION("6c3rCVE-fTU", "libkernel", 1, "libkernel", 1, 1, posix_open); // _open shoudld be equal to open function
}
} // namespace Core::Libraries::LibKernel

View file

@ -8,9 +8,14 @@ class SymbolsResolver;
namespace Core::Libraries::LibKernel {
struct SceKernelIovec {
void *iov_base;
size_t iov_len;
};
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);