Ignore:
Timestamp:
Sep 26, 2002, 6:06:07 PM (23 years ago)
Author:
sandervl
Message:

lots of fixes/changes for physical disk & volume access

File:
1 edited

Legend:

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

    r8980 r9298  
    1 /* $Id: hmdisk.cpp,v 1.52 2002-08-09 13:17:22 sandervl Exp $ */
     1/* $Id: hmdisk.cpp,v 1.53 2002-09-26 16:06:06 sandervl Exp $ */
    22
    33/*
     
    5252    HFILE     hTemplate;
    5353    BOOL      fPhysicalDisk;
     54    DWORD     dwPhysicalDiskNr;
    5455    BOOL      fCDPlaying;
    5556    BOOL      fShareViolation;
     
    134135    VOLUME_DISK_EXTENTS volext = {0};
    135136    BOOL                fPhysicalDisk = FALSE;
     137    DWORD               dwPhysicalDiskNr = 0;
    136138
    137139    dprintf2(("KERNEL32: HMDeviceDiskClass::CreateFile %s(%s,%08x,%08x,%08x)\n",
     
    174176               
    175177                //Note: this only works on Warp 4.5 and up
    176                 sprintf(szDiskName, "\\\\.\\Physical_Disk%d", volext.Extents[0].DiskNumber);
    177                 fPhysicalDisk = TRUE;
     178                sprintf(szDiskName, "\\\\.\\Physical_Disk%d", volext.Extents[0].DiskNumber+1);
     179                fPhysicalDisk    = TRUE;
     180                dwPhysicalDiskNr = volext.Extents[0].DiskNumber + 1;
    178181
    179182                if(fLVMVolume && (pHMHandleData->dwAccess & GENERIC_WRITE)) {
     
    199202    {
    200203        //Note: this only works on Warp 4.5 and up
    201         sprintf(szDiskName, "\\\\.\\Physical_Disk%c", lpFileName[17]);
    202         fPhysicalDisk = TRUE;
     204        sprintf(szDiskName, "\\\\.\\Physical_Disk%c", lpFileName[17]+1);
     205        fPhysicalDisk    = TRUE;
     206        dwPhysicalDiskNr = (DWORD)(lpFileName[17] - '0')+1;
    203207
    204208        //TODO: could be removable in theory
     
    285289        //save volume start & length if volume must be accessed through the physical disk
    286290        //(no other choice for unmounted volumes)
    287         drvInfo->fPhysicalDisk  = fPhysicalDisk;
    288         drvInfo->StartingOffset = volext.Extents[0].StartingOffset;
    289         drvInfo->PartitionSize  = volext.Extents[0].ExtentLength;
     291        drvInfo->fPhysicalDisk    = fPhysicalDisk;
     292        drvInfo->dwPhysicalDiskNr = dwPhysicalDiskNr;
     293        drvInfo->StartingOffset   = volext.Extents[0].StartingOffset;
     294        drvInfo->PartitionSize    = volext.Extents[0].ExtentLength;
    290295
    291296        //save volume name for later (IOCtls)
     
    891896        }
    892897
    893         if(OSLibDosGetDiskGeometry(pHMHandleData->hHMHandle, drvInfo->driveLetter, pGeom) == FALSE) {
    894             dprintf(("!ERROR!: IOCTL_DISK_GET_DRIVE_GEOMETRY: OSLibDosGetDiskGeometry failed!!"));
    895             return FALSE;
     898        if(drvInfo->fPhysicalDisk) {
     899            if(OSLibLVMGetDiskGeometry(drvInfo->dwPhysicalDiskNr, pGeom) == FALSE) {
     900                dprintf(("!ERROR!: IOCTL_DISK_GET_DRIVE_GEOMETRY: OSLibDosGetDiskGeometry failed!!"));
     901                return FALSE;
     902            }
     903        }
     904        else {
     905            if(OSLibDosGetDiskGeometry(pHMHandleData->hHMHandle, drvInfo->driveLetter, pGeom) == FALSE) {
     906                dprintf(("!ERROR!: IOCTL_DISK_GET_DRIVE_GEOMETRY: OSLibDosGetDiskGeometry failed!!"));
     907                return FALSE;
     908            }
    896909        }
    897910        dprintf(("Cylinders         %d", pGeom->Cylinders));
     
    16491662    DWORD        offset, bytesread;
    16501663    BOOL         bRC;
     1664    DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
    16511665
    16521666    dprintf2(("KERNEL32: HMDeviceDiskClass::ReadFile %s(%08x,%08x,%08x,%08x,%08x)",
     
    16711685    //If we didn't get an OS/2 handle for the disk before, get one now
    16721686    if(!pHMHandleData->hHMHandle) {
    1673         DRIVE_INFO *drvInfo = (DRIVE_INFO*)pHMHandleData->dwUserData;
    16741687        pHMHandleData->hHMHandle = OpenDisk(drvInfo);
    16751688        if(!pHMHandleData->hHMHandle) {
     
    17001713    else  lpRealBuf = (LPVOID)lpBuffer;
    17011714
     1715    //if unmounted volume, check upper boundary as we're accessing the entire physical drive
     1716    //instead of just the volume
     1717    if(drvInfo->fPhysicalDisk && (drvInfo->StartingOffset.HighPart != 0 ||
     1718       drvInfo->StartingOffset.LowPart != 0))
     1719    {
     1720        LARGE_INTEGER distance, result, endpos;
     1721
     1722        //calculate end position in partition
     1723        Add64(&drvInfo->StartingOffset, &drvInfo->PartitionSize, &endpos);
     1724
     1725        distance.HighPart = 0;
     1726        distance.LowPart  = nNumberOfBytesToRead;
     1727        Add64(&distance, &drvInfo->CurrentFilePointer, &result);
     1728
     1729        //check upper boundary
     1730        if(result.HighPart > endpos.HighPart ||
     1731           (result.HighPart == endpos.HighPart && result.LowPart > endpos.LowPart) )
     1732        {
     1733            Sub64(&endpos, &drvInfo->CurrentFilePointer, &result);
     1734            nNumberOfBytesToRead = result.LowPart;
     1735            dprintf(("Read past end of volume; nNumberOfBytesToRead reduced to %d", nNumberOfBytesToRead));
     1736            DebugInt3();
     1737        }
     1738    }
     1739
    17021740    if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
    17031741        dprintf(("ERROR: Overlapped IO not yet implememented!!"));
     
    17151753    }
    17161754    else dprintf2(("KERNEL32: HMDeviceDiskClass::ReadFile read %x bytes pos %x", *lpNumberOfBytesRead, SetFilePointer(pHMHandleData, 0, NULL, FILE_CURRENT)));
     1755
     1756    //if unmounted volume, add starting offset to position as we're accessing the entire physical drive
     1757    //instead of just the volume
     1758    if(drvInfo->fPhysicalDisk && (drvInfo->StartingOffset.HighPart != 0 ||
     1759       drvInfo->StartingOffset.LowPart != 0) && bRC == TRUE)
     1760    {
     1761        LARGE_INTEGER distance, result;
     1762
     1763        distance.HighPart = 0;
     1764        distance.LowPart  = *lpNumberOfBytesRead;
     1765        Add64(&distance, &drvInfo->CurrentFilePointer, &result);
     1766        drvInfo->CurrentFilePointer = result;
     1767
     1768        dprintf(("New unmounted volume current file pointer %08x%08x", drvInfo->CurrentFilePointer.HighPart, drvInfo->CurrentFilePointer.LowPart));
     1769    }
    17171770
    17181771    return bRC;
     
    19271980    else  lpRealBuf = (LPVOID)lpBuffer;
    19281981
     1982    //if unmounted volume, check upper boundary as we're accessing the entire physical drive
     1983    //instead of just the volume
     1984    if(drvInfo->fPhysicalDisk && (drvInfo->StartingOffset.HighPart != 0 ||
     1985       drvInfo->StartingOffset.LowPart != 0))
     1986    {
     1987        LARGE_INTEGER distance, result, endpos;
     1988
     1989        //calculate end position in partition
     1990        Add64(&drvInfo->StartingOffset, &drvInfo->PartitionSize, &endpos);
     1991
     1992        distance.HighPart = 0;
     1993        distance.LowPart  = nNumberOfBytesToWrite;
     1994        Add64(&distance, &drvInfo->CurrentFilePointer, &result);
     1995
     1996        //check upper boundary
     1997        if(result.HighPart > endpos.HighPart ||
     1998           (result.HighPart == endpos.HighPart && result.LowPart > endpos.LowPart) )
     1999        {
     2000            Sub64(&endpos, &drvInfo->CurrentFilePointer, &result);
     2001            nNumberOfBytesToWrite = result.LowPart;
     2002            dprintf(("Write past end of volume; nNumberOfBytesToWrite reduced to %d", nNumberOfBytesToWrite));
     2003            DebugInt3();
     2004        }
     2005    }
     2006
    19292007    if(pHMHandleData->dwFlags & FILE_FLAG_OVERLAPPED) {
    19302008        dprintf(("ERROR: Overlapped IO not yet implememented!!"));
     
    19362014                            lpNumberOfBytesWritten);
    19372015//  }
     2016
     2017    //if unmounted volume, add starting offset to position as we're accessing the entire physical drive
     2018    //instead of just the volume
     2019    if(drvInfo->fPhysicalDisk && (drvInfo->StartingOffset.HighPart != 0 ||
     2020       drvInfo->StartingOffset.LowPart != 0) && bRC == TRUE)
     2021    {
     2022        LARGE_INTEGER distance, result;
     2023
     2024        distance.HighPart = 0;
     2025        distance.LowPart  = *lpNumberOfBytesWritten;
     2026        Add64(&distance, &drvInfo->CurrentFilePointer, &result);
     2027        drvInfo->CurrentFilePointer = result;
     2028
     2029        dprintf(("New unmounted volume current file pointer %08x%08x", drvInfo->CurrentFilePointer.HighPart, drvInfo->CurrentFilePointer.LowPart));
     2030    }
    19382031
    19392032    dprintf2(("KERNEL32: HMDeviceDiskClass::WriteFile returned %08xh\n",
Note: See TracChangeset for help on using the changeset viewer.