From 16620f6835ea815d35282a221ed4d327f723849d Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 19 May 2021 16:34:31 +0300 Subject: [PATCH] vm_native: sparse file fixup (Win32) Clear file if it occupies blocks. Makes it more fool-proof and fixes possible bug. --- rpcs3/util/vm_native.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rpcs3/util/vm_native.cpp b/rpcs3/util/vm_native.cpp index 00323d73be..00af16f1e8 100644 --- a/rpcs3/util/vm_native.cpp +++ b/rpcs3/util/vm_native.cpp @@ -345,6 +345,16 @@ namespace utils if (DeviceIoControl(h, FSCTL_SET_SPARSE, nullptr, 0, nullptr, 0, nullptr, nullptr)) { + FILE_STANDARD_INFO info; + ensure(GetFileInformationByHandleEx(h, FileStandardInfo, &info, sizeof(info))); + + if (info.AllocationSize.QuadPart) + { + // Make sure the file is not "dirty" + FILE_END_OF_FILE_INFO _eof{}; + ensure(SetFileInformationByHandle(h, FileEndOfFileInfo, &_eof, sizeof(_eof))); + } + return true; }