VirtualBox

Ignore:
Timestamp:
Aug 19, 2023 2:57:05 AM (17 months ago)
Author:
vboxsync
Message:

IPRT,Storage,Puel: Changed the pfnRead and pfnWrite VFS methods and the RTVfsIoStrmSgRead, RTVfsIoStrmSgWrite, RTVfsFileSgRead and RTVfsFileSgWrite APIs to advance pSgBuf and respect the incoming position just like RTFileSgRead & RTFileSgWrite.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/checksum/manifest3.cpp

    r99758 r100908  
    306306 *
    307307 * @param   pThis               The passthru I/O stream instance data.
    308  * @param   pSgBuf              The scather/gather buffer.
     308 * @param   pSgBuf              The scather/gather buffer (clone, can be
     309 *                              updated).
    309310 * @param   cbLeft              The number of bytes to take from the buffer.
    310311 */
    311 static void rtManifestPtIos_UpdateHashes(PRTMANIFESTPTIOS pThis, PCRTSGBUF pSgBuf, size_t cbLeft)
    312 {
    313     for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
    314     {
    315         size_t cbSeg = pSgBuf->paSegs[iSeg].cbSeg;
    316         if (cbSeg > cbLeft)
    317             cbSeg = cbLeft;
    318         rtManifestHashesUpdate(pThis->pHashes, pSgBuf->paSegs[iSeg].pvSeg, cbSeg);
     312static void rtManifestPtIos_UpdateHashes(PRTMANIFESTPTIOS pThis, PRTSGBUF pSgBuf, size_t cbLeft)
     313{
     314    while (cbLeft > 0)
     315    {
     316        Assert(!RTSgBufIsAtEnd(pSgBuf));
     317        size_t             cbSeg = cbLeft;
     318        void const * const pvSeg = RTSgBufGetNextSegment(pSgBuf, &cbSeg);
     319        rtManifestHashesUpdate(pThis->pHashes, pvSeg, cbSeg);
    319320        cbLeft -= cbSeg;
    320         if (!cbLeft)
    321             break;
    322321    }
    323322}
     
    326325 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    327326 */
    328 static DECLCALLBACK(int) rtManifestPtIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     327static DECLCALLBACK(int) rtManifestPtIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    329328{
    330329    PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis;
     
    332331
    333332    /*
     333     * Clone the buffer for the manifest pass.
     334     */
     335    RTSGBUF CloneSgBuf;
     336    RTSgBufClone(&CloneSgBuf, pSgBuf);
     337
     338    /*
    334339     * To make sure we're continuing where we left off, we must have the exact
    335340     * stream position since a previous read using 'off' may change it.
     
    338343    if (offActual == pThis->offCurPos)
    339344    {
     345        size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf);
    340346        rc = RTVfsIoStrmSgRead(pThis->hVfsIos, off, pSgBuf, fBlocking, pcbRead);
    341347        if (RT_SUCCESS(rc))
    342348        {
    343             rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbRead ? *pcbRead : ~(size_t)0);
    344             if (!pcbRead)
    345                 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
    346                     pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg;
    347             else
    348                 pThis->offCurPos += *pcbRead;
     349            rtManifestPtIos_UpdateHashes(pThis, &CloneSgBuf, pcbRead ? *pcbRead : cbReq);
     350            pThis->offCurPos += pcbRead ? *pcbRead : cbReq;
    349351        }
    350352        Assert(RTVfsIoStrmTell(pThis->hVfsIos) == pThis->offCurPos);
     
    390392        {
    391393            /* See if there is anything to update the hash with. */
    392             size_t cbLeft = pcbRead ? *pcbRead : ~(size_t)0;
    393             for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     394            size_t cbLeft = pcbRead ? *pcbRead : RTSgBufCalcLengthLeft(&CloneSgBuf);
     395            while (cbLeft > 0)
    394396            {
    395                 size_t cbThis = pSgBuf->paSegs[iSeg].cbSeg;
    396                 if (cbThis > cbLeft)
    397                     cbThis = cbLeft;
     397                Assert(!RTSgBufIsAtEnd(&CloneSgBuf));
     398                size_t         cbSeg = cbLeft;
     399                const uint8_t *pbSeg = (uint8_t const *)RTSgBufGetNextSegment(&CloneSgBuf, &cbSeg);
    398400
    399401                if (   offActual >= pThis->offCurPos
    400                     && pThis->offCurPos < offActual + (ssize_t)cbThis)
     402                    && pThis->offCurPos < offActual + (ssize_t)cbSeg)
    401403                {
    402404                    size_t offSeg = (size_t)(offActual - pThis->offCurPos);
    403                     rtManifestHashesUpdate(pThis->pHashes, (uint8_t *)pSgBuf->paSegs[iSeg].pvSeg + offSeg, cbThis - offSeg);
    404                     pThis->offCurPos += cbThis - offSeg;
     405                    rtManifestHashesUpdate(pThis->pHashes, &pbSeg[offSeg], cbSeg - offSeg);
     406                    pThis->offCurPos += cbSeg - offSeg;
    405407                }
    406408
    407                 cbLeft -= cbThis;
    408                 if (!cbLeft)
    409                     break;
    410                 offActual += cbThis;
     409                cbLeft -= cbSeg;
    411410            }
    412411        }
     
    419418 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    420419 */
    421 static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     420static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    422421{
    423422    PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis;
     
    454453
    455454    /*
     455     * Clone the buffer for the manifest pass.
     456     */
     457    RTSGBUF CloneSgBuf;
     458    RTSgBufClone(&CloneSgBuf, pSgBuf);
     459    size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf);
     460
     461    /*
    456462     * Do the writing.
    457463     */
     
    459465    if (RT_SUCCESS(rc))
    460466    {
    461         rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbWritten ? *pcbWritten : ~(size_t)0);
    462         if (!pcbWritten)
    463             for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
    464                 pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg;
    465         else
    466             pThis->offCurPos += *pcbWritten;
     467        rtManifestPtIos_UpdateHashes(pThis, &CloneSgBuf, pcbWritten ? *pcbWritten : cbReq);
     468        pThis->offCurPos += pcbWritten ? *pcbWritten : cbReq;
    467469    }
    468470    return rc;
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