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
22 * We use function pointers here as there is no import library for NTDLL on
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"
39 #ifndef IO_COMPLETION_ALL_ACCESS
40 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
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());
99 static HANDLE
create_temp_file( ULONG flags
)
101 char buffer
[MAX_PATH
];
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
)
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
);
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
));
146 static void WINAPI
apc( void *arg
, IO_STATUS_BLOCK
*iosb
, ULONG reserved
)
150 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
151 iosb
, U(*iosb
).Status
, iosb
->Information
);
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};
162 WCHAR path
[MAX_PATH
];
163 OBJECT_ATTRIBUTES attr
;
165 UNICODE_STRING nameW
;
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
);
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
);
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
);
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
);
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
;
245 status
= pNtCreateFile( &dir
, FILE_APPEND_DATA
, &attr
, &io
, NULL
, FILE_ATTRIBUTE_NORMAL
, 0,
246 FILE_OPEN_IF
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0 );
248 ok( status
== STATUS_INVALID_PARAMETER
,
249 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
250 pRtlFreeUnicodeString( &nameW
);
253 static void open_file_test(void)
256 HANDLE dir
, root
, handle
;
257 WCHAR path
[MAX_PATH
];
259 OBJECT_ATTRIBUTES attr
;
261 UNICODE_STRING nameW
;
265 len
= GetWindowsDirectoryW( path
, MAX_PATH
);
266 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
267 attr
.Length
= sizeof(attr
);
268 attr
.RootDirectory
= 0;
269 attr
.ObjectName
= &nameW
;
270 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
271 attr
.SecurityDescriptor
= NULL
;
272 attr
.SecurityQualityOfService
= NULL
;
273 status
= pNtOpenFile( &dir
, GENERIC_READ
, &attr
, &io
,
274 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
275 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
276 pRtlFreeUnicodeString( &nameW
);
278 path
[3] = 0; /* root of the drive */
279 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
280 status
= pNtOpenFile( &root
, GENERIC_READ
, &attr
, &io
,
281 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
282 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
283 pRtlFreeUnicodeString( &nameW
);
285 /* test opening system dir with RootDirectory set to windows dir */
286 GetSystemDirectoryW( path
, MAX_PATH
);
287 while (path
[len
] == '\\') len
++;
288 nameW
.Buffer
= path
+ len
;
289 nameW
.Length
= lstrlenW(path
+ len
) * sizeof(WCHAR
);
290 attr
.RootDirectory
= dir
;
291 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
292 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
293 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
294 CloseHandle( handle
);
296 /* try uppercase name */
297 for (i
= len
; path
[i
]; i
++) if (path
[i
] >= 'a' && path
[i
] <= 'z') path
[i
] -= 'a' - 'A';
298 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
299 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
300 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
301 CloseHandle( handle
);
303 /* try with leading backslash */
305 nameW
.Length
+= sizeof(WCHAR
);
306 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
307 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
308 ok( status
== STATUS_INVALID_PARAMETER
||
309 status
== STATUS_OBJECT_NAME_INVALID
||
310 status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
311 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
312 if (!status
) CloseHandle( handle
);
314 /* try with empty name */
316 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
317 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
318 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
319 CloseHandle( handle
);
321 /* try open by file id */
323 while (!pNtQueryDirectoryFile( dir
, NULL
, NULL
, NULL
, &io
, data
, sizeof(data
),
324 FileIdBothDirectoryInformation
, FALSE
, NULL
, restart
))
326 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)data
;
331 if (!info
->FileId
.QuadPart
) goto next
;
332 nameW
.Buffer
= (WCHAR
*)&info
->FileId
;
333 nameW
.Length
= sizeof(info
->FileId
);
334 info
->FileName
[info
->FileNameLength
/sizeof(WCHAR
)] = 0;
335 attr
.RootDirectory
= dir
;
336 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
337 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
338 FILE_OPEN_BY_FILE_ID
|
339 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
340 ok( status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_DENIED
|| status
== STATUS_NOT_IMPLEMENTED
,
341 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
342 if (status
== STATUS_NOT_IMPLEMENTED
)
344 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
349 FILE_ALL_INFORMATION all_info
;
351 if (!pNtQueryInformationFile( handle
, &io
, &all_info
, sizeof(all_info
), FileAllInformation
))
353 /* check that it's the same file */
354 ok( info
->EndOfFile
.QuadPart
== all_info
.StandardInformation
.EndOfFile
.QuadPart
,
355 "mismatched file size for %s\n", wine_dbgstr_w(info
->FileName
));
356 ok( info
->LastWriteTime
.QuadPart
== all_info
.BasicInformation
.LastWriteTime
.QuadPart
,
357 "mismatched write time for %s\n", wine_dbgstr_w(info
->FileName
));
359 CloseHandle( handle
);
361 /* try same thing from drive root */
362 attr
.RootDirectory
= root
;
363 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
364 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
365 FILE_OPEN_BY_FILE_ID
|
366 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
367 ok( status
== STATUS_SUCCESS
|| status
== STATUS_NOT_IMPLEMENTED
,
368 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
369 if (!status
) CloseHandle( handle
);
372 if (!info
->NextEntryOffset
) break;
373 info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)((char *)info
+ info
->NextEntryOffset
);
381 static void delete_file_test(void)
384 OBJECT_ATTRIBUTES attr
;
385 UNICODE_STRING nameW
;
386 WCHAR pathW
[MAX_PATH
];
387 WCHAR pathsubW
[MAX_PATH
];
388 static const WCHAR testdirW
[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
389 static const WCHAR subdirW
[] = {'\\','s','u','b',0};
391 ret
= GetTempPathW(MAX_PATH
, pathW
);
394 ok(0, "couldn't get temp dir\n");
397 if (ret
+ sizeof(testdirW
)/sizeof(WCHAR
)-1 + sizeof(subdirW
)/sizeof(WCHAR
)-1 >= MAX_PATH
)
399 ok(0, "MAX_PATH exceeded in constructing paths\n");
403 lstrcatW(pathW
, testdirW
);
404 lstrcpyW(pathsubW
, pathW
);
405 lstrcatW(pathsubW
, subdirW
);
407 ret
= CreateDirectoryW(pathW
, NULL
);
408 ok(ret
== TRUE
, "couldn't create directory ntdeletefile\n");
409 if (!pRtlDosPathNameToNtPathName_U(pathW
, &nameW
, NULL
, NULL
))
411 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
415 attr
.Length
= sizeof(attr
);
416 attr
.RootDirectory
= 0;
417 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
418 attr
.ObjectName
= &nameW
;
419 attr
.SecurityDescriptor
= NULL
;
420 attr
.SecurityQualityOfService
= NULL
;
422 /* test NtDeleteFile on an empty directory */
423 ret
= pNtDeleteFile(&attr
);
424 ok(ret
== STATUS_SUCCESS
, "NtDeleteFile should succeed in removing an empty directory\n");
425 ret
= RemoveDirectoryW(pathW
);
426 ok(ret
== FALSE
, "expected to fail removing directory, NtDeleteFile should have removed it\n");
428 /* test NtDeleteFile on a non-empty directory */
429 ret
= CreateDirectoryW(pathW
, NULL
);
430 ok(ret
== TRUE
, "couldn't create directory ntdeletefile ?!\n");
431 ret
= CreateDirectoryW(pathsubW
, NULL
);
432 ok(ret
== TRUE
, "couldn't create directory subdir\n");
433 ret
= pNtDeleteFile(&attr
);
434 ok(ret
== STATUS_SUCCESS
, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
435 ret
= RemoveDirectoryW(pathsubW
);
436 ok(ret
== TRUE
, "expected to remove directory ntdeletefile\\sub\n");
437 ret
= RemoveDirectoryW(pathW
);
438 ok(ret
== TRUE
, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
440 pRtlFreeUnicodeString( &nameW
);
443 static void read_file_test(void)
445 const char text
[] = "foobar";
446 HANDLE handle
, read
, write
;
448 IO_STATUS_BLOCK iosb
, iosb2
;
452 LARGE_INTEGER offset
;
453 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
457 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
459 /* try read with no data */
460 U(iosb
).Status
= 0xdeadbabe;
461 iosb
.Information
= 0xdeadbeef;
462 ok( is_signaled( read
), "read handle is not signaled\n" );
463 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
464 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
465 ok( !is_signaled( read
), "read handle is signaled\n" );
466 ok( !is_signaled( event
), "event is signaled\n" );
467 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
468 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
469 ok( !apc_count
, "apc was called\n" );
470 WriteFile( write
, buffer
, 1, &written
, NULL
);
471 /* iosb updated here by async i/o */
472 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
473 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
474 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
475 ok( !is_signaled( read
), "read handle is signaled\n" );
476 ok( is_signaled( event
), "event is not signaled\n" );
477 ok( !apc_count
, "apc was called\n" );
479 SleepEx( 1, FALSE
); /* non-alertable sleep */
480 ok( !apc_count
, "apc was called\n" );
481 SleepEx( 1, TRUE
); /* alertable sleep */
482 ok( apc_count
== 1, "apc not called\n" );
484 /* with no event, the pipe handle itself gets signaled */
486 U(iosb
).Status
= 0xdeadbabe;
487 iosb
.Information
= 0xdeadbeef;
488 ok( !is_signaled( read
), "read handle is not signaled\n" );
489 status
= pNtReadFile( read
, 0, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
490 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
491 ok( !is_signaled( read
), "read handle is signaled\n" );
492 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
493 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
494 ok( !apc_count
, "apc was called\n" );
495 WriteFile( write
, buffer
, 1, &written
, NULL
);
496 /* iosb updated here by async i/o */
497 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
498 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
499 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
500 ok( is_signaled( read
), "read handle is signaled\n" );
501 ok( !apc_count
, "apc was called\n" );
503 SleepEx( 1, FALSE
); /* non-alertable sleep */
504 ok( !apc_count
, "apc was called\n" );
505 SleepEx( 1, TRUE
); /* alertable sleep */
506 ok( apc_count
== 1, "apc not called\n" );
508 /* now read with data ready */
510 U(iosb
).Status
= 0xdeadbabe;
511 iosb
.Information
= 0xdeadbeef;
513 WriteFile( write
, buffer
, 1, &written
, NULL
);
514 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
515 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
516 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
517 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
518 ok( is_signaled( event
), "event is not signaled\n" );
519 ok( !apc_count
, "apc was called\n" );
520 SleepEx( 1, FALSE
); /* non-alertable sleep */
521 ok( !apc_count
, "apc was called\n" );
522 SleepEx( 1, TRUE
); /* alertable sleep */
523 ok( apc_count
== 1, "apc not called\n" );
525 /* try read with no data */
527 U(iosb
).Status
= 0xdeadbabe;
528 iosb
.Information
= 0xdeadbeef;
529 ok( is_signaled( event
), "event is not signaled\n" ); /* check that read resets the event */
530 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
531 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
532 ok( !is_signaled( event
), "event is signaled\n" );
533 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
534 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
535 ok( !apc_count
, "apc was called\n" );
536 WriteFile( write
, buffer
, 1, &written
, NULL
);
537 /* partial read is good enough */
538 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
539 ok( is_signaled( event
), "event is signaled\n" );
540 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
541 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
542 ok( !apc_count
, "apc was called\n" );
543 SleepEx( 1, TRUE
); /* alertable sleep */
544 ok( apc_count
== 1, "apc was not called\n" );
546 /* read from disconnected pipe */
548 U(iosb
).Status
= 0xdeadbabe;
549 iosb
.Information
= 0xdeadbeef;
550 CloseHandle( write
);
551 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
552 ok( status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", status
);
553 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
554 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
555 ok( !is_signaled( event
), "event is signaled\n" );
556 ok( !apc_count
, "apc was called\n" );
557 SleepEx( 1, TRUE
); /* alertable sleep */
558 ok( !apc_count
, "apc was called\n" );
561 /* read from closed handle */
563 U(iosb
).Status
= 0xdeadbabe;
564 iosb
.Information
= 0xdeadbeef;
566 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
567 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
568 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
569 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
570 ok( is_signaled( event
), "event is signaled\n" ); /* not reset on invalid handle */
571 ok( !apc_count
, "apc was called\n" );
572 SleepEx( 1, TRUE
); /* alertable sleep */
573 ok( !apc_count
, "apc was called\n" );
575 /* disconnect while async read is in progress */
576 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
578 U(iosb
).Status
= 0xdeadbabe;
579 iosb
.Information
= 0xdeadbeef;
580 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
581 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
582 ok( !is_signaled( event
), "event is signaled\n" );
583 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
584 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
585 ok( !apc_count
, "apc was called\n" );
586 CloseHandle( write
);
587 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
588 ok( U(iosb
).Status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", U(iosb
).Status
);
589 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
590 ok( is_signaled( event
), "event is signaled\n" );
591 ok( !apc_count
, "apc was called\n" );
592 SleepEx( 1, TRUE
); /* alertable sleep */
593 ok( apc_count
== 1, "apc was not called\n" );
596 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
597 ok(DuplicateHandle(GetCurrentProcess(), read
, GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
598 "Failed to duplicate handle: %d\n", GetLastError());
601 U(iosb
).Status
= 0xdeadbabe;
602 iosb
.Information
= 0xdeadbeef;
603 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
604 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
605 ok( !is_signaled( event
), "event is signaled\n" );
606 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
607 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
608 ok( !apc_count
, "apc was called\n" );
609 /* Cancel by other handle */
610 status
= pNtCancelIoFile( read
, &iosb2
);
611 ok(status
== STATUS_SUCCESS
, "failed to cancel by different handle: %x\n", status
);
612 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
613 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
614 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
615 ok( is_signaled( event
), "event is signaled\n" );
616 todo_wine
ok( !apc_count
, "apc was called\n" );
617 SleepEx( 1, TRUE
); /* alertable sleep */
618 ok( apc_count
== 1, "apc was not called\n" );
621 U(iosb
).Status
= 0xdeadbabe;
622 iosb
.Information
= 0xdeadbeef;
623 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
624 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
625 ok( !is_signaled( event
), "event is signaled\n" );
626 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
627 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
628 ok( !apc_count
, "apc was called\n" );
629 /* Close queued handle */
631 SleepEx( 1, TRUE
); /* alertable sleep */
632 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
633 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
634 status
= pNtCancelIoFile( read
, &iosb2
);
635 ok(status
== STATUS_INVALID_HANDLE
, "cancelled by closed handle?\n");
636 status
= pNtCancelIoFile( handle
, &iosb2
);
637 ok(status
== STATUS_SUCCESS
, "failed to cancel: %x\n", status
);
638 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
639 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
640 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
641 ok( is_signaled( event
), "event is signaled\n" );
642 todo_wine
ok( !apc_count
, "apc was called\n" );
643 SleepEx( 1, TRUE
); /* alertable sleep */
644 ok( apc_count
== 1, "apc was not called\n" );
645 CloseHandle( handle
);
646 CloseHandle( write
);
648 if (pNtCancelIoFileEx
)
650 /* Basic Cancel Ex */
651 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
654 U(iosb
).Status
= 0xdeadbabe;
655 iosb
.Information
= 0xdeadbeef;
656 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
657 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
658 ok( !is_signaled( event
), "event is signaled\n" );
659 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
660 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
661 ok( !apc_count
, "apc was called\n" );
662 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
663 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
664 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
665 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
666 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
667 ok( is_signaled( event
), "event is signaled\n" );
668 todo_wine
ok( !apc_count
, "apc was called\n" );
669 SleepEx( 1, TRUE
); /* alertable sleep */
670 ok( apc_count
== 1, "apc was not called\n" );
674 U(iosb
).Status
= 0xdeadbabe;
675 iosb
.Information
= 0xdeadbeef;
676 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
677 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
678 ok( !is_signaled( event
), "event is signaled\n" );
679 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
680 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
681 ok( !apc_count
, "apc was called\n" );
682 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
683 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
684 ok( !is_signaled( event
), "event is signaled\n" );
685 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
686 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
687 ok( !apc_count
, "apc was called\n" );
688 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
689 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
690 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
691 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
692 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
693 ok( is_signaled( event
), "event is signaled\n" );
694 todo_wine
ok( !apc_count
, "apc was called\n" );
695 SleepEx( 1, TRUE
); /* alertable sleep */
696 ok( apc_count
== 2, "apc was not called\n" );
699 CloseHandle( write
);
702 /* now try a real file */
703 if (!(handle
= create_temp_file( FILE_FLAG_OVERLAPPED
))) return;
705 U(iosb
).Status
= 0xdeadbabe;
706 iosb
.Information
= 0xdeadbeef;
709 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
710 ok( status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
, "wrong status %x\n", status
);
711 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
712 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
713 ok( is_signaled( event
), "event is signaled\n" );
714 ok( !apc_count
, "apc was called\n" );
715 SleepEx( 1, TRUE
); /* alertable sleep */
716 ok( apc_count
== 1, "apc was not called\n" );
719 U(iosb
).Status
= 0xdeadbabe;
720 iosb
.Information
= 0xdeadbeef;
723 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
724 ok( status
== STATUS_SUCCESS
||
725 status
== STATUS_PENDING
, /* vista */
726 "wrong status %x\n", status
);
727 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
728 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
729 ok( is_signaled( event
), "event is signaled\n" );
730 ok( !apc_count
, "apc was called\n" );
731 SleepEx( 1, TRUE
); /* alertable sleep */
732 ok( apc_count
== 1, "apc was not called\n" );
734 /* read beyond eof */
736 U(iosb
).Status
= 0xdeadbabe;
737 iosb
.Information
= 0xdeadbeef;
738 offset
.QuadPart
= strlen(text
) + 2;
739 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
740 if (status
== STATUS_PENDING
) /* vista */
742 ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
743 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
744 ok( is_signaled( event
), "event is signaled\n" );
745 ok( !apc_count
, "apc was called\n" );
746 SleepEx( 1, TRUE
); /* alertable sleep */
747 ok( apc_count
== 1, "apc was not called\n" );
751 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
752 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
753 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
754 ok( !is_signaled( event
), "event is signaled\n" );
755 ok( !apc_count
, "apc was called\n" );
756 SleepEx( 1, TRUE
); /* alertable sleep */
757 ok( !apc_count
, "apc was called\n" );
759 CloseHandle( handle
);
761 /* now a non-overlapped file */
762 if (!(handle
= create_temp_file(0))) return;
764 U(iosb
).Status
= 0xdeadbabe;
765 iosb
.Information
= 0xdeadbeef;
767 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
768 ok( status
== STATUS_END_OF_FILE
||
769 status
== STATUS_SUCCESS
||
770 status
== STATUS_PENDING
, /* vista */
771 "wrong status %x\n", status
);
772 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
773 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
774 ok( is_signaled( event
), "event is signaled\n" );
775 ok( !apc_count
, "apc was called\n" );
776 SleepEx( 1, TRUE
); /* alertable sleep */
777 ok( apc_count
== 1, "apc was not called\n" );
780 U(iosb
).Status
= 0xdeadbabe;
781 iosb
.Information
= 0xdeadbeef;
784 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
785 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
786 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
787 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
788 ok( is_signaled( event
), "event is signaled\n" );
789 ok( !apc_count
, "apc was called\n" );
790 SleepEx( 1, TRUE
); /* alertable sleep */
791 todo_wine
ok( !apc_count
, "apc was called\n" );
793 /* read beyond eof */
795 U(iosb
).Status
= 0xdeadbabe;
796 iosb
.Information
= 0xdeadbeef;
797 offset
.QuadPart
= strlen(text
) + 2;
799 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
800 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
801 todo_wine
ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
802 todo_wine
ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
803 todo_wine
ok( is_signaled( event
), "event is not signaled\n" );
804 ok( !apc_count
, "apc was called\n" );
805 SleepEx( 1, TRUE
); /* alertable sleep */
806 ok( !apc_count
, "apc was called\n" );
808 CloseHandle( handle
);
810 CloseHandle( event
);
813 static void nt_mailslot_test(void)
816 ACCESS_MASK DesiredAccess
;
817 OBJECT_ATTRIBUTES attr
;
821 ULONG MaxMessageSize
;
822 LARGE_INTEGER TimeOut
;
823 IO_STATUS_BLOCK IoStatusBlock
;
826 WCHAR buffer1
[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
827 'R',':','\\','F','R','E','D','\0' };
829 TimeOut
.QuadPart
= -1;
831 pRtlInitUnicodeString(&str
, buffer1
);
832 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
833 CreateOptions
= MailslotQuota
= MaxMessageSize
= 0;
834 DesiredAccess
= GENERIC_READ
;
837 * Check for NULL pointer handling
839 rc
= pNtCreateMailslotFile(NULL
, DesiredAccess
,
840 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
842 ok( rc
== STATUS_ACCESS_VIOLATION
||
843 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
844 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc
);
847 * Test to see if the Timeout can be NULL
849 hslot
= (HANDLE
)0xdeadbeef;
850 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
851 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
853 ok( rc
== STATUS_SUCCESS
||
854 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
855 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc
);
856 ok( hslot
!= 0, "Handle is invalid\n");
858 if ( rc
== STATUS_SUCCESS
) rc
= pNtClose(hslot
);
861 * Test that the length field is checked properly
864 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
865 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
867 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
869 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
871 attr
.Length
= sizeof(OBJECT_ATTRIBUTES
)+1;
872 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
873 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
875 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
877 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
880 * Test handling of a NULL unicode string in ObjectName
882 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
883 attr
.ObjectName
= NULL
;
884 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
885 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
887 ok( rc
== STATUS_OBJECT_PATH_SYNTAX_BAD
||
888 rc
== STATUS_INVALID_PARAMETER
,
889 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc
);
891 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
896 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
897 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
898 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
900 ok( rc
== STATUS_SUCCESS
, "Create MailslotFile failed rc = %x\n", rc
);
901 ok( hslot
!= 0, "Handle is invalid\n");
903 rc
= pNtClose(hslot
);
904 ok( rc
== STATUS_SUCCESS
, "NtClose failed\n");
907 static void test_iocp_setcompletion(HANDLE h
)
912 res
= pNtSetIoCompletion( h
, CKEY_FIRST
, CVALUE_FIRST
, STATUS_INVALID_DEVICE_REQUEST
, 3 );
913 ok( res
== STATUS_SUCCESS
, "NtSetIoCompletion failed: %x\n", res
);
915 count
= get_pending_msgs(h
);
916 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
920 ok( completionKey
== CKEY_FIRST
, "Invalid completion key: %lx\n", completionKey
);
921 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
922 ok( U(ioSb
).Status
== STATUS_INVALID_DEVICE_REQUEST
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
923 ok( completionValue
== CVALUE_FIRST
, "Invalid completion value: %lx\n", completionValue
);
926 count
= get_pending_msgs(h
);
927 ok( !count
, "Unexpected msg count: %ld\n", count
);
930 static void test_iocp_fileio(HANDLE h
)
932 static const char pipe_name
[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
934 IO_STATUS_BLOCK iosb
;
935 FILE_COMPLETION_INFORMATION fci
= {h
, CKEY_SECOND
};
936 HANDLE hPipeSrv
, hPipeClt
;
939 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
940 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
941 if (hPipeSrv
!= INVALID_HANDLE_VALUE
)
943 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
944 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
945 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
947 res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
948 ok( res
== STATUS_INVALID_PARAMETER
, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res
);
949 CloseHandle(hPipeClt
);
951 CloseHandle( hPipeSrv
);
954 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
| FILE_FLAG_OVERLAPPED
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
955 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
956 if (hPipeSrv
== INVALID_HANDLE_VALUE
)
959 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
960 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
961 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
964 BYTE send_buf
[TEST_BUF_LEN
], recv_buf
[TEST_BUF_LEN
];
968 NTSTATUS res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
969 ok( res
== STATUS_SUCCESS
, "NtSetInformationFile failed: %x\n", res
);
970 ok( U(iosb
).Status
== STATUS_SUCCESS
, "iosb.Status invalid: %x\n", U(iosb
).Status
);
972 memset( send_buf
, 0, TEST_BUF_LEN
);
973 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
974 count
= get_pending_msgs(h
);
975 ok( !count
, "Unexpected msg count: %ld\n", count
);
976 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
977 count
= get_pending_msgs(h
);
978 ok( !count
, "Unexpected msg count: %ld\n", count
);
979 WriteFile( hPipeClt
, send_buf
, TEST_BUF_LEN
, &read
, NULL
);
983 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
984 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
985 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
986 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
987 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] );
989 count
= get_pending_msgs(h
);
990 ok( !count
, "Unexpected msg count: %ld\n", count
);
992 memset( send_buf
, 0, TEST_BUF_LEN
);
993 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
994 WriteFile( hPipeClt
, send_buf
, 2, &read
, NULL
);
995 count
= get_pending_msgs(h
);
996 ok( !count
, "Unexpected msg count: %ld\n", count
);
997 ReadFile( hPipeSrv
, recv_buf
, 2, &read
, &o
);
998 count
= get_pending_msgs(h
);
999 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
1002 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1003 ok( ioSb
.Information
== 2, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1004 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1005 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1006 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] );
1009 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
1010 CloseHandle( hPipeSrv
);
1011 count
= get_pending_msgs(h
);
1012 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
1015 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1016 ok( ioSb
.Information
== 0, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1017 /* wine sends wrong status here */
1018 todo_wine
ok( U(ioSb
).Status
== STATUS_PIPE_BROKEN
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1019 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1023 CloseHandle( hPipeClt
);
1026 static void test_file_basic_information(void)
1029 FILE_BASIC_INFORMATION fbi
;
1032 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1034 if (!(h
= create_temp_file(0))) return;
1036 /* Check default first */
1037 memset(&fbi
, 0, sizeof(fbi
));
1038 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1039 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1040 ok ( (fbi
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1041 "attribute %x not expected\n", fbi
.FileAttributes
);
1044 /* Clear fbi to avoid setting times */
1045 memset(&fbi
, 0, sizeof(fbi
));
1046 fbi
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1047 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1048 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1050 memset(&fbi
, 0, sizeof(fbi
));
1051 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1052 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1053 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_SYSTEM
, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi
.FileAttributes
);
1056 memset(&fbi
, 0, sizeof(fbi
));
1057 fbi
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1058 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1059 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1061 memset(&fbi
, 0, sizeof(fbi
));
1062 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1063 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1064 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_HIDDEN
, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi
.FileAttributes
);
1066 /* Check NORMAL last of all (to make sure we can clear attributes) */
1067 memset(&fbi
, 0, sizeof(fbi
));
1068 fbi
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1069 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1070 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1072 memset(&fbi
, 0, sizeof(fbi
));
1073 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1074 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1075 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_NORMAL
, "attribute %x not 0\n", fbi
.FileAttributes
);
1080 static void test_file_all_information(void)
1083 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1084 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1085 * don't leave enough room there.
1088 FILE_ALL_INFORMATION fai
;
1093 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1095 if (!(h
= create_temp_file(0))) return;
1097 /* Check default first */
1098 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1099 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1100 ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1101 "attribute %x not expected\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1104 /* Clear fbi to avoid setting times */
1105 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1106 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1107 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1108 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to set FileAllInformation, res %x\n", res
);
1109 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1110 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1112 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1113 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1114 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1115 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
);
1118 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1119 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1120 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1121 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1123 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1124 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1125 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1126 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
);
1128 /* Check NORMAL last of all (to make sure we can clear attributes) */
1129 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1130 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1131 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1132 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1134 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1135 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1136 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1137 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
);
1142 static void test_file_both_information(void)
1145 FILE_BOTH_DIR_INFORMATION fbi
;
1149 if (!(h
= create_temp_file(0))) return;
1151 memset(&fbi
, 0, sizeof(fbi
));
1152 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBothDirectoryInformation
);
1153 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res
);
1158 static void test_iocompletion(void)
1160 HANDLE h
= INVALID_HANDLE_VALUE
;
1163 res
= pNtCreateIoCompletion( &h
, IO_COMPLETION_ALL_ACCESS
, NULL
, 0);
1165 ok( res
== 0, "NtCreateIoCompletion anonymous failed: %x\n", res
);
1166 ok( h
&& h
!= INVALID_HANDLE_VALUE
, "Invalid handle returned\n" );
1168 if ( h
&& h
!= INVALID_HANDLE_VALUE
)
1170 test_iocp_setcompletion(h
);
1171 test_iocp_fileio(h
);
1176 static void test_file_name_information(void)
1178 WCHAR
*file_name
, *volume_prefix
, *expected
;
1179 FILE_NAME_INFORMATION
*info
;
1180 ULONG old_redir
= 1, tmp
;
1181 UINT file_name_size
;
1188 /* GetVolumePathName is not present before w2k */
1189 if (!pGetVolumePathNameW
) {
1190 win_skip("GetVolumePathNameW not found\n");
1194 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1195 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1196 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1197 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1199 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1200 ok(len
== file_name_size
- 1,
1201 "GetSystemDirectoryW returned %u, expected %u.\n",
1202 len
, file_name_size
- 1);
1204 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1205 ok(len
, "GetVolumePathNameW failed.\n");
1207 len
= lstrlenW( volume_prefix
);
1208 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1209 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1210 expected
[file_name_size
- len
- 1] = '\0';
1212 /* A bit more than we actually need, but it keeps the calculation simple. */
1213 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1214 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1216 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1217 h
= CreateFileW( file_name
, GENERIC_READ
,
1218 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1219 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1220 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1221 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1223 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileNameInformation
);
1224 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x.\n", hr
);
1226 memset( info
, 0xcc, info_size
);
1227 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileNameInformation
);
1228 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1229 hr
, STATUS_BUFFER_OVERFLOW
);
1230 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1231 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1232 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1233 ok(info
->FileName
[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info
->FileName
[2]);
1234 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1235 "info->FileName[1] is %p, expected %p.\n",
1236 CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1237 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1239 memset( info
, 0xcc, info_size
);
1240 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1241 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1242 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1243 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1244 ok(info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1245 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)]);
1246 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1247 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1248 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1249 ok(io
.Information
== FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
,
1250 "io.Information is %lu, expected %u.\n",
1251 io
.Information
, FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
);
1254 HeapFree( GetProcessHeap(), 0, info
);
1255 HeapFree( GetProcessHeap(), 0, expected
);
1256 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1258 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1260 skip("Not running on WoW64, skipping test.\n");
1261 HeapFree( GetProcessHeap(), 0, file_name
);
1265 h
= CreateFileW( file_name
, GENERIC_READ
,
1266 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1267 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1268 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1269 HeapFree( GetProcessHeap(), 0, file_name
);
1271 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1272 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1273 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1275 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1276 ok(len
== file_name_size
- 1,
1277 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1278 len
, file_name_size
- 1);
1280 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1281 ok(len
, "GetVolumePathNameW failed.\n");
1283 len
= lstrlenW( volume_prefix
);
1284 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1285 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1286 expected
[file_name_size
- len
- 1] = '\0';
1288 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1289 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1291 memset( info
, 0xcc, info_size
);
1292 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1293 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1294 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1295 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1296 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1299 HeapFree( GetProcessHeap(), 0, info
);
1300 HeapFree( GetProcessHeap(), 0, expected
);
1301 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1302 HeapFree( GetProcessHeap(), 0, file_name
);
1305 static void test_file_all_name_information(void)
1307 WCHAR
*file_name
, *volume_prefix
, *expected
;
1308 FILE_ALL_INFORMATION
*info
;
1309 ULONG old_redir
= 1, tmp
;
1310 UINT file_name_size
;
1317 /* GetVolumePathName is not present before w2k */
1318 if (!pGetVolumePathNameW
) {
1319 win_skip("GetVolumePathNameW not found\n");
1323 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1324 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1325 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1326 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1328 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1329 ok(len
== file_name_size
- 1,
1330 "GetSystemDirectoryW returned %u, expected %u.\n",
1331 len
, file_name_size
- 1);
1333 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1334 ok(len
, "GetVolumePathNameW failed.\n");
1336 len
= lstrlenW( volume_prefix
);
1337 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1338 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1339 expected
[file_name_size
- len
- 1] = '\0';
1341 /* A bit more than we actually need, but it keeps the calculation simple. */
1342 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1343 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1345 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1346 h
= CreateFileW( file_name
, GENERIC_READ
,
1347 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1348 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1349 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1350 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1352 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileAllInformation
);
1353 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1354 hr
, STATUS_INFO_LENGTH_MISMATCH
);
1356 memset( info
, 0xcc, info_size
);
1357 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileAllInformation
);
1358 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1359 hr
, STATUS_BUFFER_OVERFLOW
);
1360 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1361 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1362 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1363 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1364 ok(info
->NameInformation
.FileName
[2] == 0xcccc,
1365 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info
->NameInformation
.FileName
[2]);
1366 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1367 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1368 CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1369 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1371 memset( info
, 0xcc, info_size
);
1372 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1373 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1374 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1375 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1376 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1377 ok(info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] == 0xcccc,
1378 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1379 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)]);
1380 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1381 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
),
1382 "info->NameInformation.FileName is %s, expected %s.\n",
1383 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1384 ok(io
.Information
== FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
)
1385 + info
->NameInformation
.FileNameLength
,
1386 "io.Information is %lu\n", io
.Information
);
1389 HeapFree( GetProcessHeap(), 0, info
);
1390 HeapFree( GetProcessHeap(), 0, expected
);
1391 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1393 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1395 skip("Not running on WoW64, skipping test.\n");
1396 HeapFree( GetProcessHeap(), 0, file_name
);
1400 h
= CreateFileW( file_name
, GENERIC_READ
,
1401 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1402 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1403 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1404 HeapFree( GetProcessHeap(), 0, file_name
);
1406 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1407 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1408 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1410 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1411 ok(len
== file_name_size
- 1,
1412 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1413 len
, file_name_size
- 1);
1415 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1416 ok(len
, "GetVolumePathNameW failed.\n");
1418 len
= lstrlenW( volume_prefix
);
1419 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1420 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1421 expected
[file_name_size
- len
- 1] = '\0';
1423 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1424 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1426 memset( info
, 0xcc, info_size
);
1427 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1428 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1429 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1430 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
), "info->NameInformation.FileName is %s, expected %s.\n",
1431 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1434 HeapFree( GetProcessHeap(), 0, info
);
1435 HeapFree( GetProcessHeap(), 0, expected
);
1436 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1437 HeapFree( GetProcessHeap(), 0, file_name
);
1442 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1443 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
1446 skip("not running on NT, skipping test\n");
1450 pGetVolumePathNameW
= (void *)GetProcAddress(hkernel32
, "GetVolumePathNameW");
1451 pGetSystemWow64DirectoryW
= (void *)GetProcAddress(hkernel32
, "GetSystemWow64DirectoryW");
1453 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
1454 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
1455 pRtlDosPathNameToNtPathName_U
= (void *)GetProcAddress(hntdll
, "RtlDosPathNameToNtPathName_U");
1456 pRtlWow64EnableFsRedirectionEx
= (void *)GetProcAddress(hntdll
, "RtlWow64EnableFsRedirectionEx");
1457 pNtCreateMailslotFile
= (void *)GetProcAddress(hntdll
, "NtCreateMailslotFile");
1458 pNtCreateFile
= (void *)GetProcAddress(hntdll
, "NtCreateFile");
1459 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
1460 pNtDeleteFile
= (void *)GetProcAddress(hntdll
, "NtDeleteFile");
1461 pNtReadFile
= (void *)GetProcAddress(hntdll
, "NtReadFile");
1462 pNtWriteFile
= (void *)GetProcAddress(hntdll
, "NtWriteFile");
1463 pNtCancelIoFile
= (void *)GetProcAddress(hntdll
, "NtCancelIoFile");
1464 pNtCancelIoFileEx
= (void *)GetProcAddress(hntdll
, "NtCancelIoFileEx");
1465 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
1466 pNtCreateIoCompletion
= (void *)GetProcAddress(hntdll
, "NtCreateIoCompletion");
1467 pNtOpenIoCompletion
= (void *)GetProcAddress(hntdll
, "NtOpenIoCompletion");
1468 pNtQueryIoCompletion
= (void *)GetProcAddress(hntdll
, "NtQueryIoCompletion");
1469 pNtRemoveIoCompletion
= (void *)GetProcAddress(hntdll
, "NtRemoveIoCompletion");
1470 pNtSetIoCompletion
= (void *)GetProcAddress(hntdll
, "NtSetIoCompletion");
1471 pNtSetInformationFile
= (void *)GetProcAddress(hntdll
, "NtSetInformationFile");
1472 pNtQueryInformationFile
= (void *)GetProcAddress(hntdll
, "NtQueryInformationFile");
1473 pNtQueryDirectoryFile
= (void *)GetProcAddress(hntdll
, "NtQueryDirectoryFile");
1480 test_iocompletion();
1481 test_file_basic_information();
1482 test_file_all_information();
1483 test_file_both_information();
1484 test_file_name_information();
1485 test_file_all_name_information();