Win32 fallocate(fd, FALLOC_FL_PUNCH_HOLE|FALLOC_FL_KEEP_SIZE, ...) API example?

139 Views Asked by At

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);?

1

There are 1 best solutions below

1
On BEST ANSWER
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);