Changeset 32599 in vbox
- Timestamp:
- Sep 17, 2010 12:46:39 PM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 65999
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/include/iprt/err.h ¶
r31590 r32599 1256 1256 /** The checksum of a tar header record doesn't match. */ 1257 1257 #define VERR_TAR_CHKSUM_MISMATCH (-925) 1258 /** The tar end of file record was read. */ 1259 #define VERR_TAR_END_OF_FILE (-926) 1258 1260 /** @} */ 1259 1261 -
TabularUnified trunk/src/VBox/Runtime/common/misc/tar.cpp ¶
r32566 r32599 5 5 6 6 /* 7 * Copyright (C) 2009 Oracle Corporation7 * Copyright (C) 2009-2010 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 95 95 *******************************************************************************/ 96 96 97 static intrtTarCalcChkSum(PRTTARRECORD pRecord, uint32_t *pChkSum)97 DECLINLINE(int) rtTarCalcChkSum(PRTTARRECORD pRecord, uint32_t *pChkSum) 98 98 { 99 99 uint32_t check = 0; … … 114 114 /* EOF? */ 115 115 if (!zero) 116 return VERR_ EOF;116 return VERR_TAR_END_OF_FILE; 117 117 118 118 *pChkSum = check; … … 120 120 } 121 121 122 static int rtTarCheckHeader(PRTTARRECORD pRecord) 123 { 122 DECLINLINE(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 */ 124 134 uint32_t check; 125 intrc = rtTarCalcChkSum(pRecord, &check);135 rc = rtTarCalcChkSum(pRecord, &check); 126 136 /* EOF? */ 127 137 if (RT_FAILURE(rc)) … … 136 146 } 137 147 138 static int rtTarCopyFileFromToBuf(RTFILE hFile, void **ppvBuf, uint64_t *pcbSize, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser) 148 DECLINLINE(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 164 static int rtTarExtractFileToBuf(RTFILE hFile, void **ppvBuf, uint64_t *pcbSize, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser) 139 165 { 140 166 int rc = VINF_SUCCESS; … … 142 168 uint64_t cbToCopy = RTStrToUInt64(pRecord->h.size); 143 169 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) 184 228 RTMemFree(*ppvBuf); 185 229 else … … 189 233 } 190 234 191 static int rtTar CopyFileFrom(RTFILE hFile, const char *pszTargetName, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)235 static int rtTarExtractFileToFile(RTFILE hFile, const char *pszTargetName, PRTTARRECORD pRecord, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser) 192 236 { 193 237 RTFILE hNewFile; … … 197 241 return rc; 198 242 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); 231 292 232 293 /* Now set all file attributes */ … … 242 303 } 243 304 } 244 /* Make sure the called doesn't mix truncated tar files with the official245 * end indicated by rtTarCalcChkSum. */246 else if (rc == VERR_EOF)247 rc = VERR_FILE_IO_ERROR;248 305 249 306 RTFileClose(hNewFile); … … 256 313 } 257 314 258 static int rtTar CopyFileTo(RTFILE hFile, const char *pszSrcName, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser)315 static int rtTarAppendFileFromFile(RTFILE hFile, const char *pszSrcName, const uint64_t cbOverallSize, uint64_t &cbOverallWritten, PFNRTPROGRESS pfnProgressCallback, void *pvUser) 259 316 { 260 317 RTFILE hOldFile; … … 264 321 return rc; 265 322 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 */ 309 367 RTStrPrintf(record.h.chksum, sizeof(record.h.chksum), "%0.7o", chksum); 310 311 368 /* Write the header first */ 312 369 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); 355 422 356 423 RTFileClose(hOldFile); … … 375 442 for (;;) 376 443 { 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); 384 446 /* Check for error or EOF. */ 385 if (RT_FAILURE(rc))386 break;387 /* Check for EOF & data integrity */388 rc = rtTarCheckHeader(&record);389 447 if (RT_FAILURE(rc)) 390 448 break; … … 414 472 break; 415 473 } 474 if (rc == VERR_TAR_END_OF_FILE) 475 rc = VINF_SUCCESS; 476 416 477 /* Make sure the file pointer is at the begin of the file again. */ 417 478 if (RT_SUCCESS(rc)) … … 440 501 for (;;) 441 502 { 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); 449 505 /* Check for error or EOF. */ 450 if (RT_FAILURE(rc))451 break;452 /* Check for EOF & data integrity */453 rc = rtTarCheckHeader(&record);454 506 if (RT_FAILURE(rc)) 455 507 break; … … 471 523 RTFileClose(hFile); 472 524 473 if (rc == VERR_ EOF)525 if (rc == VERR_TAR_END_OF_FILE) 474 526 rc = VINF_SUCCESS; 475 527 … … 510 562 for (;;) 511 563 { 512 rc = RTFileRead(hFile, &record, sizeof(record), NULL); 564 /* Read & verify a header record */ 565 rc = rtTarReadHeaderRecord(hFile, &record); 513 566 /* Check for error or EOF. */ 514 if (RT_FAILURE(rc))515 break;516 /* Check for EOF & data integrity */517 rc = rtTarCheckHeader(&record);518 567 if (RT_FAILURE(rc)) 519 568 break; … … 554 603 RTFileClose(hFile); 555 604 556 if (rc == VERR_ EOF)605 if (rc == VERR_TAR_END_OF_FILE) 557 606 rc = VINF_SUCCESS; 558 607 … … 597 646 for (;;) 598 647 { 599 rc = RTFileRead(hFile, &record, sizeof(record), NULL); 648 /* Read & verify a header record */ 649 rc = rtTarReadHeaderRecord(hFile, &record); 600 650 /* Check for error or EOF. */ 601 if (RT_FAILURE(rc))602 break;603 /* Check for EOF & data integrity */604 rc = rtTarCheckHeader(&record);605 651 if (RT_FAILURE(rc)) 606 652 break; … … 612 658 { 613 659 fFound = true; 614 rc = rtTar CopyFileFromToBuf(hFile, ppvBuf, pcbSize, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);660 rc = rtTarExtractFileToBuf(hFile, ppvBuf, pcbSize, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser); 615 661 /* We are finished */ 616 662 break; … … 625 671 } 626 672 627 if (rc == VERR_ EOF)673 if (rc == VERR_TAR_END_OF_FILE) 628 674 rc = VINF_SUCCESS; 629 675 … … 666 712 for (;;) 667 713 { 668 rc = RTFileRead(hFile, &record, sizeof(record), NULL); 714 /* Read & verify a header record */ 715 rc = rtTarReadHeaderRecord(hFile, &record); 669 716 /* Check for error or EOF. */ 670 if (RT_FAILURE(rc))671 break;672 /* Check for EOF & data integrity */673 rc = rtTarCheckHeader(&record);674 717 if (RT_FAILURE(rc)) 675 718 break; 676 719 /* We support normal files only */ 677 720 if ( record.h.linkflag == LF_OLDNORMAL 678 721 || record.h.linkflag == LF_NORMAL) 679 722 { 680 723 bool fFound = false; … … 690 733 if (rc > 0) 691 734 { 692 rc = rtTar CopyFileFrom(hFile, pszTargetFile, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);735 rc = rtTarExtractFileToFile(hFile, pszTargetFile, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser); 693 736 if (RT_SUCCESS(rc)) 694 737 paExtracted[cExtracted++] = pszTargetFile; … … 717 760 } 718 761 719 if (rc == VERR_ EOF)762 if (rc == VERR_TAR_END_OF_FILE) 720 763 rc = VINF_SUCCESS; 721 764 … … 759 802 for (;;) 760 803 { 761 rc = RTFileRead(hFile, &record, sizeof(record), NULL); 804 /* Read & verify a header record */ 805 rc = rtTarReadHeaderRecord(hFile, &record); 762 806 /* Check for error or EOF. */ 763 if (RT_FAILURE(rc))764 break;765 /* Check for EOF & data integrity */766 rc = rtTarCheckHeader(&record);767 807 if (RT_FAILURE(rc)) 768 808 break; … … 784 824 if (RT_FAILURE(rc)) 785 825 break; 786 rc = rtTar CopyFileFrom(hFile, pszTargetName, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);826 rc = rtTarExtractFileToFile(hFile, pszTargetName, &record, cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser); 787 827 /* On success pass on the filename if requested. */ 788 828 if ( RT_SUCCESS(rc) … … 805 845 RTFileClose(hFile); 806 846 807 if (rc == VERR_ EOF)847 if (rc == VERR_TAR_END_OF_FILE) 808 848 rc = VINF_SUCCESS; 809 849 … … 864 904 for (size_t i = 0; i < cFiles; ++i) 865 905 { 866 rc = rtTar CopyFileTo(hFile, papszFiles[i], cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser);906 rc = rtTarAppendFileFromFile(hFile, papszFiles[i], cbOverallSize, cbOverallWritten, pfnProgressCallback, pvUser); 867 907 if (RT_FAILURE(rc)) 868 908 break;
Note:
See TracChangeset
for help on using the changeset viewer.