vm_native: sparse file fixup (Win32)

Clear file if it occupies blocks.
Makes it more fool-proof and fixes possible bug.
This commit is contained in:
Nekotekina 2021-05-19 16:34:31 +03:00
parent 88bfd3c3a7
commit 16620f6835
1 changed files with 10 additions and 0 deletions

View File

@ -345,6 +345,16 @@ namespace utils
if (DeviceIoControl(h, FSCTL_SET_SPARSE, nullptr, 0, nullptr, 0, nullptr, nullptr)) 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; return true;
} }