ntdll/tests: Don't free a string that wasn't allocated.
[wine/multimedia.git] / dlls / ntdll / tests / file.c
blob7540d789e74aed29458d99509324ca0ca30d18b0
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[8192];
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, GENERIC_READ, &attr, &io,
273 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
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, FALSE, NULL, restart ))
325 FILE_ID_BOTH_DIRECTORY_INFORMATION *info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)data;
327 restart = FALSE;
328 for (;;)
330 if (!info->FileId.QuadPart) goto next;
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 );
370 next:
371 if (!info->NextEntryOffset) break;
372 info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)((char *)info + info->NextEntryOffset);
376 CloseHandle( dir );
377 CloseHandle( root );
380 static void delete_file_test(void)
382 NTSTATUS ret;
383 OBJECT_ATTRIBUTES attr;
384 UNICODE_STRING nameW;
385 WCHAR pathW[MAX_PATH];
386 WCHAR pathsubW[MAX_PATH];
387 static const WCHAR testdirW[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
388 static const WCHAR subdirW[] = {'\\','s','u','b',0};
390 ret = GetTempPathW(MAX_PATH, pathW);
391 if (!ret)
393 ok(0, "couldn't get temp dir\n");
394 return;
396 if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
398 ok(0, "MAX_PATH exceeded in constructing paths\n");
399 return;
402 lstrcatW(pathW, testdirW);
403 lstrcpyW(pathsubW, pathW);
404 lstrcatW(pathsubW, subdirW);
406 ret = CreateDirectoryW(pathW, NULL);
407 ok(ret == TRUE, "couldn't create directory ntdeletefile\n");
408 if (!pRtlDosPathNameToNtPathName_U(pathW, &nameW, NULL, NULL))
410 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
411 return;
414 attr.Length = sizeof(attr);
415 attr.RootDirectory = 0;
416 attr.Attributes = OBJ_CASE_INSENSITIVE;
417 attr.ObjectName = &nameW;
418 attr.SecurityDescriptor = NULL;
419 attr.SecurityQualityOfService = NULL;
421 /* test NtDeleteFile on an empty directory */
422 ret = pNtDeleteFile(&attr);
423 ok(ret == STATUS_SUCCESS, "NtDeleteFile should succeed in removing an empty directory\n");
424 ret = RemoveDirectoryW(pathW);
425 ok(ret == FALSE, "expected to fail removing directory, NtDeleteFile should have removed it\n");
427 /* test NtDeleteFile on a non-empty directory */
428 ret = CreateDirectoryW(pathW, NULL);
429 ok(ret == TRUE, "couldn't create directory ntdeletefile ?!\n");
430 ret = CreateDirectoryW(pathsubW, NULL);
431 ok(ret == TRUE, "couldn't create directory subdir\n");
432 ret = pNtDeleteFile(&attr);
433 ok(ret == STATUS_SUCCESS, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
434 ret = RemoveDirectoryW(pathsubW);
435 ok(ret == TRUE, "expected to remove directory ntdeletefile\\sub\n");
436 ret = RemoveDirectoryW(pathW);
437 ok(ret == TRUE, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
439 pRtlFreeUnicodeString( &nameW );
442 static void read_file_test(void)
444 const char text[] = "foobar";
445 HANDLE handle, read, write;
446 NTSTATUS status;
447 IO_STATUS_BLOCK iosb, iosb2;
448 DWORD written;
449 int apc_count = 0;
450 char buffer[128];
451 LARGE_INTEGER offset;
452 HANDLE event = CreateEventA( NULL, TRUE, FALSE, NULL );
454 buffer[0] = 1;
456 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
458 /* try read with no data */
459 U(iosb).Status = 0xdeadbabe;
460 iosb.Information = 0xdeadbeef;
461 ok( is_signaled( read ), "read handle is not signaled\n" );
462 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
463 ok( status == STATUS_PENDING, "wrong status %x\n", status );
464 ok( !is_signaled( read ), "read handle is signaled\n" );
465 ok( !is_signaled( event ), "event is signaled\n" );
466 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
467 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
468 ok( !apc_count, "apc was called\n" );
469 WriteFile( write, buffer, 1, &written, NULL );
470 /* iosb updated here by async i/o */
471 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
472 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
473 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
474 ok( !is_signaled( read ), "read handle is signaled\n" );
475 ok( is_signaled( event ), "event is not signaled\n" );
476 ok( !apc_count, "apc was called\n" );
477 apc_count = 0;
478 SleepEx( 1, FALSE ); /* non-alertable sleep */
479 ok( !apc_count, "apc was called\n" );
480 SleepEx( 1, TRUE ); /* alertable sleep */
481 ok( apc_count == 1, "apc not called\n" );
483 /* with no event, the pipe handle itself gets signaled */
484 apc_count = 0;
485 U(iosb).Status = 0xdeadbabe;
486 iosb.Information = 0xdeadbeef;
487 ok( !is_signaled( read ), "read handle is not signaled\n" );
488 status = pNtReadFile( read, 0, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
489 ok( status == STATUS_PENDING, "wrong status %x\n", status );
490 ok( !is_signaled( read ), "read handle is signaled\n" );
491 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
492 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
493 ok( !apc_count, "apc was called\n" );
494 WriteFile( write, buffer, 1, &written, NULL );
495 /* iosb updated here by async i/o */
496 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
497 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
498 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
499 ok( is_signaled( read ), "read handle is signaled\n" );
500 ok( !apc_count, "apc was called\n" );
501 apc_count = 0;
502 SleepEx( 1, FALSE ); /* non-alertable sleep */
503 ok( !apc_count, "apc was called\n" );
504 SleepEx( 1, TRUE ); /* alertable sleep */
505 ok( apc_count == 1, "apc not called\n" );
507 /* now read with data ready */
508 apc_count = 0;
509 U(iosb).Status = 0xdeadbabe;
510 iosb.Information = 0xdeadbeef;
511 ResetEvent( event );
512 WriteFile( write, buffer, 1, &written, NULL );
513 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
514 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
515 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
516 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
517 ok( is_signaled( event ), "event is not signaled\n" );
518 ok( !apc_count, "apc was called\n" );
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" );
524 /* try read with no data */
525 apc_count = 0;
526 U(iosb).Status = 0xdeadbabe;
527 iosb.Information = 0xdeadbeef;
528 ok( is_signaled( event ), "event is not signaled\n" ); /* check that read resets the event */
529 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
530 ok( status == STATUS_PENDING, "wrong status %x\n", status );
531 ok( !is_signaled( event ), "event 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 WriteFile( write, buffer, 1, &written, NULL );
536 /* partial read is good enough */
537 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
538 ok( is_signaled( event ), "event is signaled\n" );
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( !apc_count, "apc was called\n" );
542 SleepEx( 1, TRUE ); /* alertable sleep */
543 ok( apc_count == 1, "apc was not called\n" );
545 /* read from disconnected pipe */
546 apc_count = 0;
547 U(iosb).Status = 0xdeadbabe;
548 iosb.Information = 0xdeadbeef;
549 CloseHandle( write );
550 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
551 ok( status == STATUS_PIPE_BROKEN, "wrong status %x\n", status );
552 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
553 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
554 ok( !is_signaled( event ), "event is signaled\n" );
555 ok( !apc_count, "apc was called\n" );
556 SleepEx( 1, TRUE ); /* alertable sleep */
557 ok( !apc_count, "apc was called\n" );
558 CloseHandle( read );
560 /* read from closed handle */
561 apc_count = 0;
562 U(iosb).Status = 0xdeadbabe;
563 iosb.Information = 0xdeadbeef;
564 SetEvent( event );
565 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
566 ok( status == STATUS_INVALID_HANDLE, "wrong status %x\n", status );
567 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
568 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
569 ok( is_signaled( event ), "event is signaled\n" ); /* not reset on invalid handle */
570 ok( !apc_count, "apc was called\n" );
571 SleepEx( 1, TRUE ); /* alertable sleep */
572 ok( !apc_count, "apc was called\n" );
574 /* disconnect while async read is in progress */
575 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
576 apc_count = 0;
577 U(iosb).Status = 0xdeadbabe;
578 iosb.Information = 0xdeadbeef;
579 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
580 ok( status == STATUS_PENDING, "wrong status %x\n", status );
581 ok( !is_signaled( event ), "event is signaled\n" );
582 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
583 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
584 ok( !apc_count, "apc was called\n" );
585 CloseHandle( write );
586 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
587 ok( U(iosb).Status == STATUS_PIPE_BROKEN, "wrong status %x\n", U(iosb).Status );
588 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
589 ok( is_signaled( event ), "event is signaled\n" );
590 ok( !apc_count, "apc was called\n" );
591 SleepEx( 1, TRUE ); /* alertable sleep */
592 ok( apc_count == 1, "apc was not called\n" );
593 CloseHandle( read );
595 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
596 ok(DuplicateHandle(GetCurrentProcess(), read, GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS),
597 "Failed to duplicate handle: %d\n", GetLastError());
599 apc_count = 0;
600 U(iosb).Status = 0xdeadbabe;
601 iosb.Information = 0xdeadbeef;
602 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
603 ok( status == STATUS_PENDING, "wrong status %x\n", status );
604 ok( !is_signaled( event ), "event is signaled\n" );
605 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
606 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
607 ok( !apc_count, "apc was called\n" );
608 /* Cancel by other handle */
609 status = pNtCancelIoFile( read, &iosb2 );
610 ok(status == STATUS_SUCCESS, "failed to cancel by different handle: %x\n", status);
611 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
612 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
613 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
614 ok( is_signaled( event ), "event is signaled\n" );
615 todo_wine ok( !apc_count, "apc was called\n" );
616 SleepEx( 1, TRUE ); /* alertable sleep */
617 ok( apc_count == 1, "apc was not called\n" );
619 apc_count = 0;
620 U(iosb).Status = 0xdeadbabe;
621 iosb.Information = 0xdeadbeef;
622 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
623 ok( status == STATUS_PENDING, "wrong status %x\n", status );
624 ok( !is_signaled( event ), "event is signaled\n" );
625 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
626 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
627 ok( !apc_count, "apc was called\n" );
628 /* Close queued handle */
629 CloseHandle( read );
630 SleepEx( 1, TRUE ); /* alertable sleep */
631 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
632 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
633 status = pNtCancelIoFile( read, &iosb2 );
634 ok(status == STATUS_INVALID_HANDLE, "cancelled by closed handle?\n");
635 status = pNtCancelIoFile( handle, &iosb2 );
636 ok(status == STATUS_SUCCESS, "failed to cancel: %x\n", status);
637 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
638 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
639 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
640 ok( is_signaled( event ), "event is signaled\n" );
641 todo_wine ok( !apc_count, "apc was called\n" );
642 SleepEx( 1, TRUE ); /* alertable sleep */
643 ok( apc_count == 1, "apc was not called\n" );
644 CloseHandle( handle );
645 CloseHandle( write );
647 if (pNtCancelIoFileEx)
649 /* Basic Cancel Ex */
650 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
652 apc_count = 0;
653 U(iosb).Status = 0xdeadbabe;
654 iosb.Information = 0xdeadbeef;
655 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
656 ok( status == STATUS_PENDING, "wrong status %x\n", status );
657 ok( !is_signaled( event ), "event is signaled\n" );
658 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
659 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
660 ok( !apc_count, "apc was called\n" );
661 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
662 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
663 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
664 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
665 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
666 ok( is_signaled( event ), "event is signaled\n" );
667 todo_wine ok( !apc_count, "apc was called\n" );
668 SleepEx( 1, TRUE ); /* alertable sleep */
669 ok( apc_count == 1, "apc was not called\n" );
671 /* Duplicate iosb */
672 apc_count = 0;
673 U(iosb).Status = 0xdeadbabe;
674 iosb.Information = 0xdeadbeef;
675 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
676 ok( status == STATUS_PENDING, "wrong status %x\n", status );
677 ok( !is_signaled( event ), "event is signaled\n" );
678 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
679 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
680 ok( !apc_count, "apc was called\n" );
681 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
682 ok( status == STATUS_PENDING, "wrong status %x\n", status );
683 ok( !is_signaled( event ), "event is signaled\n" );
684 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
685 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
686 ok( !apc_count, "apc was called\n" );
687 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
688 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
689 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
690 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
691 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
692 ok( is_signaled( event ), "event is signaled\n" );
693 todo_wine ok( !apc_count, "apc was called\n" );
694 SleepEx( 1, TRUE ); /* alertable sleep */
695 ok( apc_count == 2, "apc was not called\n" );
697 CloseHandle( read );
698 CloseHandle( write );
701 /* now try a real file */
702 if (!(handle = create_temp_file( FILE_FLAG_OVERLAPPED ))) return;
703 apc_count = 0;
704 U(iosb).Status = 0xdeadbabe;
705 iosb.Information = 0xdeadbeef;
706 offset.QuadPart = 0;
707 ResetEvent( event );
708 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
709 ok( status == STATUS_SUCCESS || status == STATUS_PENDING, "wrong status %x\n", status );
710 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
711 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
712 ok( is_signaled( event ), "event is signaled\n" );
713 ok( !apc_count, "apc was called\n" );
714 SleepEx( 1, TRUE ); /* alertable sleep */
715 ok( apc_count == 1, "apc was not called\n" );
717 apc_count = 0;
718 U(iosb).Status = 0xdeadbabe;
719 iosb.Information = 0xdeadbeef;
720 offset.QuadPart = 0;
721 ResetEvent( event );
722 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
723 ok( status == STATUS_SUCCESS ||
724 status == STATUS_PENDING, /* vista */
725 "wrong status %x\n", status );
726 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
727 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
728 ok( is_signaled( event ), "event is signaled\n" );
729 ok( !apc_count, "apc was called\n" );
730 SleepEx( 1, TRUE ); /* alertable sleep */
731 ok( apc_count == 1, "apc was not called\n" );
733 /* read beyond eof */
734 apc_count = 0;
735 U(iosb).Status = 0xdeadbabe;
736 iosb.Information = 0xdeadbeef;
737 offset.QuadPart = strlen(text) + 2;
738 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
739 if (status == STATUS_PENDING) /* vista */
741 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
742 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
743 ok( is_signaled( event ), "event is signaled\n" );
744 ok( !apc_count, "apc was called\n" );
745 SleepEx( 1, TRUE ); /* alertable sleep */
746 ok( apc_count == 1, "apc was not called\n" );
748 else
750 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
751 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
752 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
753 ok( !is_signaled( event ), "event is signaled\n" );
754 ok( !apc_count, "apc was called\n" );
755 SleepEx( 1, TRUE ); /* alertable sleep */
756 ok( !apc_count, "apc was called\n" );
758 CloseHandle( handle );
760 /* now a non-overlapped file */
761 if (!(handle = create_temp_file(0))) return;
762 apc_count = 0;
763 U(iosb).Status = 0xdeadbabe;
764 iosb.Information = 0xdeadbeef;
765 offset.QuadPart = 0;
766 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
767 ok( status == STATUS_END_OF_FILE ||
768 status == STATUS_SUCCESS ||
769 status == STATUS_PENDING, /* vista */
770 "wrong status %x\n", status );
771 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
772 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
773 ok( is_signaled( event ), "event is signaled\n" );
774 ok( !apc_count, "apc was called\n" );
775 SleepEx( 1, TRUE ); /* alertable sleep */
776 ok( apc_count == 1, "apc was not called\n" );
778 apc_count = 0;
779 U(iosb).Status = 0xdeadbabe;
780 iosb.Information = 0xdeadbeef;
781 offset.QuadPart = 0;
782 ResetEvent( event );
783 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
784 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
785 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
786 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
787 ok( is_signaled( event ), "event is signaled\n" );
788 ok( !apc_count, "apc was called\n" );
789 SleepEx( 1, TRUE ); /* alertable sleep */
790 todo_wine ok( !apc_count, "apc was called\n" );
792 /* read beyond eof */
793 apc_count = 0;
794 U(iosb).Status = 0xdeadbabe;
795 iosb.Information = 0xdeadbeef;
796 offset.QuadPart = strlen(text) + 2;
797 ResetEvent( event );
798 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
799 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
800 todo_wine ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
801 todo_wine ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
802 todo_wine ok( is_signaled( event ), "event is not signaled\n" );
803 ok( !apc_count, "apc was called\n" );
804 SleepEx( 1, TRUE ); /* alertable sleep */
805 ok( !apc_count, "apc was called\n" );
807 CloseHandle( handle );
809 CloseHandle( event );
812 static void nt_mailslot_test(void)
814 HANDLE hslot;
815 ACCESS_MASK DesiredAccess;
816 OBJECT_ATTRIBUTES attr;
818 ULONG CreateOptions;
819 ULONG MailslotQuota;
820 ULONG MaxMessageSize;
821 LARGE_INTEGER TimeOut;
822 IO_STATUS_BLOCK IoStatusBlock;
823 NTSTATUS rc;
824 UNICODE_STRING str;
825 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
826 'R',':','\\','F','R','E','D','\0' };
828 TimeOut.QuadPart = -1;
830 pRtlInitUnicodeString(&str, buffer1);
831 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
832 CreateOptions = MailslotQuota = MaxMessageSize = 0;
833 DesiredAccess = GENERIC_READ;
836 * Check for NULL pointer handling
838 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
839 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
840 &TimeOut);
841 ok( rc == STATUS_ACCESS_VIOLATION ||
842 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
843 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
846 * Test to see if the Timeout can be NULL
848 hslot = (HANDLE)0xdeadbeef;
849 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
850 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
851 NULL);
852 ok( rc == STATUS_SUCCESS ||
853 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
854 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
855 ok( hslot != 0, "Handle is invalid\n");
857 if ( rc == STATUS_SUCCESS ) rc = pNtClose(hslot);
860 * Test that the length field is checked properly
862 attr.Length = 0;
863 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
864 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
865 &TimeOut);
866 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
868 if (rc == STATUS_SUCCESS) pNtClose(hslot);
870 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
871 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
872 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
873 &TimeOut);
874 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
876 if (rc == STATUS_SUCCESS) pNtClose(hslot);
879 * Test handling of a NULL unicode string in ObjectName
881 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
882 attr.ObjectName = NULL;
883 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
884 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
885 &TimeOut);
886 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
887 rc == STATUS_INVALID_PARAMETER,
888 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
890 if (rc == STATUS_SUCCESS) pNtClose(hslot);
893 * Test a valid call
895 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
896 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
897 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
898 &TimeOut);
899 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
900 ok( hslot != 0, "Handle is invalid\n");
902 rc = pNtClose(hslot);
903 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
906 static void test_iocp_setcompletion(HANDLE h)
908 NTSTATUS res;
909 long count;
911 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, 3 );
912 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
914 count = get_pending_msgs(h);
915 ok( count == 1, "Unexpected msg count: %ld\n", count );
917 if (get_msg(h))
919 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
920 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
921 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
922 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
925 count = get_pending_msgs(h);
926 ok( !count, "Unexpected msg count: %ld\n", count );
929 static void test_iocp_fileio(HANDLE h)
931 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
933 IO_STATUS_BLOCK iosb;
934 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
935 HANDLE hPipeSrv, hPipeClt;
936 NTSTATUS res;
938 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
939 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
940 if (hPipeSrv != INVALID_HANDLE_VALUE )
942 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
943 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
944 if (hPipeClt != INVALID_HANDLE_VALUE)
946 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
947 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
948 CloseHandle(hPipeClt);
950 CloseHandle( hPipeSrv );
953 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
954 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
955 if (hPipeSrv == INVALID_HANDLE_VALUE )
956 return;
958 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
959 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
960 if (hPipeClt != INVALID_HANDLE_VALUE)
962 OVERLAPPED o = {0,};
963 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
964 DWORD read;
965 long count;
967 NTSTATUS res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
968 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
969 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
971 memset( send_buf, 0, TEST_BUF_LEN );
972 memset( recv_buf, 0xde, TEST_BUF_LEN );
973 count = get_pending_msgs(h);
974 ok( !count, "Unexpected msg count: %ld\n", count );
975 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
976 count = get_pending_msgs(h);
977 ok( !count, "Unexpected msg count: %ld\n", count );
978 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
980 if (get_msg(h))
982 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
983 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
984 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
985 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
986 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] );
988 count = get_pending_msgs(h);
989 ok( !count, "Unexpected msg count: %ld\n", count );
991 memset( send_buf, 0, TEST_BUF_LEN );
992 memset( recv_buf, 0xde, TEST_BUF_LEN );
993 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
994 count = get_pending_msgs(h);
995 ok( !count, "Unexpected msg count: %ld\n", count );
996 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
997 count = get_pending_msgs(h);
998 ok( count == 1, "Unexpected msg count: %ld\n", count );
999 if (get_msg(h))
1001 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1002 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1003 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1004 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1005 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] );
1008 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1009 CloseHandle( hPipeSrv );
1010 count = get_pending_msgs(h);
1011 ok( count == 1, "Unexpected msg count: %ld\n", count );
1012 if (get_msg(h))
1014 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1015 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1016 /* wine sends wrong status here */
1017 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1018 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1022 CloseHandle( hPipeClt );
1025 static void test_file_basic_information(void)
1027 IO_STATUS_BLOCK io;
1028 FILE_BASIC_INFORMATION fbi;
1029 HANDLE h;
1030 int res;
1031 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1033 if (!(h = create_temp_file(0))) return;
1035 /* Check default first */
1036 memset(&fbi, 0, sizeof(fbi));
1037 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1038 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1039 ok ( (fbi.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1040 "attribute %x not expected\n", fbi.FileAttributes );
1042 /* Then SYSTEM */
1043 /* Clear fbi to avoid setting times */
1044 memset(&fbi, 0, sizeof(fbi));
1045 fbi.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1046 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1047 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1049 memset(&fbi, 0, sizeof(fbi));
1050 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1051 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1052 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi.FileAttributes );
1054 /* Then HIDDEN */
1055 memset(&fbi, 0, sizeof(fbi));
1056 fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1057 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1058 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1060 memset(&fbi, 0, sizeof(fbi));
1061 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1062 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1063 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi.FileAttributes );
1065 /* Check NORMAL last of all (to make sure we can clear attributes) */
1066 memset(&fbi, 0, sizeof(fbi));
1067 fbi.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1068 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1069 ok ( res == STATUS_SUCCESS, "can't set normal attribute\n");
1071 memset(&fbi, 0, sizeof(fbi));
1072 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1073 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1074 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not 0\n", fbi.FileAttributes );
1076 CloseHandle( h );
1079 static void test_file_all_information(void)
1081 IO_STATUS_BLOCK io;
1082 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1083 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1084 * don't leave enough room there.
1086 struct {
1087 FILE_ALL_INFORMATION fai;
1088 WCHAR buf[256];
1089 } fai_buf;
1090 HANDLE h;
1091 int res;
1092 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1094 if (!(h = create_temp_file(0))) return;
1096 /* Check default first */
1097 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1098 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1099 ok ( (fai_buf.fai.BasicInformation.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1100 "attribute %x not expected\n", fai_buf.fai.BasicInformation.FileAttributes );
1102 /* Then SYSTEM */
1103 /* Clear fbi to avoid setting times */
1104 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1105 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1106 res = pNtSetInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1107 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to set FileAllInformation, res %x\n", res);
1108 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1109 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1111 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1112 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1113 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1114 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 );
1116 /* Then HIDDEN */
1117 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1118 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1119 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1120 ok ( res == STATUS_SUCCESS, "can't set system attribute\n");
1122 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1123 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1124 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1125 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 );
1127 /* Check NORMAL last of all (to make sure we can clear attributes) */
1128 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1129 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1130 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1131 ok ( res == STATUS_SUCCESS, "can't set normal attribute\n");
1133 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1134 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1135 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1136 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 );
1138 CloseHandle( h );
1141 static void test_file_both_information(void)
1143 IO_STATUS_BLOCK io;
1144 FILE_BOTH_DIR_INFORMATION fbi;
1145 HANDLE h;
1146 int res;
1148 if (!(h = create_temp_file(0))) return;
1150 memset(&fbi, 0, sizeof(fbi));
1151 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBothDirectoryInformation);
1152 ok ( res == STATUS_INVALID_INFO_CLASS || res == STATUS_NOT_IMPLEMENTED, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res);
1154 CloseHandle( h );
1157 static void test_iocompletion(void)
1159 HANDLE h = INVALID_HANDLE_VALUE;
1160 NTSTATUS res;
1162 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
1164 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
1165 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
1167 if ( h && h != INVALID_HANDLE_VALUE)
1169 test_iocp_setcompletion(h);
1170 test_iocp_fileio(h);
1171 pNtClose(h);
1175 static void test_file_name_information(void)
1177 WCHAR *file_name, *volume_prefix, *expected;
1178 FILE_NAME_INFORMATION *info;
1179 ULONG old_redir = 1, tmp;
1180 UINT file_name_size;
1181 IO_STATUS_BLOCK io;
1182 UINT info_size;
1183 HRESULT hr;
1184 HANDLE h;
1185 UINT len;
1187 /* GetVolumePathName is not present before w2k */
1188 if (!pGetVolumePathNameW) {
1189 win_skip("GetVolumePathNameW not found\n");
1190 return;
1193 file_name_size = GetSystemDirectoryW( NULL, 0 );
1194 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1195 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1196 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1198 len = GetSystemDirectoryW( file_name, file_name_size );
1199 ok(len == file_name_size - 1,
1200 "GetSystemDirectoryW returned %u, expected %u.\n",
1201 len, file_name_size - 1);
1203 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1204 ok(len, "GetVolumePathNameW failed.\n");
1206 len = lstrlenW( volume_prefix );
1207 if (len && volume_prefix[len - 1] == '\\') --len;
1208 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1209 expected[file_name_size - len - 1] = '\0';
1211 /* A bit more than we actually need, but it keeps the calculation simple. */
1212 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1213 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1215 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1216 h = CreateFileW( file_name, GENERIC_READ,
1217 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1218 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1219 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1220 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1222 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileNameInformation );
1223 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x.\n", hr);
1225 memset( info, 0xcc, info_size );
1226 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileNameInformation );
1227 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1228 hr, STATUS_BUFFER_OVERFLOW);
1229 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1230 U(io).Status, STATUS_BUFFER_OVERFLOW);
1231 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1232 ok(info->FileName[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info->FileName[2]);
1233 ok(CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1234 "info->FileName[1] is %p, expected %p.\n",
1235 CharLowerW((LPWSTR)(UINT_PTR)info->FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1236 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1238 memset( info, 0xcc, info_size );
1239 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1240 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1241 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1242 ok(info->FileNameLength == lstrlenW( expected ) * sizeof(WCHAR), "info->FileNameLength is %u\n", info->FileNameLength);
1243 ok(info->FileName[info->FileNameLength / sizeof(WCHAR)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1244 info->FileName[info->FileNameLength / sizeof(WCHAR)]);
1245 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1246 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1247 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1248 ok(io.Information == FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength,
1249 "io.Information is %lu, expected %u.\n",
1250 io.Information, FIELD_OFFSET(FILE_NAME_INFORMATION, FileName) + info->FileNameLength);
1252 CloseHandle( h );
1253 HeapFree( GetProcessHeap(), 0, info );
1254 HeapFree( GetProcessHeap(), 0, expected );
1255 HeapFree( GetProcessHeap(), 0, volume_prefix );
1257 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1259 skip("Not running on WoW64, skipping test.\n");
1260 HeapFree( GetProcessHeap(), 0, file_name );
1261 return;
1264 h = CreateFileW( file_name, GENERIC_READ,
1265 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1266 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1267 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1268 HeapFree( GetProcessHeap(), 0, file_name );
1270 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1271 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1272 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1274 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1275 ok(len == file_name_size - 1,
1276 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1277 len, file_name_size - 1);
1279 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1280 ok(len, "GetVolumePathNameW failed.\n");
1282 len = lstrlenW( volume_prefix );
1283 if (len && volume_prefix[len - 1] == '\\') --len;
1284 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1285 expected[file_name_size - len - 1] = '\0';
1287 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1288 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1290 memset( info, 0xcc, info_size );
1291 hr = pNtQueryInformationFile( h, &io, info, info_size, FileNameInformation );
1292 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1293 info->FileName[info->FileNameLength / sizeof(WCHAR)] = '\0';
1294 ok(!lstrcmpiW( info->FileName, expected ), "info->FileName is %s, expected %s.\n",
1295 wine_dbgstr_w( info->FileName ), wine_dbgstr_w( expected ));
1297 CloseHandle( h );
1298 HeapFree( GetProcessHeap(), 0, info );
1299 HeapFree( GetProcessHeap(), 0, expected );
1300 HeapFree( GetProcessHeap(), 0, volume_prefix );
1301 HeapFree( GetProcessHeap(), 0, file_name );
1304 static void test_file_all_name_information(void)
1306 WCHAR *file_name, *volume_prefix, *expected;
1307 FILE_ALL_INFORMATION *info;
1308 ULONG old_redir = 1, tmp;
1309 UINT file_name_size;
1310 IO_STATUS_BLOCK io;
1311 UINT info_size;
1312 HRESULT hr;
1313 HANDLE h;
1314 UINT len;
1316 /* GetVolumePathName is not present before w2k */
1317 if (!pGetVolumePathNameW) {
1318 win_skip("GetVolumePathNameW not found\n");
1319 return;
1322 file_name_size = GetSystemDirectoryW( NULL, 0 );
1323 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1324 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1325 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1327 len = GetSystemDirectoryW( file_name, file_name_size );
1328 ok(len == file_name_size - 1,
1329 "GetSystemDirectoryW returned %u, expected %u.\n",
1330 len, file_name_size - 1);
1332 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1333 ok(len, "GetVolumePathNameW failed.\n");
1335 len = lstrlenW( volume_prefix );
1336 if (len && volume_prefix[len - 1] == '\\') --len;
1337 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1338 expected[file_name_size - len - 1] = '\0';
1340 /* A bit more than we actually need, but it keeps the calculation simple. */
1341 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1342 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1344 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( TRUE, &old_redir );
1345 h = CreateFileW( file_name, GENERIC_READ,
1346 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1347 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1348 if (pRtlWow64EnableFsRedirectionEx) pRtlWow64EnableFsRedirectionEx( old_redir, &tmp );
1349 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1351 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info) - 1, FileAllInformation );
1352 ok(hr == STATUS_INFO_LENGTH_MISMATCH, "NtQueryInformationFile returned %#x, expected %#x.\n",
1353 hr, STATUS_INFO_LENGTH_MISMATCH);
1355 memset( info, 0xcc, info_size );
1356 hr = pNtQueryInformationFile( h, &io, info, sizeof(*info), FileAllInformation );
1357 ok(hr == STATUS_BUFFER_OVERFLOW, "NtQueryInformationFile returned %#x, expected %#x.\n",
1358 hr, STATUS_BUFFER_OVERFLOW);
1359 ok(U(io).Status == STATUS_BUFFER_OVERFLOW, "io.Status is %#x, expected %#x.\n",
1360 U(io).Status, STATUS_BUFFER_OVERFLOW);
1361 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1362 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1363 ok(info->NameInformation.FileName[2] == 0xcccc,
1364 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info->NameInformation.FileName[2]);
1365 ok(CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]) == CharLowerW((LPWSTR)(UINT_PTR)expected[1]),
1366 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1367 CharLowerW((LPWSTR)(UINT_PTR)info->NameInformation.FileName[1]), CharLowerW((LPWSTR)(UINT_PTR)expected[1]));
1368 ok(io.Information == sizeof(*info), "io.Information is %lu\n", io.Information);
1370 memset( info, 0xcc, info_size );
1371 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1372 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1373 ok(U(io).Status == STATUS_SUCCESS, "io.Status is %#x, expected %#x.\n", U(io).Status, STATUS_SUCCESS);
1374 ok(info->NameInformation.FileNameLength == lstrlenW( expected ) * sizeof(WCHAR),
1375 "info->NameInformation.FileNameLength is %u\n", info->NameInformation.FileNameLength );
1376 ok(info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] == 0xcccc,
1377 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1378 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)]);
1379 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1380 ok(!lstrcmpiW( info->NameInformation.FileName, expected ),
1381 "info->NameInformation.FileName is %s, expected %s.\n",
1382 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1383 ok(io.Information == FIELD_OFFSET(FILE_ALL_INFORMATION, NameInformation.FileName)
1384 + info->NameInformation.FileNameLength,
1385 "io.Information is %lu\n", io.Information );
1387 CloseHandle( h );
1388 HeapFree( GetProcessHeap(), 0, info );
1389 HeapFree( GetProcessHeap(), 0, expected );
1390 HeapFree( GetProcessHeap(), 0, volume_prefix );
1392 if (old_redir || !pGetSystemWow64DirectoryW || !(file_name_size = pGetSystemWow64DirectoryW( NULL, 0 )))
1394 skip("Not running on WoW64, skipping test.\n");
1395 HeapFree( GetProcessHeap(), 0, file_name );
1396 return;
1399 h = CreateFileW( file_name, GENERIC_READ,
1400 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
1401 NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1402 ok(h != INVALID_HANDLE_VALUE, "Failed to open file.\n");
1403 HeapFree( GetProcessHeap(), 0, file_name );
1405 file_name = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*file_name) );
1406 volume_prefix = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*volume_prefix) );
1407 expected = HeapAlloc( GetProcessHeap(), 0, file_name_size * sizeof(*expected) );
1409 len = pGetSystemWow64DirectoryW( file_name, file_name_size );
1410 ok(len == file_name_size - 1,
1411 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1412 len, file_name_size - 1);
1414 len = pGetVolumePathNameW( file_name, volume_prefix, file_name_size );
1415 ok(len, "GetVolumePathNameW failed.\n");
1417 len = lstrlenW( volume_prefix );
1418 if (len && volume_prefix[len - 1] == '\\') --len;
1419 memcpy( expected, file_name + len, (file_name_size - len - 1) * sizeof(WCHAR) );
1420 expected[file_name_size - len - 1] = '\0';
1422 info_size = sizeof(*info) + (file_name_size * sizeof(WCHAR));
1423 info = HeapAlloc( GetProcessHeap(), 0, info_size );
1425 memset( info, 0xcc, info_size );
1426 hr = pNtQueryInformationFile( h, &io, info, info_size, FileAllInformation );
1427 ok(hr == STATUS_SUCCESS, "NtQueryInformationFile returned %#x, expected %#x.\n", hr, STATUS_SUCCESS);
1428 info->NameInformation.FileName[info->NameInformation.FileNameLength / sizeof(WCHAR)] = '\0';
1429 ok(!lstrcmpiW( info->NameInformation.FileName, expected ), "info->NameInformation.FileName is %s, expected %s.\n",
1430 wine_dbgstr_w( info->NameInformation.FileName ), wine_dbgstr_w( expected ));
1432 CloseHandle( h );
1433 HeapFree( GetProcessHeap(), 0, info );
1434 HeapFree( GetProcessHeap(), 0, expected );
1435 HeapFree( GetProcessHeap(), 0, volume_prefix );
1436 HeapFree( GetProcessHeap(), 0, file_name );
1439 START_TEST(file)
1441 HMODULE hkernel32 = GetModuleHandleA("kernel32.dll");
1442 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
1443 if (!hntdll)
1445 skip("not running on NT, skipping test\n");
1446 return;
1449 pGetVolumePathNameW = (void *)GetProcAddress(hkernel32, "GetVolumePathNameW");
1450 pGetSystemWow64DirectoryW = (void *)GetProcAddress(hkernel32, "GetSystemWow64DirectoryW");
1452 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
1453 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
1454 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
1455 pRtlWow64EnableFsRedirectionEx = (void *)GetProcAddress(hntdll, "RtlWow64EnableFsRedirectionEx");
1456 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
1457 pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile");
1458 pNtOpenFile = (void *)GetProcAddress(hntdll, "NtOpenFile");
1459 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
1460 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
1461 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
1462 pNtCancelIoFile = (void *)GetProcAddress(hntdll, "NtCancelIoFile");
1463 pNtCancelIoFileEx = (void *)GetProcAddress(hntdll, "NtCancelIoFileEx");
1464 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
1465 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
1466 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
1467 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
1468 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
1469 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
1470 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");
1471 pNtQueryInformationFile = (void *)GetProcAddress(hntdll, "NtQueryInformationFile");
1472 pNtQueryDirectoryFile = (void *)GetProcAddress(hntdll, "NtQueryDirectoryFile");
1474 create_file_test();
1475 open_file_test();
1476 delete_file_test();
1477 read_file_test();
1478 nt_mailslot_test();
1479 test_iocompletion();
1480 test_file_basic_information();
1481 test_file_all_information();
1482 test_file_both_information();
1483 test_file_name_information();
1484 test_file_all_name_information();