From 712caf35964d7896c775217745e1da81b2372f17 Mon Sep 17 00:00:00 2001 From: Juergen Schmied Date: Sat, 3 Aug 2002 19:11:33 +0000 Subject: [PATCH] - Fixed possible loss of data with given overlapped structure on a file opened in non overlapped mode. - Fixme for file-lock functions. --- files/file.c | 54 +++++++++++++++++++++++++++++++++++++++++++---- include/winbase.h | 6 +++++- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/files/file.c b/files/file.c index 9b04fc5c151..99bbb490654 100644 --- a/files/file.c +++ b/files/file.c @@ -1675,11 +1675,27 @@ BOOL WINAPI ReadFile( HANDLE hFile, LPVOID buffer, DWORD bytesToRead, { case FD_TYPE_SMB: return SMB_ReadFile(hFile, buffer, bytesToRead, bytesRead, NULL); + case FD_TYPE_CONSOLE: return FILE_ReadConsole(hFile, buffer, bytesToRead, bytesRead, NULL); + case FD_TYPE_DEFAULT: + /* normal unix files */ + if (unix_handle == -1) return FALSE; + if (overlapped) + { + DWORD highOffset = overlapped->OffsetHigh; + if ( (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, overlapped->Offset, + &highOffset, FILE_BEGIN)) && + (GetLastError() != NO_ERROR) ) + { + close(unix_handle); + return FALSE; + } + } + break; + default: - /* normal unix files */ if (unix_handle == -1) return FALSE; if (overlapped) @@ -1877,9 +1893,33 @@ BOOL WINAPI WriteFile( HANDLE hFile, LPCVOID buffer, DWORD bytesToWrite, TRACE("%d %s %ld %p %p\n", hFile, debugstr_an(buffer, bytesToWrite), bytesToWrite, bytesWritten, overlapped ); return FILE_WriteConsole(hFile, buffer, bytesToWrite, bytesWritten, NULL); + + case FD_TYPE_DEFAULT: + if (unix_handle == -1) return FALSE; + + if(overlapped) + { + DWORD highOffset = overlapped->OffsetHigh; + if ( (INVALID_SET_FILE_POINTER == SetFilePointer(hFile, overlapped->Offset, + &highOffset, FILE_BEGIN)) && + (GetLastError() != NO_ERROR) ) + { + close(unix_handle); + return FALSE; + } + } + break; + default: - if (unix_handle == -1) - return FALSE; + if (unix_handle == -1) + return FALSE; + if (overlapped) + { + close(unix_handle); + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + break; } /* synchronous file write */ @@ -1975,7 +2015,7 @@ HFILE WINAPI _lcreat( LPCSTR path, INT attr ) DWORD WINAPI SetFilePointer( HANDLE hFile, LONG distance, LONG *highword, DWORD method ) { - DWORD ret = 0xffffffff; + DWORD ret = INVALID_SET_FILE_POINTER; TRACE("handle %d offset %ld high %ld origin %ld\n", hFile, distance, highword?*highword:0, method ); @@ -2719,6 +2759,9 @@ BOOL WINAPI LockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetHig DWORD nNumberOfBytesToLockLow, DWORD nNumberOfBytesToLockHigh ) { BOOL ret; + + FIXME("not implemented in server\n"); + SERVER_START_REQ( lock_file ) { req->handle = hFile; @@ -2770,6 +2813,9 @@ BOOL WINAPI UnlockFile( HANDLE hFile, DWORD dwFileOffsetLow, DWORD dwFileOffsetH DWORD nNumberOfBytesToUnlockLow, DWORD nNumberOfBytesToUnlockHigh ) { BOOL ret; + + FIXME("not implemented in server\n"); + SERVER_START_REQ( unlock_file ) { req->handle = hFile; diff --git a/include/winbase.h b/include/winbase.h index a27ded143d4..a317a989aa3 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -286,7 +286,11 @@ typedef struct #define PROCESS_HEAP_ENTRY_MOVEABLE 0x0010 #define PROCESS_HEAP_ENTRY_DDESHARE 0x0020 -#define INVALID_HANDLE_VALUE ((HANDLE) -1) +#define INVALID_HANDLE_VALUE ((HANDLE) -1) +#define INVALID_FILE_SIZE ((DWORD)0xFFFFFFFF) +#define INVALID_SET_FILE_POINTER ((DWORD)-1) +#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) + #define TLS_OUT_OF_INDEXES ((DWORD)0xFFFFFFFF)