From ff0365290bbacc3e3de09611e91109195c1d5a1a Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Tue, 25 Nov 2003 01:51:07 +0000 Subject: [PATCH] Got rid of DRIVE_OpenDevice, and replaced it with Win32 equivalents. --- dlls/kernel/kernel32.spec | 1 - dlls/winedos/int13.c | 16 +++++++++++----- dlls/winedos/int25.c | 16 ++++++++++------ dlls/winedos/int26.c | 15 +++++++++------ files/drive.c | 12 ------------ include/drive.h | 1 - 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/dlls/kernel/kernel32.spec b/dlls/kernel/kernel32.spec index 61fb303898c..47d49376518 100644 --- a/dlls/kernel/kernel32.spec +++ b/dlls/kernel/kernel32.spec @@ -1147,7 +1147,6 @@ @ cdecl DOSMEM_GetBlock(long ptr) @ cdecl DOSMEM_Init(long) @ cdecl DOSMEM_ResizeBlock(ptr long long) -@ cdecl DRIVE_OpenDevice(long long) @ cdecl FILE_Dup2(long long) @ cdecl LOCAL_Alloc(long long long) @ cdecl LOCAL_Compact(long long long) diff --git a/dlls/winedos/int13.c b/dlls/winedos/int13.c index cde64a92982..cf5f1cc515f 100644 --- a/dlls/winedos/int13.c +++ b/dlls/winedos/int13.c @@ -35,8 +35,8 @@ #endif #include "dosexe.h" +#include "wine/server.h" #include "wine/debug.h" -#include "drive.h" WINE_DEFAULT_DEBUG_CHANNEL(int); @@ -98,7 +98,8 @@ static void INT13_ReadFloppyParams( CONTEXT86 *context ) int floppy_fd; int r; struct floppy_drive_params floppy_parm; - char root[] = "A:\\"; + WCHAR root[] = {'A',':','\\',0}, drive_root[] = {'\\','\\','.','\\','A',':',0}; + HANDLE h; TRACE("in [ EDX=%08lx ]\n", context->Edx ); @@ -108,7 +109,7 @@ static void INT13_ReadFloppyParams( CONTEXT86 *context ) SET_DH( context, 0 ); for (i = 0; i < MAX_DOS_DRIVES; i++, root[0]++) - if (GetDriveTypeA(root) == DRIVE_REMOVABLE) nr_of_drives++; + if (GetDriveTypeW(root) == DRIVE_REMOVABLE) nr_of_drives++; SET_DL( context, nr_of_drives ); if (drive_nr > 1) { @@ -117,15 +118,20 @@ static void INT13_ReadFloppyParams( CONTEXT86 *context ) return; } - if ( (floppy_fd = DRIVE_OpenDevice( drive_nr, O_RDONLY|O_NONBLOCK)) == -1) + drive_root[4] = 'A' + drive_nr; + h = CreateFileW(drive_root, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (h == INVALID_HANDLE_VALUE || + wine_server_handle_to_fd(h, GENERIC_READ, &floppy_fd, NULL, NULL)) { WARN("Can't determine floppy geometry !\n"); INT13_SetStatus( context, 0x07 ); /* drive parameter activity failed */ return; } r = ioctl(floppy_fd, FDGETDRVPRM, &floppy_parm); - + close(floppy_fd); + CloseHandle(h); if(r<0) { diff --git a/dlls/winedos/int25.c b/dlls/winedos/int25.c index ae46c5eb160..22c454ba1a5 100644 --- a/dlls/winedos/int25.c +++ b/dlls/winedos/int25.c @@ -27,7 +27,6 @@ # include #endif #include "dosexe.h" -#include "drive.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(int); @@ -40,17 +39,22 @@ WINE_DEFAULT_DEBUG_CHANNEL(int); */ BOOL DOSVM_RawRead(BYTE drive, DWORD begin, DWORD nr_sect, BYTE *dataptr, BOOL fake_success) { - int fd; + WCHAR root[] = {'\\','\\','.','\\','A',':',0}; + HANDLE h; - if ((fd = DRIVE_OpenDevice( drive, O_RDONLY )) != -1) + root[4] += drive; + h = CreateFileW(root, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, NULL); + if (h != INVALID_HANDLE_VALUE) { - lseek( fd, begin * 512, SEEK_SET ); + SetFilePointer(h, begin * 512, NULL, SEEK_SET ); /* FIXME: check errors */ - read( fd, dataptr, nr_sect * 512 ); - close( fd ); + ReadFile(h, dataptr, nr_sect * 512, NULL, NULL ); + CloseHandle(h); } else { + if (h != INVALID_HANDLE_VALUE) CloseHandle(h); memset( dataptr, 0, nr_sect * 512 ); if (fake_success) { diff --git a/dlls/winedos/int26.c b/dlls/winedos/int26.c index bdd58d699ba..ac66187f219 100644 --- a/dlls/winedos/int26.c +++ b/dlls/winedos/int26.c @@ -26,7 +26,6 @@ # include #endif #include "dosexe.h" -#include "drive.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(int); @@ -39,14 +38,18 @@ WINE_DEFAULT_DEBUG_CHANNEL(int); */ BOOL DOSVM_RawWrite(BYTE drive, DWORD begin, DWORD nr_sect, BYTE *dataptr, BOOL fake_success) { - int fd; + WCHAR root[] = {'\\','\\','.','\\','A',':',0}; + HANDLE h; - if ((fd = DRIVE_OpenDevice( drive, O_RDONLY )) != -1) + root[4] += drive; + h = CreateFileW(root, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, + 0, NULL); + if (h != INVALID_HANDLE_VALUE) { - lseek( fd, begin * 512, SEEK_SET ); + SetFilePointer(h, begin * 512, NULL, SEEK_SET ); /* FIXME: check errors */ - write( fd, dataptr, nr_sect * 512 ); - close( fd ); + WriteFile( h, dataptr, nr_sect * 512, NULL, NULL ); + CloseHandle( h ); } else if (!fake_success) return FALSE; diff --git a/files/drive.c b/files/drive.c index 8ffbb37e60b..e2ff7f27f2f 100644 --- a/files/drive.c +++ b/files/drive.c @@ -1364,18 +1364,6 @@ BOOL WINAPI DefineDosDeviceW(DWORD flags,LPCWSTR devname,LPCWSTR targetpath) } -/*********************************************************************** - * DRIVE_OpenDevice - * - * Open the drive raw device and return a Unix fd (or -1 on error). - */ -int DRIVE_OpenDevice( int drive, int flags ) -{ - if (!DRIVE_IsValid( drive )) return -1; - return open( DOSDrives[drive].device, flags ); -} - - /*********************************************************************** * DRIVE_GetFreeSpace */ diff --git a/include/drive.h b/include/drive.h index 8e7436859ad..2f0bec5db06 100644 --- a/include/drive.h +++ b/include/drive.h @@ -51,7 +51,6 @@ extern UINT DRIVE_GetFlags( int drive ); extern int DRIVE_Chdir( int drive, LPCWSTR path ); extern int DRIVE_Disable( int drive ); extern int DRIVE_Enable( int drive ); -extern int DRIVE_OpenDevice( int drive, int flags ); extern WCHAR *DRIVE_BuildEnv(void); #endif /* __WINE_DRIVE_H */