2 * File handling functions
4 * Copyright 1993 John Burton
5 * Copyright 1996 Alexandre Julliard
15 #include <sys/errno.h>
16 #include <sys/types.h>
37 #if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
38 #define MAP_ANON MAP_ANONYMOUS
41 struct DOS_FILE_LOCK {
42 struct DOS_FILE_LOCK * next;
46 FILE_OBJECT * dos_file;
50 typedef struct DOS_FILE_LOCK DOS_FILE_LOCK;
52 static DOS_FILE_LOCK *locks = NULL;
53 static void DOS_RemoveFileLocks(FILE_OBJECT *file);
55 /***********************************************************************
60 static HFILE32 FILE_Alloc( FILE_OBJECT **file )
63 *file = HeapAlloc( SystemHeap, 0, sizeof(FILE_OBJECT) );
66 DOS_ERROR( ER_TooManyOpenFiles, EC_ProgramError, SA_Abort, EL_Disk );
69 (*file)->header.type = K32OBJ_FILE;
70 (*file)->header.refcount = 0;
71 (*file)->unix_handle = -1;
72 (*file)->unix_name = NULL;
73 (*file)->type = FILE_TYPE_DISK;
75 handle = PROCESS_AllocHandle( &(*file)->header, 0 );
76 if (handle == INVALID_HANDLE_VALUE32) *file = NULL;
81 /***********************************************************************
86 void FILE_Destroy( K32OBJ *ptr )
88 FILE_OBJECT *file = (FILE_OBJECT *)ptr;
89 assert( ptr->type == K32OBJ_FILE );
91 DOS_RemoveFileLocks(file);
93 if (file->unix_handle != -1) close( file->unix_handle );
94 if (file->unix_name) HeapFree( SystemHeap, 0, file->unix_name );
95 ptr->type = K32OBJ_UNKNOWN;
96 HeapFree( SystemHeap, 0, file );
100 /***********************************************************************
103 * Return the DOS file associated to a task file handle. FILE_ReleaseFile must
104 * be called to release the file.
106 static FILE_OBJECT *FILE_GetFile( HFILE32 handle )
108 return (FILE_OBJECT *)PROCESS_GetObjPtr( handle, K32OBJ_FILE );
112 /***********************************************************************
115 * Release a DOS file obtained with FILE_GetFile.
117 static void FILE_ReleaseFile( FILE_OBJECT *file )
119 K32OBJ_DecCount( &file->header );
123 /***********************************************************************
126 * Return the Unix handle associated to a file handle.
128 int FILE_GetUnixHandle( HFILE32 hFile )
133 if (!(file = FILE_GetFile( hFile ))) return -1;
134 ret = file->unix_handle;
135 FILE_ReleaseFile( file );
140 /***********************************************************************
143 * Set the DOS error code from errno.
145 void FILE_SetDosError(void)
147 int save_errno = errno; /* errno gets overwritten by printf */
149 dprintf_file(stddeb, "FILE_SetDosError: errno = %d %s\n", errno,
150 sys_errlist[errno] );
154 DOS_ERROR( ER_ShareViolation, EC_Temporary, SA_Retry, EL_Disk );
157 DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
160 DOS_ERROR( ER_DiskFull, EC_MediaError, SA_Abort, EL_Disk );
165 DOS_ERROR( ER_AccessDenied, EC_AccessDenied, SA_Abort, EL_Disk );
168 DOS_ERROR( ER_LockViolation, EC_AccessDenied, SA_Abort, EL_Disk );
171 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
174 DOS_ERROR( ER_CanNotMakeDir, EC_AccessDenied, SA_Abort, EL_Unknown );
178 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Unknown );
181 DOS_ERROR( ER_FileExists, EC_Exists, SA_Abort, EL_Disk );
184 DOS_ERROR( ER_SeekError, EC_NotFound, SA_Ignore, EL_Disk );
187 DOS_ERROR( ERROR_DIR_NOT_EMPTY, EC_Exists, SA_Ignore, EL_Disk );
190 perror( "int21: unknown errno" );
191 DOS_ERROR( ER_GeneralFailure, EC_SystemFailure, SA_Abort, EL_Unknown );
198 /***********************************************************************
201 * Duplicate a Unix handle into a task handle.
203 HFILE32 FILE_DupUnixHandle( int fd )
208 if ((handle = FILE_Alloc( &file )) != INVALID_HANDLE_VALUE32)
210 if ((file->unix_handle = dup(fd)) == -1)
213 CloseHandle( handle );
214 return INVALID_HANDLE_VALUE32;
221 /***********************************************************************
224 static HFILE32 FILE_OpenUnixFile( const char *name, int mode )
230 if ((handle = FILE_Alloc( &file )) == INVALID_HANDLE_VALUE32)
231 return INVALID_HANDLE_VALUE32;
233 if ((file->unix_handle = open( name, mode, 0666 )) == -1)
235 if (!Options.failReadOnly && (mode == O_RDWR))
236 file->unix_handle = open( name, O_RDONLY );
238 if ((file->unix_handle == -1) || (fstat( file->unix_handle, &st ) == -1))
241 CloseHandle( handle );
242 return INVALID_HANDLE_VALUE32;
244 if (S_ISDIR(st.st_mode))
246 DOS_ERROR( ER_AccessDenied, EC_AccessDenied, SA_Abort, EL_Disk );
247 CloseHandle( handle );
248 return INVALID_HANDLE_VALUE32;
251 /* File opened OK, now fill the FILE_OBJECT */
253 file->unix_name = HEAP_strdupA( SystemHeap, 0, name );
258 /***********************************************************************
261 HFILE32 FILE_Open( LPCSTR path, INT32 mode )
263 DOS_FULL_NAME full_name;
264 const char *unixName;
266 dprintf_file(stddeb, "FILE_Open: '%s' %04x\n", path, mode );
268 if (!path) return HFILE_ERROR32;
270 if ((unixName = DOSFS_IsDevice( path )) != NULL)
272 dprintf_file( stddeb, "FILE_Open: opening device '%s'\n", unixName );
273 if (!unixName[0]) /* Non-existing device */
275 dprintf_file(stddeb, "FILE_Open: Non-existing device\n");
276 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
277 return HFILE_ERROR32;
280 else /* check for filename, don't check for last entry if creating */
282 if (!DOSFS_GetFullName( path, !(mode & O_CREAT), &full_name ))
283 return HFILE_ERROR32;
284 unixName = full_name.long_name;
286 return FILE_OpenUnixFile( unixName, mode );
290 /***********************************************************************
293 static HFILE32 FILE_Create( LPCSTR path, int mode, int unique )
297 const char *unixName;
298 DOS_FULL_NAME full_name;
300 dprintf_file(stddeb, "FILE_Create: '%s' %04x %d\n", path, mode, unique );
302 if (!path) return INVALID_HANDLE_VALUE32;
304 if ((unixName = DOSFS_IsDevice( path )) != NULL)
306 dprintf_file(stddeb, "FILE_Create: creating device '%s'!\n", unixName);
307 DOS_ERROR( ER_AccessDenied, EC_NotFound, SA_Abort, EL_Disk );
308 return INVALID_HANDLE_VALUE32;
311 if ((handle = FILE_Alloc( &file )) == INVALID_HANDLE_VALUE32)
312 return INVALID_HANDLE_VALUE32;
314 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
316 CloseHandle( handle );
317 return INVALID_HANDLE_VALUE32;
319 if ((file->unix_handle = open( full_name.long_name,
320 O_CREAT | O_TRUNC | O_RDWR | (unique ? O_EXCL : 0),
324 CloseHandle( handle );
325 return INVALID_HANDLE_VALUE32;
328 /* File created OK, now fill the FILE_OBJECT */
330 file->unix_name = HEAP_strdupA( SystemHeap, 0, full_name.long_name );
335 /***********************************************************************
338 * Fill a file information from a struct stat.
340 static void FILE_FillInfo( struct stat *st, BY_HANDLE_FILE_INFORMATION *info )
342 if (S_ISDIR(st->st_mode))
343 info->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
345 info->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE;
346 if (!(st->st_mode & S_IWUSR))
347 info->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
349 DOSFS_UnixTimeToFileTime( st->st_mtime, &info->ftCreationTime, 0 );
350 DOSFS_UnixTimeToFileTime( st->st_mtime, &info->ftLastWriteTime, 0 );
351 DOSFS_UnixTimeToFileTime( st->st_atime, &info->ftLastAccessTime, 0 );
353 info->dwVolumeSerialNumber = 0; /* FIXME */
354 info->nFileSizeHigh = 0;
355 info->nFileSizeLow = S_ISDIR(st->st_mode) ? 0 : st->st_size;
356 info->nNumberOfLinks = st->st_nlink;
357 info->nFileIndexHigh = 0;
358 info->nFileIndexLow = st->st_ino;
362 /***********************************************************************
365 * Stat a Unix path name. Return TRUE if OK.
367 BOOL32 FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info )
371 if (!unixName || !info) return FALSE;
373 if (stat( unixName, &st ) == -1)
378 FILE_FillInfo( &st, info );
383 /***********************************************************************
384 * GetFileInformationByHandle (KERNEL32.219)
386 DWORD WINAPI GetFileInformationByHandle( HFILE32 hFile,
387 BY_HANDLE_FILE_INFORMATION *info )
395 if (!(file = FILE_GetFile( hFile ))) return 0;
396 if (fstat( file->unix_handle, &st ) == -1) FILE_SetDosError();
399 FILE_FillInfo( &st, info );
402 FILE_ReleaseFile( file );
407 /**************************************************************************
408 * GetFileAttributes16 (KERNEL.420)
410 DWORD WINAPI GetFileAttributes16( LPCSTR name )
412 return GetFileAttributes32A( name );
416 /**************************************************************************
417 * GetFileAttributes32A (KERNEL32.217)
419 DWORD WINAPI GetFileAttributes32A( LPCSTR name )
421 DOS_FULL_NAME full_name;
422 BY_HANDLE_FILE_INFORMATION info;
424 if (name == NULL) return -1;
426 if (!DOSFS_GetFullName( name, TRUE, &full_name )) return -1;
427 if (!FILE_Stat( full_name.long_name, &info )) return -1;
428 return info.dwFileAttributes;
432 /**************************************************************************
433 * GetFileAttributes32W (KERNEL32.218)
435 DWORD WINAPI GetFileAttributes32W( LPCWSTR name )
437 LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
438 DWORD res = GetFileAttributes32A( nameA );
439 HeapFree( GetProcessHeap(), 0, nameA );
444 /***********************************************************************
445 * GetFileSize (KERNEL32.220)
447 DWORD WINAPI GetFileSize( HFILE32 hFile, LPDWORD filesizehigh )
449 BY_HANDLE_FILE_INFORMATION info;
450 if (!GetFileInformationByHandle( hFile, &info )) return 0;
451 if (filesizehigh) *filesizehigh = info.nFileSizeHigh;
452 return info.nFileSizeLow;
456 /***********************************************************************
457 * GetFileTime (KERNEL32.221)
459 BOOL32 WINAPI GetFileTime( HFILE32 hFile, FILETIME *lpCreationTime,
460 FILETIME *lpLastAccessTime,
461 FILETIME *lpLastWriteTime )
463 BY_HANDLE_FILE_INFORMATION info;
464 if (!GetFileInformationByHandle( hFile, &info )) return FALSE;
465 if (lpCreationTime) *lpCreationTime = info.ftCreationTime;
466 if (lpLastAccessTime) *lpLastAccessTime = info.ftLastAccessTime;
467 if (lpLastWriteTime) *lpLastWriteTime = info.ftLastWriteTime;
471 /***********************************************************************
472 * CompareFileTime (KERNEL32.28)
474 INT32 WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y )
476 if (!x || !y) return -1;
478 if (x->dwHighDateTime > y->dwHighDateTime)
480 if (x->dwHighDateTime < y->dwHighDateTime)
482 if (x->dwLowDateTime > y->dwLowDateTime)
484 if (x->dwLowDateTime < y->dwLowDateTime)
489 /***********************************************************************
492 * dup() function for DOS handles.
494 HFILE32 FILE_Dup( HFILE32 hFile )
499 dprintf_file( stddeb, "FILE_Dup for handle %d\n", hFile );
500 if (!(file = FILE_GetFile( hFile ))) return HFILE_ERROR32;
501 handle = PROCESS_AllocHandle( &file->header, 0 );
502 FILE_ReleaseFile( file );
503 dprintf_file( stddeb, "FILE_Dup return handle %d\n", handle );
508 /***********************************************************************
511 * dup2() function for DOS handles.
513 HFILE32 FILE_Dup2( HFILE32 hFile1, HFILE32 hFile2 )
517 dprintf_file( stddeb, "FILE_Dup2 for handle %d\n", hFile1 );
518 if (!(file = FILE_GetFile( hFile1 ))) return HFILE_ERROR32;
519 if (!PROCESS_SetObjPtr( hFile2, &file->header, 0 )) hFile2 = HFILE_ERROR32;
520 FILE_ReleaseFile( file );
525 /***********************************************************************
526 * GetTempFileName16 (KERNEL.97)
528 UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
533 if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */
534 drive |= DRIVE_GetCurrentDrive();
536 if ((drive & TF_FORCEDRIVE) &&
537 !DRIVE_IsValid( toupper(drive & ~TF_FORCEDRIVE) - 'A' ))
539 drive &= ~TF_FORCEDRIVE;
540 fprintf( stderr, "Warning: GetTempFileName: invalid drive %d specified\n",
544 if (drive & TF_FORCEDRIVE)
545 sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
548 GetTempPath32A( 132, temppath );
549 strcat( temppath, "\\" );
551 return (UINT16)GetTempFileName32A( temppath, prefix, unique, buffer );
555 /***********************************************************************
556 * GetTempFileName32A (KERNEL32.290)
558 UINT32 WINAPI GetTempFileName32A( LPCSTR path, LPCSTR prefix, UINT32 unique,
561 DOS_FULL_NAME full_name;
564 UINT32 num = unique ? (unique & 0xffff) : time(NULL) & 0xffff;
566 if ( !path || !prefix || !buffer ) return 0;
568 strcpy( buffer, path );
569 p = buffer + strlen(buffer);
570 /* add a \, if there isn't one ... */
571 if ((p == buffer) || (p[-1] != '\\')) *p++ = '\\';
573 for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++;
574 sprintf( p, "%04x.tmp", num );
576 /* Now try to create it */
582 HFILE32 handle = FILE_Create( buffer, 0666, TRUE );
583 if (handle != INVALID_HANDLE_VALUE32)
584 { /* We created it */
585 dprintf_file( stddeb, "GetTempFileName32A: created %s\n",
587 CloseHandle( handle );
590 if (DOS_ExtendedError != ER_FileExists)
591 break; /* No need to go on */
593 sprintf( p, "%04x.tmp", num );
594 } while (num != (unique & 0xffff));
597 /* Get the full path name */
599 if (DOSFS_GetFullName( buffer, FALSE, &full_name ))
601 /* Check if we have write access in the directory */
602 if ((p = strrchr( full_name.long_name, '/' ))) *p = '\0';
603 if (access( full_name.long_name, W_OK ) == -1)
605 "Warning: GetTempFileName returns '%s', which doesn't seem to be writeable.\n"
606 "Please check your configuration file if this generates a failure.\n",
609 dprintf_file( stddeb, "GetTempFileName32A: returning %s\n", buffer );
610 return unique ? unique : num;
614 /***********************************************************************
615 * GetTempFileName32W (KERNEL32.291)
617 UINT32 WINAPI GetTempFileName32W( LPCWSTR path, LPCWSTR prefix, UINT32 unique,
625 patha = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
626 prefixa = HEAP_strdupWtoA( GetProcessHeap(), 0, prefix );
627 ret = GetTempFileName32A( patha, prefixa, unique, buffera );
628 lstrcpyAtoW( buffer, buffera );
629 HeapFree( GetProcessHeap(), 0, patha );
630 HeapFree( GetProcessHeap(), 0, prefixa );
635 /***********************************************************************
638 * Implementation of OpenFile16() and OpenFile32().
640 static HFILE32 FILE_DoOpenFile( LPCSTR name, OFSTRUCT *ofs, UINT32 mode,
645 WORD filedatetime[2];
646 DOS_FULL_NAME full_name;
650 if (!ofs) return HFILE_ERROR32;
653 ofs->cBytes = sizeof(OFSTRUCT);
655 if (mode & OF_REOPEN) name = ofs->szPathName;
658 fprintf(stderr, "ERROR: FILE_DoOpenFile() called with `name' set to NULL ! Please debug.\n");
660 return HFILE_ERROR32;
663 dprintf_file( stddeb, "OpenFile: %s %04x\n", name, mode );
665 /* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
666 Are there any cases where getting the path here is wrong?
667 Uwe Bonnes 1997 Apr 2 */
668 if (!GetFullPathName32A( name, sizeof(ofs->szPathName),
669 ofs->szPathName, NULL )) goto error;
671 /* OF_PARSE simply fills the structure */
675 ofs->fFixedDisk = (GetDriveType16( ofs->szPathName[0]-'A' )
677 dprintf_file( stddeb, "OpenFile(%s): OF_PARSE, res = '%s'\n",
678 name, ofs->szPathName );
682 /* OF_CREATE is completely different from all other options, so
685 if (mode & OF_CREATE)
687 if ((hFileRet = FILE_Create(name,0666,FALSE))== INVALID_HANDLE_VALUE32)
692 /* If OF_SEARCH is set, ignore the given path */
694 if ((mode & OF_SEARCH) && !(mode & OF_REOPEN))
696 /* First try the file name as is */
697 if (DOSFS_GetFullName( name, TRUE, &full_name )) goto found;
698 /* Now remove the path */
699 if (name[0] && (name[1] == ':')) name += 2;
700 if ((p = strrchr( name, '\\' ))) name = p + 1;
701 if ((p = strrchr( name, '/' ))) name = p + 1;
702 if (!name[0]) goto not_found;
705 /* Now look for the file */
707 if (!DIR_SearchPath( NULL, name, NULL, &full_name, win32 )) goto not_found;
710 dprintf_file( stddeb, "OpenFile: found %s = %s\n",
711 full_name.long_name, full_name.short_name );
712 lstrcpyn32A( ofs->szPathName, full_name.short_name,
713 sizeof(ofs->szPathName) );
715 if (mode & OF_DELETE)
717 if (unlink( full_name.long_name ) == -1) goto not_found;
718 dprintf_file( stddeb, "OpenFile(%s): OF_DELETE return = OK\n", name);
725 unixMode = O_WRONLY; break;
727 unixMode = O_RDWR; break;
730 unixMode = O_RDONLY; break;
733 hFileRet = FILE_OpenUnixFile( full_name.long_name, unixMode );
734 if (hFileRet == HFILE_ERROR32) goto not_found;
735 GetFileTime( hFileRet, NULL, NULL, &filetime );
736 FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] );
737 if ((mode & OF_VERIFY) && (mode & OF_REOPEN))
739 if (memcmp( ofs->reserved, filedatetime, sizeof(ofs->reserved) ))
741 CloseHandle( hFileRet );
742 dprintf_file( stddeb, "OpenFile(%s): OF_VERIFY failed\n", name );
743 /* FIXME: what error here? */
744 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
748 memcpy( ofs->reserved, filedatetime, sizeof(ofs->reserved) );
750 success: /* We get here if the open was successful */
751 dprintf_file( stddeb, "OpenFile(%s): OK, return = %d\n", name, hFileRet );
752 if (mode & OF_EXIST) /* Return the handle, but close it first */
753 CloseHandle( hFileRet );
756 not_found: /* We get here if the file does not exist */
757 dprintf_file( stddeb, "OpenFile: '%s' not found\n", name );
758 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
761 error: /* We get here if there was an error opening the file */
762 ofs->nErrCode = DOS_ExtendedError;
763 dprintf_file( stddeb, "OpenFile(%s): return = HFILE_ERROR error= %d\n",
764 name,ofs->nErrCode );
765 return HFILE_ERROR32;
769 /***********************************************************************
770 * OpenFile16 (KERNEL.74)
772 HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
774 return FILE_DoOpenFile( name, ofs, mode, FALSE );
778 /***********************************************************************
779 * OpenFile32 (KERNEL32.396)
781 HFILE32 WINAPI OpenFile32( LPCSTR name, OFSTRUCT *ofs, UINT32 mode )
783 return FILE_DoOpenFile( name, ofs, mode, TRUE );
787 /***********************************************************************
788 * _lclose16 (KERNEL.81)
790 HFILE16 WINAPI _lclose16( HFILE16 hFile )
792 dprintf_file( stddeb, "_lclose16: handle %d\n", hFile );
793 return CloseHandle( hFile ) ? 0 : HFILE_ERROR16;
797 /***********************************************************************
798 * _lclose32 (KERNEL32.592)
800 HFILE32 WINAPI _lclose32( HFILE32 hFile )
802 dprintf_file( stddeb, "_lclose32: handle %d\n", hFile );
803 return CloseHandle( hFile ) ? 0 : HFILE_ERROR32;
807 /***********************************************************************
810 LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
814 dprintf_file( stddeb, "WIN16_hread: %d %08lx %ld\n",
815 hFile, (DWORD)buffer, count );
817 /* Some programs pass a count larger than the allocated buffer */
818 maxlen = GetSelectorLimit( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
819 if (count > maxlen) count = maxlen;
820 return _lread32( hFile, PTR_SEG_TO_LIN(buffer), count );
824 /***********************************************************************
827 UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
829 return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
833 /***********************************************************************
834 * _lread32 (KERNEL32.596)
836 UINT32 WINAPI _lread32( HFILE32 hFile, LPVOID buffer, UINT32 count )
841 dprintf_file( stddeb, "_lread32: %d %p %d\n", hFile, buffer, count );
842 if (!(file = FILE_GetFile( hFile ))) return -1;
843 if (!count) result = 0;
844 else if ((result = read( file->unix_handle, buffer, count )) == -1)
846 FILE_ReleaseFile( file );
851 /***********************************************************************
852 * _lread16 (KERNEL.82)
854 UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
856 return (UINT16)_lread32( hFile, buffer, (LONG)count );
860 /***********************************************************************
861 * _lcreat16 (KERNEL.83)
863 HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
865 int mode = (attr & 1) ? 0444 : 0666;
866 dprintf_file( stddeb, "_lcreat16: %s %02x\n", path, attr );
867 return (HFILE16)FILE_Create( path, mode, FALSE );
871 /***********************************************************************
872 * _lcreat32 (KERNEL32.593)
874 HFILE32 WINAPI _lcreat32( LPCSTR path, INT32 attr )
876 int mode = (attr & 1) ? 0444 : 0666;
877 dprintf_file( stddeb, "_lcreat32: %s %02x\n", path, attr );
878 return FILE_Create( path, mode, FALSE );
882 /***********************************************************************
883 * _lcreat_uniq (Not a Windows API)
885 HFILE32 _lcreat_uniq( LPCSTR path, INT32 attr )
887 int mode = (attr & 1) ? 0444 : 0666;
888 dprintf_file( stddeb, "_lcreat_uniq: %s %02x\n", path, attr );
889 return FILE_Create( path, mode, TRUE );
893 /***********************************************************************
894 * SetFilePointer (KERNEL32.492)
896 DWORD WINAPI SetFilePointer( HFILE32 hFile, LONG distance, LONG *highword,
902 if (highword && *highword)
904 fprintf( stderr, "SetFilePointer: 64-bit offsets not supported yet\n");
905 SetLastError( ERROR_INVALID_PARAMETER );
908 dprintf_file( stddeb, "SetFilePointer: handle %d offset %ld origin %ld\n",
909 hFile, distance, method );
911 if (!(file = FILE_GetFile( hFile ))) return 0xffffffff;
914 case FILE_CURRENT: origin = SEEK_CUR; break;
915 case FILE_END: origin = SEEK_END; break;
916 default: origin = SEEK_SET; break;
919 if ((result = lseek( file->unix_handle, distance, origin )) == -1)
921 FILE_ReleaseFile( file );
922 return (DWORD)result;
926 /***********************************************************************
927 * _llseek16 (KERNEL.84)
929 LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
931 return SetFilePointer( hFile, lOffset, NULL, nOrigin );
935 /***********************************************************************
936 * _llseek32 (KERNEL32.594)
938 LONG WINAPI _llseek32( HFILE32 hFile, LONG lOffset, INT32 nOrigin )
940 return SetFilePointer( hFile, lOffset, NULL, nOrigin );
944 /***********************************************************************
945 * _lopen16 (KERNEL.85)
947 HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
949 return _lopen32( path, mode );
953 /***********************************************************************
954 * _lopen32 (KERNEL32.595)
956 HFILE32 WINAPI _lopen32( LPCSTR path, INT32 mode )
960 dprintf_file(stddeb, "_lopen32('%s',%04x)\n", path, mode );
975 return FILE_Open( path, unixMode );
979 /***********************************************************************
980 * _lwrite16 (KERNEL.86)
982 UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
984 return (UINT16)_hwrite32( hFile, buffer, (LONG)count );
987 /***********************************************************************
988 * _lwrite32 (KERNEL.86)
990 UINT32 WINAPI _lwrite32( HFILE32 hFile, LPCSTR buffer, UINT32 count )
992 return (UINT32)_hwrite32( hFile, buffer, (LONG)count );
996 /***********************************************************************
997 * _hread16 (KERNEL.349)
999 LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
1001 return _lread32( hFile, buffer, count );
1005 /***********************************************************************
1006 * _hread32 (KERNEL32.590)
1008 LONG WINAPI _hread32( HFILE32 hFile, LPVOID buffer, LONG count)
1010 return _lread32( hFile, buffer, count );
1014 /***********************************************************************
1015 * _hwrite16 (KERNEL.350)
1017 LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
1019 return _hwrite32( hFile, buffer, count );
1023 /***********************************************************************
1024 * _hwrite32 (KERNEL32.591)
1026 LONG WINAPI _hwrite32( HFILE32 hFile, LPCSTR buffer, LONG count )
1031 dprintf_file( stddeb, "_hwrite32: %d %p %ld\n", hFile, buffer, count );
1033 if (!(file = FILE_GetFile( hFile ))) return HFILE_ERROR32;
1034 if (count == 0) /* Expand or truncate at current position */
1035 result = ftruncate( file->unix_handle,
1036 lseek( file->unix_handle, 0, SEEK_CUR ) );
1039 result = write( file->unix_handle, buffer, count );
1040 if (result != -1) break;
1048 FILE_ReleaseFile( file );
1053 /***********************************************************************
1054 * SetHandleCount16 (KERNEL.199)
1056 UINT16 WINAPI SetHandleCount16( UINT16 count )
1058 HGLOBAL16 hPDB = GetCurrentPDB();
1059 PDB *pdb = (PDB *)GlobalLock16( hPDB );
1060 BYTE *files = PTR_SEG_TO_LIN( pdb->fileHandlesPtr );
1062 dprintf_file( stddeb, "SetHandleCount16(%d)\n", count );
1064 if (count < 20) count = 20; /* No point in going below 20 */
1065 else if (count > 254) count = 254;
1069 if (pdb->nbFiles > 20)
1071 memcpy( pdb->fileHandles, files, 20 );
1072 GlobalFree16( pdb->hFileHandles );
1073 pdb->fileHandlesPtr = (SEGPTR)MAKELONG( 0x18,
1074 GlobalHandleToSel( hPDB ) );
1075 pdb->hFileHandles = 0;
1079 else /* More than 20, need a new file handles table */
1082 HGLOBAL16 newhandle = GlobalAlloc16( GMEM_MOVEABLE, count );
1085 DOS_ERROR( ER_OutOfMemory, EC_OutOfResource, SA_Abort, EL_Memory );
1086 return pdb->nbFiles;
1088 newfiles = (BYTE *)GlobalLock16( newhandle );
1090 if (count > pdb->nbFiles)
1092 memcpy( newfiles, files, pdb->nbFiles );
1093 memset( newfiles + pdb->nbFiles, 0xff, count - pdb->nbFiles );
1095 else memcpy( newfiles, files, count );
1096 if (pdb->nbFiles > 20) GlobalFree16( pdb->hFileHandles );
1097 pdb->fileHandlesPtr = WIN16_GlobalLock16( newhandle );
1098 pdb->hFileHandles = newhandle;
1099 pdb->nbFiles = count;
1101 return pdb->nbFiles;
1105 /*************************************************************************
1106 * SetHandleCount32 (KERNEL32.494)
1108 UINT32 WINAPI SetHandleCount32( UINT32 count )
1110 return MIN( 256, count );
1114 /***********************************************************************
1115 * FlushFileBuffers (KERNEL32.133)
1117 BOOL32 WINAPI FlushFileBuffers( HFILE32 hFile )
1122 dprintf_file( stddeb, "FlushFileBuffers(%d)\n", hFile );
1123 if (!(file = FILE_GetFile( hFile ))) return FALSE;
1124 if (fsync( file->unix_handle ) != -1) ret = TRUE;
1130 FILE_ReleaseFile( file );
1135 /**************************************************************************
1136 * SetEndOfFile (KERNEL32.483)
1138 BOOL32 WINAPI SetEndOfFile( HFILE32 hFile )
1143 dprintf_file( stddeb, "SetEndOfFile(%d)\n", hFile );
1144 if (!(file = FILE_GetFile( hFile ))) return FALSE;
1145 if (ftruncate( file->unix_handle,
1146 lseek( file->unix_handle, 0, SEEK_CUR ) ))
1151 FILE_ReleaseFile( file );
1156 /***********************************************************************
1157 * DeleteFile16 (KERNEL.146)
1159 BOOL16 WINAPI DeleteFile16( LPCSTR path )
1161 return DeleteFile32A( path );
1165 /***********************************************************************
1166 * DeleteFile32A (KERNEL32.71)
1168 BOOL32 WINAPI DeleteFile32A( LPCSTR path )
1170 DOS_FULL_NAME full_name;
1171 const char *unixName;
1173 dprintf_file(stddeb, "DeleteFile: '%s'\n", path );
1175 if ((unixName = DOSFS_IsDevice( path )) != NULL)
1177 dprintf_file(stddeb, "DeleteFile: removing device '%s'!\n", unixName);
1178 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
1182 if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE;
1183 if (unlink( full_name.long_name ) == -1)
1192 /***********************************************************************
1193 * DeleteFile32W (KERNEL32.72)
1195 BOOL32 WINAPI DeleteFile32W( LPCWSTR path )
1197 LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
1198 BOOL32 ret = DeleteFile32A( xpath );
1199 HeapFree( GetProcessHeap(), 0, xpath );
1204 /***********************************************************************
1207 BOOL32 FILE_SetFileType( HFILE32 hFile, DWORD type )
1209 FILE_OBJECT *file = FILE_GetFile( hFile );
1210 if (!file) return FALSE;
1212 FILE_ReleaseFile( file );
1217 /***********************************************************************
1220 LPVOID FILE_mmap( HFILE32 hFile, LPVOID start,
1221 DWORD size_high, DWORD size_low,
1222 DWORD offset_high, DWORD offset_low,
1223 int prot, int flags )
1226 FILE_OBJECT *file = FILE_GetFile( hFile );
1227 if (!file) return (LPVOID)-1;
1228 ret = FILE_dommap( file, start, size_high, size_low,
1229 offset_high, offset_low, prot, flags );
1230 FILE_ReleaseFile( file );
1235 /***********************************************************************
1238 LPVOID FILE_dommap( FILE_OBJECT *file, LPVOID start,
1239 DWORD size_high, DWORD size_low,
1240 DWORD offset_high, DWORD offset_low,
1241 int prot, int flags )
1247 if (size_high || offset_high)
1248 fprintf( stderr, "FILE_mmap: offsets larger than 4Gb not supported\n");
1255 static int fdzero = -1;
1259 if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
1261 perror( "/dev/zero: open" );
1266 #endif /* MAP_ANON */
1267 /* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
1269 flags &= ~MAP_SHARED;
1272 flags |= MAP_PRIVATE;
1275 else fd = file->unix_handle;
1277 if ((ret = mmap( start, size_low, prot,
1278 flags, fd, offset_low )) != (LPVOID)-1)
1281 /* mmap() failed; if this is because the file offset is not */
1282 /* page-aligned (EINVAL), or because the underlying filesystem */
1283 /* does not support mmap() (ENOEXEC), we do it by hand. */
1285 if (!file) return ret;
1286 if ((errno != ENOEXEC) && (errno != EINVAL)) return ret;
1287 if (prot & PROT_WRITE)
1289 /* We cannot fake shared write mappings */
1291 if (flags & MAP_SHARED) return ret;
1294 if (!(flags & MAP_PRIVATE)) return ret;
1297 /* printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
1298 /* Reserve the memory with an anonymous mmap */
1299 ret = FILE_dommap( NULL, start, size_high, size_low, 0, 0,
1300 PROT_READ | PROT_WRITE, flags );
1301 if (ret == (LPVOID)-1) return ret;
1302 /* Now read in the file */
1303 if ((pos = lseek( fd, offset_low, SEEK_SET )) == -1)
1305 FILE_munmap( ret, size_high, size_low );
1308 read( fd, ret, size_low );
1309 lseek( fd, pos, SEEK_SET ); /* Restore the file pointer */
1310 mprotect( ret, size_low, prot ); /* Set the right protection */
1315 /***********************************************************************
1318 int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low )
1321 fprintf( stderr, "FILE_munmap: offsets larger than 4Gb not supported\n");
1322 return munmap( start, size_low );
1326 /***********************************************************************
1327 * GetFileType (KERNEL32.222)
1329 DWORD WINAPI GetFileType( HFILE32 hFile )
1331 FILE_OBJECT *file = FILE_GetFile(hFile);
1332 if (!file) return FILE_TYPE_UNKNOWN; /* FIXME: correct? */
1333 FILE_ReleaseFile( file );
1338 /**************************************************************************
1339 * MoveFileEx32A (KERNEL32.???)
1341 BOOL32 WINAPI MoveFileEx32A( LPCSTR fn1, LPCSTR fn2, DWORD flag )
1343 DOS_FULL_NAME full_name1, full_name2;
1344 int mode=0; /* mode == 1: use copy */
1346 dprintf_file( stddeb, "MoveFileEx32A(%s,%s,%04lx)\n", fn1, fn2, flag);
1348 if (!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) return FALSE;
1349 if (fn2) { /* !fn2 means delete fn1 */
1350 if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) return FALSE;
1351 /* Source name and target path are valid */
1352 if ( full_name1.drive != full_name2.drive)
1353 /* use copy, if allowed */
1354 if (!(flag & MOVEFILE_COPY_ALLOWED)) {
1355 /* FIXME: Use right error code */
1356 DOS_ERROR( ER_FileExists, EC_Exists, SA_Abort, EL_Disk );
1360 if (DOSFS_GetFullName( fn2, TRUE, &full_name2 ))
1361 /* target exists, check if we may overwrite */
1362 if (!(flag & MOVEFILE_REPLACE_EXISTING)) {
1363 /* FIXME: Use right error code */
1364 DOS_ERROR( ER_AccessDenied, EC_AccessDenied, SA_Abort, EL_Disk );
1368 else /* fn2 == NULL means delete source */
1369 if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) {
1370 if (flag & MOVEFILE_COPY_ALLOWED) {
1372 "MoveFileEx32A: Illegal flag\n");
1373 DOS_ERROR( ER_GeneralFailure, EC_SystemFailure, SA_Abort,
1377 /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
1378 Perhaps we should queue these command and execute it
1379 when exiting... What about using on_exit(2)
1381 fprintf( stderr,"MoveFileEx32A: Please delete file %s\n",
1382 full_name1.long_name);
1383 fprintf( stderr," when Wine has finished\n");
1384 fprintf( stderr," like \"rm %s\"\n",
1385 full_name1.long_name);
1388 else if (unlink( full_name1.long_name ) == -1)
1393 else return TRUE; /* successfully deleted */
1395 if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) {
1396 /* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
1397 Perhaps we should queue these command and execute it
1398 when exiting... What about using on_exit(2)
1400 fprintf( stderr,"MoveFileEx32A: Please move existing file %s\n"
1401 ,full_name1.long_name);
1402 fprintf( stderr," to file %s\n"
1403 ,full_name2.long_name);
1404 fprintf( stderr," when Wine has finished\n");
1405 fprintf( stderr," like \" mv %s %s\"\n",
1406 full_name1.long_name,full_name2.long_name);
1410 if (!mode) /* move the file */
1411 if (rename( full_name1.long_name, full_name2.long_name ) == -1)
1417 else /* copy File */
1418 return CopyFile32A(fn1, fn2, (!(flag & MOVEFILE_REPLACE_EXISTING)));
1422 /**************************************************************************
1423 * MoveFileEx32W (KERNEL32.???)
1425 BOOL32 WINAPI MoveFileEx32W( LPCWSTR fn1, LPCWSTR fn2, DWORD flag )
1427 LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 );
1428 LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 );
1429 BOOL32 res = MoveFileEx32A( afn1, afn2, flag );
1430 HeapFree( GetProcessHeap(), 0, afn1 );
1431 HeapFree( GetProcessHeap(), 0, afn2 );
1436 /**************************************************************************
1437 * MoveFile32A (KERNEL32.387)
1439 * Move file or directory
1441 BOOL32 WINAPI MoveFile32A( LPCSTR fn1, LPCSTR fn2 )
1443 DOS_FULL_NAME full_name1, full_name2;
1446 dprintf_file( stddeb, "MoveFile32A(%s,%s)\n", fn1, fn2 );
1448 if (!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) return FALSE;
1449 if (DOSFS_GetFullName( fn2, TRUE, &full_name2 ))
1450 /* The new name must not already exist */
1452 if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) return FALSE;
1454 if (full_name1.drive == full_name2.drive) /* move */
1455 if (rename( full_name1.long_name, full_name2.long_name ) == -1)
1462 if (stat( full_name1.long_name, &fstat ))
1464 dprintf_file( stddeb, "Invalid source file %s\n",
1465 full_name1.long_name);
1469 if (S_ISDIR(fstat.st_mode)) {
1470 /* No Move for directories across file systems */
1471 /* FIXME: Use right error code */
1472 DOS_ERROR( ER_GeneralFailure, EC_SystemFailure, SA_Abort,
1477 return CopyFile32A(fn1, fn2, TRUE); /*fail, if exist */
1482 /**************************************************************************
1483 * MoveFile32W (KERNEL32.390)
1485 BOOL32 WINAPI MoveFile32W( LPCWSTR fn1, LPCWSTR fn2 )
1487 LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 );
1488 LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 );
1489 BOOL32 res = MoveFile32A( afn1, afn2 );
1490 HeapFree( GetProcessHeap(), 0, afn1 );
1491 HeapFree( GetProcessHeap(), 0, afn2 );
1496 /**************************************************************************
1497 * CopyFile32A (KERNEL32.36)
1499 BOOL32 WINAPI CopyFile32A( LPCSTR source, LPCSTR dest, BOOL32 fail_if_exists )
1502 BY_HANDLE_FILE_INFORMATION info;
1508 if ((h1 = _lopen32( source, OF_READ )) == HFILE_ERROR32) return FALSE;
1509 if (!GetFileInformationByHandle( h1, &info ))
1514 mode = (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666;
1515 if ((h2 = FILE_Create( dest, mode, fail_if_exists )) == HFILE_ERROR32)
1520 while ((count = _lread32( h2, buffer, sizeof(buffer) )) > 0)
1525 INT32 res = _lwrite32( h2, p, count );
1526 if (res <= 0) goto done;
1539 /**************************************************************************
1540 * CopyFile32W (KERNEL32.37)
1542 BOOL32 WINAPI CopyFile32W( LPCWSTR source, LPCWSTR dest, BOOL32 fail_if_exists)
1544 LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, source );
1545 LPSTR destA = HEAP_strdupWtoA( GetProcessHeap(), 0, dest );
1546 BOOL32 ret = CopyFile32A( sourceA, destA, fail_if_exists );
1547 HeapFree( GetProcessHeap(), 0, sourceA );
1548 HeapFree( GetProcessHeap(), 0, destA );
1553 /***********************************************************************
1554 * SetFileTime (KERNEL32.493)
1556 BOOL32 WINAPI SetFileTime( HFILE32 hFile,
1557 const FILETIME *lpCreationTime,
1558 const FILETIME *lpLastAccessTime,
1559 const FILETIME *lpLastWriteTime )
1561 FILE_OBJECT *file = FILE_GetFile(hFile);
1562 struct utimbuf utimbuf;
1564 if (!file) return FILE_TYPE_UNKNOWN; /* FIXME: correct? */
1565 dprintf_file(stddeb,"SetFileTime(%s,%p,%p,%p)\n",
1571 if (lpLastAccessTime)
1572 utimbuf.actime = DOSFS_FileTimeToUnixTime(lpLastAccessTime, NULL);
1574 utimbuf.actime = 0; /* FIXME */
1575 if (lpLastWriteTime)
1576 utimbuf.modtime = DOSFS_FileTimeToUnixTime(lpLastWriteTime, NULL);
1578 utimbuf.modtime = 0; /* FIXME */
1579 if (-1==utime(file->unix_name,&utimbuf))
1581 FILE_ReleaseFile( file );
1585 FILE_ReleaseFile( file );
1589 /* Locks need to be mirrored because unix file locking is based
1590 * on the pid. Inside of wine there can be multiple WINE processes
1591 * that share the same unix pid.
1592 * Read's and writes should check these locks also - not sure
1593 * how critical that is at this point (FIXME).
1596 static BOOL32 DOS_AddLock(FILE_OBJECT *file, struct flock *f)
1598 DOS_FILE_LOCK *curr;
1601 processId = GetCurrentProcessId();
1603 /* check if lock overlaps a current lock for the same file */
1604 for (curr = locks; curr; curr = curr->next) {
1605 if (strcmp(curr->unix_name, file->unix_name) == 0) {
1606 if ((f->l_start < (curr->base + curr->len)) &&
1607 ((f->l_start + f->l_len) > curr->base)) {
1608 /* region overlaps */
1614 curr = HeapAlloc( SystemHeap, 0, sizeof(DOS_FILE_LOCK) );
1615 curr->processId = GetCurrentProcessId();
1616 curr->base = f->l_start;
1617 curr->len = f->l_len;
1618 curr->unix_name = HEAP_strdupA( SystemHeap, 0, file->unix_name);
1620 curr->dos_file = file;
1625 static void DOS_RemoveFileLocks(FILE_OBJECT *file)
1628 DOS_FILE_LOCK **curr;
1631 processId = GetCurrentProcessId();
1634 if ((*curr)->dos_file == file) {
1636 *curr = (*curr)->next;
1637 HeapFree( SystemHeap, 0, rem->unix_name );
1638 HeapFree( SystemHeap, 0, rem );
1641 curr = &(*curr)->next;
1645 static BOOL32 DOS_RemoveLock(FILE_OBJECT *file, struct flock *f)
1648 DOS_FILE_LOCK **curr;
1651 processId = GetCurrentProcessId();
1652 for (curr = &locks; *curr; curr = &(*curr)->next) {
1653 if ((*curr)->processId == processId &&
1654 (*curr)->dos_file == file &&
1655 (*curr)->base == f->l_start &&
1656 (*curr)->len == f->l_len) {
1657 /* this is the same lock */
1659 *curr = (*curr)->next;
1660 HeapFree( SystemHeap, 0, rem->unix_name );
1661 HeapFree( SystemHeap, 0, rem );
1665 /* no matching lock found */
1670 /**************************************************************************
1671 * LockFile (KERNEL32.511)
1673 BOOL32 WINAPI LockFile(
1674 HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
1675 DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh )
1680 dprintf_file(stddeb, "LockFile32: handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
1681 hFile, dwFileOffsetLow, dwFileOffsetHigh,
1682 nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh);
1684 if (dwFileOffsetHigh || nNumberOfBytesToLockHigh) {
1685 dprintf_file(stddeb, "LockFile32: Unimplemented bytes > 32bits\n");
1689 f.l_start = dwFileOffsetLow;
1690 f.l_len = nNumberOfBytesToLockLow;
1691 f.l_whence = SEEK_SET;
1695 if (!(file = FILE_GetFile(hFile))) return FALSE;
1697 /* shadow locks internally */
1698 if (!DOS_AddLock(file, &f)) {
1699 DOS_ERROR( ER_LockViolation, EC_AccessDenied, SA_Ignore, EL_Disk );
1703 /* FIXME: Unix locking commented out for now, doesn't work with Excel */
1704 #ifdef USE_UNIX_LOCKS
1705 if (fcntl(file->unix_handle, F_SETLK, &f) == -1) {
1706 if (errno == EACCES || errno == EAGAIN) {
1707 DOS_ERROR( ER_LockViolation, EC_AccessDenied, SA_Ignore, EL_Disk );
1712 /* remove our internal copy of the lock */
1713 DOS_RemoveLock(file, &f);
1721 /**************************************************************************
1722 * UnlockFile (KERNEL32.703)
1724 BOOL32 WINAPI UnlockFile(
1725 HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
1726 DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh )
1731 dprintf_file(stddeb, "UnlockFile32: handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
1732 hFile, dwFileOffsetLow, dwFileOffsetHigh,
1733 nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh);
1735 if (dwFileOffsetHigh || nNumberOfBytesToUnlockHigh) {
1736 dprintf_file(stddeb, "UnlockFile32: Unimplemented bytes > 32bits\n");
1740 f.l_start = dwFileOffsetLow;
1741 f.l_len = nNumberOfBytesToUnlockLow;
1742 f.l_whence = SEEK_SET;
1746 if (!(file = FILE_GetFile(hFile))) return FALSE;
1748 DOS_RemoveLock(file, &f); /* ok if fails - may be another wine */
1750 /* FIXME: Unix locking commented out for now, doesn't work with Excel */
1751 #ifdef USE_UNIX_LOCKS
1752 if (fcntl(file->unix_handle, F_SETLK, &f) == -1) {