From 3e064462977ae0bfa84b93fa5f677ad64c3ed39f Mon Sep 17 00:00:00 2001 From: Eladash Date: Tue, 21 Sep 2021 12:07:01 +0300 Subject: [PATCH] sys_fs: Fix sys_fs_read/write when nbytes is 0 --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 986cd4d0e7..b7486d52e3 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -637,12 +637,25 @@ error_code sys_fs_read(ppu_thread& ppu, u32 fd, vm::ptr buf, u64 nbytes, v const auto file = idm::get(fd); - if (!file || file->flags & CELL_FS_O_WRONLY) + if (!file || (nbytes && file->flags & CELL_FS_O_WRONLY)) { nread.try_write(0); // nread writing is allowed to fail, error code is unchanged return CELL_EBADF; } + if (!nbytes) + { + // Whole function is skipped, only EBADF and EBUSY are checked + if (file->lock == 1) + { + nread.try_write(0); + return CELL_EBUSY; + } + + *nread = 0; + return CELL_OK; + } + std::lock_guard lock(file->mp->mutex); if (!file->file) @@ -681,12 +694,25 @@ error_code sys_fs_write(ppu_thread& ppu, u32 fd, vm::cptr buf, u64 nbytes, const auto file = idm::get(fd); - if (!file || !(file->flags & CELL_FS_O_ACCMODE)) + if (!file || (nbytes && !(file->flags & CELL_FS_O_ACCMODE))) { nwrite.try_write(0); // nwrite writing is allowed to fail, error code is unchanged return CELL_EBADF; } + if (!nbytes) + { + // Whole function is skipped, only EBADF and EBUSY are checked + if (file->lock == 1) + { + nwrite.try_write(0); + return CELL_EBUSY; + } + + *nwrite = 0; + return CELL_OK; + } + if (file->mp->flags & lv2_mp_flag::read_only) { nwrite.try_write(0);