From e6680912a298dc2dee83f41837cb52160cf562d9 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 24 Mar 2020 16:37:13 +0000 Subject: dd: create a sparse file when seek=N is used When the seek=N argument is used mark the file as sparse and set the range that is sparse. See https://stackoverflow.com/questions/4011508/how-to-create-a-sparse-file-on-ntfs --- win32/mingw.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index 894388b64..7f8fecdc3 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1750,3 +1750,20 @@ void fix_path_case(char *path) } } } + +void seek_sparse(int fd, size_t size) +{ + DWORD dwTemp; + HANDLE fh; + FILE_ZERO_DATA_INFORMATION fzdi; + + if ((fh=(HANDLE)_get_osfhandle(fd)) == INVALID_HANDLE_VALUE) + return; + + DeviceIoControl(fh, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dwTemp, NULL); + + fzdi.FileOffset.QuadPart = 0; + fzdi.BeyondFinalZero.QuadPart = size; + DeviceIoControl(fh, FSCTL_SET_ZERO_DATA, &fzdi, sizeof(fzdi), + NULL, 0, &dwTemp, NULL); +} -- cgit v1.2.3-55-g6feb