ReactOS 0.4.17-dev-357-ga8f14ff
file.c
Go to the documentation of this file.
1/*
2 * Unit tests for file functions in Wine
3 *
4 * Copyright (c) 2002, 2004 Jakob Eriksson
5 * Copyright (c) 2008 Jeff Zaroyko
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 */
22
23#include <stdarg.h>
24#include <stdlib.h>
25#include <time.h>
26#include <stdio.h>
27
28#include "ntstatus.h"
29#define WIN32_NO_STATUS
30#include "wine/test.h"
31#include "windef.h"
32#include "winbase.h"
33#include "winerror.h"
34#include "winternl.h"
35#include "winnls.h"
36#include "fileapi.h"
37
38#undef DeleteFile /* needed for FILE_DISPOSITION_INFO */
39
41static BOOL (WINAPI *pReplaceFileW)(LPCWSTR, LPCWSTR, LPCWSTR, DWORD, LPVOID, LPVOID);
42static UINT (WINAPI *pGetSystemWindowsDirectoryA)(LPSTR, UINT);
43static BOOL (WINAPI *pGetVolumeNameForVolumeMountPointA)(LPCSTR, LPSTR, DWORD);
44static BOOL (WINAPI *pGetFileInformationByHandleEx)(HANDLE, FILE_INFO_BY_HANDLE_CLASS, LPVOID, DWORD);
46static BOOL (WINAPI *pSetFileValidData)(HANDLE, LONGLONG);
47static HRESULT (WINAPI *pCopyFile2)(PCWSTR,PCWSTR,COPYFILE2_EXTENDED_PARAMETERS*);
49static DWORD (WINAPI *pGetFinalPathNameByHandleA)(HANDLE, LPSTR, DWORD, DWORD);
53static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)(LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR*);
54static NTSTATUS (WINAPI *pRtlAnsiStringToUnicodeString)(PUNICODE_STRING, PCANSI_STRING, BOOLEAN);
55static BOOL (WINAPI *pSetFileInformationByHandle)(HANDLE, FILE_INFO_BY_HANDLE_CLASS, void*, DWORD);
56static BOOL (WINAPI *pGetQueuedCompletionStatusEx)(HANDLE, OVERLAPPED_ENTRY*, ULONG, ULONG*, DWORD, BOOL);
57static HANDLE (WINAPI *pReOpenFile)(HANDLE, DWORD, DWORD, DWORD);
58static void (WINAPI *pRtlInitAnsiString)(PANSI_STRING,PCSZ);
59static void (WINAPI *pRtlFreeUnicodeString)(PUNICODE_STRING);
60static BOOL (WINAPI *pSetFileCompletionNotificationModes)(HANDLE, UCHAR);
61static HANDLE (WINAPI *pFindFirstStreamW)(LPCWSTR filename, STREAM_INFO_LEVELS infolevel, void *data, DWORD flags);
62
63static char filename[MAX_PATH];
64static const char sillytext[] =
65"en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla."
66"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
67"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
68"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
69"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
70"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
71"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
72"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
73"1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
74"sdlkfjasdlkfj a dslkj adsklf \n \nasdklf askldfa sdlkf \nsadklf asdklf asdf ";
75
76struct test_list {
77 const char *file; /* file string to test */
78 const DWORD err; /* Win NT and further error code */
79 const LONG err2; /* Win 9x & ME error code or -1 */
80 const DWORD options; /* option flag to use for open */
81 const BOOL todo_flag; /* todo_wine indicator */
82} ;
83
84static void InitFunctionPointers(void)
85{
88
89 pNtCreateFile = (void *)GetProcAddress(hntdll, "NtCreateFile");
90 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
91 pRtlAnsiStringToUnicodeString = (void *)GetProcAddress(hntdll, "RtlAnsiStringToUnicodeString");
92 pRtlInitAnsiString = (void *)GetProcAddress(hntdll, "RtlInitAnsiString");
93 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
94
95 pFindFirstFileExA=(void*)GetProcAddress(hkernel32, "FindFirstFileExA");
96 pReplaceFileW=(void*)GetProcAddress(hkernel32, "ReplaceFileW");
97 pGetSystemWindowsDirectoryA=(void*)GetProcAddress(hkernel32, "GetSystemWindowsDirectoryA");
98 pGetVolumeNameForVolumeMountPointA = (void *) GetProcAddress(hkernel32, "GetVolumeNameForVolumeMountPointA");
99 pGetFileInformationByHandleEx = (void *) GetProcAddress(hkernel32, "GetFileInformationByHandleEx");
100 pOpenFileById = (void *) GetProcAddress(hkernel32, "OpenFileById");
101 pSetFileValidData = (void *) GetProcAddress(hkernel32, "SetFileValidData");
102 pCopyFile2 = (void *) GetProcAddress(hkernel32, "CopyFile2");
103 pCreateFile2 = (void *) GetProcAddress(hkernel32, "CreateFile2");
104 pGetFinalPathNameByHandleA = (void *) GetProcAddress(hkernel32, "GetFinalPathNameByHandleA");
105 pGetFinalPathNameByHandleW = (void *) GetProcAddress(hkernel32, "GetFinalPathNameByHandleW");
106 pSetFileInformationByHandle = (void *) GetProcAddress(hkernel32, "SetFileInformationByHandle");
107 pGetQueuedCompletionStatusEx = (void *) GetProcAddress(hkernel32, "GetQueuedCompletionStatusEx");
108 pReOpenFile = (void *) GetProcAddress(hkernel32, "ReOpenFile");
109 pSetFileCompletionNotificationModes = (void *)GetProcAddress(hkernel32, "SetFileCompletionNotificationModes");
110 pFindFirstStreamW = (void *)GetProcAddress(hkernel32, "FindFirstStreamW");
111}
112
113static void create_file( const char *path )
114{
115 FILE *f = fopen( path, "wb" );
116 fputs( path, f );
117 fclose( f );
118}
119
120static void test__hread( void )
121{
122 HFILE filehandle;
123 char buffer[10000];
124 LONG bytes_read;
125 LONG bytes_wanted;
126 LONG i;
127 BOOL ret;
128
129 SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL); /* be sure to remove stale files */
131 filehandle = _lcreat( filename, 0 );
132 if (filehandle == HFILE_ERROR)
133 {
134 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
135 return;
136 }
137
138 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
139
140 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
141
142 filehandle = _lopen( filename, OF_READ );
143
144 ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError( ) );
145
146 bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
147
148 ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
149
150 for (bytes_wanted = 0; bytes_wanted < lstrlenA( sillytext ); bytes_wanted++)
151 {
152 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
153 ok( _hread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
154 for (i = 0; i < bytes_wanted; i++)
155 {
156 ok( buffer[i] == sillytext[i], "that's not what's written\n" );
157 }
158 }
159
160 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
161
163 ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
164}
165
166
167static void test__hwrite( void )
168{
169 HFILE filehandle;
170 char buffer[10000];
171 LONG bytes_read;
172 LONG bytes_written;
174 LONG i;
175 char *contents;
176 HLOCAL memory_object;
177 char checksum[1];
178 BOOL ret;
179
180 filehandle = _lcreat( filename, 0 );
181 if (filehandle == HFILE_ERROR)
182 {
183 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
184 return;
185 }
186
187 ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains\n" );
188
189 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
190
191 filehandle = _lopen( filename, OF_READ );
192
193 bytes_read = _hread( filehandle, buffer, 1);
194
195 ok( 0 == bytes_read, "file read size error\n" );
196
197 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
198
199 filehandle = _lopen( filename, OF_READWRITE );
200
201 bytes_written = 0;
202 checksum[0] = '\0';
203 srand( (unsigned)time( NULL ) );
204 for (blocks = 0; blocks < 100; blocks++)
205 {
206 for (i = 0; i < (LONG)sizeof( buffer ); i++)
207 {
208 buffer[i] = rand( );
209 checksum[0] = checksum[0] + buffer[i];
210 }
211 ok( HFILE_ERROR != _hwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
212 bytes_written = bytes_written + sizeof( buffer );
213 }
214
215 ok( HFILE_ERROR != _hwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
216 bytes_written++;
217
218 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
219
220 memory_object = LocalAlloc( LPTR, bytes_written );
221
222 ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)\n" );
223
224 contents = LocalLock( memory_object );
225 ok( NULL != contents, "LocalLock whines\n" );
226
227 filehandle = _lopen( filename, OF_READ );
228
229 contents = LocalLock( memory_object );
230 ok( NULL != contents, "LocalLock whines\n" );
231
232 ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
233
234 checksum[0] = '\0';
235 i = 0;
236 do
237 {
238 checksum[0] = checksum[0] + contents[i];
239 i++;
240 }
241 while (i < bytes_written - 1);
242
243 ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
244
245 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
246
248 ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
249
251}
252
253
254static void test__lclose( void )
255{
256 HFILE filehandle;
257 BOOL ret;
258
259 filehandle = _lcreat( filename, 0 );
260 if (filehandle == HFILE_ERROR)
261 {
262 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
263 return;
264 }
265
266 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
267
268 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
269
271 ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
272}
273
274/* helper function for test__lcreat */
275static void get_nt_pathW( const char *name, UNICODE_STRING *nameW )
276{
280 BOOLEAN ret;
281
282 pRtlInitAnsiString( &str, name );
283
284 status = pRtlAnsiStringToUnicodeString( &strW, &str, TRUE );
285 ok( !status, "RtlAnsiStringToUnicodeString failed with %08lx\n", status );
286
287 ret = pRtlDosPathNameToNtPathName_U( strW.Buffer, nameW, NULL, NULL );
288 ok( ret, "RtlDosPathNameToNtPathName_U failed\n" );
289
290 pRtlFreeUnicodeString( &strW );
291}
292
293static void test__lcreat( void )
294{
298 HFILE filehandle;
299 char buffer[10000];
300 WIN32_FIND_DATAA search_results;
301 char slashname[] = "testfi/";
302 int err;
305 BOOL ret;
306
307 filehandle = _lcreat( filename, 0 );
308 if (filehandle == HFILE_ERROR)
309 {
310 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
311 return;
312 }
313
314 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
315
316 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
317
318 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
319
320 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
321
322 find = FindFirstFileA( filename, &search_results );
323 ok( INVALID_HANDLE_VALUE != find, "should be able to find file\n" );
324 FindClose( find );
325
327 ok( ret != 0, "DeleteFile failed (%ld)\n", GetLastError());
328
329 filehandle = _lcreat( filename, 1 ); /* readonly */
330 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
331
332 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less\n" );
333
334 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
335
336 find = FindFirstFileA( filename, &search_results );
337 ok( INVALID_HANDLE_VALUE != find, "should be able to find file\n" );
338 FindClose( find );
339
340 SetLastError( 0xdeadbeef );
341 ok( 0 == DeleteFileA( filename ), "shouldn't be able to delete a readonly file\n" );
342 ok( GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %ld\n", GetLastError() );
343
344 ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" );
345
346 ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file!\n" );
347
348 filehandle = _lcreat( filename, 1 ); /* readonly */
349 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError() );
350 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen(sillytext) ),
351 "_hwrite shouldn't be able to write never the less\n" );
352 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
353
354 find = FindFirstFileA( filename, &search_results );
355 ok( INVALID_HANDLE_VALUE != find, "should be able to find file\n" );
356 FindClose( find );
357
359 attr.Length = sizeof(attr);
360 attr.RootDirectory = 0;
361 attr.Attributes = OBJ_CASE_INSENSITIVE;
362 attr.ObjectName = &filenameW;
363 attr.SecurityDescriptor = NULL;
364 attr.SecurityQualityOfService = NULL;
365
366 status = pNtCreateFile( &file, GENERIC_READ | GENERIC_WRITE | DELETE, &attr, &io, NULL, 0,
369 ok( status == STATUS_ACCESS_DENIED, "expected STATUS_ACCESS_DENIED, got %08lx\n", status );
370 ok( GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES, "file was deleted\n" );
371
372 status = pNtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
375 ok( status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08lx\n", status );
376
377 status = pNtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
380 ok( status == STATUS_NOT_A_DIRECTORY, "expected STATUS_NOT_A_DIRECTORY, got %08lx\n", status );
381
382 status = pNtCreateFile( &file, DELETE, &attr, &io, NULL, 0,
386 ok( status == STATUS_CANNOT_DELETE, "expected STATUS_CANNOT_DELETE, got %08lx\n", status );
387 if (!status) CloseHandle( file );
388
389 pRtlFreeUnicodeString( &filenameW );
390
392 ok( GetFileAttributesA( filename ) != INVALID_FILE_ATTRIBUTES, "file was deleted\n" );
394 ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" );
396 ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file\n" );
397
398 filehandle = _lcreat( filename, 2 );
399 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
400
401 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
402
403 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
404
405 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
406
407 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
408
409 find = FindFirstFileA( filename, &search_results );
410 ok( INVALID_HANDLE_VALUE != find, "should STILL be able to find file\n" );
411 FindClose( find );
412
414 ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
415
416 filehandle = _lcreat( filename, 4 ); /* SYSTEM file */
417 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
418
419 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
420
421 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
422
423 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
424
425 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
426
427 find = FindFirstFileA( filename, &search_results );
428 ok( INVALID_HANDLE_VALUE != find, "should STILL be able to find file\n" );
429 FindClose( find );
430
432 ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
433
434 filehandle=_lcreat (slashname, 0); /* illegal name */
435 ok( filehandle == HFILE_ERROR, "succeeded\n" );
436 err=GetLastError ();
438 "creating file \"%s\" failed with error %d\n", slashname, err);
439
440 filehandle=_lcreat (filename, 8); /* illegal attribute */
441 if (HFILE_ERROR==filehandle)
442 ok (0, "couldn't create volume label \"%s\"\n", filename);
443 else {
444 _lclose(filehandle);
445 find=FindFirstFileA (filename, &search_results);
447 ok (0, "file \"%s\" not found\n", filename);
448 else {
449 const char *name = strrchr(filename, '\\');
450
451 if (name) name++;
452 else name = filename;
453
454 ret = FindClose(find);
455 ok ( 0 != ret, "FindClose complains (%ld)\n", GetLastError ());
456 ok (!strcmp (name, search_results.cFileName),
457 "expected \"%s\", got \"%s\"\n", name, search_results.cFileName);
458 search_results.dwFileAttributes &= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
459 search_results.dwFileAttributes &= ~FILE_ATTRIBUTE_COMPRESSED;
460 ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes,
461 "attributes of file \"%s\" are 0x%04lx\n", search_results.cFileName,
462 search_results.dwFileAttributes);
463 }
465 ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
466 }
467}
468
469
470static void test__llseek( void )
471{
472 INT i;
473 HFILE filehandle;
474 char buffer[1];
475 LONG bytes_read;
476 BOOL ret;
477
478 filehandle = _lcreat( filename, 0 );
479 if (filehandle == HFILE_ERROR)
480 {
481 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
482 return;
483 }
484
485 for (i = 0; i < 400; i++)
486 {
487 ok( _hwrite( filehandle, sillytext, strlen( sillytext ) ) != -1, "_hwrite complains\n" );
488 }
489 ok( _llseek( filehandle, 400 * strlen( sillytext ), FILE_CURRENT ) != -1, "should be able to seek\n" );
490 ok( _llseek( filehandle, 27 + 35 * strlen( sillytext ), FILE_BEGIN ) != -1, "should be able to seek\n" );
491
492 bytes_read = _hread( filehandle, buffer, 1);
493 ok( 1 == bytes_read, "file read size error\n" );
494 ok( buffer[0] == sillytext[27], "_llseek error, it got lost seeking\n" );
495 ok( _llseek( filehandle, -400 * (LONG)strlen( sillytext ), FILE_END ) != -1, "should be able to seek\n" );
496
497 bytes_read = _hread( filehandle, buffer, 1);
498 ok( 1 == bytes_read, "file read size error\n" );
499 ok( buffer[0] == sillytext[0], "_llseek error, it got lost seeking\n" );
500 ok( _llseek( filehandle, 1000000, FILE_END ) != -1, "should be able to seek past file; poor, poor Windows programmers\n" );
501 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
502
504 ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
505}
506
507
508static void test__llopen( void )
509{
510 HFILE filehandle;
511 UINT bytes_read;
512 char buffer[10000];
513 BOOL ret;
514
515 filehandle = _lcreat( filename, 0 );
516 if (filehandle == HFILE_ERROR)
517 {
518 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
519 return;
520 }
521
522 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
523 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
524
525 filehandle = _lopen( filename, OF_READ );
526 ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write!\n" );
527 bytes_read = _hread( filehandle, buffer, strlen( sillytext ) );
528 ok( strlen( sillytext ) == bytes_read, "file read size error\n" );
529 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
530
531 filehandle = _lopen( filename, OF_READWRITE );
532 bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
533 ok( strlen( sillytext ) == bytes_read, "file read size error\n" );
534 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
535 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
536
537 filehandle = _lopen( filename, OF_WRITE );
538 ok( HFILE_ERROR == _hread( filehandle, buffer, 1 ), "you should only be able to write this file\n" );
539 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
540 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
541
543 ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
544 /* TODO - add tests for the SHARE modes - use two processes to pull this one off */
545}
546
547
548static void test__lread( void )
549{
550 HFILE filehandle;
551 char buffer[10000];
552 UINT bytes_read;
553 UINT bytes_wanted;
554 UINT i;
555 BOOL ret;
556
557 filehandle = _lcreat( filename, 0 );
558 if (filehandle == HFILE_ERROR)
559 {
560 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
561 return;
562 }
563
564 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
565
566 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
567
568 filehandle = _lopen( filename, OF_READ );
569
570 ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError());
571
572 bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) );
573
574 ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
575
576 for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
577 {
578 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
579 ok( _lread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
580 for (i = 0; i < bytes_wanted; i++)
581 {
582 ok( buffer[i] == sillytext[i], "that's not what's written\n" );
583 }
584 }
585
586 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
587
589 ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
590}
591
592
593static void test__lwrite( void )
594{
595 HFILE filehandle;
596 char buffer[10000];
597 UINT bytes_read;
598 UINT bytes_written;
599 UINT blocks;
600 INT i;
601 char *contents;
602 HLOCAL memory_object;
603 char checksum[1];
604 BOOL ret;
605
606 filehandle = _lcreat( filename, 0 );
607 if (filehandle == HFILE_ERROR)
608 {
609 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
610 return;
611 }
612
613 ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains\n" );
614
615 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
616
617 filehandle = _lopen( filename, OF_READ );
618
619 bytes_read = _hread( filehandle, buffer, 1);
620
621 ok( 0 == bytes_read, "file read size error\n" );
622
623 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
624
625 filehandle = _lopen( filename, OF_READWRITE );
626
627 bytes_written = 0;
628 checksum[0] = '\0';
629 srand( (unsigned)time( NULL ) );
630 for (blocks = 0; blocks < 100; blocks++)
631 {
632 for (i = 0; i < (INT)sizeof( buffer ); i++)
633 {
634 buffer[i] = rand( );
635 checksum[0] = checksum[0] + buffer[i];
636 }
637 ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
638 bytes_written = bytes_written + sizeof( buffer );
639 }
640
641 ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
642 bytes_written++;
643
644 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
645
646 memory_object = LocalAlloc( LPTR, bytes_written );
647
648 ok( 0 != memory_object, "LocalAlloc fails, could be out of memory\n" );
649
650 contents = LocalLock( memory_object );
651 ok( NULL != contents, "LocalLock whines\n" );
652
653 filehandle = _lopen( filename, OF_READ );
654
655 contents = LocalLock( memory_object );
656 ok( NULL != contents, "LocalLock whines\n" );
657
658 ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
659
660 checksum[0] = '\0';
661 i = 0;
662 do
663 {
664 checksum[0] += contents[i];
665 i++;
666 }
667 while (i < bytes_written - 1);
668
669 ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
670
671 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
672
674 ok( ret, "DeleteFile failed (%ld)\n", GetLastError( ) );
675
677}
678
679static void test_CopyFileA(void)
680{
681 char temp_path[MAX_PATH];
683 static const char prefix[] = "pfx";
684 HANDLE hfile;
685 HANDLE hmapfile;
686 FILETIME ft1, ft2;
687 char buf[10];
688 DWORD ret;
689 BOOL retok;
690
692 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
693 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
694
696 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
697
698 /* copying a file to itself must fail */
699 retok = CopyFileA(source, source, FALSE);
700 ok( !retok && (GetLastError() == ERROR_SHARING_VIOLATION || broken(GetLastError() == ERROR_FILE_EXISTS) /* Win 9x */),
701 "copying a file to itself didn't fail (ret=%d, err=%ld)\n", retok, GetLastError());
702
703 /* make the source have not zero size */
704 hfile = CreateFileA(source, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
705 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
706 retok = WriteFile(hfile, prefix, sizeof(prefix), &ret, NULL );
707 ok( retok && ret == sizeof(prefix),
708 "WriteFile error %ld\n", GetLastError());
709 ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n");
710 /* get the file time and change it to prove the difference */
711 ret = GetFileTime(hfile, NULL, NULL, &ft1);
712 ok( ret, "GetFileTime error %ld\n", GetLastError());
713 ft1.dwLowDateTime -= 600000000; /* 60 second */
714 ret = SetFileTime(hfile, NULL, NULL, &ft1);
715 ok( ret, "SetFileTime error %ld\n", GetLastError());
716 GetFileTime(hfile, NULL, NULL, &ft1); /* get the actual time back */
717 CloseHandle(hfile);
718
720 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
721
722 SetLastError(0xdeadbeef);
725 "CopyFileA: unexpected error %ld\n", GetLastError());
726
728 ok(ret, "CopyFileA: error %ld\n", GetLastError());
729
730 /* NULL checks */
731 retok = CopyFileA(NULL, dest, TRUE);
732 ok(!retok && GetLastError() == ERROR_PATH_NOT_FOUND,
733 "CopyFileA: ret = %d, unexpected error %ld\n", retok, GetLastError());
734 retok = CopyFileA(source, NULL, TRUE);
735 ok(!retok && GetLastError() == ERROR_PATH_NOT_FOUND,
736 "CopyFileA: ret = %d, unexpected error %ld\n", retok, GetLastError());
737
738 /* copying from a read-locked source fails */
740 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %ld\n", GetLastError());
741 retok = CopyFileA(source, dest, FALSE);
743 "copying from a read-locked file succeeded when it shouldn't have\n");
744 /* in addition, the source is opened before the destination */
745 retok = CopyFileA("25f99d3b-4ba4-4f66-88f5-2906886993cc", dest, FALSE);
746 ok(!retok && GetLastError() == ERROR_FILE_NOT_FOUND,
747 "copying from a file that doesn't exist failed in an unexpected way (ret=%d, err=%ld)\n", retok, GetLastError());
748 CloseHandle(hfile);
749
750 /* copying from a r+w opened, r shared source succeeds */
752 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %ld\n", GetLastError());
753 retok = CopyFileA(source, dest, FALSE);
754 ok(retok,
755 "copying from an r+w opened and r shared file failed (ret=%d, err=%ld)\n", retok, GetLastError());
756 CloseHandle(hfile);
757
758 /* copying from a delete-locked source mostly succeeds */
760 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %ld\n", GetLastError());
761 retok = CopyFileA(source, dest, FALSE);
762 ok(retok || broken(!retok && GetLastError() == ERROR_SHARING_VIOLATION) /* NT, 2000, XP */,
763 "copying from a delete-locked file failed (ret=%d, err=%ld)\n", retok, GetLastError());
764 CloseHandle(hfile);
765
766 /* copying to a write-locked destination fails */
768 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
769 retok = CopyFileA(source, dest, FALSE);
771 "copying to a write-locked file didn't fail (ret=%d, err=%ld)\n", retok, GetLastError());
772 CloseHandle(hfile);
773
774 /* copying to a r+w opened, w shared destination mostly succeeds */
776 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
777 retok = CopyFileA(source, dest, FALSE);
778 ok(retok || broken(!retok && GetLastError() == ERROR_SHARING_VIOLATION) /* Win 9x */,
779 "copying to a r+w opened and w shared file failed (ret=%d, err=%ld)\n", retok, GetLastError());
780 CloseHandle(hfile);
781
782 /* copying to a delete-locked destination fails, even when the destination is delete-shared */
785 "failed to open destination file, error %ld\n", GetLastError());
786 if (hfile != INVALID_HANDLE_VALUE)
787 {
788 retok = CopyFileA(source, dest, FALSE);
790 "copying to a delete-locked shared file didn't fail (ret=%d, err=%ld)\n", retok, GetLastError());
791 CloseHandle(hfile);
792 }
793
794 /* copy to a file that's opened the way Wine opens the source */
796 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
797 retok = CopyFileA(source, dest, FALSE);
798 ok(retok || broken(GetLastError() == ERROR_SHARING_VIOLATION) /* Win 9x */,
799 "copying to a file opened the way Wine opens the source failed (ret=%d, err=%ld)\n", retok, GetLastError());
800 CloseHandle(hfile);
801
802 /* make sure that destination has correct size */
804 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
805 ret = GetFileSize(hfile, NULL);
806 ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret);
807
808 /* make sure that destination has the same filetime */
809 ret = GetFileTime(hfile, NULL, NULL, &ft2);
810 ok( ret, "GetFileTime error %ld\n", GetLastError());
811 ok(CompareFileTime(&ft1, &ft2) == 0, "destination file has wrong filetime\n");
812
813 SetLastError(0xdeadbeef);
816 "CopyFileA: ret = %ld, unexpected error %ld\n", ret, GetLastError());
817
818 /* make sure that destination still has correct size */
819 ret = GetFileSize(hfile, NULL);
820 ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret);
821 retok = ReadFile(hfile, buf, sizeof(buf), &ret, NULL);
822 ok( retok && ret == sizeof(prefix),
823 "ReadFile: error %ld\n", GetLastError());
824 ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n");
825
826 /* check error on copying over a mapped file that was opened with FILE_SHARE_READ */
827 hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
828 ok(hmapfile != NULL, "CreateFileMapping: error %ld\n", GetLastError());
829
832 "CopyFileA with mapped dest file: expected ERROR_SHARING_VIOLATION, got %ld\n", GetLastError());
833
834 CloseHandle(hmapfile);
835 CloseHandle(hfile);
836
838 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
839
840 /* check error on copying over a mapped file that was opened with FILE_SHARE_WRITE */
841 hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
842 ok(hmapfile != NULL, "CreateFileMapping: error %ld\n", GetLastError());
843
845 ok(!ret, "CopyFileA: expected failure\n");
848 "CopyFileA with mapped dest file: expected ERROR_USER_MAPPED_FILE, got %ld\n", GetLastError());
849
850 CloseHandle(hmapfile);
851 CloseHandle(hfile);
852
853 /* check read-only attribute */
855 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
856 ok(!(ret & FILE_ATTRIBUTE_READONLY), "source is read-only\n");
858 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
859 ok(!(ret & FILE_ATTRIBUTE_READONLY), "dest is read-only\n");
860
861 /* make source read-only */
863 ok(ret, "SetFileAttributesA: error %ld\n", GetLastError());
865 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
866 ok(ret & FILE_ATTRIBUTE_READONLY, "source is not read-only\n");
868 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
869 ok(!(ret & FILE_ATTRIBUTE_READONLY), "dest is read-only\n");
870
871 /* dest becomes read-only after copied from read-only source */
873 ok(ret, "SetFileAttributesA: error %ld\n", GetLastError());
875 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
876 ok(ret & FILE_ATTRIBUTE_READONLY, "source is not read-only\n");
878 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
879 ok(!(ret & FILE_ATTRIBUTE_READONLY), "dest is read-only\n");
880
882 ok(ret, "CopyFileA: error %ld\n", GetLastError());
884 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
885 ok(ret & FILE_ATTRIBUTE_READONLY, "dest is not read-only\n");
886
887 /* same when dest does not exist */
889 ok(ret, "SetFileAttributesA: error %ld\n", GetLastError());
891 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
893 ok(ret, "CopyFileA: error %ld\n", GetLastError());
895 ok(ret != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError());
896 ok(ret & FILE_ATTRIBUTE_READONLY, "dest is not read-only\n");
897
899 ok(ret, "SetFileAttributesA: error %ld\n", GetLastError());
901 ok(ret, "SetFileAttributesA: error %ld\n", GetLastError());
902
904 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
906 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
907}
908
909static void test_CopyFileW(void)
910{
913 static const WCHAR prefix[] = {'p','f','x',0};
914 DWORD ret;
915
918 {
919 win_skip("GetTempPathW is not available\n");
920 return;
921 }
922 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
923 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
924
926 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
927
929 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
930
933 "CopyFileW: unexpected error %ld\n", GetLastError());
934
935 SetLastError(0xdeadbeef);
937 ok(ret, "CopyFileW: error %ld\n", GetLastError());
938 ok(GetLastError() == ERROR_SUCCESS || broken(GetLastError() == ERROR_INVALID_PARAMETER) /* some win8 machines */,
939 "Unexpected error %lu.\n", GetLastError());
940
941 SetLastError(0xdeadbeef);
943 ok(ret, "CopyFileExW: error %ld\n", GetLastError());
944 ok(GetLastError() == ERROR_SUCCESS || broken(GetLastError() == ERROR_INVALID_PARAMETER) /* some win8 machines */,
945 "Unexpected error %lu.\n", GetLastError());
946
948 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
950 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
951}
952
953static void test_CopyFile2(void)
954{
955 static const WCHAR doesntexistW[] = {'d','o','e','s','n','t','e','x','i','s','t',0};
956 static const WCHAR prefix[] = {'p','f','x',0};
958 COPYFILE2_EXTENDED_PARAMETERS params;
959 HANDLE hfile, hmapfile;
960 FILETIME ft1, ft2;
961 DWORD ret, len;
962 char buf[10];
963 HRESULT hr;
964
965 if (!pCopyFile2)
966 {
967 todo_wine win_skip("CopyFile2 is not available\n");
968 return;
969 }
970
972 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
973 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
974
976 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
977
979 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
980
981 /* fail if exists */
982 memset(&params, 0, sizeof(params));
983 params.dwSize = sizeof(params);
984 params.dwCopyFlags = COPY_FILE_FAIL_IF_EXISTS;
985
986 SetLastError(0xdeadbeef);
987 hr = pCopyFile2(source, dest, &params);
988 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "CopyFile2: unexpected error 0x%08lx\n", hr);
989 ok(GetLastError() == ERROR_FILE_EXISTS, "CopyFile2: last error %ld\n", GetLastError());
990
991 /* don't fail if exists */
992 params.dwSize = sizeof(params);
993 params.dwCopyFlags = 0;
994
995 hr = pCopyFile2(source, dest, &params);
996 ok(hr == S_OK, "CopyFile2: error 0x%08lx\n", hr);
997
998 /* copying a file to itself must fail */
999 params.dwSize = sizeof(params);
1000 params.dwCopyFlags = 0;
1001
1002 SetLastError(0xdeadbeef);
1003 hr = pCopyFile2(source, source, &params);
1004 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: copying a file to itself didn't fail, 0x%08lx\n", hr);
1005 ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %ld\n", GetLastError());
1006
1007 /* make the source have not zero size */
1008 hfile = CreateFileW(source, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
1009 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
1010 ret = WriteFile(hfile, prefix, sizeof(prefix), &len, NULL );
1011 ok(ret && len == sizeof(prefix), "WriteFile error %ld\n", GetLastError());
1012 ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n");
1013
1014 /* get the file time and change it to prove the difference */
1015 ret = GetFileTime(hfile, NULL, NULL, &ft1);
1016 ok(ret, "GetFileTime error %ld\n", GetLastError());
1017 ft1.dwLowDateTime -= 600000000; /* 60 second */
1018 ret = SetFileTime(hfile, NULL, NULL, &ft1);
1019 ok(ret, "SetFileTime error %ld\n", GetLastError());
1020 GetFileTime(hfile, NULL, NULL, &ft1); /* get the actual time back */
1021 CloseHandle(hfile);
1022
1024 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
1025
1026 params.dwSize = sizeof(params);
1027 params.dwCopyFlags = COPY_FILE_FAIL_IF_EXISTS;
1028
1029 SetLastError(0xdeadbeef);
1030 hr = pCopyFile2(source, dest, &params);
1031 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_EXISTS), "CopyFile2: unexpected error 0x%08lx\n", hr);
1032 ok(GetLastError() == ERROR_FILE_EXISTS, "CopyFile2: last error %ld\n", GetLastError());
1033
1034 params.dwSize = sizeof(params);
1035 params.dwCopyFlags = 0;
1036 hr = pCopyFile2(source, dest, &params);
1037 ok(ret, "CopyFile2: error 0x%08lx\n", hr);
1038
1039 /* copying from a read-locked source fails */
1041 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %ld\n", GetLastError());
1042
1043 params.dwSize = sizeof(params);
1044 params.dwCopyFlags = 0;
1045 SetLastError(0xdeadbeef);
1046 hr = pCopyFile2(source, dest, &params);
1047 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08lx\n", hr);
1048 ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %ld\n", GetLastError());
1049
1050 /* in addition, the source is opened before the destination */
1051 params.dwSize = sizeof(params);
1052 params.dwCopyFlags = 0;
1053 SetLastError(0xdeadbeef);
1054 hr = pCopyFile2(doesntexistW, dest, &params);
1055 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08lx\n", hr);
1056 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "CopyFile2: last error %ld\n", GetLastError());
1057 CloseHandle(hfile);
1058
1059 /* copying from a r+w opened, r shared source succeeds */
1061 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %ld\n", GetLastError());
1062
1063 params.dwSize = sizeof(params);
1064 params.dwCopyFlags = 0;
1065 hr = pCopyFile2(source, dest, &params);
1066 ok(hr == S_OK, "failed 0x%08lx\n", hr);
1067 CloseHandle(hfile);
1068
1069 /* copying from a delete-locked source mostly succeeds */
1071 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file, error %ld\n", GetLastError());
1072
1073 params.dwSize = sizeof(params);
1074 params.dwCopyFlags = 0;
1075 hr = pCopyFile2(source, dest, &params);
1076 ok(hr == S_OK, "failed 0x%08lx\n", hr);
1077 CloseHandle(hfile);
1078
1079 /* copying to a write-locked destination fails */
1081 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
1082
1083 params.dwSize = sizeof(params);
1084 params.dwCopyFlags = 0;
1085 SetLastError(0xdeadbeef);
1086 hr = pCopyFile2(source, dest, FALSE);
1087 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08lx\n", hr);
1088 ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %ld\n", GetLastError());
1089 CloseHandle(hfile);
1090
1091 /* copying to a r+w opened, w shared destination mostly succeeds */
1093 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
1094
1095 params.dwSize = sizeof(params);
1096 params.dwCopyFlags = 0;
1097 hr = pCopyFile2(source, dest, FALSE);
1098 ok(hr == S_OK, "got 0x%08lx\n", hr);
1099 CloseHandle(hfile);
1100
1101 /* copying to a delete-locked destination fails, even when the destination is delete-shared */
1103 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
1104
1105 params.dwSize = sizeof(params);
1106 params.dwCopyFlags = 0;
1107 SetLastError(0xdeadbeef);
1108 hr = pCopyFile2(source, dest, &params);
1109 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08lx\n", hr);
1110 ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %ld\n", GetLastError());
1111 CloseHandle(hfile);
1112
1113 /* copy to a file that's opened the way Wine opens the source */
1115 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
1116
1117 params.dwSize = sizeof(params);
1118 params.dwCopyFlags = 0;
1119 hr = pCopyFile2(source, dest, &params);
1120 ok(hr == S_OK, "got 0x%08lx\n", hr);
1121 CloseHandle(hfile);
1122
1123 /* make sure that destination has correct size */
1125 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
1126 ret = GetFileSize(hfile, NULL);
1127 ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret);
1128
1129 /* make sure that destination has the same filetime */
1130 ret = GetFileTime(hfile, NULL, NULL, &ft2);
1131 ok(ret, "GetFileTime error %ld\n", GetLastError());
1132 ok(CompareFileTime(&ft1, &ft2) == 0, "destination file has wrong filetime\n");
1133
1134 params.dwSize = sizeof(params);
1135 params.dwCopyFlags = 0;
1136 SetLastError(0xdeadbeef);
1137 hr = pCopyFile2(source, dest, &params);
1138 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08lx\n", hr);
1139 ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %ld\n", GetLastError());
1140
1141 /* make sure that destination still has correct size */
1142 ret = GetFileSize(hfile, NULL);
1143 ok(ret == sizeof(prefix), "destination file has wrong size %ld\n", ret);
1144 ret = ReadFile(hfile, buf, sizeof(buf), &len, NULL);
1145 ok(ret && len == sizeof(prefix), "ReadFile: error %ld\n", GetLastError());
1146 ok(!memcmp(prefix, buf, sizeof(prefix)), "buffer contents mismatch\n");
1147
1148 /* check error on copying over a mapped file that was opened with FILE_SHARE_READ */
1149 hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
1150 ok(hmapfile != NULL, "CreateFileMapping: error %ld\n", GetLastError());
1151
1152 params.dwSize = sizeof(params);
1153 params.dwCopyFlags = 0;
1154 SetLastError(0xdeadbeef);
1155 hr = pCopyFile2(source, dest, &params);
1156 ok(hr == HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), "CopyFile2: unexpected error 0x%08lx\n", hr);
1157 ok(GetLastError() == ERROR_SHARING_VIOLATION, "CopyFile2: last error %ld\n", GetLastError());
1158
1159 CloseHandle(hmapfile);
1160 CloseHandle(hfile);
1161
1163 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file\n");
1164
1165 /* check error on copying over a mapped file that was opened with FILE_SHARE_WRITE */
1166 hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
1167 ok(hmapfile != NULL, "CreateFileMapping: error %ld\n", GetLastError());
1168
1169 params.dwSize = sizeof(params);
1170 params.dwCopyFlags = 0;
1171 hr = pCopyFile2(source, dest, &params);
1172 ok(hr == HRESULT_FROM_WIN32(ERROR_USER_MAPPED_FILE), "CopyFile2: unexpected error 0x%08lx\n", hr);
1173 ok(GetLastError() == ERROR_USER_MAPPED_FILE, "CopyFile2: last error %ld\n", GetLastError());
1174
1175 CloseHandle(hmapfile);
1176 CloseHandle(hfile);
1177
1180}
1181
1182static DWORD WINAPI copy_progress_cb(LARGE_INTEGER total_size, LARGE_INTEGER total_transferred,
1183 LARGE_INTEGER stream_size, LARGE_INTEGER stream_transferred,
1185{
1186 ok(reason == CALLBACK_STREAM_SWITCH, "expected CALLBACK_STREAM_SWITCH, got %lu\n", reason);
1187 CloseHandle(userdata);
1188 return PROGRESS_CANCEL;
1189}
1190
1191static void test_CopyFileEx(void)
1192{
1193 char temp_path[MAX_PATH];
1194 char source[MAX_PATH], dest[MAX_PATH];
1195 static const char prefix[] = "pfx";
1196 HANDLE hfile;
1197 DWORD ret;
1198 BOOL retok;
1199
1201 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
1202 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
1203
1205 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
1206
1208 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
1209
1211 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
1212 SetLastError(0xdeadbeef);
1213 retok = CopyFileExA(source, dest, copy_progress_cb, hfile, NULL, 0);
1214 todo_wine
1215 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1216 todo_wine
1217 ok(GetLastError() == ERROR_REQUEST_ABORTED, "expected ERROR_REQUEST_ABORTED, got %ld\n", GetLastError());
1218 ok(GetFileAttributesA(dest) != INVALID_FILE_ATTRIBUTES, "file was deleted\n");
1219
1221 NULL, OPEN_EXISTING, 0, 0);
1222 todo_wine
1223 ok(hfile != INVALID_HANDLE_VALUE, "failed to open destination file, error %ld\n", GetLastError());
1224 SetLastError(0xdeadbeef);
1225 retok = CopyFileExA(source, dest, copy_progress_cb, hfile, NULL, 0);
1226 todo_wine
1227 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1228 todo_wine
1229 ok(GetLastError() == ERROR_REQUEST_ABORTED, "expected ERROR_REQUEST_ABORTED, got %ld\n", GetLastError());
1230 todo_wine
1231 ok(GetFileAttributesA(dest) == INVALID_FILE_ATTRIBUTES, "file was not deleted\n");
1232
1233 retok = CopyFileExA(source, NULL, copy_progress_cb, hfile, NULL, 0);
1234 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1235 ok(GetLastError() == ERROR_PATH_NOT_FOUND, "expected ERROR_PATH_NOT_FOUND, got %ld\n", GetLastError());
1236 retok = CopyFileExA(NULL, dest, copy_progress_cb, hfile, NULL, 0);
1237 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1238 ok(GetLastError() == ERROR_PATH_NOT_FOUND, "expected ERROR_PATH_NOT_FOUND, got %ld\n", GetLastError());
1239
1241 ok(ret, "DeleteFileA failed with error %ld\n", GetLastError());
1242 ret = DeleteFileA(dest);
1243 ok(!ret, "DeleteFileA unexpectedly succeeded\n");
1244#ifdef __REACTOS__
1245 /* Cover ReactOS bug in CORE-10271:
1246 * BasepCopyFileExW was handling any set flags as COPY_FILE_FAIL_IF_EXISTS.
1247 * This affected CopyFileEx, PrivCopyFileEx, and MoveFileWithProgress */
1249 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
1250
1252 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
1253
1254 /* Only use the file name as target */
1255 ret = DeleteFileA(dest);
1256 ok(ret, "DeleteFileA unexpectedly failed\n");
1257
1258 retok = CopyFileExA(source, dest, NULL, NULL, FALSE, 0);
1259 ok(retok, "CopyFileExA unexpectedly failed\n");
1260 ok(GetLastError() == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", GetLastError());
1261
1262 /* Copy again overwriting the dest file */
1263 retok = CopyFileExA(source, dest, NULL, NULL, FALSE, 0);
1264 ok(retok, "CopyFileExA unexpectedly failed\n");
1265 ok(GetLastError() == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", GetLastError());
1266
1268
1270 ok(retok, "CopyFileExA unexpectedly failed\n");
1271 ok(GetLastError() == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", GetLastError());
1272
1274 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1275 ok(GetLastError() == ERROR_FILE_EXISTS, "expected ERROR_FILE_EXISTS, got %ld\n", GetLastError());
1276
1278 ok(retok, "CopyFileExA unexpectedly failed\n");
1279 ok(GetLastError() == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", GetLastError());
1280
1282 ok(retok, "CopyFileExA unexpectedly failed\n");
1283 ok(GetLastError() == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", GetLastError());
1284
1286 ok(retok, "CopyFileExA unexpectedly failed\n");
1287 ok(GetLastError() == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %ld\n", GetLastError());
1288
1290 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1291 ok(GetLastError() == ERROR_FILE_EXISTS, "expected ERROR_FILE_EXISTS, got %ld\n", GetLastError());
1292
1294 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1295 ok(GetLastError() == ERROR_FILE_EXISTS, "expected ERROR_FILE_EXISTS, got %ld\n", GetLastError());
1296
1298 ok(!retok, "CopyFileExA unexpectedly succeeded\n");
1299 ok(GetLastError() == ERROR_FILE_EXISTS, "expected ERROR_FILE_EXISTS, got %ld\n", GetLastError());
1300
1303#endif
1304}
1305
1306/*
1307 * Debugging routine to dump a buffer in a hexdump-like fashion.
1308 */
1309static void dumpmem(unsigned char *mem, int len)
1310{
1311 int x = 0;
1312 char hex[49], *p;
1313 char txt[17], *c;
1314
1315 while (x < len)
1316 {
1317 p = hex;
1318 c = txt;
1319 do {
1320 p += sprintf(p, "%02x ", mem[x]);
1321 *c++ = (mem[x] >= 32 && mem[x] <= 127) ? mem[x] : '.';
1322 } while (++x % 16 && x < len);
1323 *c = '\0';
1324 trace("%04x: %-48s- %s\n", x, hex, txt);
1325 }
1326}
1327
1328static void test_CreateFileA(void)
1329{
1330 HANDLE hFile;
1332 char filename[MAX_PATH];
1333 static const char prefix[] = "pfx";
1334 char windowsdir[MAX_PATH];
1335 char Volume_1[MAX_PATH];
1336 unsigned char buffer[512];
1337 char directory[] = "removeme";
1338 static const char nt_drive[] = "\\\\?\\A:";
1339 DWORD i, ret, len;
1340 static const struct test_list p[] =
1341 {
1342 {"", ERROR_PATH_NOT_FOUND, -1, FILE_ATTRIBUTE_NORMAL, TRUE }, /* dir as file w \ */
1344 {"a", ERROR_FILE_NOT_FOUND, -1, FILE_ATTRIBUTE_NORMAL, FALSE }, /* non-exist file */
1346 {"removeme", ERROR_ACCESS_DENIED, -1, FILE_ATTRIBUTE_NORMAL, FALSE }, /* exist dir w/o \ */
1347 {"removeme\\", ERROR_PATH_NOT_FOUND, -1, FILE_ATTRIBUTE_NORMAL, TRUE }, /* exst dir w \ */
1348 {"c:", ERROR_ACCESS_DENIED, ERROR_PATH_NOT_FOUND, FILE_ATTRIBUTE_NORMAL, FALSE }, /* device in file namespace */
1349 {"c:", ERROR_SUCCESS, ERROR_PATH_NOT_FOUND, FILE_FLAG_BACKUP_SEMANTICS, FALSE }, /* device in file namespace as dir */
1350 {"c:\\", ERROR_PATH_NOT_FOUND, ERROR_ACCESS_DENIED, FILE_ATTRIBUTE_NORMAL, TRUE }, /* root dir w \ */
1351 {"c:\\", ERROR_SUCCESS, ERROR_ACCESS_DENIED, FILE_FLAG_BACKUP_SEMANTICS, FALSE }, /* root dir w \ as dir */
1352 {"c:c:\\windows", ERROR_INVALID_NAME, -1, FILE_ATTRIBUTE_NORMAL, TRUE }, /* invalid path */
1353 {"\\\\?\\c:", ERROR_SUCCESS, ERROR_BAD_NETPATH, FILE_ATTRIBUTE_NORMAL,FALSE }, /* dev namespace drive */
1354 {"\\\\?\\c:\\", ERROR_PATH_NOT_FOUND, ERROR_BAD_NETPATH, FILE_ATTRIBUTE_NORMAL, TRUE }, /* dev namespace drive w \ */
1355 {NULL, 0, -1, 0, FALSE}
1356 };
1358 WCHAR curdir[MAX_PATH];
1359
1361 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
1362 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
1363
1365 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
1366
1367 SetLastError(0xdeadbeef);
1371 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
1372
1373 SetLastError(0xdeadbeef);
1377 "hFile %p, last error %lu\n", hFile, GetLastError());
1378
1380
1381 SetLastError(0xdeadbeef);
1385 "hFile %p, last error %lu\n", hFile, GetLastError());
1386
1388
1390 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
1391
1392 SetLastError(0xdeadbeef);
1396 "hFile %p, last error %lu\n", hFile, GetLastError());
1397
1399
1401 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
1402
1403 SetLastError(0xdeadbeef);
1405 ok(hFile == INVALID_HANDLE_VALUE, "hFile should have been INVALID_HANDLE_VALUE\n");
1407 broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* Win98 */
1408 "LastError should have been ERROR_INVALID_NAME or ERROR_FILE_NOT_FOUND but got %lu\n", GetLastError());
1409
1410 /* get windows drive letter */
1411 ret = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
1412 ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
1413 ok(ret != 0, "GetWindowsDirectory: error %ld\n", GetLastError());
1414
1415 /* test error return codes from CreateFile for some cases */
1417 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
1421 ok( ret, "Createdirectory failed, gle=%ld\n", GetLastError() );
1422 /* set current drive & directory to known location */
1425 i = 0;
1426 while (p[i].file)
1427 {
1428 filename[0] = 0;
1429 /* update the drive id in the table entry with the current one */
1430 if (p[i].file[1] == ':')
1431 {
1432 strcpy(filename, p[i].file);
1433 filename[0] = windowsdir[0];
1434 }
1435 else if (p[i].file[0] == '\\' && p[i].file[5] == ':')
1436 {
1437 strcpy(filename, p[i].file);
1438 filename[4] = windowsdir[0];
1439 }
1440 else
1441 {
1442 /* prefix the table entry with the current temp directory */
1444 strcat(filename, p[i].file);
1445 }
1449 p[i].options, NULL );
1450 /* if we get ACCESS_DENIED when we do not expect it, assume
1451 * no access to the volume
1452 */
1453 if (hFile == INVALID_HANDLE_VALUE &&
1456 {
1457 if (p[i].todo_flag)
1458 skip("Either no authority to volume, or is todo_wine for %s err=%ld should be %ld\n", filename, GetLastError(), p[i].err);
1459 else
1460 skip("Do not have authority to access volumes. Test for %s skipped\n", filename);
1461 }
1462 /* otherwise validate results with expectations */
1463 else
1464 {
1467 (p[i].err == GetLastError() || p[i].err2 == GetLastError())) ||
1469 "CreateFileA failed on %s, hFile %p, err=%lu, should be %lu\n",
1471 }
1473 CloseHandle( hFile );
1474 i++;
1475 }
1477 ok(ret, "RemoveDirectoryA: error %ld\n", GetLastError());
1478 SetCurrentDirectoryW(curdir);
1479
1480 /* test opening directory as a directory */
1483 NULL,
1487 {
1489 "CreateFileA did not work, last error %lu on volume <%s>\n",
1491
1493 {
1495 if (ret)
1496 {
1498 "CreateFileA probably did not open temp directory %s correctly\n file information does not include FILE_ATTRIBUTE_DIRECTORY, actual=0x%08lx\n",
1500 }
1501 CloseHandle( hFile );
1502 }
1503 }
1504 else
1505 skip("Probable Win9x, got ERROR_PATH_NOT_FOUND w/ FILE_FLAG_BACKUP_SEMANTICS or %s\n", temp_path);
1506
1507
1508 /* *** Test opening volumes/devices using drive letter *** */
1509
1510 /* test using drive letter in non-rewrite format without trailing \ */
1511 /* this should work */
1512 strcpy(filename, nt_drive);
1513 filename[4] = windowsdir[0];
1518 if (hFile != INVALID_HANDLE_VALUE ||
1520 {
1521 /* if we have adm rights to volume, then try rest of tests */
1522 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA did not open %s, last error=%lu\n",
1525 {
1526 /* if we opened the volume/device, try to read it. Since it */
1527 /* opened, we should be able to read it. We don't care about*/
1528 /* what the data is at this time. */
1529 len = 512;
1530 ret = ReadFile( hFile, buffer, len, &len, NULL );
1531 todo_wine ok(ret, "Failed to read volume, last error %lu, %lu, for %s\n",
1533 if (ret)
1534 {
1535 trace("buffer is\n");
1536 dumpmem(buffer, 64);
1537 }
1538 CloseHandle( hFile );
1539 }
1540
1541 /* test using drive letter with trailing \ and in non-rewrite */
1542 /* this should not work */
1543 strcpy(filename, nt_drive);
1544 filename[4] = windowsdir[0];
1545 strcat( filename, "\\" );
1550 todo_wine
1552 "CreateFileA should have returned ERROR_PATH_NOT_FOUND on %s, but got %lu\n",
1555 CloseHandle( hFile );
1556
1557 /* test using temp path with trailing \ and in non-rewrite as dir */
1558 /* this should work */
1559 strcpy(filename, nt_drive);
1560 filename[4] = 0;
1567 "CreateFileA should have worked on %s, but got %lu\n",
1570 CloseHandle( hFile );
1571
1572 /* test using drive letter without trailing \ and in device ns */
1573 /* this should work */
1574 strcpy(filename, nt_drive);
1575 filename[4] = windowsdir[0];
1576 filename[2] = '.';
1581 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA did not open %s, last error=%lu\n",
1584 CloseHandle( hFile );
1585 }
1586 /* If we see ERROR_BAD_NETPATH then on Win9x or WinME, so skip */
1587 else if (GetLastError() == ERROR_BAD_NETPATH)
1588 skip("Probable Win9x, got ERROR_BAD_NETPATH (53)\n");
1589 else
1590 skip("Do not have authority to access volumes. Tests skipped\n");
1591
1592
1593 /* *** Test opening volumes/devices using GUID *** */
1594
1595 if (pGetVolumeNameForVolumeMountPointA)
1596 {
1597 strcpy(filename, "c:\\");
1598 filename[0] = windowsdir[0];
1599 ret = pGetVolumeNameForVolumeMountPointA( filename, Volume_1, MAX_PATH );
1600 ok(ret, "GetVolumeNameForVolumeMountPointA failed, for %s, last error=%ld\n", filename, GetLastError());
1601 if (ret)
1602 {
1603 ok(strlen(Volume_1) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name <%s>\n", Volume_1);
1604
1605 /* test the result of opening a unique volume name (GUID)
1606 * with the trailing \
1607 * this should error out
1608 */
1609 strcpy(filename, Volume_1);
1614 todo_wine
1616 "CreateFileA should not have opened %s, hFile %p\n",
1617 filename, hFile);
1618 todo_wine
1620 "CreateFileA should have returned ERROR_PATH_NOT_FOUND on %s, but got %lu\n",
1623 CloseHandle( hFile );
1624
1625 /* test the result of opening a unique volume name (GUID)
1626 * with the temp path string as dir
1627 * this should work
1628 */
1629 strcpy(filename, Volume_1);
1635 todo_wine
1637 "CreateFileA should have opened %s, but got %lu\n",
1640 CloseHandle( hFile );
1641
1642 /* test the result of opening a unique volume name (GUID)
1643 * without the trailing \ and in device namespace
1644 * this should work
1645 */
1646 strcpy(filename, Volume_1);
1647 filename[2] = '.';
1648 filename[48] = 0;
1654 {
1655 /* if we have adm rights to volume, then try rest of tests */
1656 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA did not open %s, last error=%lu\n",
1659 {
1660 /* if we opened the volume/device, try to read it. Since it */
1661 /* opened, we should be able to read it. We don't care about*/
1662 /* what the data is at this time. */
1663 len = 512;
1664 ret = ReadFile( hFile, buffer, len, &len, NULL );
1665 todo_wine ok(ret, "Failed to read volume, last error %lu, %lu, for %s\n",
1667 if (ret)
1668 {
1669 trace("buffer is\n");
1670 dumpmem(buffer, 64);
1671 }
1672 CloseHandle( hFile );
1673 }
1674 }
1675 else
1676 skip("Do not have authority to access volumes. Tests skipped\n");
1677 }
1678 else
1679 win_skip("GetVolumeNameForVolumeMountPointA not functioning\n");
1680 }
1681 else
1682 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
1683}
1684
1685static void test_CreateFileW(void)
1686{
1687 HANDLE hFile;
1690 static const WCHAR emptyW[]={'\0'};
1691 static const WCHAR prefix[] = {'p','f','x',0};
1692 static const WCHAR bogus[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 };
1693 DWORD ret;
1694
1697 {
1698 win_skip("GetTempPathW is not available\n");
1699 return;
1700 }
1701 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
1702 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
1703
1705 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
1706
1707 SetLastError(0xdeadbeef);
1711 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
1712
1713 SetLastError(0xdeadbeef);
1717 "hFile %p, last error %lu\n", hFile, GetLastError());
1718
1720
1721 SetLastError(0xdeadbeef);
1725 "hFile %p, last error %lu\n", hFile, GetLastError());
1726
1728
1730 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
1731
1732 SetLastError(0xdeadbeef);
1736 "hFile %p, last error %lu\n", hFile, GetLastError());
1737
1739
1741 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
1742
1743 if (0)
1744 {
1745 /* this crashes on NT4.0 */
1749 "CreateFileW(NULL) returned ret=%p error=%lu\n",hFile,GetLastError());
1750 }
1751
1755 "CreateFileW(\"\") returned ret=%p error=%ld\n",hFile,GetLastError());
1756
1757 /* test the result of opening a nonexistent driver name */
1761 "CreateFileW on invalid VxD name returned ret=%p error=%ld\n",hFile,GetLastError());
1762
1764 ok(ret == TRUE, "couldn't create temporary directory\n");
1768 "expected CreateFile to succeed on existing directory, error: %ld\n", GetLastError());
1771 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
1772}
1773
1774static void test_CreateFile2(void)
1775{
1776 HANDLE hFile, iocp;
1780 static const WCHAR emptyW[]={'\0'};
1781 static const WCHAR prefix[] = {'p','f','x',0};
1782 static const WCHAR bogus[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 };
1783 DWORD i, ret;
1784
1785 if (!pCreateFile2)
1786 {
1787 win_skip("CreateFile2 is missing\n");
1788 return;
1789 }
1790
1792 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
1793 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
1794
1796 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
1797
1798 SetLastError(0xdeadbeef);
1799 exparams.dwSize = sizeof(exparams);
1800 exparams.dwFileAttributes = 0;
1802 exparams.dwSecurityQosFlags = 0;
1803 exparams.lpSecurityAttributes = NULL;
1804 exparams.hTemplateFile = 0;
1805 hFile = pCreateFile2(filename, GENERIC_READ, 0, CREATE_NEW, &exparams);
1807 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
1808
1809 SetLastError(0xdeadbeef);
1810 hFile = pCreateFile2(filename, GENERIC_READ, FILE_SHARE_READ, CREATE_ALWAYS, &exparams);
1812 "hFile %p, last error %lu\n", hFile, GetLastError());
1814
1815 SetLastError(0xdeadbeef);
1816 hFile = pCreateFile2(filename, GENERIC_READ, FILE_SHARE_READ, OPEN_ALWAYS, &exparams);
1818 "hFile %p, last error %lu\n", hFile, GetLastError());
1820
1822 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
1823
1824 SetLastError(0xdeadbeef);
1825 hFile = pCreateFile2(filename, GENERIC_READ, FILE_SHARE_READ, OPEN_ALWAYS, &exparams);
1827 "hFile %p, last error %lu\n", hFile, GetLastError());
1829
1831 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
1832
1833 hFile = pCreateFile2(emptyW, GENERIC_READ, 0, CREATE_NEW, &exparams);
1835 "CreateFile2(\"\") returned ret=%p error=%ld\n",hFile,GetLastError());
1836
1837 /* test the result of opening a nonexistent driver name */
1839 hFile = pCreateFile2(bogus, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, &exparams);
1841 "CreateFile2 on invalid VxD name returned ret=%p error=%ld\n",hFile,GetLastError());
1842
1844 ok(ret == TRUE, "couldn't create temporary directory\n");
1847 SetLastError(0xdeadbeef);
1848 hFile = pCreateFile2(filename, GENERIC_READ | GENERIC_WRITE, 0, OPEN_ALWAYS, &exparams);
1850 "CreateFile2 failed with FILE_FLAG_BACKUP_SEMANTICS on existing directory, error: %ld\n", GetLastError());
1853 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
1854
1855 for (i = 0; i < 2; ++i)
1856 {
1857 memset(&exparams, 0, sizeof(exparams));
1858 exparams.dwSize = sizeof(exparams);
1859 if (i == 0)
1860 {
1863 }
1864 else
1865 {
1868 }
1869
1870 SetLastError(0xdeadbeef);
1871 hFile = pCreateFile2(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, CREATE_ALWAYS, &exparams);
1872 ok(hFile != INVALID_HANDLE_VALUE && GetLastError() == 0, "%ld: hFile %p, last error %lu\n", i, hFile, GetLastError());
1873
1874 iocp = CreateIoCompletionPort(hFile, NULL, 0, 2);
1875 if (i == 1) ok(iocp == NULL && GetLastError() == ERROR_INVALID_PARAMETER, "%ld: CreateIoCompletionPort returned %p, error %lu\n", i, iocp, GetLastError());
1876 else ok(iocp != INVALID_HANDLE_VALUE && GetLastError() == 0, "%ld: CreateIoCompletionPort returned %p, error %lu\n", i, iocp, GetLastError());
1877
1878 CloseHandle(iocp);
1880
1882 if (i == 1) ok(ret, "%ld: unexpected DeleteFileW failure, error %lu\n", i, GetLastError());
1883 else ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "%ld: unexpected DeleteFileW result, ret %ld error %lu\n", i, ret, GetLastError());
1884 }
1885}
1886
1887static void test_GetTempFileNameA(void)
1888{
1889 UINT result;
1890 char out[MAX_PATH];
1891 char expected[MAX_PATH + 10];
1892 char windowsdir[MAX_PATH + 10];
1893 char windowsdrive[3];
1894
1895 result = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
1896 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
1897 ok(result != 0, "GetWindowsDirectory: error %ld\n", GetLastError());
1898
1899 /* If the Windows directory is the root directory, it ends in backslash, not else. */
1900 if (strlen(windowsdir) != 3) /* As in "C:\" or "F:\" */
1901 {
1902 strcat(windowsdir, "\\");
1903 }
1904
1905 windowsdrive[0] = windowsdir[0];
1906 windowsdrive[1] = windowsdir[1];
1907 windowsdrive[2] = '\0';
1908
1909 result = GetTempFileNameA(windowsdrive, "abc", 1, out);
1910 ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError());
1911 ok(((out[0] == windowsdrive[0]) && (out[1] == ':')) && (out[2] == '\\'),
1912 "GetTempFileNameA: first three characters should be %c:\\, string was actually %s\n",
1913 windowsdrive[0], out);
1914
1915 result = GetTempFileNameA(windowsdir, "abc", 2, out);
1916 ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError());
1917 expected[0] = '\0';
1918 strcat(expected, windowsdir);
1919 strcat(expected, "abc2.tmp");
1920 ok(lstrcmpiA(out, expected) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n",
1921 out, expected);
1922}
1923
1924static void test_DeleteFileA( void )
1925{
1926 BOOL ret;
1928 HANDLE hfile, mapping;
1929 char **argv;
1930
1931 ret = DeleteFileA(NULL);
1934 "DeleteFileA(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
1935
1936 ret = DeleteFileA("");
1939 "DeleteFileA(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
1940
1941 ret = DeleteFileA("nul");
1946 "DeleteFileA(\"nul\") returned ret=%d error=%ld\n",ret,GetLastError());
1947
1948 ret = DeleteFileA("nonexist.txt");
1949 ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "DeleteFileA(\"nonexist.txt\") returned ret=%d error=%ld\n",ret,GetLastError());
1950
1953
1954 SetLastError(0xdeadbeef);
1956 ok(hfile != INVALID_HANDLE_VALUE, "CreateFile error %ld\n", GetLastError());
1957
1958 SetLastError(0xdeadbeef);
1960 ok(ret, "DeleteFile error %ld\n", GetLastError());
1961
1962 SetLastError(0xdeadbeef);
1963 ret = CloseHandle(hfile);
1964 ok(ret, "CloseHandle error %ld\n", GetLastError());
1966 ok(!ret, "DeleteFile should fail\n");
1967
1968 SetLastError(0xdeadbeef);
1969 ret = CreateDirectoryA("testdir", NULL);
1970 ok(ret, "CreateDirectory failed, got err %ld\n", GetLastError());
1971 ret = DeleteFileA("testdir");
1973 "Expected ERROR_ACCESS_DENIED, got error %ld\n", GetLastError());
1974 ret = RemoveDirectoryA("testdir");
1975 ok(ret, "Remove a directory failed, got error %ld\n", GetLastError());
1976
1978
1980 ok(ret, "got error %lu\n", GetLastError());
1982 ok(hfile != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
1983
1985 ok(!!mapping, "got error %lu\n", GetLastError());
1986
1987 SetLastError(0xdeadbeef);
1989 ok(!ret, "expected failure\n");
1990 ok(GetLastError() == ERROR_ACCESS_DENIED, "got error %lu\n", GetLastError());
1991
1993
1995 ok(ret, "got error %lu\n", GetLastError());
1996
1997 CloseHandle(hfile);
1998}
1999
2000static void test_DeleteFileW( void )
2001{
2002 BOOL ret;
2004 WCHAR pathsubW[MAX_PATH];
2005 static const WCHAR dirW[] = {'d','e','l','e','t','e','f','i','l','e',0};
2006 static const WCHAR subdirW[] = {'\\','s','u','b',0};
2007 static const WCHAR emptyW[]={'\0'};
2008
2009 ret = DeleteFileW(NULL);
2011 {
2012 win_skip("DeleteFileW is not available\n");
2013 return;
2014 }
2016 "DeleteFileW(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
2017
2020 "DeleteFileW(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
2021
2022 /* test DeleteFile on empty directory */
2024 if (ret + ARRAY_SIZE(dirW)-1 + ARRAY_SIZE(subdirW)-1 >= MAX_PATH)
2025 {
2026 ok(0, "MAX_PATH exceeded in constructing paths\n");
2027 return;
2028 }
2029 lstrcatW(pathW, dirW);
2030 lstrcpyW(pathsubW, pathW);
2031 lstrcatW(pathsubW, subdirW);
2033 ok(ret == TRUE, "couldn't create directory deletefile\n");
2035 ok(ret == FALSE, "DeleteFile should fail for empty directories\n");
2037 ok(ret == TRUE, "expected to remove directory deletefile\n");
2038
2039 /* test DeleteFile on non-empty directory */
2041 ok(ret == TRUE, "couldn't create directory deletefile\n");
2042 ret = CreateDirectoryW(pathsubW, NULL);
2043 ok(ret == TRUE, "couldn't create directory deletefile\\sub\n");
2045 ok(ret == FALSE, "DeleteFile should fail for non-empty directories\n");
2046 ret = RemoveDirectoryW(pathsubW);
2047 ok(ret == TRUE, "expected to remove directory deletefile\\sub\n");
2049 ok(ret == TRUE, "expected to remove directory deletefile\n");
2050}
2051
2052#define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
2053
2054static void test_MoveFileA(void)
2055{
2056 char tempdir[MAX_PATH];
2057 char source[MAX_PATH], dest[MAX_PATH];
2058 static const char prefix[] = "pfx";
2060 HANDLE hfile;
2061 HANDLE hmapfile;
2062 DWORD ret;
2063 BOOL retok;
2064
2065 ret = GetTempPathA(MAX_PATH, tempdir);
2066 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
2067 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
2068
2069 ret = GetTempFileNameA(tempdir, prefix, 0, source);
2070 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
2071
2072 ret = GetTempFileNameA(tempdir, prefix, 0, dest);
2073 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
2074
2076 ok(ret, "MoveFileA: failed, error %ld\n", GetLastError());
2077
2080 "MoveFileA: unexpected error %ld\n", GetLastError());
2081
2082 ret = DeleteFileA(dest);
2083 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
2084
2086 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
2087
2088 retok = WriteFile(hfile, prefix, sizeof(prefix), &ret, NULL );
2089 ok( retok && ret == sizeof(prefix),
2090 "WriteFile error %ld\n", GetLastError());
2091
2092 hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
2093 ok(hmapfile != NULL, "CreateFileMapping: error %ld\n", GetLastError());
2094
2096 ok(!ret, "MoveFileA: expected failure\n");
2098 broken(GetLastError() == ERROR_ACCESS_DENIED), /* Win9x and WinMe */
2099 "MoveFileA: expected ERROR_SHARING_VIOLATION, got %ld\n", GetLastError());
2100
2101 CloseHandle(hmapfile);
2102 CloseHandle(hfile);
2103
2104 /* if MoveFile succeeded, move back to dest */
2105 if (ret) MoveFileA(dest, source);
2106
2108 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
2109
2110 hmapfile = CreateFileMappingW(hfile, NULL, PAGE_READONLY | SEC_COMMIT, 0, 0, NULL);
2111 ok(hmapfile != NULL, "CreateFileMapping: error %ld\n", GetLastError());
2112
2114 ok(!ret, "MoveFileA: expected failure\n");
2116 broken(GetLastError() == ERROR_ACCESS_DENIED), /* Win9x and WinMe */
2117 "MoveFileA: expected ERROR_SHARING_VIOLATION, got %ld\n", GetLastError());
2118
2119 CloseHandle(hmapfile);
2120 CloseHandle(hfile);
2121
2122 /* if MoveFile succeeded, move back to dest */
2123 if (ret) MoveFileA(dest, source);
2124
2126 ok(ret, "MoveFileA: failed, error %ld\n", GetLastError());
2127
2128 lstrcatA(tempdir, "Remove Me");
2129
2130 /* test renaming a file "Remove Me" to itself but in lowercase "me" */
2131 lstrcpyA(source, tempdir);
2132 tempdir[lstrlenA(tempdir) - 2] = 'm';
2133
2135 ok(hfile != INVALID_HANDLE_VALUE, "failed to create %s\n", source);
2136 CloseHandle(hfile);
2137
2138 ret = MoveFileA(source, tempdir);
2139 ok(ret, "MoveFileA: failed, error %ld\n", GetLastError());
2140
2141 hfile = FindFirstFileA(tempdir, &find_data);
2142 ok(hfile != INVALID_HANDLE_VALUE, "FindFirstFileA: failed, error %ld\n", GetLastError());
2143 if (hfile != INVALID_HANDLE_VALUE)
2144 {
2145 todo_wine ok(!lstrcmpA(strrchr(tempdir, '\\') + 1, find_data.cFileName),
2146 "MoveFile failed to change casing on same file: got %s\n", find_data.cFileName);
2147 }
2148 CloseHandle(hfile);
2149
2150 /* test renaming another file "Remove Be" to "Remove Me", which replaces the existing "Remove me" */
2151 tempdir[lstrlenA(tempdir) - 2] = 'B';
2152
2154 ok(hfile != INVALID_HANDLE_VALUE, "failed to create %s\n", tempdir);
2155 CloseHandle(hfile);
2156
2157 ret = MoveFileA(tempdir, source);
2158 ok(!ret, "MoveFileA: expected failure\n");
2159 ok(GetLastError() == ERROR_ALREADY_EXISTS, "MoveFileA: expected ERROR_ALREADY_EXISTS, got %ld\n", GetLastError());
2161 ok(ret, "MoveFileExA: failed, error %ld\n", GetLastError());
2162
2163 tempdir[lstrlenA(tempdir) - 2] = 'm';
2164
2165 hfile = FindFirstFileA(tempdir, &find_data);
2166 ok(hfile != INVALID_HANDLE_VALUE, "FindFirstFileA: failed, error %ld\n", GetLastError());
2167 if (hfile != INVALID_HANDLE_VALUE)
2168 {
2169 ok(!lstrcmpA(strrchr(source, '\\') + 1, find_data.cFileName),
2170 "MoveFile failed to change casing on existing target file: got %s\n", find_data.cFileName);
2171 }
2172 CloseHandle(hfile);
2173
2174 ret = DeleteFileA(tempdir);
2175 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
2176
2177 /* now test a directory from "Remove me" to uppercase "Me" */
2178 ret = CreateDirectoryA(tempdir, NULL);
2179 ok(ret == TRUE, "CreateDirectoryA failed\n");
2180
2181 lstrcpyA(source, tempdir);
2182 tempdir[lstrlenA(tempdir) - 2] = 'M';
2183 ret = MoveFileA(source, tempdir);
2184 ok(ret, "MoveFileA: failed, error %ld\n", GetLastError());
2185
2186 hfile = FindFirstFileA(tempdir, &find_data);
2187 ok(hfile != INVALID_HANDLE_VALUE, "FindFirstFileA: failed, error %ld\n", GetLastError());
2188 if (hfile != INVALID_HANDLE_VALUE)
2189 {
2190 todo_wine ok(!lstrcmpA(strrchr(tempdir, '\\') + 1, find_data.cFileName),
2191 "MoveFile failed to change casing on same directory: got %s\n", find_data.cFileName);
2192 }
2193 CloseHandle(hfile);
2194
2196 lstrcpyA(dest, tempdir);
2197 lstrcatA(dest, "\\wild?.*");
2198 /* FIXME: if we create a file with wildcards we can't delete it now that DeleteFile works correctly */
2200 ok(!ret, "MoveFileA: shouldn't move to wildcard file\n");
2201 ok(GetLastError() == ERROR_INVALID_NAME || /* NT */
2202 GetLastError() == ERROR_FILE_NOT_FOUND, /* Win9x */
2203 "MoveFileA: with wildcards, unexpected error %ld\n", GetLastError());
2204 if (ret || (GetLastError() != ERROR_INVALID_NAME))
2205 {
2207 char temppath[MAX_PATH];
2208 HANDLE hFind;
2209
2210 lstrcpyA(temppath, tempdir);
2211 lstrcatA(temppath, "\\*.*");
2212 hFind = FindFirstFileA(temppath, &fd);
2213 if (INVALID_HANDLE_VALUE != hFind)
2214 {
2215 LPSTR lpName;
2216 do
2217 {
2218 lpName = fd.cAlternateFileName;
2219 if (!lpName[0])
2220 lpName = fd.cFileName;
2221 ok(IsDotDir(lpName), "MoveFileA: wildcards file created!\n");
2222 }
2223 while (FindNextFileA(hFind, &fd));
2224 FindClose(hFind);
2225 }
2226 }
2228 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
2229 ret = DeleteFileA(dest);
2230 ok(!ret, "DeleteFileA: error %ld\n", GetLastError());
2231 ret = RemoveDirectoryA(tempdir);
2232 ok(ret, "DeleteDirectoryA: error %ld\n", GetLastError());
2233}
2234
2235static void test_MoveFileW(void)
2236{
2239 static const WCHAR prefix[] = {'p','f','x',0};
2240 DWORD ret;
2241
2244 {
2245 win_skip("GetTempPathW is not available\n");
2246 return;
2247 }
2248 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
2249 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
2250
2252 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
2253
2255 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
2256
2259 "MoveFileW: unexpected error %ld\n", GetLastError());
2260
2262 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
2263 ret = DeleteFileW(dest);
2264 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
2265}
2266
2267#define PATTERN_OFFSET 0x10
2268
2270{
2271 HANDLE hFile;
2272 OVERLAPPED ov;
2273 DWORD done, offset;
2274 BOOL rc;
2275 BYTE buf[256], pattern[] = "TeSt";
2276 UINT i;
2277 char temp_path[MAX_PATH], temp_fname[MAX_PATH];
2278 BOOL ret;
2279
2281 ok( ret, "GetTempPathA error %ld\n", GetLastError());
2282 ret =GetTempFileNameA(temp_path, "pfx", 0, temp_fname);
2283 ok( ret, "GetTempFileNameA error %ld\n", GetLastError());
2284
2285 /*** Write File *****************************************************/
2286
2288 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
2289
2290 for(i = 0; i < sizeof(buf); i++) buf[i] = i;
2291 ret = WriteFile(hFile, buf, sizeof(buf), &done, NULL);
2292 ok( ret, "WriteFile error %ld\n", GetLastError());
2293 ok(done == sizeof(buf), "expected number of bytes written %lu\n", done);
2294
2295 memset(&ov, 0, sizeof(ov));
2297 ov.OffsetHigh = 0;
2298 rc=WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
2299 /* Win 9x does not support the overlapped I/O on files */
2301 ok(rc, "WriteFile error %ld\n", GetLastError());
2302 ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
2304 ok(offset == PATTERN_OFFSET + sizeof(pattern), "wrong file offset %ld\n", offset);
2305
2306 ov.Offset = sizeof(buf) * 2;
2307 ov.OffsetHigh = 0;
2308 ret = WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
2309 ok( ret, "WriteFile error %ld\n", GetLastError());
2310 ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
2312 ok(offset == sizeof(buf) * 2 + sizeof(pattern), "wrong file offset %ld\n", offset);
2313 }
2314
2316
2317 /*** Read File *****************************************************/
2318
2319 hFile = CreateFileA(temp_fname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
2320 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
2321
2322 memset(buf, 0, sizeof(buf));
2323 memset(&ov, 0, sizeof(ov));
2325 ov.OffsetHigh = 0;
2326 rc=ReadFile(hFile, buf, sizeof(pattern), &done, &ov);
2327 /* Win 9x does not support the overlapped I/O on files */
2329 ok(rc, "ReadFile error %ld\n", GetLastError());
2330 ok(done == sizeof(pattern), "expected number of bytes read %lu\n", done);
2332 ok(offset == PATTERN_OFFSET + sizeof(pattern), "wrong file offset %ld\n", offset);
2333 ok(!memcmp(buf, pattern, sizeof(pattern)), "pattern match failed\n");
2334 }
2335
2337
2338 ret = DeleteFileA(temp_fname);
2339 ok( ret, "DeleteFileA error %ld\n", GetLastError());
2340}
2341
2342static void test_LockFile(void)
2343{
2344 HANDLE handle, handle2;
2345 DWORD written;
2347 int limited_LockFile;
2348 int limited_UnLockFile;
2349 BOOL ret;
2350
2353 CREATE_ALWAYS, 0, 0 );
2355 {
2356 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
2357 return;
2358 }
2361 OPEN_EXISTING, 0, 0 );
2362 if (handle2 == INVALID_HANDLE_VALUE)
2363 {
2364 ok( 0, "couldn't open file \"%s\" (err=%ld)\n", filename, GetLastError() );
2365 goto cleanup;
2366 }
2367 ok( WriteFile( handle, sillytext, strlen(sillytext), &written, NULL ), "write failed\n" );
2368
2369 ok( LockFile( handle, 0, 0, 0, 0 ), "LockFile failed\n" );
2370 ok( UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile failed\n" );
2371
2372 limited_UnLockFile = 0;
2373 if (UnlockFile( handle, 0, 0, 0, 0 ))
2374 {
2375 limited_UnLockFile = 1;
2376 }
2377
2378 ok( LockFile( handle, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
2379 /* overlapping locks must fail */
2380 ok( !LockFile( handle, 12, 0, 10, 0 ), "LockFile 12,10 succeeded\n" );
2381 ok( !LockFile( handle, 5, 0, 6, 0 ), "LockFile 5,6 succeeded\n" );
2382 /* non-overlapping locks must succeed */
2383 ok( LockFile( handle, 5, 0, 5, 0 ), "LockFile 5,5 failed\n" );
2384
2385 ok( !UnlockFile( handle, 10, 0, 10, 0 ), "UnlockFile 10,10 succeeded\n" );
2386 ok( UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 failed\n" );
2387 ok( !UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" );
2388 ok( UnlockFile( handle, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" );
2389
2390 overlapped.Offset = 100;
2391 overlapped.OffsetHigh = 0;
2392 overlapped.hEvent = 0;
2393
2394 /* Test for broken LockFileEx a la Windows 95 OSR2. */
2395 if (LockFileEx( handle, 0, 0, 100, 0, &overlapped ))
2396 {
2397 /* LockFileEx is probably OK, test it more. */
2398 ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ),
2399 "LockFileEx 100,100 failed\n" );
2400 }
2401
2402 /* overlapping shared locks are OK */
2403 overlapped.Offset = 150;
2404 limited_UnLockFile || ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" );
2405
2406 /* but exclusive is not */
2408 0, 50, 0, &overlapped ),
2409 "LockFileEx exclusive 150,50 succeeded\n" );
2410 if (!UnlockFileEx( handle, 0, 100, 0, &overlapped ))
2411 { /* UnLockFile is capable. */
2412 overlapped.Offset = 100;
2413 ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ),
2414 "UnlockFileEx 150,100 again succeeded\n" );
2415 }
2416
2417 /* shared lock can overlap exclusive if handles are equal */
2418 overlapped.Offset = 300;
2420 "LockFileEx exclusive 300,100 failed\n" );
2421 ok( !LockFileEx( handle2, LOCKFILE_FAIL_IMMEDIATELY, 0, 100, 0, &overlapped ),
2422 "LockFileEx handle2 300,100 succeeded\n" );
2424 ok( ret, "LockFileEx 300,100 failed\n" );
2425 ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 300,100 failed\n" );
2426 /* exclusive lock is removed first */
2427 ok( LockFileEx( handle2, LOCKFILE_FAIL_IMMEDIATELY, 0, 100, 0, &overlapped ),
2428 "LockFileEx handle2 300,100 failed\n" );
2429 ok( UnlockFileEx( handle2, 0, 100, 0, &overlapped ), "UnlockFileEx 300,100 failed\n" );
2430 if (ret)
2431 ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 300,100 failed\n" );
2432
2433 ret = LockFile( handle, 0, 0x10000000, 0, 0xf0000000 );
2434 if (ret)
2435 {
2436 ok( !LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" );
2437 ok( !LockFile( handle, 0, 0x20000000, 20, 0 ), "LockFile 0x20000000,20 succeeded\n" );
2438 ok( UnlockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "UnlockFile failed\n" );
2439 }
2440 else /* win9x */
2441 ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong LockFile error %lu\n", GetLastError() );
2442
2443 /* wrap-around lock should not do anything */
2444 /* (but still succeeds on NT4 so we don't check result) */
2445 LockFile( handle, 0, 0x10000000, 0, 0xf0000001 );
2446
2447 limited_LockFile = 0;
2448 if (!LockFile( handle, ~0, ~0, 1, 0 ))
2449 {
2450 limited_LockFile = 1;
2451 }
2452
2453 limited_UnLockFile || ok( UnlockFile( handle, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" );
2454
2455 /* zero-byte lock */
2456 ok( LockFile( handle, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" );
2457 if (!limited_LockFile) ok( !LockFile( handle, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
2458 ok( LockFile( handle, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
2459 if (!limited_LockFile) ok( !LockFile( handle, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
2460
2461 ok( UnlockFile( handle, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
2462 ok( !UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 succeeded\n" );
2463
2464 ok( UnlockFile( handle, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" );
2465
2466 CloseHandle( handle2 );
2467cleanup:
2470}
2471
2473{
2477 BYTE *buffer;
2478 DWORD lfanew = sizeof(*dos);
2479 DWORD size = lfanew + sizeof(*nt) + sizeof(*sec);
2480 DWORD written;
2481 BOOL ret;
2482
2484 if (file == INVALID_HANDLE_VALUE) return FALSE;
2485
2487
2490 dos->e_cblp = sizeof(*dos);
2491 dos->e_cp = 1;
2492 dos->e_cparhdr = lfanew / 16;
2493 dos->e_minalloc = 0;
2494 dos->e_maxalloc = 0xffff;
2495 dos->e_ss = 0x0000;
2496 dos->e_sp = 0x00b8;
2497 dos->e_lfarlc = lfanew;
2498 dos->e_lfanew = lfanew;
2499
2500 nt = (IMAGE_NT_HEADERS *)(buffer + lfanew);
2502#if defined __i386__
2504#elif defined __x86_64__
2506#elif defined __arm__
2508#elif defined __aarch64__
2510#else
2511# error You must specify the machine type
2512#endif
2519 nt->OptionalHeader.ImageBase = 0x10000000;
2528 nt->OptionalHeader.SizeOfImage = 0x2000;
2533
2534 sec = (IMAGE_SECTION_HEADER *)(nt + 1);
2535 memcpy( sec->Name, ".rodata", sizeof(".rodata") );
2536 sec->Misc.VirtualSize = 0x1000;
2537 sec->VirtualAddress = 0x1000;
2538 sec->SizeOfRawData = 0;
2539 sec->PointerToRawData = 0;
2541
2542 ret = WriteFile( file, buffer, size, &written, NULL ) && written == size;
2544 CloseHandle( file );
2545 return ret;
2546}
2547
2548static unsigned int map_file_access( unsigned int access )
2549{
2555}
2556
2557static BOOL is_sharing_compatible( DWORD access1, DWORD sharing1, DWORD access2, DWORD sharing2 )
2558{
2559 access1 = map_file_access( access1 );
2560 access2 = map_file_access( access2 );
2563
2564 if (!access1) sharing1 = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE;
2565 if (!access2) sharing2 = FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE;
2566
2567 if ((access1 & (FILE_READ_DATA|FILE_EXECUTE)) && !(sharing2 & FILE_SHARE_READ)) return FALSE;
2568 if ((access1 & (FILE_WRITE_DATA|FILE_APPEND_DATA)) && !(sharing2 & FILE_SHARE_WRITE)) return FALSE;
2569 if ((access1 & DELETE) && !(sharing2 & FILE_SHARE_DELETE)) return FALSE;
2570 if ((access2 & (FILE_READ_DATA|FILE_EXECUTE)) && !(sharing1 & FILE_SHARE_READ)) return FALSE;
2571 if ((access2 & (FILE_WRITE_DATA|FILE_APPEND_DATA)) && !(sharing1 & FILE_SHARE_WRITE)) return FALSE;
2572 if ((access2 & DELETE) && !(sharing1 & FILE_SHARE_DELETE)) return FALSE;
2573 return TRUE;
2574}
2575
2576static BOOL is_sharing_map_compatible( DWORD map_access, DWORD access2, DWORD sharing2 )
2577{
2578 if ((map_access == PAGE_READWRITE || map_access == PAGE_EXECUTE_READWRITE) &&
2579 !(sharing2 & FILE_SHARE_WRITE)) return FALSE;
2580 access2 = map_file_access( access2 );
2581 if ((map_access & SEC_IMAGE) && (access2 & FILE_WRITE_DATA)) return FALSE;
2582 return TRUE;
2583}
2584
2585static void test_file_sharing(void)
2586{
2587 struct mode { DWORD dw; const char* str; };
2588#define M(x) {x, # x}
2589 static const struct mode access_modes[] =
2597 static const struct mode sharing_modes[] =
2598 { M(0), M(FILE_SHARE_READ),
2602 static const struct mode mapping_modes[] =
2604#undef M
2605 int a1, s1, a2, s2;
2606 int ret;
2607 HANDLE h, h2;
2608
2609 /* make sure the file exists */
2610 if (!create_fake_dll( filename ))
2611 {
2612 ok(0, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError());
2613 return;
2614 }
2615
2616 for (a1 = 0; a1 < ARRAY_SIZE(access_modes); a1++)
2617 {
2618 for (s1 = 0; s1 < ARRAY_SIZE(sharing_modes); s1++)
2619 {
2620 SetLastError(0xdeadbeef);
2621 h = CreateFileA( filename, access_modes[a1].dw, sharing_modes[s1].dw,
2622 NULL, OPEN_EXISTING, 0, 0 );
2623 if (h == INVALID_HANDLE_VALUE)
2624 {
2625 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
2626 return;
2627 }
2628 for (a2 = 0; a2 < ARRAY_SIZE(access_modes); a2++)
2629 {
2630 for (s2 = 0; s2 < ARRAY_SIZE(sharing_modes); s2++)
2631 {
2632 SetLastError(0xdeadbeef);
2633 h2 = CreateFileA( filename, access_modes[a2].dw, sharing_modes[s2].dw,
2634 NULL, OPEN_EXISTING, 0, 0 );
2635 ret = GetLastError();
2636 if (is_sharing_compatible( access_modes[a1].dw, sharing_modes[s1].dw,
2637 access_modes[a2].dw, sharing_modes[s2].dw ))
2638 {
2639 ok( h2 != INVALID_HANDLE_VALUE,
2640 "open failed for modes %s / %s / %s / %s\n",
2641 access_modes[a1].str, sharing_modes[s1].str,
2642 access_modes[a2].str, sharing_modes[s2].str );
2643 ok( ret == 0, "wrong error code %d\n", ret );
2644 }
2645 else
2646 {
2647 ok( h2 == INVALID_HANDLE_VALUE,
2648 "open succeeded for modes %s / %s / %s / %s\n",
2649 access_modes[a1].str, sharing_modes[s1].str,
2650 access_modes[a2].str, sharing_modes[s2].str );
2652 "wrong error code %d\n", ret );
2653 }
2654 if (h2 != INVALID_HANDLE_VALUE) CloseHandle( h2 );
2655 }
2656 }
2657 CloseHandle( h );
2658 }
2659 }
2660
2661 for (a1 = 0; a1 < ARRAY_SIZE(mapping_modes); a1++)
2662 {
2663 HANDLE m;
2664
2666 SetLastError(0xdeadbeef);
2668 if (h == INVALID_HANDLE_VALUE)
2669 {
2670 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
2671 return;
2672 }
2673 m = CreateFileMappingA( h, NULL, mapping_modes[a1].dw, 0, 0, NULL );
2674 ok( m != 0, "failed to create mapping %s err %lu\n", mapping_modes[a1].str, GetLastError() );
2675 CloseHandle( h );
2676 if (!m) continue;
2677
2678 for (a2 = 0; a2 < ARRAY_SIZE(access_modes); a2++)
2679 {
2680 for (s2 = 0; s2 < ARRAY_SIZE(sharing_modes); s2++)
2681 {
2682 SetLastError(0xdeadbeef);
2683 h2 = CreateFileA( filename, access_modes[a2].dw, sharing_modes[s2].dw,
2684 NULL, OPEN_EXISTING, 0, 0 );
2685
2686 ret = GetLastError();
2687 if (h2 == INVALID_HANDLE_VALUE)
2688 {
2689 ok( !is_sharing_map_compatible(mapping_modes[a1].dw, access_modes[a2].dw, sharing_modes[s2].dw),
2690 "open failed for modes map %s / %s / %s\n",
2691 mapping_modes[a1].str, access_modes[a2].str, sharing_modes[s2].str );
2693 "wrong error code %d\n", ret );
2694 }
2695 else
2696 {
2697 if (!is_sharing_map_compatible(mapping_modes[a1].dw, access_modes[a2].dw, sharing_modes[s2].dw))
2698 ok( broken(1), /* no checking on nt4 */
2699 "open succeeded for modes map %s / %s / %s\n",
2700 mapping_modes[a1].str, access_modes[a2].str, sharing_modes[s2].str );
2701 ok( ret == 0xdeadbeef /* Win9x */ ||
2702 ret == 0, /* XP */
2703 "wrong error code %d\n", ret );
2704 CloseHandle( h2 );
2705 }
2706 }
2707 }
2708
2709 /* try CREATE_ALWAYS over an existing mapping */
2710 SetLastError(0xdeadbeef);
2712 NULL, CREATE_ALWAYS, 0, 0 );
2713 ret = GetLastError();
2714 if (mapping_modes[a1].dw & SEC_IMAGE)
2715 {
2716 ok( h2 == INVALID_HANDLE_VALUE, "create succeeded for map %s\n", mapping_modes[a1].str );
2717 ok( ret == ERROR_SHARING_VIOLATION, "wrong error code %d for %s\n", ret, mapping_modes[a1].str );
2718 }
2719 else
2720 {
2721 ok( h2 == INVALID_HANDLE_VALUE, "create succeeded for map %s\n", mapping_modes[a1].str );
2722 ok( ret == ERROR_USER_MAPPED_FILE, "wrong error code %d for %s\n", ret, mapping_modes[a1].str );
2723 }
2724 if (h2 != INVALID_HANDLE_VALUE) CloseHandle( h2 );
2725
2726 /* try DELETE_ON_CLOSE over an existing mapping */
2727 SetLastError(0xdeadbeef);
2730 ret = GetLastError();
2731 if (mapping_modes[a1].dw & SEC_IMAGE)
2732 {
2733 ok( h2 == INVALID_HANDLE_VALUE, "create succeeded for map %s\n", mapping_modes[a1].str );
2734 ok( ret == ERROR_ACCESS_DENIED, "wrong error code %d for %s\n", ret, mapping_modes[a1].str );
2735 }
2736 else
2737 {
2738 ok( h2 != INVALID_HANDLE_VALUE, "open failed for map %s err %u\n", mapping_modes[a1].str, ret );
2739 }
2740 if (h2 != INVALID_HANDLE_VALUE) CloseHandle( h2 );
2741
2742 CloseHandle( m );
2743 }
2744
2745 SetLastError(0xdeadbeef);
2747 ok( h != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError() );
2748
2749 SetLastError(0xdeadbeef);
2751 ok( h2 == INVALID_HANDLE_VALUE, "CreateFileA should fail\n");
2752 ok( GetLastError() == ERROR_SHARING_VIOLATION, "wrong error code %ld\n", GetLastError() );
2753
2755 ok( h2 != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError() );
2756
2757 CloseHandle(h);
2758 CloseHandle(h2);
2759
2761}
2762
2763static char get_windows_drive(void)
2764{
2765 char windowsdir[MAX_PATH];
2766 GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
2767 return windowsdir[0];
2768}
2769
2770static void test_FindFirstFileA(void)
2771{
2772 HANDLE handle;
2774 int err;
2775 char buffer[5] = "C:\\";
2776 char buffer2[100];
2777 char nonexistent[MAX_PATH];
2778 BOOL found = FALSE;
2779
2780 /* try FindFirstFileA on "C:\" */
2782
2783 SetLastError( 0xdeadbeaf );
2785 err = GetLastError();
2786 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on root directory should fail\n" );
2787 ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err );
2788
2789 /* try FindFirstFileA on "C:\*" */
2790 strcpy(buffer2, buffer);
2791 strcat(buffer2, "*");
2792 handle = FindFirstFileA(buffer2, &data);
2793 ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s should succeed\n", buffer2 );
2794 ok ( strcmp( data.cFileName, "." ) && strcmp( data.cFileName, ".." ),
2795 "FindFirstFile shouldn't return '%s' in drive root\n", data.cFileName );
2796 if (FindNextFileA( handle, &data ))
2797 ok ( strcmp( data.cFileName, "." ) && strcmp( data.cFileName, ".." ),
2798 "FindNextFile shouldn't return '%s' in drive root\n", data.cFileName );
2799 ok ( FindClose(handle) == TRUE, "Failed to close handle %s\n", buffer2 );
2800
2801 /* try FindFirstFileA on windows dir */
2802 GetWindowsDirectoryA( buffer2, sizeof(buffer2) );
2803 strcat(buffer2, "\\*");
2804 handle = FindFirstFileA(buffer2, &data);
2805 ok( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s should succeed\n", buffer2 );
2806 ok( !strcmp( data.cFileName, "." ), "FindFirstFile should return '.' first\n" );
2807 ok( FindNextFileA( handle, &data ), "FindNextFile failed\n" );
2808 ok( !strcmp( data.cFileName, ".." ), "FindNextFile should return '..' as second entry\n" );
2809 while (FindNextFileA( handle, &data ))
2810 {
2811 ok ( strcmp( data.cFileName, "." ) && strcmp( data.cFileName, ".." ),
2812 "FindNextFile shouldn't return '%s'\n", data.cFileName );
2813 if (!found && (data.dwFileAttributes == FILE_ATTRIBUTE_NORMAL ||
2814 data.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE))
2815 {
2816 GetWindowsDirectoryA( buffer2, sizeof(buffer2) );
2817 strcat(buffer2, "\\");
2818 strcat(buffer2, data.cFileName);
2819 strcat(buffer2, "\\*");
2820 found = TRUE;
2821 }
2822 }
2823 ok ( FindClose(handle) == TRUE, "Failed to close handle %s\n", buffer2 );
2824
2825 ok ( found, "Windows dir should not be empty\n" );
2826 if (found)
2827 {
2828 SetLastError( 0xdeadbeef );
2829 handle = FindFirstFileA(buffer2, &data);
2830 err = GetLastError();
2831 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2832 ok ( err == ERROR_DIRECTORY, "Bad Error number %x\n", err );
2833 }
2834
2835 /* try FindFirstFileA on "C:\foo\" */
2836 SetLastError( 0xdeadbeaf );
2837 if (!GetTempFileNameA( buffer, "foo", 0, nonexistent ))
2838 {
2839 char tmp[MAX_PATH];
2840 GetTempPathA( sizeof(tmp), tmp );
2841 GetTempFileNameA( tmp, "foo", 0, nonexistent );
2842 }
2843 DeleteFileA( nonexistent );
2844 strcpy(buffer2, nonexistent);
2845 strcat(buffer2, "\\");
2846 handle = FindFirstFileA(buffer2, &data);
2847 err = GetLastError();
2848 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2849 todo_wine {
2850 ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
2851 }
2852
2853 /* try FindFirstFileA without trailing backslash */
2854 SetLastError( 0xdeadbeaf );
2855 strcpy(buffer2, nonexistent);
2856 handle = FindFirstFileA(buffer2, &data);
2857 err = GetLastError();
2858 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2859 ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err );
2860
2861 /* try FindFirstFileA on "C:\foo\bar.txt" */
2862 SetLastError( 0xdeadbeaf );
2863 strcpy(buffer2, nonexistent);
2864 strcat(buffer2, "\\bar.txt");
2865 handle = FindFirstFileA(buffer2, &data);
2866 err = GetLastError();
2867 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2868 ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
2869
2870 /* try FindFirstFileA on "C:\foo\*.*" */
2871 SetLastError( 0xdeadbeaf );
2872 strcpy(buffer2, nonexistent);
2873 strcat(buffer2, "\\*.*");
2874 handle = FindFirstFileA(buffer2, &data);
2875 err = GetLastError();
2876 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2877 ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
2878
2879 /* try FindFirstFileA on "foo\bar.txt" */
2880 SetLastError( 0xdeadbeaf );
2881 strcpy(buffer2, nonexistent + 3);
2882 strcat(buffer2, "\\bar.txt");
2883 handle = FindFirstFileA(buffer2, &data);
2884 err = GetLastError();
2885 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2886 ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
2887
2888 /* try FindFirstFileA on "c:\nul" */
2889 SetLastError( 0xdeadbeaf );
2890 strcpy(buffer2, buffer);
2891 strcat(buffer2, "nul");
2892 handle = FindFirstFileA(buffer2, &data);
2893 err = GetLastError();
2894 ok( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s failed: %d\n", buffer2, err );
2895 ok( 0 == lstrcmpiA(data.cFileName, "nul"), "wrong name %s\n", data.cFileName );
2896 ok( FILE_ATTRIBUTE_ARCHIVE == data.dwFileAttributes ||
2897 FILE_ATTRIBUTE_DEVICE == data.dwFileAttributes /* Win9x */,
2898 "wrong attributes %lx\n", data.dwFileAttributes );
2899 if (data.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE)
2900 {
2901 ok( 0 == data.nFileSizeHigh, "wrong size %ld\n", data.nFileSizeHigh );
2902 ok( 0 == data.nFileSizeLow, "wrong size %ld\n", data.nFileSizeLow );
2903 }
2904 SetLastError( 0xdeadbeaf );
2905 ok( !FindNextFileA( handle, &data ), "FindNextFileA succeeded\n" );
2906 ok( GetLastError() == ERROR_NO_MORE_FILES, "bad error %ld\n", GetLastError() );
2907 ok( FindClose( handle ), "failed to close handle\n" );
2908
2909 /* try FindFirstFileA on "lpt1" */
2910 SetLastError( 0xdeadbeaf );
2911 strcpy(buffer2, "lpt1");
2912 handle = FindFirstFileA(buffer2, &data);
2913 err = GetLastError();
2914 ok( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s failed: %d\n", buffer2, err );
2915 ok( 0 == lstrcmpiA(data.cFileName, "lpt1"), "wrong name %s\n", data.cFileName );
2916 ok( FILE_ATTRIBUTE_ARCHIVE == data.dwFileAttributes ||
2917 FILE_ATTRIBUTE_DEVICE == data.dwFileAttributes /* Win9x */,
2918 "wrong attributes %lx\n", data.dwFileAttributes );
2919 if (data.dwFileAttributes == FILE_ATTRIBUTE_ARCHIVE)
2920 {
2921 ok( 0 == data.nFileSizeHigh, "wrong size %ld\n", data.nFileSizeHigh );
2922 ok( 0 == data.nFileSizeLow, "wrong size %ld\n", data.nFileSizeLow );
2923 }
2924 SetLastError( 0xdeadbeaf );
2925 ok( !FindNextFileA( handle, &data ), "FindNextFileA succeeded\n" );
2926 ok( GetLastError() == ERROR_NO_MORE_FILES, "bad error %ld\n", GetLastError() );
2927 ok( FindClose( handle ), "failed to close handle\n" );
2928
2929 /* try FindFirstFileA on "c:\nul\*" */
2930 SetLastError( 0xdeadbeaf );
2931 strcpy(buffer2, buffer);
2932 strcat(buffer2, "nul\\*");
2933 handle = FindFirstFileA(buffer2, &data);
2934 err = GetLastError();
2935 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2936 ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
2937
2938 /* try FindFirstFileA on "c:\nul*" */
2939 SetLastError( 0xdeadbeaf );
2940 strcpy(buffer2, buffer);
2941 strcat(buffer2, "nul*");
2942 handle = FindFirstFileA(buffer2, &data);
2943 err = GetLastError();
2944 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2945 ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err );
2946
2947 /* try FindFirstFileA on "c:\foo\bar\nul" */
2948 SetLastError( 0xdeadbeaf );
2949 strcpy(buffer2, buffer);
2950 strcat(buffer2, "foo\\bar\\nul");
2951 handle = FindFirstFileA(buffer2, &data);
2952 err = GetLastError();
2953 ok( handle == INVALID_HANDLE_VALUE || broken(1), /* win8 */
2954 "FindFirstFile on %s should fail\n", buffer2 );
2956 ok( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
2957 else
2959
2960 /* try FindFirstFileA on "c:\foo\nul\bar" */
2961 SetLastError( 0xdeadbeaf );
2962 strcpy(buffer2, buffer);
2963 strcat(buffer2, "foo\\nul\\bar");
2964 handle = FindFirstFileA(buffer2, &data);
2965 err = GetLastError();
2966 ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should fail\n", buffer2 );
2967 ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
2968}
2969
2970static void test_FindNextFileA(void)
2971{
2972 HANDLE handle;
2973 WIN32_FIND_DATAA search_results;
2974 int err;
2975 char buffer[5] = "C:\\*";
2976
2978 handle = FindFirstFileA(buffer,&search_results);
2979 ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed\n" );
2980 while (FindNextFileA(handle, &search_results))
2981 {
2982 /* get to the end of the files */
2983 }
2984 ok ( FindClose(handle) == TRUE, "Failed to close handle\n");
2985 err = GetLastError();
2986 ok ( err == ERROR_NO_MORE_FILES, "GetLastError should return ERROR_NO_MORE_FILES\n");
2987}
2988
2990{
2991 WIN32_FIND_DATAA search_results;
2992 HANDLE handle;
2993 BOOL ret;
2994
2995 if (!pFindFirstFileExA)
2996 {
2997 win_skip("FindFirstFileExA() is missing\n");
2998 return;
2999 }
3000
3001 trace("Running FindFirstFileExA tests with level=%d, search_ops=%d, flags=%lu\n",
3002 level, search_ops, flags);
3003
3004 CreateDirectoryA("test-dir", NULL);
3005 _lclose(_lcreat("test-dir\\file1", 0));
3006 _lclose(_lcreat("test-dir\\file2", 0));
3007 CreateDirectoryA("test-dir\\dir1", NULL);
3008 SetLastError(0xdeadbeef);
3009 handle = pFindFirstFileExA("test-dir\\*", level, &search_results, search_ops, NULL, flags);
3011 {
3012 win_skip("FindFirstFileExA is not implemented\n");
3013 goto cleanup;
3014 }
3016 {
3017 win_skip("FindFirstFileExA flag FIND_FIRST_EX_LARGE_FETCH not supported, skipping test\n");
3018 goto cleanup;
3019 }
3021 {
3022 win_skip("FindFirstFileExA level FindExInfoBasic not supported, skipping test\n");
3023 goto cleanup;
3024 }
3025
3026#define CHECK_NAME(fn) (strcmp((fn), "file1") == 0 || strcmp((fn), "file2") == 0 || strcmp((fn), "dir1") == 0)
3027#define CHECK_LEVEL(fn) (level != FindExInfoBasic || !(fn)[0])
3028
3029 ok(handle != INVALID_HANDLE_VALUE, "FindFirstFile failed (err=%lu)\n", GetLastError());
3030 ok(strcmp(search_results.cFileName, ".") == 0, "First entry should be '.', is %s\n", search_results.cFileName);
3031 ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n");
3032
3033 ok(FindNextFileA(handle, &search_results), "Fetching second file failed\n");
3034 ok(strcmp(search_results.cFileName, "..") == 0, "Second entry should be '..' is %s\n", search_results.cFileName);
3035 ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n");
3036
3037 ok(FindNextFileA(handle, &search_results), "Fetching third file failed\n");
3038 ok(CHECK_NAME(search_results.cFileName), "Invalid third entry - %s\n", search_results.cFileName);
3039 ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n");
3040
3041 SetLastError(0xdeadbeef);
3042 ret = FindNextFileA(handle, &search_results);
3043 if (!ret && (GetLastError() == ERROR_NO_MORE_FILES) && (search_ops == FindExSearchLimitToDirectories))
3044 {
3045 skip("File system supports directory filtering\n");
3046 /* Results from the previous call are not cleared */
3047 ok(strcmp(search_results.cFileName, "dir1") == 0, "Third entry should be 'dir1' is %s\n", search_results.cFileName);
3048 ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n");
3049
3050 }
3051 else
3052 {
3053 ok(ret, "Fetching fourth file failed\n");
3054 ok(CHECK_NAME(search_results.cFileName), "Invalid fourth entry - %s\n", search_results.cFileName);
3055 ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n");
3056
3057 ok(FindNextFileA(handle, &search_results), "Fetching fifth file failed\n");
3058 ok(CHECK_NAME(search_results.cFileName), "Invalid fifth entry - %s\n", search_results.cFileName);
3059 ok(CHECK_LEVEL(search_results.cAlternateFileName), "FindFirstFile unexpectedly returned an alternate filename\n");
3060
3061 ok(FindNextFileA(handle, &search_results) == FALSE, "Fetching sixth file should fail\n");
3062 }
3063
3064#undef CHECK_NAME
3065#undef CHECK_LEVEL
3066
3067 FindClose( handle );
3068
3069 /* Most Windows systems seem to ignore the FIND_FIRST_EX_CASE_SENSITIVE flag. Unofficial documentation
3070 * suggests that there are registry keys and that it might depend on the used filesystem. */
3071 SetLastError(0xdeadbeef);
3072 handle = pFindFirstFileExA("TEST-DIR\\*", level, &search_results, search_ops, NULL, flags);
3074 {
3076 "Unexpected error %lx, expected valid handle or ERROR_PATH_NOT_FOUND\n", GetLastError());
3077 trace("FindFirstFileExA flag FIND_FIRST_EX_CASE_SENSITIVE is %signored\n",
3078 (handle == INVALID_HANDLE_VALUE) ? "not " : "");
3079 }
3080 else
3081 ok(handle != INVALID_HANDLE_VALUE, "Unexpected error %lx, expected valid handle\n", GetLastError());
3083 FindClose( handle );
3084
3085cleanup:
3086 DeleteFileA("test-dir\\file1");
3087 DeleteFileA("test-dir\\file2");
3088 RemoveDirectoryA("test-dir\\dir1");
3089 RemoveDirectoryA("test-dir");
3090}
3091
3093{
3095 HANDLE handle;
3096 int i;
3097 static const char* files[] = {
3098 "..a", "..a.a", ".a", ".a..a", ".a.a", ".aaa",
3099 "a", "a..a", "a.a", "a.a.a", "aa", "aaa", "aaaa", " .a"
3100 };
3101 static const struct {
3102 const char *pattern, *result;
3103 } tests[] = {
3104 {"*.*.*", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3105 {"*.*.", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3106 {".*.*", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa'"},
3107 {"*.*", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3108 {".*", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa'"},
3109 {". *", ""},
3110 {"*.", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3111 {"*", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3112 {"*..*", ", '.', '..', '..a', '..a.a', '.a..a', 'a..a'"},
3113 {"*..", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3114 {".*.", ", '.', '..', '.a', '.aaa'"},
3115 {"..*", ", '.', '..', '..a', '..a.a'"},
3116 {"**", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3117 {"**.", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3118 {"*. ", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3119 {"* .", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3120 {"* . ", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3121 {"* . *", ""},
3122 {"*.. ", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3123 {"*. .", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3124 {"* ..", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3125 {" *..", ""},
3126 {"..* ", ", '.', '..', '..a', '..a.a'"},
3127 {"* .*.", ", ' .a'"},
3128
3129 {"a*.", ", '..a', '.a', '.aaa', 'a', 'aa', 'aaa', 'aaaa'"},
3130 {"*a ", ", '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3131 {"*aa*", ", '.aaa', 'a.a.a', 'aa', 'aaa', 'aaaa'"},
3132 {"aa*.", ", '.aaa', 'aa', 'aaa', 'aaaa'"},
3133 {"aa.*", ", 'aa'"},
3134 {"a a*.*", ""},
3135 {"a\"*\"a", ", 'a..a', 'a.a.a'"},
3136 {"aa*.*", ", '.aaa', 'a.a.a', 'aa', 'aaa', 'aaaa'"},
3137 {"a ?.*", ""},
3138 {"? a.*", ""},
3139 {"a* a", ""},
3140 {" *a", ", ' .a'"},
3141 {"* *", ", ' .a'"},
3142 {"a* .", ", 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3143 {" ?a", ""},
3144 {"* .a", ", ' .a'"},
3145 {"< .a", ", ' .a'"},
3146 {"** .a", ", ' .a'"},
3147 {"<< .a", ", ' .a'"},
3148 {"aa? ", ", 'aa', 'aaa'"},
3149 {"aa\"*", ", 'aa'"},
3150 {"*.a", ", '..a', '..a.a', '.a', '.a..a', '.a.a', 'a..a', 'a.a', 'a.a.a', ' .a'"},
3151 {"<.a", ", '..a', '..a.a', '.a', '.a..a', '.a.a', 'a..a', 'a.a', 'a.a.a', ' .a'"},
3152
3153 {"<.<.<", ", '..a', '..a.a', '.a..a', '.a.a', 'a..a', 'a.a.a'"},
3154 {"<.<.< ", ", '..a', '..a.a', '.a..a', '.a.a', 'a..a', 'a.a.a'"},
3155 {"<.<.", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a..a', 'a.a', 'a.a.a', ' .a'"},
3156 {"< .<.", ", ' .a'"},
3157 {"< .<. ", ", ' .a'"},
3158 {"<.<. ", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a..a', 'a.a', 'a.a.a', ' .a'"},
3159 {".<.<", ", '..a', '..a.a', '.a..a', '.a.a'"},
3160 {"<.<", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a..a', 'a.a', 'a.a.a', ' .a'"},
3161 {".<", ", '.', '..', '.a', '.aaa'"},
3162 {"<.", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3163 {"<", ", '.', '..', '..a', '.a', '.aaa', 'a', 'aa', 'aaa', 'aaaa'"},
3164 {"<..<", ", '..a', '.a..a', 'a..a'"},
3165 {"<..", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3166 {".<.", ", '.', '..', '.a', '.aaa'"},
3167 {"..<", ", '..a'"},
3168 {"<<", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3169 {"<<.", ", '.', '..', '..a', '..a.a', '.a', '.a..a', '.a.a', '.aaa', 'a', 'a..a', 'a.a', 'a.a.a', 'aa', 'aaa', 'aaaa', ' .a'"},
3170 {"<. ", ", '.', '..', '..a', '.a', '.aaa', 'a', 'aa', 'aaa', 'aaaa'"},
3171 {"< .", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3172 {"< . ", ", '.', '..', '..a', '.a', '.aaa', 'a', 'aa', 'aaa', 'aaaa'"},
3173 {"<.. ", ", '.', '..', '..a', '.a', '.aaa', 'a', 'aa', 'aaa', 'aaaa'"},
3174 {"<. .", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3175 {"< ..", ", '.', '..', 'a', '.a', '..a', 'aa', 'aaa', 'aaaa', '.aaa'"},
3176 {" <..", ""},
3177 {"..< ", ", '..a'"},
3178
3179 {"?", ", '.', '..', 'a'"},
3180 {"?.", ", '.', '..', 'a'"},
3181 {"?. ", ", '.', '..', 'a'"},
3182 {"? .*", ""},
3183 {"??.", ", '.', '..', 'a', 'aa'"},
3184 {"??. ", ", '.', '..', 'a', 'aa'"},
3185 {"???.", ", '.', '..', 'a', 'aa', 'aaa'"},
3186 {"?.??.", ", '.', '..', '.a', 'a', 'a.a', ' .a'"},
3187 {". ?", ""},
3188
3189 {">", ", '.', '..', 'a'"},
3190 {">.", ", '.', '..', 'a'"},
3191 {">. ", ", '.', '..', 'a'"},
3192 {">>.", ", '.', '..', 'a', 'aa'"},
3193 {">>. ", ", '.', '..', 'a', 'aa'"},
3194 {">>>.", ", '.', '..', 'a', 'aa', 'aaa'"},
3195 {">.>>.", ", '.', '..', '.a', 'a.a', ' .a'"},
3196 };
3197
3198 CreateDirectoryA("test-dir", NULL);
3199 SetCurrentDirectoryA("test-dir");
3200 for (i = 0; i < ARRAY_SIZE(files); ++i)
3201 _lclose(_lcreat(files[i], 0));
3202
3203 for (i = 0; i < ARRAY_SIZE(tests); ++i)
3204 {
3205 char correct[512];
3206 char incorrect[512];
3207 char missing[512];
3208
3209 strcpy(missing, tests[i].result);
3210 correct[0] = incorrect[0] = 0;
3211
3214 {
3215 do {
3216 char *ptr;
3217 char quoted[16];
3218
3219 sprintf(quoted, ", '%.10s'", find_data.cFileName);
3220
3221 if ((ptr = strstr(missing, quoted)))
3222 {
3223 int len = strlen(quoted);
3224 while ((ptr[0] = ptr[len]) != 0)
3225 ++ptr;
3226 strcat(correct, quoted);
3227 }
3228 else
3229 strcat(incorrect, quoted);
3230 } while (FindNextFileA(handle, &find_data));
3232 }
3233
3234 ok(missing[0] == 0 && incorrect[0] == 0,
3235 "FindFirstFile with '%s' found correctly %s, found incorrectly %s, and missed %s\n",
3236 tests[i].pattern,
3237 correct[0] ? correct+2 : "none",
3238 incorrect[0] ? incorrect+2 : "none",
3239 missing[0] ? missing+2 : "none");
3240 }
3241
3242 for (i = 0; i < ARRAY_SIZE(files); ++i)
3243 DeleteFileA(files[i]);
3245 RemoveDirectoryA("test-dir");
3246}
3247
3249{
3254 if (*handle != INVALID_HANDLE_VALUE) {
3255
3256 return 1;
3257 }
3258
3259 return 0;
3260}
3261
3262static void test_MapFile(void)
3263{
3264 HANDLE handle;
3265 HANDLE hmap;
3266 UINT err;
3267
3268 ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n");
3269
3270 hmap = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0, 0x1000, "named_file_map" );
3271 ok( hmap != NULL, "mapping should work, I named it!\n" );
3272
3273 ok( CloseHandle( hmap ), "can't close mapping handle\n");
3274
3275 /* We have to close file before we try new stuff with mapping again.
3276 Else we would always succeed on XP or block descriptors on 95. */
3278 ok( hmap != NULL, "We should still be able to map!\n" );
3279 ok( CloseHandle( hmap ), "can't close mapping handle\n");
3280 ok( CloseHandle( handle ), "can't close file handle\n");
3281 handle = NULL;
3282
3283 ok(test_Mapfile_createtemp(&handle), "Couldn't create test file.\n");
3284
3285 SetLastError( 0xdeadbeef );
3287 err = GetLastError();
3288 ok( hmap == NULL, "mapped zero size file\n");
3289 ok( err == ERROR_FILE_INVALID, "got %u\n", err );
3290
3291 SetLastError( 0xdeadbeef );
3292 hmap = CreateFileMappingA( handle, NULL, PAGE_READWRITE, 0x8000000, 0x10000, NULL );
3293 err = GetLastError();
3294 ok( hmap == NULL, "mapping should fail\n");
3296
3297 /* On XP you can now map again, on Win 95 you cannot. */
3298
3299 ok( CloseHandle( handle ), "can't close file handle\n");
3300 ok( DeleteFileA( filename ), "DeleteFile failed after map\n" );
3301}
3302
3303static void test_GetFileType(void)
3304{
3305 DWORD type, type2;
3306 HANDLE h, h2;
3307 BOOL ret;
3309 ok( h != INVALID_HANDLE_VALUE, "open %s failed\n", filename );
3310 type = GetFileType(h);
3311 ok( type == FILE_TYPE_DISK, "expected type disk got %ld\n", type );
3312 CloseHandle( h );
3314 ok( h != INVALID_HANDLE_VALUE, "open nul failed\n" );
3315 type = GetFileType(h);
3316 ok( type == FILE_TYPE_CHAR, "expected type char for nul got %ld\n", type );
3317 CloseHandle( h );
3320 ok( h != INVALID_HANDLE_VALUE, "GetStdHandle failed\n" );
3322 type2 = GetFileType( h );
3323 ok(type == type2, "expected type %ld for STD_OUTPUT_HANDLE got %ld\n", type2, type);
3324
3325 ret = CreatePipe( &h, &h2, NULL, 0 );
3326 ok( ret, "CreatePipe failed\n" );
3327 type = GetFileType( h );
3328 ok( type == FILE_TYPE_PIPE, "expected type pipe got %ld\n", type );
3329 type = GetFileType( h2 );
3330 ok( type == FILE_TYPE_PIPE, "expected type pipe got %ld\n", type );
3331 CloseHandle( h2 );
3332 CloseHandle( h );
3333
3334 h = CreateNamedPipeW( L"\\\\.\\pipe\\wine_test", PIPE_ACCESS_DUPLEX, 0, 2, 32, 32, 0, NULL );
3335 ok( h != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n" );
3336 type = GetFileType( h );
3337 ok( type == FILE_TYPE_PIPE, "expected type pipe got %ld\n", type );
3338 CloseHandle( h );
3339
3341 ok( h != INVALID_HANDLE_VALUE, "open %s failed\n", filename );
3342 h2 = CreateFileMappingW( h, NULL, PAGE_READWRITE, 0, 0x1000, NULL );
3343 ok( h2 != NULL, "CreateFileMapping failed\n" );
3344 SetLastError( 12345678 );
3345 type = GetFileType( h2 );
3346 todo_wine
3347 ok( type == FILE_TYPE_UNKNOWN, "expected type unknown got %ld\n", type );
3348 todo_wine
3349 ok( GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE got %lx\n", GetLastError() );
3350 CloseHandle( h2 );
3351 CloseHandle( h );
3353
3355 ok( h != NULL, "CreateFileMapping failed\n" );
3356 SetLastError( 12345678 );
3357 type = GetFileType( h );
3358 todo_wine
3359 ok( type == FILE_TYPE_UNKNOWN, "expected type unknown got %ld\n", type );
3360 todo_wine
3361 ok( GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE got %lx\n", GetLastError() );
3362 CloseHandle( h );
3363
3364 h = CreateMailslotW( L"\\\\.\\mailslot\\wine_test", 0, 0, NULL );
3365 ok( h != INVALID_HANDLE_VALUE, "CreateMailslot failed\n" );
3366 SetLastError( 12345678 );
3367 type = GetFileType( h );
3368 ok( type == FILE_TYPE_UNKNOWN, "expected type unknown got %ld\n", type );
3369 todo_wine
3370 ok( GetLastError() == NO_ERROR, "expected ERROR_NO_ERROR got %lx\n", GetLastError() );
3371 CloseHandle( h );
3372
3373 SetLastError( 12345678 );
3375 ok( type == FILE_TYPE_UNKNOWN, "expected type unknown got %ld\n", type );
3376 ok( GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE got %lx\n", GetLastError() );
3377
3378 SetLastError( 12345678 );
3380 ok( type == FILE_TYPE_UNKNOWN, "expected type unknown got %ld\n", type );
3381 ok( GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE got %lx\n", GetLastError() );
3382
3383 h = CreateMutexW( NULL, TRUE, NULL );
3384 ok( h != NULL, "CreateMutex failed\n" );
3385 SetLastError( 12345678 );
3386 type = GetFileType( h );
3387 ok( type == FILE_TYPE_UNKNOWN, "expected type unknown got %ld\n", type );
3388 ok( GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE got %lx\n", GetLastError() );
3389 CloseHandle( h );
3390}
3391
3393
3394static void CALLBACK FileIOComplete(DWORD dwError, DWORD dwBytes, LPOVERLAPPED ovl)
3395{
3396/* printf("(%ld, %ld, %p { %ld, %ld, %ld, %ld, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->Offset, ovl->OffsetHigh, ovl->hEvent);*/
3397 ReleaseSemaphore(ovl->hEvent, 1, NULL);
3399}
3400
3401static void test_async_file_errors(void)
3402{
3403 char szFile[MAX_PATH];
3404 HANDLE hSem = CreateSemaphoreW(NULL, 1, 1, NULL);
3405 HANDLE hFile;
3407 OVERLAPPED ovl;
3408#ifdef __REACTOS__
3409 if (is_reactos()) {
3410 ok(FALSE, "FIXME: test_async_file_errors() crashes on ReactOS!\n");
3411 return;
3412 }
3413#endif
3414 ovl.Offset = 0;
3415 ovl.OffsetHigh = 0;
3416 ovl.hEvent = hSem;
3417 completion_count = 0;
3418 szFile[0] = '\0';
3419 GetWindowsDirectoryA(szFile, ARRAY_SIZE(szFile)-1-strlen("\\win.ini"));
3420 strcat(szFile, "\\win.ini");
3423 if (hFile == INVALID_HANDLE_VALUE) /* win9x doesn't like FILE_SHARE_DELETE */
3426 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA(%s ...) failed\n", szFile);
3427 while (TRUE)
3428 {
3429 BOOL res;
3430 DWORD count;
3432 ;
3433 res = ReadFileEx(hFile, lpBuffer, 4096, &ovl, FileIOComplete);
3434 /*printf("Offset = %ld, result = %s\n", ovl.Offset, res ? "TRUE" : "FALSE");*/
3435 if (!res)
3436 break;
3437 if (!GetOverlappedResult(hFile, &ovl, &count, FALSE))
3438 break;
3439 ovl.Offset += count;
3440 /* i/o completion routine only called if ReadFileEx returned success.
3441 * we only care about violations of this rule so undo what should have
3442 * been done */
3444 }
3445 ok(completion_count == 0, "completion routine should only be called when ReadFileEx succeeds (this rule was violated %d times)\n", completion_count);
3446 /*printf("Error = %ld\n", GetLastError());*/
3448}
3449
3452{
3454}
3455
3456static void test_read_write(void)
3457{
3458 DWORD bytes, ret, old_prot;
3459 HANDLE hFile;
3460 char temp_path[MAX_PATH];
3461 char filename[MAX_PATH];
3462 char *mem;
3463 static const char prefix[] = "pfx";
3464
3466 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
3467 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
3468
3470 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
3471
3474 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %ld\n", GetLastError());
3475
3478 ok(ret, "QueueUserAPC failed: %ld\n", GetLastError());
3479
3480 SetLastError(12345678);
3481 bytes = 12345678;
3482 ret = WriteFile(hFile, NULL, 0, &bytes, NULL);
3483 ok(ret && GetLastError() == 12345678,
3484 "ret = %ld, error %ld\n", ret, GetLastError());
3485 ok(!bytes, "bytes = %ld\n", bytes);
3486
3487 SetLastError(12345678);
3488 bytes = 12345678;
3489 ret = WriteFile(hFile, NULL, 10, &bytes, NULL);
3490 ok((!ret && GetLastError() == ERROR_INVALID_USER_BUFFER) || /* Win2k */
3491 (ret && GetLastError() == 12345678), /* Win9x */
3492 "ret = %ld, error %ld\n", ret, GetLastError());
3493 ok(!bytes || /* Win2k */
3494 bytes == 10, /* Win9x */
3495 "bytes = %ld\n", bytes);
3496
3497 /* make sure the file contains data */
3498 WriteFile(hFile, "this is the test data", 21, &bytes, NULL);
3500
3501 SetLastError(12345678);
3502 bytes = 12345678;
3503 ret = ReadFile(hFile, NULL, 0, &bytes, NULL);
3504 ok(ret && GetLastError() == 12345678,
3505 "ret = %ld, error %ld\n", ret, GetLastError());
3506 ok(!bytes, "bytes = %ld\n", bytes);
3507
3508 SetLastError(12345678);
3509 bytes = 12345678;
3510 ret = ReadFile(hFile, NULL, 10, &bytes, NULL);
3511 ok(!ret && (GetLastError() == ERROR_NOACCESS || /* Win2k */
3512 GetLastError() == ERROR_INVALID_PARAMETER), /* Win9x */
3513 "ret = %ld, error %ld\n", ret, GetLastError());
3514 ok(!bytes, "bytes = %ld\n", bytes);
3515
3516 ok(user_apc_ran == FALSE, "UserAPC ran, file using alertable io mode\n");
3517 SleepEx(0, TRUE); /* get rid of apc */
3518
3519 /* test passing protected memory as buffer */
3520
3522 ok( mem != NULL, "failed to allocate virtual mem error %lu\n", GetLastError() );
3523
3524 ret = WriteFile( hFile, mem, 0x4000, &bytes, NULL );
3525 ok( ret, "WriteFile failed error %lu\n", GetLastError() );
3526 ok( bytes == 0x4000, "only wrote %lx bytes\n", bytes );
3527
3528 ret = VirtualProtect( mem + 0x2000, 0x2000, PAGE_NOACCESS, &old_prot );
3529 ok( ret, "VirtualProtect failed error %lu\n", GetLastError() );
3530
3531 ret = WriteFile( hFile, mem, 0x4000, &bytes, NULL );
3532 ok( !ret, "WriteFile succeeded\n" );
3534 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3535 "wrong error %lu\n", GetLastError() );
3536 ok( bytes == 0, "wrote %lx bytes\n", bytes );
3537
3538 ret = WriteFile( (HANDLE)0xdead, mem, 0x4000, &bytes, NULL );
3539 ok( !ret, "WriteFile succeeded\n" );
3540 ok( GetLastError() == ERROR_INVALID_HANDLE || /* handle is checked before buffer on NT */
3541 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3542 "wrong error %lu\n", GetLastError() );
3543 ok( bytes == 0, "wrote %lx bytes\n", bytes );
3544
3545 ret = VirtualProtect( mem, 0x2000, PAGE_NOACCESS, &old_prot );
3546 ok( ret, "VirtualProtect failed error %lu\n", GetLastError() );
3547
3548 ret = WriteFile( hFile, mem, 0x4000, &bytes, NULL );
3549 ok( !ret, "WriteFile succeeded\n" );
3551 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3552 "wrong error %lu\n", GetLastError() );
3553 ok( bytes == 0, "wrote %lx bytes\n", bytes );
3554
3556
3557 ret = ReadFile( hFile, mem, 0x4000, &bytes, NULL );
3558 ok( !ret, "ReadFile succeeded\n" );
3560 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3561 "wrong error %lu\n", GetLastError() );
3562 ok( bytes == 0, "read %lx bytes\n", bytes );
3563
3564 ret = VirtualProtect( mem, 0x2000, PAGE_READONLY, &old_prot );
3565 ok( ret, "VirtualProtect failed error %lu\n", GetLastError() );
3566
3567 ret = ReadFile( hFile, mem, 0x4000, &bytes, NULL );
3568 ok( !ret, "ReadFile succeeded\n" );
3570 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3571 "wrong error %lu\n", GetLastError() );
3572 ok( bytes == 0, "read %lx bytes\n", bytes );
3573
3574 ret = VirtualProtect( mem, 0x2000, PAGE_READWRITE, &old_prot );
3575 ok( ret, "VirtualProtect failed error %lu\n", GetLastError() );
3576
3577 ret = ReadFile( hFile, mem, 0x4000, &bytes, NULL );
3578 ok( !ret, "ReadFile succeeded\n" );
3580 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3581 "wrong error %lu\n", GetLastError() );
3582 ok( bytes == 0, "read %lx bytes\n", bytes );
3583
3584 SetFilePointer( hFile, 0x1234, NULL, FILE_BEGIN );
3587
3588 ret = ReadFile( hFile, mem, 0x4000, &bytes, NULL );
3589 ok( !ret, "ReadFile succeeded\n" );
3591 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3592 "wrong error %lu\n", GetLastError() );
3593 ok( bytes == 0, "read %lx bytes\n", bytes );
3594
3595 ret = ReadFile( hFile, mem, 0x2000, &bytes, NULL );
3596 ok( ret, "ReadFile failed error %lu\n", GetLastError() );
3597 ok( bytes == 0x1234, "read %lx bytes\n", bytes );
3598
3599 ret = ReadFile( hFile, NULL, 1, &bytes, NULL );
3600 ok( !ret, "ReadFile succeeded\n" );
3602 GetLastError() == ERROR_INVALID_PARAMETER, /* win9x */
3603 "wrong error %lu\n", GetLastError() );
3604 ok( bytes == 0, "read %lx bytes\n", bytes );
3605
3607
3609 ok( ret, "CloseHandle: error %ld\n", GetLastError());
3611 ok( ret, "DeleteFileA: error %ld\n", GetLastError());
3612}
3613
3614static void test_OpenFile(void)
3615{
3616 HFILE hFile;
3617 OFSTRUCT ofs;
3618 BOOL ret;
3619 DWORD retval;
3620
3621 static const char file[] = "regedit.exe";
3622 static const char foo[] = ".\\foo-bar-foo.baz";
3623 static const char *foo_too_long = ".\\foo-bar-foo.baz+++++++++++++++"
3624 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
3625 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
3626 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
3627 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
3628 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
3629 char buff[MAX_PATH];
3630 char buff_long[4*MAX_PATH];
3631 char filled_0xA5[OFS_MAXPATHNAME];
3632 char *p;
3633 UINT length;
3634
3635 /* Check for existing file */
3636 if (!pGetSystemWindowsDirectoryA)
3638 else
3639 length = pGetSystemWindowsDirectoryA(buff, MAX_PATH);
3640
3641 if (length + sizeof(file) < MAX_PATH)
3642 {
3643 p = buff + strlen(buff);
3644 if (p > buff && p[-1] != '\\') *p++ = '\\';
3645 strcpy( p, file );
3646 memset(&ofs, 0xA5, sizeof(ofs));
3647 SetLastError(0xfaceabee);
3648
3649 hFile = OpenFile(buff, &ofs, OF_EXIST);
3650 ok( hFile == TRUE, "%s not found : %ld\n", buff, GetLastError() );
3651 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS,
3652 "GetLastError() returns %ld\n", GetLastError() );
3653 ok( ofs.cBytes == sizeof(ofs), "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3654 ok( ofs.nErrCode == ERROR_SUCCESS, "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3655 ok( lstrcmpiA(ofs.szPathName, buff) == 0,
3656 "OpenFile returned '%s', but was expected to return '%s' or string filled with 0xA5\n",
3657 ofs.szPathName, buff );
3658 }
3659
3660 memset(&filled_0xA5, 0xA5, OFS_MAXPATHNAME);
3662
3663 /* Check for nonexistent file */
3664 if (length + sizeof(foo) < MAX_PATH)
3665 {
3666 p = buff + strlen(buff);
3667 if (p > buff && p[-1] != '\\') *p++ = '\\';
3668 strcpy( p, foo + 2 );
3669 memset(&ofs, 0xA5, sizeof(ofs));
3670 SetLastError(0xfaceabee);
3671
3672 hFile = OpenFile(foo, &ofs, OF_EXIST);
3673 ok( hFile == HFILE_ERROR, "hFile != HFILE_ERROR : %ld\n", GetLastError());
3674 ok( GetLastError() == ERROR_FILE_NOT_FOUND, "GetLastError() returns %ld\n", GetLastError() );
3675 todo_wine
3676 ok( ofs.cBytes == 0xA5, "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3677 ok( ofs.nErrCode == ERROR_FILE_NOT_FOUND, "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3678 ok( lstrcmpiA(ofs.szPathName, buff) == 0 || strncmp(ofs.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
3679 "OpenFile returned '%s', but was expected to return '%s' or string filled with 0xA5\n",
3680 ofs.szPathName, buff );
3681 }
3682
3683 length = GetCurrentDirectoryA(MAX_PATH, buff_long);
3684 length += lstrlenA(foo_too_long + 1);
3685
3686 /* Check for nonexistent file with too long filename */
3687 if (length >= OFS_MAXPATHNAME && length < sizeof(buff_long))
3688 {
3689 lstrcatA(buff_long, foo_too_long + 1); /* Avoid '.' during concatenation */
3690 memset(&ofs, 0xA5, sizeof(ofs));
3691 SetLastError(0xfaceabee);
3692
3693 hFile = OpenFile(foo_too_long, &ofs, OF_EXIST);
3694 ok( hFile == HFILE_ERROR, "hFile != HFILE_ERROR : %ld\n", GetLastError());
3696 "GetLastError() returns %ld\n", GetLastError() );
3697 todo_wine
3698 ok( ofs.cBytes == 0xA5, "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3700 "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3701 ok( strncmp(ofs.szPathName, filled_0xA5, OFS_MAXPATHNAME) == 0,
3702 "OpenFile returned '%s', but was expected to return string filled with 0xA5\n",
3703 ofs.szPathName );
3704 }
3705
3706 memset(&ofs, 0xA5, sizeof(ofs));
3707 SetLastError(0xfaceabee);
3708 /* Create an empty file */
3709 hFile = OpenFile(filename, &ofs, OF_CREATE);
3710 ok( hFile != HFILE_ERROR, "OpenFile failed to create nonexistent file\n" );
3711 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS,
3712 "GetLastError() returns %ld\n", GetLastError() );
3713 ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3714 ok( ofs.nErrCode == ERROR_SUCCESS || broken(ofs.nErrCode != ERROR_SUCCESS) /* win9x */,
3715 "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3716 ret = _lclose(hFile);
3717 ok( !ret, "_lclose() returns %d\n", ret );
3719 ok( retval != INVALID_FILE_ATTRIBUTES, "GetFileAttributesA: error %ld\n", GetLastError() );
3720
3721 memset(&ofs, 0xA5, sizeof(ofs));
3722 SetLastError(0xfaceabee);
3723 /* Check various opening options: */
3724 /* for reading only, */
3725 hFile = OpenFile(filename, &ofs, OF_READ);
3726 ok( hFile != HFILE_ERROR, "OpenFile failed on read\n" );
3727 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS,
3728 "GetLastError() returns %ld\n", GetLastError() );
3729 ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3730 ok( ofs.nErrCode == ERROR_SUCCESS || broken(ofs.nErrCode != ERROR_SUCCESS) /* win9x */,
3731 "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3732 ok( lstrcmpiA(ofs.szPathName, filename) == 0,
3733 "OpenFile returned '%s', but was expected to return '%s'\n", ofs.szPathName, filename );
3734 ret = _lclose(hFile);
3735 ok( !ret, "_lclose() returns %d\n", ret );
3736
3737 memset(&ofs, 0xA5, sizeof(ofs));
3738 SetLastError(0xfaceabee);
3739 /* for writing only, */
3740 hFile = OpenFile(filename, &ofs, OF_WRITE);
3741 ok( hFile != HFILE_ERROR, "OpenFile failed on write\n" );
3742 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS,
3743 "GetLastError() returns %ld\n", GetLastError() );
3744 ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3745 ok( ofs.nErrCode == ERROR_SUCCESS || broken(ofs.nErrCode != ERROR_SUCCESS) /* win9x */,
3746 "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3747 ok( lstrcmpiA(ofs.szPathName, filename) == 0,
3748 "OpenFile returned '%s', but was expected to return '%s'\n", ofs.szPathName, filename );
3749 ret = _lclose(hFile);
3750 ok( !ret, "_lclose() returns %d\n", ret );
3751
3752 memset(&ofs, 0xA5, sizeof(ofs));
3753 SetLastError(0xfaceabee);
3754 /* for reading and writing, */
3756 ok( hFile != HFILE_ERROR, "OpenFile failed on read/write\n" );
3757 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS,
3758 "GetLastError() returns %ld\n", GetLastError() );
3759 ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3760 ok( ofs.nErrCode == ERROR_SUCCESS || broken(ofs.nErrCode != ERROR_SUCCESS) /* win9x */,
3761 "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3762 ok( lstrcmpiA(ofs.szPathName, filename) == 0,
3763 "OpenFile returned '%s', but was expected to return '%s'\n", ofs.szPathName, filename );
3764 ret = _lclose(hFile);
3765 ok( !ret, "_lclose() returns %d\n", ret );
3766
3767 memset(&ofs, 0xA5, sizeof(ofs));
3768 SetLastError(0xfaceabee);
3769 /* for checking file presence. */
3770 hFile = OpenFile(filename, &ofs, OF_EXIST);
3771 ok( hFile == 1, "OpenFile failed on finding our created file\n" );
3772 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS,
3773 "GetLastError() returns %ld\n", GetLastError() );
3774 ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3775 ok( ofs.nErrCode == ERROR_SUCCESS || broken(ofs.nErrCode != ERROR_SUCCESS) /* win9x */,
3776 "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3777 ok( lstrcmpiA(ofs.szPathName, filename) == 0,
3778 "OpenFile returned '%s', but was expected to return '%s'\n", ofs.szPathName, filename );
3779
3780 memset(&ofs, 0xA5, sizeof(ofs));
3781 SetLastError(0xfaceabee);
3782 /* Delete the file and make sure it doesn't exist anymore */
3783 hFile = OpenFile(filename, &ofs, OF_DELETE);
3784 ok( hFile == 1, "OpenFile failed on delete (%d)\n", hFile );
3785 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS,
3786 "GetLastError() returns %ld\n", GetLastError() );
3787 ok( ofs.cBytes == sizeof(OFSTRUCT), "OpenFile set ofs.cBytes to %d\n", ofs.cBytes );
3788 ok( ofs.nErrCode == ERROR_SUCCESS || broken(ofs.nErrCode != ERROR_SUCCESS) /* win9x */,
3789 "OpenFile set ofs.nErrCode to %d\n", ofs.nErrCode );
3790 ok( lstrcmpiA(ofs.szPathName, filename) == 0,
3791 "OpenFile returned '%s', but was expected to return '%s'\n", ofs.szPathName, filename );
3792
3794 ok( retval == INVALID_FILE_ATTRIBUTES, "GetFileAttributesA succeeded on deleted file\n" );
3795}
3796
3797static void test_overlapped(void)
3798{
3799 OVERLAPPED ov;
3800 DWORD r, result;
3801
3802 /* GetOverlappedResult crashes if the 2nd or 3rd param are NULL */
3803 if (0) /* tested: WinXP */
3804 {
3806 GetOverlappedResult(0, &ov, NULL, FALSE);
3808 }
3809
3810 memset( &ov, 0, sizeof ov );
3811 result = 1;
3812 r = GetOverlappedResult(0, &ov, &result, 0);
3813 if (r)
3814 ok( result == 0, "wrong result %lu\n", result );
3815 else /* win9x */
3816 ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %lu\n", GetLastError() );
3817
3818 result = 0;
3819 ov.Internal = 0;
3820 ov.InternalHigh = 0xabcd;
3821 r = GetOverlappedResult(0, &ov, &result, 0);
3822 if (r)
3823 ok( result == 0xabcd, "wrong result %lu\n", result );
3824 else /* win9x */
3825 ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %lu\n", GetLastError() );
3826
3827 SetLastError( 0xb00 );
3828 result = 0;
3830 ov.InternalHigh = 0xabcd;
3831 r = GetOverlappedResult(0, &ov, &result, 0);
3832 ok( GetLastError() == ERROR_INVALID_HANDLE, "wrong error %lu\n", GetLastError() );
3833 ok( r == FALSE, "should return false\n");
3834 ok( result == 0xabcd || result == 0 /* win9x */, "wrong result %lu\n", result );
3835
3836 SetLastError( 0xb00 );
3837 result = 0;
3839 ov.InternalHigh = 0xabcd;
3840 r = GetOverlappedResult(0, &ov, &result, 0);
3842 "wrong error %lu\n", GetLastError() );
3843 ok( r == FALSE, "should return false\n");
3844 ok( result == 0, "wrong result %lu\n", result );
3845
3846 SetLastError( 0xb00 );
3847 ov.hEvent = CreateEventW( NULL, 1, 1, NULL );
3849 ov.InternalHigh = 0xabcd;
3850 r = GetOverlappedResult(0, &ov, &result, 0);
3852 "wrong error %lu\n", GetLastError() );
3853 ok( r == FALSE, "should return false\n");
3854
3855 r = GetOverlappedResult( 0, &ov, &result, TRUE );
3856 ok( r == TRUE, "should return TRUE\n" );
3857 ok( result == 0xabcd, "wrong result %lu\n", result );
3858 ok( ov.Internal == STATUS_PENDING, "expected STATUS_PENDING, got %08Ix\n", ov.Internal );
3859
3860 ResetEvent( ov.hEvent );
3861
3862 SetLastError( 0xb00 );
3864 ov.InternalHigh = 0;
3865 r = GetOverlappedResult(0, &ov, &result, 0);
3867 "wrong error %lu\n", GetLastError() );
3868 ok( r == FALSE, "should return false\n");
3869
3870 r = CloseHandle( ov.hEvent );
3871 ok( r == TRUE, "close handle failed\n");
3872}
3873
3874static void test_RemoveDirectory(void)
3875{
3876 int rc;
3877 char directory[] = "removeme";
3878
3880 ok( rc, "Createdirectory failed, gle=%ld\n", GetLastError() );
3881
3883 ok( rc, "SetCurrentDirectory failed, gle=%ld\n", GetLastError() );
3884
3885 rc = RemoveDirectoryA(".");
3886 if (!rc)
3887 {
3888 rc = SetCurrentDirectoryA("..");
3889 ok( rc, "SetCurrentDirectory failed, gle=%ld\n", GetLastError() );
3890
3892 ok( rc, "RemoveDirectory failed, gle=%ld\n", GetLastError() );
3893 }
3894}
3895
3896static BOOL check_file_time( const FILETIME *ft1, const FILETIME *ft2, UINT tolerance )
3897{
3898 ULONGLONG t1 = ((ULONGLONG)ft1->dwHighDateTime << 32) | ft1->dwLowDateTime;
3899 ULONGLONG t2 = ((ULONGLONG)ft2->dwHighDateTime << 32) | ft2->dwLowDateTime;
3900 return (t1 > t2 ? t1 - t2 : t2 - t1) <= tolerance;
3901}
3902
3903static void test_ReplaceFileA(void)
3904{
3905 char replaced[MAX_PATH], replacement[MAX_PATH], backup[MAX_PATH];
3906 HANDLE hReplacedFile, hReplacementFile, hBackupFile, mapping;
3907 static const char replacedData[] = "file-to-replace";
3908 static const char replacementData[] = "new-file";
3909 static const char backupData[] = "backup-file";
3910 FILETIME ftReplaced, ftReplacement, ftBackup;
3911 static const char prefix[] = "pfx";
3912 char temp_path[MAX_PATH];
3913 DWORD ret;
3914 BOOL retok, removeBackup = FALSE;
3915 char **argv;
3916
3918 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
3919 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
3920
3921 ret = GetTempFileNameA(temp_path, prefix, 0, replaced);
3922 ok(ret != 0, "GetTempFileNameA error (replaced) %ld\n", GetLastError());
3923
3924 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
3925 ok(ret != 0, "GetTempFileNameA error (replacement) %ld\n", GetLastError());
3926
3928 ok(ret != 0, "GetTempFileNameA error (backup) %ld\n", GetLastError());
3929
3930 /* place predictable data in the file to be replaced */
3931 hReplacedFile = CreateFileA(replaced, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
3932 ok(hReplacedFile != INVALID_HANDLE_VALUE,
3933 "failed to open replaced file\n");
3934 retok = WriteFile(hReplacedFile, replacedData, sizeof(replacedData), &ret, NULL );
3935 ok( retok && ret == sizeof(replacedData),
3936 "WriteFile error (replaced) %ld\n", GetLastError());
3937 ok(GetFileSize(hReplacedFile, NULL) == sizeof(replacedData),
3938 "replaced file has wrong size\n");
3939 /* place predictable data in the file to be the replacement */
3940 hReplacementFile = CreateFileA(replacement, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
3941 ok(hReplacementFile != INVALID_HANDLE_VALUE,
3942 "failed to open replacement file\n");
3943 retok = WriteFile(hReplacementFile, replacementData, sizeof(replacementData), &ret, NULL );
3944 ok( retok && ret == sizeof(replacementData),
3945 "WriteFile error (replacement) %ld\n", GetLastError());
3946 ok(GetFileSize(hReplacementFile, NULL) == sizeof(replacementData),
3947 "replacement file has wrong size\n");
3948 /* place predictable data in the backup file (to be over-written) */
3949 hBackupFile = CreateFileA(backup, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
3950 ok(hBackupFile != INVALID_HANDLE_VALUE,
3951 "failed to open backup file\n");
3952 retok = WriteFile(hBackupFile, backupData, sizeof(backupData), &ret, NULL );
3953 ok( retok && ret == sizeof(backupData),
3954 "WriteFile error (replacement) %ld\n", GetLastError());
3955 ok(GetFileSize(hBackupFile, NULL) == sizeof(backupData),
3956 "backup file has wrong size\n");
3957 /* change the filetime on the "replaced" file to ensure that it changes */
3958 ret = GetFileTime(hReplacedFile, NULL, NULL, &ftReplaced);
3959 ok( ret, "GetFileTime error (replaced) %ld\n", GetLastError());
3960 ftReplaced.dwLowDateTime -= 600000000; /* 60 second */
3961 ret = SetFileTime(hReplacedFile, NULL, NULL, &ftReplaced);
3962 ok( ret, "SetFileTime error (replaced) %ld\n", GetLastError());
3963 GetFileTime(hReplacedFile, NULL, NULL, &ftReplaced); /* get the actual time back */
3964 CloseHandle(hReplacedFile);
3965 /* change the filetime on the backup to ensure that it changes */
3966 ret = GetFileTime(hBackupFile, NULL, NULL, &ftBackup);
3967 ok( ret, "GetFileTime error (backup) %ld\n", GetLastError());
3968 ftBackup.dwLowDateTime -= 1200000000; /* 120 second */
3969 ret = SetFileTime(hBackupFile, NULL, NULL, &ftBackup);
3970 ok( ret, "SetFileTime error (backup) %ld\n", GetLastError());
3971 GetFileTime(hBackupFile, NULL, NULL, &ftBackup); /* get the actual time back */
3972 CloseHandle(hBackupFile);
3973 /* get the filetime on the replacement file to perform checks */
3974 ret = GetFileTime(hReplacementFile, NULL, NULL, &ftReplacement);
3975 ok( ret, "GetFileTime error (replacement) %ld\n", GetLastError());
3976 CloseHandle(hReplacementFile);
3977
3978 /* perform replacement w/ backup
3979 * TODO: flags are not implemented
3980 */
3981 SetLastError(0xdeadbeef);
3982 ret = ReplaceFileA(replaced, replacement, backup, 0, 0, 0);
3983 ok(ret, "ReplaceFileA: unexpected error %ld\n", GetLastError());
3984 /* make sure that the backup has the size of the old "replaced" file */
3986 ok(hBackupFile != INVALID_HANDLE_VALUE,
3987 "failed to open backup file\n");
3988 ret = GetFileSize(hBackupFile, NULL);
3989 ok(ret == sizeof(replacedData),
3990 "backup file has wrong size %ld\n", ret);
3991 /* make sure that the "replaced" file has the size of the replacement file */
3992 hReplacedFile = CreateFileA(replaced, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
3993 ok(hReplacedFile != INVALID_HANDLE_VALUE,
3994 "failed to open replaced file: %ld\n", GetLastError());
3995 if (hReplacedFile != INVALID_HANDLE_VALUE)
3996 {
3997 ret = GetFileSize(hReplacedFile, NULL);
3998 ok(ret == sizeof(replacementData),
3999 "replaced file has wrong size %ld\n", ret);
4000 /* make sure that the replacement file no-longer exists */
4001 hReplacementFile = CreateFileA(replacement, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
4002 ok(hReplacementFile == INVALID_HANDLE_VALUE,
4003 "unexpected error, replacement file should not exist %ld\n", GetLastError());
4004 /* make sure that the backup has the old "replaced" filetime */
4005 ret = GetFileTime(hBackupFile, NULL, NULL, &ftBackup);
4006 ok( ret, "GetFileTime error (backup %ld\n", GetLastError());
4007 ok(check_file_time(&ftBackup, &ftReplaced, 20000000), "backup file has wrong filetime\n");
4008 CloseHandle(hBackupFile);
4009 /* make sure that the "replaced" has the old replacement filetime */
4010 ret = GetFileTime(hReplacedFile, NULL, NULL, &ftReplaced);
4011 ok( ret, "GetFileTime error (backup %ld\n", GetLastError());
4012 ok(check_file_time(&ftReplaced, &ftReplacement, 20000000),
4013 "replaced file has wrong filetime %lx%08lx / %lx%08lx\n",
4014 ftReplaced.dwHighDateTime, ftReplaced.dwLowDateTime,
4015 ftReplacement.dwHighDateTime, ftReplacement.dwLowDateTime );
4016 CloseHandle(hReplacedFile);
4017 }
4018 else
4019 skip("couldn't open replacement file, skipping tests\n");
4020
4021 /* re-create replacement file for pass w/o backup (blank) */
4022 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4023 ok(ret != 0, "GetTempFileNameA error (replacement) %ld\n", GetLastError());
4024 /* perform replacement w/o backup
4025 * TODO: flags are not implemented
4026 */
4027 SetLastError(0xdeadbeef);
4028 ret = ReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
4030 "ReplaceFileA: unexpected error %ld\n", GetLastError());
4031
4032 /* re-create replacement file for pass w/ backup (backup-file not existing) */
4033 DeleteFileA(replacement);
4034 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4035 ok(ret != 0, "GetTempFileNameA error (replacement) %ld\n", GetLastError());
4037 ok(ret, "DeleteFileA: error (backup) %ld\n", GetLastError());
4038 /* perform replacement w/ backup (no pre-existing backup)
4039 * TODO: flags are not implemented
4040 */
4041 SetLastError(0xdeadbeef);
4042 ret = ReplaceFileA(replaced, replacement, backup, 0, 0, 0);
4044 "ReplaceFileA: unexpected error %ld\n", GetLastError());
4045 if (ret)
4046 removeBackup = TRUE;
4047
4048 /* re-create replacement file for pass w/ no permissions to "replaced" */
4049 DeleteFileA(replacement);
4050 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4051 ok(ret != 0, "GetTempFileNameA error (replacement) %ld\n", GetLastError());
4054 "SetFileAttributesA: error setting to read only %ld\n", GetLastError());
4055 /* perform replacement w/ backup (no permission to "replaced")
4056 * TODO: flags are not implemented
4057 */
4058 SetLastError(0xdeadbeef);
4059 ret = ReplaceFileA(replaced, replacement, backup, 0, 0, 0);
4060 ok(ret == 0 && GetLastError() == ERROR_ACCESS_DENIED, "ReplaceFileA: unexpected error %ld\n", GetLastError());
4061 /* make sure that the replacement file still exists */
4062 hReplacementFile = CreateFileA(replacement, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
4063 ok(hReplacementFile != INVALID_HANDLE_VALUE ||
4064 broken(GetLastError() == ERROR_FILE_NOT_FOUND), /* win2k */
4065 "unexpected error, replacement file should still exist %ld\n", GetLastError());
4066 CloseHandle(hReplacementFile);
4069 "SetFileAttributesA: error setting to normal %ld\n", GetLastError());
4070
4071 /* replacement readonly */
4072 DeleteFileA(replacement);
4073 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4074 ok(ret != 0, "GetTempFileNameA error (replacement) %#lx\n", GetLastError());
4076 ok(ret, "SetFileAttributesA: error setting to readonly %#lx\n", GetLastError());
4077 ret = ReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
4078 ok(GetLastError() == ERROR_ACCESS_DENIED, "ReplaceFileA: unexpected error %#lx\n", GetLastError());
4080 ok(ret, "SetFileAttributesA: error setting to normal %#lx\n", GetLastError());
4081
4082 /* re-create replacement file for pass w/ replaced opened with
4083 * the same permissions as an exe (Replicating an exe trying to
4084 * replace itself)
4085 */
4086 DeleteFileA(replacement);
4087 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4088 ok(ret != 0, "GetTempFileNameA error (replacement) %ld\n", GetLastError());
4089
4090 /* make sure that the replaced file is opened like an exe*/
4092 ok(hReplacedFile != INVALID_HANDLE_VALUE,
4093 "unexpected error, replaced file should be able to be opened %ld\n", GetLastError());
4094 /*Calling ReplaceFileA on an exe should succeed*/
4095 ret = ReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
4096 ok(ret, "ReplaceFileA: unexpected error %ld\n", GetLastError());
4097 CloseHandle(hReplacedFile);
4098
4099 /* replace file while replacement is opened */
4100 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4101 ok(ret != 0, "GetTempFileNameA error (replacement) %ld\n", GetLastError());
4102 hReplacementFile = CreateFileA(replacement, GENERIC_READ | SYNCHRONIZE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, 0, 0);
4103 ok(hReplacementFile != INVALID_HANDLE_VALUE, "unexpected error, replacement file should be able to be opened %ld\n",
4104 GetLastError());
4105 ret = ReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
4106 ok(!ret, "expect failure\n");
4107 ok(GetLastError() == ERROR_SHARING_VIOLATION, "expect ERROR_SHARING_VIOLATION, got %#lx.\n", GetLastError());
4108 CloseHandle(hReplacementFile);
4109
4110 /* replacement file still exists, make pass w/o "replaced" */
4111 ret = DeleteFileA(replaced);
4113 "DeleteFileA: error (replaced) %ld\n", GetLastError());
4114 /* perform replacement w/ backup (no pre-existing backup or "replaced")
4115 * TODO: flags are not implemented
4116 */
4117 SetLastError(0xdeadbeef);
4118 ret = ReplaceFileA(replaced, replacement, backup, 0, 0, 0);
4121 "ReplaceFileA: unexpected error %ld\n", GetLastError());
4122
4123 /* perform replacement w/o existing "replacement" file
4124 * TODO: flags are not implemented
4125 */
4126 SetLastError(0xdeadbeef);
4127 ret = ReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
4130 "ReplaceFileA: unexpected error %ld\n", GetLastError());
4131 DeleteFileA( replacement );
4132
4133 /*
4134 * if the first round (w/ backup) worked then as long as there is no
4135 * failure then there is no need to check this round (w/ backup is the
4136 * more complete case)
4137 */
4138
4139 /* delete temporary files, replacement and replaced are already deleted */
4140 if (removeBackup)
4141 {
4143 ok(ret ||
4144 broken(GetLastError() == ERROR_ACCESS_DENIED), /* win2k */
4145 "DeleteFileA: error (backup) %ld\n", GetLastError());
4146 }
4147
4148 ret = GetTempFileNameA(temp_path, prefix, 0, replaced);
4149 ok(ret, "got error %lu\n", GetLastError());
4150 hReplacedFile = CreateFileA(replaced, 0, 0, NULL, OPEN_EXISTING, 0, 0);
4151 ok(hReplacedFile != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
4152
4153 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4154 ok(ret, "got error %lu\n", GetLastError());
4155
4156 ret = ReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
4157 ok(ret, "got error %lu\n", GetLastError());
4158
4159 CloseHandle(hReplacedFile);
4160 ret = DeleteFileA(replaced);
4161 ok(ret, "got error %lu\n", GetLastError());
4162
4164
4165 ret = CopyFileA(argv[0], replaced, FALSE);
4166 ok(ret, "got error %lu\n", GetLastError());
4167 hReplacedFile = CreateFileA(replaced, GENERIC_READ,
4169 ok(hReplacedFile != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
4170
4171 mapping = CreateFileMappingA(hReplacedFile, NULL, PAGE_READONLY | SEC_IMAGE, 0, 0, NULL);
4172 ok(!!mapping, "got error %lu\n", GetLastError());
4173
4174 ret = GetTempFileNameA(temp_path, prefix, 0, replacement);
4175 ok(ret, "got error %lu\n", GetLastError());
4176
4177 ret = ReplaceFileA(replaced, replacement, NULL, 0, 0, 0);
4178 ok(ret, "got error %lu\n", GetLastError());
4179
4181 CloseHandle(hReplacedFile);
4182 ret = DeleteFileA(replaced);
4183 ok(ret, "got error %lu\n", GetLastError());
4184}
4185
4186/*
4187 * ReplaceFileW is a simpler case of ReplaceFileA, there is no
4188 * need to be as thorough.
4189 */
4190static void test_ReplaceFileW(void)
4191{
4192 WCHAR replaced[MAX_PATH], replacement[MAX_PATH], backup[MAX_PATH];
4193 static const WCHAR prefix[] = {'p','f','x',0};
4195 DWORD ret;
4196 BOOL removeBackup = FALSE;
4197
4198 if (!pReplaceFileW)
4199 {
4200 win_skip("ReplaceFileW() is missing\n");
4201 return;
4202 }
4203
4206 {
4207 win_skip("GetTempPathW is not available\n");
4208 return;
4209 }
4210 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
4211 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
4212
4213 ret = GetTempFileNameW(temp_path, prefix, 0, replaced);
4214 ok(ret != 0, "GetTempFileNameW error (replaced) %ld\n", GetLastError());
4215
4216 ret = GetTempFileNameW(temp_path, prefix, 0, replacement);
4217 ok(ret != 0, "GetTempFileNameW error (replacement) %ld\n", GetLastError());
4218
4220 ok(ret != 0, "GetTempFileNameW error (backup) %ld\n", GetLastError());
4221
4222 ret = pReplaceFileW(replaced, replacement, backup, 0, 0, 0);
4223 ok(ret, "ReplaceFileW: error %ld\n", GetLastError());
4224
4225 ret = GetTempFileNameW(temp_path, prefix, 0, replacement);
4226 ok(ret != 0, "GetTempFileNameW error (replacement) %ld\n", GetLastError());
4227 ret = pReplaceFileW(replaced, replacement, NULL, 0, 0, 0);
4229 "ReplaceFileW: error %ld\n", GetLastError());
4230
4231 ret = GetTempFileNameW(temp_path, prefix, 0, replacement);
4232 ok(ret != 0, "GetTempFileNameW error (replacement) %ld\n", GetLastError());
4234 ok(ret, "DeleteFileW: error (backup) %ld\n", GetLastError());
4235 ret = pReplaceFileW(replaced, replacement, backup, 0, 0, 0);
4237 "ReplaceFileW: error %ld\n", GetLastError());
4238
4239 ret = GetTempFileNameW(temp_path, prefix, 0, replacement);
4240 ok(ret != 0, "GetTempFileNameW error (replacement) %ld\n", GetLastError());
4243 "SetFileAttributesW: error setting to read only %ld\n", GetLastError());
4244
4245 SetLastError(0xdeadbeef);
4246 ret = pReplaceFileW(replaced, replacement, backup, 0, 0, 0);
4247 ok(!ret, "expected failure\n");
4248 ok(GetLastError() == ERROR_ACCESS_DENIED, "got error %lu\n", GetLastError());
4251 "SetFileAttributesW: error setting to normal %ld\n", GetLastError());
4252 if (ret)
4253 removeBackup = TRUE;
4254
4255 ret = DeleteFileW(replaced);
4256 ok(ret, "DeleteFileW: error (replaced) %ld\n", GetLastError());
4257 ret = pReplaceFileW(replaced, replacement, backup, 0, 0, 0);
4258 ok(!ret, "ReplaceFileW: error %ld\n", GetLastError());
4259
4260 ret = pReplaceFileW(replaced, replacement, NULL, 0, 0, 0);
4263 "ReplaceFileW: unexpected error %ld\n", GetLastError());
4264 DeleteFileW( replacement );
4265
4266 if (removeBackup)
4267 {
4269 ok(ret ||
4270 broken(GetLastError() == ERROR_ACCESS_DENIED), /* win2k */
4271 "DeleteFileW: error (backup) %ld\n", GetLastError());
4272 }
4273}
4274
4275static void test_CreateFile(void)
4276{
4277 static const struct test_data
4278 {
4279 DWORD disposition, access, error, clean_up;
4280 } td[] =
4281 {
4282 /* 0 */ { 0, 0, ERROR_INVALID_PARAMETER, 0 },
4283 /* 1 */ { 0, GENERIC_READ, ERROR_INVALID_PARAMETER, 0 },
4285 /* 3 */ { CREATE_NEW, 0, ERROR_FILE_EXISTS, 1 },
4286 /* 4 */ { CREATE_NEW, 0, 0, 1 },
4287 /* 5 */ { CREATE_NEW, GENERIC_READ, 0, 1 },
4288 /* 6 */ { CREATE_NEW, GENERIC_WRITE, 0, 1 },
4289 /* 7 */ { CREATE_NEW, GENERIC_READ|GENERIC_WRITE, 0, 0 },
4290 /* 8 */ { CREATE_ALWAYS, 0, 0, 0 },
4291 /* 9 */ { CREATE_ALWAYS, GENERIC_READ, 0, 0 },
4292 /* 10*/ { CREATE_ALWAYS, GENERIC_WRITE, 0, 0 },
4293 /* 11*/ { CREATE_ALWAYS, GENERIC_READ|GENERIC_WRITE, 0, 1 },
4294 /* 12*/ { OPEN_EXISTING, 0, ERROR_FILE_NOT_FOUND, 0 },
4295 /* 13*/ { CREATE_ALWAYS, 0, 0, 0 },
4296 /* 14*/ { OPEN_EXISTING, 0, 0, 0 },
4297 /* 15*/ { OPEN_EXISTING, GENERIC_READ, 0, 0 },
4298 /* 16*/ { OPEN_EXISTING, GENERIC_WRITE, 0, 0 },
4299 /* 17*/ { OPEN_EXISTING, GENERIC_READ|GENERIC_WRITE, 0, 1 },
4300 /* 18*/ { OPEN_ALWAYS, 0, 0, 0 },
4301 /* 19*/ { OPEN_ALWAYS, GENERIC_READ, 0, 0 },
4302 /* 20*/ { OPEN_ALWAYS, GENERIC_WRITE, 0, 0 },
4303 /* 21*/ { OPEN_ALWAYS, GENERIC_READ|GENERIC_WRITE, 0, 0 },
4304 /* 22*/ { TRUNCATE_EXISTING, 0, ERROR_INVALID_PARAMETER, 0 },
4306 /* 24*/ { TRUNCATE_EXISTING, GENERIC_WRITE, 0, 0 },
4307 /* 25*/ { TRUNCATE_EXISTING, GENERIC_READ|GENERIC_WRITE, 0, 0 },
4309 };
4310 char temp_path[MAX_PATH];
4311 char file_name[MAX_PATH];
4312 DWORD i, ret, written;
4313 HANDLE hfile;
4314
4317
4318 i = strlen(temp_path);
4319 if (i && temp_path[i - 1] == '\\') temp_path[i - 1] = 0;
4320
4321 for (i = 0; i <= 5; i++)
4322 {
4323 SetLastError(0xdeadbeef);
4324 hfile = CreateFileA(temp_path, GENERIC_READ, 0, NULL, i, 0, 0);
4325 ok(hfile == INVALID_HANDLE_VALUE, "CreateFile should fail\n");
4326 if (i == 0 || i == 5)
4327 {
4328 /* FIXME: remove once Wine is fixed */
4329 todo_wine_if (i == 5)
4330 ok(GetLastError() == ERROR_INVALID_PARAMETER, "%ld: expected ERROR_INVALID_PARAMETER, got %ld\n", i, GetLastError());
4331 }
4332 else
4333 {
4334 /* FIXME: remove once Wine is fixed */
4335 todo_wine_if (i == 1)
4336 ok(GetLastError() == ERROR_ACCESS_DENIED, "%ld: expected ERROR_ACCESS_DENIED, got %ld\n", i, GetLastError());
4337 }
4338
4339 SetLastError(0xdeadbeef);
4340 hfile = CreateFileA(temp_path, GENERIC_WRITE, 0, NULL, i, 0, 0);
4341 ok(hfile == INVALID_HANDLE_VALUE, "CreateFile should fail\n");
4342 if (i == 0)
4343 ok(GetLastError() == ERROR_INVALID_PARAMETER, "%ld: expected ERROR_INVALID_PARAMETER, got %ld\n", i, GetLastError());
4344 else
4345 {
4346 /* FIXME: remove once Wine is fixed */
4347 todo_wine_if (i == 1)
4348 ok(GetLastError() == ERROR_ACCESS_DENIED, "%ld: expected ERROR_ACCESS_DENIED, got %ld\n", i, GetLastError());
4349 }
4350 }
4351
4352 for (i = 0; i < ARRAY_SIZE(td); i++)
4353 {
4354 SetLastError(0xdeadbeef);
4355 hfile = CreateFileA(file_name, td[i].access, 0, NULL, td[i].disposition, 0, 0);
4356 if (!td[i].error)
4357 {
4358 ok(hfile != INVALID_HANDLE_VALUE, "%ld: CreateFile error %ld\n", i, GetLastError());
4359 written = 0xdeadbeef;
4360 SetLastError(0xdeadbeef);
4361 ret = WriteFile(hfile, &td[i].error, sizeof(td[i].error), &written, NULL);
4362 if (td[i].access & GENERIC_WRITE)
4363 ok(ret, "%ld: WriteFile error %ld\n", i, GetLastError());
4364 else
4365 {
4366 ok(!ret, "%ld: WriteFile should fail\n", i);
4367 ok(GetLastError() == ERROR_ACCESS_DENIED, "%ld: expected ERROR_ACCESS_DENIED, got %ld\n", i, GetLastError());
4368 }
4369 SetLastError(0xdeadbeef);
4370 ret = SetFileTime(hfile, NULL, NULL, NULL);
4371 if (td[i].access & GENERIC_WRITE) /* actually FILE_WRITE_ATTRIBUTES */
4372 ok(ret, "%ld: SetFileTime error %ld\n", i, GetLastError());
4373 else
4374 {
4375 todo_wine
4376 {
4377 ok(!ret, "%ld: SetFileTime should fail\n", i);
4378 ok(GetLastError() == ERROR_ACCESS_DENIED, "%ld: expected ERROR_ACCESS_DENIED, got %ld\n", i, GetLastError());
4379 }
4380 }
4381 CloseHandle(hfile);
4382 }
4383 else
4384 {
4385 /* FIXME: remove the condition below once Wine is fixed */
4386 if (td[i].disposition == TRUNCATE_EXISTING && !(td[i].access & GENERIC_WRITE))
4387 {
4388 todo_wine
4389 {
4390 ok(hfile == INVALID_HANDLE_VALUE, "%ld: CreateFile should fail\n", i);
4391 ok(GetLastError() == td[i].error, "%ld: expected %ld, got %ld\n", i, td[i].error, GetLastError());
4392 }
4393 CloseHandle(hfile);
4394 }
4395 else
4396 {
4397 ok(hfile == INVALID_HANDLE_VALUE, "%ld: CreateFile should fail\n", i);
4398 ok(GetLastError() == td[i].error, "%ld: expected %ld, got %ld\n", i, td[i].error, GetLastError());
4399 }
4400 }
4401
4402 if (td[i].clean_up) DeleteFileA(file_name);
4403 }
4404
4406}
4407
4409{
4410 int i;
4411 char tempPath[MAX_PATH], tempFileName[MAX_PATH], buffer[1024], *strPtr;
4412 BOOL ret;
4413 DWORD ret2, written;
4415 FILE_ID_BOTH_DIR_INFO *bothDirInfo;
4416 FILE_BASIC_INFO *basicInfo;
4417 FILE_STANDARD_INFO *standardInfo;
4418 FILE_NAME_INFO *nameInfo;
4419 LARGE_INTEGER prevWrite;
4420 FILE_IO_PRIORITY_HINT_INFO priohintinfo;
4421 FILE_ALLOCATION_INFO allocinfo;
4422 FILE_DISPOSITION_INFO dispinfo;
4423 FILE_END_OF_FILE_INFO eofinfo;
4424 FILE_RENAME_INFO renameinfo;
4425
4426 struct {
4427 FILE_INFO_BY_HANDLE_CLASS handleClass;
4428 void *ptr;
4429 DWORD size;
4430 DWORD errorCode;
4431 } checks[] = {
4432 {0xdeadbeef, NULL, 0, ERROR_INVALID_PARAMETER},
4436
4437 if (!pGetFileInformationByHandleEx)
4438 {
4439 win_skip("GetFileInformationByHandleEx is missing.\n");
4440 return;
4441 }
4442
4443 ret2 = GetTempPathA(sizeof(tempPath), tempPath);
4444 ok(ret2, "GetFileInformationByHandleEx: GetTempPathA failed, got error %lu.\n", GetLastError());
4445
4446 /* ensure the existence of a file in the temp folder */
4447 ret2 = GetTempFileNameA(tempPath, "abc", 0, tempFileName);
4448 ok(ret2, "GetFileInformationByHandleEx: GetTempFileNameA failed, got error %lu.\n", GetLastError());
4449 ret2 = GetFileAttributesA(tempFileName);
4450 ok(ret2 != INVALID_FILE_ATTRIBUTES, "GetFileInformationByHandleEx: "
4451 "GetFileAttributesA failed to find the temp file, got error %lu.\n", GetLastError());
4452
4455 ok(directory != INVALID_HANDLE_VALUE, "GetFileInformationByHandleEx: failed to open the temp folder, "
4456 "got error %lu.\n", GetLastError());
4457
4458 for (i = 0; i < ARRAY_SIZE(checks); i += 1)
4459 {
4460 SetLastError(0xdeadbeef);
4461 ret = pGetFileInformationByHandleEx(directory, checks[i].handleClass, checks[i].ptr, checks[i].size);
4462 ok(!ret && GetLastError() == checks[i].errorCode, "GetFileInformationByHandleEx: expected error %lu, "
4463 "got %lu.\n", checks[i].errorCode, GetLastError());
4464 }
4465
4466 while (TRUE)
4467 {
4468 memset(buffer, 0xff, sizeof(buffer));
4469 ret = pGetFileInformationByHandleEx(directory, FileIdBothDirectoryInfo, buffer, sizeof(buffer));
4471 break;
4472 ok(ret, "GetFileInformationByHandleEx: failed to query for FileIdBothDirectoryInfo, got error %lu.\n", GetLastError());
4473 if (!ret)
4474 break;
4475 bothDirInfo = (FILE_ID_BOTH_DIR_INFO *)buffer;
4476 while (TRUE)
4477 {
4478 ok(bothDirInfo->FileAttributes != 0xffffffff, "GetFileInformationByHandleEx: returned invalid file attributes.\n");
4479 ok(bothDirInfo->FileId.u.LowPart != 0xffffffff, "GetFileInformationByHandleEx: returned invalid file id.\n");
4480 ok(bothDirInfo->FileNameLength != 0xffffffff, "GetFileInformationByHandleEx: returned invalid file name length.\n");
4481 if (!bothDirInfo->NextEntryOffset)
4482 break;
4483 bothDirInfo = (FILE_ID_BOTH_DIR_INFO *)(((char *)bothDirInfo) + bothDirInfo->NextEntryOffset);
4484 }
4485 }
4486
4488
4490 NULL, OPEN_EXISTING, 0, NULL);
4491 ok(file != INVALID_HANDLE_VALUE, "GetFileInformationByHandleEx: failed to open the temp file, "
4492 "got error %lu.\n", GetLastError());
4493
4494 /* Test FileBasicInfo; make sure the write time changes when a file is updated */
4495 memset(buffer, 0xff, sizeof(buffer));
4496 ret = pGetFileInformationByHandleEx(file, FileBasicInfo, buffer, sizeof(buffer));
4497 ok(ret, "GetFileInformationByHandleEx: failed to get FileBasicInfo, %lu\n", GetLastError());
4498 basicInfo = (FILE_BASIC_INFO *)buffer;
4499 prevWrite = basicInfo->LastWriteTime;
4501
4502 Sleep(30); /* Make sure a new write time is different from the previous */
4503
4504 /* Write something to the file, to make sure the write time has changed */
4506 NULL, OPEN_EXISTING, 0, NULL);
4507 ok(file != INVALID_HANDLE_VALUE, "GetFileInformationByHandleEx: failed to open the temp file, "
4508 "got error %lu.\n", GetLastError());
4509 ret = WriteFile(file, tempFileName, strlen(tempFileName), &written, NULL);
4510 ok(ret, "GetFileInformationByHandleEx: Write failed\n");
4512
4514 NULL, OPEN_EXISTING, 0, NULL);
4515 ok(file != INVALID_HANDLE_VALUE, "GetFileInformationByHandleEx: failed to open the temp file, "
4516 "got error %lu.\n", GetLastError());
4517
4518 memset(buffer, 0xff, sizeof(buffer));
4519 ret = pGetFileInformationByHandleEx(file, FileBasicInfo, buffer, sizeof(buffer));
4520 ok(ret, "GetFileInformationByHandleEx: failed to get FileBasicInfo, %lu\n", GetLastError());
4521 basicInfo = (FILE_BASIC_INFO *)buffer;
4522 /* Could also check that the creation time didn't change - on windows
4523 * it doesn't, but on wine, it does change even if it shouldn't. */
4524 ok(basicInfo->LastWriteTime.QuadPart != prevWrite.QuadPart,
4525 "GetFileInformationByHandleEx: last write time didn't change\n");
4526
4527 /* Test FileStandardInfo, check some basic parameters */
4528 memset(buffer, 0xff, sizeof(buffer));
4529 ret = pGetFileInformationByHandleEx(file, FileStandardInfo, buffer, sizeof(buffer));
4530 ok(ret, "GetFileInformationByHandleEx: failed to get FileStandardInfo, %lu\n", GetLastError());
4531 standardInfo = (FILE_STANDARD_INFO *)buffer;
4532 ok(standardInfo->NumberOfLinks == 1, "GetFileInformationByHandleEx: Unexpected number of links\n");
4533 ok(standardInfo->DeletePending == FALSE, "GetFileInformationByHandleEx: Unexpected pending delete\n");
4534 ok(standardInfo->Directory == FALSE, "GetFileInformationByHandleEx: Incorrect directory flag\n");
4535
4536 /* Test FileNameInfo */
4537 memset(buffer, 0xff, sizeof(buffer));
4538 ret = pGetFileInformationByHandleEx(file, FileNameInfo, buffer, sizeof(buffer));
4539 ok(ret, "GetFileInformationByHandleEx: failed to get FileNameInfo, %lu\n", GetLastError());
4540 nameInfo = (FILE_NAME_INFO *)buffer;
4541 strPtr = strchr(tempFileName, '\\');
4542 ok(strPtr != NULL, "GetFileInformationByHandleEx: Temp filename didn't contain backslash\n");
4543 ok(nameInfo->FileNameLength == strlen(strPtr) * 2,
4544 "GetFileInformationByHandleEx: Incorrect file name length\n");
4545 for (i = 0; i < nameInfo->FileNameLength/2; i++)
4546 ok(strPtr[i] == nameInfo->FileName[i], "Incorrect filename char %d: %c vs %c\n",
4547 i, strPtr[i], nameInfo->FileName[i]);
4548
4549 /* invalid classes */
4550 SetLastError(0xdeadbeef);
4551 ret = pGetFileInformationByHandleEx(file, FileEndOfFileInfo, &eofinfo, sizeof(eofinfo));
4552 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
4553
4554 SetLastError(0xdeadbeef);
4555 ret = pGetFileInformationByHandleEx(file, FileIoPriorityHintInfo, &priohintinfo, sizeof(priohintinfo));
4556 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
4557
4558 SetLastError(0xdeadbeef);
4559 ret = pGetFileInformationByHandleEx(file, FileAllocationInfo, &allocinfo, sizeof(allocinfo));
4560 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
4561
4562 SetLastError(0xdeadbeef);
4563 ret = pGetFileInformationByHandleEx(file, FileDispositionInfo, &dispinfo, sizeof(dispinfo));
4564 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
4565
4566 SetLastError(0xdeadbeef);
4567 ret = pGetFileInformationByHandleEx(file, FileRenameInfo, &renameinfo, sizeof(renameinfo));
4568 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
4569
4571 DeleteFileA(tempFileName);
4572}
4573
4574static void test_OpenFileById(void)
4575{
4576 char tempPath[MAX_PATH], tempFileName[MAX_PATH], buffer[256], tickCount[256];
4577 WCHAR tempFileNameW[MAX_PATH];
4578 BOOL ret, found;
4579 DWORD ret2, count, tempFileNameLen;
4580 HANDLE directory, handle, tempFile;
4581 FILE_ID_BOTH_DIR_INFO *bothDirInfo;
4582 FILE_ID_DESCRIPTOR fileIdDescr;
4583
4584 if (!pGetFileInformationByHandleEx || !pOpenFileById)
4585 {
4586 win_skip("GetFileInformationByHandleEx or OpenFileById is missing.\n");
4587 return;
4588 }
4589
4590 ret2 = GetTempPathA(sizeof(tempPath), tempPath);
4591 ok(ret2, "OpenFileById: GetTempPath failed, got error %lu.\n", GetLastError());
4592
4593 /* ensure the existence of a file in the temp folder */
4594 ret2 = GetTempFileNameA(tempPath, "abc", 0, tempFileName);
4595 ok(ret2, "OpenFileById: GetTempFileNameA failed, got error %lu.\n", GetLastError());
4596 ret2 = GetFileAttributesA(tempFileName);
4598 "OpenFileById: GetFileAttributesA failed to find the temp file, got error %lu\n", GetLastError());
4599
4600 ret2 = MultiByteToWideChar(CP_ACP, 0, tempFileName + strlen(tempPath), -1, tempFileNameW, ARRAY_SIZE(tempFileNameW));
4601 ok(ret2, "OpenFileById: MultiByteToWideChar failed to convert tempFileName, got error %lu.\n", GetLastError());
4602 tempFileNameLen = ret2 - 1;
4603
4605 ok(tempFile != INVALID_HANDLE_VALUE, "OpenFileById: failed to create a temp file, "
4606 "got error %lu.\n", GetLastError());
4607 ret2 = sprintf(tickCount, "%lu", GetTickCount());
4608 ret = WriteFile(tempFile, tickCount, ret2, &count, NULL);
4609 ok(ret, "OpenFileById: WriteFile failed, got error %lu.\n", GetLastError());
4610 CloseHandle(tempFile);
4611
4614 ok(directory != INVALID_HANDLE_VALUE, "OpenFileById: failed to open the temp folder, "
4615 "got error %lu.\n", GetLastError());
4616
4617 /* get info about the temp folder itself */
4618 bothDirInfo = (FILE_ID_BOTH_DIR_INFO *)buffer;
4619 ret = pGetFileInformationByHandleEx(directory, FileIdBothDirectoryInfo, buffer, sizeof(buffer));
4620 ok(ret, "OpenFileById: failed to query for FileIdBothDirectoryInfo, got error %lu.\n", GetLastError());
4621 ok(bothDirInfo->FileNameLength == sizeof(WCHAR) && bothDirInfo->FileName[0] == '.',
4622 "OpenFileById: failed to return the temp folder at the first entry, got error %lu.\n", GetLastError());
4623
4624 /* open the temp folder itself */
4625 fileIdDescr.dwSize = sizeof(fileIdDescr);
4626 fileIdDescr.Type = FileIdType;
4627 fileIdDescr.FileId = bothDirInfo->FileId;
4628 handle = pOpenFileById(directory, &fileIdDescr, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, 0);
4629 todo_wine
4630 ok(handle != INVALID_HANDLE_VALUE, "OpenFileById: failed to open the temp folder itself, got error %lu.\n", GetLastError());
4632
4633 /* find the temp file in the temp folder */
4634 found = FALSE;
4635 while (!found)
4636 {
4637 ret = pGetFileInformationByHandleEx(directory, FileIdBothDirectoryInfo, buffer, sizeof(buffer));
4638 ok(ret, "OpenFileById: failed to query for FileIdBothDirectoryInfo, got error %lu.\n", GetLastError());
4639 if (!ret)
4640 break;
4641 bothDirInfo = (FILE_ID_BOTH_DIR_INFO *)buffer;
4642 while (TRUE)
4643 {
4644 if (tempFileNameLen == bothDirInfo->FileNameLength / sizeof(WCHAR) &&
4645 memcmp(tempFileNameW, bothDirInfo->FileName, bothDirInfo->FileNameLength) == 0)
4646 {
4647 found = TRUE;
4648 break;
4649 }
4650 if (!bothDirInfo->NextEntryOffset)
4651 break;
4652 bothDirInfo = (FILE_ID_BOTH_DIR_INFO *)(((char *)bothDirInfo) + bothDirInfo->NextEntryOffset);
4653 }
4654 }
4655 ok(found, "OpenFileById: failed to find the temp file in the temp folder.\n");
4656
4657 SetLastError(0xdeadbeef);
4660 "OpenFileById: expected ERROR_INVALID_PARAMETER, got error %lu.\n", GetLastError());
4661
4662 fileIdDescr.dwSize = sizeof(fileIdDescr);
4663 fileIdDescr.Type = FileIdType;
4664 fileIdDescr.FileId = bothDirInfo->FileId;
4665 handle = pOpenFileById(directory, &fileIdDescr, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, 0);
4666 ok(handle != INVALID_HANDLE_VALUE, "OpenFileById: failed to open the file, got error %lu.\n", GetLastError());
4667
4668 ret = ReadFile(handle, buffer, sizeof(buffer), &count, NULL);
4669 buffer[count] = 0;
4670 ok(ret, "OpenFileById: ReadFile failed, got error %lu.\n", GetLastError());
4671 ok(strcmp(tickCount, buffer) == 0, "OpenFileById: invalid contents of the temp file.\n");
4672
4675 DeleteFileA(tempFileName);
4676}
4677
4678static void test_SetFileValidData(void)
4679{
4680 BOOL ret;
4681 HANDLE handle;
4682 DWORD error, count;
4684 TOKEN_PRIVILEGES privs;
4685 HANDLE token = NULL;
4686
4687 if (!pSetFileValidData)
4688 {
4689 win_skip("SetFileValidData is missing\n");
4690 return;
4691 }
4692 GetTempPathA(sizeof(path), path);
4693 GetTempFileNameA(path, "tst", 0, filename);
4695 WriteFile(handle, "test", sizeof("test") - 1, &count, NULL);
4697
4698 SetLastError(0xdeadbeef);
4699 ret = pSetFileValidData(INVALID_HANDLE_VALUE, 0);
4700 error = GetLastError();
4701 ok(!ret, "SetFileValidData succeeded\n");
4702 ok(error == ERROR_INVALID_HANDLE, "got %lu\n", error);
4703
4704 SetLastError(0xdeadbeef);
4705 ret = pSetFileValidData(INVALID_HANDLE_VALUE, -1);
4706 error = GetLastError();
4707 ok(!ret, "SetFileValidData succeeded\n");
4708 ok(error == ERROR_INVALID_HANDLE, "got %lu\n", error);
4709
4710 /* file opened for reading */
4712
4713 SetLastError(0xdeadbeef);
4714 ret = pSetFileValidData(handle, 0);
4715 ok(!ret, "SetFileValidData succeeded\n");
4716 error = GetLastError();
4717 ok(error == ERROR_ACCESS_DENIED, "got %lu\n", error);
4718
4719 SetLastError(0xdeadbeef);
4720 ret = pSetFileValidData(handle, -1);
4721 error = GetLastError();
4722 ok(!ret, "SetFileValidData succeeded\n");
4723 ok(error == ERROR_ACCESS_DENIED, "got %lu\n", error);
4725
4727
4728 SetLastError(0xdeadbeef);
4729 ret = pSetFileValidData(handle, 0);
4730 error = GetLastError();
4731 ok(!ret, "SetFileValidData succeeded\n");
4734
4735 privs.PrivilegeCount = 1;
4737
4740 !AdjustTokenPrivileges(token, FALSE, &privs, sizeof(privs), NULL, NULL) ||
4742 {
4743 win_skip("cannot enable SE_MANAGE_VOLUME_NAME privilege\n");
4746 return;
4747 }
4749
4750 SetLastError(0xdeadbeef);
4751 ret = pSetFileValidData(handle, 0);
4752 error = GetLastError();
4753 ok(!ret, "SetFileValidData succeeded\n");
4754 ok(error == ERROR_INVALID_PARAMETER, "got %lu\n", error);
4755
4756 SetLastError(0xdeadbeef);
4757 ret = pSetFileValidData(handle, -1);
4758 error = GetLastError();
4759 ok(!ret, "SetFileValidData succeeded\n");
4760 ok(error == ERROR_INVALID_PARAMETER, "got %lu\n", error);
4761
4762 SetLastError(0xdeadbeef);
4763 ret = pSetFileValidData(handle, 2);
4764 error = GetLastError();
4765 todo_wine ok(!ret, "SetFileValidData succeeded\n");
4767
4768 ret = pSetFileValidData(handle, 4);
4769 ok(ret, "SetFileValidData failed %lu\n", GetLastError());
4770
4771 SetLastError(0xdeadbeef);
4772 ret = pSetFileValidData(handle, 8);
4773 error = GetLastError();
4774 ok(!ret, "SetFileValidData succeeded\n");
4775 ok(error == ERROR_INVALID_PARAMETER, "got %lu\n", error);
4776
4778 ok(count != INVALID_SET_FILE_POINTER, "SetFilePointer failed %lu\n", GetLastError());
4780 ok(ret, "SetEndOfFile failed %lu\n", GetLastError());
4781
4782 SetLastError(0xdeadbeef);
4783 ret = pSetFileValidData(handle, 2);
4784 error = GetLastError();
4785 todo_wine ok(!ret, "SetFileValidData succeeded\n");
4787
4788 ret = pSetFileValidData(handle, 4);
4789 ok(ret, "SetFileValidData failed %lu\n", GetLastError());
4790
4791 ret = pSetFileValidData(handle, 8);
4792 ok(ret, "SetFileValidData failed %lu\n", GetLastError());
4793
4794 ret = pSetFileValidData(handle, 4);
4795 error = GetLastError();
4796 todo_wine ok(!ret, "SetFileValidData succeeded\n");
4798
4799 ret = pSetFileValidData(handle, 1024);
4800 ok(ret, "SetFileValidData failed %lu\n", GetLastError());
4801
4802 ret = pSetFileValidData(handle, 2048);
4803 error = GetLastError();
4804 ok(!ret, "SetFileValidData succeeded\n");
4805 ok(error == ERROR_INVALID_PARAMETER, "got %lu\n", error);
4806
4807 privs.Privileges[0].Attributes = 0;
4808 AdjustTokenPrivileges(token, FALSE, &privs, sizeof(privs), NULL, NULL);
4809
4813}
4814
4815static void test_ReOpenFile(void)
4816{
4817 char path[MAX_PATH], filename[MAX_PATH], buffer[4];
4818 HANDLE file, new;
4819 unsigned int i;
4820 DWORD size;
4821 BOOL ret;
4822
4823 static const DWORD invalid_attributes[] =
4824 {
4833 };
4834
4835 static const DWORD valid_attributes[] =
4836 {
4843 };
4844
4845 if (!pReOpenFile)
4846 {
4847 win_skip("ReOpenFile() is not available\n");
4848 return;
4849 }
4850
4851 GetTempPathA(sizeof(path), path);
4852 GetTempFileNameA(path, "tst", 0, filename);
4853
4856 ok(file != INVALID_HANDLE_VALUE, "failed to create file, error %lu\n", GetLastError());
4857 ret = WriteFile(file, "foo", 4, &size, NULL);
4858 ok(ret, "failed to write file, error %lu\n", GetLastError());
4859
4860 for (i = 0; i < ARRAY_SIZE(invalid_attributes); ++i)
4861 {
4862 SetLastError(0xdeadbeef);
4863 new = pReOpenFile(file, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, invalid_attributes[i]);
4864 ok(new == INVALID_HANDLE_VALUE, "got %p\n", new);
4865 ok(GetLastError() == ERROR_INVALID_PARAMETER, "got error %lu\n", GetLastError());
4866 }
4867
4868 new = pReOpenFile(file, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0);
4869 ok(new != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
4870
4871 ret = ReadFile(new, buffer, sizeof(buffer), &size, NULL);
4872 ok(ret, "failed to read file, error %lu\n", GetLastError());
4873 ok(size == 4, "got size %lu\n", size);
4874 ok(!strcmp(buffer, "foo"), "got wrong data\n");
4875 CloseHandle(new);
4876
4877 for (i = 0; i < ARRAY_SIZE(valid_attributes); ++i)
4878 {
4879 new = pReOpenFile(file, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, valid_attributes[i]);
4880 ok(new != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
4881 CloseHandle(new);
4882 }
4883
4884 SetLastError(0xdeadbeef);
4885 new = pReOpenFile(file, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0);
4886 ok(new == INVALID_HANDLE_VALUE, "got %p\n", new);
4887 ok(GetLastError() == ERROR_SHARING_VIOLATION, "got error %lu\n", GetLastError());
4888
4891 ok(ret, "failed to delete file, error %lu\n", GetLastError());
4892
4893 file = CreateNamedPipeA("\\\\.\\pipe\\test_pipe", PIPE_ACCESS_DUPLEX, 0, 1, 1000, 1000, 1000, NULL);
4894 ok(file != INVALID_HANDLE_VALUE, "failed to create pipe, error %lu\n", GetLastError());
4895
4896 new = pReOpenFile(file, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0);
4897 ok(new != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
4898
4899 ret = WriteFile(file, "foo", 4, &size, NULL);
4900 ok(ret, "failed to write file, error %lu\n", GetLastError());
4901 ret = ReadFile(new, buffer, sizeof(buffer), &size, NULL);
4902 ok(ret, "failed to read file, error %lu\n", GetLastError());
4903 ok(size == 4, "got size %lu\n", size);
4904 ok(!strcmp(buffer, "foo"), "got wrong data\n");
4905
4906 CloseHandle(new);
4908}
4909
4910static void test_WriteFileGather(void)
4911{
4913 HANDLE hfile, hiocp1, hiocp2, evt;
4914 DWORD ret, size, tx;
4915 ULONG_PTR key;
4916 FILE_SEGMENT_ELEMENT fse[2];
4917 OVERLAPPED ovl, *povl = NULL;
4919 char *wbuf = NULL, *rbuf1, *rbuf2;
4920 BOOL br;
4921
4922 evt = CreateEventW( NULL, TRUE, FALSE, NULL );
4923
4925 ok( ret != 0, "GetTempPathA error %ld\n", GetLastError() );
4926 ok( ret < MAX_PATH, "temp path should fit into MAX_PATH\n" );
4927 ret = GetTempFileNameA( temp_path, "wfg", 0, filename );
4928 ok( ret != 0, "GetTempFileNameA error %ld\n", GetLastError() );
4929
4932 ok( hfile != INVALID_HANDLE_VALUE, "CreateFile failed err %lu\n", GetLastError() );
4933 if (hfile == INVALID_HANDLE_VALUE) return;
4934
4936 hiocp2 = CreateIoCompletionPort( hfile, hiocp1, 999, 0 );
4937 ok( hiocp2 != 0, "CreateIoCompletionPort failed err %lu\n", GetLastError() );
4938
4939 GetSystemInfo( &si );
4941 ok( wbuf != NULL, "VirtualAlloc failed err %lu\n", GetLastError() );
4942
4944 ok( rbuf1 != NULL, "VirtualAlloc failed err %lu\n", GetLastError() );
4945
4947 ok( rbuf2 != NULL, "VirtualAlloc failed err %lu\n", GetLastError() );
4948
4949 memset( &ovl, 0, sizeof(ovl) );
4950 ovl.hEvent = evt;
4951 memset( fse, 0, sizeof(fse) );
4952 fse[0].Buffer = wbuf;
4953 memset( wbuf, 0x42, si.dwPageSize );
4954 SetLastError( 0xdeadbeef );
4955 if (!WriteFileGather( hfile, fse, si.dwPageSize, NULL, &ovl ))
4956 ok( GetLastError() == ERROR_IO_PENDING, "WriteFileGather failed err %lu\n", GetLastError() );
4957
4958 ret = GetQueuedCompletionStatus( hiocp2, &size, &key, &povl, 1000 );
4959 ok( ret, "GetQueuedCompletionStatus failed err %lu\n", GetLastError());
4960 ok( povl == &ovl, "wrong ovl %p\n", povl );
4961
4962#ifdef __REACTOS__
4963 if (is_reactos()) {
4964 ok(FALSE, "FIXME: Calls to GetOverlappedResult hang on ReactOS!\n");
4965 } else {
4966#endif
4967 tx = 0;
4968 br = GetOverlappedResult( hfile, &ovl, &tx, TRUE );
4969 ok( br == TRUE, "GetOverlappedResult failed: %lu\n", GetLastError() );
4970 ok( tx == si.dwPageSize, "got unexpected bytes transferred: %lu\n", tx );
4971#ifdef __REACTOS__
4972 }
4973#endif
4974
4975 ResetEvent( evt );
4976
4977 /* read exact size */
4978 memset( &ovl, 0, sizeof(ovl) );
4979 ovl.hEvent = evt;
4980 memset( fse, 0, sizeof(fse) );
4981 fse[0].Buffer = rbuf1;
4982 memset( rbuf1, 0, si.dwPageSize );
4983 SetLastError( 0xdeadbeef );
4984 br = ReadFileScatter( hfile, fse, si.dwPageSize, NULL, &ovl );
4985 ok( br == FALSE, "ReadFileScatter should be asynchronous\n" );
4986 ok( GetLastError() == ERROR_IO_PENDING, "ReadFileScatter failed err %lu\n", GetLastError() );
4987
4988 ret = GetQueuedCompletionStatus( hiocp2, &size, &key, &povl, 1000 );
4989 ok( ret, "GetQueuedCompletionStatus failed err %lu\n", GetLastError());
4990 ok( povl == &ovl, "wrong ovl %p\n", povl );
4991
4992#ifdef __REACTOS__
4993 if (is_reactos()) {
4994 ok(FALSE, "FIXME: Calls to GetOverlappedResult hang on ReactOS!\n");
4995 } else {
4996#endif
4997 tx = 0;
4998 br = GetOverlappedResult( hfile, &ovl, &tx, TRUE );
4999 ok( br == TRUE, "GetOverlappedResult failed: %lu\n", GetLastError() );
5000 ok( tx == si.dwPageSize, "got unexpected bytes transferred: %lu\n", tx );
5001#ifdef __REACTOS__
5002 }
5003#endif
5004
5005 ok( memcmp( rbuf1, wbuf, si.dwPageSize ) == 0,
5006 "data was not read into buffer\n" );
5007
5008 ResetEvent( evt );
5009
5010 /* start read at EOF */
5011 memset( &ovl, 0, sizeof(ovl) );
5012 ovl.hEvent = evt;
5013 ovl.OffsetHigh = 0;
5014 ovl.Offset = si.dwPageSize;
5015 memset( fse, 0, sizeof(fse) );
5016 fse[0].Buffer = rbuf1;
5017 SetLastError( 0xdeadbeef );
5018 br = ReadFileScatter( hfile, fse, si.dwPageSize, NULL, &ovl );
5019 ok( br == FALSE, "ReadFileScatter should have failed\n" );
5021 GetLastError() == ERROR_IO_PENDING, "ReadFileScatter gave wrong error %lu\n", GetLastError() );
5023 {
5024 SetLastError( 0xdeadbeef );
5025 ret = GetQueuedCompletionStatus( hiocp2, &size, &key, &povl, 1000 );
5026 ok( !ret, "GetQueuedCompletionStatus should have returned failure\n" );
5027 ok( GetLastError() == ERROR_HANDLE_EOF, "Got wrong error: %lu\n", GetLastError() );
5028 ok( povl == &ovl, "wrong ovl %p\n", povl );
5029
5030 SetLastError( 0xdeadbeef );
5031 br = GetOverlappedResult( hfile, &ovl, &tx, TRUE );
5032 ok( br == FALSE, "GetOverlappedResult should have failed\n" );
5033 ok( GetLastError() == ERROR_HANDLE_EOF, "Got wrong error: %lu\n", GetLastError() );
5034 }
5035 else
5036 {
5037 SetLastError( 0xdeadbeef );
5038 ret = GetQueuedCompletionStatus( hiocp2, &size, &key, &povl, 100 );
5039 ok( !ret, "GetQueuedCompletionStatus failed err %lu\n", GetLastError() );
5040 ok( GetLastError() == WAIT_TIMEOUT, "GetQueuedCompletionStatus gave wrong error %lu\n", GetLastError() );
5041 ok( povl == NULL, "wrong ovl %p\n", povl );
5042 }
5043
5044 ResetEvent( evt );
5045
5046 /* read past EOF */
5047 memset( &ovl, 0, sizeof(ovl) );
5048 ovl.hEvent = evt;
5049 memset( fse, 0, sizeof(fse) );
5050 fse[0].Buffer = rbuf1;
5051 fse[1].Buffer = rbuf2;
5052 memset( rbuf1, 0, si.dwPageSize );
5053 memset( rbuf2, 0x17, si.dwPageSize );
5054 SetLastError( 0xdeadbeef );
5055 br = ReadFileScatter( hfile, fse, si.dwPageSize * 2, NULL, &ovl );
5056 ok( br == FALSE, "ReadFileScatter should be asynchronous\n" );
5057 ok( GetLastError() == ERROR_IO_PENDING, "ReadFileScatter failed err %lu\n", GetLastError() );
5058
5059 ret = GetQueuedCompletionStatus( hiocp2, &size, &key, &povl, 1000 );
5060 ok( ret, "GetQueuedCompletionStatus failed err %lu\n", GetLastError() );
5061 ok( povl == &ovl, "wrong ovl %p\n", povl );
5062
5063#ifdef __REACTOS__
5064 if (is_reactos()) {
5065 ok(FALSE, "FIXME: Calls to GetOverlappedResult hang on ReactOS!\n");
5066 } else {
5067#endif
5068 tx = 0;
5069 br = GetOverlappedResult( hfile, &ovl, &tx, TRUE );
5070 ok( br == TRUE, "GetOverlappedResult failed: %lu\n", GetLastError() );
5071 ok( tx == si.dwPageSize, "got unexpected bytes transferred: %lu\n", tx );
5072#ifdef __REACTOS__
5073 }
5074#endif
5075
5076 ok( memcmp( rbuf1, wbuf, si.dwPageSize ) == 0,
5077 "data was not read into buffer\n" );
5078 memset( rbuf1, 0x17, si.dwPageSize );
5079 ok( memcmp( rbuf2, rbuf1, si.dwPageSize ) == 0,
5080 "data should not have been read into buffer\n" );
5081
5082 ResetEvent( evt );
5083
5084 /* partial page read */
5085 memset( &ovl, 0, sizeof(ovl) );
5086 ovl.hEvent = evt;
5087 memset( fse, 0, sizeof(fse) );
5088 fse[0].Buffer = rbuf1;
5089 memset( rbuf1, 0, si.dwPageSize );
5090 SetLastError( 0xdeadbeef );
5091 br = ReadFileScatter( hfile, fse, si.dwPageSize / 2, NULL, &ovl );
5092 ok( br == FALSE, "ReadFileScatter should be asynchronous\n" );
5093 ok( GetLastError() == ERROR_IO_PENDING, "ReadFileScatter failed err %lu\n", GetLastError() );
5094
5095 ret = GetQueuedCompletionStatus( hiocp2, &size, &key, &povl, 1000 );
5096 ok( ret, "GetQueuedCompletionStatus failed err %lu\n", GetLastError() );
5097 ok( povl == &ovl, "wrong ovl %p\n", povl );
5098
5099#ifdef __REACTOS__
5100 if (is_reactos()) {
5101 ok(FALSE, "FIXME: Calls to GetOverlappedResult hang on ReactOS!\n");
5102 } else {
5103#endif
5104 tx = 0;
5105 br = GetOverlappedResult( hfile, &ovl, &tx, TRUE );
5106 ok( br == TRUE, "GetOverlappedResult failed: %lu\n", GetLastError() );
5107 ok( tx == si.dwPageSize / 2, "got unexpected bytes transferred: %lu\n", tx );
5108#ifdef __REACTOS__
5109 }
5110#endif
5111
5112 ok( memcmp( rbuf1, wbuf, si.dwPageSize / 2 ) == 0,
5113 "invalid data was read into buffer\n" );
5114 memset( rbuf2, 0, si.dwPageSize );
5115 ok( memcmp( rbuf1 + si.dwPageSize / 2, rbuf2, si.dwPageSize - si.dwPageSize / 2 ) == 0,
5116 "invalid data was read into buffer\n" );
5117
5118 if (pSetFileCompletionNotificationModes)
5119 {
5120 br = pSetFileCompletionNotificationModes(hfile, FILE_SKIP_COMPLETION_PORT_ON_SUCCESS);
5121 ok(br, "SetFileCompletionNotificationModes failed, error %lu.\n", GetLastError());
5122
5123 br = ReadFileScatter(hfile, fse, si.dwPageSize, NULL, &ovl);
5124 ok(br == FALSE, "ReadFileScatter should be asynchronous.\n");
5125 ok(GetLastError() == ERROR_IO_PENDING, "ReadFileScatter failed, error %lu.\n", GetLastError());
5126
5127 br = GetQueuedCompletionStatus(hiocp2, &size, &key, &povl, 1000);
5128 ok(br, "GetQueuedCompletionStatus failed, err %lu.\n", GetLastError());
5129 ok(povl == &ovl, "Wrong ovl %p.\n", povl);
5130
5131#ifdef __REACTOS__
5132 if (is_reactos()) {
5133 ok(FALSE, "FIXME: Calls to GetOverlappedResult hang on ReactOS!\n");
5134 } else {
5135#endif
5136 br = GetOverlappedResult(hfile, &ovl, &tx, TRUE);
5137 ok(br, "GetOverlappedResult failed, err %lu.\n", GetLastError());
5138 ok(tx == si.dwPageSize, "Got unexpected size %lu.\n", tx);
5139#ifdef __REACTOS__
5140 }
5141#endif
5142
5143 ResetEvent(evt);
5144 }
5145 else
5146 win_skip("SetFileCompletionNotificationModes not available.\n");
5147
5148 CloseHandle( hfile );
5149 CloseHandle( hiocp1 );
5150 CloseHandle( hiocp2 );
5151
5152 /* file handle must be overlapped */
5155 ok( hfile != INVALID_HANDLE_VALUE, "CreateFile failed err %lu\n", GetLastError() );
5156
5157 memset( &ovl, 0, sizeof(ovl) );
5158 memset( fse, 0, sizeof(fse) );
5159 fse[0].Buffer = rbuf1;
5160 memset( rbuf1, 0, si.dwPageSize );
5161 SetLastError( 0xdeadbeef );
5162 br = ReadFileScatter( hfile, fse, si.dwPageSize, NULL, &ovl );
5163 ok( br == FALSE, "ReadFileScatter should fail\n" );
5164 ok( GetLastError() == ERROR_INVALID_PARAMETER, "ReadFileScatter failed err %lu\n", GetLastError() );
5165
5166 VirtualFree( wbuf, 0, MEM_RELEASE );
5167 VirtualFree( rbuf1, 0, MEM_RELEASE );
5168 VirtualFree( rbuf2, 0, MEM_RELEASE );
5169 CloseHandle( evt );
5171}
5172
5173static unsigned file_map_access(unsigned access)
5174{
5180}
5181
5182static BOOL is_access_compatible(unsigned obj_access, unsigned desired_access)
5183{
5184 obj_access = file_map_access(obj_access);
5185 desired_access = file_map_access(desired_access);
5186 return (obj_access & desired_access) == desired_access;
5187}
5188
5189static void test_file_access(void)
5190{
5191 static const struct
5192 {
5193 unsigned access, create_error, write_error, read_error;
5194 } td[] =
5195 {
5196 { GENERIC_READ | GENERIC_WRITE, 0, 0, 0 },
5199 { FILE_READ_DATA | FILE_WRITE_DATA, 0, 0, 0 },
5203 { FILE_READ_DATA | FILE_APPEND_DATA, 0, 0, 0 },
5206 };
5207 char path[MAX_PATH], fname[MAX_PATH];
5208 unsigned char buf[16];
5209 HANDLE hfile, hdup;
5210 DWORD i, j, ret, bytes;
5211
5213 GetTempFileNameA(path, "foo", 0, fname);
5214
5215 for (i = 0; i < ARRAY_SIZE(td); i++)
5216 {
5217 SetLastError(0xdeadbeef);
5218 hfile = CreateFileA(fname, td[i].access, 0, NULL, CREATE_ALWAYS,
5220 if (td[i].create_error)
5221 {
5222 ok(hfile == INVALID_HANDLE_VALUE, "%ld: CreateFile should fail\n", i);
5223 ok(td[i].create_error == GetLastError(), "%ld: expected %d, got %ld\n", i, td[i].create_error, GetLastError());
5224 continue;
5225 }
5226 else
5227 ok(hfile != INVALID_HANDLE_VALUE, "%ld: CreateFile error %ld\n", i, GetLastError());
5228
5229 for (j = 0; j < ARRAY_SIZE(td); j++)
5230 {
5231 SetLastError(0xdeadbeef);
5233 td[j].access, 0, 0);
5234 if (is_access_compatible(td[i].access, td[j].access))
5235 ok(ret, "DuplicateHandle(%#x => %#x) error %ld\n", td[i].access, td[j].access, GetLastError());
5236 else
5237 {
5238 /* FIXME: Remove once Wine is fixed */
5240 (!(td[i].access & (GENERIC_WRITE | FILE_WRITE_DATA)) && (td[j].access & FILE_WRITE_DATA)) ||
5241 (!(td[i].access & (GENERIC_READ | FILE_READ_DATA)) && (td[j].access & FILE_READ_DATA)) ||
5242 (!(td[i].access & (GENERIC_WRITE)) && (td[j].access & FILE_APPEND_DATA))))
5243 {
5244 ok(!ret, "DuplicateHandle(%#x => %#x) should fail\n", td[i].access, td[j].access);
5245 ok(GetLastError() == ERROR_ACCESS_DENIED, "expected ERROR_ACCESS_DENIED, got %ld\n", GetLastError());
5246 }
5247 }
5248 if (ret) CloseHandle(hdup);
5249 }
5250
5251 SetLastError(0xdeadbeef);
5252 bytes = 0xdeadbeef;
5253 ret = WriteFile(hfile, "\x5e\xa7", 2, &bytes, NULL);
5254 if (td[i].write_error)
5255 {
5256 ok(!ret, "%ld: WriteFile should fail\n", i);
5257 ok(td[i].write_error == GetLastError(), "%ld: expected %d, got %ld\n", i, td[i].write_error, GetLastError());
5258 ok(bytes == 0, "%ld: expected 0, got %lu\n", i, bytes);
5259 }
5260 else
5261 {
5262 ok(ret, "%ld: WriteFile error %ld\n", i, GetLastError());
5263 ok(bytes == 2, "%ld: expected 2, got %lu\n", i, bytes);
5264 }
5265
5266 SetLastError(0xdeadbeef);
5267 ret = SetFilePointer(hfile, 0, NULL, FILE_BEGIN);
5268 ok(ret != INVALID_SET_FILE_POINTER, "SetFilePointer error %ld\n", GetLastError());
5269
5270 SetLastError(0xdeadbeef);
5271 bytes = 0xdeadbeef;
5272 ret = ReadFile(hfile, buf, sizeof(buf), &bytes, NULL);
5273 if (td[i].read_error)
5274 {
5275 ok(!ret, "%ld: ReadFile should fail\n", i);
5276 ok(td[i].read_error == GetLastError(), "%ld: expected %d, got %ld\n", i, td[i].read_error, GetLastError());
5277 ok(bytes == 0, "%ld: expected 0, got %lu\n", i, bytes);
5278 }
5279 else
5280 {
5281 ok(ret, "%ld: ReadFile error %ld\n", i, GetLastError());
5282 if (td[i].write_error)
5283 ok(bytes == 0, "%ld: expected 0, got %lu\n", i, bytes);
5284 else
5285 {
5286 ok(bytes == 2, "%ld: expected 2, got %lu\n", i, bytes);
5287 ok(buf[0] == 0x5e && buf[1] == 0xa7, "%ld: expected 5ea7, got %02x%02x\n", i, buf[0], buf[1]);
5288 }
5289 }
5290
5291 CloseHandle(hfile);
5292 }
5293}
5294
5296{
5297 static char prefix[] = "GetFinalPathNameByHandleA";
5298 static char dos_prefix[] = "\\\\?\\";
5299 char temp_path[MAX_PATH], test_path[MAX_PATH];
5300 char long_path[MAX_PATH], result_path[MAX_PATH];
5301 char dos_path[MAX_PATH + sizeof(dos_prefix)];
5302 HANDLE file;
5303 DWORD count;
5304 UINT ret;
5305
5306 if (!pGetFinalPathNameByHandleA)
5307 {
5308 win_skip("GetFinalPathNameByHandleA is missing\n");
5309 return;
5310 }
5311
5312 /* Test calling with INVALID_HANDLE_VALUE */
5313 SetLastError(0xdeadbeaf);
5314 count = pGetFinalPathNameByHandleA(INVALID_HANDLE_VALUE, result_path, MAX_PATH, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5315 ok(count == 0, "Expected length 0, got %lu\n", count);
5316 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %lu\n", GetLastError());
5317
5319 ok(count, "Failed to get temp path, error %lu\n", GetLastError());
5320 ret = GetTempFileNameA(temp_path, prefix, 0, test_path);
5321 ok(ret != 0, "GetTempFileNameA error %lu\n", GetLastError());
5322 ret = GetLongPathNameA(test_path, long_path, MAX_PATH);
5323 ok(ret != 0, "GetLongPathNameA error %lu\n", GetLastError());
5324 strcpy(dos_path, dos_prefix);
5325 strcat(dos_path, long_path);
5326
5327 count = pGetFinalPathNameByHandleA(INVALID_HANDLE_VALUE, NULL, 0, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5328 ok(count == 0, "Expected length 0, got %lu\n", count);
5329 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %lu\n", GetLastError());
5330
5331 file = CreateFileA(test_path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
5333 ok(file != INVALID_HANDLE_VALUE, "CreateFileA error %lu\n", GetLastError());
5334
5335 if (0) {
5336 /* Windows crashes on NULL path */
5337 count = pGetFinalPathNameByHandleA(file, NULL, MAX_PATH, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5338 ok(count == 0, "Expected length 0, got %lu\n", count);
5339 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %lu\n", GetLastError());
5340 }
5341
5342 /* Test 0-length path */
5343 count = pGetFinalPathNameByHandleA(file, result_path, 0, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5344 ok(count == strlen(dos_path), "Expected length %u, got %lu\n", lstrlenA(dos_path), count);
5345
5346 /* Test 0 and NULL path */
5347 count = pGetFinalPathNameByHandleA(file, NULL, 0, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5348 ok(count == strlen(dos_path), "Expected length %u, got %lu\n", lstrlenA(dos_path), count);
5349
5350 /* Test VOLUME_NAME_DOS with sufficient buffer size */
5351 memset(result_path, 0x11, sizeof(result_path));
5352 count = pGetFinalPathNameByHandleA(file, result_path, MAX_PATH, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5353 ok(count == strlen(dos_path), "Expected length %lu, got %lu\n", (DWORD)strlen(dos_path), count);
5354 ok(lstrcmpiA(dos_path, result_path) == 0, "Expected %s, got %s\n", dos_path, result_path);
5355
5356 /* Test VOLUME_NAME_DOS with insufficient buffer size */
5357 memset(result_path, 0x11, sizeof(result_path));
5358 count = pGetFinalPathNameByHandleA(file, result_path, strlen(dos_path)-2, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5359 ok(count == strlen(dos_path), "Expected length %lu, got %lu\n", (DWORD)strlen(dos_path), count);
5360 ok(result_path[0] == 0x11, "Result path was modified\n");
5361
5362 memset(result_path, 0x11, sizeof(result_path));
5363 count = pGetFinalPathNameByHandleA(file, result_path, strlen(dos_path)-1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5364 ok(count == strlen(dos_path), "Expected length %lu, got %lu\n", (DWORD)strlen(dos_path), count);
5365 ok(result_path[0] == 0x11, "Result path was modified\n");
5366
5367 memset(result_path, 0x11, sizeof(result_path));
5368 count = pGetFinalPathNameByHandleA(file, result_path, strlen(dos_path), FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5369 ok(count == strlen(dos_path), "Expected length %lu, got %lu\n", (DWORD)strlen(dos_path), count);
5370 ok(result_path[0] == 0x11, "Result path was modified\n");
5371
5372 memset(result_path, 0x11, sizeof(result_path));
5373 count = pGetFinalPathNameByHandleA(file, result_path, strlen(dos_path)+1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
5374 ok(count == strlen(dos_path), "Expected length %lu, got %lu\n", (DWORD)strlen(dos_path), count);
5375 ok(result_path[0] != 0x11, "Result path was not modified\n");
5376 ok(!result_path[strlen(dos_path)], "Expected nullterminated string\n");
5377 ok(result_path[strlen(dos_path)+1] == 0x11, "Buffer overflow\n");
5378
5380}
5381
5383{
5384 static WCHAR prefix[] = {'G','e','t','F','i','n','a','l','P','a','t','h',
5385 'N','a','m','e','B','y','H','a','n','d','l','e','W','\0'};
5386 static WCHAR dos_prefix[] = {'\\','\\','?','\\','\0'};
5387 WCHAR temp_path[MAX_PATH], test_path[MAX_PATH];
5388 WCHAR long_path[MAX_PATH], result_path[MAX_PATH];
5389 WCHAR dos_path[MAX_PATH + sizeof(dos_prefix)];
5390 WCHAR drive_part[MAX_PATH];
5391 WCHAR *file_part;
5392 WCHAR volume_path[MAX_PATH + 50];
5393 WCHAR nt_path[2 * MAX_PATH];
5394 BOOL success;
5395 HANDLE file;
5396 DWORD count;
5397 UINT ret;
5398
5400 {
5401 win_skip("GetFinalPathNameByHandleW is missing\n");
5402 return;
5403 }
5404
5405 /* Test calling with INVALID_HANDLE_VALUE */
5406 SetLastError(0xdeadbeaf);
5408 ok(count == 0, "Expected length 0, got %lu\n", count);
5409 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %lu\n", GetLastError());
5410
5412 ok(count == 0, "Expected length 0, got %lu\n", count);
5413 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %lu\n", GetLastError());
5414
5416 ok(count, "Failed to get temp path, error %lu\n", GetLastError());
5417 ret = GetTempFileNameW(temp_path, prefix, 0, test_path);
5418 ok(ret != 0, "GetTempFileNameW error %lu\n", GetLastError());
5419 ret = GetLongPathNameW(test_path, long_path, MAX_PATH);
5420 ok(ret != 0, "GetLongPathNameW error %lu\n", GetLastError());
5421 lstrcpyW(dos_path, dos_prefix);
5422 lstrcatW(dos_path, long_path);
5423
5424 file = CreateFileW(test_path, GENERIC_READ | GENERIC_WRITE, 0, NULL,
5426 ok(file != INVALID_HANDLE_VALUE, "CreateFileW error %lu\n", GetLastError());
5427
5428 if (0) {
5429 /* Windows crashes on NULL path */
5431 ok(count == 0, "Expected length 0, got %lu\n", count);
5432 ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %lu\n", GetLastError());
5433 }
5434
5435 /* Test 0-length path */
5437 ok(count == lstrlenW(dos_path) + 1 ||
5438 broken(count == lstrlenW(dos_path) + 2), "Expected length %u, got %lu\n", lstrlenW(dos_path) + 1, count);
5439
5440 /* Test 0 and NULL path */
5442 ok(count == lstrlenW(dos_path) + 1 ||
5443 broken(count == lstrlenW(dos_path) + 2), "Expected length %u, got %lu\n", lstrlenW(dos_path) + 1, count);
5444
5445 /* Test VOLUME_NAME_DOS with sufficient buffer size */
5446 memset(result_path, 0x11, sizeof(result_path));
5448 ok(count == lstrlenW(dos_path), "Expected length %u, got %lu\n", lstrlenW(dos_path), count);
5449 ok(lstrcmpiW(dos_path, result_path) == 0, "Expected %s, got %s\n", wine_dbgstr_w(dos_path), wine_dbgstr_w(result_path));
5450
5451 /* Test VOLUME_NAME_DOS with insufficient buffer size */
5452 memset(result_path, 0x11, sizeof(result_path));
5454 ok(count == lstrlenW(dos_path) + 1, "Expected length %u, got %lu\n", lstrlenW(dos_path) + 1, count);
5455 ok(result_path[0] == 0x1111, "Result path was modified\n");
5456
5457 memset(result_path, 0x11, sizeof(result_path));
5459 ok(count == lstrlenW(dos_path) + 1, "Expected length %u, got %lu\n", lstrlenW(dos_path) + 1, count);
5460 ok(result_path[0] == 0x1111, "Result path was modified\n");
5461
5462 memset(result_path, 0x11, sizeof(result_path));
5464 ok(count == lstrlenW(dos_path), "Expected length %u, got %lu\n", lstrlenW(dos_path), count);
5465 ok(result_path[0] != 0x1111, "Result path was not modified\n");
5466 ok(!result_path[lstrlenW(dos_path)], "Expected nullterminated string\n");
5467 ok(result_path[lstrlenW(dos_path)+1] == 0x1111, "Buffer overflow\n");
5468
5469 success = GetVolumePathNameW(long_path, drive_part, MAX_PATH);
5470 ok(success, "GetVolumePathNameW error %lu\n", GetLastError());
5471 success = GetVolumeNameForVolumeMountPointW(drive_part, volume_path, ARRAY_SIZE(volume_path));
5472 ok(success, "GetVolumeNameForVolumeMountPointW error %lu\n", GetLastError());
5473
5474 /* Test for VOLUME_NAME_GUID */
5475 lstrcatW(volume_path, long_path + lstrlenW(drive_part));
5476 memset(result_path, 0x11, sizeof(result_path));
5478 ok(count == lstrlenW(volume_path), "Expected length %u, got %lu\n", lstrlenW(volume_path), count);
5479 ok(lstrcmpiW(volume_path, result_path) == 0, "Expected %s, got %s\n",
5480 wine_dbgstr_w(volume_path), wine_dbgstr_w(result_path));
5481
5482 /* Test for VOLUME_NAME_NONE */
5483 file_part = long_path + lstrlenW(drive_part) - 1;
5484 memset(result_path, 0x11, sizeof(result_path));
5486 ok(count == lstrlenW(file_part), "Expected length %u, got %lu\n", lstrlenW(file_part), count);
5487 ok(lstrcmpiW(file_part, result_path) == 0, "Expected %s, got %s\n",
5488 wine_dbgstr_w(file_part), wine_dbgstr_w(result_path));
5489
5490 drive_part[lstrlenW(drive_part)-1] = 0;
5491 success = QueryDosDeviceW(drive_part, nt_path, ARRAY_SIZE(nt_path));
5492 ok(success, "QueryDosDeviceW error %lu\n", GetLastError());
5493
5494 /* Test for VOLUME_NAME_NT */
5495 lstrcatW(nt_path, file_part);
5496 memset(result_path, 0x11, sizeof(result_path));
5498 ok(count == lstrlenW(nt_path), "Expected length %u, got %lu\n", lstrlenW(nt_path), count);
5499 ok(lstrcmpiW(nt_path, result_path) == 0, "Expected %s, got %s\n",
5500 wine_dbgstr_w(nt_path), wine_dbgstr_w(result_path));
5501
5503}
5504
5506{
5507 FILE_ATTRIBUTE_TAG_INFO fileattrinfo = { 0 };
5508 FILE_REMOTE_PROTOCOL_INFO protinfo = { 0 };
5509 FILE_STANDARD_INFO stdinfo = { {{0}},{{0}},0,FALSE,FALSE };
5510 FILE_COMPRESSION_INFO compressinfo;
5511 FILE_DISPOSITION_INFO dispinfo;
5512 DECLSPEC_ALIGN(8) FILE_IO_PRIORITY_HINT_INFO hintinfo;
5513 FILE_BASIC_INFO basicinfo = { {{0}} };
5514 char tempFileName[MAX_PATH];
5515 char tempPath[MAX_PATH];
5516 LARGE_INTEGER atime;
5517 HANDLE file;
5518 BOOL ret;
5519
5520#if defined(__REACTOS__) && DLL_EXPORT_VERSION >= 0x600
5521 /* FIXME: SetFileInformationByHandle is a STUB on ReactOS. */
5522 if (is_reactos() || !pSetFileInformationByHandle)
5523#else
5524 if (!pSetFileInformationByHandle)
5525#endif
5526 {
5527 win_skip("SetFileInformationByHandle is not supported\n");
5528 return;
5529 }
5530
5531 ret = GetTempPathA(sizeof(tempPath), tempPath);
5532 ok(ret, "GetTempPathA failed, got error %lu.\n", GetLastError());
5533
5534 /* ensure the existence of a file in the temp folder */
5535 ret = GetTempFileNameA(tempPath, "abc", 0, tempFileName);
5536 ok(ret, "GetTempFileNameA failed, got error %lu.\n", GetLastError());
5537
5540 ok(file != INVALID_HANDLE_VALUE, "failed to open the temp file, error %lu.\n", GetLastError());
5541
5542 /* invalid classes */
5543 SetLastError(0xdeadbeef);
5544 ret = pSetFileInformationByHandle(file, FileStandardInfo, &stdinfo, sizeof(stdinfo));
5545 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
5546
5547 memset(&compressinfo, 0, sizeof(compressinfo));
5548 SetLastError(0xdeadbeef);
5549 ret = pSetFileInformationByHandle(file, FileCompressionInfo, &compressinfo, sizeof(compressinfo));
5550 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
5551
5552 SetLastError(0xdeadbeef);
5553 ret = pSetFileInformationByHandle(file, FileAttributeTagInfo, &fileattrinfo, sizeof(fileattrinfo));
5554 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
5555
5556 SetLastError(0xdeadbeef);
5557 hintinfo.PriorityHint = MaximumIoPriorityHintType;
5558 ret = pSetFileInformationByHandle(file, FileIoPriorityHintInfo, &hintinfo, sizeof(hintinfo));
5559 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
5560
5561 hintinfo.PriorityHint = IoPriorityHintNormal;
5562 ret = pSetFileInformationByHandle(file, FileIoPriorityHintInfo, &hintinfo, sizeof(hintinfo));
5563 ok(ret, "setting FileIoPriorityHintInfo got %d, error %ld\n", ret, GetLastError());
5564
5565 hintinfo.PriorityHint = IoPriorityHintVeryLow;
5566 ret = pSetFileInformationByHandle(file, FileIoPriorityHintInfo, &hintinfo, sizeof(hintinfo));
5567 ok(ret, "setting FileIoPriorityHintInfo got %d, error %ld\n", ret, GetLastError());
5568
5569 SetLastError(0xdeadbeef);
5570 ret = pSetFileInformationByHandle(file, FileIoPriorityHintInfo, &hintinfo, sizeof(hintinfo) - 1);
5571 ok(!ret && GetLastError() == ERROR_BAD_LENGTH, "got %d, error %ld\n", ret, GetLastError());
5572
5573 SetLastError(0xdeadbeef);
5574 hintinfo.PriorityHint = IoPriorityHintVeryLow - 1;
5575 ret = pSetFileInformationByHandle(file, FileIoPriorityHintInfo, &hintinfo, sizeof(hintinfo));
5576 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
5577
5578 memset(&protinfo, 0, sizeof(protinfo));
5579 protinfo.StructureVersion = 1;
5580 protinfo.StructureSize = sizeof(protinfo);
5581 SetLastError(0xdeadbeef);
5582 ret = pSetFileInformationByHandle(file, FileRemoteProtocolInfo, &protinfo, sizeof(protinfo));
5583 ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %d, error %ld\n", ret, GetLastError());
5584
5585 /* test FileDispositionInfo, additional details already covered by ntdll tests */
5586 SetLastError(0xdeadbeef);
5587 ret = pSetFileInformationByHandle(file, FileDispositionInfo, &dispinfo, 0);
5588 todo_wine
5589 ok(!ret && GetLastError() == ERROR_BAD_LENGTH, "got %d, error %ld\n", ret, GetLastError());
5590
5591 SetLastError(0xdeadbeef);
5592 ret = pSetFileInformationByHandle(file, FileBasicInfo, &basicinfo, 0);
5593 todo_wine
5594 ok(!ret && GetLastError() == ERROR_BAD_LENGTH, "got %d, error %ld\n", ret, GetLastError());
5595
5596 memset(&basicinfo, 0, sizeof(basicinfo));
5597 ret = pGetFileInformationByHandleEx(file, FileBasicInfo, &basicinfo, sizeof(basicinfo));
5598 ok(ret, "Failed to get basic info, error %ld.\n", GetLastError());
5599 atime = basicinfo.LastAccessTime;
5600
5601 basicinfo.LastAccessTime.QuadPart++;
5602 ret = pSetFileInformationByHandle(file, FileBasicInfo, &basicinfo, sizeof(basicinfo));
5603 ok(ret, "Failed to set basic info, error %ld.\n", GetLastError());
5604
5605 memset(&basicinfo, 0, sizeof(basicinfo));
5606 ret = pGetFileInformationByHandleEx(file, FileBasicInfo, &basicinfo, sizeof(basicinfo));
5607 ok(ret, "Failed to get basic info, error %ld.\n", GetLastError());
5608 ok(atime.QuadPart + 1 == basicinfo.LastAccessTime.QuadPart, "Unexpected access time.\n");
5609
5610 memset(&basicinfo, 0, sizeof(basicinfo));
5611 basicinfo.LastAccessTime.QuadPart = -1;
5612 ret = pSetFileInformationByHandle(file, FileBasicInfo, &basicinfo, sizeof(basicinfo));
5613 ok(ret, "Failed to set basic info, error %ld.\n", GetLastError());
5614
5615 memset(&basicinfo, 0, sizeof(basicinfo));
5616 ret = pGetFileInformationByHandleEx(file, FileBasicInfo, &basicinfo, sizeof(basicinfo));
5617 ok(ret, "Failed to get basic info, error %ld.\n", GetLastError());
5618 ok(atime.QuadPart + 1 == basicinfo.LastAccessTime.QuadPart, "Unexpected access time.\n");
5619
5620 dispinfo.DeleteFile = TRUE;
5621 ret = pSetFileInformationByHandle(file, FileDispositionInfo, &dispinfo, sizeof(dispinfo));
5622 ok(ret, "setting FileDispositionInfo failed, error %ld\n", GetLastError());
5623
5625}
5626
5627static void test_SetFileRenameInfo(void)
5628{
5629 WCHAR tempFileFrom[MAX_PATH], tempFileTo1[MAX_PATH], tempFileTo2[MAX_PATH];
5630 WCHAR tempPath[MAX_PATH];
5632 HANDLE file;
5633 DWORD size;
5634 BOOL ret;
5635
5636#if defined(__REACTOS__) && DLL_EXPORT_VERSION >= 0x600
5637 /* FIXME: SetFileInformationByHandle is a STUB on ReactOS. */
5638 if (is_reactos() || !pSetFileInformationByHandle)
5639#else
5640 if (!pSetFileInformationByHandle)
5641#endif
5642 {
5643 win_skip("SetFileInformationByHandle is not supported\n");
5644 return;
5645 }
5646
5647 ret = GetTempPathW(MAX_PATH, tempPath);
5648 ok(ret, "GetTempPathW failed, got error %lu.\n", GetLastError());
5649
5650 ret = GetTempFileNameW(tempPath, L"abc", 0, tempFileFrom);
5651 ok(ret, "GetTempFileNameW failed, got error %lu.\n", GetLastError());
5652
5653 ret = GetTempFileNameW(tempPath, L"abc", 0, tempFileTo1);
5654 ok(ret, "GetTempFileNameW failed, got error %lu.\n", GetLastError());
5655
5656 ret = GetTempFileNameW(tempPath, L"abc", 1, tempFileTo2);
5657 ok(ret, "GetTempFileNameW failed, got error %lu.\n", GetLastError());
5658
5659 file = CreateFileW(tempFileFrom, GENERIC_READ | GENERIC_WRITE | DELETE, 0, 0, OPEN_EXISTING, 0, 0);
5660 ok(file != INVALID_HANDLE_VALUE, "failed to create temp file, error %lu.\n", GetLastError());
5661
5663 fri = HeapAlloc(GetProcessHeap(), 0, size);
5664
5665 fri->ReplaceIfExists = FALSE;
5666 fri->RootDirectory = NULL;
5667 fri->FileNameLength = wcslen(tempFileTo1) * sizeof(WCHAR);
5668 memcpy(fri->FileName, tempFileTo1, fri->FileNameLength + sizeof(WCHAR));
5669 ret = pSetFileInformationByHandle(file, FileRenameInfo, fri, size);
5670 ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS, "FileRenameInfo unexpected result %ld\n", GetLastError());
5671
5672 fri->ReplaceIfExists = TRUE;
5673 ret = pSetFileInformationByHandle(file, FileRenameInfo, fri, size);
5674 ok(ret, "FileRenameInfo failed, error %ld\n", GetLastError());
5675
5676 fri->ReplaceIfExists = FALSE;
5677 fri->FileNameLength = wcslen(tempFileTo2) * sizeof(WCHAR);
5678 memcpy(fri->FileName, tempFileTo2, fri->FileNameLength + sizeof(WCHAR));
5679 ret = pSetFileInformationByHandle(file, FileRenameInfo, fri, size);
5680 ok(ret, "FileRenameInfo failed, error %ld\n", GetLastError());
5682
5683 file = CreateFileW(tempFileTo2, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
5684 ok(file != INVALID_HANDLE_VALUE, "file not renamed, error %ld\n", GetLastError());
5685
5686 fri->FileNameLength = wcslen(tempFileTo1) * sizeof(WCHAR);
5687 memcpy(fri->FileName, tempFileTo1, fri->FileNameLength + sizeof(WCHAR));
5688 ret = pSetFileInformationByHandle(file, FileRenameInfo, fri, size);
5689 todo_wine
5690 ok(!ret && GetLastError() == ERROR_ACCESS_DENIED, "FileRenameInfo unexpected result %ld\n", GetLastError());
5692
5693 HeapFree(GetProcessHeap(), 0, fri);
5694 DeleteFileW(tempFileFrom);
5695 DeleteFileW(tempFileTo1);
5696 DeleteFileW(tempFileTo2);
5697}
5698
5700{
5701 static const struct
5702 {
5703 const WCHAR *path;
5704 DWORD expected_error;
5705 }
5706 tests[] =
5707 {
5708 {L"\\\\?\\", ERROR_INVALID_NAME},
5709 {L"\\??\\", ERROR_INVALID_NAME},
5710 {L"\\DosDevices\\", ERROR_FILE_NOT_FOUND},
5711 {L"\\\\?\\C:\\windows\\system32\\..\\system32\\kernel32.dll", ERROR_INVALID_NAME},
5712 };
5714 DWORD error, test_idx;
5715 BOOL ret;
5716
5717 for (test_idx = 0; test_idx < ARRAY_SIZE(tests); ++test_idx)
5718 {
5719 winetest_push_context("Test %lu", test_idx);
5720
5721 SetLastError(0xdeadbeef);
5723 error = GetLastError();
5724 ok(!ret, "GetFileAttributesExW succeeded\n");
5725 ok(error == tests[test_idx].expected_error, "Expected error %lu, got %lu\n",
5726 tests[test_idx].expected_error, error);
5727
5729 }
5730}
5731
5732static void test_post_completion(void)
5733{
5734 OVERLAPPED ovl, ovl2, *povl;
5735 OVERLAPPED_ENTRY entries[2];
5736 ULONG_PTR key;
5737 HANDLE port;
5738 ULONG count;
5739 DWORD size;
5740 BOOL ret;
5741
5743 ok(port != NULL, "CreateIoCompletionPort failed: %lu\n", GetLastError());
5744
5745 ret = GetQueuedCompletionStatus( port, &size, &key, &povl, 0 );
5746 ok(!ret, "GetQueuedCompletionStatus succeeded\n");
5747 ok(GetLastError() == WAIT_TIMEOUT, "wrong error %lu\n", GetLastError());
5748
5749 ret = PostQueuedCompletionStatus( port, 123, 456, &ovl );
5750 ok(ret, "PostQueuedCompletionStatus failed: %lu\n", GetLastError());
5751
5752 ret = GetQueuedCompletionStatus( port, &size, &key, &povl, 0 );
5753 ok(ret, "GetQueuedCompletionStatus failed: %lu\n", GetLastError());
5754 ok(size == 123, "wrong size %lu\n", size);
5755 ok(key == 456, "wrong key %Iu\n", key);
5756 ok(povl == &ovl, "wrong ovl %p\n", povl);
5757
5758 ret = GetQueuedCompletionStatus( port, &size, &key, &povl, 0 );
5759 ok(!ret, "GetQueuedCompletionStatus succeeded\n");
5760 ok(GetLastError() == WAIT_TIMEOUT, "wrong error %lu\n", GetLastError());
5761
5762#if defined(__REACTOS__) && DLL_EXPORT_VERSION >= 0x600
5763 /* FIXME: GetQueuedCompletionStatusEx is a STUB on ReactOS. */
5764 if (is_reactos() || !pGetQueuedCompletionStatusEx)
5765#else
5766 if (!pGetQueuedCompletionStatusEx)
5767#endif
5768 {
5769 win_skip("GetQueuedCompletionStatusEx not available\n");
5770 CloseHandle( port );
5771 return;
5772 }
5773
5774 count = 0xdeadbeef;
5775 ret = pGetQueuedCompletionStatusEx( port, entries, 2, &count, 0, FALSE );
5776 ok(!ret, "GetQueuedCompletionStatusEx succeeded\n");
5777 ok(GetLastError() == WAIT_TIMEOUT, "wrong error %lu\n", GetLastError());
5778 ok(count <= 1, "wrong count %lu\n", count);
5779
5780 ret = PostQueuedCompletionStatus( port, 123, 456, &ovl );
5781 ok(ret, "PostQueuedCompletionStatus failed: %lu\n", GetLastError());
5782
5783 count = 0xdeadbeef;
5784 memset( entries, 0xcc, sizeof(entries) );
5785 ret = pGetQueuedCompletionStatusEx( port, entries, 2, &count, 0, FALSE );
5786 ok(ret, "GetQueuedCompletionStatusEx failed\n");
5787 ok(count == 1, "wrong count %lu\n", count);
5788 ok(entries[0].lpCompletionKey == 456, "wrong key %Iu\n", entries[0].lpCompletionKey);
5789 ok(entries[0].lpOverlapped == &ovl, "wrong ovl %p\n", entries[0].lpOverlapped);
5790 ok(!(ULONG)entries[0].Internal, "wrong internal %#lx\n", (ULONG)entries[0].Internal);
5791 ok(entries[0].dwNumberOfBytesTransferred == 123, "wrong size %lu\n", entries[0].dwNumberOfBytesTransferred);
5792
5793 ret = PostQueuedCompletionStatus( port, 123, 456, &ovl );
5794 ok(ret, "PostQueuedCompletionStatus failed: %lu\n", GetLastError());
5795
5796 ret = PostQueuedCompletionStatus( port, 654, 321, &ovl2 );
5797 ok(ret, "PostQueuedCompletionStatus failed: %lu\n", GetLastError());
5798
5799 count = 0xdeadbeef;
5800 memset( entries, 0xcc, sizeof(entries) );
5801 ret = pGetQueuedCompletionStatusEx( port, entries, 2, &count, 0, FALSE );
5802 ok(ret, "GetQueuedCompletionStatusEx failed\n");
5803 ok(count == 2, "wrong count %lu\n", count);
5804 ok(entries[0].lpCompletionKey == 456, "wrong key %Iu\n", entries[0].lpCompletionKey);
5805 ok(entries[0].lpOverlapped == &ovl, "wrong ovl %p\n", entries[0].lpOverlapped);
5806 ok(!(ULONG)entries[0].Internal, "wrong internal %#lx\n", (ULONG)entries[0].Internal);
5807 ok(entries[0].dwNumberOfBytesTransferred == 123, "wrong size %lu\n", entries[0].dwNumberOfBytesTransferred);
5808 ok(entries[1].lpCompletionKey == 321, "wrong key %Iu\n", entries[1].lpCompletionKey);
5809 ok(entries[1].lpOverlapped == &ovl2, "wrong ovl %p\n", entries[1].lpOverlapped);
5810 ok(!(ULONG)entries[1].Internal, "wrong internal %#lx\n", (ULONG)entries[1].Internal);
5811 ok(entries[1].dwNumberOfBytesTransferred == 654, "wrong size %lu\n", entries[1].dwNumberOfBytesTransferred);
5812
5815
5816 ret = pGetQueuedCompletionStatusEx( port, entries, 2, &count, 0, FALSE );
5817 ok(!ret, "GetQueuedCompletionStatusEx succeeded\n");
5818 ok(GetLastError() == WAIT_TIMEOUT, "wrong error %lu\n", GetLastError());
5819 ok(count <= 1, "wrong count %lu\n", count);
5820 ok(!user_apc_ran, "user APC should not have run\n");
5821
5822 ret = pGetQueuedCompletionStatusEx( port, entries, 2, &count, 0, TRUE );
5823 ok(!ret || broken(ret) /* Vista */, "GetQueuedCompletionStatusEx succeeded\n");
5824 if (!ret)
5825 ok(GetLastError() == WAIT_IO_COMPLETION, "wrong error %lu\n", GetLastError());
5826 ok(count <= 1, "wrong count %lu\n", count);
5827 ok(user_apc_ran, "user APC should have run\n");
5828
5831
5832 ret = PostQueuedCompletionStatus( port, 123, 456, &ovl );
5833 ok(ret, "PostQueuedCompletionStatus failed: %lu\n", GetLastError());
5834
5835 ret = pGetQueuedCompletionStatusEx( port, entries, 2, &count, 0, TRUE );
5836 ok(ret, "GetQueuedCompletionStatusEx failed\n");
5837 ok(count == 1, "wrong count %lu\n", count);
5838 ok(!user_apc_ran, "user APC should not have run\n");
5839
5840 SleepEx(0, TRUE);
5841
5842 CloseHandle( port );
5843}
5844
5845#define TEST_OVERLAPPED_READ_SIZE 4096
5846
5847static void test_overlapped_read(void)
5848{
5850 static const char prefix[] = "pfx";
5851 char temp_path[MAX_PATH];
5852 char file_name[MAX_PATH];
5853 DWORD bytes_count;
5854 OVERLAPPED ov;
5855 HANDLE hfile;
5856 DWORD err;
5857 DWORD ret;
5858
5860 ok(ret, "Unexpected error %lu.\n", GetLastError());
5862 ok(ret, "Unexpected error %lu.\n", GetLastError());
5863
5866 ok(hfile != INVALID_HANDLE_VALUE, "Failed to create file, GetLastError() %lu.\n", GetLastError());
5867 memset(buffer, 0x55, sizeof(buffer));
5868 ret = WriteFile(hfile, buffer, TEST_OVERLAPPED_READ_SIZE, &bytes_count, NULL);
5869 ok(ret && bytes_count == TEST_OVERLAPPED_READ_SIZE,
5870 "Unexpected WriteFile result, ret %#lx, bytes_count %lu, GetLastError() %lu.\n",
5871 ret, bytes_count, GetLastError());
5872 CloseHandle(hfile);
5873
5876 ok(hfile != INVALID_HANDLE_VALUE, "Failed to create file, GetLastError() %lu.\n", GetLastError());
5877
5878 memset(&ov, 0, sizeof(ov));
5879
5880 bytes_count = 0xffffffff;
5881 ret = ReadFile(hfile, buffer, TEST_OVERLAPPED_READ_SIZE, &bytes_count, &ov);
5883 "Unexpected ReadFile result, ret %#lx, GetLastError() %lu.\n", ret, GetLastError());
5884 ok(!bytes_count, "Unexpected read size %lu.\n", bytes_count);
5885 ret = GetOverlappedResult(hfile, &ov, &bytes_count, TRUE);
5886 ok(ret, "Unexpected error %lu.\n", GetLastError());
5887 ok(bytes_count == TEST_OVERLAPPED_READ_SIZE, "Unexpected read size %lu.\n", bytes_count);
5888
5889 ov.Offset = bytes_count;
5890 ret = ReadFile(hfile, buffer, TEST_OVERLAPPED_READ_SIZE, &bytes_count, &ov);
5891 err = GetLastError();
5892 /* Win8+ return ERROR_IO_PENDING like stated in MSDN, while older ones
5893 * return ERROR_HANDLE_EOF right away. */
5895 "Unexpected ReadFile result, ret %#lx, GetLastError() %lu.\n", ret, GetLastError());
5896 if (err == ERROR_IO_PENDING)
5897 {
5898 ret = GetOverlappedResult(hfile, &ov, &bytes_count, TRUE);
5899 ok(!ret && GetLastError() == ERROR_HANDLE_EOF, "Unexpected result %#lx, GetLasttError() %lu.\n",
5900 ret, GetLastError());
5901 }
5902 ok(!bytes_count, "Unexpected read size %lu.\n", bytes_count);
5903
5904 CloseHandle(hfile);
5906 ok(ret, "Unexpected error %lu.\n", GetLastError());
5907}
5908
5910{
5911 static const DWORD default_sharing = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
5912 static const CHAR prefix[] = "pfx";
5913 CHAR file_name[MAX_PATH], file_name2[MAX_PATH];
5915 HANDLE handle;
5916 DWORD error;
5917 DWORD ret;
5918
5919 /* Set up */
5921 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
5922 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
5923
5925 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
5927 ok(ret, "expect success\n");
5928
5929 ret = GetTempFileNameA(temp_path, prefix, 0, file_name2);
5930 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
5931 ret = DeleteFileA(file_name2);
5932 ok(ret, "expect success\n");
5933
5935 ok(handle != INVALID_HANDLE_VALUE, "CreateFileA: error %ld\n", GetLastError());
5937
5938 /* CreateFile GENERIC_WRITE */
5939 SetLastError(0xdeadbeef);
5941 error = GetLastError();
5942 ok(handle == INVALID_HANDLE_VALUE, "expect failure\n");
5943 ok(error == ERROR_ACCESS_DENIED, "wrong error code: %#lx\n", error);
5944
5945 /* CreateFile DELETE without FILE_FLAG_DELETE_ON_CLOSE */
5947 ok(handle != INVALID_HANDLE_VALUE, "expect success\n");
5949
5950 /* CreateFile DELETE with FILE_FLAG_DELETE_ON_CLOSE */
5951 SetLastError(0xdeadbeef);
5952 handle = CreateFileA(file_name, DELETE, default_sharing, NULL, OPEN_EXISTING,
5954 error = GetLastError();
5955 ok(handle == INVALID_HANDLE_VALUE, "expect failure\n");
5956 ok(error == ERROR_ACCESS_DENIED, "wrong error code: %#lx\n", error);
5957
5958 ret = MoveFileA(file_name, file_name2);
5959 ok(ret, "expect success\n");
5960 ret = MoveFileA(file_name2, file_name);
5961 ok(ret, "expect success\n");
5962
5963 SetLastError(0xdeadbeef);
5965 error = GetLastError();
5966 ok(!ret, "expect failure\n");
5967 ok(error == ERROR_ACCESS_DENIED, "wrong error code: %#lx\n", error);
5968
5970 ok(ret & FILE_ATTRIBUTE_READONLY, "got wrong attribute: %#lx.\n", ret);
5971
5972 /* Clean up */
5975 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
5976}
5977
5978static void test_find_file_stream(void)
5979{
5980#ifdef __REACTOS__
5982#else
5983 WCHAR path[] = {'C',':','\\','w','i','n','d','o','w','s',0};
5984#endif
5985 HANDLE handle;
5986 int error;
5987 WIN32_FIND_STREAM_DATA data;
5988
5989 if (!pFindFirstStreamW)
5990 {
5991 win_skip("FindFirstStreamW is missing\n");
5992 return;
5993 }
5994
5995#ifdef __REACTOS__
5997#endif
5998 SetLastError(0xdeadbeef);
5999 handle = pFindFirstStreamW(path, FindStreamInfoStandard, &data, 0);
6000 error = GetLastError();
6001 ok(handle == INVALID_HANDLE_VALUE, "Expected INVALID_HANDLE_VALUE, got %p\n", handle);
6002 ok(error == ERROR_HANDLE_EOF, "Expected ERROR_HANDLE_EOF, got %d\n", error);
6003}
6004
6005static void test_SetFileTime(void)
6006{
6007 static const WCHAR prefix[] = {'p','f','x',0};
6009 FILETIME ft1, ft2;
6010 DWORD ret, len;
6011 HANDLE hfile;
6012
6014 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
6015 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
6016
6018 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
6019
6021 ok(hfile != INVALID_HANDLE_VALUE, "failed to open source file\n");
6022 ret = WriteFile(hfile, prefix, sizeof(prefix), &len, NULL );
6023 ok(ret && len == sizeof(prefix), "WriteFile error %ld\n", GetLastError());
6024 ok(GetFileSize(hfile, NULL) == sizeof(prefix), "source file has wrong size\n");
6025
6026 ret = GetFileTime(hfile, NULL, NULL, &ft1);
6027 ok(ret, "GetFileTime error %ld\n", GetLastError());
6028 ft2 = ft1;
6029 ft2.dwLowDateTime -= 600000000; /* 60 second */
6030 ret = SetFileTime(hfile, NULL, NULL, &ft2);
6031 ok(ret, "SetFileTime error %ld\n", GetLastError());
6032 memset(&ft2, 0, sizeof(ft2));
6033 ret = GetFileTime(hfile, NULL, NULL, &ft2); /* get the actual time back */
6034 ok(ret, "GetFileTime error %ld\n", GetLastError());
6035 ok(memcmp(&ft1, &ft2, sizeof(ft1)), "Unexpected write time.\n");
6036
6037 memset(&ft1, 0xff, sizeof(ft1));
6038 ret = SetFileTime(hfile, NULL, NULL, &ft1);
6039 ok(ret, "SetFileTime error %ld\n", GetLastError());
6040 memset(&ft1, 0, sizeof(ft1));
6041 ret = GetFileTime(hfile, NULL, NULL, &ft1); /* get the actual time back */
6042 ok(ret, "GetFileTime error %ld\n", GetLastError());
6043 ok(!memcmp(&ft1, &ft2, sizeof(ft1)), "Unexpected write time.\n");
6044
6045 CloseHandle(hfile);
6046}
6047
6048static void test_hard_link(void)
6049{
6050 char cwd[MAX_PATH], temp_dir[MAX_PATH], name_buffer[200], buffer[20];
6051 FILE_NAME_INFORMATION *name_info = (FILE_NAME_INFORMATION *)name_buffer;
6054 HANDLE file;
6055 DWORD size;
6056 BOOL ret;
6057
6058 GetCurrentDirectoryA( sizeof(cwd), cwd );
6059 GetTempPathA( sizeof(temp_dir), temp_dir );
6061
6062 ret = CreateDirectoryA( "winetest_dir1", NULL );
6063 ok(ret, "failed to create directory, error %lu\n", GetLastError());
6064 ret = CreateDirectoryA( "winetest_dir2", NULL );
6065 ok(ret, "failed to create directory, error %lu\n", GetLastError());
6066 create_file( "winetest_file1" );
6067 create_file( "winetest_file2" );
6068
6069 ret = CreateHardLinkA( "winetest_file3", "winetest_file1", NULL );
6070 ok(ret, "got error %lu\n", GetLastError());
6071
6072 file = CreateFileA( "winetest_file3", FILE_READ_DATA, 0, NULL, OPEN_EXISTING, 0, NULL );
6073 ok(file != INVALID_HANDLE_VALUE, "got error %lu\n", GetLastError());
6074
6075 status = NtQueryInformationFile( file, &io, name_buffer, sizeof(name_buffer), FileNameInformation );
6076 ok(!status, "got status %#lx\n", status);
6077#ifdef __REACTOS__
6078 if (!status)
6079#endif
6080 ok(!wcsncmp(name_info->FileName + (name_info->FileNameLength / sizeof(WCHAR)) - wcslen(L"\\winetest_file3"),
6081 L"\\winetest_file3", wcslen(L"\\winetest_file3")), "got name %s\n",
6082 debugstr_wn(name_info->FileName, name_info->FileNameLength / sizeof(WCHAR)));
6083
6084 ret = ReadFile( file, buffer, sizeof(buffer), &size, NULL );
6085 ok(ret, "got error %lu\n", GetLastError());
6086 ok(!memcmp( buffer, "winetest_file1", size ), "got file contents %s\n", debugstr_an( buffer, size ));
6087
6088 CloseHandle( file );
6089
6090 ret = DeleteFileA( "winetest_file3" );
6091 ok(ret, "failed to delete file, error %lu\n", GetLastError());
6092
6093 SetLastError(0xdeadbeef);
6094 ret = CreateHardLinkA( "winetest_file2", "winetest_file1", NULL );
6095 ok(!ret, "expected failure\n");
6096 ok(GetLastError() == ERROR_ALREADY_EXISTS, "got error %lu\n", GetLastError());
6097
6098 SetLastError(0xdeadbeef);
6099 ret = CreateHardLinkA( "WineTest_File1", "winetest_file1", NULL );
6100 ok(!ret, "expected failure\n");
6101 ok(GetLastError() == ERROR_ALREADY_EXISTS, "got error %lu\n", GetLastError());
6102
6103 SetLastError(0xdeadbeef);
6104 ret = CreateHardLinkA( "winetest_file3", "winetest_dir1", NULL );
6105 ok(!ret, "expected failure\n");
6106 ok(GetLastError() == ERROR_ACCESS_DENIED, "got error %lu\n", GetLastError());
6107
6108 SetLastError(0xdeadbeef);
6109 ret = CreateHardLinkA( "winetest_dir2", "winetest_dir1", NULL );
6110 ok(!ret, "expected failure\n");
6112 || GetLastError() == ERROR_ALREADY_EXISTS /* XP */, "got error %lu\n", GetLastError());
6113
6114 SetLastError(0xdeadbeef);
6115 ret = CreateHardLinkA( "winetest_dir1", "winetest_file1", NULL );
6116 ok(!ret, "expected failure\n");
6117 ok(GetLastError() == ERROR_ALREADY_EXISTS, "got error %lu\n", GetLastError());
6118
6119 ret = RemoveDirectoryA( "winetest_dir1" );
6120 ok(ret, "failed to remove directory, error %lu\n", GetLastError());
6121 ret = RemoveDirectoryA( "winetest_dir2" );
6122 ok(ret, "failed to remove directory, error %lu\n", GetLastError());
6123 ret = DeleteFileA( "winetest_file1" );
6124 ok(ret, "failed to delete file, error %lu\n", GetLastError());
6125 ret = DeleteFileA( "winetest_file2" );
6126 ok(ret, "failed to delete file, error %lu\n", GetLastError());
6127 SetCurrentDirectoryA( cwd );
6128}
6129
6130static void test_move_file(void)
6131{
6132 char cwd[MAX_PATH], temp_dir[MAX_PATH];
6133 HANDLE file;
6134 BOOL ret;
6135
6136 GetCurrentDirectoryA( sizeof(cwd), cwd );
6137 GetTempPathA( sizeof(temp_dir), temp_dir );
6139
6140 ret = CreateDirectoryA( "winetest_dir1", NULL );
6141 ok(ret, "failed to create directory, error %lu\n", GetLastError());
6142 ret = CreateDirectoryA( "winetest_dir2", NULL );
6143 ok(ret, "failed to create directory, error %lu\n", GetLastError());
6144 create_file( "winetest_file1" );
6145 create_file( "winetest_file2" );
6146
6147 ret = MoveFileA( "winetest_file1", "winetest_file3" );
6148 ok(ret, "failed to move file, error %lu\n", GetLastError());
6149 ret = GetFileAttributesA( "winetest_file1" );
6150 ok(ret == INVALID_FILE_ATTRIBUTES, "got %#x\n", ret);
6151 ret = GetFileAttributesA( "winetest_file3" );
6152 ok(ret != INVALID_FILE_ATTRIBUTES, "got %#x\n", ret);
6153
6154 SetLastError(0xdeadbeef);
6155 ret = MoveFileA( "winetest_file3", "winetest_file2" );
6156 ok(!ret, "expected failure\n");
6157 ok(GetLastError() == ERROR_ALREADY_EXISTS, "got error %lu\n", GetLastError());
6158
6159 SetLastError(0xdeadbeef);
6160 ret = MoveFileA( "winetest_file1", "winetest_file4" );
6161 ok(!ret, "expected failure\n");
6162 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "got error %lu\n", GetLastError());
6163
6164 ret = MoveFileA( "winetest_dir1", "winetest_dir3" );
6165 ok(ret, "failed to move file, error %lu\n", GetLastError());
6166
6167 SetLastError(0xdeadbeef);
6168 ret = MoveFileA( "winetest_dir3", "winetest_dir2" );
6169 ok(!ret, "expected failure\n");
6170 ok(GetLastError() == ERROR_ALREADY_EXISTS, "got error %lu\n", GetLastError());
6171
6172 file = CreateFileA( "winetest_file3", DELETE, 0, NULL, OPEN_EXISTING, 0, 0 );
6173 ok(file != INVALID_HANDLE_VALUE, "failed to open file, error %lu\n", GetLastError());
6174 ret = MoveFileA( "winetest_file3", "winetest_file1" );
6175 ok(!ret, "expected failure\n");
6176 ok(GetLastError() == ERROR_SHARING_VIOLATION, "got error %lu\n", GetLastError());
6177 CloseHandle( file );
6178
6179 file = CreateFileA( "winetest_file3", 0, 0, NULL, OPEN_EXISTING, 0, 0 );
6180 ok(file != INVALID_HANDLE_VALUE, "failed to open file, error %lu\n", GetLastError());
6181 ret = MoveFileA( "winetest_file3", "winetest_file1" );
6182 ok(ret, "failed to move file, error %lu\n", GetLastError());
6183 ret = GetFileAttributesA( "winetest_file1" );
6184 ok(ret != INVALID_FILE_ATTRIBUTES, "got %#x\n", ret);
6185 ret = GetFileAttributesA( "winetest_file3" );
6186 ok(ret == INVALID_FILE_ATTRIBUTES, "got %#x\n", ret);
6187 CloseHandle( file );
6188
6189 ret = MoveFileExA( "winetest_file1", "winetest_file2", MOVEFILE_REPLACE_EXISTING );
6190 ok(ret, "failed to move file, error %lu\n", GetLastError());
6191
6192 file = CreateFileA( "winetest_file1", GENERIC_ALL,
6194 ok(file != INVALID_HANDLE_VALUE, "failed to open file, error %lu\n", GetLastError());
6195 SetLastError(0xdeadbeef);
6196 ret = MoveFileExA( "winetest_file2", "winetest_file1", MOVEFILE_REPLACE_EXISTING );
6197 ok(!ret, "expected failure\n");
6198 ok(GetLastError() == ERROR_ACCESS_DENIED, "got error %lu\n", GetLastError());
6199 CloseHandle( file );
6200
6201 SetLastError(0xdeadbeef);
6202 ret = MoveFileExA( "winetest_file2", "winetest_dir2", MOVEFILE_REPLACE_EXISTING );
6203 ok(!ret, "expected failure\n");
6204 ok(GetLastError() == ERROR_ACCESS_DENIED, "got error %lu\n", GetLastError());
6205
6206 SetLastError(0xdeadbeef);
6207 ret = MoveFileExA( "winetest_dir3", "winetest_dir2", MOVEFILE_REPLACE_EXISTING );
6208 ok(!ret, "expected failure\n");
6209 ok(GetLastError() == ERROR_ACCESS_DENIED, "got error %lu\n", GetLastError());
6210
6211 ret = MoveFileExA( "winetest_dir2", "winetest_file2", MOVEFILE_REPLACE_EXISTING );
6212 ok(ret, "failed to move file, error %lu\n", GetLastError());
6213
6214 ret = RemoveDirectoryA( "winetest_dir3" );
6215 ok(ret, "failed to remove directory, error %lu\n", GetLastError());
6216 ret = RemoveDirectoryA( "winetest_file2" );
6217 ok(ret, "failed to remove directory, error %lu\n", GetLastError());
6218 ret = DeleteFileA( "winetest_file1" );
6219 ok(ret, "failed to delete file, error %lu\n", GetLastError());
6220 SetCurrentDirectoryA( cwd );
6221}
6222
6223static void test_eof(void)
6224{
6226 OVERLAPPED overlapped = {0};
6229 unsigned int i;
6230 void *view;
6231 DWORD size;
6232 BOOL ret;
6233
6234 static const struct
6235 {
6236 DWORD protection;
6237 DWORD view_access;
6238 }
6239 map_tests[] =
6240 {
6243 };
6244
6247
6249 ok(file != INVALID_HANDLE_VALUE, "failed to create file, error %lu\n", GetLastError());
6250
6252 ok(ret, "failed to get size, error %lu\n", GetLastError());
6253 ok(!file_size.QuadPart, "got size %I64d\n", file_size.QuadPart);
6254
6256
6258 ok(ret, "failed to get size, error %lu\n", GetLastError());
6259 ok(!file_size.QuadPart, "got size %I64d\n", file_size.QuadPart);
6260
6261 SetLastError(0xdeadbeef);
6262 ret = ReadFile(file, buffer, sizeof(buffer), &size, NULL);
6263 ok(ret, "failed to read, error %lu\n", GetLastError());
6264 ok(!size, "got size %lu\n", size);
6265 ok(GetLastError() == 0xdeadbeef, "got error %lu\n", GetLastError());
6266
6268
6269 SetLastError(0xdeadbeef);
6270 size = 0xdeadbeef;
6271 overlapped.Offset = 2;
6272 ret = ReadFile(file, buffer, sizeof(buffer), &size, &overlapped);
6273 ok(!ret, "expected failure\n");
6274 ok(GetLastError() == ERROR_HANDLE_EOF, "got error %lu\n", GetLastError());
6275 ok(!size, "got size %lu\n", size);
6277 "got status %#lx\n", (NTSTATUS)overlapped.Internal);
6278 ok(!overlapped.InternalHigh, "got size %Iu\n", overlapped.InternalHigh);
6279
6281
6283 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6284
6286 ok(ret, "failed to get size, error %lu\n", GetLastError());
6287 ok(file_size.QuadPart == 2, "got size %I64d\n", file_size.QuadPart);
6288
6289 ret = WriteFile(file, "data", 4, &size, NULL);
6290 ok(ret, "failed to write, error %lu\n", GetLastError());
6291 ok(size == 4, "got size %lu\n", size);
6292
6294 ok(ret, "failed to get size, error %lu\n", GetLastError());
6295 ok(file_size.QuadPart == 6, "got size %I64d\n", file_size.QuadPart);
6296
6299 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6300
6302 ok(ret, "failed to get size, error %lu\n", GetLastError());
6303 ok(file_size.QuadPart == 4, "got size %I64d\n", file_size.QuadPart);
6304
6306 ret = ReadFile(file, buffer, sizeof(buffer), &size, NULL);
6307 ok(ret, "failed to read, error %lu\n", GetLastError());
6308 ok(size == 4, "got size %lu\n", size);
6309 ok(!memcmp(buffer, "\0\0da", 4), "wrong data\n");
6310
6313 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6314
6316 ok(ret, "failed to get size, error %lu\n", GetLastError());
6317 ok(file_size.QuadPart == 6, "got size %I64d\n", file_size.QuadPart);
6318
6320 ret = ReadFile(file, buffer, sizeof(buffer), &size, NULL);
6321 ok(ret, "failed to read, error %lu\n", GetLastError());
6322 ok(size == 6, "got size %lu\n", size);
6323 ok(!memcmp(buffer, "\0\0da\0\0", 6), "wrong data\n");
6324
6326 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6327
6329 ret = WriteFile(file, "data", 4, &size, NULL);
6330 ok(ret, "failed to write, error %lu\n", GetLastError());
6331 ok(size == 4, "got size %lu\n", size);
6332
6334 ok(ret, "failed to get size, error %lu\n", GetLastError());
6335 ok(file_size.QuadPart == 6, "got size %I64d\n", file_size.QuadPart);
6336
6338 ret = ReadFile(file, buffer, sizeof(buffer), &size, NULL);
6339 ok(ret, "failed to read, error %lu\n", GetLastError());
6340 ok(size == 6, "got size %lu\n", size);
6341 ok(!memcmp(buffer, "\0\0data", 6), "wrong data\n");
6342
6343 for (i = 0; i < ARRAY_SIZE(map_tests); ++i)
6344 {
6345 mapping = CreateFileMappingA(file, NULL, map_tests[i].protection, 0, 4, NULL);
6346 ok(!!mapping, "failed to create mapping, error %lu\n", GetLastError());
6347
6349 ok(ret, "failed to get size, error %lu\n", GetLastError());
6350 ok(file_size.QuadPart == 6, "got size %I64d\n", file_size.QuadPart);
6351
6354 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6356 ok(ret, "failed to get size, error %lu\n", GetLastError());
6357 ok(file_size.QuadPart == 6, "got size %I64d\n", file_size.QuadPart);
6358
6361 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6363 ok(ret, "failed to get size, error %lu\n", GetLastError());
6364 ok(file_size.QuadPart == 8, "got size %I64d\n", file_size.QuadPart);
6365
6366 SetLastError(0xdeadbeef);
6369 ok(!ret, "expected failure\n");
6370 ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %lu\n", GetLastError());
6372 ok(ret, "failed to get size, error %lu\n", GetLastError());
6373 ok(file_size.QuadPart == 8, "got size %I64d\n", file_size.QuadPart);
6374
6377 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6379 ok(ret, "failed to get size, error %lu\n", GetLastError());
6380 ok(file_size.QuadPart == 8192, "got size %I64d\n", file_size.QuadPart);
6381
6384 ok(!ret, "expected failure\n");
6385 ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %lu\n", GetLastError());
6387 ok(ret, "failed to get size, error %lu\n", GetLastError());
6388 ok(file_size.QuadPart == 8192, "got size %I64d\n", file_size.QuadPart);
6389
6390 view = MapViewOfFile(mapping, map_tests[i].view_access, 0, 0, 4);
6391 ok(!!view, "failed to map view, error %lu\n", GetLastError());
6392
6394
6395 SetFilePointer(file, 16384, NULL, SEEK_SET);
6397 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6399 ok(ret, "failed to get size, error %lu\n", GetLastError());
6400 ok(file_size.QuadPart == 16384, "got size %I64d\n", file_size.QuadPart);
6401
6402 SetFilePointer(file, 16383, NULL, SEEK_SET);
6404 ok(!ret, "expected failure\n");
6405 ok(GetLastError() == ERROR_USER_MAPPED_FILE, "got error %lu\n", GetLastError());
6407 ok(ret, "failed to get size, error %lu\n", GetLastError());
6408 ok(file_size.QuadPart == 16384, "got size %I64d\n", file_size.QuadPart);
6409
6411 ok(ret, "failed to unmap view, error %lu\n", GetLastError());
6412
6415 ok(ret, "failed to set EOF, error %lu\n", GetLastError());
6417 ok(ret, "failed to get size, error %lu\n", GetLastError());
6418 ok(file_size.QuadPart == 6, "got size %I64d\n", file_size.QuadPart);
6419 }
6420
6423 ok(ret, "failed to delete %s, error %lu\n", debugstr_a(filename), GetLastError());
6424}
6425
6427{
6428 char temp_path[MAX_PATH];
6429 DWORD ret;
6430
6432
6434 ok(ret != 0, "GetTempPath error %lu\n", GetLastError());
6435 ret = GetTempFileNameA(temp_path, "tmp", 0, filename);
6436 ok(ret != 0, "GetTempFileName error %lu\n", GetLastError());
6438 ok(ret != 0, "DeleteFile error %lu\n", GetLastError());
6439
6440 test__hread( );
6441 test__hwrite( );
6442 test__lclose( );
6443 test__lcreat( );
6444 test__llseek( );
6445 test__llopen( );
6446 test__lread( );
6447 test__lwrite( );
6468 /* FindExLimitToDirectories is ignored if the file system doesn't support directory filtering */
6473 test_LockFile();
6476 test_MapFile();
6480 test_OpenFile();
6503 test_eof();
6504}
ios_base &_STLP_CALL hex(ios_base &__s)
Definition: _ios_base.h:324
unsigned char BOOLEAN
Definition: actypes.h:127
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
static long backup()
Definition: maze.c:403
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define broken(x)
Definition: atltest.h:178
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
static const WCHAR nameW[]
Definition: main.c:49
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define ARRAY_SIZE(A)
Definition: main.h:20
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
BOOL WINAPI CopyFileExA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName, IN LPPROGRESS_ROUTINE lpProgressRoutine OPTIONAL, IN LPVOID lpData OPTIONAL, IN LPBOOL pbCancel OPTIONAL, IN DWORD dwCopyFlags)
Definition: copyansi.c:20
BOOL WINAPI CopyFileA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName, IN BOOL bFailIfExists)
Definition: copyansi.c:58
#define STATUS_INVALID_HANDLE
Definition: d3dkmdt.h:40
static TAGID TAGID find
Definition: db.cpp:156
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
PIMAGE_NT_HEADERS nt
Definition: delayimp.cpp:445
HRESULT hr
Definition: delayimp.cpp:582
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static int find_data(const struct Vector *v, const BYTE *pData, int size)
Definition: filtermapper.c:162
#define NTSTATUS
Definition: precomp.h:19
BOOL WINAPI LookupPrivilegeValueA(LPCSTR lpSystemName, LPCSTR lpName, PLUID lpLuid)
Definition: misc.c:732
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
static cab_ULONG checksum(const cab_UBYTE *data, cab_UWORD bytes, cab_ULONG csum)
Definition: fdi.c:353
static WCHAR reason[MAX_STRING_RESOURCE_LEN]
Definition: object.c:1904
#define CloseHandle
Definition: compat.h:739
#define IMAGE_FILE_MACHINE_ARMNT
Definition: compat.h:127
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define PAGE_READONLY
Definition: compat.h:138
#define FILE_BEGIN
Definition: compat.h:761
#define INVALID_SET_FILE_POINTER
Definition: compat.h:732
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define UnmapViewOfFile
Definition: compat.h:746
#define CP_ACP
Definition: compat.h:109
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define SetFilePointer
Definition: compat.h:743
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define HeapAlloc
Definition: compat.h:733
#define CreateFileMappingW(a, b, c, d, e, f)
Definition: compat.h:744
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:740
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define GetCurrentProcess()
Definition: compat.h:759
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define CreateFileW
Definition: compat.h:741
#define FILE_MAP_READ
Definition: compat.h:776
#define IMAGE_FILE_MACHINE_ARM64
Definition: compat.h:129
#define GetFileSizeEx
Definition: compat.h:757
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define CALLBACK
Definition: compat.h:35
#define lstrcpyW
Definition: compat.h:749
#define MapViewOfFile
Definition: compat.h:745
#define MultiByteToWideChar
Definition: compat.h:110
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define FILE_SHARE_READ
Definition: compat.h:136
#define ERROR_INVALID_NAME
Definition: compat.h:103
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define lstrlenW
Definition: compat.h:750
static void cleanup(void)
Definition: main.c:1335
static HRESULT create_error(script_ctx_t *ctx, jsdisp_t *constr, UINT number, jsstr_t *msg, jsdisp_t **ret)
Definition: error.c:181
DWORD WINAPI QueryDosDeviceW(LPCWSTR lpDeviceName, LPWSTR lpTargetPath, DWORD ucchMax)
Definition: dosdev.c:542
HFILE WINAPI OpenFile(LPCSTR lpFileName, LPOFSTRUCT lpReOpenBuff, UINT uStyle)
Definition: create.c:368
HANDLE WINAPI CreateMailslotW(IN LPCWSTR lpName, IN DWORD nMaxMessageSize, IN DWORD lReadTimeout, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: mailslot.c:37
BOOL WINAPI MoveFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName)
Definition: move.c:1058
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:751
BOOL WINAPI DuplicateHandle(IN HANDLE hSourceProcessHandle, IN HANDLE hSourceHandle, IN HANDLE hTargetProcessHandle, OUT LPHANDLE lpTargetHandle, IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN DWORD dwOptions)
Definition: handle.c:149
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
VOID WINAPI GetSystemInfo(IN LPSYSTEM_INFO lpSystemInfo)
Definition: sysinfo.c:143
DWORD WINAPI QueueUserAPC(IN PAPCFUNC pfnAPC, IN HANDLE hThread, IN ULONG_PTR dwData)
Definition: thread.c:959
int WINAPI lstrcmpA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4104
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4171
int WINAPI lstrcmpiA(LPCSTR str1, LPCSTR str2)
Definition: locale.c:4133
DWORD WINAPI DECLSPEC_HOTPATCH GetTempPathA(DWORD count, LPSTR path)
Definition: file.c:2420
BOOL WINAPI DECLSPEC_HOTPATCH UnlockFileEx(HANDLE file, DWORD reserved, DWORD count_low, DWORD count_high, LPOVERLAPPED overlapped)
Definition: file.c:3879
BOOL WINAPI DECLSPEC_HOTPATCH WriteFileGather(HANDLE file, FILE_SEGMENT_ELEMENT *segments, DWORD count, LPDWORD reserved, LPOVERLAPPED overlapped)
Definition: file.c:3974
UINT WINAPI DECLSPEC_HOTPATCH GetTempFileNameW(LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer)
Definition: file.c:2355
DWORD WINAPI DECLSPEC_HOTPATCH GetLongPathNameW(LPCWSTR shortpath, LPWSTR longpath, DWORD longlen)
Definition: file.c:2014
DWORD WINAPI DECLSPEC_HOTPATCH GetTempPathW(DWORD count, LPWSTR path)
Definition: file.c:2438
BOOL WINAPI DECLSPEC_HOTPATCH WriteFile(HANDLE file, LPCVOID buffer, DWORD count, LPDWORD result, LPOVERLAPPED overlapped)
Definition: file.c:3896
BOOL WINAPI DECLSPEC_HOTPATCH UnlockFile(HANDLE file, DWORD offset_low, DWORD offset_high, DWORD count_low, DWORD count_high)
Definition: file.c:3863
UINT WINAPI DECLSPEC_HOTPATCH GetCurrentDirectoryA(UINT buflen, LPSTR buf)
Definition: file.c:1620
DWORD WINAPI DECLSPEC_HOTPATCH GetFileType(HANDLE file)
Definition: file.c:3221
BOOL WINAPI DECLSPEC_HOTPATCH SetFileAttributesA(LPCSTR name, DWORD attributes)
Definition: file.c:2906
BOOL WINAPI DECLSPEC_HOTPATCH GetOverlappedResult(HANDLE file, LPOVERLAPPED overlapped, LPDWORD result, BOOL wait)
Definition: file.c:3255
UINT WINAPI DECLSPEC_HOTPATCH GetWindowsDirectoryA(LPSTR path, UINT count)
Definition: file.c:2513
BOOL WINAPI DECLSPEC_HOTPATCH GetFileInformationByHandle(HANDLE file, BY_HANDLE_FILE_INFORMATION *info)
Definition: file.c:3038
BOOL WINAPI DECLSPEC_HOTPATCH DeleteFileW(LPCWSTR path)
Definition: file.c:1003
BOOL WINAPI DECLSPEC_HOTPATCH DeleteFileA(LPCSTR path)
Definition: file.c:991
DWORD WINAPI DECLSPEC_HOTPATCH GetFileSize(HANDLE file, LPDWORD size_high)
Definition: file.c:3160
UINT WINAPI DECLSPEC_HOTPATCH GetTempFileNameA(LPCSTR path, LPCSTR prefix, UINT unique, LPSTR buffer)
Definition: file.c:2335
BOOL WINAPI DECLSPEC_HOTPATCH RemoveDirectoryA(LPCSTR path)
Definition: file.c:3607
BOOL WINAPI DECLSPEC_HOTPATCH ReadFileEx(HANDLE file, LPVOID buffer, DWORD count, LPOVERLAPPED overlapped, LPOVERLAPPED_COMPLETION_ROUTINE completion)
Definition: file.c:3553
BOOL WINAPI DECLSPEC_HOTPATCH CopyFileW(const WCHAR *source, const WCHAR *dest, BOOL fail_if_exists)
Definition: file.c:632
DWORD WINAPI DECLSPEC_HOTPATCH GetFileAttributesA(LPCSTR name)
Definition: file.c:1659
UINT WINAPI DECLSPEC_HOTPATCH GetWindowsDirectoryW(LPWSTR path, UINT count)
Definition: file.c:2522
HANDLE WINAPI DECLSPEC_HOTPATCH FindFirstFileA(const char *filename, WIN32_FIND_DATAA *data)
Definition: file.c:1363
BOOL WINAPI DECLSPEC_HOTPATCH SetCurrentDirectoryA(LPCSTR dir)
Definition: file.c:2862
BOOL WINAPI DECLSPEC_HOTPATCH SetFileAttributesW(LPCWSTR name, DWORD attributes)
Definition: file.c:2918
BOOL WINAPI DECLSPEC_HOTPATCH CreateHardLinkA(const char *dest, const char *source, SECURITY_ATTRIBUTES *attr)
Definition: file.c:909
DWORD WINAPI DECLSPEC_HOTPATCH GetLongPathNameA(LPCSTR shortpath, LPSTR longpath, DWORD longlen)
Definition: file.c:1989
BOOL WINAPI DECLSPEC_HOTPATCH CreateDirectoryW(LPCWSTR path, LPSECURITY_ATTRIBUTES sa)
Definition: file.c:653
BOOL WINAPI CopyFileExW(const WCHAR *source, const WCHAR *dest, LPPROGRESS_ROUTINE progress, void *param, BOOL *cancel_ptr, DWORD flags)
Definition: file.c:609
BOOL WINAPI DECLSPEC_HOTPATCH SetCurrentDirectoryW(LPCWSTR dir)
Definition: file.c:2876
BOOL WINAPI DECLSPEC_HOTPATCH CreateDirectoryA(LPCSTR path, LPSECURITY_ATTRIBUTES sa)
Definition: file.c:641
BOOL WINAPI DECLSPEC_HOTPATCH FindNextFileA(HANDLE handle, WIN32_FIND_DATAA *data)
Definition: file.c:1401
BOOL WINAPI DECLSPEC_HOTPATCH GetFileAttributesExW(LPCWSTR name, GET_FILEEX_INFO_LEVELS level, void *ptr)
Definition: file.c:1721
BOOL WINAPI DECLSPEC_HOTPATCH GetFileTime(HANDLE file, FILETIME *creation, FILETIME *access, FILETIME *write)
Definition: file.c:3190
BOOL WINAPI DECLSPEC_HOTPATCH RemoveDirectoryW(LPCWSTR path)
Definition: file.c:3619
BOOL WINAPI DECLSPEC_HOTPATCH LockFile(HANDLE file, DWORD offset_low, DWORD offset_high, DWORD count_low, DWORD count_high)
Definition: file.c:3306
BOOL WINAPI DECLSPEC_HOTPATCH FindClose(HANDLE handle)
Definition: file.c:1525
BOOL WINAPI DECLSPEC_HOTPATCH LockFileEx(HANDLE file, DWORD flags, DWORD reserved, DWORD count_low, DWORD count_high, LPOVERLAPPED overlapped)
Definition: file.c:3324
BOOL WINAPI DECLSPEC_HOTPATCH ReadFileScatter(HANDLE file, FILE_SEGMENT_ELEMENT *segments, DWORD count, LPDWORD reserved, LPOVERLAPPED overlapped)
Definition: file.c:3583
INT WINAPI DECLSPEC_HOTPATCH CompareFileTime(const FILETIME *x, const FILETIME *y)
Definition: file.c:4003
BOOL WINAPI DECLSPEC_HOTPATCH SetEndOfFile(HANDLE file)
Definition: file.c:3651
BOOL WINAPI DECLSPEC_HOTPATCH SetFileTime(HANDLE file, const FILETIME *ctime, const FILETIME *atime, const FILETIME *mtime)
Definition: file.c:3819
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
int CDECL fclose(FILE *file)
Definition: file.c:3757
int CDECL fputs(const char *s, FILE *file)
Definition: file.c:4769
FILE *CDECL fopen(const char *path, const char *mode)
Definition: file.c:4310
#define DECLSPEC_ALIGN(x)
Definition: corecrt.h:141
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2988
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
_ACRTIMP int __cdecl wcsncmp(const wchar_t *, const wchar_t *, size_t)
Definition: wcs.c:523
_ACRTIMP int __cdecl rand(void)
Definition: misc.c:59
_ACRTIMP void __cdecl srand(unsigned int)
Definition: misc.c:50
_ACRTIMP char *__cdecl strchr(const char *, int)
Definition: string.c:3291
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
_ACRTIMP int __cdecl strncmp(const char *, const char *, size_t)
Definition: string.c:3335
_ACRTIMP char *__cdecl strrchr(const char *, int)
Definition: string.c:3303
USHORT port
Definition: uri.c:228
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define INFINITE
Definition: serial.h:102
struct _IO_STATUS_BLOCK * PIO_STATUS_BLOCK
Definition: change.c:34
ANSI_STRING * PANSI_STRING
Definition: env_spec_w32.h:380
HANDLE NTAPI CreateFileMappingA(IN HANDLE hFile, IN LPSECURITY_ATTRIBUTES lpFileMappingAttributes, IN DWORD flProtect, IN DWORD dwMaximumSizeHigh, IN DWORD dwMaximumSizeLow, IN LPCSTR lpName)
Definition: filemap.c:23
#define MOVEFILE_REPLACE_EXISTING
Definition: filesup.h:28
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES
Definition: ntddk_ex.h:135
@ FileNameInformation
Definition: from_kernel.h:70
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_OPEN_IF
Definition: from_kernel.h:56
GLint level
Definition: gl.h:1546
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint res
Definition: glext.h:9613
GLuint buffer
Definition: glext.h:5915
GLsizeiptr size
Definition: glext.h:5919
GLintptr offset
Definition: glext.h:5920
const GLubyte * c
Definition: glext.h:8905
GLubyte * pattern
Definition: glext.h:7787
GLfloat f
Definition: glext.h:7540
GLenum mode
Definition: glext.h:6217
GLenum const GLfloat * params
Definition: glext.h:5645
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLbitfield flags
Definition: glext.h:7161
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
GLuint64EXT * result
Definition: glext.h:11304
GLenum GLenum GLenum GLenum mapping
Definition: glext.h:9031
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat param
Definition: glext.h:5796
GLenum GLsizei len
Definition: glext.h:6722
const GLfloat * m
Definition: glext.h:10848
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
HLOCAL NTAPI LocalAlloc(UINT uFlags, SIZE_T dwBytes)
Definition: heapmem.c:1390
LPVOID NTAPI LocalLock(HLOCAL hMem)
Definition: heapmem.c:1616
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
static const WCHAR emptyW[]
Definition: navigate.c:40
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
#define S_OK
Definition: intsafe.h:52
const char * filename
Definition: ioapi.h:137
BOOL WINAPI PostQueuedCompletionStatus(IN HANDLE CompletionHandle, IN DWORD dwNumberOfBytesTransferred, IN ULONG_PTR dwCompletionKey, IN LPOVERLAPPED lpOverlapped)
Definition: iocompl.c:192
HANDLE WINAPI CreateIoCompletionPort(IN HANDLE FileHandle, IN HANDLE ExistingCompletionPort, IN ULONG_PTR CompletionKey, IN DWORD NumberOfConcurrentThreads)
Definition: iocompl.c:65
#define FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
Definition: iocompl.c:22
BOOL WINAPI GetQueuedCompletionStatus(IN HANDLE CompletionHandle, IN LPDWORD lpNumberOfBytesTransferred, OUT PULONG_PTR lpCompletionKey, OUT LPOVERLAPPED *lpOverlapped, IN DWORD dwMilliseconds)
Definition: iocompl.c:131
#define SEEK_SET
Definition: jmemansi.c:26
#define c
Definition: ke_i.h:80
#define debugstr_a
Definition: kernel32.h:31
#define _lread(a, b, c)
Definition: kernel32.h:168
#define debugstr_wn
Definition: kernel32.h:33
#define wine_dbgstr_w
Definition: kernel32.h:34
int WINAPI _lclose(HFILE hFile)
Definition: lfile.c:138
LONG WINAPI _llseek(HFILE hFile, LONG lOffset, int iOrigin)
Definition: lfile.c:149
HFILE WINAPI _lopen(LPCSTR lpPathName, int iReadWrite)
Definition: lfile.c:70
HFILE WINAPI _lcreat(LPCSTR lpPathName, int iAttribute)
Definition: lfile.c:116
long WINAPI _hwrite(HFILE hFile, LPCSTR lpBuffer, long lBytes)
Definition: lfile.c:41
long WINAPI _hread(HFILE hFile, LPVOID lpBuffer, long lBytes)
Definition: lfile.c:20
__cdecl __MINGW_NOTHROW char * dirname(char *)
LPSTR WINAPI lstrcpyA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:100
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
LPSTR WINAPI lstrcatA(LPSTR lpString1, LPCSTR lpString2)
Definition: lstring.c:123
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145
struct S1 s1
#define win_skip
Definition: minitest.h:67
#define todo_wine_if(is_todo)
Definition: minitest.h:81
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl void winetest_pop_context(void)
void __cdecl void __cdecl void __cdecl void __cdecl void __cdecl winetest_push_context(const char *fmt,...) __WINE_PRINTF_ATTR(1
Definition: test.h:537
#define todo_wine
Definition: minitest.h:80
enum _FINDEX_SEARCH_OPS FINDEX_SEARCH_OPS
#define LOCKFILE_FAIL_IMMEDIATELY
Definition: minwinbase.h:100
#define LOCKFILE_EXCLUSIVE_LOCK
Definition: minwinbase.h:101
@ FindExSearchLimitToDirectories
Definition: minwinbase.h:349
#define LPTR
Definition: minwinbase.h:93
#define FIND_FIRST_EX_LARGE_FETCH
Definition: minwinbase.h:70
#define FIND_FIRST_EX_CASE_SENSITIVE
Definition: minwinbase.h:69
@ GetFileExInfoStandard
Definition: minwinbase.h:356
@ FileIoPriorityHintInfo
Definition: minwinbase.h:316
@ FileCompressionInfo
Definition: minwinbase.h:312
@ FileRemoteProtocolInfo
Definition: minwinbase.h:317
@ FileAttributeTagInfo
Definition: minwinbase.h:313
@ FileIdBothDirectoryInfo
Definition: minwinbase.h:314
@ FileRenameInfo
Definition: minwinbase.h:307
@ FileEndOfFileInfo
Definition: minwinbase.h:310
@ FileStandardInfo
Definition: minwinbase.h:305
@ FileAllocationInfo
Definition: minwinbase.h:309
@ FileDispositionInfo
Definition: minwinbase.h:308
@ FileNameInfo
Definition: minwinbase.h:306
@ FileBasicInfo
Definition: minwinbase.h:304
enum _FINDEX_INFO_LEVELS FINDEX_INFO_LEVELS
@ FindExInfoStandard
Definition: minwinbase.h:341
@ FindExInfoBasic
Definition: minwinbase.h:342
enum _FILE_INFO_BY_HANDLE_CLASS FILE_INFO_BY_HANDLE_CLASS
Definition: file.c:55
int HFILE
Definition: minwindef.h:222
__u16 time
Definition: mkdosfs.c:8
static int blocks
Definition: mkdosfs.c:527
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
BOOL WINAPI GetVolumeNameForVolumeMountPointW(IN LPCWSTR VolumeMountPoint, OUT LPWSTR VolumeName, IN DWORD VolumeNameLength)
Definition: mntpoint.c:496
#define CREATE_ALWAYS
Definition: disk.h:72
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define TRUNCATE_EXISTING
Definition: disk.h:71
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define FILE_FLAG_NO_BUFFERING
Definition: disk.h:45
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FILE_FLAG_RANDOM_ACCESS
Definition: disk.h:44
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define CREATE_NEW
Definition: disk.h:69
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_ATTRIBUTE_DEVICE
Definition: disk.h:27
#define FILE_FLAG_SEQUENTIAL_SCAN
Definition: disk.h:43
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define FILE_FLAG_WRITE_THROUGH
Definition: disk.h:47
static PVOID ptr
Definition: dispmode.c:27
static struct test_info tests[]
#define sprintf
Definition: sprintf.c:45
#define VOLUME_NAME_GUID
FN_GetFinalPathNameByHandleW * pGetFinalPathNameByHandleW
#define VOLUME_NAME_NONE
#define FILE_NAME_NORMALIZED
#define VOLUME_NAME_NT
#define VOLUME_NAME_DOS
static const WCHAR filenameW[]
Definition: amstream.c:41
static const struct update_accum a1
Definition: msg.c:534
static const struct update_accum a2
Definition: msg.c:542
BOOL expected
Definition: store.c:2000
#define create_file(name, size)
Definition: asmcache.c:813
static ACCESS_MASK
Definition: file.c:51
static POBJECT_ATTRIBUTES
Definition: file.c:51
static void test_ReplaceFileA(void)
Definition: file.c:3903
static void CALLBACK user_apc(ULONG_PTR param)
Definition: file.c:3451
static PCWSTR
Definition: file.c:47
static LPSTR
Definition: file.c:43
static void test_FindFirstFileExA(FINDEX_INFO_LEVELS level, FINDEX_SEARCH_OPS search_ops, DWORD flags)
Definition: file.c:2989
static void test_GetFileInformationByHandleEx(void)
Definition: file.c:4408
static void test_ReplaceFileW(void)
Definition: file.c:4190
static void test_DeleteFileA(void)
Definition: file.c:1924
static void test_SetFileTime(void)
Definition: file.c:6005
static void test_eof(void)
Definition: file.c:6223
static char filename[MAX_PATH]
Definition: file.c:63
static const char sillytext[]
Definition: file.c:64
static PCSZ
Definition: file.c:58
static void test_CreateFileA(void)
Definition: file.c:1328
static void test_FindNextFileA(void)
Definition: file.c:2970
static DWORD WINAPI copy_progress_cb(LARGE_INTEGER total_size, LARGE_INTEGER total_transferred, LARGE_INTEGER stream_size, LARGE_INTEGER stream_transferred, DWORD stream, DWORD reason, HANDLE source, HANDLE dest, LPVOID userdata)
Definition: file.c:1182
static void test__lcreat(void)
Definition: file.c:293
static void test_OpenFileById(void)
Definition: file.c:4574
static void test_async_file_errors(void)
Definition: file.c:3401
#define IsDotDir(x)
Definition: file.c:2052
static void test_GetFileType(void)
Definition: file.c:3303
static BOOL is_sharing_map_compatible(DWORD map_access, DWORD access2, DWORD sharing2)
Definition: file.c:2576
#define TEST_OVERLAPPED_READ_SIZE
Definition: file.c:5845
static FINDEX_SEARCH_OPS
Definition: file.c:40
static void test_CopyFile2(void)
Definition: file.c:953
static void test_ReOpenFile(void)
Definition: file.c:4815
static LPSECURITY_ATTRIBUTES
Definition: file.c:45
static int completion_count
Definition: file.c:3392
static void test_move_file(void)
Definition: file.c:6130
#define PATTERN_OFFSET
Definition: file.c:2267
static void test__hwrite(void)
Definition: file.c:167
static BOOL is_access_compatible(unsigned obj_access, unsigned desired_access)
Definition: file.c:5182
static void test_file_readonly_access(void)
Definition: file.c:5909
static BOOL create_fake_dll(LPCSTR filename)
Definition: file.c:2472
static void test_MoveFileA(void)
Definition: file.c:2054
static void test_CreateFileW(void)
Definition: file.c:1685
static void test__llopen(void)
Definition: file.c:508
static LPWSTR
Definition: file.c:50
static void test_OpenFile(void)
Definition: file.c:3614
static BOOL check_file_time(const FILETIME *ft1, const FILETIME *ft2, UINT tolerance)
Definition: file.c:3896
static void test_find_file_stream(void)
Definition: file.c:5978
static void test_GetFinalPathNameByHandleA(void)
Definition: file.c:5295
static void test_RemoveDirectory(void)
Definition: file.c:3874
static void test_offset_in_overlapped_structure(void)
Definition: file.c:2269
static void test_WriteFileGather(void)
Definition: file.c:4910
static BOOL user_apc_ran
Definition: file.c:3450
static void test__hread(void)
Definition: file.c:120
static void CALLBACK FileIOComplete(DWORD dwError, DWORD dwBytes, LPOVERLAPPED ovl)
Definition: file.c:3394
static void test_LockFile(void)
Definition: file.c:2342
static void test_CreateFile(void)
Definition: file.c:4275
#define CHECK_LEVEL(fn)
static char get_windows_drive(void)
Definition: file.c:2763
static LPFILE_ID_DESCRIPTOR
Definition: file.c:45
static void test_FindFirstFile_wildcards(void)
Definition: file.c:3092
static STREAM_INFO_LEVELS infolevel
Definition: file.c:61
static void test_file_access(void)
Definition: file.c:5189
static void test_DeleteFileW(void)
Definition: file.c:2000
static void test__lread(void)
Definition: file.c:548
static void test_file_sharing(void)
Definition: file.c:2585
static void test_GetTempFileNameA(void)
Definition: file.c:1887
static void test_CopyFileA(void)
Definition: file.c:679
static void test_FindFirstFileA(void)
Definition: file.c:2770
static unsigned int map_file_access(unsigned int access)
Definition: file.c:2548
static PWSTR CURDIR *static BOOLEAN
Definition: file.c:54
static unsigned file_map_access(unsigned access)
Definition: file.c:5173
static PLARGE_INTEGER
Definition: file.c:52
static void dumpmem(unsigned char *mem, int len)
Definition: file.c:1309
static void test_CopyFileEx(void)
Definition: file.c:1191
static PUNICODE_STRING
Definition: file.c:53
static void test_CopyFileW(void)
Definition: file.c:909
static void test_overlapped_read(void)
Definition: file.c:5847
static void test_SetFileRenameInfo(void)
Definition: file.c:5627
static LPVOID
Definition: file.c:40
static void test_GetFinalPathNameByHandleW(void)
Definition: file.c:5382
static void test_MoveFileW(void)
Definition: file.c:2235
static OVERLAPPED_ENTRY ULONG BOOL
Definition: file.c:56
static void get_nt_pathW(const char *name, UNICODE_STRING *nameW)
Definition: file.c:275
#define CHECK_NAME(fn)
static void test_GetFileAttributesExW(void)
Definition: file.c:5699
static void test_hard_link(void)
Definition: file.c:6048
static void test_overlapped(void)
Definition: file.c:3797
static FINDEX_INFO_LEVELS
Definition: file.c:40
static int test_Mapfile_createtemp(HANDLE *handle)
Definition: file.c:3248
static void test__llseek(void)
Definition: file.c:470
static void test_SetFileValidData(void)
Definition: file.c:4678
static void test_SetFileInformationByHandle(void)
Definition: file.c:5505
static FILE_INFO_BY_HANDLE_CLASS
Definition: file.c:44
static void test_CreateFile2(void)
Definition: file.c:1774
#define M(x)
static BOOL is_sharing_compatible(DWORD access1, DWORD sharing1, DWORD access2, DWORD sharing2)
Definition: file.c:2557
static void test_read_write(void)
Definition: file.c:3456
static PWSTR CURDIR *static PCANSI_STRING
Definition: file.c:54
static void test__lclose(void)
Definition: file.c:254
static void test_post_completion(void)
Definition: file.c:5732
static UCHAR
Definition: file.c:60
static void test__lwrite(void)
Definition: file.c:593
static void InitFunctionPointers(void)
Definition: file.c:84
static void test_MapFile(void)
Definition: file.c:3262
static LONGLONG
Definition: file.c:46
static UINT
Definition: file.c:42
IMAGE_DOS_HEADER dos
Definition: module.c:67
static const WCHAR pathW[]
Definition: path.c:2368
static HINSTANCE hkernel32
Definition: process.c:68
static HINSTANCE hntdll
Definition: process.c:68
static SYSTEM_INFO si
Definition: virtual.c:39
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:72
static char * dest
Definition: rtl.c:149
static const DWORD access_modes[4]
Definition: storage32.c:2054
static const char * contents
Definition: parser.c:511
static LPCWSTR file_name
Definition: protocol.c:147
WCHAR strW[12]
Definition: clipboard.c:2216
BOOL WINAPI MoveFileA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName)
Definition: moveansi.c:23
BOOL WINAPI ReplaceFileA(IN LPCSTR lpReplacedFileName, IN LPCSTR lpReplacementFileName, IN LPCSTR lpBackupFileName OPTIONAL, IN DWORD dwReplaceFlags, IN LPVOID lpExclude, IN LPVOID lpReserved)
Definition: moveansi.c:55
BOOL WINAPI MoveFileExA(IN LPCSTR lpExistingFileName, IN LPCSTR lpNewFileName OPTIONAL, IN DWORD dwFlags)
Definition: moveansi.c:39
#define argv
Definition: mplay32.c:18
char temp_path[MAX_PATH]
Definition: mspatcha.c:123
_In_ HANDLE hFile
Definition: mswsock.h:90
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:93
unsigned int UINT
Definition: ndis.h:50
#define SEC_COMMIT
Definition: mmtypes.h:100
#define SEC_IMAGE
Definition: mmtypes.h:97
_Out_ LPWSTR lpBuffer
Definition: netsh.h:68
HANDLE WINAPI CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: npipe.c:220
BOOL WINAPI CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)
Definition: npipe.c:117
HANDLE WINAPI CreateNamedPipeW(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: npipe.c:246
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
#define PAGE_WRITECOPY
Definition: nt_native.h:1308
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_DATA
Definition: nt_native.h:628
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define FILE_GENERIC_EXECUTE
Definition: nt_native.h:668
#define PAGE_READWRITE
Definition: nt_native.h:1307
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_ATTRIBUTE_HIDDEN
Definition: nt_native.h:703
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define FILE_DELETE_CHILD
Definition: nt_native.h:645
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
#define FILE_READ_EA
Definition: nt_native.h:638
#define FILE_ATTRIBUTE_OFFLINE
Definition: nt_native.h:712
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_EXECUTE
Definition: nt_native.h:642
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define GENERIC_ALL
Definition: nt_native.h:92
#define FILE_ATTRIBUTE_ARCHIVE
Definition: nt_native.h:706
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define DELETE
Definition: nt_native.h:57
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define MEM_RELEASE
Definition: nt_native.h:1319
#define DWORD
Definition: nt_native.h:44
#define GENERIC_WRITE
Definition: nt_native.h:90
#define MEM_COMMIT
Definition: nt_native.h:1316
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define FILE_WRITE_EA
Definition: nt_native.h:640
#define GENERIC_EXECUTE
Definition: nt_native.h:91
#define PAGE_NOACCESS
Definition: nt_native.h:1305
#define PAGE_EXECUTE_READWRITE
Definition: nt_native.h:1311
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define FILE_ATTRIBUTE_TEMPORARY
Definition: nt_native.h:708
#define FILE_ATTRIBUTE_ENCRYPTED
Definition: ntifs_ex.h:385
#define IMAGE_SCN_MEM_WRITE
Definition: ntimage.h:241
#define IMAGE_DLLCHARACTERISTICS_NX_COMPAT
Definition: ntimage.h:457
#define IMAGE_SUBSYSTEM_WINDOWS_GUI
Definition: ntimage.h:437
#define IMAGE_FILE_MACHINE_AMD64
Definition: ntimage.h:17
#define IMAGE_SCN_MEM_READ
Definition: ntimage.h:240
#define IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE
Definition: ntimage.h:455
#define IMAGE_NT_OPTIONAL_HDR_MAGIC
Definition: ntimage.h:387
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define IMAGE_FILE_EXECUTABLE_IMAGE
Definition: pedump.c:160
#define IMAGE_FILE_MACHINE_I386
Definition: pedump.c:174
struct _IMAGE_OPTIONAL_HEADER IMAGE_OPTIONAL_HEADER
short WCHAR
Definition: pedump.c:58
#define IMAGE_NT_SIGNATURE
Definition: pedump.c:93
#define IMAGE_FILE_DLL
Definition: pedump.c:169
long LONG
Definition: pedump.c:60
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
char CHAR
Definition: pedump.c:57
#define INT
Definition: polytest.cpp:20
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define err(...)
static unsigned int file_size
Definition: regtests2xml.c:47
@ Internal
Definition: restypes.h:121
const WCHAR * str
strcat
Definition: string.h:92
strcpy
Definition: string.h:131
int winetest_get_mainargs(char ***pargv)
int const char int stream_size
Definition: zlib.h:814
static int fd
Definition: io.c:51
#define memset(x, y, z)
Definition: compat.h:39
const char * temp_dir
Definition: widl.c:134
static const char *static const char const char DWORD void DWORD *static const char const char DWORD void DWORD *static const char DWORD DWORD void * buff
Definition: shcore.c:41
PCWSTR s2
Definition: shell32_main.h:38
#define STATUS_CANNOT_DELETE
Definition: shellext.h:71
#define STATUS_END_OF_FILE
Definition: shellext.h:67
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:81
LPSECURITY_ATTRIBUTES lpSecurityAttributes
Definition: fileapi.h:31
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
WORD SizeOfOptionalHeader
Definition: ntddk_ex.h:127
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
IMAGE_FILE_HEADER FileHeader
Definition: ntddk_ex.h:183
WORD MinorOperatingSystemVersion
Definition: ntddk_ex.h:161
WORD MajorOperatingSystemVersion
Definition: ntddk_ex.h:160
union _IMAGE_SECTION_HEADER::@1695 Misc
DWORD PointerToRawData
Definition: pedump.c:290
BYTE Name[IMAGE_SIZEOF_SHORT_NAME]
Definition: pedump.c:281
WORD nErrCode
Definition: winbase.h:974
CHAR szPathName[OFS_MAXPATHNAME]
Definition: winbase.h:977
BYTE cBytes
Definition: winbase.h:972
Definition: minwinbase.h:234
DWORD OffsetHigh
Definition: minwinbase.h:226
DWORD Offset
Definition: minwinbase.h:225
HANDLE hEvent
Definition: minwinbase.h:230
ULONG_PTR Internal
Definition: minwinbase.h:219
ULONG_PTR InternalHigh
Definition: minwinbase.h:220
DWORD dwPageSize
Definition: winbase.h:898
$ULONG PrivilegeCount
Definition: setypes.h:1035
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:1036
Definition: cookie.c:202
Definition: fci.c:127
Definition: copy.c:22
Definition: mem.c:349
Definition: name.c:39
Definition: ps.c:97
Definition: parse.h:23
Definition: fci.c:110
Definition: file.c:76
const DWORD err
Definition: file.c:78
const char * file
Definition: file.c:77
const LONG err2
Definition: file.c:79
const DWORD options
Definition: file.c:80
const BOOL todo_flag
Definition: file.c:81
DWORD WINAPI SleepEx(IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:738
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:726
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexW(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:525
DWORD WINAPI WaitForSingleObjectEx(IN HANDLE hHandle, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:94
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:587
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:650
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:406
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:491
#define STATUS_PENDING
Definition: telnetd.h:14
Character const *const prefix
Definition: tempnam.cpp:195
uint16_t * PWSTR
Definition: typedefs.h:56
const char * LPCSTR
Definition: typedefs.h:52
const uint16_t * LPCWSTR
Definition: typedefs.h:57
void * PVOID
Definition: typedefs.h:50
PVOID HANDLE
Definition: typedefs.h:73
char * LPSTR
Definition: typedefs.h:51
int32_t INT
Definition: typedefs.h:58
uint64_t ULONGLONG
Definition: typedefs.h:67
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_NOT_A_DIRECTORY
Definition: udferr_usr.h:169
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
LONGLONG QuadPart
Definition: typedefs.h:114
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
int retval
Definition: wcstombs.cpp:91
LPVOID NTAPI VirtualAlloc(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flAllocationType, IN DWORD flProtect)
Definition: virtmem.c:65
BOOL NTAPI VirtualProtect(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD flNewProtect, OUT PDWORD lpflOldProtect)
Definition: virtmem.c:135
BOOL NTAPI VirtualFree(IN LPVOID lpAddress, IN SIZE_T dwSize, IN DWORD dwFreeType)
Definition: virtmem.c:119
#define success(from, fromstr, to, tostr)
#define COPY_FILE_FAIL_IF_EXISTS
Definition: winbase.h:233
#define STD_OUTPUT_HANDLE
Definition: winbase.h:293
#define FILE_END
Definition: winbase.h:117
#define COPY_FILE_RESTARTABLE
Definition: winbase.h:234
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FILE_MAP_WRITE
Definition: winbase.h:157
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1145
#define OF_EXIST
Definition: winbase.h:130
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:167
#define FILE_TYPE_UNKNOWN
Definition: winbase.h:283
#define WAIT_IO_COMPLETION
Definition: winbase.h:388
_In_ LPCSTR lpName
Definition: winbase.h:2519
#define FILE_CURRENT
Definition: winbase.h:116
#define HFILE_ERROR
Definition: winbase.h:114
#define OF_READWRITE
Definition: winbase.h:120
UINT WINAPI _lwrite(_In_ HFILE hFile, _In_reads_bytes_(uBytes) LPCCH lpBuffer, _In_ UINT uBytes)
#define FILE_TYPE_CHAR
Definition: winbase.h:285
#define FILE_TYPE_PIPE
Definition: winbase.h:286
#define COPY_FILE_ALLOW_DECRYPTED_DESTINATION
Definition: winbase.h:236
#define OFS_MAXPATHNAME
Definition: winbase.h:155
#define PROGRESS_CANCEL
Definition: winbase.h:150
#define CALLBACK_STREAM_SWITCH
Definition: winbase.h:154
#define OF_READ
Definition: winbase.h:119
#define OF_CREATE
Definition: winbase.h:128
#define OF_DELETE
Definition: winbase.h:129
#define OF_WRITE
Definition: winbase.h:121
#define FILE_TYPE_DISK
Definition: winbase.h:284
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
struct _FILE_RENAME_INFORMATION FILE_RENAME_INFORMATION
#define ERROR_BAD_NETPATH
Definition: winerror.h:267
static HRESULT HRESULT_FROM_WIN32(unsigned int x)
Definition: winerror.h:210
#define ERROR_IO_INCOMPLETE
Definition: winerror.h:900
#define ERROR_SHARING_VIOLATION
Definition: winerror.h:257
#define ERROR_BAD_LENGTH
Definition: winerror.h:249
#define ERROR_INVALID_USER_BUFFER
Definition: winerror.h:1448
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:228
#define ERROR_DIRECTORY
Definition: winerror.h:416
#define ERROR_NOT_ALL_ASSIGNED
Definition: winerror.h:1127
#define ERROR_BAD_PATHNAME
Definition: winerror.h:355
#define ERROR_HANDLE_EOF
Definition: winerror.h:262
#define ERROR_FILE_EXISTS
Definition: winerror.h:287
#define ERROR_NO_MORE_FILES
Definition: winerror.h:243
#define ERROR_FILE_INVALID
Definition: winerror.h:909
#define ERROR_FILENAME_EXCED_RANGE
Definition: winerror.h:385
#define ERROR_REQUEST_ABORTED
Definition: winerror.h:1067
#define ERROR_USER_MAPPED_FILE
Definition: winerror.h:1056
#define ERROR_NOACCESS
Definition: winerror.h:902
#define ERROR_INVALID_DATA
Definition: winerror.h:238
#define ERROR_PRIVILEGE_NOT_HELD
Definition: winerror.h:1141
#define SE_MANAGE_VOLUME_NAME
Definition: winnt_old.h:436
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:942
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
unsigned char BYTE
Definition: xxhash.c:193