[NTDLL_WINETEST] Partial sync with Wine Staging 1.9.14. CORE-11368 holds some remaini...
[reactos.git] / rostests / winetests / ntdll / file.c
1 /* Unit test suite for Ntdll file functions
2 *
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
5 * Copyright 2008 Jeff Zaroyko
6 * Copyright 2011 Dmitry Timoshkov
7 *
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.
12 *
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.
17 *
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
21 *
22 * NOTES
23 * We use function pointers here as there is no import library for NTDLL on
24 * windows.
25 */
26
27 #include <stdio.h>
28 #include <stdarg.h>
29
30 #include "ntstatus.h"
31 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
32 * definition errors when we get to winnt.h
33 */
34 #define WIN32_NO_STATUS
35
36 #include "wine/test.h"
37 #include "wine/winternl.h"
38 #include "winuser.h"
39 #include "wine/winioctl.h"
40
41 /* FIXME */
42 typedef struct _REPARSE_DATA_BUFFER {
43 ULONG ReparseTag;
44 USHORT ReparseDataLength;
45 USHORT Reserved;
46 _ANONYMOUS_UNION union {
47 struct {
48 USHORT SubstituteNameOffset;
49 USHORT SubstituteNameLength;
50 USHORT PrintNameOffset;
51 USHORT PrintNameLength;
52 ULONG Flags;
53 WCHAR PathBuffer[1];
54 } SymbolicLinkReparseBuffer;
55 struct {
56 USHORT SubstituteNameOffset;
57 USHORT SubstituteNameLength;
58 USHORT PrintNameOffset;
59 USHORT PrintNameLength;
60 WCHAR PathBuffer[1];
61 } MountPointReparseBuffer;
62 struct {
63 UCHAR DataBuffer[1];
64 } GenericReparseBuffer;
65 } DUMMYUNIONNAME;
66 } REPARSE_DATA_BUFFER, *PREPARSE_DATA_BUFFER;
67
68 #ifndef IO_COMPLETION_ALL_ACCESS
69 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
70 #endif
71
72 static BOOL (WINAPI * pGetVolumePathNameW)(LPCWSTR, LPWSTR, DWORD);
73 static UINT (WINAPI *pGetSystemWow64DirectoryW)( LPWSTR, UINT );
74
75 static VOID (WINAPI *pRtlFreeUnicodeString)( PUNICODE_STRING );
76 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
77 static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)( LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR* );
78 static NTSTATUS (WINAPI *pRtlWow64EnableFsRedirectionEx)( ULONG, ULONG * );
79
80 static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
81 ULONG, ULONG, ULONG, PLARGE_INTEGER );
82 static NTSTATUS (WINAPI *pNtCreateFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,PLARGE_INTEGER,ULONG,ULONG,ULONG,ULONG,PVOID,ULONG);
83 static NTSTATUS (WINAPI *pNtOpenFile)(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,ULONG,ULONG);
84 static NTSTATUS (WINAPI *pNtDeleteFile)(POBJECT_ATTRIBUTES ObjectAttributes);
85 static NTSTATUS (WINAPI *pNtReadFile)(HANDLE hFile, HANDLE hEvent,
86 PIO_APC_ROUTINE apc, void* apc_user,
87 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
88 PLARGE_INTEGER offset, PULONG key);
89 static NTSTATUS (WINAPI *pNtWriteFile)(HANDLE hFile, HANDLE hEvent,
90 PIO_APC_ROUTINE apc, void* apc_user,
91 PIO_STATUS_BLOCK io_status,
92 const void* buffer, ULONG length,
93 PLARGE_INTEGER offset, PULONG key);
94 static NTSTATUS (WINAPI *pNtCancelIoFile)(HANDLE hFile, PIO_STATUS_BLOCK io_status);
95 static NTSTATUS (WINAPI *pNtCancelIoFileEx)(HANDLE hFile, PIO_STATUS_BLOCK iosb, PIO_STATUS_BLOCK io_status);
96 static NTSTATUS (WINAPI *pNtClose)( PHANDLE );
97
98 static NTSTATUS (WINAPI *pNtCreateIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG);
99 static NTSTATUS (WINAPI *pNtOpenIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
100 static NTSTATUS (WINAPI *pNtQueryIoCompletion)(HANDLE, IO_COMPLETION_INFORMATION_CLASS, PVOID, ULONG, PULONG);
101 static NTSTATUS (WINAPI *pNtRemoveIoCompletion)(HANDLE, PULONG_PTR, PULONG_PTR, PIO_STATUS_BLOCK, PLARGE_INTEGER);
102 static NTSTATUS (WINAPI *pNtSetIoCompletion)(HANDLE, ULONG_PTR, ULONG_PTR, NTSTATUS, SIZE_T);
103 static NTSTATUS (WINAPI *pNtSetInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
104 static NTSTATUS (WINAPI *pNtQueryInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
105 static NTSTATUS (WINAPI *pNtQueryDirectoryFile)(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,
106 PVOID,ULONG,FILE_INFORMATION_CLASS,BOOLEAN,PUNICODE_STRING,BOOLEAN);
107 static NTSTATUS (WINAPI *pNtQueryVolumeInformationFile)(HANDLE,PIO_STATUS_BLOCK,PVOID,ULONG,FS_INFORMATION_CLASS);
108 static NTSTATUS (WINAPI *pNtQueryFullAttributesFile)(const OBJECT_ATTRIBUTES*, FILE_NETWORK_OPEN_INFORMATION*);
109 static NTSTATUS (WINAPI *pNtQueryEaFile)(HANDLE,PIO_STATUS_BLOCK,PVOID,ULONG,BOOLEAN,PVOID,ULONG,PULONG,BOOLEAN);
110
111 static inline BOOL is_signaled( HANDLE obj )
112 {
113 return WaitForSingleObject( obj, 0 ) == WAIT_OBJECT_0;
114 }
115
116 static const char* debugstr_longlong(ULONGLONG ll)
117 {
118 static char str[17];
119 if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
120 sprintf(str, "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll);
121 else
122 sprintf(str, "%lx", (unsigned long)ll);
123 return str;
124 }
125
126 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
127 #define TEST_BUF_LEN 3
128
129 static BOOL create_pipe( HANDLE *read, HANDLE *write, ULONG flags, ULONG size )
130 {
131 *read = CreateNamedPipeA(PIPENAME, PIPE_ACCESS_INBOUND | flags, PIPE_TYPE_BYTE | PIPE_WAIT,
132 1, size, size, NMPWAIT_USE_DEFAULT_WAIT, NULL);
133 ok(*read != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
134
135 *write = CreateFileA(PIPENAME, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
136 ok(*write != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError());
137
138 return TRUE;
139 }
140
141 static HANDLE create_temp_file( ULONG flags )
142 {
143 char path[MAX_PATH], buffer[MAX_PATH];
144 HANDLE handle;
145
146 GetTempPathA( MAX_PATH, path );
147 GetTempFileNameA( path, "foo", 0, buffer );
148 handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
149 flags | FILE_FLAG_DELETE_ON_CLOSE, 0);
150 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
151 return (handle == INVALID_HANDLE_VALUE) ? 0 : handle;
152 }
153
154 #define CVALUE_FIRST 0xfffabbcc
155 #define CKEY_FIRST 0x1030341
156 #define CKEY_SECOND 0x132E46
157
158 static ULONG_PTR completionKey;
159 static IO_STATUS_BLOCK ioSb;
160 static ULONG_PTR completionValue;
161
162 static ULONG get_pending_msgs(HANDLE h)
163 {
164 NTSTATUS res;
165 ULONG a, req;
166
167 res = pNtQueryIoCompletion( h, IoCompletionBasicInformation, &a, sizeof(a), &req );
168 ok( res == STATUS_SUCCESS, "NtQueryIoCompletion failed: %x\n", res );
169 if (res != STATUS_SUCCESS) return -1;
170 ok( req == sizeof(a), "Unexpected response size: %x\n", req );
171 return a;
172 }
173
174 static BOOL get_msg(HANDLE h)
175 {
176 LARGE_INTEGER timeout = {{-10000000*3}};
177 DWORD res = pNtRemoveIoCompletion( h, &completionKey, &completionValue, &ioSb, &timeout);
178 ok( res == STATUS_SUCCESS, "NtRemoveIoCompletion failed: %x\n", res );
179 if (res != STATUS_SUCCESS)
180 {
181 completionKey = completionValue = 0;
182 memset(&ioSb, 0, sizeof(ioSb));
183 return FALSE;
184 }
185 return TRUE;
186 }
187
188
189 static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved )
190 {
191 int *count = arg;
192
193 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
194 iosb, U(*iosb).Status, iosb->Information );
195 (*count)++;
196 ok( !reserved, "reserved is not 0: %x\n", reserved );
197 }
198
199 static void create_file_test(void)
200 {
201 static const WCHAR systemrootW[] = {'\\','S','y','s','t','e','m','R','o','o','t',
202 '\\','f','a','i','l','i','n','g',0};
203 static const WCHAR questionmarkInvalidNameW[] = {'a','f','i','l','e','?',0};
204 static const WCHAR pipeInvalidNameW[] = {'a','|','b',0};
205 static const WCHAR pathInvalidNtW[] = {'\\','\\','?','\\',0};
206 static const WCHAR pathInvalidNt2W[] = {'\\','?','?','\\',0};
207 static const WCHAR pathInvalidDosW[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\',0};
208 static const char testdata[] = "Hello World";
209 FILE_NETWORK_OPEN_INFORMATION info;
210 NTSTATUS status;
211 HANDLE dir, file;
212 WCHAR path[MAX_PATH];
213 OBJECT_ATTRIBUTES attr;
214 IO_STATUS_BLOCK io;
215 UNICODE_STRING nameW;
216 LARGE_INTEGER offset;
217 char buf[32];
218 DWORD ret;
219
220 GetCurrentDirectoryW( MAX_PATH, path );
221 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
222 attr.Length = sizeof(attr);
223 attr.RootDirectory = 0;
224 attr.ObjectName = &nameW;
225 attr.Attributes = OBJ_CASE_INSENSITIVE;
226 attr.SecurityDescriptor = NULL;
227 attr.SecurityQualityOfService = NULL;
228
229 /* try various open modes and options on directories */
230 status = pNtCreateFile( &dir, GENERIC_READ|GENERIC_WRITE, &attr, &io, NULL, 0,
231 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, FILE_DIRECTORY_FILE, NULL, 0 );
232 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
233
234 U(io).Status = 0xdeadbeef;
235 offset.QuadPart = 0;
236 status = pNtReadFile( dir, NULL, NULL, NULL, &io, buf, sizeof(buf), &offset, NULL );
237 ok( status == STATUS_INVALID_DEVICE_REQUEST || status == STATUS_PENDING, "NtReadFile error %08x\n", status );
238 if (status == STATUS_PENDING)
239 {
240 ret = WaitForSingleObject( dir, 1000 );
241 ok( ret == WAIT_OBJECT_0, "WaitForSingleObject error %u\n", ret );
242 ok( U(io).Status == STATUS_INVALID_DEVICE_REQUEST,
243 "expected STATUS_INVALID_DEVICE_REQUEST, got %08x\n", U(io).Status );
244 }
245
246 U(io).Status = 0xdeadbeef;
247 offset.QuadPart = 0;
248 status = pNtWriteFile( dir, NULL, NULL, NULL, &io, testdata, sizeof(testdata), &offset, NULL);
249 todo_wine
250 ok( status == STATUS_INVALID_DEVICE_REQUEST || status == STATUS_PENDING, "NtWriteFile error %08x\n", status );
251 if (status == STATUS_PENDING)
252 {
253 ret = WaitForSingleObject( dir, 1000 );
254 ok( ret == WAIT_OBJECT_0, "WaitForSingleObject error %u\n", ret );
255 ok( U(io).Status == STATUS_INVALID_DEVICE_REQUEST,
256 "expected STATUS_INVALID_DEVICE_REQUEST, got %08x\n", U(io).Status );
257 }
258
259 CloseHandle( dir );
260
261 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
262 FILE_CREATE, FILE_DIRECTORY_FILE, NULL, 0 );
263 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
264 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
265
266 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
267 FILE_OPEN_IF, FILE_DIRECTORY_FILE, NULL, 0 );
268 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
269 CloseHandle( dir );
270
271 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
272 FILE_SUPERSEDE, FILE_DIRECTORY_FILE, NULL, 0 );
273 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
274
275 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
276 FILE_OVERWRITE, FILE_DIRECTORY_FILE, NULL, 0 );
277 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
278
279 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
280 FILE_OVERWRITE_IF, FILE_DIRECTORY_FILE, NULL, 0 );
281 ok( status == STATUS_INVALID_PARAMETER, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
282
283 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
284 FILE_OPEN, 0, NULL, 0 );
285 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
286 CloseHandle( dir );
287
288 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
289 FILE_CREATE, 0, NULL, 0 );
290 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
291 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
292
293 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
294 FILE_OPEN_IF, 0, NULL, 0 );
295 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
296 CloseHandle( dir );
297
298 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
299 FILE_SUPERSEDE, 0, NULL, 0 );
300 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
301 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
302
303 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
304 FILE_OVERWRITE, 0, NULL, 0 );
305 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
306 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
307
308 status = pNtCreateFile( &dir, GENERIC_READ, &attr, &io, NULL, 0, FILE_SHARE_READ|FILE_SHARE_WRITE,
309 FILE_OVERWRITE_IF, 0, NULL, 0 );
310 ok( status == STATUS_OBJECT_NAME_COLLISION || status == STATUS_ACCESS_DENIED,
311 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
312
313 pRtlFreeUnicodeString( &nameW );
314
315 pRtlInitUnicodeString( &nameW, systemrootW );
316 attr.Length = sizeof(attr);
317 attr.RootDirectory = NULL;
318 attr.ObjectName = &nameW;
319 attr.Attributes = OBJ_CASE_INSENSITIVE;
320 attr.SecurityDescriptor = NULL;
321 attr.SecurityQualityOfService = NULL;
322 dir = NULL;
323 status = pNtCreateFile( &dir, FILE_APPEND_DATA, &attr, &io, NULL, FILE_ATTRIBUTE_NORMAL, 0,
324 FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
325 todo_wine
326 ok( status == STATUS_INVALID_PARAMETER,
327 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
328
329 /* Invalid chars in file/dirnames */
330 pRtlDosPathNameToNtPathName_U(questionmarkInvalidNameW, &nameW, NULL, NULL);
331 attr.ObjectName = &nameW;
332 status = pNtCreateFile(&dir, GENERIC_READ|SYNCHRONIZE, &attr, &io, NULL, 0,
333 FILE_SHARE_READ, FILE_CREATE,
334 FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
335 ok(status == STATUS_OBJECT_NAME_INVALID,
336 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
337
338 status = pNtCreateFile(&file, GENERIC_WRITE|SYNCHRONIZE, &attr, &io, NULL, 0,
339 0, FILE_CREATE,
340 FILE_NON_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
341 ok(status == STATUS_OBJECT_NAME_INVALID,
342 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
343 pRtlFreeUnicodeString(&nameW);
344
345 pRtlDosPathNameToNtPathName_U(pipeInvalidNameW, &nameW, NULL, NULL);
346 attr.ObjectName = &nameW;
347 status = pNtCreateFile(&dir, GENERIC_READ|SYNCHRONIZE, &attr, &io, NULL, 0,
348 FILE_SHARE_READ, FILE_CREATE,
349 FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
350 ok(status == STATUS_OBJECT_NAME_INVALID,
351 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
352
353 status = pNtCreateFile(&file, GENERIC_WRITE|SYNCHRONIZE, &attr, &io, NULL, 0,
354 0, FILE_CREATE,
355 FILE_NON_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
356 ok(status == STATUS_OBJECT_NAME_INVALID,
357 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status);
358 pRtlFreeUnicodeString(&nameW);
359
360 pRtlInitUnicodeString( &nameW, pathInvalidNtW );
361 status = pNtCreateFile( &dir, GENERIC_READ|SYNCHRONIZE, &attr, &io, NULL, 0,
362 FILE_SHARE_READ, FILE_CREATE,
363 FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
364 ok( status == STATUS_OBJECT_NAME_INVALID,
365 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
366
367 status = pNtQueryFullAttributesFile( &attr, &info );
368 todo_wine ok( status == STATUS_OBJECT_NAME_INVALID,
369 "query %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
370
371 pRtlInitUnicodeString( &nameW, pathInvalidNt2W );
372 status = pNtCreateFile( &dir, GENERIC_READ|SYNCHRONIZE, &attr, &io, NULL, 0,
373 FILE_SHARE_READ, FILE_CREATE,
374 FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
375 ok( status == STATUS_OBJECT_NAME_INVALID,
376 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
377
378 status = pNtQueryFullAttributesFile( &attr, &info );
379 ok( status == STATUS_OBJECT_NAME_INVALID,
380 "query %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
381
382 pRtlInitUnicodeString( &nameW, pathInvalidDosW );
383 status = pNtCreateFile( &dir, GENERIC_READ|SYNCHRONIZE, &attr, &io, NULL, 0,
384 FILE_SHARE_READ, FILE_CREATE,
385 FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 );
386 ok( status == STATUS_OBJECT_NAME_INVALID,
387 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
388
389 status = pNtQueryFullAttributesFile( &attr, &info );
390 ok( status == STATUS_OBJECT_NAME_INVALID,
391 "query %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
392 }
393
394 static void open_file_test(void)
395 {
396 static const char testdata[] = "Hello World";
397 static WCHAR fooW[] = {'f','o','o',0};
398 NTSTATUS status;
399 HANDLE dir, root, handle, file;
400 WCHAR path[MAX_PATH], tmpfile[MAX_PATH];
401 BYTE data[1024];
402 OBJECT_ATTRIBUTES attr;
403 IO_STATUS_BLOCK io;
404 UNICODE_STRING nameW;
405 UINT i, len;
406 BOOL ret, restart = TRUE;
407 DWORD numbytes;
408
409 len = GetWindowsDirectoryW( path, MAX_PATH );
410 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
411 attr.Length = sizeof(attr);
412 attr.RootDirectory = 0;
413 attr.ObjectName = &nameW;
414 attr.Attributes = OBJ_CASE_INSENSITIVE;
415 attr.SecurityDescriptor = NULL;
416 attr.SecurityQualityOfService = NULL;
417 status = pNtOpenFile( &dir, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
418 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE|FILE_SYNCHRONOUS_IO_NONALERT );
419 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
420 pRtlFreeUnicodeString( &nameW );
421
422 path[3] = 0; /* root of the drive */
423 pRtlDosPathNameToNtPathName_U( path, &nameW, NULL, NULL );
424 status = pNtOpenFile( &root, GENERIC_READ, &attr, &io,
425 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
426 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
427 pRtlFreeUnicodeString( &nameW );
428
429 /* test opening system dir with RootDirectory set to windows dir */
430 GetSystemDirectoryW( path, MAX_PATH );
431 while (path[len] == '\\') len++;
432 nameW.Buffer = path + len;
433 nameW.Length = lstrlenW(path + len) * sizeof(WCHAR);
434 attr.RootDirectory = dir;
435 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
436 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
437 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
438 CloseHandle( handle );
439
440 /* try uppercase name */
441 for (i = len; path[i]; i++) if (path[i] >= 'a' && path[i] <= 'z') path[i] -= 'a' - 'A';
442 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
443 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
444 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
445 CloseHandle( handle );
446
447 /* try with leading backslash */
448 nameW.Buffer--;
449 nameW.Length += sizeof(WCHAR);
450 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
451 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
452 ok( status == STATUS_INVALID_PARAMETER ||
453 status == STATUS_OBJECT_NAME_INVALID ||
454 status == STATUS_OBJECT_PATH_SYNTAX_BAD,
455 "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
456 if (!status) CloseHandle( handle );
457
458 /* try with empty name */
459 nameW.Length = 0;
460 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
461 FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_DIRECTORY_FILE );
462 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
463 CloseHandle( handle );
464
465 /* try open by file id */
466
467 while (!pNtQueryDirectoryFile( dir, NULL, NULL, NULL, &io, data, sizeof(data),
468 FileIdBothDirectoryInformation, TRUE, NULL, restart ))
469 {
470 FILE_ID_BOTH_DIRECTORY_INFORMATION *info = (FILE_ID_BOTH_DIRECTORY_INFORMATION *)data;
471
472 restart = FALSE;
473
474 if (!info->FileId.QuadPart) continue;
475
476 nameW.Buffer = (WCHAR *)&info->FileId;
477 nameW.Length = sizeof(info->FileId);
478 info->FileName[info->FileNameLength/sizeof(WCHAR)] = 0;
479 attr.RootDirectory = dir;
480 /* We skip 'open' files by not specifying FILE_SHARE_WRITE */
481 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
482 FILE_SHARE_READ,
483 FILE_OPEN_BY_FILE_ID |
484 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
485 ok( status == STATUS_SUCCESS || status == STATUS_ACCESS_DENIED || status == STATUS_NOT_IMPLEMENTED || status == STATUS_SHARING_VIOLATION,
486 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
487 if (status == STATUS_NOT_IMPLEMENTED)
488 {
489 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
490 break;
491 }
492 if (status == STATUS_SHARING_VIOLATION)
493 trace( "%s is currently open\n", wine_dbgstr_w(info->FileName) );
494 if (!status)
495 {
496 BYTE buf[sizeof(FILE_ALL_INFORMATION) + MAX_PATH * sizeof(WCHAR)];
497
498 if (!pNtQueryInformationFile( handle, &io, buf, sizeof(buf), FileAllInformation ))
499 {
500 FILE_ALL_INFORMATION *fai = (FILE_ALL_INFORMATION *)buf;
501
502 /* check that it's the same file/directory */
503
504 /* don't check the size for directories */
505 if (!(info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY))
506 ok( info->EndOfFile.QuadPart == fai->StandardInformation.EndOfFile.QuadPart,
507 "mismatched file size for %s\n", wine_dbgstr_w(info->FileName));
508
509 ok( info->CreationTime.QuadPart == fai->BasicInformation.CreationTime.QuadPart,
510 "mismatched creation time for %s\n", wine_dbgstr_w(info->FileName));
511 }
512 CloseHandle( handle );
513
514 /* try same thing from drive root */
515 attr.RootDirectory = root;
516 status = pNtOpenFile( &handle, GENERIC_READ, &attr, &io,
517 FILE_SHARE_READ|FILE_SHARE_WRITE,
518 FILE_OPEN_BY_FILE_ID |
519 ((info->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? FILE_DIRECTORY_FILE : 0) );
520 ok( status == STATUS_SUCCESS || status == STATUS_NOT_IMPLEMENTED,
521 "open %s failed %x\n", wine_dbgstr_w(info->FileName), status );
522 if (!status) CloseHandle( handle );
523 }
524 }
525
526 CloseHandle( dir );
527 CloseHandle( root );
528
529 GetTempPathW( MAX_PATH, path );
530 GetTempFileNameW( path, fooW, 0, tmpfile );
531 pRtlDosPathNameToNtPathName_U( tmpfile, &nameW, NULL, NULL );
532
533 file = CreateFileW( tmpfile, FILE_WRITE_DATA, 0, NULL, CREATE_ALWAYS, 0, 0 );
534 ok( file != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError() );
535 numbytes = 0xdeadbeef;
536 ret = WriteFile( file, testdata, sizeof(testdata) - 1, &numbytes, NULL );
537 ok( ret, "WriteFile failed with error %u\n", GetLastError() );
538 ok( numbytes == sizeof(testdata) - 1, "failed to write all data\n" );
539 CloseHandle( file );
540
541 attr.Length = sizeof(attr);
542 attr.RootDirectory = 0;
543 attr.ObjectName = &nameW;
544 attr.Attributes = OBJ_CASE_INSENSITIVE;
545 attr.SecurityDescriptor = NULL;
546 attr.SecurityQualityOfService = NULL;
547 status = pNtOpenFile( &file, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
548 FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT );
549 ok( !status, "open %s failed %x\n", wine_dbgstr_w(nameW.Buffer), status );
550 pRtlFreeUnicodeString( &nameW );
551
552 numbytes = 0xdeadbeef;
553 memset( data, 0, sizeof(data) );
554 ret = ReadFile( file, data, sizeof(data), &numbytes, NULL );
555 ok( ret, "ReadFile failed with error %u\n", GetLastError() );
556 ok( numbytes == sizeof(testdata) - 1, "failed to read all data\n" );
557 ok( !memcmp( data, testdata, sizeof(testdata) - 1 ), "testdata doesn't match\n" );
558
559 nameW.Length = sizeof(fooW) - sizeof(WCHAR);
560 nameW.Buffer = fooW;
561 attr.RootDirectory = file;
562 attr.ObjectName = &nameW;
563 status = pNtOpenFile( &root, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
564 FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT );
565 ok( status == STATUS_OBJECT_PATH_NOT_FOUND,
566 "expected STATUS_OBJECT_PATH_NOT_FOUND, got %08x\n", status );
567
568 nameW.Length = 0;
569 nameW.Buffer = NULL;
570 attr.RootDirectory = file;
571 attr.ObjectName = &nameW;
572 status = pNtOpenFile( &root, SYNCHRONIZE|FILE_LIST_DIRECTORY, &attr, &io,
573 FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT );
574 ok( !status, "open %s failed %x\n", wine_dbgstr_w(tmpfile), status );
575
576 numbytes = SetFilePointer( file, 0, 0, FILE_CURRENT );
577 ok( numbytes == sizeof(testdata) - 1, "SetFilePointer returned %u\n", numbytes );
578 numbytes = SetFilePointer( root, 0, 0, FILE_CURRENT );
579 ok( numbytes == 0, "SetFilePointer returned %u\n", numbytes );
580
581 numbytes = 0xdeadbeef;
582 memset( data, 0, sizeof(data) );
583 ret = ReadFile( root, data, sizeof(data), &numbytes, NULL );
584 ok( ret, "ReadFile failed with error %u\n", GetLastError() );
585 ok( numbytes == sizeof(testdata) - 1, "failed to read all data\n" );
586 ok( !memcmp( data, testdata, sizeof(testdata) - 1 ), "testdata doesn't match\n" );
587
588 numbytes = SetFilePointer( file, 0, 0, FILE_CURRENT );
589 ok( numbytes == sizeof(testdata) - 1, "SetFilePointer returned %u\n", numbytes );
590 numbytes = SetFilePointer( root, 0, 0, FILE_CURRENT );
591 ok( numbytes == sizeof(testdata) - 1, "SetFilePointer returned %u\n", numbytes );
592
593 CloseHandle( file );
594 CloseHandle( root );
595 DeleteFileW( tmpfile );
596 }
597
598 static void delete_file_test(void)
599 {
600 NTSTATUS ret;
601 OBJECT_ATTRIBUTES attr;
602 UNICODE_STRING nameW;
603 WCHAR pathW[MAX_PATH];
604 WCHAR pathsubW[MAX_PATH];
605 static const WCHAR testdirW[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
606 static const WCHAR subdirW[] = {'\\','s','u','b',0};
607
608 ret = GetTempPathW(MAX_PATH, pathW);
609 if (!ret)
610 {
611 ok(0, "couldn't get temp dir\n");
612 return;
613 }
614 if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
615 {
616 ok(0, "MAX_PATH exceeded in constructing paths\n");
617 return;
618 }
619
620 lstrcatW(pathW, testdirW);
621 lstrcpyW(pathsubW, pathW);
622 lstrcatW(pathsubW, subdirW);
623
624 ret = CreateDirectoryW(pathW, NULL);
625 ok(ret == TRUE, "couldn't create directory ntdeletefile\n");
626 if (!pRtlDosPathNameToNtPathName_U(pathW, &nameW, NULL, NULL))
627 {
628 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
629 return;
630 }
631
632 attr.Length = sizeof(attr);
633 attr.RootDirectory = 0;
634 attr.Attributes = OBJ_CASE_INSENSITIVE;
635 attr.ObjectName = &nameW;
636 attr.SecurityDescriptor = NULL;
637 attr.SecurityQualityOfService = NULL;
638
639 /* test NtDeleteFile on an empty directory */
640 ret = pNtDeleteFile(&attr);
641 ok(ret == STATUS_SUCCESS, "NtDeleteFile should succeed in removing an empty directory\n");
642 ret = RemoveDirectoryW(pathW);
643 ok(ret == FALSE, "expected to fail removing directory, NtDeleteFile should have removed it\n");
644
645 /* test NtDeleteFile on a non-empty directory */
646 ret = CreateDirectoryW(pathW, NULL);
647 ok(ret == TRUE, "couldn't create directory ntdeletefile ?!\n");
648 ret = CreateDirectoryW(pathsubW, NULL);
649 ok(ret == TRUE, "couldn't create directory subdir\n");
650 ret = pNtDeleteFile(&attr);
651 ok(ret == STATUS_SUCCESS, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
652 ret = RemoveDirectoryW(pathsubW);
653 ok(ret == TRUE, "expected to remove directory ntdeletefile\\sub\n");
654 ret = RemoveDirectoryW(pathW);
655 ok(ret == TRUE, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
656
657 pRtlFreeUnicodeString( &nameW );
658 }
659
660 static void read_file_test(void)
661 {
662 const char text[] = "foobar";
663 HANDLE handle, read, write;
664 NTSTATUS status;
665 IO_STATUS_BLOCK iosb, iosb2;
666 DWORD written;
667 int apc_count = 0;
668 char buffer[128];
669 LARGE_INTEGER offset;
670 HANDLE event = CreateEventA( NULL, TRUE, FALSE, NULL );
671 BOOL ret;
672
673 buffer[0] = 1;
674
675 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
676
677 /* try read with no data */
678 U(iosb).Status = 0xdeadbabe;
679 iosb.Information = 0xdeadbeef;
680 ok( is_signaled( read ), "read handle is not signaled\n" );
681 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
682 ok( status == STATUS_PENDING, "wrong status %x\n", status );
683 ok( !is_signaled( read ), "read handle is signaled\n" );
684 ok( !is_signaled( event ), "event is signaled\n" );
685 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
686 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
687 ok( !apc_count, "apc was called\n" );
688 ret = WriteFile( write, buffer, 1, &written, NULL );
689 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
690 /* iosb updated here by async i/o */
691 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
692 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
693 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
694 ok( !is_signaled( read ), "read handle is signaled\n" );
695 ok( is_signaled( event ), "event is not signaled\n" );
696 ok( !apc_count, "apc was called\n" );
697 apc_count = 0;
698 SleepEx( 1, FALSE ); /* non-alertable sleep */
699 ok( !apc_count, "apc was called\n" );
700 SleepEx( 1, TRUE ); /* alertable sleep */
701 ok( apc_count == 1, "apc not called\n" );
702
703 /* with no event, the pipe handle itself gets signaled */
704 apc_count = 0;
705 U(iosb).Status = 0xdeadbabe;
706 iosb.Information = 0xdeadbeef;
707 ok( !is_signaled( read ), "read handle is signaled\n" );
708 status = pNtReadFile( read, 0, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
709 ok( status == STATUS_PENDING, "wrong status %x\n", status );
710 ok( !is_signaled( read ), "read handle is signaled\n" );
711 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
712 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
713 ok( !apc_count, "apc was called\n" );
714 ret = WriteFile( write, buffer, 1, &written, NULL );
715 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
716 /* iosb updated here by async i/o */
717 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
718 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
719 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
720 ok( is_signaled( read ), "read handle is not signaled\n" );
721 ok( !apc_count, "apc was called\n" );
722 apc_count = 0;
723 SleepEx( 1, FALSE ); /* non-alertable sleep */
724 ok( !apc_count, "apc was called\n" );
725 SleepEx( 1, TRUE ); /* alertable sleep */
726 ok( apc_count == 1, "apc not called\n" );
727
728 /* now read with data ready */
729 apc_count = 0;
730 U(iosb).Status = 0xdeadbabe;
731 iosb.Information = 0xdeadbeef;
732 ResetEvent( event );
733 ret = WriteFile( write, buffer, 1, &written, NULL );
734 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
735 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
736 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
737 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
738 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
739 ok( is_signaled( event ), "event is not signaled\n" );
740 ok( !apc_count, "apc was called\n" );
741 SleepEx( 1, FALSE ); /* non-alertable sleep */
742 ok( !apc_count, "apc was called\n" );
743 SleepEx( 1, TRUE ); /* alertable sleep */
744 ok( apc_count == 1, "apc not called\n" );
745
746 /* try read with no data */
747 apc_count = 0;
748 U(iosb).Status = 0xdeadbabe;
749 iosb.Information = 0xdeadbeef;
750 ok( is_signaled( event ), "event is not signaled\n" ); /* check that read resets the event */
751 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
752 ok( status == STATUS_PENDING, "wrong status %x\n", status );
753 ok( !is_signaled( event ), "event is signaled\n" );
754 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
755 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
756 ok( !apc_count, "apc was called\n" );
757 ret = WriteFile( write, buffer, 1, &written, NULL );
758 ok(ret && written == 1, "WriteFile error %d\n", GetLastError());
759 /* partial read is good enough */
760 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
761 ok( is_signaled( event ), "event is not signaled\n" );
762 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
763 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
764 ok( !apc_count, "apc was called\n" );
765 SleepEx( 1, TRUE ); /* alertable sleep */
766 ok( apc_count == 1, "apc was not called\n" );
767
768 /* read from disconnected pipe */
769 apc_count = 0;
770 U(iosb).Status = 0xdeadbabe;
771 iosb.Information = 0xdeadbeef;
772 CloseHandle( write );
773 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
774 ok( status == STATUS_PIPE_BROKEN, "wrong status %x\n", status );
775 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
776 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
777 ok( !is_signaled( event ), "event is signaled\n" );
778 ok( !apc_count, "apc was called\n" );
779 SleepEx( 1, TRUE ); /* alertable sleep */
780 ok( !apc_count, "apc was called\n" );
781 CloseHandle( read );
782
783 /* read from closed handle */
784 apc_count = 0;
785 U(iosb).Status = 0xdeadbabe;
786 iosb.Information = 0xdeadbeef;
787 SetEvent( event );
788 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
789 ok( status == STATUS_INVALID_HANDLE, "wrong status %x\n", status );
790 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
791 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
792 ok( is_signaled( event ), "event is not signaled\n" ); /* not reset on invalid handle */
793 ok( !apc_count, "apc was called\n" );
794 SleepEx( 1, TRUE ); /* alertable sleep */
795 ok( !apc_count, "apc was called\n" );
796
797 /* disconnect while async read is in progress */
798 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
799 apc_count = 0;
800 U(iosb).Status = 0xdeadbabe;
801 iosb.Information = 0xdeadbeef;
802 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
803 ok( status == STATUS_PENDING, "wrong status %x\n", status );
804 ok( !is_signaled( event ), "event is signaled\n" );
805 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
806 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
807 ok( !apc_count, "apc was called\n" );
808 CloseHandle( write );
809 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
810 ok( U(iosb).Status == STATUS_PIPE_BROKEN, "wrong status %x\n", U(iosb).Status );
811 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
812 ok( is_signaled( event ), "event is not signaled\n" );
813 ok( !apc_count, "apc was called\n" );
814 SleepEx( 1, TRUE ); /* alertable sleep */
815 ok( apc_count == 1, "apc was not called\n" );
816 CloseHandle( read );
817
818 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
819 ret = DuplicateHandle(GetCurrentProcess(), read, GetCurrentProcess(), &handle, 0, TRUE, DUPLICATE_SAME_ACCESS);
820 ok(ret, "Failed to duplicate handle: %d\n", GetLastError());
821
822 apc_count = 0;
823 U(iosb).Status = 0xdeadbabe;
824 iosb.Information = 0xdeadbeef;
825 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
826 ok( status == STATUS_PENDING, "wrong status %x\n", status );
827 ok( !is_signaled( event ), "event is signaled\n" );
828 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
829 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
830 ok( !apc_count, "apc was called\n" );
831 /* Cancel by other handle */
832 status = pNtCancelIoFile( read, &iosb2 );
833 ok(status == STATUS_SUCCESS, "failed to cancel by different handle: %x\n", status);
834 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
835 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
836 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
837 ok( is_signaled( event ), "event is not signaled\n" );
838 ok( !apc_count, "apc was called\n" );
839 SleepEx( 1, TRUE ); /* alertable sleep */
840 ok( apc_count == 1, "apc was not called\n" );
841
842 apc_count = 0;
843 U(iosb).Status = 0xdeadbabe;
844 iosb.Information = 0xdeadbeef;
845 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
846 ok( status == STATUS_PENDING, "wrong status %x\n", status );
847 ok( !is_signaled( event ), "event is signaled\n" );
848 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
849 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
850 ok( !apc_count, "apc was called\n" );
851 /* Close queued handle */
852 CloseHandle( read );
853 SleepEx( 1, TRUE ); /* alertable sleep */
854 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
855 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
856 status = pNtCancelIoFile( read, &iosb2 );
857 ok(status == STATUS_INVALID_HANDLE, "cancelled by closed handle?\n");
858 status = pNtCancelIoFile( handle, &iosb2 );
859 ok(status == STATUS_SUCCESS, "failed to cancel: %x\n", status);
860 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
861 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
862 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
863 ok( is_signaled( event ), "event is not signaled\n" );
864 ok( !apc_count, "apc was called\n" );
865 SleepEx( 1, TRUE ); /* alertable sleep */
866 ok( apc_count == 1, "apc was not called\n" );
867 CloseHandle( handle );
868 CloseHandle( write );
869
870 if (pNtCancelIoFileEx)
871 {
872 /* Basic Cancel Ex */
873 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
874
875 apc_count = 0;
876 U(iosb).Status = 0xdeadbabe;
877 iosb.Information = 0xdeadbeef;
878 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
879 ok( status == STATUS_PENDING, "wrong status %x\n", status );
880 ok( !is_signaled( event ), "event is signaled\n" );
881 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
882 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
883 ok( !apc_count, "apc was called\n" );
884 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
885 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
886 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
887 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
888 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
889 ok( is_signaled( event ), "event is not signaled\n" );
890 ok( !apc_count, "apc was called\n" );
891 SleepEx( 1, TRUE ); /* alertable sleep */
892 ok( apc_count == 1, "apc was not called\n" );
893
894 /* Duplicate iosb */
895 apc_count = 0;
896 U(iosb).Status = 0xdeadbabe;
897 iosb.Information = 0xdeadbeef;
898 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
899 ok( status == STATUS_PENDING, "wrong status %x\n", status );
900 ok( !is_signaled( event ), "event is signaled\n" );
901 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
902 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
903 ok( !apc_count, "apc was called\n" );
904 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
905 ok( status == STATUS_PENDING, "wrong status %x\n", status );
906 ok( !is_signaled( event ), "event is signaled\n" );
907 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
908 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
909 ok( !apc_count, "apc was called\n" );
910 status = pNtCancelIoFileEx( read, &iosb, &iosb2 );
911 ok(status == STATUS_SUCCESS, "Failed to cancel I/O\n");
912 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
913 ok( U(iosb).Status == STATUS_CANCELLED, "wrong status %x\n", U(iosb).Status );
914 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
915 ok( is_signaled( event ), "event is not signaled\n" );
916 ok( !apc_count, "apc was called\n" );
917 SleepEx( 1, TRUE ); /* alertable sleep */
918 ok( apc_count == 2, "apc was not called\n" );
919
920 CloseHandle( read );
921 CloseHandle( write );
922 }
923
924 /* now try a real file */
925 if (!(handle = create_temp_file( FILE_FLAG_OVERLAPPED ))) return;
926 apc_count = 0;
927 U(iosb).Status = 0xdeadbabe;
928 iosb.Information = 0xdeadbeef;
929 offset.QuadPart = 0;
930 ResetEvent( event );
931 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
932 ok( status == STATUS_SUCCESS || status == STATUS_PENDING, "wrong status %x\n", status );
933 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
934 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
935 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
936 ok( is_signaled( event ), "event is not signaled\n" );
937 ok( !apc_count, "apc was called\n" );
938 SleepEx( 1, TRUE ); /* alertable sleep */
939 ok( apc_count == 1, "apc was not called\n" );
940
941 apc_count = 0;
942 U(iosb).Status = 0xdeadbabe;
943 iosb.Information = 0xdeadbeef;
944 offset.QuadPart = 0;
945 ResetEvent( event );
946 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
947 ok( status == STATUS_SUCCESS ||
948 status == STATUS_PENDING, /* vista */
949 "wrong status %x\n", status );
950 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
951 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
952 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
953 ok( is_signaled( event ), "event is not signaled\n" );
954 ok( !apc_count, "apc was called\n" );
955 SleepEx( 1, TRUE ); /* alertable sleep */
956 ok( apc_count == 1, "apc was not called\n" );
957
958 /* read beyond eof */
959 apc_count = 0;
960 U(iosb).Status = 0xdeadbabe;
961 iosb.Information = 0xdeadbeef;
962 offset.QuadPart = strlen(text) + 2;
963 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
964 ok(status == STATUS_PENDING || status == STATUS_END_OF_FILE /* before Vista */, "expected STATUS_PENDING or STATUS_END_OF_FILE, got %#x\n", status);
965 if (status == STATUS_PENDING) /* vista */
966 {
967 WaitForSingleObject( event, 1000 );
968 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
969 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
970 ok( is_signaled( event ), "event is not signaled\n" );
971 ok( !apc_count, "apc was called\n" );
972 SleepEx( 1, TRUE ); /* alertable sleep */
973 ok( apc_count == 1, "apc was not called\n" );
974 }
975 CloseHandle( handle );
976
977 /* now a non-overlapped file */
978 if (!(handle = create_temp_file(0))) return;
979 apc_count = 0;
980 U(iosb).Status = 0xdeadbabe;
981 iosb.Information = 0xdeadbeef;
982 offset.QuadPart = 0;
983 status = pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
984 ok( status == STATUS_END_OF_FILE ||
985 status == STATUS_SUCCESS ||
986 status == STATUS_PENDING, /* vista */
987 "wrong status %x\n", status );
988 if (status == STATUS_PENDING) WaitForSingleObject( event, 1000 );
989 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
990 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
991 ok( is_signaled( event ), "event is not signaled\n" );
992 ok( !apc_count, "apc was called\n" );
993 SleepEx( 1, TRUE ); /* alertable sleep */
994 ok( apc_count == 1, "apc was not called\n" );
995
996 apc_count = 0;
997 U(iosb).Status = 0xdeadbabe;
998 iosb.Information = 0xdeadbeef;
999 offset.QuadPart = 0;
1000 ResetEvent( event );
1001 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
1002 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
1003 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
1004 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
1005 ok( is_signaled( event ), "event is not signaled\n" );
1006 ok( !apc_count, "apc was called\n" );
1007 SleepEx( 1, TRUE ); /* alertable sleep */
1008 todo_wine ok( !apc_count, "apc was called\n" );
1009
1010 /* read beyond eof */
1011 apc_count = 0;
1012 U(iosb).Status = 0xdeadbabe;
1013 iosb.Information = 0xdeadbeef;
1014 offset.QuadPart = strlen(text) + 2;
1015 ResetEvent( event );
1016 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
1017 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
1018 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
1019 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
1020 ok( is_signaled( event ), "event is not signaled\n" );
1021 ok( !apc_count, "apc was called\n" );
1022 SleepEx( 1, TRUE ); /* alertable sleep */
1023 ok( !apc_count, "apc was called\n" );
1024
1025 CloseHandle( handle );
1026
1027 CloseHandle( event );
1028 }
1029
1030 static void append_file_test(void)
1031 {
1032 static const char text[6] = "foobar";
1033 HANDLE handle;
1034 NTSTATUS status;
1035 IO_STATUS_BLOCK iosb;
1036 LARGE_INTEGER offset;
1037 char path[MAX_PATH], buffer[MAX_PATH], buf[16];
1038 DWORD ret;
1039
1040 GetTempPathA( MAX_PATH, path );
1041 GetTempFileNameA( path, "foo", 0, buffer );
1042
1043 handle = CreateFileA(buffer, FILE_WRITE_DATA, 0, NULL, CREATE_ALWAYS, 0, 0);
1044 ok(handle != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
1045
1046 U(iosb).Status = -1;
1047 iosb.Information = -1;
1048 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text, 2, NULL, NULL);
1049 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
1050 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
1051 ok(iosb.Information == 2, "expected 2, got %lu\n", iosb.Information);
1052
1053 CloseHandle(handle);
1054
1055 /* It is possible to open a file with only FILE_APPEND_DATA access flags.
1056 It matches the O_WRONLY|O_APPEND open() posix behavior */
1057 handle = CreateFileA(buffer, FILE_APPEND_DATA, 0, NULL, OPEN_EXISTING, 0, 0);
1058 ok(handle != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
1059
1060 U(iosb).Status = -1;
1061 iosb.Information = -1;
1062 offset.QuadPart = 1;
1063 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text + 2, 2, &offset, NULL);
1064 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
1065 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
1066 ok(iosb.Information == 2, "expected 2, got %lu\n", iosb.Information);
1067
1068 ret = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
1069 ok(ret == 4, "expected 4, got %u\n", ret);
1070
1071 U(iosb).Status = -1;
1072 iosb.Information = -1;
1073 offset.QuadPart = 3;
1074 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text + 4, 2, &offset, NULL);
1075 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
1076 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
1077 ok(iosb.Information == 2, "expected 2, got %lu\n", iosb.Information);
1078
1079 ret = SetFilePointer(handle, 0, NULL, FILE_CURRENT);
1080 ok(ret == 6, "expected 6, got %u\n", ret);
1081
1082 CloseHandle(handle);
1083
1084 handle = CreateFileA(buffer, FILE_READ_DATA | FILE_WRITE_DATA | FILE_APPEND_DATA, 0, NULL, OPEN_EXISTING, 0, 0);
1085 ok(handle != INVALID_HANDLE_VALUE, "CreateFile error %d\n", GetLastError());
1086
1087 memset(buf, 0, sizeof(buf));
1088 U(iosb).Status = -1;
1089 iosb.Information = -1;
1090 offset.QuadPart = 0;
1091 status = pNtReadFile(handle, 0, NULL, NULL, &iosb, buf, sizeof(buf), &offset, NULL);
1092 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
1093 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
1094 ok(iosb.Information == 6, "expected 6, got %lu\n", iosb.Information);
1095 buf[6] = 0;
1096 ok(memcmp(buf, text, 6) == 0, "wrong file contents: %s\n", buf);
1097
1098 U(iosb).Status = -1;
1099 iosb.Information = -1;
1100 offset.QuadPart = 0;
1101 status = pNtWriteFile(handle, NULL, NULL, NULL, &iosb, text + 3, 3, &offset, NULL);
1102 ok(status == STATUS_SUCCESS, "NtWriteFile error %#x\n", status);
1103 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
1104 ok(iosb.Information == 3, "expected 3, got %lu\n", iosb.Information);
1105
1106 memset(buf, 0, sizeof(buf));
1107 U(iosb).Status = -1;
1108 iosb.Information = -1;
1109 offset.QuadPart = 0;
1110 status = pNtReadFile(handle, 0, NULL, NULL, &iosb, buf, sizeof(buf), &offset, NULL);
1111 ok(status == STATUS_SUCCESS, "NtReadFile error %#x\n", status);
1112 ok(U(iosb).Status == STATUS_SUCCESS, "expected STATUS_SUCCESS, got %#x\n", U(iosb).Status);
1113 ok(iosb.Information == 6, "expected 6, got %lu\n", iosb.Information);
1114 buf[6] = 0;
1115 ok(memcmp(buf, "barbar", 6) == 0, "wrong file contents: %s\n", buf);
1116
1117 CloseHandle(handle);
1118 DeleteFileA(buffer);
1119 }
1120
1121 static void nt_mailslot_test(void)
1122 {
1123 HANDLE hslot;
1124 ACCESS_MASK DesiredAccess;
1125 OBJECT_ATTRIBUTES attr;
1126
1127 ULONG CreateOptions;
1128 ULONG MailslotQuota;
1129 ULONG MaxMessageSize;
1130 LARGE_INTEGER TimeOut;
1131 IO_STATUS_BLOCK IoStatusBlock;
1132 NTSTATUS rc;
1133 UNICODE_STRING str;
1134 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
1135 'R',':','\\','F','R','E','D','\0' };
1136
1137 TimeOut.QuadPart = -1;
1138
1139 pRtlInitUnicodeString(&str, buffer1);
1140 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
1141 CreateOptions = MailslotQuota = MaxMessageSize = 0;
1142 DesiredAccess = GENERIC_READ;
1143
1144 /*
1145 * Check for NULL pointer handling
1146 */
1147 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
1148 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
1149 &TimeOut);
1150 ok( rc == STATUS_ACCESS_VIOLATION ||
1151 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
1152 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
1153
1154 /*
1155 * Test to see if the Timeout can be NULL
1156 */
1157 hslot = (HANDLE)0xdeadbeef;
1158 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
1159 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
1160 NULL);
1161 ok( rc == STATUS_SUCCESS ||
1162 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
1163 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
1164 ok( hslot != 0, "Handle is invalid\n");
1165
1166 if ( rc == STATUS_SUCCESS ) pNtClose(hslot);
1167
1168 /*
1169 * Test a valid call
1170 */
1171 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
1172 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
1173 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
1174 &TimeOut);
1175 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
1176 ok( hslot != 0, "Handle is invalid\n");
1177
1178 rc = pNtClose(hslot);
1179 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
1180 }
1181
1182 static void test_iocp_setcompletion(HANDLE h)
1183 {
1184 NTSTATUS res;
1185 ULONG count;
1186 SIZE_T size = 3;
1187
1188 if (sizeof(size) > 4) size |= (ULONGLONG)0x12345678 << 32;
1189
1190 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, size );
1191 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
1192
1193 count = get_pending_msgs(h);
1194 ok( count == 1, "Unexpected msg count: %d\n", count );
1195
1196 if (get_msg(h))
1197 {
1198 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
1199 ok( ioSb.Information == size, "Invalid ioSb.Information: %lu\n", ioSb.Information );
1200 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1201 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
1202 }
1203
1204 count = get_pending_msgs(h);
1205 ok( !count, "Unexpected msg count: %d\n", count );
1206 }
1207
1208 static void test_iocp_fileio(HANDLE h)
1209 {
1210 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
1211
1212 IO_STATUS_BLOCK iosb;
1213 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
1214 HANDLE hPipeSrv, hPipeClt;
1215 NTSTATUS res;
1216
1217 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1218 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1219 if (hPipeSrv != INVALID_HANDLE_VALUE )
1220 {
1221 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1222 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1223 if (hPipeClt != INVALID_HANDLE_VALUE)
1224 {
1225 U(iosb).Status = 0xdeadbeef;
1226 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1227 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
1228 ok( U(iosb).Status == STATUS_INVALID_PARAMETER /* 98 */ || U(iosb).Status == 0xdeadbeef /* NT4+ */,
1229 "Unexpected iosb.Status on non-overlapped handle: %x\n", U(iosb).Status );
1230 CloseHandle(hPipeClt);
1231 }
1232 CloseHandle( hPipeSrv );
1233 }
1234
1235 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1236 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1237 if (hPipeSrv == INVALID_HANDLE_VALUE )
1238 return;
1239
1240 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1241 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1242 if (hPipeClt != INVALID_HANDLE_VALUE)
1243 {
1244 OVERLAPPED o = {0,};
1245 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
1246 DWORD read;
1247 long count;
1248
1249 U(iosb).Status = 0xdeadbeef;
1250 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1251 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
1252 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
1253
1254 memset( send_buf, 0, TEST_BUF_LEN );
1255 memset( recv_buf, 0xde, TEST_BUF_LEN );
1256 count = get_pending_msgs(h);
1257 ok( !count, "Unexpected msg count: %ld\n", count );
1258 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1259 count = get_pending_msgs(h);
1260 ok( !count, "Unexpected msg count: %ld\n", count );
1261 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
1262
1263 if (get_msg(h))
1264 {
1265 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1266 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1267 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1268 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1269 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] );
1270 }
1271 count = get_pending_msgs(h);
1272 ok( !count, "Unexpected msg count: %ld\n", count );
1273
1274 memset( send_buf, 0, TEST_BUF_LEN );
1275 memset( recv_buf, 0xde, TEST_BUF_LEN );
1276 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
1277 count = get_pending_msgs(h);
1278 ok( !count, "Unexpected msg count: %ld\n", count );
1279 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
1280 count = get_pending_msgs(h);
1281 ok( count == 1, "Unexpected msg count: %ld\n", count );
1282 if (get_msg(h))
1283 {
1284 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1285 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1286 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1287 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1288 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] );
1289 }
1290
1291 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1292 CloseHandle( hPipeSrv );
1293 count = get_pending_msgs(h);
1294 ok( count == 1, "Unexpected msg count: %ld\n", count );
1295 if (get_msg(h))
1296 {
1297 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1298 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1299 /* wine sends wrong status here */
1300 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1301 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1302 }
1303 }
1304
1305 CloseHandle( hPipeClt );
1306
1307 /* test associating a completion port with a handle after an async is queued */
1308 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
1309 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
1310 if (hPipeSrv == INVALID_HANDLE_VALUE )
1311 return;
1312 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
1313 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
1314 if (hPipeClt != INVALID_HANDLE_VALUE)
1315 {
1316 OVERLAPPED o = {0,};
1317 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
1318 DWORD read;
1319 long count;
1320
1321 memset( send_buf, 0, TEST_BUF_LEN );
1322 memset( recv_buf, 0xde, TEST_BUF_LEN );
1323 count = get_pending_msgs(h);
1324 ok( !count, "Unexpected msg count: %ld\n", count );
1325 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
1326
1327 U(iosb).Status = 0xdeadbeef;
1328 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
1329 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
1330 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
1331 count = get_pending_msgs(h);
1332 ok( !count, "Unexpected msg count: %ld\n", count );
1333
1334 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
1335
1336 if (get_msg(h))
1337 {
1338 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
1339 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
1340 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
1341 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
1342 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] );
1343 }
1344 count = get_pending_msgs(h);
1345 ok( !count, "Unexpected msg count: %ld\n", count );
1346 }
1347
1348 CloseHandle( hPipeSrv );
1349 CloseHandle( hPipeClt );
1350 }
1351
1352 static void test_file_full_size_information(void)
1353 {
1354 IO_STATUS_BLOCK io;
1355 FILE_FS_FULL_SIZE_INFORMATION ffsi;
1356 FILE_FS_SIZE_INFORMATION fsi;
1357 HANDLE h;
1358 NTSTATUS res;
1359
1360 if(!(h = create_temp_file(0))) return ;
1361
1362 memset(&ffsi,0,sizeof(ffsi));
1363 memset(&fsi,0,sizeof(fsi));
1364
1365 /* Assume No Quota Settings configured on Wine Testbot */
1366 res = pNtQueryVolumeInformationFile(h, &io, &ffsi, sizeof ffsi, FileFsFullSizeInformation);
1367 ok(res == STATUS_SUCCESS, "cannot get attributes, res %x\n", res);
1368 res = pNtQueryVolumeInformationFile(h, &io, &fsi, sizeof fsi, FileFsSizeInformation);
1369 ok(res == STATUS_SUCCESS, "cannot get attributes, res %x\n", res);
1370
1371 /* Test for FileFsSizeInformation */
1372 ok(fsi.TotalAllocationUnits.QuadPart > 0,
1373 "[fsi] TotalAllocationUnits expected positive, got 0x%s\n",
1374 debugstr_longlong(fsi.TotalAllocationUnits.QuadPart));
1375 ok(fsi.AvailableAllocationUnits.QuadPart > 0,
1376 "[fsi] AvailableAllocationUnits expected positive, got 0x%s\n",
1377 debugstr_longlong(fsi.AvailableAllocationUnits.QuadPart));
1378
1379 /* Assume file system is NTFS */
1380 ok(fsi.BytesPerSector == 512, "[fsi] BytesPerSector expected 512, got %d\n",fsi.BytesPerSector);
1381 ok(fsi.SectorsPerAllocationUnit == 8, "[fsi] SectorsPerAllocationUnit expected 8, got %d\n",fsi.SectorsPerAllocationUnit);
1382
1383 ok(ffsi.TotalAllocationUnits.QuadPart > 0,
1384 "[ffsi] TotalAllocationUnits expected positive, got negative value 0x%s\n",
1385 debugstr_longlong(ffsi.TotalAllocationUnits.QuadPart));
1386 ok(ffsi.CallerAvailableAllocationUnits.QuadPart > 0,
1387 "[ffsi] CallerAvailableAllocationUnits expected positive, got negative value 0x%s\n",
1388 debugstr_longlong(ffsi.CallerAvailableAllocationUnits.QuadPart));
1389 ok(ffsi.ActualAvailableAllocationUnits.QuadPart > 0,
1390 "[ffsi] ActualAvailableAllocationUnits expected positive, got negative value 0x%s\n",
1391 debugstr_longlong(ffsi.ActualAvailableAllocationUnits.QuadPart));
1392 ok(ffsi.TotalAllocationUnits.QuadPart == fsi.TotalAllocationUnits.QuadPart,
1393 "[ffsi] TotalAllocationUnits error fsi:0x%s, ffsi:0x%s\n",
1394 debugstr_longlong(fsi.TotalAllocationUnits.QuadPart),
1395 debugstr_longlong(ffsi.TotalAllocationUnits.QuadPart));
1396 ok(ffsi.CallerAvailableAllocationUnits.QuadPart == fsi.AvailableAllocationUnits.QuadPart,
1397 "[ffsi] CallerAvailableAllocationUnits error fsi:0x%s, ffsi: 0x%s\n",
1398 debugstr_longlong(fsi.AvailableAllocationUnits.QuadPart),
1399 debugstr_longlong(ffsi.CallerAvailableAllocationUnits.QuadPart));
1400
1401 /* Assume file system is NTFS */
1402 ok(ffsi.BytesPerSector == 512, "[ffsi] BytesPerSector expected 512, got %d\n",ffsi.BytesPerSector);
1403 ok(ffsi.SectorsPerAllocationUnit == 8, "[ffsi] SectorsPerAllocationUnit expected 8, got %d\n",ffsi.SectorsPerAllocationUnit);
1404
1405 CloseHandle( h );
1406 }
1407
1408 static void test_file_basic_information(void)
1409 {
1410 IO_STATUS_BLOCK io;
1411 FILE_BASIC_INFORMATION fbi;
1412 HANDLE h;
1413 int res;
1414 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1415
1416 if (!(h = create_temp_file(0))) return;
1417
1418 /* Check default first */
1419 memset(&fbi, 0, sizeof(fbi));
1420 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1421 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1422 ok ( (fbi.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1423 "attribute %x not expected\n", fbi.FileAttributes );
1424
1425 /* Then SYSTEM */
1426 /* Clear fbi to avoid setting times */
1427 memset(&fbi, 0, sizeof(fbi));
1428 fbi.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1429 U(io).Status = 0xdeadbeef;
1430 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1431 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1432 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1433
1434 memset(&fbi, 0, sizeof(fbi));
1435 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1436 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1437 ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM (ok in old linux without xattr)\n", fbi.FileAttributes );
1438
1439 /* Then HIDDEN */
1440 memset(&fbi, 0, sizeof(fbi));
1441 fbi.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1442 U(io).Status = 0xdeadbeef;
1443 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1444 ok ( res == STATUS_SUCCESS, "can't set system attribute, NtSetInformationFile returned %x\n", res );
1445 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status is %x\n", U(io).Status );
1446
1447 memset(&fbi, 0, sizeof(fbi));
1448 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1449 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1450 ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN (ok in old linux without xattr)\n", fbi.FileAttributes );
1451
1452 /* Check NORMAL last of all (to make sure we can clear attributes) */
1453 memset(&fbi, 0, sizeof(fbi));
1454 fbi.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1455 U(io).Status = 0xdeadbeef;
1456 res = pNtSetInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1457 ok ( res == STATUS_SUCCESS, "can't set normal attribute, NtSetInformationFile returned %x\n", res );
1458 ok ( U(io).Status == STATUS_SUCCESS, "can't set normal attribute, io.Status is %x\n", U(io).Status );
1459
1460 memset(&fbi, 0, sizeof(fbi));
1461 res = pNtQueryInformationFile(h, &io, &fbi, sizeof fbi, FileBasicInformation);
1462 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1463 todo_wine ok ( (fbi.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_NORMAL, "attribute %x not 0\n", fbi.FileAttributes );
1464
1465 CloseHandle( h );
1466 }
1467
1468 static void test_file_all_information(void)
1469 {
1470 IO_STATUS_BLOCK io;
1471 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1472 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1473 * don't leave enough room there.
1474 */
1475 struct {
1476 FILE_ALL_INFORMATION fai;
1477 WCHAR buf[256];
1478 } fai_buf;
1479 HANDLE h;
1480 int res;
1481 int attrib_mask = FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_NORMAL;
1482
1483 if (!(h = create_temp_file(0))) return;
1484
1485 /* Check default first */
1486 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1487 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1488 ok ( (fai_buf.fai.BasicInformation.FileAttributes & FILE_ATTRIBUTE_ARCHIVE) == FILE_ATTRIBUTE_ARCHIVE,
1489 "attribute %x not expected\n", fai_buf.fai.BasicInformation.FileAttributes );
1490
1491 /* Then SYSTEM */
1492 /* Clear fbi to avoid setting times */
1493 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1494 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_SYSTEM;
1495 U(io).Status = 0xdeadbeef;
1496 res = pNtSetInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1497 ok ( res == STATUS_INVALID_INFO_CLASS || broken(res == STATUS_NOT_IMPLEMENTED), "shouldn't be able to set FileAllInformation, res %x\n", res);
1498 todo_wine ok ( U(io).Status == 0xdeadbeef, "shouldn't be able to set FileAllInformation, io.Status is %x\n", U(io).Status);
1499 U(io).Status = 0xdeadbeef;
1500 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1501 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1502 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1503
1504 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1505 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1506 ok ( res == STATUS_SUCCESS, "can't get attributes, res %x\n", res);
1507 ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_SYSTEM, "attribute %x not FILE_ATTRIBUTE_SYSTEM (ok in old linux without xattr)\n", fai_buf.fai.BasicInformation.FileAttributes );
1508
1509 /* Then HIDDEN */
1510 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1511 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_HIDDEN;
1512 U(io).Status = 0xdeadbeef;
1513 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1514 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1515 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1516
1517 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1518 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1519 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1520 ok ( (fai_buf.fai.BasicInformation.FileAttributes & attrib_mask) == FILE_ATTRIBUTE_HIDDEN, "attribute %x not FILE_ATTRIBUTE_HIDDEN (ok in old linux without xattr)\n", fai_buf.fai.BasicInformation.FileAttributes );
1521
1522 /* Check NORMAL last of all (to make sure we can clear attributes) */
1523 memset(&fai_buf.fai.BasicInformation, 0, sizeof(fai_buf.fai.BasicInformation));
1524 fai_buf.fai.BasicInformation.FileAttributes = FILE_ATTRIBUTE_NORMAL;
1525 U(io).Status = 0xdeadbeef;
1526 res = pNtSetInformationFile(h, &io, &fai_buf.fai.BasicInformation, sizeof fai_buf.fai.BasicInformation, FileBasicInformation);
1527 ok ( res == STATUS_SUCCESS, "can't set system attribute, res: %x\n", res );
1528 ok ( U(io).Status == STATUS_SUCCESS, "can't set system attribute, io.Status: %x\n", U(io).Status );
1529
1530 memset(&fai_buf.fai, 0, sizeof(fai_buf.fai));
1531 res = pNtQueryInformationFile(h, &io, &fai_buf.fai, sizeof fai_buf, FileAllInformation);
1532 ok ( res == STATUS_SUCCESS, "can't get attributes\n");
1533 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 );
1534
1535 CloseHandle( h );
1536 }
1537
1538 static void delete_object( WCHAR *path )
1539 {
1540 BOOL ret = DeleteFileW( path );
1541 ok( ret || GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_ACCESS_DENIED,
1542 "DeleteFileW failed with %u\n", GetLastError() );
1543 if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
1544 {
1545 ret = RemoveDirectoryW( path );
1546 ok( ret, "RemoveDirectoryW failed with %u\n", GetLastError() );
1547 }
1548 }
1549
1550 static void test_file_rename_information(void)
1551 {
1552 static const WCHAR foo_txtW[] = {'\\','f','o','o','.','t','x','t',0};
1553 static const WCHAR fooW[] = {'f','o','o',0};
1554 WCHAR tmp_path[MAX_PATH], oldpath[MAX_PATH + 16], newpath[MAX_PATH + 16], *filename, *p;
1555 FILE_RENAME_INFORMATION *fri;
1556 FILE_NAME_INFORMATION *fni;
1557 BOOL success, fileDeleted;
1558 UNICODE_STRING name_str;
1559 HANDLE handle, handle2;
1560 IO_STATUS_BLOCK io;
1561 NTSTATUS res;
1562
1563 GetTempPathW( MAX_PATH, tmp_path );
1564
1565 /* oldpath is a file, newpath doesn't exist */
1566 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1567 ok( res != 0, "failed to create temp file\n" );
1568 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1569 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1570
1571 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1572 ok( res != 0, "failed to create temp file\n" );
1573 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1574 DeleteFileW( newpath );
1575 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1576 fri->Replace = FALSE;
1577 fri->RootDir = NULL;
1578 fri->FileNameLength = name_str.Length;
1579 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1580 pRtlFreeUnicodeString( &name_str );
1581
1582 U(io).Status = 0xdeadbeef;
1583 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1584 ok( U(io).Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %x\n", U(io).Status );
1585 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
1586 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1587 ok( fileDeleted, "file should not exist\n" );
1588 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1589 ok( !fileDeleted, "file should exist\n" );
1590
1591 fni = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR) );
1592 res = pNtQueryInformationFile( handle, &io, fni, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR), FileNameInformation );
1593 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
1594 fni->FileName[ fni->FileNameLength / sizeof(WCHAR) ] = 0;
1595 ok( !lstrcmpW(fni->FileName, newpath + 2), "FileName expected %s, got %s\n",
1596 wine_dbgstr_w(newpath + 2), wine_dbgstr_w(fni->FileName) );
1597 HeapFree( GetProcessHeap(), 0, fni );
1598
1599 CloseHandle( handle );
1600 HeapFree( GetProcessHeap(), 0, fri );
1601 delete_object( oldpath );
1602 delete_object( newpath );
1603
1604 /* oldpath is a file, newpath is a file, Replace = FALSE */
1605 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1606 ok( res != 0, "failed to create temp file\n" );
1607 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1608 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1609
1610 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1611 ok( res != 0, "failed to create temp file\n" );
1612 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1613 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1614 fri->Replace = FALSE;
1615 fri->RootDir = NULL;
1616 fri->FileNameLength = name_str.Length;
1617 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1618 pRtlFreeUnicodeString( &name_str );
1619
1620 U(io).Status = 0xdeadbeef;
1621 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1622 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1623 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
1624 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1625 ok( !fileDeleted, "file should exist\n" );
1626 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1627 ok( !fileDeleted, "file should exist\n" );
1628
1629 CloseHandle( handle );
1630 HeapFree( GetProcessHeap(), 0, fri );
1631 delete_object( oldpath );
1632 delete_object( newpath );
1633
1634 /* oldpath is a file, newpath is a file, Replace = TRUE */
1635 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1636 ok( res != 0, "failed to create temp file\n" );
1637 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1638 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1639
1640 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1641 ok( res != 0, "failed to create temp file\n" );
1642 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1643 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1644 fri->Replace = TRUE;
1645 fri->RootDir = NULL;
1646 fri->FileNameLength = name_str.Length;
1647 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1648 pRtlFreeUnicodeString( &name_str );
1649
1650 U(io).Status = 0xdeadbeef;
1651 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1652 ok( U(io).Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %x\n", U(io).Status );
1653 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
1654 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1655 ok( fileDeleted, "file should not exist\n" );
1656 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1657 ok( !fileDeleted, "file should exist\n" );
1658
1659 CloseHandle( handle );
1660 HeapFree( GetProcessHeap(), 0, fri );
1661 delete_object( oldpath );
1662 delete_object( newpath );
1663
1664 /* oldpath is a file, newpath is a file, Replace = FALSE, target file opened */
1665 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1666 ok( res != 0, "failed to create temp file\n" );
1667 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1668 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1669
1670 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1671 ok( res != 0, "failed to create temp file\n" );
1672 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1673 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1674
1675 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1676 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1677 fri->Replace = FALSE;
1678 fri->RootDir = NULL;
1679 fri->FileNameLength = name_str.Length;
1680 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1681 pRtlFreeUnicodeString( &name_str );
1682
1683 U(io).Status = 0xdeadbeef;
1684 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1685 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1686 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
1687 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1688 ok( !fileDeleted, "file should exist\n" );
1689 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1690 ok( !fileDeleted, "file should exist\n" );
1691
1692 CloseHandle( handle );
1693 CloseHandle( handle2 );
1694 HeapFree( GetProcessHeap(), 0, fri );
1695 delete_object( oldpath );
1696 delete_object( newpath );
1697
1698 /* oldpath is a file, newpath is a file, Replace = TRUE, target file opened */
1699 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1700 ok( res != 0, "failed to create temp file\n" );
1701 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1702 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1703
1704 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1705 ok( res != 0, "failed to create temp file\n" );
1706 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1707 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1708
1709 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1710 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1711 fri->Replace = TRUE;
1712 fri->RootDir = NULL;
1713 fri->FileNameLength = name_str.Length;
1714 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1715 pRtlFreeUnicodeString( &name_str );
1716
1717 U(io).Status = 0xdeadbeef;
1718 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1719 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1720 ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %x\n", res );
1721 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1722 ok( !fileDeleted, "file should exist\n" );
1723 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1724 ok( !fileDeleted, "file should exist\n" );
1725
1726 CloseHandle( handle );
1727 CloseHandle( handle2 );
1728 HeapFree( GetProcessHeap(), 0, fri );
1729 delete_object( oldpath );
1730 delete_object( newpath );
1731
1732 /* oldpath is a directory, newpath doesn't exist, Replace = FALSE */
1733 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1734 ok( res != 0, "failed to create temp file\n" );
1735 DeleteFileW( oldpath );
1736 success = CreateDirectoryW( oldpath, NULL );
1737 ok( success != 0, "failed to create temp directory\n" );
1738 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1739 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1740
1741 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1742 ok( res != 0, "failed to create temp file\n" );
1743 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1744 DeleteFileW( newpath );
1745 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1746 fri->Replace = FALSE;
1747 fri->RootDir = NULL;
1748 fri->FileNameLength = name_str.Length;
1749 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1750 pRtlFreeUnicodeString( &name_str );
1751
1752 U(io).Status = 0xdeadbeef;
1753 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1754 ok( U(io).Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %x\n", U(io).Status );
1755 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
1756 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1757 ok( fileDeleted, "file should not exist\n" );
1758 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1759 ok( !fileDeleted, "file should exist\n" );
1760
1761 fni = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR) );
1762 res = pNtQueryInformationFile( handle, &io, fni, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR), FileNameInformation );
1763 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
1764 fni->FileName[ fni->FileNameLength / sizeof(WCHAR) ] = 0;
1765 ok( !lstrcmpW(fni->FileName, newpath + 2), "FileName expected %s, got %s\n",
1766 wine_dbgstr_w(newpath + 2), wine_dbgstr_w(fni->FileName) );
1767 HeapFree( GetProcessHeap(), 0, fni );
1768
1769 CloseHandle( handle );
1770 HeapFree( GetProcessHeap(), 0, fri );
1771 delete_object( oldpath );
1772 delete_object( newpath );
1773
1774 /* oldpath is a directory (but child object opened), newpath doesn't exist, Replace = FALSE */
1775 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1776 ok( res != 0, "failed to create temp file\n" );
1777 DeleteFileW( oldpath );
1778 success = CreateDirectoryW( oldpath, NULL );
1779 ok( success != 0, "failed to create temp directory\n" );
1780 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1781 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1782
1783 lstrcpyW( newpath, oldpath );
1784 lstrcatW( newpath, foo_txtW );
1785 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0 );
1786 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1787
1788 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1789 ok( res != 0, "failed to create temp file\n" );
1790 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1791 DeleteFileW( newpath );
1792 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1793 fri->Replace = FALSE;
1794 fri->RootDir = NULL;
1795 fri->FileNameLength = name_str.Length;
1796 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1797 pRtlFreeUnicodeString( &name_str );
1798
1799 U(io).Status = 0xdeadbeef;
1800 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1801 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1802 todo_wine ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %x\n", res );
1803 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1804 todo_wine ok( !fileDeleted, "file should exist\n" );
1805 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1806 todo_wine ok( fileDeleted, "file should not exist\n" );
1807
1808 CloseHandle( handle );
1809 CloseHandle( handle2 );
1810 HeapFree( GetProcessHeap(), 0, fri );
1811 delete_object( oldpath );
1812 if (res == STATUS_SUCCESS) /* remove when Wine is fixed */
1813 {
1814 lstrcpyW( oldpath, newpath );
1815 lstrcatW( oldpath, foo_txtW );
1816 delete_object( oldpath );
1817 }
1818 delete_object( newpath );
1819
1820 /* oldpath is a directory, newpath is a file, Replace = FALSE */
1821 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1822 ok( res != 0, "failed to create temp file\n" );
1823 DeleteFileW( oldpath );
1824 success = CreateDirectoryW( oldpath, NULL );
1825 ok( success != 0, "failed to create temp directory\n" );
1826 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1827 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1828
1829 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1830 ok( res != 0, "failed to create temp file\n" );
1831 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1832 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1833 fri->Replace = FALSE;
1834 fri->RootDir = NULL;
1835 fri->FileNameLength = name_str.Length;
1836 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1837 pRtlFreeUnicodeString( &name_str );
1838
1839 U(io).Status = 0xdeadbeef;
1840 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1841 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1842 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
1843 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1844 ok( !fileDeleted, "file should exist\n" );
1845 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1846 ok( !fileDeleted, "file should exist\n" );
1847
1848 CloseHandle( handle );
1849 HeapFree( GetProcessHeap(), 0, fri );
1850 delete_object( oldpath );
1851 delete_object( newpath );
1852
1853 /* oldpath is a directory, newpath is a file, Replace = FALSE, target file opened */
1854 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1855 ok( res != 0, "failed to create temp file\n" );
1856 DeleteFileW( oldpath );
1857 success = CreateDirectoryW( oldpath, NULL );
1858 ok( success != 0, "failed to create temp directory\n" );
1859 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1860 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1861
1862 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1863 ok( res != 0, "failed to create temp file\n" );
1864 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1865 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1866
1867 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1868 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1869 fri->Replace = FALSE;
1870 fri->RootDir = NULL;
1871 fri->FileNameLength = name_str.Length;
1872 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1873 pRtlFreeUnicodeString( &name_str );
1874
1875 U(io).Status = 0xdeadbeef;
1876 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1877 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1878 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
1879 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1880 ok( !fileDeleted, "file should exist\n" );
1881 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1882 ok( !fileDeleted, "file should exist\n" );
1883
1884 CloseHandle( handle );
1885 CloseHandle( handle2 );
1886 HeapFree( GetProcessHeap(), 0, fri );
1887 delete_object( oldpath );
1888 delete_object( newpath );
1889
1890 /* oldpath is a directory, newpath is a file, Replace = TRUE */
1891 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1892 ok( res != 0, "failed to create temp file\n" );
1893 DeleteFileW( oldpath );
1894 success = CreateDirectoryW( oldpath, NULL );
1895 ok( success != 0, "failed to create temp directory\n" );
1896 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1897 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1898
1899 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1900 ok( res != 0, "failed to create temp file\n" );
1901 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1902 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1903 fri->Replace = TRUE;
1904 fri->RootDir = NULL;
1905 fri->FileNameLength = name_str.Length;
1906 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1907 pRtlFreeUnicodeString( &name_str );
1908
1909 U(io).Status = 0xdeadbeef;
1910 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1911 ok( U(io).Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %x\n", U(io).Status );
1912 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
1913 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1914 ok( fileDeleted, "file should not exist\n" );
1915 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1916 ok( !fileDeleted, "file should exist\n" );
1917
1918 CloseHandle( handle );
1919 HeapFree( GetProcessHeap(), 0, fri );
1920 delete_object( oldpath );
1921 delete_object( newpath );
1922
1923 /* oldpath is a directory, newpath is a file, Replace = TRUE, target file opened */
1924 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1925 ok( res != 0, "failed to create temp file\n" );
1926 DeleteFileW( oldpath );
1927 success = CreateDirectoryW( oldpath, NULL );
1928 ok( success != 0, "failed to create temp directory\n" );
1929 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1930 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1931
1932 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1933 ok( res != 0, "failed to create temp file\n" );
1934 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1935 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1936
1937 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1938 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1939 fri->Replace = TRUE;
1940 fri->RootDir = NULL;
1941 fri->FileNameLength = name_str.Length;
1942 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1943 pRtlFreeUnicodeString( &name_str );
1944
1945 U(io).Status = 0xdeadbeef;
1946 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1947 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1948 ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %x\n", res );
1949 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1950 ok( !fileDeleted, "file should exist\n" );
1951 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1952 ok( !fileDeleted, "file should exist\n" );
1953
1954 CloseHandle( handle );
1955 CloseHandle( handle2 );
1956 HeapFree( GetProcessHeap(), 0, fri );
1957 delete_object( oldpath );
1958 delete_object( newpath );
1959
1960 /* oldpath is a directory, newpath is a directory, Replace = FALSE */
1961 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1962 ok( res != 0, "failed to create temp file\n" );
1963 DeleteFileW( oldpath );
1964 success = CreateDirectoryW( oldpath, NULL );
1965 ok( success != 0, "failed to create temp directory\n" );
1966 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
1967 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
1968
1969 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
1970 ok( res != 0, "failed to create temp file\n" );
1971 DeleteFileW( newpath );
1972 success = CreateDirectoryW( newpath, NULL );
1973 ok( success != 0, "failed to create temp directory\n" );
1974 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
1975 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
1976 fri->Replace = FALSE;
1977 fri->RootDir = NULL;
1978 fri->FileNameLength = name_str.Length;
1979 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
1980 pRtlFreeUnicodeString( &name_str );
1981
1982 U(io).Status = 0xdeadbeef;
1983 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
1984 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
1985 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
1986 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1987 ok( !fileDeleted, "file should exist\n" );
1988 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
1989 ok( !fileDeleted, "file should exist\n" );
1990
1991 CloseHandle( handle );
1992 HeapFree( GetProcessHeap(), 0, fri );
1993 delete_object( oldpath );
1994 delete_object( newpath );
1995
1996 /* oldpath is a directory, newpath is a directory, Replace = TRUE */
1997 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
1998 ok( res != 0, "failed to create temp file\n" );
1999 DeleteFileW( oldpath );
2000 success = CreateDirectoryW( oldpath, NULL );
2001 ok( success != 0, "failed to create temp directory\n" );
2002 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
2003 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2004
2005 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2006 ok( res != 0, "failed to create temp file\n" );
2007 DeleteFileW( newpath );
2008 success = CreateDirectoryW( newpath, NULL );
2009 ok( success != 0, "failed to create temp directory\n" );
2010 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2011 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
2012 fri->Replace = TRUE;
2013 fri->RootDir = NULL;
2014 fri->FileNameLength = name_str.Length;
2015 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
2016 pRtlFreeUnicodeString( &name_str );
2017
2018 U(io).Status = 0xdeadbeef;
2019 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
2020 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2021 ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %x\n", res );
2022 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2023 ok( !fileDeleted, "file should exist\n" );
2024 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2025 ok( !fileDeleted, "file should exist\n" );
2026
2027 CloseHandle( handle );
2028 HeapFree( GetProcessHeap(), 0, fri );
2029 delete_object( oldpath );
2030 delete_object( newpath );
2031
2032 /* oldpath is a directory, newpath is a directory, Replace = TRUE, target file opened */
2033 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2034 ok( res != 0, "failed to create temp file\n" );
2035 DeleteFileW( oldpath );
2036 success = CreateDirectoryW( oldpath, NULL );
2037 ok( success != 0, "failed to create temp directory\n" );
2038 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
2039 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2040
2041 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2042 ok( res != 0, "failed to create temp file\n" );
2043 DeleteFileW( newpath );
2044 success = CreateDirectoryW( newpath, NULL );
2045 ok( success != 0, "failed to create temp directory\n" );
2046 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
2047 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2048
2049 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2050 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
2051 fri->Replace = TRUE;
2052 fri->RootDir = NULL;
2053 fri->FileNameLength = name_str.Length;
2054 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
2055 pRtlFreeUnicodeString( &name_str );
2056
2057 U(io).Status = 0xdeadbeef;
2058 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
2059 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2060 ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %x\n", res );
2061 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2062 ok( !fileDeleted, "file should exist\n" );
2063 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2064 ok( !fileDeleted, "file should exist\n" );
2065
2066 CloseHandle( handle );
2067 CloseHandle( handle2 );
2068 HeapFree( GetProcessHeap(), 0, fri );
2069 delete_object( oldpath );
2070 delete_object( newpath );
2071
2072 /* oldpath is a file, newpath is a directory, Replace = FALSE */
2073 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2074 ok( res != 0, "failed to create temp file\n" );
2075 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2076 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2077
2078 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2079 ok( res != 0, "failed to create temp file\n" );
2080 DeleteFileW( newpath );
2081 success = CreateDirectoryW( newpath, NULL );
2082 ok( success != 0, "failed to create temp directory\n" );
2083 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2084 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
2085 fri->Replace = FALSE;
2086 fri->RootDir = NULL;
2087 fri->FileNameLength = name_str.Length;
2088 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
2089 pRtlFreeUnicodeString( &name_str );
2090
2091 U(io).Status = 0xdeadbeef;
2092 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
2093 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2094 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
2095 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2096 ok( !fileDeleted, "file should exist\n" );
2097 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2098 ok( !fileDeleted, "file should exist\n" );
2099
2100 CloseHandle( handle );
2101 HeapFree( GetProcessHeap(), 0, fri );
2102 delete_object( oldpath );
2103 delete_object( newpath );
2104
2105 /* oldpath is a file, newpath is a directory, Replace = TRUE */
2106 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2107 ok( res != 0, "failed to create temp file\n" );
2108 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2109 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2110
2111 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2112 ok( res != 0, "failed to create temp file\n" );
2113 DeleteFileW( newpath );
2114 success = CreateDirectoryW( newpath, NULL );
2115 ok( success != 0, "failed to create temp directory\n" );
2116 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2117 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + name_str.Length );
2118 fri->Replace = TRUE;
2119 fri->RootDir = NULL;
2120 fri->FileNameLength = name_str.Length;
2121 memcpy( fri->FileName, name_str.Buffer, name_str.Length );
2122 pRtlFreeUnicodeString( &name_str );
2123
2124 U(io).Status = 0xdeadbeef;
2125 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
2126 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2127 ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %x\n", res );
2128 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2129 ok( !fileDeleted, "file should exist\n" );
2130 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2131 ok( !fileDeleted, "file should exist\n" );
2132
2133 CloseHandle( handle );
2134 HeapFree( GetProcessHeap(), 0, fri );
2135 delete_object( oldpath );
2136 delete_object( newpath );
2137
2138 /* oldpath is a file, newpath doesn't exist, test with RootDir != NULL */
2139 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2140 ok( res != 0, "failed to create temp file\n" );
2141 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2142 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2143
2144 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2145 ok( res != 0, "failed to create temp file\n" );
2146 DeleteFileW( newpath );
2147 for (filename = newpath, p = newpath; *p; p++)
2148 if (*p == '\\') filename = p + 1;
2149 handle2 = CreateFileW( tmp_path, 0, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
2150 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2151
2152 fri = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_RENAME_INFORMATION) + lstrlenW(filename) * sizeof(WCHAR) );
2153 fri->Replace = FALSE;
2154 fri->RootDir = handle2;
2155 fri->FileNameLength = lstrlenW(filename) * sizeof(WCHAR);
2156 memcpy( fri->FileName, filename, fri->FileNameLength );
2157
2158 U(io).Status = 0xdeadbeef;
2159 res = pNtSetInformationFile( handle, &io, fri, sizeof(FILE_RENAME_INFORMATION) + fri->FileNameLength, FileRenameInformation );
2160 ok( U(io).Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %x\n", U(io).Status );
2161 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
2162 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2163 ok( fileDeleted, "file should not exist\n" );
2164 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2165 ok( !fileDeleted, "file should exist\n" );
2166
2167 fni = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR) );
2168 res = pNtQueryInformationFile( handle, &io, fni, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR), FileNameInformation );
2169 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
2170 fni->FileName[ fni->FileNameLength / sizeof(WCHAR) ] = 0;
2171 ok( !lstrcmpW(fni->FileName, newpath + 2), "FileName expected %s, got %s\n",
2172 wine_dbgstr_w(newpath + 2), wine_dbgstr_w(fni->FileName) );
2173 HeapFree( GetProcessHeap(), 0, fni );
2174
2175 CloseHandle( handle );
2176 CloseHandle( handle2 );
2177 HeapFree( GetProcessHeap(), 0, fri );
2178 delete_object( oldpath );
2179 delete_object( newpath );
2180 }
2181
2182 static void test_file_link_information(void)
2183 {
2184 static const WCHAR foo_txtW[] = {'\\','f','o','o','.','t','x','t',0};
2185 static const WCHAR fooW[] = {'f','o','o',0};
2186 WCHAR tmp_path[MAX_PATH], oldpath[MAX_PATH + 16], newpath[MAX_PATH + 16], *filename, *p;
2187 FILE_LINK_INFORMATION *fli;
2188 FILE_NAME_INFORMATION *fni;
2189 BOOL success, fileDeleted;
2190 UNICODE_STRING name_str;
2191 HANDLE handle, handle2;
2192 IO_STATUS_BLOCK io;
2193 NTSTATUS res;
2194
2195 GetTempPathW( MAX_PATH, tmp_path );
2196
2197 /* oldpath is a file, newpath doesn't exist */
2198 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2199 ok( res != 0, "failed to create temp file\n" );
2200 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2201 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2202
2203 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2204 ok( res != 0, "failed to create temp file\n" );
2205 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2206 DeleteFileW( newpath );
2207 fli = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_LINK_INFORMATION) + name_str.Length );
2208 fli->ReplaceIfExists = FALSE;
2209 fli->RootDirectory = NULL;
2210 fli->FileNameLength = name_str.Length;
2211 memcpy( fli->FileName, name_str.Buffer, name_str.Length );
2212 pRtlFreeUnicodeString( &name_str );
2213
2214 U(io).Status = 0xdeadbeef;
2215 res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
2216 ok( U(io).Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %x\n", U(io).Status );
2217 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
2218 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2219 ok( !fileDeleted, "file should exist\n" );
2220 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2221 ok( !fileDeleted, "file should exist\n" );
2222
2223 fni = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR) );
2224 res = pNtQueryInformationFile( handle, &io, fni, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR), FileNameInformation );
2225 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
2226 fni->FileName[ fni->FileNameLength / sizeof(WCHAR) ] = 0;
2227 ok( !lstrcmpW(fni->FileName, oldpath + 2), "FileName expected %s, got %s\n",
2228 wine_dbgstr_w(oldpath + 2), wine_dbgstr_w(fni->FileName) );
2229 HeapFree( GetProcessHeap(), 0, fni );
2230
2231 CloseHandle( handle );
2232 HeapFree( GetProcessHeap(), 0, fli );
2233 delete_object( oldpath );
2234 delete_object( newpath );
2235
2236 /* oldpath is a file, newpath is a file, ReplaceIfExists = FALSE */
2237 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2238 ok( res != 0, "failed to create temp file\n" );
2239 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2240 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2241
2242 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2243 ok( res != 0, "failed to create temp file\n" );
2244 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2245 fli = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_LINK_INFORMATION) + name_str.Length );
2246 fli->ReplaceIfExists = FALSE;
2247 fli->RootDirectory = NULL;
2248 fli->FileNameLength = name_str.Length;
2249 memcpy( fli->FileName, name_str.Buffer, name_str.Length );
2250 pRtlFreeUnicodeString( &name_str );
2251
2252 U(io).Status = 0xdeadbeef;
2253 res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
2254 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2255 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
2256 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2257 ok( !fileDeleted, "file should exist\n" );
2258 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2259 ok( !fileDeleted, "file should exist\n" );
2260
2261 CloseHandle( handle );
2262 HeapFree( GetProcessHeap(), 0, fli );
2263 delete_object( oldpath );
2264 delete_object( newpath );
2265
2266 /* oldpath is a file, newpath is a file, ReplaceIfExists = TRUE */
2267 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2268 ok( res != 0, "failed to create temp file\n" );
2269 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2270 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2271
2272 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2273 ok( res != 0, "failed to create temp file\n" );
2274 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2275 fli = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_LINK_INFORMATION) + name_str.Length );
2276 fli->ReplaceIfExists = TRUE;
2277 fli->RootDirectory = NULL;
2278 fli->FileNameLength = name_str.Length;
2279 memcpy( fli->FileName, name_str.Buffer, name_str.Length );
2280 pRtlFreeUnicodeString( &name_str );
2281
2282 U(io).Status = 0xdeadbeef;
2283 res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
2284 ok( U(io).Status == STATUS_SUCCESS, "io.Status expected STATUS_SUCCESS, got %x\n", U(io).Status );
2285 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
2286 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2287 ok( !fileDeleted, "file should exist\n" );
2288 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2289 ok( !fileDeleted, "file should exist\n" );
2290
2291 CloseHandle( handle );
2292 HeapFree( GetProcessHeap(), 0, fli );
2293 delete_object( oldpath );
2294 delete_object( newpath );
2295
2296 /* oldpath is a file, newpath is a file, ReplaceIfExists = FALSE, target file opened */
2297 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2298 ok( res != 0, "failed to create temp file\n" );
2299 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2300 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2301
2302 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2303 ok( res != 0, "failed to create temp file\n" );
2304 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2305 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2306
2307 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2308 fli = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_LINK_INFORMATION) + name_str.Length );
2309 fli->ReplaceIfExists = FALSE;
2310 fli->RootDirectory = NULL;
2311 fli->FileNameLength = name_str.Length;
2312 memcpy( fli->FileName, name_str.Buffer, name_str.Length );
2313 pRtlFreeUnicodeString( &name_str );
2314
2315 U(io).Status = 0xdeadbeef;
2316 res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
2317 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2318 ok( res == STATUS_OBJECT_NAME_COLLISION, "res expected STATUS_OBJECT_NAME_COLLISION, got %x\n", res );
2319 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2320 ok( !fileDeleted, "file should exist\n" );
2321 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2322 ok( !fileDeleted, "file should exist\n" );
2323
2324 CloseHandle( handle );
2325 CloseHandle( handle2 );
2326 HeapFree( GetProcessHeap(), 0, fli );
2327 delete_object( oldpath );
2328 delete_object( newpath );
2329
2330 /* oldpath is a file, newpath is a file, ReplaceIfExists = TRUE, target file opened */
2331 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2332 ok( res != 0, "failed to create temp file\n" );
2333 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2334 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2335
2336 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2337 ok( res != 0, "failed to create temp file\n" );
2338 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, 0, 0 );
2339 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2340
2341 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2342 fli = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_LINK_INFORMATION) + name_str.Length );
2343 fli->ReplaceIfExists = TRUE;
2344 fli->RootDirectory = NULL;
2345 fli->FileNameLength = name_str.Length;
2346 memcpy( fli->FileName, name_str.Buffer, name_str.Length );
2347 pRtlFreeUnicodeString( &name_str );
2348
2349 U(io).Status = 0xdeadbeef;
2350 res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
2351 todo_wine ok( U(io).Status == 0xdeadbeef, "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2352 ok( res == STATUS_ACCESS_DENIED, "res expected STATUS_ACCESS_DENIED, got %x\n", res );
2353 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2354 ok( !fileDeleted, "file should exist\n" );
2355 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2356 ok( !fileDeleted, "file should exist\n" );
2357
2358 CloseHandle( handle );
2359 CloseHandle( handle2 );
2360 HeapFree( GetProcessHeap(), 0, fli );
2361 delete_object( oldpath );
2362 delete_object( newpath );
2363
2364 /* oldpath is a directory, newpath doesn't exist, ReplaceIfExists = FALSE */
2365 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2366 ok( res != 0, "failed to create temp file\n" );
2367 DeleteFileW( oldpath );
2368 success = CreateDirectoryW( oldpath, NULL );
2369 ok( success != 0, "failed to create temp directory\n" );
2370 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
2371 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2372
2373 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2374 ok( res != 0, "failed to create temp file\n" );
2375 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2376 DeleteFileW( newpath );
2377 fli = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_LINK_INFORMATION) + name_str.Length );
2378 fli->ReplaceIfExists = FALSE;
2379 fli->RootDirectory = NULL;
2380 fli->FileNameLength = name_str.Length;
2381 memcpy( fli->FileName, name_str.Buffer, name_str.Length );
2382 pRtlFreeUnicodeString( &name_str );
2383
2384 U(io).Status = 0xdeadbeef;
2385 res = pNtSetInformationFile( handle, &io, fli, sizeof(FILE_LINK_INFORMATION) + fli->FileNameLength, FileLinkInformation );
2386 todo_wine ok( U(io).Status == 0xdeadbeef , "io.Status expected 0xdeadbeef, got %x\n", U(io).Status );
2387 ok( res == STATUS_FILE_IS_A_DIRECTORY, "res expected STATUS_FILE_IS_A_DIRECTORY, got %x\n", res );
2388 fileDeleted = GetFileAttributesW( oldpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2389 ok( !fileDeleted, "file should exist\n" );
2390 fileDeleted = GetFileAttributesW( newpath ) == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_FILE_NOT_FOUND;
2391 ok( fileDeleted, "file should not exist\n" );
2392
2393 fni = HeapAlloc( GetProcessHeap(), 0, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR) );
2394 res = pNtQueryInformationFile( handle, &io, fni, sizeof(FILE_NAME_INFORMATION) + MAX_PATH * sizeof(WCHAR), FileNameInformation );
2395 ok( res == STATUS_SUCCESS, "res expected STATUS_SUCCESS, got %x\n", res );
2396 fni->FileName[ fni->FileNameLength / sizeof(WCHAR) ] = 0;
2397 ok( !lstrcmpW(fni->FileName, oldpath + 2), "FileName expected %s, got %s\n",
2398 wine_dbgstr_w(oldpath + 2), wine_dbgstr_w(fni->FileName) );
2399 HeapFree( GetProcessHeap(), 0, fni );
2400
2401 CloseHandle( handle );
2402 HeapFree( GetProcessHeap(), 0, fli );
2403 delete_object( oldpath );
2404 delete_object( newpath );
2405
2406 /* oldpath is a directory (but child object opened), newpath doesn't exist, ReplaceIfExists = FALSE */
2407 res = GetTempFileNameW( tmp_path, fooW, 0, oldpath );
2408 ok( res != 0, "failed to create temp file\n" );
2409 DeleteFileW( oldpath );
2410 success = CreateDirectoryW( oldpath, NULL );
2411 ok( success != 0, "failed to create temp directory\n" );
2412 handle = CreateFileW( oldpath, GENERIC_WRITE | DELETE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0 );
2413 ok( handle != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2414
2415 lstrcpyW( newpath, oldpath );
2416 lstrcatW( newpath, foo_txtW );
2417 handle2 = CreateFileW( newpath, GENERIC_WRITE | DELETE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_DELETE_ON_CLOSE, 0 );
2418 ok( handle2 != INVALID_HANDLE_VALUE, "CreateFileW failed\n" );
2419
2420 res = GetTempFileNameW( tmp_path, fooW, 0, newpath );
2421 ok( res != 0, "failed to create temp file\n" );
2422 pRtlDosPathNameToNtPathName_U( newpath, &name_str, NULL, NULL );
2423 DeleteFileW( newpath );
2424 fli = HeapAlloc( GetProcessHeap(), 0, sizeof