2 * File handling functions
4 * Copyright 1993 John Burton
5 * Copyright 1996 Alexandre Julliard
8 * Fix the CopyFileEx methods to implement the "extented" functionality.
9 * Right now, they simply call the CopyFile method.
18 #include <sys/errno.h>
19 #include <sys/types.h>
30 #include "wine/winbase16.h"
31 #include "wine/winestring.h"
48 DEFAULT_DEBUG_CHANNEL(file
)
50 #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
51 #define MAP_ANON MAP_ANONYMOUS
54 /* Size of per-process table of DOS handles */
55 #define DOS_TABLE_SIZE 256
58 /***********************************************************************
61 * Convert OF_* mode into flags for CreateFile.
63 static void FILE_ConvertOFMode( INT mode
, DWORD
*access
, DWORD
*sharing
)
67 case OF_READ
: *access
= GENERIC_READ
; break;
68 case OF_WRITE
: *access
= GENERIC_WRITE
; break;
69 case OF_READWRITE
: *access
= GENERIC_READ
| GENERIC_WRITE
; break;
70 default: *access
= 0; break;
74 case OF_SHARE_EXCLUSIVE
: *sharing
= 0; break;
75 case OF_SHARE_DENY_WRITE
: *sharing
= FILE_SHARE_READ
; break;
76 case OF_SHARE_DENY_READ
: *sharing
= FILE_SHARE_WRITE
; break;
77 case OF_SHARE_DENY_NONE
:
79 default: *sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
; break;
85 /***********************************************************************
89 * oldmode[I] mode how file was first opened
90 * mode[I] mode how the file should get opened
95 * Look what we have to do with the given SHARE modes
97 * Ralph Brown's interrupt list gives following explication, I guess
98 * the same holds for Windows, DENY ALL should be OF_SHARE_COMPAT
100 * FIXME: Validate this function
101 ========from Ralph Brown's list =========
103 Values of DOS file sharing behavior:
104 | Second and subsequent Opens
105 First |Compat Deny Deny Deny Deny
106 Open | All Write Read None
107 |R W RW R W RW R W RW R W RW R W RW
108 - - - - -| - - - - - - - - - - - - - - - - -
109 Compat R |Y Y Y N N N 1 N N N N N 1 N N
110 W |Y Y Y N N N N N N N N N N N N
111 RW|Y Y Y N N N N N N N N N N N N
113 Deny R |C C C N N N N N N N N N N N N
114 All W |C C C N N N N N N N N N N N N
115 RW|C C C N N N N N N N N N N N N
117 Deny R |2 C C N N N Y N N N N N Y N N
118 Write W |C C C N N N N N N Y N N Y N N
119 RW|C C C N N N N N N N N N Y N N
121 Deny R |C C C N N N N Y N N N N N Y N
122 Read W |C C C N N N N N N N Y N N Y N
123 RW|C C C N N N N N N N N N N Y N
125 Deny R |2 C C N N N Y Y Y N N N Y Y Y
126 None W |C C C N N N N N N Y Y Y Y Y Y
127 RW|C C C N N N N N N N N N Y Y Y
128 Legend: Y = open succeeds, N = open fails with error code 05h
129 C = open fails, INT 24 generated
130 1 = open succeeds if file read-only, else fails with error code
131 2 = open succeeds if file read-only, else fails with INT 24
132 ========end of description from Ralph Brown's List =====
133 For every "Y" in the table we return FALSE
134 For every "N" we set the DOS_ERROR and return TRUE
135 For all other cases we barf,set the DOS_ERROR and return TRUE
138 static BOOL
FILE_ShareDeny( int mode
, int oldmode
)
140 int oldsharemode
= oldmode
& 0x70;
141 int sharemode
= mode
& 0x70;
142 int oldopenmode
= oldmode
& 3;
143 int openmode
= mode
& 3;
145 switch (oldsharemode
)
147 case OF_SHARE_COMPAT
:
148 if (sharemode
== OF_SHARE_COMPAT
) return FALSE
;
149 if (openmode
== OF_READ
) goto test_ro_err05
;
151 case OF_SHARE_EXCLUSIVE
:
152 if (sharemode
== OF_SHARE_COMPAT
) goto fail_int24
;
154 case OF_SHARE_DENY_WRITE
:
155 if (openmode
!= OF_READ
)
157 if (sharemode
== OF_SHARE_COMPAT
) goto fail_int24
;
162 case OF_SHARE_COMPAT
:
163 if (oldopenmode
== OF_READ
) goto test_ro_int24
;
165 case OF_SHARE_DENY_NONE
:
167 case OF_SHARE_DENY_WRITE
:
168 if (oldopenmode
== OF_READ
) return FALSE
;
169 case OF_SHARE_DENY_READ
:
170 if (oldopenmode
== OF_WRITE
) return FALSE
;
171 case OF_SHARE_EXCLUSIVE
:
176 case OF_SHARE_DENY_READ
:
177 if (openmode
!= OF_WRITE
)
179 if (sharemode
== OF_SHARE_COMPAT
) goto fail_int24
;
184 case OF_SHARE_COMPAT
:
186 case OF_SHARE_DENY_NONE
:
188 case OF_SHARE_DENY_WRITE
:
189 if (oldopenmode
== OF_READ
) return FALSE
;
190 case OF_SHARE_DENY_READ
:
191 if (oldopenmode
== OF_WRITE
) return FALSE
;
192 case OF_SHARE_EXCLUSIVE
:
197 case OF_SHARE_DENY_NONE
:
200 case OF_SHARE_COMPAT
:
202 case OF_SHARE_DENY_NONE
:
204 case OF_SHARE_DENY_WRITE
:
205 if (oldopenmode
== OF_READ
) return FALSE
;
206 case OF_SHARE_DENY_READ
:
207 if (oldopenmode
== OF_WRITE
) return FALSE
;
208 case OF_SHARE_EXCLUSIVE
:
213 ERR(file
,"unknown mode\n");
215 ERR(file
,"shouldn't happen\n");
216 ERR(file
,"Please report to bon@elektron.ikp.physik.tu-darmstadt.de\n");
220 if (oldmode
== OF_READ
)
224 FIXME(file
,"generate INT24 missing\n");
225 /* Is this the right error? */
226 SetLastError( ERROR_ACCESS_DENIED
);
230 if (oldmode
== OF_READ
)
234 TRACE(file
,"Access Denied, oldmode 0x%02x mode 0x%02x\n",oldmode
,mode
);
235 SetLastError( ERROR_ACCESS_DENIED
);
241 /***********************************************************************
244 * Set the DOS error code from errno.
246 void FILE_SetDosError(void)
248 int save_errno
= errno
; /* errno gets overwritten by printf */
250 TRACE(file
, "errno = %d %s\n", errno
, strerror(errno
));
254 SetLastError( ERROR_SHARING_VIOLATION
);
257 SetLastError( ERROR_INVALID_HANDLE
);
260 SetLastError( ERROR_HANDLE_DISK_FULL
);
265 SetLastError( ERROR_ACCESS_DENIED
);
268 SetLastError( ERROR_LOCK_VIOLATION
);
271 SetLastError( ERROR_FILE_NOT_FOUND
);
274 SetLastError( ERROR_CANNOT_MAKE
);
278 SetLastError( ERROR_NO_MORE_FILES
);
281 SetLastError( ERROR_FILE_EXISTS
);
285 SetLastError( ERROR_SEEK
);
288 SetLastError( ERROR_DIR_NOT_EMPTY
);
291 perror( "int21: unknown errno" );
292 SetLastError( ERROR_GEN_FAILURE
);
299 /***********************************************************************
302 * Duplicate a Unix handle into a task handle.
304 HFILE
FILE_DupUnixHandle( int fd
, DWORD access
)
307 struct create_file_request req
;
308 struct create_file_reply reply
;
310 if ((unix_handle
= dup(fd
)) == -1)
313 return INVALID_HANDLE_VALUE
;
317 req
.sharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
321 CLIENT_SendRequest( REQ_CREATE_FILE
, unix_handle
, 1,
323 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
328 /***********************************************************************
331 * Implementation of CreateFile. Takes a Unix path name.
333 HFILE
FILE_CreateFile( LPCSTR filename
, DWORD access
, DWORD sharing
,
334 LPSECURITY_ATTRIBUTES sa
, DWORD creation
,
335 DWORD attributes
, HANDLE
template )
337 struct create_file_request req
;
338 struct create_file_reply reply
;
341 req
.inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
342 req
.sharing
= sharing
;
343 req
.create
= creation
;
344 req
.attrs
= attributes
;
345 CLIENT_SendRequest( REQ_CREATE_FILE
, -1, 2,
347 filename
, strlen(filename
) + 1 );
349 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
351 /* If write access failed, retry without GENERIC_WRITE */
353 if ((reply
.handle
== -1) && !Options
.failReadOnly
&&
354 (access
& GENERIC_WRITE
))
356 DWORD lasterror
= GetLastError();
357 if ((lasterror
== ERROR_ACCESS_DENIED
) ||
358 (lasterror
== ERROR_WRITE_PROTECT
))
360 req
.access
&= ~GENERIC_WRITE
;
361 CLIENT_SendRequest( REQ_CREATE_FILE
, -1, 2,
363 filename
, strlen(filename
) + 1 );
365 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
372 /***********************************************************************
375 * Same as FILE_CreateFile but for a device
377 HFILE
FILE_CreateDevice( int client_id
, DWORD access
, LPSECURITY_ATTRIBUTES sa
)
379 struct create_device_request req
;
380 struct create_device_reply reply
;
383 req
.inherit
= (sa
&& (sa
->nLength
>=sizeof(*sa
)) && sa
->bInheritHandle
);
385 CLIENT_SendRequest( REQ_CREATE_DEVICE
, -1, 1, &req
, sizeof(req
) );
387 CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
);
392 /*************************************************************************
393 * CreateFile32A [KERNEL32.45] Creates or opens a file or other object
395 * Creates or opens an object, and returns a handle that can be used to
396 * access that object.
400 * filename [I] pointer to filename to be accessed
401 * access [I] access mode requested
402 * sharing [I] share mode
403 * sa [I] pointer to security attributes
404 * creation [I] how to create the file
405 * attributes [I] attributes for newly created file
406 * template [I] handle to file with extended attributes to copy
409 * Success: Open handle to specified file
410 * Failure: INVALID_HANDLE_VALUE
413 * Should call SetLastError() on failure.
417 * Doesn't support character devices, pipes, template files, or a
418 * lot of the 'attributes' flags yet.
420 HFILE WINAPI
CreateFileA( LPCSTR filename
, DWORD access
, DWORD sharing
,
421 LPSECURITY_ATTRIBUTES sa
, DWORD creation
,
422 DWORD attributes
, HANDLE
template )
424 DOS_FULL_NAME full_name
;
428 SetLastError( ERROR_INVALID_PARAMETER
);
431 TRACE(file
,"%s %s%s%s%s%s%s%s\n",filename
,
432 ((access
& GENERIC_READ
)==GENERIC_READ
)?"GENERIC_READ ":"",
433 ((access
& GENERIC_WRITE
)==GENERIC_WRITE
)?"GENERIC_WRITE ":"",
434 (!access
)?"QUERY_ACCESS ":"",
435 ((sharing
& FILE_SHARE_READ
)==FILE_SHARE_READ
)?"FILE_SHARE_READ ":"",
436 ((sharing
& FILE_SHARE_WRITE
)==FILE_SHARE_WRITE
)?"FILE_SHARE_WRITE ":"",
437 ((sharing
& FILE_SHARE_DELETE
)==FILE_SHARE_DELETE
)?"FILE_SHARE_DELETE ":"",
438 (creation
==CREATE_NEW
)?"CREATE_NEW":
439 (creation
==CREATE_ALWAYS
)?"CREATE_ALWAYS ":
440 (creation
==OPEN_EXISTING
)?"OPEN_EXISTING ":
441 (creation
==OPEN_ALWAYS
)?"OPEN_ALWAYS ":
442 (creation
==TRUNCATE_EXISTING
)?"TRUNCATE_EXISTING ":"");
444 /* If the name starts with '\\?\', ignore the first 4 chars. */
445 if (!strncmp(filename
, "\\\\?\\", 4))
448 if (!strncmp(filename
, "UNC\\", 4))
450 FIXME( file
, "UNC name (%s) not supported.\n", filename
);
451 SetLastError( ERROR_PATH_NOT_FOUND
);
456 if (!strncmp(filename
, "\\\\.\\", 4))
457 return DEVICE_Open( filename
+4, access
, sa
);
459 /* If the name still starts with '\\', it's a UNC name. */
460 if (!strncmp(filename
, "\\\\", 2))
462 FIXME( file
, "UNC name (%s) not supported.\n", filename
);
463 SetLastError( ERROR_PATH_NOT_FOUND
);
467 /* Open a console for CONIN$ or CONOUT$ */
468 if (!lstrcmpiA(filename
, "CONIN$")) return CONSOLE_OpenHandle( FALSE
, access
, sa
);
469 if (!lstrcmpiA(filename
, "CONOUT$")) return CONSOLE_OpenHandle( TRUE
, access
, sa
);
471 if (DOSFS_GetDevice( filename
))
475 TRACE(file
, "opening device '%s'\n", filename
);
477 if (HFILE_ERROR
!=(ret
=DOSFS_OpenDevice( filename
, access
)))
480 /* Do not silence this please. It is a critical error. -MM */
481 ERR(file
, "Couldn't open device '%s'!\n",filename
);
482 SetLastError( ERROR_FILE_NOT_FOUND
);
486 /* check for filename, don't check for last entry if creating */
487 if (!DOSFS_GetFullName( filename
,
488 (creation
== OPEN_EXISTING
) || (creation
== TRUNCATE_EXISTING
), &full_name
))
491 return FILE_CreateFile( full_name
.long_name
, access
, sharing
,
492 sa
, creation
, attributes
, template );
497 /*************************************************************************
498 * CreateFile32W (KERNEL32.48)
500 HFILE WINAPI
CreateFileW( LPCWSTR filename
, DWORD access
, DWORD sharing
,
501 LPSECURITY_ATTRIBUTES sa
, DWORD creation
,
502 DWORD attributes
, HANDLE
template)
504 LPSTR afn
= HEAP_strdupWtoA( GetProcessHeap(), 0, filename
);
505 HFILE res
= CreateFileA( afn
, access
, sharing
, sa
, creation
, attributes
, template );
506 HeapFree( GetProcessHeap(), 0, afn
);
511 /***********************************************************************
514 * Fill a file information from a struct stat.
516 static void FILE_FillInfo( struct stat
*st
, BY_HANDLE_FILE_INFORMATION
*info
)
518 if (S_ISDIR(st
->st_mode
))
519 info
->dwFileAttributes
= FILE_ATTRIBUTE_DIRECTORY
;
521 info
->dwFileAttributes
= FILE_ATTRIBUTE_ARCHIVE
;
522 if (!(st
->st_mode
& S_IWUSR
))
523 info
->dwFileAttributes
|= FILE_ATTRIBUTE_READONLY
;
525 DOSFS_UnixTimeToFileTime( st
->st_mtime
, &info
->ftCreationTime
, 0 );
526 DOSFS_UnixTimeToFileTime( st
->st_mtime
, &info
->ftLastWriteTime
, 0 );
527 DOSFS_UnixTimeToFileTime( st
->st_atime
, &info
->ftLastAccessTime
, 0 );
529 info
->dwVolumeSerialNumber
= 0; /* FIXME */
530 info
->nFileSizeHigh
= 0;
531 info
->nFileSizeLow
= S_ISDIR(st
->st_mode
) ? 0 : st
->st_size
;
532 info
->nNumberOfLinks
= st
->st_nlink
;
533 info
->nFileIndexHigh
= 0;
534 info
->nFileIndexLow
= st
->st_ino
;
538 /***********************************************************************
541 * Stat a Unix path name. Return TRUE if OK.
543 BOOL
FILE_Stat( LPCSTR unixName
, BY_HANDLE_FILE_INFORMATION
*info
)
547 if (!unixName
|| !info
) return FALSE
;
549 if (stat( unixName
, &st
) == -1)
554 FILE_FillInfo( &st
, info
);
559 /***********************************************************************
560 * GetFileInformationByHandle (KERNEL32.219)
562 DWORD WINAPI
GetFileInformationByHandle( HFILE hFile
,
563 BY_HANDLE_FILE_INFORMATION
*info
)
565 struct get_file_info_request req
;
566 struct get_file_info_reply reply
;
570 CLIENT_SendRequest( REQ_GET_FILE_INFO
, -1, 1, &req
, sizeof(req
) );
571 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
))
573 DOSFS_UnixTimeToFileTime( reply
.write_time
, &info
->ftCreationTime
, 0 );
574 DOSFS_UnixTimeToFileTime( reply
.write_time
, &info
->ftLastWriteTime
, 0 );
575 DOSFS_UnixTimeToFileTime( reply
.access_time
, &info
->ftLastAccessTime
, 0 );
576 info
->dwFileAttributes
= reply
.attr
;
577 info
->dwVolumeSerialNumber
= reply
.serial
;
578 info
->nFileSizeHigh
= reply
.size_high
;
579 info
->nFileSizeLow
= reply
.size_low
;
580 info
->nNumberOfLinks
= reply
.links
;
581 info
->nFileIndexHigh
= reply
.index_high
;
582 info
->nFileIndexLow
= reply
.index_low
;
587 /**************************************************************************
588 * GetFileAttributes16 (KERNEL.420)
590 DWORD WINAPI
GetFileAttributes16( LPCSTR name
)
592 return GetFileAttributesA( name
);
596 /**************************************************************************
597 * GetFileAttributes32A (KERNEL32.217)
599 DWORD WINAPI
GetFileAttributesA( LPCSTR name
)
601 DOS_FULL_NAME full_name
;
602 BY_HANDLE_FILE_INFORMATION info
;
604 if (name
== NULL
|| *name
=='\0') return -1;
606 if (!DOSFS_GetFullName( name
, TRUE
, &full_name
)) return -1;
607 if (!FILE_Stat( full_name
.long_name
, &info
)) return -1;
608 return info
.dwFileAttributes
;
612 /**************************************************************************
613 * GetFileAttributes32W (KERNEL32.218)
615 DWORD WINAPI
GetFileAttributesW( LPCWSTR name
)
617 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, name
);
618 DWORD res
= GetFileAttributesA( nameA
);
619 HeapFree( GetProcessHeap(), 0, nameA
);
624 /***********************************************************************
625 * GetFileSize (KERNEL32.220)
627 DWORD WINAPI
GetFileSize( HFILE hFile
, LPDWORD filesizehigh
)
629 BY_HANDLE_FILE_INFORMATION info
;
630 if (!GetFileInformationByHandle( hFile
, &info
)) return 0;
631 if (filesizehigh
) *filesizehigh
= info
.nFileSizeHigh
;
632 return info
.nFileSizeLow
;
636 /***********************************************************************
637 * GetFileTime (KERNEL32.221)
639 BOOL WINAPI
GetFileTime( HFILE hFile
, FILETIME
*lpCreationTime
,
640 FILETIME
*lpLastAccessTime
,
641 FILETIME
*lpLastWriteTime
)
643 BY_HANDLE_FILE_INFORMATION info
;
644 if (!GetFileInformationByHandle( hFile
, &info
)) return FALSE
;
645 if (lpCreationTime
) *lpCreationTime
= info
.ftCreationTime
;
646 if (lpLastAccessTime
) *lpLastAccessTime
= info
.ftLastAccessTime
;
647 if (lpLastWriteTime
) *lpLastWriteTime
= info
.ftLastWriteTime
;
651 /***********************************************************************
652 * CompareFileTime (KERNEL32.28)
654 INT WINAPI
CompareFileTime( LPFILETIME x
, LPFILETIME y
)
656 if (!x
|| !y
) return -1;
658 if (x
->dwHighDateTime
> y
->dwHighDateTime
)
660 if (x
->dwHighDateTime
< y
->dwHighDateTime
)
662 if (x
->dwLowDateTime
> y
->dwLowDateTime
)
664 if (x
->dwLowDateTime
< y
->dwLowDateTime
)
670 /***********************************************************************
671 * GetTempFileName16 (KERNEL.97)
673 UINT16 WINAPI
GetTempFileName16( BYTE drive
, LPCSTR prefix
, UINT16 unique
,
678 if (!(drive
& ~TF_FORCEDRIVE
)) /* drive 0 means current default drive */
679 drive
|= DRIVE_GetCurrentDrive() + 'A';
681 if ((drive
& TF_FORCEDRIVE
) &&
682 !DRIVE_IsValid( toupper(drive
& ~TF_FORCEDRIVE
) - 'A' ))
684 drive
&= ~TF_FORCEDRIVE
;
685 WARN(file
, "invalid drive %d specified\n", drive
);
688 if (drive
& TF_FORCEDRIVE
)
689 sprintf(temppath
,"%c:", drive
& ~TF_FORCEDRIVE
);
691 GetTempPathA( 132, temppath
);
692 return (UINT16
)GetTempFileNameA( temppath
, prefix
, unique
, buffer
);
696 /***********************************************************************
697 * GetTempFileName32A (KERNEL32.290)
699 UINT WINAPI
GetTempFileNameA( LPCSTR path
, LPCSTR prefix
, UINT unique
,
702 static UINT unique_temp
;
703 DOS_FULL_NAME full_name
;
708 if ( !path
|| !prefix
|| !buffer
) return 0;
710 if (!unique_temp
) unique_temp
= time(NULL
) & 0xffff;
711 num
= unique
? (unique
& 0xffff) : (unique_temp
++ & 0xffff);
713 strcpy( buffer
, path
);
714 p
= buffer
+ strlen(buffer
);
716 /* add a \, if there isn't one and path is more than just the drive letter ... */
717 if ( !((strlen(buffer
) == 2) && (buffer
[1] == ':'))
718 && ((p
== buffer
) || (p
[-1] != '\\'))) *p
++ = '\\';
721 for (i
= 3; (i
> 0) && (*prefix
); i
--) *p
++ = *prefix
++;
722 sprintf( p
, "%04x.tmp", num
);
724 /* Now try to create it */
730 HFILE handle
= CreateFileA( buffer
, GENERIC_WRITE
, 0, NULL
,
731 CREATE_NEW
, FILE_ATTRIBUTE_NORMAL
, -1 );
732 if (handle
!= INVALID_HANDLE_VALUE
)
733 { /* We created it */
734 TRACE(file
, "created %s\n",
736 CloseHandle( handle
);
739 if (GetLastError() != ERROR_FILE_EXISTS
)
740 break; /* No need to go on */
742 sprintf( p
, "%04x.tmp", num
);
743 } while (num
!= (unique
& 0xffff));
746 /* Get the full path name */
748 if (DOSFS_GetFullName( buffer
, FALSE
, &full_name
))
750 /* Check if we have write access in the directory */
751 if ((p
= strrchr( full_name
.long_name
, '/' ))) *p
= '\0';
752 if (access( full_name
.long_name
, W_OK
) == -1)
753 WARN(file
, "returns '%s', which doesn't seem to be writeable.\n",
756 TRACE(file
, "returning %s\n", buffer
);
757 return unique
? unique
: num
;
761 /***********************************************************************
762 * GetTempFileName32W (KERNEL32.291)
764 UINT WINAPI
GetTempFileNameW( LPCWSTR path
, LPCWSTR prefix
, UINT unique
,
772 patha
= HEAP_strdupWtoA( GetProcessHeap(), 0, path
);
773 prefixa
= HEAP_strdupWtoA( GetProcessHeap(), 0, prefix
);
774 ret
= GetTempFileNameA( patha
, prefixa
, unique
, buffera
);
775 lstrcpyAtoW( buffer
, buffera
);
776 HeapFree( GetProcessHeap(), 0, patha
);
777 HeapFree( GetProcessHeap(), 0, prefixa
);
782 /***********************************************************************
785 * Implementation of OpenFile16() and OpenFile32().
787 static HFILE
FILE_DoOpenFile( LPCSTR name
, OFSTRUCT
*ofs
, UINT mode
,
792 WORD filedatetime
[2];
793 DOS_FULL_NAME full_name
;
794 DWORD access
, sharing
;
797 if (!ofs
) return HFILE_ERROR
;
799 TRACE(file
,"%s %s %s %s%s%s%s%s%s%s%s%s\n",name
,
800 ((mode
& 0x3 )==OF_READ
)?"OF_READ":
801 ((mode
& 0x3 )==OF_WRITE
)?"OF_WRITE":
802 ((mode
& 0x3 )==OF_READWRITE
)?"OF_READWRITE":"unknown",
803 ((mode
& 0x70 )==OF_SHARE_COMPAT
)?"OF_SHARE_COMPAT":
804 ((mode
& 0x70 )==OF_SHARE_DENY_NONE
)?"OF_SHARE_DENY_NONE":
805 ((mode
& 0x70 )==OF_SHARE_DENY_READ
)?"OF_SHARE_DENY_READ":
806 ((mode
& 0x70 )==OF_SHARE_DENY_WRITE
)?"OF_SHARE_DENY_WRITE":
807 ((mode
& 0x70 )==OF_SHARE_EXCLUSIVE
)?"OF_SHARE_EXCLUSIVE":"unknown",
808 ((mode
& OF_PARSE
)==OF_PARSE
)?"OF_PARSE ":"",
809 ((mode
& OF_DELETE
)==OF_DELETE
)?"OF_DELETE ":"",
810 ((mode
& OF_VERIFY
)==OF_VERIFY
)?"OF_VERIFY ":"",
811 ((mode
& OF_SEARCH
)==OF_SEARCH
)?"OF_SEARCH ":"",
812 ((mode
& OF_CANCEL
)==OF_CANCEL
)?"OF_CANCEL ":"",
813 ((mode
& OF_CREATE
)==OF_CREATE
)?"OF_CREATE ":"",
814 ((mode
& OF_PROMPT
)==OF_PROMPT
)?"OF_PROMPT ":"",
815 ((mode
& OF_EXIST
)==OF_EXIST
)?"OF_EXIST ":"",
816 ((mode
& OF_REOPEN
)==OF_REOPEN
)?"OF_REOPEN ":""
820 ofs
->cBytes
= sizeof(OFSTRUCT
);
822 if (mode
& OF_REOPEN
) name
= ofs
->szPathName
;
825 ERR(file
, "called with `name' set to NULL ! Please debug.\n");
829 TRACE(file
, "%s %04x\n", name
, mode
);
831 /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
832 Are there any cases where getting the path here is wrong?
833 Uwe Bonnes 1997 Apr 2 */
834 if (!GetFullPathNameA( name
, sizeof(ofs
->szPathName
),
835 ofs
->szPathName
, NULL
)) goto error
;
836 FILE_ConvertOFMode( mode
, &access
, &sharing
);
838 /* OF_PARSE simply fills the structure */
842 ofs
->fFixedDisk
= (GetDriveType16( ofs
->szPathName
[0]-'A' )
844 TRACE(file
, "(%s): OF_PARSE, res = '%s'\n",
845 name
, ofs
->szPathName
);
849 /* OF_CREATE is completely different from all other options, so
852 if (mode
& OF_CREATE
)
854 if ((hFileRet
= CreateFileA( name
, GENERIC_READ
| GENERIC_WRITE
,
855 sharing
, NULL
, CREATE_ALWAYS
,
856 FILE_ATTRIBUTE_NORMAL
, -1 ))== INVALID_HANDLE_VALUE
)
861 /* If OF_SEARCH is set, ignore the given path */
863 if ((mode
& OF_SEARCH
) && !(mode
& OF_REOPEN
))
865 /* First try the file name as is */
866 if (DOSFS_GetFullName( name
, TRUE
, &full_name
)) goto found
;
867 /* Now remove the path */
868 if (name
[0] && (name
[1] == ':')) name
+= 2;
869 if ((p
= strrchr( name
, '\\' ))) name
= p
+ 1;
870 if ((p
= strrchr( name
, '/' ))) name
= p
+ 1;
871 if (!name
[0]) goto not_found
;
874 /* Now look for the file */
876 if (!DIR_SearchPath( NULL
, name
, NULL
, &full_name
, win32
)) goto not_found
;
879 TRACE(file
, "found %s = %s\n",
880 full_name
.long_name
, full_name
.short_name
);
881 lstrcpynA( ofs
->szPathName
, full_name
.short_name
,
882 sizeof(ofs
->szPathName
) );
884 if (mode
& OF_SHARE_EXCLUSIVE
)
885 /* Some InstallShield version uses OF_SHARE_EXCLUSIVE
886 on the file <tempdir>/_ins0432._mp to determine how
887 far installation has proceeded.
888 _ins0432._mp is an executable and while running the
889 application expects the open with OF_SHARE_ to fail*/
891 As our loader closes the files after loading the executable,
892 we can't find the running executable with FILE_InUse.
893 Perhaps the loader should keep the file open.
894 Recheck against how Win handles that case */
896 char *last
= strrchr(full_name
.long_name
,'/');
898 last
= full_name
.long_name
- 1;
899 if (GetModuleHandle16(last
+1))
901 TRACE(file
,"Denying shared open for %s\n",full_name
.long_name
);
906 if (mode
& OF_DELETE
)
908 if (unlink( full_name
.long_name
) == -1) goto not_found
;
909 TRACE(file
, "(%s): OF_DELETE return = OK\n", name
);
913 hFileRet
= FILE_CreateFile( full_name
.long_name
, access
, sharing
,
914 NULL
, OPEN_EXISTING
, 0, -1 );
915 if (hFileRet
== HFILE_ERROR
) goto not_found
;
917 GetFileTime( hFileRet
, NULL
, NULL
, &filetime
);
918 FileTimeToDosDateTime( &filetime
, &filedatetime
[0], &filedatetime
[1] );
919 if ((mode
& OF_VERIFY
) && (mode
& OF_REOPEN
))
921 if (memcmp( ofs
->reserved
, filedatetime
, sizeof(ofs
->reserved
) ))
923 CloseHandle( hFileRet
);
924 WARN(file
, "(%s): OF_VERIFY failed\n", name
);
925 /* FIXME: what error here? */
926 SetLastError( ERROR_FILE_NOT_FOUND
);
930 memcpy( ofs
->reserved
, filedatetime
, sizeof(ofs
->reserved
) );
932 success
: /* We get here if the open was successful */
933 TRACE(file
, "(%s): OK, return = %d\n", name
, hFileRet
);
936 if (mode
& OF_EXIST
) /* Return the handle, but close it first */
937 CloseHandle( hFileRet
);
941 hFileRet
= FILE_AllocDosHandle( hFileRet
);
942 if (hFileRet
== HFILE_ERROR16
) goto error
;
943 if (mode
& OF_EXIST
) /* Return the handle, but close it first */
944 _lclose16( hFileRet
);
948 not_found
: /* We get here if the file does not exist */
949 WARN(file
, "'%s' not found\n", name
);
950 SetLastError( ERROR_FILE_NOT_FOUND
);
953 error
: /* We get here if there was an error opening the file */
954 ofs
->nErrCode
= GetLastError();
955 WARN(file
, "(%s): return = HFILE_ERROR error= %d\n",
956 name
,ofs
->nErrCode
);
961 /***********************************************************************
962 * OpenFile16 (KERNEL.74)
964 HFILE16 WINAPI
OpenFile16( LPCSTR name
, OFSTRUCT
*ofs
, UINT16 mode
)
966 return FILE_DoOpenFile( name
, ofs
, mode
, FALSE
);
970 /***********************************************************************
971 * OpenFile32 (KERNEL32.396)
973 HFILE WINAPI
OpenFile( LPCSTR name
, OFSTRUCT
*ofs
, UINT mode
)
975 return FILE_DoOpenFile( name
, ofs
, mode
, TRUE
);
979 /***********************************************************************
980 * FILE_InitProcessDosHandles
982 * Allocates the default DOS handles for a process. Called either by
983 * AllocDosHandle below or by the DOSVM stuff.
985 BOOL
FILE_InitProcessDosHandles( void ) {
988 if (!(ptr
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
,
989 sizeof(*ptr
) * DOS_TABLE_SIZE
)))
991 PROCESS_Current()->dos_handles
= ptr
;
992 ptr
[0] = GetStdHandle(STD_INPUT_HANDLE
);
993 ptr
[1] = GetStdHandle(STD_OUTPUT_HANDLE
);
994 ptr
[2] = GetStdHandle(STD_ERROR_HANDLE
);
995 ptr
[3] = GetStdHandle(STD_ERROR_HANDLE
);
996 ptr
[4] = GetStdHandle(STD_ERROR_HANDLE
);
1000 /***********************************************************************
1001 * FILE_AllocDosHandle
1003 * Allocate a DOS handle for a Win32 handle. The Win32 handle is no
1004 * longer valid after this function (even on failure).
1006 HFILE16
FILE_AllocDosHandle( HANDLE handle
)
1009 HANDLE
*ptr
= PROCESS_Current()->dos_handles
;
1011 if (!handle
|| (handle
== INVALID_HANDLE_VALUE
))
1012 return INVALID_HANDLE_VALUE16
;
1015 if (!FILE_InitProcessDosHandles())
1017 ptr
= PROCESS_Current()->dos_handles
;
1020 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++, ptr
++)
1024 TRACE( file
, "Got %d for h32 %d\n", i
, handle
);
1028 CloseHandle( handle
);
1029 SetLastError( ERROR_TOO_MANY_OPEN_FILES
);
1030 return INVALID_HANDLE_VALUE16
;
1034 /***********************************************************************
1037 * Return the Win32 handle for a DOS handle.
1039 HANDLE
FILE_GetHandle( HFILE16 hfile
)
1041 HANDLE
*table
= PROCESS_Current()->dos_handles
;
1042 if ((hfile
>= DOS_TABLE_SIZE
) || !table
|| !table
[hfile
])
1044 SetLastError( ERROR_INVALID_HANDLE
);
1045 return INVALID_HANDLE_VALUE
;
1047 return table
[hfile
];
1051 /***********************************************************************
1054 * dup2() function for DOS handles.
1056 HFILE16
FILE_Dup2( HFILE16 hFile1
, HFILE16 hFile2
)
1058 HANDLE
*table
= PROCESS_Current()->dos_handles
;
1061 if ((hFile1
>= DOS_TABLE_SIZE
) || (hFile2
>= DOS_TABLE_SIZE
) ||
1062 !table
|| !table
[hFile1
])
1064 SetLastError( ERROR_INVALID_HANDLE
);
1065 return HFILE_ERROR16
;
1069 FIXME( file
, "stdio handle closed, need proper conversion\n" );
1070 SetLastError( ERROR_INVALID_HANDLE
);
1071 return HFILE_ERROR16
;
1073 if (!DuplicateHandle( GetCurrentProcess(), table
[hFile1
],
1074 GetCurrentProcess(), &new_handle
,
1075 0, FALSE
, DUPLICATE_SAME_ACCESS
))
1076 return HFILE_ERROR16
;
1077 if (table
[hFile2
]) CloseHandle( table
[hFile2
] );
1078 table
[hFile2
] = new_handle
;
1083 /***********************************************************************
1084 * _lclose16 (KERNEL.81)
1086 HFILE16 WINAPI
_lclose16( HFILE16 hFile
)
1088 HANDLE
*table
= PROCESS_Current()->dos_handles
;
1092 FIXME( file
, "stdio handle closed, need proper conversion\n" );
1093 SetLastError( ERROR_INVALID_HANDLE
);
1094 return HFILE_ERROR16
;
1096 if ((hFile
>= DOS_TABLE_SIZE
) || !table
|| !table
[hFile
])
1098 SetLastError( ERROR_INVALID_HANDLE
);
1099 return HFILE_ERROR16
;
1101 TRACE( file
, "%d (handle32=%d)\n", hFile
, table
[hFile
] );
1102 CloseHandle( table
[hFile
] );
1108 /***********************************************************************
1109 * _lclose32 (KERNEL32.592)
1111 HFILE WINAPI
_lclose( HFILE hFile
)
1113 TRACE(file
, "handle %d\n", hFile
);
1114 return CloseHandle( hFile
) ? 0 : HFILE_ERROR
;
1118 /***********************************************************************
1119 * ReadFile (KERNEL32.428)
1121 BOOL WINAPI
ReadFile( HANDLE hFile
, LPVOID buffer
, DWORD bytesToRead
,
1122 LPDWORD bytesRead
, LPOVERLAPPED overlapped
)
1124 struct get_read_fd_request req
;
1125 int unix_handle
, result
;
1127 TRACE(file
, "%d %p %ld\n", hFile
, buffer
, bytesToRead
);
1129 if (bytesRead
) *bytesRead
= 0; /* Do this before anything else */
1130 if (!bytesToRead
) return TRUE
;
1133 CLIENT_SendRequest( REQ_GET_READ_FD
, -1, 1, &req
, sizeof(req
) );
1134 CLIENT_WaitReply( NULL
, &unix_handle
, 0 );
1135 if (unix_handle
== -1) return FALSE
;
1136 while ((result
= read( unix_handle
, buffer
, bytesToRead
)) == -1)
1138 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
1139 if ((errno
== EFAULT
) && VIRTUAL_HandleFault( buffer
)) continue;
1143 close( unix_handle
);
1144 if (result
== -1) return FALSE
;
1145 if (bytesRead
) *bytesRead
= result
;
1150 /***********************************************************************
1151 * WriteFile (KERNEL32.578)
1153 BOOL WINAPI
WriteFile( HANDLE hFile
, LPCVOID buffer
, DWORD bytesToWrite
,
1154 LPDWORD bytesWritten
, LPOVERLAPPED overlapped
)
1156 struct get_write_fd_request req
;
1157 int unix_handle
, result
;
1159 TRACE(file
, "%d %p %ld\n", hFile
, buffer
, bytesToWrite
);
1161 if (bytesWritten
) *bytesWritten
= 0; /* Do this before anything else */
1162 if (!bytesToWrite
) return TRUE
;
1165 CLIENT_SendRequest( REQ_GET_WRITE_FD
, -1, 1, &req
, sizeof(req
) );
1166 CLIENT_WaitReply( NULL
, &unix_handle
, 0 );
1167 if (unix_handle
== -1) return FALSE
;
1168 while ((result
= write( unix_handle
, buffer
, bytesToWrite
)) == -1)
1170 if ((errno
== EAGAIN
) || (errno
== EINTR
)) continue;
1171 if ((errno
== EFAULT
) && VIRTUAL_HandleFault( buffer
)) continue;
1175 close( unix_handle
);
1176 if (result
== -1) return FALSE
;
1177 if (bytesWritten
) *bytesWritten
= result
;
1182 /***********************************************************************
1185 LONG WINAPI
WIN16_hread( HFILE16 hFile
, SEGPTR buffer
, LONG count
)
1189 TRACE(file
, "%d %08lx %ld\n",
1190 hFile
, (DWORD
)buffer
, count
);
1192 /* Some programs pass a count larger than the allocated buffer */
1193 maxlen
= GetSelectorLimit16( SELECTOROF(buffer
) ) - OFFSETOF(buffer
) + 1;
1194 if (count
> maxlen
) count
= maxlen
;
1195 return _lread(FILE_GetHandle(hFile
), PTR_SEG_TO_LIN(buffer
), count
);
1199 /***********************************************************************
1202 UINT16 WINAPI
WIN16_lread( HFILE16 hFile
, SEGPTR buffer
, UINT16 count
)
1204 return (UINT16
)WIN16_hread( hFile
, buffer
, (LONG
)count
);
1208 /***********************************************************************
1209 * _lread32 (KERNEL32.596)
1211 UINT WINAPI
_lread( HFILE handle
, LPVOID buffer
, UINT count
)
1214 if (!ReadFile( handle
, buffer
, count
, &result
, NULL
)) return -1;
1219 /***********************************************************************
1220 * _lread16 (KERNEL.82)
1222 UINT16 WINAPI
_lread16( HFILE16 hFile
, LPVOID buffer
, UINT16 count
)
1224 return (UINT16
)_lread(FILE_GetHandle(hFile
), buffer
, (LONG
)count
);
1228 /***********************************************************************
1229 * _lcreat16 (KERNEL.83)
1231 HFILE16 WINAPI
_lcreat16( LPCSTR path
, INT16 attr
)
1233 return FILE_AllocDosHandle( _lcreat( path
, attr
) );
1237 /***********************************************************************
1238 * _lcreat (KERNEL32.593)
1240 HFILE WINAPI
_lcreat( LPCSTR path
, INT attr
)
1242 /* Mask off all flags not explicitly allowed by the doc */
1243 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
1244 TRACE(file
, "%s %02x\n", path
, attr
);
1245 return CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
1246 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1247 CREATE_ALWAYS
, attr
, -1 );
1251 /***********************************************************************
1252 * SetFilePointer (KERNEL32.492)
1254 DWORD WINAPI
SetFilePointer( HFILE hFile
, LONG distance
, LONG
*highword
,
1257 struct set_file_pointer_request req
;
1258 struct set_file_pointer_reply reply
;
1260 if (highword
&& *highword
)
1262 FIXME(file
, "64-bit offsets not supported yet\n");
1263 SetLastError( ERROR_INVALID_PARAMETER
);
1266 TRACE(file
, "handle %d offset %ld origin %ld\n",
1267 hFile
, distance
, method
);
1271 req
.high
= highword
? *highword
: 0;
1272 /* FIXME: assumes 1:1 mapping between Windows and Unix seek constants */
1273 req
.whence
= method
;
1274 CLIENT_SendRequest( REQ_SET_FILE_POINTER
, -1, 1, &req
, sizeof(req
) );
1275 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
)) return 0xffffffff;
1277 if (highword
) *highword
= reply
.high
;
1282 /***********************************************************************
1283 * _llseek16 (KERNEL.84)
1286 * Seeking before the start of the file should be allowed for _llseek16,
1287 * but cause subsequent I/O operations to fail (cf. interrupt list)
1290 LONG WINAPI
_llseek16( HFILE16 hFile
, LONG lOffset
, INT16 nOrigin
)
1292 return SetFilePointer( FILE_GetHandle(hFile
), lOffset
, NULL
, nOrigin
);
1296 /***********************************************************************
1297 * _llseek32 (KERNEL32.594)
1299 LONG WINAPI
_llseek( HFILE hFile
, LONG lOffset
, INT nOrigin
)
1301 return SetFilePointer( hFile
, lOffset
, NULL
, nOrigin
);
1305 /***********************************************************************
1306 * _lopen16 (KERNEL.85)
1308 HFILE16 WINAPI
_lopen16( LPCSTR path
, INT16 mode
)
1310 return FILE_AllocDosHandle( _lopen( path
, mode
) );
1314 /***********************************************************************
1315 * _lopen32 (KERNEL32.595)
1317 HFILE WINAPI
_lopen( LPCSTR path
, INT mode
)
1319 DWORD access
, sharing
;
1321 TRACE(file
, "('%s',%04x)\n", path
, mode
);
1322 FILE_ConvertOFMode( mode
, &access
, &sharing
);
1323 return CreateFileA( path
, access
, sharing
, NULL
, OPEN_EXISTING
, 0, -1 );
1327 /***********************************************************************
1328 * _lwrite16 (KERNEL.86)
1330 UINT16 WINAPI
_lwrite16( HFILE16 hFile
, LPCSTR buffer
, UINT16 count
)
1332 return (UINT16
)_hwrite( FILE_GetHandle(hFile
), buffer
, (LONG
)count
);
1335 /***********************************************************************
1336 * _lwrite32 (KERNEL32.761)
1338 UINT WINAPI
_lwrite( HFILE hFile
, LPCSTR buffer
, UINT count
)
1340 return (UINT
)_hwrite( hFile
, buffer
, (LONG
)count
);
1344 /***********************************************************************
1345 * _hread16 (KERNEL.349)
1347 LONG WINAPI
_hread16( HFILE16 hFile
, LPVOID buffer
, LONG count
)
1349 return _lread( FILE_GetHandle(hFile
), buffer
, count
);
1353 /***********************************************************************
1354 * _hread32 (KERNEL32.590)
1356 LONG WINAPI
_hread( HFILE hFile
, LPVOID buffer
, LONG count
)
1358 return _lread( hFile
, buffer
, count
);
1362 /***********************************************************************
1363 * _hwrite16 (KERNEL.350)
1365 LONG WINAPI
_hwrite16( HFILE16 hFile
, LPCSTR buffer
, LONG count
)
1367 return _hwrite( FILE_GetHandle(hFile
), buffer
, count
);
1371 /***********************************************************************
1372 * _hwrite32 (KERNEL32.591)
1374 * experimentation yields that _lwrite:
1375 * o truncates the file at the current position with
1377 * o returns 0 on a 0 length write
1378 * o works with console handles
1381 LONG WINAPI
_hwrite( HFILE handle
, LPCSTR buffer
, LONG count
)
1385 TRACE(file
, "%d %p %ld\n", handle
, buffer
, count
);
1389 /* Expand or truncate at current position */
1390 if (!SetEndOfFile( handle
)) return HFILE_ERROR
;
1393 if (!WriteFile( handle
, buffer
, count
, &result
, NULL
))
1399 /***********************************************************************
1400 * SetHandleCount16 (KERNEL.199)
1402 UINT16 WINAPI
SetHandleCount16( UINT16 count
)
1404 HGLOBAL16 hPDB
= GetCurrentPDB16();
1405 PDB16
*pdb
= (PDB16
*)GlobalLock16( hPDB
);
1406 BYTE
*files
= PTR_SEG_TO_LIN( pdb
->fileHandlesPtr
);
1408 TRACE(file
, "(%d)\n", count
);
1410 if (count
< 20) count
= 20; /* No point in going below 20 */
1411 else if (count
> 254) count
= 254;
1415 if (pdb
->nbFiles
> 20)
1417 memcpy( pdb
->fileHandles
, files
, 20 );
1418 GlobalFree16( pdb
->hFileHandles
);
1419 pdb
->fileHandlesPtr
= (SEGPTR
)MAKELONG( 0x18,
1420 GlobalHandleToSel16( hPDB
) );
1421 pdb
->hFileHandles
= 0;
1425 else /* More than 20, need a new file handles table */
1428 HGLOBAL16 newhandle
= GlobalAlloc16( GMEM_MOVEABLE
, count
);
1431 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
1432 return pdb
->nbFiles
;
1434 newfiles
= (BYTE
*)GlobalLock16( newhandle
);
1436 if (count
> pdb
->nbFiles
)
1438 memcpy( newfiles
, files
, pdb
->nbFiles
);
1439 memset( newfiles
+ pdb
->nbFiles
, 0xff, count
- pdb
->nbFiles
);
1441 else memcpy( newfiles
, files
, count
);
1442 if (pdb
->nbFiles
> 20) GlobalFree16( pdb
->hFileHandles
);
1443 pdb
->fileHandlesPtr
= WIN16_GlobalLock16( newhandle
);
1444 pdb
->hFileHandles
= newhandle
;
1445 pdb
->nbFiles
= count
;
1447 return pdb
->nbFiles
;
1451 /*************************************************************************
1452 * SetHandleCount32 (KERNEL32.494)
1454 UINT WINAPI
SetHandleCount( UINT count
)
1456 return MIN( 256, count
);
1460 /***********************************************************************
1461 * FlushFileBuffers (KERNEL32.133)
1463 BOOL WINAPI
FlushFileBuffers( HFILE hFile
)
1465 struct flush_file_request req
;
1468 CLIENT_SendRequest( REQ_FLUSH_FILE
, -1, 1, &req
, sizeof(req
) );
1469 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1473 /**************************************************************************
1474 * SetEndOfFile (KERNEL32.483)
1476 BOOL WINAPI
SetEndOfFile( HFILE hFile
)
1478 struct truncate_file_request req
;
1481 CLIENT_SendRequest( REQ_TRUNCATE_FILE
, -1, 1, &req
, sizeof(req
) );
1482 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1486 /***********************************************************************
1487 * DeleteFile16 (KERNEL.146)
1489 BOOL16 WINAPI
DeleteFile16( LPCSTR path
)
1491 return DeleteFileA( path
);
1495 /***********************************************************************
1496 * DeleteFile32A (KERNEL32.71)
1498 BOOL WINAPI
DeleteFileA( LPCSTR path
)
1500 DOS_FULL_NAME full_name
;
1502 TRACE(file
, "'%s'\n", path
);
1506 ERR(file
, "Empty path passed\n");
1509 if (DOSFS_GetDevice( path
))
1511 WARN(file
, "cannot remove DOS device '%s'!\n", path
);
1512 SetLastError( ERROR_FILE_NOT_FOUND
);
1516 if (!DOSFS_GetFullName( path
, TRUE
, &full_name
)) return FALSE
;
1517 if (unlink( full_name
.long_name
) == -1)
1526 /***********************************************************************
1527 * DeleteFile32W (KERNEL32.72)
1529 BOOL WINAPI
DeleteFileW( LPCWSTR path
)
1531 LPSTR xpath
= HEAP_strdupWtoA( GetProcessHeap(), 0, path
);
1532 BOOL ret
= DeleteFileA( xpath
);
1533 HeapFree( GetProcessHeap(), 0, xpath
);
1538 /***********************************************************************
1541 LPVOID
FILE_dommap( int unix_handle
, LPVOID start
,
1542 DWORD size_high
, DWORD size_low
,
1543 DWORD offset_high
, DWORD offset_low
,
1544 int prot
, int flags
)
1550 if (size_high
|| offset_high
)
1551 FIXME(file
, "offsets larger than 4Gb not supported\n");
1553 if (unix_handle
== -1)
1558 static int fdzero
= -1;
1562 if ((fdzero
= open( "/dev/zero", O_RDONLY
)) == -1)
1564 perror( "/dev/zero: open" );
1569 #endif /* MAP_ANON */
1570 /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
1572 flags
&= ~MAP_SHARED
;
1575 flags
|= MAP_PRIVATE
;
1578 else fd
= unix_handle
;
1580 if ((ret
= mmap( start
, size_low
, prot
,
1581 flags
, fd
, offset_low
)) != (LPVOID
)-1)
1584 /* mmap() failed; if this is because the file offset is not */
1585 /* page-aligned (EINVAL), or because the underlying filesystem */
1586 /* does not support mmap() (ENOEXEC), we do it by hand. */
1588 if (unix_handle
== -1) return ret
;
1589 if ((errno
!= ENOEXEC
) && (errno
!= EINVAL
)) return ret
;
1590 if (prot
& PROT_WRITE
)
1592 /* We cannot fake shared write mappings */
1594 if (flags
& MAP_SHARED
) return ret
;
1597 if (!(flags
& MAP_PRIVATE
)) return ret
;
1600 /* printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
1601 /* Reserve the memory with an anonymous mmap */
1602 ret
= FILE_dommap( -1, start
, size_high
, size_low
, 0, 0,
1603 PROT_READ
| PROT_WRITE
, flags
);
1604 if (ret
== (LPVOID
)-1) return ret
;
1605 /* Now read in the file */
1606 if ((pos
= lseek( fd
, offset_low
, SEEK_SET
)) == -1)
1608 FILE_munmap( ret
, size_high
, size_low
);
1611 read( fd
, ret
, size_low
);
1612 lseek( fd
, pos
, SEEK_SET
); /* Restore the file pointer */
1613 mprotect( ret
, size_low
, prot
); /* Set the right protection */
1618 /***********************************************************************
1621 int FILE_munmap( LPVOID start
, DWORD size_high
, DWORD size_low
)
1624 FIXME(file
, "offsets larger than 4Gb not supported\n");
1625 return munmap( start
, size_low
);
1629 /***********************************************************************
1630 * GetFileType (KERNEL32.222)
1632 DWORD WINAPI
GetFileType( HFILE hFile
)
1634 struct get_file_info_request req
;
1635 struct get_file_info_reply reply
;
1638 CLIENT_SendRequest( REQ_GET_FILE_INFO
, -1, 1, &req
, sizeof(req
) );
1639 if (CLIENT_WaitSimpleReply( &reply
, sizeof(reply
), NULL
))
1640 return FILE_TYPE_UNKNOWN
;
1645 /**************************************************************************
1646 * MoveFileEx32A (KERNEL32.???)
1648 BOOL WINAPI
MoveFileExA( LPCSTR fn1
, LPCSTR fn2
, DWORD flag
)
1650 DOS_FULL_NAME full_name1
, full_name2
;
1651 int mode
=0; /* mode == 1: use copy */
1653 TRACE(file
, "(%s,%s,%04lx)\n", fn1
, fn2
, flag
);
1655 if (!DOSFS_GetFullName( fn1
, TRUE
, &full_name1
)) return FALSE
;
1656 if (fn2
) { /* !fn2 means delete fn1 */
1657 if (!DOSFS_GetFullName( fn2
, FALSE
, &full_name2
)) return FALSE
;
1658 /* Source name and target path are valid */
1659 if ( full_name1
.drive
!= full_name2
.drive
)
1661 /* use copy, if allowed */
1662 if (!(flag
& MOVEFILE_COPY_ALLOWED
)) {
1663 /* FIXME: Use right error code */
1664 SetLastError( ERROR_FILE_EXISTS
);
1669 if (DOSFS_GetFullName( fn2
, TRUE
, &full_name2
))
1670 /* target exists, check if we may overwrite */
1671 if (!(flag
& MOVEFILE_REPLACE_EXISTING
)) {
1672 /* FIXME: Use right error code */
1673 SetLastError( ERROR_ACCESS_DENIED
);
1677 else /* fn2 == NULL means delete source */
1678 if (flag
& MOVEFILE_DELAY_UNTIL_REBOOT
) {
1679 if (flag
& MOVEFILE_COPY_ALLOWED
) {
1680 WARN(file
, "Illegal flag\n");
1681 SetLastError( ERROR_GEN_FAILURE
);
1684 /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
1685 Perhaps we should queue these command and execute it
1686 when exiting... What about using on_exit(2)
1688 FIXME(file
, "Please delete file '%s' when Wine has finished\n",
1689 full_name1
.long_name
);
1692 else if (unlink( full_name1
.long_name
) == -1)
1697 else return TRUE
; /* successfully deleted */
1699 if (flag
& MOVEFILE_DELAY_UNTIL_REBOOT
) {
1700 /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
1701 Perhaps we should queue these command and execute it
1702 when exiting... What about using on_exit(2)
1704 FIXME(file
,"Please move existing file '%s' to file '%s'"
1705 "when Wine has finished\n",
1706 full_name1
.long_name
, full_name2
.long_name
);
1710 if (!mode
) /* move the file */
1711 if (rename( full_name1
.long_name
, full_name2
.long_name
) == -1)
1717 else /* copy File */
1718 return CopyFileA(fn1
, fn2
, (!(flag
& MOVEFILE_REPLACE_EXISTING
)));
1722 /**************************************************************************
1723 * MoveFileEx32W (KERNEL32.???)
1725 BOOL WINAPI
MoveFileExW( LPCWSTR fn1
, LPCWSTR fn2
, DWORD flag
)
1727 LPSTR afn1
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn1
);
1728 LPSTR afn2
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn2
);
1729 BOOL res
= MoveFileExA( afn1
, afn2
, flag
);
1730 HeapFree( GetProcessHeap(), 0, afn1
);
1731 HeapFree( GetProcessHeap(), 0, afn2
);
1736 /**************************************************************************
1737 * MoveFile32A (KERNEL32.387)
1739 * Move file or directory
1741 BOOL WINAPI
MoveFileA( LPCSTR fn1
, LPCSTR fn2
)
1743 DOS_FULL_NAME full_name1
, full_name2
;
1746 TRACE(file
, "(%s,%s)\n", fn1
, fn2
);
1748 if (!DOSFS_GetFullName( fn1
, TRUE
, &full_name1
)) return FALSE
;
1749 if (DOSFS_GetFullName( fn2
, TRUE
, &full_name2
))
1750 /* The new name must not already exist */
1752 if (!DOSFS_GetFullName( fn2
, FALSE
, &full_name2
)) return FALSE
;
1754 if (full_name1
.drive
== full_name2
.drive
) /* move */
1755 if (rename( full_name1
.long_name
, full_name2
.long_name
) == -1)
1762 if (stat( full_name1
.long_name
, &fstat
))
1764 WARN(file
, "Invalid source file %s\n",
1765 full_name1
.long_name
);
1769 if (S_ISDIR(fstat
.st_mode
)) {
1770 /* No Move for directories across file systems */
1771 /* FIXME: Use right error code */
1772 SetLastError( ERROR_GEN_FAILURE
);
1776 return CopyFileA(fn1
, fn2
, TRUE
); /*fail, if exist */
1781 /**************************************************************************
1782 * MoveFile32W (KERNEL32.390)
1784 BOOL WINAPI
MoveFileW( LPCWSTR fn1
, LPCWSTR fn2
)
1786 LPSTR afn1
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn1
);
1787 LPSTR afn2
= HEAP_strdupWtoA( GetProcessHeap(), 0, fn2
);
1788 BOOL res
= MoveFileA( afn1
, afn2
);
1789 HeapFree( GetProcessHeap(), 0, afn1
);
1790 HeapFree( GetProcessHeap(), 0, afn2
);
1795 /**************************************************************************
1796 * CopyFile32A (KERNEL32.36)
1798 BOOL WINAPI
CopyFileA( LPCSTR source
, LPCSTR dest
, BOOL fail_if_exists
)
1801 BY_HANDLE_FILE_INFORMATION info
;
1807 if ((h1
= _lopen( source
, OF_READ
)) == HFILE_ERROR
) return FALSE
;
1808 if (!GetFileInformationByHandle( h1
, &info
))
1813 mode
= (info
.dwFileAttributes
& FILE_ATTRIBUTE_READONLY
) ? 0444 : 0666;
1814 if ((h2
= CreateFileA( dest
, GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1815 fail_if_exists
? CREATE_NEW
: CREATE_ALWAYS
,
1816 info
.dwFileAttributes
, h1
)) == HFILE_ERROR
)
1821 while ((count
= _lread( h1
, buffer
, sizeof(buffer
) )) > 0)
1826 INT res
= _lwrite( h2
, p
, count
);
1827 if (res
<= 0) goto done
;
1840 /**************************************************************************
1841 * CopyFile32W (KERNEL32.37)
1843 BOOL WINAPI
CopyFileW( LPCWSTR source
, LPCWSTR dest
, BOOL fail_if_exists
)
1845 LPSTR sourceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, source
);
1846 LPSTR destA
= HEAP_strdupWtoA( GetProcessHeap(), 0, dest
);
1847 BOOL ret
= CopyFileA( sourceA
, destA
, fail_if_exists
);
1848 HeapFree( GetProcessHeap(), 0, sourceA
);
1849 HeapFree( GetProcessHeap(), 0, destA
);
1854 /**************************************************************************
1855 * CopyFileEx32A (KERNEL32.858)
1857 * This implementation ignores most of the extra parameters passed-in into
1858 * the "ex" version of the method and calls the CopyFile method.
1859 * It will have to be fixed eventually.
1861 BOOL WINAPI
CopyFileExA(LPCSTR sourceFilename
,
1862 LPCSTR destFilename
,
1863 LPPROGRESS_ROUTINE progressRoutine
,
1865 LPBOOL cancelFlagPointer
,
1868 BOOL failIfExists
= FALSE
;
1871 * Interpret the only flag that CopyFile can interpret.
1873 if ( (copyFlags
& COPY_FILE_FAIL_IF_EXISTS
) != 0)
1875 failIfExists
= TRUE
;
1878 return CopyFileA(sourceFilename
, destFilename
, failIfExists
);
1881 /**************************************************************************
1882 * CopyFileEx32W (KERNEL32.859)
1884 BOOL WINAPI
CopyFileExW(LPCWSTR sourceFilename
,
1885 LPCWSTR destFilename
,
1886 LPPROGRESS_ROUTINE progressRoutine
,
1888 LPBOOL cancelFlagPointer
,
1891 LPSTR sourceA
= HEAP_strdupWtoA( GetProcessHeap(), 0, sourceFilename
);
1892 LPSTR destA
= HEAP_strdupWtoA( GetProcessHeap(), 0, destFilename
);
1894 BOOL ret
= CopyFileExA(sourceA
,
1901 HeapFree( GetProcessHeap(), 0, sourceA
);
1902 HeapFree( GetProcessHeap(), 0, destA
);
1908 /***********************************************************************
1909 * SetFileTime (KERNEL32.650)
1911 BOOL WINAPI
SetFileTime( HFILE hFile
,
1912 const FILETIME
*lpCreationTime
,
1913 const FILETIME
*lpLastAccessTime
,
1914 const FILETIME
*lpLastWriteTime
)
1916 struct set_file_time_request req
;
1919 if (lpLastAccessTime
)
1920 req
.access_time
= DOSFS_FileTimeToUnixTime(lpLastAccessTime
, NULL
);
1922 req
.access_time
= 0; /* FIXME */
1923 if (lpLastWriteTime
)
1924 req
.write_time
= DOSFS_FileTimeToUnixTime(lpLastWriteTime
, NULL
);
1926 req
.write_time
= 0; /* FIXME */
1928 CLIENT_SendRequest( REQ_SET_FILE_TIME
, -1, 1, &req
, sizeof(req
) );
1929 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1933 /**************************************************************************
1934 * LockFile (KERNEL32.511)
1936 BOOL WINAPI
LockFile( HFILE hFile
, DWORD dwFileOffsetLow
, DWORD dwFileOffsetHigh
,
1937 DWORD nNumberOfBytesToLockLow
, DWORD nNumberOfBytesToLockHigh
)
1939 struct lock_file_request req
;
1942 req
.offset_low
= dwFileOffsetLow
;
1943 req
.offset_high
= dwFileOffsetHigh
;
1944 req
.count_low
= nNumberOfBytesToLockLow
;
1945 req
.count_high
= nNumberOfBytesToLockHigh
;
1946 CLIENT_SendRequest( REQ_LOCK_FILE
, -1, 1, &req
, sizeof(req
) );
1947 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
1950 /**************************************************************************
1951 * LockFileEx [KERNEL32.512]
1953 * Locks a byte range within an open file for shared or exclusive access.
1960 * Per Microsoft docs, the third parameter (reserved) must be set to 0.
1962 BOOL WINAPI
LockFileEx( HANDLE hFile
, DWORD flags
, DWORD reserved
,
1963 DWORD nNumberOfBytesToLockLow
, DWORD nNumberOfBytesToLockHigh
,
1964 LPOVERLAPPED pOverlapped
)
1966 FIXME(file
, "hFile=%d,flags=%ld,reserved=%ld,lowbytes=%ld,highbytes=%ld,overlapped=%p: stub.\n",
1967 hFile
, flags
, reserved
, nNumberOfBytesToLockLow
, nNumberOfBytesToLockHigh
,
1970 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1973 ERR(file
, "reserved == %ld: Supposed to be 0??\n", reserved
);
1974 SetLastError(ERROR_INVALID_PARAMETER
);
1981 /**************************************************************************
1982 * UnlockFile (KERNEL32.703)
1984 BOOL WINAPI
UnlockFile( HFILE hFile
, DWORD dwFileOffsetLow
, DWORD dwFileOffsetHigh
,
1985 DWORD nNumberOfBytesToUnlockLow
, DWORD nNumberOfBytesToUnlockHigh
)
1987 struct unlock_file_request req
;
1990 req
.offset_low
= dwFileOffsetLow
;
1991 req
.offset_high
= dwFileOffsetHigh
;
1992 req
.count_low
= nNumberOfBytesToUnlockLow
;
1993 req
.count_high
= nNumberOfBytesToUnlockHigh
;
1994 CLIENT_SendRequest( REQ_UNLOCK_FILE
, -1, 1, &req
, sizeof(req
) );
1995 return !CLIENT_WaitReply( NULL
, NULL
, 0 );
2001 struct DOS_FILE_LOCK
{
2002 struct DOS_FILE_LOCK
* next
;
2006 FILE_OBJECT
* dos_file
;
2007 /* char * unix_name;*/
2010 typedef struct DOS_FILE_LOCK DOS_FILE_LOCK
;
2012 static DOS_FILE_LOCK
*locks
= NULL
;
2013 static void DOS_RemoveFileLocks(FILE_OBJECT
*file
);
2016 /* Locks need to be mirrored because unix file locking is based
2017 * on the pid. Inside of wine there can be multiple WINE processes
2018 * that share the same unix pid.
2019 * Read's and writes should check these locks also - not sure
2020 * how critical that is at this point (FIXME).
2023 static BOOL
DOS_AddLock(FILE_OBJECT
*file
, struct flock
*f
)
2025 DOS_FILE_LOCK
*curr
;
2028 processId
= GetCurrentProcessId();
2030 /* check if lock overlaps a current lock for the same file */
2032 for (curr
= locks
; curr
; curr
= curr
->next
) {
2033 if (strcmp(curr
->unix_name
, file
->unix_name
) == 0) {
2034 if ((f
->l_start
== curr
->base
) && (f
->l_len
== curr
->len
))
2035 return TRUE
;/* region is identic */
2036 if ((f
->l_start
< (curr
->base
+ curr
->len
)) &&
2037 ((f
->l_start
+ f
->l_len
) > curr
->base
)) {
2038 /* region overlaps */
2045 curr
= HeapAlloc( SystemHeap
, 0, sizeof(DOS_FILE_LOCK
) );
2046 curr
->processId
= GetCurrentProcessId();
2047 curr
->base
= f
->l_start
;
2048 curr
->len
= f
->l_len
;
2049 /* curr->unix_name = HEAP_strdupA( SystemHeap, 0, file->unix_name);*/
2051 curr
->dos_file
= file
;
2056 static void DOS_RemoveFileLocks(FILE_OBJECT
*file
)
2059 DOS_FILE_LOCK
**curr
;
2062 processId
= GetCurrentProcessId();
2065 if ((*curr
)->dos_file
== file
) {
2067 *curr
= (*curr
)->next
;
2068 /* HeapFree( SystemHeap, 0, rem->unix_name );*/
2069 HeapFree( SystemHeap
, 0, rem
);
2072 curr
= &(*curr
)->next
;
2076 static BOOL
DOS_RemoveLock(FILE_OBJECT
*file
, struct flock
*f
)
2079 DOS_FILE_LOCK
**curr
;
2082 processId
= GetCurrentProcessId();
2083 for (curr
= &locks
; *curr
; curr
= &(*curr
)->next
) {
2084 if ((*curr
)->processId
== processId
&&
2085 (*curr
)->dos_file
== file
&&
2086 (*curr
)->base
== f
->l_start
&&
2087 (*curr
)->len
== f
->l_len
) {
2088 /* this is the same lock */
2090 *curr
= (*curr
)->next
;
2091 /* HeapFree( SystemHeap, 0, rem->unix_name );*/
2092 HeapFree( SystemHeap
, 0, rem
);
2096 /* no matching lock found */
2101 /**************************************************************************
2102 * LockFile (KERNEL32.511)
2104 BOOL WINAPI
LockFile(
2105 HFILE hFile
,DWORD dwFileOffsetLow
,DWORD dwFileOffsetHigh
,
2106 DWORD nNumberOfBytesToLockLow
,DWORD nNumberOfBytesToLockHigh
)
2111 TRACE(file
, "handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
2112 hFile
, dwFileOffsetLow
, dwFileOffsetHigh
,
2113 nNumberOfBytesToLockLow
, nNumberOfBytesToLockHigh
);
2115 if (dwFileOffsetHigh
|| nNumberOfBytesToLockHigh
) {
2116 FIXME(file
, "Unimplemented bytes > 32bits\n");
2120 f
.l_start
= dwFileOffsetLow
;
2121 f
.l_len
= nNumberOfBytesToLockLow
;
2122 f
.l_whence
= SEEK_SET
;
2126 if (!(file
= FILE_GetFile(hFile
,0,NULL
))) return FALSE
;
2128 /* shadow locks internally */
2129 if (!DOS_AddLock(file
, &f
)) {
2130 SetLastError( ERROR_LOCK_VIOLATION
);
2134 /* FIXME: Unix locking commented out for now, doesn't work with Excel */
2135 #ifdef USE_UNIX_LOCKS
2136 if (fcntl(file
->unix_handle
, F_SETLK
, &f
) == -1) {
2137 if (errno
== EACCES
|| errno
== EAGAIN
) {
2138 SetLastError( ERROR_LOCK_VIOLATION
);
2143 /* remove our internal copy of the lock */
2144 DOS_RemoveLock(file
, &f
);
2152 /**************************************************************************
2153 * UnlockFile (KERNEL32.703)
2155 BOOL WINAPI
UnlockFile(
2156 HFILE hFile
,DWORD dwFileOffsetLow
,DWORD dwFileOffsetHigh
,
2157 DWORD nNumberOfBytesToUnlockLow
,DWORD nNumberOfBytesToUnlockHigh
)
2162 TRACE(file
, "handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
2163 hFile
, dwFileOffsetLow
, dwFileOffsetHigh
,
2164 nNumberOfBytesToUnlockLow
, nNumberOfBytesToUnlockHigh
);
2166 if (dwFileOffsetHigh
|| nNumberOfBytesToUnlockHigh
) {
2167 WARN(file
, "Unimplemented bytes > 32bits\n");
2171 f
.l_start
= dwFileOffsetLow
;
2172 f
.l_len
= nNumberOfBytesToUnlockLow
;
2173 f
.l_whence
= SEEK_SET
;
2177 if (!(file
= FILE_GetFile(hFile
,0,NULL
))) return FALSE
;
2179 DOS_RemoveLock(file
, &f
); /* ok if fails - may be another wine */
2181 /* FIXME: Unix locking commented out for now, doesn't work with Excel */
2182 #ifdef USE_UNIX_LOCKS
2183 if (fcntl(file
->unix_handle
, F_SETLK
, &f
) == -1) {
2192 /**************************************************************************
2193 * GetFileAttributesEx32A [KERNEL32.874]
2195 BOOL WINAPI
GetFileAttributesExA(
2196 LPCSTR lpFileName
, GET_FILEEX_INFO_LEVELS fInfoLevelId
,
2197 LPVOID lpFileInformation
)
2199 DOS_FULL_NAME full_name
;
2200 BY_HANDLE_FILE_INFORMATION info
;
2202 if (lpFileName
== NULL
) return FALSE
;
2203 if (lpFileInformation
== NULL
) return FALSE
;
2205 if (fInfoLevelId
== GetFileExInfoStandard
) {
2206 LPWIN32_FILE_ATTRIBUTE_DATA lpFad
=
2207 (LPWIN32_FILE_ATTRIBUTE_DATA
) lpFileInformation
;
2208 if (!DOSFS_GetFullName( lpFileName
, TRUE
, &full_name
)) return FALSE
;
2209 if (!FILE_Stat( full_name
.long_name
, &info
)) return FALSE
;
2211 lpFad
->dwFileAttributes
= info
.dwFileAttributes
;
2212 lpFad
->ftCreationTime
= info
.ftCreationTime
;
2213 lpFad
->ftLastAccessTime
= info
.ftLastAccessTime
;
2214 lpFad
->ftLastWriteTime
= info
.ftLastWriteTime
;
2215 lpFad
->nFileSizeHigh
= info
.nFileSizeHigh
;
2216 lpFad
->nFileSizeLow
= info
.nFileSizeLow
;
2219 FIXME (file
, "invalid info level %d!\n", fInfoLevelId
);
2227 /**************************************************************************
2228 * GetFileAttributesEx32W [KERNEL32.875]
2230 BOOL WINAPI
GetFileAttributesExW(
2231 LPCWSTR lpFileName
, GET_FILEEX_INFO_LEVELS fInfoLevelId
,
2232 LPVOID lpFileInformation
)
2234 LPSTR nameA
= HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName
);
2236 GetFileAttributesExA( nameA
, fInfoLevelId
, lpFileInformation
);
2237 HeapFree( GetProcessHeap(), 0, nameA
);