Changeset 21859 in vbox
- Timestamp:
- Jul 29, 2009 8:06:03 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/tar.cpp
r21813 r21859 251 251 RTStrPrintf(record.h.gname, sizeof(record.h.gname), "someone"); 252 252 record.h.linkflag = LF_NORMAL; 253 253 254 /* Create the checksum out of the new header */ 254 255 uint32_t chksum; 255 rtTarCalcChkSum(&record, &chksum); 256 RTStrPrintf(record.h.chksum, sizeof(record.h.chksum), "%0.7o", chksum); 257 258 /* Write the header first */ 259 rc = RTFileWrite(hFile, &record, sizeof(record), NULL); 256 rc = rtTarCalcChkSum(&record, &chksum); 260 257 if (RT_SUCCESS(rc)) 261 258 { 259 RTStrPrintf(record.h.chksum, sizeof(record.h.chksum), "%0.7o", chksum); 260 261 /* Write the header first */ 262 rc = RTFileWrite(hFile, &record, sizeof(record), NULL); 263 if (RT_SUCCESS(rc)) 264 { 262 265 /** @todo r=bird: using a 64KB buffer here instead of 0.5KB would probably be 263 266 * a good thing. */ 264 uint64_t cbAllWritten = 0; 265 /* Copy the content from pszSrcName over to hFile. This is done block 266 * wise in 512 byte steps. After this copying is finished hFile will be 267 * on a 512 byte boundary, regardless if the file copied is 512 byte 268 * size aligned. */ 269 for (;;) 270 { 271 if (cbAllWritten >= cbSize) 272 break; 273 size_t cbToRead = sizeof(record); 274 /* Last record? */ 275 if (cbAllWritten + cbToRead > cbSize) 267 uint64_t cbAllWritten = 0; 268 /* Copy the content from pszSrcName over to hFile. This is done block 269 * wise in 512 byte steps. After this copying is finished hFile will be 270 * on a 512 byte boundary, regardless if the file copied is 512 byte 271 * size aligned. */ 272 for (;;) 276 273 { 277 /* Initialize with zeros */ 278 RT_ZERO(record); 279 cbToRead = cbSize - cbAllWritten; 274 if (cbAllWritten >= cbSize) 275 break; 276 size_t cbToRead = sizeof(record); 277 /* Last record? */ 278 if (cbAllWritten + cbToRead > cbSize) 279 { 280 /* Initialize with zeros */ 281 RT_ZERO(record); 282 cbToRead = cbSize - cbAllWritten; 283 } 284 /* Read one block */ 285 rc = RTFileRead(hOldFile, &record, cbToRead, NULL); 286 if (RT_FAILURE(rc)) 287 break; 288 /* Write one block */ 289 rc = RTFileWrite(hFile, &record, sizeof(record), NULL); 290 if (RT_FAILURE(rc)) 291 break; 292 /* Count how many bytes are written already */ 293 cbAllWritten += sizeof(record); 280 294 } 281 /* Read one block */ 282 rc = RTFileRead(hOldFile, &record, cbToRead, NULL); 283 if (RT_FAILURE(rc)) 284 break; 285 /* Write one block */ 286 rc = RTFileWrite(hFile, &record, sizeof(record), NULL); 287 if (RT_FAILURE(rc)) 288 break; 289 /* Count how many bytes are written already */ 290 cbAllWritten += sizeof(record); 295 296 /* Make sure the called doesn't mix truncated tar files with the 297 * official end indicated by rtTarCalcChkSum. */ 298 if (rc == VERR_EOF) 299 rc == VERR_FILE_IO_ERROR; 291 300 } 292 293 /* Make sure the called doesn't mix truncated tar files with the 294 * official end indicated by rtTarCalcChkSum. */ 295 if (rc == VERR_EOF) 296 rc == VERR_FILE_IO_ERROR; 297 } 301 } 302 298 303 RTFileClose(hOldFile); 299 300 304 return rc; 301 305 }
Note:
See TracChangeset
for help on using the changeset viewer.