diff --git a/core/libs/prx/libkernel/File/src/Open.cpp b/core/libs/prx/libkernel/File/src/Open.cpp index 82b95da718..8d70e35eb6 100644 --- a/core/libs/prx/libkernel/File/src/Open.cpp +++ b/core/libs/prx/libkernel/File/src/Open.cpp @@ -458,7 +458,7 @@ static int StatNative(const std::filesystem::path& native, bool directory, FileS int APS5_VABI sceKernelStat(const char* path, FileStat* sb) { std::string copy; - if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error); + if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error); path = copy.c_str(); if (copy.empty()) return SceErrorFromErrno(2); std::filesystem::path native; @@ -479,7 +479,7 @@ int StatInDirectory_nid_no_patch(int directory, const char* path, FileStat* sb, int APS5_VABI sceKernelUnlink(const char* path) { std::string copy; - if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error); + if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error); path = copy.c_str(); if (copy.empty()) return SceErrorFromErrno(2); if (const int dot = RenameDotError_nid_no_patch(path)) return SceKernelError(dot); diff --git a/core/libs/prx/libkernel/File/src/Stdio.cpp b/core/libs/prx/libkernel/File/src/Stdio.cpp index 08e0a82b9c..886a5b3131 100644 --- a/core/libs/prx/libkernel/File/src/Stdio.cpp +++ b/core/libs/prx/libkernel/File/src/Stdio.cpp @@ -1346,7 +1346,7 @@ int APS5_VABI getdents_nid_postfix(int fd, char* buf, int nbytes) { int APS5_VABI sceKernelMkdir(const char* path, uint16_t mode) { (void)mode; std::string copy; - if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error); + if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error); path = copy.c_str(); if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT); std::filesystem::path native; @@ -1643,7 +1643,7 @@ int APS5_VABI sceKernelRename(const char* from, const char* to) { int APS5_VABI sceKernelRmdir(const char* path) { std::string copy; - if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error); + if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error); path = copy.c_str(); if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT); if (const int dot = RenameDotError_nid_no_patch(path)) return SceKernelError(dot); @@ -1687,7 +1687,7 @@ extern "C" { int APS5_VABI sceKernelChmod_nid_postfix(const char* path, std::uint16_t mode) { std::string copy; - if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error); + if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error); path = copy.c_str(); if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT); std::filesystem::path native; @@ -1727,7 +1727,7 @@ static bool CopyInTimes(const KernelTimeval*& times, KernelTimeval (&local)[2]) int APS5_VABI sceKernelTruncate_nid_postfix(const char* path, std::int64_t length) { if (length < 0) return SceErrorFromErrno(GUEST_EINVAL); std::string copy; - if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error); + if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error); path = copy.c_str(); if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT); std::filesystem::path native; @@ -1765,7 +1765,7 @@ int APS5_VABI sceKernelUtimes_nid_postfix(const char* path, const KernelTimeval* if (!CopyInTimes(times, local)) return SCE_KERNEL_ERROR_EFAULT; if (InvalidTimes(times)) return SCE_KERNEL_ERROR_EINVAL; std::string copy; - if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceErrorFromErrno(error); + if (const int error = CopyGuestPath_nid_no_patch(path, copy)) return SceKernelError(error); path = copy.c_str(); if (copy.empty()) return SceErrorFromErrno(GUEST_ENOENT); std::filesystem::path native; diff --git a/core/libs/tests/GuestPathNameLength.cpp b/core/libs/tests/GuestPathNameLength.cpp index c6197d2e8f..0276453546 100644 --- a/core/libs/tests/GuestPathNameLength.cpp +++ b/core/libs/tests/GuestPathNameLength.cpp @@ -1,4 +1,6 @@ #include "prx/libkernel/include/Api.hpp" +#include "prx/libkernel/File/include/File.hpp" +#include "prx/libkernel/KernelErrors.hpp" #include "prx/libc/include/Api.hpp" #include "prx/libc/include/general/VabiMacros.hpp" #include @@ -24,6 +26,18 @@ bool TooLong(const std::string& path) { return Fails(stat_nid_postfix(path.c_str(), reinterpret_cast(status)), ErrorNameTooLong); } +void RequireSceTooLong(const std::string& path, const char* what) { + unsigned char status[256]; + const char* name = path.c_str(); + const int results[] = {sceKernelStat(name, reinterpret_cast(status)), sceKernelUnlink(name), sceKernelMkdir(name, 0755), sceKernelRmdir(name), sceKernelChmod_nid_postfix(name, 0644), sceKernelTruncate_nid_postfix(name, 0), sceKernelUtimes_nid_postfix(name, nullptr)}; + const char* calls[] = {"sceKernelStat", "sceKernelUnlink", "sceKernelMkdir", "sceKernelRmdir", "sceKernelChmod", "sceKernelTruncate", "sceKernelUtimes"}; + for (int index = 0; index < 7; ++index) { + if (results[index] == SCE_KERNEL_ERROR_ENAMETOOLONG) continue; + std::fprintf(stderr, "%s: %s returned 0x%X\n", what, calls[index], static_cast(results[index])); + std::abort(); + } +} + } int main() { @@ -49,9 +63,11 @@ int main() { Require(!TooLong(block + block + block + name255), "a path of exactly 1023 bytes must not be too long"); #endif Require(TooLong(block + block + block + block), "a path of exactly 1024 bytes must fail with ENAMETOOLONG (63)"); + RequireSceTooLong(block + block + block + block, "the sce path calls must fail a path of exactly 1024 bytes with SCE_KERNEL_ERROR_ENAMETOOLONG"); Require(rmdir_nid_postfix("anyps5_name_length") == 0, "rmdir of the test directory failed"); Require(Fails(stat_nid_postfix((longName + "/x").c_str(), reinterpret_cast(status)), ErrorNameTooLong), "stat of a long first component must fail with ENAMETOOLONG (63)"); Require(Fails(stat_nid_postfix(longPath.c_str(), reinterpret_cast(status)), ErrorNameTooLong), "stat of a path of 1100 bytes must fail with ENAMETOOLONG (63)"); + RequireSceTooLong(longPath, "the sce path calls must fail a path of 1100 bytes with SCE_KERNEL_ERROR_ENAMETOOLONG"); Require(Fails(access_nid_postfix(longName.c_str(), 0), ErrorNameTooLong), "access of a long name must fail with ENAMETOOLONG (63)"); Require(Fails(chflags_nid_postfix(longName.c_str(), 0), ErrorNameTooLong), "chflags of a long name must fail with ENAMETOOLONG (63)"); Require(Fails(unlink_nid_postfix(longName.c_str()), ErrorNameTooLong), "unlink of a long name must fail with ENAMETOOLONG (63)");