Changeset 59620 in vbox for trunk/src/VBox/Runtime/common/checksum
- Timestamp:
- Feb 10, 2016 12:47:33 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105459
- Location:
- trunk/src/VBox/Runtime/common/checksum
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/checksum/manifest2.cpp
r59575 r59620 527 527 528 528 /* 529 * Ignore this entry .529 * Ignore this entry? 530 530 */ 531 531 char const * const *ppsz = pEquals->papszIgnoreEntries; -
trunk/src/VBox/Runtime/common/checksum/manifest3.cpp
r57358 r59620 32 32 #include <iprt/manifest.h> 33 33 34 #include <iprt/alloca.h> 34 35 #include <iprt/asm.h> 35 36 #include <iprt/assert.h> … … 91 92 /** The hashes. */ 92 93 PRTMANIFESTHASHES pHashes; 94 /** The current hash position. */ 95 RTFOFF offCurPos; 93 96 /** Whether we're reading or writing. */ 94 97 bool fReadOrWrite; … … 315 318 { 316 319 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; 317 int rc = RTVfsIoStrmSgRead(pThis->hVfsIos, pSgBuf, fBlocking, pcbRead); 320 int rc; 321 322 /* 323 * To make sure we're continuing where we left off, we must have the exact 324 * stream position since a previous read using 'off' may change it. 325 */ 326 RTFOFF offActual = off == -1 ? RTVfsIoStrmTell(pThis->hVfsIos) : off; 327 if (offActual == pThis->offCurPos) 328 { 329 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, off, pSgBuf, fBlocking, pcbRead); 330 if (RT_SUCCESS(rc)) 331 { 332 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbRead ? *pcbRead : ~(size_t)0); 333 if (!pcbRead) 334 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 335 pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg; 336 else 337 pThis->offCurPos += *pcbRead; 338 } 339 Assert(RTVfsIoStrmTell(pThis->hVfsIos) == pThis->offCurPos); 340 } 341 else 342 { 343 /* 344 * If we're skipping over stuff, we need to read the gap and hash it. 345 */ 346 if (pThis->offCurPos < offActual) 347 { 348 size_t cbBuf = _8K; 349 void *pvBuf = alloca(cbBuf); 350 do 351 { 352 RTFOFF cbGap = off - pThis->offCurPos; 353 size_t cbThisRead = cbGap >= (RTFOFF)cbBuf ? cbBuf : (size_t)cbGap; 354 size_t cbActual; 355 rc = RTVfsIoStrmReadAt(pThis->hVfsIos, pThis->offCurPos, pvBuf, cbThisRead, fBlocking, &cbActual); 356 if (RT_FAILURE(rc) || rc == VINF_TRY_AGAIN) 357 return rc; 358 359 rtManifestHashesUpdate(pThis->pHashes, pvBuf, cbActual); 360 pThis->offCurPos += cbActual; 361 362 if (rc == VINF_EOF) 363 { 364 if (pcbRead) 365 *pcbRead = 0; 366 else 367 rc = VERR_EOF; 368 return rc; 369 } 370 } while (pThis->offCurPos < offActual); 371 Assert(RTVfsIoStrmTell(pThis->hVfsIos) == offActual); 372 } 373 374 /* 375 * At this point we've eliminated any gap and can execute the requested read. 376 */ 377 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, off, pSgBuf, fBlocking, pcbRead); 378 if (RT_SUCCESS(rc)) 379 { 380 /* See if there is anything to update the hash with. */ 381 size_t cbLeft = pcbRead ? *pcbRead : ~(size_t)0; 382 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 383 { 384 size_t cbThis = pSgBuf->paSegs[iSeg].cbSeg; 385 if (cbThis > cbLeft) 386 cbThis = cbLeft; 387 388 if ( offActual >= pThis->offCurPos 389 && pThis->offCurPos < offActual + (ssize_t)cbThis) 390 { 391 size_t offSeg = (size_t)(offActual - pThis->offCurPos); 392 rtManifestHashesUpdate(pThis->pHashes, (uint8_t *)pSgBuf->paSegs[iSeg].pvSeg + offSeg, cbThis - offSeg); 393 pThis->offCurPos += cbThis - offSeg; 394 } 395 396 cbLeft -= cbThis; 397 if (!cbLeft) 398 break; 399 offActual += cbThis; 400 } 401 } 402 } 403 return rc; 404 } 405 406 407 /** 408 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 409 */ 410 static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 411 { 412 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; 413 AssertReturn(off == -1 || off == pThis->offCurPos, VERR_WRONG_ORDER); 414 Assert(RTVfsIoStrmTell(pThis->hVfsIos) == pThis->offCurPos); 415 416 int rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, -1 /*off*/, pSgBuf, fBlocking, pcbWritten); 318 417 if (RT_SUCCESS(rc)) 319 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbRead ? *pcbRead : ~(size_t)0); 320 Assert(off == -1); NOREF(off); 321 return rc; 322 } 323 324 325 /** 326 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 327 */ 328 static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 329 { 330 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; 331 int rc = RTVfsIoStrmSgWrite(pThis->hVfsIos, pSgBuf, fBlocking, pcbWritten); 332 if (RT_SUCCESS(rc)) 418 { 333 419 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbWritten ? *pcbWritten : ~(size_t)0); 334 Assert(off == -1); NOREF(off); 420 if (!pcbWritten) 421 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 422 pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg; 423 else 424 pThis->offCurPos += *pcbWritten; 425 } 335 426 return rc; 336 427 } … … 425 516 AssertPtr(pszEntry); 426 517 AssertPtr(phVfsIosPassthru); 518 519 RTFOFF const offCurPos = RTVfsIoStrmTell(hVfsIos); 520 AssertReturn(offCurPos >= 0, (int)offCurPos); 521 427 522 uint32_t cRefs = RTManifestRetain(hManifest); 428 523 AssertReturn(cRefs != UINT32_MAX, VERR_INVALID_HANDLE); 524 429 525 cRefs = RTVfsIoStrmRetain(hVfsIos); 430 526 AssertReturnStmt(cRefs != UINT32_MAX, RTManifestRelease(hManifest), VERR_INVALID_HANDLE); … … 441 537 pThis->hVfsIos = hVfsIos; 442 538 pThis->pHashes = rtManifestHashesCreate(fAttrs); 539 pThis->offCurPos = offCurPos; 443 540 pThis->hManifest = hManifest; 444 541 pThis->fReadOrWrite = fReadOrWrite; … … 478 575 rtManifestHashesFinal(pThis->pHashes); 479 576 return rtManifestHashesSetAttrs(pThis->pHashes, pThis->hManifest, pThis->pszEntry); 577 } 578 579 580 /** 581 * Checks if the give I/O stream is a manifest passthru instance or not. 582 * 583 * @returns true if it's a manifest passthru I/O stream, false if not. 584 * @param hVfsPtIos Possible the manifest passthru I/O stream handle. 585 */ 586 RTDECL(bool) RTManifestPtIosIsInstanceOf(RTVFSIOSTREAM hVfsPtIos) 587 { 588 if (hVfsPtIos != NIL_RTVFSIOSTREAM) 589 { 590 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)RTVfsIoStreamToPrivate(hVfsPtIos, &g_rtManifestPassthruIosOps); 591 if (pThis) 592 return true; 593 } 594 return false; 480 595 } 481 596
Note:
See TracChangeset
for help on using the changeset viewer.