From 256dfc5729451ff5b8a94c3a45a3b93c554cf88c Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 24 Apr 2017 18:43:27 +0300 Subject: [PATCH] sys_fs_fsync implemented sys_fs_fdatasync implemented as equal function --- Utilities/File.cpp | 25 +++++++++++++++++++----- Utilities/File.h | 15 +++++++++------ rpcs3/Emu/Cell/Modules/cellFs.cpp | 19 ++++++++++-------- rpcs3/Emu/Cell/lv2/lv2.cpp | 4 ++-- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 32 +++++++++++++++++++++++++++++++ rpcs3/Emu/Cell/lv2/sys_fs.h | 2 ++ 6 files changed, 76 insertions(+), 21 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index 1c9248587c..4cc73c179c 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -156,6 +156,16 @@ namespace fs { } + stat_t file_base::stat() + { + fmt::throw_exception("fs::file::stat() not supported for %s", typeid(*this).name()); + } + + void file_base::sync() + { + // Do notning + } + dir_base::~dir_base() { } @@ -745,6 +755,11 @@ fs::file::file(const std::string& path, bs_t mode) return info; } + void sync() override + { + verify("file::sync" HERE), FlushFileBuffers(m_handle); + } + bool trunc(u64 length) override { LARGE_INTEGER old, pos; @@ -870,6 +885,11 @@ fs::file::file(const std::string& path, bs_t mode) return info; } + void sync() override + { + verify("file::sync" HERE), ::fsync(m_fd) == 0; + } + bool trunc(u64 length) override { if (::ftruncate(m_fd, length) != 0) @@ -945,11 +965,6 @@ fs::file::file(const void* ptr, std::size_t size) { } - fs::stat_t stat() override - { - fmt::raw_error("fs::file::memory_stream::stat(): not supported"); - } - bool trunc(u64 length) override { return false; diff --git a/Utilities/File.h b/Utilities/File.h index 0d9e985785..f9bd852091 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -60,7 +60,8 @@ namespace fs { virtual ~file_base(); - virtual stat_t stat() = 0; + virtual stat_t stat(); + virtual void sync(); virtual bool trunc(u64 length) = 0; virtual u64 read(void* buffer, u64 size) = 0; virtual u64 write(const void* buffer, u64 size) = 0; @@ -206,6 +207,13 @@ namespace fs return m_file->stat(); } + // Sync file buffers + void sync() const + { + if (!m_file) xnull(); + return m_file->sync(); + } + // Read the data from the file and return the amount of data written in buffer u64 read(void* buffer, u64 count) const { @@ -488,11 +496,6 @@ namespace fs { } - stat_t stat() override - { - fmt::raw_error("fs::container_stream<>::stat(): not supported"); - } - bool trunc(u64 length) override { obj.resize(length); diff --git a/rpcs3/Emu/Cell/Modules/cellFs.cpp b/rpcs3/Emu/Cell/Modules/cellFs.cpp index 885b3cb652..e6fd7c8340 100644 --- a/rpcs3/Emu/Cell/Modules/cellFs.cpp +++ b/rpcs3/Emu/Cell/Modules/cellFs.cpp @@ -163,11 +163,20 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr pos) return sys_fs_lseek(fd, offset, whence, pos); } +s32 cellFsFdatasync(u32 fd) +{ + cellFs.trace("cellFsFdatasync(fd=%d)", fd); + + // Call the syscall + return sys_fs_fdatasync(fd); +} + s32 cellFsFsync(u32 fd) { - cellFs.todo("cellFsFsync(fd=0x%x)", fd); + cellFs.trace("cellFsFsync(fd=%d)", fd); - return CELL_OK; + // Call the syscall + return sys_fs_fsync(fd); } s32 cellFsFGetBlockSize(u32 fd, vm::ptr sector_size, vm::ptr block_size) @@ -878,12 +887,6 @@ s32 cellFsFcntl() return CELL_OK; } -s32 cellFsFdatasync() -{ - UNIMPLEMENTED_FUNC(cellFs); - return CELL_OK; -} - s32 cellFsLink() { UNIMPLEMENTED_FUNC(cellFs); diff --git a/rpcs3/Emu/Cell/lv2/lv2.cpp b/rpcs3/Emu/Cell/lv2/lv2.cpp index 47a32fbaae..d02548b3b3 100644 --- a/rpcs3/Emu/Cell/lv2/lv2.cpp +++ b/rpcs3/Emu/Cell/lv2/lv2.cpp @@ -738,8 +738,8 @@ std::array g_ppu_syscall_table null_func,//BIND_FUNC(sys_fs_access), //816 (0x330) BIND_FUNC(sys_fs_fcntl), //817 (0x331) BIND_FUNC(sys_fs_lseek), //818 (0x332) - null_func,//BIND_FUNC(sys_fs_fdatasync), //819 (0x333) - null_func,//BIND_FUNC(sys_fs_fsync), //820 (0x334) + BIND_FUNC(sys_fs_fdatasync), //819 (0x333) + BIND_FUNC(sys_fs_fsync), //820 (0x334) BIND_FUNC(sys_fs_fget_block_size), //821 (0x335) BIND_FUNC(sys_fs_get_block_size), //822 (0x336) null_func,//BIND_FUNC(sys_fs_acl_read), //823 (0x337) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 7a6d270f04..7803084d5c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -775,6 +775,38 @@ error_code sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ptr pos) return CELL_OK; } +error_code sys_fs_fdatasync(u32 fd) +{ + sys_fs.trace("sys_fs_fdadasync(fd=%d)", fd); + + const auto file = idm::get(fd); + + if (!file) + { + return CELL_EBADF; + } + + file->file.sync(); + + return CELL_OK; +} + +error_code sys_fs_fsync(u32 fd) +{ + sys_fs.trace("sys_fs_fsync(fd=%d)", fd); + + const auto file = idm::get(fd); + + if (!file) + { + return CELL_EBADF; + } + + file->file.sync(); + + return CELL_OK; +} + error_code sys_fs_fget_block_size(u32 fd, vm::ptr sector_size, vm::ptr block_size, vm::ptr arg4, vm::ptr arg5) { sys_fs.todo("sys_fs_fget_block_size(fd=%d, sector_size=*0x%x, block_size=*0x%x, arg4=*0x%x, arg5=*0x%x)", fd, sector_size, block_size, arg4, arg5); diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.h b/rpcs3/Emu/Cell/lv2/sys_fs.h index f91be7042f..02e9091753 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.h +++ b/rpcs3/Emu/Cell/lv2/sys_fs.h @@ -300,6 +300,8 @@ error_code sys_fs_rmdir(vm::ps3::cptr path); error_code sys_fs_unlink(vm::ps3::cptr path); error_code sys_fs_fcntl(u32 fd, u32 op, vm::ps3::ptr arg, u32 size); error_code sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ps3::ptr pos); +error_code sys_fs_fdatasync(u32 fd); +error_code sys_fs_fsync(u32 fd); error_code sys_fs_fget_block_size(u32 fd, vm::ps3::ptr sector_size, vm::ps3::ptr block_size, vm::ps3::ptr arg4, vm::ps3::ptr arg5); error_code sys_fs_get_block_size(vm::ps3::cptr path, vm::ps3::ptr sector_size, vm::ps3::ptr block_size, vm::ps3::ptr arg4); error_code sys_fs_truncate(vm::ps3::cptr path, u64 size);