Changeset 8401 for trunk/src


Ignore:
Timestamp:
May 10, 2002, 4:55:13 PM (23 years ago)
Author:
sandervl
Message:

hard disk access updates & fixes

Location:
trunk/src/kernel32
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/HandleManager.cpp

    r7927 r8401  
    1 /* $Id: HandleManager.cpp,v 1.87 2002-02-15 19:14:50 sandervl Exp $ */
     1/* $Id: HandleManager.cpp,v 1.88 2002-05-10 14:55:09 sandervl Exp $ */
    22
    33/*
     
    16671667  {
    16681668    SetLastError(ERROR_INVALID_HANDLE);       /* set win32 error information */
    1669     return (INVALID_HANDLE_ERROR);                         /* signal failure */
     1669    return -1; //INVALID_SET_FILE_POINTER
    16701670  }
    16711671
  • trunk/src/kernel32/disk.cpp

    r8397 r8401  
    1 /* $Id: disk.cpp,v 1.35 2002-05-09 13:55:33 sandervl Exp $ */
     1/* $Id: disk.cpp,v 1.36 2002-05-10 14:55:10 sandervl Exp $ */
    22
    33/*
     
    2424#include "oslibdos.h"
    2525#include "osliblvm.h"
    26 #include "exceptutil.h"
     26#include "asmutil.h"
    2727#include "profile.h"
    2828#include "hmdisk.h"
     
    240240            pszVolume = (char *)alloca(length);
    241241
    242             strcpy(pszVolume, &lpszDrive[sizeof(VOLUME_NAME_PREFIX)-1+1]);  //-zero term + starting '{'
    243             length -= sizeof(VOLUME_NAME_PREFIX)-1+1;
    244             if(pszVolume[length-2] == '}') {
    245                 pszVolume[length-2] = 0;
     242            if(OSLibLVMStripVolumeName(lpszDrive, pszVolume, length))
     243            {
    246244                rc = OSLibLVMGetDriveType(pszVolume);
    247245                dprintf(("KERNEL32:  GetDriveType %s = %d (LVM)", lpszDrive, rc));
     
    314312            pszVolume = (char *)alloca(length);
    315313
    316             strcpy(pszVolume, &lpRootPathName[sizeof(VOLUME_NAME_PREFIX)-1]);
    317             length -= sizeof(VOLUME_NAME_PREFIX)-1;
    318             if(pszVolume[length-1] == '}') {
     314            if(OSLibLVMStripVolumeName(lpRootPathName, pszVolume, length))
     315            {
     316                pszVolume[length-2] = 0;
    319317                fVolumeName = TRUE;
    320318                goto proceed;
     
    361359            else
    362360            if(!strcmp(lpFileSystemNameBuffer, "CDFS") ||
    363                !strcmp(lpFileSystemNameBuffer, "UDF"))
     361               !strcmp(lpFileSystemNameBuffer, "UDF") ||
     362               !strcmp(lpFileSystemNameBuffer, "NTFS") ||
     363               !strcmp(lpFileSystemNameBuffer, "FAT32"))
    364364            {
    365365                //do nothing
     
    738738                                                DWORD cchBufferLength)
    739739{
    740     if(!VERSION_IS_WIN2000_OR_HIGHER()) {
    741         SetLastError(ERROR_NOT_SUPPORTED);
    742         return FALSE;
    743     }
    744 
    745     dprintf(("GetVolumeNameForVolumeMountPointA: %s", lpszVolumeMountPoint));
    746     if(OSLibLVMGetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint, lpszVolumeName,
     740    LPSTR pszvol;
     741
     742    pszvol = (char *)alloca(cchBufferLength);
     743    if(pszvol == NULL) {
     744        DebugInt3();
     745        return FALSE;
     746    }
     747
     748    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     749        SetLastError(ERROR_NOT_SUPPORTED);
     750        return FALSE;
     751    }
     752
     753    if(OSLibLVMGetVolumeNameForVolumeMountPoint(lpszVolumeMountPoint, pszvol,
    747754                                                cchBufferLength) == TRUE)
    748755    {
     756        int length = strlen(pszvol);
     757        if(length + sizeof(VOLUME_NAME_PREFIX) - 1 + 3 > cchBufferLength) {
     758            SetLastError(ERROR_INSUFFICIENT_BUFFER);
     759            return FALSE;
     760        }
     761        sprintf(lpszVolumeName, VOLUME_NAME_PREFIX"{%s}\\", pszvol);
     762
     763        dprintf(("GetVolumeNameForVolumeMountPointA %s returned %s", lpszVolumeMountPoint, lpszVolumeName));
    749764        SetLastError(ERROR_SUCCESS);
    750765        return TRUE;
    751766    }
     767    dprintf(("GetVolumeNameForVolumeMountPointA: %s not found!!", lpszVolumeMountPoint));
    752768    SetLastError(ERROR_FILE_NOT_FOUND);
    753769    return FALSE;
  • trunk/src/kernel32/exceptstackdump.cpp

    r6375 r8401  
    1 /* $Id: exceptstackdump.cpp,v 1.4 2001-07-20 15:33:29 sandervl Exp $ */
     1/* $Id: exceptstackdump.cpp,v 1.5 2002-05-10 14:55:11 sandervl Exp $ */
    22/*
    33 * Stack dump code
     
    2020#include "exceptstackdump.h"
    2121#include "exceptutil.h"
     22#include "asmutil.h"
    2223#include "oslibmisc.h"
    2324#include "winexebase.h"
  • trunk/src/kernel32/exceptutil.asm

    r6375 r8401  
    1 ; $Id: exceptutil.asm,v 1.18 2001-07-20 15:33:29 sandervl Exp $
     1; $Id: exceptutil.asm,v 1.19 2002-05-10 14:55:11 sandervl Exp $
    22
    33;/*
     
    154154_SetExceptionChain endp
    155155
    156         PUBLIC getEAX
    157         PUBLIC getEBX
    158 getEAX  proc near
    159         ret
    160 getEAX  endp
    161 
    162 public  getEDX
    163 getEDX  proc    near
    164         mov     EAX, EDX
    165         ret
    166 endp
    167 
    168 getEBX  proc near
    169         mov  eax, ebx
    170         ret
    171 getEBX  endp
    172 
    173         PUBLIC GetFS
    174 GetFS   proc near
    175         mov     eax, fs
    176         ret
    177 GetFS   endp
    178 
    179         PUBLIC SetFS
    180 SetFS   proc near
    181         mov     eax, [esp+4]
    182         mov     fs, eax
    183         ret
    184 SetFS   endp
    185 
    186         PUBLIC getCS
    187 getCS   proc near
    188         mov     eax, cs
    189         ret
    190 getCS   endp
    191 
    192         PUBLIC getDS
    193 getDS   proc near
    194         mov     eax, ds
    195         ret
    196 getDS   endp
    197 
    198         PUBLIC SetReturnFS
    199 SetReturnFS proc near
    200         push    fs
    201         mov     eax, [esp+8]
    202         mov     fs, eax
    203         pop     eax
    204         ret
    205 SetReturnFS endp
    206 
    207         PUBLIC getSS
    208 getSS   proc near
    209         mov     ax, ss
    210         ret
    211 getSS   endp
    212 
    213         PUBLIC getES
    214 getES   proc near
    215         mov     eax, es
    216         ret
    217 getES   endp
    218 
    219         PUBLIC getGS
    220 getGS   proc near
    221         mov     eax, gs
    222         ret
    223 getGS   endp
    224 
    225         PUBLIC getESP
    226 getESP  proc near
    227         mov     eax, esp
    228         ret
    229 getESP  endp
    230 
    231         PUBLIC RestoreOS2FS
    232 RestoreOS2FS proc near
    233         push    150bh
    234         mov     ax, fs
    235         pop     fs
    236         ret
    237 RestoreOS2FS endp
    238 
    239         PUBLIC _Mul32x32to64
    240 _Mul32x32to64 proc near
    241         push    ebp
    242         mov     ebp, esp
    243         push    eax
    244         push    edx
    245         push    edi
    246 
    247         mov     edi, [ebp+8]    ;64 bits result
    248         mov     eax, [ebp+12]   ;op1
    249         mov     edx, [ebp+16]   ;op2
    250         mul     edx
    251         mov     [edi], eax
    252         mov     [edi+4], edx
    253 
    254         pop     edi
    255         pop     edx
    256         pop     eax
    257         pop     ebp
    258         ret
    259 _Mul32x32to64 endp
    260156
    261157        PUBLIC  _AsmCallThreadHandler
  • trunk/src/kernel32/exceptutil.h

    r6133 r8401  
    1 /* $Id: exceptutil.h,v 1.12 2001-06-27 19:09:35 sandervl Exp $ */
     1/* $Id: exceptutil.h,v 1.13 2002-05-10 14:55:11 sandervl Exp $ */
    22
    33/*
     
    3232#endif
    3333
    34 ULONG  getEAX();
    35 ULONG  getEBX();
    36 ULONG  getESP();
    37 USHORT getSS();
    38 USHORT getDS();
    39 USHORT getCS();
    40 USHORT getSS();
    41 USHORT getES();
    42 USHORT getFS();
    43 USHORT getGS();
    44 
    45 void CDECL Mul32x32to64(PVOID result, DWORD op1, DWORD op2);
    46 
    4734ULONG CDECL AsmCallThreadHandler(ULONG handler, LPVOID parameter);
    4835
  • trunk/src/kernel32/hmdevice.cpp

    r7549 r8401  
    1 /* $Id: hmdevice.cpp,v 1.31 2001-12-05 14:15:59 sandervl Exp $ */
     1/* $Id: hmdevice.cpp,v 1.32 2002-05-10 14:55:11 sandervl Exp $ */
    22
    33/*
     
    426426           pSize));
    427427
    428   return(ERROR_INVALID_FUNCTION);
     428  return -1; //INVALID_SET_FILE_POINTER
    429429}
    430430
  • trunk/src/kernel32/hmdisk.cpp

    r8397 r8401  
    1 /* $Id: hmdisk.cpp,v 1.43 2002-05-09 13:55:33 sandervl Exp $ */
     1/* $Id: hmdisk.cpp,v 1.44 2002-05-10 14:55:11 sandervl Exp $ */
    22
    33/*
    44 * Win32 Disk API functions for OS/2
    55 *
    6  * Copyright 2000 Sander van Leeuwen
     6 * Copyright 2000-2002 Sander van Leeuwen
    77 *
    88 *
     
    1212#include <os2win.h>
    1313#include <string.h>
     14#include <stdio.h>
    1415#include <versionos2.h>
    1516
     
    2324#include "oslibdos.h"
    2425#include "osliblvm.h"
     26#include "asmutil.h"
    2527
    2628#define DBG_LOCALLOG    DBG_hmdisk
     
    3537{
    3638    HINSTANCE hInstAspi;
    37     DWORD (WIN32API *GetASPI32SupportInfo)();
    38     DWORD (CDECL *SendASPI32Command)(LPSRB lpSRB);
     39    DWORD     (WIN32API *GetASPI32SupportInfo)();
     40    DWORD     (CDECL *SendASPI32Command)(LPSRB lpSRB);
    3941    ULONG     driveLetter;
    4042    ULONG     driveType;
     
    4749    LPSECURITY_ATTRIBUTES lpSecurityAttributes;
    4850    HFILE     hTemplate;
     51    BOOL      fPhysicalDisk;
     52    LARGE_INTEGER StartingOffset;
     53    LARGE_INTEGER PartitionSize;
     54    LARGE_INTEGER CurrentFilePointer;
     55    CHAR      szVolumeName[256];
    4956} DRIVE_INFO;
    5057
     
    7077BOOL HMDeviceDiskClass::FindDevice(LPCSTR lpClassDevName, LPCSTR lpDeviceName, int namelength)
    7178{
    72   // check for "x:"
    73   if (namelength == 2)
    74   {
    75     if (lpDeviceName[1] != ':')
    76       return FALSE;
    77 
    78     if ( (lpDeviceName[0] < 'A') ||
    79          (lpDeviceName[0] > 'Z') )
    80       return FALSE;
    81 
    82     return TRUE;
    83   }
     79    // check for "x:"
     80    if (namelength == 2)
     81    {
     82        if (lpDeviceName[1] != ':')
     83            return FALSE;
     84
     85        if (!( ((lpDeviceName[0] >= 'A') &&
     86                (lpDeviceName[0] <= 'Z')) ||
     87               ((lpDeviceName[0] >= 'a') &&
     88                (lpDeviceName[0] <= 'z')) ))
     89            return FALSE;
     90
     91        return TRUE;
     92    }
    8493
    8594    //\\.\x:                -> length 6
     
    94103    }
    95104
    96     //SvL: \\.\x:             -> drive x (i.e. \\.\C:)
    97     //     \\.\PHYSICALDRIVEn -> drive n (n>=0)
     105    // \\.\x:             -> drive x (i.e. \\.\C:)
     106    // \\.\PHYSICALDRIVEn -> drive n (n>=0)
    98107    if((strncmp(lpDeviceName, "\\\\.\\", 4) == 0) &&
    99108        namelength == 6 && lpDeviceName[5] == ':')
     
    107116}
    108117//******************************************************************************
    109 //TODO: PHYSICALDRIVEn!!
    110118//******************************************************************************
    111119DWORD HMDeviceDiskClass::CreateFile (LPCSTR        lpFileName,
     
    114122                                     PHMHANDLEDATA pHMHandleDataTemplate)
    115123{
    116     HFILE hFile;
    117     HFILE hTemplate;
    118     DWORD dwDriveType;
     124    HFILE               hFile;
     125    HFILE               hTemplate;
     126    DWORD               dwDriveType;
     127    CHAR                szDiskName[256];
     128    CHAR                szVolumeName[256] = "";
     129    VOLUME_DISK_EXTENTS volext = {0};
     130    BOOL                fPhysicalDisk = FALSE;
    119131
    120132    dprintf2(("KERNEL32: HMDeviceDiskClass::CreateFile %s(%s,%08x,%08x,%08x)\n",
    121              lpHMDeviceName,
    122              lpFileName,
    123              pHMHandleData,
    124              lpSecurityAttributes,
    125              pHMHandleDataTemplate));
     133             lpHMDeviceName, lpFileName, pHMHandleData, lpSecurityAttributes, pHMHandleDataTemplate));
    126134
    127135    //TODO: check in NT if CREATE_ALWAYS is allowed!!
     
    136144
    137145    //if volume name, query
    138     if(VERSION_IS_WIN2000_OR_HIGHER() && !strncmp(lpFileName, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1)) {
    139         char *pszVolume;
    140         int   length;
    141 
    142         //strip volume name prefix (\\\\?\\Volume\\)
    143         length = strlen(lpFileName);
    144         pszVolume = (char *)alloca(length);
    145 
    146         strcpy(pszVolume, &lpFileName[sizeof(VOLUME_NAME_PREFIX)-1+1]);  //-zero term + starting '{'
    147         length -= sizeof(VOLUME_NAME_PREFIX)-1+1;
    148         if(pszVolume[length-2] == '}') {
    149             pszVolume[length-2] = 0;
    150             szDrive[0] = OSLibLVMQueryDriveFromVolumeName(pszVolume);
     146    if(!strncmp(lpFileName, VOLUME_NAME_PREFIX, sizeof(VOLUME_NAME_PREFIX)-1))
     147    {
     148        int length;
     149
     150        if(!VERSION_IS_WIN2000_OR_HIGHER()) {
     151            return ERROR_FILE_NOT_FOUND;    //not allowed
     152        }
     153        if(OSLibLVMStripVolumeName(lpFileName, szVolumeName, sizeof(szVolumeName)))
     154        {
     155            BOOL fLVMVolume;
     156
     157            dwDriveType = GetDriveTypeA(lpFileName);
     158
     159            szDrive[0] = OSLibLVMQueryDriveFromVolumeName(szVolumeName);
     160            if(szDrive[0] == -1) {
     161                return ERROR_FILE_NOT_FOUND;    //not found
     162            }
     163            if((dwDriveType == DRIVE_FIXED) && OSLibLVMGetVolumeExtents(szDrive[0], szVolumeName, &volext, &fLVMVolume) == FALSE) {
     164                return ERROR_FILE_NOT_FOUND;    //not found
     165            }
     166            if(szDrive[0] == 0)
     167            {
     168                //volume isn't mounted
     169               
     170                //Note: this only works on Warp 4.5 and up
     171                sprintf(szDiskName, "\\\\.\\Physical_Disk%d", volext.Extents[0].DiskNumber);
     172                fPhysicalDisk = TRUE;
     173
     174                if(fLVMVolume && (pHMHandleData->dwAccess & GENERIC_WRITE)) {
     175                    //no write access allowed for LVM volumes
     176                    dprintf(("CreateFile: WARNING: Write access to LVM volume denied!!"));
     177                    pHMHandleData->dwAccess &= ~GENERIC_WRITE;
     178                }
     179            }
     180            else {
     181                //mounted drive, make sure access requested is readonly, else fail
     182                if(pHMHandleData->dwAccess & GENERIC_WRITE) {
     183                    //no write access allowed for mounted partitions
     184                    dprintf(("CreateFile: WARNING: Write access to mounted partition denied!!"));
     185                    pHMHandleData->dwAccess &= ~GENERIC_WRITE;
     186                }
     187                strcpy(szDiskName, szDrive);
     188            }
    151189        }
    152190        else return ERROR_FILE_NOT_FOUND;
    153 
     191    }
     192    else
     193    if(strncmp(lpFileName, "\\\\.\\PHYSICALDRIVE", 17) == 0)
     194    {
     195        //Note: this only works on Warp 4.5 and up
     196        sprintf(szDiskName, "\\\\.\\Physical_Disk%c", lpFileName[17]);
     197        fPhysicalDisk = TRUE;
     198
     199        //TODO: could be removable in theory
     200        dwDriveType = DRIVE_FIXED;
     201
     202        if(pHMHandleData->dwAccess & GENERIC_WRITE) {
     203            //no write access allowed for whole disks
     204            dprintf(("CreateFile: WARNING: Write access to whole disk denied!!"));
     205            pHMHandleData->dwAccess &= ~GENERIC_WRITE;
     206        }
    154207    }
    155208    else {
     209        strcpy(szDiskName, lpFileName);
    156210        szDrive[0] = *lpFileName;
    157     }
    158     dwDriveType = GetDriveTypeA(szDrive);
     211        dwDriveType = GetDriveTypeA(szDrive);
     212    }
    159213
    160214    //Disable error popus. NT allows an app to open a cdrom/dvd drive without a disk inside
    161215    //OS/2 fails in that case with error ERROR_NOT_READY
    162216    ULONG oldmode = SetErrorMode(SEM_FAILCRITICALERRORS);
    163     hFile = OSLibDosCreateFile((LPSTR)lpFileName,
     217    hFile = OSLibDosCreateFile(szDiskName,
    164218                               pHMHandleData->dwAccess,
    165219                               pHMHandleData->dwShare,
     
    177231    {
    178232        pHMHandleData->dwAccess &= ~GENERIC_WRITE;
    179         hFile = OSLibDosCreateFile((LPSTR)lpFileName,
     233        hFile = OSLibDosCreateFile((LPSTR)szDiskName,
    180234                                   pHMHandleData->dwAccess,
    181235                                   pHMHandleData->dwShare,
     
    211265        drvInfo->dwAccess  = pHMHandleData->dwFlags;
    212266        drvInfo->hTemplate = hTemplate;
     267
     268        //save volume start & length if volume must be accessed through the physical disk
     269        //(no other choice for unmounted volumes)
     270        drvInfo->fPhysicalDisk  = fPhysicalDisk;
     271        drvInfo->StartingOffset = volext.Extents[0].StartingOffset;
     272        drvInfo->PartitionSize  = volext.Extents[0].ExtentLength;
     273
     274        //save volume name for later (IOCtls)
     275        strncpy(drvInfo->szVolumeName, szVolumeName, sizeof(drvInfo->szVolumeName)-1);
    213276
    214277        drvInfo->driveLetter = *lpFileName; //save drive letter
     
    242305        }
    243306
    244         if(hFile) {
     307        if(hFile && drvInfo->driveType != DRIVE_FIXED) {
    245308            OSLibDosQueryVolumeSerialAndName(1 + drvInfo->driveLetter - 'A', &drvInfo->dwVolumelabel, NULL, 0);
    246309        }
    247310
     311        //for an unmounted partition we open the physical disk that contains it, so we
     312        //must set the file pointer to the correct beginning
     313        if(drvInfo->fPhysicalDisk && (drvInfo->StartingOffset.HighPart != 0 ||
     314           drvInfo->StartingOffset.LowPart != 0))
     315        {
     316            SetFilePointer(pHMHandleData, 0, NULL, FILE_BEGIN);
     317        }
    248318        return (NO_ERROR);
    249319    }
     
    618688    {
    619689        APIRET rc;
    620         DWORD ret;
     690            DWORD ret;
    621691        ULONG  ulBytesRead    = 0;      /* Number of bytes read by DosRead */
    622692        ULONG  ulWrote        = 0;      /* Number of bytes written by DosWrite */
     
    638708            return FALSE;
    639709        }
     710        else
     711        if(drvInfo->driveType == DRIVE_FIXED) {
     712            SetLastError(ERROR_SUCCESS);
     713            return TRUE;
     714        }
    640715
    641716        OSLibDosDevIOCtl(pHMHandleData->hHMHandle,IOCTL_DISK,DSK_LOCKDRIVE,0,0,0,0,0,0);
     
    720795        //label has changed
    721796        //TODO: Find better way to determine if floppy was removed or switched
    722         rc = OSLibDosQueryVolumeSerialAndName(1 + drvInfo->driveLetter - 'A', &volumelabel, NULL, 0);
    723         if(rc) {
    724             dprintf(("IOCTL_DISK_GET_DRIVE_GEOMETRY: OSLibDosQueryVolumeSerialAndName failed with rc %d", GetLastError()));
    725             if(pHMHandleData->hHMHandle) OSLibDosClose(pHMHandleData->hHMHandle);
    726             pHMHandleData->hHMHandle = 0;
    727             SetLastError(ERROR_MEDIA_CHANGED);
    728             return FALSE;
    729         }
    730         if(volumelabel != drvInfo->dwVolumelabel) {
    731             dprintf(("IOCTL_DISK_GET_DRIVE_GEOMETRY: volume changed %x -> %x", drvInfo->dwVolumelabel, volumelabel));
    732             SetLastError(ERROR_MEDIA_CHANGED);
    733             return FALSE;
     797        if(drvInfo->driveType != DRIVE_FIXED)
     798        {
     799            rc = OSLibDosQueryVolumeSerialAndName(1 + drvInfo->driveLetter - 'A', &volumelabel, NULL, 0);
     800            if(rc) {
     801                dprintf(("IOCTL_DISK_GET_DRIVE_GEOMETRY: OSLibDosQueryVolumeSerialAndName failed with rc %d", GetLastError()));
     802                if(pHMHandleData->hHMHandle) OSLibDosClose(pHMHandleData->hHMHandle);
     803                pHMHandleData->hHMHandle = 0;
     804                SetLastError(ERROR_MEDIA_CHANGED);
     805                return FALSE;
     806            }
     807            if(volumelabel != drvInfo->dwVolumelabel) {
     808                dprintf(("IOCTL_DISK_GET_DRIVE_GEOMETRY: volume changed %x -> %x", drvInfo->dwVolumelabel, volumelabel));
     809                SetLastError(ERROR_MEDIA_CHANGED);
     810                return FALSE;
     811            }
    734812        }
    735813
     
    754832            *lpBytesReturned = sizeof(PARTITION_INFORMATION);
    755833        }
    756         if(OSLibLVMGetPartitionInfo(drvInfo->driveLetter, pPartition)) {
     834        if(OSLibLVMGetPartitionInfo(drvInfo->driveLetter, drvInfo->szVolumeName, pPartition) == FALSE) {
    757835            SetLastError(ERROR_NOT_ENOUGH_MEMORY); //wrong error, but who cares
    758836            return FALSE;
     
    781859            return FALSE;
    782860        }
    783         if(OSLibLVMGetVolumeExtents(drvInfo->driveLetter, pVolExtent)) {
     861        if(OSLibLVMGetVolumeExtents(drvInfo->driveLetter, drvInfo->szVolumeName, pVolExtent) == FALSE) {
    784862            SetLastError(ERROR_NOT_ENOUGH_MEMORY); //wrong error, but who cares
    785863            return FALSE;
     
    816894        } ParameterBlock;
    817895#pragma pack()
    818 
    819896        PCDROM_TOC pTOC = (PCDROM_TOC)lpOutBuffer;
    820897        DWORD rc, numtracks;
     
    915992    case IOCTL_CDROM_PLAY_AUDIO_MSF:
    916993    {
    917       dprintf(("Play CDROM audio playback"));
    918 
    919994#pragma pack(1)
    920995      struct
     
    9261001      } ParameterBlock;
    9271002#pragma pack()
     1003      dprintf(("Play CDROM audio playback"));
    9281004
    9291005      PCDROM_PLAY_AUDIO_MSF pPlay = (PCDROM_PLAY_AUDIO_MSF)lpInBuffer;
     
    10961172    case IOCTL_STORAGE_CHECK_VERIFY:
    10971173    {
     1174#pragma pack(1)
     1175      typedef struct
     1176      {
     1177        BYTE  ucCommandInfo;
     1178        WORD  usDriveUnit;
     1179      } ParameterBlock;
     1180#pragma pack()
     1181
    10981182        dprintf(("IOCTL_CDROM(DISK/STORAGE)CHECK_VERIFY %s", drvInfo->signature));
    10991183        if(lpBytesReturned) {
     
    11091193            }
    11101194        }
    1111 
    1112 #pragma pack(1)
    1113       typedef struct
    1114       {
    1115         BYTE  ucCommandInfo;
    1116         WORD  usDriveUnit;
    1117       } ParameterBlock;
    1118 #pragma pack()
    11191195
    11201196        DWORD parsize = sizeof(ParameterBlock);
     
    13541430                                 LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
    13551431{
    1356   LPVOID       lpRealBuf;
    1357   Win32MemMap *map;
    1358   DWORD        offset, bytesread;
    1359   BOOL         bRC;
    1360 
    1361   dprintf2(("KERNEL32: HMDeviceDiskClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)",
    1362            lpHMDeviceName,
    1363            pHMHandleData,
    1364            lpBuffer,
    1365            nNumberOfBytesToRead,
    1366            lpNumberOfBytesRead,
    1367            lpOverlapped));
    1368 
    1369   //SvL: It's legal for this pointer to be NULL
    1370   if(lpNumberOfBytesRead)
    1371     *lpNumberOfBytesRead = 0;
    1372   else
    1373     lpNumberOfBytesRead = &bytesread;
    1374 
    1375   if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
    1376     dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
    1377     SetLastError(ERROR_INVALID_PARAMETER);
    1378     return FALSE;
    1379   }
    1380 
    1381   if(lpCompletionRoutine) {
    1382       dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
    1383   }
    1384 
    1385   //If we didn't get an OS/2 handle for the disk before, get one now
    1386   if(!pHMHandleData->hHMHandle) {
    1387       DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
    1388       pHMHandleData->hHMHandle = OpenDisk(drvInfo);
    1389       if(!pHMHandleData->hHMHandle) {
    1390           dprintf(("No disk inserted; aborting"));
    1391           SetLastError(ERROR_NOT_READY);
    1392           return FALSE;
    1393       }
    1394   }
    1395 
    1396   if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
    1397     dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    1398   }
    1399 
    1400   //SvL: DosRead doesn't like writing to memory addresses returned by
    1401   //     DosAliasMem -> search for original memory mapped pointer and use
    1402   //     that one + commit pages if not already present
    1403   map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_WRITE);
    1404   if(map) {
    1405     lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
    1406     DWORD nrpages = nNumberOfBytesToRead/4096;
    1407     if(offset & 0xfff)
    1408         nrpages++;
    1409     if(nNumberOfBytesToRead & 0xfff)
    1410         nrpages++;
    1411 
    1412     map->commitPage(offset & ~0xfff, TRUE, nrpages);
    1413   }
    1414   else  lpRealBuf = (LPVOID)lpBuffer;
    1415 
    1416   if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
    1417     dprintf(("ERROR: Overlapped IO not yet implememented!!"));
    1418   }
    1419 //  else {
     1432    LPVOID       lpRealBuf;
     1433    Win32MemMap *map;
     1434    DWORD        offset, bytesread;
     1435    BOOL         bRC;
     1436
     1437    dprintf2(("KERNEL32: HMDeviceDiskClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)",
     1438               lpHMDeviceName, pHMHandleData, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped));
     1439
     1440    //It's legal for this pointer to be NULL
     1441    if(lpNumberOfBytesRead)
     1442        *lpNumberOfBytesRead = 0;
     1443    else
     1444        lpNumberOfBytesRead = &bytesread;
     1445
     1446    if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
     1447        dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
     1448        SetLastError(ERROR_INVALID_PARAMETER);
     1449        return FALSE;
     1450    }
     1451
     1452    if(lpCompletionRoutine) {
     1453        dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     1454    }
     1455
     1456    //If we didn't get an OS/2 handle for the disk before, get one now
     1457    if(!pHMHandleData->hHMHandle) {
     1458        DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1459        pHMHandleData->hHMHandle = OpenDisk(drvInfo);
     1460        if(!pHMHandleData->hHMHandle) {
     1461            dprintf(("No disk inserted; aborting"));
     1462            SetLastError(ERROR_NOT_READY);
     1463            return FALSE;
     1464        }
     1465    }
     1466
     1467    if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
     1468        dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
     1469    }
     1470
     1471    //SvL: DosRead doesn't like writing to memory addresses returned by
     1472    //     DosAliasMem -> search for original memory mapped pointer and use
     1473    //     that one + commit pages if not already present
     1474    map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_WRITE);
     1475    if(map) {
     1476        lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
     1477        DWORD nrpages = nNumberOfBytesToRead/4096;
     1478        if(offset & 0xfff)
     1479            nrpages++;
     1480        if(nNumberOfBytesToRead & 0xfff)
     1481            nrpages++;
     1482   
     1483        map->commitPage(offset & ~0xfff, TRUE, nrpages);
     1484    }
     1485    else  lpRealBuf = (LPVOID)lpBuffer;
     1486
     1487    if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
     1488        dprintf(("ERROR: Overlapped IO not yet implememented!!"));
     1489    }
     1490    //  else {
    14201491    bRC = OSLibDosRead(pHMHandleData->hHMHandle,
    14211492                           (PVOID)lpRealBuf,
     
    14241495//  }
    14251496
    1426   if(bRC == 0) {
    1427       dprintf(("KERNEL32: HMDeviceDiskClass::ReadFile returned %08xh %x", bRC, GetLastError()));
    1428       dprintf(("%x -> %d", lpBuffer, IsBadWritePtr((LPVOID)lpBuffer, nNumberOfBytesToRead)));
    1429   }
    1430   else dprintf2(("KERNEL32: HMDeviceDiskClass::ReadFile read %x bytes pos %x", *lpNumberOfBytesRead, SetFilePointer(pHMHandleData, 0, NULL, FILE_CURRENT)));
    1431 
    1432   return bRC;
     1497    if(bRC == 0) {
     1498        dprintf(("KERNEL32: HMDeviceDiskClass::ReadFile returned %08xh %x", bRC, GetLastError()));
     1499        dprintf(("%x -> %d", lpBuffer, IsBadWritePtr((LPVOID)lpBuffer, nNumberOfBytesToRead)));
     1500    }
     1501    else dprintf2(("KERNEL32: HMDeviceDiskClass::ReadFile read %x bytes pos %x", *lpNumberOfBytesRead, SetFilePointer(pHMHandleData, 0, NULL, FILE_CURRENT)));
     1502
     1503    return bRC;
    14331504}
    14341505/*****************************************************************************
     
    14461517 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
    14471518 *****************************************************************************/
    1448 
    14491519DWORD HMDeviceDiskClass::SetFilePointer(PHMHANDLEDATA pHMHandleData,
    14501520                                        LONG          lDistanceToMove,
     
    14521522                                        DWORD         dwMoveMethod)
    14531523{
    1454   DWORD ret;
    1455 
    1456   dprintf2(("KERNEL32: HMDeviceDiskClass::SetFilePointer %s(%08xh,%08xh,%08xh,%08xh)\n",
    1457            lpHMDeviceName,
    1458            pHMHandleData,
    1459            lDistanceToMove,
    1460            lpDistanceToMoveHigh,
    1461            dwMoveMethod));
    1462 
    1463   if(!pHMHandleData->hHMHandle) {
    1464       DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
    1465       pHMHandleData->hHMHandle = OpenDisk(drvInfo);
    1466       if(!pHMHandleData->hHMHandle) {
    1467           dprintf(("No disk inserted; aborting"));
    1468           SetLastError(ERROR_NOT_READY);
    1469           return -1;
    1470       }
    1471   }
    1472 
    1473   ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle,
    1474                                lDistanceToMove,
    1475                                (DWORD *)lpDistanceToMoveHigh,
    1476                                dwMoveMethod);
    1477 
    1478   if(ret == -1) {
    1479       dprintf(("SetFilePointer failed (error = %d)", GetLastError()));
    1480   }
    1481   return ret;
     1524    DWORD ret;
     1525
     1526    if(lpDistanceToMoveHigh) {
     1527        dprintf(("KERNEL32: HMDeviceDiskClass::SetFilePointer %s %08x%08x %d",
     1528                 lpHMDeviceName, *lpDistanceToMoveHigh, lDistanceToMove, dwMoveMethod));
     1529    }
     1530
     1531    DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1532    if(drvInfo == NULL) {
     1533        dprintf(("ERROR: SetFilePointer: drvInfo == NULL!!!"));
     1534        DebugInt3();
     1535        SetLastError(ERROR_INVALID_HANDLE);
     1536        return FALSE;
     1537    }
     1538
     1539    if(!pHMHandleData->hHMHandle) {
     1540        DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1541        pHMHandleData->hHMHandle = OpenDisk(drvInfo);
     1542        if(!pHMHandleData->hHMHandle) {
     1543            dprintf(("No disk inserted; aborting"));
     1544            SetLastError(ERROR_NOT_READY);
     1545            return -1;
     1546        }
     1547    }
     1548
     1549    //if unmounted volume, add starting offset to position as we're accessing the entire physical drive
     1550    //instead of just the volume
     1551    if(drvInfo->fPhysicalDisk && (drvInfo->StartingOffset.HighPart != 0 ||
     1552       drvInfo->StartingOffset.LowPart != 0))
     1553    {
     1554        LARGE_INTEGER distance, result, endpos;
     1555        LARGE_INTEGER position;
     1556
     1557        if(lpDistanceToMoveHigh) {
     1558            distance.HighPart =  *lpDistanceToMoveHigh;
     1559        }
     1560        else {
     1561            if(lDistanceToMove < 0) {
     1562                 distance.HighPart = -1;
     1563            }
     1564            else distance.HighPart = 0;
     1565        }
     1566        distance.LowPart = lDistanceToMove;
     1567
     1568        //calculate end position in partition
     1569        Add64(&drvInfo->StartingOffset, &drvInfo->PartitionSize, &endpos);
     1570        result.HighPart = 0;
     1571        result.LowPart  = 1;
     1572        Sub64(&endpos, &result, &endpos);
     1573
     1574        switch(dwMoveMethod) {
     1575        case FILE_BEGIN:
     1576            Add64(&distance, &drvInfo->StartingOffset, &result);
     1577            break;
     1578        case FILE_CURRENT:
     1579            Add64(&distance, &drvInfo->CurrentFilePointer, &result);
     1580            break;
     1581        case FILE_END:
     1582            Add64(&distance, &endpos, &result);
     1583            break;
     1584        }
     1585        //check upper boundary
     1586        if(result.HighPart > endpos.HighPart ||
     1587           (result.HighPart == endpos.HighPart && result.LowPart > endpos.LowPart) )
     1588        {
     1589            SetLastError(ERROR_INVALID_PARAMETER);
     1590            return -1;
     1591        }
     1592        //check lower boundary
     1593        if(result.HighPart < drvInfo->StartingOffset.HighPart ||
     1594           (result.HighPart == drvInfo->StartingOffset.HighPart && result.LowPart < drvInfo->StartingOffset.LowPart))
     1595        {
     1596            SetLastError(ERROR_NEGATIVE_SEEK);
     1597            return -1;
     1598        }
     1599
     1600        dprintf(("SetFilePointer (unmounted partition) %08x%08x -> %08x%08x", distance.HighPart, distance.LowPart, result.HighPart, result.LowPart));
     1601        ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle,
     1602                                     result.LowPart,
     1603                                     (DWORD *)&result.HighPart,
     1604                                     FILE_BEGIN);
     1605
     1606        Sub64(&result, &drvInfo->StartingOffset, &drvInfo->CurrentFilePointer);
     1607        ret = drvInfo->CurrentFilePointer.LowPart;
     1608        if(lpDistanceToMoveHigh) {
     1609            *lpDistanceToMoveHigh = drvInfo->CurrentFilePointer.HighPart;
     1610        }
     1611    }
     1612    else {
     1613        ret = OSLibDosSetFilePointer(pHMHandleData->hHMHandle,
     1614                                     lDistanceToMove,
     1615                                     (DWORD *)lpDistanceToMoveHigh,
     1616                                     dwMoveMethod);
     1617    }
     1618
     1619    if(ret == -1) {
     1620        dprintf(("SetFilePointer failed (error = %d)", GetLastError()));
     1621    }
     1622    return ret;
    14821623}
    14831624
     
    14991640
    15001641BOOL HMDeviceDiskClass::WriteFile(PHMHANDLEDATA pHMHandleData,
    1501                                     LPCVOID       lpBuffer,
    1502                                     DWORD         nNumberOfBytesToWrite,
    1503                                     LPDWORD       lpNumberOfBytesWritten,
    1504                                     LPOVERLAPPED  lpOverlapped,
    1505                                     LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
     1642                                  LPCVOID       lpBuffer,
     1643                                  DWORD         nNumberOfBytesToWrite,
     1644                                  LPDWORD       lpNumberOfBytesWritten,
     1645                                  LPOVERLAPPED  lpOverlapped,
     1646                                  LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine)
    15061647{
    1507   LPVOID       lpRealBuf;
    1508   Win32MemMap *map;
    1509   DWORD        offset, byteswritten;
    1510   BOOL         bRC;
    1511 
    1512    dprintf2(("KERNEL32: HMDeviceDiskClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
    1513            lpHMDeviceName,
    1514            pHMHandleData,
    1515            lpBuffer,
    1516            nNumberOfBytesToWrite,
    1517            lpNumberOfBytesWritten,
    1518            lpOverlapped));
    1519 
    1520   DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
    1521   if(drvInfo == NULL) {
    1522       dprintf(("ERROR: DeviceIoControl: drvInfo == NULL!!!"));
    1523       DebugInt3();
    1524       SetLastError(ERROR_INVALID_HANDLE);
    1525       return FALSE;
    1526   }
    1527 
    1528   //SvL: It's legal for this pointer to be NULL
    1529   if(lpNumberOfBytesWritten)
    1530     *lpNumberOfBytesWritten = 0;
    1531   else
    1532     lpNumberOfBytesWritten = &byteswritten;
    1533 
    1534   if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
    1535     dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
    1536     SetLastError(ERROR_INVALID_PARAMETER);
    1537     return FALSE;
    1538   }
    1539   if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
    1540       dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
    1541   }
    1542   if(lpCompletionRoutine) {
    1543       dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
    1544   }
    1545 
    1546   //If we didn't get an OS/2 handle for the disk before, get one now
    1547   if(!pHMHandleData->hHMHandle) {
    1548       DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
    1549       pHMHandleData->hHMHandle = OpenDisk(drvInfo);
    1550       if(!pHMHandleData->hHMHandle) {
    1551           dprintf(("No disk inserted; aborting"));
    1552           SetLastError(ERROR_NOT_READY);
    1553           return FALSE;
    1554       }
    1555   }
    1556   //NOTE: For now only allow an application to write to drive A
    1557   //      Might want to extend this to all removable media, but it's
    1558   //      too dangerous to allow win32 apps to write to the harddisk directly
    1559   if(drvInfo->driveLetter != 'A') {
    1560       SetLastError(ERROR_ACCESS_DENIED);
    1561       return FALSE;
    1562   }
    1563 
    1564 
    1565   //SvL: DosWrite doesn't like reading from memory addresses returned by
    1566   //     DosAliasMem -> search for original memory mapped pointer and use
    1567   //     that one + commit pages if not already present
    1568   map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_READ);
    1569   if(map) {
    1570     lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
    1571     DWORD nrpages = nNumberOfBytesToWrite/4096;
    1572     if(offset & 0xfff)
    1573         nrpages++;
    1574     if(nNumberOfBytesToWrite & 0xfff)
    1575         nrpages++;
    1576 
    1577     map->commitPage(offset & ~0xfff, TRUE, nrpages);
    1578   }
    1579   else  lpRealBuf = (LPVOID)lpBuffer;
    1580 
    1581   OSLibDosDevIOCtl(pHMHandleData->hHMHandle,IOCTL_DISK,DSK_LOCKDRIVE,0,0,0,0,0,0);
    1582 
    1583   if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
    1584     dprintf(("ERROR: Overlapped IO not yet implememented!!"));
    1585   }
     1648    LPVOID       lpRealBuf;
     1649    Win32MemMap *map;
     1650    DWORD        offset, byteswritten;
     1651    BOOL         bRC;
     1652
     1653    dprintf2(("KERNEL32: HMDeviceDiskClass::WriteFile %s(%08x,%08x,%08x,%08x,%08x) - stub?\n",
     1654              lpHMDeviceName, pHMHandleData, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten,
     1655              lpOverlapped));
     1656
     1657    DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1658    if(drvInfo == NULL) {
     1659        dprintf(("ERROR: WriteFile: drvInfo == NULL!!!"));
     1660        DebugInt3();
     1661        SetLastError(ERROR_INVALID_HANDLE);
     1662        return FALSE;
     1663    }
     1664    if(!(drvInfo->dwAccess & GENERIC_WRITE)) {
     1665        dprintf(("ERROR: WriteFile: write access denied!"));
     1666        SetLastError(ERROR_ACCESS_DENIED);
     1667        return FALSE;
     1668    }
     1669    //It's legal for this pointer to be NULL
     1670    if(lpNumberOfBytesWritten)
     1671        *lpNumberOfBytesWritten = 0;
     1672    else
     1673        lpNumberOfBytesWritten = &byteswritten;
     1674
     1675    if((pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && !lpOverlapped) {
     1676        dprintf(("FILE_FLAG_OVERLAPPED flag set, but lpOverlapped NULL!!"));
     1677        SetLastError(ERROR_INVALID_PARAMETER);
     1678        return FALSE;
     1679    }
     1680    if(!(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) && lpOverlapped) {
     1681        dprintf(("Warning: lpOverlapped != NULL & !FILE_FLAG_OVERLAPPED; sync operation"));
     1682    }
     1683    if(lpCompletionRoutine) {
     1684        dprintf(("!WARNING!: lpCompletionRoutine not supported -> fall back to sync IO"));
     1685    }
     1686
     1687    //If we didn't get an OS/2 handle for the disk before, get one now
     1688    if(!pHMHandleData->hHMHandle) {
     1689        DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1690        pHMHandleData->hHMHandle = OpenDisk(drvInfo);
     1691        if(!pHMHandleData->hHMHandle) {
     1692            dprintf(("No disk inserted; aborting"));
     1693            SetLastError(ERROR_NOT_READY);
     1694            return FALSE;
     1695        }
     1696    }
     1697
     1698    //SvL: DosWrite doesn't like reading from memory addresses returned by
     1699    //     DosAliasMem -> search for original memory mapped pointer and use
     1700    //     that one + commit pages if not already present
     1701    map = Win32MemMapView::findMapByView((ULONG)lpBuffer, &offset, MEMMAP_ACCESS_READ);
     1702    if(map) {
     1703        lpRealBuf = (LPVOID)((ULONG)map->getMappingAddr() + offset);
     1704        DWORD nrpages = nNumberOfBytesToWrite/4096;
     1705        if(offset & 0xfff)
     1706            nrpages++;
     1707        if(nNumberOfBytesToWrite & 0xfff)
     1708            nrpages++;
     1709   
     1710        map->commitPage(offset & ~0xfff, TRUE, nrpages);
     1711    }
     1712    else  lpRealBuf = (LPVOID)lpBuffer;
     1713
     1714    OSLibDosDevIOCtl(pHMHandleData->hHMHandle,IOCTL_DISK,DSK_LOCKDRIVE,0,0,0,0,0,0);
     1715
     1716    if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
     1717        dprintf(("ERROR: Overlapped IO not yet implememented!!"));
     1718    }
    15861719//  else {
    15871720    bRC = OSLibDosWrite(pHMHandleData->hHMHandle,
     
    15911724//  }
    15921725
    1593   OSLibDosDevIOCtl(pHMHandleData->hHMHandle,IOCTL_DISK,DSK_UNLOCKDRIVE,0,0,0,0,0,0);
    1594   dprintf2(("KERNEL32: HMDeviceDiskClass::WriteFile returned %08xh\n",
    1595            bRC));
    1596 
    1597   return bRC;
     1726    OSLibDosDevIOCtl(pHMHandleData->hHMHandle,IOCTL_DISK,DSK_UNLOCKDRIVE,0,0,0,0,0,0);
     1727    dprintf2(("KERNEL32: HMDeviceDiskClass::WriteFile returned %08xh\n",
     1728               bRC));
     1729
     1730    return bRC;
    15981731}
    15991732
     1733/*****************************************************************************
     1734 * Name      : DWORD HMDeviceDiskClass::GetFileSize
     1735 * Purpose   : set file time
     1736 * Parameters: PHMHANDLEDATA pHMHandleData
     1737 *             PDWORD        pSize
     1738 * Variables :
     1739 * Result    : API returncode
     1740 * Remark    :
     1741 * Status    :
     1742 *
     1743 * Author    : Patrick Haller [Wed, 1999/06/17 20:44]
     1744 *****************************************************************************/
     1745
     1746DWORD HMDeviceDiskClass::GetFileSize(PHMHANDLEDATA pHMHandleData,
     1747                                     PDWORD        lpdwFileSizeHigh)
     1748{
     1749    DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
     1750    if(drvInfo == NULL) {
     1751        dprintf(("ERROR: GetFileSize: drvInfo == NULL!!!"));
     1752        DebugInt3();
     1753        SetLastError(ERROR_INVALID_HANDLE);
     1754        return -1; //INVALID_SET_FILE_POINTER
     1755    }
     1756
     1757    dprintf2(("KERNEL32: HMDeviceDiskClass::GetFileSize %s(%08xh,%08xh)\n",
     1758              lpHMDeviceName, pHMHandleData, lpdwFileSizeHigh));
     1759
     1760    //If we didn't get an OS/2 handle for the disk before, get one now
     1761    if(!pHMHandleData->hHMHandle) {
     1762        pHMHandleData->hHMHandle = OpenDisk(drvInfo);
     1763        if(!pHMHandleData->hHMHandle) {
     1764            dprintf(("No disk inserted; aborting"));
     1765            SetLastError(ERROR_NOT_READY);
     1766            return -1; //INVALID_SET_FILE_POINTER
     1767        }
     1768    }
     1769
     1770    if(drvInfo->PartitionSize.HighPart || drvInfo->PartitionSize.LowPart) {
     1771        if(lpdwFileSizeHigh)
     1772            *lpdwFileSizeHigh = drvInfo->PartitionSize.HighPart;
     1773
     1774        return drvInfo->PartitionSize.LowPart;
     1775    }
     1776    else {
     1777        LARGE_INTEGER position, size;
     1778
     1779        //get current position
     1780        position.HighPart = 0;
     1781        position.LowPart  = SetFilePointer(pHMHandleData, 0, (PLONG)&position.HighPart, FILE_CURRENT);
     1782        SetFilePointer(pHMHandleData, 0, NULL, FILE_BEGIN);
     1783        size.HighPart     = 0;
     1784        size.LowPart      = SetFilePointer(pHMHandleData, 0, (PLONG)&size.HighPart, FILE_END);
     1785
     1786        //restore old position
     1787        SetFilePointer(pHMHandleData, position.LowPart, (PLONG)&position.HighPart, FILE_BEGIN);
     1788
     1789        if(lpdwFileSizeHigh)
     1790            *lpdwFileSizeHigh = size.HighPart;
     1791
     1792        return size.LowPart;
     1793    }
     1794}
    16001795
    16011796/*****************************************************************************
     
    16131808DWORD HMDeviceDiskClass::GetFileType(PHMHANDLEDATA pHMHandleData)
    16141809{
    1615   dprintf2(("KERNEL32: HMDeviceDiskClass::GetFileType %s(%08x)\n",
    1616              lpHMDeviceName,
    1617              pHMHandleData));
    1618 
    1619   return FILE_TYPE_DISK;
     1810    dprintf2(("KERNEL32: HMDeviceDiskClass::GetFileType %s(%08x)\n",
     1811               lpHMDeviceName, pHMHandleData));
     1812
     1813    return FILE_TYPE_DISK;
    16201814}
    16211815//******************************************************************************
  • trunk/src/kernel32/hmdisk.h

    r8397 r8401  
    1 /* $Id: hmdisk.h,v 1.9 2002-05-09 13:55:33 sandervl Exp $ */
     1/* $Id: hmdisk.h,v 1.10 2002-05-10 14:55:12 sandervl Exp $ */
    22
    33#ifndef __HMDISK_H__
     
    1111#include "HMDevice.h"
    1212#include "HMObjects.h"
    13 
    14 #define VOLUME_NAME_PREFIX  "\\\\?\\Volume\\"
    1513
    1614/*****************************************************************************
     
    6260                                     LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped);
    6361
     62  /* this is a handler method for calls to GetFileSize() */
     63  virtual DWORD GetFileSize(PHMHANDLEDATA pHMHandleData,
     64                            PDWORD        pSizeHigh);
     65
    6466  /* this is a handler method for calls to GetFileType() */
    6567  virtual DWORD GetFileType (PHMHANDLEDATA pHMHandleData);
  • trunk/src/kernel32/hmthread.cpp

    r8015 r8401  
    1 /* $Id: hmthread.cpp,v 1.10 2002-02-26 11:11:17 sandervl Exp $ */
     1/* $Id: hmthread.cpp,v 1.11 2002-05-10 14:55:12 sandervl Exp $ */
    22
    33/*
     
    2929#include <win\thread.h>
    3030#include "thread.h"
    31 #include "exceptutil.h"
     31#include "asmutil.h"
    3232
    3333#define DBG_LOCALLOG    DBG_hmthread
  • trunk/src/kernel32/kernel32.mak

    r8397 r8401  
    1 # $Id: kernel32.mak,v 1.29 2002-05-09 13:55:33 sandervl Exp $
     1# $Id: kernel32.mak,v 1.30 2002-05-10 14:55:12 sandervl Exp $
    22
    33#
     
    6464$(OBJDIR)\misc.obj \
    6565$(OBJDIR)\exceptutil.obj \
     66$(OBJDIR)\asmutil.obj \
    6667$(OBJDIR)\lang.obj \
    6768$(OBJDIR)\iccio.obj \
  • trunk/src/kernel32/oslibdos.cpp

    r8397 r8401  
    1 /* $Id: oslibdos.cpp,v 1.101 2002-05-09 13:55:34 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.102 2002-05-10 14:55:12 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    244244    case ERROR_CRC: //23
    245245        return ERROR_CRC_W;
     246
     247    case ERROR_SEEK:
     248        return ERROR_SEEK_W;
    246249
    247250    case ERROR_NOT_DOS_DISK: //26
     
    11231126
    11241127   if(strlen(lpszFile) == 2 && lpszFile[1] == ':') {
    1125         //app tries to open physical disk
     1128        //app tries to open logical volume/partition
    11261129        openMode |= OPEN_FLAGS_DASD;
    11271130   }
  • trunk/src/kernel32/osliblvm.cpp

    r8397 r8401  
    1 /* $Id: osliblvm.cpp,v 1.1 2002-05-09 13:55:34 sandervl Exp $ */
     1/* $Id: osliblvm.cpp,v 1.2 2002-05-10 14:55:13 sandervl Exp $ */
    22
    33/*
     
    329329//******************************************************************************
    330330//******************************************************************************
    331 static Volume_Information_Record OSLibLVMFindVolumeFromDriveLetter(ULONG driveLetter,
    332                                                                    Volume_Control_Record *pVolRec,
    333                                                                    CARDINAL32 *lasterror)
     331static Volume_Information_Record OSLibLVMFindVolumeByDriveLetter(ULONG driveLetter,
     332                                                                 Volume_Control_Record *pVolRec,
     333                                                                 CARDINAL32 *lasterror)
    334334{
    335335    Volume_Control_Array      *volctrl;
     
    367367//******************************************************************************
    368368//******************************************************************************
    369 static Volume_Information_Record OSLibLVMFindVolumeFromName(LPSTR pszVolName,
    370                                                             Volume_Control_Record *pVolRec,
    371                                                             CARDINAL32 *lasterror)
     369static Volume_Information_Record OSLibLVMFindVolumeByName(LPSTR pszVolName,
     370                                                          Volume_Control_Record *pVolRec,
     371                                                          CARDINAL32 *lasterror)
    372372{
    373373    Volume_Control_Array      *volctrl;
     
    405405//******************************************************************************
    406406//******************************************************************************
    407 BOOL OSLibLVMGetPartitionInfo(ULONG driveLetter, PPARTITION_INFORMATION pPartition)
     407BOOL OSLibLVMGetPartitionInfo(ULONG driveLetter, LPSTR lpszVolumeName, PPARTITION_INFORMATION pPartition)
    408408{
    409409    Volume_Information_Record  volinfo;
     
    412412    CARDINAL32                 lasterror;
    413413
    414     volinfo = OSLibLVMFindVolumeFromDriveLetter(driveLetter, &volctrl, &lasterror);
    415     if(lasterror != LVM_ENGINE_NO_ERROR) {
    416         DebugInt3();
    417         return FALSE;
    418     }
    419 
    420     //We will not return information about LVM volumes (too dangerous as
    421     //they contain extra information in the volume and can be spanned)
    422     if(volinfo.Compatibility_Volume == FALSE) {
     414    if(lpszVolumeName && lpszVolumeName[0]) {
     415         volinfo = OSLibLVMFindVolumeByName(lpszVolumeName, &volctrl, &lasterror);
     416    }
     417    else volinfo = OSLibLVMFindVolumeByDriveLetter(driveLetter, &volctrl, &lasterror);
     418    if(lasterror != LVM_ENGINE_NO_ERROR) {
     419        DebugInt3();
    423420        return FALSE;
    424421    }
    425422
    426423    partctrl = Get_Partitions(volctrl.Volume_Handle, &lasterror);
    427     if(lasterror != LVM_ENGINE_NO_ERROR) {
     424    if(lasterror != LVM_ENGINE_NO_ERROR || partctrl.Count == 0) {
    428425        return FALSE;
    429426    }
     
    445442//******************************************************************************
    446443//******************************************************************************
    447 BOOL OSLibLVMGetVolumeExtents(ULONG driveLetter, PVOLUME_DISK_EXTENTS pVolExtent)
     444BOOL OSLibLVMGetVolumeExtents(ULONG driveLetter, LPSTR lpszVolumeName, PVOLUME_DISK_EXTENTS pVolExtent,
     445                              BOOL *pfLVMVolume)
    448446{
    449447    Volume_Information_Record  volinfo;
    450448    Volume_Control_Record      volctrl;
     449    Drive_Control_Array        diskinfo;
    451450    Partition_Information_Array partctrl;
    452451    CARDINAL32                 lasterror;
    453 
    454     volinfo = OSLibLVMFindVolumeFromDriveLetter(driveLetter, &volctrl, &lasterror);
    455     if(lasterror != LVM_ENGINE_NO_ERROR) {
    456         DebugInt3();
    457         return FALSE;
    458     }
    459     //We will not return information about LVM volumes (too dangerous as
    460     //they contain extra information in the volume and can be spanned)
    461     if(volinfo.Compatibility_Volume == FALSE) {
     452    BOOL                       ret = TRUE;
     453
     454    if(lpszVolumeName && lpszVolumeName[0]) {
     455         volinfo = OSLibLVMFindVolumeByName(lpszVolumeName, &volctrl, &lasterror);
     456    }
     457    else volinfo = OSLibLVMFindVolumeByDriveLetter(driveLetter, &volctrl, &lasterror);
     458    if(lasterror != LVM_ENGINE_NO_ERROR) {
     459        DebugInt3();
    462460        return FALSE;
    463461    }
    464462
    465463    partctrl = Get_Partitions(volctrl.Volume_Handle, &lasterror);
    466     if(lasterror != LVM_ENGINE_NO_ERROR) {
     464    if(lasterror != LVM_ENGINE_NO_ERROR || partctrl.Count == 0) {
    467465        return FALSE;
    468466    }
     
    475473    pVolExtent->Extents[0].ExtentLength.u.LowPart    = partctrl.Partition_Array[0].Usable_Partition_Size << 9;
    476474
     475    dprintf(("pVolExtent->NumberOfDiskExtents       %d", pVolExtent->NumberOfDiskExtents));
     476    dprintf(("pVolExtent->Extents[0].DiskNumber     %d",  pVolExtent->Extents[0].DiskNumber));
     477    dprintf(("pVolExtent->Extents[0].StartingOffset %08x%08x", pVolExtent->Extents[0].StartingOffset.u.HighPart, pVolExtent->Extents[0].StartingOffset.u.LowPart));
     478    dprintf(("pVolExtent->Extents[0].ExtentLength   %08x%08x", pVolExtent->Extents[0].ExtentLength.u.HighPart, pVolExtent->Extents[0].ExtentLength.u.LowPart));
     479
     480    //find number of disk on which this volume is located
     481    diskinfo = Get_Drive_Control_Data(&lasterror);
     482    if(lasterror != LVM_ENGINE_NO_ERROR) {
     483        return FALSE;
     484    }
     485    for(int i=0;i<diskinfo.Count;i++) {
     486        if(diskinfo.Drive_Control_Data[i].Drive_Handle == partctrl.Partition_Array[0].Drive_Handle) {
     487            pVolExtent->Extents[0].DiskNumber = diskinfo.Drive_Control_Data[i].Drive_Number;
     488            break;
     489        }
     490    }
     491    if(i == diskinfo.Count) {
     492        ret = FALSE;
     493    }
     494    if(pfLVMVolume) {
     495        *pfLVMVolume = (volinfo.Compatibility_Volume == FALSE);
     496    }
     497    Free_Engine_Memory((ULONG)diskinfo.Drive_Control_Data);
    477498    Free_Engine_Memory((ULONG)partctrl.Partition_Array);
    478     return TRUE;
     499    return ret;
    479500}
    480501//******************************************************************************
     
    487508    CARDINAL32                 lasterror;
    488509
    489     volinfo = OSLibLVMFindVolumeFromName((char *)lpszVolume, &volctrl, &lasterror);
     510    volinfo = OSLibLVMFindVolumeByName((char *)lpszVolume, &volctrl, &lasterror);
    490511    if(lasterror != LVM_ENGINE_NO_ERROR) {
    491512        DebugInt3();
     
    512533}
    513534//******************************************************************************
     535// OSLibLVMQueryDriveFromVolumeName
     536//
     537//   Returns:
     538//            - drive letter corresponding to volume name
     539//            - -1 if volume wasn't found
     540//            - 0 if volume is present, but not mounted
     541//   
    514542//******************************************************************************
    515543CHAR OSLibLVMQueryDriveFromVolumeName(LPCSTR lpszVolume)
     
    519547    CARDINAL32                 lasterror;
    520548
    521     volinfo = OSLibLVMFindVolumeFromName((char *)lpszVolume, NULL, &lasterror);
    522     if(lasterror != LVM_ENGINE_NO_ERROR) {
    523         DebugInt3();
    524         return 0;
     549    volinfo = OSLibLVMFindVolumeByName((char *)lpszVolume, NULL, &lasterror);
     550    if(lasterror != LVM_ENGINE_NO_ERROR) {
     551        DebugInt3();
     552        return -1;  //not found
    525553    }
    526554    return volinfo.Current_Drive_Letter;
     
    533561    CARDINAL32                lasterror;
    534562
    535     volinfo = OSLibLVMFindVolumeFromName(lpszVolume, NULL, &lasterror);
     563    volinfo = OSLibLVMFindVolumeByName(lpszVolume, NULL, &lasterror);
    536564    if(lasterror != LVM_ENGINE_NO_ERROR) {
    537565        DebugInt3();
     
    551579    int                        i;
    552580
    553     volinfo = OSLibLVMFindVolumeFromName(lpszVolume, &volctrl, &lasterror);
     581    volinfo = OSLibLVMFindVolumeByName(lpszVolume, &volctrl, &lasterror);
    554582    if(lasterror != LVM_ENGINE_NO_ERROR) {
    555583        DebugInt3();
     
    576604    //We only support drive letters as mountpoint names
    577605    if('A' <= *lpszVolumeMountPoint && *lpszVolumeMountPoint <= 'Z') {
    578         drive = *lpszVolumeMountPoint - 'A' + 1;
     606        drive = *lpszVolumeMountPoint - 'A';
    579607    }
    580608    else
    581609    if('a' <= *lpszVolumeMountPoint && *lpszVolumeMountPoint <= 'z') {
    582         drive = *lpszVolumeMountPoint - 'a' + 1;
     610        drive = *lpszVolumeMountPoint - 'a';
    583611    }
    584612    else {
     
    592620    CARDINAL32                lasterror;
    593621
    594     volinfo = OSLibLVMFindVolumeFromDriveLetter(drive, NULL, &lasterror);
     622    volinfo = OSLibLVMFindVolumeByDriveLetter(drive, NULL, &lasterror);
    595623    if(lasterror != LVM_ENGINE_NO_ERROR) {
    596624        DebugInt3();
     
    603631//******************************************************************************
    604632//******************************************************************************
    605 
     633BOOL OSLibLVMStripVolumeName(LPCSTR lpszWin32VolumeName, LPSTR lpszOS2VolumeName, DWORD cchBufferLength)
     634{
     635    int length;
     636
     637    //strip volume name prefix (\\\\?\\Volume\\)
     638    length = strlen(lpszWin32VolumeName);
     639
     640    strncpy(lpszOS2VolumeName, &lpszWin32VolumeName[sizeof(VOLUME_NAME_PREFIX)-1+1], cchBufferLength-1);  //-zero term + starting '{'
     641    length -= sizeof(VOLUME_NAME_PREFIX)-1+1;
     642    if(lpszOS2VolumeName[length-2] == '}')
     643    {
     644        lpszOS2VolumeName[length-2] = 0;
     645        return TRUE;
     646    }
     647    else
     648    if(lpszOS2VolumeName[length-1] == '}')
     649    {
     650        lpszOS2VolumeName[length-1] = 0;
     651        return TRUE;
     652    }
     653    return FALSE;
     654}
     655//******************************************************************************
     656//******************************************************************************
     657
  • trunk/src/kernel32/osliblvm.h

    r8397 r8401  
    1 /* $Id: osliblvm.h,v 1.1 2002-05-09 13:55:35 sandervl Exp $ */
     1/* $Id: osliblvm.h,v 1.2 2002-05-10 14:55:13 sandervl Exp $ */
    22/*
    33 * OS/2 LVM (Logical Volume Management) functions
     
    321321#endif
    322322
     323#define VOLUME_NAME_PREFIX  "\\\\?\\Volume\\"
    323324
    324325BOOL   OSLibLVMInit();
     
    329330                               LPSTR lpszVolumeName, DWORD cchBufferLength);
    330331
    331 BOOL   OSLibLVMGetPartitionInfo(ULONG driveLetter, PPARTITION_INFORMATION pPartition);
    332 BOOL   OSLibLVMGetVolumeExtents(ULONG driveLetter, PVOLUME_DISK_EXTENTS pVolExtent);
     332BOOL   OSLibLVMGetPartitionInfo(ULONG driveLetter, LPSTR lpszVolumeName, PPARTITION_INFORMATION pPartition);
     333BOOL   OSLibLVMGetVolumeExtents(ULONG driveLetter, LPSTR lpszVolumeName, PVOLUME_DISK_EXTENTS pVolExtent, BOOL *pfLVMVolume = NULL);
     334
    333335ULONG  OSLibLVMGetDriveType(LPCSTR lpszVolume);
    334336CHAR   OSLibLVMQueryDriveFromVolumeName(LPCSTR lpszVolume);
     
    340342DWORD  OSLibLVMQueryVolumeSerialAndName(LPSTR lpszVolume, LPDWORD lpVolumeSerialNumber, LPSTR lpVolumeNameBuffer, DWORD nVolumeNameSize);
    341343
     344BOOL   OSLibLVMStripVolumeName(LPCSTR lpszWin32VolumeName, LPSTR lpszOS2VolumeName, DWORD cchBufferLength);
     345
    342346#endif //__OSLIBLVM_H__
  • trunk/src/kernel32/wprocess.cpp

    r8327 r8401  
    1 /* $Id: wprocess.cpp,v 1.150 2002-04-29 17:05:30 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.151 2002-05-10 14:55:13 sandervl Exp $ */
    22
    33/*
     
    3434#include "odin32validate.h"
    3535#include "exceptutil.h"
     36#include "asmutil.h"
    3637#include "oslibdos.h"
    3738#include "oslibmisc.h"
Note: See TracChangeset for help on using the changeset viewer.