Skip to content

Commit

Permalink
Merge pull request #7 from brunom/master
Browse files Browse the repository at this point in the history
Don't grow file all at once
  • Loading branch information
0xbadfca11 authored Jun 13, 2020
2 parents 5a38f60 + 773fa4c commit def8294
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 def8294

Please sign in to comment.