Sun Sep 27 14:25:38 1998 Petter Reinholdtsen <pere@td.org.uit.no> * [files/drive.c] Make sure GetDriveType32A() handles param NULL. Added some doc on function. Sun Sep 27 14:07:26 1998 Huw D M Davies <daviesh@abacus.physics.ox.ac.uk> * [controls/edit.c] [windows/win.c] Don't call SetWindowLong() in EDIT_WM_NCREATE. Fix SetWindowLong(GWL_[EX]STYLE) to work for 16bit windows. Remove UpdateWindow() call. Sun Sep 27 13:41:22 1998 Alexandre Julliard <julliard@lrc.epfl.ch> * [scheduler/*.c] [server/event.c] [server/mutex.c] [server/semaphore.c] Implemented server-side synchronisation objects. Sun Sep 27 01:13:35 1998 Alex Priem <alexp@sci.kun.nl> * [dlls/comctl32/treeview.c] [include/treeview.h] [include/comctl.h] Treeview implementation. * [dlls/comctl32/trackbar.c] [include/trackbar.h] Trackbar implementation. Sat Sep 26 20:49:13 1998 Ulrich Weigand <weigand@informatik.uni-erlangen.de> * [if1632/thunk.c] [tools/build.c] [win32/kernel32.c] Bugfix: several problems with flat thunks fixed. * [memory/selector.c] Bugfix: IsBad...Ptr16 didn't work for limit_in_pages segments. * [scheduler/thread.c] Bugfix: CreateThread: Allow id parameter == NULL. * [objects/gdiobj.c] Bugfix: IsGDIObject: Return correct object type for stock objects. * [msdos/dpmi.c] Bugfix: fixed typo in INT_DoRealModeInt. * [msdos/int21.c] Bugfix: int21 READ *must* use WIN16_hread, not _hread16. * [if1632/kernel.spec] [if1632/dummy.c] [if1632/thunk.c] [loader/ne/module.c] [scheduler/event.c] [scheduler/synchro.c] [scheduler/thread.c] [win32/kernel32.c] [win32/ordinals.c] Added names/stubs for all undocumented KERNEL routines (Win95). Added the following undoc. 16-bit equivalents to Win32 routines: KERNEL.441-443,449-453,456-462,471-476,479-486,488. Added stubs for some other KERNEL routines. * [memory/heap.c] [memory/global.c] [include/global.h] Implemented Local32... 32-bit local heap routines (KERNEL.208-215, 229). * [miscemu/instr.c] [loader/module.c] [include/module.h] Implemented __GP fault handling and HasGPHandler (KERNEL.338). * [misc/error.c] Implemented LogParamErrorRegs (KERNEL.327). * [loader/task.c] [include/windows.h] Implemented GetCodeInfo (KERNEL.104). * [loader/task.c] [scheduler/thread.c] [include/thread.h] Implemented [GS]etThreadQueue and [GS]etFastQueue (KERNEL.463/4, 624/5). * [if1632/gdi.spec] [objects/dc.c] [objects/dib.c] [objects/bitmap.c] [include/windows.h] Bugfix: fixed wrong parameter for CreateDIBSection16. Added [GS]etDIBColorTable16, stub for GetBoundsRect16. Partially implemented BITMAP_GetObject16 for DIBs. * [if1632/gdi.spec] [relay32/gdi32.spec] [objects/palette.c] Added some GDI stubs. * [if1632/Makefile.in] [if1632/display.spec] [if1632/mouse.spec] [if1632/keyboard.spec] [if1632/builtin.c] [windows/keyboard.c] Added some stubs for Win16 drivers: KEYBOARD, MOUSE, DISPLAY. * [if1632/wprocs.spec] [msdos/vxd.c] Added some stubs for VxDs: VMM, ConfigMG, TimerAPI. * [msdos/int2f.c] Added some stubs for real-mode network drivers. Sat Sep 26 18:18:18 1998 Marcus Meissner <marcus@jet.franken.de> * [configure.in] Merged in some more of the FreeBSD ports/emulators/wine patches. (Maintainer(s) of this port: You can just submit these patches to Alexandre directly.) * [loader/pe_image.c] Check filesize of image against size derived from header to spot truncated executeables without crashing. * [files/directory.c] Set envvar "COMSPEC". One win32(!!) program crashes without it. * [multimedia/mmio.c] Added mmioSetInfo32. * [include/file.h] Return STD_ERROR_HANDLE for AUX and PRT dos handles. * [loader/module.c] Handle executeables with spaces in their names a bit better in CreateProcess. * [relay32/msvfw32.spec][if1632/msvideo.spec][multimedia/msvideo.c][include/vfw.h] Started on MS Video support (can load Win32 ICMs). * [tools/testrun] A bit smarter use of ps. * [memory/virtual.c] Report PAGE_GUARDed pages as PAGE_PROTECTED (AutoCAD LT R17 fails without that check (since Win95 doesn't know about PAGE_GUARD)). Sat Sep 26 15:04:05 1998 Ove Kaaven <ovek@arcticnet.no> * [include/miscemu.h] [if1632/builtin.c] [loader/task.c] [miscemu/instr.c] [msdos/dpmi.c] [msdos/int21.c] [msdos/interrupts.c] [windows/user.c] INT_[S|G]etHandler was renamed to INT_[S|G]etPMHandler. Added handlers to deal with real-mode interrupts; DOS programs are now able to hook real-mode interrupts. * [loader/dos/module.c] [msdos/dosmem.c] [msdos/int21.c] Moved real-mode interrupt table initialization to msdos/dosmem.c, and made new V86 tasks get a full copy of the existing "system memory" instead of almost empty space. Misc fixes. * [include/dosexe.h] [loader/dos/module.c] [msdos/dpmi.c] [msdos/int2f.c] First shot at letting DOS programs start up DPMI (but DPMI is still disabled for DOS programs, for pkunzip's sake). * [include/debugger.h] [debugger/break.c] [debugger/dbg.y] [debugger/registers.c] [debugger/memory.c] [debugger/info.c] [loader/dos/dosvm.c] First shot at making Wine's debugger work for DOS programs. The -debug flag works, as do "nexti" and "stepi". Sat Sep 26 13:13:13 1998 Juergen Schmied <juergen.schmied@metronet.de> * [dlls/shell32/dataobject.c] New classes IEnumFORMATETC implemented, IDataObject stubs. * [dlls/shell32/*.*][relay32/shell32.spec] Bugfixes. New: ICM_InsertItem(), ILCreateFromPath(). Implemented: ILCloneFirst(). Stubs: ILIsEqual(), ILFindChild(), SHLogILFromFSIL(), PathMatchSpec(), PathIsExe(). Changed: ILGetSize(), _ILIsDesktop(), PathCombine(). * [include/shlobj.h] New SHLGUID's New structures: DVTARGETDEVICE32, STGMEDIUM32, FORMATETC32, CLIPFORMAT32. New interfaces: IEnumFORMATETC, IDataObject, ICommDlgBrowser IDockingWindowFrame, IServiceProvider. * [dlls/shell32/folders.c] Stubs for IShellLink. * [loader/resource.c] Small fixes. * [misc/crtdll.c][relay32/crtdll.spec] New __dllonexit(). * [windows/message.c] SendNotifyMessageA, SendMessageCallBack32A half implemented. * [controls/edit.c] EDIT_WM_SetText set EF_UPDATE flag not for ES_MULTILINE. * [files/file.c] Handling of fileposition fixed. Fri Sep 25 18:13:30 1998 Patrik Stridvall <ps@leissner.se> * [include/windows.h] [include/wintypes.h] [ole/ole2nls.h] [relay32/kernel32.spec] Implemented EnumDateFormats and EnumTimeFormats. Only adds US English support. * [Makefile.in] [configure.in] [dlls/Makefile.in] [dlls/psapi/Makefile.in] [dlls/psapi/psapi_main.c] New files to implement stubs for PSAPI.DLL (NT only). * [relay32/Makefile.in] [relay32/builtin32.c] [relay32/psapi.spec] New spec file for PSAPI.DLL (NT only). * [scheduler/handle.c] HANDLE_GetObjPtr should only interpret the pseudo handles as the current thread or the current process if a thread or a process is requested. * [include/winversion.h] [misc/version.c] Adds the global function VERSION_GetVersion() so functions can have different behavior depending on the -winver flag. * [include/oledlg.h] [ole/oledlg.c] Minor fixes. * [windows/winproc.c] Minor changes. * [include/imm.h] [misc/imm.c] Now returns correct values under both Windows 95 and NT 4.0. Thu Sep 24 22:11:44 1998 Kristian Nielsen <kristian.nielsen@risoe.dk> * [configure.in] [include/acconfig.h] [include/thread.h] [scheduler/sysdeps.c] Autoconfig test for non-reentrant libc. Wed Sep 23 19:52:12 1998 Matthew Becker <mbecker@glasscity.net> * [*/*.c] Miscellaneous documentation updates and debugging output standardizations. * [objects/clipping.c] Added ExtSelectClipRgn. Wed Sep 23 00:03:28 EDT 1998 Pete Ratzlaff <pratzlaff@cfa.harvard.edu> * [include/windows.h] [if1632/user.spec] [relay32/user32.spec] [windows/keyboard.c] Added, marginally implemented, GetKeyboardLayoutName(). Only returns US English keyboard name. Tue Sep 22 16:32:41 1998 Marcel Baur <mbaur@iiic.ethz.ch> * [programs/control/*] New Winelib application. Mon Sep 21 00:29:18 1998 Peter Hunnisett <hunnise@nortel.ca> * [include/dplay.h][multimedia/dplay.c][ole/compobj.c] Added all DirectPlayLobby interfaces and enhanced DirectPlay and DirectPlayLobby support. Still not all that much. Useful enough if you just need to start a program, don't try any real dplay/lobby stuff. * [documentation/status/directplay] Added a very little bit. * [graphics/ddraw.c] - Call to SetWindowLong32A wasn't working because there was no memory set aside when the window class was registered. - Fixed some xlib reference counting and change the behaviour of DirectDrawSurface3_SetPalette to mimic observed behaviour (palette is associated will all backbuffers) - Also stored all palette colour fields and spit back our saved colour fields rather than query X for them. - Added plenty of AddRef and Release traces. - Added Xlib support for using -desktop option. - Fixed Xlib message handling. Messages weren't being passed to the application. Fixes mouse movements in some xlib DDraw games. - Added a few stubs. * [windows/win.c][include/winerror.h] Fixed up some error handling in WIN_SetWindowLong. SetLastError wasn't being used. Could cause problems with 0 return codes. Added new error in winerror (1400). * [AUTHORS] [include/authors.h] Added myself as a Wine author. Sun Sep 20 21:22:44 1998 Alexander Larsson <alla@lysator.liu.se> * [loader/module.c] Changed GetModuleFileName32A so that is returns the long version of the filename. Note that just the name is long, not the directories. Sat Sep 19 20:05:30 1998 Per Ångström <pang@mind.nu> * [controls/menu.c] Made a couple of fixes to make life easier for applications that alter their menus at runtime. * [windows/defdlg.c] Removed the cast of the return value from dialog procedures to a 16-bit bool. The return value needs to retain all its 32 bits, since it is not always a bool, such as when responding to the WM_NCHITTEST message. Fri Sep 18 11:30:38 1998 Sergey Turchanov <turchanov@usa.net> * [loader/resource.c] Fixed very funny bug (though gravely affecting further excecution) with FindResource[Ex]32 functions. * [include/multimon.h] [windows/multimon.c] [relay32/user32.spec] [include/windows.h] [windows/sysmetrics.c] Default implementation for Multimonitor API. * [include/windows.h] [windows/winpos.c] Fixed incorrect declaration (and behaviour) of GetWindowRect32. Wed Sep 16 10:21:15 1998 Gerard Patel <G.Patel@Wanadoo.fr> * [controls/edit.c] Fixed EDIT_EM_GetLine to use correctly length of lines. Tue Sep 15 20:40:16 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de> * [misc/tweak.c][include/tweak.h][controls/menu.c] Replaced the tweak graphic routines by calls to DrawEdge32(). * [misc/tweak.c][include/tweak.h][documentation/win95look] [wine.ini][*/*] Changed "look and feel" selection. Allows Win3.1, Win95 and Win98 (no GUI code implemented) look and feel. * [dlls/comctl32/header.c][include/header.h][include/commctrl.h] Started callback item support and did some minor improvements. * [dlls/comctl32/imagelist.c] Fixed bug in transparent image display. ImageList_GetIcon is still buggy :-( * [dlls/comctl32/toolbar.c] Fixed button drawing (partial hack). * [dlls/comctl32/commctrl.c] Fixed MenuHelp(). * [controls/button.c] Added 3d effect for groupbox. * [windows/msgbox.c] Added font support for message boxes. * [windows/nonclient.c] Fixed window moving bug. * [dlls/comctl32/*.c] Various improvements. * [dlls/comctl32/listview.c][dlls/comctl32/rebar.c] [include/commctrl.h] More messages. * [windows/syscolor.c][include/windows.h] Introduced new Win98 system colors. Tue Sep 15 18:29:45 1998 Wesley Filardo <eightknots@aol.com> * [files/profile.c] Added support in PROFILE_LoadWineIni for -config option * [misc/main.c] [include/options.h] Added -config option. Tue Sep 15 18:22:26 1998 Petter Reinholdtsen <pere@td.org.uit.no> * [documentation/Makefile.in] Make sure directory exists before installing into it. Tue Sep 15 01:47:33 1998 Pablo Saratxaga <pablo.sarachaga@ping.be> * [ole/nls/*] [ole/ole2nls.c] [include/winnls.h] Fixed a few errors and completed some NLS files. Mon Sep 14 01:23:45 1998 Joseph Pranevich <knight@baltimore.wwaves.com> * [include/miscemu.h] [msdos/interrupts.c] Removed a compilation warning, added INT 25 to the list of interrupts callable from DOS applications, added a debug message when unsupported interrupts are used. Sun Sep 13 19:55:22 1998 Lawson Whitney <lawson_whitney@juno.com> * [if1632/relay.c] CallProcEx32W should not reverse arguments. Sun Aug 17 21:18:12 1998 Eric Pouech <eric.pouech@lemel.fr> * [multimedia/midi.c] [multimedia/init.c] [multimedia/mmsys.c] [include/multimedia.h] [include/mmsystem.h] [multimedia/Makefile.in] [multimedia/midipatch.c] [if1632/multimedia.spec] Made MIDI input and output functional on OSS capable systems. * [multimedia/timer.c] Changes to trigger callbacks at the accurate pace even when fake timers are used.
1964 lines
55 KiB
C
1964 lines
55 KiB
C
/*
|
|
* File handling functions
|
|
*
|
|
* Copyright 1993 John Burton
|
|
* Copyright 1996 Alexandre Julliard
|
|
*/
|
|
|
|
#include <assert.h>
|
|
#include <ctype.h>
|
|
#include <errno.h>
|
|
#include <fcntl.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/errno.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/mman.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
#include <utime.h>
|
|
|
|
#include "windows.h"
|
|
#include "winerror.h"
|
|
#include "drive.h"
|
|
#include "file.h"
|
|
#include "global.h"
|
|
#include "heap.h"
|
|
#include "msdos.h"
|
|
#include "options.h"
|
|
#include "ldt.h"
|
|
#include "process.h"
|
|
#include "task.h"
|
|
#include "debug.h"
|
|
|
|
#if defined(MAP_ANONYMOUS) && !defined(MAP_ANON)
|
|
#define MAP_ANON MAP_ANONYMOUS
|
|
#endif
|
|
|
|
static BOOL32 FILE_Read(K32OBJ *ptr, LPVOID lpBuffer, DWORD nNumberOfChars,
|
|
LPDWORD lpNumberOfChars, LPOVERLAPPED lpOverlapped);
|
|
static BOOL32 FILE_Write(K32OBJ *ptr, LPCVOID lpBuffer, DWORD nNumberOfChars,
|
|
LPDWORD lpNumberOfChars, LPOVERLAPPED lpOverlapped);
|
|
static void FILE_Destroy( K32OBJ *obj );
|
|
|
|
const K32OBJ_OPS FILE_Ops =
|
|
{
|
|
/* Object cannot be waited upon (FIXME: for now) */
|
|
NULL, /* signaled */
|
|
NULL, /* satisfied */
|
|
NULL, /* add_wait */
|
|
NULL, /* remove_wait */
|
|
FILE_Read, /* read */
|
|
FILE_Write, /* write */
|
|
FILE_Destroy /* destroy */
|
|
};
|
|
|
|
struct DOS_FILE_LOCK {
|
|
struct DOS_FILE_LOCK * next;
|
|
DWORD base;
|
|
DWORD len;
|
|
DWORD processId;
|
|
FILE_OBJECT * dos_file;
|
|
char * unix_name;
|
|
};
|
|
|
|
typedef struct DOS_FILE_LOCK DOS_FILE_LOCK;
|
|
|
|
static DOS_FILE_LOCK *locks = NULL;
|
|
static void DOS_RemoveFileLocks(FILE_OBJECT *file);
|
|
|
|
/***********************************************************************
|
|
* FILE_Alloc
|
|
*
|
|
* Allocate a file.
|
|
*/
|
|
HFILE32 FILE_Alloc( FILE_OBJECT **file )
|
|
{
|
|
HFILE32 handle;
|
|
*file = HeapAlloc( SystemHeap, 0, sizeof(FILE_OBJECT) );
|
|
if (!*file)
|
|
{
|
|
DOS_ERROR( ER_TooManyOpenFiles, EC_ProgramError, SA_Abort, EL_Disk );
|
|
return (HFILE32)NULL;
|
|
}
|
|
(*file)->header.type = K32OBJ_FILE;
|
|
(*file)->header.refcount = 0;
|
|
(*file)->unix_handle = -1;
|
|
(*file)->unix_name = NULL;
|
|
(*file)->type = FILE_TYPE_DISK;
|
|
(*file)->pos = 0;
|
|
|
|
handle = HANDLE_Alloc( PROCESS_Current(), &(*file)->header,
|
|
FILE_ALL_ACCESS | GENERIC_READ |
|
|
GENERIC_WRITE | GENERIC_EXECUTE /*FIXME*/, TRUE, -1 );
|
|
/* If the allocation failed, the object is already destroyed */
|
|
if (handle == INVALID_HANDLE_VALUE32) *file = NULL;
|
|
return handle;
|
|
}
|
|
|
|
|
|
/* FIXME: lpOverlapped is ignored */
|
|
static BOOL32 FILE_Read(K32OBJ *ptr, LPVOID lpBuffer, DWORD nNumberOfChars,
|
|
LPDWORD lpNumberOfChars, LPOVERLAPPED lpOverlapped)
|
|
{
|
|
FILE_OBJECT *file = (FILE_OBJECT *)ptr;
|
|
int result;
|
|
|
|
TRACE(file, "%p %p %ld\n", ptr, lpBuffer,
|
|
nNumberOfChars);
|
|
|
|
if (nNumberOfChars == 0) {
|
|
*lpNumberOfChars = 0; /* FIXME: does this change */
|
|
return TRUE;
|
|
}
|
|
|
|
if ( (file->pos < 0) || /* workaround, see SetFilePointer */
|
|
((result = read(file->unix_handle, lpBuffer, nNumberOfChars)) == -1) )
|
|
{
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
file->pos += result;
|
|
*lpNumberOfChars = result;
|
|
return TRUE;
|
|
}
|
|
|
|
/**
|
|
* experimentation yields that WriteFile:
|
|
* o does not truncate on write of 0
|
|
* o always changes the *lpNumberOfChars to actual number of
|
|
* characters written
|
|
* o write of 0 nNumberOfChars returns TRUE
|
|
*/
|
|
static BOOL32 FILE_Write(K32OBJ *ptr, LPCVOID lpBuffer, DWORD nNumberOfChars,
|
|
LPDWORD lpNumberOfChars, LPOVERLAPPED lpOverlapped)
|
|
{
|
|
FILE_OBJECT *file = (FILE_OBJECT *)ptr;
|
|
int result;
|
|
|
|
TRACE(file, "%p %p %ld\n", ptr, lpBuffer,
|
|
nNumberOfChars);
|
|
|
|
*lpNumberOfChars = 0;
|
|
|
|
/*
|
|
* I assume this loop around EAGAIN is here because
|
|
* win32 doesn't have interrupted system calls
|
|
*/
|
|
|
|
if (file->pos < 0) { /* workaround, see SetFilePointer */
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
|
|
for (;;)
|
|
{
|
|
result = write(file->unix_handle, lpBuffer, nNumberOfChars);
|
|
if (result != -1) {
|
|
*lpNumberOfChars = result;
|
|
file->pos += result;
|
|
return TRUE;
|
|
}
|
|
if (errno != EINTR) {
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_Destroy
|
|
*
|
|
* Destroy a DOS file.
|
|
*/
|
|
static void FILE_Destroy( K32OBJ *ptr )
|
|
{
|
|
FILE_OBJECT *file = (FILE_OBJECT *)ptr;
|
|
assert( ptr->type == K32OBJ_FILE );
|
|
|
|
DOS_RemoveFileLocks(file);
|
|
|
|
if (file->unix_handle != -1) close( file->unix_handle );
|
|
if (file->unix_name) HeapFree( SystemHeap, 0, file->unix_name );
|
|
ptr->type = K32OBJ_UNKNOWN;
|
|
HeapFree( SystemHeap, 0, file );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_GetFile
|
|
*
|
|
* Return the DOS file associated to a task file handle. FILE_ReleaseFile must
|
|
* be called to release the file.
|
|
*/
|
|
FILE_OBJECT *FILE_GetFile( HFILE32 handle )
|
|
{
|
|
return (FILE_OBJECT *)HANDLE_GetObjPtr( PROCESS_Current(), handle,
|
|
K32OBJ_FILE, 0 /*FIXME*/, NULL );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_ReleaseFile
|
|
*
|
|
* Release a DOS file obtained with FILE_GetFile.
|
|
*/
|
|
void FILE_ReleaseFile( FILE_OBJECT *file )
|
|
{
|
|
K32OBJ_DecCount( &file->header );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_GetUnixHandle
|
|
*
|
|
* Return the Unix handle associated to a file handle.
|
|
*/
|
|
int FILE_GetUnixHandle( HFILE32 hFile )
|
|
{
|
|
FILE_OBJECT *file;
|
|
int ret;
|
|
|
|
if (!(file = FILE_GetFile( hFile ))) return -1;
|
|
ret = file->unix_handle;
|
|
FILE_ReleaseFile( file );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_SetDosError
|
|
*
|
|
* Set the DOS error code from errno.
|
|
*/
|
|
void FILE_SetDosError(void)
|
|
{
|
|
int save_errno = errno; /* errno gets overwritten by printf */
|
|
|
|
TRACE(file, "errno = %d %s\n", errno, strerror(errno));
|
|
switch (save_errno)
|
|
{
|
|
case EAGAIN:
|
|
DOS_ERROR( ER_ShareViolation, EC_Temporary, SA_Retry, EL_Disk );
|
|
break;
|
|
case EBADF:
|
|
DOS_ERROR( ER_InvalidHandle, EC_ProgramError, SA_Abort, EL_Disk );
|
|
break;
|
|
case ENOSPC:
|
|
DOS_ERROR( ER_DiskFull, EC_MediaError, SA_Abort, EL_Disk );
|
|
break;
|
|
case EACCES:
|
|
case EPERM:
|
|
case EROFS:
|
|
DOS_ERROR( ER_AccessDenied, EC_AccessDenied, SA_Abort, EL_Disk );
|
|
break;
|
|
case EBUSY:
|
|
DOS_ERROR( ER_LockViolation, EC_AccessDenied, SA_Abort, EL_Disk );
|
|
break;
|
|
case ENOENT:
|
|
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
|
|
break;
|
|
case EISDIR:
|
|
DOS_ERROR( ER_CanNotMakeDir, EC_AccessDenied, SA_Abort, EL_Unknown );
|
|
break;
|
|
case ENFILE:
|
|
case EMFILE:
|
|
DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Unknown );
|
|
break;
|
|
case EEXIST:
|
|
DOS_ERROR( ER_FileExists, EC_Exists, SA_Abort, EL_Disk );
|
|
break;
|
|
case EINVAL:
|
|
case ESPIPE:
|
|
DOS_ERROR( ER_SeekError, EC_NotFound, SA_Ignore, EL_Disk );
|
|
break;
|
|
case ENOTEMPTY:
|
|
DOS_ERROR( ERROR_DIR_NOT_EMPTY, EC_Exists, SA_Ignore, EL_Disk );
|
|
break;
|
|
default:
|
|
perror( "int21: unknown errno" );
|
|
DOS_ERROR( ER_GeneralFailure, EC_SystemFailure, SA_Abort, EL_Unknown );
|
|
break;
|
|
}
|
|
errno = save_errno;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_DupUnixHandle
|
|
*
|
|
* Duplicate a Unix handle into a task handle.
|
|
*/
|
|
HFILE32 FILE_DupUnixHandle( int fd )
|
|
{
|
|
HFILE32 handle;
|
|
FILE_OBJECT *file;
|
|
|
|
if ((handle = FILE_Alloc( &file )) != INVALID_HANDLE_VALUE32)
|
|
{
|
|
if ((file->unix_handle = dup(fd)) == -1)
|
|
{
|
|
FILE_SetDosError();
|
|
CloseHandle( handle );
|
|
return INVALID_HANDLE_VALUE32;
|
|
}
|
|
}
|
|
return handle;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_OpenUnixFile
|
|
*/
|
|
HFILE32 FILE_OpenUnixFile( const char *name, int mode )
|
|
{
|
|
HFILE32 handle;
|
|
FILE_OBJECT *file;
|
|
struct stat st;
|
|
|
|
if ((handle = FILE_Alloc( &file )) == INVALID_HANDLE_VALUE32)
|
|
return INVALID_HANDLE_VALUE32;
|
|
|
|
if ((file->unix_handle = open( name, mode, 0666 )) == -1)
|
|
{
|
|
if (!Options.failReadOnly && (mode == O_RDWR))
|
|
file->unix_handle = open( name, O_RDONLY );
|
|
}
|
|
if ((file->unix_handle == -1) || (fstat( file->unix_handle, &st ) == -1))
|
|
{
|
|
FILE_SetDosError();
|
|
CloseHandle( handle );
|
|
return INVALID_HANDLE_VALUE32;
|
|
}
|
|
if (S_ISDIR(st.st_mode))
|
|
{
|
|
DOS_ERROR( ER_AccessDenied, EC_AccessDenied, SA_Abort, EL_Disk );
|
|
CloseHandle( handle );
|
|
return INVALID_HANDLE_VALUE32;
|
|
}
|
|
|
|
/* File opened OK, now fill the FILE_OBJECT */
|
|
|
|
file->unix_name = HEAP_strdupA( SystemHeap, 0, name );
|
|
return handle;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_Open
|
|
*/
|
|
HFILE32 FILE_Open( LPCSTR path, INT32 mode )
|
|
{
|
|
DOS_FULL_NAME full_name;
|
|
const char *unixName;
|
|
|
|
TRACE(file, "'%s' %04x\n", path, mode );
|
|
|
|
if (!path) return HFILE_ERROR32;
|
|
|
|
if (DOSFS_GetDevice( path ))
|
|
{
|
|
HFILE32 ret;
|
|
|
|
TRACE(file, "opening device '%s'\n", path );
|
|
|
|
if (HFILE_ERROR32!=(ret=DOSFS_OpenDevice( path, mode )))
|
|
return ret;
|
|
|
|
/* Do not silence this please. It is a critical error. -MM */
|
|
ERR(file, "Couldn't open device '%s'!\n",path);
|
|
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
|
|
return HFILE_ERROR32;
|
|
|
|
}
|
|
else /* check for filename, don't check for last entry if creating */
|
|
{
|
|
if (!DOSFS_GetFullName( path, !(mode & O_CREAT), &full_name ))
|
|
return HFILE_ERROR32;
|
|
unixName = full_name.long_name;
|
|
}
|
|
return FILE_OpenUnixFile( unixName, mode );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_Create
|
|
*/
|
|
static HFILE32 FILE_Create( LPCSTR path, int mode, int unique )
|
|
{
|
|
HFILE32 handle;
|
|
FILE_OBJECT *file;
|
|
DOS_FULL_NAME full_name;
|
|
|
|
TRACE(file, "'%s' %04x %d\n", path, mode, unique );
|
|
|
|
if (!path) return INVALID_HANDLE_VALUE32;
|
|
|
|
if (DOSFS_GetDevice( path ))
|
|
{
|
|
WARN(file, "cannot create DOS device '%s'!\n", path);
|
|
DOS_ERROR( ER_AccessDenied, EC_NotFound, SA_Abort, EL_Disk );
|
|
return INVALID_HANDLE_VALUE32;
|
|
}
|
|
|
|
if ((handle = FILE_Alloc( &file )) == INVALID_HANDLE_VALUE32)
|
|
return INVALID_HANDLE_VALUE32;
|
|
|
|
if (!DOSFS_GetFullName( path, FALSE, &full_name ))
|
|
{
|
|
CloseHandle( handle );
|
|
return INVALID_HANDLE_VALUE32;
|
|
}
|
|
if ((file->unix_handle = open( full_name.long_name,
|
|
O_CREAT | O_TRUNC | O_RDWR | (unique ? O_EXCL : 0),
|
|
mode )) == -1)
|
|
{
|
|
FILE_SetDosError();
|
|
CloseHandle( handle );
|
|
return INVALID_HANDLE_VALUE32;
|
|
}
|
|
|
|
/* File created OK, now fill the FILE_OBJECT */
|
|
|
|
file->unix_name = HEAP_strdupA( SystemHeap, 0, full_name.long_name );
|
|
return handle;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_FillInfo
|
|
*
|
|
* Fill a file information from a struct stat.
|
|
*/
|
|
static void FILE_FillInfo( struct stat *st, BY_HANDLE_FILE_INFORMATION *info )
|
|
{
|
|
if (S_ISDIR(st->st_mode))
|
|
info->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
|
|
else
|
|
info->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE;
|
|
if (!(st->st_mode & S_IWUSR))
|
|
info->dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
|
|
|
|
DOSFS_UnixTimeToFileTime( st->st_mtime, &info->ftCreationTime, 0 );
|
|
DOSFS_UnixTimeToFileTime( st->st_mtime, &info->ftLastWriteTime, 0 );
|
|
DOSFS_UnixTimeToFileTime( st->st_atime, &info->ftLastAccessTime, 0 );
|
|
|
|
info->dwVolumeSerialNumber = 0; /* FIXME */
|
|
info->nFileSizeHigh = 0;
|
|
info->nFileSizeLow = S_ISDIR(st->st_mode) ? 0 : st->st_size;
|
|
info->nNumberOfLinks = st->st_nlink;
|
|
info->nFileIndexHigh = 0;
|
|
info->nFileIndexLow = st->st_ino;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_Stat
|
|
*
|
|
* Stat a Unix path name. Return TRUE if OK.
|
|
*/
|
|
BOOL32 FILE_Stat( LPCSTR unixName, BY_HANDLE_FILE_INFORMATION *info )
|
|
{
|
|
struct stat st;
|
|
|
|
if (!unixName || !info) return FALSE;
|
|
|
|
if (stat( unixName, &st ) == -1)
|
|
{
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
FILE_FillInfo( &st, info );
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetFileInformationByHandle (KERNEL32.219)
|
|
*/
|
|
DWORD WINAPI GetFileInformationByHandle( HFILE32 hFile,
|
|
BY_HANDLE_FILE_INFORMATION *info )
|
|
{
|
|
FILE_OBJECT *file;
|
|
DWORD ret = 0;
|
|
struct stat st;
|
|
|
|
if (!info) return 0;
|
|
|
|
if (!(file = FILE_GetFile( hFile ))) return 0;
|
|
if (fstat( file->unix_handle, &st ) == -1) FILE_SetDosError();
|
|
else
|
|
{
|
|
FILE_FillInfo( &st, info );
|
|
ret = 1;
|
|
}
|
|
FILE_ReleaseFile( file );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* GetFileAttributes16 (KERNEL.420)
|
|
*/
|
|
DWORD WINAPI GetFileAttributes16( LPCSTR name )
|
|
{
|
|
return GetFileAttributes32A( name );
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* GetFileAttributes32A (KERNEL32.217)
|
|
*/
|
|
DWORD WINAPI GetFileAttributes32A( LPCSTR name )
|
|
{
|
|
DOS_FULL_NAME full_name;
|
|
BY_HANDLE_FILE_INFORMATION info;
|
|
|
|
if (name == NULL || *name=='\0') return -1;
|
|
|
|
if (!DOSFS_GetFullName( name, TRUE, &full_name )) return -1;
|
|
if (!FILE_Stat( full_name.long_name, &info )) return -1;
|
|
return info.dwFileAttributes;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* GetFileAttributes32W (KERNEL32.218)
|
|
*/
|
|
DWORD WINAPI GetFileAttributes32W( LPCWSTR name )
|
|
{
|
|
LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, name );
|
|
DWORD res = GetFileAttributes32A( nameA );
|
|
HeapFree( GetProcessHeap(), 0, nameA );
|
|
return res;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetFileSize (KERNEL32.220)
|
|
*/
|
|
DWORD WINAPI GetFileSize( HFILE32 hFile, LPDWORD filesizehigh )
|
|
{
|
|
BY_HANDLE_FILE_INFORMATION info;
|
|
if (!GetFileInformationByHandle( hFile, &info )) return 0;
|
|
if (filesizehigh) *filesizehigh = info.nFileSizeHigh;
|
|
return info.nFileSizeLow;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetFileTime (KERNEL32.221)
|
|
*/
|
|
BOOL32 WINAPI GetFileTime( HFILE32 hFile, FILETIME *lpCreationTime,
|
|
FILETIME *lpLastAccessTime,
|
|
FILETIME *lpLastWriteTime )
|
|
{
|
|
BY_HANDLE_FILE_INFORMATION info;
|
|
if (!GetFileInformationByHandle( hFile, &info )) return FALSE;
|
|
if (lpCreationTime) *lpCreationTime = info.ftCreationTime;
|
|
if (lpLastAccessTime) *lpLastAccessTime = info.ftLastAccessTime;
|
|
if (lpLastWriteTime) *lpLastWriteTime = info.ftLastWriteTime;
|
|
return TRUE;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* CompareFileTime (KERNEL32.28)
|
|
*/
|
|
INT32 WINAPI CompareFileTime( LPFILETIME x, LPFILETIME y )
|
|
{
|
|
if (!x || !y) return -1;
|
|
|
|
if (x->dwHighDateTime > y->dwHighDateTime)
|
|
return 1;
|
|
if (x->dwHighDateTime < y->dwHighDateTime)
|
|
return -1;
|
|
if (x->dwLowDateTime > y->dwLowDateTime)
|
|
return 1;
|
|
if (x->dwLowDateTime < y->dwLowDateTime)
|
|
return -1;
|
|
return 0;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* FILE_Dup
|
|
*
|
|
* dup() function for DOS handles.
|
|
*/
|
|
HFILE32 FILE_Dup( HFILE32 hFile )
|
|
{
|
|
HFILE32 handle;
|
|
|
|
TRACE(file, "FILE_Dup for handle %d\n", hFile );
|
|
if (!DuplicateHandle( GetCurrentProcess(), hFile, GetCurrentProcess(),
|
|
&handle, FILE_ALL_ACCESS /* FIXME */, FALSE, 0 ))
|
|
handle = HFILE_ERROR32;
|
|
TRACE(file, "FILE_Dup return handle %d\n", handle );
|
|
return handle;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_Dup2
|
|
*
|
|
* dup2() function for DOS handles.
|
|
*/
|
|
HFILE32 FILE_Dup2( HFILE32 hFile1, HFILE32 hFile2 )
|
|
{
|
|
FILE_OBJECT *file;
|
|
|
|
TRACE(file, "FILE_Dup2 for handle %d\n", hFile1 );
|
|
/* FIXME: should use DuplicateHandle */
|
|
if (!(file = FILE_GetFile( hFile1 ))) return HFILE_ERROR32;
|
|
if (!HANDLE_SetObjPtr( PROCESS_Current(), hFile2, &file->header, 0 ))
|
|
hFile2 = HFILE_ERROR32;
|
|
FILE_ReleaseFile( file );
|
|
return hFile2;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetTempFileName16 (KERNEL.97)
|
|
*/
|
|
UINT16 WINAPI GetTempFileName16( BYTE drive, LPCSTR prefix, UINT16 unique,
|
|
LPSTR buffer )
|
|
{
|
|
char temppath[144];
|
|
|
|
if (!(drive & ~TF_FORCEDRIVE)) /* drive 0 means current default drive */
|
|
drive |= DRIVE_GetCurrentDrive() + 'A';
|
|
|
|
if ((drive & TF_FORCEDRIVE) &&
|
|
!DRIVE_IsValid( toupper(drive & ~TF_FORCEDRIVE) - 'A' ))
|
|
{
|
|
drive &= ~TF_FORCEDRIVE;
|
|
WARN(file, "invalid drive %d specified\n", drive );
|
|
}
|
|
|
|
if (drive & TF_FORCEDRIVE)
|
|
sprintf(temppath,"%c:", drive & ~TF_FORCEDRIVE );
|
|
else
|
|
GetTempPath32A( 132, temppath );
|
|
return (UINT16)GetTempFileName32A( temppath, prefix, unique, buffer );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetTempFileName32A (KERNEL32.290)
|
|
*/
|
|
UINT32 WINAPI GetTempFileName32A( LPCSTR path, LPCSTR prefix, UINT32 unique,
|
|
LPSTR buffer)
|
|
{
|
|
DOS_FULL_NAME full_name;
|
|
int i;
|
|
LPSTR p;
|
|
UINT32 num = unique ? (unique & 0xffff) : time(NULL) & 0xffff;
|
|
|
|
if ( !path || !prefix || !buffer ) return 0;
|
|
|
|
strcpy( buffer, path );
|
|
p = buffer + strlen(buffer);
|
|
|
|
/* add a \, if there isn't one and path is more than just the drive letter ... */
|
|
if ( !((strlen(buffer) == 2) && (buffer[1] == ':'))
|
|
&& ((p == buffer) || (p[-1] != '\\'))) *p++ = '\\';
|
|
|
|
*p++ = '~';
|
|
for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++;
|
|
sprintf( p, "%04x.tmp", num );
|
|
|
|
/* Now try to create it */
|
|
|
|
if (!unique)
|
|
{
|
|
do
|
|
{
|
|
HFILE32 handle = FILE_Create( buffer, 0666, TRUE );
|
|
if (handle != INVALID_HANDLE_VALUE32)
|
|
{ /* We created it */
|
|
TRACE(file, "created %s\n",
|
|
buffer);
|
|
CloseHandle( handle );
|
|
break;
|
|
}
|
|
if (DOS_ExtendedError != ER_FileExists)
|
|
break; /* No need to go on */
|
|
num++;
|
|
sprintf( p, "%04x.tmp", num );
|
|
} while (num != (unique & 0xffff));
|
|
}
|
|
|
|
/* Get the full path name */
|
|
|
|
if (DOSFS_GetFullName( buffer, FALSE, &full_name ))
|
|
{
|
|
/* Check if we have write access in the directory */
|
|
if ((p = strrchr( full_name.long_name, '/' ))) *p = '\0';
|
|
if (access( full_name.long_name, W_OK ) == -1)
|
|
WARN(file, "returns '%s', which doesn't seem to be writeable.\n",
|
|
buffer);
|
|
}
|
|
TRACE(file, "returning %s\n", buffer );
|
|
return unique ? unique : num;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetTempFileName32W (KERNEL32.291)
|
|
*/
|
|
UINT32 WINAPI GetTempFileName32W( LPCWSTR path, LPCWSTR prefix, UINT32 unique,
|
|
LPWSTR buffer )
|
|
{
|
|
LPSTR patha,prefixa;
|
|
char buffera[144];
|
|
UINT32 ret;
|
|
|
|
if (!path) return 0;
|
|
patha = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
|
|
prefixa = HEAP_strdupWtoA( GetProcessHeap(), 0, prefix );
|
|
ret = GetTempFileName32A( patha, prefixa, unique, buffera );
|
|
lstrcpyAtoW( buffer, buffera );
|
|
HeapFree( GetProcessHeap(), 0, patha );
|
|
HeapFree( GetProcessHeap(), 0, prefixa );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_DoOpenFile
|
|
*
|
|
* Implementation of OpenFile16() and OpenFile32().
|
|
*/
|
|
static HFILE32 FILE_DoOpenFile( LPCSTR name, OFSTRUCT *ofs, UINT32 mode,
|
|
BOOL32 win32 )
|
|
{
|
|
HFILE32 hFileRet;
|
|
FILETIME filetime;
|
|
WORD filedatetime[2];
|
|
DOS_FULL_NAME full_name;
|
|
char *p;
|
|
int unixMode;
|
|
|
|
if (!ofs) return HFILE_ERROR32;
|
|
|
|
|
|
ofs->cBytes = sizeof(OFSTRUCT);
|
|
ofs->nErrCode = 0;
|
|
if (mode & OF_REOPEN) name = ofs->szPathName;
|
|
|
|
if (!name) {
|
|
ERR(file, "called with `name' set to NULL ! Please debug.\n");
|
|
return HFILE_ERROR32;
|
|
}
|
|
|
|
TRACE(file, "%s %04x\n", name, mode );
|
|
|
|
/* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
|
|
Are there any cases where getting the path here is wrong?
|
|
Uwe Bonnes 1997 Apr 2 */
|
|
if (!GetFullPathName32A( name, sizeof(ofs->szPathName),
|
|
ofs->szPathName, NULL )) goto error;
|
|
|
|
/* OF_PARSE simply fills the structure */
|
|
|
|
if (mode & OF_PARSE)
|
|
{
|
|
ofs->fFixedDisk = (GetDriveType16( ofs->szPathName[0]-'A' )
|
|
!= DRIVE_REMOVABLE);
|
|
TRACE(file, "(%s): OF_PARSE, res = '%s'\n",
|
|
name, ofs->szPathName );
|
|
return 0;
|
|
}
|
|
|
|
/* OF_CREATE is completely different from all other options, so
|
|
handle it first */
|
|
|
|
if (mode & OF_CREATE)
|
|
{
|
|
if ((hFileRet = FILE_Create(name,0666,FALSE))== INVALID_HANDLE_VALUE32)
|
|
goto error;
|
|
goto success;
|
|
}
|
|
|
|
/* If OF_SEARCH is set, ignore the given path */
|
|
|
|
if ((mode & OF_SEARCH) && !(mode & OF_REOPEN))
|
|
{
|
|
/* First try the file name as is */
|
|
if (DOSFS_GetFullName( name, TRUE, &full_name )) goto found;
|
|
/* Now remove the path */
|
|
if (name[0] && (name[1] == ':')) name += 2;
|
|
if ((p = strrchr( name, '\\' ))) name = p + 1;
|
|
if ((p = strrchr( name, '/' ))) name = p + 1;
|
|
if (!name[0]) goto not_found;
|
|
}
|
|
|
|
/* Now look for the file */
|
|
|
|
if (!DIR_SearchPath( NULL, name, NULL, &full_name, win32 )) goto not_found;
|
|
|
|
found:
|
|
TRACE(file, "found %s = %s\n",
|
|
full_name.long_name, full_name.short_name );
|
|
lstrcpyn32A( ofs->szPathName, full_name.short_name,
|
|
sizeof(ofs->szPathName) );
|
|
|
|
if (mode & OF_SHARE_EXCLUSIVE)
|
|
{
|
|
char *last = strrchr(full_name.long_name,'/');
|
|
if (!last)
|
|
last = full_name.long_name - 1;
|
|
/* Some InstallShield version uses OF_SHARE_EXCLUSIVE
|
|
on the file <tempdir>/_ins0432._mp to determine how
|
|
far installation has proceeded*/
|
|
if (GetModuleHandle16(last+1))
|
|
{
|
|
TRACE(file,"Denying shared open for %s\n",full_name.long_name);
|
|
return HFILE_ERROR32;
|
|
}
|
|
FIXME(file,"OF_SHARE_EXCLUSIVE only partial implemented\n");
|
|
}
|
|
|
|
if (mode & OF_DELETE)
|
|
{
|
|
if (unlink( full_name.long_name ) == -1) goto not_found;
|
|
TRACE(file, "(%s): OF_DELETE return = OK\n", name);
|
|
return 1;
|
|
}
|
|
|
|
switch(mode & 3)
|
|
{
|
|
case OF_WRITE:
|
|
unixMode = O_WRONLY; break;
|
|
case OF_READWRITE:
|
|
unixMode = O_RDWR; break;
|
|
case OF_READ:
|
|
default:
|
|
unixMode = O_RDONLY; break;
|
|
}
|
|
|
|
hFileRet = FILE_OpenUnixFile( full_name.long_name, unixMode );
|
|
if (hFileRet == HFILE_ERROR32) goto not_found;
|
|
GetFileTime( hFileRet, NULL, NULL, &filetime );
|
|
FileTimeToDosDateTime( &filetime, &filedatetime[0], &filedatetime[1] );
|
|
if ((mode & OF_VERIFY) && (mode & OF_REOPEN))
|
|
{
|
|
if (memcmp( ofs->reserved, filedatetime, sizeof(ofs->reserved) ))
|
|
{
|
|
CloseHandle( hFileRet );
|
|
WARN(file, "(%s): OF_VERIFY failed\n", name );
|
|
/* FIXME: what error here? */
|
|
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
|
|
goto error;
|
|
}
|
|
}
|
|
memcpy( ofs->reserved, filedatetime, sizeof(ofs->reserved) );
|
|
|
|
success: /* We get here if the open was successful */
|
|
TRACE(file, "(%s): OK, return = %d\n", name, hFileRet );
|
|
if (mode & OF_EXIST) /* Return the handle, but close it first */
|
|
CloseHandle( hFileRet );
|
|
return hFileRet;
|
|
|
|
not_found: /* We get here if the file does not exist */
|
|
WARN(file, "'%s' not found\n", name );
|
|
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
|
|
/* fall through */
|
|
|
|
error: /* We get here if there was an error opening the file */
|
|
ofs->nErrCode = DOS_ExtendedError;
|
|
WARN(file, "(%s): return = HFILE_ERROR error= %d\n",
|
|
name,ofs->nErrCode );
|
|
return HFILE_ERROR32;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* OpenFile16 (KERNEL.74)
|
|
*/
|
|
HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
|
|
{
|
|
TRACE(file,"OpenFile16(%s,%i)\n", name, mode);
|
|
return HFILE32_TO_HFILE16(FILE_DoOpenFile( name, ofs, mode, FALSE ));
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* OpenFile32 (KERNEL32.396)
|
|
*/
|
|
HFILE32 WINAPI OpenFile32( LPCSTR name, OFSTRUCT *ofs, UINT32 mode )
|
|
{
|
|
return FILE_DoOpenFile( name, ofs, mode, TRUE );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lclose16 (KERNEL.81)
|
|
*/
|
|
HFILE16 WINAPI _lclose16( HFILE16 hFile )
|
|
{
|
|
TRACE(file, "handle %d\n", hFile );
|
|
return CloseHandle( HFILE16_TO_HFILE32( hFile ) ) ? 0 : HFILE_ERROR16;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lclose32 (KERNEL32.592)
|
|
*/
|
|
HFILE32 WINAPI _lclose32( HFILE32 hFile )
|
|
{
|
|
TRACE(file, "handle %d\n", hFile );
|
|
return CloseHandle( hFile ) ? 0 : HFILE_ERROR32;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* WIN16_hread
|
|
*/
|
|
LONG WINAPI WIN16_hread( HFILE16 hFile, SEGPTR buffer, LONG count )
|
|
{
|
|
LONG maxlen;
|
|
|
|
TRACE(file, "%d %08lx %ld\n",
|
|
hFile, (DWORD)buffer, count );
|
|
|
|
/* Some programs pass a count larger than the allocated buffer */
|
|
maxlen = GetSelectorLimit( SELECTOROF(buffer) ) - OFFSETOF(buffer) + 1;
|
|
if (count > maxlen) count = maxlen;
|
|
return _lread32(HFILE16_TO_HFILE32(hFile), PTR_SEG_TO_LIN(buffer), count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* WIN16_lread
|
|
*/
|
|
UINT16 WINAPI WIN16_lread( HFILE16 hFile, SEGPTR buffer, UINT16 count )
|
|
{
|
|
return (UINT16)WIN16_hread( hFile, buffer, (LONG)count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lread32 (KERNEL32.596)
|
|
*/
|
|
UINT32 WINAPI _lread32( HFILE32 handle, LPVOID buffer, UINT32 count )
|
|
{
|
|
K32OBJ *ptr;
|
|
DWORD numWritten;
|
|
BOOL32 result = FALSE;
|
|
|
|
TRACE( file, "%d %p %d\n", handle, buffer, count);
|
|
if (!(ptr = HANDLE_GetObjPtr( PROCESS_Current(), handle,
|
|
K32OBJ_UNKNOWN, 0, NULL))) return -1;
|
|
if (K32OBJ_OPS(ptr)->read)
|
|
result = K32OBJ_OPS(ptr)->read(ptr, buffer, count, &numWritten, NULL);
|
|
K32OBJ_DecCount( ptr );
|
|
if (!result) return -1;
|
|
return (UINT32)numWritten;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lread16 (KERNEL.82)
|
|
*/
|
|
UINT16 WINAPI _lread16( HFILE16 hFile, LPVOID buffer, UINT16 count )
|
|
{
|
|
return (UINT16)_lread32(HFILE16_TO_HFILE32(hFile), buffer, (LONG)count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lcreat16 (KERNEL.83)
|
|
*/
|
|
HFILE16 WINAPI _lcreat16( LPCSTR path, INT16 attr )
|
|
{
|
|
int mode = (attr & 1) ? 0444 : 0666;
|
|
TRACE(file, "%s %02x\n", path, attr );
|
|
return (HFILE16) HFILE32_TO_HFILE16(FILE_Create( path, mode, FALSE ));
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lcreat32 (KERNEL32.593)
|
|
*/
|
|
HFILE32 WINAPI _lcreat32( LPCSTR path, INT32 attr )
|
|
{
|
|
int mode = (attr & 1) ? 0444 : 0666;
|
|
TRACE(file, "%s %02x\n", path, attr );
|
|
return FILE_Create( path, mode, FALSE );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lcreat_uniq (Not a Windows API)
|
|
*/
|
|
HFILE32 _lcreat_uniq( LPCSTR path, INT32 attr )
|
|
{
|
|
int mode = (attr & 1) ? 0444 : 0666;
|
|
TRACE(file, "%s %02x\n", path, attr );
|
|
return FILE_Create( path, mode, TRUE );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* SetFilePointer (KERNEL32.492)
|
|
*/
|
|
DWORD WINAPI SetFilePointer( HFILE32 hFile, LONG distance, LONG *highword,
|
|
DWORD method )
|
|
{
|
|
FILE_OBJECT *file;
|
|
DWORD result = 0xffffffff;
|
|
|
|
if (highword && *highword)
|
|
{
|
|
FIXME(file, "64-bit offsets not supported yet\n");
|
|
SetLastError( ERROR_INVALID_PARAMETER );
|
|
return 0xffffffff;
|
|
}
|
|
TRACE(file, "handle %d offset %ld origin %ld\n",
|
|
hFile, distance, method );
|
|
|
|
if (!(file = FILE_GetFile( hFile ))) return 0xffffffff;
|
|
|
|
|
|
/* the pointer may be positioned before the start of the file;
|
|
no error is returned in that case,
|
|
but subsequent attempts at I/O will produce errors.
|
|
This is not allowed with Unix lseek(),
|
|
so we'll need some emulation here */
|
|
switch(method)
|
|
{
|
|
case FILE_CURRENT:
|
|
distance += file->pos; /* fall through */
|
|
case FILE_BEGIN:
|
|
if ((result = lseek(file->unix_handle, distance, SEEK_SET)) == -1)
|
|
{
|
|
if ((INT32)distance < 0)
|
|
file->pos = result = distance;
|
|
}
|
|
else
|
|
file->pos = result;
|
|
break;
|
|
case FILE_END:
|
|
if ((result = lseek(file->unix_handle, distance, SEEK_END)) == -1)
|
|
{
|
|
if ((INT32)distance < 0)
|
|
{
|
|
/* get EOF */
|
|
result = lseek(file->unix_handle, 0, SEEK_END);
|
|
|
|
/* return to the old pos, as the first lseek failed */
|
|
lseek(file->unix_handle, file->pos, SEEK_END);
|
|
|
|
file->pos = (result += distance);
|
|
}
|
|
else
|
|
ERR(file, "lseek: unknown error. Please report.\n");
|
|
}
|
|
else file->pos = result;
|
|
break;
|
|
default:
|
|
ERR(file, "Unknown origin %ld !\n", method);
|
|
}
|
|
|
|
if (result == -1)
|
|
FILE_SetDosError();
|
|
|
|
FILE_ReleaseFile( file );
|
|
return result;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _llseek16 (KERNEL.84)
|
|
*/
|
|
LONG WINAPI _llseek16( HFILE16 hFile, LONG lOffset, INT16 nOrigin )
|
|
{
|
|
return SetFilePointer( HFILE16_TO_HFILE32(hFile), lOffset, NULL, nOrigin );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _llseek32 (KERNEL32.594)
|
|
*/
|
|
LONG WINAPI _llseek32( HFILE32 hFile, LONG lOffset, INT32 nOrigin )
|
|
{
|
|
return SetFilePointer( hFile, lOffset, NULL, nOrigin );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lopen16 (KERNEL.85)
|
|
*/
|
|
HFILE16 WINAPI _lopen16( LPCSTR path, INT16 mode )
|
|
{
|
|
return HFILE32_TO_HFILE16(_lopen32( path, mode ));
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lopen32 (KERNEL32.595)
|
|
*/
|
|
HFILE32 WINAPI _lopen32( LPCSTR path, INT32 mode )
|
|
{
|
|
INT32 unixMode;
|
|
|
|
TRACE(file, "('%s',%04x)\n", path, mode );
|
|
|
|
switch(mode & 3)
|
|
{
|
|
case OF_WRITE:
|
|
unixMode = O_WRONLY;
|
|
break;
|
|
case OF_READWRITE:
|
|
unixMode = O_RDWR;
|
|
break;
|
|
case OF_READ:
|
|
default:
|
|
unixMode = O_RDONLY;
|
|
break;
|
|
}
|
|
return FILE_Open( path, unixMode );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _lwrite16 (KERNEL.86)
|
|
*/
|
|
UINT16 WINAPI _lwrite16( HFILE16 hFile, LPCSTR buffer, UINT16 count )
|
|
{
|
|
return (UINT16)_hwrite32( HFILE16_TO_HFILE32(hFile), buffer, (LONG)count );
|
|
}
|
|
|
|
/***********************************************************************
|
|
* _lwrite32 (KERNEL.86)
|
|
*/
|
|
UINT32 WINAPI _lwrite32( HFILE32 hFile, LPCSTR buffer, UINT32 count )
|
|
{
|
|
return (UINT32)_hwrite32( hFile, buffer, (LONG)count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _hread16 (KERNEL.349)
|
|
*/
|
|
LONG WINAPI _hread16( HFILE16 hFile, LPVOID buffer, LONG count)
|
|
{
|
|
return _lread32( HFILE16_TO_HFILE32(hFile), buffer, count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _hread32 (KERNEL32.590)
|
|
*/
|
|
LONG WINAPI _hread32( HFILE32 hFile, LPVOID buffer, LONG count)
|
|
{
|
|
return _lread32( hFile, buffer, count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _hwrite16 (KERNEL.350)
|
|
*/
|
|
LONG WINAPI _hwrite16( HFILE16 hFile, LPCSTR buffer, LONG count )
|
|
{
|
|
return _hwrite32( HFILE16_TO_HFILE32(hFile), buffer, count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* _hwrite32 (KERNEL32.591)
|
|
*
|
|
* experimenation yields that _lwrite:
|
|
* o truncates the file at the current position with
|
|
* a 0 len write
|
|
* o returns 0 on a 0 length write
|
|
* o works with console handles
|
|
*
|
|
*/
|
|
LONG WINAPI _hwrite32( HFILE32 handle, LPCSTR buffer, LONG count )
|
|
{
|
|
K32OBJ *ioptr;
|
|
DWORD result;
|
|
BOOL32 status = FALSE;
|
|
|
|
TRACE(file, "%d %p %ld\n", handle, buffer, count );
|
|
|
|
if (count == 0) { /* Expand or truncate at current position */
|
|
FILE_OBJECT *file = FILE_GetFile(handle);
|
|
|
|
if ( ftruncate(file->unix_handle,
|
|
lseek( file->unix_handle, 0, SEEK_CUR)) == 0 ) {
|
|
FILE_ReleaseFile(file);
|
|
return 0;
|
|
} else {
|
|
FILE_SetDosError();
|
|
FILE_ReleaseFile(file);
|
|
return HFILE_ERROR32;
|
|
}
|
|
}
|
|
|
|
if (!(ioptr = HANDLE_GetObjPtr( PROCESS_Current(), handle,
|
|
K32OBJ_UNKNOWN, 0, NULL )))
|
|
return HFILE_ERROR32;
|
|
if (K32OBJ_OPS(ioptr)->write)
|
|
status = K32OBJ_OPS(ioptr)->write(ioptr, buffer, count, &result, NULL);
|
|
K32OBJ_DecCount( ioptr );
|
|
if (!status) result = HFILE_ERROR32;
|
|
return result;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* SetHandleCount16 (KERNEL.199)
|
|
*/
|
|
UINT16 WINAPI SetHandleCount16( UINT16 count )
|
|
{
|
|
HGLOBAL16 hPDB = GetCurrentPDB();
|
|
PDB *pdb = (PDB *)GlobalLock16( hPDB );
|
|
BYTE *files = PTR_SEG_TO_LIN( pdb->fileHandlesPtr );
|
|
|
|
TRACE(file, "(%d)\n", count );
|
|
|
|
if (count < 20) count = 20; /* No point in going below 20 */
|
|
else if (count > 254) count = 254;
|
|
|
|
if (count == 20)
|
|
{
|
|
if (pdb->nbFiles > 20)
|
|
{
|
|
memcpy( pdb->fileHandles, files, 20 );
|
|
GlobalFree16( pdb->hFileHandles );
|
|
pdb->fileHandlesPtr = (SEGPTR)MAKELONG( 0x18,
|
|
GlobalHandleToSel( hPDB ) );
|
|
pdb->hFileHandles = 0;
|
|
pdb->nbFiles = 20;
|
|
}
|
|
}
|
|
else /* More than 20, need a new file handles table */
|
|
{
|
|
BYTE *newfiles;
|
|
HGLOBAL16 newhandle = GlobalAlloc16( GMEM_MOVEABLE, count );
|
|
if (!newhandle)
|
|
{
|
|
DOS_ERROR( ER_OutOfMemory, EC_OutOfResource, SA_Abort, EL_Memory );
|
|
return pdb->nbFiles;
|
|
}
|
|
newfiles = (BYTE *)GlobalLock16( newhandle );
|
|
|
|
if (count > pdb->nbFiles)
|
|
{
|
|
memcpy( newfiles, files, pdb->nbFiles );
|
|
memset( newfiles + pdb->nbFiles, 0xff, count - pdb->nbFiles );
|
|
}
|
|
else memcpy( newfiles, files, count );
|
|
if (pdb->nbFiles > 20) GlobalFree16( pdb->hFileHandles );
|
|
pdb->fileHandlesPtr = WIN16_GlobalLock16( newhandle );
|
|
pdb->hFileHandles = newhandle;
|
|
pdb->nbFiles = count;
|
|
}
|
|
return pdb->nbFiles;
|
|
}
|
|
|
|
|
|
/*************************************************************************
|
|
* SetHandleCount32 (KERNEL32.494)
|
|
*/
|
|
UINT32 WINAPI SetHandleCount32( UINT32 count )
|
|
{
|
|
return MIN( 256, count );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FlushFileBuffers (KERNEL32.133)
|
|
*/
|
|
BOOL32 WINAPI FlushFileBuffers( HFILE32 hFile )
|
|
{
|
|
FILE_OBJECT *file;
|
|
BOOL32 ret;
|
|
|
|
TRACE(file, "(%d)\n", hFile );
|
|
if (!(file = FILE_GetFile( hFile ))) return FALSE;
|
|
if (fsync( file->unix_handle ) != -1) ret = TRUE;
|
|
else
|
|
{
|
|
FILE_SetDosError();
|
|
ret = FALSE;
|
|
}
|
|
FILE_ReleaseFile( file );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* SetEndOfFile (KERNEL32.483)
|
|
*/
|
|
BOOL32 WINAPI SetEndOfFile( HFILE32 hFile )
|
|
{
|
|
FILE_OBJECT *file;
|
|
BOOL32 ret = TRUE;
|
|
|
|
TRACE(file, "(%d)\n", hFile );
|
|
if (!(file = FILE_GetFile( hFile ))) return FALSE;
|
|
if (ftruncate( file->unix_handle,
|
|
lseek( file->unix_handle, 0, SEEK_CUR ) ))
|
|
{
|
|
FILE_SetDosError();
|
|
ret = FALSE;
|
|
}
|
|
FILE_ReleaseFile( file );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* DeleteFile16 (KERNEL.146)
|
|
*/
|
|
BOOL16 WINAPI DeleteFile16( LPCSTR path )
|
|
{
|
|
return DeleteFile32A( path );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* DeleteFile32A (KERNEL32.71)
|
|
*/
|
|
BOOL32 WINAPI DeleteFile32A( LPCSTR path )
|
|
{
|
|
DOS_FULL_NAME full_name;
|
|
|
|
TRACE(file, "'%s'\n", path );
|
|
|
|
if (DOSFS_GetDevice( path ))
|
|
{
|
|
WARN(file, "cannot remove DOS device '%s'!\n", path);
|
|
DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
|
|
return FALSE;
|
|
}
|
|
|
|
if (!DOSFS_GetFullName( path, TRUE, &full_name )) return FALSE;
|
|
if (unlink( full_name.long_name ) == -1)
|
|
{
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* DeleteFile32W (KERNEL32.72)
|
|
*/
|
|
BOOL32 WINAPI DeleteFile32W( LPCWSTR path )
|
|
{
|
|
LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, path );
|
|
BOOL32 ret = DeleteFile32A( xpath );
|
|
HeapFree( GetProcessHeap(), 0, xpath );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_SetFileType
|
|
*/
|
|
BOOL32 FILE_SetFileType( HFILE32 hFile, DWORD type )
|
|
{
|
|
FILE_OBJECT *file = FILE_GetFile( hFile );
|
|
if (!file) return FALSE;
|
|
file->type = type;
|
|
FILE_ReleaseFile( file );
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_mmap
|
|
*/
|
|
LPVOID FILE_mmap( HFILE32 hFile, LPVOID start,
|
|
DWORD size_high, DWORD size_low,
|
|
DWORD offset_high, DWORD offset_low,
|
|
int prot, int flags )
|
|
{
|
|
LPVOID ret;
|
|
FILE_OBJECT *file = FILE_GetFile( hFile );
|
|
if (!file) return (LPVOID)-1;
|
|
ret = FILE_dommap( file, start, size_high, size_low,
|
|
offset_high, offset_low, prot, flags );
|
|
FILE_ReleaseFile( file );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_dommap
|
|
*/
|
|
LPVOID FILE_dommap( FILE_OBJECT *file, LPVOID start,
|
|
DWORD size_high, DWORD size_low,
|
|
DWORD offset_high, DWORD offset_low,
|
|
int prot, int flags )
|
|
{
|
|
int fd = -1;
|
|
int pos;
|
|
LPVOID ret;
|
|
|
|
if (size_high || offset_high)
|
|
FIXME(file, "offsets larger than 4Gb not supported\n");
|
|
|
|
if (!file)
|
|
{
|
|
#ifdef MAP_ANON
|
|
flags |= MAP_ANON;
|
|
#else
|
|
static int fdzero = -1;
|
|
|
|
if (fdzero == -1)
|
|
{
|
|
if ((fdzero = open( "/dev/zero", O_RDONLY )) == -1)
|
|
{
|
|
perror( "/dev/zero: open" );
|
|
exit(1);
|
|
}
|
|
}
|
|
fd = fdzero;
|
|
#endif /* MAP_ANON */
|
|
/* Linux EINVAL's on us if we don't pass MAP_PRIVATE to an anon mmap */
|
|
#ifdef MAP_SHARED
|
|
flags &= ~MAP_SHARED;
|
|
#endif
|
|
#ifdef MAP_PRIVATE
|
|
flags |= MAP_PRIVATE;
|
|
#endif
|
|
}
|
|
else fd = file->unix_handle;
|
|
|
|
if ((ret = mmap( start, size_low, prot,
|
|
flags, fd, offset_low )) != (LPVOID)-1)
|
|
return ret;
|
|
|
|
/* mmap() failed; if this is because the file offset is not */
|
|
/* page-aligned (EINVAL), or because the underlying filesystem */
|
|
/* does not support mmap() (ENOEXEC), we do it by hand. */
|
|
|
|
if (!file) return ret;
|
|
if ((errno != ENOEXEC) && (errno != EINVAL)) return ret;
|
|
if (prot & PROT_WRITE)
|
|
{
|
|
/* We cannot fake shared write mappings */
|
|
#ifdef MAP_SHARED
|
|
if (flags & MAP_SHARED) return ret;
|
|
#endif
|
|
#ifdef MAP_PRIVATE
|
|
if (!(flags & MAP_PRIVATE)) return ret;
|
|
#endif
|
|
}
|
|
/* printf( "FILE_mmap: mmap failed (%d), faking it\n", errno );*/
|
|
/* Reserve the memory with an anonymous mmap */
|
|
ret = FILE_dommap( NULL, start, size_high, size_low, 0, 0,
|
|
PROT_READ | PROT_WRITE, flags );
|
|
if (ret == (LPVOID)-1) return ret;
|
|
/* Now read in the file */
|
|
if ((pos = lseek( fd, offset_low, SEEK_SET )) == -1)
|
|
{
|
|
FILE_munmap( ret, size_high, size_low );
|
|
return (LPVOID)-1;
|
|
}
|
|
read( fd, ret, size_low );
|
|
lseek( fd, pos, SEEK_SET ); /* Restore the file pointer */
|
|
mprotect( ret, size_low, prot ); /* Set the right protection */
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* FILE_munmap
|
|
*/
|
|
int FILE_munmap( LPVOID start, DWORD size_high, DWORD size_low )
|
|
{
|
|
if (size_high)
|
|
FIXME(file, "offsets larger than 4Gb not supported\n");
|
|
return munmap( start, size_low );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetFileType (KERNEL32.222)
|
|
*/
|
|
DWORD WINAPI GetFileType( HFILE32 hFile )
|
|
{
|
|
FILE_OBJECT *file = FILE_GetFile(hFile);
|
|
if (!file) return FILE_TYPE_UNKNOWN; /* FIXME: correct? */
|
|
FILE_ReleaseFile( file );
|
|
return file->type;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* MoveFileEx32A (KERNEL32.???)
|
|
*/
|
|
BOOL32 WINAPI MoveFileEx32A( LPCSTR fn1, LPCSTR fn2, DWORD flag )
|
|
{
|
|
DOS_FULL_NAME full_name1, full_name2;
|
|
int mode=0; /* mode == 1: use copy */
|
|
|
|
TRACE(file, "(%s,%s,%04lx)\n", fn1, fn2, flag);
|
|
|
|
if (!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) return FALSE;
|
|
if (fn2) { /* !fn2 means delete fn1 */
|
|
if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) return FALSE;
|
|
/* Source name and target path are valid */
|
|
if ( full_name1.drive != full_name2.drive)
|
|
/* use copy, if allowed */
|
|
if (!(flag & MOVEFILE_COPY_ALLOWED)) {
|
|
/* FIXME: Use right error code */
|
|
DOS_ERROR( ER_FileExists, EC_Exists, SA_Abort, EL_Disk );
|
|
return FALSE;
|
|
}
|
|
else mode =1;
|
|
if (DOSFS_GetFullName( fn2, TRUE, &full_name2 ))
|
|
/* target exists, check if we may overwrite */
|
|
if (!(flag & MOVEFILE_REPLACE_EXISTING)) {
|
|
/* FIXME: Use right error code */
|
|
DOS_ERROR( ER_AccessDenied, EC_AccessDenied, SA_Abort, EL_Disk );
|
|
return FALSE;
|
|
}
|
|
}
|
|
else /* fn2 == NULL means delete source */
|
|
if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) {
|
|
if (flag & MOVEFILE_COPY_ALLOWED) {
|
|
WARN(file, "Illegal flag\n");
|
|
DOS_ERROR( ER_GeneralFailure, EC_SystemFailure, SA_Abort,
|
|
EL_Unknown );
|
|
return FALSE;
|
|
}
|
|
/* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
|
|
Perhaps we should queue these command and execute it
|
|
when exiting... What about using on_exit(2)
|
|
*/
|
|
FIXME(file, "Please delete file '%s' when Wine has finished\n",
|
|
full_name1.long_name);
|
|
return TRUE;
|
|
}
|
|
else if (unlink( full_name1.long_name ) == -1)
|
|
{
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
else return TRUE; /* successfully deleted */
|
|
|
|
if (flag & MOVEFILE_DELAY_UNTIL_REBOOT) {
|
|
/* FIXME: (bon@elektron.ikp.physik.th-darmstadt.de 970706)
|
|
Perhaps we should queue these command and execute it
|
|
when exiting... What about using on_exit(2)
|
|
*/
|
|
FIXME(file,"Please move existing file '%s' to file '%s'"
|
|
"when Wine has finished\n",
|
|
full_name1.long_name, full_name2.long_name);
|
|
return TRUE;
|
|
}
|
|
|
|
if (!mode) /* move the file */
|
|
if (rename( full_name1.long_name, full_name2.long_name ) == -1)
|
|
{
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
else return TRUE;
|
|
else /* copy File */
|
|
return CopyFile32A(fn1, fn2, (!(flag & MOVEFILE_REPLACE_EXISTING)));
|
|
|
|
}
|
|
|
|
/**************************************************************************
|
|
* MoveFileEx32W (KERNEL32.???)
|
|
*/
|
|
BOOL32 WINAPI MoveFileEx32W( LPCWSTR fn1, LPCWSTR fn2, DWORD flag )
|
|
{
|
|
LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 );
|
|
LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 );
|
|
BOOL32 res = MoveFileEx32A( afn1, afn2, flag );
|
|
HeapFree( GetProcessHeap(), 0, afn1 );
|
|
HeapFree( GetProcessHeap(), 0, afn2 );
|
|
return res;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* MoveFile32A (KERNEL32.387)
|
|
*
|
|
* Move file or directory
|
|
*/
|
|
BOOL32 WINAPI MoveFile32A( LPCSTR fn1, LPCSTR fn2 )
|
|
{
|
|
DOS_FULL_NAME full_name1, full_name2;
|
|
struct stat fstat;
|
|
|
|
TRACE(file, "(%s,%s)\n", fn1, fn2 );
|
|
|
|
if (!DOSFS_GetFullName( fn1, TRUE, &full_name1 )) return FALSE;
|
|
if (DOSFS_GetFullName( fn2, TRUE, &full_name2 ))
|
|
/* The new name must not already exist */
|
|
return FALSE;
|
|
if (!DOSFS_GetFullName( fn2, FALSE, &full_name2 )) return FALSE;
|
|
|
|
if (full_name1.drive == full_name2.drive) /* move */
|
|
if (rename( full_name1.long_name, full_name2.long_name ) == -1)
|
|
{
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
else return TRUE;
|
|
else /*copy */ {
|
|
if (stat( full_name1.long_name, &fstat ))
|
|
{
|
|
WARN(file, "Invalid source file %s\n",
|
|
full_name1.long_name);
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
if (S_ISDIR(fstat.st_mode)) {
|
|
/* No Move for directories across file systems */
|
|
/* FIXME: Use right error code */
|
|
DOS_ERROR( ER_GeneralFailure, EC_SystemFailure, SA_Abort,
|
|
EL_Unknown );
|
|
return FALSE;
|
|
}
|
|
else
|
|
return CopyFile32A(fn1, fn2, TRUE); /*fail, if exist */
|
|
}
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* MoveFile32W (KERNEL32.390)
|
|
*/
|
|
BOOL32 WINAPI MoveFile32W( LPCWSTR fn1, LPCWSTR fn2 )
|
|
{
|
|
LPSTR afn1 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn1 );
|
|
LPSTR afn2 = HEAP_strdupWtoA( GetProcessHeap(), 0, fn2 );
|
|
BOOL32 res = MoveFile32A( afn1, afn2 );
|
|
HeapFree( GetProcessHeap(), 0, afn1 );
|
|
HeapFree( GetProcessHeap(), 0, afn2 );
|
|
return res;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* CopyFile32A (KERNEL32.36)
|
|
*/
|
|
BOOL32 WINAPI CopyFile32A( LPCSTR source, LPCSTR dest, BOOL32 fail_if_exists )
|
|
{
|
|
HFILE32 h1, h2;
|
|
BY_HANDLE_FILE_INFORMATION info;
|
|
UINT32 count;
|
|
BOOL32 ret = FALSE;
|
|
int mode;
|
|
char buffer[2048];
|
|
|
|
if ((h1 = _lopen32( source, OF_READ )) == HFILE_ERROR32) return FALSE;
|
|
if (!GetFileInformationByHandle( h1, &info ))
|
|
{
|
|
CloseHandle( h1 );
|
|
return FALSE;
|
|
}
|
|
mode = (info.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666;
|
|
if ((h2 = FILE_Create( dest, mode, fail_if_exists )) == HFILE_ERROR32)
|
|
{
|
|
CloseHandle( h1 );
|
|
return FALSE;
|
|
}
|
|
while ((count = _lread32( h1, buffer, sizeof(buffer) )) > 0)
|
|
{
|
|
char *p = buffer;
|
|
while (count > 0)
|
|
{
|
|
INT32 res = _lwrite32( h2, p, count );
|
|
if (res <= 0) goto done;
|
|
p += res;
|
|
count -= res;
|
|
}
|
|
}
|
|
ret = TRUE;
|
|
done:
|
|
CloseHandle( h1 );
|
|
CloseHandle( h2 );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* CopyFile32W (KERNEL32.37)
|
|
*/
|
|
BOOL32 WINAPI CopyFile32W( LPCWSTR source, LPCWSTR dest, BOOL32 fail_if_exists)
|
|
{
|
|
LPSTR sourceA = HEAP_strdupWtoA( GetProcessHeap(), 0, source );
|
|
LPSTR destA = HEAP_strdupWtoA( GetProcessHeap(), 0, dest );
|
|
BOOL32 ret = CopyFile32A( sourceA, destA, fail_if_exists );
|
|
HeapFree( GetProcessHeap(), 0, sourceA );
|
|
HeapFree( GetProcessHeap(), 0, destA );
|
|
return ret;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* SetFileTime (KERNEL32.650)
|
|
*/
|
|
BOOL32 WINAPI SetFileTime( HFILE32 hFile,
|
|
const FILETIME *lpCreationTime,
|
|
const FILETIME *lpLastAccessTime,
|
|
const FILETIME *lpLastWriteTime )
|
|
{
|
|
FILE_OBJECT *file = FILE_GetFile(hFile);
|
|
struct utimbuf utimbuf;
|
|
|
|
if (!file) return FILE_TYPE_UNKNOWN; /* FIXME: correct? */
|
|
TRACE(file,"('%s',%p,%p,%p)\n",
|
|
file->unix_name,
|
|
lpCreationTime,
|
|
lpLastAccessTime,
|
|
lpLastWriteTime
|
|
);
|
|
if (lpLastAccessTime)
|
|
utimbuf.actime = DOSFS_FileTimeToUnixTime(lpLastAccessTime, NULL);
|
|
else
|
|
utimbuf.actime = 0; /* FIXME */
|
|
if (lpLastWriteTime)
|
|
utimbuf.modtime = DOSFS_FileTimeToUnixTime(lpLastWriteTime, NULL);
|
|
else
|
|
utimbuf.modtime = 0; /* FIXME */
|
|
if (-1==utime(file->unix_name,&utimbuf))
|
|
{
|
|
MSG("Couldn't set the time for file '%s'. Insufficient permissions !?\n", file->unix_name);
|
|
FILE_ReleaseFile( file );
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
FILE_ReleaseFile( file );
|
|
return TRUE;
|
|
}
|
|
|
|
/* Locks need to be mirrored because unix file locking is based
|
|
* on the pid. Inside of wine there can be multiple WINE processes
|
|
* that share the same unix pid.
|
|
* Read's and writes should check these locks also - not sure
|
|
* how critical that is at this point (FIXME).
|
|
*/
|
|
|
|
static BOOL32 DOS_AddLock(FILE_OBJECT *file, struct flock *f)
|
|
{
|
|
DOS_FILE_LOCK *curr;
|
|
DWORD processId;
|
|
|
|
processId = GetCurrentProcessId();
|
|
|
|
/* check if lock overlaps a current lock for the same file */
|
|
for (curr = locks; curr; curr = curr->next) {
|
|
if (strcmp(curr->unix_name, file->unix_name) == 0) {
|
|
if ((f->l_start == curr->base) && (f->l_len == curr->len))
|
|
return TRUE;/* region is identic */
|
|
if ((f->l_start < (curr->base + curr->len)) &&
|
|
((f->l_start + f->l_len) > curr->base)) {
|
|
/* region overlaps */
|
|
return FALSE;
|
|
}
|
|
}
|
|
}
|
|
|
|
curr = HeapAlloc( SystemHeap, 0, sizeof(DOS_FILE_LOCK) );
|
|
curr->processId = GetCurrentProcessId();
|
|
curr->base = f->l_start;
|
|
curr->len = f->l_len;
|
|
curr->unix_name = HEAP_strdupA( SystemHeap, 0, file->unix_name);
|
|
curr->next = locks;
|
|
curr->dos_file = file;
|
|
locks = curr;
|
|
return TRUE;
|
|
}
|
|
|
|
static void DOS_RemoveFileLocks(FILE_OBJECT *file)
|
|
{
|
|
DWORD processId;
|
|
DOS_FILE_LOCK **curr;
|
|
DOS_FILE_LOCK *rem;
|
|
|
|
processId = GetCurrentProcessId();
|
|
curr = &locks;
|
|
while (*curr) {
|
|
if ((*curr)->dos_file == file) {
|
|
rem = *curr;
|
|
*curr = (*curr)->next;
|
|
HeapFree( SystemHeap, 0, rem->unix_name );
|
|
HeapFree( SystemHeap, 0, rem );
|
|
}
|
|
else
|
|
curr = &(*curr)->next;
|
|
}
|
|
}
|
|
|
|
static BOOL32 DOS_RemoveLock(FILE_OBJECT *file, struct flock *f)
|
|
{
|
|
DWORD processId;
|
|
DOS_FILE_LOCK **curr;
|
|
DOS_FILE_LOCK *rem;
|
|
|
|
processId = GetCurrentProcessId();
|
|
for (curr = &locks; *curr; curr = &(*curr)->next) {
|
|
if ((*curr)->processId == processId &&
|
|
(*curr)->dos_file == file &&
|
|
(*curr)->base == f->l_start &&
|
|
(*curr)->len == f->l_len) {
|
|
/* this is the same lock */
|
|
rem = *curr;
|
|
*curr = (*curr)->next;
|
|
HeapFree( SystemHeap, 0, rem->unix_name );
|
|
HeapFree( SystemHeap, 0, rem );
|
|
return TRUE;
|
|
}
|
|
}
|
|
/* no matching lock found */
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* LockFile (KERNEL32.511)
|
|
*/
|
|
BOOL32 WINAPI LockFile(
|
|
HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
|
|
DWORD nNumberOfBytesToLockLow,DWORD nNumberOfBytesToLockHigh )
|
|
{
|
|
struct flock f;
|
|
FILE_OBJECT *file;
|
|
|
|
TRACE(file, "handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
|
|
hFile, dwFileOffsetLow, dwFileOffsetHigh,
|
|
nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh);
|
|
|
|
if (dwFileOffsetHigh || nNumberOfBytesToLockHigh) {
|
|
FIXME(file, "Unimplemented bytes > 32bits\n");
|
|
return FALSE;
|
|
}
|
|
|
|
f.l_start = dwFileOffsetLow;
|
|
f.l_len = nNumberOfBytesToLockLow;
|
|
f.l_whence = SEEK_SET;
|
|
f.l_pid = 0;
|
|
f.l_type = F_WRLCK;
|
|
|
|
if (!(file = FILE_GetFile(hFile))) return FALSE;
|
|
|
|
/* shadow locks internally */
|
|
if (!DOS_AddLock(file, &f)) {
|
|
DOS_ERROR( ER_LockViolation, EC_AccessDenied, SA_Ignore, EL_Disk );
|
|
return FALSE;
|
|
}
|
|
|
|
/* FIXME: Unix locking commented out for now, doesn't work with Excel */
|
|
#ifdef USE_UNIX_LOCKS
|
|
if (fcntl(file->unix_handle, F_SETLK, &f) == -1) {
|
|
if (errno == EACCES || errno == EAGAIN) {
|
|
DOS_ERROR( ER_LockViolation, EC_AccessDenied, SA_Ignore, EL_Disk );
|
|
}
|
|
else {
|
|
FILE_SetDosError();
|
|
}
|
|
/* remove our internal copy of the lock */
|
|
DOS_RemoveLock(file, &f);
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* UnlockFile (KERNEL32.703)
|
|
*/
|
|
BOOL32 WINAPI UnlockFile(
|
|
HFILE32 hFile,DWORD dwFileOffsetLow,DWORD dwFileOffsetHigh,
|
|
DWORD nNumberOfBytesToUnlockLow,DWORD nNumberOfBytesToUnlockHigh )
|
|
{
|
|
FILE_OBJECT *file;
|
|
struct flock f;
|
|
|
|
TRACE(file, "handle %d offsetlow=%ld offsethigh=%ld nbyteslow=%ld nbyteshigh=%ld\n",
|
|
hFile, dwFileOffsetLow, dwFileOffsetHigh,
|
|
nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh);
|
|
|
|
if (dwFileOffsetHigh || nNumberOfBytesToUnlockHigh) {
|
|
WARN(file, "Unimplemented bytes > 32bits\n");
|
|
return FALSE;
|
|
}
|
|
|
|
f.l_start = dwFileOffsetLow;
|
|
f.l_len = nNumberOfBytesToUnlockLow;
|
|
f.l_whence = SEEK_SET;
|
|
f.l_pid = 0;
|
|
f.l_type = F_UNLCK;
|
|
|
|
if (!(file = FILE_GetFile(hFile))) return FALSE;
|
|
|
|
DOS_RemoveLock(file, &f); /* ok if fails - may be another wine */
|
|
|
|
/* FIXME: Unix locking commented out for now, doesn't work with Excel */
|
|
#ifdef USE_UNIX_LOCKS
|
|
if (fcntl(file->unix_handle, F_SETLK, &f) == -1) {
|
|
FILE_SetDosError();
|
|
return FALSE;
|
|
}
|
|
#endif
|
|
return TRUE;
|
|
}
|
|
|
|
/**************************************************************************
|
|
* GetFileAttributesEx32A [KERNEL32.874]
|
|
*/
|
|
BOOL32 WINAPI GetFileAttributesEx32A(
|
|
LPCSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId,
|
|
LPVOID lpFileInformation)
|
|
{
|
|
DOS_FULL_NAME full_name;
|
|
BY_HANDLE_FILE_INFORMATION info;
|
|
|
|
if (lpFileName == NULL) return FALSE;
|
|
if (lpFileInformation == NULL) return FALSE;
|
|
|
|
if (fInfoLevelId == GetFileExInfoStandard) {
|
|
LPWIN32_FILE_ATTRIBUTE_DATA lpFad =
|
|
(LPWIN32_FILE_ATTRIBUTE_DATA) lpFileInformation;
|
|
if (!DOSFS_GetFullName( lpFileName, TRUE, &full_name )) return FALSE;
|
|
if (!FILE_Stat( full_name.long_name, &info )) return FALSE;
|
|
|
|
lpFad->dwFileAttributes = info.dwFileAttributes;
|
|
lpFad->ftCreationTime = info.ftCreationTime;
|
|
lpFad->ftLastAccessTime = info.ftLastAccessTime;
|
|
lpFad->ftLastWriteTime = info.ftLastWriteTime;
|
|
lpFad->nFileSizeHigh = info.nFileSizeHigh;
|
|
lpFad->nFileSizeLow = info.nFileSizeLow;
|
|
}
|
|
else {
|
|
FIXME (file, "invalid info level %d!\n", fInfoLevelId);
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/**************************************************************************
|
|
* GetFileAttributesEx32W [KERNEL32.875]
|
|
*/
|
|
BOOL32 WINAPI GetFileAttributesEx32W(
|
|
LPCWSTR lpFileName, GET_FILEEX_INFO_LEVELS fInfoLevelId,
|
|
LPVOID lpFileInformation)
|
|
{
|
|
LPSTR nameA = HEAP_strdupWtoA( GetProcessHeap(), 0, lpFileName );
|
|
BOOL32 res =
|
|
GetFileAttributesEx32A( nameA, fInfoLevelId, lpFileInformation);
|
|
HeapFree( GetProcessHeap(), 0, nameA );
|
|
return res;
|
|
}
|
|
|
|
|