Changeset 9298 for trunk/src


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

lots of fixes/changes for physical disk & volume access

Location:
trunk/src/kernel32
Files:
5 edited

Legend:

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

    r8409 r9298  
    1 /* $Id: disk.cpp,v 1.37 2002-05-14 09:28:19 sandervl Exp $ */
     1/* $Id: disk.cpp,v 1.38 2002-09-26 16:06:06 sandervl Exp $ */
    22
    33/*
     
    570570    char     szVolume[256];
    571571
    572     //tetsetsetetsetsetset
    573     SetLastError(ERROR_NO_MORE_FILES);
    574     return FALSE;
    575     //tetsetsetetsetsetset
    576 
    577572    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
    578573        SetLastError(ERROR_NOT_SUPPORTED);
     
    654649    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
    655650        SetLastError(ERROR_NOT_SUPPORTED);
    656         return FALSE;
     651        return INVALID_HANDLE_VALUE;
    657652    }
    658653   
    659654    SetLastError(ERROR_NO_MORE_FILES);
    660     return 0;
     655    return INVALID_HANDLE_VALUE;
    661656}
    662657//******************************************************************************
     
    672667    if(!VERSION_IS_WIN2000_OR_HIGHER()) {
    673668        SetLastError(ERROR_NOT_SUPPORTED);
    674         return FALSE;
     669        return INVALID_HANDLE_VALUE;
    675670    }
    676671
  • 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",
  • trunk/src/kernel32/oslibdos.cpp

    r9095 r9298  
    1 /* $Id: oslibdos.cpp,v 1.108 2002-08-22 14:21:26 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.109 2002-09-26 16:06:07 sandervl Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    996996      // @@@AH 2001-06-02 Win2k SP2 returns error 2 in this case
    997997      int winError = error2WinError(rc);
    998       if (winError == ERROR_OPEN_FAILED_W)
     998      if (winError == ERROR_OPEN_FAILED_W || winError == ERROR_PATH_NOT_FOUND_W)
    999999        winError = ERROR_FILE_NOT_FOUND_W;
    10001000      SetLastError(winError);
     
    24732473//******************************************************************************
    24742474//******************************************************************************
    2475 BOOL  OSLibDosGetDiskGeometry(HANDLE hDisk, DWORD cDisk, PVOID pdiskgeom)
     2475BOOL OSLibDosGetDiskGeometry(HANDLE hDisk, DWORD cDisk, PVOID pdiskgeom)
    24762476{
    24772477   PDISK_GEOMETRY pGeom = (PDISK_GEOMETRY)pdiskgeom;
     
    24872487   if(rc == 0)
    24882488   {
    2489         pGeom->SectorsPerTrack   = bpb.usSectorsPerTrack;
    2490         pGeom->BytesPerSector    = bpb.usBytesPerSector;
    2491         pGeom->TracksPerCylinder = 80;  //TODO:!!!!!
    2492         pGeom->Cylinders.u.LowPart  = bpb.cCylinders;
    2493         pGeom->Cylinders.u.HighPart = 0;
    2494         switch(bpb.bDeviceType) {
    2495         case DEVTYPE_48TPI:
    2496             pGeom->MediaType = F5_360_512;  //?????
    2497             break;
    2498         case DEVTYPE_96TPI:
    2499             pGeom->MediaType = F5_1Pt2_512; //?????
    2500             break;
    2501         case DEVTYPE_35:
    2502             pGeom->MediaType = F3_720_512;
    2503             break;
    2504         case DEVTYPE_8SD:
    2505         case DEVTYPE_8DD:
    2506             pGeom->MediaType = RemovableMedia;
    2507             break;
    2508         case DEVTYPE_FIXED:
    2509             pGeom->MediaType = FixedMedia;
    2510             break;
    2511         case DEVTYPE_TAPE:
    2512             pGeom->MediaType = RemovableMedia;
    2513             break;
    2514         case DEVTYPE_UNKNOWN: //others, include 1.44 3.5 inch disk drive
    2515             pGeom->MediaType = F3_1Pt44_512;
    2516             break;
    2517         case 8: //RW optical disk
    2518             pGeom->MediaType = RemovableMedia;
    2519             break;
    2520         case 9: //2.88 3.5 inch disk
    2521             pGeom->MediaType = F3_2Pt88_512;
    2522             break;
    2523         }
    2524         SetLastError(ERROR_SUCCESS_W);
    2525         return TRUE;
     2489            pGeom->SectorsPerTrack   = bpb.usSectorsPerTrack;
     2490            pGeom->BytesPerSector    = bpb.usBytesPerSector;
     2491            pGeom->TracksPerCylinder = 80;  //TODO:!!!!!
     2492            pGeom->Cylinders.u.LowPart  = bpb.cCylinders;
     2493            pGeom->Cylinders.u.HighPart = 0;
     2494            switch(bpb.bDeviceType) {
     2495            case DEVTYPE_48TPI:
     2496                pGeom->MediaType = F5_360_512;  //?????
     2497                break;
     2498            case DEVTYPE_96TPI:
     2499                pGeom->MediaType = F5_1Pt2_512; //?????
     2500                break;
     2501            case DEVTYPE_35:
     2502                pGeom->MediaType = F3_720_512;
     2503                break;
     2504            case DEVTYPE_8SD:
     2505            case DEVTYPE_8DD:
     2506                pGeom->MediaType = RemovableMedia;
     2507                break;
     2508            case DEVTYPE_FIXED:
     2509                pGeom->MediaType = FixedMedia;
     2510                break;
     2511            case DEVTYPE_TAPE:
     2512                pGeom->MediaType = RemovableMedia;
     2513                break;
     2514            case DEVTYPE_UNKNOWN: //others, include 1.44 3.5 inch disk drive
     2515                pGeom->MediaType = F3_1Pt44_512;
     2516                break;
     2517            case 8: //RW optical disk
     2518                pGeom->MediaType = RemovableMedia;
     2519                break;
     2520            case 9: //2.88 3.5 inch disk
     2521                pGeom->MediaType = F3_2Pt88_512;
     2522                break;
     2523            }
     2524            SetLastError(ERROR_SUCCESS_W);
     2525            return TRUE;
    25262526   }
    25272527   dprintf(("OSLibDosGetDiskGeometry: error %d -> %d", rc, error2WinError(rc)));
  • trunk/src/kernel32/osliblvm.cpp

    r8401 r9298  
    1 /* $Id: osliblvm.cpp,v 1.2 2002-05-10 14:55:13 sandervl Exp $ */
     1/* $Id: osliblvm.cpp,v 1.3 2002-09-26 16:06:07 sandervl Exp $ */
    22
    33/*
     
    319319        return FALSE;   //no more volumes
    320320    }
    321     volinfo = Get_Volume_Information(volctrl->Volume_Control_Data[volindex].Volume_Handle, &lasterror);
    322     if(lasterror != LVM_ENGINE_NO_ERROR) {
    323         DebugInt3();
    324         return FALSE;
     321    while(volindex < volctrl->Count) {
     322        volinfo = Get_Volume_Information(volctrl->Volume_Control_Data[volindex].Volume_Handle, &lasterror);
     323        if(lasterror != LVM_ENGINE_NO_ERROR) {
     324            DebugInt3();
     325            return FALSE;
     326        }
     327        //Don't report anything about LVM volumes until we support all those
     328        //fancy features (like spanned volumes)
     329        if(volinfo.Compatibility_Volume == TRUE) break;
     330        dprintf(("Ignoring LVM volume %s", volinfo.Volume_Name));
     331        volindex++;
     332    }
     333    if(volindex >= volctrl->Count) {
     334        return FALSE;   //no more volumes
    325335    }
    326336    strncpy(lpszVolumeName, volinfo.Volume_Name, min(sizeof(volinfo.Volume_Name), cchBufferLength)-1);
     
    428438    pPartition->StartingOffset.u.HighPart = partctrl.Partition_Array[0].Partition_Start >> 23;
    429439    pPartition->StartingOffset.u.LowPart  = partctrl.Partition_Array[0].Partition_Start << 9;
     440//    pPartition->PartitionLength.u.HighPart= partctrl.Partition_Array[0].True_Partition_Size >> 23;
     441//    pPartition->PartitionLength.u.LowPart = partctrl.Partition_Array[0].True_Partition_Size << 9;
     442//    pPartition->HiddenSectors             = 0;
    430443    pPartition->PartitionLength.u.HighPart= partctrl.Partition_Array[0].Usable_Partition_Size >> 23;
    431444    pPartition->PartitionLength.u.LowPart = partctrl.Partition_Array[0].Usable_Partition_Size << 9;
     
    466479    }
    467480
     481    //TODO: spanned volumes
    468482    pVolExtent->NumberOfDiskExtents = 1;
    469483    pVolExtent->Extents[0].DiskNumber  = 0;
    470484    pVolExtent->Extents[0].StartingOffset.u.HighPart = partctrl.Partition_Array[0].Partition_Start >> 23;;
    471485    pVolExtent->Extents[0].StartingOffset.u.LowPart  = partctrl.Partition_Array[0].Partition_Start << 9;
     486//    pVolExtent->Extents[0].ExtentLength.u.HighPart   = partctrl.Partition_Array[0].True_Partition_Size >> 23;
     487//    pVolExtent->Extents[0].ExtentLength.u.LowPart    = partctrl.Partition_Array[0].True_Partition_Size << 9;
    472488    pVolExtent->Extents[0].ExtentLength.u.HighPart   = partctrl.Partition_Array[0].Usable_Partition_Size >> 23;
    473489    pVolExtent->Extents[0].ExtentLength.u.LowPart    = partctrl.Partition_Array[0].Usable_Partition_Size << 9;
    474490
     491    //find number of disk on which this volume is located
     492    diskinfo = Get_Drive_Control_Data(&lasterror);
     493    if(lasterror != LVM_ENGINE_NO_ERROR) {
     494        return FALSE;
     495    }
     496    for(int i=0;i<diskinfo.Count;i++) {
     497        if(diskinfo.Drive_Control_Data[i].Drive_Handle == partctrl.Partition_Array[0].Drive_Handle) {
     498            //win32 base = 0, os2 base = 1
     499            pVolExtent->Extents[0].DiskNumber = diskinfo.Drive_Control_Data[i].Drive_Number - 1;
     500#ifdef DEBUG
     501            if(diskinfo.Drive_Control_Data[i].Drive_Number == 0) DebugInt3();
     502#endif
     503            break;
     504        }
     505    }
     506    if(i == diskinfo.Count) {
     507        ret = FALSE;
     508    }
    475509    dprintf(("pVolExtent->NumberOfDiskExtents       %d", pVolExtent->NumberOfDiskExtents));
    476510    dprintf(("pVolExtent->Extents[0].DiskNumber     %d",  pVolExtent->Extents[0].DiskNumber));
     
    478512    dprintf(("pVolExtent->Extents[0].ExtentLength   %08x%08x", pVolExtent->Extents[0].ExtentLength.u.HighPart, pVolExtent->Extents[0].ExtentLength.u.LowPart));
    479513
    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     }
    494514    if(pfLVMVolume) {
    495515        *pfLVMVolume = (volinfo.Compatibility_Volume == FALSE);
     
    655675//******************************************************************************
    656676//******************************************************************************
    657 
     677BOOL OSLibLVMGetDiskGeometry(DWORD dwDiskNr, PDISK_GEOMETRY pGeom)
     678{
     679    Drive_Control_Array   driveinfo;
     680    Drive_Control_Record *pDriveRec;
     681    CARDINAL32            lasterror;
     682    BOOL                  ret = FALSE;
     683    int                   i;
     684
     685    driveinfo = Get_Drive_Control_Data(&lasterror);
     686    if(lasterror != LVM_ENGINE_NO_ERROR) {
     687        DebugInt3();
     688        return FALSE;
     689    }
     690    pDriveRec = driveinfo.Drive_Control_Data;
     691    if(pDriveRec == NULL) {
     692        DebugInt3();
     693        return FALSE;
     694    }
     695    if(dwDiskNr > driveinfo.Count) {
     696        DebugInt3();
     697        ret = FALSE;
     698        goto endfunc;
     699    }
     700    for(i=0;i<driveinfo.Count;i++) {
     701        if(pDriveRec->Drive_Number == dwDiskNr) {
     702            pGeom->Cylinders.u.LowPart  = pDriveRec->Cylinder_Count;
     703            pGeom->Cylinders.u.HighPart = 0;
     704            pGeom->TracksPerCylinder    = pDriveRec->Heads_Per_Cylinder;
     705            pGeom->SectorsPerTrack      = pDriveRec->Sectors_Per_Track;
     706            pGeom->BytesPerSector       = 512;
     707            pGeom->MediaType            = FixedMedia;
     708
     709            ret = TRUE;
     710            break;
     711        }
     712    }
     713endfunc:
     714    Free_Engine_Memory((ULONG)driveinfo.Drive_Control_Data);
     715    return ret;
     716}
     717//******************************************************************************
     718//******************************************************************************
  • trunk/src/kernel32/osliblvm.h

    r8401 r9298  
    1 /* $Id: osliblvm.h,v 1.2 2002-05-10 14:55:13 sandervl Exp $ */
     1/* $Id: osliblvm.h,v 1.3 2002-09-26 16:06:07 sandervl Exp $ */
    22/*
    33 * OS/2 LVM (Logical Volume Management) functions
     
    343343
    344344BOOL   OSLibLVMStripVolumeName(LPCSTR lpszWin32VolumeName, LPSTR lpszOS2VolumeName, DWORD cchBufferLength);
     345BOOL   OSLibLVMGetDiskGeometry(DWORD dwDiskNr, PDISK_GEOMETRY pGeom);
    345346
    346347#endif //__OSLIBLVM_H__
Note: See TracChangeset for help on using the changeset viewer.