Skip to content

Commit

Permalink
Don't grow file all at once
Browse files Browse the repository at this point in the history
  • Loading branch information
brunom committed Jun 12, 2020
1 parent 5a38f60 commit 773fa4c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions reflink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
{
Expand Down

0 comments on commit 773fa4c

Please sign in to comment.