From aeed349a99e6d11ff1d9b4c8aaab20238a62a45e Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 11 Jan 2020 04:48:42 +0300 Subject: [PATCH] sys_fs: adjust permissions for /dev_bdvd Remove write permissions returned by stat, fstat, etc. Also make sys_fs_open return CELL_EPERM on write attempt. --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index f4ddf88e39..eb47f08fc8 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -251,6 +251,14 @@ error_code sys_fs_open(ppu_thread& ppu, vm::cptr path, s32 flags, vm::ptr< case CELL_FS_O_RDWR: open_mode += fs::read + fs::write; break; } + if (mp->flags & lv2_mp_flag::read_only) + { + if (flags & CELL_FS_O_ACCMODE || flags & (CELL_FS_O_CREAT | CELL_FS_O_TRUNC)) + { + return {CELL_EPERM, path}; + } + } + if (flags & CELL_FS_O_CREAT) { open_mode += fs::create; @@ -771,6 +779,12 @@ error_code sys_fs_stat(ppu_thread& ppu, vm::cptr path, vm::ptr sb->size = info.size; sb->blksize = mp->block_size; + if (mp->flags & lv2_mp_flag::read_only) + { + // Remove write permissions + sb->mode &= ~0222; + } + return CELL_OK; } @@ -805,6 +819,12 @@ error_code sys_fs_fstat(ppu_thread& ppu, u32 fd, vm::ptr sb) sb->size = info.size; sb->blksize = file->mp->block_size; + if (file->mp->flags & lv2_mp_flag::read_only) + { + // Remove write permissions + sb->mode &= ~0222; + } + return CELL_OK; } @@ -1339,6 +1359,12 @@ error_code sys_fs_fcntl(ppu_thread& ppu, u32 fd, u32 op, vm::ptr _arg, u32 entry.attribute.size = info->size; entry.attribute.blksize = directory->mp->block_size; + if (directory->mp->flags & lv2_mp_flag::read_only) + { + // Remove write permissions + entry.attribute.mode &= ~0222; + } + entry.entry_name.d_type = info->is_directory ? CELL_FS_TYPE_DIRECTORY : CELL_FS_TYPE_REGULAR; entry.entry_name.d_namlen = u8(std::min(info->name.size(), CELL_FS_MAX_FS_FILE_NAME_LENGTH)); strcpy_trunc(entry.entry_name.d_name, info->name);