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 ULONG
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
;
167 GetCurrentDirectoryW( MAX_PATH
, path
);
168 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
169 attr
.Length
= sizeof(attr
);
170 attr
.RootDirectory
= 0;
171 attr
.ObjectName
= &nameW
;
172 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
173 attr
.SecurityDescriptor
= NULL
;
174 attr
.SecurityQualityOfService
= NULL
;
176 /* try various open modes and options on directories */
177 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
178 FILE_OPEN
, FILE_DIRECTORY_FILE
, NULL
, 0 );
179 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
182 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
183 FILE_CREATE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
184 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
185 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
187 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
188 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
189 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
192 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
193 FILE_SUPERSEDE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
194 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
196 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
197 FILE_OVERWRITE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
198 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
200 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
201 FILE_OVERWRITE_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
202 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
204 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
205 FILE_OPEN
, 0, NULL
, 0 );
206 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
209 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
210 FILE_CREATE
, 0, NULL
, 0 );
211 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
212 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
214 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
215 FILE_OPEN_IF
, 0, NULL
, 0 );
216 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
219 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
220 FILE_SUPERSEDE
, 0, NULL
, 0 );
221 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
222 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
224 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
225 FILE_OVERWRITE
, 0, NULL
, 0 );
226 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
227 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
229 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
230 FILE_OVERWRITE_IF
, 0, NULL
, 0 );
231 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
232 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
234 pRtlFreeUnicodeString( &nameW
);
236 pRtlInitUnicodeString( &nameW
, systemrootW
);
237 attr
.Length
= sizeof(attr
);
238 attr
.RootDirectory
= NULL
;
239 attr
.ObjectName
= &nameW
;
240 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
241 attr
.SecurityDescriptor
= NULL
;
242 attr
.SecurityQualityOfService
= NULL
;
244 status
= pNtCreateFile( &dir
, FILE_APPEND_DATA
, &attr
, &io
, NULL
, FILE_ATTRIBUTE_NORMAL
, 0,
245 FILE_OPEN_IF
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0 );
247 ok( status
== STATUS_INVALID_PARAMETER
,
248 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
251 static void open_file_test(void)
254 HANDLE dir
, root
, handle
;
255 WCHAR path
[MAX_PATH
];
257 OBJECT_ATTRIBUTES attr
;
259 UNICODE_STRING nameW
;
263 len
= GetWindowsDirectoryW( path
, MAX_PATH
);
264 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
265 attr
.Length
= sizeof(attr
);
266 attr
.RootDirectory
= 0;
267 attr
.ObjectName
= &nameW
;
268 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
269 attr
.SecurityDescriptor
= NULL
;
270 attr
.SecurityQualityOfService
= NULL
;
271 status
= pNtOpenFile( &dir
, SYNCHRONIZE
|FILE_LIST_DIRECTORY
, &attr
, &io
,
272 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
);
273 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
274 pRtlFreeUnicodeString( &nameW
);
276 path
[3] = 0; /* root of the drive */
277 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
278 status
= pNtOpenFile( &root
, GENERIC_READ
, &attr
, &io
,
279 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
280 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
281 pRtlFreeUnicodeString( &nameW
);
283 /* test opening system dir with RootDirectory set to windows dir */
284 GetSystemDirectoryW( path
, MAX_PATH
);
285 while (path
[len
] == '\\') len
++;
286 nameW
.Buffer
= path
+ len
;
287 nameW
.Length
= lstrlenW(path
+ len
) * sizeof(WCHAR
);
288 attr
.RootDirectory
= dir
;
289 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
290 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
291 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
292 CloseHandle( handle
);
294 /* try uppercase name */
295 for (i
= len
; path
[i
]; i
++) if (path
[i
] >= 'a' && path
[i
] <= 'z') path
[i
] -= 'a' - 'A';
296 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
297 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
298 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
299 CloseHandle( handle
);
301 /* try with leading backslash */
303 nameW
.Length
+= sizeof(WCHAR
);
304 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
305 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
306 ok( status
== STATUS_INVALID_PARAMETER
||
307 status
== STATUS_OBJECT_NAME_INVALID
||
308 status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
309 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
310 if (!status
) CloseHandle( handle
);
312 /* try with empty name */
314 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
315 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
316 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
317 CloseHandle( handle
);
319 /* try open by file id */
321 while (!pNtQueryDirectoryFile( dir
, NULL
, NULL
, NULL
, &io
, data
, sizeof(data
),
322 FileIdBothDirectoryInformation
, TRUE
, NULL
, restart
))
324 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)data
;
328 if (!info
->FileId
.QuadPart
) continue;
330 nameW
.Buffer
= (WCHAR
*)&info
->FileId
;
331 nameW
.Length
= sizeof(info
->FileId
);
332 info
->FileName
[info
->FileNameLength
/sizeof(WCHAR
)] = 0;
333 attr
.RootDirectory
= dir
;
334 /* We skip 'open' files by not specifying FILE_SHARE_WRITE */
335 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
337 FILE_OPEN_BY_FILE_ID
|
338 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
339 ok( status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_DENIED
|| status
== STATUS_NOT_IMPLEMENTED
|| status
== STATUS_SHARING_VIOLATION
,
340 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
341 if (status
== STATUS_NOT_IMPLEMENTED
)
343 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
346 if (status
== STATUS_SHARING_VIOLATION
)
347 trace( "%s is currently open\n", wine_dbgstr_w(info
->FileName
) );
350 BYTE buf
[sizeof(FILE_ALL_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
)];
352 if (!pNtQueryInformationFile( handle
, &io
, buf
, sizeof(buf
), FileAllInformation
))
354 FILE_ALL_INFORMATION
*fai
= (FILE_ALL_INFORMATION
*)buf
;
356 /* check that it's the same file/directory */
358 /* don't check the size for directories */
359 if (!(info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
360 ok( info
->EndOfFile
.QuadPart
== fai
->StandardInformation
.EndOfFile
.QuadPart
,
361 "mismatched file size for %s\n", wine_dbgstr_w(info
->FileName
));
363 ok( info
->CreationTime
.QuadPart
== fai
->BasicInformation
.CreationTime
.QuadPart
,
364 "mismatched creation time for %s\n", wine_dbgstr_w(info
->FileName
));
366 CloseHandle( handle
);
368 /* try same thing from drive root */
369 attr
.RootDirectory
= root
;
370 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
371 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
372 FILE_OPEN_BY_FILE_ID
|
373 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
374 ok( status
== STATUS_SUCCESS
|| status
== STATUS_NOT_IMPLEMENTED
,
375 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
376 if (!status
) CloseHandle( handle
);
384 static void delete_file_test(void)
387 OBJECT_ATTRIBUTES attr
;
388 UNICODE_STRING nameW
;
389 WCHAR pathW
[MAX_PATH
];
390 WCHAR pathsubW
[MAX_PATH
];
391 static const WCHAR testdirW
[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
392 static const WCHAR subdirW
[] = {'\\','s','u','b',0};
394 ret
= GetTempPathW(MAX_PATH
, pathW
);
397 ok(0, "couldn't get temp dir\n");
400 if (ret
+ sizeof(testdirW
)/sizeof(WCHAR
)-1 + sizeof(subdirW
)/sizeof(WCHAR
)-1 >= MAX_PATH
)
402 ok(0, "MAX_PATH exceeded in constructing paths\n");
406 lstrcatW(pathW
, testdirW
);
407 lstrcpyW(pathsubW
, pathW
);
408 lstrcatW(pathsubW
, subdirW
);
410 ret
= CreateDirectoryW(pathW
, NULL
);
411 ok(ret
== TRUE
, "couldn't create directory ntdeletefile\n");
412 if (!pRtlDosPathNameToNtPathName_U(pathW
, &nameW
, NULL
, NULL
))
414 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
418 attr
.Length
= sizeof(attr
);
419 attr
.RootDirectory
= 0;
420 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
421 attr
.ObjectName
= &nameW
;
422 attr
.SecurityDescriptor
= NULL
;
423 attr
.SecurityQualityOfService
= NULL
;
425 /* test NtDeleteFile on an empty directory */
426 ret
= pNtDeleteFile(&attr
);
427 ok(ret
== STATUS_SUCCESS
, "NtDeleteFile should succeed in removing an empty directory\n");
428 ret
= RemoveDirectoryW(pathW
);
429 ok(ret
== FALSE
, "expected to fail removing directory, NtDeleteFile should have removed it\n");
431 /* test NtDeleteFile on a non-empty directory */
432 ret
= CreateDirectoryW(pathW
, NULL
);
433 ok(ret
== TRUE
, "couldn't create directory ntdeletefile ?!\n");
434 ret
= CreateDirectoryW(pathsubW
, NULL
);
435 ok(ret
== TRUE
, "couldn't create directory subdir\n");
436 ret
= pNtDeleteFile(&attr
);
437 ok(ret
== STATUS_SUCCESS
, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
438 ret
= RemoveDirectoryW(pathsubW
);
439 ok(ret
== TRUE
, "expected to remove directory ntdeletefile\\sub\n");
440 ret
= RemoveDirectoryW(pathW
);
441 ok(ret
== TRUE
, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
443 pRtlFreeUnicodeString( &nameW
);
446 static void read_file_test(void)
448 const char text
[] = "foobar";
449 HANDLE handle
, read
, write
;
451 IO_STATUS_BLOCK iosb
, iosb2
;
455 LARGE_INTEGER offset
;
456 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
460 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
462 /* try read with no data */
463 U(iosb
).Status
= 0xdeadbabe;
464 iosb
.Information
= 0xdeadbeef;
465 ok( is_signaled( read
), "read handle is not signaled\n" );
466 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
467 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
468 ok( !is_signaled( read
), "read handle is signaled\n" );
469 ok( !is_signaled( event
), "event is signaled\n" );
470 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
471 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
472 ok( !apc_count
, "apc was called\n" );
473 WriteFile( write
, buffer
, 1, &written
, NULL
);
474 /* iosb updated here by async i/o */
475 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
476 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
477 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
478 ok( !is_signaled( read
), "read handle is signaled\n" );
479 ok( is_signaled( event
), "event is not signaled\n" );
480 ok( !apc_count
, "apc was called\n" );
482 SleepEx( 1, FALSE
); /* non-alertable sleep */
483 ok( !apc_count
, "apc was called\n" );
484 SleepEx( 1, TRUE
); /* alertable sleep */
485 ok( apc_count
== 1, "apc not called\n" );
487 /* with no event, the pipe handle itself gets signaled */
489 U(iosb
).Status
= 0xdeadbabe;
490 iosb
.Information
= 0xdeadbeef;
491 ok( !is_signaled( read
), "read handle is not signaled\n" );
492 status
= pNtReadFile( read
, 0, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
493 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
494 ok( !is_signaled( read
), "read handle is signaled\n" );
495 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
496 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
497 ok( !apc_count
, "apc was called\n" );
498 WriteFile( write
, buffer
, 1, &written
, NULL
);
499 /* iosb updated here by async i/o */
500 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
501 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
502 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
503 ok( is_signaled( read
), "read handle is signaled\n" );
504 ok( !apc_count
, "apc was called\n" );
506 SleepEx( 1, FALSE
); /* non-alertable sleep */
507 ok( !apc_count
, "apc was called\n" );
508 SleepEx( 1, TRUE
); /* alertable sleep */
509 ok( apc_count
== 1, "apc not called\n" );
511 /* now read with data ready */
513 U(iosb
).Status
= 0xdeadbabe;
514 iosb
.Information
= 0xdeadbeef;
516 WriteFile( write
, buffer
, 1, &written
, NULL
);
517 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
518 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
519 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
520 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
521 ok( is_signaled( event
), "event is not signaled\n" );
522 ok( !apc_count
, "apc was called\n" );
523 SleepEx( 1, FALSE
); /* non-alertable sleep */
524 ok( !apc_count
, "apc was called\n" );
525 SleepEx( 1, TRUE
); /* alertable sleep */
526 ok( apc_count
== 1, "apc not called\n" );
528 /* try read with no data */
530 U(iosb
).Status
= 0xdeadbabe;
531 iosb
.Information
= 0xdeadbeef;
532 ok( is_signaled( event
), "event is not signaled\n" ); /* check that read resets the event */
533 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
534 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
535 ok( !is_signaled( event
), "event is signaled\n" );
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( !apc_count
, "apc was called\n" );
539 WriteFile( write
, buffer
, 1, &written
, NULL
);
540 /* partial read is good enough */
541 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
542 ok( is_signaled( event
), "event is signaled\n" );
543 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
544 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
545 ok( !apc_count
, "apc was called\n" );
546 SleepEx( 1, TRUE
); /* alertable sleep */
547 ok( apc_count
== 1, "apc was not called\n" );
549 /* read from disconnected pipe */
551 U(iosb
).Status
= 0xdeadbabe;
552 iosb
.Information
= 0xdeadbeef;
553 CloseHandle( write
);
554 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
555 ok( status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", status
);
556 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
557 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
558 ok( !is_signaled( event
), "event is signaled\n" );
559 ok( !apc_count
, "apc was called\n" );
560 SleepEx( 1, TRUE
); /* alertable sleep */
561 ok( !apc_count
, "apc was called\n" );
564 /* read from closed handle */
566 U(iosb
).Status
= 0xdeadbabe;
567 iosb
.Information
= 0xdeadbeef;
569 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
570 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
571 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
572 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
573 ok( is_signaled( event
), "event is signaled\n" ); /* not reset on invalid handle */
574 ok( !apc_count
, "apc was called\n" );
575 SleepEx( 1, TRUE
); /* alertable sleep */
576 ok( !apc_count
, "apc was called\n" );
578 /* disconnect while async read is in progress */
579 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
581 U(iosb
).Status
= 0xdeadbabe;
582 iosb
.Information
= 0xdeadbeef;
583 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
584 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
585 ok( !is_signaled( event
), "event is signaled\n" );
586 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
587 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
588 ok( !apc_count
, "apc was called\n" );
589 CloseHandle( write
);
590 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
591 ok( U(iosb
).Status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", U(iosb
).Status
);
592 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
593 ok( is_signaled( event
), "event is signaled\n" );
594 ok( !apc_count
, "apc was called\n" );
595 SleepEx( 1, TRUE
); /* alertable sleep */
596 ok( apc_count
== 1, "apc was not called\n" );
599 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
600 ok(DuplicateHandle(GetCurrentProcess(), read
, GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
601 "Failed to duplicate handle: %d\n", GetLastError());
604 U(iosb
).Status
= 0xdeadbabe;
605 iosb
.Information
= 0xdeadbeef;
606 status
= pNtReadFile( handle
, 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 /* Cancel by other handle */
613 status
= pNtCancelIoFile( read
, &iosb2
);
614 ok(status
== STATUS_SUCCESS
, "failed to cancel by different handle: %x\n", status
);
615 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
616 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
617 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
618 ok( is_signaled( event
), "event is signaled\n" );
619 todo_wine
ok( !apc_count
, "apc was called\n" );
620 SleepEx( 1, TRUE
); /* alertable sleep */
621 ok( apc_count
== 1, "apc was not called\n" );
624 U(iosb
).Status
= 0xdeadbabe;
625 iosb
.Information
= 0xdeadbeef;
626 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
627 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
628 ok( !is_signaled( event
), "event is signaled\n" );
629 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
630 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
631 ok( !apc_count
, "apc was called\n" );
632 /* Close queued handle */
634 SleepEx( 1, TRUE
); /* alertable sleep */
635 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
636 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
637 status
= pNtCancelIoFile( read
, &iosb2
);
638 ok(status
== STATUS_INVALID_HANDLE
, "cancelled by closed handle?\n");
639 status
= pNtCancelIoFile( handle
, &iosb2
);
640 ok(status
== STATUS_SUCCESS
, "failed to cancel: %x\n", status
);
641 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
642 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
643 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
644 ok( is_signaled( event
), "event is signaled\n" );
645 todo_wine
ok( !apc_count
, "apc was called\n" );
646 SleepEx( 1, TRUE
); /* alertable sleep */
647 ok( apc_count
== 1, "apc was not called\n" );
648 CloseHandle( handle
);
649 CloseHandle( write
);
651 if (pNtCancelIoFileEx
)
653 /* Basic Cancel Ex */
654 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
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
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
666 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
667 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
668 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
669 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
670 ok( is_signaled( event
), "event is signaled\n" );
671 todo_wine
ok( !apc_count
, "apc was called\n" );
672 SleepEx( 1, TRUE
); /* alertable sleep */
673 ok( apc_count
== 1, "apc was not called\n" );
677 U(iosb
).Status
= 0xdeadbabe;
678 iosb
.Information
= 0xdeadbeef;
679 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
680 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
681 ok( !is_signaled( event
), "event is signaled\n" );
682 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
683 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
684 ok( !apc_count
, "apc was called\n" );
685 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
686 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
687 ok( !is_signaled( event
), "event is signaled\n" );
688 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
689 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
690 ok( !apc_count
, "apc was called\n" );
691 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
692 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
693 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
694 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
695 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
696 ok( is_signaled( event
), "event is signaled\n" );
697 todo_wine
ok( !apc_count
, "apc was called\n" );
698 SleepEx( 1, TRUE
); /* alertable sleep */
699 ok( apc_count
== 2, "apc was not called\n" );
702 CloseHandle( write
);
705 /* now try a real file */
706 if (!(handle
= create_temp_file( FILE_FLAG_OVERLAPPED
))) return;
708 U(iosb
).Status
= 0xdeadbabe;
709 iosb
.Information
= 0xdeadbeef;
712 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
713 ok( status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
, "wrong status %x\n", status
);
714 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
715 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
716 ok( is_signaled( event
), "event is signaled\n" );
717 ok( !apc_count
, "apc was called\n" );
718 SleepEx( 1, TRUE
); /* alertable sleep */
719 ok( apc_count
== 1, "apc was not called\n" );
722 U(iosb
).Status
= 0xdeadbabe;
723 iosb
.Information
= 0xdeadbeef;
726 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
727 ok( status
== STATUS_SUCCESS
||
728 status
== STATUS_PENDING
, /* vista */
729 "wrong status %x\n", status
);
730 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
731 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
732 ok( is_signaled( event
), "event is signaled\n" );
733 ok( !apc_count
, "apc was called\n" );
734 SleepEx( 1, TRUE
); /* alertable sleep */
735 ok( apc_count
== 1, "apc was not called\n" );
737 /* read beyond eof */
739 U(iosb
).Status
= 0xdeadbabe;
740 iosb
.Information
= 0xdeadbeef;
741 offset
.QuadPart
= strlen(text
) + 2;
742 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
743 if (status
== STATUS_PENDING
) /* vista */
745 ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
746 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
747 ok( is_signaled( event
), "event is signaled\n" );
748 ok( !apc_count
, "apc was called\n" );
749 SleepEx( 1, TRUE
); /* alertable sleep */
750 ok( apc_count
== 1, "apc was not called\n" );
754 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
755 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
756 ok( iosb
.Information
== 0xdeadbeef, "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
, "apc was called\n" );
762 CloseHandle( handle
);
764 /* now a non-overlapped file */
765 if (!(handle
= create_temp_file(0))) return;
767 U(iosb
).Status
= 0xdeadbabe;
768 iosb
.Information
= 0xdeadbeef;
770 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
771 ok( status
== STATUS_END_OF_FILE
||
772 status
== STATUS_SUCCESS
||
773 status
== STATUS_PENDING
, /* vista */
774 "wrong status %x\n", status
);
775 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
776 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
777 ok( is_signaled( event
), "event is signaled\n" );
778 ok( !apc_count
, "apc was called\n" );
779 SleepEx( 1, TRUE
); /* alertable sleep */
780 ok( apc_count
== 1, "apc was not called\n" );
783 U(iosb
).Status
= 0xdeadbabe;
784 iosb
.Information
= 0xdeadbeef;
787 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
788 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
789 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
790 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
791 ok( is_signaled( event
), "event is signaled\n" );
792 ok( !apc_count
, "apc was called\n" );
793 SleepEx( 1, TRUE
); /* alertable sleep */
794 todo_wine
ok( !apc_count
, "apc was called\n" );
796 /* read beyond eof */
798 U(iosb
).Status
= 0xdeadbabe;
799 iosb
.Information
= 0xdeadbeef;
800 offset
.QuadPart
= strlen(text
) + 2;
802 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
803 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
804 todo_wine
ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
805 todo_wine
ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
806 todo_wine
ok( is_signaled( event
), "event is not signaled\n" );
807 ok( !apc_count
, "apc was called\n" );
808 SleepEx( 1, TRUE
); /* alertable sleep */
809 ok( !apc_count
, "apc was called\n" );
811 CloseHandle( handle
);
813 CloseHandle( event
);
816 static void nt_mailslot_test(void)
819 ACCESS_MASK DesiredAccess
;
820 OBJECT_ATTRIBUTES attr
;
824 ULONG MaxMessageSize
;
825 LARGE_INTEGER TimeOut
;
826 IO_STATUS_BLOCK IoStatusBlock
;
829 WCHAR buffer1
[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
830 'R',':','\\','F','R','E','D','\0' };
832 TimeOut
.QuadPart
= -1;
834 pRtlInitUnicodeString(&str
, buffer1
);
835 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
836 CreateOptions
= MailslotQuota
= MaxMessageSize
= 0;
837 DesiredAccess
= GENERIC_READ
;
840 * Check for NULL pointer handling
842 rc
= pNtCreateMailslotFile(NULL
, DesiredAccess
,
843 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
845 ok( rc
== STATUS_ACCESS_VIOLATION
||
846 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
847 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc
);
850 * Test to see if the Timeout can be NULL
852 hslot
= (HANDLE
)0xdeadbeef;
853 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
854 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
856 ok( rc
== STATUS_SUCCESS
||
857 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
858 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc
);
859 ok( hslot
!= 0, "Handle is invalid\n");
861 if ( rc
== STATUS_SUCCESS
) rc
= pNtClose(hslot
);
864 * Test that the length field is checked properly
867 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
868 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
870 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
872 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
874 attr
.Length
= sizeof(OBJECT_ATTRIBUTES
)+1;
875 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
876 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
878 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
880 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
883 * Test handling of a NULL unicode string in ObjectName
885 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
886 attr
.ObjectName
= NULL
;
887 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
888 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
890 ok( rc
== STATUS_OBJECT_PATH_SYNTAX_BAD
||
891 rc
== STATUS_INVALID_PARAMETER
,
892 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc
);
894 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
899 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
900 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
901 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
903 ok( rc
== STATUS_SUCCESS
, "Create MailslotFile failed rc = %x\n", rc
);
904 ok( hslot
!= 0, "Handle is invalid\n");
906 rc
= pNtClose(hslot
);
907 ok( rc
== STATUS_SUCCESS
, "NtClose failed\n");
910 static void test_iocp_setcompletion(HANDLE h
)
915 res
= pNtSetIoCompletion( h
, CKEY_FIRST
, CVALUE_FIRST
, STATUS_INVALID_DEVICE_REQUEST
, 3 );
916 ok( res
== STATUS_SUCCESS
, "NtSetIoCompletion failed: %x\n", res
);
918 count
= get_pending_msgs(h
);
919 ok( count
== 1, "Unexpected msg count: %d\n", count
);
923 ok( completionKey
== CKEY_FIRST
, "Invalid completion key: %lx\n", completionKey
);
924 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
925 ok( U(ioSb
).Status
== STATUS_INVALID_DEVICE_REQUEST
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
926 ok( completionValue
== CVALUE_FIRST
, "Invalid completion value: %lx\n", completionValue
);
929 count
= get_pending_msgs(h
);
930 ok( !count
, "Unexpected msg count: %d\n", count
);
933 static void test_iocp_fileio(HANDLE h
)
935 static const char pipe_name
[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
937 IO_STATUS_BLOCK iosb
;
938 FILE_COMPLETION_INFORMATION fci
= {h
, CKEY_SECOND
};
939 HANDLE hPipeSrv
, hPipeClt
;
942 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
943 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
944 if (hPipeSrv
!= INVALID_HANDLE_VALUE
)
946 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
947 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
948 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
950 res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
951 ok( res
== STATUS_INVALID_PARAMETER
, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res
);
952 CloseHandle(hPipeClt
);
954 CloseHandle( hPipeSrv
);
957 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
| FILE_FLAG_OVERLAPPED
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
958 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
959 if (hPipeSrv
== INVALID_HANDLE_VALUE
)
962 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
963 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
964 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
967 BYTE send_buf
[TEST_BUF_LEN
], recv_buf
[TEST_BUF_LEN
];
971 NTSTATUS res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
972 ok( res
== STATUS_SUCCESS
, "NtSetInformationFile failed: %x\n", res
);
973 ok( U(iosb
).Status
== STATUS_SUCCESS
, "iosb.Status invalid: %x\n", U(iosb
).Status
);
975 memset( send_buf
, 0, TEST_BUF_LEN
);
976 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
977 count
= get_pending_msgs(h
);
978 ok( !count
, "Unexpected msg count: %ld\n", count
);
979 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
980 count
= get_pending_msgs(h
);
981 ok( !count
, "Unexpected msg count: %ld\n", count
);
982 WriteFile( hPipeClt
, send_buf
, TEST_BUF_LEN
, &read
, NULL
);
986 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
987 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
988 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
989 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
990 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] );
992 count
= get_pending_msgs(h
);
993 ok( !count
, "Unexpected msg count: %ld\n", count
);
995 memset( send_buf
, 0, TEST_BUF_LEN
);
996 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
997 WriteFile( hPipeClt
, send_buf
, 2, &read
, NULL
);
998 count
= get_pending_msgs(h
);
999 ok( !count
, "Unexpected msg count: %ld\n", count
);
1000 ReadFile( hPipeSrv
, recv_buf
, 2, &read
, &o
);
1001 count
= get_pending_msgs(h
);
1002 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
1005 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1006 ok( ioSb
.Information
== 2, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1007 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1008 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1009 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] );
1012 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
1013 CloseHandle( hPipeSrv
);
1014 count
= get_pending_msgs(h
);
1015 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
1018 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1019 ok( ioSb
.Information
== 0, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1020 /* wine sends wrong status here */
1021 todo_wine
ok( U(ioSb
).Status
== STATUS_PIPE_BROKEN
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1022 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1026 CloseHandle( hPipeClt
);
1029 static void test_file_basic_information(void)
1032 FILE_BASIC_INFORMATION fbi
;
1035 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1037 if (!(h
= create_temp_file(0))) return;
1039 /* Check default first */
1040 memset(&fbi
, 0, sizeof(fbi
));
1041 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1042 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1043 ok ( (fbi
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1044 "attribute %x not expected\n", fbi
.FileAttributes
);
1047 /* Clear fbi to avoid setting times */
1048 memset(&fbi
, 0, sizeof(fbi
));
1049 fbi
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1050 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1051 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1053 memset(&fbi
, 0, sizeof(fbi
));
1054 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1055 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1056 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_SYSTEM
, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi
.FileAttributes
);
1059 memset(&fbi
, 0, sizeof(fbi
));
1060 fbi
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1061 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1062 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1064 memset(&fbi
, 0, sizeof(fbi
));
1065 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1066 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1067 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_HIDDEN
, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi
.FileAttributes
);
1069 /* Check NORMAL last of all (to make sure we can clear attributes) */
1070 memset(&fbi
, 0, sizeof(fbi
));
1071 fbi
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1072 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1073 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1075 memset(&fbi
, 0, sizeof(fbi
));
1076 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1077 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1078 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_NORMAL
, "attribute %x not 0\n", fbi
.FileAttributes
);
1083 static void test_file_all_information(void)
1086 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1087 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1088 * don't leave enough room there.
1091 FILE_ALL_INFORMATION fai
;
1096 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1098 if (!(h
= create_temp_file(0))) return;
1100 /* Check default first */
1101 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1102 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1103 ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1104 "attribute %x not expected\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1107 /* Clear fbi to avoid setting times */
1108 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1109 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1110 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1111 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to set FileAllInformation, res %x\n", res
);
1112 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1113 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1115 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1116 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1117 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1118 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
);
1121 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1122 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1123 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1124 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1126 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1127 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1128 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1129 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
);
1131 /* Check NORMAL last of all (to make sure we can clear attributes) */
1132 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1133 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1134 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1135 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1137 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1138 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1139 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1140 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
);
1145 static void test_file_both_information(void)
1148 FILE_BOTH_DIR_INFORMATION fbi
;
1152 if (!(h
= create_temp_file(0))) return;
1154 memset(&fbi
, 0, sizeof(fbi
));
1155 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBothDirectoryInformation
);
1156 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res
);
1161 static void test_iocompletion(void)
1163 HANDLE h
= INVALID_HANDLE_VALUE
;
1166 res
= pNtCreateIoCompletion( &h
, IO_COMPLETION_ALL_ACCESS
, NULL
, 0);
1168 ok( res
== 0, "NtCreateIoCompletion anonymous failed: %x\n", res
);
1169 ok( h
&& h
!= INVALID_HANDLE_VALUE
, "Invalid handle returned\n" );
1171 if ( h
&& h
!= INVALID_HANDLE_VALUE
)
1173 test_iocp_setcompletion(h
);
1174 test_iocp_fileio(h
);
1179 static void test_file_name_information(void)
1181 WCHAR
*file_name
, *volume_prefix
, *expected
;
1182 FILE_NAME_INFORMATION
*info
;
1183 ULONG old_redir
= 1, tmp
;
1184 UINT file_name_size
;
1191 /* GetVolumePathName is not present before w2k */
1192 if (!pGetVolumePathNameW
) {
1193 win_skip("GetVolumePathNameW not found\n");
1197 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1198 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1199 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1200 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1202 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1203 ok(len
== file_name_size
- 1,
1204 "GetSystemDirectoryW returned %u, expected %u.\n",
1205 len
, file_name_size
- 1);
1207 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1208 ok(len
, "GetVolumePathNameW failed.\n");
1210 len
= lstrlenW( volume_prefix
);
1211 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1212 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1213 expected
[file_name_size
- len
- 1] = '\0';
1215 /* A bit more than we actually need, but it keeps the calculation simple. */
1216 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1217 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1219 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1220 h
= CreateFileW( file_name
, GENERIC_READ
,
1221 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1222 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1223 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1224 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1226 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileNameInformation
);
1227 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x.\n", hr
);
1229 memset( info
, 0xcc, info_size
);
1230 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileNameInformation
);
1231 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1232 hr
, STATUS_BUFFER_OVERFLOW
);
1233 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1234 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1235 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1236 ok(info
->FileName
[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info
->FileName
[2]);
1237 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1238 "info->FileName[1] is %p, expected %p.\n",
1239 CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1240 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1242 memset( info
, 0xcc, info_size
);
1243 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1244 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1245 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1246 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1247 ok(info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1248 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)]);
1249 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1250 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1251 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1252 ok(io
.Information
== FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
,
1253 "io.Information is %lu, expected %u.\n",
1254 io
.Information
, FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
);
1257 HeapFree( GetProcessHeap(), 0, info
);
1258 HeapFree( GetProcessHeap(), 0, expected
);
1259 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1261 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1263 skip("Not running on WoW64, skipping test.\n");
1264 HeapFree( GetProcessHeap(), 0, file_name
);
1268 h
= CreateFileW( file_name
, GENERIC_READ
,
1269 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1270 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1271 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1272 HeapFree( GetProcessHeap(), 0, file_name
);
1274 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1275 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1276 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1278 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1279 ok(len
== file_name_size
- 1,
1280 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1281 len
, file_name_size
- 1);
1283 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1284 ok(len
, "GetVolumePathNameW failed.\n");
1286 len
= lstrlenW( volume_prefix
);
1287 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1288 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1289 expected
[file_name_size
- len
- 1] = '\0';
1291 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1292 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1294 memset( info
, 0xcc, info_size
);
1295 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1296 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1297 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1298 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1299 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1302 HeapFree( GetProcessHeap(), 0, info
);
1303 HeapFree( GetProcessHeap(), 0, expected
);
1304 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1305 HeapFree( GetProcessHeap(), 0, file_name
);
1308 static void test_file_all_name_information(void)
1310 WCHAR
*file_name
, *volume_prefix
, *expected
;
1311 FILE_ALL_INFORMATION
*info
;
1312 ULONG old_redir
= 1, tmp
;
1313 UINT file_name_size
;
1320 /* GetVolumePathName is not present before w2k */
1321 if (!pGetVolumePathNameW
) {
1322 win_skip("GetVolumePathNameW not found\n");
1326 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1327 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1328 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1329 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1331 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1332 ok(len
== file_name_size
- 1,
1333 "GetSystemDirectoryW returned %u, expected %u.\n",
1334 len
, file_name_size
- 1);
1336 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1337 ok(len
, "GetVolumePathNameW failed.\n");
1339 len
= lstrlenW( volume_prefix
);
1340 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1341 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1342 expected
[file_name_size
- len
- 1] = '\0';
1344 /* A bit more than we actually need, but it keeps the calculation simple. */
1345 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1346 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1348 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1349 h
= CreateFileW( file_name
, GENERIC_READ
,
1350 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1351 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1352 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1353 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1355 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileAllInformation
);
1356 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1357 hr
, STATUS_INFO_LENGTH_MISMATCH
);
1359 memset( info
, 0xcc, info_size
);
1360 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileAllInformation
);
1361 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1362 hr
, STATUS_BUFFER_OVERFLOW
);
1363 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1364 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1365 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1366 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1367 ok(info
->NameInformation
.FileName
[2] == 0xcccc,
1368 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info
->NameInformation
.FileName
[2]);
1369 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1370 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1371 CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1372 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1374 memset( info
, 0xcc, info_size
);
1375 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1376 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1377 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1378 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1379 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1380 ok(info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] == 0xcccc,
1381 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1382 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)]);
1383 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1384 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
),
1385 "info->NameInformation.FileName is %s, expected %s.\n",
1386 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1387 ok(io
.Information
== FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
)
1388 + info
->NameInformation
.FileNameLength
,
1389 "io.Information is %lu\n", io
.Information
);
1392 HeapFree( GetProcessHeap(), 0, info
);
1393 HeapFree( GetProcessHeap(), 0, expected
);
1394 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1396 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1398 skip("Not running on WoW64, skipping test.\n");
1399 HeapFree( GetProcessHeap(), 0, file_name
);
1403 h
= CreateFileW( file_name
, GENERIC_READ
,
1404 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1405 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1406 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1407 HeapFree( GetProcessHeap(), 0, file_name
);
1409 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1410 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1411 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1413 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1414 ok(len
== file_name_size
- 1,
1415 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1416 len
, file_name_size
- 1);
1418 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1419 ok(len
, "GetVolumePathNameW failed.\n");
1421 len
= lstrlenW( volume_prefix
);
1422 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1423 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1424 expected
[file_name_size
- len
- 1] = '\0';
1426 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1427 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1429 memset( info
, 0xcc, info_size
);
1430 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1431 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1432 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1433 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
), "info->NameInformation.FileName is %s, expected %s.\n",
1434 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1437 HeapFree( GetProcessHeap(), 0, info
);
1438 HeapFree( GetProcessHeap(), 0, expected
);
1439 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1440 HeapFree( GetProcessHeap(), 0, file_name
);
1445 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1446 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
1449 skip("not running on NT, skipping test\n");
1453 pGetVolumePathNameW
= (void *)GetProcAddress(hkernel32
, "GetVolumePathNameW");
1454 pGetSystemWow64DirectoryW
= (void *)GetProcAddress(hkernel32
, "GetSystemWow64DirectoryW");
1456 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
1457 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
1458 pRtlDosPathNameToNtPathName_U
= (void *)GetProcAddress(hntdll
, "RtlDosPathNameToNtPathName_U");
1459 pRtlWow64EnableFsRedirectionEx
= (void *)GetProcAddress(hntdll
, "RtlWow64EnableFsRedirectionEx");
1460 pNtCreateMailslotFile
= (void *)GetProcAddress(hntdll
, "NtCreateMailslotFile");
1461 pNtCreateFile
= (void *)GetProcAddress(hntdll
, "NtCreateFile");
1462 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
1463 pNtDeleteFile
= (void *)GetProcAddress(hntdll
, "NtDeleteFile");
1464 pNtReadFile
= (void *)GetProcAddress(hntdll
, "NtReadFile");
1465 pNtWriteFile
= (void *)GetProcAddress(hntdll
, "NtWriteFile");
1466 pNtCancelIoFile
= (void *)GetProcAddress(hntdll
, "NtCancelIoFile");
1467 pNtCancelIoFileEx
= (void *)GetProcAddress(hntdll
, "NtCancelIoFileEx");
1468 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
1469 pNtCreateIoCompletion
= (void *)GetProcAddress(hntdll
, "NtCreateIoCompletion");
1470 pNtOpenIoCompletion
= (void *)GetProcAddress(hntdll
, "NtOpenIoCompletion");
1471 pNtQueryIoCompletion
= (void *)GetProcAddress(hntdll
, "NtQueryIoCompletion");
1472 pNtRemoveIoCompletion
= (void *)GetProcAddress(hntdll
, "NtRemoveIoCompletion");
1473 pNtSetIoCompletion
= (void *)GetProcAddress(hntdll
, "NtSetIoCompletion");
1474 pNtSetInformationFile
= (void *)GetProcAddress(hntdll
, "NtSetInformationFile");
1475 pNtQueryInformationFile
= (void *)GetProcAddress(hntdll
, "NtQueryInformationFile");
1476 pNtQueryDirectoryFile
= (void *)GetProcAddress(hntdll
, "NtQueryDirectoryFile");
1483 test_iocompletion();
1484 test_file_basic_information();
1485 test_file_all_information();
1486 test_file_both_information();
1487 test_file_name_information();
1488 test_file_all_name_information();