diff options
author | Ron Yorston <rmy@pobox.com> | 2020-05-20 15:52:42 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2020-05-20 15:52:42 +0100 |
commit | 184aa4b5d07d5f3fcc15dd4bb0d4636fba734de3 (patch) | |
tree | e34649217179b033cbc2838df5302b74346caaad /win32/mingw.c | |
parent | 1d2a15e040b272155d3e40b597292a56de540e7d (diff) | |
download | busybox-w32-184aa4b5d07d5f3fcc15dd4bb0d4636fba734de3.tar.gz busybox-w32-184aa4b5d07d5f3fcc15dd4bb0d4636fba734de3.tar.bz2 busybox-w32-184aa4b5d07d5f3fcc15dd4bb0d4636fba734de3.zip |
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.
Diffstat (limited to 'win32/mingw.c')
-rw-r--r-- | win32/mingw.c | 6 |
1 files changed, 3 insertions, 3 deletions
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) | |||
1751 | } | 1751 | } |
1752 | } | 1752 | } |
1753 | 1753 | ||
1754 | void seek_sparse(int fd, size_t size) | 1754 | void make_sparse(int fd, off_t start, off_t end) |
1755 | { | 1755 | { |
1756 | DWORD dwTemp; | 1756 | DWORD dwTemp; |
1757 | HANDLE fh; | 1757 | HANDLE fh; |
@@ -1762,8 +1762,8 @@ void seek_sparse(int fd, size_t size) | |||
1762 | 1762 | ||
1763 | DeviceIoControl(fh, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dwTemp, NULL); | 1763 | DeviceIoControl(fh, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dwTemp, NULL); |
1764 | 1764 | ||
1765 | fzdi.FileOffset.QuadPart = 0; | 1765 | fzdi.FileOffset.QuadPart = start; |
1766 | fzdi.BeyondFinalZero.QuadPart = size; | 1766 | fzdi.BeyondFinalZero.QuadPart = end; |
1767 | DeviceIoControl(fh, FSCTL_SET_ZERO_DATA, &fzdi, sizeof(fzdi), | 1767 | DeviceIoControl(fh, FSCTL_SET_ZERO_DATA, &fzdi, sizeof(fzdi), |
1768 | NULL, 0, &dwTemp, NULL); | 1768 | NULL, 0, &dwTemp, NULL); |
1769 | } | 1769 | } |