Slightly adjust check for invalid flags

Any open call with invalid flags should return EINVAL, regardless of other errors parameters might cause.
This commit is contained in:
Stephen Miller 2025-04-30 18:28:00 -05:00
parent 297ac4c896
commit c051a47cb6

View File

@ -67,6 +67,12 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
bool write = (flags & 0x3) == ORBIS_KERNEL_O_WRONLY; bool write = (flags & 0x3) == ORBIS_KERNEL_O_WRONLY;
bool rdwr = (flags & 0x3) == ORBIS_KERNEL_O_RDWR; bool rdwr = (flags & 0x3) == ORBIS_KERNEL_O_RDWR;
if (!read && !write && !rdwr) {
// Start by checking for invalid flags.
*__Error() = POSIX_EINVAL;
return -1;
}
bool nonblock = (flags & ORBIS_KERNEL_O_NONBLOCK) != 0; bool nonblock = (flags & ORBIS_KERNEL_O_NONBLOCK) != 0;
bool append = (flags & ORBIS_KERNEL_O_APPEND) != 0; bool append = (flags & ORBIS_KERNEL_O_APPEND) != 0;
bool fsync = (flags & ORBIS_KERNEL_O_FSYNC) != 0; bool fsync = (flags & ORBIS_KERNEL_O_FSYNC) != 0;
@ -114,10 +120,10 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
*__Error() = POSIX_EROFS; *__Error() = POSIX_EROFS;
return -1; return -1;
} }
// Create file if it doesn't exist // Create a file if it doesn't exist
Common::FS::IOFile out(file->m_host_name, Common::FS::FileAccessMode::Write); Common::FS::IOFile out(file->m_host_name, Common::FS::FileAccessMode::Write);
} else if (!exists) { } else if (!exists) {
// File to open doesn't exist, return ENOENT // If we're not creating a file, and it doesn't exist, return ENOENT
h->DeleteHandle(handle); h->DeleteHandle(handle);
*__Error() = POSIX_ENOENT; *__Error() = POSIX_ENOENT;
return -1; return -1;
@ -126,10 +132,7 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
if (std::filesystem::is_directory(file->m_host_name) || directory) { if (std::filesystem::is_directory(file->m_host_name) || directory) {
// Directories can be opened even if the directory flag isn't set. // Directories can be opened even if the directory flag isn't set.
// In these cases, error behavior is identical to the directory code path. // In these cases, error behavior is identical to the directory code path.
directory = true; directory = true;
file->type = Core::FileSys::FileType::Directory;
} else {
file->type = Core::FileSys::FileType::Regular;
} }
if (directory) { if (directory) {
@ -141,6 +144,8 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
return -1; return -1;
} }
file->type = Core::FileSys::FileType::Directory;
// Populate directory contents // Populate directory contents
mnt->IterateDirectory(file->m_guest_name, mnt->IterateDirectory(file->m_guest_name,
[&file](const auto& ent_path, const auto ent_is_file) { [&file](const auto& ent_path, const auto ent_is_file) {
@ -157,11 +162,6 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
h->DeleteHandle(handle); h->DeleteHandle(handle);
*__Error() = POSIX_EISDIR; *__Error() = POSIX_EISDIR;
return -1; return -1;
} else {
// Invalid flags
h->DeleteHandle(handle);
*__Error() = POSIX_EINVAL;
return -1;
} }
if (e == EACCES) { if (e == EACCES) {
@ -181,6 +181,8 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
// Since open starts by closing the file, this won't interfere with later open calls. // Since open starts by closing the file, this won't interfere with later open calls.
e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::ReadWrite); e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::ReadWrite);
file->type = Core::FileSys::FileType::Regular;
if (truncate && read_only) { if (truncate && read_only) {
// Can't open files with truncate flag in a read only directory // Can't open files with truncate flag in a read only directory
h->DeleteHandle(handle); h->DeleteHandle(handle);
@ -208,11 +210,6 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) {
} else if (rdwr) { } else if (rdwr) {
// Read and write // Read and write
e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::ReadWrite); e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::ReadWrite);
} else {
// Invalid flags
h->DeleteHandle(handle);
*__Error() = POSIX_EINVAL;
return -1;
} }
} }