Reputation: 185
Linux has fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, ...)
to punch a hole into a file, i.e. deallocate the blocks given and make the file a "sparse file".
But how can I do that with the Win32 API? Does anyone have an example for Win32, which is the Win equivalent to Linux fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, 1048576, 2097152);
?
Upvotes: 1
Views: 184
Reputation: 152
DWORD dwBytesReturned;
FILE_ZERO_DATA_INFORMATION FZDI;
FZDI.FileOffset.QuadPart = 1048576;
FZDI.BeyondFinalZero.QuadPart = 1048576 + 2097152;
int res = DeviceIoControl(hFile, FSCTL_SET_ZERO_DATA, &FZDI, sizeof(FZDI), NULL, 0, &dwBytesReturned, NULL);
Upvotes: 3