Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions core/libs/prx/libkernel/File/src/Open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,15 @@ std::int64_t APS5_VABI sceKernelLseek(int d, std::int64_t offset, int whence) {
return result;
}

constexpr int GuestEfault = 14;

int APS5_VABI sceKernelStat(const char* path, FileStat* sb) {
if (path == nullptr) {
throw std::invalid_argument(std::string(__func__) + ": path is null");
}
if (path == nullptr) return SceErrorFromErrno(GuestEfault);
if (*path == '\0') return SceErrorFromErrno(2);
std::filesystem::path native;
if (const int error = ResolvePathError_nid_no_patch(path, native, true, true)) return SceKernelError(error);
std::error_code error;
constexpr int GuestEnotdir = 20;
constexpr int GuestEfault = 14;
FileStat archived{};
if (File::FillArchivedStat(native, &archived)) {
if (std::string_view(path).back() == '/' && (archived.st_mode & 0170000) != 0040000) return SceErrorFromErrno(GuestEnotdir);
Expand All @@ -346,9 +345,7 @@ int APS5_VABI sceKernelStat(const char* path, FileStat* sb) {
}

int APS5_VABI sceKernelUnlink(const char* path) {
if (path == nullptr) {
throw std::invalid_argument(std::string(__func__) + ": path is null");
}
if (path == nullptr) return SceErrorFromErrno(GuestEfault);
if (*path == '\0') return SceErrorFromErrno(2);
std::filesystem::path native;
if (const int error = ResolvePathError_nid_no_patch(path, native)) return SceKernelError(error);
Expand Down
6 changes: 6 additions & 0 deletions core/libs/tests/GuestPosixScalarIo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ std::int64_t APS5_VABI pwrite_nid_disambig1_nid_postfix(int, const void*, std::s
std::int64_t APS5_VABI sceKernelRead(int, void*, std::size_t);
std::int64_t APS5_VABI sceKernelWrite(int, const void*, std::size_t);
std::int64_t APS5_VABI sceKernelLseek(int, std::int64_t, int);
int APS5_VABI sceKernelStat(const char*, FileStat*);
int APS5_VABI sceKernelUnlink(const char*);
}

static void Check(bool value, int line) {
Expand Down Expand Up @@ -153,6 +155,10 @@ int main() {
Require(sceKernelWrite(descriptor, nullptr, 0) == 0);
Require(sceKernelRead(-1, nullptr, 0) == static_cast<std::int32_t>(0x80020009u));
Require(sceKernelWrite(-1, nullptr, 0) == static_cast<std::int32_t>(0x80020009u));
FileStat nullStat{};
Require(sceKernelStat(nullptr, &nullStat) == static_cast<std::int32_t>(0x8002000eu));
Require(sceKernelStat(nullptr, nullptr) == static_cast<std::int32_t>(0x8002000eu));
Require(sceKernelUnlink(nullptr) == static_cast<std::int32_t>(0x8002000eu));
Require(close_nid_postfix(descriptor) == 0);
const int readOnly = open_nid_postfix(fileName.c_str(), SCE_KERNEL_O_RDONLY, 0);
Require(readOnly >= 0);
Expand Down
Loading