From fc251b32b0a36a598a8779674fcf61db377afa29 Mon Sep 17 00:00:00 2001 From: zhupengfei Date: Thu, 5 Mar 2020 14:50:08 +0800 Subject: [PATCH] service/fs: Update file size on write The file's size is stored in FileSessionSlot and retrieved when the game calls GetSize. However, it is not updated when the file is written to, which can possibly change the file size. Therefore, this can cause GetSize to return incorrect results. --- src/core/hle/service/fs/file.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/fs/file.cpp b/src/core/hle/service/fs/file.cpp index e31f89d0e7..f91cbee99b 100644 --- a/src/core/hle/service/fs/file.cpp +++ b/src/core/hle/service/fs/file.cpp @@ -90,7 +90,7 @@ void File::Write(Kernel::HLERequestContext& ctx) { IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); - const FileSessionSlot* file = GetSessionData(ctx.Session()); + FileSessionSlot* file = GetSessionData(ctx.Session()); // Subfiles can not be written to if (file->subfile) { @@ -103,6 +103,10 @@ void File::Write(Kernel::HLERequestContext& ctx) { std::vector data(length); buffer.Read(data.data(), 0, data.size()); ResultVal written = backend->Write(offset, data.size(), flush != 0, data.data()); + + // Update file size + file->size = backend->GetSize(); + if (written.Failed()) { rb.Push(written.Code()); rb.Push(0);