[REACTOS]
[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 = CreateNamedPipeA(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 ok(status == STATUS_PENDING || status == STATUS_END_OF_FILE /* before Vista */, "expected STATUS_PENDING or STATUS_END_OF_FILE, got %#x\n", status);
786 if (status == STATUS_PENDING) /* vista */
787 {
788 WaitForSingleObject( event, 1000 );
789 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
790 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
791 ok( is_signaled( event ), "event is signaled\n" );
792 ok( !apc_count, "apc was called\n" );
793 SleepEx( 1, TRUE ); /* alertable sleep */
794 ok( apc_count == 1, "apc was not called\n" );
795 }
796 CloseHandle( handle );
797
798 /* now a non-overlapped file */
799 if (!(handle = create_temp_file(0))) return;
800 apc_count = 0;
801 U(iosb).Status = 0xdeadbabe;
802 iosb.Information = 0xdeadbeef;
803 offset.QuadPart = 0;
804 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
805 ok( status == STATUS_END_OF_FILE ||
806 status == STATUS_SUCCESS ||
807 status == STATUS_PENDING, /* vista */
808 "wrong status %x\n", status );
809 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
810 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
811 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
812 ok( is_signaled( event ), "event is signaled\n" );
813 ok( !apc_count, "apc was called\n" );
814 SleepEx( 1, TRUE ); /* alertable sleep */
815 ok( apc_count == 1, "apc was not called\n" );
816
817 apc_count = 0;
818 U(iosb).Status = 0xdeadbabe;
819 iosb.Information = 0xdeadbeef;
820 offset.QuadPart = 0;
821 ResetEvent( event );
822 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
823 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
824 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
825 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
826 ok( is_signaled( event ), "event is signaled\n" );
827 ok( !apc_count, "apc was called\n" );
828 SleepEx( 1, TRUE ); /* alertable sleep */
829 todo_wine ok( !apc_count, "apc was called\n" );
830
831 /* read beyond eof */
832 apc_count = 0;
833 U(iosb).Status = 0xdeadbabe;
834 iosb.Information = 0xdeadbeef;
835 offset.QuadPart = strlen(text) + 2;
836 ResetEvent( event );
837 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
838 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
839 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
840 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
841 ok( is_signaled( event ), "event is not signaled\n" );
842 ok( !apc_count, "apc was called\n" );
843 SleepEx( 1, TRUE ); /* alertable sleep */
844 ok( !apc_count, "apc was called\n" );
845
846 CloseHandle( handle );
847
848 CloseHandle( event );
849 }
850
851 static void append_file_test(void)
852 {
853 static const char text[6] = "foobar";
854 HANDLE handle;
855 NTSTATUS status;
856 IO_STATUS_BLOCK iosb;
857 LARGE_INTEGER offset;
858 char path[MAX_PATH], buffer[MAX_PATH], buf[16];
859 DWORD ret;
860
861 GetTempPathA( MAX_PATH, path );
862 GetTempFileNameA( path, "foo", 0, buffer );
863
864 handle = CreateFileA(buffer, FILE_WRITE_DATA, 0, NULL, CREATE_ALWAYS, 0, 0);
865 ok(handle != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
866
867 U(iosb).Status = -1;
868 iosb.Information = -1;
869 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text, 2, NULL, NULL);
870 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
871 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
872 ok(iosb.Information == 2, "expected 2, got %lu\n", iosb.Information);
873
874 CloseHandle(handle);
875
876 /* It is possible to open a file with only FILE_APPEND_DATA access flags.
877 It matches the O_WRONLY|O_APPEND open() posix behavior */
878 handle = CreateFileA(buffer, FILE_APPEND_DATA, 0, NULL, OPEN_EXISTING, 0, 0);
879 ok(handle != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
880
881 U(iosb).Status = -1;
882 iosb.Information = -1;
883 offset.QuadPart = 1;
884 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text + 2, 2, &offset, NULL);
885 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
886 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
887 ok(iosb.Information == 2, "expected 2, got %lu\n", iosb.Information);
888
889 ret = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
890 ok(ret == 4, "expected 4, got %u\n", ret);
891
892 U(iosb).Status = -1;
893 iosb.Information = -1;
894 offset.QuadPart = 3;
895 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text + 4, 2, &offset, NULL);
896 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
897 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
898 ok(iosb.Information == 2, "expected 2, got %lu\n", iosb.Information);
899
900 ret = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
901 ok(ret == 6, "expected 6, got %u\n", ret);
902
903 CloseHandle(handle);
904
905 handle = CreateFileA(buffer, FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA, 0, NULL, OPEN_EXISTING, 0, 0);
906 ok(handle != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
907
908 memset(buf, 0, sizeof(buf));
909 U(iosb).Status = -1;
910 iosb.Information = -1;
911 offset.QuadPart = 0;
912 status = pNtReadFile(handle, 0, NULL, NULL, &iosb, buf, sizeof(buf), &offset, NULL);
913 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
914 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
915 ok(iosb.Information == 6, "expected 6, got %lu\n", iosb.Information);
916 buf[6] = 0;
917 ok(memcmp(buf, text, 6) == 0, "wrong file contents: %s\n", buf);
918
919 U(iosb).Status = -1;
920 iosb.Information = -1;
921 offset.QuadPart = 0;
922 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text + 3, 3, &offset, NULL);
923 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
924 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
925 ok(iosb.Information == 3, "expected 3, got %lu\n", iosb.Information);
926
927 memset(buf, 0, sizeof(buf));
928 U(iosb).Status = -1;
929 iosb.Information = -1;
930 offset.QuadPart = 0;
931 status = pNtReadFile(handle, 0, NULL, NULL, &iosb, buf, sizeof(buf), &offset, NULL);
932 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
933 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
934 ok(iosb.Information == 6, "expected 6, got %lu\n", iosb.Information);
935 buf[6] = 0;
936 ok(memcmp(buf, "barbar", 6) == 0, "wrong file contents: %s\n", buf);
937
938 CloseHandle(handle);
939 DeleteFileA(buffer);
940 }
941
942 static void nt_mailslot_test(void)
943 {
944 HANDLE hslot;
945 ACCESS_MASK DesiredAccess;
946 OBJECT_ATTRIBUTES attr;
947
948 ULONG CreateOptions;
949 ULONG MailslotQuota;
950 ULONG MaxMessageSize;
951 LARGE_INTEGER TimeOut;
952 IO_STATUS_BLOCK IoStatusBlock;
953 NTSTATUS rc;
954 UNICODE_STRING str;
955 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
956 'R',':','\\','F','R','E','D','\0' };
957
958 TimeOut.QuadPart = -1;
959
960 pRtlInitUnicodeString(&str, buffer1);
961 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
962 CreateOptions = MailslotQuota = MaxMessageSize = 0;
963 DesiredAccess = GENERIC_READ;
964
965 /*
966 * Check for NULL pointer handling
967 */
968 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
969 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
970 &TimeOut);
971 ok( rc == STATUS_ACCESS_VIOLATION ||
972 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
973 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
974
975 /*
976 * Test to see if the Timeout can be NULL
977 */
978 hslot = (HANDLE)0xdeadbeef;
979 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
980 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
981 NULL);
982 ok( rc == STATUS_SUCCESS ||
983 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
984 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
985 ok( hslot != 0, "Handle is invalid\n");
986
987 if ( rc == STATUS_SUCCESS ) pNtClose(hslot);
988
989 /*
990 * Test that the length field is checked properly
991 */
992 attr.Length = 0;
993 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
994 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
995 &TimeOut);
996 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
997
998 if (rc == STATUS_SUCCESS) pNtClose(hslot);
999
1000 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
1001 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
1002 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
1003 &TimeOut);
1004 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
1005
1006 if (rc == STATUS_SUCCESS) pNtClose(hslot);
1007
1008 /*
1009 * Test handling of a NULL unicode string in ObjectName
1010 */
1011 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
1012 attr.ObjectName = NULL;
1013 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
1014 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
1015 &TimeOut);
1016 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
1017 rc == STATUS_INVALID_PARAMETER,
1018 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
1019
1020 if (rc == STATUS_SUCCESS) pNtClose(hslot);
1021
1022 /*
1023 * Test a valid call
1024 */
1025 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
1026 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
1027 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
1028 &TimeOut);
1029 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
1030 ok( hslot != 0, "Handle is invalid\n");
1031
1032 rc = pNtClose(hslot);
1033 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
1034 }
1035
1036 static void test_iocp_setcompletion(HANDLE h)
1037 {
1038 NTSTATUS res;
1039 ULONG count;
1040 SIZE_T size = 3;
1041
1042 if (sizeof(size) > 4) size |= (ULONGLONG)0x12345678 << 32;
1043
1044 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, size );
1045 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
1046
1047 count = get_pending_msgs(h);
1048 ok( count == 1, "Unexpected msg count: %d\n", count );
1049
1050 if (get_msg(h))
1051 {
1052 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
1053 ok( ioSb.Information == size, "Invalid ioSb.Information: %lu\n", ioSb.Information );
1054 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1055 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
1056 }
1057
1058 count = get_pending_msgs(h);
1059 ok( !count, "Unexpected msg count: %d\n", count );
1060 }
1061
1062 static void test_iocp_fileio(HANDLE h)
1063 {
1064 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
1065
1066 IO_STATUS_BLOCK iosb;
1067 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
1068 HANDLE hPipeSrv, hPipeClt;
1069 NTSTATUS res;
1070
1071 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1072 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1073 if (hPipeSrv != INVALID_HANDLE_VALUE )
1074 {
1075 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1076 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1077 if (hPipeClt != INVALID_HANDLE_VALUE)
1078 {
1079 U(iosb).Status = 0xdeadbeef;
1080 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1081 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
1082 ok( U(iosb).Status == STATUS_INVALID_PARAMETER /* 98 */ || U(iosb).Status == 0xdeadbeef /* NT4+ */,
1083 "Unexpected iosb.Status on non-overlapped handle: %x\n", U(iosb).Status );
1084 CloseHandle(hPipeClt);
1085 }
1086 CloseHandle( hPipeSrv );
1087 }
1088
1089 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1090 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1091 if (hPipeSrv == INVALID_HANDLE_VALUE )
1092 return;
1093
1094 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1095 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1096 if (hPipeClt != INVALID_HANDLE_VALUE)
1097 {
1098 OVERLAPPED o = {0,};
1099 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
1100 DWORD read;
1101 long count;
1102
1103 U(iosb).Status = 0xdeadbeef;
1104 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1105 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
1106 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
1107
1108 memset( send_buf, 0, TEST_BUF_LEN );
1109 memset( recv_buf, 0xde, TEST_BUF_LEN );
1110 count = get_pending_msgs(h);
1111 ok( !count, "Unexpected msg count: %ld\n", count );
1112 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1113 count = get_pending_msgs(h);
1114 ok( !count, "Unexpected msg count: %ld\n", count );
1115 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
1116
1117 if (get_msg(h))
1118 {
1119 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1120 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1121 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1122 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1123 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] );
1124 }
1125 count = get_pending_msgs(h);
1126 ok( !count, "Unexpected msg count: %ld\n", count );
1127
1128 memset( send_buf, 0, TEST_BUF_LEN );
1129 memset( recv_buf, 0xde, TEST_BUF_LEN );
1130 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
1131 count = get_pending_msgs(h);
1132 ok( !count, "Unexpected msg count: %ld\n", count );
1133 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
1134 count = get_pending_msgs(h);
1135 ok( count == 1, "Unexpected msg count: %ld\n", count );
1136 if (get_msg(h))
1137 {
1138 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1139 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1140 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1141 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1142 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] );
1143 }
1144
1145 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1146 CloseHandle( hPipeSrv );
1147 count = get_pending_msgs(h);
1148 ok( count == 1, "Unexpected msg count: %ld\n", count );
1149 if (get_msg(h))
1150 {
1151 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1152 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1153 /* wine sends wrong status here */
1154 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1155 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1156 }
1157 }
1158
1159 CloseHandle( hPipeClt );
1160
1161 /* test associating a completion port with a handle after an async is queued */
1162 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1163 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1164 if (hPipeSrv == INVALID_HANDLE_VALUE )
1165 return;
1166 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1167 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1168 if (hPipeClt != INVALID_HANDLE_VALUE)
1169 {
1170 OVERLAPPED o = {0,};
1171 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
1172 DWORD read;
1173 long count;
1174
1175 memset( send_buf, 0, TEST_BUF_LEN );
1176 memset( recv_buf, 0xde, TEST_BUF_LEN );
1177 count = get_pending_msgs(h);
1178 ok( !count, "Unexpected msg count: %ld\n", count );
1179 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1180
1181 U(iosb).Status = 0xdeadbeef;
1182 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1183 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
1184 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
1185 count = get_pending_msgs(h);
1186 ok( !count, "Unexpected msg count: %ld\n", count );
1187
1188 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
1189
1190 if (get_msg(h))
1191 {
1192 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1193 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1194 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1195 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1196 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] );
1197 }
1198 count = get_pending_msgs(h);
1199 ok( !count, "Unexpected msg count: %ld\n", count );
1200 }
1201
1202 CloseHandle( hPipeSrv );
1203 CloseHandle( hPipeClt );
1204 }
1205
1206 static void test_file_basic_information(void)
1207 {
1208 IO_STATUS_BLOCK io;
1209 FILE_BASIC_INFORMATION fbi;
1210 HANDLE h;
1211 int res;
1212 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1213
1214 if (!(h = create_temp_file(0))) return;
1215
1216 /* Check default first */
1217 memset(&fbi, 0, sizeof(fbi));
1218 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1219 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1220 ok ( (fbi.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1221 "attribute %x not expected\n", fbi.FileAttributes );
1222
1223 /* Then SYSTEM */
1224 /* Clear fbi to avoid setting times */
1225 memset(&fbi, 0, sizeof(fbi));
1226 fbi.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1227 U(io).Status = 0xdeadbeef;
1228 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1229 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1230 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1231
1232 memset(&fbi, 0, sizeof(fbi));
1233 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1234 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1235 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi.FileAttributes );
1236
1237 /* Then HIDDEN */
1238 memset(&fbi, 0, sizeof(fbi));
1239 fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1240 U(io).Status = 0xdeadbeef;
1241 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1242 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1243 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1244
1245 memset(&fbi, 0, sizeof(fbi));
1246 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1247 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1248 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi.FileAttributes );
1249
1250 /* Check NORMAL last of all (to make sure we can clear attributes) */
1251 memset(&fbi, 0, sizeof(fbi));
1252 fbi.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1253 U(io).Status = 0xdeadbeef;
1254 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1255 ok ( res == STATUS_SUCCESS, "can't set normal attribute, NtSetInformationFile returned %x\n", res );
1256 ok ( U(io).Status == STATUS_SUCCESS, "can't set normal attribute, io.Status is %x\n", U(io).Status );
1257
1258 memset(&fbi, 0, sizeof(fbi));
1259 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1260 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1261 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not 0\n", fbi.FileAttributes );
1262
1263 CloseHandle( h );
1264 }
1265
1266 static void test_file_all_information(void)
1267 {
1268 IO_STATUS_BLOCK io;
1269 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1270 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1271 * don't leave enough room there.
1272 */
1273 struct {
1274 FILE_ALL_INFORMATION fai;
1275 WCHAR buf[256];
1276 } fai_buf;
1277 HANDLE h;
1278 int res;
1279 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1280
1281 if (!(h = create_temp_file(0))) return;
1282
1283 /* Check default first */
1284 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1285 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1286 ok ( (fai_buf.fai.BasicInformation.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1287 "attribute %x not expected\n", fai_buf.fai.BasicInformation.FileAttributes );
1288
1289 /* Then SYSTEM */
1290 /* Clear fbi to avoid setting times */
1291 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1292 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1293 U(io).Status = 0xdeadbeef;
1294 res = pNtSetInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1295 ok ( res == STATUS_INVALID_INFO_CLASS || broken(res == STATUS_NOT_IMPLEMENTED), "shouldn't be able to set FileAllInformation, res %x\n", res);
1296 todo_wine ok ( U(io).Status == 0xdeadbeef, "shouldn't be able to set FileAllInformation, io.Status is %x\n", U(io).Status);
1297 U(io).Status = 0xdeadbeef;
1298 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1299 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1300 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1301
1302 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1303 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1304 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1305 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 );
1306
1307 /* Then HIDDEN */
1308 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1309 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1310 U(io).Status = 0xdeadbeef;
1311 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1312 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1313 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1314
1315 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1316 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1317 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1318 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 );
1319
1320 /* Check NORMAL last of all (to make sure we can clear attributes) */
1321 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1322 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1323 U(io).Status = 0xdeadbeef;
1324 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1325 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1326 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1327
1328 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1329 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1330 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1331 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 );
1332
1333 CloseHandle( h );
1334 }
1335
1336 static void test_file_both_information(void)
1337 {
1338 IO_STATUS_BLOCK io;
1339 FILE_BOTH_DIR_INFORMATION fbi;
1340 HANDLE h;
1341 int res;
1342
1343 if (!(h = create_temp_file(0))) return;
1344
1345 memset(&fbi, 0, sizeof(fbi));
1346 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBothDirectoryInformation);
1347 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res);
1348
1349 CloseHandle( h );
1350 }
1351
1352 static void test_file_disposition_information(void)
1353 {
1354 char tmp_path[MAX_PATH], buffer[MAX_PATH + 16];
1355 DWORD dirpos;
1356 HANDLE handle, handle2;
1357 NTSTATUS res;
1358 IO_STATUS_BLOCK io;
1359 FILE_DISPOSITION_INFORMATION fdi;
1360 BOOL fileDeleted;
1361
1362 GetTempPathA( MAX_PATH, tmp_path );
1363
1364 /* cannot set disposition on file not opened with delete access */
1365 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1366 handle = CreateFileA(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
1367 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1368 res = pNtQueryInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1369 ok( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "Unexpected NtQueryInformationFile result (expected STATUS_INVALID_INFO_CLASS, got %x)\n", res );
1370 fdi.DoDeleteFile = TRUE;
1371 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1372 todo_wine
1373 ok( res == STATUS_ACCESS_DENIED, "unexpected FileDispositionInformation result (expected STATUS_ACCESS_DENIED, got %x)\n", res );
1374 CloseHandle( handle );
1375 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1376 ok( !fileDeleted, "File shouldn't have been deleted\n" );
1377 DeleteFileA( buffer );
1378
1379 /* can set disposition on file opened with proper access */
1380 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1381 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
1382 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1383 fdi.DoDeleteFile = TRUE;
1384 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1385 todo_wine
1386 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1387 CloseHandle( handle );
1388 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1389 todo_wine
1390 ok( fileDeleted, "File should have been deleted\n" );
1391 DeleteFileA( buffer );
1392
1393 /* cannot set disposition on readonly file */
1394 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1395 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_READONLY, 0);
1396 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1397 fdi.DoDeleteFile = TRUE;
1398 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1399 todo_wine
1400 ok( res == STATUS_CANNOT_DELETE, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res );
1401 CloseHandle( handle );
1402 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1403 ok( !fileDeleted, "File shouldn't have been deleted\n" );
1404 SetFileAttributesA( buffer, FILE_ATTRIBUTE_NORMAL );
1405 DeleteFileA( buffer );
1406
1407 /* can set disposition on file and then reset it */
1408 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1409 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0);
1410 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1411 fdi.DoDeleteFile = TRUE;
1412 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1413 todo_wine
1414 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1415 fdi.DoDeleteFile = FALSE;
1416 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1417 todo_wine
1418 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1419 CloseHandle( handle );
1420 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1421 ok( !fileDeleted, "File shouldn't have been deleted\n" );
1422 DeleteFileA( buffer );
1423
1424 /* Delete-on-close flag doesn't change file disposition until a handle is closed */
1425 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1426 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0);
1427 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1428 fdi.DoDeleteFile = FALSE;
1429 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1430 todo_wine
1431 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1432 CloseHandle( handle );
1433 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1434 ok( fileDeleted, "File should have been deleted\n" );
1435 DeleteFileA( buffer );
1436
1437 /* Delete-on-close flag sets disposition when a handle is closed and then it could be changed back */
1438 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1439 handle = CreateFileA(buffer, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0);
1440 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
1441 ok( DuplicateHandle( GetCurrentProcess(), handle, GetCurrentProcess(), &handle2, 0, FALSE, DUPLICATE_SAME_ACCESS ), "DuplicateHandle failed\n" );
1442 CloseHandle( handle );
1443 fdi.DoDeleteFile = FALSE;
1444 res = pNtSetInformationFile( handle2, &io, &fdi, sizeof fdi, FileDispositionInformation );
1445 todo_wine
1446 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1447 CloseHandle( handle2 );
1448 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1449 ok( fileDeleted, "File should have been deleted\n" );
1450 DeleteFileA( buffer );
1451
1452 /* can set disposition on a directory opened with proper access */
1453 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1454 DeleteFileA( buffer );
1455 ok( CreateDirectoryA( buffer, NULL ), "CreateDirectory failed\n" );
1456 handle = CreateFileA(buffer, DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
1457 ok( handle != INVALID_HANDLE_VALUE, "failed to open a directory\n" );
1458 fdi.DoDeleteFile = TRUE;
1459 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1460 todo_wine
1461 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1462 CloseHandle( handle );
1463 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1464 todo_wine
1465 ok( fileDeleted, "Directory should have been deleted\n" );
1466 RemoveDirectoryA( buffer );
1467
1468 /* RemoveDirectory sets directory disposition and it can be undone */
1469 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1470 DeleteFileA( buffer );
1471 ok( CreateDirectoryA( buffer, NULL ), "CreateDirectory failed\n" );
1472 handle = CreateFileA(buffer, DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
1473 ok( handle != INVALID_HANDLE_VALUE, "failed to open a directory\n" );
1474 RemoveDirectoryA( buffer );
1475 fdi.DoDeleteFile = FALSE;
1476 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1477 todo_wine
1478 ok( res == STATUS_SUCCESS, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res );
1479 CloseHandle( handle );
1480 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1481 ok( !fileDeleted, "Directory shouldn't have been deleted\n" );
1482 RemoveDirectoryA( buffer );
1483
1484 /* cannot set disposition on a non-empty directory */
1485 GetTempFileNameA( tmp_path, "dis", 0, buffer );
1486 DeleteFileA( buffer );
1487 ok( CreateDirectoryA( buffer, NULL ), "CreateDirectory failed\n" );
1488 handle = CreateFileA(buffer, DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
1489 ok( handle != INVALID_HANDLE_VALUE, "failed to open a directory\n" );
1490 dirpos = lstrlenA( buffer );
1491 lstrcpyA( buffer + dirpos, "\\tst" );
1492 handle2 = CreateFileA(buffer, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0);
1493 CloseHandle( handle2 );
1494 fdi.DoDeleteFile = TRUE;
1495 res = pNtSetInformationFile( handle, &io, &fdi, sizeof fdi, FileDispositionInformation );
1496 todo_wine
1497 ok( res == STATUS_DIRECTORY_NOT_EMPTY, "unexpected FileDispositionInformation result (expected STATUS_DIRECTORY_NOT_EMPTY, got %x)\n", res );
1498 DeleteFileA( buffer );
1499 buffer[dirpos] = '\0';
1500 CloseHandle( handle );
1501 fileDeleted = GetFileAttributesA( buffer ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1502 ok( !fileDeleted, "Directory shouldn't have been deleted\n" );
1503 RemoveDirectoryA( buffer );
1504 }
1505
1506 static void test_iocompletion(void)
1507 {
1508 HANDLE h = INVALID_HANDLE_VALUE;
1509 NTSTATUS res;
1510
1511 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
1512
1513 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
1514 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
1515
1516 if ( h && h != INVALID_HANDLE_VALUE)
1517 {
1518 test_iocp_setcompletion(h);
1519 test_iocp_fileio(h);
1520 pNtClose(h);
1521 }
1522 }
1523
1524 static void test_file_name_information(void)
1525 {
1526 WCHAR *file_name, *volume_prefix, *expected;
1527 FILE_NAME_INFORMATION *info;
1528 ULONG old_redir = 1, tmp;
1529 UINT file_name_size;
1530 IO_STATUS_BLOCK io;
1531 UINT info_size;
1532 HRESULT hr;
1533 HANDLE h;
1534 UINT len;
1535
1536 /* GetVolumePathName is not present before w2k */
1537 if (!pGetVolumePathNameW) {
1538 win_skip("GetVolumePathNameW not found\n");
1539 return;
1540 }
1541
1542 file_name_size = GetSystemDirectoryW( NULL, 0 );
1543 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1544 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1545 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1546
1547 len = GetSystemDirectoryW( file_name, file_name_size );
1548 ok(len == file_name_size - 1,
1549 "GetSystemDirectoryW returned %u, expected %u.\n",
1550 len, file_name_size - 1);
1551
1552 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1553 ok(len, "GetVolumePathNameW failed.\n");
1554
1555 len = lstrlenW( volume_prefix );
1556 if (len && volume_prefix[len - 1] == '\\') --len;
1557 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1558 expected[file_name_size - len - 1] = '\0';
1559
1560 /* A bit more than we actually need, but it keeps the calculation simple. */
1561 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1562 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1563
1564 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1565 h = CreateFileW( file_name, GENERIC_READ,
1566 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1567 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1568 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1569 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1570
1571 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileNameInformation );
1572 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x.\n", hr);
1573
1574 memset( info, 0xcc, info_size );
1575 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileNameInformation );
1576 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1577 hr, STATUS_BUFFER_OVERFLOW);
1578 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1579 U(io).Status, STATUS_BUFFER_OVERFLOW);
1580 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1581 ok(info->FileName[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info->FileName[2]);
1582 ok(CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1583 "info->FileName[1] is %p, expected %p.\n",
1584 CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1585 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1586
1587 memset( info, 0xcc, info_size );
1588 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1589 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1590 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1591 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1592 ok(info->FileName[info->FileNameLength / sizeof(WCHAR)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1593 info->FileName[info->FileNameLength / sizeof(WCHAR)]);
1594 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1595 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1596 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1597 ok(io.Information == FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength,
1598 "io.Information is %lu, expected %u.\n",
1599 io.Information, FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength);
1600
1601 CloseHandle( h );
1602 HeapFree( GetProcessHeap(), 0, info );
1603 HeapFree( GetProcessHeap(), 0, expected );
1604 HeapFree( GetProcessHeap(), 0, volume_prefix );
1605
1606 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1607 {
1608 skip("Not running on WoW64, skipping test.\n");
1609 HeapFree( GetProcessHeap(), 0, file_name );
1610 return;
1611 }
1612
1613 h = CreateFileW( file_name, GENERIC_READ,
1614 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1615 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1616 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1617 HeapFree( GetProcessHeap(), 0, file_name );
1618
1619 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1620 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1621 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1622
1623 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1624 ok(len == file_name_size - 1,
1625 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1626 len, file_name_size - 1);
1627
1628 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1629 ok(len, "GetVolumePathNameW failed.\n");
1630
1631 len = lstrlenW( volume_prefix );
1632 if (len && volume_prefix[len - 1] == '\\') --len;
1633 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1634 expected[file_name_size - len - 1] = '\0';
1635
1636 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1637 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1638
1639 memset( info, 0xcc, info_size );
1640 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1641 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1642 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1643 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1644 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1645
1646 CloseHandle( h );
1647 HeapFree( GetProcessHeap(), 0, info );
1648 HeapFree( GetProcessHeap(), 0, expected );
1649 HeapFree( GetProcessHeap(), 0, volume_prefix );
1650 HeapFree( GetProcessHeap(), 0, file_name );
1651 }
1652
1653 static void test_file_all_name_information(void)
1654 {
1655 WCHAR *file_name, *volume_prefix, *expected;
1656 FILE_ALL_INFORMATION *info;
1657 ULONG old_redir = 1, tmp;
1658 UINT file_name_size;
1659 IO_STATUS_BLOCK io;
1660 UINT info_size;
1661 HRESULT hr;
1662 HANDLE h;
1663 UINT len;
1664
1665 /* GetVolumePathName is not present before w2k */
1666 if (!pGetVolumePathNameW) {
1667 win_skip("GetVolumePathNameW not found\n");
1668 return;
1669 }
1670
1671 file_name_size = GetSystemDirectoryW( NULL, 0 );
1672 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1673 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1674 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1675
1676 len = GetSystemDirectoryW( file_name, file_name_size );
1677 ok(len == file_name_size - 1,
1678 "GetSystemDirectoryW returned %u, expected %u.\n",
1679 len, file_name_size - 1);
1680
1681 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1682 ok(len, "GetVolumePathNameW failed.\n");
1683
1684 len = lstrlenW( volume_prefix );
1685 if (len && volume_prefix[len - 1] == '\\') --len;
1686 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1687 expected[file_name_size - len - 1] = '\0';
1688
1689 /* A bit more than we actually need, but it keeps the calculation simple. */
1690 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1691 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1692
1693 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1694 h = CreateFileW( file_name, GENERIC_READ,
1695 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1696 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1697 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1698 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1699
1700 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileAllInformation );
1701 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x, expected %#x.\n",
1702 hr, STATUS_INFO_LENGTH_MISMATCH);
1703
1704 memset( info, 0xcc, info_size );
1705 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileAllInformation );
1706 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1707 hr, STATUS_BUFFER_OVERFLOW);
1708 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1709 U(io).Status, STATUS_BUFFER_OVERFLOW);
1710 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1711 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1712 ok(info->NameInformation.FileName[2] == 0xcccc,
1713 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info->NameInformation.FileName[2]);
1714 ok(CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1715 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1716 CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1717 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1718
1719 memset( info, 0xcc, info_size );
1720 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1721 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1722 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1723 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1724 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1725 ok(info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] == 0xcccc,
1726 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1727 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)]);
1728 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1729 ok(!lstrcmpiW( info->NameInformation.FileName, expected ),
1730 "info->NameInformation.FileName is %s, expected %s.\n",
1731 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1732 ok(io.Information == FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName)
1733 + info->NameInformation.FileNameLength,
1734 "io.Information is %lu\n", io.Information );
1735
1736 CloseHandle( h );
1737 HeapFree( GetProcessHeap(), 0, info );
1738 HeapFree( GetProcessHeap(), 0, expected );
1739 HeapFree( GetProcessHeap(), 0, volume_prefix );
1740
1741 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1742 {
1743 skip("Not running on WoW64, skipping test.\n");
1744 HeapFree( GetProcessHeap(), 0, file_name );
1745 return;
1746 }
1747
1748 h = CreateFileW( file_name, GENERIC_READ,
1749 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1750 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1751 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1752 HeapFree( GetProcessHeap(), 0, file_name );
1753
1754 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1755 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1756 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1757
1758 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1759 ok(len == file_name_size - 1,
1760 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1761 len, file_name_size - 1);
1762
1763 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1764 ok(len, "GetVolumePathNameW failed.\n");
1765
1766 len = lstrlenW( volume_prefix );
1767 if (len && volume_prefix[len - 1] == '\\') --len;
1768 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1769 expected[file_name_size - len - 1] = '\0';
1770
1771 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1772 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1773
1774 memset( info, 0xcc, info_size );
1775 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1776 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1777 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1778 ok(!lstrcmpiW( info->NameInformation.FileName, expected ), "info->NameInformation.FileName is %s, expected %s.\n",
1779 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1780
1781 CloseHandle( h );
1782 HeapFree( GetProcessHeap(), 0, info );
1783 HeapFree( GetProcessHeap(), 0, expected );
1784 HeapFree( GetProcessHeap(), 0, volume_prefix );
1785 HeapFree( GetProcessHeap(), 0, file_name );
1786 }
1787
1788 static void test_query_volume_information_file(void)
1789 {
1790 NTSTATUS status;
1791 HANDLE dir;
1792 WCHAR path[MAX_PATH];
1793 OBJECT_ATTRIBUTES attr;
1794 IO_STATUS_BLOCK io;
1795 UNICODE_STRING nameW;
1796 FILE_FS_VOLUME_INFORMATION *ffvi;
1797 BYTE buf[sizeof(FILE_FS_VOLUME_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
1798
1799 GetWindowsDirectoryW( path, MAX_PATH );
1800 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
1801 attr.Length = sizeof(attr);
1802 attr.RootDirectory = 0;
1803 attr.ObjectName = &nameW;
1804 attr.Attributes = OBJ_CASE_INSENSITIVE;
1805 attr.SecurityDescriptor = NULL;
1806 attr.SecurityQualityOfService = NULL;
1807
1808 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
1809 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
1810 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
1811 pRtlFreeUnicodeString( &nameW );
1812
1813 ZeroMemory( buf, sizeof(buf) );
1814 U(io).Status = 0xdadadada;
1815 io.Information = 0xcacacaca;
1816
1817 status = pNtQueryVolumeInformationFile( dir, &io, buf, sizeof(buf), FileFsVolumeInformation );
1818
1819 ffvi = (FILE_FS_VOLUME_INFORMATION *)buf;
1820
1821 todo_wine
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
1826 ok(io.Information == (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + ffvi->VolumeLabelLength),
1827 "expected %d, got %lu\n", (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION, VolumeLabel) + ffvi->VolumeLabelLength),
1828 io.Information);
1829
1830 ok(ffvi->VolumeCreationTime.QuadPart != 0, "Missing VolumeCreationTime\n");
1831 ok(ffvi->VolumeSerialNumber != 0, "Missing VolumeSerialNumber\n");
1832 ok(ffvi->SupportsObjects == 1,"expected 1, got %d\n", ffvi->SupportsObjects);
1833 }
1834 ok(ffvi->VolumeLabelLength == lstrlenW(ffvi->VolumeLabel) * sizeof(WCHAR), "got %d\n", ffvi->VolumeLabelLength);
1835
1836 trace("VolumeSerialNumber: %x VolumeLabelName: %s\n", ffvi->VolumeSerialNumber, wine_dbgstr_w(ffvi->VolumeLabel));
1837
1838 CloseHandle( dir );
1839 }
1840
1841 static void test_query_attribute_information_file(void)
1842 {
1843 NTSTATUS status;
1844 HANDLE dir;
1845 WCHAR path[MAX_PATH];
1846 OBJECT_ATTRIBUTES attr;
1847 IO_STATUS_BLOCK io;
1848 UNICODE_STRING nameW;
1849 FILE_FS_ATTRIBUTE_INFORMATION *ffai;
1850 BYTE buf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
1851
1852 GetWindowsDirectoryW( path, MAX_PATH );
1853 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
1854 attr.Length = sizeof(attr);
1855 attr.RootDirectory = 0;
1856 attr.ObjectName = &nameW;
1857 attr.Attributes = OBJ_CASE_INSENSITIVE;
1858 attr.SecurityDescriptor = NULL;
1859 attr.SecurityQualityOfService = NULL;
1860
1861 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
1862 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
1863 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
1864 pRtlFreeUnicodeString( &nameW );
1865
1866 ZeroMemory( buf, sizeof(buf) );
1867 U(io).Status = 0xdadadada;
1868 io.Information = 0xcacacaca;
1869
1870 status = pNtQueryVolumeInformationFile( dir, &io, buf, sizeof(buf), FileFsAttributeInformation );
1871
1872 ffai = (FILE_FS_ATTRIBUTE_INFORMATION *)buf;
1873
1874 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", status);
1875 ok(U(io).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %d\n", U(io).Status);
1876 ok(ffai->FileSystemAttribute != 0, "Missing FileSystemAttribute\n");
1877 ok(ffai->MaximumComponentNameLength != 0, "Missing MaximumComponentNameLength\n");
1878 ok(ffai->FileSystemNameLength != 0, "Missing FileSystemNameLength\n");
1879
1880 trace("FileSystemAttribute: %x MaximumComponentNameLength: %x FileSystemName: %s\n",
1881 ffai->FileSystemAttribute, ffai->MaximumComponentNameLength,
1882 wine_dbgstr_wn(ffai->FileSystemName, ffai->FileSystemNameLength / sizeof(WCHAR)));
1883
1884 CloseHandle( dir );
1885 }
1886
1887 static void test_NtCreateFile(void)
1888 {
1889 static const struct test_data
1890 {
1891 DWORD disposition, attrib_in, status, result, attrib_out, needs_cleanup;
1892 } td[] =
1893 {
1894 /* 0*/{ FILE_CREATE, FILE_ATTRIBUTE_READONLY, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1895 /* 1*/{ FILE_CREATE, 0, STATUS_OBJECT_NAME_COLLISION, 0, 0, TRUE },
1896 /* 2*/{ FILE_CREATE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1897 /* 3*/{ FILE_OPEN, FILE_ATTRIBUTE_READONLY, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE, TRUE },
1898 /* 4*/{ FILE_OPEN, FILE_ATTRIBUTE_READONLY, STATUS_OBJECT_NAME_NOT_FOUND, 0, 0, FALSE },
1899 /* 5*/{ FILE_OPEN_IF, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1900 /* 6*/{ FILE_OPEN_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE, TRUE },
1901 /* 7*/{ FILE_OPEN_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1902 /* 8*/{ FILE_OPEN_IF, 0, 0, FILE_OPENED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1903 /* 9*/{ FILE_OVERWRITE, 0, STATUS_ACCESS_DENIED, 0, 0, TRUE },
1904 /*10*/{ FILE_OVERWRITE, 0, STATUS_OBJECT_NAME_NOT_FOUND, 0, 0, FALSE },
1905 /*11*/{ FILE_CREATE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1906 /*12*/{ FILE_OVERWRITE, FILE_ATTRIBUTE_READONLY, 0, FILE_OVERWRITTEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1907 /*13*/{ FILE_OVERWRITE_IF, 0, STATUS_ACCESS_DENIED, 0, 0, TRUE },
1908 /*14*/{ FILE_OVERWRITE_IF, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1909 /*15*/{ FILE_OVERWRITE_IF, FILE_ATTRIBUTE_READONLY, 0, FILE_OVERWRITTEN, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, FALSE },
1910 /*16*/{ FILE_SUPERSEDE, 0, 0, FILE_SUPERSEDED, FILE_ATTRIBUTE_ARCHIVE, FALSE },
1911 /*17*/{ FILE_SUPERSEDE, FILE_ATTRIBUTE_READONLY, 0, FILE_SUPERSEDED, FILE_ATTRIBUTE_ARCHIVE|FILE_ATTRIBUTE_READONLY, TRUE },
1912 /*18*/{ FILE_SUPERSEDE, 0, 0, FILE_CREATED, FILE_ATTRIBUTE_ARCHIVE, TRUE }
1913 };
1914 static const WCHAR fooW[] = {'f','o','o',0};
1915 NTSTATUS status;
1916 HANDLE handle;
1917 WCHAR path[MAX_PATH];
1918 OBJECT_ATTRIBUTES attr;
1919 IO_STATUS_BLOCK io;
1920 UNICODE_STRING nameW;
1921 DWORD ret, i;
1922
1923 GetTempPathW(MAX_PATH, path);
1924 GetTempFileNameW(path, fooW, 0, path);
1925 DeleteFileW(path);
1926 pRtlDosPathNameToNtPathName_U(path, &nameW, NULL, NULL);
1927
1928 attr.Length = sizeof(attr);
1929 attr.RootDirectory = NULL;
1930 attr.ObjectName = &nameW;
1931 attr.Attributes = OBJ_CASE_INSENSITIVE;
1932 attr.SecurityDescriptor = NULL;
1933 attr.SecurityQualityOfService = NULL;
1934
1935 for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
1936 {
1937 status = pNtCreateFile(&handle, GENERIC_READ, &attr, &io, NULL,
1938 td[i].attrib_in, FILE_SHARE_READ|FILE_SHARE_WRITE,
1939 td[i].disposition, 0, NULL, 0);
1940
1941 ok(status == td[i].status, "%d: expected %#x got %#x\n", i, td[i].status, status);
1942
1943 if (!status)
1944 {
1945 ok(io.Information == td[i].result,"%d: expected %#x got %#lx\n", i, td[i].result, io.Information);
1946
1947 ret = GetFileAttributesW(path);
1948 ret &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
1949 /* FIXME: leave only 'else' case below once Wine is fixed */
1950 if (ret != td[i].attrib_out)
1951 {
1952 todo_wine
1953 ok(ret == td[i].attrib_out, "%d: expected %#x got %#x\n", i, td[i].attrib_out, ret);
1954 SetFileAttributesW(path, td[i].attrib_out);
1955 }
1956 else
1957 ok(ret == td[i].attrib_out, "%d: expected %#x got %#x\n", i, td[i].attrib_out, ret);
1958
1959 CloseHandle(handle);
1960 }
1961
1962 if (td[i].needs_cleanup)
1963 {
1964 SetFileAttributesW(path, FILE_ATTRIBUTE_ARCHIVE);
1965 DeleteFileW(path);
1966 }
1967 }
1968
1969 SetFileAttributesW(path, FILE_ATTRIBUTE_ARCHIVE);
1970 DeleteFileW( path );
1971 }
1972
1973 static void test_read_write(void)
1974 {
1975 static const char contents[14] = "1234567890abcd";
1976 char buf[256];
1977 HANDLE hfile;
1978 OVERLAPPED ovl;
1979 IO_STATUS_BLOCK iob;
1980 DWORD ret, bytes, status, off;
1981 LARGE_INTEGER offset;
1982 LONG i;
1983
1984 U(iob).Status = -1;
1985 iob.Information = -1;
1986 offset.QuadPart = 0;
1987 status = pNtReadFile(INVALID_HANDLE_VALUE, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
1988 ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE, "expected STATUS_OBJECT_TYPE_MISMATCH, got %#x\n", status);
1989 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
1990 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
1991
1992 U(iob).Status = -1;
1993 iob.Information = -1;
1994 offset.QuadPart = 0;
1995 status = pNtWriteFile(INVALID_HANDLE_VALUE, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
1996 ok(status == STATUS_OBJECT_TYPE_MISMATCH || status == STATUS_INVALID_HANDLE, "expected STATUS_OBJECT_TYPE_MISMATCH, got %#x\n", status);
1997 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
1998 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
1999
2000 hfile = create_temp_file(0);
2001 if (!hfile) return;
2002
2003 U(iob).Status = -1;
2004 iob.Information = -1;
2005 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, NULL, sizeof(contents), NULL, NULL);
2006 ok(status == STATUS_INVALID_USER_BUFFER, "expected STATUS_INVALID_USER_BUFFER, got %#x\n", status);
2007 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2008 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
2009
2010 U(iob).Status = -1;
2011 iob.Information = -1;
2012 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, NULL, sizeof(contents), NULL, NULL);
2013 ok(status == STATUS_ACCESS_VIOLATION, "expected STATUS_ACCESS_VIOLATION, got %#x\n", status);
2014 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2015 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
2016
2017 U(iob).Status = -1;
2018 iob.Information = -1;
2019 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, 7, NULL, NULL);
2020 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
2021 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2022 ok(iob.Information == 7, "expected 7, got %lu\n", iob.Information);
2023
2024 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2025
2026 U(iob).Status = -1;
2027 iob.Information = -1;
2028 offset.QuadPart = (LONGLONG)-1 /* FILE_WRITE_TO_END_OF_FILE */;
2029 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents + 7, sizeof(contents) - 7, &offset, NULL);
2030 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
2031 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2032 ok(iob.Information == sizeof(contents) - 7, "expected sizeof(contents)-7, got %lu\n", iob.Information);
2033
2034 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2035 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2036
2037 bytes = 0xdeadbeef;
2038 SetLastError(0xdeadbeef);
2039 ret = ReadFile(INVALID_HANDLE_VALUE, buf, 0, &bytes, NULL);
2040 ok(!ret, "ReadFile should fail\n");
2041 ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
2042 ok(bytes == 0, "bytes %u\n", bytes);
2043
2044 bytes = 0xdeadbeef;
2045 SetLastError(0xdeadbeef);
2046 ret = ReadFile(hfile, buf, 0, &bytes, NULL);
2047 ok(ret, "ReadFile error %d\n", GetLastError());
2048 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2049 ok(bytes == 0, "bytes %u\n", bytes);
2050
2051 bytes = 0xdeadbeef;
2052 SetLastError(0xdeadbeef);
2053 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2054 ok(ret, "ReadFile error %d\n", GetLastError());
2055 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2056 ok(bytes == 0, "bytes %u\n", bytes);
2057
2058 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2059
2060 bytes = 0;
2061 SetLastError(0xdeadbeef);
2062 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2063 ok(ret, "ReadFile error %d\n", GetLastError());
2064 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2065 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
2066
2067 for (i = -20; i < -1; i++)
2068 {
2069 if (i == -2) continue;
2070
2071 U(iob).Status = -1;
2072 iob.Information = -1;
2073 offset.QuadPart = (LONGLONG)i;
2074 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), &offset, NULL);
2075 ok(status == STATUS_INVALID_PARAMETER, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i, status);
2076 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2077 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2078 }
2079
2080 SetFilePointer(hfile, sizeof(contents) - 4, NULL, FILE_BEGIN);
2081
2082 U(iob).Status = -1;
2083 iob.Information = -1;
2084 offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2085 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, "DCBA", 4, &offset, NULL);
2086 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
2087 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2088 ok(iob.Information == 4, "expected 4, got %lu\n", iob.Information);
2089
2090 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2091 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2092
2093 U(iob).Status = -1;
2094 iob.Information = -1;
2095 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), NULL, NULL);
2096 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2097 ok(U(iob).Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", U(iob).Status);
2098 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2099
2100 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2101
2102 bytes = 0;
2103 SetLastError(0xdeadbeef);
2104 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2105 ok(ret, "ReadFile error %d\n", GetLastError());
2106 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2107 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2108 ok(!memcmp(buf + sizeof(contents) - 4, "DCBA", 4), "file contents mismatch\n");
2109
2110 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2111 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2112
2113 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2114
2115 bytes = 0;
2116 SetLastError(0xdeadbeef);
2117 ret = WriteFile(hfile, contents, sizeof(contents), &bytes, NULL);
2118 ok(ret, "WriteFile error %d\n", GetLastError());
2119 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2120
2121 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2122 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2123
2124 /* test reading beyond EOF */
2125 bytes = -1;
2126 SetLastError(0xdeadbeef);
2127 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2128 ok(ret, "ReadFile error %d\n", GetLastError());
2129 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2130 ok(bytes == 0, "bytes %u\n", bytes);
2131
2132 bytes = -1;
2133 SetLastError(0xdeadbeef);
2134 ret = ReadFile(hfile, buf, 0, &bytes, NULL);
2135 ok(ret, "ReadFile error %d\n", GetLastError());
2136 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2137 ok(bytes == 0, "bytes %u\n", bytes);
2138
2139 bytes = -1;
2140 SetLastError(0xdeadbeef);
2141 ret = ReadFile(hfile, NULL, 0, &bytes, NULL);
2142 ok(ret, "ReadFile error %d\n", GetLastError());
2143 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2144 ok(bytes == 0, "bytes %u\n", bytes);
2145
2146 S(U(ovl)).Offset = sizeof(contents);
2147 S(U(ovl)).OffsetHigh = 0;
2148 ovl.Internal = -1;
2149 ovl.InternalHigh = -1;
2150 ovl.hEvent = 0;
2151 bytes = -1;
2152 SetLastError(0xdeadbeef);
2153 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2154 ok(!ret, "ReadFile should fail\n");
2155 ok(GetLastError() == ERROR_HANDLE_EOF, "expected ERROR_HANDLE_EOF, got %d\n", GetLastError());
2156 ok(bytes == 0, "bytes %u\n", bytes);
2157 ok((NTSTATUS)ovl.Internal == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#lx\n", ovl.Internal);
2158 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2159
2160 S(U(ovl)).Offset = sizeof(contents);
2161 S(U(ovl)).OffsetHigh = 0;
2162 ovl.Internal = -1;
2163 ovl.InternalHigh = -1;
2164 ovl.hEvent = 0;
2165 bytes = -1;
2166 SetLastError(0xdeadbeef);
2167 ret = ReadFile(hfile, buf, 0, &bytes, &ovl);
2168 ok(ret, "ReadFile error %d\n", GetLastError());
2169 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2170 ok(bytes == 0, "bytes %u\n", bytes);
2171 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2172 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2173
2174 U(iob).Status = -1;
2175 iob.Information = -1;
2176 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), NULL, NULL);
2177 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2178 ok(U(iob).Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", U(iob).Status);
2179 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2180
2181 U(iob).Status = -1;
2182 iob.Information = -1;
2183 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, 0, NULL, NULL);
2184 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
2185 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2186 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2187
2188 U(iob).Status = -1;
2189 iob.Information = -1;
2190 offset.QuadPart = sizeof(contents);
2191 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2192 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2193 ok(U(iob).Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", U(iob).Status);
2194 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2195
2196 U(iob).Status = -1;
2197 iob.Information = -1;
2198 offset.QuadPart = sizeof(contents);
2199 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, 0, &offset, NULL);
2200 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
2201 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2202 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2203
2204 U(iob).Status = -1;
2205 iob.Information = -1;
2206 offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2207 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2208 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2209 ok(U(iob).Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", U(iob).Status);
2210 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2211
2212 U(iob).Status = -1;
2213 iob.Information = -1;
2214 offset.QuadPart = (LONGLONG)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2215 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, 0, &offset, NULL);
2216 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
2217 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2218 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2219
2220 for (i = -20; i < 0; i++)
2221 {
2222 if (i == -2) continue;
2223
2224 U(iob).Status = -1;
2225 iob.Information = -1;
2226 offset.QuadPart = (LONGLONG)i;
2227 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2228 ok(status == STATUS_INVALID_PARAMETER, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i, status);
2229 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2230 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2231 }
2232
2233 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2234
2235 bytes = 0;
2236 SetLastError(0xdeadbeef);
2237 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2238 ok(ret, "ReadFile error %d\n", GetLastError());
2239 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2240 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
2241
2242 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2243 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2244
2245 U(iob).Status = -1;
2246 iob.Information = -1;
2247 offset.QuadPart = 0;
2248 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2249 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
2250 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2251 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2252 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
2253
2254 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2255 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2256
2257 U(iob).Status = -1;
2258 iob.Information = -1;
2259 offset.QuadPart = sizeof(contents) - 4;
2260 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, "DCBA", 4, &offset, NULL);
2261 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
2262 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2263 ok(iob.Information == 4, "expected 4, got %lu\n", iob.Information);
2264
2265 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2266 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2267
2268 U(iob).Status = -1;
2269 iob.Information = -1;
2270 offset.QuadPart = 0;
2271 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2272 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
2273 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2274 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2275 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2276 ok(!memcmp(buf + sizeof(contents) - 4, "DCBA", 4), "file contents mismatch\n");
2277
2278 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2279 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2280
2281 S(U(ovl)).Offset = sizeof(contents) - 4;
2282 S(U(ovl)).OffsetHigh = 0;
2283 ovl.hEvent = 0;
2284 bytes = 0;
2285 SetLastError(0xdeadbeef);
2286 ret = WriteFile(hfile, "ABCD", 4, &bytes, &ovl);
2287 ok(ret, "WriteFile error %d\n", GetLastError());
2288 ok(bytes == 4, "bytes %u\n", bytes);
2289
2290 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2291 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2292
2293 S(U(ovl)).Offset = 0;
2294 S(U(ovl)).OffsetHigh = 0;
2295 ovl.Internal = -1;
2296 ovl.InternalHigh = -1;
2297 ovl.hEvent = 0;
2298 bytes = 0;
2299 SetLastError(0xdeadbeef);
2300 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2301 ok(ret, "ReadFile error %d\n", GetLastError());
2302 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2303 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2304 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2305 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2306 ok(!memcmp(buf + sizeof(contents) - 4, "ABCD", 4), "file contents mismatch\n");
2307
2308 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2309 ok(off == sizeof(contents), "expected sizeof(contents), got %u\n", off);
2310
2311 CloseHandle(hfile);
2312
2313 hfile = create_temp_file(FILE_FLAG_OVERLAPPED);
2314 if (!hfile) return;
2315
2316 bytes = 0xdeadbeef;
2317 SetLastError(0xdeadbeef);
2318 ret = ReadFile(INVALID_HANDLE_VALUE, buf, 0, &bytes, NULL);
2319 ok(!ret, "ReadFile should fail\n");
2320 ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
2321 ok(bytes == 0, "bytes %u\n", bytes);
2322
2323 S(U(ovl)).Offset = 0;
2324 S(U(ovl)).OffsetHigh = 0;
2325 ovl.Internal = -1;
2326 ovl.InternalHigh = -1;
2327 ovl.hEvent = 0;
2328 bytes = 0xdeadbeef;
2329 SetLastError(0xdeadbeef);
2330 /* ReadFile return value depends on Windows version and testing it is not practical */
2331 ReadFile(hfile, buf, 0, &bytes, &ovl);
2332 ok(bytes == 0, "bytes %u\n", bytes);
2333 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2334 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2335
2336 bytes = 0xdeadbeef;
2337 SetLastError(0xdeadbeef);
2338 ret = WriteFile(hfile, contents, sizeof(contents), &bytes, NULL);
2339 ok(!ret, "WriteFile should fail\n");
2340 ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2341 ok(bytes == 0, "bytes %u\n", bytes);
2342
2343 U(iob).Status = -1;
2344 iob.Information = -1;
2345 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), NULL, NULL);
2346 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got %#x\n", status);
2347 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2348 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2349
2350 for (i = -20; i < -1; i++)
2351 {
2352 U(iob).Status = -1;
2353 iob.Information = -1;
2354 offset.QuadPart = (LONGLONG)i;
2355 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), &offset, NULL);
2356 ok(status == STATUS_INVALID_PARAMETER, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i, status);
2357 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2358 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2359 }
2360
2361 U(iob).Status = -1;
2362 iob.Information = -1;
2363 offset.QuadPart = 0;
2364 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, contents, sizeof(contents), &offset, NULL);
2365 ok(status == STATUS_PENDING || status == STATUS_SUCCESS /* before Vista */, "expected STATUS_PENDING or STATUS_SUCCESS, got %#x\n", status);
2366 if (status == STATUS_PENDING)
2367 {
2368 ret = WaitForSingleObject(hfile, 3000);
2369 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2370 }
2371 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2372 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2373
2374 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2375 ok(off == 0, "expected 0, got %u\n", off);
2376
2377 bytes = 0xdeadbeef;
2378 SetLastError(0xdeadbeef);
2379 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
2380 ok(!ret, "ReadFile should fail\n");
2381 ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2382 ok(bytes == 0, "bytes %u\n", bytes);
2383
2384 U(iob).Status = -1;
2385 iob.Information = -1;
2386 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), NULL, NULL);
2387 ok(status == STATUS_INVALID_PARAMETER, "expected STATUS_INVALID_PARAMETER, got %#x\n", status);
2388 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2389 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2390
2391 for (i = -20; i < 0; i++)
2392 {
2393 U(iob).Status = -1;
2394 iob.Information = -1;
2395 offset.QuadPart = (LONGLONG)i;
2396 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2397 ok(status == STATUS_INVALID_PARAMETER, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i, status);
2398 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2399 ok(iob.Information == -1, "expected -1, got %ld\n", iob.Information);
2400 }
2401
2402 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2403 ok(off == 0, "expected 0, got %u\n", off);
2404
2405 /* test reading beyond EOF */
2406 offset.QuadPart = sizeof(contents);
2407 S(U(ovl)).Offset = offset.u.LowPart;
2408 S(U(ovl)).OffsetHigh = offset.u.HighPart;
2409 ovl.Internal = -1;
2410 ovl.InternalHigh = -1;
2411 ovl.hEvent = 0;
2412 bytes = 0xdeadbeef;
2413 SetLastError(0xdeadbeef);
2414 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2415 ok(!ret, "ReadFile should fail\n");
2416 ret = GetLastError();
2417 ok(ret == ERROR_IO_PENDING || ret == ERROR_HANDLE_EOF /* before Vista */, "expected ERROR_IO_PENDING or ERROR_HANDLE_EOF, got %d\n", ret);
2418 ok(bytes == 0, "bytes %u\n", bytes);
2419
2420 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2421 ok(off == 0, "expected 0, got %u\n", off);
2422
2423 if (ret == ERROR_IO_PENDING)
2424 {
2425 bytes = 0xdeadbeef;
2426 SetLastError(0xdeadbeef);
2427 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2428 ok(!ret, "GetOverlappedResult should report FALSE\n");
2429 ok(GetLastError() == ERROR_HANDLE_EOF, "expected ERROR_HANDLE_EOF, got %d\n", GetLastError());
2430 ok(bytes == 0, "expected 0, read %u\n", bytes);
2431 ok((NTSTATUS)ovl.Internal == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#lx\n", ovl.Internal);
2432 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2433 }
2434
2435 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2436 ok(off == 0, "expected 0, got %u\n", off);
2437
2438 offset.QuadPart = sizeof(contents);
2439 S(U(ovl)).Offset = offset.u.LowPart;
2440 S(U(ovl)).OffsetHigh = offset.u.HighPart;
2441 ovl.Internal = -1;
2442 ovl.InternalHigh = -1;
2443 ovl.hEvent = 0;
2444 bytes = 0xdeadbeef;
2445 SetLastError(0xdeadbeef);
2446 ret = ReadFile(hfile, buf, 0, &bytes, &ovl);
2447 /* ReadFile return value depends on Windows version and testing it is not practical */
2448 if (!ret)
2449 todo_wine
2450 ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2451 ret = GetLastError();
2452 ok(bytes == 0, "bytes %u\n", bytes);
2453
2454 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2455 ok(off == 0, "expected 0, got %u\n", off);
2456
2457 if (ret == ERROR_IO_PENDING)
2458 {
2459 bytes = 0xdeadbeef;
2460 SetLastError(0xdeadbeef);
2461 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2462 ok(ret, "GetOverlappedResult should report TRUE\n");
2463 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2464 ok(bytes == 0, "expected 0, read %u\n", bytes);
2465 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2466 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2467 }
2468
2469 offset.QuadPart = sizeof(contents);
2470 S(U(ovl)).Offset = offset.u.LowPart;
2471 S(U(ovl)).OffsetHigh = offset.u.HighPart;
2472 ovl.Internal = -1;
2473 ovl.InternalHigh = -1;
2474 ovl.hEvent = 0;
2475 bytes = 0xdeadbeef;
2476 SetLastError(0xdeadbeef);
2477 ret = ReadFile(hfile, NULL, 0, &bytes, &ovl);
2478 /* ReadFile return value depends on Windows version and testing it is not practical */
2479 if (!ret)
2480 todo_wine
2481 ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2482 ret = GetLastError();
2483 ok(bytes == 0, "bytes %u\n", bytes);
2484
2485 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2486 ok(off == 0, "expected 0, got %u\n", off);
2487
2488 if (ret == ERROR_IO_PENDING)
2489 {
2490 bytes = 0xdeadbeef;
2491 SetLastError(0xdeadbeef);
2492 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2493 ok(ret, "GetOverlappedResult should report TRUE\n");
2494 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2495 ok(bytes == 0, "expected 0, read %u\n", bytes);
2496 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2497 ok(ovl.InternalHigh == 0, "expected 0, got %lu\n", ovl.InternalHigh);
2498 }
2499
2500 U(iob).Status = -1;
2501 iob.Information = -1;
2502 offset.QuadPart = sizeof(contents);
2503 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2504 if (status == STATUS_PENDING)
2505 {
2506 ret = WaitForSingleObject(hfile, 3000);
2507 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2508 ok(U(iob).Status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", U(iob).Status);
2509 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2510 }
2511 else
2512 {
2513 ok(status == STATUS_END_OF_FILE, "expected STATUS_END_OF_FILE, got %#x\n", status);
2514 ok(U(iob).Status == -1, "expected -1, got %#x\n", U(iob).Status);
2515 ok(iob.Information == -1, "expected -1, got %lu\n", iob.Information);
2516 }
2517
2518 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2519 ok(off == 0, "expected 0, got %u\n", off);
2520
2521 U(iob).Status = -1;
2522 iob.Information = -1;
2523 offset.QuadPart = sizeof(contents);
2524 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, 0, &offset, NULL);
2525 if (status == STATUS_PENDING)
2526 {
2527 ret = WaitForSingleObject(hfile, 3000);
2528 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2529 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2530 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2531 }
2532 else
2533 {
2534 ok(status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", status);
2535 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2536 ok(iob.Information == 0, "expected 0, got %lu\n", iob.Information);
2537 }
2538
2539 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2540 ok(off == 0, "expected 0, got %u\n", off);
2541
2542 S(U(ovl)).Offset = 0;
2543 S(U(ovl)).OffsetHigh = 0;
2544 ovl.Internal = -1;
2545 ovl.InternalHigh = -1;
2546 ovl.hEvent = 0;
2547 bytes = 0;
2548 SetLastError(0xdeadbeef);
2549 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2550 /* ReadFile return value depends on Windows version and testing it is not practical */
2551 if (!ret)
2552 {
2553 ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2554 ok(bytes == 0, "bytes %u\n", bytes);
2555 }
2556 else ok(bytes == 14, "bytes %u\n", bytes);
2557 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2558 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2559
2560 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2561 ok(off == 0, "expected 0, got %u\n", off);
2562
2563 bytes = 0xdeadbeef;
2564 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2565 ok(ret, "GetOverlappedResult error %d\n", GetLastError());
2566 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2567 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2568 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2569 ok(!memcmp(contents, buf, sizeof(contents)), "file contents mismatch\n");
2570
2571 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2572 ok(off == 0, "expected 0, got %u\n", off);
2573
2574 SetFilePointer(hfile, sizeof(contents) - 4, NULL, FILE_BEGIN);
2575 SetEndOfFile(hfile);
2576 SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
2577
2578 U(iob).Status = -1;
2579 iob.Information = -1;
2580 offset.QuadPart = (LONGLONG)-1 /* FILE_WRITE_TO_END_OF_FILE */;
2581 status = pNtWriteFile(hfile, 0, NULL, NULL, &iob, "DCBA", 4, &offset, NULL);
2582 ok(status == STATUS_PENDING || status == STATUS_SUCCESS /* before Vista */, "expected STATUS_PENDING or STATUS_SUCCESS, got %#x\n", status);
2583 if (status == STATUS_PENDING)
2584 {
2585 ret = WaitForSingleObject(hfile, 3000);
2586 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2587 }
2588 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2589 ok(iob.Information == 4, "expected 4, got %lu\n", iob.Information);
2590
2591 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2592 ok(off == 0, "expected 0, got %u\n", off);
2593
2594 U(iob).Status = -1;
2595 iob.Information = -1;
2596 offset.QuadPart = 0;
2597 status = pNtReadFile(hfile, 0, NULL, NULL, &iob, buf, sizeof(buf), &offset, NULL);
2598 ok(status == STATUS_PENDING || status == STATUS_SUCCESS, "expected STATUS_PENDING or STATUS_SUCCESS, got %#x\n", status);
2599 if (status == STATUS_PENDING)
2600 {
2601 ret = WaitForSingleObject(hfile, 3000);
2602 ok(ret == WAIT_OBJECT_0, "WaitForSingleObject error %d\n", ret);
2603 }
2604 ok(U(iob).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iob).Status);
2605 ok(iob.Information == sizeof(contents), "expected sizeof(contents), got %lu\n", iob.Information);
2606
2607 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2608 ok(off == 0, "expected 0, got %u\n", off);
2609
2610 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2611 ok(!memcmp(buf + sizeof(contents) - 4, "DCBA", 4), "file contents mismatch\n");
2612
2613 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2614 ok(off == 0, "expected 0, got %u\n", off);
2615
2616 S(U(ovl)).Offset = sizeof(contents) - 4;
2617 S(U(ovl)).OffsetHigh = 0;
2618 ovl.Internal = -1;
2619 ovl.InternalHigh = -1;
2620 ovl.hEvent = 0;
2621 bytes = 0;
2622 SetLastError(0xdeadbeef);
2623 ret = WriteFile(hfile, "ABCD", 4, &bytes, &ovl);
2624 /* WriteFile return value depends on Windows version and testing it is not practical */
2625 if (!ret)
2626 {
2627 ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2628 ok(bytes == 0, "bytes %u\n", bytes);
2629 }
2630 else ok(bytes == 4, "bytes %u\n", bytes);
2631 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2632 ok(ovl.InternalHigh == 4, "expected 4, got %lu\n", ovl.InternalHigh);
2633
2634 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2635 ok(off == 0, "expected 0, got %u\n", off);
2636
2637 bytes = 0xdeadbeef;
2638 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2639 ok(ret, "GetOverlappedResult error %d\n", GetLastError());
2640 ok(bytes == 4, "bytes %u\n", bytes);
2641 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2642 ok(ovl.InternalHigh == 4, "expected 4, got %lu\n", ovl.InternalHigh);
2643
2644 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2645 ok(off == 0, "expected 0, got %u\n", off);
2646
2647 S(U(ovl)).Offset = 0;
2648 S(U(ovl)).OffsetHigh = 0;
2649 ovl.Internal = -1;
2650 ovl.InternalHigh = -1;
2651 ovl.hEvent = 0;
2652 bytes = 0;
2653 SetLastError(0xdeadbeef);
2654 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, &ovl);
2655 /* ReadFile return value depends on Windows version and testing it is not practical */
2656 if (!ret)
2657 {
2658 ok(GetLastError() == ERROR_IO_PENDING, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2659 ok(bytes == 0, "bytes %u\n", bytes);
2660 }
2661 else ok(bytes == 14, "bytes %u\n", bytes);
2662 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2663 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2664
2665 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2666 ok(off == 0, "expected 0, got %u\n", off);
2667
2668 bytes = 0xdeadbeef;
2669 ret = GetOverlappedResult(hfile, &ovl, &bytes, TRUE);
2670 ok(ret, "GetOverlappedResult error %d\n", GetLastError());
2671 ok(bytes == sizeof(contents), "bytes %u\n", bytes);
2672 ok((NTSTATUS)ovl.Internal == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#lx\n", ovl.Internal);
2673 ok(ovl.InternalHigh == sizeof(contents), "expected sizeof(contents), got %lu\n", ovl.InternalHigh);
2674 ok(!memcmp(contents, buf, sizeof(contents) - 4), "file contents mismatch\n");
2675 ok(!memcmp(buf + sizeof(contents) - 4, "ABCD", 4), "file contents mismatch\n");
2676
2677 off = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
2678 ok(off == 0, "expected 0, got %u\n", off);
2679
2680 CloseHandle(hfile);
2681 }
2682
2683 START_TEST(file)
2684 {
2685 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
2686 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
2687 if (!hntdll)
2688 {
2689 skip("not running on NT, skipping test\n");
2690 return;
2691 }
2692
2693 pGetVolumePathNameW = (void *)GetProcAddress(hkernel32, "GetVolumePathNameW");
2694 pGetSystemWow64DirectoryW = (void *)GetProcAddress(hkernel32, "GetSystemWow64DirectoryW");
2695
2696 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
2697 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
2698 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
2699 pRtlWow64EnableFsRedirectionEx = (void *)GetProcAddress(hntdll, "RtlWow64EnableFsRedirectionEx");
2700 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
2701 pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile");
2702 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
2703 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
2704 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
2705 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
2706 pNtCancelIoFile = (void *)GetProcAddress(hntdll, "NtCancelIoFile");
2707 pNtCancelIoFileEx = (void *)GetProcAddress(hntdll, "NtCancelIoFileEx");
2708 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
2709 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
2710 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
2711 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
2712 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
2713 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
2714 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");
2715 pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
2716 pNtQueryDirectoryFile = (void *)GetProcAddress(hntdll, "NtQueryDirectoryFile");
2717 pNtQueryVolumeInformationFile = (void *)GetProcAddress(hntdll, "NtQueryVolumeInformationFile");
2718
2719 test_read_write();
2720 test_NtCreateFile();
2721 create_file_test();
2722 open_file_test();
2723 delete_file_test();
2724 read_file_test();
2725 append_file_test();
2726 nt_mailslot_test();
2727 test_iocompletion();
2728 test_file_basic_information();
2729 test_file_all_information();
2730 test_file_both_information();
2731 test_file_name_information();
2732 test_file_all_name_information();
2733 test_file_disposition_information();
2734 test_query_volume_information_file();
2735 test_query_attribute_information_file();
2736 }