From 83e139cd1a0a831f2b2b01148f5f985ee3fadf22 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Mon, 4 Sep 2017 02:09:22 +0300 Subject: [PATCH] Improve sys_fs_ftruncate Handle stream API lock (EBUSY) Handle append mode --- rpcs3/Emu/Cell/lv2/sys_fs.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/rpcs3/Emu/Cell/lv2/sys_fs.cpp b/rpcs3/Emu/Cell/lv2/sys_fs.cpp index 4fc07f18cf..3e84f31ee4 100644 --- a/rpcs3/Emu/Cell/lv2/sys_fs.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_fs.cpp @@ -1129,7 +1129,21 @@ error_code sys_fs_ftruncate(u32 fd, u64 size) std::lock_guard lock(file->mp->mutex); - if (!file->file.trunc(size)) + if (file->lock) + { + return CELL_EBUSY; + } + + if (file->flags & CELL_FS_O_APPEND) + { + const u64 fsize = file->file.size(); + + if (size > fsize && !file->file.write(std::vector(size - fsize))) + { + return CELL_ENOSPC; + } + } + else if (!file->file.trunc(size)) { switch (auto error = fs::g_tls_error) {