VirtualBox

Changeset 100908 in vbox for trunk/src/VBox/Storage


Ignore:
Timestamp:
Aug 19, 2023 2:57:05 AM (18 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/src/VBox/Storage
Files:
2 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}
  • 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.

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