VirtualBox

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/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}
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