From 6a41b22a1b6128d36e61680d3bc3889ca09052e8 Mon Sep 17 00:00:00 2001 From: brian218 Date: Tue, 2 May 2023 23:57:39 +0800 Subject: [PATCH] sys_fs: Further implemented cellFsArcadeHddSerialNumber (0xc0000007) --- Utilities/StrUtil.h | 2 +- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 22 +++++++++++++++++++++- rpcs3/Emu/Cell/lv2/sys_fs.h | 13 +++++++------ rpcs3/Emu/system_config.h | 2 ++ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Utilities/StrUtil.h b/Utilities/StrUtil.h index 012d7eac94..7bae3179c5 100644 --- a/Utilities/StrUtil.h +++ b/Utilities/StrUtil.h @@ -15,7 +15,7 @@ std::u16string utf8_to_utf16(std::string_view src); // Copy null-terminated string from a std::string or a char array to a char array with truncation template -inline void strcpy_trunc(D& dst, const T& src) +inline void strcpy_trunc(D&& dst, const T& src) { const usz count = std::size(src) >= std::size(dst) ? std::max(std::size(dst), 1) - 1 : std::size(src); std::memcpy(std::data(dst), std::data(src), count); diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 6c7097c08a..748a9477ff 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -2053,8 +2053,28 @@ error_code sys_fs_fcntl(ppu_thread& ppu, u32 fd, u32 op, vm::ptr _arg, u32 case 0xc0000007: // cellFsArcadeHddSerialNumber { const auto arg = vm::static_ptr_cast(_arg); - // TODO populate arg-> unk1+2 + + std::string_view device{arg->device.get_ptr(), arg->device_size}; + + // Trim trailing '\0' + if (const auto trim_pos = device.find('\0'); trim_pos != umax) + device.remove_suffix(device.size() - trim_pos); + + if (device != "CELL_FS_IOS:ATA_HDD"sv) + { + arg->out_code = CELL_ENOTSUP; + return {CELL_ENOTSUP, device}; + } + + const auto model = g_cfg.sys.hdd_model.to_string(); + const auto serial = g_cfg.sys.hdd_serial.to_string(); + + strcpy_trunc(std::span(arg->model.get_ptr(), arg->model_size), model); + strcpy_trunc(std::span(arg->serial.get_ptr(), arg->serial_size), serial); + arg->out_code = CELL_OK; + + sys_fs.trace("sys_fs_fcntl(0xc0000007): found device \"%s\" (model=\"%s\", serial=\"%s\")", device, model, serial); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.h b/rpcs3/Emu/Cell/lv2/sys_fs.h index 2296ce9b72..085ce12b4c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.h +++ b/rpcs3/Emu/Cell/lv2/sys_fs.h @@ -535,15 +535,16 @@ struct lv2_file_c0000006 : lv2_file_op CHECK_SIZE(lv2_file_c0000006, 0x20); +// sys_fs_fcntl: cellFsArcadeHddSerialNumber struct lv2_file_c0000007 : lv2_file_op { be_t out_code; - vm::bcptr name; - be_t name_size; // 0x14 - vm::bptr unk1; - be_t unk1_size; //0x41 - vm::bptr unk2; - be_t unk2_size; //0x21 + vm::bcptr device; + be_t device_size; // 0x14 + vm::bptr model; + be_t model_size; // 0x29 + vm::bptr serial; + be_t serial_size; // 0x15 }; CHECK_SIZE(lv2_file_c0000007, 0x1c); diff --git a/rpcs3/Emu/system_config.h b/rpcs3/Emu/system_config.h index 986eaf1cef..3a9ffea945 100644 --- a/rpcs3/Emu/system_config.h +++ b/rpcs3/Emu/system_config.h @@ -288,6 +288,8 @@ struct cfg_root : cfg::node cfg::_int<-60*60*24*365*100LL, 60*60*24*365*100LL> console_time_offset{ this, "Console time offset (s)", 0 }; // console time offset, limited to +/-100years cfg::uint<0, umax> console_psid_high{this, "PSID high"}; cfg::uint<0, umax> console_psid_low{this, "PSID low"}; + cfg::string hdd_model{this, "HDD Model Name", ""}; + cfg::string hdd_serial{this, "HDD Serial Number", ""}; } sys{ this }; struct node_net : cfg::node