fs fixes and clean
This commit is contained in:
parent
03a95ecadd
commit
0a689270b3
|
@ -6,6 +6,7 @@ constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c; // Insufficient memor
|
||||||
constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer
|
constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer
|
||||||
constexpr int SCE_KERNEL_ERROR_ENOTDIR = 0x80020014;
|
constexpr int SCE_KERNEL_ERROR_ENOTDIR = 0x80020014;
|
||||||
constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states
|
constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states
|
||||||
|
constexpr int SCE_KERNEL_ERROR_EMFILE = 0x80020018; // Limit on the number of file descriptors that can be open has been reached
|
||||||
constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023; // Memory cannot be allocated
|
constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023; // Memory cannot be allocated
|
||||||
constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003f; // character strings exceeds valid size
|
constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003f; // character strings exceeds valid size
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include "file_system.h"
|
#include "file_system.h"
|
||||||
#include <debug.h>
|
|
||||||
#include <Util/log.h>
|
|
||||||
#include <Emulator/Util/singleton.h>
|
|
||||||
#include "Emulator/Host/fs.h"
|
|
||||||
#include <Core/PS4/HLE/ErrorCodes.h>
|
|
||||||
|
|
||||||
|
#include <Core/PS4/HLE/ErrorCodes.h>
|
||||||
|
#include <Emulator/Util/singleton.h>
|
||||||
|
#include <Util/log.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include "Emulator/Host/fs.h"
|
||||||
|
|
||||||
namespace Emulator::HLE::Libraries::LibKernel::FileSystem {
|
namespace Emulator::HLE::Libraries::LibKernel::FileSystem {
|
||||||
constexpr bool log_file_fs = true; // disable it to disable logging
|
constexpr bool log_file_fs = true; // disable it to disable logging
|
||||||
|
@ -13,21 +14,24 @@ 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));
|
LOG_INFO_IF(log_file_fs, "sceKernelOpen path = {} flags = {} mode = {}\n", path, log_hex_full(flags), log_hex_full(mode));
|
||||||
|
|
||||||
bool isDirectory = (flags & SCE_KERNEL_O_DIRECTORY) != 0;
|
bool isDirectory = (flags & SCE_KERNEL_O_DIRECTORY) != 0;
|
||||||
bool createFileOrDir = (flags & SCE_KERNEL_O_CREAT) != 0;
|
bool create = (flags & SCE_KERNEL_O_CREAT) != 0;
|
||||||
|
|
||||||
auto* h = singleton<Emulator::Host::Fs::HandleTable>::instance();
|
auto* h = singleton<Emulator::Host::Fs::HandleTable>::instance();
|
||||||
auto* mnt = singleton<Emulator::Host::Fs::MntPoints>::instance();
|
auto* mnt = singleton<Emulator::Host::Fs::MntPoints>::instance();
|
||||||
|
u32 handle = 0;
|
||||||
|
if (h->createHandle().has_value()) {
|
||||||
|
handle = h->createHandle().value();
|
||||||
|
} else {
|
||||||
|
return SCE_KERNEL_ERROR_EMFILE; // file descriptors is full error(?)
|
||||||
|
}
|
||||||
|
Emulator::Host::Fs::File* file = h->getFile(handle);
|
||||||
|
|
||||||
u32 handle = h->createHandle().value();//TODO check if overflows
|
file->guest_path = path;
|
||||||
|
|
||||||
Emulator::Host::Fs::File file = h->getFile(handle);
|
|
||||||
|
|
||||||
file.guest_path = path;
|
|
||||||
if (isDirectory) {
|
if (isDirectory) {
|
||||||
file.host_path = mnt->getHostDirectory(path);
|
file->host_path = mnt->getHostDirectory(path);
|
||||||
if (!std::filesystem::exists(file.host_path)) { //directory doesn't exist
|
if (!std::filesystem::is_directory(file->host_path)) { // directory doesn't exist
|
||||||
if (createFileOrDir) { //if we have a create flag create it
|
if (create) { // if we have a create flag create it
|
||||||
if (std::filesystem::create_directories(file.host_path)) {
|
if (std::filesystem::create_directories(file->host_path)) {
|
||||||
return handle;
|
return handle;
|
||||||
} else {
|
} else {
|
||||||
return SCE_KERNEL_ERROR_ENOTDIR;
|
return SCE_KERNEL_ERROR_ENOTDIR;
|
||||||
|
@ -40,12 +44,12 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceKernelClose(int d) {
|
int PS4_SYSV_ABI sceKernelClose(int handle) {
|
||||||
LOG_INFO_IF(log_file_fs, "sceKernelClose descriptor = {}\n", d);
|
LOG_INFO_IF(log_file_fs, "sceKernelClose descriptor = {}\n", handle);
|
||||||
auto* h = singleton<Emulator::Host::Fs::HandleTable>::instance();
|
auto* h = singleton<Emulator::Host::Fs::HandleTable>::instance();
|
||||||
Emulator::Host::Fs::File file = h->getFile(d);
|
Emulator::Host::Fs::File* file = h->getFile(handle);
|
||||||
file.valid = false;
|
file->valid = false;
|
||||||
h->freeHandle(d);
|
h->freeHandle(handle);
|
||||||
return SCE_OK;
|
return SCE_OK;
|
||||||
}
|
}
|
||||||
} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem
|
} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem
|
|
@ -7,6 +7,6 @@ constexpr u32 SCE_KERNEL_O_CREAT = 0x0200;
|
||||||
constexpr u32 SCE_KERNEL_O_DIRECTORY = 0x00020000;
|
constexpr u32 SCE_KERNEL_O_DIRECTORY = 0x00020000;
|
||||||
|
|
||||||
int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode);
|
int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode);
|
||||||
int PS4_SYSV_ABI sceKernelClose(int d);
|
int PS4_SYSV_ABI sceKernelClose(int handle);
|
||||||
|
|
||||||
} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem
|
} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem
|
|
@ -1,4 +1,5 @@
|
||||||
#include "fs.h"
|
#include "fs.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
namespace Emulator::Host::Fs {
|
namespace Emulator::Host::Fs {
|
||||||
|
@ -12,11 +13,10 @@ void MntPoints::mount(const std::string& host_folder, const std::string& guest_f
|
||||||
m_mnt_pairs.push_back(pair);
|
m_mnt_pairs.push_back(pair);
|
||||||
}
|
}
|
||||||
void MntPoints::unMount(const std::string& path) {}
|
void MntPoints::unMount(const std::string& path) {}
|
||||||
void MntPoints::unMountAll() {}
|
void MntPoints::unmountAll() {}
|
||||||
std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
|
std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
|
||||||
Lib::LockMutexGuard lock(m_mutex);
|
Lib::LockMutexGuard lock(m_mutex);
|
||||||
for (auto& pair : m_mnt_pairs)
|
for (auto& pair : m_mnt_pairs) {
|
||||||
{
|
|
||||||
if (pair.guest_path.starts_with(guest_directory)) {
|
if (pair.guest_path.starts_with(guest_directory)) {
|
||||||
return pair.host_path + guest_directory;
|
return pair.host_path + guest_directory;
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,6 @@ std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
|
||||||
return pair.host_path + guest_directory;
|
return pair.host_path + guest_directory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::string();
|
return "";
|
||||||
}
|
}
|
||||||
} // namespace Emulator::Host::Fs
|
} // namespace Emulator::Host::Fs
|
|
@ -23,7 +23,7 @@ class MntPoints {
|
||||||
virtual ~MntPoints() {}
|
virtual ~MntPoints() {}
|
||||||
void mount(const std::string& host_folder, const std::string& guest_folder);
|
void mount(const std::string& host_folder, const std::string& guest_folder);
|
||||||
void unMount(const std::string& path);
|
void unMount(const std::string& path);
|
||||||
void unMountAll();
|
void unmountAll();
|
||||||
std::string getHostDirectory(const std::string& guest_directory);
|
std::string getHostDirectory(const std::string& guest_directory);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -88,7 +88,7 @@ class HandleTable {
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
File getFile(u32 handle) { return files[handle]; }
|
File* getFile(u32 handle) { return &files[handle]; }
|
||||||
|
|
||||||
void freeHandle(u32 handle) {
|
void freeHandle(u32 handle) {
|
||||||
if (handle >= files.size()) {
|
if (handle >= files.size()) {
|
||||||
|
|
Loading…
Reference in New Issue