Skip to content

Instantly share code, notes, and snippets.

@ayende
Created September 16, 2024 05:43
Show Gist options
  • Save ayende/68dcb097c0500785b18a14ab9afa69a1 to your computer and use it in GitHub Desktop.
Save ayende/68dcb097c0500785b18a14ab9afa69a1 to your computer and use it in GitHub Desktop.
HANDLE hFile = CreateFile("test.file",GENERIC_WRITE,
0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
);
DWORD temp;
DeviceIoControl(hFile, FSCTL_SET_SPARSE, NULL, 0,
NULL, 0, &temp, NULL);
LARGE_INTEGER li;
li.QuadPart = 128LL * 1024 * 1024 - 1;
SetFilePointerEx(hFile, li, NULL, FILE_BEGIN);
SetEndOfFile(hFile);
FILE_ZERO_DATA_INFORMATION zeroData;
zeroData.FileOffset.QuadPart = 16LL * 1024 * 1024;
zeroData.BeyondFinalZero.QuadPart = 32LL * 1024 * 1024;
DeviceIoControl(hFile, FSCTL_SET_ZERO_DATA, &zeroData,
sizeof(zeroData), NULL, 0, &temp, NULL);
CloseHandle(hFile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment