ntdll/tests: Enumerate one by one.
[wine/hacks.git] / dlls / ntdll / tests / file.c
blob08f8139aba783ac00595db4f5fac5a07b07608d6
1 /* Unit test suite for Ntdll file functions
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
5 * Copyright 2008 Jeff Zaroyko
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES
22 * We use function pointers here as there is no import library for NTDLL on
23 * windows.
26 #include <stdio.h>
27 #include <stdarg.h>
29 #include "ntstatus.h"
30 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
31 * definition errors when we get to winnt.h
33 #define WIN32_NO_STATUS
35 #include "wine/test.h"
36 #include "winternl.h"
37 #include "winuser.h"
39 #ifndef IO_COMPLETION_ALL_ACCESS
40 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
41 #endif
43 static BOOL (WINAPI * pGetVolumePathNameW)(LPCWSTR, LPWSTR, DWORD);
44 static UINT (WINAPI *pGetSystemWow64DirectoryW)( LPWSTR, UINT );
46 static VOID (WINAPI *pRtlFreeUnicodeString)( PUNICODE_STRING );
47 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
48 static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)( LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR* );
49 static NTSTATUS (WINAPI *pRtlWow64EnableFsRedirectionEx)( ULONG, ULONG * );
51 static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
52 ULONG, ULONG, ULONG, PLARGE_INTEGER );
53 static NTSTATUS (WINAPI *pNtCreateFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,PLARGE_INTEGER,ULONG,ULONG,ULONG,ULONG,PVOID,ULONG);
54 static NTSTATUS (WINAPI *pNtOpenFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,ULONG,ULONG);
55 static NTSTATUS (WINAPI *pNtDeleteFile)(POBJECT_ATTRIBUTES ObjectAttributes);
56 static NTSTATUS (WINAPI *pNtReadFile)(HANDLE hFile, HANDLE hEvent,
57 PIO_APC_ROUTINE apc, void* apc_user,
58 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
59 PLARGE_INTEGER offset, PULONG key);
60 static NTSTATUS (WINAPI *pNtWriteFile)(HANDLE hFile, HANDLE hEvent,
61 PIO_APC_ROUTINE apc, void* apc_user,
62 PIO_STATUS_BLOCK io_status,
63 const void* buffer, ULONG length,
64 PLARGE_INTEGER offset, PULONG key);
65 static NTSTATUS (WINAPI *pNtCancelIoFile)(HANDLE hFile, PIO_STATUS_BLOCK io_status);
66 static NTSTATUS (WINAPI *pNtCancelIoFileEx)(HANDLE hFile, PIO_STATUS_BLOCK iosb, PIO_STATUS_BLOCK io_status);
67 static NTSTATUS (WINAPI *pNtClose)( PHANDLE );
69 static NTSTATUS (WINAPI *pNtCreateIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG);
70 static NTSTATUS (WINAPI *pNtOpenIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
71 static NTSTATUS (WINAPI *pNtQueryIoCompletion)(HANDLE, IO_COMPLETION_INFORMATION_CLASS, PVOID, ULONG, PULONG);
72 static NTSTATUS (WINAPI *pNtRemoveIoCompletion)(HANDLE, PULONG_PTR, PULONG_PTR, PIO_STATUS_BLOCK, PLARGE_INTEGER);
73 static NTSTATUS (WINAPI *pNtSetIoCompletion)(HANDLE, ULONG_PTR, ULONG_PTR, NTSTATUS, ULONG);
74 static NTSTATUS (WINAPI *pNtSetInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
75 static NTSTATUS (WINAPI *pNtQueryInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
76 static NTSTATUS (WINAPI *pNtQueryDirectoryFile)(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,
77 PVOID,ULONG,FILE_INFORMATION_CLASS,BOOLEAN,PUNICODE_STRING,BOOLEAN);
79 static inline BOOL is_signaled( HANDLE obj )
81 return WaitForSingleObject( obj, 0 ) == 0;
84 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
85 #define TEST_BUF_LEN 3
87 static BOOL create_pipe( HANDLE *read, HANDLE *write, ULONG flags, ULONG size )
89 *read = CreateNamedPipe(PIPENAME, PIPE_ACCESS_INBOUND | flags, PIPE_TYPE_BYTE | PIPE_WAIT,
90 1, size, size, NMPWAIT_USE_DEFAULT_WAIT, NULL);
91 ok(*read != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
93 *write = CreateFileA(PIPENAME, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
94 ok(*write != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError());
96 return TRUE;
99 static HANDLE create_temp_file( ULONG flags )
101 char buffer[MAX_PATH];
102 HANDLE handle;
104 GetTempFileNameA( ".", "foo", 0, buffer );
105 handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
106 flags | FILE_FLAG_DELETE_ON_CLOSE, 0);
107 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
108 return (handle == INVALID_HANDLE_VALUE) ? 0 : handle;
111 #define CVALUE_FIRST 0xfffabbcc
112 #define CKEY_FIRST 0x1030341
113 #define CKEY_SECOND 0x132E46
115 ULONG_PTR completionKey;
116 IO_STATUS_BLOCK ioSb;
117 ULONG_PTR completionValue;
119 static long get_pending_msgs(HANDLE h)
121 NTSTATUS res;
122 ULONG a, req;
124 res = pNtQueryIoCompletion( h, IoCompletionBasicInformation, &a, sizeof(a), &req );
125 ok( res == STATUS_SUCCESS, "NtQueryIoCompletion failed: %x\n", res );
126 if (res != STATUS_SUCCESS) return -1;
127 ok( req == sizeof(a), "Unexpected response size: %x\n", req );
128 return a;
131 static BOOL get_msg(HANDLE h)
133 LARGE_INTEGER timeout = {{-10000000*3}};
134 DWORD res = pNtRemoveIoCompletion( h, &completionKey, &completionValue, &ioSb, &timeout);
135 ok( res == STATUS_SUCCESS, "NtRemoveIoCompletion failed: %x\n", res );
136 if (res != STATUS_SUCCESS)
138 completionKey = completionValue = 0;
139 memset(&ioSb, 0, sizeof(ioSb));
140 return FALSE;
142 return TRUE;
146 static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved )
148 int *count = arg;
150 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
151 iosb, U(*iosb).Status, iosb->Information );
152 (*count)++;
153 ok( !reserved, "reserved is not 0: %x\n", reserved );
156 static void create_file_test(void)
158 static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t',
159 '\\','f','a','i','l','i','n','g',0};
160 NTSTATUS status;
161 HANDLE dir;
162 WCHAR path[MAX_PATH];
163 OBJECT_ATTRIBUTES attr;
164 IO_STATUS_BLOCK io;
165 UNICODE_STRING nameW;
166 UINT len;
168 len = GetCurrentDirectoryW( MAX_PATH, path );
169 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
170 attr.Length = sizeof(attr);
171 attr.RootDirectory = 0;
172 attr.ObjectName = &nameW;
173 attr.Attributes = OBJ_CASE_INSENSITIVE;
174 attr.SecurityDescriptor = NULL;
175 attr.SecurityQualityOfService = NULL;
177 /* try various open modes and options on directories */
178 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
179 FILE_OPEN, FILE_DIRECTORY_FILE, NULL, 0 );
180 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
181 CloseHandle( dir );
183 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
184 FILE_CREATE, FILE_DIRECTORY_FILE, NULL, 0 );
185 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
186 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
188 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
189 FILE_OPEN_IF, FILE_DIRECTORY_FILE, NULL, 0 );
190 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
191 CloseHandle( dir );
193 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
194 FILE_SUPERSEDE, FILE_DIRECTORY_FILE, NULL, 0 );
195 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
197 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
198 FILE_OVERWRITE, FILE_DIRECTORY_FILE, NULL, 0 );
199 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
201 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
202 FILE_OVERWRITE_IF, FILE_DIRECTORY_FILE, NULL, 0 );
203 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
205 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
206 FILE_OPEN, 0, NULL, 0 );
207 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
208 CloseHandle( dir );
210 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
211 FILE_CREATE, 0, NULL, 0 );
212 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
213 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
215 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
216 FILE_OPEN_IF, 0, NULL, 0 );
217 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
218 CloseHandle( dir );
220 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
221 FILE_SUPERSEDE, 0, NULL, 0 );
222 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
223 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
225 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
226 FILE_OVERWRITE, 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 );
230 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
231 FILE_OVERWRITE_IF, 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 );
235 pRtlFreeUnicodeString( &nameW );
237 pRtlInitUnicodeString( &nameW, systemrootW );
238 attr.Length = sizeof(attr);
239 attr.RootDirectory = NULL;
240 attr.ObjectName = &nameW;
241 attr.Attributes = OBJ_CASE_INSENSITIVE;
242 attr.SecurityDescriptor = NULL;
243 attr.SecurityQualityOfService = NULL;
244 dir = NULL;
245 status = pNtCreateFile( &dir, FILE_APPEND_DATA, &attr, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
246 FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
247 todo_wine
248 ok( status == STATUS_INVALID_PARAMETER,
249 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
252 static void open_file_test(void)
254 NTSTATUS status;
255 HANDLE dir, root, handle;
256 WCHAR path[MAX_PATH];
257 BYTE data[1024];
258 OBJECT_ATTRIBUTES attr;
259 IO_STATUS_BLOCK io;
260 UNICODE_STRING nameW;
261 UINT i, len;
262 BOOL restart = TRUE;
264 len = GetWindowsDirectoryW( path, MAX_PATH );
265 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
266 attr.Length = sizeof(attr);
267 attr.RootDirectory = 0;
268 attr.ObjectName = &nameW;
269 attr.Attributes = OBJ_CASE_INSENSITIVE;
270 attr.SecurityDescriptor = NULL;
271 attr.SecurityQualityOfService = NULL;
272 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
273 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
274 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
275 pRtlFreeUnicodeString( &nameW );
277 path[3] = 0; /* root of the drive */
278 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
279 status = pNtOpenFile( &root, GENERIC_READ, &attr, &io,
280 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
281 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
282 pRtlFreeUnicodeString( &nameW );
284 /* test opening system dir with RootDirectory set to windows dir */
285 GetSystemDirectoryW( path, MAX_PATH );
286 while (path[len] == '\\') len++;
287 nameW.Buffer = path + len;
288 nameW.Length = lstrlenW(path + len) * sizeof(WCHAR);
289 attr.RootDirectory = dir;
290 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
291 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
292 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
293 CloseHandle( handle );
295 /* try uppercase name */
296 for (i = len; path[i]; i++) if (path[i] >= 'a' && path[i] <= 'z') path[i] -= 'a' - 'A';
297 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
298 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
299 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
300 CloseHandle( handle );
302 /* try with leading backslash */
303 nameW.Buffer--;
304 nameW.Length += sizeof(WCHAR);
305 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
306 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
307 ok( status == STATUS_INVALID_PARAMETER ||
308 status == STATUS_OBJECT_NAME_INVALID ||
309 status == STATUS_OBJECT_PATH_SYNTAX_BAD,
310 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
311 if (!status) CloseHandle( handle );
313 /* try with empty name */
314 nameW.Length = 0;
315 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
316 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
317 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
318 CloseHandle( handle );
320 /* try open by file id */
322 while (!pNtQueryDirectoryFile( dir, NULL, NULL, NULL, &io, data, sizeof(data),
323 FileIdBothDirectoryInformation, TRUE, NULL, restart ))
325 FILE_ID_BOTH_DIRECTORY_INFORMATION *info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)data;
327 restart = FALSE;
329 if (!info->FileId.QuadPart) continue;
331 nameW.Buffer = (WCHAR *)&info->FileId;
332 nameW.Length = sizeof(info->FileId);
333 info->FileName[info->FileNameLength/sizeof(WCHAR)] = 0;
334 attr.RootDirectory = dir;
335 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
336 FILE_SHARE_READ|FILE_SHARE_WRITE,
337 FILE_OPEN_BY_FILE_ID |
338 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
339 ok( status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED || status == STATUS_NOT_IMPLEMENTED,
340 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
341 if (status == STATUS_NOT_IMPLEMENTED)
343 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
344 break;
346 if (!status)
348 FILE_ALL_INFORMATION all_info;
350 if (!pNtQueryInformationFile( handle, &io, &all_info, sizeof(all_info), FileAllInformation ))
352 /* check that it's the same file */
353 ok( info->EndOfFile.QuadPart == all_info.StandardInformation.EndOfFile.QuadPart,
354 "mismatched file size for %s\n", wine_dbgstr_w(info->FileName));
355 ok( info->LastWriteTime.QuadPart == all_info.BasicInformation.LastWriteTime.QuadPart,
356 "mismatched write time for %s\n", wine_dbgstr_w(info->FileName));
358 CloseHandle( handle );
360 /* try same thing from drive root */
361 attr.RootDirectory = root;
362 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
363 FILE_SHARE_READ|FILE_SHARE_WRITE,
364 FILE_OPEN_BY_FILE_ID |
365 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
366 ok( status == STATUS_SUCCESS || status == STATUS_NOT_IMPLEMENTED,
367 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
368 if (!status) CloseHandle( handle );
372 CloseHandle( dir );
373 CloseHandle( root );
376 static void delete_file_test(void)
378 NTSTATUS ret;
379 OBJECT_ATTRIBUTES attr;
380 UNICODE_STRING nameW;
381 WCHAR pathW[MAX_PATH];
382 WCHAR pathsubW[MAX_PATH];
383 static const WCHAR testdirW[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
384 static const WCHAR subdirW[] = {'\\','s','u','b',0};
386 ret = GetTempPathW(MAX_PATH, pathW);
387 if (!ret)
389 ok(0, "couldn't get temp dir\n");
390 return;
392 if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
394 ok(0, "MAX_PATH exceeded in constructing paths\n");
395 return;
398 lstrcatW(pathW, testdirW);
399 lstrcpyW(pathsubW, pathW);
400 lstrcatW(pathsubW, subdirW);
402 ret = CreateDirectoryW(pathW, NULL);
403 ok(ret == TRUE, "couldn't create directory ntdeletefile\n");
404 if (!pRtlDosPathNameToNtPathName_U(pathW, &nameW, NULL, NULL))
406 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
407 return;
410 attr.Length = sizeof(attr);
411 attr.RootDirectory = 0;
412 attr.Attributes = OBJ_CASE_INSENSITIVE;
413 attr.ObjectName = &nameW;
414 attr.SecurityDescriptor = NULL;
415 attr.SecurityQualityOfService = NULL;
417 /* test NtDeleteFile on an empty directory */
418 ret = pNtDeleteFile(&attr);
419 ok(ret == STATUS_SUCCESS, "NtDeleteFile should succeed in removing an empty directory\n");
420 ret = RemoveDirectoryW(pathW);
421 ok(ret == FALSE, "expected to fail removing directory, NtDeleteFile should have removed it\n");
423 /* test NtDeleteFile on a non-empty directory */
424 ret = CreateDirectoryW(pathW, NULL);
425 ok(ret == TRUE, "couldn't create directory ntdeletefile ?!\n");
426 ret = CreateDirectoryW(pathsubW, NULL);
427 ok(ret == TRUE, "couldn't create directory subdir\n");
428 ret = pNtDeleteFile(&attr);
429 ok(ret == STATUS_SUCCESS, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
430 ret = RemoveDirectoryW(pathsubW);
431 ok(ret == TRUE, "expected to remove directory ntdeletefile\\sub\n");
432 ret = RemoveDirectoryW(pathW);
433 ok(ret == TRUE, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
435 pRtlFreeUnicodeString( &nameW );
438 static void read_file_test(void)
440 const char text[] = "foobar";
441 HANDLE handle, read, write;
442 NTSTATUS status;
443 IO_STATUS_BLOCK iosb, iosb2;
444 DWORD written;
445 int apc_count = 0;
446 char buffer[128];
447 LARGE_INTEGER offset;
448 HANDLE event = CreateEventA( NULL, TRUE, FALSE, NULL );
450 buffer[0] = 1;
452 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
454 /* try read with no data */
455 U(iosb).Status = 0xdeadbabe;
456 iosb.Information = 0xdeadbeef;
457 ok( is_signaled( read ), "read handle is not signaled\n" );
458 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
459 ok( status == STATUS_PENDING, "wrong status %x\n", status );
460 ok( !is_signaled( read ), "read handle is signaled\n" );
461 ok( !is_signaled( event ), "event is signaled\n" );
462 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
463 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
464 ok( !apc_count, "apc was called\n" );
465 WriteFile( write, buffer, 1, &written, NULL );
466 /* iosb updated here by async i/o */
467 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
468 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
469 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
470 ok( !is_signaled( read ), "read handle is signaled\n" );
471 ok( is_signaled( event ), "event is not signaled\n" );
472 ok( !apc_count, "apc was called\n" );
473 apc_count = 0;
474 SleepEx( 1, FALSE ); /* non-alertable sleep */
475 ok( !apc_count, "apc was called\n" );
476 SleepEx( 1, TRUE ); /* alertable sleep */
477 ok( apc_count == 1, "apc not called\n" );
479 /* with no event, the pipe handle itself gets signaled */
480 apc_count = 0;
481 U(iosb).Status = 0xdeadbabe;
482 iosb.Information = 0xdeadbeef;
483 ok( !is_signaled( read ), "read handle is not signaled\n" );
484 status = pNtReadFile( read, 0, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
485 ok( status == STATUS_PENDING, "wrong status %x\n", status );
486 ok( !is_signaled( read ), "read handle is signaled\n" );
487 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
488 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
489 ok( !apc_count, "apc was called\n" );
490 WriteFile( write, buffer, 1, &written, NULL );
491 /* iosb updated here by async i/o */
492 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
493 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
494 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
495 ok( is_signaled( read ), "read handle is signaled\n" );
496 ok( !apc_count, "apc was called\n" );
497 apc_count = 0;
498 SleepEx( 1, FALSE ); /* non-alertable sleep */
499 ok( !apc_count, "apc was called\n" );
500 SleepEx( 1, TRUE ); /* alertable sleep */
501 ok( apc_count == 1, "apc not called\n" );
503 /* now read with data ready */
504 apc_count = 0;
505 U(iosb).Status = 0xdeadbabe;
506 iosb.Information = 0xdeadbeef;
507 ResetEvent( event );
508 WriteFile( write, buffer, 1, &written, NULL );
509 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
510 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
511 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
512 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
513 ok( is_signaled( event ), "event is not signaled\n" );
514 ok( !apc_count, "apc was called\n" );
515 SleepEx( 1, FALSE ); /* non-alertable sleep */
516 ok( !apc_count, "apc was called\n" );
517 SleepEx( 1, TRUE ); /* alertable sleep */
518 ok( apc_count == 1, "apc not called\n" );
520 /* try read with no data */
521 apc_count = 0;
522 U(iosb).Status = 0xdeadbabe;
523 iosb.Information = 0xdeadbeef;
524 ok( is_signaled( event ), "event is not signaled\n" ); /* check that read resets the event */
525 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
526 ok( status == STATUS_PENDING, "wrong status %x\n", status );
527 ok( !is_signaled( event ), "event is signaled\n" );
528 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
529 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
530 ok( !apc_count, "apc was called\n" );
531 WriteFile( write, buffer, 1, &written, NULL );
532 /* partial read is good enough */
533 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
534 ok( is_signaled( event ), "event is signaled\n" );
535 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
536 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
537 ok( !apc_count, "apc was called\n" );
538 SleepEx( 1, TRUE ); /* alertable sleep */
539 ok( apc_count == 1, "apc was not called\n" );
541 /* read from disconnected pipe */
542 apc_count = 0;
543 U(iosb).Status = 0xdeadbabe;
544 iosb.Information = 0xdeadbeef;
545 CloseHandle( write );
546 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
547 ok( status == STATUS_PIPE_BROKEN, "wrong status %x\n", status );
548 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
549 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
550 ok( !is_signaled( event ), "event is signaled\n" );
551 ok( !apc_count, "apc was called\n" );
552 SleepEx( 1, TRUE ); /* alertable sleep */
553 ok( !apc_count, "apc was called\n" );
554 CloseHandle( read );
556 /* read from closed handle */
557 apc_count = 0;
558 U(iosb).Status = 0xdeadbabe;
559 iosb.Information = 0xdeadbeef;
560 SetEvent( event );
561 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
562 ok( status == STATUS_INVALID_HANDLE, "wrong status %x\n", status );
563 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
564 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
565 ok( is_signaled( event ), "event is signaled\n" ); /* not reset on invalid handle */
566 ok( !apc_count, "apc was called\n" );
567 SleepEx( 1, TRUE ); /* alertable sleep */
568 ok( !apc_count, "apc was called\n" );
570 /* disconnect while async read is in progress */
571 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
572 apc_count = 0;
573 U(iosb).Status = 0xdeadbabe;
574 iosb.Information = 0xdeadbeef;
575 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
576 ok( status == STATUS_PENDING, "wrong status %x\n", status );
577 ok( !is_signaled( event ), "event is signaled\n" );
578 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
579 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
580 ok( !apc_count, "apc was called\n" );
581 CloseHandle( write );
582 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
583 ok( U(iosb).Status == STATUS_PIPE_BROKEN, "wrong status %x\n", U(iosb).Status );
584 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
585 ok( is_signaled( event ), "event is signaled\n" );
586 ok( !apc_count, "apc was called\n" );
587 SleepEx( 1, TRUE ); /* alertable sleep */
588 ok( apc_count == 1, "apc was not called\n" );
589 CloseHandle( read );
591 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
592 ok(DuplicateHandle(GetCurrentProcess(), read, GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS),
593 "Failed to duplicate handle: %d\n", GetLastError());
595 apc_count = 0;
596 U(iosb).Status = 0xdeadbabe;
597 iosb.Information = 0xdeadbeef;
598 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
599 ok( status == STATUS_PENDING, "wrong status %x\n", status );
600 ok( !is_signaled( event ), "event is signaled\n" );
601 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
602 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
603 ok( !apc_count, "apc was called\n" );
604 /* Cancel by other handle */
605 status = pNtCancelIoFile( read, &iosb2 );
606 ok(status == STATUS_SUCCESS, "failed to cancel by different handle: %x\n", status);
607 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
608 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
609 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
610 ok( is_signaled( event ), "event is signaled\n" );
611 todo_wine ok( !apc_count, "apc was called\n" );
612 SleepEx( 1, TRUE ); /* alertable sleep */
613 ok( apc_count == 1, "apc was not called\n" );
615 apc_count = 0;
616 U(iosb).Status = 0xdeadbabe;
617 iosb.Information = 0xdeadbeef;
618 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
619 ok( status == STATUS_PENDING, "wrong status %x\n", status );
620 ok( !is_signaled( event ), "event is signaled\n" );
621 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
622 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
623 ok( !apc_count, "apc was called\n" );
624 /* Close queued handle */
625 CloseHandle( read );
626 SleepEx( 1, TRUE ); /* alertable sleep */
627 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
628 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
629 status = pNtCancelIoFile( read, &iosb2 );
630 ok(status == STATUS_INVALID_HANDLE, "cancelled by closed handle?\n");
631 status = pNtCancelIoFile( handle, &iosb2 );
632 ok(status == STATUS_SUCCESS, "failed to cancel: %x\n", status);
633 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
634 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
635 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
636 ok( is_signaled( event ), "event is signaled\n" );
637 todo_wine ok( !apc_count, "apc was called\n" );
638 SleepEx( 1, TRUE ); /* alertable sleep */
639 ok( apc_count == 1, "apc was not called\n" );
640 CloseHandle( handle );
641 CloseHandle( write );
643 if (pNtCancelIoFileEx)
645 /* Basic Cancel Ex */
646 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
648 apc_count = 0;
649 U(iosb).Status = 0xdeadbabe;
650 iosb.Information = 0xdeadbeef;
651 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
652 ok( status == STATUS_PENDING, "wrong status %x\n", status );
653 ok( !is_signaled( event ), "event is signaled\n" );
654 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
655 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
656 ok( !apc_count, "apc was called\n" );
657 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
658 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
659 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
660 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
661 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
662 ok( is_signaled( event ), "event is signaled\n" );
663 todo_wine ok( !apc_count, "apc was called\n" );
664 SleepEx( 1, TRUE ); /* alertable sleep */
665 ok( apc_count == 1, "apc was not called\n" );
667 /* Duplicate iosb */
668 apc_count = 0;
669 U(iosb).Status = 0xdeadbabe;
670 iosb.Information = 0xdeadbeef;
671 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
672 ok( status == STATUS_PENDING, "wrong status %x\n", status );
673 ok( !is_signaled( event ), "event is signaled\n" );
674 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
675 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
676 ok( !apc_count, "apc was called\n" );
677 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
678 ok( status == STATUS_PENDING, "wrong status %x\n", status );
679 ok( !is_signaled( event ), "event is signaled\n" );
680 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
681 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
682 ok( !apc_count, "apc was called\n" );
683 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
684 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
685 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
686 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
687 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
688 ok( is_signaled( event ), "event is signaled\n" );
689 todo_wine ok( !apc_count, "apc was called\n" );
690 SleepEx( 1, TRUE ); /* alertable sleep */
691 ok( apc_count == 2, "apc was not called\n" );
693 CloseHandle( read );
694 CloseHandle( write );
697 /* now try a real file */
698 if (!(handle = create_temp_file( FILE_FLAG_OVERLAPPED ))) return;
699 apc_count = 0;
700 U(iosb).Status = 0xdeadbabe;
701 iosb.Information = 0xdeadbeef;
702 offset.QuadPart = 0;
703 ResetEvent( event );
704 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
705 ok( status == STATUS_SUCCESS || status == STATUS_PENDING, "wrong status %x\n", status );
706 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
707 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
708 ok( is_signaled( event ), "event is signaled\n" );
709 ok( !apc_count, "apc was called\n" );
710 SleepEx( 1, TRUE ); /* alertable sleep */
711 ok( apc_count == 1, "apc was not called\n" );
713 apc_count = 0;
714 U(iosb).Status = 0xdeadbabe;
715 iosb.Information = 0xdeadbeef;
716 offset.QuadPart = 0;
717 ResetEvent( event );
718 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
719 ok( status == STATUS_SUCCESS ||
720 status == STATUS_PENDING, /* vista */
721 "wrong status %x\n", status );
722 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
723 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
724 ok( is_signaled( event ), "event is signaled\n" );
725 ok( !apc_count, "apc was called\n" );
726 SleepEx( 1, TRUE ); /* alertable sleep */
727 ok( apc_count == 1, "apc was not called\n" );
729 /* read beyond eof */
730 apc_count = 0;
731 U(iosb).Status = 0xdeadbabe;
732 iosb.Information = 0xdeadbeef;
733 offset.QuadPart = strlen(text) + 2;
734 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
735 if (status == STATUS_PENDING) /* vista */
737 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
738 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
739 ok( is_signaled( event ), "event is signaled\n" );
740 ok( !apc_count, "apc was called\n" );
741 SleepEx( 1, TRUE ); /* alertable sleep */
742 ok( apc_count == 1, "apc was not called\n" );
744 else
746 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
747 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
748 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
749 ok( !is_signaled( event ), "event is signaled\n" );
750 ok( !apc_count, "apc was called\n" );
751 SleepEx( 1, TRUE ); /* alertable sleep */
752 ok( !apc_count, "apc was called\n" );
754 CloseHandle( handle );
756 /* now a non-overlapped file */
757 if (!(handle = create_temp_file(0))) return;
758 apc_count = 0;
759 U(iosb).Status = 0xdeadbabe;
760 iosb.Information = 0xdeadbeef;
761 offset.QuadPart = 0;
762 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
763 ok( status == STATUS_END_OF_FILE ||
764 status == STATUS_SUCCESS ||
765 status == STATUS_PENDING, /* vista */
766 "wrong status %x\n", status );
767 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
768 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
769 ok( is_signaled( event ), "event is signaled\n" );
770 ok( !apc_count, "apc was called\n" );
771 SleepEx( 1, TRUE ); /* alertable sleep */
772 ok( apc_count == 1, "apc was not called\n" );
774 apc_count = 0;
775 U(iosb).Status = 0xdeadbabe;
776 iosb.Information = 0xdeadbeef;
777 offset.QuadPart = 0;
778 ResetEvent( event );
779 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
780 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
781 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
782 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
783 ok( is_signaled( event ), "event is signaled\n" );
784 ok( !apc_count, "apc was called\n" );
785 SleepEx( 1, TRUE ); /* alertable sleep */
786 todo_wine ok( !apc_count, "apc was called\n" );
788 /* read beyond eof */
789 apc_count = 0;
790 U(iosb).Status = 0xdeadbabe;
791 iosb.Information = 0xdeadbeef;
792 offset.QuadPart = strlen(text) + 2;
793 ResetEvent( event );
794 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
795 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
796 todo_wine ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
797 todo_wine ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
798 todo_wine ok( is_signaled( event ), "event is not signaled\n" );
799 ok( !apc_count, "apc was called\n" );
800 SleepEx( 1, TRUE ); /* alertable sleep */
801 ok( !apc_count, "apc was called\n" );
803 CloseHandle( handle );
805 CloseHandle( event );
808 static void nt_mailslot_test(void)
810 HANDLE hslot;
811 ACCESS_MASK DesiredAccess;
812 OBJECT_ATTRIBUTES attr;
814 ULONG CreateOptions;
815 ULONG MailslotQuota;
816 ULONG MaxMessageSize;
817 LARGE_INTEGER TimeOut;
818 IO_STATUS_BLOCK IoStatusBlock;
819 NTSTATUS rc;
820 UNICODE_STRING str;
821 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
822 'R',':','\\','F','R','E','D','\0' };
824 TimeOut.QuadPart = -1;
826 pRtlInitUnicodeString(&str, buffer1);
827 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
828 CreateOptions = MailslotQuota = MaxMessageSize = 0;
829 DesiredAccess = GENERIC_READ;
832 * Check for NULL pointer handling
834 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
835 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
836 &TimeOut);
837 ok( rc == STATUS_ACCESS_VIOLATION ||
838 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
839 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
842 * Test to see if the Timeout can be NULL
844 hslot = (HANDLE)0xdeadbeef;
845 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
846 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
847 NULL);
848 ok( rc == STATUS_SUCCESS ||
849 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
850 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
851 ok( hslot != 0, "Handle is invalid\n");
853 if ( rc == STATUS_SUCCESS ) rc = pNtClose(hslot);
856 * Test that the length field is checked properly
858 attr.Length = 0;
859 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
860 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
861 &TimeOut);
862 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
864 if (rc == STATUS_SUCCESS) pNtClose(hslot);
866 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
867 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
868 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
869 &TimeOut);
870 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
872 if (rc == STATUS_SUCCESS) pNtClose(hslot);
875 * Test handling of a NULL unicode string in ObjectName
877 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
878 attr.ObjectName = NULL;
879 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
880 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
881 &TimeOut);
882 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
883 rc == STATUS_INVALID_PARAMETER,
884 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
886 if (rc == STATUS_SUCCESS) pNtClose(hslot);
889 * Test a valid call
891 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
892 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
893 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
894 &TimeOut);
895 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
896 ok( hslot != 0, "Handle is invalid\n");
898 rc = pNtClose(hslot);
899 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
902 static void test_iocp_setcompletion(HANDLE h)
904 NTSTATUS res;
905 long count;
907 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, 3 );
908 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
910 count = get_pending_msgs(h);
911 ok( count == 1, "Unexpected msg count: %ld\n", count );
913 if (get_msg(h))
915 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
916 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
917 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
918 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
921 count = get_pending_msgs(h);
922 ok( !count, "Unexpected msg count: %ld\n", count );
925 static void test_iocp_fileio(HANDLE h)
927 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
929 IO_STATUS_BLOCK iosb;
930 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
931 HANDLE hPipeSrv, hPipeClt;
932 NTSTATUS res;
934 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
935 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
936 if (hPipeSrv != INVALID_HANDLE_VALUE )
938 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
939 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
940 if (hPipeClt != INVALID_HANDLE_VALUE)
942 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
943 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
944 CloseHandle(hPipeClt);
946 CloseHandle( hPipeSrv );
949 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
950 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
951 if (hPipeSrv == INVALID_HANDLE_VALUE )
952 return;
954 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
955 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
956 if (hPipeClt != INVALID_HANDLE_VALUE)
958 OVERLAPPED o = {0,};
959 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
960 DWORD read;
961 long count;
963 NTSTATUS res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
964 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
965 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
967 memset( send_buf, 0, TEST_BUF_LEN );
968 memset( recv_buf, 0xde, TEST_BUF_LEN );
969 count = get_pending_msgs(h);
970 ok( !count, "Unexpected msg count: %ld\n", count );
971 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
972 count = get_pending_msgs(h);
973 ok( !count, "Unexpected msg count: %ld\n", count );
974 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
976 if (get_msg(h))
978 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
979 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
980 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
981 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
982 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] );
984 count = get_pending_msgs(h);
985 ok( !count, "Unexpected msg count: %ld\n", count );
987 memset( send_buf, 0, TEST_BUF_LEN );
988 memset( recv_buf, 0xde, TEST_BUF_LEN );
989 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
990 count = get_pending_msgs(h);
991 ok( !count, "Unexpected msg count: %ld\n", count );
992 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
993 count = get_pending_msgs(h);
994 ok( count == 1, "Unexpected msg count: %ld\n", count );
995 if (get_msg(h))
997 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
998 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
999 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1000 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1001 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] );
1004 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1005 CloseHandle( hPipeSrv );
1006 count = get_pending_msgs(h);
1007 ok( count == 1, "Unexpected msg count: %ld\n", count );
1008 if (get_msg(h))
1010 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1011 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1012 /* wine sends wrong status here */
1013 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1014 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1018 CloseHandle( hPipeClt );
1021 static void test_file_basic_information(void)
1023 IO_STATUS_BLOCK io;
1024 FILE_BASIC_INFORMATION fbi;
1025 HANDLE h;
1026 int res;
1027 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1029 if (!(h = create_temp_file(0))) return;
1031 /* Check default first */
1032 memset(&fbi, 0, sizeof(fbi));
1033 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1034 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1035 ok ( (fbi.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1036 "attribute %x not expected\n", fbi.FileAttributes );
1038 /* Then SYSTEM */
1039 /* Clear fbi to avoid setting times */
1040 memset(&fbi, 0, sizeof(fbi));
1041 fbi.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1042 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1043 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1045 memset(&fbi, 0, sizeof(fbi));
1046 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1047 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1048 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi.FileAttributes );
1050 /* Then HIDDEN */
1051 memset(&fbi, 0, sizeof(fbi));
1052 fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1053 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1054 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1056 memset(&fbi, 0, sizeof(fbi));
1057 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1058 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1059 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi.FileAttributes );
1061 /* Check NORMAL last of all (to make sure we can clear attributes) */
1062 memset(&fbi, 0, sizeof(fbi));
1063 fbi.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1064 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1065 ok ( res == STATUS_SUCCESS, "can't set normal attribute\n");
1067 memset(&fbi, 0, sizeof(fbi));
1068 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1069 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1070 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not 0\n", fbi.FileAttributes );
1072 CloseHandle( h );
1075 static void test_file_all_information(void)
1077 IO_STATUS_BLOCK io;
1078 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1079 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1080 * don't leave enough room there.
1082 struct {
1083 FILE_ALL_INFORMATION fai;
1084 WCHAR buf[256];
1085 } fai_buf;
1086 HANDLE h;
1087 int res;
1088 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1090 if (!(h = create_temp_file(0))) return;
1092 /* Check default first */
1093 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1094 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1095 ok ( (fai_buf.fai.BasicInformation.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1096 "attribute %x not expected\n", fai_buf.fai.BasicInformation.FileAttributes );
1098 /* Then SYSTEM */
1099 /* Clear fbi to avoid setting times */
1100 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1101 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1102 res = pNtSetInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1103 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to set FileAllInformation, res %x\n", res);
1104 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1105 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1107 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1108 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1109 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1110 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 );
1112 /* Then HIDDEN */
1113 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1114 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1115 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1116 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1118 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1119 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1120 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1121 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 );
1123 /* Check NORMAL last of all (to make sure we can clear attributes) */
1124 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1125 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1126 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1127 ok ( res == STATUS_SUCCESS, "can't set normal attribute\n");
1129 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1130 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1131 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1132 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 );
1134 CloseHandle( h );
1137 static void test_file_both_information(void)
1139 IO_STATUS_BLOCK io;
1140 FILE_BOTH_DIR_INFORMATION fbi;
1141 HANDLE h;
1142 int res;
1144 if (!(h = create_temp_file(0))) return;
1146 memset(&fbi, 0, sizeof(fbi));
1147 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBothDirectoryInformation);
1148 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res);
1150 CloseHandle( h );
1153 static void test_iocompletion(void)
1155 HANDLE h = INVALID_HANDLE_VALUE;
1156 NTSTATUS res;
1158 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
1160 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
1161 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
1163 if ( h && h != INVALID_HANDLE_VALUE)
1165 test_iocp_setcompletion(h);
1166 test_iocp_fileio(h);
1167 pNtClose(h);
1171 static void test_file_name_information(void)
1173 WCHAR *file_name, *volume_prefix, *expected;
1174 FILE_NAME_INFORMATION *info;
1175 ULONG old_redir = 1, tmp;
1176 UINT file_name_size;
1177 IO_STATUS_BLOCK io;
1178 UINT info_size;
1179 HRESULT hr;
1180 HANDLE h;
1181 UINT len;
1183 /* GetVolumePathName is not present before w2k */
1184 if (!pGetVolumePathNameW) {
1185 win_skip("GetVolumePathNameW not found\n");
1186 return;
1189 file_name_size = GetSystemDirectoryW( NULL, 0 );
1190 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1191 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1192 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1194 len = GetSystemDirectoryW( file_name, file_name_size );
1195 ok(len == file_name_size - 1,
1196 "GetSystemDirectoryW returned %u, expected %u.\n",
1197 len, file_name_size - 1);
1199 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1200 ok(len, "GetVolumePathNameW failed.\n");
1202 len = lstrlenW( volume_prefix );
1203 if (len && volume_prefix[len - 1] == '\\') --len;
1204 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1205 expected[file_name_size - len - 1] = '\0';
1207 /* A bit more than we actually need, but it keeps the calculation simple. */
1208 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1209 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1211 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1212 h = CreateFileW( file_name, GENERIC_READ,
1213 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1214 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1215 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1216 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1218 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileNameInformation );
1219 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x.\n", hr);
1221 memset( info, 0xcc, info_size );
1222 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileNameInformation );
1223 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1224 hr, STATUS_BUFFER_OVERFLOW);
1225 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1226 U(io).Status, STATUS_BUFFER_OVERFLOW);
1227 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1228 ok(info->FileName[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info->FileName[2]);
1229 ok(CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1230 "info->FileName[1] is %p, expected %p.\n",
1231 CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1232 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1234 memset( info, 0xcc, info_size );
1235 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1236 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1237 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1238 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1239 ok(info->FileName[info->FileNameLength / sizeof(WCHAR)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1240 info->FileName[info->FileNameLength / sizeof(WCHAR)]);
1241 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1242 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1243 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1244 ok(io.Information == FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength,
1245 "io.Information is %lu, expected %u.\n",
1246 io.Information, FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength);
1248 CloseHandle( h );
1249 HeapFree( GetProcessHeap(), 0, info );
1250 HeapFree( GetProcessHeap(), 0, expected );
1251 HeapFree( GetProcessHeap(), 0, volume_prefix );
1253 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1255 skip("Not running on WoW64, skipping test.\n");
1256 HeapFree( GetProcessHeap(), 0, file_name );
1257 return;
1260 h = CreateFileW( file_name, GENERIC_READ,
1261 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1262 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1263 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1264 HeapFree( GetProcessHeap(), 0, file_name );
1266 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1267 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1268 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1270 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1271 ok(len == file_name_size - 1,
1272 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1273 len, file_name_size - 1);
1275 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1276 ok(len, "GetVolumePathNameW failed.\n");
1278 len = lstrlenW( volume_prefix );
1279 if (len && volume_prefix[len - 1] == '\\') --len;
1280 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1281 expected[file_name_size - len - 1] = '\0';
1283 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1284 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1286 memset( info, 0xcc, info_size );
1287 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1288 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1289 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1290 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1291 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1293 CloseHandle( h );
1294 HeapFree( GetProcessHeap(), 0, info );
1295 HeapFree( GetProcessHeap(), 0, expected );
1296 HeapFree( GetProcessHeap(), 0, volume_prefix );
1297 HeapFree( GetProcessHeap(), 0, file_name );
1300 static void test_file_all_name_information(void)
1302 WCHAR *file_name, *volume_prefix, *expected;
1303 FILE_ALL_INFORMATION *info;
1304 ULONG old_redir = 1, tmp;
1305 UINT file_name_size;
1306 IO_STATUS_BLOCK io;
1307 UINT info_size;
1308 HRESULT hr;
1309 HANDLE h;
1310 UINT len;
1312 /* GetVolumePathName is not present before w2k */
1313 if (!pGetVolumePathNameW) {
1314 win_skip("GetVolumePathNameW not found\n");
1315 return;
1318 file_name_size = GetSystemDirectoryW( NULL, 0 );
1319 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1320 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1321 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1323 len = GetSystemDirectoryW( file_name, file_name_size );
1324 ok(len == file_name_size - 1,
1325 "GetSystemDirectoryW returned %u, expected %u.\n",
1326 len, file_name_size - 1);
1328 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1329 ok(len, "GetVolumePathNameW failed.\n");
1331 len = lstrlenW( volume_prefix );
1332 if (len && volume_prefix[len - 1] == '\\') --len;
1333 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1334 expected[file_name_size - len - 1] = '\0';
1336 /* A bit more than we actually need, but it keeps the calculation simple. */
1337 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1338 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1340 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1341 h = CreateFileW( file_name, GENERIC_READ,
1342 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1343 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1344 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1345 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1347 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileAllInformation );
1348 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x, expected %#x.\n",
1349 hr, STATUS_INFO_LENGTH_MISMATCH);
1351 memset( info, 0xcc, info_size );
1352 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileAllInformation );
1353 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1354 hr, STATUS_BUFFER_OVERFLOW);
1355 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1356 U(io).Status, STATUS_BUFFER_OVERFLOW);
1357 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1358 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1359 ok(info->NameInformation.FileName[2] == 0xcccc,
1360 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info->NameInformation.FileName[2]);
1361 ok(CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1362 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1363 CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1364 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1366 memset( info, 0xcc, info_size );
1367 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1368 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1369 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1370 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1371 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1372 ok(info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] == 0xcccc,
1373 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1374 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)]);
1375 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1376 ok(!lstrcmpiW( info->NameInformation.FileName, expected ),
1377 "info->NameInformation.FileName is %s, expected %s.\n",
1378 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1379 ok(io.Information == FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName)
1380 + info->NameInformation.FileNameLength,
1381 "io.Information is %lu\n", io.Information );
1383 CloseHandle( h );
1384 HeapFree( GetProcessHeap(), 0, info );
1385 HeapFree( GetProcessHeap(), 0, expected );
1386 HeapFree( GetProcessHeap(), 0, volume_prefix );
1388 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1390 skip("Not running on WoW64, skipping test.\n");
1391 HeapFree( GetProcessHeap(), 0, file_name );
1392 return;
1395 h = CreateFileW( file_name, GENERIC_READ,
1396 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1397 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1398 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1399 HeapFree( GetProcessHeap(), 0, file_name );
1401 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1402 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1403 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1405 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1406 ok(len == file_name_size - 1,
1407 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1408 len, file_name_size - 1);
1410 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1411 ok(len, "GetVolumePathNameW failed.\n");
1413 len = lstrlenW( volume_prefix );
1414 if (len && volume_prefix[len - 1] == '\\') --len;
1415 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1416 expected[file_name_size - len - 1] = '\0';
1418 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1419 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1421 memset( info, 0xcc, info_size );
1422 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1423 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1424 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1425 ok(!lstrcmpiW( info->NameInformation.FileName, expected ), "info->NameInformation.FileName is %s, expected %s.\n",
1426 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1428 CloseHandle( h );
1429 HeapFree( GetProcessHeap(), 0, info );
1430 HeapFree( GetProcessHeap(), 0, expected );
1431 HeapFree( GetProcessHeap(), 0, volume_prefix );
1432 HeapFree( GetProcessHeap(), 0, file_name );
1435 START_TEST(file)
1437 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
1438 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
1439 if (!hntdll)
1441 skip("not running on NT, skipping test\n");
1442 return;
1445 pGetVolumePathNameW = (void *)GetProcAddress(hkernel32, "GetVolumePathNameW");
1446 pGetSystemWow64DirectoryW = (void *)GetProcAddress(hkernel32, "GetSystemWow64DirectoryW");
1448 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
1449 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
1450 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
1451 pRtlWow64EnableFsRedirectionEx = (void *)GetProcAddress(hntdll, "RtlWow64EnableFsRedirectionEx");
1452 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
1453 pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile");
1454 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
1455 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
1456 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
1457 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
1458 pNtCancelIoFile = (void *)GetProcAddress(hntdll, "NtCancelIoFile");
1459 pNtCancelIoFileEx = (void *)GetProcAddress(hntdll, "NtCancelIoFileEx");
1460 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
1461 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
1462 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
1463 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
1464 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
1465 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
1466 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");
1467 pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
1468 pNtQueryDirectoryFile = (void *)GetProcAddress(hntdll, "NtQueryDirectoryFile");
1470 create_file_test();
1471 open_file_test();
1472 delete_file_test();
1473 read_file_test();
1474 nt_mailslot_test();
1475 test_iocompletion();
1476 test_file_basic_information();
1477 test_file_all_information();
1478 test_file_both_information();
1479 test_file_name_information();
1480 test_file_all_name_information();