VirtualBox

Changeset 32599 in vbox


Ignore:
Timestamp:
Sep 17, 2010 12:46:39 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
65999
Message:

Runtime: fixed todos; distinct between real VERR_EOF and tar end of file; Use bigger buffers (_1M) for data reading and writing.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/include/iprt/err.h

    r31590 r32599  
    12561256/** The checksum of a tar header record doesn't match. */
    12571257#define VERR_TAR_CHKSUM_MISMATCH                (-925)
     1258/** The tar end of file record was read. */
     1259#define VERR_TAR_END_OF_FILE                    (-926)
    12581260/** @} */
    12591261
  • TabularUnified trunk/src/VBox/Runtime/common/misc/tar.cpp

    r32566 r32599  
    55
    66/*
    7  * Copyright (C) 2009 Oracle Corporation
     7 * Copyright (C) 2009-2010 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    9595*******************************************************************************/
    9696
    97 static int rtTarCalcChkSum(PRTTARRECORD pRecord, uint32_t *pChkSum)
     97DECLINLINE(int) rtTarCalcChkSum(PRTTARRECORD pRecord, uint32_t *pChkSum)
    9898{
    9999    uint32_t check = 0;
     
    114114    /* EOF? */
    115115    if (!zero)
    116         return VERR_EOF;
     116        return VERR_TAR_END_OF_FILE;
    117117
    118118    *pChkSum = check;
     
    120120}
    121121
    122 static int rtTarCheckHeader(PRTTARRECORD pRecord)
    123 {
     122DECLINLINE(int) rtTarReadHeaderRecord(RTFILE hFile, PRTTARRECORD pRecord)
     123{
     124    int rc = RTFileRead(hFile, pRecord, sizeof(RTTARRECORD), NULL);
     125    /* Check for EOF. EOF is valid in this case, cause it indicates no more
     126     * data in the tar archive. */
     127    if (rc == VERR_EOF)
     128        return VERR_TAR_END_OF_FILE;
     129    /* Report any other errors */
     130    else if (RT_FAILURE(rc))
     131        return rc;
     132
     133    /* Check for data integrity & an EOF record */
    124134    uint32_t check;
    125     int rc = rtTarCalcChkSum(pRecord, &check);
     135    rc = rtTarCalcChkSum(pRecord, &check);
    126136    /* EOF? */
    127137    if (RT_FAILURE(rc))
     
    136146}
    137147
    138 static int rtTarCopyFileFromToBuf(RTFILE hFile, void **ppvBuf, uint64_t *pcbSize, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
     148DECLINLINE(void*) rtTarMemTmpAlloc(size_t *pcbSize)
     149{
     150    *pcbSize = 0;
     151    /* Allocate a reasonably large buffer, fall back on a tiny one. Note:
     152     * has to be 512 byte aligned and >= 512 byte. */
     153    size_t cbTmp = _1M;
     154    void *pvTmp = RTMemTmpAlloc(cbTmp);
     155    if (!pvTmp)
     156    {
     157        cbTmp = sizeof(RTTARRECORD);
     158        pvTmp = RTMemTmpAlloc(cbTmp);
     159    }
     160    *pcbSize = cbTmp;
     161    return pvTmp;
     162}
     163
     164static int rtTarExtractFileToBuf(RTFILE hFile, void **ppvBuf, uint64_t *pcbSize, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
    139165{
    140166    int rc = VINF_SUCCESS;
     
    142168    uint64_t cbToCopy = RTStrToUInt64(pRecord->h.size);
    143169
    144     *ppvBuf = RTMemAlloc(cbToCopy);
    145     char* pcsTmp = (char*)*ppvBuf;
    146     if (!pcsTmp)
    147         return VERR_NO_MEMORY;
    148 
    149     uint64_t cbAllWritten = 0;
    150     RTTARRECORD record;
    151     /* Copy the content from hFile over to the memory. This is done block
    152      * wise in 512 byte steps. After this copying is finished hFile will be on
    153      * a 512 byte boundary, regardless if the file copied is 512 byte size
    154      * aligned. */
    155     for (;;)
    156     {
    157         if (pfnProgressCallback)
    158             pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
    159         /* Finished already? */
    160         if (cbAllWritten == cbToCopy)
    161             break;
    162         /* Read one block */
    163         rc = RTFileRead(hFile, &record, sizeof(record), NULL);
    164         if (RT_FAILURE(rc))
    165             break;
    166         uint64_t cbToWrite = sizeof(record);
    167         /* Check for the last block which has not to be 512 bytes in size. */
    168         if (cbAllWritten + cbToWrite > cbToCopy)
    169             cbToWrite = cbToCopy - cbAllWritten;
    170         /* Write the block */
    171         memcpy(pcsTmp, &record, cbToWrite);
    172         /* Count how many bytes are written already */
    173         cbAllWritten += cbToWrite;
    174         cbOverallWritten += cbToWrite;
    175         pcsTmp += cbToWrite;
    176     }
    177 
    178     /* Make sure the called doesn't mix truncated tar files with the official
    179      * end indicated by rtTarCalcChkSum. */
    180     if (rc == VERR_EOF)
    181         rc = VERR_FILE_IO_ERROR;
    182 
    183     if (RT_FAILURE(rc))
     170    *ppvBuf = 0;
     171    void *pvTmp = 0;
     172    do
     173    {
     174        /* Allocate the memory for the file content. */
     175        *ppvBuf = RTMemAlloc(cbToCopy);
     176        char* pcsTmp = (char*)*ppvBuf;
     177        if (!pcsTmp)
     178        {
     179            rc = VERR_NO_MEMORY;
     180            break;
     181        }
     182
     183        /* Allocate a temporary buffer for reading the tar content in blocks. */
     184        size_t cbTmp = 0;
     185        pvTmp = rtTarMemTmpAlloc(&cbTmp);
     186        if (!pvTmp)
     187        {
     188            rc = VERR_NO_MEMORY;
     189            break;
     190        }
     191
     192        uint64_t cbAllWritten = 0; /* Already copied */
     193        uint64_t cbRead = 0; /* Actually read in the last step */
     194        /* Copy the content from hFile over to the memory. This is done block
     195         * wise in 512 byte aligned steps. After this copying is finished hFile
     196         * will be on a 512 byte boundary, regardless if the file copied is 512
     197         * byte size aligned. */
     198        for (;;)
     199        {
     200            if (pfnProgressCallback)
     201                pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
     202            /* Finished already? */
     203            if (cbAllWritten == cbToCopy)
     204                break;
     205            /* Read one block. This will be 512 aligned in any case. */
     206            cbRead = RT_ALIGN(RT_MIN(cbToCopy - cbAllWritten, cbTmp), sizeof(RTTARRECORD));
     207            rc = RTFileRead(hFile, pvTmp, cbRead, NULL);
     208            if (RT_FAILURE(rc))
     209                break;
     210            /* Check for the last block which has not to be 512 bytes in size. */
     211            if (cbAllWritten + cbRead > cbToCopy)
     212                cbRead = cbToCopy - cbAllWritten;
     213            /* Write the block */
     214            memcpy(pcsTmp, pvTmp, cbRead);
     215            /* Count how many bytes are written already */
     216            cbAllWritten += cbRead;
     217            cbOverallWritten += cbRead;
     218            pcsTmp += cbRead;
     219        }
     220    }
     221    while(0);
     222
     223    if (pvTmp)
     224        RTMemTmpFree(pvTmp);
     225
     226    if (   RT_FAILURE(rc)
     227        && *ppvBuf)
    184228        RTMemFree(*ppvBuf);
    185229    else
     
    189233}
    190234
    191 static int rtTarCopyFileFrom(RTFILE hFile, const char *pszTargetName, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
     235static int rtTarExtractFileToFile(RTFILE hFile, const char *pszTargetName, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
    192236{
    193237    RTFILE hNewFile;
     
    197241        return rc;
    198242
    199 /**@todo r=bird: Use a bigger buffer here, see comment in rtTarCopyFileTo. */
    200 
    201     uint64_t cbToCopy = RTStrToUInt64(pRecord->h.size);
    202     size_t cbAllWritten = 0;
    203     RTTARRECORD record;
    204     /* Copy the content from hFile over to pszTargetName. This is done block
    205      * wise in 512 byte steps. After this copying is finished hFile will be on
    206      * a 512 byte boundary, regardless if the file copied is 512 byte size
    207      * aligned. */
    208     for (;;)
    209     {
    210         if (pfnProgressCallback)
    211             pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
    212         /* Finished already? */
    213         if (cbAllWritten == cbToCopy)
    214             break;
    215         /* Read one block */
    216         rc = RTFileRead(hFile, &record, sizeof(record), NULL);
    217         if (RT_FAILURE(rc))
    218             break;
    219         size_t cbToWrite = sizeof(record);
    220         /* Check for the last block which has not to be 512 bytes in size. */
    221         if (cbAllWritten + cbToWrite > cbToCopy)
    222             cbToWrite = cbToCopy - cbAllWritten;
    223         /* Write the block */
    224         rc = RTFileWrite(hNewFile, &record, cbToWrite, NULL);
    225         if (RT_FAILURE(rc))
    226             break;
    227         /* Count how many bytes are written already */
    228         cbAllWritten += cbToWrite;
    229         cbOverallWritten += cbToWrite;
    230     }
     243    void *pvTmp = 0;
     244    do
     245    {
     246        /* Allocate a temporary buffer for reading the tar content in blocks. */
     247        size_t cbTmp = 0;
     248        pvTmp = rtTarMemTmpAlloc(&cbTmp);
     249        if (!pvTmp)
     250        {
     251            rc = VERR_NO_MEMORY;
     252            break;
     253        }
     254
     255        uint64_t cbToCopy = RTStrToUInt64(pRecord->h.size);
     256        uint64_t cbAllWritten = 0; /* Already copied */
     257        uint64_t cbRead = 0; /* Actually read in the last step */
     258        /* Copy the content from hFile over to pszTargetName. This is done block
     259         * wise in 512 byte aligned steps. After this copying is finished hFile
     260         * will be on a 512 byte boundary, regardless if the file copied is 512
     261         * byte size aligned. */
     262        for (;;)
     263        {
     264            if (pfnProgressCallback)
     265                pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
     266            /* Finished already? */
     267            if (cbAllWritten == cbToCopy)
     268                break;
     269            /* Read one block. This will be 512 aligned in any case. */
     270            cbRead = RT_ALIGN(RT_MIN(cbToCopy - cbAllWritten, cbTmp), sizeof(RTTARRECORD));
     271            rc = RTFileRead(hFile, pvTmp, cbRead, NULL);
     272            if (RT_FAILURE(rc))
     273                break;
     274            /* Check for the last block which has not to be 512 bytes in size. */
     275            if (cbAllWritten + cbRead > cbToCopy)
     276                cbRead = cbToCopy - cbAllWritten;
     277            /* Write the block */
     278            rc = RTFileWrite(hNewFile, pvTmp, cbRead, NULL);
     279            if (RT_FAILURE(rc))
     280                break;
     281            /* Count how many bytes are written already */
     282            cbAllWritten += cbRead;
     283            cbOverallWritten += cbRead;
     284        }
     285
     286    }
     287    while(0);
     288
     289    /* Cleanup */
     290    if (pvTmp)
     291        RTMemTmpFree(pvTmp);
    231292
    232293    /* Now set all file attributes */
     
    242303        }
    243304    }
    244     /* Make sure the called doesn't mix truncated tar files with the official
    245      * end indicated by rtTarCalcChkSum. */
    246     else if (rc == VERR_EOF)
    247         rc = VERR_FILE_IO_ERROR;
    248305
    249306    RTFileClose(hNewFile);
     
    256313}
    257314
    258 static int rtTarCopyFileTo(RTFILE hFile, const char *pszSrcName, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
     315static int rtTarAppendFileFromFile(RTFILE hFile, const char *pszSrcName, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)
    259316{
    260317    RTFILE hOldFile;
     
    264321        return rc;
    265322
    266     /* Get the size of the source file */
    267     uint64_t cbSize;
    268     rc = RTFileGetSize(hOldFile, &cbSize);
    269     if (RT_FAILURE(rc))
    270     {
    271         RTFileClose(hOldFile);
    272         return rc;
    273     }
    274     /* Get some info from the source file */
    275     RTFSOBJINFO info;
    276     RTUID uid = 0;
    277     RTGID gid = 0;
    278     RTFMODE fmode = 0600; /* Make some save default */
    279     int64_t mtime = 0;
    280     /* This isn't critical. Use the defaults if it fails. */
    281     rc = RTFileQueryInfo(hOldFile, &info, RTFSOBJATTRADD_UNIX);
    282     if (RT_SUCCESS(rc))
    283     {
    284         fmode = info.Attr.fMode & RTFS_UNIX_MASK;
    285         uid = info.Attr.u.Unix.uid;
    286         gid = info.Attr.u.Unix.gid;
    287         mtime = RTTimeSpecGetSeconds(&info.ModificationTime);
    288     }
    289 
    290     /* Fill the header record */
    291     RTTARRECORD record;
    292     RT_ZERO(record);
    293     RTStrPrintf(record.h.name,  sizeof(record.h.name),  "%s",     RTPathFilename(pszSrcName));
    294     RTStrPrintf(record.h.mode,  sizeof(record.h.mode),  "%0.7o",  fmode);
    295     RTStrPrintf(record.h.uid,   sizeof(record.h.uid),   "%0.7o",  uid);
    296     RTStrPrintf(record.h.gid,   sizeof(record.h.gid),   "%0.7o",  gid);
    297     RTStrPrintf(record.h.size,  sizeof(record.h.size),  "%0.11o", cbSize);
    298     RTStrPrintf(record.h.mtime, sizeof(record.h.mtime), "%0.11o", mtime);
    299     RTStrPrintf(record.h.magic, sizeof(record.h.magic), "ustar  ");
    300     RTStrPrintf(record.h.uname, sizeof(record.h.uname), "someone");
    301     RTStrPrintf(record.h.gname, sizeof(record.h.gname), "someone");
    302     record.h.linkflag = LF_NORMAL;
    303 
    304     /* Create the checksum out of the new header */
    305     uint32_t chksum;
    306     rc = rtTarCalcChkSum(&record, &chksum);
    307     if (RT_SUCCESS(rc))
    308     {
     323    void *pvTmp = 0;
     324    do
     325    {
     326        /* Get the size of the source file */
     327        uint64_t cbToCopy;
     328        rc = RTFileGetSize(hOldFile, &cbToCopy);
     329        if (RT_FAILURE(rc))
     330            break;
     331        /* Get some info from the source file */
     332        RTFSOBJINFO info;
     333        RTUID uid = 0;
     334        RTGID gid = 0;
     335        RTFMODE fmode = 0600; /* Make some save default */
     336        int64_t mtime = 0;
     337        /* This isn't critical. Use the defaults if it fails. */
     338        rc = RTFileQueryInfo(hOldFile, &info, RTFSOBJATTRADD_UNIX);
     339        if (RT_SUCCESS(rc))
     340        {
     341            fmode = info.Attr.fMode & RTFS_UNIX_MASK;
     342            uid = info.Attr.u.Unix.uid;
     343            gid = info.Attr.u.Unix.gid;
     344            mtime = RTTimeSpecGetSeconds(&info.ModificationTime);
     345        }
     346
     347        /* Fill the header record */
     348        RTTARRECORD record;
     349        RT_ZERO(record);
     350        RTStrPrintf(record.h.name,  sizeof(record.h.name),  "%s",     RTPathFilename(pszSrcName));
     351        RTStrPrintf(record.h.mode,  sizeof(record.h.mode),  "%0.7o",  fmode);
     352        RTStrPrintf(record.h.uid,   sizeof(record.h.uid),   "%0.7o",  uid);
     353        RTStrPrintf(record.h.gid,   sizeof(record.h.gid),   "%0.7o",  gid);
     354        RTStrPrintf(record.h.size,  sizeof(record.h.size),  "%0.11o", cbToCopy);
     355        RTStrPrintf(record.h.mtime, sizeof(record.h.mtime), "%0.11o", mtime);
     356        RTStrPrintf(record.h.magic, sizeof(record.h.magic), "ustar  ");
     357        RTStrPrintf(record.h.uname, sizeof(record.h.uname), "someone");
     358        RTStrPrintf(record.h.gname, sizeof(record.h.gname), "someone");
     359        record.h.linkflag = LF_NORMAL;
     360
     361        /* Create the checksum out of the new header */
     362        uint32_t chksum;
     363        rc = rtTarCalcChkSum(&record, &chksum);
     364        if (RT_FAILURE(rc))
     365            break;
     366        /* Format the checksum */
    309367        RTStrPrintf(record.h.chksum, sizeof(record.h.chksum), "%0.7o", chksum);
    310 
    311368        /* Write the header first */
    312369        rc = RTFileWrite(hFile, &record, sizeof(record), NULL);
    313         if (RT_SUCCESS(rc))
    314         {
    315 /** @todo r=bird: using a 64KB buffer here instead of 0.5KB would probably be
    316  *        a good thing. */
    317             uint64_t cbAllWritten = 0;
    318             /* Copy the content from pszSrcName over to hFile. This is done block
    319              * wise in 512 byte steps. After this copying is finished hFile will be
    320              * on a 512 byte boundary, regardless if the file copied is 512 byte
    321              * size aligned. */
    322             for (;;)
    323             {
    324                 if (pfnProgressCallback)
    325                     pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
    326                 if (cbAllWritten >= cbSize)
    327                     break;
    328                 size_t cbToRead = sizeof(record);
    329                 /* Last record? */
    330                 if (cbAllWritten + cbToRead > cbSize)
    331                 {
    332                     /* Initialize with zeros */
    333                     RT_ZERO(record);
    334                     cbToRead = cbSize - cbAllWritten;
    335                 }
    336                 /* Read one block */
    337                 rc = RTFileRead(hOldFile, &record, cbToRead, NULL);
    338                 if (RT_FAILURE(rc))
    339                     break;
    340                 /* Write one block */
    341                 rc = RTFileWrite(hFile, &record, sizeof(record), NULL);
    342                 if (RT_FAILURE(rc))
    343                     break;
    344                 /* Count how many bytes are written already */
    345                 cbAllWritten += sizeof(record);
    346                 cbOverallWritten += sizeof(record);
    347             }
    348 
    349             /* Make sure the called doesn't mix truncated tar files with the
    350              * official end indicated by rtTarCalcChkSum. */
    351             if (rc == VERR_EOF)
    352                 rc = VERR_FILE_IO_ERROR;
    353         }
    354     }
     370        if (RT_FAILURE(rc))
     371            break;
     372
     373        /* Allocate a temporary buffer for copying the tar content in blocks. */
     374        size_t cbTmp = 0;
     375        pvTmp = rtTarMemTmpAlloc(&cbTmp);
     376        if (!pvTmp)
     377        {
     378            rc = VERR_NO_MEMORY;
     379            break;
     380        }
     381
     382        uint64_t cbAllWritten = 0; /* Already copied */
     383        uint64_t cbRead = 0; /* Actually read in the last step */
     384        uint64_t cbWrite = 0; /* Actually write in the last step */
     385        /* Copy the content from pszSrcName over to hFile. This is done block
     386         * wise in 512 byte steps. After this copying is finished hFile will be
     387         * on a 512 byte boundary, regardless if the file copied is 512 byte
     388         * size aligned. */
     389        for (;;)
     390        {
     391            if (pfnProgressCallback)
     392                pfnProgressCallback((unsigned)(100.0 / cbOverallSize * cbOverallWritten), pvUser);
     393            if (cbAllWritten >= cbToCopy)
     394                break;
     395            /* Read one block. Either its the buffer size or the rest of the
     396             * file. */
     397            cbRead = RT_MIN(cbToCopy - cbAllWritten, cbTmp);
     398            /* Write one block. This will be 512 byte aligned in any case. */
     399            cbWrite = RT_ALIGN(cbRead, sizeof(RTTARRECORD));
     400            /* Last record? */
     401            if (cbRead != cbWrite)
     402                /* Initialize the rest with zeros */
     403                RT_BZERO(&((char*)pvTmp)[cbRead], cbWrite-cbRead);
     404            /* Read one block */
     405            rc = RTFileRead(hOldFile, pvTmp, cbRead, NULL);
     406            if (RT_FAILURE(rc))
     407                break;
     408            /* Write one block. Tar needs to be 512 byte aligned. */
     409            rc = RTFileWrite(hFile, pvTmp, cbWrite, NULL);
     410            if (RT_FAILURE(rc))
     411                break;
     412            /* Count how many bytes (of the original file) are written already */
     413            cbAllWritten += cbRead;
     414            cbOverallWritten += cbRead;
     415        }
     416    }
     417    while(0);
     418
     419    /* Cleanup */
     420    if (pvTmp)
     421        RTMemTmpFree(pvTmp);
    355422
    356423    RTFileClose(hOldFile);
     
    375442    for (;;)
    376443    {
    377 /** @todo r=bird: the reading, validation and EOF check done here should be
    378  *        moved to a separate helper function. That would make it easiser to
    379  *        distinguish genuine-end-of-tar-file and VERR_EOF caused by a
    380  *        trunacted file. That said, rtTarSkipData won't return VERR_EOF, at
    381  *        least not on unix, since it's not a sin to seek beyond the end of a
    382  *        file. */
    383         rc = RTFileRead(hFile, &record, sizeof(record), NULL);
     444        /* Read & verify a header record */
     445        rc = rtTarReadHeaderRecord(hFile, &record);
    384446        /* Check for error or EOF. */
    385         if (RT_FAILURE(rc))
    386             break;
    387         /* Check for EOF & data integrity */
    388         rc = rtTarCheckHeader(&record);
    389447        if (RT_FAILURE(rc))
    390448            break;
     
    414472            break;
    415473    }
     474    if (rc == VERR_TAR_END_OF_FILE)
     475        rc = VINF_SUCCESS;
     476
    416477    /* Make sure the file pointer is at the begin of the file again. */
    417478    if (RT_SUCCESS(rc))
     
    440501    for (;;)
    441502    {
    442 /** @todo r=bird: the reading, validation and EOF check done here should be
    443  *        moved to a separate helper function. That would make it easiser to
    444  *        distinguish genuine-end-of-tar-file and VERR_EOF caused by a
    445  *        trunacted file. That said, rtTarSkipData won't return VERR_EOF, at
    446  *        least not on unix, since it's not a sin to seek beyond the end of a
    447  *        file. */
    448         rc = RTFileRead(hFile, &record, sizeof(record), NULL);
     503        /* Read & verify a header record */
     504        rc = rtTarReadHeaderRecord(hFile, &record);
    449505        /* Check for error or EOF. */
    450         if (RT_FAILURE(rc))
    451             break;
    452         /* Check for EOF & data integrity */
    453         rc = rtTarCheckHeader(&record);
    454506        if (RT_FAILURE(rc))
    455507            break;
     
    471523    RTFileClose(hFile);
    472524
    473     if (rc == VERR_EOF)
     525    if (rc == VERR_TAR_END_OF_FILE)
    474526        rc = VINF_SUCCESS;
    475527
     
    510562    for (;;)
    511563    {
    512         rc = RTFileRead(hFile, &record, sizeof(record), NULL);
     564        /* Read & verify a header record */
     565        rc = rtTarReadHeaderRecord(hFile, &record);
    513566        /* Check for error or EOF. */
    514         if (RT_FAILURE(rc))
    515             break;
    516         /* Check for EOF & data integrity */
    517         rc = rtTarCheckHeader(&record);
    518567        if (RT_FAILURE(rc))
    519568            break;
     
    554603    RTFileClose(hFile);
    555604
    556     if (rc == VERR_EOF)
     605    if (rc == VERR_TAR_END_OF_FILE)
    557606        rc = VINF_SUCCESS;
    558607
     
    597646        for (;;)
    598647        {
    599             rc = RTFileRead(hFile, &record, sizeof(record), NULL);
     648            /* Read & verify a header record */
     649            rc = rtTarReadHeaderRecord(hFile, &record);
    600650            /* Check for error or EOF. */
    601             if (RT_FAILURE(rc))
    602                 break;
    603             /* Check for EOF & data integrity */
    604             rc = rtTarCheckHeader(&record);
    605651            if (RT_FAILURE(rc))
    606652                break;
     
    612658                {
    613659                    fFound = true;
    614                     rc = rtTarCopyFileFromToBuf(hFile, ppvBuf, pcbSize, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
     660                    rc = rtTarExtractFileToBuf(hFile, ppvBuf, pcbSize, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
    615661                    /* We are finished */
    616662                    break;
     
    625671        }
    626672
    627         if (rc == VERR_EOF)
     673        if (rc == VERR_TAR_END_OF_FILE)
    628674            rc = VINF_SUCCESS;
    629675
     
    666712            for (;;)
    667713            {
    668                 rc = RTFileRead(hFile, &record, sizeof(record), NULL);
     714                /* Read & verify a header record */
     715                rc = rtTarReadHeaderRecord(hFile, &record);
    669716                /* Check for error or EOF. */
    670                 if (RT_FAILURE(rc))
    671                     break;
    672                 /* Check for EOF & data integrity */
    673                 rc = rtTarCheckHeader(&record);
    674717                if (RT_FAILURE(rc))
    675718                    break;
    676719                /* We support normal files only */
    677720                if (   record.h.linkflag == LF_OLDNORMAL
    678                        || record.h.linkflag == LF_NORMAL)
     721                    || record.h.linkflag == LF_NORMAL)
    679722                {
    680723                    bool fFound = false;
     
    690733                                if (rc > 0)
    691734                                {
    692                                     rc = rtTarCopyFileFrom(hFile, pszTargetFile, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
     735                                    rc = rtTarExtractFileToFile(hFile, pszTargetFile, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
    693736                                    if (RT_SUCCESS(rc))
    694737                                        paExtracted[cExtracted++] = pszTargetFile;
     
    717760            }
    718761
    719             if (rc == VERR_EOF)
     762            if (rc == VERR_TAR_END_OF_FILE)
    720763                rc = VINF_SUCCESS;
    721764
     
    759802    for (;;)
    760803    {
    761         rc = RTFileRead(hFile, &record, sizeof(record), NULL);
     804        /* Read & verify a header record */
     805        rc = rtTarReadHeaderRecord(hFile, &record);
    762806        /* Check for error or EOF. */
    763         if (RT_FAILURE(rc))
    764             break;
    765         /* Check for EOF & data integrity */
    766         rc = rtTarCheckHeader(&record);
    767807        if (RT_FAILURE(rc))
    768808            break;
     
    784824                    if (RT_FAILURE(rc))
    785825                        break;
    786                     rc = rtTarCopyFileFrom(hFile, pszTargetName, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
     826                    rc = rtTarExtractFileToFile(hFile, pszTargetName, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
    787827                    /* On success pass on the filename if requested. */
    788828                    if (    RT_SUCCESS(rc)
     
    805845    RTFileClose(hFile);
    806846
    807     if (rc == VERR_EOF)
     847    if (rc == VERR_TAR_END_OF_FILE)
    808848        rc = VINF_SUCCESS;
    809849
     
    864904        for (size_t i = 0; i < cFiles; ++i)
    865905        {
    866             rc = rtTarCopyFileTo(hFile, papszFiles[i], cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
     906            rc = rtTarAppendFileFromFile(hFile, papszFiles[i], cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);
    867907            if (RT_FAILURE(rc))
    868908                break;
Note: See TracChangeset for help on using the changeset viewer.

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