From 773fa4cd874d67a0260d86b32eeddbb4189abccd Mon Sep 17 00:00:00 2001 From: Bruno Date: Fri, 12 Jun 2020 00:24:48 -0300 Subject: [PATCH] Don't grow file all at once --- reflink.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/reflink.cpp b/reflink.cpp index 1d11c08..a899fef 100644 --- a/reflink.cpp +++ b/reflink.cpp @@ -71,12 +71,9 @@ bool reflink(_In_z_ PCWSTR oldpath, _In_z_ PCWSTR newpath) return false; } - if (file_basic.FileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) + if (!DeviceIoControl(destination, FSCTL_SET_SPARSE, nullptr, 0, nullptr, 0, &junk, nullptr)) { - if (!DeviceIoControl(destination, FSCTL_SET_SPARSE, nullptr, 0, nullptr, 0, &junk, nullptr)) - { - return false; - } + return false; } FSCTL_SET_INTEGRITY_INFORMATION_BUFFER set_integrity = { get_integrity.ChecksumAlgorithm, get_integrity.Reserved, get_integrity.Flags }; if (!DeviceIoControl(destination, FSCTL_SET_INTEGRITY_INFORMATION, &set_integrity, sizeof set_integrity, nullptr, 0, nullptr, nullptr)) @@ -107,6 +104,15 @@ bool reflink(_In_z_ PCWSTR oldpath, _In_z_ PCWSTR newpath) } } + if (!(file_basic.FileAttributes & FILE_ATTRIBUTE_SPARSE_FILE)) + { + FILE_SET_SPARSE_BUFFER set_sparse = { FALSE }; + if (!DeviceIoControl(destination, FSCTL_SET_SPARSE, &set_sparse, sizeof set_sparse, nullptr, 0, &junk, nullptr)) + { + return false; + } + } + file_basic.CreationTime.QuadPart = 0; if (!SetFileInformationByHandle(destination, FileBasicInfo, &file_basic, sizeof file_basic)) {