VirtualBox

Changeset 53148 in vbox


Ignore:
Timestamp:
Oct 26, 2014 6:03:09 PM (10 years ago)
Author:
vboxsync
Message:

Port a part of r95116 (disk encryption changes in 4.3) which was forgotten to trunk. Fixes starting a VM with an encrypted VHD image

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/vmm/pdmifs.h

    r52023 r53148  
    10311031
    10321032    /**
     1033     * Read bits - version for DevPcBios.
     1034     *
     1035     * @returns VBox status code.
     1036     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1037     * @param   off             Offset to start reading from. The offset must be aligned to a sector boundary.
     1038     * @param   pvBuf           Where to store the read bits.
     1039     * @param   cbRead          Number of bytes to read. Must be aligned to a sector boundary.
     1040     * @thread  Any thread.
     1041     *
     1042     * @note: Special version of pfnRead which doesn't try to suspend the VM when the DEKs for encrypted disks
     1043     *        are missing but just returns an error.
     1044     */
     1045    DECLR3CALLBACKMEMBER(int, pfnReadPcBios,(PPDMIBLOCK pInterface, uint64_t off, void *pvBuf, size_t cbRead));
     1046
     1047    /**
    10331048     * Write bits.
    10341049     *
     
    13661381     */
    13671382    DECLR3CALLBACKMEMBER(int, pfnRead,(PPDMIMEDIA pInterface, uint64_t off, void *pvBuf, size_t cbRead));
     1383
     1384    /**
     1385     * Read bits - version for DevPcBios.
     1386     *
     1387     * @returns VBox status code.
     1388     * @param   pInterface      Pointer to the interface structure containing the called function pointer.
     1389     * @param   off             Offset to start reading from. The offset must be aligned to a sector boundary.
     1390     * @param   pvBuf           Where to store the read bits.
     1391     * @param   cbRead          Number of bytes to read. Must be aligned to a sector boundary.
     1392     * @thread  Any thread.
     1393     *
     1394     * @note: Special version of pfnRead which doesn't try to suspend the VM when the DEKs for encrypted disks
     1395     *        are missing but just returns an error.
     1396     */
     1397    DECLR3CALLBACKMEMBER(int, pfnReadPcBios,(PPDMIMEDIA pInterface, uint64_t off, void *pvBuf, size_t cbRead));
    13681398
    13691399    /**
  • trunk/src/VBox/Devices/PC/DevPcBios.cpp

    r51520 r53148  
    298298    if (!pBlock)
    299299        return VERR_INVALID_PARAMETER;
    300     rc = pBlock->pfnRead(pBlock, 0, aMBR, sizeof(aMBR));
     300    rc = pBlock->pfnReadPcBios(pBlock, 0, aMBR, sizeof(aMBR));
    301301    if (RT_FAILURE(rc))
    302302        return rc;
  • trunk/src/VBox/Devices/Storage/DrvBlock.cpp

    r52023 r53148  
    148148
    149149
     150/** @copydoc PDMIBLOCK::pfnReadPcBios */
     151static DECLCALLBACK(int) drvblockReadPcBios(PPDMIBLOCK pInterface, uint64_t off, void *pvBuf, size_t cbRead)
     152{
     153    PDRVBLOCK pThis = PDMIBLOCK_2_DRVBLOCK(pInterface);
     154
     155    /*
     156     * Check the state.
     157     */
     158    if (!pThis->pDrvMedia)
     159    {
     160        AssertMsgFailed(("Invalid state! Not mounted!\n"));
     161        return VERR_PDM_MEDIA_NOT_MOUNTED;
     162    }
     163
     164    int rc = pThis->pDrvMedia->pfnReadPcBios(pThis->pDrvMedia, off, pvBuf, cbRead);
     165    return rc;
     166}
     167
     168
    150169/** @copydoc PDMIBLOCK::pfnWrite */
    151170static DECLCALLBACK(int) drvblockWrite(PPDMIBLOCK pInterface, uint64_t off, const void *pvBuf, size_t cbWrite)
     
    881900    /* IBlock. */
    882901    pThis->IBlock.pfnRead                   = drvblockRead;
     902    pThis->IBlock.pfnReadPcBios             = drvblockReadPcBios;
    883903    pThis->IBlock.pfnWrite                  = drvblockWrite;
    884904    pThis->IBlock.pfnFlush                  = drvblockFlush;
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r52063 r53148  
    16011601}
    16021602
     1603/** @copydoc PDMIMEDIA::pfnRead */
     1604static DECLCALLBACK(int) drvvdReadPcBios(PPDMIMEDIA pInterface,
     1605                                         uint64_t off, void *pvBuf, size_t cbRead)
     1606{
     1607    int rc = VINF_SUCCESS;
     1608
     1609    LogFlowFunc(("off=%#llx pvBuf=%p cbRead=%d\n", off, pvBuf, cbRead));
     1610    PVBOXDISK pThis = PDMIMEDIA_2_VBOXDISK(pInterface);
     1611
     1612    if (   pThis->pCfgCrypto
     1613        && !pThis->pIfSecKey)
     1614        return VERR_VD_DEK_MISSING;
     1615
     1616    if (!pThis->fBootAccelActive)
     1617        rc = VDRead(pThis->pDisk, off, pvBuf, cbRead);
     1618    else
     1619    {
     1620        /* Can we serve the request from the buffer? */
     1621        if (   off >= pThis->offDisk
     1622            && off - pThis->offDisk < pThis->cbDataValid)
     1623        {
     1624            size_t cbToCopy = RT_MIN(cbRead, pThis->offDisk + pThis->cbDataValid - off);
     1625
     1626            memcpy(pvBuf, pThis->pbData + (off - pThis->offDisk), cbToCopy);
     1627            cbRead -= cbToCopy;
     1628            off    += cbToCopy;
     1629            pvBuf   = (char *)pvBuf + cbToCopy;
     1630        }
     1631
     1632        if (   cbRead > 0
     1633            && cbRead < pThis->cbBootAccelBuffer)
     1634        {
     1635            /* Increase request to the buffer size and read. */
     1636            pThis->cbDataValid = RT_MIN(pThis->cbDisk - off, pThis->cbBootAccelBuffer);
     1637            pThis->offDisk = off;
     1638            rc = VDRead(pThis->pDisk, off, pThis->pbData, pThis->cbDataValid);
     1639            if (RT_FAILURE(rc))
     1640                pThis->cbDataValid = 0;
     1641            else
     1642                memcpy(pvBuf, pThis->pbData, cbRead);
     1643        }
     1644        else if (cbRead >= pThis->cbBootAccelBuffer)
     1645        {
     1646            pThis->fBootAccelActive = false; /* Deactiviate */
     1647        }
     1648    }
     1649
     1650    if (RT_SUCCESS(rc))
     1651        Log2(("%s: off=%#llx pvBuf=%p cbRead=%d\n%.*Rhxd\n", __FUNCTION__,
     1652              off, pvBuf, cbRead, cbRead, pvBuf));
     1653    LogFlowFunc(("returns %Rrc\n", rc));
     1654    return rc;
     1655}
     1656
     1657
    16031658/** @copydoc PDMIMEDIA::pfnWrite */
    16041659static DECLCALLBACK(int) drvvdWrite(PPDMIMEDIA pInterface,
     
    24222477    /* IMedia */
    24232478    pThis->IMedia.pfnRead               = drvvdRead;
     2479    pThis->IMedia.pfnReadPcBios         = drvvdReadPcBios;
    24242480    pThis->IMedia.pfnWrite              = drvvdWrite;
    24252481    pThis->IMedia.pfnFlush              = drvvdFlush;
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