You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DestinationMustMatchSourceSparseness flag not working, block-cloned file is always sparsed #17
If source file is NOT sparsed and CloneFlag.DestinationMustMatchSourceSparseness is set, block-cloned destination file should be NOT sparsed, however destination file is sparsed.
This Windows command can be used to check a file sparness: fsutil sparse queryflag C:\Temp\myfile.vhdx
To set the destination file as not sparsed a FILE_SET_SPARSE_BUFFER structure should be used, currently a bool[] value is used.
This sample code successfully sets a file as not sparsed. Tested on Windows 2016 1607 and Windows 10 21H2. The only variation with the code on CloneFileAsync method is the use of a FILE_SET_SPARSE_BUFFER struct.
var FILE_SET_SPARSE_BUFFER = new FILE_SET_SPARSE_BUFFER
{
SetSparse = false
};
if (!NativeMethods.DeviceIoControl(
destFileHandle,
NativeMethods.FSCTL_SET_SPARSE,
FILE_SET_SPARSE_BUFFER,
Marshal.SizeOf(FILE_SET_SPARSE_BUFFER),
null,
0,
ref numBytesReturned,
IntPtr.Zero))
{
int lastErr = Marshal.GetLastWin32Error();
NativeMethods.ThrowSpecificIoException(lastErr,
$"Failed to turn off file sparseness with winerror {lastErr} for destination file '{destination}'");
}
Activity
Fix issue with mismatched sparseness (#18)