VirtualBox

Changeset 64251 in vbox for trunk/src


Ignore:
Timestamp:
Oct 13, 2016 2:00:33 PM (8 years ago)
Author:
vboxsync
Message:

Devices/Storage/DrvHost*: Move the read/write/flush methods to the host specific code

Location:
trunk/src/VBox/Devices/Storage
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DrvHostBase-darwin.cpp

    r64246 r64251  
    154154}
    155155
     156
     157DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead)
     158{
     159    int rc = VINF_SUCCESS;
     160
     161    if (    pThis->ppScsiTaskDI
     162        &&  pThis->cbBlock)
     163    {
     164        /*
     165         * Issue a READ(12) request.
     166         */
     167        do
     168        {
     169            const uint32_t  LBA       = off / pThis->cbBlock;
     170            AssertReturn(!(off % pThis->cbBlock), VERR_INVALID_PARAMETER);
     171            uint32_t        cbRead32  =   cbRead > SCSI_MAX_BUFFER_SIZE
     172                                        ? SCSI_MAX_BUFFER_SIZE
     173                                        : (uint32_t)cbRead;
     174            const uint32_t  cBlocks   = cbRead32 / pThis->cbBlock;
     175            AssertReturn(!(cbRead % pThis->cbBlock), VERR_INVALID_PARAMETER);
     176            uint8_t         abCmd[16] =
     177            {
     178                SCSI_READ_12, 0,
     179                RT_BYTE4(LBA),     RT_BYTE3(LBA),     RT_BYTE2(LBA),     RT_BYTE1(LBA),
     180                RT_BYTE4(cBlocks), RT_BYTE3(cBlocks), RT_BYTE2(cBlocks), RT_BYTE1(cBlocks),
     181                0, 0, 0, 0, 0
     182            };
     183            rc = drvHostBaseScsiCmdOs(pThis, abCmd, 12, PDMMEDIATXDIR_FROM_DEVICE, pvBuf, &cbRead32, NULL, 0, 0);
     184
     185            off    += cbRead32;
     186            cbRead -= cbRead32;
     187            pvBuf   = (uint8_t *)pvBuf + cbRead32;
     188        } while ((cbRead > 0) && RT_SUCCESS(rc));
     189    }
     190    else
     191        rc = VERR_MEDIA_NOT_PRESENT;
     192
     193    return rc;
     194}
     195
     196
     197DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite)
     198{
     199    RT_NOREF4(pThis, off, pvBuf, cbWrite);
     200    return VERR_WRITE_PROTECT;
     201}
     202
     203
     204DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis)
     205{
     206    RT_NOREF1(pThis);
     207    return VINF_SUCCESS;
     208}
     209
  • trunk/src/VBox/Devices/Storage/DrvHostBase-freebsd.cpp

    r64246 r64251  
    155155}
    156156
     157
     158DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead)
     159{
     160    int rc = VINF_SUCCESS;
     161
     162    if (pThis->cbBlock)
     163    {
     164        /*
     165         * Issue a READ(12) request.
     166         */
     167        do
     168        {
     169            const uint32_t  LBA       = off / pThis->cbBlock;
     170            AssertReturn(!(off % pThis->cbBlock), VERR_INVALID_PARAMETER);
     171            uint32_t        cbRead32  =   cbRead > SCSI_MAX_BUFFER_SIZE
     172                                        ? SCSI_MAX_BUFFER_SIZE
     173                                        : (uint32_t)cbRead;
     174            const uint32_t  cBlocks   = cbRead32 / pThis->cbBlock;
     175            AssertReturn(!(cbRead % pThis->cbBlock), VERR_INVALID_PARAMETER);
     176            uint8_t         abCmd[16] =
     177            {
     178                SCSI_READ_12, 0,
     179                RT_BYTE4(LBA),     RT_BYTE3(LBA),     RT_BYTE2(LBA),     RT_BYTE1(LBA),
     180                RT_BYTE4(cBlocks), RT_BYTE3(cBlocks), RT_BYTE2(cBlocks), RT_BYTE1(cBlocks),
     181                0, 0, 0, 0, 0
     182            };
     183            rc = drvHostBaseScsiCmdOs(pThis, abCmd, 12, PDMMEDIATXDIR_FROM_DEVICE, pvBuf, &cbRead32, NULL, 0, 0);
     184
     185            off    += cbRead32;
     186            cbRead -= cbRead32;
     187            pvBuf   = (uint8_t *)pvBuf + cbRead32;
     188        } while ((cbRead > 0) && RT_SUCCESS(rc));
     189    }
     190    else
     191        rc = VERR_MEDIA_NOT_PRESENT;
     192
     193    return rc;
     194}
     195
     196
     197DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite)
     198{
     199    RT_NOREF4(pThis, off, pvBuf, cbWrite);
     200    return VERR_WRITE_PROTECT;
     201}
     202
     203
     204DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis)
     205{
     206    RT_NOREF1(pThis);
     207    return VINF_SUCCESS;
     208}
     209
  • trunk/src/VBox/Devices/Storage/DrvHostBase-linux.cpp

    r64246 r64251  
    163163}
    164164
     165
     166DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead)
     167{
     168    return RTFileReadAt(pThis->hFileDevice, off, pvBuf, cbRead, NULL);
     169}
     170
     171
     172DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite)
     173{
     174    return RTFileWriteAt(pThis->hFileDevice, off, pvBuf, cbWrite, NULL);
     175}
     176
     177
     178DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis)
     179{
     180    return RTFileFlush(pThis->hFileDevice);
     181}
     182
  • trunk/src/VBox/Devices/Storage/DrvHostBase-solaris.cpp

    r64246 r64251  
    183183}
    184184
     185
     186DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead)
     187{
     188    return RTFileReadAt(pThis->hFileDevice, off, pvBuf, cbRead, NULL);
     189}
     190
     191
     192DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite)
     193{
     194    return RTFileWriteAt(pThis->hFileDevice, off, pvBuf, cbWrite, NULL);
     195}
     196
     197
     198DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis)
     199{
     200    return RTFileFlush(pThis->hFileDevice);
     201}
     202
  • trunk/src/VBox/Devices/Storage/DrvHostBase-win.cpp

    r64248 r64251  
    221221}
    222222
     223
     224DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead)
     225{
     226    return RTFileReadAt(pThis->hFileDevice, off, pvBuf, cbRead, NULL);
     227}
     228
     229
     230DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite)
     231{
     232    return RTFileWriteAt(pThis->hFileDevice, off, pvBuf, cbWrite, NULL);
     233}
     234
     235
     236DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis)
     237{
     238    return RTFileFlush(pThis->hFileDevice);
     239}
     240
  • trunk/src/VBox/Devices/Storage/DrvHostBase.cpp

    r64246 r64251  
    145145     */
    146146    int rc;
    147 #ifdef RT_OS_DARWIN
    148     if (    pThis->fMediaPresent
    149         &&  pThis->ppScsiTaskDI
    150         &&  pThis->cbBlock)
    151 #elif defined(RT_OS_FREEBSD)
    152     if (    pThis->fMediaPresent
    153         &&  pThis->cbBlock)
    154 #else
    155147    if (pThis->fMediaPresent)
    156 #endif
    157     {
    158 #if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
    159         /*
    160          * Issue a READ(12) request.
    161          */
    162         do
    163         {
    164             const uint32_t  LBA       = off / pThis->cbBlock;
    165             AssertReturn(!(off % pThis->cbBlock), VERR_INVALID_PARAMETER);
    166             uint32_t        cbRead32  =   cbRead > SCSI_MAX_BUFFER_SIZE
    167                                         ? SCSI_MAX_BUFFER_SIZE
    168                                         : (uint32_t)cbRead;
    169             const uint32_t  cBlocks   = cbRead32 / pThis->cbBlock;
    170             AssertReturn(!(cbRead % pThis->cbBlock), VERR_INVALID_PARAMETER);
    171             uint8_t         abCmd[16] =
    172             {
    173                 SCSI_READ_12, 0,
    174                 RT_BYTE4(LBA),     RT_BYTE3(LBA),     RT_BYTE2(LBA),     RT_BYTE1(LBA),
    175                 RT_BYTE4(cBlocks), RT_BYTE3(cBlocks), RT_BYTE2(cBlocks), RT_BYTE1(cBlocks),
    176                 0, 0, 0, 0, 0
    177             };
    178             rc = drvHostBaseScsiCmdOs(pThis, abCmd, 12, PDMMEDIATXDIR_FROM_DEVICE, pvBuf, &cbRead32, NULL, 0, 0);
    179 
    180             off    += cbRead32;
    181             cbRead -= cbRead32;
    182             pvBuf   = (uint8_t *)pvBuf + cbRead32;
    183         } while ((cbRead > 0) && RT_SUCCESS(rc));
    184 
    185 #else
     148    {
    186149        /*
    187150         * Seek and read.
    188151         */
    189         rc = RTFileReadAt(pThis->hFileDevice, off, pvBuf, cbRead, NULL);
     152        rc = drvHostBaseReadOs(pThis, off, pvBuf, cbRead);
    190153        if (RT_SUCCESS(rc))
    191154        {
    192             Log2(("%s-%d: drvHostBaseRead: off=%#llx cbRead=%#x\n"
     155            Log2(("%s-%d: drvHostBaseReadOs: off=%#llx cbRead=%#x\n"
    193156                  "%16.*Rhxd\n",
    194157                  pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, off, cbRead, cbRead, pvBuf));
    195158        }
    196159        else
    197             Log(("%s-%d: drvHostBaseRead: RTFileReadAt(%RTfile, %#llx, %p, %#x) -> %Rrc ('%s')\n",
    198                  pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, pThis->hFileDevice,
     160            Log(("%s-%d: drvHostBaseReadOs: drvHostBaseReadOs(%#llx, %p, %#x) -> %Rrc ('%s')\n",
     161                 pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance,
    199162                 off, pvBuf, cbRead, rc, pThis->pszDevice));
    200 #endif
    201163    }
    202164    else
     
    229191        if (pThis->fMediaPresent)
    230192        {
    231 #if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
    232             /** @todo write support... */
    233             rc = VERR_WRITE_PROTECT;
    234 
    235 #else
    236193            /*
    237194             * Seek and write.
    238195             */
    239             rc = RTFileWriteAt(pThis->hFileDevice, off, pvBuf, cbWrite, NULL);
     196            rc = drvHostBaseWriteOs(pThis, off, pvBuf, cbWrite);
    240197            if (RT_FAILURE(rc))
    241                 Log(("%s-%d: drvHostBaseWrite: RTFileWriteAt(%RTfile, %#llx, %p, %#x) -> %Rrc ('%s')\n",
    242                      pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance, pThis->hFileDevice,
     198                Log(("%s-%d: drvHostBaseWrite: drvHostBaseWriteOs(%#llx, %p, %#x) -> %Rrc ('%s')\n",
     199                     pThis->pDrvIns->pReg->szName, pThis->pDrvIns->iInstance,
    243200                     off, pvBuf, cbWrite, rc, pThis->pszDevice));
    244 #endif
    245201        }
    246202        else
     
    266222
    267223    if (pThis->fMediaPresent)
    268     {
    269 #if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
    270         rc = VINF_SUCCESS;
    271         /** @todo scsi device buffer flush... */
    272 #else
    273         rc = RTFileFlush(pThis->hFileDevice);
    274 #endif
    275     }
     224        rc = drvHostBaseFlushOs(pThis);
    276225    else
    277226        rc = VERR_MEDIA_NOT_PRESENT;
  • trunk/src/VBox/Devices/Storage/DrvHostBase.h

    r64246 r64251  
    192192DECLHIDDEN(int) drvHostBaseScsiCmdOs(PDRVHOSTBASE pThis, const uint8_t *pbCmd, size_t cbCmd, PDMMEDIATXDIR enmTxDir,
    193193                                     void *pvBuf, uint32_t *pcbBuf, uint8_t *pbSense, size_t cbSense, uint32_t cTimeoutMillies);
    194 
    195194DECLHIDDEN(int) drvHostBaseGetMediaSizeOs(PDRVHOSTBASE pThis, uint64_t *pcb);
     195DECLHIDDEN(int) drvHostBaseReadOs(PDRVHOSTBASE pThis, uint64_t off, void *pvBuf, size_t cbRead);
     196DECLHIDDEN(int) drvHostBaseWriteOs(PDRVHOSTBASE pThis, uint64_t off, const void *pvBuf, size_t cbWrite);
     197DECLHIDDEN(int) drvHostBaseFlushOs(PDRVHOSTBASE pThis);
    196198
    197199/** Makes a PDRVHOSTBASE out of a PPDMIMOUNT. */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette