From 39a79de1b6d9bcb9a43b7af50fa92a5fc8dd061d Mon Sep 17 00:00:00 2001 From: brian218 Date: Wed, 26 Jul 2023 17:36:44 +0800 Subject: [PATCH 1/2] sys_fs: Fixed up sys_fs_fcntl(0xc0000007) aka cellFsArcadeHddSerialNumber according to real hardware testing --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 27 +++++++++------------------ rpcs3/Emu/Cell/lv2/sys_fs.h | 4 ++-- rpcs3/Emu/Io/usio.cpp | 2 +- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 2f41a8f36074..575000565f74 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -2064,27 +2064,18 @@ error_code sys_fs_fcntl(ppu_thread& ppu, u32 fd, u32 op, vm::ptr _arg, u32 { const auto arg = vm::static_ptr_cast(_arg); - 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(); + arg->out_code = CELL_OK; - strcpy_trunc(std::span(arg->model.get_ptr(), arg->model_size), model); - strcpy_trunc(std::span(arg->serial.get_ptr(), arg->serial_size), serial); + if (const auto size = arg->model_size; size > 0) + strcpy_trunc(std::span(arg->model.get_ptr(), size), + fmt::format("%-*s", size - 1, g_cfg.sys.hdd_model.to_string())); // Example: "TOSHIBA MK3265GSX H " - arg->out_code = CELL_OK; + if (const auto size = arg->serial_size; size > 0) + strcpy_trunc(std::span(arg->serial.get_ptr(), size), + fmt::format("%*s", size - 1, g_cfg.sys.hdd_serial.to_string())); // Example: " 0A1B2C3D4" + else + return CELL_EFAULT; // CELL_EFAULT is returned only when arg->serial_size == 0 - 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 0f5c9a3be3ab..1f1e2c2ec185 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.h +++ b/rpcs3/Emu/Cell/lv2/sys_fs.h @@ -529,8 +529,8 @@ CHECK_SIZE(lv2_file_c0000006, 0x20); // sys_fs_fcntl: cellFsArcadeHddSerialNumber struct lv2_file_c0000007 : lv2_file_op { - be_t out_code; - vm::bcptr device; + be_t out_code; // set to 0 + vm::bcptr device; // CELL_FS_IOS:ATA_HDD be_t device_size; // 0x14 vm::bptr model; be_t model_size; // 0x29 diff --git a/rpcs3/Emu/Io/usio.cpp b/rpcs3/Emu/Io/usio.cpp index 0da11170fc46..a5b4348937b9 100644 --- a/rpcs3/Emu/Io/usio.cpp +++ b/rpcs3/Emu/Io/usio.cpp @@ -334,7 +334,7 @@ void usb_device_usio::translate_input_tekken() } break; case usio_btn::down: - if ( pressed) + if (pressed) { digital_input |= 0x100000ULL << shift; if (player == 0) From 4093fd65e91238778cfdf9fbcc5224bcde6ada62 Mon Sep 17 00:00:00 2001 From: brian218 Date: Wed, 26 Jul 2023 17:36:57 +0800 Subject: [PATCH 2/2] sys_fs: Updated sys_fs_fcntl(0xc0000015&0xc000001c)'s error handling according to real hardware testing --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 42 +++++++++++++++++------------------ rpcs3/Emu/Cell/lv2/sys_fs.h | 8 +++---- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 575000565f74..bfcf0c09ec3a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -2181,39 +2181,37 @@ error_code sys_fs_fcntl(ppu_thread& ppu, u32 fd, u32 op, vm::ptr _arg, u32 break; } - std::string_view vpath{arg->name.get_ptr(), arg->name_size}; + std::string_view vpath{arg->path.get_ptr(), arg->path_size}; + + if (vpath.size() == 0) + return CELL_ENOMEM; // Trim trailing '\0' if (const auto trim_pos = vpath.find('\0'); trim_pos != umax) vpath.remove_suffix(vpath.size() - trim_pos); - if (vfs::get(vpath).empty()) - { - arg->out_code = CELL_ENOTMOUNTED; - return {CELL_ENOTMOUNTED, vpath}; - } - - const auto& mp = g_fxo->get().lookup(vpath, true); + arg->out_code = CELL_ENOTMOUNTED; // arg->out_code is set to CELL_ENOTMOUNTED on real hardware when the device doesn't exist or when the device isn't USB - if (mp != &g_mp_sys_dev_usb) + if (!vfs::get(vpath).empty()) { - arg->out_code = CELL_ENOTSUP; - return {CELL_ENOTSUP, vpath}; - } + if (const auto& mp = g_fxo->get().lookup(vpath, true); mp == &g_mp_sys_dev_usb) + { + const cfg::device_info device = g_cfg_vfs.get_device(g_cfg_vfs.dev_usb, fmt::format("%s%s", mp->root, mp.device.substr(mp->device.size()))); + const auto usb_ids = device.get_usb_ids(); + std::tie(arg->vendorID, arg->productID) = usb_ids; - const cfg::device_info device = g_cfg_vfs.get_device(g_cfg_vfs.dev_usb, fmt::format("%s%s", mp->root, mp.device.substr(mp->device.size()))); - std::tie(arg->vendorID, arg->productID) = device.get_usb_ids(); + if (with_serial) + { + const auto arg_c000001c = vm::static_ptr_cast(_arg); + const std::u16string serial = utf8_to_utf16(device.serial); // Serial needs to be encoded to utf-16 BE + std::copy_n(serial.begin(), std::min(serial.size(), sizeof(arg_c000001c->serial) / sizeof(u16)), arg_c000001c->serial); + } - if (with_serial) - { - const auto arg_c000001c = vm::static_ptr_cast(_arg); - const std::u16string serial = utf8_to_utf16(device.serial); // Serial needs to be encoded to utf-16 BE - std::copy_n(serial.begin(), std::min(serial.size(), sizeof(arg_c000001c->serial) / sizeof(u16)), arg_c000001c->serial); + arg->out_code = CELL_OK; + sys_fs.trace("sys_fs_fcntl(0x%08x): found device \"%s\" (vid=0x%04x, pid=0x%04x, serial=\"%s\")", op, mp.device, usb_ids.first, usb_ids.second, device.serial); + } } - arg->out_code = CELL_OK; - - sys_fs.trace("sys_fs_fcntl(0x%08x): found device \"%s\" (vid=0x%04x, pid=0x%04x, serial=\"%s\")", op, mp.device, arg->vendorID, arg->productID, device.serial); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.h b/rpcs3/Emu/Cell/lv2/sys_fs.h index 1f1e2c2ec185..79ee4636bd5d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.h +++ b/rpcs3/Emu/Cell/lv2/sys_fs.h @@ -562,8 +562,8 @@ struct lv2_file_c0000015 : lv2_file_op be_t size; // 0x20 be_t _x4; // 0x10 be_t _x8; // 0x18 - offset of out_code - be_t name_size; - vm::bcptr name; + be_t path_size; + vm::bcptr path; be_t _x14; // be_t vendorID; be_t productID; @@ -590,8 +590,8 @@ struct lv2_file_c000001c : lv2_file_op be_t size; // 0x60 be_t _x4; // 0x10 be_t _x8; // 0x18 - offset of out_code - be_t name_size; - vm::bcptr name; + be_t path_size; + vm::bcptr path; be_t unk1; be_t vendorID; be_t productID;