VirtualBox

Ignore:
Timestamp:
Jun 1, 2017 7:40:58 AM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
115865
Message:

IPRT: rtManifestPtIos_Write: Handle gaps in the output as zero filled.

File:
1 edited

Legend:

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

    r62477 r67188  
    4343#include <iprt/vfs.h>
    4444#include <iprt/vfslowlevel.h>
     45#include <iprt/zero.h>
    4546
    4647
     
    411412{
    412413    PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis;
    413     AssertReturn(off == -1 || off == pThis->offCurPos, VERR_WRONG_ORDER);
    414414    Assert(RTVfsIoStrmTell(pThis->hVfsIos) == pThis->offCurPos);
    415415
     416    /*
     417     * Validate the offset.
     418     */
     419    if (off < 0 || off == pThis->offCurPos)
     420    { /* likely */ }
     421    else
     422    {
     423        /* We cannot go back and rewrite stuff. Sorry. */
     424        AssertReturn(off > pThis->offCurPos, VERR_WRONG_ORDER);
     425
     426        /*
     427         * We've got a gap between the current and new position.
     428         * Fill it with zeros and hope for the best.
     429         */
     430        uint64_t cbZeroGap = off - pThis->offCurPos;
     431        do
     432        {
     433            size_t cbToZero = cbZeroGap >= sizeof(g_abRTZero64K) ? sizeof(g_abRTZero64K) : (size_t)cbZeroGap;
     434            size_t cbZeroed = 0;
     435            int rc = RTVfsIoStrmWrite(pThis->hVfsIos, g_abRTZero64K, cbToZero, true /*fBlocking*/, &cbZeroed);
     436            if (RT_FAILURE(rc))
     437                return rc;
     438            pThis->offCurPos += cbZeroed;
     439            rtManifestHashesUpdate(pThis->pHashes, g_abRTZero64K, cbZeroed);
     440            cbZeroGap -= cbZeroed;
     441        } while (cbZeroGap > 0);
     442        Assert(off == pThis->offCurPos);
     443    }
     444
     445    /*
     446     * Do the writing.
     447     */
    416448    int rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, -1 /*off*/, pSgBuf, fBlocking, pcbWritten);
    417449    if (RT_SUCCESS(rc))
Note: See TracChangeset for help on using the changeset viewer.

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