-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0002-kernelbase-use-IOCTL_COPYCHUNK-in-CopyFile.mypatch
153 lines (143 loc) · 5.94 KB
/
0002-kernelbase-use-IOCTL_COPYCHUNK-in-CopyFile.mypatch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
From: "Alex Xu (Hello71)" <[email protected]>
Subject: [PATCH v3 2/5] kernelbase: use IOCTL_COPYCHUNK in CopyFile*
Message-Id: <[email protected]>
Date: Mon, 23 Aug 2021 11:56:50 -0400
In-Reply-To: <[email protected]>
References: <[email protected]>
---
dlls/kernelbase/file.c | 44 +++++++++++++++++-------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/dlls/kernelbase/file.c b/dlls/kernelbase/file.c
index d21ad299d1f..3c06f38fe57 100644
--- a/dlls/kernelbase/file.c
+++ b/dlls/kernelbase/file.c
@@ -497,29 +497,27 @@ BOOL WINAPI DECLSPEC_HOTPATCH AreFileApisANSI(void)
BOOL WINAPI CopyFileExW( const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUTINE progress,
void *param, BOOL *cancel_ptr, DWORD flags )
{
- static const int buffer_size = 65536;
HANDLE h1, h2;
FILE_NETWORK_OPEN_INFORMATION info;
FILE_BASIC_INFORMATION basic_info;
IO_STATUS_BLOCK io;
DWORD count;
BOOL ret = FALSE;
- char *buffer;
+ SRV_COPYCHUNK_COPY copychunk = {
+ .ChunkCount = 1,
+ .Chunk = { [0] = { .Length = 1UL<<30 } }
+ };
+ SRV_COPYCHUNK_RESPONSE copychunk_resp;
LARGE_INTEGER size;
LARGE_INTEGER transferred;
DWORD cbret;
DWORD source_access = GENERIC_READ;
if (!source || !dest)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
- if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
- {
- SetLastError( ERROR_NOT_ENOUGH_MEMORY );
- return FALSE;
- }
TRACE("%s -> %s, %x\n", debugstr_w(source), debugstr_w(dest), flags);
@@ -522,14 +520,12 @@ BOOL WINAPI CopyFileExW( const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUT
NULL, OPEN_EXISTING, 0, 0 )) == INVALID_HANDLE_VALUE)
{
WARN("Unable to open source %s\n", debugstr_w(source));
- HeapFree( GetProcessHeap(), 0, buffer );
return FALSE;
}
if (!set_ntstatus( NtQueryInformationFile( h1, &io, &info, sizeof(info), FileNetworkOpenInformation )))
{
WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source));
- HeapFree( GetProcessHeap(), 0, buffer );
CloseHandle( h1 );
return FALSE;
}
@@ -545,7 +541,6 @@ BOOL WINAPI CopyFileExW( const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUT
}
if (same_file)
{
- HeapFree( GetProcessHeap(), 0, buffer );
CloseHandle( h1 );
SetLastError( ERROR_SHARING_VIOLATION );
return FALSE;
@@ -557,7 +552,6 @@ BOOL WINAPI CopyFileExW( const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUT
info.FileAttributes, h1 )) == INVALID_HANDLE_VALUE)
{
WARN("Unable to open dest %s\n", debugstr_w(dest));
- HeapFree( GetProcessHeap(), 0, buffer );
CloseHandle( h1 );
return FALSE;
}
@@ -557,49 +552,48 @@ BOOL WINAPI CopyFileExW( const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUT
goto done;
}
}
- while (ReadFile( h1, buffer, buffer_size, &count, NULL ) && count)
+ /* wine extension: IOCTL_COPYCHUNK works even on local files */
+ ret = DeviceIoControl( h1, IOCTL_PREPARE_COPYCHUNK, NULL, 0,
+ ©chunk.SourceFile, sizeof(copychunk.SourceFile), &count, NULL );
+ if (ret)
{
- char *p = buffer;
- while (count != 0)
- {
- DWORD res;
- if (!WriteFile( h2, p, count, &res, NULL ) || !res) goto done;
- p += res;
- count -= res;
+ do {
+ ret = DeviceIoControl( h2, IOCTL_COPYCHUNK, ©chunk, sizeof(copychunk),
+ ©chunk_resp, sizeof(copychunk_resp), &count, NULL );
+ copychunk.Chunk[0].SourceOffset.QuadPart += copychunk_resp.TotalBytesWritten;
+ copychunk.Chunk[0].DestinationOffset.QuadPart += copychunk_resp.TotalBytesWritten;
if (progress)
{
- transferred.QuadPart += res;
+ transferred.QuadPart += copychunk_resp.TotalBytesWritten;
cbret = progress( size, transferred, size, transferred, 1,
CALLBACK_CHUNK_FINISHED, h1, h2, param );
if (cbret == PROGRESS_QUIET)
progress = NULL;
else if (cbret == PROGRESS_STOP)
{
SetLastError( ERROR_REQUEST_ABORTED );
goto done;
}
else if (cbret == PROGRESS_CANCEL)
{
BOOLEAN disp = TRUE;
SetFileInformationByHandle( h2, FileDispositionInfo, &disp, sizeof(disp) );
SetLastError( ERROR_REQUEST_ABORTED );
goto done;
}
}
- }
+ } while (ret && copychunk_resp.TotalBytesWritten);
+ /* Maintain the timestamp of source file to destination file */
+ basic_info.CreationTime = info.CreationTime;
+ basic_info.LastAccessTime = info.LastAccessTime;
+ basic_info.LastWriteTime = info.LastWriteTime;
+ basic_info.ChangeTime = info.ChangeTime;
+ basic_info.FileAttributes = 0;
+ NtSetInformationFile( h2, &io, &basic_info, sizeof(basic_info), FileBasicInformation );
}
- ret = TRUE;
done:
- /* Maintain the timestamp of source file to destination file */
- basic_info.CreationTime = info.CreationTime;
- basic_info.LastAccessTime = info.LastAccessTime;
- basic_info.LastWriteTime = info.LastWriteTime;
- basic_info.ChangeTime = info.ChangeTime;
- basic_info.FileAttributes = 0;
- NtSetInformationFile( h2, &io, &basic_info, sizeof(basic_info), FileBasicInformation );
- HeapFree( GetProcessHeap(), 0, buffer );
CloseHandle( h1 );
CloseHandle( h2 );
return ret;
--
2.33.0