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)
160 WCHAR path
[MAX_PATH
];
161 OBJECT_ATTRIBUTES attr
;
163 UNICODE_STRING nameW
;
166 len
= GetCurrentDirectoryW( MAX_PATH
, path
);
167 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
168 attr
.Length
= sizeof(attr
);
169 attr
.RootDirectory
= 0;
170 attr
.ObjectName
= &nameW
;
171 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
172 attr
.SecurityDescriptor
= NULL
;
173 attr
.SecurityQualityOfService
= NULL
;
175 /* try various open modes and options on directories */
176 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
177 FILE_OPEN
, FILE_DIRECTORY_FILE
, NULL
, 0 );
178 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
181 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
182 FILE_CREATE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
183 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
184 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
186 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
187 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
188 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
191 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
192 FILE_SUPERSEDE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
193 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
195 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
196 FILE_OVERWRITE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
197 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
199 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
200 FILE_OVERWRITE_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
201 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
203 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
204 FILE_OPEN
, 0, NULL
, 0 );
205 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
208 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
209 FILE_CREATE
, 0, NULL
, 0 );
210 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
211 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
213 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
214 FILE_OPEN_IF
, 0, NULL
, 0 );
215 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
218 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
219 FILE_SUPERSEDE
, 0, NULL
, 0 );
220 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
221 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
223 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
224 FILE_OVERWRITE
, 0, NULL
, 0 );
225 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
226 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
228 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
229 FILE_OVERWRITE_IF
, 0, NULL
, 0 );
230 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
231 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
233 pRtlFreeUnicodeString( &nameW
);
236 static void open_file_test(void)
239 HANDLE dir
, root
, handle
;
240 WCHAR path
[MAX_PATH
];
242 OBJECT_ATTRIBUTES attr
;
244 UNICODE_STRING nameW
;
248 len
= GetWindowsDirectoryW( path
, MAX_PATH
);
249 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
250 attr
.Length
= sizeof(attr
);
251 attr
.RootDirectory
= 0;
252 attr
.ObjectName
= &nameW
;
253 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
254 attr
.SecurityDescriptor
= NULL
;
255 attr
.SecurityQualityOfService
= NULL
;
256 status
= pNtOpenFile( &dir
, GENERIC_READ
, &attr
, &io
,
257 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
258 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
259 pRtlFreeUnicodeString( &nameW
);
261 path
[3] = 0; /* root of the drive */
262 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
263 status
= pNtOpenFile( &root
, GENERIC_READ
, &attr
, &io
,
264 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
265 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
266 pRtlFreeUnicodeString( &nameW
);
268 /* test opening system dir with RootDirectory set to windows dir */
269 GetSystemDirectoryW( path
, MAX_PATH
);
270 while (path
[len
] == '\\') len
++;
271 nameW
.Buffer
= path
+ len
;
272 nameW
.Length
= lstrlenW(path
+ len
) * sizeof(WCHAR
);
273 attr
.RootDirectory
= dir
;
274 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
275 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
276 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
277 CloseHandle( handle
);
279 /* try uppercase name */
280 for (i
= len
; path
[i
]; i
++) if (path
[i
] >= 'a' && path
[i
] <= 'z') path
[i
] -= 'a' - 'A';
281 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
282 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
283 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
284 CloseHandle( handle
);
286 /* try with leading backslash */
288 nameW
.Length
+= sizeof(WCHAR
);
289 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
290 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
291 ok( status
== STATUS_INVALID_PARAMETER
||
292 status
== STATUS_OBJECT_NAME_INVALID
||
293 status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
294 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
295 if (!status
) CloseHandle( handle
);
297 /* try with empty name */
299 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
300 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
301 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
302 CloseHandle( handle
);
304 /* try open by file id */
306 while (!pNtQueryDirectoryFile( dir
, NULL
, NULL
, NULL
, &io
, data
, sizeof(data
),
307 FileIdBothDirectoryInformation
, FALSE
, NULL
, restart
))
309 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)data
;
314 if (!info
->FileId
.QuadPart
) goto next
;
315 nameW
.Buffer
= (WCHAR
*)&info
->FileId
;
316 nameW
.Length
= sizeof(info
->FileId
);
317 info
->FileName
[info
->FileNameLength
/sizeof(WCHAR
)] = 0;
318 attr
.RootDirectory
= dir
;
319 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
320 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
321 FILE_OPEN_BY_FILE_ID
|
322 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
323 ok( status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_DENIED
|| status
== STATUS_NOT_IMPLEMENTED
,
324 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
325 if (status
== STATUS_NOT_IMPLEMENTED
)
327 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
332 FILE_ALL_INFORMATION all_info
;
334 if (!pNtQueryInformationFile( handle
, &io
, &all_info
, sizeof(all_info
), FileAllInformation
))
336 /* check that it's the same file */
337 ok( info
->EndOfFile
.QuadPart
== all_info
.StandardInformation
.EndOfFile
.QuadPart
,
338 "mismatched file size for %s\n", wine_dbgstr_w(info
->FileName
));
339 ok( info
->LastWriteTime
.QuadPart
== all_info
.BasicInformation
.LastWriteTime
.QuadPart
,
340 "mismatched write time for %s\n", wine_dbgstr_w(info
->FileName
));
342 CloseHandle( handle
);
344 /* try same thing from drive root */
345 attr
.RootDirectory
= root
;
346 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
347 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
348 FILE_OPEN_BY_FILE_ID
|
349 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
350 ok( status
== STATUS_SUCCESS
|| status
== STATUS_NOT_IMPLEMENTED
,
351 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
352 if (!status
) CloseHandle( handle
);
355 if (!info
->NextEntryOffset
) break;
356 info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)((char *)info
+ info
->NextEntryOffset
);
364 static void delete_file_test(void)
367 OBJECT_ATTRIBUTES attr
;
368 UNICODE_STRING nameW
;
369 WCHAR pathW
[MAX_PATH
];
370 WCHAR pathsubW
[MAX_PATH
];
371 static const WCHAR testdirW
[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
372 static const WCHAR subdirW
[] = {'\\','s','u','b',0};
374 ret
= GetTempPathW(MAX_PATH
, pathW
);
377 ok(0, "couldn't get temp dir\n");
380 if (ret
+ sizeof(testdirW
)/sizeof(WCHAR
)-1 + sizeof(subdirW
)/sizeof(WCHAR
)-1 >= MAX_PATH
)
382 ok(0, "MAX_PATH exceeded in constructing paths\n");
386 lstrcatW(pathW
, testdirW
);
387 lstrcpyW(pathsubW
, pathW
);
388 lstrcatW(pathsubW
, subdirW
);
390 ret
= CreateDirectoryW(pathW
, NULL
);
391 ok(ret
== TRUE
, "couldn't create directory ntdeletefile\n");
392 if (!pRtlDosPathNameToNtPathName_U(pathW
, &nameW
, NULL
, NULL
))
394 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
398 attr
.Length
= sizeof(attr
);
399 attr
.RootDirectory
= 0;
400 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
401 attr
.ObjectName
= &nameW
;
402 attr
.SecurityDescriptor
= NULL
;
403 attr
.SecurityQualityOfService
= NULL
;
405 /* test NtDeleteFile on an empty directory */
406 ret
= pNtDeleteFile(&attr
);
407 ok(ret
== STATUS_SUCCESS
, "NtDeleteFile should succeed in removing an empty directory\n");
408 ret
= RemoveDirectoryW(pathW
);
409 ok(ret
== FALSE
, "expected to fail removing directory, NtDeleteFile should have removed it\n");
411 /* test NtDeleteFile on a non-empty directory */
412 ret
= CreateDirectoryW(pathW
, NULL
);
413 ok(ret
== TRUE
, "couldn't create directory ntdeletefile ?!\n");
414 ret
= CreateDirectoryW(pathsubW
, NULL
);
415 ok(ret
== TRUE
, "couldn't create directory subdir\n");
416 ret
= pNtDeleteFile(&attr
);
417 ok(ret
== STATUS_SUCCESS
, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
418 ret
= RemoveDirectoryW(pathsubW
);
419 ok(ret
== TRUE
, "expected to remove directory ntdeletefile\\sub\n");
420 ret
= RemoveDirectoryW(pathW
);
421 ok(ret
== TRUE
, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
423 pRtlFreeUnicodeString( &nameW
);
426 static void read_file_test(void)
428 const char text
[] = "foobar";
429 HANDLE handle
, read
, write
;
431 IO_STATUS_BLOCK iosb
, iosb2
;
435 LARGE_INTEGER offset
;
436 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
440 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
442 /* try read with no data */
443 U(iosb
).Status
= 0xdeadbabe;
444 iosb
.Information
= 0xdeadbeef;
445 ok( is_signaled( read
), "read handle is not signaled\n" );
446 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
447 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
448 ok( !is_signaled( read
), "read handle is signaled\n" );
449 ok( !is_signaled( event
), "event is signaled\n" );
450 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
451 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
452 ok( !apc_count
, "apc was called\n" );
453 WriteFile( write
, buffer
, 1, &written
, NULL
);
454 /* iosb updated here by async i/o */
455 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
456 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
457 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
458 ok( !is_signaled( read
), "read handle is signaled\n" );
459 ok( is_signaled( event
), "event is not signaled\n" );
460 ok( !apc_count
, "apc was called\n" );
462 SleepEx( 1, FALSE
); /* non-alertable sleep */
463 ok( !apc_count
, "apc was called\n" );
464 SleepEx( 1, TRUE
); /* alertable sleep */
465 ok( apc_count
== 1, "apc not called\n" );
467 /* with no event, the pipe handle itself gets signaled */
469 U(iosb
).Status
= 0xdeadbabe;
470 iosb
.Information
= 0xdeadbeef;
471 ok( !is_signaled( read
), "read handle is not signaled\n" );
472 status
= pNtReadFile( read
, 0, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
473 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
474 ok( !is_signaled( read
), "read handle is signaled\n" );
475 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
476 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
477 ok( !apc_count
, "apc was called\n" );
478 WriteFile( write
, buffer
, 1, &written
, NULL
);
479 /* iosb updated here by async i/o */
480 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
481 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
482 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
483 ok( is_signaled( read
), "read handle is signaled\n" );
484 ok( !apc_count
, "apc was called\n" );
486 SleepEx( 1, FALSE
); /* non-alertable sleep */
487 ok( !apc_count
, "apc was called\n" );
488 SleepEx( 1, TRUE
); /* alertable sleep */
489 ok( apc_count
== 1, "apc not called\n" );
491 /* now read with data ready */
493 U(iosb
).Status
= 0xdeadbabe;
494 iosb
.Information
= 0xdeadbeef;
496 WriteFile( write
, buffer
, 1, &written
, NULL
);
497 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
498 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
499 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
500 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
501 ok( is_signaled( event
), "event is not signaled\n" );
502 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 /* try read with no data */
510 U(iosb
).Status
= 0xdeadbabe;
511 iosb
.Information
= 0xdeadbeef;
512 ok( is_signaled( event
), "event is not signaled\n" ); /* check that read resets the event */
513 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
514 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
515 ok( !is_signaled( event
), "event is signaled\n" );
516 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
517 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
518 ok( !apc_count
, "apc was called\n" );
519 WriteFile( write
, buffer
, 1, &written
, NULL
);
520 /* partial read is good enough */
521 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
522 ok( is_signaled( event
), "event is signaled\n" );
523 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
524 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
525 ok( !apc_count
, "apc was called\n" );
526 SleepEx( 1, TRUE
); /* alertable sleep */
527 ok( apc_count
== 1, "apc was not called\n" );
529 /* read from disconnected pipe */
531 U(iosb
).Status
= 0xdeadbabe;
532 iosb
.Information
= 0xdeadbeef;
533 CloseHandle( write
);
534 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
535 ok( status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", status
);
536 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
537 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
538 ok( !is_signaled( event
), "event is signaled\n" );
539 ok( !apc_count
, "apc was called\n" );
540 SleepEx( 1, TRUE
); /* alertable sleep */
541 ok( !apc_count
, "apc was called\n" );
544 /* read from closed handle */
546 U(iosb
).Status
= 0xdeadbabe;
547 iosb
.Information
= 0xdeadbeef;
549 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
550 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
551 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
552 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
553 ok( is_signaled( event
), "event is signaled\n" ); /* not reset on invalid handle */
554 ok( !apc_count
, "apc was called\n" );
555 SleepEx( 1, TRUE
); /* alertable sleep */
556 ok( !apc_count
, "apc was called\n" );
558 /* disconnect while async read is in progress */
559 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
561 U(iosb
).Status
= 0xdeadbabe;
562 iosb
.Information
= 0xdeadbeef;
563 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
564 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
565 ok( !is_signaled( event
), "event is signaled\n" );
566 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
567 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
568 ok( !apc_count
, "apc was called\n" );
569 CloseHandle( write
);
570 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
571 ok( U(iosb
).Status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", U(iosb
).Status
);
572 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
573 ok( is_signaled( event
), "event is signaled\n" );
574 ok( !apc_count
, "apc was called\n" );
575 SleepEx( 1, TRUE
); /* alertable sleep */
576 ok( apc_count
== 1, "apc was not called\n" );
579 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
580 ok(DuplicateHandle(GetCurrentProcess(), read
, GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
581 "Failed to duplicate handle: %d\n", GetLastError());
584 U(iosb
).Status
= 0xdeadbabe;
585 iosb
.Information
= 0xdeadbeef;
586 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
587 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
588 ok( !is_signaled( event
), "event is signaled\n" );
589 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
590 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
591 ok( !apc_count
, "apc was called\n" );
592 /* Cancel by other handle */
593 status
= pNtCancelIoFile( read
, &iosb2
);
594 ok(status
== STATUS_SUCCESS
, "failed to cancel by different handle: %x\n", status
);
595 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
596 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
597 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
598 ok( is_signaled( event
), "event is signaled\n" );
599 todo_wine
ok( !apc_count
, "apc was called\n" );
600 SleepEx( 1, TRUE
); /* alertable sleep */
601 ok( apc_count
== 1, "apc was not called\n" );
604 U(iosb
).Status
= 0xdeadbabe;
605 iosb
.Information
= 0xdeadbeef;
606 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
607 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
608 ok( !is_signaled( event
), "event is signaled\n" );
609 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
610 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
611 ok( !apc_count
, "apc was called\n" );
612 /* Close queued handle */
614 SleepEx( 1, TRUE
); /* alertable sleep */
615 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
616 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
617 status
= pNtCancelIoFile( read
, &iosb2
);
618 ok(status
== STATUS_INVALID_HANDLE
, "cancelled by closed handle?\n");
619 status
= pNtCancelIoFile( handle
, &iosb2
);
620 ok(status
== STATUS_SUCCESS
, "failed to cancel: %x\n", status
);
621 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
622 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
623 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
624 ok( is_signaled( event
), "event is signaled\n" );
625 todo_wine
ok( !apc_count
, "apc was called\n" );
626 SleepEx( 1, TRUE
); /* alertable sleep */
627 ok( apc_count
== 1, "apc was not called\n" );
628 CloseHandle( handle
);
629 CloseHandle( write
);
631 if (pNtCancelIoFileEx
)
633 /* Basic Cancel Ex */
634 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
637 U(iosb
).Status
= 0xdeadbabe;
638 iosb
.Information
= 0xdeadbeef;
639 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
640 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
641 ok( !is_signaled( event
), "event is signaled\n" );
642 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
643 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
644 ok( !apc_count
, "apc was called\n" );
645 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
646 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
647 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
648 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
649 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
650 ok( is_signaled( event
), "event is signaled\n" );
651 todo_wine
ok( !apc_count
, "apc was called\n" );
652 SleepEx( 1, TRUE
); /* alertable sleep */
653 ok( apc_count
== 1, "apc was not called\n" );
657 U(iosb
).Status
= 0xdeadbabe;
658 iosb
.Information
= 0xdeadbeef;
659 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
660 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
661 ok( !is_signaled( event
), "event is signaled\n" );
662 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
663 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
664 ok( !apc_count
, "apc was called\n" );
665 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
666 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
667 ok( !is_signaled( event
), "event is signaled\n" );
668 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
669 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
670 ok( !apc_count
, "apc was called\n" );
671 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
672 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
673 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
674 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
675 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
676 ok( is_signaled( event
), "event is signaled\n" );
677 todo_wine
ok( !apc_count
, "apc was called\n" );
678 SleepEx( 1, TRUE
); /* alertable sleep */
679 ok( apc_count
== 2, "apc was not called\n" );
682 CloseHandle( write
);
685 /* now try a real file */
686 if (!(handle
= create_temp_file( FILE_FLAG_OVERLAPPED
))) return;
688 U(iosb
).Status
= 0xdeadbabe;
689 iosb
.Information
= 0xdeadbeef;
692 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
693 ok( status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
, "wrong status %x\n", status
);
694 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
695 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
696 ok( is_signaled( event
), "event is signaled\n" );
697 ok( !apc_count
, "apc was called\n" );
698 SleepEx( 1, TRUE
); /* alertable sleep */
699 ok( apc_count
== 1, "apc was not called\n" );
702 U(iosb
).Status
= 0xdeadbabe;
703 iosb
.Information
= 0xdeadbeef;
706 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
707 ok( status
== STATUS_SUCCESS
||
708 status
== STATUS_PENDING
, /* vista */
709 "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 /* read beyond eof */
719 U(iosb
).Status
= 0xdeadbabe;
720 iosb
.Information
= 0xdeadbeef;
721 offset
.QuadPart
= strlen(text
) + 2;
722 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
723 if (status
== STATUS_PENDING
) /* vista */
725 ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
726 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
727 ok( is_signaled( event
), "event is signaled\n" );
728 ok( !apc_count
, "apc was called\n" );
729 SleepEx( 1, TRUE
); /* alertable sleep */
730 ok( apc_count
== 1, "apc was not called\n" );
734 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
735 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
736 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
737 ok( !is_signaled( event
), "event is signaled\n" );
738 ok( !apc_count
, "apc was called\n" );
739 SleepEx( 1, TRUE
); /* alertable sleep */
740 ok( !apc_count
, "apc was called\n" );
742 CloseHandle( handle
);
744 /* now a non-overlapped file */
745 if (!(handle
= create_temp_file(0))) return;
747 U(iosb
).Status
= 0xdeadbabe;
748 iosb
.Information
= 0xdeadbeef;
750 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
751 ok( status
== STATUS_END_OF_FILE
||
752 status
== STATUS_SUCCESS
||
753 status
== STATUS_PENDING
, /* vista */
754 "wrong status %x\n", status
);
755 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
756 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
757 ok( is_signaled( event
), "event is signaled\n" );
758 ok( !apc_count
, "apc was called\n" );
759 SleepEx( 1, TRUE
); /* alertable sleep */
760 ok( apc_count
== 1, "apc was not called\n" );
763 U(iosb
).Status
= 0xdeadbabe;
764 iosb
.Information
= 0xdeadbeef;
767 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
768 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
769 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
770 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
771 ok( is_signaled( event
), "event is signaled\n" );
772 ok( !apc_count
, "apc was called\n" );
773 SleepEx( 1, TRUE
); /* alertable sleep */
774 todo_wine
ok( !apc_count
, "apc was called\n" );
776 /* read beyond eof */
778 U(iosb
).Status
= 0xdeadbabe;
779 iosb
.Information
= 0xdeadbeef;
780 offset
.QuadPart
= strlen(text
) + 2;
782 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
783 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
784 todo_wine
ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
785 todo_wine
ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
786 todo_wine
ok( is_signaled( event
), "event is not signaled\n" );
787 ok( !apc_count
, "apc was called\n" );
788 SleepEx( 1, TRUE
); /* alertable sleep */
789 ok( !apc_count
, "apc was called\n" );
791 CloseHandle( handle
);
793 CloseHandle( event
);
796 static void nt_mailslot_test(void)
799 ACCESS_MASK DesiredAccess
;
800 OBJECT_ATTRIBUTES attr
;
804 ULONG MaxMessageSize
;
805 LARGE_INTEGER TimeOut
;
806 IO_STATUS_BLOCK IoStatusBlock
;
809 WCHAR buffer1
[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
810 'R',':','\\','F','R','E','D','\0' };
812 TimeOut
.QuadPart
= -1;
814 pRtlInitUnicodeString(&str
, buffer1
);
815 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
816 CreateOptions
= MailslotQuota
= MaxMessageSize
= 0;
817 DesiredAccess
= GENERIC_READ
;
820 * Check for NULL pointer handling
822 rc
= pNtCreateMailslotFile(NULL
, DesiredAccess
,
823 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
825 ok( rc
== STATUS_ACCESS_VIOLATION
||
826 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
827 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc
);
830 * Test to see if the Timeout can be NULL
832 hslot
= (HANDLE
)0xdeadbeef;
833 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
834 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
836 ok( rc
== STATUS_SUCCESS
||
837 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
838 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc
);
839 ok( hslot
!= 0, "Handle is invalid\n");
841 if ( rc
== STATUS_SUCCESS
) rc
= pNtClose(hslot
);
844 * Test that the length field is checked properly
847 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
848 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
850 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
852 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
854 attr
.Length
= sizeof(OBJECT_ATTRIBUTES
)+1;
855 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
856 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
858 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
860 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
863 * Test handling of a NULL unicode string in ObjectName
865 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
866 attr
.ObjectName
= NULL
;
867 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
868 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
870 ok( rc
== STATUS_OBJECT_PATH_SYNTAX_BAD
||
871 rc
== STATUS_INVALID_PARAMETER
,
872 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc
);
874 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
879 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
880 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
881 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
883 ok( rc
== STATUS_SUCCESS
, "Create MailslotFile failed rc = %x\n", rc
);
884 ok( hslot
!= 0, "Handle is invalid\n");
886 rc
= pNtClose(hslot
);
887 ok( rc
== STATUS_SUCCESS
, "NtClose failed\n");
890 static void test_iocp_setcompletion(HANDLE h
)
895 res
= pNtSetIoCompletion( h
, CKEY_FIRST
, CVALUE_FIRST
, STATUS_INVALID_DEVICE_REQUEST
, 3 );
896 ok( res
== STATUS_SUCCESS
, "NtSetIoCompletion failed: %x\n", res
);
898 count
= get_pending_msgs(h
);
899 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
903 ok( completionKey
== CKEY_FIRST
, "Invalid completion key: %lx\n", completionKey
);
904 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
905 ok( U(ioSb
).Status
== STATUS_INVALID_DEVICE_REQUEST
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
906 ok( completionValue
== CVALUE_FIRST
, "Invalid completion value: %lx\n", completionValue
);
909 count
= get_pending_msgs(h
);
910 ok( !count
, "Unexpected msg count: %ld\n", count
);
913 static void test_iocp_fileio(HANDLE h
)
915 static const char pipe_name
[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
917 IO_STATUS_BLOCK iosb
;
918 FILE_COMPLETION_INFORMATION fci
= {h
, CKEY_SECOND
};
919 HANDLE hPipeSrv
, hPipeClt
;
922 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
923 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
924 if (hPipeSrv
!= INVALID_HANDLE_VALUE
)
926 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
927 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
928 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
930 res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
931 ok( res
== STATUS_INVALID_PARAMETER
, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res
);
932 CloseHandle(hPipeClt
);
934 CloseHandle( hPipeSrv
);
937 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
| FILE_FLAG_OVERLAPPED
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
938 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
939 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
)
947 BYTE send_buf
[TEST_BUF_LEN
], recv_buf
[TEST_BUF_LEN
];
951 NTSTATUS res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
952 ok( res
== STATUS_SUCCESS
, "NtSetInformationFile failed: %x\n", res
);
953 ok( U(iosb
).Status
== STATUS_SUCCESS
, "iosb.Status invalid: %x\n", U(iosb
).Status
);
955 memset( send_buf
, 0, TEST_BUF_LEN
);
956 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
957 count
= get_pending_msgs(h
);
958 ok( !count
, "Unexpected msg count: %ld\n", count
);
959 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
960 count
= get_pending_msgs(h
);
961 ok( !count
, "Unexpected msg count: %ld\n", count
);
962 WriteFile( hPipeClt
, send_buf
, TEST_BUF_LEN
, &read
, NULL
);
966 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
967 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
968 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
969 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
970 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] );
972 count
= get_pending_msgs(h
);
973 ok( !count
, "Unexpected msg count: %ld\n", count
);
975 memset( send_buf
, 0, TEST_BUF_LEN
);
976 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
977 WriteFile( hPipeClt
, send_buf
, 2, &read
, NULL
);
978 count
= get_pending_msgs(h
);
979 ok( !count
, "Unexpected msg count: %ld\n", count
);
980 ReadFile( hPipeSrv
, recv_buf
, 2, &read
, &o
);
981 count
= get_pending_msgs(h
);
982 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
985 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
986 ok( ioSb
.Information
== 2, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
987 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
988 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
989 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] );
992 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
993 CloseHandle( hPipeSrv
);
994 count
= get_pending_msgs(h
);
995 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
998 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
999 ok( ioSb
.Information
== 0, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1000 /* wine sends wrong status here */
1001 todo_wine
ok( U(ioSb
).Status
== STATUS_PIPE_BROKEN
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1002 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1006 CloseHandle( hPipeClt
);
1009 static void test_file_basic_information(void)
1012 FILE_BASIC_INFORMATION fbi
;
1015 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1017 if (!(h
= create_temp_file(0))) return;
1019 /* Check default first */
1020 memset(&fbi
, 0, sizeof(fbi
));
1021 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1022 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1023 ok ( (fbi
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1024 "attribute %x not expected\n", fbi
.FileAttributes
);
1027 /* Clear fbi to avoid setting times */
1028 memset(&fbi
, 0, sizeof(fbi
));
1029 fbi
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1030 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1031 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1033 memset(&fbi
, 0, sizeof(fbi
));
1034 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1035 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1036 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_SYSTEM
, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi
.FileAttributes
);
1039 memset(&fbi
, 0, sizeof(fbi
));
1040 fbi
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1041 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1042 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1044 memset(&fbi
, 0, sizeof(fbi
));
1045 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1046 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1047 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_HIDDEN
, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi
.FileAttributes
);
1049 /* Check NORMAL last of all (to make sure we can clear attributes) */
1050 memset(&fbi
, 0, sizeof(fbi
));
1051 fbi
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1052 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1053 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1055 memset(&fbi
, 0, sizeof(fbi
));
1056 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1057 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1058 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_NORMAL
, "attribute %x not 0\n", fbi
.FileAttributes
);
1063 static void test_file_all_information(void)
1066 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1067 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1068 * don't leave enough room there.
1071 FILE_ALL_INFORMATION fai
;
1076 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1078 if (!(h
= create_temp_file(0))) return;
1080 /* Check default first */
1081 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1082 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1083 ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1084 "attribute %x not expected\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1087 /* Clear fbi to avoid setting times */
1088 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1089 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1090 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1091 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to set FileAllInformation, res %x\n", res
);
1092 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1093 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1095 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1096 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1097 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1098 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
);
1101 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1102 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1103 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1104 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1106 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1107 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1108 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1109 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
);
1111 /* Check NORMAL last of all (to make sure we can clear attributes) */
1112 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1113 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1114 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1115 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1117 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1118 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1119 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1120 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
);
1125 static void test_file_both_information(void)
1128 FILE_BOTH_DIR_INFORMATION fbi
;
1132 if (!(h
= create_temp_file(0))) return;
1134 memset(&fbi
, 0, sizeof(fbi
));
1135 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBothDirectoryInformation
);
1136 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res
);
1141 static void test_iocompletion(void)
1143 HANDLE h
= INVALID_HANDLE_VALUE
;
1146 res
= pNtCreateIoCompletion( &h
, IO_COMPLETION_ALL_ACCESS
, NULL
, 0);
1148 ok( res
== 0, "NtCreateIoCompletion anonymous failed: %x\n", res
);
1149 ok( h
&& h
!= INVALID_HANDLE_VALUE
, "Invalid handle returned\n" );
1151 if ( h
&& h
!= INVALID_HANDLE_VALUE
)
1153 test_iocp_setcompletion(h
);
1154 test_iocp_fileio(h
);
1159 static void test_file_name_information(void)
1161 WCHAR
*file_name
, *volume_prefix
, *expected
;
1162 FILE_NAME_INFORMATION
*info
;
1163 ULONG old_redir
= 1, tmp
;
1164 UINT file_name_size
;
1171 /* GetVolumePathName is not present before w2k */
1172 if (!pGetVolumePathNameW
) {
1173 win_skip("GetVolumePathNameW not found\n");
1177 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1178 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1179 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1180 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1182 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1183 ok(len
== file_name_size
- 1,
1184 "GetSystemDirectoryW returned %u, expected %u.\n",
1185 len
, file_name_size
- 1);
1187 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1188 ok(len
, "GetVolumePathNameW failed.\n");
1190 len
= lstrlenW( volume_prefix
);
1191 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1192 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1193 expected
[file_name_size
- len
- 1] = '\0';
1195 /* A bit more than we actually need, but it keeps the calculation simple. */
1196 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1197 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1199 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1200 h
= CreateFileW( file_name
, GENERIC_READ
,
1201 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1202 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1203 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1204 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1206 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileNameInformation
);
1207 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x.\n", hr
);
1209 memset( info
, 0xcc, info_size
);
1210 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileNameInformation
);
1211 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1212 hr
, STATUS_BUFFER_OVERFLOW
);
1213 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1214 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1215 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1216 ok(info
->FileName
[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info
->FileName
[2]);
1217 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1218 "info->FileName[1] is %p, expected %p.\n",
1219 CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1220 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1222 memset( info
, 0xcc, info_size
);
1223 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1224 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1225 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1226 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1227 ok(info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1228 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)]);
1229 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1230 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1231 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1232 ok(io
.Information
== FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
,
1233 "io.Information is %lu, expected %u.\n",
1234 io
.Information
, FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
);
1237 HeapFree( GetProcessHeap(), 0, info
);
1238 HeapFree( GetProcessHeap(), 0, expected
);
1239 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1241 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1243 skip("Not running on WoW64, skipping test.\n");
1244 HeapFree( GetProcessHeap(), 0, file_name
);
1248 h
= CreateFileW( file_name
, GENERIC_READ
,
1249 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1250 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1251 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1252 HeapFree( GetProcessHeap(), 0, file_name
);
1254 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1255 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1256 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1258 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1259 ok(len
== file_name_size
- 1,
1260 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1261 len
, file_name_size
- 1);
1263 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1264 ok(len
, "GetVolumePathNameW failed.\n");
1266 len
= lstrlenW( volume_prefix
);
1267 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1268 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1269 expected
[file_name_size
- len
- 1] = '\0';
1271 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1272 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1274 memset( info
, 0xcc, info_size
);
1275 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1276 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1277 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1278 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1279 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1282 HeapFree( GetProcessHeap(), 0, info
);
1283 HeapFree( GetProcessHeap(), 0, expected
);
1284 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1285 HeapFree( GetProcessHeap(), 0, file_name
);
1288 static void test_file_all_name_information(void)
1290 WCHAR
*file_name
, *volume_prefix
, *expected
;
1291 FILE_ALL_INFORMATION
*info
;
1292 ULONG old_redir
= 1, tmp
;
1293 UINT file_name_size
;
1300 /* GetVolumePathName is not present before w2k */
1301 if (!pGetVolumePathNameW
) {
1302 win_skip("GetVolumePathNameW not found\n");
1306 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1307 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1308 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1309 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1311 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1312 ok(len
== file_name_size
- 1,
1313 "GetSystemDirectoryW returned %u, expected %u.\n",
1314 len
, file_name_size
- 1);
1316 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1317 ok(len
, "GetVolumePathNameW failed.\n");
1319 len
= lstrlenW( volume_prefix
);
1320 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1321 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1322 expected
[file_name_size
- len
- 1] = '\0';
1324 /* A bit more than we actually need, but it keeps the calculation simple. */
1325 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1326 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1328 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1329 h
= CreateFileW( file_name
, GENERIC_READ
,
1330 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1331 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1332 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1333 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1335 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileAllInformation
);
1336 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1337 hr
, STATUS_INFO_LENGTH_MISMATCH
);
1339 memset( info
, 0xcc, info_size
);
1340 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileAllInformation
);
1341 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1342 hr
, STATUS_BUFFER_OVERFLOW
);
1343 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1344 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1345 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1346 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1347 ok(info
->NameInformation
.FileName
[2] == 0xcccc,
1348 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info
->NameInformation
.FileName
[2]);
1349 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1350 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1351 CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1352 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1354 memset( info
, 0xcc, info_size
);
1355 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1356 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1357 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1358 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1359 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1360 ok(info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] == 0xcccc,
1361 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1362 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)]);
1363 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1364 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
),
1365 "info->NameInformation.FileName is %s, expected %s.\n",
1366 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1367 ok(io
.Information
== FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
)
1368 + info
->NameInformation
.FileNameLength
,
1369 "io.Information is %lu\n", io
.Information
);
1372 HeapFree( GetProcessHeap(), 0, info
);
1373 HeapFree( GetProcessHeap(), 0, expected
);
1374 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1376 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1378 skip("Not running on WoW64, skipping test.\n");
1379 HeapFree( GetProcessHeap(), 0, file_name
);
1383 h
= CreateFileW( file_name
, GENERIC_READ
,
1384 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1385 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1386 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1387 HeapFree( GetProcessHeap(), 0, file_name
);
1389 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1390 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1391 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1393 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1394 ok(len
== file_name_size
- 1,
1395 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1396 len
, file_name_size
- 1);
1398 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1399 ok(len
, "GetVolumePathNameW failed.\n");
1401 len
= lstrlenW( volume_prefix
);
1402 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1403 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1404 expected
[file_name_size
- len
- 1] = '\0';
1406 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1407 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1409 memset( info
, 0xcc, info_size
);
1410 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1411 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1412 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1413 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
), "info->NameInformation.FileName is %s, expected %s.\n",
1414 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1417 HeapFree( GetProcessHeap(), 0, info
);
1418 HeapFree( GetProcessHeap(), 0, expected
);
1419 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1420 HeapFree( GetProcessHeap(), 0, file_name
);
1425 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1426 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
1429 skip("not running on NT, skipping test\n");
1433 pGetVolumePathNameW
= (void *)GetProcAddress(hkernel32
, "GetVolumePathNameW");
1434 pGetSystemWow64DirectoryW
= (void *)GetProcAddress(hkernel32
, "GetSystemWow64DirectoryW");
1436 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
1437 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
1438 pRtlDosPathNameToNtPathName_U
= (void *)GetProcAddress(hntdll
, "RtlDosPathNameToNtPathName_U");
1439 pRtlWow64EnableFsRedirectionEx
= (void *)GetProcAddress(hntdll
, "RtlWow64EnableFsRedirectionEx");
1440 pNtCreateMailslotFile
= (void *)GetProcAddress(hntdll
, "NtCreateMailslotFile");
1441 pNtCreateFile
= (void *)GetProcAddress(hntdll
, "NtCreateFile");
1442 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
1443 pNtDeleteFile
= (void *)GetProcAddress(hntdll
, "NtDeleteFile");
1444 pNtReadFile
= (void *)GetProcAddress(hntdll
, "NtReadFile");
1445 pNtWriteFile
= (void *)GetProcAddress(hntdll
, "NtWriteFile");
1446 pNtCancelIoFile
= (void *)GetProcAddress(hntdll
, "NtCancelIoFile");
1447 pNtCancelIoFileEx
= (void *)GetProcAddress(hntdll
, "NtCancelIoFileEx");
1448 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
1449 pNtCreateIoCompletion
= (void *)GetProcAddress(hntdll
, "NtCreateIoCompletion");
1450 pNtOpenIoCompletion
= (void *)GetProcAddress(hntdll
, "NtOpenIoCompletion");
1451 pNtQueryIoCompletion
= (void *)GetProcAddress(hntdll
, "NtQueryIoCompletion");
1452 pNtRemoveIoCompletion
= (void *)GetProcAddress(hntdll
, "NtRemoveIoCompletion");
1453 pNtSetIoCompletion
= (void *)GetProcAddress(hntdll
, "NtSetIoCompletion");
1454 pNtSetInformationFile
= (void *)GetProcAddress(hntdll
, "NtSetInformationFile");
1455 pNtQueryInformationFile
= (void *)GetProcAddress(hntdll
, "NtQueryInformationFile");
1456 pNtQueryDirectoryFile
= (void *)GetProcAddress(hntdll
, "NtQueryDirectoryFile");
1463 test_iocompletion();
1464 test_file_basic_information();
1465 test_file_all_information();
1466 test_file_both_information();
1467 test_file_name_information();
1468 test_file_all_name_information();