diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 7803084d5c..9ab313b4c3 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -153,10 +153,36 @@ fs::file lv2_file::make_view(const std::shared_ptr& _file, u64 offset) return result; } -error_code sys_fs_test(u32 arg1, u32 arg2, vm::ptr arg3, u32 arg4, vm::ptr arg5, u32 arg6) +error_code sys_fs_test(u32 arg1, u32 arg2, vm::ptr arg3, u32 arg4, vm::ptr buf, u32 buf_size) { - sys_fs.todo("sys_fs_test(arg1=0x%x, arg2=0x%x, arg3=*0x%x, arg4=0x%x, arg5=*0x%x, arg6=0x%x) -> CELL_OK", arg1, arg2, arg3, arg4, arg5, arg6); + sys_fs.trace("sys_fs_test(arg1=0x%x, arg2=0x%x, arg3=*0x%x, arg4=0x%x, buf=*0x%x, buf_size=0x%x)", arg1, arg2, arg3, arg4, buf, buf_size); + if (arg1 != 6 || arg2 != 0 || arg4 != sizeof(u32)) + { + sys_fs.todo("sys_fs_test: unknown arguments (arg1=0x%x, arg2=0x%x, arg3=*0x%x, arg4=0x%x)", arg1, arg2, arg3, arg4); + } + + if (!arg3) + { + return CELL_EFAULT; + } + + const auto file = idm::get(*arg3); + + if (!file) + { + return CELL_EBADF; + } + + for (u32 i = 0; i < buf_size; i++) + { + if (!(buf[i] = file->name[i])) + { + return CELL_OK; + } + } + + buf[buf_size - 1] = 0; return CELL_OK; } @@ -664,7 +690,7 @@ error_code sys_fs_fcntl(u32 fd, u32 op, vm::ptr _arg, u32 _size) fs::file stream; stream.reset(std::move(sdata_file)); - if (const u32 id = idm::make(file->mp, std::move(stream), file->mode, file->flags)) + if (const u32 id = idm::make(*file, std::move(stream), file->mode, file->flags)) { arg->out_code = CELL_OK; arg->out_fd = id; diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.h b/rpcs3/Emu/Cell/lv2/sys_fs.h index 02e9091753..6fea6b7d09 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.h +++ b/rpcs3/Emu/Cell/lv2/sys_fs.h @@ -130,12 +130,34 @@ struct lv2_fs_object // Mount Point const std::add_pointer_t mp; - lv2_fs_object(lv2_fs_mount_point* mp) + // File Name (max 1055) + const std::array name; + + lv2_fs_object(lv2_fs_mount_point* mp, const char* filename) : mp(mp) + , name(get_name(filename)) { } static lv2_fs_mount_point* get_mp(const char* filename); + + static std::array get_name(const char* filename) + { + std::array name; + + for (auto& c : name) + { + c = *filename++; + + if (!c) + { + return name; + } + } + + name.back() = 0; + return name; + } }; struct lv2_file final : lv2_fs_object @@ -145,15 +167,15 @@ struct lv2_file final : lv2_fs_object const s32 flags; lv2_file(const char* filename, fs::file&& file, s32 mode, s32 flags) - : lv2_fs_object(lv2_fs_object::get_mp(filename)) + : lv2_fs_object(lv2_fs_object::get_mp(filename), filename) , file(std::move(file)) , mode(mode) , flags(flags) { } - lv2_file(lv2_fs_mount_point* mp, fs::file&& file, s32 mode, s32 flags) - : lv2_fs_object(mp) + lv2_file(const lv2_file& host, fs::file&& file, s32 mode, s32 flags) + : lv2_fs_object(host.mp, host.name.data()) , file(std::move(file)) , mode(mode) , flags(flags) @@ -178,7 +200,7 @@ struct lv2_dir final : lv2_fs_object const fs::dir dir; lv2_dir(const char* filename, fs::dir&& dir) - : lv2_fs_object(lv2_fs_object::get_mp(filename)) + : lv2_fs_object(lv2_fs_object::get_mp(filename), filename) , dir(std::move(dir)) { } @@ -284,7 +306,7 @@ CHECK_SIZE(lv2_file_c0000006, 0x20); // Syscalls -error_code sys_fs_test(u32 arg1, u32 arg2, vm::ps3::ptr arg3, u32 arg4, vm::ps3::ptr arg5, u32 arg6); +error_code sys_fs_test(u32 arg1, u32 arg2, vm::ps3::ptr arg3, u32 arg4, vm::ps3::ptr buf, u32 buf_size); error_code sys_fs_open(vm::ps3::cptr path, s32 flags, vm::ps3::ptr fd, s32 mode, vm::ps3::cptr arg, u64 size); error_code sys_fs_read(u32 fd, vm::ps3::ptr buf, u64 nbytes, vm::ps3::ptr nread); error_code sys_fs_write(u32 fd, vm::ps3::cptr buf, u64 nbytes, vm::ps3::ptr nwrite);