From 184aa4b5d07d5f3fcc15dd4bb0d4636fba734de3 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Wed, 20 May 2020 15:52:42 +0100 Subject: dd: fix handling of 'conv=notrunc seek=N' Commit e6680912a (dd: create a sparse file when seek=N is used) broke the use of 'conv=notrunc seek=N' to modify existing files. Rename seek_sparse() to make_sparse() and: - add an argument to specify the start of the sparse region; - call make_sparse() before ftruncate(); - call make_sparse() only if: * we can determine the size of the file; * the file is not open in append mode; * the file is being extended. This should fix GitHub issue #186. --- win32/mingw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'win32') diff --git a/win32/mingw.c b/win32/mingw.c index 7f8fecdc3..5c4c39b9d 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -1751,7 +1751,7 @@ void fix_path_case(char *path) } } -void seek_sparse(int fd, size_t size) +void make_sparse(int fd, off_t start, off_t end) { DWORD dwTemp; HANDLE fh; @@ -1762,8 +1762,8 @@ void seek_sparse(int fd, size_t size) DeviceIoControl(fh, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dwTemp, NULL); - fzdi.FileOffset.QuadPart = 0; - fzdi.BeyondFinalZero.QuadPart = size; + fzdi.FileOffset.QuadPart = start; + fzdi.BeyondFinalZero.QuadPart = end; DeviceIoControl(fh, FSCTL_SET_ZERO_DATA, &fzdi, sizeof(fzdi), NULL, 0, &dwTemp, NULL); } -- cgit v1.2.3-55-g6feb