From bd6d635a4b91d0607212f97f6405720760fd08b8 Mon Sep 17 00:00:00 2001 From: georgemoralis Date: Mon, 6 Nov 2023 22:47:46 +0200 Subject: [PATCH] sceKernelOpen create directories works --- src/core/hle/error_codes.h | 5 +++-- .../hle/libraries/libkernel/file_system.cpp | 20 +++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/core/hle/error_codes.h b/src/core/hle/error_codes.h index 3629342f..1e11850b 100644 --- a/src/core/hle/error_codes.h +++ b/src/core/hle/error_codes.h @@ -22,5 +22,6 @@ constexpr int SCE_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; // slot al constexpr int SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; // flip queue is full constexpr int SCE_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; // Invalid buffer attribute option -//filesystem -constexpr int SCE_KERNEL_ERROR_EMFILE = 0x80020018;//limit of max descriptors reached +// filesystem +constexpr int SCE_KERNEL_ERROR_ENOTDIR = 0x80020014; // Specified file is not a directory +constexpr int SCE_KERNEL_ERROR_EMFILE = 0x80020018; // limit of max descriptors reached diff --git a/src/core/hle/libraries/libkernel/file_system.cpp b/src/core/hle/libraries/libkernel/file_system.cpp index 58c68746..4511e865 100644 --- a/src/core/hle/libraries/libkernel/file_system.cpp +++ b/src/core/hle/libraries/libkernel/file_system.cpp @@ -1,5 +1,5 @@ #include "core/hle/libraries/libkernel/file_system.h" - +#include #include "common/debug.h" #include "common/log.h" #include "common/singleton.h" @@ -28,9 +28,25 @@ int PS4_SYSV_ABI sceKernelOpen(const char* path, int flags, u16 mode) { file->isDirectory = true; file->m_guest_name = path; file->m_host_name = mnt->getHostDirectory(file->m_guest_name); + if (!std::filesystem::is_directory(file->m_host_name)) { // directory doesn't exist + if (create) { // if we have a create flag create it + if (std::filesystem::create_directories(file->m_host_name)) { + return handle; + } else { + return SCE_KERNEL_ERROR_ENOTDIR; + } + return SCE_KERNEL_ERROR_ENOTDIR; + } + } else { + if (create) { + return handle;//directory already exists + } else { + BREAKPOINT();//here we should handle open directory mode + } + } } - return 0; + return handle; } int PS4_SYSV_ABI posix_open(const char* path, int flags, /* SceKernelMode*/ u16 mode) {