we can create directories now
This commit is contained in:
parent
51260ca6ce
commit
40a3868cbc
|
@ -4,6 +4,7 @@ constexpr int SCE_OK = 0;
|
|||
constexpr int SCE_KERNEL_ERROR_EBADF = 0x80020009;
|
||||
constexpr int SCE_KERNEL_ERROR_ENOMEM = 0x8002000c; // Insufficient memory
|
||||
constexpr int SCE_KERNEL_ERROR_EFAULT = 0x8002000e; // Invalid address pointer
|
||||
constexpr int SCE_KERNEL_ERROR_ENOTDIR = 0x80020014;
|
||||
constexpr int SCE_KERNEL_ERROR_EINVAL = 0x80020016; // null or invalid states
|
||||
constexpr int SCE_KERNEL_ERROR_EAGAIN = 0x80020023; // Memory cannot be allocated
|
||||
constexpr int SCE_KERNEL_ERROR_ENAMETOOLONG = 0x8002003f; // character strings exceeds valid size
|
||||
|
|
|
@ -1,13 +1,43 @@
|
|||
#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>
|
||||
|
||||
|
||||
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;
|
||||
|
||||
bool isDirectory = (flags & SCE_KERNEL_O_DIRECTORY) != 0;
|
||||
bool createFileOrDir = (flags & SCE_KERNEL_O_CREAT) != 0;
|
||||
|
||||
auto* h = singleton<Emulator::Host::Fs::HandleTable>::instance();
|
||||
auto* mnt = singleton<Emulator::Host::Fs::MntPoints>::instance();
|
||||
|
||||
u32 handle = h->createHandle().value();//TODO check if overflows
|
||||
|
||||
Emulator::Host::Fs::File file = h->getFile(handle);
|
||||
|
||||
file.guest_path = path;
|
||||
if (isDirectory) {
|
||||
file.host_path = mnt->getHostDirectory(path);
|
||||
if (!std::filesystem::exists(file.host_path)) { //directory doesn't exist
|
||||
if (createFileOrDir) { //if we have a create flag create it
|
||||
if (std::filesystem::create_directories(file.host_path)) {
|
||||
return handle;
|
||||
} else {
|
||||
return SCE_KERNEL_ERROR_ENOTDIR;
|
||||
}
|
||||
} else {
|
||||
return SCE_KERNEL_ERROR_ENOTDIR;
|
||||
}
|
||||
}
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem
|
|
@ -2,6 +2,10 @@
|
|||
#include <types.h>
|
||||
|
||||
namespace Emulator::HLE::Libraries::LibKernel::FileSystem {
|
||||
|
||||
constexpr u32 SCE_KERNEL_O_CREAT = 0x0200;
|
||||
constexpr u32 SCE_KERNEL_O_DIRECTORY = 0x00020000;
|
||||
|
||||
int PS4_SYSV_ABI sceKernelOpen(const char *path, int flags, /* SceKernelMode*/ u16 mode);
|
||||
|
||||
}
|
||||
} // namespace Emulator::HLE::Libraries::LibKernel::FileSystem
|
|
@ -1,4 +1,5 @@
|
|||
#include "fs.h"
|
||||
#include <algorithm>
|
||||
|
||||
namespace Emulator::Host::Fs {
|
||||
void MntPoints::mount(const std::string& host_folder, const std::string& guest_folder) {
|
||||
|
@ -12,4 +13,21 @@ void MntPoints::mount(const std::string& host_folder, const std::string& guest_f
|
|||
}
|
||||
void MntPoints::unMount(const std::string& path) {}
|
||||
void MntPoints::unMountAll() {}
|
||||
std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
|
||||
Lib::LockMutexGuard 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 std::string();
|
||||
}
|
||||
} // namespace Emulator::Host::Fs
|
|
@ -24,16 +24,17 @@ class 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;
|
||||
Lib::Mutex m_mutex;
|
||||
|
||||
};
|
||||
struct File {
|
||||
bool valid = false; // Το descriptor ειναι οντως ανοιχτο;
|
||||
FILE* file; // File handle του αρχειο
|
||||
std::filesystem::path path; // Path του στο host FS
|
||||
bool valid = false; // Ôï descriptor åéíáé ïíôùò áíïé÷ôï;
|
||||
FILE* file; // File handle ôïõ áñ÷åéï
|
||||
std::filesystem::path host_path; // Path in host FS
|
||||
std::string guest_path; // Path in PS4 FS
|
||||
|
||||
File() : valid(true) {}
|
||||
};
|
||||
|
@ -87,6 +88,8 @@ class HandleTable {
|
|||
return handle;
|
||||
}
|
||||
|
||||
File getFile(u32 handle) { return files[handle]; }
|
||||
|
||||
void freeHandle(u32 handle) {
|
||||
if (handle >= files.size()) {
|
||||
// Óôáíôáñ invalid
|
||||
|
|
Loading…
Reference in New Issue