[THEMES]
[reactos.git] / rostests / winetests / ntdll / file.c
1 /* Unit test suite for Ntdll file functions
2 *
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
5 * Copyright 2008 Jeff Zaroyko
6 * Copyright 2011 Dmitry Timoshkov
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 *
22 * NOTES
23 * We use function pointers here as there is no import library for NTDLL on
24 * windows.
25 */
26
27 #include <stdio.h>
28 #include <stdarg.h>
29
30 #include "ntstatus.h"
31 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
32 * definition errors when we get to winnt.h
33 */
34 #define WIN32_NO_STATUS
35
36 #include "wine/test.h"
37 #include "winternl.h"
38 #include "winuser.h"
39 #include "wine/winioctl.h"
40
41 #ifndef IO_COMPLETION_ALL_ACCESS
42 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
43 #endif
44
45 static BOOL (WINAPI * pGetVolumePathNameW)(LPCWSTR, LPWSTR, DWORD);
46 static UINT (WINAPI *pGetSystemWow64DirectoryW)( LPWSTR, UINT );
47
48 static VOID (WINAPI *pRtlFreeUnicodeString)( PUNICODE_STRING );
49 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
50 static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)( LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR* );
51 static NTSTATUS (WINAPI *pRtlWow64EnableFsRedirectionEx)( ULONG, ULONG * );
52
53 static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
54 ULONG, ULONG, ULONG, PLARGE_INTEGER );
55 static NTSTATUS (WINAPI *pNtCreateFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,PLARGE_INTEGER,ULONG,ULONG,ULONG,ULONG,PVOID,ULONG);
56 static NTSTATUS (WINAPI *pNtOpenFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,ULONG,ULONG);
57 static NTSTATUS (WINAPI *pNtDeleteFile)(POBJECT_ATTRIBUTES ObjectAttributes);
58 static NTSTATUS (WINAPI *pNtReadFile)(HANDLE hFile, HANDLE hEvent,
59 PIO_APC_ROUTINE apc, void* apc_user,
60 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
61 PLARGE_INTEGER offset, PULONG key);
62 static NTSTATUS (WINAPI *pNtWriteFile)(HANDLE hFile, HANDLE hEvent,
63 PIO_APC_ROUTINE apc, void* apc_user,
64 PIO_STATUS_BLOCK io_status,
65 const void* buffer, ULONG length,
66 PLARGE_INTEGER offset, PULONG key);
67 static NTSTATUS (WINAPI *pNtCancelIoFile)(HANDLE hFile, PIO_STATUS_BLOCK io_status);
68 static NTSTATUS (WINAPI *pNtCancelIoFileEx)(HANDLE hFile, PIO_STATUS_BLOCK iosb, PIO_STATUS_BLOCK io_status);
69 static NTSTATUS (WINAPI *pNtClose)( PHANDLE );
70
71 static NTSTATUS (WINAPI *pNtCreateIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG);
72 static NTSTATUS (WINAPI *pNtOpenIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
73 static NTSTATUS (WINAPI *pNtQueryIoCompletion)(HANDLE, IO_COMPLETION_INFORMATION_CLASS, PVOID, ULONG, PULONG);
74 static NTSTATUS (WINAPI *pNtRemoveIoCompletion)(HANDLE, PULONG_PTR, PULONG_PTR, PIO_STATUS_BLOCK, PLARGE_INTEGER);
75 static NTSTATUS (WINAPI *pNtSetIoCompletion)(HANDLE, ULONG_PTR, ULONG_PTR, NTSTATUS, SIZE_T);
76 static NTSTATUS (WINAPI *pNtSetInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
77 static NTSTATUS (WINAPI *pNtQueryInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
78 static NTSTATUS (WINAPI *pNtQueryDirectoryFile)(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,
79 PVOID,ULONG,FILE_INFORMATION_CLASS,BOOLEAN,PUNICODE_STRING,BOOLEAN);
80 static NTSTATUS (WINAPI *pNtQueryVolumeInformationFile)(HANDLE,PIO_STATUS_BLOCK,PVOID,ULONG,FS_INFORMATION_CLASS);
81
82 static inline BOOL is_signaled( HANDLE obj )
83 {
84 return WaitForSingleObject( obj, 0 ) == WAIT_OBJECT_0;
85 }
86
87 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
88 #define TEST_BUF_LEN 3
89
90 static BOOL create_pipe( HANDLE *read, HANDLE *write, ULONG flags, ULONG size )
91 {
92 *read = CreateNamedPipe(PIPENAME, PIPE_ACCESS_INBOUND | flags, PIPE_TYPE_BYTE | PIPE_WAIT,
93 1, size, size, NMPWAIT_USE_DEFAULT_WAIT, NULL);
94 ok(*read != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
95
96 *write = CreateFileA(PIPENAME, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
97 ok(*write != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError());
98
99 return TRUE;
100 }
101
102 static HANDLE create_temp_file( ULONG flags )
103 {
104 char path[MAX_PATH], buffer[MAX_PATH];
105 HANDLE handle;
106
107 GetTempPathA( MAX_PATH, path );
108 GetTempFileNameA( path, "foo", 0, buffer );
109 handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
110 flags | FILE_FLAG_DELETE_ON_CLOSE, 0);
111 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
112 return (handle == INVALID_HANDLE_VALUE) ? 0 : handle;
113 }
114
115 #define CVALUE_FIRST 0xfffabbcc
116 #define CKEY_FIRST 0x1030341
117 #define CKEY_SECOND 0x132E46
118
119 static ULONG_PTR completionKey;
120 static IO_STATUS_BLOCK ioSb;
121 static ULONG_PTR completionValue;
122
123 static ULONG get_pending_msgs(HANDLE h)
124 {
125 NTSTATUS res;
126 ULONG a, req;
127
128 res = pNtQueryIoCompletion( h, IoCompletionBasicInformation, &a, sizeof(a), &req );
129 ok( res == STATUS_SUCCESS, "NtQueryIoCompletion failed: %x\n", res );
130 if (res != STATUS_SUCCESS) return -1;
131 ok( req == sizeof(a), "Unexpected response size: %x\n", req );
132 return a;
133 }
134
135 static BOOL get_msg(HANDLE h)
136 {
137 LARGE_INTEGER timeout = {{-10000000*3}};
138 DWORD res = pNtRemoveIoCompletion( h, &completionKey, &completionValue, &ioSb, &timeout);
139 ok( res == STATUS_SUCCESS, "NtRemoveIoCompletion failed: %x\n", res );
140 if (res != STATUS_SUCCESS)
141 {
142 completionKey = completionValue = 0;
143 memset(&ioSb, 0, sizeof(ioSb));
144 return FALSE;
145 }
146 return TRUE;
147 }
148
149
150 static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved )
151 {
152 int *count = arg;
153
154 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
155 iosb, U(*iosb).Status, iosb->Information );
156 (*count)++;
157 ok( !reserved, "reserved is not 0: %x\n", reserved );
158 }
159
160 static void create_file_test(void)
161 {
162 static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t',
163 '\\','f','a','i','l','i','n','g',0};
164 static const WCHAR questionmarkInvalidNameW[] = {'a','f','i','l','e','?',0};
165 static const WCHAR pipeInvalidNameW[] = {'a','|','b',0};
166 NTSTATUS status;
167 HANDLE dir, file;
168 WCHAR path[MAX_PATH];
169 OBJECT_ATTRIBUTES attr;
170 IO_STATUS_BLOCK io;
171 UNICODE_STRING nameW;
172
173 GetCurrentDirectoryW( MAX_PATH, path );
174 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
175 attr.Length = sizeof(attr);
176 attr.RootDirectory = 0;
177 attr.ObjectName = &nameW;
178 attr.Attributes = OBJ_CASE_INSENSITIVE;
179 attr.SecurityDescriptor = NULL;
180 attr.SecurityQualityOfService = NULL;
181
182 /* try various open modes and options on directories */
183 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
184 FILE_OPEN, FILE_DIRECTORY_FILE, NULL, 0 );
185 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
186 CloseHandle( dir );
187
188 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
189 FILE_CREATE, FILE_DIRECTORY_FILE, NULL, 0 );
190 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
191 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
192
193 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
194 FILE_OPEN_IF, FILE_DIRECTORY_FILE, NULL, 0 );
195 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
196 CloseHandle( dir );
197
198 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
199 FILE_SUPERSEDE, FILE_DIRECTORY_FILE, NULL, 0 );
200 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
201
202 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
203 FILE_OVERWRITE, FILE_DIRECTORY_FILE, NULL, 0 );
204 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
205
206 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
207 FILE_OVERWRITE_IF, FILE_DIRECTORY_FILE, NULL, 0 );
208 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
209
210 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
211 FILE_OPEN, 0, NULL, 0 );
212 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
213 CloseHandle( dir );
214
215 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
216 FILE_CREATE, 0, NULL, 0 );
217 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
218 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
219
220 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
221 FILE_OPEN_IF, 0, NULL, 0 );
222 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
223 CloseHandle( dir );
224
225 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
226 FILE_SUPERSEDE, 0, NULL, 0 );
227 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
228 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
229
230 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
231 FILE_OVERWRITE, 0, NULL, 0 );
232 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
233 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
234
235 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
236 FILE_OVERWRITE_IF, 0, NULL, 0 );
237 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
238 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
239
240 pRtlFreeUnicodeString( &nameW );
241
242 pRtlInitUnicodeString( &nameW, systemrootW );
243 attr.Length = sizeof(attr);
244 attr.RootDirectory = NULL;
245 attr.ObjectName = &nameW;
246 attr.Attributes = OBJ_CASE_INSENSITIVE;
247 attr.SecurityDescriptor = NULL;
248 attr.SecurityQualityOfService = NULL;
249 dir = NULL;
250 status = pNtCreateFile( &dir, FILE_APPEND_DATA, &attr, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
251 FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
252 todo_wine
253 ok( status == STATUS_INVALID_PARAMETER,
254 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
255
256 /* Invalid chars in file/dirnames */
257 pRtlDosPathNameToNtPathName_U(questionmarkInvalidNameW, &nameW, NULL, NULL);
258 attr.ObjectName = &nameW;
259 status = pNtCreateFile(&dir, GENERIC_READ|SYNCHRONIZE, &attr, &io, NULL, 0,
260 FILE_SHARE_READ, FILE_CREATE,
261 FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
262 ok(status == STATUS_OBJECT_NAME_INVALID,
263 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
264
265 status = pNtCreateFile(&file, GENERIC_WRITE|SYNCHRONIZE, &attr, &io, NULL, 0,
266 0, FILE_CREATE,
267 FILE_NON_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
268 ok(status == STATUS_OBJECT_NAME_INVALID,
269 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
270
271 pRtlDosPathNameToNtPathName_U(pipeInvalidNameW, &nameW, NULL, NULL);
272 attr.ObjectName = &nameW;
273 status = pNtCreateFile(&dir, GENERIC_READ|SYNCHRONIZE, &attr, &io, NULL, 0,
274 FILE_SHARE_READ, FILE_CREATE,
275 FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
276 ok(status == STATUS_OBJECT_NAME_INVALID,
277 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
278
279 status = pNtCreateFile(&file, GENERIC_WRITE|SYNCHRONIZE, &attr, &io, NULL, 0,
280 0, FILE_CREATE,
281 FILE_NON_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
282 ok(status == STATUS_OBJECT_NAME_INVALID,
283 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
284 }
285
286 static void open_file_test(void)
287 {
288 NTSTATUS status;
289 HANDLE dir, root, handle;
290 WCHAR path[MAX_PATH];
291 BYTE data[1024];
292 OBJECT_ATTRIBUTES attr;
293 IO_STATUS_BLOCK io;
294 UNICODE_STRING nameW;
295 UINT i, len;
296 BOOL restart = TRUE;
297
298 len = GetWindowsDirectoryW( path, MAX_PATH );
299 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
300 attr.Length = sizeof(attr);
301 attr.RootDirectory = 0;
302 attr.ObjectName = &nameW;
303 attr.Attributes = OBJ_CASE_INSENSITIVE;
304 attr.SecurityDescriptor = NULL;
305 attr.SecurityQualityOfService = NULL;
306 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
307 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
308 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
309 pRtlFreeUnicodeString( &nameW );
310
311 path[3] = 0; /* root of the drive */
312 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
313 status = pNtOpenFile( &root, GENERIC_READ, &attr, &io,
314 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
315 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
316 pRtlFreeUnicodeString( &nameW );
317
318 /* test opening system dir with RootDirectory set to windows dir */
319 GetSystemDirectoryW( path, MAX_PATH );
320 while (path[len] == '\\') len++;
321 nameW.Buffer = path + len;
322 nameW.Length = lstrlenW(path + len) * sizeof(WCHAR);
323 attr.RootDirectory = dir;
324 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
325 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
326 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
327 CloseHandle( handle );
328
329 /* try uppercase name */
330 for (i = len; path[i]; i++) if (path[i] >= 'a' && path[i] <= 'z') path[i] -= 'a' - 'A';
331 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
332 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
333 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
334 CloseHandle( handle );
335
336 /* try with leading backslash */
337 nameW.Buffer--;
338 nameW.Length += sizeof(WCHAR);
339 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
340 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
341 ok( status == STATUS_INVALID_PARAMETER ||
342 status == STATUS_OBJECT_NAME_INVALID ||
343 status == STATUS_OBJECT_PATH_SYNTAX_BAD,
344 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
345 if (!status) CloseHandle( handle );
346
347 /* try with empty name */
348 nameW.Length = 0;
349 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
350 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
351 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
352 CloseHandle( handle );
353
354 /* try open by file id */
355
356 while (!pNtQueryDirectoryFile( dir, NULL, NULL, NULL, &io, data, sizeof(data),
357 FileIdBothDirectoryInformation, TRUE, NULL, restart ))
358 {
359 FILE_ID_BOTH_DIRECTORY_INFORMATION *info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)data;
360
361 restart = FALSE;
362
363 if (!info->FileId.QuadPart) continue;
364
365 nameW.Buffer = (WCHAR *)&info->FileId;
366 nameW.Length = sizeof(info->FileId);
367 info->FileName[info->FileNameLength/sizeof(WCHAR)] = 0;
368 attr.RootDirectory = dir;
369 /* We skip 'open' files by not specifying FILE_SHARE_WRITE */
370 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
371 FILE_SHARE_READ,
372 FILE_OPEN_BY_FILE_ID |
373 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
374 ok( status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED || status == STATUS_NOT_IMPLEMENTED || status == STATUS_SHARING_VIOLATION,
375 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
376 if (status == STATUS_NOT_IMPLEMENTED)
377 {
378 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
379 break;
380 }
381 if (status == STATUS_SHARING_VIOLATION)
382 trace( "%s is currently open\n", wine_dbgstr_w(info->FileName) );
383 if (!status)
384 {
385 BYTE buf[sizeof(FILE_ALL_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
386
387 if (!pNtQueryInformationFile( handle, &io, buf, sizeof(buf), FileAllInformation ))
388 {
389 FILE_ALL_INFORMATION *fai = (FILE_ALL_INFORMATION *)buf;
390
391 /* check that it's the same file/directory */
392
393 /* don't check the size for directories */
394 if (!(info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY))
395 ok( info->EndOfFile.QuadPart == fai->StandardInformation.EndOfFile.QuadPart,
396 "mismatched file size for %s\n", wine_dbgstr_w(info->FileName));
397
398 ok( info->CreationTime.QuadPart == fai->BasicInformation.CreationTime.QuadPart,
399 "mismatched creation time for %s\n", wine_dbgstr_w(info->FileName));
400 }
401 CloseHandle( handle );
402
403 /* try same thing from drive root */
404 attr.RootDirectory = root;
405 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
406 FILE_SHARE_READ|FILE_SHARE_WRITE,
407 FILE_OPEN_BY_FILE_ID |
408 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
409 ok( status == STATUS_SUCCESS || status == STATUS_NOT_IMPLEMENTED,
410 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
411 if (!status) CloseHandle( handle );
412 }
413 }
414
415 CloseHandle( dir );
416 CloseHandle( root );
417 }
418
419 static void delete_file_test(void)
420 {
421 NTSTATUS ret;
422 OBJECT_ATTRIBUTES attr;
423 UNICODE_STRING nameW;
424 WCHAR pathW[MAX_PATH];
425 WCHAR pathsubW[MAX_PATH];
426 static const WCHAR testdirW[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
427 static const WCHAR subdirW[] = {'\\','s','u','b',0};
428
429 ret = GetTempPathW(MAX_PATH, pathW);
430 if (!ret)
431 {
432 ok(0, "couldn't get temp dir\n");
433 return;
434 }
435 if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
436 {
437 ok(0, "MAX_PATH exceeded in constructing paths\n");
438 return;
439 }
440
441 lstrcatW(pathW, testdirW);
442 lstrcpyW(pathsubW, pathW);
443 lstrcatW(pathsubW, subdirW);
444
445 ret = CreateDirectoryW(pathW, NULL);
446 ok(ret == TRUE, "couldn't create directory ntdeletefile\n");
447 if (!pRtlDosPathNameToNtPathName_U(pathW, &nameW, NULL, NULL))
448 {
449 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
450 return;
451 }
452
453 attr.Length = sizeof(attr);
454 attr.RootDirectory = 0;
455 attr.Attributes = OBJ_CASE_INSENSITIVE;
456 attr.ObjectName = &nameW;
457 attr.SecurityDescriptor = NULL;
458 attr.SecurityQualityOfService = NULL;
459
460 /* test NtDeleteFile on an empty directory */
461 ret = pNtDeleteFile(&attr);
462 ok(ret == STATUS_SUCCESS, "NtDeleteFile should succeed in removing an empty directory\n");
463 ret = RemoveDirectoryW(pathW);
464 ok(ret == FALSE, "expected to fail removing directory, NtDeleteFile should have removed it\n");
465
466 /* test NtDeleteFile on a non-empty directory */
467 ret = CreateDirectoryW(pathW, NULL);
468 ok(ret == TRUE, "couldn't create directory ntdeletefile ?!\n");
469 ret = CreateDirectoryW(pathsubW, NULL);
470 ok(ret == TRUE, "couldn't create directory subdir\n");
471 ret = pNtDeleteFile(&attr);
472 ok(ret == STATUS_SUCCESS, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
473 ret = RemoveDirectoryW(pathsubW);
474 ok(ret == TRUE, "expected to remove directory ntdeletefile\\sub\n");
475 ret = RemoveDirectoryW(pathW);
476 ok(ret == TRUE, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
477
478 pRtlFreeUnicodeString( &nameW );
479 }
480
481 static void read_file_test(void)
482 {
483 const char text[] = "foobar";
484 HANDLE handle, read, write;
485 NTSTATUS status;
486 IO_STATUS_BLOCK iosb, iosb2;
487 DWORD written;
488 int apc_count = 0;
489 char buffer[128];
490 LARGE_INTEGER offset;
491 HANDLE event = CreateEventA( NULL, TRUE, FALSE, NULL );
492 BOOL ret;
493
494 buffer[0] = 1;
495
496 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
497
498 /* try read with no data */
499 U(iosb).Status = 0xdeadbabe;
500 iosb.Information = 0xdeadbeef;
501 ok( is_signaled( read ), "read handle is not signaled\n" );
502 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
503 ok( status == STATUS_PENDING, "wrong status %x\n", status );
504 ok( !is_signaled( read ), "read handle is signaled\n" );
505 ok( !is_signaled( event ), "event is signaled\n" );
506 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
507 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
508 ok( !apc_count, "apc was called\n" );
509 ret = WriteFile( write, buffer, 1, &written, NULL );
510 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
511 /* iosb updated here by async i/o */
512 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
513 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
514 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
515 ok( !is_signaled( read ), "read handle is signaled\n" );
516 ok( is_signaled( event ), "event is not signaled\n" );
517 ok( !apc_count, "apc was called\n" );
518 apc_count = 0;
519 SleepEx( 1, FALSE ); /* non-alertable sleep */
520 ok( !apc_count, "apc was called\n" );
521 SleepEx( 1, TRUE ); /* alertable sleep */
522 ok( apc_count == 1, "apc not called\n" );
523
524 /* with no event, the pipe handle itself gets signaled */
525 apc_count = 0;
526 U(iosb).Status = 0xdeadbabe;
527 iosb.Information = 0xdeadbeef;
528 ok( !is_signaled( read ), "read handle is not signaled\n" );
529 status = pNtReadFile( read, 0, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
530 ok( status == STATUS_PENDING, "wrong status %x\n", status );
531 ok( !is_signaled( read ), "read handle is signaled\n" );
532 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
533 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
534 ok( !apc_count, "apc was called\n" );
535 ret = WriteFile( write, buffer, 1, &written, NULL );
536 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
537 /* iosb updated here by async i/o */
538 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
539 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
540 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
541 ok( is_signaled( read ), "read handle is signaled\n" );
542 ok( !apc_count, "apc was called\n" );
543 apc_count = 0;
544 SleepEx( 1, FALSE ); /* non-alertable sleep */
545 ok( !apc_count, "apc was called\n" );
546 SleepEx( 1, TRUE ); /* alertable sleep */
547 ok( apc_count == 1, "apc not called\n" );
548
549 /* now read with data ready */
550 apc_count = 0;
551 U(iosb).Status = 0xdeadbabe;
552 iosb.Information = 0xdeadbeef;
553 ResetEvent( event );
554 ret = WriteFile( write, buffer, 1, &written, NULL );
555 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
556 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
557 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
558 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
559 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
560 ok( is_signaled( event ), "event is not signaled\n" );
561 ok( !apc_count, "apc was called\n" );
562 SleepEx( 1, FALSE ); /* non-alertable sleep */
563 ok( !apc_count, "apc was called\n" );
564 SleepEx( 1, TRUE ); /* alertable sleep */
565 ok( apc_count == 1, "apc not called\n" );
566
567 /* try read with no data */
568 apc_count = 0;
569 U(iosb).Status = 0xdeadbabe;
570 iosb.Information = 0xdeadbeef;
571 ok( is_signaled( event ), "event is not signaled\n" ); /* check that read resets the event */
572 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
573 ok( status == STATUS_PENDING, "wrong status %x\n", status );
574 ok( !is_signaled( event ), "event is signaled\n" );
575 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
576 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
577 ok( !apc_count, "apc was called\n" );
578 ret = WriteFile( write, buffer, 1, &written, NULL );
579 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
580 /* partial read is good enough */
581 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
582 ok( is_signaled( event ), "event is signaled\n" );
583 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
584 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
585 ok( !apc_count, "apc was called\n" );
586 SleepEx( 1, TRUE ); /* alertable sleep */
587 ok( apc_count == 1, "apc was not called\n" );
588
589 /* read from disconnected pipe */
590 apc_count = 0;
591 U(iosb).Status = 0xdeadbabe;
592 iosb.Information = 0xdeadbeef;
593 CloseHandle( write );
594 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
595 ok( status == STATUS_PIPE_BROKEN, "wrong status %x\n", status );
596 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
597 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
598 ok( !is_signaled( event ), "event is signaled\n" );
599 ok( !apc_count, "apc was called\n" );
600 SleepEx( 1, TRUE ); /* alertable sleep */
601 ok( !apc_count, "apc was called\n" );
602 CloseHandle( read );
603
604 /* read from closed handle */
605 apc_count = 0;
606 U(iosb).Status = 0xdeadbabe;
607 iosb.Information = 0xdeadbeef;
608 SetEvent( event );
609 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
610 ok( status == STATUS_INVALID_HANDLE, "wrong status %x\n", status );
611 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
612 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
613 ok( is_signaled( event ), "event is signaled\n" ); /* not reset on invalid handle */
614 ok( !apc_count, "apc was called\n" );
615 SleepEx( 1, TRUE ); /* alertable sleep */
616 ok( !apc_count, "apc was called\n" );
617
618 /* disconnect while async read is in progress */
619 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
620 apc_count = 0;
621 U(iosb).Status = 0xdeadbabe;
622 iosb.Information = 0xdeadbeef;
623 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
624 ok( status == STATUS_PENDING, "wrong status %x\n", status );
625 ok( !is_signaled( event ), "event is signaled\n" );
626 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
627 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
628 ok( !apc_count, "apc was called\n" );
629 CloseHandle( write );
630 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
631 ok( U(iosb).Status == STATUS_PIPE_BROKEN, "wrong status %x\n", U(iosb).Status );
632 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
633 ok( is_signaled( event ), "event is signaled\n" );
634 ok( !apc_count, "apc was called\n" );
635 SleepEx( 1, TRUE ); /* alertable sleep */
636 ok( apc_count == 1, "apc was not called\n" );
637 CloseHandle( read );
638
639 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
640 ret = DuplicateHandle(GetCurrentProcess(), read, GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS);
641 ok(ret, "Failed to duplicate handle: %d\n", GetLastError());
642
643 apc_count = 0;
644 U(iosb).Status = 0xdeadbabe;
645 iosb.Information = 0xdeadbeef;
646 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
647 ok( status == STATUS_PENDING, "wrong status %x\n", status );
648 ok( !is_signaled( event ), "event is signaled\n" );
649 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
650 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
651 ok( !apc_count, "apc was called\n" );
652 /* Cancel by other handle */
653 status = pNtCancelIoFile( read, &iosb2 );
654 ok(status == STATUS_SUCCESS, "failed to cancel by different handle: %x\n", status);
655 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
656 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
657 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
658 ok( is_signaled( event ), "event is signaled\n" );
659 todo_wine ok( !apc_count, "apc was called\n" );
660 SleepEx( 1, TRUE ); /* alertable sleep */
661 ok( apc_count == 1, "apc was not called\n" );
662
663 apc_count = 0;
664 U(iosb).Status = 0xdeadbabe;
665 iosb.Information = 0xdeadbeef;
666 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
667 ok( status == STATUS_PENDING, "wrong status %x\n", status );
668 ok( !is_signaled( event ), "event is signaled\n" );
669 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
670 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
671 ok( !apc_count, "apc was called\n" );
672 /* Close queued handle */
673 CloseHandle( read );
674 SleepEx( 1, TRUE ); /* alertable sleep */
675 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
676 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
677 status = pNtCancelIoFile( read, &iosb2 );
678 ok(status == STATUS_INVALID_HANDLE, "cancelled by closed handle?\n");
679 status = pNtCancelIoFile( handle, &iosb2 );
680 ok(status == STATUS_SUCCESS, "failed to cancel: %x\n", status);
681 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
682 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
683 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
684 ok( is_signaled( event ), "event is signaled\n" );
685 todo_wine ok( !apc_count, "apc was called\n" );
686 SleepEx( 1, TRUE ); /* alertable sleep */
687 ok( apc_count == 1, "apc was not called\n" );
688 CloseHandle( handle );
689 CloseHandle( write );
690
691 if (pNtCancelIoFileEx)
692 {
693 /* Basic Cancel Ex */
694 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
695
696 apc_count = 0;
697 U(iosb).Status = 0xdeadbabe;
698 iosb.Information = 0xdeadbeef;
699 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
700 ok( status == STATUS_PENDING, "wrong status %x\n", status );
701 ok( !is_signaled( event ), "event is signaled\n" );
702 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
703 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
704 ok( !apc_count, "apc was called\n" );
705 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
706 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
707 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
708 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
709 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
710 ok( is_signaled( event ), "event is signaled\n" );
711 todo_wine ok( !apc_count, "apc was called\n" );
712 SleepEx( 1, TRUE ); /* alertable sleep */
713 ok( apc_count == 1, "apc was not called\n" );
714
715 /* Duplicate iosb */
716 apc_count = 0;
717 U(iosb).Status = 0xdeadbabe;
718 iosb.Information = 0xdeadbeef;
719 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
720 ok( status == STATUS_PENDING, "wrong status %x\n", status );
721 ok( !is_signaled( event ), "event is signaled\n" );
722 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
723 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
724 ok( !apc_count, "apc was called\n" );
725 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
726 ok( status == STATUS_PENDING, "wrong status %x\n", status );
727 ok( !is_signaled( event ), "event is signaled\n" );
728 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
729 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
730 ok( !apc_count, "apc was called\n" );
731 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
732 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
733 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
734 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
735 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
736 ok( is_signaled( event ), "event is signaled\n" );
737 todo_wine ok( !apc_count, "apc was called\n" );
738 SleepEx( 1, TRUE ); /* alertable sleep */
739 ok( apc_count == 2, "apc was not called\n" );
740
741 CloseHandle( read );
742 CloseHandle( write );
743 }
744
745 /* now try a real file */
746 if (!(handle = create_temp_file( FILE_FLAG_OVERLAPPED ))) return;
747 apc_count = 0;
748 U(iosb).Status = 0xdeadbabe;
749 iosb.Information = 0xdeadbeef;
750 offset.QuadPart = 0;
751 ResetEvent( event );
752 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
753 ok( status == STATUS_SUCCESS || status == STATUS_PENDING, "wrong status %x\n", status );
754 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
755 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
756 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
757 ok( is_signaled( event ), "event is signaled\n" );
758 ok( !apc_count, "apc was called\n" );
759 SleepEx( 1, TRUE ); /* alertable sleep */
760 ok( apc_count == 1, "apc was not called\n" );
761
762 apc_count = 0;
763 U(iosb).Status = 0xdeadbabe;
764 iosb.Information = 0xdeadbeef;
765 offset.QuadPart = 0;
766 ResetEvent( event );
767 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
768 ok( status == STATUS_SUCCESS ||
769 status == STATUS_PENDING, /* vista */
770 "wrong status %x\n", status );
771 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
772 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
773 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
774 ok( is_signaled( event ), "event is signaled\n" );
775 ok( !apc_count, "apc was called\n" );
776 SleepEx( 1, TRUE ); /* alertable sleep */
777 ok( apc_count == 1, "apc was not called\n" );
778
779 /* read beyond eof */
780 apc_count = 0;
781 U(iosb).Status = 0xdeadbabe;
782 iosb.Information = 0xdeadbeef;
783 offset.QuadPart = strlen(text) + 2;
784 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
785 todo_wine
786 ok(status == STATUS_PENDING || broken(status == STATUS_END_OF_FILE) /* before Vista */, "expected STATUS_PENDING, got %#x\n", status);
787 if (status == STATUS_PENDING) /* vista */
788 {
789 WaitForSingleObject( event, 1000 );
790 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
791 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
792 ok( is_signaled( event ), "event is signaled\n" );
793 ok( !apc_count, "apc was called\n" );
794 SleepEx( 1, TRUE ); /* alertable sleep */
795 ok( apc_count == 1, "apc was not called\n" );
796 }
797 CloseHandle( handle );
798
799 /* now a non-overlapped file */
800 if (!(handle = create_temp_file(0))) return;
801 apc_count = 0;
802 U(iosb).Status = 0xdeadbabe;
803 iosb.Information = 0xdeadbeef;
804 offset.QuadPart = 0;
805 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
806 ok( status == STATUS_END_OF_FILE ||
807 status == STATUS_SUCCESS ||
808 status == STATUS_PENDING, /* vista */
809 "wrong status %x\n", status );
810 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
811 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
812 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
813 ok( is_signaled( event ), "event is signaled\n" );
814 ok( !apc_count, "apc was called\n" );
815 SleepEx( 1, TRUE ); /* alertable sleep */
816 ok( apc_count == 1, "apc was not called\n" );
817
818 apc_count = 0;
819 U(iosb).Status = 0xdeadbabe;
820 iosb.Information = 0xdeadbeef;
821 offset.QuadPart = 0;
822 ResetEvent( event );
823 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
824 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
825 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
826 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
827 ok( is_signaled( event ), "event is signaled\n" );
828 ok( !apc_count, "apc was called\n" );
829 SleepEx( 1, TRUE ); /* alertable sleep */
830 todo_wine ok( !apc_count, "apc was called\n" );
831
832 /* read beyond eof */
833 apc_count = 0;
834 U(iosb).Status = 0xdeadbabe;
835 iosb.Information = 0xdeadbeef;
836 offset.QuadPart = strlen(text) + 2;
837 ResetEvent( event );
838 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
839 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
840 todo_wine ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
841 todo_wine ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
842 todo_wine ok( is_signaled( event ), "event is not signaled\n" );
843 ok( !apc_count, "apc was called\n" );
844 SleepEx( 1, TRUE ); /* alertable sleep */
845 ok( !apc_count, "apc was called\n" );
846
847 CloseHandle( handle );
848
849 CloseHandle( event );
850 }
851
852 static void append_file_test(void)
853 {
854 const char text[] = "foobar";
855 HANDLE handle;
856 NTSTATUS status;
857 IO_STATUS_BLOCK iosb;
858 DWORD written;
859 char path[MAX_PATH], buffer[MAX_PATH];
860
861 GetTempPathA( MAX_PATH, path );
862 GetTempFileNameA( path, "foo", 0, buffer );
863 /* It is possible to open a file with only FILE_APPEND_DATA access flags.
864 It matches the O_WRONLY|O_APPEND open() posix behavior */
865 handle = CreateFileA(buffer, FILE_APPEND_DATA, 0, NULL, CREATE_ALWAYS,
866 FILE_FLAG_DELETE_ON_CLOSE, 0);
867 ok( handle != INVALID_HANDLE_VALUE, "Failed to create a temp file in FILE_APPEND_DATA mode.\n" );
868 if(handle == INVALID_HANDLE_VALUE)
869 {
870 skip("Couldn't create a temporary file, skipping FILE_APPEND_DATA test\n");
871 return;
872 }
873
874 U(iosb).Status = STATUS_PENDING;
875 iosb.Information = 0;
876
877 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb,
878 text, sizeof(text), NULL, NULL);
879
880 if (status == STATUS_PENDING)
881 {
882 WaitForSingleObject( handle, 1000 );
883 status = U(iosb).Status;
884 }
885 written = iosb.Information;
886
887 todo_wine
888 ok(status == STATUS_SUCCESS && written == sizeof(text), "FILE_APPEND_DATA NtWriteFile failed\n");
889
890 CloseHandle(handle);
891 }
892
893 static void nt_mailslot_test(void)
894 {
895 HANDLE hslot;
896 ACCESS_MASK DesiredAccess;
897 OBJECT_ATTRIBUTES attr;
898
899 ULONG CreateOptions;
900 ULONG MailslotQuota;
901 ULONG MaxMessageSize;
902 LARGE_INTEGER TimeOut;
903 IO_STATUS_BLOCK IoStatusBlock;
904 NTSTATUS rc;
905 UNICODE_STRING str;
906 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
907 'R',':','\\','F','R','E','D','\0' };
908
909 TimeOut.QuadPart = -1;
910
911 pRtlInitUnicodeString(&str, buffer1);
912 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
913 CreateOptions = MailslotQuota = MaxMessageSize = 0;
914 DesiredAccess = GENERIC_READ;
915
916 /*
917 * Check for NULL pointer handling
918 */
919 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
920 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
921 &TimeOut);
922 ok( rc == STATUS_ACCESS_VIOLATION ||
923 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
924 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
925
926 /*
927 * Test to see if the Timeout can be NULL
928 */
929 hslot = (HANDLE)0xdeadbeef;
930 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
931 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
932 NULL);
933 ok( rc == STATUS_SUCCESS ||
934 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
935 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
936 ok( hslot != 0, "Handle is invalid\n");
937
938 if ( rc == STATUS_SUCCESS ) pNtClose(hslot);
939
940 /*
941 * Test that the length field is checked properly
942 */
943 attr.Length = 0;
944 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
945 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
946 &TimeOut);
947 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
948
949 if (rc == STATUS_SUCCESS) pNtClose(hslot);
950
951 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
952 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
953 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
954 &TimeOut);
955 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
956
957 if (rc == STATUS_SUCCESS) pNtClose(hslot);
958
959 /*
960 * Test handling of a NULL unicode string in ObjectName
961 */
962 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
963 attr.ObjectName = NULL;
964 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
965 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
966 &TimeOut);
967 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
968 rc == STATUS_INVALID_PARAMETER,
969 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
970
971 if (rc == STATUS_SUCCESS) pNtClose(hslot);
972
973 /*
974 * Test a valid call
975 */
976 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
977 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
978 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
979 &TimeOut);
980 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
981 ok( hslot != 0, "Handle is invalid\n");
982
983 rc = pNtClose(hslot);
984 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
985 }
986
987 static void test_iocp_setcompletion(HANDLE h)
988 {
989 NTSTATUS res;
990 ULONG count;
991 SIZE_T size = 3;
992
993 if (sizeof(size) > 4) size |= (ULONGLONG)0x12345678 << 32;
994
995 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, size );
996 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
997
998 count = get_pending_msgs(h);
999 ok( count == 1, "Unexpected msg count: %d\n", count );
1000
1001 if (get_msg(h))
1002 {
1003 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
1004 ok( ioSb.Information == size, "Invalid ioSb.Information: %lu\n", ioSb.Information );
1005 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1006 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
1007 }
1008
1009 count = get_pending_msgs(h);
1010 ok( !count, "Unexpected msg count: %d\n", count );
1011 }
1012
1013 static void test_iocp_fileio(HANDLE h)
1014 {
1015 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
1016
1017 IO_STATUS_BLOCK iosb;
1018 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
1019 HANDLE hPipeSrv, hPipeClt;
1020 NTSTATUS res;
1021
1022 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1023 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1024 if (hPipeSrv != INVALID_HANDLE_VALUE )
1025 {
1026 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1027 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1028 if (hPipeClt != INVALID_HANDLE_VALUE)
1029 {
1030 U(iosb).Status = 0xdeadbeef;
1031 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1032 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
1033 ok( U(iosb).Status == STATUS_INVALID_PARAMETER /* 98 */ || U(iosb).Status == 0xdeadbeef /* NT4+ */,
1034 "Unexpected iosb.Status on non-overlapped handle: %x\n", U(iosb).Status );
1035 CloseHandle(hPipeClt);
1036 }
1037 CloseHandle( hPipeSrv );
1038 }
1039
1040 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1041 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1042 if (hPipeSrv == INVALID_HANDLE_VALUE )
1043 return;
1044
1045 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1046 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1047 if (hPipeClt != INVALID_HANDLE_VALUE)
1048 {
1049 OVERLAPPED o = {0,};
1050 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
1051 DWORD read;
1052 long count;
1053
1054 U(iosb).Status = 0xdeadbeef;
1055 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1056 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
1057 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
1058
1059 memset( send_buf, 0, TEST_BUF_LEN );
1060 memset( recv_buf, 0xde, TEST_BUF_LEN );
1061 count = get_pending_msgs(h);
1062 ok( !count, "Unexpected msg count: %ld\n", count );
1063 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1064 count = get_pending_msgs(h);
1065 ok( !count, "Unexpected msg count: %ld\n", count );
1066 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
1067
1068 if (get_msg(h))
1069 {
1070 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1071 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1072 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1073 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1074 ok( !memcmp( send_buf, recv_buf, TEST_BUF_LEN ), "Receive buffer (%x %x %x) did not match send buffer (%x %x %x)\n", recv_buf[0], recv_buf[1], recv_buf[2], send_buf[0], send_buf[1], send_buf[2] );
1075 }
1076 count = get_pending_msgs(h);
1077 ok( !count, "Unexpected msg count: %ld\n", count );
1078
1079 memset( send_buf, 0, TEST_BUF_LEN );
1080 memset( recv_buf, 0xde, TEST_BUF_LEN );
1081 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
1082 count = get_pending_msgs(h);
1083 ok( !count, "Unexpected msg count: %ld\n", count );
1084 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
1085 count = get_pending_msgs(h);
1086 ok( count == 1, "Unexpected msg count: %ld\n", count );
1087 if (get_msg(h))
1088 {
1089 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1090 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1091 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1092 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1093 ok( !memcmp( send_buf, recv_buf, 2 ), "Receive buffer (%x %x) did not match send buffer (%x %x)\n", recv_buf[0], recv_buf[1], send_buf[0], send_buf[1] );
1094 }
1095
1096 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1097 CloseHandle( hPipeSrv );
1098 count = get_pending_msgs(h);
1099 ok( count == 1, "Unexpected msg count: %ld\n", count );
1100 if (get_msg(h))
1101 {
1102 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1103 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1104 /* wine sends wrong status here */
1105 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1106 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1107 }
1108 }
1109
1110 CloseHandle( hPipeClt );
1111
1112 /* test associating a completion port with a handle after an async is queued */
1113 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1114 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1115 if (hPipeSrv == INVALID_HANDLE_VALUE )
1116 return;
1117 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1118 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1119 if (hPipeClt != INVALID_HANDLE_VALUE)
1120 {
1121 OVERLAPPED o = {0,};
1122 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
1123 DWORD read;
1124 long count;
1125
1126 memset( send_buf, 0, TEST_BUF_LEN );
1127 memset( recv_buf, 0xde, TEST_BUF_LEN );
1128 count = get_pending_msgs(h);
1129 ok( !count, "Unexpected msg count: %ld\n", count );
1130 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1131
1132 U(iosb).Status = 0xdeadbeef;
1133 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1134 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
1135 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
1136 count = get_pending_msgs(h);
1137 ok( !count, "Unexpected msg count: %ld\n", count );
1138
1139 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
1140
1141 if (get_msg(h))
1142 {
1143 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1144 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1145 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1146 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1147 ok( !memcmp( send_buf, recv_buf, TEST_BUF_LEN ), "Receive buffer (%x %x %x) did not match send buffer (%x %x %x)\n", recv_buf[0], recv_buf[1], recv_buf[2], send_buf[0], send_buf[1], send_buf[2] );
1148 }
1149 count = get_pending_msgs(h);
1150 ok( !count, "Unexpected msg count: %ld\n", count );
1151 }
1152
1153 CloseHandle( hPipeSrv );
1154 CloseHandle( hPipeClt );
1155 }
1156
1157 static void test_file_basic_information(void)
1158 {
1159 IO_STATUS_BLOCK io;
1160 FILE_BASIC_INFORMATION fbi;
1161 HANDLE h;
1162 int res;
1163 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1164
1165 if (!(h = create_temp_file(0))) return;
1166
1167 /* Check default first */
1168 memset(&fbi, 0, sizeof(fbi));
1169 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1170 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1171 ok ( (fbi.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1172 "attribute %x not expected\n", fbi.FileAttributes );
1173
1174 /* Then SYSTEM */
1175 /* Clear fbi to avoid setting times */
1176 memset(&fbi, 0, sizeof(fbi));
1177 fbi.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1178 U(io).Status = 0xdeadbeef;
1179 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1180 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1181 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1182
1183 memset(&fbi, 0, sizeof(fbi));
1184 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1185 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1186 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi.FileAttributes );
1187
1188 /* Then HIDDEN */
1189 memset(&fbi, 0, sizeof(fbi));
1190 fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1191 U(io).Status = 0xdeadbeef;
1192 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1193 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1194 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1195
1196 memset(&fbi, 0, sizeof(fbi));
1197 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1198 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1199 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi.FileAttributes );
1200
1201 /* Check NORMAL last of all (to make sure we can clear attributes) */
1202 memset(&fbi, 0, sizeof(fbi));
1203 fbi.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1204 U(io).Status = 0xdeadbeef;
1205 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1206 ok ( res == STATUS_SUCCESS, "can't set normal attribute, NtSetInformationFile returned %x\n", res );
1207 ok ( U(io).Status == STATUS_SUCCESS, "can't set normal attribute, io.Status is %x\n", U(io).Status );
1208
1209 memset(&fbi, 0, sizeof(fbi));
1210 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1211 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1212 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not 0\n", fbi.FileAttributes );
1213
1214 CloseHandle( h );
1215 }
1216
1217 static void test_file_all_information(void)
1218 {
1219 IO_STATUS_BLOCK io;
1220 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1221 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1222 * don't leave enough room there.
1223 */
1224 struct {
1225 FILE_ALL_INFORMATION fai;
1226 WCHAR buf[256];
1227 } fai_buf;
1228 HANDLE h;
1229 int res;
1230 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1231
1232 if (!(h = create_temp_file(0))) return;
1233
1234 /* Check default first */
1235 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1236 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1237 ok ( (fai_buf.fai.BasicInformation.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1238 "attribute %x not expected\n", fai_buf.fai.BasicInformation.FileAttributes );
1239
1240 /* Then SYSTEM */
1241 /* Clear fbi to avoid setting times */
1242 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1243 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1244 U(io).Status = 0xdeadbeef;
1245 res = pNtSetInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1246 ok ( res == STATUS_INVALID_INFO_CLASS || broken(res == STATUS_NOT_IMPLEMENTED), "shouldn't be able to set FileAllInformation, res %x\n", res);
1247 todo_wine ok ( U(io).Status == 0xdeadbeef, "shouldn't be able to set FileAllInformation, io.Status is %x\n", U(io).Status);
1248 U(io).Status = 0xdeadbeef;
1249 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1250 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1251 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1252
1253 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1254 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1255 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1256 todo_wine ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fai_buf.fai.BasicInformation.FileAttributes );
1257
1258 /* Then HIDDEN */
1259 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1260 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1261 U(io).Status = 0xdeadbeef;
1262 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1263 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1264 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1265
1266 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1267 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1268 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1269 todo_wine ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fai_buf.fai.BasicInformation.FileAttributes );
1270
1271 /* Check NORMAL last of all (to make sure we can clear attributes) */
1272 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1273 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1274 U(io).Status = 0xdeadbeef;
1275 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1276 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1277 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1278
1279 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1280 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1281 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1282 todo_wine ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not FILE_ATTRIBUTE_NORMAL\n", fai_buf.fai.BasicInformation.FileAttributes );
1283
1284 CloseHandle( h );
1285 }
1286
1287 static void test_file_both_information(void)
1288 {
1289 IO_STATUS_BLOCK io;
1290 FILE_BOTH_DIR_INFORMATION fbi;
1291 HANDLE h;
1292 int res;
1293
1294 if (!(h = create_temp_file(0))) return;
1295
1296 memset(&fbi, 0, sizeof(fbi));
1297 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBothDirectoryInformation);
1298 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res);
1299
1300 CloseHandle( h );
1301 }
1302
1303 static void test_file_disposition_information(void)
1304 {
1305 char buffer[MAX_PATH + 16];
1306 DWORD dirpos;
1307 HANDLE handle, handle2;
1308 NTSTATUS res;
1309 IO_STATUS_BLOCK io;
1310 FILE_DISPOSITION_INFORMATION fdi;
1311 BOOL fileDeleted;
1312
1313 /* cannot set disposition on file not opened with delete access */
1314 GetTempFileNameA( ".", "dis", 0, buffer );
1315 handle = CreateFileA(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
1316 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1317 res = pNtQueryInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1318 ok( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "Unexpected NtQueryInformationFile result (expected STATUS_INVALID_INFO_CLASS, got %x)\n", res );
1319 fdi.DoDeleteFile = TRUE;
1320 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1321 todo_wine
1322 ok( res == STATUS_ACCESS_DENIED, "unexpected FileDispositionInformation result (expected STATUS_ACCESS_DENIED, got %x)\n", res );
1323 CloseHandle( handle );
1324 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1325 ok( !fileDeleted, "File shouldn't have been deleted\n" );
1326 DeleteFileA( buffer );
1327
1328 /* can set disposition on file opened with proper access */
1329 GetTempFileNameA( ".", "dis", 0, buffer );
1330 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
1331 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1332 fdi.DoDeleteFile = TRUE;
1333 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1334 todo_wine
1335 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1336 CloseHandle( handle );
1337 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1338 todo_wine
1339 ok( fileDeleted, "File should have been deleted\n" );
1340 DeleteFileA( buffer );
1341
1342 /* cannot set disposition on readonly file */
1343 GetTempFileNameA( ".", "dis", 0, buffer );
1344 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_READONLY, 0);
1345 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1346 fdi.DoDeleteFile = TRUE;
1347 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1348 todo_wine
1349 ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
1350 CloseHandle( handle );
1351 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1352 ok( !fileDeleted, "File shouldn't have been deleted\n" );
1353 SetFileAttributesA( buffer, FILE_ATTRIBUTE_NORMAL );
1354 DeleteFileA( buffer );
1355
1356 /* can set disposition on file and then reset it */
1357 GetTempFileNameA( ".", "dis", 0, buffer );
1358 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
1359 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1360 fdi.DoDeleteFile = TRUE;
1361 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1362 todo_wine
1363 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1364 fdi.DoDeleteFile = FALSE;
1365 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1366 todo_wine
1367 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1368 CloseHandle( handle );
1369 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1370 ok( !fileDeleted, "File shouldn't have been deleted\n" );
1371 DeleteFileA( buffer );
1372
1373 /* Delete-on-close flag doesn't change file disposition until a handle is closed */
1374 GetTempFileNameA( ".", "dis", 0, buffer );
1375 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0);
1376 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1377 fdi.DoDeleteFile = FALSE;
1378 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1379 todo_wine
1380 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1381 CloseHandle( handle );
1382 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1383 ok( fileDeleted, "File should have been deleted\n" );
1384 DeleteFileA( buffer );
1385
1386 /* Delete-on-close flag sets disposition when a handle is closed and then it could be changed back */
1387 GetTempFileNameA( ".", "dis", 0, buffer );
1388 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0);
1389 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1390 ok( DuplicateHandle( GetCurrentProcess(), handle, GetCurrentProcess(), &handle2, 0, FALSE, DUPLICATE_SAME_ACCESS ), "DuplicateHandle failed\n" );
1391 CloseHandle( handle );
1392 fdi.DoDeleteFile = FALSE;
1393 res = pNtSetInformationFile( handle2, &io, &fdi, sizeof fdi, FileDispositionInformation );
1394 todo_wine
1395 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1396 CloseHandle( handle2 );
1397 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1398 ok( fileDeleted, "File should have been deleted\n" );
1399 DeleteFileA( buffer );
1400
1401 /* can set disposition on a directory opened with proper access */
1402 GetTempFileNameA( ".", "dis", 0, buffer );
1403 DeleteFileA( buffer );
1404 ok( CreateDirectoryA( buffer, NULL ), "CreateDirectory failed\n" );
1405 handle = CreateFileA(buffer, DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
1406 ok( handle != INVALID_HANDLE_VALUE, "failed to open a directory\n" );
1407 fdi.DoDeleteFile = TRUE;
1408 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1409 todo_wine
1410 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1411 CloseHandle( handle );
1412 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1413 todo_wine
1414 ok( fileDeleted, "Directory should have been deleted\n" );
1415 RemoveDirectoryA( buffer );
1416
1417 /* RemoveDirectory sets directory disposition and it can be undone */
1418 GetTempFileNameA( ".", "dis", 0, buffer );
1419 DeleteFileA( buffer );
1420 ok( CreateDirectoryA( buffer, NULL ), "CreateDirectory failed\n" );
1421 handle = CreateFileA(buffer, DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
1422 ok( handle != INVALID_HANDLE_VALUE, "failed to open a directory\n" );
1423 RemoveDirectoryA( buffer );
1424 fdi.DoDeleteFile = FALSE;
1425 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1426 todo_wine
1427 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1428 CloseHandle( handle );
1429 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1430 ok( !fileDeleted, "Directory shouldn't have been deleted\n" );
1431 RemoveDirectoryA( buffer );
1432
1433 /* cannot set disposition on a non-empty directory */
1434 GetTempFileNameA( ".", "dis", 0, buffer );
1435 DeleteFileA( buffer );
1436 ok( CreateDirectoryA( buffer, NULL ), "CreateDirectory failed\n" );
1437 handle = CreateFileA(buffer, DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
1438 ok( handle != INVALID_HANDLE_VALUE, "failed to open a directory\n" );
1439 dirpos = lstrlenA( buffer );
1440 lstrcpyA( buffer + dirpos, "\\tst" );
1441 handle2 = CreateFileA(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
1442 CloseHandle( handle2 );
1443 fdi.DoDeleteFile = TRUE;
1444 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1445 todo_wine
1446 ok( res == STATUS_DIRECTORY_NOT_EMPTY, "unexpected FileDispositionInformation result (expected STATUS_DIRECTORY_NOT_EMPTY, got %x)\n", res );
1447 DeleteFileA( buffer );
1448 buffer[dirpos] = '\0';
1449 CloseHandle( handle );
1450 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1451 ok( !fileDeleted, "Directory shouldn't have been deleted\n" );
1452 RemoveDirectoryA( buffer );
1453 }
1454
1455 static void test_iocompletion(void)
1456 {
1457 HANDLE h = INVALID_HANDLE_VALUE;
1458 NTSTATUS res;
1459
1460 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
1461
1462 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
1463 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
1464
1465 if ( h && h != INVALID_HANDLE_VALUE)
1466 {
1467 test_iocp_setcompletion(h);
1468 test_iocp_fileio(h);
1469 pNtClose(h);
1470 }
1471 }
1472
1473 static void test_file_name_information(void)
1474 {
1475 WCHAR *file_name, *volume_prefix, *expected;
1476 FILE_NAME_INFORMATION *info;
1477 ULONG old_redir = 1, tmp;
1478 UINT file_name_size;
1479 IO_STATUS_BLOCK io;
1480 UINT info_size;
1481 HRESULT hr;
1482 HANDLE h;
1483 UINT len;
1484
1485 /* GetVolumePathName is not present before w2k */
1486 if (!pGetVolumePathNameW) {
1487 win_skip("GetVolumePathNameW not found\n");
1488 return;
1489 }
1490
1491 file_name_size = GetSystemDirectoryW( NULL, 0 );
1492 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1493 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1494 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1495
1496 len = GetSystemDirectoryW( file_name, file_name_size );
1497 ok(len == file_name_size - 1,
1498 "GetSystemDirectoryW returned %u, expected %u.\n",
1499 len, file_name_size - 1);
1500
1501 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1502 ok(len, "GetVolumePathNameW failed.\n");
1503
1504 len = lstrlenW( volume_prefix );
1505 if (len && volume_prefix[len - 1] == '\\') --len;
1506 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1507 expected[file_name_size - len - 1] = '\0';
1508
1509 /* A bit more than we actually need, but it keeps the calculation simple. */
1510 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1511 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1512
1513 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1514 h = CreateFileW( file_name, GENERIC_READ,
1515 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1516 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1517 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1518 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1519
1520 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileNameInformation );
1521 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x.\n", hr);
1522
1523 memset( info, 0xcc, info_size );
1524 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileNameInformation );
1525 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1526 hr, STATUS_BUFFER_OVERFLOW);
1527 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1528 U(io).Status, STATUS_BUFFER_OVERFLOW);
1529 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1530 ok(info->FileName[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info->FileName[2]);
1531 ok(CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1532 "info->FileName[1] is %p, expected %p.\n",
1533 CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1534 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1535
1536 memset( info, 0xcc, info_size );
1537 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1538 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1539 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1540 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1541 ok(info->FileName[info->FileNameLength / sizeof(WCHAR)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1542 info->FileName[info->FileNameLength / sizeof(WCHAR)]);
1543 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1544 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1545 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1546 ok(io.Information == FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength,
1547 "io.Information is %lu, expected %u.\n",
1548 io.Information, FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength);
1549
1550 CloseHandle( h );
1551 HeapFree( GetProcessHeap(), 0, info );
1552 HeapFree( GetProcessHeap(), 0, expected );
1553 HeapFree( GetProcessHeap(), 0, volume_prefix );
1554
1555 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1556 {
1557 skip("Not running on WoW64, skipping test.\n");
1558 HeapFree( GetProcessHeap(), 0, file_name );
1559 return;
1560 }
1561
1562 h = CreateFileW( file_name, GENERIC_READ,
1563 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1564 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1565 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1566 HeapFree( GetProcessHeap(), 0, file_name );
1567
1568 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1569 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1570 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1571
1572 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1573 ok(len == file_name_size - 1,
1574 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1575 len, file_name_size - 1);
1576
1577 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1578 ok(len, "GetVolumePathNameW failed.\n");
1579
1580 len = lstrlenW( volume_prefix );
1581 if (len && volume_prefix[len - 1] == '\\') --len;
1582 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1583 expected[file_name_size - len - 1] = '\0';
1584
1585 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1586 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1587
1588 memset( info, 0xcc, info_size );
1589 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1590 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1591 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1592 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1593 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1594
1595 CloseHandle( h );
1596 HeapFree( GetProcessHeap(), 0, info );
1597 HeapFree( GetProcessHeap(), 0, expected );
1598 HeapFree( GetProcessHeap(), 0, volume_prefix );
1599 HeapFree( GetProcessHeap(), 0, file_name );
1600 }
1601
1602 static void test_file_all_name_information(void)
1603 {
1604 WCHAR *file_name, *volume_prefix, *expected;
1605 FILE_ALL_INFORMATION *info;
1606 ULONG old_redir = 1, tmp;
1607 UINT file_name_size;
1608 IO_STATUS_BLOCK io;
1609 UINT info_size;
1610 HRESULT hr;
1611 HANDLE h;
1612 UINT len;
1613
1614 /* GetVolumePathName is not present before w2k */
1615 if (!pGetVolumePathNameW) {
1616 win_skip("GetVolumePathNameW not found\n");
1617 return;
1618 }
1619
1620 file_name_size = GetSystemDirectoryW( NULL, 0 );
1621 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1622 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1623 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1624
1625 len = GetSystemDirectoryW( file_name, file_name_size );
1626 ok(len == file_name_size - 1,
1627 "GetSystemDirectoryW returned %u, expected %u.\n",
1628 len, file_name_size - 1);
1629
1630 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1631 ok(len, "GetVolumePathNameW failed.\n");
1632
1633 len = lstrlenW( volume_prefix );
1634 if (len && volume_prefix[len - 1] == '\\') --len;
1635 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1636 expected[file_name_size - len - 1] = '\0';
1637
1638 /* A bit more than we actually need, but it keeps the calculation simple. */
1639 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1640 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1641
1642 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1643 h = CreateFileW( file_name, GENERIC_READ,
1644 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1645 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1646 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1647 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1648
1649 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileAllInformation );
1650 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x, expected %#x.\n",
1651 hr, STATUS_INFO_LENGTH_MISMATCH);
1652
1653 memset( info, 0xcc, info_size );
1654 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileAllInformation );
1655 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1656 hr, STATUS_BUFFER_OVERFLOW);
1657 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1658 U(io).Status, STATUS_BUFFER_OVERFLOW);
1659 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1660 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1661 ok(info->NameInformation.FileName[2] == 0xcccc,
1662 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info->NameInformation.FileName[2]);
1663 ok(CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1664 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1665 CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1666 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1667
1668 memset( info, 0xcc, info_size );
1669 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1670 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1671 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1672 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1673 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1674 ok(info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] == 0xcccc,
1675 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1676 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)]);
1677 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1678 ok(!lstrcmpiW( info->NameInformation.FileName, expected ),
1679 "info->NameInformation.FileName is %s, expected %s.\n",
1680 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1681 ok(io.Information == FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName)
1682 + info->NameInformation.FileNameLength,
1683 "io.Information is %lu\n", io.Information );
1684
1685 CloseHandle( h );
1686 HeapFree( GetProcessHeap(), 0, info );
1687 HeapFree( GetProcessHeap(), 0, expected );
1688 HeapFree( GetProcessHeap(), 0, volume_prefix );
1689
1690 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1691 {
1692 skip("Not running on WoW64, skipping test.\n");
1693 HeapFree( GetProcessHeap(), 0, file_name );
1694 return;
1695 }
1696
1697 h = CreateFileW( file_name, GENERIC_READ,
1698 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1699 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1700 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1701 HeapFree( GetProcessHeap(), 0, file_name );
1702
1703 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1704 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1705 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1706
1707 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1708 ok(len == file_name_size - 1,
1709 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1710 len, file_name_size - 1);
1711
1712 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1713 ok(len, "GetVolumePathNameW failed.\n");
1714
1715 len = lstrlenW( volume_prefix );
1716 if (len && volume_prefix[len - 1] == '\\') --len;
1717 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1718 expected[file_name_size - len - 1] = '\0';
1719
1720 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1721 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1722
1723 memset( info, 0xcc, info_size );
1724 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1725 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1726 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1727 ok(!lstrcmpiW( info->NameInformation.FileName, expected ), "info->NameInformation.FileName is %s, expected %s.\n",
1728 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1729
1730 CloseHandle( h );
1731 HeapFree( GetProcessHeap(), 0, info );
1732 HeapFree( GetProcessHeap(), 0, expected );
1733 HeapFree( GetProcessHeap(), 0, volume_prefix );
1734 HeapFree( GetProcessHeap(), 0, file_name );
1735 }
1736
1737 static void test_query_volume_information_file(void)
1738 {
1739 NTSTATUS status;
1740 HANDLE dir;
1741 WCHAR path[MAX_PATH];
1742 OBJECT_ATTRIBUTES attr;
1743 IO_STATUS_BLOCK io;
1744 UNICODE_STRING nameW;
1745 FILE_FS_VOLUME_INFORMATION *ffvi;
1746 BYTE buf[sizeof(FILE_FS_VOLUME_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
1747
1748 GetWindowsDirectoryW( path, MAX_PATH );
1749 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
1750 attr.Length = sizeof(attr);
1751 attr.RootDirectory = 0;
1752 attr.ObjectName = &nameW;
1753 attr.Attributes = OBJ_CASE_INSENSITIVE;
1754 attr.SecurityDescriptor = NULL;
1755 attr.SecurityQualityOfService = NULL;
1756
1757 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
1758 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
1759 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
1760 pRtlFreeUnicodeString( &nameW );
1761
1762 ZeroMemory( buf, sizeof(buf) );
1763 U(io).Status = 0xdadadada;
1764 io.Information = 0xcacacaca;
1765
1766 status = pNtQueryVolumeInformationFile( dir, &io, buf, sizeof(buf), FileFsVolumeInformation );
1767
1768 ffvi = (FILE_FS_VOLUME_INFORMATION *)buf;
1769
1770 todo_wine
1771 {
1772 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", status);
1773 ok(U(io).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", U(io).Status);
1774
1775 ok(io.Information == (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + ffvi->VolumeLabelLength),
1776 "expected %d, got %lu\n", (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + ffvi->VolumeLabelLength),
1777 io.Information);
1778
1779 ok(ffvi->VolumeCreationTime.QuadPart != 0, "Missing VolumeCreationTime\n");
1780 ok(ffvi->VolumeSerialNumber != 0, "Missing VolumeSerialNumber\n");
1781 ok(ffvi->SupportsObjects == 1,"expected 1, got %d\n", ffvi->SupportsObjects);
1782 }
1783 ok(ffvi->VolumeLabelLength == lstrlenW(ffvi->VolumeLabel) * sizeof(WCHAR), "got %d\n", ffvi->VolumeLabelLength);
1784
1785 trace("VolumeSerialNumber: %x VolumeLabelName: %s\n", ffvi->VolumeSerialNumber, wine_dbgstr_w(ffvi->VolumeLabel));
1786
1787 CloseHandle( dir );
1788 }
1789
1790 static void test_query_attribute_information_file(void)
1791 {
1792 NTSTATUS status;
1793 HANDLE dir;
1794 WCHAR path[MAX_PATH];
1795 OBJECT_ATTRIBUTES attr;
1796 IO_STATUS_BLOCK io;
1797 UNICODE_STRING nameW;
1798 FILE_FS_ATTRIBUTE_INFORMATION *ffai;
1799 BYTE buf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
1800
1801 GetWindowsDirectoryW( path, MAX_PATH );
1802 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
1803 attr.Length = sizeof(attr);
1804 attr.RootDirectory = 0;
1805 attr.ObjectName = &nameW;
1806 attr.Attributes = OBJ_CASE_INSENSITIVE;
1807 attr.SecurityDescriptor = NULL;
1808 attr.SecurityQualityOfService = NULL;
1809
1810 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
1811 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
1812 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
1813 pRtlFreeUnicodeString( &nameW );
1814
1815 ZeroMemory( buf, sizeof(buf) );
1816 U(io).Status = 0xdadadada;
1817 io.Information = 0xcacacaca;
1818
1819 status = pNtQueryVolumeInformationFile( dir, &io, buf, sizeof(buf), FileFsAttributeInformation );
1820
1821 ffai = (FILE_FS_ATTRIBUTE_INFORMATION *)buf;
1822
1823 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", status);
1824 ok(U(io).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", U(io).Status);
1825 ok(ffai->FileSystemAttribute != 0, "Missing FileSystemAttribute\n");
1826 ok(ffai->MaximumComponentNameLength != 0, "Missing MaximumComponentNameLength\n");
1827 ok(ffai->FileSystemNameLength != 0, "Missing FileSystemNameLength\n");
1828
1829 trace("FileSystemAttribute: %x MaximumComponentNameLength: %x FileSystemName: %s\n",
1830 ffai->FileSystemAttribute, ffai->MaximumComponentNameLength,
1831 wine_dbgstr_wn(ffai->FileSystemName, ffai->FileSystemNameLength / sizeof(WCHAR)));
1832
1833 CloseHandle( dir );
1834 }
1835
1836 static void test_NtCreateFile(void)
1837 {
1838 static const struct test_data
1839 {
1840 DWORD disposition, attrib_in, status, result, attrib_out, needs_cleanup;
1841 } td[] =
1842 {
1843 /* 0*/{ FILE_CREATE, FILE_ATTRIBUTE_READONLY, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1844 /* 1*/{ FILE_CREATE, 0, STATUS_OBJECT_NAME_COLLISION, 0, 0, TRUE },
1845 /* 2*/{ FILE_CREATE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1846 /* 3*/{ FILE_OPEN, FILE_ATTRIBUTE_READONLY, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE, TRUE },
1847 /* 4*/{ FILE_OPEN, FILE_ATTRIBUTE_READONLY, STATUS_OBJECT_NAME_NOT_FOUND, 0, 0, FALSE },
1848 /* 5*/{ FILE_OPEN_IF, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1849 /* 6*/{ FILE_OPEN_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE, TRUE },
1850 /* 7*/{ FILE_OPEN_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1851 /* 8*/{ FILE_OPEN_IF, 0, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1852 /* 9*/{ FILE_OVERWRITE, 0, STATUS_ACCESS_DENIED, 0, 0, TRUE },
1853 /*10*/{ FILE_OVERWRITE, 0, STATUS_OBJECT_NAME_NOT_FOUND, 0, 0, FALSE },
1854 /*11*/{ FILE_CREATE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1855 /*12*/{ FILE_OVERWRITE, FILE_ATTRIBUTE_READONLY, 0, FILE_OVERWRITTEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1856 /*13*/{ FILE_OVERWRITE_IF, 0, STATUS_ACCESS_DENIED, 0, 0, TRUE },
1857 /*14*/{ FILE_OVERWRITE_IF, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1858 /*15*/{ FILE_OVERWRITE_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_OVERWRITTEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1859 /*16*/{ FILE_SUPERSEDE, 0, 0, FILE_SUPERSEDED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1860 /*17*/{ FILE_SUPERSEDE, FILE_ATTRIBUTE_READONLY, 0, FILE_SUPERSEDED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, TRUE },
1861 /*18*/{ FILE_SUPERSEDE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, TRUE }
1862 };
1863 static const WCHAR fooW[] = {'f','o','o',0};
1864 NTSTATUS status;
1865 HANDLE handle;
1866 WCHAR path[MAX_PATH];
1867 OBJECT_ATTRIBUTES attr;
1868 IO_STATUS_BLOCK io;
1869 UNICODE_STRING nameW;
1870 DWORD ret, i;
1871
1872 GetTempPathW(MAX_PATH, path);
1873 GetTempFileNameW(path, fooW, 0, path);
1874 DeleteFileW(path);
1875 pRtlDosPathNameToNtPathName_U(path, &nameW, NULL, NULL);
1876
1877 attr.Length = sizeof(attr);
1878 attr.RootDirectory = NULL;
1879 attr.ObjectName = &nameW;
1880 attr.Attributes = OBJ_CASE_INSENSITIVE;
1881 attr.SecurityDescriptor = NULL;
1882 attr.SecurityQualityOfService = NULL;
1883
1884 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
1885 {
1886 status = pNtCreateFile(&handle, GENERIC_READ, &attr, &io, NULL,
1887 td[i].attrib_in, FILE_SHARE_READ|FILE_SHARE_WRITE,
1888 td[i].disposition, 0, NULL, 0);
1889
1890 ok(status == td[i].status, "%d: expected %#x got %#x\n", i, td[i].status, status);
1891
1892 if (!status)
1893 {
1894 ok(io.Information == td[i].result,"%d: expected %#x got %#lx\n", i, td[i].result, io.Information);
1895
1896 ret = GetFileAttributesW(path);
1897 ret &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
1898 /* FIXME: leave only 'else' case below once Wine is fixed */
1899 if (ret != td[i].attrib_out)
1900 {
1901 todo_wine
1902 ok(ret == td[i].attrib_out, "%d: expected %#x got %#x\n", i, td[i].attrib_out, ret);
1903 SetFileAttributesW(path, td[i].attrib_out);
1904 }
1905 else
1906 ok(ret == td[i].attrib_out, "%d: expected %#x got %#x\n", i, td[i].attrib_out, ret);
1907
1908 CloseHandle(handle);
1909 }
1910
1911 if (td[i].needs_cleanup)
1912 {
1913 SetFileAttributesW(path, FILE_ATTRIBUTE_ARCHIVE);
1914 DeleteFileW(path);
1915 }
1916 }
1917
1918 SetFileAttributesW(path, FILE_ATTRIBUTE_ARCHIVE);
1919 DeleteFileW( path );
1920 }
1921
1922 static void test_read_write(void)
1923 {
1924 static const char contents[] = "1234567890abcd";
1925 char buf[256];
1926 HANDLE hfile;
1927 OVERLAPPED ovl;
1928 IO_STATUS_BLOCK iob;
1929 DWORD ret, bytes, status;
1930 LARGE_INTEGER offset;
1931
1932 iob.Status = -1;
1933 iob.Information = -1;
1934 offset.QuadPart = 0;
1935 status = pNtReadFile(INVALID_HANDLE_VALUE, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
1936 ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE, "expected STATUS_OBJECT_TYPE_MISMATCH, got %#x\n", status);
1937 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
1938 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
1939
1940 iob.Status = -1;
1941 iob.Information = -1;
1942 offset.QuadPart = 0;
1943 status = pNtWriteFile(INVALID_HANDLE_VALUE, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
1944 ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE, "expected STATUS_OBJECT_TYPE_MISMATCH, got %#x\n", status);
1945 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
1946 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
1947
1948 hfile = create_temp_file(0);
1949 if (!hfile) return;
1950
1951 iob.Status = -1;
1952 iob.Information = -1;
1953 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, NULL, sizeof(contents), NULL, NULL);
1954 ok(status == STATUS_INVALID_USER_BUFFER, "expected STATUS_INVALID_USER_BUFFER, got %#x\n", status);
1955 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
1956 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
1957
1958 iob.Status = -1;
1959 iob.Information = -1;
1960 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, NULL, sizeof(contents), NULL, NULL);
1961 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %#x\n", status);
1962 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
1963 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
1964
1965 iob.Status = -1;
1966 iob.Information = -1;
1967 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), NULL, NULL);
1968 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
1969 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
1970 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
1971
1972 bytes = 0xdeadbeef;
1973 SetLastError(0xdeadbeef);
1974 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
1975 ok(ret, "ReadFile error %d\n", GetLastError());
1976 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1977 ok(bytes == 0, "bytes %u\n", bytes);
1978
1979 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
1980
1981 bytes = 0;
1982 SetLastError(0xdeadbeef);
1983 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
1984 ok(ret, "ReadFile error %d\n", GetLastError());
1985 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
1986 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
1987
1988 SetFilePointer(hfile, sizeof(contents) - 4, NULL, FILE_BEGIN);
1989
1990 iob.Status = -1;
1991 iob.Information = -1;
1992 offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
1993 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, "DCBA", 4, &offset, NULL);
1994 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
1995 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
1996 ok(iob.Information == 4, "expected 4, got %lu\n", iob.Information);
1997
1998 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
1999
2000 bytes = 0;
2001 SetLastError(0xdeadbeef);
2002 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2003 ok(ret, "ReadFile error %d\n", GetLastError());
2004 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2005 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2006 ok(!memcmp(buf + sizeof(contents) - 4, "DCBA", 4), "file contents mismatch\n");
2007
2008 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2009
2010 bytes = 0;
2011 SetLastError(0xdeadbeef);
2012 ret = WriteFile(hfile, contents, sizeof(contents), &bytes, NULL);
2013 ok(ret, "WriteFile error %d\n", GetLastError());
2014 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2015
2016 iob.Status = -1;
2017 iob.Information = -1;
2018 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), NULL, NULL);
2019 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2020 todo_wine
2021 ok(iob.Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", iob.Status);
2022 todo_wine
2023 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2024
2025 iob.Status = -1;
2026 iob.Information = -1;
2027 offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2028 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2029 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2030 todo_wine
2031 ok(iob.Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", iob.Status);
2032 todo_wine
2033 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2034
2035 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2036
2037 bytes = 0;
2038 SetLastError(0xdeadbeef);
2039 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2040 ok(ret, "ReadFile error %d\n", GetLastError());
2041 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2042 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
2043
2044 iob.Status = -1;
2045 iob.Information = -1;
2046 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), NULL, NULL);
2047 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2048 todo_wine
2049 ok(iob.Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", iob.Status);
2050 todo_wine
2051 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2052
2053 iob.Status = -1;
2054 iob.Information = -1;
2055 offset.QuadPart = 0;
2056 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2057 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
2058 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
2059 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2060 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
2061
2062 iob.Status = -1;
2063 iob.Information = -1;
2064 offset.QuadPart = sizeof(contents) - 4;
2065 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, "DCBA", 4, &offset, NULL);
2066 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
2067 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
2068 ok(iob.Information == 4, "expected 4, got %lu\n", iob.Information);
2069
2070 iob.Status = -1;
2071 iob.Information = -1;
2072 offset.QuadPart = 0;
2073 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2074 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
2075 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
2076 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2077 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2078 ok(!memcmp(buf + sizeof(contents) - 4, "DCBA", 4), "file contents mismatch\n");
2079
2080 S(U(ovl)).Offset = sizeof(contents) - 4;
2081 S(U(ovl)).OffsetHigh = 0;
2082 ovl.hEvent = 0;
2083 bytes = 0;
2084 SetLastError(0xdeadbeef);
2085 ret = WriteFile(hfile, "ABCD", 4, &bytes, &ovl);
2086 ok(ret, "WriteFile error %d\n", GetLastError());
2087 ok(bytes == 4, "bytes %u\n", bytes);
2088
2089 S(U(ovl)).Offset = 0;
2090 S(U(ovl)).OffsetHigh = 0;
2091 ovl.Internal = -1;
2092 ovl.InternalHigh = -1;
2093 ovl.hEvent = 0;
2094 bytes = 0;
2095 SetLastError(0xdeadbeef);
2096 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2097 ok(ret, "ReadFile error %d\n", GetLastError());
2098 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2099 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2100 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2101 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2102 ok(!memcmp(buf + sizeof(contents) - 4, "ABCD", 4), "file contents mismatch\n");
2103
2104 CloseHandle(hfile);
2105
2106 hfile = create_temp_file(FILE_FLAG_OVERLAPPED);
2107 if (!hfile) return;
2108
2109 bytes = 0xdeadbeef;
2110 SetLastError(0xdeadbeef);
2111 ret = WriteFile(hfile, contents, sizeof(contents), &bytes, NULL);
2112 todo_wine
2113 ok(!ret, "WriteFile should fail\n");
2114 todo_wine
2115 ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2116 todo_wine
2117 ok(bytes == 0, "bytes %u\n", bytes);
2118
2119 iob.Status = -1;
2120 iob.Information = -1;
2121 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), NULL, NULL);
2122 todo_wine
2123 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got %#x\n", status);
2124 todo_wine
2125 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
2126 todo_wine
2127 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2128
2129 iob.Status = -1;
2130 iob.Information = -1;
2131 offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2132 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), &offset, NULL);
2133 todo_wine
2134 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got %#x\n", status);
2135 todo_wine
2136 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
2137 todo_wine
2138 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2139
2140 iob.Status = -1;
2141 iob.Information = -1;
2142 offset.QuadPart = 0;
2143 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), &offset, NULL);
2144 todo_wine
2145 ok(status == STATUS_PENDING || broken(status == STATUS_SUCCESS) /* see below */, "expected STATUS_PENDING, got %#x\n", status);
2146 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
2147 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2148 /* even fully updated XP passes this test, but it looks like some VMs
2149 * in a testbot get never updated, so overlapped IO is broken. Instead
2150 * of fighting with broken tests and adding a bunch of broken() statements
2151 * it's better to skip further tests completely.
2152 */
2153 if (status != STATUS_PENDING)
2154 {
2155 todo_wine
2156 win_skip("broken overlapped IO implementation, update your OS\n");
2157 CloseHandle(hfile);
2158 return;
2159 }
2160
2161 ret = WaitForSingleObject(hfile, 3000);
2162 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2163
2164 bytes = 0xdeadbeef;
2165 SetLastError(0xdeadbeef);
2166 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2167 ok(!ret, "ReadFile should fail\n");
2168 ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2169 ok(bytes == 0, "bytes %u\n", bytes);
2170
2171 iob.Status = -1;
2172 iob.Information = -1;
2173 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), NULL, NULL);
2174 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got %#x\n", status);
2175 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
2176 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2177
2178 iob.Status = -1;
2179 iob.Information = -1;
2180 offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2181 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2182 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got %#x\n", status);
2183 ok(iob.Status == -1, "expected -1, got %#x\n", iob.Status);
2184 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2185
2186 offset.QuadPart = sizeof(contents);
2187 S(U(ovl)).Offset = offset.u.LowPart;
2188 S(U(ovl)).OffsetHigh = offset.u.HighPart;
2189 ovl.Internal = -1;
2190 ovl.InternalHigh = -1;
2191 ovl.hEvent = 0;
2192 bytes = 0xdeadbeef;
2193 SetLastError(0xdeadbeef);
2194 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2195 ok(!ret, "ReadFile should fail\n");
2196 ok(GetLastError() == ERROR_IO_PENDING || broken(GetLastError() == ERROR_HANDLE_EOF), "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2197 /* even fully updated XP passes this test, but it looks like some VMs
2198 * in a testbot get never updated, so overlapped IO is broken. Instead
2199 * of fighting with broken tests and adding a bunch of broken() statements
2200 * it's better to skip further tests completely.
2201 */
2202 if (GetLastError() != ERROR_IO_PENDING)
2203 {
2204 win_skip("broken overlapped IO implementation, update your OS\n");
2205 CloseHandle(hfile);
2206 return;
2207 }
2208 ok(bytes == 0, "bytes %u\n", bytes);
2209 ok((NTSTATUS)ovl.Internal == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#lx\n", ovl.Internal);
2210 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2211
2212 bytes = 0xdeadbeef;
2213 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2214 ok(!ret, "GetOverlappedResult should report FALSE\n");
2215 ok(GetLastError() == ERROR_HANDLE_EOF, "expected ERROR_HANDLE_EOF, got %d\n", GetLastError());
2216 ok(bytes == 0, "expected 0, read %u\n", bytes);
2217 ok((NTSTATUS)ovl.Internal == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#lx\n", ovl.Internal);
2218 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2219
2220 iob.Status = -1;
2221 iob.Information = -1;
2222 offset.QuadPart = sizeof(contents);
2223 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2224 ok(status == STATUS_PENDING, "expected STATUS_PENDING, got %#x\n", status);
2225 ok(iob.Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", iob.Status);
2226 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2227
2228 S(U(ovl)).Offset = offset.u.LowPart;
2229 S(U(ovl)).OffsetHigh = offset.u.HighPart;
2230 ovl.Internal = iob.Status;
2231 ovl.InternalHigh = iob.Information;
2232 ovl.hEvent = 0;
2233 bytes = 0xdeadbeef;
2234 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2235 ok(!ret, "GetOverlappedResult should report FALSE\n");
2236 ok(GetLastError() == ERROR_HANDLE_EOF, "expected ERROR_HANDLE_EOF, got %d\n", GetLastError());
2237 ok(bytes == 0, "expected 0, read %u\n", bytes);
2238 ok((NTSTATUS)ovl.Internal == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#lx\n", ovl.Internal);
2239 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2240
2241 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2242
2243 S(U(ovl)).Offset = 0;
2244 S(U(ovl)).OffsetHigh = 0;
2245 ovl.Internal = -1;
2246 ovl.InternalHigh = -1;
2247 ovl.hEvent = 0;
2248 bytes = 0;
2249 SetLastError(0xdeadbeef);
2250 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2251 ok(!ret, "ReadFile should fail\n");
2252 ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2253 ok(bytes == 0, "bytes %u\n", bytes);
2254 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2255 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2256
2257 bytes = 0xdeadbeef;
2258 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2259 ok(ret, "GetOverlappedResult error %d\n", GetLastError());
2260 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2261 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2262 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2263 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
2264
2265 iob.Status = -1;
2266 iob.Information = -1;
2267 offset.QuadPart = sizeof(contents) - 4;
2268 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, "DCBA", 4, &offset, NULL);
2269 ok(status == STATUS_PENDING || broken(status == STATUS_SUCCESS) /* before Vista */, "expected STATUS_PENDING, got %#x\n", status);
2270 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
2271 ok(iob.Information == 4, "expected 4, got %lu\n", iob.Information);
2272
2273 ret = WaitForSingleObject(hfile, 3000);
2274 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2275
2276 iob.Status = -1;
2277 iob.Information = -1;
2278 offset.QuadPart = 0;
2279 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2280 ok(status == STATUS_PENDING, "expected STATUS_PENDING, got %#x\n", status);
2281 ok(iob.Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", iob.Status);
2282 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2283
2284 ret = WaitForSingleObject(hfile, 3000);
2285 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2286 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2287 ok(!memcmp(buf + sizeof(contents) - 4, "DCBA", 4), "file contents mismatch\n");
2288
2289 S(U(ovl)).Offset = sizeof(contents) - 4;
2290 S(U(ovl)).OffsetHigh = 0;
2291 ovl.Internal = -1;
2292 ovl.InternalHigh = -1;
2293 ovl.hEvent = 0;
2294 bytes = 0;
2295 SetLastError(0xdeadbeef);
2296 ret = WriteFile(hfile, "ABCD", 4, &bytes, &ovl);
2297 ok(!ret || broken(ret) /* before Vista */, "WriteFile should fail\n");
2298 ok(GetLastError() == ERROR_IO_PENDING || broken(GetLastError() == 0xdeadbeef) /* before Vista */, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2299 ok(bytes == 0 || broken(bytes == 4) /* before Vista */, "bytes %u\n", bytes);
2300 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2301 ok(ovl.InternalHigh == 4, "expected 4, got %lu\n", ovl.InternalHigh);
2302
2303 bytes = 0xdeadbeef;
2304 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2305 ok(ret, "GetOverlappedResult error %d\n", GetLastError());
2306 ok(bytes == 4, "bytes %u\n", bytes);
2307 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2308 ok(ovl.InternalHigh == 4, "expected 4, got %lu\n", ovl.InternalHigh);
2309
2310 S(U(ovl)).Offset = 0;
2311 S(U(ovl)).OffsetHigh = 0;
2312 ovl.Internal = -1;
2313 ovl.InternalHigh = -1;
2314 ovl.hEvent = 0;
2315 bytes = 0;
2316 SetLastError(0xdeadbeef);
2317 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2318 ok(!ret, "ReadFile should fail\n");
2319 ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2320 ok(bytes == 0, "bytes %u\n", bytes);
2321 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2322 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2323
2324 bytes = 0xdeadbeef;
2325 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2326 ok(ret, "GetOverlappedResult error %d\n", GetLastError());
2327 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2328 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2329 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2330 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2331 ok(!memcmp(buf + sizeof(contents) - 4, "ABCD", 4), "file contents mismatch\n");
2332
2333 CloseHandle(hfile);
2334 }
2335
2336 START_TEST(file)
2337 {
2338 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
2339 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
2340 if (!hntdll)
2341 {
2342 skip("not running on NT, skipping test\n");
2343 return;
2344 }
2345
2346 pGetVolumePathNameW = (void *)GetProcAddress(hkernel32, "GetVolumePathNameW");
2347 pGetSystemWow64DirectoryW = (void *)GetProcAddress(hkernel32, "GetSystemWow64DirectoryW");
2348
2349 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
2350 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
2351 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
2352 pRtlWow64EnableFsRedirectionEx = (void *)GetProcAddress(hntdll, "RtlWow64EnableFsRedirectionEx");
2353 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
2354 pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile");
2355 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
2356 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
2357 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
2358 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
2359 pNtCancelIoFile = (void *)GetProcAddress(hntdll, "NtCancelIoFile");
2360 pNtCancelIoFileEx = (void *)GetProcAddress(hntdll, "NtCancelIoFileEx");
2361 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
2362 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
2363 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
2364 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
2365 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
2366 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
2367 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");
2368 pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
2369 pNtQueryDirectoryFile = (void *)GetProcAddress(hntdll, "NtQueryDirectoryFile");
2370 pNtQueryVolumeInformationFile = (void *)GetProcAddress(hntdll, "NtQueryVolumeInformationFile");
2371
2372 test_read_write();
2373 test_NtCreateFile();
2374 create_file_test();
2375 open_file_test();
2376 delete_file_test();
2377 read_file_test();
2378 append_file_test();
2379 nt_mailslot_test();
2380 test_iocompletion();
2381 test_file_basic_information();
2382 test_file_all_information();
2383 test_file_both_information();
2384 test_file_name_information();
2385 test_file_all_name_information();
2386 test_file_disposition_information();
2387 test_query_volume_information_file();
2388 test_query_attribute_information_file();
2389 }