VirtualBox

Changeset 100908 in vbox


Ignore:
Timestamp:
Aug 19, 2023 2:57:05 AM (20 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
158845
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.

Location:
trunk
Files:
1 added
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/vfs.h

    r98103 r100908  
    11331133 * @sa      RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking
    11341134 */
    1135 RTDECL(int)         RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
     1135RTDECL(int)         RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
    11361136
    11371137/**
     
    11521152 * @sa      RTFileSgWrite, RTSocketSgWrite
    11531153 */
    1154 RTDECL(int)         RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
     1154RTDECL(int)         RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
    11551155
    11561156/**
     
    14561456 * @sa      RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking
    14571457 */
    1458 RTDECL(int)         RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
     1458RTDECL(int)         RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);
    14591459
    14601460/**
     
    14751475 * @sa      RTFileSgWrite, RTSocketSgWrite
    14761476 */
    1477 RTDECL(int)         RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
     1477RTDECL(int)         RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);
    14781478
    14791479/**
  • trunk/include/iprt/vfslowlevel.h

    r98103 r100908  
    922922     * @param   pvThis      The implementation specific file data.
    923923     * @param   off         Where to read at, -1 for the current position.
    924      * @param   pSgBuf      Gather buffer describing the bytes that are to be
    925      *                      written.
     924     * @param   pSgBuf      Gather buffer for the bytes that are to be read.
    926925     * @param   fBlocking   If @c true, the call is blocking, if @c false it
    927926     *                      should not block.
     
    932931     *          RTVfsFileReadAt, RTFileRead, RTFileReadAt.
    933932     */
    934     DECLCALLBACKMEMBER(int, pfnRead,(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead));
     933    DECLCALLBACKMEMBER(int, pfnRead,(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead));
    935934
    936935    /**
     
    951950     * @sa      RTFileWrite, RTFileWriteAt.
    952951     */
    953     DECLCALLBACKMEMBER(int, pfnWrite,(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten));
     952    DECLCALLBACKMEMBER(int, pfnWrite,(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten));
    954953
    955954    /**
  • 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;
  • trunk/src/VBox/Runtime/common/dvm/dvmvfs.cpp

    r98103 r100908  
    246246 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    247247 */
    248 static DECLCALLBACK(int) rtDvmVfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    249 {
    250     PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
    251     int rc = VINF_SUCCESS;
     248static DECLCALLBACK(int) rtDvmVfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     249{
     250    PRTVFSDVMFILE const pThis = (PRTVFSDVMFILE)pvThis;
    252251
    253252    Assert(pSgBuf->cSegs == 1);
     
    257256     * Find the current position and check if it's within the volume.
    258257     */
     258    uint64_t const cbVol = RTDvmVolumeGetSize(pThis->hVol);
    259259    uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off;
    260     if (offUnsigned >= RTDvmVolumeGetSize(pThis->hVol))
     260    if (offUnsigned >= cbVol)
    261261    {
    262262        if (pcbRead)
     
    269269    }
    270270
    271     size_t cbLeftToRead;
    272     if (offUnsigned + pSgBuf->paSegs[0].cbSeg > RTDvmVolumeGetSize(pThis->hVol))
    273     {
    274         if (!pcbRead)
    275             return VERR_EOF;
    276         *pcbRead = cbLeftToRead = (size_t)(RTDvmVolumeGetSize(pThis->hVol) - offUnsigned);
     271    size_t       cbSeg = 0;
     272    void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     273
     274    int    rcRet = VINF_SUCCESS;
     275    size_t cbToRead;
     276    if (cbSeg <= cbVol - offUnsigned)
     277        cbToRead = cbSeg;
     278    else if (pcbRead)
     279    {
     280        rcRet    = VINF_EOF;
     281        cbToRead = (size_t)(cbVol - offUnsigned);
    277282    }
    278283    else
    279     {
    280         cbLeftToRead = pSgBuf->paSegs[0].cbSeg;
    281         if (pcbRead)
    282             *pcbRead = cbLeftToRead;
    283     }
     284        return VERR_EOF;
    284285
    285286    /*
    286287     * Ok, we've got a valid stretch within the file.  Do the reading.
    287288     */
    288     if (cbLeftToRead > 0)
    289     {
    290         rc = RTDvmVolumeRead(pThis->hVol, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToRead);
    291         if (RT_SUCCESS(rc))
    292             offUnsigned += cbLeftToRead;
     289    if (cbToRead > 0)
     290    {
     291        int rc2 = RTDvmVolumeRead(pThis->hVol, offUnsigned, pvSeg, cbToRead);
     292        if (RT_SUCCESS(rc2))
     293        {
     294            offUnsigned += cbToRead;
     295            RTSgBufAdvance(pSgBuf, cbToRead);
     296        }
     297        else
     298        {
     299            cbToRead = 0;
     300            rcRet = rc2;
     301        }
    293302    }
    294303
    295304    pThis->offCurPos = offUnsigned;
    296     return rc;
     305    if (pcbRead)
     306        *pcbRead = cbToRead;
     307    return rcRet;
    297308}
    298309
     
    301312 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    302313 */
    303 static DECLCALLBACK(int) rtDvmVfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    304 {
    305     PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis;
    306     int rc = VINF_SUCCESS;
     314static DECLCALLBACK(int) rtDvmVfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     315{
     316    PRTVFSDVMFILE const pThis = (PRTVFSDVMFILE)pvThis;
    307317
    308318    Assert(pSgBuf->cSegs == 1);
     
    313323     * Writing beyond the end of a volume is not supported.
    314324     */
     325    uint64_t const cbVol = RTDvmVolumeGetSize(pThis->hVol);
    315326    uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off;
    316     if (offUnsigned >= RTDvmVolumeGetSize(pThis->hVol))
     327    if (offUnsigned >= cbVol)
    317328    {
    318329        if (pcbWritten)
     
    321332            pThis->offCurPos = offUnsigned;
    322333        }
    323         return VERR_NOT_SUPPORTED;
    324     }
    325 
    326     size_t cbLeftToWrite;
    327     if (offUnsigned + pSgBuf->paSegs[0].cbSeg > RTDvmVolumeGetSize(pThis->hVol))
    328     {
    329         if (!pcbWritten)
    330             return VERR_EOF;
    331         *pcbWritten = cbLeftToWrite = (size_t)(RTDvmVolumeGetSize(pThis->hVol) - offUnsigned);
    332     }
     334        return VERR_DISK_FULL; /** @todo VERR_DISK_FULL is not the best status code. */
     335    }
     336
     337    size_t       cbSeg = 0;
     338    void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     339
     340    size_t cbToWrite;
     341    if (cbSeg <= cbVol - offUnsigned)
     342        cbToWrite = cbSeg;
     343    else if (pcbWritten)
     344        cbToWrite = (size_t)(cbVol - offUnsigned);
    333345    else
    334     {
    335         cbLeftToWrite = pSgBuf->paSegs[0].cbSeg;
    336         if (pcbWritten)
    337             *pcbWritten = cbLeftToWrite;
    338     }
     346        return VERR_EOF; /** @todo status to use above? or rather use VERR_DISK_FULL? */
    339347
    340348    /*
    341349     * Ok, we've got a valid stretch within the file.  Do the reading.
    342350     */
    343     if (cbLeftToWrite > 0)
    344     {
    345         rc = RTDvmVolumeWrite(pThis->hVol, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite);
     351    int rc = VINF_SUCCESS;
     352    if (cbToWrite > 0)
     353    {
     354        rc = RTDvmVolumeWrite(pThis->hVol, offUnsigned, pvSeg, cbToWrite);
    346355        if (RT_SUCCESS(rc))
    347             offUnsigned += cbLeftToWrite;
     356        {
     357            offUnsigned += cbToWrite;
     358            RTSgBufAdvance(pSgBuf, cbToWrite);
     359        }
     360        else
     361            cbToWrite = 0;
    348362    }
    349363
    350364    pThis->offCurPos = offUnsigned;
     365    if (pcbWritten)
     366        *pcbWritten = cbToWrite;
    351367    return rc;
    352368}
  • trunk/src/VBox/Runtime/common/efi/efivarstorevfs.cpp

    r99739 r100908  
    557557 * @returns IPRT status code.
    558558 * @param   pThis               The EFI variable file instance.
    559  * @param   pvData              Pointer to the start of the data.
     559 * @param   pbData              Pointer to the start of the data.
    560560 * @param   cbData              Size of the variable data in bytes.
    561561 * @param   off                 Where to start reading relative from the data start offset.
     
    563563 * @param   pcbRead             Where to return the number of bytes read, optional.
    564564 */
    565 static int rtEfiVarStoreFile_ReadMem(PRTEFIVARFILE pThis, const void *pvData, size_t cbData,
    566                                      RTFOFF off, PCRTSGBUF pSgBuf, size_t *pcbRead)
    567 {
    568     int rc = VINF_SUCCESS;
    569     size_t cbRead = pSgBuf->paSegs[0].cbSeg;
    570     size_t cbThisRead = RT_MIN(cbData - off, cbRead);
    571     const uint8_t *pbData = (const uint8_t *)pvData;
     565static int rtEfiVarStoreFile_ReadMem(PRTEFIVARFILE pThis, const uint8_t *pbData, size_t cbData,
     566                                     RTFOFF off, PRTSGBUF pSgBuf, size_t *pcbRead)
     567{
     568    int          rc;
     569    size_t       cbSeg      = 0;
     570    void * const pvSeg      = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     571    size_t const cbDataLeft = (uint64_t)off < cbData ? cbData - (size_t)off : 0;
    572572    if (!pcbRead)
    573573    {
    574         if (cbThisRead == cbRead)
    575             memcpy(pSgBuf->paSegs[0].pvSeg, &pbData[off], cbThisRead);
     574        if (cbSeg <= cbDataLeft)
     575        {
     576            memcpy(pvSeg, &pbData[off], cbSeg);
     577            pThis->offFile = off + cbSeg;
     578            Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> VINF_SUCCESS\n", off, cbSeg));
     579            RTSgBufAdvance(pSgBuf, cbSeg);
     580            rc = VINF_SUCCESS;
     581        }
    576582        else
     583        {
     584            Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> VERR_EOF (cbDataLeft=%#x)\n", off, cbSeg, cbDataLeft));
    577585            rc = VERR_EOF;
    578 
    579         if (RT_SUCCESS(rc))
    580             pThis->offFile = off + cbThisRead;
    581         Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc));
     586        }
     587    }
     588    else if (cbDataLeft == 0)
     589    {
     590        Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> VINF_EOF *pcbRead=0\n", off, cbSeg));
     591        *pcbRead = 0;
     592        rc = VINF_EOF;
    582593    }
    583594    else
    584595    {
    585         if ((uint64_t)off >= cbData)
    586         {
    587             *pcbRead = 0;
    588             rc = VINF_EOF;
    589         }
    590         else
    591         {
    592             memcpy(pSgBuf->paSegs[0].pvSeg, &pbData[off], cbThisRead);
    593             /* Return VINF_EOF if beyond end-of-file. */
    594             if (cbThisRead < cbRead)
    595                 rc = VINF_EOF;
    596             pThis->offFile = off + cbThisRead;
    597             *pcbRead = cbThisRead;
    598         }
    599         Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, pSgBuf->paSegs[0].cbSeg, rc, *pcbRead));
     596        size_t const cbThisRead = RT_MAX(cbSeg, cbDataLeft);
     597        memcpy(pvSeg, &pbData[off], cbThisRead);
     598
     599        pThis->offFile = off + cbThisRead;
     600        *pcbRead = cbThisRead;
     601        RTSgBufAdvance(pSgBuf, cbThisRead);
     602
     603        /* Return VINF_EOF if beyond end-of-file. */
     604        rc = cbThisRead == cbSeg ? VINF_SUCCESS : VINF_EOF;
     605        Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, cbSeg, rc, cbThisRead));
    600606    }
    601607
     
    609615 * @returns IPRT status code.
    610616 * @param   pThis               The EFI variable file instance.
    611  * @param   pvData              Pointer to the start of the data.
     617 * @param   pbData              Pointer to the start of the data.
    612618 * @param   cbData              Size of the variable data in bytes.
    613619 * @param   off                 Where to start writing relative from the data start offset.
     
    615621 * @param   pcbWritten          Where to return the number of bytes written, optional.
    616622 */
    617 static int rtEfiVarStoreFile_WriteMem(PRTEFIVARFILE pThis, void *pvData, size_t cbData,
    618                                       RTFOFF off, PCRTSGBUF pSgBuf, size_t *pcbWritten)
    619 {
    620     int rc = VINF_SUCCESS;
    621     size_t cbWrite = pSgBuf->paSegs[0].cbSeg;
    622     size_t cbThisWrite = RT_MIN(cbData - off, cbWrite);
    623     uint8_t *pbData = (uint8_t *)pvData;
     623static int rtEfiVarStoreFile_WriteMem(PRTEFIVARFILE pThis, uint8_t *pbData, size_t cbData,
     624                                      RTFOFF off, PRTSGBUF pSgBuf, size_t *pcbWritten)
     625{
     626    int                rc;
     627    size_t             cbSeg      = 0;
     628    void const * const pvSeg      = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     629    size_t const       cbDataLeft = (uint64_t)off < cbData ? cbData - (size_t)off : 0;
    624630    if (!pcbWritten)
    625631    {
    626         if (cbThisWrite == cbWrite)
    627             memcpy(&pbData[off], pSgBuf->paSegs[0].pvSeg, cbThisWrite);
     632        if (cbSeg <= cbDataLeft)
     633        {
     634            memcpy(&pbData[off], pvSeg, cbSeg);
     635            pThis->offFile = off + cbSeg;
     636            RTSgBufAdvance(pSgBuf, cbSeg);
     637            Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> VINF_SUCCESS\n", off, cbSeg));
     638            rc = VINF_SUCCESS;
     639        }
    628640        else
    629             rc = VERR_EOF;
    630 
    631         if (RT_SUCCESS(rc))
    632             pThis->offFile = off + cbThisWrite;
    633         Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc));
     641        {
     642            Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> VERR_EOF\n", off, cbSeg));
     643            rc = VERR_EOF; /** @todo r=bird: This status seems bogus. Use VERR_FILE_TOO_BIG instead? */
     644        }
     645    }
     646    else if (cbDataLeft == 0)
     647    {
     648        *pcbWritten = 0;
     649        rc = VINF_EOF; /** @todo r=bird: This is weird. Implementing the read EOF protocol for a write... */
    634650    }
    635651    else
    636652    {
    637         if ((uint64_t)off >= cbData)
    638         {
    639             *pcbWritten = 0;
    640             rc = VINF_EOF;
    641         }
    642         else
    643         {
    644             memcpy(&pbData[off], pSgBuf->paSegs[0].pvSeg, cbThisWrite);
    645             /* Return VINF_EOF if beyond end-of-file. */
    646             if (cbThisWrite < cbWrite)
    647                 rc = VINF_EOF;
    648             pThis->offFile = off + cbThisWrite;
    649             *pcbWritten = cbThisWrite;
    650         }
    651         Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbWritten=%#x\n", off, pSgBuf->paSegs[0].cbSeg, rc, *pcbWritten));
    652     }
    653 
     653        size_t const cbThisWrite = RT_MAX(cbSeg, cbDataLeft);
     654        memcpy(&pbData[off], pvSeg, cbThisWrite);
     655
     656        pThis->offFile = off + cbThisWrite;
     657        *pcbWritten = cbThisWrite;
     658        RTSgBufAdvance(pSgBuf, cbThisWrite);
     659
     660        /* Return VINF_EOF if beyond end-of-file. */
     661        /** @todo r=bird: This is weird. Implementing the read EOF protocol for a write... */
     662        rc = cbThisWrite == cbSeg ? VINF_SUCCESS : VINF_EOF;
     663        Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbWritten=%#x\n", off, cbSeg, rc, cbThisWrite));
     664    }
    654665    return rc;
    655666}
     
    668679 */
    669680static int rtEfiVarStoreFile_ReadFile(PRTEFIVARFILE pThis, uint64_t offData, size_t cbData,
    670                                       RTFOFF off, PCRTSGBUF pSgBuf, size_t *pcbRead)
    671 {
    672     int rc;
    673     PRTEFIVARSTORE pVarStore = pThis->pVarStore;
    674     size_t cbRead = pSgBuf->paSegs[0].cbSeg;
    675     size_t cbThisRead = RT_MIN(cbData - off, cbRead);
    676     uint64_t offStart = offData + off;
     681                                      RTFOFF off, PRTSGBUF pSgBuf, size_t *pcbRead)
     682{
     683    int                  rc;
     684    PRTEFIVARSTORE const pVarStore  = pThis->pVarStore;
     685    size_t               cbSeg      = 0;
     686    void * const         pvSeg      = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     687    size_t const         cbDataLeft = (uint64_t)off < cbData ? cbData - (size_t)off : 0;
     688    uint64_t const       offBacking = offData + off;
    677689    if (!pcbRead)
    678690    {
    679         if (cbThisRead == cbRead)
    680             rc = RTVfsFileReadAt(pVarStore->hVfsBacking, offStart, pSgBuf->paSegs[0].pvSeg, cbThisRead, NULL);
     691        if (cbSeg <= cbDataLeft)
     692        {
     693            rc = RTVfsFileSgRead(pVarStore->hVfsBacking, offBacking, pSgBuf, true /*fBlocking*/, NULL /*pcbRead*/);
     694            if (RT_SUCCESS(rc))
     695                pThis->offFile = off + cbSeg;
     696            Log6(("rtEfiVarStoreFile_ReadFile: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, cbSeg, rc));
     697        }
    681698        else
     699        {
     700            Log6(("rtEfiVarStoreFile_ReadFile: off=%#RX64 cbSeg=%#x cbDataLeft=%#zx -> VERR_EOF\n", off, cbSeg, cbDataLeft));
    682701            rc = VERR_EOF;
    683 
     702        }
     703    }
     704    else if (cbDataLeft == 0)
     705    {
     706        Log6(("rtEfiVarStoreFile_ReadFile: off=%#RX64 cbSeg=%#x -> VINF_EOF\n", off, cbSeg));
     707        *pcbRead = 0;
     708        rc = VINF_EOF;
     709    }
     710    else
     711    {
     712        size_t const cbThisRead = RT_MAX(cbSeg, cbDataLeft);
     713        rc = RTVfsFileReadAt(pVarStore->hVfsBacking, offBacking, pvSeg, cbThisRead, NULL /*pcbRead*/);
    684714        if (RT_SUCCESS(rc))
     715        {
    685716            pThis->offFile = off + cbThisRead;
    686         Log6(("rtFsEfiVarStore_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc));
    687     }
    688     else
    689     {
    690         if ((uint64_t)off >= cbData)
    691         {
     717            *pcbRead = cbThisRead;
     718            RTSgBufAdvance(pSgBuf, cbThisRead);
     719
     720            /* Return VINF_EOF if beyond end-of-file. */
     721            rc = cbThisRead == cbSeg ? VINF_SUCCESS : VINF_EOF;
     722        }
     723        else
    692724            *pcbRead = 0;
    693             rc = VINF_EOF;
    694         }
    695         else
    696         {
    697             rc = RTVfsFileReadAt(pVarStore->hVfsBacking, offStart, pSgBuf->paSegs[0].pvSeg, cbThisRead, NULL);
    698             if (RT_SUCCESS(rc))
    699             {
    700                 /* Return VINF_EOF if beyond end-of-file. */
    701                 if (cbThisRead < cbRead)
    702                     rc = VINF_EOF;
    703                 pThis->offFile = off + cbThisRead;
    704                 *pcbRead = cbThisRead;
    705             }
    706             else
    707                 *pcbRead = 0;
    708         }
    709         Log6(("rtFsEfiVarStore_Read: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, pSgBuf->paSegs[0].cbSeg, rc, *pcbRead));
    710     }
    711 
     725        Log6(("rtFsEfiVarStore_Read: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, cbSeg, rc, *pcbRead));
     726    }
    712727    return rc;
    713728}
     
    10651080 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    10661081 */
    1067 static DECLCALLBACK(int) rtEfiVarStoreFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     1082static DECLCALLBACK(int) rtEfiVarStoreFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    10681083{
    10691084    PRTEFIVARFILE pThis = (PRTEFIVARFILE)pvThis;
     
    10791094    int rc;
    10801095    if (pThis->pEntry->cbObject)
    1081         rc = rtEfiVarStoreFile_ReadMem(pThis, (const uint8_t *)pVar + pThis->pEntry->offObject, pThis->pEntry->cbObject, off, pSgBuf, pcbRead);
     1096        rc = rtEfiVarStoreFile_ReadMem(pThis, (const uint8_t *)pVar + pThis->pEntry->offObject, pThis->pEntry->cbObject, off,
     1097                                       pSgBuf, pcbRead);
    10821098    else
    10831099    {
    10841100        /* Data section. */
    10851101        if (!pVar->offVarData)
    1086             rc = rtEfiVarStoreFile_ReadMem(pThis, pVar->pvData, pVar->cbData, off, pSgBuf, pcbRead);
     1102            rc = rtEfiVarStoreFile_ReadMem(pThis, (const uint8_t *)pVar->pvData, pVar->cbData, off, pSgBuf, pcbRead);
    10871103        else
    10881104            rc = rtEfiVarStoreFile_ReadFile(pThis, pVar->offVarData, pVar->cbData, off, pSgBuf, pcbRead);
     
    10961112 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    10971113 */
    1098 static DECLCALLBACK(int) rtEfiVarStoreFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     1114static DECLCALLBACK(int) rtEfiVarStoreFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    10991115{
    11001116    PRTEFIVARFILE pThis = (PRTEFIVARFILE)pvThis;
     
    11251141                rc = rtEfiVarStore_VarEnsureDataSz(pVar, off + pSgBuf->paSegs[0].cbSeg);
    11261142            if (RT_SUCCESS(rc))
    1127                 rc = rtEfiVarStoreFile_WriteMem(pThis, pVar->pvData, pVar->cbData, off, pSgBuf, pcbWritten);
     1143                rc = rtEfiVarStoreFile_WriteMem(pThis, (uint8_t *)pVar->pvData, pVar->cbData, off, pSgBuf, pcbWritten);
    11281144        }
    11291145    }
  • trunk/src/VBox/Runtime/common/fs/extvfs.cpp

    r99739 r100908  
    17161716 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    17171717 */
    1718 static DECLCALLBACK(int) rtFsExtFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     1718static DECLCALLBACK(int) rtFsExtFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    17191719{
    17201720    PRTFSEXTFILE pThis = (PRTFSEXTFILE)pvThis;
     
    17331733        rc = rtFsExtInode_Read(pThis->pVol, pThis->pInode, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbRead, NULL);
    17341734        if (RT_SUCCESS(rc))
     1735        {
    17351736            pThis->offFile = off + cbRead;
     1737            RTSgBufAdvance(pSgBuf, cbRead);
     1738        }
    17361739        Log6(("rtFsExtFile_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc));
    17371740    }
     
    17601763                pThis->offFile = off + cbRead;
    17611764                *pcbRead = cbRead;
     1765                RTSgBufAdvance(pSgBuf, cbRead);
    17621766            }
    17631767            else
     
    17741778 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    17751779 */
    1776 static DECLCALLBACK(int) rtFsExtFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     1780static DECLCALLBACK(int) rtFsExtFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    17771781{
    17781782    RT_NOREF(pvThis, off, pSgBuf, fBlocking, pcbWritten);
  • trunk/src/VBox/Runtime/common/fs/fatvfs.cpp

    r98103 r100908  
    21652165 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    21662166 */
    2167 static DECLCALLBACK(int) rtFsFatFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     2167static DECLCALLBACK(int) rtFsFatFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    21682168{
    21692169    PRTFSFATFILE     pThis   = (PRTFSFATFILE)pvThis;
     
    22302230    if (pcbRead)
    22312231        *pcbRead = cbRead;
     2232    RTSgBufAdvance(pSgBuf, cbRead);
    22322233    return rc;
    22332234}
     
    23272328 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    23282329 */
    2329 static DECLCALLBACK(int) rtFsFatFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     2330static DECLCALLBACK(int) rtFsFatFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    23302331{
    23312332    PRTFSFATFILE     pThis   = (PRTFSFATFILE)pvThis;
     
    24012402    if (pcbWritten)
    24022403        *pcbWritten = cbWritten;
     2404    RTSgBufAdvance(pSgBuf, cbWritten);
    24032405    return rc;
    24042406}
  • trunk/src/VBox/Runtime/common/fs/isomaker.cpp

    r98103 r100908  
    72807280 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    72817281 */
    7282 static DECLCALLBACK(int) rtFsIsoMakerOutFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     7282static DECLCALLBACK(int) rtFsIsoMakerOutFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    72837283{
    72847284    PRTFSISOMAKEROUTPUTFILE pThis     = (PRTFSISOMAKEROUTPUTFILE)pvThis;
     
    73967396    if (pcbRead)
    73977397        *pcbRead = cbRead;
     7398    RTSgBufAdvance(pSgBuf, cbRead);
    73987399    return rc;
    73997400}
  • trunk/src/VBox/Runtime/common/fs/isovfs.cpp

    r98103 r100908  
    21192119 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    21202120 */
    2121 static DECLCALLBACK(int) rtFsIsoFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     2121static DECLCALLBACK(int) rtFsIsoFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    21222122{
    21232123    PRTFSISOFILEOBJ  pThis   = (PRTFSISOFILEOBJ)pvThis;
     
    21402140    /* Update the file position and return. */
    21412141    pThis->offFile = off + offDelta;
     2142    RTSgBufAdvance(pSgBuf, offDelta);
     2143
    21422144    return rc;
    21432145#else
  • trunk/src/VBox/Runtime/common/fs/ntfsvfs.cpp

    r98103 r100908  
    23742374 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    23752375 */
    2376 static DECLCALLBACK(int) rtFsNtfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     2376static DECLCALLBACK(int) rtFsNtfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    23772377{
    23782378    PRTFSNTFSFILE pThis = (PRTFSNTFSFILE)pvThis;
     
    23912391        rc = rtFsNtfsAttr_Read(pThis->pShared->pData, off, pSgBuf->paSegs[0].pvSeg, cbRead);
    23922392        if (RT_SUCCESS(rc))
     2393        {
    23932394            pThis->offFile = off + cbRead;
     2395            RTSgBufAdvance(pSgBuf, cbRead);
     2396        }
    23942397        Log6(("rtFsNtfsFile_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc));
    23952398    }
     
    24182421                pThis->offFile = off + cbRead;
    24192422                *pcbRead = cbRead;
     2423                RTSgBufAdvance(pSgBuf, cbRead);
    24202424            }
    24212425            else
     
    24322436 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    24332437 */
    2434 static DECLCALLBACK(int) rtFsNtfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     2438static DECLCALLBACK(int) rtFsNtfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    24352439{
    24362440    PRTFSNTFSFILE pThis = (PRTFSNTFSFILE)pvThis;
     
    24512455        Log6(("rtFsNtfsFile_Write: off=%#RX64 cbToWrite=%#zx -> %Rrc\n", off, cbToWrite, rc));
    24522456        if (RT_SUCCESS(rc))
     2457        {
    24532458            pThis->offFile = off + cbToWrite;
     2459            RTSgBufAdvance(pSgBuf, cbToWrite);
     2460        }
    24542461        if (pcbWritten)
    24552462            *pcbWritten = RT_SUCCESS(rc) ? cbToWrite : 0;
     
    24662473            if (pcbWritten)
    24672474                *pcbWritten = cbWritten;
     2475            RTSgBufAdvance(pSgBuf, cbWritten);
    24682476            rc = VERR_EOF;
    24692477        }
  • trunk/src/VBox/Runtime/common/fs/xfsvfs.cpp

    r99739 r100908  
    14741474 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    14751475 */
    1476 static DECLCALLBACK(int) rtFsXfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     1476static DECLCALLBACK(int) rtFsXfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    14771477{
    14781478    PRTFSXFSFILE pThis = (PRTFSXFSFILE)pvThis;
     
    14911491        rc = rtFsXfsInode_Read(pThis->pVol, pThis->pInode, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbRead, NULL);
    14921492        if (RT_SUCCESS(rc))
     1493        {
    14931494            pThis->offFile = off + cbRead;
     1495            RTSgBufAdvance(pSgBuf, cbRead);
     1496        }
    14941497        Log6(("rtFsXfsFile_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc));
    14951498    }
     
    15181521                pThis->offFile = off + cbRead;
    15191522                *pcbRead = cbRead;
     1523                RTSgBufAdvance(pSgBuf, cbRead);
    15201524            }
    15211525            else
     
    15321536 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    15331537 */
    1534 static DECLCALLBACK(int) rtFsXfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     1538static DECLCALLBACK(int) rtFsXfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    15351539{
    15361540    RT_NOREF(pvThis, off, pSgBuf, fBlocking, pcbWritten);
  • trunk/src/VBox/Runtime/common/misc/sg.cpp

    r99961 r100908  
    439439    size_t cbLeft = cbAdvance;
    440440
    441     while (cbLeft)
     441    while (    cbLeft
     442           || (   pSgBuf->cbSegLeft == 0
     443               && pSgBuf->idxSeg > pSgBuf->cSegs))
    442444    {
    443445        size_t cbThisAdvance = cbLeft;
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r98103 r100908  
    110110        AssertPtrNull((pDirOps)->pfnCreateDir); \
    111111        AssertPtrNull((pDirOps)->pfnOpenSymlink); \
    112         AssertPtr((pDirOps)->pfnCreateSymlink); \
    113         AssertPtr((pDirOps)->pfnUnlinkEntry); \
     112        AssertPtrNull((pDirOps)->pfnCreateSymlink); \
     113        AssertPtrNull((pDirOps)->pfnUnlinkEntry); \
     114        AssertPtrNull((pDirOps)->pfnRenameEntry); \
    114115        AssertPtr((pDirOps)->pfnRewindDir); \
    115116        AssertPtr((pDirOps)->pfnReadDir); \
     
    32413242
    32423243                RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock);
    3243                 rc = pVfsParentDir->pOps->pfnUnlinkEntry(pVfsParentDir->Base.pvThis, pszEntryName, RTFS_TYPE_DIRECTORY);
     3244                if (pVfsParentDir->pOps->pfnUnlinkEntry)
     3245                    rc = pVfsParentDir->pOps->pfnUnlinkEntry(pVfsParentDir->Base.pvThis, pszEntryName, RTFS_TYPE_DIRECTORY);
     3246                else
     3247                    rc = VERR_NOT_SUPPORTED;
    32443248                RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock);
    32453249
     
    36123616    int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbRead);
    36133617    RTVfsLockReleaseWrite(pThis->Base.hLock);
     3618    Assert(rc != VINF_SUCCESS || RTSgBufIsAtEnd(&SgBuf));
    36143619    return rc;
    36153620}
     
    36353640    int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbRead);
    36363641    RTVfsLockReleaseWrite(pThis->Base.hLock);
     3642    Assert(rc != VINF_SUCCESS || RTSgBufIsAtEnd(&SgBuf));
    36373643    return rc;
    36383644}
     
    36603666        rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten);
    36613667        RTVfsLockReleaseWrite(pThis->Base.hLock);
     3668        Assert(!pcbWritten || *pcbWritten + RTSgBufCalcLengthLeft(&SgBuf) == cbToWrite || RT_FAILURE(rc));
    36623669    }
    36633670    else
     
    36893696        rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten);
    36903697        RTVfsLockReleaseWrite(pThis->Base.hLock);
     3698        Assert(!pcbWritten || *pcbWritten + RTSgBufCalcLengthLeft(&SgBuf) == cbToWrite || RT_FAILURE(rc));
    36913699    }
    36923700    else
     
    36963704
    36973705
    3698 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     3706RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    36993707{
    37003708    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     
    37173725        rc = VINF_SUCCESS;
    37183726
    3719         for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     3727        while (!RTSgBufIsAtEnd(pSgBuf))
    37203728        {
    37213729            RTSGBUF SgBuf;
    3722             RTSgBufInit(&SgBuf, &pSgBuf->paSegs[iSeg], 1);
    3723 
    3724             size_t cbReadSeg = pcbRead ? 0 : pSgBuf->paSegs[iSeg].cbSeg;
     3730            RTSGSEG SgSeg;
     3731            SgSeg.pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &SgSeg.cbSeg);
     3732            RTSgBufInit(&SgBuf, &SgSeg, 1);
     3733
     3734            size_t cbReadSeg = pcbRead ? 0 : SgSeg.cbSeg;
    37253735            rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbRead ? &cbReadSeg : NULL);
    37263736            if (RT_FAILURE(rc))
    37273737                break;
    37283738            cbRead += cbReadSeg;
    3729             if ((pcbRead && cbReadSeg != SgBuf.paSegs[0].cbSeg) || rc != VINF_SUCCESS)
     3739            RTSgBufAdvance(pSgBuf, cbReadSeg);
     3740            if ((pcbRead && cbReadSeg != SgSeg.cbSeg) || rc != VINF_SUCCESS)
    37303741                break;
    37313742            if (off != -1)
     
    37373748    }
    37383749    RTVfsLockReleaseWrite(pThis->Base.hLock);
    3739     return rc;
    3740 }
    3741 
    3742 
    3743 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     3750    Assert(rc != VINF_SUCCESS || RTSgBufIsAtEnd(pSgBuf));
     3751    return rc;
     3752}
     3753
     3754
     3755RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    37443756{
    37453757    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
     
    37643776            rc = VINF_SUCCESS;
    37653777
    3766             for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     3778            while (!RTSgBufIsAtEnd(pSgBuf))
    37673779            {
    37683780                RTSGBUF SgBuf;
    3769                 RTSgBufInit(&SgBuf, &pSgBuf->paSegs[iSeg], 1);
     3781                RTSGSEG SgSeg;
     3782                SgSeg.pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &SgSeg.cbSeg);
     3783                RTSgBufInit(&SgBuf, &SgSeg, 1);
    37703784
    37713785                size_t cbWrittenSeg = 0;
     
    37763790                {
    37773791                    cbWritten += cbWrittenSeg;
    3778                     if (cbWrittenSeg != SgBuf.paSegs[0].cbSeg)
     3792                    RTSgBufAdvance(pSgBuf, cbWrittenSeg);
     3793                    if (cbWrittenSeg != SgSeg.cbSeg)
    37793794                        break;
    37803795                    if (off != -1)
    37813796                        off += cbWrittenSeg;
    37823797                }
    3783                 else if (off != -1)
    3784                     off += pSgBuf->paSegs[iSeg].cbSeg;
     3798                else
     3799                {
     3800                    RTSgBufAdvance(pSgBuf, SgSeg.cbSeg);
     3801                    if (off != -1)
     3802                        off += SgSeg.cbSeg;
     3803                }
    37853804            }
    37863805
     
    42324251
    42334252
    4234 RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     4253RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    42354254{
    42364255    AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER);
     
    42454264
    42464265
    4247 RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     4266RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    42484267{
    42494268    AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER);
  • trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp

    r98103 r100908  
    264264 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    265265 */
    266 static DECLCALLBACK(int) rtVfsMemFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     266static DECLCALLBACK(int) rtVfsMemFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    267267{
    268268    PRTVFSMEMFILE pThis = (PRTVFSMEMFILE)pvThis;
     
    305305    if (cbLeftToRead > 0)
    306306    {
     307        RTSgBufAdvance(pSgBuf, cbLeftToRead);
     308
    307309        uint8_t        *pbDst   = (uint8_t *)pSgBuf->paSegs[0].pvSeg;
    308310        bool            fHit;
     
    458460 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    459461 */
    460 static DECLCALLBACK(int) rtVfsMemFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     462static DECLCALLBACK(int) rtVfsMemFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    461463{
    462464    PRTVFSMEMFILE pThis = (PRTVFSMEMFILE)pvThis;
     
    551553        pThis->Base.ObjInfo.cbObject = offUnsigned;
    552554
     555    size_t const cbWritten = pSgBuf->paSegs[0].cbSeg - cbLeftToWrite;
    553556    if (pcbWritten)
    554         *pcbWritten = pSgBuf->paSegs[0].cbSeg - cbLeftToWrite;
     557        *pcbWritten = cbWritten;
     558    RTSgBufAdvance(pSgBuf, cbWritten);
    555559    return rc;
    556560}
  • trunk/src/VBox/Runtime/common/vfs/vfsprogress.cpp

    r98103 r100908  
    149149 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    150150 */
    151 static DECLCALLBACK(int) rtVfsProgressFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     151static DECLCALLBACK(int) rtVfsProgressFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    152152{
    153153    PRTVFSPROGRESSFILE pThis = (PRTVFSPROGRESSFILE)pvThis;
     
    166166
    167167        /* Calc the request before calling down the stack. */
    168         size_t   cbReq = 0;
    169         unsigned i = pSgBuf->cSegs;
    170         while (i-- > 0)
    171             cbReq += pSgBuf->paSegs[i].cbSeg;
     168        size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf);
    172169
    173170        /* Do the read. */
     
    188185 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    189186 */
    190 static DECLCALLBACK(int) rtVfsProgressFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     187static DECLCALLBACK(int) rtVfsProgressFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    191188{
    192189    PRTVFSPROGRESSFILE pThis = (PRTVFSPROGRESSFILE)pvThis;
     
    205202
    206203        /* Calc the request before calling down the stack. */
    207         size_t   cbReq = 0;
    208         unsigned i = pSgBuf->cSegs;
    209         while (i-- > 0)
    210             cbReq += pSgBuf->paSegs[i].cbSeg;
     204        size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf);
    211205
    212206        /* Do the read. */
  • trunk/src/VBox/Runtime/common/vfs/vfsreadahead.cpp

    r98103 r100908  
    212212 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    213213 */
    214 static DECLCALLBACK(int) rtVfsReadAhead_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     214static DECLCALLBACK(int) rtVfsReadAhead_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    215215{
    216216    PRTVFSREADAHEAD pThis = (PRTVFSREADAHEAD)pvThis;
     
    348348        *pcbRead = cbTotalRead;
    349349    Assert(cbTotalRead <= pSgBuf->paSegs[0].cbSeg);
     350    RTSgBufAdvance(pSgBuf, cbTotalRead);
    350351
    351352    return rc;
     
    356357 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    357358 */
    358 static DECLCALLBACK(int) rtVfsReadAhead_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     359static DECLCALLBACK(int) rtVfsReadAhead_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    359360{
    360361    RT_NOREF_PV(pvThis); RT_NOREF_PV(off); RT_NOREF_PV(pSgBuf); RT_NOREF_PV(fBlocking); RT_NOREF_PV(pcbWritten);
  • trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp

    r98103 r100908  
    142142 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    143143 */
    144 static DECLCALLBACK(int) rtVfsStdFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     144static DECLCALLBACK(int) rtVfsStdFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    145145{
    146146    PRTVFSSTDFILE pThis = (PRTVFSSTDFILE)pvThis;
     
    150150    if (pSgBuf->cSegs == 1)
    151151    {
     152        size_t       cbToRead = 0;
     153        void * const pvDst    = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbToRead);
     154
    152155        if (off < 0)
    153             rc = RTFileRead(  pThis->hFile,      pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead);
     156            rc = RTFileRead(pThis->hFile, pvDst, cbToRead, pcbRead);
    154157        else
    155158        {
    156             rc = RTFileReadAt(pThis->hFile, off, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead);
     159            rc = RTFileReadAt(pThis->hFile, off, pvDst, cbToRead, pcbRead);
    157160            if (RT_SUCCESS(rc)) /* RTFileReadAt() doesn't increment the file-position indicator on some platforms */
    158                 rc = RTFileSeek(pThis->hFile, off + (pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg), RTFILE_SEEK_BEGIN, NULL);
     161                rc = RTFileSeek(pThis->hFile, off + (pcbRead ? *pcbRead : cbToRead), RTFILE_SEEK_BEGIN, NULL);
    159162        }
    160163        if (rc == VINF_SUCCESS && pcbRead)
    161             rc = rtVfsStdFile_ReadFixRC(pThis, off, pSgBuf->paSegs[0].cbSeg, *pcbRead);
     164            rc = rtVfsStdFile_ReadFixRC(pThis, off, cbToRead, *pcbRead);
     165        if (RT_SUCCESS(rc))
     166            RTSgBufAdvance(pSgBuf, pcbRead ? *pcbRead : cbToRead);
    162167    }
    163168    else
    164169    {
    165         size_t  cbSeg      = 0;
    166         size_t  cbRead     = 0;
    167         size_t  cbReadSeg  = 0;
     170        size_t  cbSeg  = 0;
     171        size_t  cbRead = 0;
    168172        rc = VINF_SUCCESS;
    169173
    170         for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     174        while (!RTSgBufIsAtEnd(pSgBuf))
    171175        {
    172             void *pvSeg = pSgBuf->paSegs[iSeg].pvSeg;
    173             cbSeg       = pSgBuf->paSegs[iSeg].cbSeg;
    174 
    175             cbReadSeg = cbSeg;
     176            void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     177
     178            size_t  cbReadSeg  = cbSeg;
    176179            if (off < 0)
    177180                rc = RTFileRead(  pThis->hFile,      pvSeg, cbSeg, pcbRead ? &cbReadSeg : NULL);
     
    184187            if (RT_FAILURE(rc))
    185188                break;
     189
    186190            if (off >= 0)
    187191                off += cbReadSeg;
    188192            cbRead  += cbReadSeg;
     193            RTSgBufAdvance(pSgBuf, cbReadSeg);
     194
    189195            if ((pcbRead && cbReadSeg != cbSeg) || rc != VINF_SUCCESS)
    190196                break;
     
    195201            *pcbRead = cbRead;
    196202            if (rc == VINF_SUCCESS)
    197                 rc = rtVfsStdFile_ReadFixRC(pThis, off, cbSeg, cbReadSeg);
     203                rc = rtVfsStdFile_ReadFixRC(pThis, off, cbSeg, cbRead);
    198204        }
    199205    }
     
    206212 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    207213 */
    208 static DECLCALLBACK(int) rtVfsStdFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     214static DECLCALLBACK(int) rtVfsStdFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    209215{
    210216    PRTVFSSTDFILE pThis = (PRTVFSSTDFILE)pvThis;
     
    214220    if (pSgBuf->cSegs == 1)
    215221    {
     222        size_t             cbToWrite = 0;
     223        void const * const pvSrc    = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbToWrite);
     224
    216225        if (off < 0)
    217             rc = RTFileWrite(pThis->hFile, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbWritten);
     226            rc = RTFileWrite(pThis->hFile, pvSrc, cbToWrite, pcbWritten);
    218227        else
    219228        {
    220             rc = RTFileWriteAt(pThis->hFile, off, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbWritten);
     229            rc = RTFileWriteAt(pThis->hFile, off, pvSrc, cbToWrite, pcbWritten);
    221230            if (RT_SUCCESS(rc)) /* RTFileWriteAt() doesn't increment the file-position indicator on some platforms */
    222                 rc = RTFileSeek(pThis->hFile, off + (pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg), RTFILE_SEEK_BEGIN,
    223                                 NULL);
     231                rc = RTFileSeek(pThis->hFile, off + (pcbWritten ? *pcbWritten : cbToWrite), RTFILE_SEEK_BEGIN, NULL);
    224232        }
     233        if (RT_SUCCESS(rc))
     234            RTSgBufAdvance(pSgBuf, pcbWritten ? *pcbWritten : cbToWrite);
    225235    }
    226236    else
     
    231241        rc = VINF_SUCCESS;
    232242
    233         for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     243        while (!RTSgBufIsAtEnd(pSgBuf))
    234244        {
    235             void   *pvSeg  = pSgBuf->paSegs[iSeg].pvSeg;
    236             size_t  cbSeg  = pSgBuf->paSegs[iSeg].cbSeg;
     245            size_t             cbSeg      = 0;
     246            void const * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
    237247
    238248            cbWrittenSeg = 0;
     
    253263            if (pcbWritten)
    254264            {
     265                RTSgBufAdvance(pSgBuf, cbWrittenSeg);
    255266                cbWritten += cbWrittenSeg;
    256267                if (cbWrittenSeg != cbSeg)
    257268                    break;
    258269            }
     270            else
     271                RTSgBufAdvance(pSgBuf, cbSeg);
    259272        }
    260273
  • trunk/src/VBox/Runtime/common/vfs/vfsstdpipe.cpp

    r98103 r100908  
    9797 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    9898 */
    99 static DECLCALLBACK(int) rtVfsStdPipe_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     99static DECLCALLBACK(int) rtVfsStdPipe_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    100100{
    101101    PRTVFSSTDPIPE pThis = (PRTVFSSTDPIPE)pvThis;
     
    111111            rc = RTPipeRead(        pThis->hPipe, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead);
    112112        if (RT_SUCCESS(rc))
    113             pThis->offFakePos += pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg;
     113        {
     114            size_t const cbAdv = pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg;
     115            pThis->offFakePos += cbAdv;
     116            RTSgBufAdvance(pSgBuf, cbAdv);
     117        }
    114118    }
    115119    else
    116120    {
    117         size_t  cbSeg      = 0;
    118121        size_t  cbRead     = 0;
    119122        size_t  cbReadSeg  = 0;
     
    121124        rc = VINF_SUCCESS;
    122125
    123         for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     126        while (!RTSgBufIsAtEnd(pSgBuf))
    124127        {
    125             void *pvSeg = pSgBuf->paSegs[iSeg].pvSeg;
    126             cbSeg       = pSgBuf->paSegs[iSeg].cbSeg;
     128            size_t cbSeg = 0;
     129            void  *pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
    127130
    128131            cbReadSeg = cbSeg;
     
    133136            if (RT_FAILURE(rc))
    134137                break;
    135             pThis->offFakePos += pcbRead ? cbReadSeg : cbSeg;
    136             cbRead += cbReadSeg;
     138
     139            pThis->offFakePos += cbReadSeg;
     140            cbRead            += cbReadSeg;
     141            RTSgBufAdvance(pSgBuf, cbReadSeg);
    137142            if (rc != VINF_SUCCESS)
    138143                break;
     
    151156 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    152157 */
    153 static DECLCALLBACK(int) rtVfsStdPipe_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     158static DECLCALLBACK(int) rtVfsStdPipe_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    154159{
    155160    PRTVFSSTDPIPE pThis = (PRTVFSSTDPIPE)pvThis;
     
    164169            rc = RTPipeWrite(        pThis->hPipe, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbWritten);
    165170        if (RT_SUCCESS(rc))
    166             pThis->offFakePos += pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg;
     171        {
     172            size_t const cbAdv = pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg;
     173            pThis->offFakePos += cbAdv;
     174            RTSgBufAdvance(pSgBuf, cbAdv);
     175        }
    167176    }
    168177    else
     
    173182        rc = VINF_SUCCESS;
    174183
    175         for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
     184        while (!RTSgBufIsAtEnd(pSgBuf))
    176185        {
    177             void   *pvSeg  = pSgBuf->paSegs[iSeg].pvSeg;
    178             size_t  cbSeg  = pSgBuf->paSegs[iSeg].cbSeg;
     186            size_t      cbSeg = 0;
     187            void const *pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
    179188
    180189            cbWrittenSeg = 0;
     
    185194            if (RT_FAILURE(rc))
    186195                break;
    187             pThis->offFakePos += pcbWritten ? cbWrittenSeg : cbSeg;
     196
     197            size_t const cbAdv = pcbWritten ? cbWrittenSeg : cbSeg;
     198            pThis->offFakePos += cbAdv;
     199            RTSgBufAdvance(pSgBuf, cbAdv);
     200
    188201            if (pcbWritten)
    189202            {
  • trunk/src/VBox/Runtime/common/zip/cpiovfs.cpp

    r98103 r100908  
    484484 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    485485 */
    486 static DECLCALLBACK(int) rtZipCpioFssIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     486static DECLCALLBACK(int) rtZipCpioFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    487487{
    488488    PRTZIPCPIOIOSTREAM pThis = (PRTZIPCPIOIOSTREAM)pvThis;
     
    518518    int rc = RTVfsIoStrmReadAt(pThis->hVfsIos, pThis->offStart + off, pSgBuf->paSegs[0].pvSeg, cbToRead, fBlocking, pcbRead);
    519519    pThis->offFile = off + *pcbRead;
     520    RTSgBufAdvance(pSgBuf, *pcbRead);
     521
    520522    if (pThis->offFile >= pThis->cbFile)
    521523    {
     
    532534 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    533535 */
    534 static DECLCALLBACK(int) rtZipCpioFssIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     536static DECLCALLBACK(int) rtZipCpioFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    535537{
    536538    /* Cannot write to a read-only I/O stream. */
  • trunk/src/VBox/Runtime/common/zip/gzipvfs.cpp

    r98103 r100908  
    289289 * @param   fBlocking       Whether to block or not.
    290290 * @param   pcbRead         Where to store the number of bytes actually read.
    291  */
    292 static int rtZipGzip_ReadOneSeg(PRTZIPGZIPSTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead)
     291 * @param   pSgBuf          The segment buffer descriptor, for advancing.
     292 */
     293static int rtZipGzip_ReadOneSeg(PRTZIPGZIPSTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking,
     294                                size_t *pcbRead, PRTSGBUF pSgBuf)
    293295{
    294296    /*
     
    324326        {
    325327            size_t cbReadIn = ~(size_t)0;
     328            RTSgBufReset(&pThis->SgBuf);
    326329            rc = RTVfsIoStrmSgRead(pThis->hVfsIos, -1 /*off*/, &pThis->SgBuf, fBlocking, &cbReadIn);
    327330            if (rc != VINF_SUCCESS)
     
    375378    if (pcbRead)
    376379        *pcbRead      = cbRead;
     380    RTSgBufAdvance(pSgBuf, cbRead);
    377381
    378382    return rc;
     
    383387 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    384388 */
    385 static DECLCALLBACK(int) rtZipGzip_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     389static DECLCALLBACK(int) rtZipGzip_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    386390{
    387391    PRTZIPGZIPSTREAM pThis = (PRTZIPGZIPSTREAM)pvThis;
     
    392396    AssertReturn(off == -1 || off == pThis->offStream , VERR_INVALID_PARAMETER);
    393397
    394     return rtZipGzip_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead);
     398    return rtZipGzip_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead, pSgBuf);
    395399}
    396400
     
    517521 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    518522 */
    519 static DECLCALLBACK(int) rtZipGzip_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     523static DECLCALLBACK(int) rtZipGzip_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    520524{
    521525    PRTZIPGZIPSTREAM pThis = (PRTZIPGZIPSTREAM)pvThis;
     
    554558    if (pcbWritten)
    555559        *pcbWritten = cbWritten;
     560    RTSgBufAdvance(pSgBuf, cbWritten);
    556561    return rc;
    557562}
  • trunk/src/VBox/Runtime/common/zip/lzmavfs.cpp

    r98766 r100908  
    215215 * @param   fBlocking       Whether to block or not.
    216216 * @param   pcbRead         Where to store the number of bytes actually read.
    217  */
    218 static int rtZipLzma_ReadOneSeg(PRTZIPLZMASTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead)
     217 * @param   pSgBuf          The S/G buffer descriptor, for advancing.
     218 */
     219static int rtZipLzma_ReadOneSeg(PRTZIPLZMASTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking,
     220                                size_t *pcbRead, PRTSGBUF pSgBuf)
    219221{
    220222    /*
     
    243245        {
    244246            size_t cbReadIn = ~(size_t)0;
     247            RTSgBufReset(&pThis->SgBuf);
    245248            rc = RTVfsIoStrmSgRead(pThis->hVfsIos, -1 /*off*/, &pThis->SgBuf, fBlocking, &cbReadIn);
    246249            if (rc != VINF_SUCCESS)
     
    298301    if (pcbRead)
    299302        *pcbRead      = cbRead;
     303    RTSgBufAdvance(pSgBuf, cbRead);
    300304
    301305    return rc;
     
    306310 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    307311 */
    308 static DECLCALLBACK(int) rtZipLzma_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     312static DECLCALLBACK(int) rtZipLzma_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    309313{
    310314    PRTZIPLZMASTREAM pThis = (PRTZIPLZMASTREAM)pvThis;
     
    315319    AssertReturn(off == -1 || off == pThis->offStream , VERR_INVALID_PARAMETER);
    316320
    317     return rtZipLzma_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead);
     321    return rtZipLzma_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead, pSgBuf);
    318322}
    319323
     
    440444 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    441445 */
    442 static DECLCALLBACK(int) rtZipLzma_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     446static DECLCALLBACK(int) rtZipLzma_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    443447{
    444448    PRTZIPLZMASTREAM pThis = (PRTZIPLZMASTREAM)pvThis;
     
    477481    if (pcbWritten)
    478482        *pcbWritten = cbWritten;
     483    RTSgBufAdvance(pSgBuf, cbWritten);
     484
    479485    return rc;
    480486}
  • trunk/src/VBox/Runtime/common/zip/pkzip.cpp

    r98103 r100908  
    9999 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    100100 */
    101 static DECLCALLBACK(int) memFssIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     101static DECLCALLBACK(int) memFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    102102{
    103103    PMEMIOSTREAM pThis = (PMEMIOSTREAM)pvThis;
     
    123123    if (pcbRead)
    124124        *pcbRead = cbToRead;
     125    RTSgBufAdvance(pSgBuf, cbToRead);
    125126
    126127    return VINF_SUCCESS;
     
    130131 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    131132 */
    132 static DECLCALLBACK(int) memFssIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     133static DECLCALLBACK(int) memFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    133134{
    134135    RT_NOREF_PV(pvThis); RT_NOREF_PV(off); RT_NOREF_PV(pSgBuf); RT_NOREF_PV(fBlocking); RT_NOREF_PV(pcbWritten);
  • trunk/src/VBox/Runtime/common/zip/pkzipvfs.cpp

    r98103 r100908  
    907907 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    908908 */
    909 static DECLCALLBACK(int) rtZipPkzipFssIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     909static DECLCALLBACK(int) rtZipPkzipFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    910910{
    911911    PRTZIPPKZIPIOSTREAM pThis = (PRTZIPPKZIPIOSTREAM)pvThis;
     
    986986    int rc = RTZipDecompress(pThis->pZip, pSgBuf->paSegs[0].pvSeg, cbToRead, pcbRead);
    987987    pThis->offFile = off + *pcbRead;
     988    RTSgBufAdvance(pSgBuf, *pcbRead);
     989
    988990    if (pThis->offFile >= pThis->cbFile)
    989991    {
     
    995997}
    996998
    997 static DECLCALLBACK(int) rtZipPkzipFssIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     999static DECLCALLBACK(int) rtZipPkzipFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    9981000{
    9991001    RT_NOREF_PV(pvThis); RT_NOREF_PV(off); RT_NOREF_PV(pSgBuf); RT_NOREF_PV(fBlocking); RT_NOREF_PV(pcbWritten);
  • trunk/src/VBox/Runtime/common/zip/tarvfs.cpp

    r98325 r100908  
    872872 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    873873 */
    874 static DECLCALLBACK(int) rtZipTarFssIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     874static DECLCALLBACK(int) rtZipTarFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    875875{
    876876    PRTZIPTARIOSTREAM pThis = (PRTZIPTARIOSTREAM)pvThis;
     
    906906    int rc = RTVfsIoStrmReadAt(pThis->hVfsIos, pThis->offStart + off, pSgBuf->paSegs[0].pvSeg, cbToRead, fBlocking, pcbRead);
    907907    pThis->offFile = off + *pcbRead;
     908    RTSgBufAdvance(pSgBuf, *pcbRead);
     909
    908910    if (pThis->offFile >= pThis->cbFile)
    909911    {
     
    920922 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    921923 */
    922 static DECLCALLBACK(int) rtZipTarFssIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     924static DECLCALLBACK(int) rtZipTarFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    923925{
    924926    /* Cannot write to a read-only I/O stream. */
  • trunk/src/VBox/Runtime/common/zip/tarvfswriter.cpp

    r99739 r100908  
    753753 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    754754 */
    755 static DECLCALLBACK(int) rtZipTarWriterPush_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     755static DECLCALLBACK(int) rtZipTarWriterPush_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    756756{
    757757    /* No read support, sorry. */
     
    765765 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    766766 */
    767 static DECLCALLBACK(int) rtZipTarWriterPush_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     767static DECLCALLBACK(int) rtZipTarWriterPush_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    768768{
    769769    PRTZIPTARFSSTREAMWRITERPUSH pPush   = (PRTZIPTARFSSTREAMWRITERPUSH)pvThis;
     
    810810            if (pcbWritten)
    811811                *pcbWritten = cbWritten;
     812            RTSgBufAdvance(pSgBuf, cbWritten);
    812813        }
    813814    }
  • trunk/src/VBox/Runtime/common/zip/xarvfs.cpp

    r98103 r100908  
    854854 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    855855 */
    856 static DECLCALLBACK(int) rtZipXarFssIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     856static DECLCALLBACK(int) rtZipXarFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    857857{
    858858    PRTZIPXARIOSTREAM pThis = (PRTZIPXARIOSTREAM)pvThis;
     
    918918    /* Update the file position. */
    919919    pThis->offCurPos += cbActuallyRead;
     920    RTSgBufAdvance(pSgBuf, cbActuallyRead);
    920921
    921922    /*
     
    963964 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    964965 */
    965 static DECLCALLBACK(int) rtZipXarFssIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     966static DECLCALLBACK(int) rtZipXarFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    966967{
    967968    /* Cannot write to a read-only I/O stream. */
     
    12261227 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    12271228 */
    1228 static DECLCALLBACK(int) rtZipXarFssDecompIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     1229static DECLCALLBACK(int) rtZipXarFssDecompIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    12291230{
    12301231    PRTZIPXARDECOMPIOS pThis = (PRTZIPXARDECOMPIOS)pvThis;
     
    12431244     * validate off wrt data digest updating.
    12441245     */
    1245     int rc = RTVfsIoStrmReadAt(pThis->hVfsIosDecompressor, off, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg,
    1246                                fBlocking, pcbRead);
     1246    size_t       cbSeg = 0;
     1247    void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     1248    int rc = RTVfsIoStrmReadAt(pThis->hVfsIosDecompressor, off, pvSeg, cbSeg, fBlocking, pcbRead);
    12471249    if (RT_FAILURE(rc))
    12481250        return rc;
     
    12511253     * Hash the data.  When reaching the end match against the expected digest.
    12521254     */
    1253     size_t cbActuallyRead = pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg;
     1255    size_t const cbActuallyRead = pcbRead ? *pcbRead : cbSeg;
    12541256    pThis->offCurPos += cbActuallyRead;
     1257    RTSgBufAdvance(pSgBuf, cbActuallyRead);
    12551258    rtZipXarHashUpdate(&pThis->CtxExtracted, pThis->uHashFunExtracted, pSgBuf->paSegs[0].pvSeg, cbActuallyRead);
     1259
    12561260    if (rc == VINF_EOF)
    12571261    {
     
    12951299 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    12961300 */
    1297 static DECLCALLBACK(int) rtZipXarFssDecompIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     1301static DECLCALLBACK(int) rtZipXarFssDecompIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    12981302{
    12991303    /* Cannot write to a read-only I/O stream. */
  • trunk/src/VBox/Storage/VDIfVfs.cpp

    r98103 r100908  
    9595 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    9696 */
    97 static DECLCALLBACK(int) vdIfVfsIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     97static DECLCALLBACK(int) vdIfVfsIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    9898{
    9999    PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis;
    100100    Assert(pSgBuf->cSegs == 1); NOREF(fBlocking);
    101101    Assert(off >= -1);
     102
     103    size_t       cbSeg = 0;
     104    void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
    102105
    103106    /*
     
    108111    int rc;
    109112    if (pThis->pVDIfsIo)
    110         rc = vdIfIoFileReadSync(pThis->pVDIfsIo, pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbRead);
     113        rc = vdIfIoFileReadSync(pThis->pVDIfsIo, pThis->pStorage, off, pvSeg, cbSeg, pcbRead);
    111114    else
    112115    {
    113         rc = vdIfIoIntFileReadSync(pThis->pVDIfsIoInt, (PVDIOSTORAGE)pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg);
     116        rc = vdIfIoIntFileReadSync(pThis->pVDIfsIoInt, (PVDIOSTORAGE)pThis->pStorage, off, pvSeg, cbSeg);
    114117        if (pcbRead)
    115             *pcbRead = RT_SUCCESS(rc) ? pSgBuf->paSegs[0].cbSeg : 0;
     118            *pcbRead = RT_SUCCESS(rc) ? cbSeg : 0;
    116119    }
    117120    if (RT_SUCCESS(rc))
    118121    {
    119         size_t cbAdvance = pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg;
     122        size_t const cbAdvance = pcbRead ? *pcbRead : cbSeg;
    120123        pThis->offCurPos = off + cbAdvance;
     124        RTSgBufAdvance(pSgBuf, cbAdvance);
    121125        if (pcbRead && !cbAdvance)
    122126            rc = VINF_EOF;
     
    129133 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    130134 */
    131 static DECLCALLBACK(int) vdIfVfsIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     135static DECLCALLBACK(int) vdIfVfsIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    132136{
    133137    PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis;
     
    135139    Assert(off >= -1);
    136140
     141    size_t             cbSeg = 0;
     142    void const * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     143
    137144    /*
    138      * This may end up being a little more complicated, esp. wrt VERR_EOF.
     145     * Do the writing.
    139146     */
    140147    if (off == -1)
     
    142149    int rc;
    143150    if (pThis->pVDIfsIo)
    144         rc = vdIfIoFileWriteSync(pThis->pVDIfsIo, pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbWritten);
     151        rc = vdIfIoFileWriteSync(pThis->pVDIfsIo, pThis->pStorage, off, pvSeg, cbSeg, pcbWritten);
    145152    else
    146153    {
    147         rc = vdIfIoIntFileWriteSync(pThis->pVDIfsIoInt, pThis->pStorage, off, pSgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg);
     154        rc = vdIfIoIntFileWriteSync(pThis->pVDIfsIoInt, pThis->pStorage, off, pvSeg, cbSeg);
    148155        if (pcbWritten)
    149             *pcbWritten = RT_SUCCESS(rc) ? pSgBuf->paSegs[0].cbSeg : 0;
     156            *pcbWritten = RT_SUCCESS(rc) ? cbSeg : 0;
    150157    }
    151158    if (RT_SUCCESS(rc))
    152         pThis->offCurPos = off + (pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg);
     159    {
     160        size_t const cbAdvance = pcbWritten ? *pcbWritten : cbSeg;
     161        pThis->offCurPos = off + cbAdvance;
     162        RTSgBufAdvance(pSgBuf, cbAdvance);
     163    }
    153164    return rc;
    154165}
  • trunk/src/VBox/Storage/VDVfs.cpp

    r98103 r100908  
    341341 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    342342 */
    343 static DECLCALLBACK(int) vdVfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    344 {
    345     PVDVFSFILE pThis = (PVDVFSFILE)pvThis;
     343static DECLCALLBACK(int) vdVfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     344{
     345    PVDVFSFILE const pThis = (PVDVFSFILE)pvThis;
    346346
    347347    Assert(pSgBuf->cSegs == 1);
     
    364364    }
    365365
    366     int rc = VINF_SUCCESS;
    367     size_t cbLeftToRead = pSgBuf->paSegs[0].cbSeg;
    368     if (offUnsigned + cbLeftToRead <= cbImage)
    369     {
    370         if (pcbRead)
    371             *pcbRead = cbLeftToRead;
     366    size_t       cbSeg = 0;
     367    void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     368
     369    int    rcRet = VINF_SUCCESS;
     370    size_t cbToRead;
     371    if (cbSeg <= cbImage - offUnsigned)
     372        cbToRead = cbSeg;
     373    else if (pcbRead)
     374    {
     375        cbToRead = (size_t)(cbImage - offUnsigned);
     376        rcRet = VINF_EOF;
    372377    }
    373378    else
    374     {
    375         if (!pcbRead)
    376             return VERR_EOF;
    377         *pcbRead = cbLeftToRead = (size_t)(cbImage - offUnsigned);
    378         rc = VINF_EOF;
    379     }
     379        return VERR_EOF;
    380380
    381381    /*
    382382     * Ok, we've got a valid stretch within the file.  Do the reading.
    383383     */
    384     if (cbLeftToRead > 0)
    385     {
    386         int rc2 = vdReadHelper(pThis->pDisk, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToRead);
     384    if (cbToRead > 0)
     385    {
     386        int rc2 = vdReadHelper(pThis->pDisk, offUnsigned, pvSeg, cbToRead);
    387387        if (RT_SUCCESS(rc2))
    388             offUnsigned += cbLeftToRead;
     388        {
     389            offUnsigned += cbToRead;
     390            RTSgBufAdvance(pSgBuf, cbToRead);
     391        }
    389392        else
    390             rc = rc2;
     393        {
     394            cbToRead = 0;
     395            rcRet = rc2;
     396        }
    391397    }
    392398
    393399    pThis->offCurPos = offUnsigned;
    394     return rc;
     400    if (pcbRead)
     401        *pcbRead = cbToRead;
     402    return rcRet;
    395403}
    396404
     
    399407 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite}
    400408 */
    401 static DECLCALLBACK(int) vdVfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
    402 {
    403     PVDVFSFILE pThis = (PVDVFSFILE)pvThis;
     409static DECLCALLBACK(int) vdVfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)
     410{
     411    PVDVFSFILE const pThis = (PVDVFSFILE)pvThis;
    404412
    405413    Assert(pSgBuf->cSegs == 1);
     
    422430    }
    423431
    424     size_t cbLeftToWrite;
    425     if (offUnsigned + pSgBuf->paSegs[0].cbSeg <= cbImage)
    426     {
    427         cbLeftToWrite = pSgBuf->paSegs[0].cbSeg;
    428         if (pcbWritten)
    429             *pcbWritten = cbLeftToWrite;
    430     }
     432    size_t             cbSeg = 0;
     433    void const * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg);
     434
     435    size_t cbToWrite;
     436    if (cbSeg <= cbImage - offUnsigned)
     437        cbToWrite = cbSeg;
     438    else if (pcbWritten)
     439        cbToWrite = (size_t)(cbImage - offUnsigned);
    431440    else
    432     {
    433         if (!pcbWritten)
    434             return VERR_EOF;
    435         *pcbWritten = cbLeftToWrite = (size_t)(cbImage - offUnsigned);
    436     }
     441        return VERR_EOF;
    437442
    438443    /*
     
    440445     */
    441446    int rc = VINF_SUCCESS;
    442     if (cbLeftToWrite > 0)
    443     {
    444         rc = vdWriteHelper(pThis->pDisk, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite);
     447    if (cbToWrite > 0)
     448    {
     449        rc = vdWriteHelper(pThis->pDisk, offUnsigned, pvSeg, cbToWrite);
    445450        if (RT_SUCCESS(rc))
    446             offUnsigned += cbLeftToWrite;
     451        {
     452            offUnsigned += cbToWrite;
     453            RTSgBufAdvance(pSgBuf, cbToWrite);
     454        }
     455        else
     456            cbToWrite = 0;
    447457    }
    448458
    449459    pThis->offCurPos = offUnsigned;
     460    if (pcbWritten)
     461        *pcbWritten = cbToWrite;
    450462    return rc;
    451463}
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