VirtualBox

Changeset 50146 in vbox


Ignore:
Timestamp:
Jan 21, 2014 5:32:30 PM (11 years ago)
Author:
vboxsync
Message:

gzipvfs.cpp,tarvfs.cpp: Allow the pfnRead off parameter to be the current stream offset, and in the tar case anything within the current-file in the tar stream.

Location:
trunk/src/VBox/Runtime/common/zip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/zip/gzipvfs.cpp

    r48836 r50146  
    148148    /** Set if we've reached the end of the zlib stream. */
    149149    bool                fEndOfStream;
    150     /** The stream offset for pfnTell. */
     150    /** The stream offset for pfnTell, always the uncompressed data. */
    151151    RTFOFF              offStream;
    152152    /** The zlib stream.  */
     
    377377
    378378    Assert(pSgBuf->cSegs == 1);
    379     AssertReturn(off == -1, VERR_INVALID_PARAMETER);
    380379    if (!pThis->fDecompress)
    381380        return VERR_ACCESS_DENIED;
     381    AssertReturn(off == -1 || off == pThis->offStream , VERR_INVALID_PARAMETER);
    382382
    383383    return rtZipGzip_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead);
     
    510510    PRTZIPGZIPSTREAM pThis = (PRTZIPGZIPSTREAM)pvThis;
    511511
    512     AssertReturn(off == -1, VERR_INVALID_PARAMETER);
    513512    Assert(pSgBuf->cSegs == 1); NOREF(fBlocking);
    514 
    515513    if (pThis->fDecompress)
    516514        return VERR_ACCESS_DENIED;
    517 
    518     /*
    519      * Write out the intput buffer. Using a loop here because of potential
     515    AssertReturn(off == -1 || off == pThis->offStream , VERR_INVALID_PARAMETER);
     516
     517    /*
     518     * Write out the input buffer. Using a loop here because of potential
    520519     * integer type overflow since avail_in is uInt and cbSeg is size_t.
    521520     */
     
    541540        }
    542541
     542    pThis->offStream += cbWritten;
    543543    if (pcbWritten)
    544544        *pcbWritten = cbWritten;
  • trunk/src/VBox/Runtime/common/zip/tarvfs.cpp

    r50086 r50146  
    126126    /** The current file position. */
    127127    RTFOFF                  offFile;
     128    /** The start position in the hVfsIos (for seekable hVfsIos). */
     129    RTFOFF                  offStart;
    128130    /** The number of padding bytes following the file. */
    129131    uint32_t                cbPadding;
     
    10111013
    10121014/**
    1013  * Reads one segment.
    1014  *
    1015  * @returns IPRT status code.
    1016  * @param   pThis           The instance data.
    1017  * @param   pvBuf           Where to put the read bytes.
    1018  * @param   cbToRead        The number of bytes to read.
    1019  * @param   fBlocking       Whether to block or not.
    1020  * @param   pcbRead         Where to store the number of bytes actually read.
    1021  */
    1022 static int rtZipTarFssIos_ReadOneSeg(PRTZIPTARIOSTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead)
    1023 {
    1024     /*
    1025      * Fend of reads beyond the end of the stream here.
    1026      */
    1027     if (pThis->fEndOfStream)
     1015 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
     1016 */
     1017static DECLCALLBACK(int) rtZipTarFssIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
     1018{
     1019    PRTZIPTARIOSTREAM pThis = (PRTZIPTARIOSTREAM)pvThis;
     1020    Assert(pSgBuf->cSegs == 1);
     1021
     1022    /*
     1023     * Make offset into a real offset so it's possible to do random access
     1024     * on TAR files that are seekable.  Fend of reads beyond the end of the
     1025     * stream.
     1026     */
     1027    if (off < 0)
     1028        off = pThis->offFile;
     1029    if (off >= pThis->cbFile)
    10281030        return pcbRead ? VINF_EOF : VERR_EOF;
    10291031
     1032
    10301033    Assert(pThis->cbFile >= pThis->offFile);
    1031     uint64_t cbLeft = (uint64_t)(pThis->cbFile - pThis->offFile);
     1034    uint64_t cbLeft   = (uint64_t)(pThis->cbFile - pThis->offFile);
     1035    size_t   cbToRead = pSgBuf->paSegs[0].cbSeg;
    10321036    if (cbToRead > cbLeft)
    10331037    {
     
    10431047    if (!pcbRead)
    10441048        pcbRead = &cbReadStack;
    1045     int rc = RTVfsIoStrmRead(pThis->hVfsIos, pvBuf, cbToRead, fBlocking, pcbRead);
    1046     pThis->offFile += *pcbRead;
     1049    int rc = RTVfsIoStrmReadAt(pThis->hVfsIos, pThis->offStart + off, pSgBuf->paSegs[0].pvSeg, cbToRead, fBlocking, pcbRead);
     1050    pThis->offFile = off + *pcbRead;
    10471051    if (pThis->offFile >= pThis->cbFile)
    10481052    {
     
    10501054        pThis->fEndOfStream = true;
    10511055        RTVfsIoStrmSkip(pThis->hVfsIos, pThis->cbPadding);
    1052     }
    1053 
    1054     return rc;
    1055 }
    1056 
    1057 
    1058 /**
    1059  * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead}
    1060  */
    1061 static DECLCALLBACK(int) rtZipTarFssIos_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)
    1062 {
    1063     PRTZIPTARIOSTREAM pThis = (PRTZIPTARIOSTREAM)pvThis;
    1064     int               rc;
    1065     AssertReturn(off == -1, VERR_INVALID_PARAMETER);
    1066 
    1067     if (pSgBuf->cSegs == 1)
    1068         rc = rtZipTarFssIos_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead);
    1069     else
    1070     {
    1071         rc = VINF_SUCCESS;
    1072         size_t  cbRead = 0;
    1073         size_t  cbReadSeg;
    1074         size_t *pcbReadSeg = pcbRead ? &cbReadSeg : NULL;
    1075         for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)
    1076         {
    1077             cbReadSeg = 0;
    1078             rc = rtZipTarFssIos_ReadOneSeg(pThis, pSgBuf->paSegs[iSeg].pvSeg, pSgBuf->paSegs[iSeg].cbSeg, fBlocking, pcbReadSeg);
    1079             if (RT_FAILURE(rc))
    1080                 break;
    1081             if (pcbRead)
    1082             {
    1083                 cbRead += cbReadSeg;
    1084                 if (cbReadSeg != pSgBuf->paSegs[iSeg].cbSeg)
    1085                     break;
    1086             }
    1087         }
    1088         if (pcbRead)
    1089             *pcbRead = cbRead;
    10901056    }
    10911057
     
    11651131    },
    11661132    RTVFSIOSTREAMOPS_VERSION,
    1167     0,
     1133    RTVFSIOSTREAMOPS_FEAT_NO_SG,
    11681134    rtZipTarFssIos_Read,
    11691135    rtZipTarFssIos_Write,
     
    14231389            pIosData->cbFile            = Info.cbObject;
    14241390            pIosData->offFile           = 0;
     1391            pIosData->offStart          = RTVfsIoStrmTell(pThis->hVfsIos);
    14251392            pIosData->cbPadding         = (uint32_t)(Info.cbAllocated - Info.cbObject);
    14261393            pIosData->fEndOfStream      = false;
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