From 9d2c9e5d62d50b9d445e5b1fce31e62684a1ff87 Mon Sep 17 00:00:00 2001 From: Eladash Date: Fri, 3 Jan 2020 22:29:39 +0200 Subject: [PATCH] cellFs: Improve cellFsGetDirectoryEntries --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 9ead6f8e48..3c745866b9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -639,7 +639,9 @@ error_code sys_fs_stat(ppu_thread& ppu, vm::cptr path, vm::ptr const std::string_view vpath = path.get_ptr(); const std::string local_path = vfs::get(vpath); - if (vpath.find_first_not_of('/') == -1) + const auto first_name_ch = vpath.find_first_not_of('/'); + + if (first_name_ch == -1) { *sb = {CELL_FS_S_IFDIR | 0444}; return CELL_OK; @@ -693,9 +695,10 @@ error_code sys_fs_stat(ppu_thread& ppu, vm::cptr path, vm::ptr } } + const bool supports_id = vpath.size() < (first_name_ch + 8) || !vpath.compare(first_name_ch, 8, "dev_hdd1"sv); // TODO sb->mode = info.is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; - sb->uid = 0; // Always zero - sb->gid = 0; // Always zero + sb->uid = supports_id ? 0 : -1; + sb->gid = supports_id ? 0 : -1; sb->atime = info.atime; sb->mtime = info.mtime; sb->ctime = info.ctime; @@ -727,9 +730,10 @@ error_code sys_fs_fstat(ppu_thread& ppu, u32 fd, vm::ptr sb) const fs::stat_t& info = file->file.stat(); + const bool supports_id = std::memcmp("/dev_hdd1", file->name.data(), 9) != 0; // TODO sb->mode = info.is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; - sb->uid = 0; // Always zero - sb->gid = 0; // Always zero + sb->uid = supports_id ? 0 : -1; + sb->gid = supports_id ? 0 : -1; sb->atime = info.atime; sb->mtime = info.mtime; sb->ctime = info.ctime; // ctime may be incorrect @@ -1218,15 +1222,21 @@ error_code sys_fs_fcntl(ppu_thread& ppu, u32 fd, u32 op, vm::ptr _arg, u32 return CELL_EBADF; } - for (; arg->_size < arg->max; arg->_size++) + arg->_size = 0; // This write is not really useful for cellFs but do it anyways + + // NOTE: This function is actually capable of reading only one entry at a time + if (arg->max) { + std::memset(arg->ptr.get_ptr(), 0, arg->max * arg->ptr.size()); + if (auto* info = directory->dir_read()) { - auto& entry = arg->ptr[arg->_size]; + auto& entry = arg->ptr[arg->_size++]; + const bool supports_id = std::memcmp("/dev_hdd1", directory->name.data(), 9) != 0; // TODO entry.attribute.mode = info->is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; - entry.attribute.uid = 0; - entry.attribute.gid = 0; + entry.attribute.uid = supports_id ? 0 : -1; + entry.attribute.gid = supports_id ? 0 : -1; entry.attribute.atime = info->atime; entry.attribute.mtime = info->mtime; entry.attribute.ctime = info->ctime; @@ -1237,10 +1247,6 @@ error_code sys_fs_fcntl(ppu_thread& ppu, u32 fd, u32 op, vm::ptr _arg, u32 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); } - else - { - break; - } } arg->_code = CELL_OK;