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.

Location:
trunk/src/VBox/Runtime/common/vfs
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • 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            {
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