VirtualBox

Ignore:
Timestamp:
Aug 19, 2023 2:57:05 AM (18 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/zip
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • 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. */
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