From c4110780bf64a53ae01d8b8d5e752aa11f80de5a Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 5 Jun 2020 10:30:30 +0100 Subject: [PATCH] lib/file: fix SetSparse on Windows 7 which fixes downloads of files > 250MB Before this change we passed both lpOverlapped and lpBytesReturned as NULL. > If lpOverlapped is NULL, lpBytesReturned cannot be NULL. Even when > an operation produces no output data, and lpOutBuffer can be NULL, > the DeviceIoControl function makes use of the variable pointed to by > lpBytesReturned. After such an operation, the value of the variable > is without meaning. After this change we set lpBytesReturned to a valid pointer. See: https://forum.rclone.org/t/errors-when-downloading-any-file-over-250mb-from-google-drive-windows-sparse-files/16889 --- lib/file/preallocate_windows.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/file/preallocate_windows.go b/lib/file/preallocate_windows.go index f238c5c73..f92f9f7f7 100644 --- a/lib/file/preallocate_windows.go +++ b/lib/file/preallocate_windows.go @@ -92,7 +92,8 @@ const SetSparseImplemented = true // SetSparse makes the file be a sparse file func SetSparse(out *os.File) error { - err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), FSCTL_SET_SPARSE, nil, 0, nil, 0, nil, nil) + var bytesReturned uint32 + err := syscall.DeviceIoControl(syscall.Handle(out.Fd()), FSCTL_SET_SPARSE, nil, 0, nil, 0, &bytesReturned, nil) if err != nil { return errors.Wrap(err, "DeviceIoControl FSCTL_SET_SPARSE") }