VirtualBox

Changeset 34045 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Nov 12, 2010 7:16:09 PM (14 years ago)
Author:
vboxsync
Message:

iprt: more tar code and vfs filesystem stream bugfixes.

Location:
trunk/src/VBox/Runtime
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r34027 r34045  
    372372        common/vfs/vfsstdfile.cpp \
    373373        common/zip/tar.cpp \
     374        common/zip/tarcmd.cpp \
    374375        common/zip/tarvfs.cpp \
    375376        common/zip/gzipvfs.cpp \
  • trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp

    r34032 r34045  
    15971597    RTVFSFSSTREAMINTERNAL *pThis = hVfsFss;
    15981598    AssertPtrReturn(pThis, VERR_INVALID_HANDLE);
    1599     AssertReturn(pThis->uMagic == RTVFSDIR_MAGIC, VERR_INVALID_HANDLE);
     1599    AssertReturn(pThis->uMagic == RTVFSFSSTREAM_MAGIC, VERR_INVALID_HANDLE);
    16001600    AssertPtrNullReturn(ppszName, VERR_INVALID_POINTER);
    16011601    if (ppszName)
  • trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp

    r34029 r34045  
    284284{
    285285    PRTVFSSTDFILE pThis = (PRTVFSSTDFILE)pvThis;
    286     return RTFileTell(pThis->hFile);
     286    uint64_t offActual;
     287    int rc = RTFileSeek(pThis->hFile, 0, RTFILE_SEEK_CURRENT, &offActual);
     288    if (RT_SUCCESS(rc))
     289        *poffActual = (RTFOFF)offActual;
     290    return rc;
    287291}
    288292
  • trunk/src/VBox/Runtime/common/zip/tarvfs.cpp

    r34029 r34045  
    3232#include <iprt/zip.h>
    3333
     34#include <iprt/asm.h>
    3435#include <iprt/assert.h>
    3536#include <iprt/err.h>
     
    144145DECLINLINE(bool) rtZipTarHdrHasPrefix(PCRTZIPTARHDR pTar)
    145146{
    146     return true;
     147    return pTar->Posix.prefix[0] != '\0';
    147148}
    148149
     
    157158{
    158159    return VINF_SUCCESS;
     160}
     161
     162
     163/**
     164 * Converts a numeric header field to the C native type.
     165 *
     166 * @returns IPRT status code.
     167 *
     168 * @param   pszField            The TAR header field.
     169 * @param   cchField            The length of the field.
     170 * @param   fOctalOnly          Must be octal.
     171 * @param   pi64                Where to store the value.
     172 */
     173static int rtZipTarHdrFieldToNum(const char *pszField, size_t cchField, bool fOctalOnly, int64_t *pi64)
     174{
     175    /** @todo check for base256 and more  */
     176    return RTStrToInt64Full(pszField, 8, pi64);
    159177}
    160178
     
    171189{
    172190    RT_ZERO(*pObjInfo);
     191    int rc;
     192
     193    int64_t i64;
     194    rc = rtZipTarHdrFieldToNum(pTar->Posix.size, sizeof(pTar->Posix.size), false, &i64);
     195    AssertRCSuccessReturn(rc, rc);
     196    pObjInfo->cbObject = i64;
     197
     198    pObjInfo->Attr.enmAdditional = RTFSOBJATTRADD_UNIX;
    173199
    174200    return VINF_SUCCESS;
     
    267293{
    268294    PRTZIPTARIOSTREAM pThis = (PRTZIPTARIOSTREAM)pvThis;
     295
     296    RTVfsIoStrmRelease(pThis->hVfsIos);
     297    pThis->hVfsIos = NIL_RTVFSIOSTREAM;
     298
    269299    return rtZipTarFssBaseObj_Close(&pThis->BaseObj);
    270300}
     
    602632           && off < pThis->offNextHdr)
    603633    {
    604         int rc = RTVfsIoStrmSkip(pThis->hVfsIos, off - pThis->offNextHdr);
     634        int rc = RTVfsIoStrmSkip(pThis->hVfsIos, pThis->offNextHdr - off);
    605635        if (RT_FAILURE(rc))
    606636        {
     
    637667    /*
    638668     * Validate the header and convert to binary object info.
    639      */
    640 /** @todo look for the two all zero headers terminating the stream... */
     669     * We pick up the two zero headers in the failure path here.
     670    */
    641671    rc = rtZipTarHdrValidate(&Hdr);
    642     if (RT_FAILURE(rc))
     672    if (RT_FAILURE_NP(rc))
     673    {
     674        if (ASMMemIsAllU32(&Hdr, sizeof(Hdr), 0) == NULL)
     675        {
     676            int rc2 = RTVfsIoStrmRead(pThis->hVfsIos, &Hdr, sizeof(Hdr), true /*fBlocking*/, &cbRead);
     677            if (RT_FAILURE(rc2))
     678                return pThis->rcFatal = rc2;
     679            if (ASMMemIsAllU32(&Hdr, sizeof(Hdr), 0) == NULL)
     680            {
     681                pThis->fEndOfStream = true;
     682                if (RTVfsIoStrmIsAtEnd(pThis->hVfsIos))
     683                    return VERR_EOF;
     684                return VERR_TAR_EOS_MORE_INPUT;
     685            }
     686        }
     687
    643688        return pThis->rcFatal = rc;
     689    }
    644690
    645691    RTFSOBJINFO Info;
     
    764810        {
    765811            *ppszName = NULL;
    766             rc = RTStrAAppendExN(ppszName, 2, Hdr.Posix.prefix, Hdr.Posix.name);
     812            rc = RTStrAAppendExN(ppszName, 3,
     813                                 Hdr.Posix.prefix, sizeof(Hdr.Posix.prefix),
     814                                 "/", 1,
     815                                 Hdr.Posix.name, sizeof(Hdr.Posix.name));
    767816        }
    768817        else
    769             rc = RTStrDupEx(ppszName, Hdr.Posix.name);
     818        {
     819            *ppszName = RTStrDupN(Hdr.Posix.name, sizeof(Hdr.Posix.name));
     820            rc = *ppszName ? VINF_SUCCESS : VERR_NO_STR_MEMORY;
     821        }
    770822        if (RT_FAILURE(rc))
    771823            return rc;
     
    806858
    807859
    808 RTDECL(int) RTZipTarFsStreamFromIoStream(RTVFSIOSTREAM hVfsIosIn, PRTVFSFSSTREAM phVfsFss)
     860RTDECL(int) RTZipTarFsStreamFromIoStream(RTVFSIOSTREAM hVfsIosIn, uint32_t fFlags, PRTVFSFSSTREAM phVfsFss)
    809861{
    810862    /*
     
    814866    *phVfsFss = NIL_RTVFSFSSTREAM;
    815867    AssertPtrReturn(hVfsIosIn, VERR_INVALID_HANDLE);
     868    AssertReturn(!fFlags, VERR_INVALID_PARAMETER);
    816869
    817870    RTFOFF const offStart = RTVfsIoStrmTell(hVfsIosIn);
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r33973 r34045  
    577577RTGzip_SOURCES = RTGzip.cpp
    578578
     579# RTTar - our tar clone (for testing the tar/gzip/gunzip streaming code)
     580PROGRAMS += RTTar
     581RTTar_TEMPLATE = VBOXR3TSTEXE
     582RTTar_SOURCES = RTTar.cpp
    579583
    580584
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