1 /* Unit test suite for Ntdll file functions
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
5 * Copyright 2008 Jeff Zaroyko
6 * Copyright 2011 Dmitry Timoshkov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * We use function pointers here as there is no import library for NTDLL on
31 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
32 * definition errors when we get to winnt.h
34 #define WIN32_NO_STATUS
36 #include "wine/test.h"
41 #ifndef IO_COMPLETION_ALL_ACCESS
42 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
45 static BOOL (WINAPI
* pGetVolumePathNameW
)(LPCWSTR
, LPWSTR
, DWORD
);
46 static UINT (WINAPI
*pGetSystemWow64DirectoryW
)( LPWSTR
, UINT
);
48 static VOID (WINAPI
*pRtlFreeUnicodeString
)( PUNICODE_STRING
);
49 static VOID (WINAPI
*pRtlInitUnicodeString
)( PUNICODE_STRING
, LPCWSTR
);
50 static BOOL (WINAPI
*pRtlDosPathNameToNtPathName_U
)( LPCWSTR
, PUNICODE_STRING
, PWSTR
*, CURDIR
* );
51 static NTSTATUS (WINAPI
*pRtlWow64EnableFsRedirectionEx
)( ULONG
, ULONG
* );
53 static NTSTATUS (WINAPI
*pNtCreateMailslotFile
)( PHANDLE
, ULONG
, POBJECT_ATTRIBUTES
, PIO_STATUS_BLOCK
,
54 ULONG
, ULONG
, ULONG
, PLARGE_INTEGER
);
55 static NTSTATUS (WINAPI
*pNtCreateFile
)(PHANDLE
,ACCESS_MASK
,POBJECT_ATTRIBUTES
,PIO_STATUS_BLOCK
,PLARGE_INTEGER
,ULONG
,ULONG
,ULONG
,ULONG
,PVOID
,ULONG
);
56 static NTSTATUS (WINAPI
*pNtOpenFile
)(PHANDLE
,ACCESS_MASK
,POBJECT_ATTRIBUTES
,PIO_STATUS_BLOCK
,ULONG
,ULONG
);
57 static NTSTATUS (WINAPI
*pNtDeleteFile
)(POBJECT_ATTRIBUTES ObjectAttributes
);
58 static NTSTATUS (WINAPI
*pNtReadFile
)(HANDLE hFile
, HANDLE hEvent
,
59 PIO_APC_ROUTINE apc
, void* apc_user
,
60 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
61 PLARGE_INTEGER offset
, PULONG key
);
62 static NTSTATUS (WINAPI
*pNtWriteFile
)(HANDLE hFile
, HANDLE hEvent
,
63 PIO_APC_ROUTINE apc
, void* apc_user
,
64 PIO_STATUS_BLOCK io_status
,
65 const void* buffer
, ULONG length
,
66 PLARGE_INTEGER offset
, PULONG key
);
67 static NTSTATUS (WINAPI
*pNtCancelIoFile
)(HANDLE hFile
, PIO_STATUS_BLOCK io_status
);
68 static NTSTATUS (WINAPI
*pNtCancelIoFileEx
)(HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PIO_STATUS_BLOCK io_status
);
69 static NTSTATUS (WINAPI
*pNtClose
)( PHANDLE
);
71 static NTSTATUS (WINAPI
*pNtCreateIoCompletion
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
, ULONG
);
72 static NTSTATUS (WINAPI
*pNtOpenIoCompletion
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
73 static NTSTATUS (WINAPI
*pNtQueryIoCompletion
)(HANDLE
, IO_COMPLETION_INFORMATION_CLASS
, PVOID
, ULONG
, PULONG
);
74 static NTSTATUS (WINAPI
*pNtRemoveIoCompletion
)(HANDLE
, PULONG_PTR
, PULONG_PTR
, PIO_STATUS_BLOCK
, PLARGE_INTEGER
);
75 static NTSTATUS (WINAPI
*pNtSetIoCompletion
)(HANDLE
, ULONG_PTR
, ULONG_PTR
, NTSTATUS
, SIZE_T
);
76 static NTSTATUS (WINAPI
*pNtSetInformationFile
)(HANDLE
, PIO_STATUS_BLOCK
, PVOID
, ULONG
, FILE_INFORMATION_CLASS
);
77 static NTSTATUS (WINAPI
*pNtQueryInformationFile
)(HANDLE
, PIO_STATUS_BLOCK
, PVOID
, ULONG
, FILE_INFORMATION_CLASS
);
78 static NTSTATUS (WINAPI
*pNtQueryDirectoryFile
)(HANDLE
,HANDLE
,PIO_APC_ROUTINE
,PVOID
,PIO_STATUS_BLOCK
,
79 PVOID
,ULONG
,FILE_INFORMATION_CLASS
,BOOLEAN
,PUNICODE_STRING
,BOOLEAN
);
80 static NTSTATUS (WINAPI
*pNtQueryVolumeInformationFile
)(HANDLE
,PIO_STATUS_BLOCK
,PVOID
,ULONG
,FS_INFORMATION_CLASS
);
82 static inline BOOL
is_signaled( HANDLE obj
)
84 return WaitForSingleObject( obj
, 0 ) == WAIT_OBJECT_0
;
87 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
88 #define TEST_BUF_LEN 3
90 static BOOL
create_pipe( HANDLE
*read
, HANDLE
*write
, ULONG flags
, ULONG size
)
92 *read
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_INBOUND
| flags
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
93 1, size
, size
, NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
94 ok(*read
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
96 *write
= CreateFileA(PIPENAME
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
97 ok(*write
!= INVALID_HANDLE_VALUE
, "CreateFile failed (%d)\n", GetLastError());
102 static HANDLE
create_temp_file( ULONG flags
)
104 char path
[MAX_PATH
], buffer
[MAX_PATH
];
107 GetTempPathA( MAX_PATH
, path
);
108 GetTempFileNameA( path
, "foo", 0, buffer
);
109 handle
= CreateFileA(buffer
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
110 flags
| FILE_FLAG_DELETE_ON_CLOSE
, 0);
111 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
112 return (handle
== INVALID_HANDLE_VALUE
) ? 0 : handle
;
115 #define CVALUE_FIRST 0xfffabbcc
116 #define CKEY_FIRST 0x1030341
117 #define CKEY_SECOND 0x132E46
119 static ULONG_PTR completionKey
;
120 static IO_STATUS_BLOCK ioSb
;
121 static ULONG_PTR completionValue
;
123 static ULONG
get_pending_msgs(HANDLE h
)
128 res
= pNtQueryIoCompletion( h
, IoCompletionBasicInformation
, &a
, sizeof(a
), &req
);
129 ok( res
== STATUS_SUCCESS
, "NtQueryIoCompletion failed: %x\n", res
);
130 if (res
!= STATUS_SUCCESS
) return -1;
131 ok( req
== sizeof(a
), "Unexpected response size: %x\n", req
);
135 static BOOL
get_msg(HANDLE h
)
137 LARGE_INTEGER timeout
= {{-10000000*3}};
138 DWORD res
= pNtRemoveIoCompletion( h
, &completionKey
, &completionValue
, &ioSb
, &timeout
);
139 ok( res
== STATUS_SUCCESS
, "NtRemoveIoCompletion failed: %x\n", res
);
140 if (res
!= STATUS_SUCCESS
)
142 completionKey
= completionValue
= 0;
143 memset(&ioSb
, 0, sizeof(ioSb
));
150 static void WINAPI
apc( void *arg
, IO_STATUS_BLOCK
*iosb
, ULONG reserved
)
154 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
155 iosb
, U(*iosb
).Status
, iosb
->Information
);
157 ok( !reserved
, "reserved is not 0: %x\n", reserved
);
160 static void create_file_test(void)
162 static const WCHAR systemrootW
[] = {'\\','S','y','s','t','e','m','R','o','o','t',
163 '\\','f','a','i','l','i','n','g',0};
164 static const WCHAR questionmarkInvalidNameW
[] = {'a','f','i','l','e','?',0};
165 static const WCHAR pipeInvalidNameW
[] = {'a','|','b',0};
168 WCHAR path
[MAX_PATH
];
169 OBJECT_ATTRIBUTES attr
;
171 UNICODE_STRING nameW
;
173 GetCurrentDirectoryW( MAX_PATH
, path
);
174 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
175 attr
.Length
= sizeof(attr
);
176 attr
.RootDirectory
= 0;
177 attr
.ObjectName
= &nameW
;
178 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
179 attr
.SecurityDescriptor
= NULL
;
180 attr
.SecurityQualityOfService
= NULL
;
182 /* try various open modes and options on directories */
183 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
184 FILE_OPEN
, FILE_DIRECTORY_FILE
, NULL
, 0 );
185 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
188 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
189 FILE_CREATE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
190 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
191 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
193 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
194 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
195 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
198 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
199 FILE_SUPERSEDE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
200 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
202 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
203 FILE_OVERWRITE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
204 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
206 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
207 FILE_OVERWRITE_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
208 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
210 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
211 FILE_OPEN
, 0, NULL
, 0 );
212 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
215 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
216 FILE_CREATE
, 0, NULL
, 0 );
217 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
218 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
220 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
221 FILE_OPEN_IF
, 0, NULL
, 0 );
222 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
225 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
226 FILE_SUPERSEDE
, 0, NULL
, 0 );
227 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
228 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
230 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
231 FILE_OVERWRITE
, 0, NULL
, 0 );
232 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
233 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
235 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
236 FILE_OVERWRITE_IF
, 0, NULL
, 0 );
237 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
238 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
240 pRtlFreeUnicodeString( &nameW
);
242 pRtlInitUnicodeString( &nameW
, systemrootW
);
243 attr
.Length
= sizeof(attr
);
244 attr
.RootDirectory
= NULL
;
245 attr
.ObjectName
= &nameW
;
246 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
247 attr
.SecurityDescriptor
= NULL
;
248 attr
.SecurityQualityOfService
= NULL
;
250 status
= pNtCreateFile( &dir
, FILE_APPEND_DATA
, &attr
, &io
, NULL
, FILE_ATTRIBUTE_NORMAL
, 0,
251 FILE_OPEN_IF
, FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0 );
253 ok( status
== STATUS_INVALID_PARAMETER
,
254 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
256 /* Invalid chars in file/dirnames */
257 pRtlDosPathNameToNtPathName_U(questionmarkInvalidNameW
, &nameW
, NULL
, NULL
);
258 attr
.ObjectName
= &nameW
;
259 status
= pNtCreateFile(&dir
, GENERIC_READ
|SYNCHRONIZE
, &attr
, &io
, NULL
, 0,
260 FILE_SHARE_READ
, FILE_CREATE
,
261 FILE_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
262 ok(status
== STATUS_OBJECT_NAME_INVALID
,
263 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
265 status
= pNtCreateFile(&file
, GENERIC_WRITE
|SYNCHRONIZE
, &attr
, &io
, NULL
, 0,
267 FILE_NON_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
268 ok(status
== STATUS_OBJECT_NAME_INVALID
,
269 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
271 pRtlDosPathNameToNtPathName_U(pipeInvalidNameW
, &nameW
, NULL
, NULL
);
272 attr
.ObjectName
= &nameW
;
273 status
= pNtCreateFile(&dir
, GENERIC_READ
|SYNCHRONIZE
, &attr
, &io
, NULL
, 0,
274 FILE_SHARE_READ
, FILE_CREATE
,
275 FILE_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
276 ok(status
== STATUS_OBJECT_NAME_INVALID
,
277 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
279 status
= pNtCreateFile(&file
, GENERIC_WRITE
|SYNCHRONIZE
, &attr
, &io
, NULL
, 0,
281 FILE_NON_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
, NULL
, 0);
282 ok(status
== STATUS_OBJECT_NAME_INVALID
,
283 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
286 static void open_file_test(void)
289 HANDLE dir
, root
, handle
;
290 WCHAR path
[MAX_PATH
];
292 OBJECT_ATTRIBUTES attr
;
294 UNICODE_STRING nameW
;
298 len
= GetWindowsDirectoryW( path
, MAX_PATH
);
299 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
300 attr
.Length
= sizeof(attr
);
301 attr
.RootDirectory
= 0;
302 attr
.ObjectName
= &nameW
;
303 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
304 attr
.SecurityDescriptor
= NULL
;
305 attr
.SecurityQualityOfService
= NULL
;
306 status
= pNtOpenFile( &dir
, SYNCHRONIZE
|FILE_LIST_DIRECTORY
, &attr
, &io
,
307 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
);
308 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
309 pRtlFreeUnicodeString( &nameW
);
311 path
[3] = 0; /* root of the drive */
312 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
313 status
= pNtOpenFile( &root
, GENERIC_READ
, &attr
, &io
,
314 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
315 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
316 pRtlFreeUnicodeString( &nameW
);
318 /* test opening system dir with RootDirectory set to windows dir */
319 GetSystemDirectoryW( path
, MAX_PATH
);
320 while (path
[len
] == '\\') len
++;
321 nameW
.Buffer
= path
+ len
;
322 nameW
.Length
= lstrlenW(path
+ len
) * sizeof(WCHAR
);
323 attr
.RootDirectory
= dir
;
324 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
325 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
326 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
327 CloseHandle( handle
);
329 /* try uppercase name */
330 for (i
= len
; path
[i
]; i
++) if (path
[i
] >= 'a' && path
[i
] <= 'z') path
[i
] -= 'a' - 'A';
331 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
332 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
333 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
334 CloseHandle( handle
);
336 /* try with leading backslash */
338 nameW
.Length
+= sizeof(WCHAR
);
339 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
340 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
341 ok( status
== STATUS_INVALID_PARAMETER
||
342 status
== STATUS_OBJECT_NAME_INVALID
||
343 status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
344 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
345 if (!status
) CloseHandle( handle
);
347 /* try with empty name */
349 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
350 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
351 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
352 CloseHandle( handle
);
354 /* try open by file id */
356 while (!pNtQueryDirectoryFile( dir
, NULL
, NULL
, NULL
, &io
, data
, sizeof(data
),
357 FileIdBothDirectoryInformation
, TRUE
, NULL
, restart
))
359 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)data
;
363 if (!info
->FileId
.QuadPart
) continue;
365 nameW
.Buffer
= (WCHAR
*)&info
->FileId
;
366 nameW
.Length
= sizeof(info
->FileId
);
367 info
->FileName
[info
->FileNameLength
/sizeof(WCHAR
)] = 0;
368 attr
.RootDirectory
= dir
;
369 /* We skip 'open' files by not specifying FILE_SHARE_WRITE */
370 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
372 FILE_OPEN_BY_FILE_ID
|
373 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
374 ok( status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_DENIED
|| status
== STATUS_NOT_IMPLEMENTED
|| status
== STATUS_SHARING_VIOLATION
,
375 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
376 if (status
== STATUS_NOT_IMPLEMENTED
)
378 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
381 if (status
== STATUS_SHARING_VIOLATION
)
382 trace( "%s is currently open\n", wine_dbgstr_w(info
->FileName
) );
385 BYTE buf
[sizeof(FILE_ALL_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
)];
387 if (!pNtQueryInformationFile( handle
, &io
, buf
, sizeof(buf
), FileAllInformation
))
389 FILE_ALL_INFORMATION
*fai
= (FILE_ALL_INFORMATION
*)buf
;
391 /* check that it's the same file/directory */
393 /* don't check the size for directories */
394 if (!(info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
395 ok( info
->EndOfFile
.QuadPart
== fai
->StandardInformation
.EndOfFile
.QuadPart
,
396 "mismatched file size for %s\n", wine_dbgstr_w(info
->FileName
));
398 ok( info
->CreationTime
.QuadPart
== fai
->BasicInformation
.CreationTime
.QuadPart
,
399 "mismatched creation time for %s\n", wine_dbgstr_w(info
->FileName
));
401 CloseHandle( handle
);
403 /* try same thing from drive root */
404 attr
.RootDirectory
= root
;
405 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
406 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
407 FILE_OPEN_BY_FILE_ID
|
408 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
409 ok( status
== STATUS_SUCCESS
|| status
== STATUS_NOT_IMPLEMENTED
,
410 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
411 if (!status
) CloseHandle( handle
);
419 static void delete_file_test(void)
422 OBJECT_ATTRIBUTES attr
;
423 UNICODE_STRING nameW
;
424 WCHAR pathW
[MAX_PATH
];
425 WCHAR pathsubW
[MAX_PATH
];
426 static const WCHAR testdirW
[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
427 static const WCHAR subdirW
[] = {'\\','s','u','b',0};
429 ret
= GetTempPathW(MAX_PATH
, pathW
);
432 ok(0, "couldn't get temp dir\n");
435 if (ret
+ sizeof(testdirW
)/sizeof(WCHAR
)-1 + sizeof(subdirW
)/sizeof(WCHAR
)-1 >= MAX_PATH
)
437 ok(0, "MAX_PATH exceeded in constructing paths\n");
441 lstrcatW(pathW
, testdirW
);
442 lstrcpyW(pathsubW
, pathW
);
443 lstrcatW(pathsubW
, subdirW
);
445 ret
= CreateDirectoryW(pathW
, NULL
);
446 ok(ret
== TRUE
, "couldn't create directory ntdeletefile\n");
447 if (!pRtlDosPathNameToNtPathName_U(pathW
, &nameW
, NULL
, NULL
))
449 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
453 attr
.Length
= sizeof(attr
);
454 attr
.RootDirectory
= 0;
455 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
456 attr
.ObjectName
= &nameW
;
457 attr
.SecurityDescriptor
= NULL
;
458 attr
.SecurityQualityOfService
= NULL
;
460 /* test NtDeleteFile on an empty directory */
461 ret
= pNtDeleteFile(&attr
);
462 ok(ret
== STATUS_SUCCESS
, "NtDeleteFile should succeed in removing an empty directory\n");
463 ret
= RemoveDirectoryW(pathW
);
464 ok(ret
== FALSE
, "expected to fail removing directory, NtDeleteFile should have removed it\n");
466 /* test NtDeleteFile on a non-empty directory */
467 ret
= CreateDirectoryW(pathW
, NULL
);
468 ok(ret
== TRUE
, "couldn't create directory ntdeletefile ?!\n");
469 ret
= CreateDirectoryW(pathsubW
, NULL
);
470 ok(ret
== TRUE
, "couldn't create directory subdir\n");
471 ret
= pNtDeleteFile(&attr
);
472 ok(ret
== STATUS_SUCCESS
, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
473 ret
= RemoveDirectoryW(pathsubW
);
474 ok(ret
== TRUE
, "expected to remove directory ntdeletefile\\sub\n");
475 ret
= RemoveDirectoryW(pathW
);
476 ok(ret
== TRUE
, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
478 pRtlFreeUnicodeString( &nameW
);
481 static void read_file_test(void)
483 const char text
[] = "foobar";
484 HANDLE handle
, read
, write
;
486 IO_STATUS_BLOCK iosb
, iosb2
;
490 LARGE_INTEGER offset
;
491 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
496 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
498 /* try read with no data */
499 U(iosb
).Status
= 0xdeadbabe;
500 iosb
.Information
= 0xdeadbeef;
501 ok( is_signaled( read
), "read handle is not signaled\n" );
502 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
503 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
504 ok( !is_signaled( read
), "read handle is signaled\n" );
505 ok( !is_signaled( event
), "event is signaled\n" );
506 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
507 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
508 ok( !apc_count
, "apc was called\n" );
509 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
510 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
511 /* iosb updated here by async i/o */
512 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
513 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
514 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
515 ok( !is_signaled( read
), "read handle is signaled\n" );
516 ok( is_signaled( event
), "event is not signaled\n" );
517 ok( !apc_count
, "apc was called\n" );
519 SleepEx( 1, FALSE
); /* non-alertable sleep */
520 ok( !apc_count
, "apc was called\n" );
521 SleepEx( 1, TRUE
); /* alertable sleep */
522 ok( apc_count
== 1, "apc not called\n" );
524 /* with no event, the pipe handle itself gets signaled */
526 U(iosb
).Status
= 0xdeadbabe;
527 iosb
.Information
= 0xdeadbeef;
528 ok( !is_signaled( read
), "read handle is not signaled\n" );
529 status
= pNtReadFile( read
, 0, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
530 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
531 ok( !is_signaled( read
), "read handle is signaled\n" );
532 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
533 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
534 ok( !apc_count
, "apc was called\n" );
535 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
536 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
537 /* iosb updated here by async i/o */
538 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
539 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
540 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
541 ok( is_signaled( read
), "read handle is signaled\n" );
542 ok( !apc_count
, "apc was called\n" );
544 SleepEx( 1, FALSE
); /* non-alertable sleep */
545 ok( !apc_count
, "apc was called\n" );
546 SleepEx( 1, TRUE
); /* alertable sleep */
547 ok( apc_count
== 1, "apc not called\n" );
549 /* now read with data ready */
551 U(iosb
).Status
= 0xdeadbabe;
552 iosb
.Information
= 0xdeadbeef;
554 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
555 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
556 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
557 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
558 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
559 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
560 ok( is_signaled( event
), "event is not signaled\n" );
561 ok( !apc_count
, "apc was called\n" );
562 SleepEx( 1, FALSE
); /* non-alertable sleep */
563 ok( !apc_count
, "apc was called\n" );
564 SleepEx( 1, TRUE
); /* alertable sleep */
565 ok( apc_count
== 1, "apc not called\n" );
567 /* try read with no data */
569 U(iosb
).Status
= 0xdeadbabe;
570 iosb
.Information
= 0xdeadbeef;
571 ok( is_signaled( event
), "event is not signaled\n" ); /* check that read resets the event */
572 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
573 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
574 ok( !is_signaled( event
), "event is signaled\n" );
575 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
576 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
577 ok( !apc_count
, "apc was called\n" );
578 ret
= WriteFile( write
, buffer
, 1, &written
, NULL
);
579 ok(ret
&& written
== 1, "WriteFile error %d\n", GetLastError());
580 /* partial read is good enough */
581 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
582 ok( is_signaled( event
), "event is signaled\n" );
583 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
584 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
585 ok( !apc_count
, "apc was called\n" );
586 SleepEx( 1, TRUE
); /* alertable sleep */
587 ok( apc_count
== 1, "apc was not called\n" );
589 /* read from disconnected pipe */
591 U(iosb
).Status
= 0xdeadbabe;
592 iosb
.Information
= 0xdeadbeef;
593 CloseHandle( write
);
594 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
595 ok( status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", status
);
596 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
597 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
598 ok( !is_signaled( event
), "event is signaled\n" );
599 ok( !apc_count
, "apc was called\n" );
600 SleepEx( 1, TRUE
); /* alertable sleep */
601 ok( !apc_count
, "apc was called\n" );
604 /* read from closed handle */
606 U(iosb
).Status
= 0xdeadbabe;
607 iosb
.Information
= 0xdeadbeef;
609 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
610 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
611 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
612 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
613 ok( is_signaled( event
), "event is signaled\n" ); /* not reset on invalid handle */
614 ok( !apc_count
, "apc was called\n" );
615 SleepEx( 1, TRUE
); /* alertable sleep */
616 ok( !apc_count
, "apc was called\n" );
618 /* disconnect while async read is in progress */
619 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
621 U(iosb
).Status
= 0xdeadbabe;
622 iosb
.Information
= 0xdeadbeef;
623 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
624 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
625 ok( !is_signaled( event
), "event is signaled\n" );
626 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
627 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
628 ok( !apc_count
, "apc was called\n" );
629 CloseHandle( write
);
630 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
631 ok( U(iosb
).Status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", U(iosb
).Status
);
632 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
633 ok( is_signaled( event
), "event is signaled\n" );
634 ok( !apc_count
, "apc was called\n" );
635 SleepEx( 1, TRUE
); /* alertable sleep */
636 ok( apc_count
== 1, "apc was not called\n" );
639 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
640 ret
= DuplicateHandle(GetCurrentProcess(), read
, GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
);
641 ok(ret
, "Failed to duplicate handle: %d\n", GetLastError());
644 U(iosb
).Status
= 0xdeadbabe;
645 iosb
.Information
= 0xdeadbeef;
646 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
647 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
648 ok( !is_signaled( event
), "event is signaled\n" );
649 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
650 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
651 ok( !apc_count
, "apc was called\n" );
652 /* Cancel by other handle */
653 status
= pNtCancelIoFile( read
, &iosb2
);
654 ok(status
== STATUS_SUCCESS
, "failed to cancel by different handle: %x\n", status
);
655 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
656 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
657 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
658 ok( is_signaled( event
), "event is signaled\n" );
659 todo_wine
ok( !apc_count
, "apc was called\n" );
660 SleepEx( 1, TRUE
); /* alertable sleep */
661 ok( apc_count
== 1, "apc was not called\n" );
664 U(iosb
).Status
= 0xdeadbabe;
665 iosb
.Information
= 0xdeadbeef;
666 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
667 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
668 ok( !is_signaled( event
), "event is signaled\n" );
669 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
670 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
671 ok( !apc_count
, "apc was called\n" );
672 /* Close queued handle */
674 SleepEx( 1, TRUE
); /* alertable sleep */
675 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
676 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
677 status
= pNtCancelIoFile( read
, &iosb2
);
678 ok(status
== STATUS_INVALID_HANDLE
, "cancelled by closed handle?\n");
679 status
= pNtCancelIoFile( handle
, &iosb2
);
680 ok(status
== STATUS_SUCCESS
, "failed to cancel: %x\n", status
);
681 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
682 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
683 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
684 ok( is_signaled( event
), "event is signaled\n" );
685 todo_wine
ok( !apc_count
, "apc was called\n" );
686 SleepEx( 1, TRUE
); /* alertable sleep */
687 ok( apc_count
== 1, "apc was not called\n" );
688 CloseHandle( handle
);
689 CloseHandle( write
);
691 if (pNtCancelIoFileEx
)
693 /* Basic Cancel Ex */
694 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
697 U(iosb
).Status
= 0xdeadbabe;
698 iosb
.Information
= 0xdeadbeef;
699 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
700 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
701 ok( !is_signaled( event
), "event is signaled\n" );
702 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
703 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
704 ok( !apc_count
, "apc was called\n" );
705 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
706 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
707 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
708 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
709 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
710 ok( is_signaled( event
), "event is signaled\n" );
711 todo_wine
ok( !apc_count
, "apc was called\n" );
712 SleepEx( 1, TRUE
); /* alertable sleep */
713 ok( apc_count
== 1, "apc was not called\n" );
717 U(iosb
).Status
= 0xdeadbabe;
718 iosb
.Information
= 0xdeadbeef;
719 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
720 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
721 ok( !is_signaled( event
), "event is signaled\n" );
722 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
723 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
724 ok( !apc_count
, "apc was called\n" );
725 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
726 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
727 ok( !is_signaled( event
), "event is signaled\n" );
728 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
729 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
730 ok( !apc_count
, "apc was called\n" );
731 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
732 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
733 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
734 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
735 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
736 ok( is_signaled( event
), "event is signaled\n" );
737 todo_wine
ok( !apc_count
, "apc was called\n" );
738 SleepEx( 1, TRUE
); /* alertable sleep */
739 ok( apc_count
== 2, "apc was not called\n" );
742 CloseHandle( write
);
745 /* now try a real file */
746 if (!(handle
= create_temp_file( FILE_FLAG_OVERLAPPED
))) return;
748 U(iosb
).Status
= 0xdeadbabe;
749 iosb
.Information
= 0xdeadbeef;
752 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
753 ok( status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
, "wrong status %x\n", status
);
754 if (status
== STATUS_PENDING
) WaitForSingleObject( event
, 1000 );
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
||
769 status
== STATUS_PENDING
, /* vista */
770 "wrong status %x\n", status
);
771 if (status
== STATUS_PENDING
) WaitForSingleObject( event
, 1000 );
772 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
773 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
774 ok( is_signaled( event
), "event is signaled\n" );
775 ok( !apc_count
, "apc was called\n" );
776 SleepEx( 1, TRUE
); /* alertable sleep */
777 ok( apc_count
== 1, "apc was not called\n" );
779 /* read beyond eof */
781 U(iosb
).Status
= 0xdeadbabe;
782 iosb
.Information
= 0xdeadbeef;
783 offset
.QuadPart
= strlen(text
) + 2;
784 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
786 ok(status
== STATUS_PENDING
|| broken(status
== STATUS_END_OF_FILE
) /* before Vista */, "expected STATUS_PENDING, got %#x\n", status
);
787 if (status
== STATUS_PENDING
) /* vista */
789 WaitForSingleObject( event
, 1000 );
790 ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
791 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
792 ok( is_signaled( event
), "event is signaled\n" );
793 ok( !apc_count
, "apc was called\n" );
794 SleepEx( 1, TRUE
); /* alertable sleep */
795 ok( apc_count
== 1, "apc was not called\n" );
797 CloseHandle( handle
);
799 /* now a non-overlapped file */
800 if (!(handle
= create_temp_file(0))) return;
802 U(iosb
).Status
= 0xdeadbabe;
803 iosb
.Information
= 0xdeadbeef;
805 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
806 ok( status
== STATUS_END_OF_FILE
||
807 status
== STATUS_SUCCESS
||
808 status
== STATUS_PENDING
, /* vista */
809 "wrong status %x\n", status
);
810 if (status
== STATUS_PENDING
) WaitForSingleObject( event
, 1000 );
811 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
812 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
813 ok( is_signaled( event
), "event is signaled\n" );
814 ok( !apc_count
, "apc was called\n" );
815 SleepEx( 1, TRUE
); /* alertable sleep */
816 ok( apc_count
== 1, "apc was not called\n" );
819 U(iosb
).Status
= 0xdeadbabe;
820 iosb
.Information
= 0xdeadbeef;
823 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
824 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
825 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
826 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
827 ok( is_signaled( event
), "event is signaled\n" );
828 ok( !apc_count
, "apc was called\n" );
829 SleepEx( 1, TRUE
); /* alertable sleep */
830 todo_wine
ok( !apc_count
, "apc was called\n" );
832 /* read beyond eof */
834 U(iosb
).Status
= 0xdeadbabe;
835 iosb
.Information
= 0xdeadbeef;
836 offset
.QuadPart
= strlen(text
) + 2;
838 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
839 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
840 todo_wine
ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
841 todo_wine
ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
842 todo_wine
ok( is_signaled( event
), "event is not signaled\n" );
843 ok( !apc_count
, "apc was called\n" );
844 SleepEx( 1, TRUE
); /* alertable sleep */
845 ok( !apc_count
, "apc was called\n" );
847 CloseHandle( handle
);
849 CloseHandle( event
);
852 static void append_file_test(void)
854 static const char text
[6] = "foobar";
857 IO_STATUS_BLOCK iosb
;
858 LARGE_INTEGER offset
;
859 char path
[MAX_PATH
], buffer
[MAX_PATH
], buf
[16];
861 GetTempPathA( MAX_PATH
, path
);
862 GetTempFileNameA( path
, "foo", 0, buffer
);
864 handle
= CreateFile(buffer
, FILE_WRITE_DATA
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
865 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFile error %d\n", GetLastError());
868 iosb
.Information
= -1;
869 status
= pNtWriteFile(handle
, NULL
, NULL
, NULL
, &iosb
, text
, 3, NULL
, NULL
);
870 ok(status
== STATUS_SUCCESS
, "NtWriteFile error %#x\n", status
);
871 ok(iosb
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iosb
.Status
);
872 ok(iosb
.Information
== 3, "expected 3, got %lu\n", iosb
.Information
);
876 /* It is possible to open a file with only FILE_APPEND_DATA access flags.
877 It matches the O_WRONLY|O_APPEND open() posix behavior */
878 handle
= CreateFile(buffer
, FILE_APPEND_DATA
, 0, NULL
, OPEN_EXISTING
, 0, 0);
879 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFile error %d\n", GetLastError());
882 iosb
.Information
= -1;
884 status
= pNtWriteFile(handle
, NULL
, NULL
, NULL
, &iosb
, text
+ 3, 3, &offset
, NULL
);
886 ok(status
== STATUS_SUCCESS
, "NtWriteFile error %#x\n", status
);
888 ok(iosb
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iosb
.Status
);
890 ok(iosb
.Information
== 3, "expected 3, got %lu\n", iosb
.Information
);
894 handle
= CreateFile(buffer
, FILE_READ_DATA
| FILE_WRITE_DATA
| FILE_APPEND_DATA
, 0, NULL
, OPEN_EXISTING
, 0, 0);
895 ok(handle
!= INVALID_HANDLE_VALUE
, "CreateFile error %d\n", GetLastError());
897 memset(buf
, 0, sizeof(buf
));
899 iosb
.Information
= -1;
901 status
= pNtReadFile(handle
, 0, NULL
, NULL
, &iosb
, buf
, sizeof(buf
), &offset
, NULL
);
902 ok(status
== STATUS_SUCCESS
, "NtReadFile error %#x\n", status
);
903 ok(iosb
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iosb
.Status
);
905 ok(iosb
.Information
== 6, "expected 6, got %lu\n", iosb
.Information
);
908 ok(memcmp(buf
, text
, 6) == 0, "wrong file contents: %s\n", buf
);
911 iosb
.Information
= -1;
913 status
= pNtWriteFile(handle
, NULL
, NULL
, NULL
, &iosb
, text
+ 3, 3, &offset
, NULL
);
914 ok(status
== STATUS_SUCCESS
, "NtWriteFile error %#x\n", status
);
915 ok(iosb
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iosb
.Status
);
916 ok(iosb
.Information
== 3, "expected 3, got %lu\n", iosb
.Information
);
918 memset(buf
, 0, sizeof(buf
));
920 iosb
.Information
= -1;
922 status
= pNtReadFile(handle
, 0, NULL
, NULL
, &iosb
, buf
, sizeof(buf
), &offset
, NULL
);
923 ok(status
== STATUS_SUCCESS
, "NtReadFile error %#x\n", status
);
924 ok(iosb
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iosb
.Status
);
926 ok(iosb
.Information
== 6, "expected 6, got %lu\n", iosb
.Information
);
929 ok(memcmp(buf
, "barbar", 6) == 0, "wrong file contents: %s\n", buf
);
935 static void nt_mailslot_test(void)
938 ACCESS_MASK DesiredAccess
;
939 OBJECT_ATTRIBUTES attr
;
943 ULONG MaxMessageSize
;
944 LARGE_INTEGER TimeOut
;
945 IO_STATUS_BLOCK IoStatusBlock
;
948 WCHAR buffer1
[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
949 'R',':','\\','F','R','E','D','\0' };
951 TimeOut
.QuadPart
= -1;
953 pRtlInitUnicodeString(&str
, buffer1
);
954 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
955 CreateOptions
= MailslotQuota
= MaxMessageSize
= 0;
956 DesiredAccess
= GENERIC_READ
;
959 * Check for NULL pointer handling
961 rc
= pNtCreateMailslotFile(NULL
, DesiredAccess
,
962 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
964 ok( rc
== STATUS_ACCESS_VIOLATION
||
965 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
966 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc
);
969 * Test to see if the Timeout can be NULL
971 hslot
= (HANDLE
)0xdeadbeef;
972 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
973 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
975 ok( rc
== STATUS_SUCCESS
||
976 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
977 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc
);
978 ok( hslot
!= 0, "Handle is invalid\n");
980 if ( rc
== STATUS_SUCCESS
) pNtClose(hslot
);
983 * Test that the length field is checked properly
986 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
987 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
989 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
991 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
993 attr
.Length
= sizeof(OBJECT_ATTRIBUTES
)+1;
994 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
995 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
997 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
999 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
1002 * Test handling of a NULL unicode string in ObjectName
1004 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
1005 attr
.ObjectName
= NULL
;
1006 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
1007 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
1009 ok( rc
== STATUS_OBJECT_PATH_SYNTAX_BAD
||
1010 rc
== STATUS_INVALID_PARAMETER
,
1011 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc
);
1013 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
1018 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
1019 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
1020 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
1022 ok( rc
== STATUS_SUCCESS
, "Create MailslotFile failed rc = %x\n", rc
);
1023 ok( hslot
!= 0, "Handle is invalid\n");
1025 rc
= pNtClose(hslot
);
1026 ok( rc
== STATUS_SUCCESS
, "NtClose failed\n");
1029 static void test_iocp_setcompletion(HANDLE h
)
1035 if (sizeof(size
) > 4) size
|= (ULONGLONG
)0x12345678 << 32;
1037 res
= pNtSetIoCompletion( h
, CKEY_FIRST
, CVALUE_FIRST
, STATUS_INVALID_DEVICE_REQUEST
, size
);
1038 ok( res
== STATUS_SUCCESS
, "NtSetIoCompletion failed: %x\n", res
);
1040 count
= get_pending_msgs(h
);
1041 ok( count
== 1, "Unexpected msg count: %d\n", count
);
1045 ok( completionKey
== CKEY_FIRST
, "Invalid completion key: %lx\n", completionKey
);
1046 ok( ioSb
.Information
== size
, "Invalid ioSb.Information: %lu\n", ioSb
.Information
);
1047 ok( U(ioSb
).Status
== STATUS_INVALID_DEVICE_REQUEST
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1048 ok( completionValue
== CVALUE_FIRST
, "Invalid completion value: %lx\n", completionValue
);
1051 count
= get_pending_msgs(h
);
1052 ok( !count
, "Unexpected msg count: %d\n", count
);
1055 static void test_iocp_fileio(HANDLE h
)
1057 static const char pipe_name
[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
1059 IO_STATUS_BLOCK iosb
;
1060 FILE_COMPLETION_INFORMATION fci
= {h
, CKEY_SECOND
};
1061 HANDLE hPipeSrv
, hPipeClt
;
1064 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
1065 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
1066 if (hPipeSrv
!= INVALID_HANDLE_VALUE
)
1068 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
1069 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
1070 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
1072 U(iosb
).Status
= 0xdeadbeef;
1073 res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
1074 ok( res
== STATUS_INVALID_PARAMETER
, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res
);
1075 ok( U(iosb
).Status
== STATUS_INVALID_PARAMETER
/* 98 */ || U(iosb
).Status
== 0xdeadbeef /* NT4+ */,
1076 "Unexpected iosb.Status on non-overlapped handle: %x\n", U(iosb
).Status
);
1077 CloseHandle(hPipeClt
);
1079 CloseHandle( hPipeSrv
);
1082 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
| FILE_FLAG_OVERLAPPED
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
1083 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
1084 if (hPipeSrv
== INVALID_HANDLE_VALUE
)
1087 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
1088 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
1089 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
1091 OVERLAPPED o
= {0,};
1092 BYTE send_buf
[TEST_BUF_LEN
], recv_buf
[TEST_BUF_LEN
];
1096 U(iosb
).Status
= 0xdeadbeef;
1097 res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
1098 ok( res
== STATUS_SUCCESS
, "NtSetInformationFile failed: %x\n", res
);
1099 ok( U(iosb
).Status
== STATUS_SUCCESS
, "iosb.Status invalid: %x\n", U(iosb
).Status
);
1101 memset( send_buf
, 0, TEST_BUF_LEN
);
1102 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
1103 count
= get_pending_msgs(h
);
1104 ok( !count
, "Unexpected msg count: %ld\n", count
);
1105 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
1106 count
= get_pending_msgs(h
);
1107 ok( !count
, "Unexpected msg count: %ld\n", count
);
1108 WriteFile( hPipeClt
, send_buf
, TEST_BUF_LEN
, &read
, NULL
);
1112 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1113 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1114 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1115 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1116 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] );
1118 count
= get_pending_msgs(h
);
1119 ok( !count
, "Unexpected msg count: %ld\n", count
);
1121 memset( send_buf
, 0, TEST_BUF_LEN
);
1122 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
1123 WriteFile( hPipeClt
, send_buf
, 2, &read
, NULL
);
1124 count
= get_pending_msgs(h
);
1125 ok( !count
, "Unexpected msg count: %ld\n", count
);
1126 ReadFile( hPipeSrv
, recv_buf
, 2, &read
, &o
);
1127 count
= get_pending_msgs(h
);
1128 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
1131 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1132 ok( ioSb
.Information
== 2, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1133 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1134 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1135 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] );
1138 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
1139 CloseHandle( hPipeSrv
);
1140 count
= get_pending_msgs(h
);
1141 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
1144 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1145 ok( ioSb
.Information
== 0, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1146 /* wine sends wrong status here */
1147 todo_wine
ok( U(ioSb
).Status
== STATUS_PIPE_BROKEN
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1148 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1152 CloseHandle( hPipeClt
);
1154 /* test associating a completion port with a handle after an async is queued */
1155 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
| FILE_FLAG_OVERLAPPED
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
1156 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
1157 if (hPipeSrv
== INVALID_HANDLE_VALUE
)
1159 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
1160 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
1161 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
1163 OVERLAPPED o
= {0,};
1164 BYTE send_buf
[TEST_BUF_LEN
], recv_buf
[TEST_BUF_LEN
];
1168 memset( send_buf
, 0, TEST_BUF_LEN
);
1169 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
1170 count
= get_pending_msgs(h
);
1171 ok( !count
, "Unexpected msg count: %ld\n", count
);
1172 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
1174 U(iosb
).Status
= 0xdeadbeef;
1175 res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
1176 ok( res
== STATUS_SUCCESS
, "NtSetInformationFile failed: %x\n", res
);
1177 ok( U(iosb
).Status
== STATUS_SUCCESS
, "iosb.Status invalid: %x\n", U(iosb
).Status
);
1178 count
= get_pending_msgs(h
);
1179 ok( !count
, "Unexpected msg count: %ld\n", count
);
1181 WriteFile( hPipeClt
, send_buf
, TEST_BUF_LEN
, &read
, NULL
);
1185 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
1186 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
1187 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
1188 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
1189 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] );
1191 count
= get_pending_msgs(h
);
1192 ok( !count
, "Unexpected msg count: %ld\n", count
);
1195 CloseHandle( hPipeSrv
);
1196 CloseHandle( hPipeClt
);
1199 static void test_file_basic_information(void)
1202 FILE_BASIC_INFORMATION fbi
;
1205 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1207 if (!(h
= create_temp_file(0))) return;
1209 /* Check default first */
1210 memset(&fbi
, 0, sizeof(fbi
));
1211 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1212 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1213 ok ( (fbi
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1214 "attribute %x not expected\n", fbi
.FileAttributes
);
1217 /* Clear fbi to avoid setting times */
1218 memset(&fbi
, 0, sizeof(fbi
));
1219 fbi
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1220 U(io
).Status
= 0xdeadbeef;
1221 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1222 ok ( res
== STATUS_SUCCESS
, "can't set system attribute, NtSetInformationFile returned %x\n", res
);
1223 ok ( U(io
).Status
== STATUS_SUCCESS
, "can't set system attribute, io.Status is %x\n", U(io
).Status
);
1225 memset(&fbi
, 0, sizeof(fbi
));
1226 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1227 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1228 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_SYSTEM
, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi
.FileAttributes
);
1231 memset(&fbi
, 0, sizeof(fbi
));
1232 fbi
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1233 U(io
).Status
= 0xdeadbeef;
1234 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1235 ok ( res
== STATUS_SUCCESS
, "can't set system attribute, NtSetInformationFile returned %x\n", res
);
1236 ok ( U(io
).Status
== STATUS_SUCCESS
, "can't set system attribute, io.Status is %x\n", U(io
).Status
);
1238 memset(&fbi
, 0, sizeof(fbi
));
1239 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1240 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1241 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_HIDDEN
, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi
.FileAttributes
);
1243 /* Check NORMAL last of all (to make sure we can clear attributes) */
1244 memset(&fbi
, 0, sizeof(fbi
));
1245 fbi
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1246 U(io
).Status
= 0xdeadbeef;
1247 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1248 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute, NtSetInformationFile returned %x\n", res
);
1249 ok ( U(io
).Status
== STATUS_SUCCESS
, "can't set normal attribute, io.Status is %x\n", U(io
).Status
);
1251 memset(&fbi
, 0, sizeof(fbi
));
1252 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1253 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1254 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_NORMAL
, "attribute %x not 0\n", fbi
.FileAttributes
);
1259 static void test_file_all_information(void)
1262 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1263 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1264 * don't leave enough room there.
1267 FILE_ALL_INFORMATION fai
;
1272 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1274 if (!(h
= create_temp_file(0))) return;
1276 /* Check default first */
1277 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1278 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1279 ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1280 "attribute %x not expected\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1283 /* Clear fbi to avoid setting times */
1284 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1285 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1286 U(io
).Status
= 0xdeadbeef;
1287 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1288 ok ( res
== STATUS_INVALID_INFO_CLASS
|| broken(res
== STATUS_NOT_IMPLEMENTED
), "shouldn't be able to set FileAllInformation, res %x\n", res
);
1289 todo_wine
ok ( U(io
).Status
== 0xdeadbeef, "shouldn't be able to set FileAllInformation, io.Status is %x\n", U(io
).Status
);
1290 U(io
).Status
= 0xdeadbeef;
1291 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1292 ok ( res
== STATUS_SUCCESS
, "can't set system attribute, res: %x\n", res
);
1293 ok ( U(io
).Status
== STATUS_SUCCESS
, "can't set system attribute, io.Status: %x\n", U(io
).Status
);
1295 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1296 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1297 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1298 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
);
1301 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1302 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1303 U(io
).Status
= 0xdeadbeef;
1304 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1305 ok ( res
== STATUS_SUCCESS
, "can't set system attribute, res: %x\n", res
);
1306 ok ( U(io
).Status
== STATUS_SUCCESS
, "can't set system attribute, io.Status: %x\n", U(io
).Status
);
1308 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1309 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1310 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1311 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
);
1313 /* Check NORMAL last of all (to make sure we can clear attributes) */
1314 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1315 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1316 U(io
).Status
= 0xdeadbeef;
1317 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1318 ok ( res
== STATUS_SUCCESS
, "can't set system attribute, res: %x\n", res
);
1319 ok ( U(io
).Status
== STATUS_SUCCESS
, "can't set system attribute, io.Status: %x\n", U(io
).Status
);
1321 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1322 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1323 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1324 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
);
1329 static void test_file_both_information(void)
1332 FILE_BOTH_DIR_INFORMATION fbi
;
1336 if (!(h
= create_temp_file(0))) return;
1338 memset(&fbi
, 0, sizeof(fbi
));
1339 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBothDirectoryInformation
);
1340 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res
);
1345 static void test_file_disposition_information(void)
1347 char buffer
[MAX_PATH
+ 16];
1349 HANDLE handle
, handle2
;
1352 FILE_DISPOSITION_INFORMATION fdi
;
1355 /* cannot set disposition on file not opened with delete access */
1356 GetTempFileNameA( ".", "dis", 0, buffer
);
1357 handle
= CreateFileA(buffer
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
1358 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
1359 res
= pNtQueryInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1360 ok( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "Unexpected NtQueryInformationFile result (expected STATUS_INVALID_INFO_CLASS, got %x)\n", res
);
1361 fdi
.DoDeleteFile
= TRUE
;
1362 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1364 ok( res
== STATUS_ACCESS_DENIED
, "unexpected FileDispositionInformation result (expected STATUS_ACCESS_DENIED, got %x)\n", res
);
1365 CloseHandle( handle
);
1366 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1367 ok( !fileDeleted
, "File shouldn't have been deleted\n" );
1368 DeleteFileA( buffer
);
1370 /* can set disposition on file opened with proper access */
1371 GetTempFileNameA( ".", "dis", 0, buffer
);
1372 handle
= CreateFileA(buffer
, GENERIC_WRITE
| DELETE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
1373 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
1374 fdi
.DoDeleteFile
= TRUE
;
1375 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1377 ok( res
== STATUS_SUCCESS
, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res
);
1378 CloseHandle( handle
);
1379 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1381 ok( fileDeleted
, "File should have been deleted\n" );
1382 DeleteFileA( buffer
);
1384 /* cannot set disposition on readonly file */
1385 GetTempFileNameA( ".", "dis", 0, buffer
);
1386 handle
= CreateFileA(buffer
, GENERIC_WRITE
| DELETE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_READONLY
, 0);
1387 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
1388 fdi
.DoDeleteFile
= TRUE
;
1389 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1391 ok( res
== STATUS_CANNOT_DELETE
, "unexpected FileDispositionInformation result (expected STATUS_CANNOT_DELETE, got %x)\n", res
);
1392 CloseHandle( handle
);
1393 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1394 ok( !fileDeleted
, "File shouldn't have been deleted\n" );
1395 SetFileAttributesA( buffer
, FILE_ATTRIBUTE_NORMAL
);
1396 DeleteFileA( buffer
);
1398 /* can set disposition on file and then reset it */
1399 GetTempFileNameA( ".", "dis", 0, buffer
);
1400 handle
= CreateFileA(buffer
, GENERIC_WRITE
| DELETE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
1401 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
1402 fdi
.DoDeleteFile
= TRUE
;
1403 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1405 ok( res
== STATUS_SUCCESS
, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res
);
1406 fdi
.DoDeleteFile
= FALSE
;
1407 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1409 ok( res
== STATUS_SUCCESS
, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res
);
1410 CloseHandle( handle
);
1411 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1412 ok( !fileDeleted
, "File shouldn't have been deleted\n" );
1413 DeleteFileA( buffer
);
1415 /* Delete-on-close flag doesn't change file disposition until a handle is closed */
1416 GetTempFileNameA( ".", "dis", 0, buffer
);
1417 handle
= CreateFileA(buffer
, GENERIC_WRITE
| DELETE
, 0, NULL
, CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, 0);
1418 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
1419 fdi
.DoDeleteFile
= FALSE
;
1420 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1422 ok( res
== STATUS_SUCCESS
, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res
);
1423 CloseHandle( handle
);
1424 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1425 ok( fileDeleted
, "File should have been deleted\n" );
1426 DeleteFileA( buffer
);
1428 /* Delete-on-close flag sets disposition when a handle is closed and then it could be changed back */
1429 GetTempFileNameA( ".", "dis", 0, buffer
);
1430 handle
= CreateFileA(buffer
, GENERIC_WRITE
| DELETE
, 0, NULL
, CREATE_ALWAYS
, FILE_FLAG_DELETE_ON_CLOSE
, 0);
1431 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
1432 ok( DuplicateHandle( GetCurrentProcess(), handle
, GetCurrentProcess(), &handle2
, 0, FALSE
, DUPLICATE_SAME_ACCESS
), "DuplicateHandle failed\n" );
1433 CloseHandle( handle
);
1434 fdi
.DoDeleteFile
= FALSE
;
1435 res
= pNtSetInformationFile( handle2
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1437 ok( res
== STATUS_SUCCESS
, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res
);
1438 CloseHandle( handle2
);
1439 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1440 ok( fileDeleted
, "File should have been deleted\n" );
1441 DeleteFileA( buffer
);
1443 /* can set disposition on a directory opened with proper access */
1444 GetTempFileNameA( ".", "dis", 0, buffer
);
1445 DeleteFileA( buffer
);
1446 ok( CreateDirectoryA( buffer
, NULL
), "CreateDirectory failed\n" );
1447 handle
= CreateFileA(buffer
, DELETE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
1448 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to open a directory\n" );
1449 fdi
.DoDeleteFile
= TRUE
;
1450 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1452 ok( res
== STATUS_SUCCESS
, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res
);
1453 CloseHandle( handle
);
1454 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1456 ok( fileDeleted
, "Directory should have been deleted\n" );
1457 RemoveDirectoryA( buffer
);
1459 /* RemoveDirectory sets directory disposition and it can be undone */
1460 GetTempFileNameA( ".", "dis", 0, buffer
);
1461 DeleteFileA( buffer
);
1462 ok( CreateDirectoryA( buffer
, NULL
), "CreateDirectory failed\n" );
1463 handle
= CreateFileA(buffer
, DELETE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
1464 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to open a directory\n" );
1465 RemoveDirectoryA( buffer
);
1466 fdi
.DoDeleteFile
= FALSE
;
1467 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1469 ok( res
== STATUS_SUCCESS
, "unexpected FileDispositionInformation result (expected STATUS_SUCCESS, got %x)\n", res
);
1470 CloseHandle( handle
);
1471 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1472 ok( !fileDeleted
, "Directory shouldn't have been deleted\n" );
1473 RemoveDirectoryA( buffer
);
1475 /* cannot set disposition on a non-empty directory */
1476 GetTempFileNameA( ".", "dis", 0, buffer
);
1477 DeleteFileA( buffer
);
1478 ok( CreateDirectoryA( buffer
, NULL
), "CreateDirectory failed\n" );
1479 handle
= CreateFileA(buffer
, DELETE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0);
1480 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to open a directory\n" );
1481 dirpos
= lstrlenA( buffer
);
1482 lstrcpyA( buffer
+ dirpos
, "\\tst" );
1483 handle2
= CreateFileA(buffer
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0);
1484 CloseHandle( handle2
);
1485 fdi
.DoDeleteFile
= TRUE
;
1486 res
= pNtSetInformationFile( handle
, &io
, &fdi
, sizeof fdi
, FileDispositionInformation
);
1488 ok( res
== STATUS_DIRECTORY_NOT_EMPTY
, "unexpected FileDispositionInformation result (expected STATUS_DIRECTORY_NOT_EMPTY, got %x)\n", res
);
1489 DeleteFileA( buffer
);
1490 buffer
[dirpos
] = '\0';
1491 CloseHandle( handle
);
1492 fileDeleted
= GetFileAttributesA( buffer
) == INVALID_FILE_ATTRIBUTES
&& GetLastError() == ERROR_FILE_NOT_FOUND
;
1493 ok( !fileDeleted
, "Directory shouldn't have been deleted\n" );
1494 RemoveDirectoryA( buffer
);
1497 static void test_iocompletion(void)
1499 HANDLE h
= INVALID_HANDLE_VALUE
;
1502 res
= pNtCreateIoCompletion( &h
, IO_COMPLETION_ALL_ACCESS
, NULL
, 0);
1504 ok( res
== 0, "NtCreateIoCompletion anonymous failed: %x\n", res
);
1505 ok( h
&& h
!= INVALID_HANDLE_VALUE
, "Invalid handle returned\n" );
1507 if ( h
&& h
!= INVALID_HANDLE_VALUE
)
1509 test_iocp_setcompletion(h
);
1510 test_iocp_fileio(h
);
1515 static void test_file_name_information(void)
1517 WCHAR
*file_name
, *volume_prefix
, *expected
;
1518 FILE_NAME_INFORMATION
*info
;
1519 ULONG old_redir
= 1, tmp
;
1520 UINT file_name_size
;
1527 /* GetVolumePathName is not present before w2k */
1528 if (!pGetVolumePathNameW
) {
1529 win_skip("GetVolumePathNameW not found\n");
1533 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1534 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1535 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1536 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1538 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1539 ok(len
== file_name_size
- 1,
1540 "GetSystemDirectoryW returned %u, expected %u.\n",
1541 len
, file_name_size
- 1);
1543 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1544 ok(len
, "GetVolumePathNameW failed.\n");
1546 len
= lstrlenW( volume_prefix
);
1547 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1548 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1549 expected
[file_name_size
- len
- 1] = '\0';
1551 /* A bit more than we actually need, but it keeps the calculation simple. */
1552 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1553 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1555 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1556 h
= CreateFileW( file_name
, GENERIC_READ
,
1557 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1558 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1559 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1560 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1562 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileNameInformation
);
1563 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x.\n", hr
);
1565 memset( info
, 0xcc, info_size
);
1566 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileNameInformation
);
1567 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1568 hr
, STATUS_BUFFER_OVERFLOW
);
1569 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1570 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1571 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1572 ok(info
->FileName
[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info
->FileName
[2]);
1573 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1574 "info->FileName[1] is %p, expected %p.\n",
1575 CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1576 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1578 memset( info
, 0xcc, info_size
);
1579 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1580 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1581 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1582 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u\n", info
->FileNameLength
);
1583 ok(info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] == 0xcccc, "info->FileName[len] is %#x, expected 0xcccc.\n",
1584 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)]);
1585 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1586 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1587 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1588 ok(io
.Information
== FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
,
1589 "io.Information is %lu, expected %u.\n",
1590 io
.Information
, FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
);
1593 HeapFree( GetProcessHeap(), 0, info
);
1594 HeapFree( GetProcessHeap(), 0, expected
);
1595 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1597 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1599 skip("Not running on WoW64, skipping test.\n");
1600 HeapFree( GetProcessHeap(), 0, file_name
);
1604 h
= CreateFileW( file_name
, GENERIC_READ
,
1605 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1606 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1607 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1608 HeapFree( GetProcessHeap(), 0, file_name
);
1610 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1611 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1612 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1614 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1615 ok(len
== file_name_size
- 1,
1616 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1617 len
, file_name_size
- 1);
1619 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1620 ok(len
, "GetVolumePathNameW failed.\n");
1622 len
= lstrlenW( volume_prefix
);
1623 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1624 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1625 expected
[file_name_size
- len
- 1] = '\0';
1627 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1628 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1630 memset( info
, 0xcc, info_size
);
1631 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1632 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1633 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1634 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1635 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1638 HeapFree( GetProcessHeap(), 0, info
);
1639 HeapFree( GetProcessHeap(), 0, expected
);
1640 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1641 HeapFree( GetProcessHeap(), 0, file_name
);
1644 static void test_file_all_name_information(void)
1646 WCHAR
*file_name
, *volume_prefix
, *expected
;
1647 FILE_ALL_INFORMATION
*info
;
1648 ULONG old_redir
= 1, tmp
;
1649 UINT file_name_size
;
1656 /* GetVolumePathName is not present before w2k */
1657 if (!pGetVolumePathNameW
) {
1658 win_skip("GetVolumePathNameW not found\n");
1662 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1663 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1664 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1665 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1667 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1668 ok(len
== file_name_size
- 1,
1669 "GetSystemDirectoryW returned %u, expected %u.\n",
1670 len
, file_name_size
- 1);
1672 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1673 ok(len
, "GetVolumePathNameW failed.\n");
1675 len
= lstrlenW( volume_prefix
);
1676 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1677 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1678 expected
[file_name_size
- len
- 1] = '\0';
1680 /* A bit more than we actually need, but it keeps the calculation simple. */
1681 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1682 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1684 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1685 h
= CreateFileW( file_name
, GENERIC_READ
,
1686 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1687 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1688 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1689 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1691 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileAllInformation
);
1692 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1693 hr
, STATUS_INFO_LENGTH_MISMATCH
);
1695 memset( info
, 0xcc, info_size
);
1696 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileAllInformation
);
1697 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1698 hr
, STATUS_BUFFER_OVERFLOW
);
1699 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1700 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1701 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1702 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1703 ok(info
->NameInformation
.FileName
[2] == 0xcccc,
1704 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info
->NameInformation
.FileName
[2]);
1705 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1706 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1707 CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1708 ok(io
.Information
== sizeof(*info
), "io.Information is %lu\n", io
.Information
);
1710 memset( info
, 0xcc, info_size
);
1711 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1712 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1713 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1714 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1715 "info->NameInformation.FileNameLength is %u\n", info
->NameInformation
.FileNameLength
);
1716 ok(info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] == 0xcccc,
1717 "info->NameInformation.FileName[len] is %#x, expected 0xcccc.\n",
1718 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)]);
1719 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1720 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
),
1721 "info->NameInformation.FileName is %s, expected %s.\n",
1722 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1723 ok(io
.Information
== FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
)
1724 + info
->NameInformation
.FileNameLength
,
1725 "io.Information is %lu\n", io
.Information
);
1728 HeapFree( GetProcessHeap(), 0, info
);
1729 HeapFree( GetProcessHeap(), 0, expected
);
1730 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1732 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1734 skip("Not running on WoW64, skipping test.\n");
1735 HeapFree( GetProcessHeap(), 0, file_name
);
1739 h
= CreateFileW( file_name
, GENERIC_READ
,
1740 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1741 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1742 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1743 HeapFree( GetProcessHeap(), 0, file_name
);
1745 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1746 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1747 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1749 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1750 ok(len
== file_name_size
- 1,
1751 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1752 len
, file_name_size
- 1);
1754 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1755 ok(len
, "GetVolumePathNameW failed.\n");
1757 len
= lstrlenW( volume_prefix
);
1758 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1759 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1760 expected
[file_name_size
- len
- 1] = '\0';
1762 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1763 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1765 memset( info
, 0xcc, info_size
);
1766 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1767 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1768 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1769 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
), "info->NameInformation.FileName is %s, expected %s.\n",
1770 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1773 HeapFree( GetProcessHeap(), 0, info
);
1774 HeapFree( GetProcessHeap(), 0, expected
);
1775 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1776 HeapFree( GetProcessHeap(), 0, file_name
);
1779 static void test_query_volume_information_file(void)
1783 WCHAR path
[MAX_PATH
];
1784 OBJECT_ATTRIBUTES attr
;
1786 UNICODE_STRING nameW
;
1787 FILE_FS_VOLUME_INFORMATION
*ffvi
;
1788 BYTE buf
[sizeof(FILE_FS_VOLUME_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
)];
1790 GetWindowsDirectoryW( path
, MAX_PATH
);
1791 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
1792 attr
.Length
= sizeof(attr
);
1793 attr
.RootDirectory
= 0;
1794 attr
.ObjectName
= &nameW
;
1795 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1796 attr
.SecurityDescriptor
= NULL
;
1797 attr
.SecurityQualityOfService
= NULL
;
1799 status
= pNtOpenFile( &dir
, SYNCHRONIZE
|FILE_LIST_DIRECTORY
, &attr
, &io
,
1800 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
);
1801 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
1802 pRtlFreeUnicodeString( &nameW
);
1804 ZeroMemory( buf
, sizeof(buf
) );
1805 U(io
).Status
= 0xdadadada;
1806 io
.Information
= 0xcacacaca;
1808 status
= pNtQueryVolumeInformationFile( dir
, &io
, buf
, sizeof(buf
), FileFsVolumeInformation
);
1810 ffvi
= (FILE_FS_VOLUME_INFORMATION
*)buf
;
1814 ok(status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %d\n", status
);
1815 ok(U(io
).Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %d\n", U(io
).Status
);
1817 ok(io
.Information
== (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION
, VolumeLabel
) + ffvi
->VolumeLabelLength
),
1818 "expected %d, got %lu\n", (FIELD_OFFSET(FILE_FS_VOLUME_INFORMATION
, VolumeLabel
) + ffvi
->VolumeLabelLength
),
1821 ok(ffvi
->VolumeCreationTime
.QuadPart
!= 0, "Missing VolumeCreationTime\n");
1822 ok(ffvi
->VolumeSerialNumber
!= 0, "Missing VolumeSerialNumber\n");
1823 ok(ffvi
->SupportsObjects
== 1,"expected 1, got %d\n", ffvi
->SupportsObjects
);
1825 ok(ffvi
->VolumeLabelLength
== lstrlenW(ffvi
->VolumeLabel
) * sizeof(WCHAR
), "got %d\n", ffvi
->VolumeLabelLength
);
1827 trace("VolumeSerialNumber: %x VolumeLabelName: %s\n", ffvi
->VolumeSerialNumber
, wine_dbgstr_w(ffvi
->VolumeLabel
));
1832 static void test_query_attribute_information_file(void)
1836 WCHAR path
[MAX_PATH
];
1837 OBJECT_ATTRIBUTES attr
;
1839 UNICODE_STRING nameW
;
1840 FILE_FS_ATTRIBUTE_INFORMATION
*ffai
;
1841 BYTE buf
[sizeof(FILE_FS_ATTRIBUTE_INFORMATION
) + MAX_PATH
* sizeof(WCHAR
)];
1843 GetWindowsDirectoryW( path
, MAX_PATH
);
1844 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
1845 attr
.Length
= sizeof(attr
);
1846 attr
.RootDirectory
= 0;
1847 attr
.ObjectName
= &nameW
;
1848 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1849 attr
.SecurityDescriptor
= NULL
;
1850 attr
.SecurityQualityOfService
= NULL
;
1852 status
= pNtOpenFile( &dir
, SYNCHRONIZE
|FILE_LIST_DIRECTORY
, &attr
, &io
,
1853 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
|FILE_SYNCHRONOUS_IO_NONALERT
);
1854 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
1855 pRtlFreeUnicodeString( &nameW
);
1857 ZeroMemory( buf
, sizeof(buf
) );
1858 U(io
).Status
= 0xdadadada;
1859 io
.Information
= 0xcacacaca;
1861 status
= pNtQueryVolumeInformationFile( dir
, &io
, buf
, sizeof(buf
), FileFsAttributeInformation
);
1863 ffai
= (FILE_FS_ATTRIBUTE_INFORMATION
*)buf
;
1865 ok(status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %d\n", status
);
1866 ok(U(io
).Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %d\n", U(io
).Status
);
1867 ok(ffai
->FileSystemAttribute
!= 0, "Missing FileSystemAttribute\n");
1868 ok(ffai
->MaximumComponentNameLength
!= 0, "Missing MaximumComponentNameLength\n");
1869 ok(ffai
->FileSystemNameLength
!= 0, "Missing FileSystemNameLength\n");
1871 trace("FileSystemAttribute: %x MaximumComponentNameLength: %x FileSystemName: %s\n",
1872 ffai
->FileSystemAttribute
, ffai
->MaximumComponentNameLength
,
1873 wine_dbgstr_wn(ffai
->FileSystemName
, ffai
->FileSystemNameLength
/ sizeof(WCHAR
)));
1878 static void test_NtCreateFile(void)
1880 static const struct test_data
1882 DWORD disposition
, attrib_in
, status
, result
, attrib_out
, needs_cleanup
;
1885 /* 0*/{ FILE_CREATE
, FILE_ATTRIBUTE_READONLY
, 0, FILE_CREATED
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
, FALSE
},
1886 /* 1*/{ FILE_CREATE
, 0, STATUS_OBJECT_NAME_COLLISION
, 0, 0, TRUE
},
1887 /* 2*/{ FILE_CREATE
, 0, 0, FILE_CREATED
, FILE_ATTRIBUTE_ARCHIVE
, FALSE
},
1888 /* 3*/{ FILE_OPEN
, FILE_ATTRIBUTE_READONLY
, 0, FILE_OPENED
, FILE_ATTRIBUTE_ARCHIVE
, TRUE
},
1889 /* 4*/{ FILE_OPEN
, FILE_ATTRIBUTE_READONLY
, STATUS_OBJECT_NAME_NOT_FOUND
, 0, 0, FALSE
},
1890 /* 5*/{ FILE_OPEN_IF
, 0, 0, FILE_CREATED
, FILE_ATTRIBUTE_ARCHIVE
, FALSE
},
1891 /* 6*/{ FILE_OPEN_IF
, FILE_ATTRIBUTE_READONLY
, 0, FILE_OPENED
, FILE_ATTRIBUTE_ARCHIVE
, TRUE
},
1892 /* 7*/{ FILE_OPEN_IF
, FILE_ATTRIBUTE_READONLY
, 0, FILE_CREATED
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
, FALSE
},
1893 /* 8*/{ FILE_OPEN_IF
, 0, 0, FILE_OPENED
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
, FALSE
},
1894 /* 9*/{ FILE_OVERWRITE
, 0, STATUS_ACCESS_DENIED
, 0, 0, TRUE
},
1895 /*10*/{ FILE_OVERWRITE
, 0, STATUS_OBJECT_NAME_NOT_FOUND
, 0, 0, FALSE
},
1896 /*11*/{ FILE_CREATE
, 0, 0, FILE_CREATED
, FILE_ATTRIBUTE_ARCHIVE
, FALSE
},
1897 /*12*/{ FILE_OVERWRITE
, FILE_ATTRIBUTE_READONLY
, 0, FILE_OVERWRITTEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
, FALSE
},
1898 /*13*/{ FILE_OVERWRITE_IF
, 0, STATUS_ACCESS_DENIED
, 0, 0, TRUE
},
1899 /*14*/{ FILE_OVERWRITE_IF
, 0, 0, FILE_CREATED
, FILE_ATTRIBUTE_ARCHIVE
, FALSE
},
1900 /*15*/{ FILE_OVERWRITE_IF
, FILE_ATTRIBUTE_READONLY
, 0, FILE_OVERWRITTEN
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
, FALSE
},
1901 /*16*/{ FILE_SUPERSEDE
, 0, 0, FILE_SUPERSEDED
, FILE_ATTRIBUTE_ARCHIVE
, FALSE
},
1902 /*17*/{ FILE_SUPERSEDE
, FILE_ATTRIBUTE_READONLY
, 0, FILE_SUPERSEDED
, FILE_ATTRIBUTE_ARCHIVE
|FILE_ATTRIBUTE_READONLY
, TRUE
},
1903 /*18*/{ FILE_SUPERSEDE
, 0, 0, FILE_CREATED
, FILE_ATTRIBUTE_ARCHIVE
, TRUE
}
1905 static const WCHAR fooW
[] = {'f','o','o',0};
1908 WCHAR path
[MAX_PATH
];
1909 OBJECT_ATTRIBUTES attr
;
1911 UNICODE_STRING nameW
;
1914 GetTempPathW(MAX_PATH
, path
);
1915 GetTempFileNameW(path
, fooW
, 0, path
);
1917 pRtlDosPathNameToNtPathName_U(path
, &nameW
, NULL
, NULL
);
1919 attr
.Length
= sizeof(attr
);
1920 attr
.RootDirectory
= NULL
;
1921 attr
.ObjectName
= &nameW
;
1922 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
1923 attr
.SecurityDescriptor
= NULL
;
1924 attr
.SecurityQualityOfService
= NULL
;
1926 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
1928 status
= pNtCreateFile(&handle
, GENERIC_READ
, &attr
, &io
, NULL
,
1929 td
[i
].attrib_in
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
1930 td
[i
].disposition
, 0, NULL
, 0);
1932 ok(status
== td
[i
].status
, "%d: expected %#x got %#x\n", i
, td
[i
].status
, status
);
1936 ok(io
.Information
== td
[i
].result
,"%d: expected %#x got %#lx\n", i
, td
[i
].result
, io
.Information
);
1938 ret
= GetFileAttributesW(path
);
1939 ret
&= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
;
1940 /* FIXME: leave only 'else' case below once Wine is fixed */
1941 if (ret
!= td
[i
].attrib_out
)
1944 ok(ret
== td
[i
].attrib_out
, "%d: expected %#x got %#x\n", i
, td
[i
].attrib_out
, ret
);
1945 SetFileAttributesW(path
, td
[i
].attrib_out
);
1948 ok(ret
== td
[i
].attrib_out
, "%d: expected %#x got %#x\n", i
, td
[i
].attrib_out
, ret
);
1950 CloseHandle(handle
);
1953 if (td
[i
].needs_cleanup
)
1955 SetFileAttributesW(path
, FILE_ATTRIBUTE_ARCHIVE
);
1960 SetFileAttributesW(path
, FILE_ATTRIBUTE_ARCHIVE
);
1961 DeleteFileW( path
);
1964 static void test_read_write(void)
1966 static const char contents
[14] = "1234567890abcd";
1970 IO_STATUS_BLOCK iob
;
1971 DWORD ret
, bytes
, status
, off
;
1972 LARGE_INTEGER offset
;
1976 iob
.Information
= -1;
1977 offset
.QuadPart
= 0;
1978 status
= pNtReadFile(INVALID_HANDLE_VALUE
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
1979 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
|| status
== STATUS_INVALID_HANDLE
, "expected STATUS_OBJECT_TYPE_MISMATCH, got %#x\n", status
);
1980 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
1981 ok(iob
.Information
== -1, "expected -1, got %lu\n", iob
.Information
);
1984 iob
.Information
= -1;
1985 offset
.QuadPart
= 0;
1986 status
= pNtWriteFile(INVALID_HANDLE_VALUE
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
1987 ok(status
== STATUS_OBJECT_TYPE_MISMATCH
|| status
== STATUS_INVALID_HANDLE
, "expected STATUS_OBJECT_TYPE_MISMATCH, got %#x\n", status
);
1988 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
1989 ok(iob
.Information
== -1, "expected -1, got %lu\n", iob
.Information
);
1991 hfile
= create_temp_file(0);
1995 iob
.Information
= -1;
1996 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, NULL
, sizeof(contents
), NULL
, NULL
);
1997 ok(status
== STATUS_INVALID_USER_BUFFER
, "expected STATUS_INVALID_USER_BUFFER, got %#x\n", status
);
1998 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
1999 ok(iob
.Information
== -1, "expected -1, got %lu\n", iob
.Information
);
2002 iob
.Information
= -1;
2003 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, NULL
, sizeof(contents
), NULL
, NULL
);
2004 ok(status
== STATUS_ACCESS_VIOLATION
, "expected STATUS_ACCESS_VIOLATION, got %#x\n", status
);
2005 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
2006 ok(iob
.Information
== -1, "expected -1, got %lu\n", iob
.Information
);
2009 iob
.Information
= -1;
2010 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, contents
, 7, NULL
, NULL
);
2011 ok(status
== STATUS_SUCCESS
, "NtWriteFile error %#x\n", status
);
2012 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2013 ok(iob
.Information
== 7, "expected 7, got %lu\n", iob
.Information
);
2015 SetFilePointer(hfile
, 0, NULL
, FILE_BEGIN
);
2018 iob
.Information
= -1;
2019 offset
.QuadPart
= (LONGLONG
)-1 /* FILE_WRITE_TO_END_OF_FILE */;
2020 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, contents
+ 7, sizeof(contents
) - 7, &offset
, NULL
);
2021 ok(status
== STATUS_SUCCESS
, "NtWriteFile error %#x\n", status
);
2022 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2023 ok(iob
.Information
== sizeof(contents
) - 7, "expected sizeof(contents)-7, got %lu\n", iob
.Information
);
2025 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2026 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2029 SetLastError(0xdeadbeef);
2030 ret
= ReadFile(INVALID_HANDLE_VALUE
, buf
, 0, &bytes
, NULL
);
2031 ok(!ret
, "ReadFile should fail\n");
2032 ok(GetLastError() == ERROR_INVALID_HANDLE
, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
2033 ok(bytes
== 0, "bytes %u\n", bytes
);
2036 SetLastError(0xdeadbeef);
2037 ret
= ReadFile(hfile
, buf
, 0, &bytes
, NULL
);
2038 ok(ret
, "ReadFile error %d\n", GetLastError());
2039 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2040 ok(bytes
== 0, "bytes %u\n", bytes
);
2043 SetLastError(0xdeadbeef);
2044 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, NULL
);
2045 ok(ret
, "ReadFile error %d\n", GetLastError());
2046 ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
2047 ok(bytes
== 0, "bytes %u\n", bytes
);
2049 SetFilePointer(hfile
, 0, NULL
, FILE_BEGIN
);
2052 SetLastError(0xdeadbeef);
2053 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, NULL
);
2054 ok(ret
, "ReadFile error %d\n", GetLastError());
2055 ok(bytes
== sizeof(contents
), "bytes %u\n", bytes
);
2056 ok(!memcmp(contents
, buf
, sizeof(contents
)), "file contents mismatch\n");
2058 for (i
= -20; i
< -1; i
++)
2060 if (i
== -2) continue;
2063 iob
.Information
= -1;
2064 offset
.QuadPart
= (LONGLONG
)i
;
2065 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, contents
, sizeof(contents
), &offset
, NULL
);
2066 ok(status
== STATUS_INVALID_PARAMETER
, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i
, status
);
2067 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
2068 ok(iob
.Information
== -1, "expected -1, got %ld\n", iob
.Information
);
2071 SetFilePointer(hfile
, sizeof(contents
) - 4, NULL
, FILE_BEGIN
);
2074 iob
.Information
= -1;
2075 offset
.QuadPart
= (LONGLONG
)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2076 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, "DCBA", 4, &offset
, NULL
);
2077 ok(status
== STATUS_SUCCESS
, "NtWriteFile error %#x\n", status
);
2078 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2079 ok(iob
.Information
== 4, "expected 4, got %lu\n", iob
.Information
);
2081 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2082 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2085 iob
.Information
= -1;
2086 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), NULL
, NULL
);
2087 ok(status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", status
);
2089 ok(iob
.Status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", iob
.Status
);
2091 ok(iob
.Information
== 0, "expected 0, got %lu\n", iob
.Information
);
2093 SetFilePointer(hfile
, 0, NULL
, FILE_BEGIN
);
2096 SetLastError(0xdeadbeef);
2097 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, NULL
);
2098 ok(ret
, "ReadFile error %d\n", GetLastError());
2099 ok(bytes
== sizeof(contents
), "bytes %u\n", bytes
);
2100 ok(!memcmp(contents
, buf
, sizeof(contents
) - 4), "file contents mismatch\n");
2101 ok(!memcmp(buf
+ sizeof(contents
) - 4, "DCBA", 4), "file contents mismatch\n");
2103 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2104 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2106 SetFilePointer(hfile
, 0, NULL
, FILE_BEGIN
);
2109 SetLastError(0xdeadbeef);
2110 ret
= WriteFile(hfile
, contents
, sizeof(contents
), &bytes
, NULL
);
2111 ok(ret
, "WriteFile error %d\n", GetLastError());
2112 ok(bytes
== sizeof(contents
), "bytes %u\n", bytes
);
2114 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2115 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2118 iob
.Information
= -1;
2119 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), NULL
, NULL
);
2120 ok(status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", status
);
2122 ok(iob
.Status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", iob
.Status
);
2124 ok(iob
.Information
== 0, "expected 0, got %lu\n", iob
.Information
);
2126 for (i
= -20; i
< 0; i
++)
2128 if (i
== -2) continue;
2131 iob
.Information
= -1;
2132 offset
.QuadPart
= (LONGLONG
)i
;
2133 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
2134 ok(status
== STATUS_INVALID_PARAMETER
, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i
, status
);
2135 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
2136 ok(iob
.Information
== -1, "expected -1, got %ld\n", iob
.Information
);
2140 iob
.Information
= -1;
2141 offset
.QuadPart
= (LONGLONG
)-2 /* FILE_USE_FILE_POINTER_POSITION */;
2142 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
2143 ok(status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", status
);
2145 ok(iob
.Status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", iob
.Status
);
2147 ok(iob
.Information
== 0, "expected 0, got %lu\n", iob
.Information
);
2149 SetFilePointer(hfile
, 0, NULL
, FILE_BEGIN
);
2152 SetLastError(0xdeadbeef);
2153 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, NULL
);
2154 ok(ret
, "ReadFile error %d\n", GetLastError());
2155 ok(bytes
== sizeof(contents
), "bytes %u\n", bytes
);
2156 ok(!memcmp(contents
, buf
, sizeof(contents
)), "file contents mismatch\n");
2158 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2159 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2162 iob
.Information
= -1;
2163 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), NULL
, NULL
);
2164 ok(status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", status
);
2166 ok(iob
.Status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", iob
.Status
);
2168 ok(iob
.Information
== 0, "expected 0, got %lu\n", iob
.Information
);
2171 iob
.Information
= -1;
2172 offset
.QuadPart
= 0;
2173 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
2174 ok(status
== STATUS_SUCCESS
, "NtReadFile error %#x\n", status
);
2175 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2176 ok(iob
.Information
== sizeof(contents
), "expected sizeof(contents), got %lu\n", iob
.Information
);
2177 ok(!memcmp(contents
, buf
, sizeof(contents
)), "file contents mismatch\n");
2179 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2180 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2183 iob
.Information
= -1;
2184 offset
.QuadPart
= sizeof(contents
) - 4;
2185 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, "DCBA", 4, &offset
, NULL
);
2186 ok(status
== STATUS_SUCCESS
, "NtWriteFile error %#x\n", status
);
2187 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2188 ok(iob
.Information
== 4, "expected 4, got %lu\n", iob
.Information
);
2190 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2191 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2194 iob
.Information
= -1;
2195 offset
.QuadPart
= 0;
2196 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
2197 ok(status
== STATUS_SUCCESS
, "NtReadFile error %#x\n", status
);
2198 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2199 ok(iob
.Information
== sizeof(contents
), "expected sizeof(contents), got %lu\n", iob
.Information
);
2200 ok(!memcmp(contents
, buf
, sizeof(contents
) - 4), "file contents mismatch\n");
2201 ok(!memcmp(buf
+ sizeof(contents
) - 4, "DCBA", 4), "file contents mismatch\n");
2203 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2204 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2206 S(U(ovl
)).Offset
= sizeof(contents
) - 4;
2207 S(U(ovl
)).OffsetHigh
= 0;
2210 SetLastError(0xdeadbeef);
2211 ret
= WriteFile(hfile
, "ABCD", 4, &bytes
, &ovl
);
2212 ok(ret
, "WriteFile error %d\n", GetLastError());
2213 ok(bytes
== 4, "bytes %u\n", bytes
);
2215 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2216 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2218 S(U(ovl
)).Offset
= 0;
2219 S(U(ovl
)).OffsetHigh
= 0;
2221 ovl
.InternalHigh
= -1;
2224 SetLastError(0xdeadbeef);
2225 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, &ovl
);
2226 ok(ret
, "ReadFile error %d\n", GetLastError());
2227 ok(bytes
== sizeof(contents
), "bytes %u\n", bytes
);
2228 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2229 ok(ovl
.InternalHigh
== sizeof(contents
), "expected sizeof(contents), got %lu\n", ovl
.InternalHigh
);
2230 ok(!memcmp(contents
, buf
, sizeof(contents
) - 4), "file contents mismatch\n");
2231 ok(!memcmp(buf
+ sizeof(contents
) - 4, "ABCD", 4), "file contents mismatch\n");
2233 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2234 ok(off
== sizeof(contents
), "expected sizeof(contents), got %u\n", off
);
2238 hfile
= create_temp_file(FILE_FLAG_OVERLAPPED
);
2242 SetLastError(0xdeadbeef);
2243 ret
= ReadFile(INVALID_HANDLE_VALUE
, buf
, 0, &bytes
, NULL
);
2244 ok(!ret
, "ReadFile should fail\n");
2245 ok(GetLastError() == ERROR_INVALID_HANDLE
, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
2246 ok(bytes
== 0, "bytes %u\n", bytes
);
2248 S(U(ovl
)).Offset
= 0;
2249 S(U(ovl
)).OffsetHigh
= 0;
2251 ovl
.InternalHigh
= -1;
2254 SetLastError(0xdeadbeef);
2255 ret
= ReadFile(hfile
, buf
, 0, &bytes
, &ovl
);
2256 /* ReadFile return value depends on Windows version and testing it is not practical */
2257 if (!ret
) ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2258 ok(bytes
== 0, "bytes %u\n", bytes
);
2260 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2261 ok(ovl
.InternalHigh
== 0, "expected 0, got %lu\n", ovl
.InternalHigh
);
2264 SetLastError(0xdeadbeef);
2265 ret
= WriteFile(hfile
, contents
, sizeof(contents
), &bytes
, NULL
);
2266 ok(!ret
, "WriteFile should fail\n");
2267 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2268 ok(bytes
== 0, "bytes %u\n", bytes
);
2271 iob
.Information
= -1;
2272 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, contents
, sizeof(contents
), NULL
, NULL
);
2273 ok(status
== STATUS_INVALID_PARAMETER
, "expected STATUS_INVALID_PARAMETER, got %#x\n", status
);
2274 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
2275 ok(iob
.Information
== -1, "expected -1, got %ld\n", iob
.Information
);
2277 for (i
= -20; i
< -1; i
++)
2280 iob
.Information
= -1;
2281 offset
.QuadPart
= (LONGLONG
)i
;
2282 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, contents
, sizeof(contents
), &offset
, NULL
);
2283 ok(status
== STATUS_INVALID_PARAMETER
, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i
, status
);
2284 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
2285 ok(iob
.Information
== -1, "expected -1, got %ld\n", iob
.Information
);
2289 iob
.Information
= -1;
2290 offset
.QuadPart
= 0;
2291 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, contents
, sizeof(contents
), &offset
, NULL
);
2293 ok(status
== STATUS_PENDING
|| broken(status
== STATUS_SUCCESS
) /* see below */, "expected STATUS_PENDING, got %#x\n", status
);
2294 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2295 ok(iob
.Information
== sizeof(contents
), "expected sizeof(contents), got %lu\n", iob
.Information
);
2296 /* even fully updated XP passes this test, but it looks like some VMs
2297 * in a testbot get never updated, so overlapped IO is broken. Instead
2298 * of fighting with broken tests and adding a bunch of broken() statements
2299 * it's better to skip further tests completely.
2301 if (status
!= STATUS_PENDING
)
2304 win_skip("broken overlapped IO implementation, update your OS\n");
2309 ret
= WaitForSingleObject(hfile
, 3000);
2310 ok(ret
== WAIT_OBJECT_0
, "WaitForSingleObject error %d\n", ret
);
2312 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2313 ok(off
== 0, "expected 0, got %u\n", off
);
2316 SetLastError(0xdeadbeef);
2317 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, NULL
);
2318 ok(!ret
, "ReadFile should fail\n");
2319 ok(GetLastError() == ERROR_INVALID_PARAMETER
, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
2320 ok(bytes
== 0, "bytes %u\n", bytes
);
2323 iob
.Information
= -1;
2324 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), NULL
, NULL
);
2325 ok(status
== STATUS_INVALID_PARAMETER
, "expected STATUS_INVALID_PARAMETER, got %#x\n", status
);
2326 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
2327 ok(iob
.Information
== -1, "expected -1, got %ld\n", iob
.Information
);
2329 for (i
= -20; i
< 0; i
++)
2332 iob
.Information
= -1;
2333 offset
.QuadPart
= (LONGLONG
)i
;
2334 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
2335 ok(status
== STATUS_INVALID_PARAMETER
, "%d: expected STATUS_INVALID_PARAMETER, got %#x\n", i
, status
);
2336 ok(iob
.Status
== -1, "expected -1, got %#x\n", iob
.Status
);
2337 ok(iob
.Information
== -1, "expected -1, got %ld\n", iob
.Information
);
2340 offset
.QuadPart
= sizeof(contents
);
2341 S(U(ovl
)).Offset
= offset
.u
.LowPart
;
2342 S(U(ovl
)).OffsetHigh
= offset
.u
.HighPart
;
2344 ovl
.InternalHigh
= -1;
2347 SetLastError(0xdeadbeef);
2348 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, &ovl
);
2349 ok(!ret
, "ReadFile should fail\n");
2350 ok(GetLastError() == ERROR_IO_PENDING
|| broken(GetLastError() == ERROR_HANDLE_EOF
), "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2351 /* even fully updated XP passes this test, but it looks like some VMs
2352 * in a testbot get never updated, so overlapped IO is broken. Instead
2353 * of fighting with broken tests and adding a bunch of broken() statements
2354 * it's better to skip further tests completely.
2356 if (GetLastError() != ERROR_IO_PENDING
)
2358 win_skip("broken overlapped IO implementation, update your OS\n");
2362 ok(bytes
== 0, "bytes %u\n", bytes
);
2363 ok((NTSTATUS
)ovl
.Internal
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#lx\n", ovl
.Internal
);
2364 ok(ovl
.InternalHigh
== 0, "expected 0, got %lu\n", ovl
.InternalHigh
);
2366 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2367 ok(off
== 0, "expected 0, got %u\n", off
);
2370 ret
= GetOverlappedResult(hfile
, &ovl
, &bytes
, TRUE
);
2371 ok(!ret
, "GetOverlappedResult should report FALSE\n");
2372 ok(GetLastError() == ERROR_HANDLE_EOF
, "expected ERROR_HANDLE_EOF, got %d\n", GetLastError());
2373 ok(bytes
== 0, "expected 0, read %u\n", bytes
);
2374 ok((NTSTATUS
)ovl
.Internal
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#lx\n", ovl
.Internal
);
2375 ok(ovl
.InternalHigh
== 0, "expected 0, got %lu\n", ovl
.InternalHigh
);
2377 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2378 ok(off
== 0, "expected 0, got %u\n", off
);
2381 iob
.Information
= -1;
2382 offset
.QuadPart
= sizeof(contents
);
2383 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
2384 ok(status
== STATUS_PENDING
, "expected STATUS_PENDING, got %#x\n", status
);
2385 ok(iob
.Status
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#x\n", iob
.Status
);
2386 ok(iob
.Information
== 0, "expected 0, got %lu\n", iob
.Information
);
2388 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2389 ok(off
== 0, "expected 0, got %u\n", off
);
2391 S(U(ovl
)).Offset
= offset
.u
.LowPart
;
2392 S(U(ovl
)).OffsetHigh
= offset
.u
.HighPart
;
2393 ovl
.Internal
= iob
.Status
;
2394 ovl
.InternalHigh
= iob
.Information
;
2397 ret
= GetOverlappedResult(hfile
, &ovl
, &bytes
, TRUE
);
2398 ok(!ret
, "GetOverlappedResult should report FALSE\n");
2399 ok(GetLastError() == ERROR_HANDLE_EOF
, "expected ERROR_HANDLE_EOF, got %d\n", GetLastError());
2400 ok(bytes
== 0, "expected 0, read %u\n", bytes
);
2401 ok((NTSTATUS
)ovl
.Internal
== STATUS_END_OF_FILE
, "expected STATUS_END_OF_FILE, got %#lx\n", ovl
.Internal
);
2402 ok(ovl
.InternalHigh
== 0, "expected 0, got %lu\n", ovl
.InternalHigh
);
2404 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2405 ok(off
== 0, "expected 0, got %u\n", off
);
2407 S(U(ovl
)).Offset
= 0;
2408 S(U(ovl
)).OffsetHigh
= 0;
2410 ovl
.InternalHigh
= -1;
2413 SetLastError(0xdeadbeef);
2414 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, &ovl
);
2415 ok(!ret
, "ReadFile should fail\n");
2416 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2417 ok(bytes
== 0, "bytes %u\n", bytes
);
2418 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2419 ok(ovl
.InternalHigh
== sizeof(contents
), "expected sizeof(contents), got %lu\n", ovl
.InternalHigh
);
2421 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2422 ok(off
== 0, "expected 0, got %u\n", off
);
2425 ret
= GetOverlappedResult(hfile
, &ovl
, &bytes
, TRUE
);
2426 ok(ret
, "GetOverlappedResult error %d\n", GetLastError());
2427 ok(bytes
== sizeof(contents
), "bytes %u\n", bytes
);
2428 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2429 ok(ovl
.InternalHigh
== sizeof(contents
), "expected sizeof(contents), got %lu\n", ovl
.InternalHigh
);
2430 ok(!memcmp(contents
, buf
, sizeof(contents
)), "file contents mismatch\n");
2432 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2433 ok(off
== 0, "expected 0, got %u\n", off
);
2435 SetFilePointer(hfile
, sizeof(contents
) - 4, NULL
, FILE_BEGIN
);
2436 SetEndOfFile(hfile
);
2437 SetFilePointer(hfile
, 0, NULL
, FILE_BEGIN
);
2440 iob
.Information
= -1;
2441 offset
.QuadPart
= (LONGLONG
)-1 /* FILE_WRITE_TO_END_OF_FILE */;
2442 status
= pNtWriteFile(hfile
, 0, NULL
, NULL
, &iob
, "DCBA", 4, &offset
, NULL
);
2443 ok(status
== STATUS_PENDING
|| broken(status
== STATUS_SUCCESS
) /* before Vista */, "expected STATUS_PENDING, got %#x\n", status
);
2444 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2445 ok(iob
.Information
== 4, "expected 4, got %lu\n", iob
.Information
);
2447 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2448 ok(off
== 0, "expected 0, got %u\n", off
);
2450 ret
= WaitForSingleObject(hfile
, 3000);
2451 ok(ret
== WAIT_OBJECT_0
, "WaitForSingleObject error %d\n", ret
);
2453 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2454 ok(off
== 0, "expected 0, got %u\n", off
);
2457 iob
.Information
= -1;
2458 offset
.QuadPart
= 0;
2459 status
= pNtReadFile(hfile
, 0, NULL
, NULL
, &iob
, buf
, sizeof(buf
), &offset
, NULL
);
2460 ok(status
== STATUS_PENDING
, "expected STATUS_PENDING, got %#x\n", status
);
2461 ok(iob
.Status
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#x\n", iob
.Status
);
2462 ok(iob
.Information
== sizeof(contents
), "expected sizeof(contents), got %lu\n", iob
.Information
);
2464 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2465 ok(off
== 0, "expected 0, got %u\n", off
);
2467 ret
= WaitForSingleObject(hfile
, 3000);
2468 ok(ret
== WAIT_OBJECT_0
, "WaitForSingleObject error %d\n", ret
);
2469 ok(!memcmp(contents
, buf
, sizeof(contents
) - 4), "file contents mismatch\n");
2470 ok(!memcmp(buf
+ sizeof(contents
) - 4, "DCBA", 4), "file contents mismatch\n");
2472 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2473 ok(off
== 0, "expected 0, got %u\n", off
);
2475 S(U(ovl
)).Offset
= sizeof(contents
) - 4;
2476 S(U(ovl
)).OffsetHigh
= 0;
2478 ovl
.InternalHigh
= -1;
2481 SetLastError(0xdeadbeef);
2482 ret
= WriteFile(hfile
, "ABCD", 4, &bytes
, &ovl
);
2483 ok(!ret
|| broken(ret
) /* before Vista */, "WriteFile should fail\n");
2484 ok(GetLastError() == ERROR_IO_PENDING
|| broken(GetLastError() == 0xdeadbeef) /* before Vista */, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2485 ok(bytes
== 0 || broken(bytes
== 4) /* before Vista */, "bytes %u\n", bytes
);
2486 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2487 ok(ovl
.InternalHigh
== 4, "expected 4, got %lu\n", ovl
.InternalHigh
);
2489 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2490 ok(off
== 0, "expected 0, got %u\n", off
);
2493 ret
= GetOverlappedResult(hfile
, &ovl
, &bytes
, TRUE
);
2494 ok(ret
, "GetOverlappedResult error %d\n", GetLastError());
2495 ok(bytes
== 4, "bytes %u\n", bytes
);
2496 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2497 ok(ovl
.InternalHigh
== 4, "expected 4, got %lu\n", ovl
.InternalHigh
);
2499 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2500 ok(off
== 0, "expected 0, got %u\n", off
);
2502 S(U(ovl
)).Offset
= 0;
2503 S(U(ovl
)).OffsetHigh
= 0;
2505 ovl
.InternalHigh
= -1;
2508 SetLastError(0xdeadbeef);
2509 ret
= ReadFile(hfile
, buf
, sizeof(buf
), &bytes
, &ovl
);
2510 ok(!ret
, "ReadFile should fail\n");
2511 ok(GetLastError() == ERROR_IO_PENDING
, "expected ERROR_IO_PENDING, got %d\n", GetLastError());
2512 ok(bytes
== 0, "bytes %u\n", bytes
);
2513 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2514 ok(ovl
.InternalHigh
== sizeof(contents
), "expected sizeof(contents), got %lu\n", ovl
.InternalHigh
);
2516 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2517 ok(off
== 0, "expected 0, got %u\n", off
);
2520 ret
= GetOverlappedResult(hfile
, &ovl
, &bytes
, TRUE
);
2521 ok(ret
, "GetOverlappedResult error %d\n", GetLastError());
2522 ok(bytes
== sizeof(contents
), "bytes %u\n", bytes
);
2523 ok((NTSTATUS
)ovl
.Internal
== STATUS_SUCCESS
, "expected STATUS_SUCCESS, got %#lx\n", ovl
.Internal
);
2524 ok(ovl
.InternalHigh
== sizeof(contents
), "expected sizeof(contents), got %lu\n", ovl
.InternalHigh
);
2525 ok(!memcmp(contents
, buf
, sizeof(contents
) - 4), "file contents mismatch\n");
2526 ok(!memcmp(buf
+ sizeof(contents
) - 4, "ABCD", 4), "file contents mismatch\n");
2528 off
= SetFilePointer(hfile
, 0, NULL
, FILE_CURRENT
);
2529 ok(off
== 0, "expected 0, got %u\n", off
);
2536 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
2537 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
2540 skip("not running on NT, skipping test\n");
2544 pGetVolumePathNameW
= (void *)GetProcAddress(hkernel32
, "GetVolumePathNameW");
2545 pGetSystemWow64DirectoryW
= (void *)GetProcAddress(hkernel32
, "GetSystemWow64DirectoryW");
2547 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
2548 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
2549 pRtlDosPathNameToNtPathName_U
= (void *)GetProcAddress(hntdll
, "RtlDosPathNameToNtPathName_U");
2550 pRtlWow64EnableFsRedirectionEx
= (void *)GetProcAddress(hntdll
, "RtlWow64EnableFsRedirectionEx");
2551 pNtCreateMailslotFile
= (void *)GetProcAddress(hntdll
, "NtCreateMailslotFile");
2552 pNtCreateFile
= (void *)GetProcAddress(hntdll
, "NtCreateFile");
2553 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
2554 pNtDeleteFile
= (void *)GetProcAddress(hntdll
, "NtDeleteFile");
2555 pNtReadFile
= (void *)GetProcAddress(hntdll
, "NtReadFile");
2556 pNtWriteFile
= (void *)GetProcAddress(hntdll
, "NtWriteFile");
2557 pNtCancelIoFile
= (void *)GetProcAddress(hntdll
, "NtCancelIoFile");
2558 pNtCancelIoFileEx
= (void *)GetProcAddress(hntdll
, "NtCancelIoFileEx");
2559 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
2560 pNtCreateIoCompletion
= (void *)GetProcAddress(hntdll
, "NtCreateIoCompletion");
2561 pNtOpenIoCompletion
= (void *)GetProcAddress(hntdll
, "NtOpenIoCompletion");
2562 pNtQueryIoCompletion
= (void *)GetProcAddress(hntdll
, "NtQueryIoCompletion");
2563 pNtRemoveIoCompletion
= (void *)GetProcAddress(hntdll
, "NtRemoveIoCompletion");
2564 pNtSetIoCompletion
= (void *)GetProcAddress(hntdll
, "NtSetIoCompletion");
2565 pNtSetInformationFile
= (void *)GetProcAddress(hntdll
, "NtSetInformationFile");
2566 pNtQueryInformationFile
= (void *)GetProcAddress(hntdll
, "NtQueryInformationFile");
2567 pNtQueryDirectoryFile
= (void *)GetProcAddress(hntdll
, "NtQueryDirectoryFile");
2568 pNtQueryVolumeInformationFile
= (void *)GetProcAddress(hntdll
, "NtQueryVolumeInformationFile");
2571 test_NtCreateFile();
2578 test_iocompletion();
2579 test_file_basic_information();
2580 test_file_all_information();
2581 test_file_both_information();
2582 test_file_name_information();
2583 test_file_all_name_information();
2584 test_file_disposition_information();
2585 test_query_volume_information_file();
2586 test_query_attribute_information_file();