Changeset 100908 in vbox for trunk/src/VBox/Runtime/common/checksum
- Timestamp:
- Aug 19, 2023 2:57:05 AM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/checksum/manifest3.cpp
r99758 r100908 306 306 * 307 307 * @param pThis The passthru I/O stream instance data. 308 * @param pSgBuf The scather/gather buffer. 308 * @param pSgBuf The scather/gather buffer (clone, can be 309 * updated). 309 310 * @param cbLeft The number of bytes to take from the buffer. 310 311 */ 311 static void rtManifestPtIos_UpdateHashes(PRTMANIFESTPTIOS pThis, P CRTSGBUF pSgBuf, size_t cbLeft)312 { 313 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)314 { 315 size_t cbSeg = pSgBuf->paSegs[iSeg].cbSeg;316 if (cbSeg > cbLeft)317 cbSeg = cbLeft;318 rtManifestHashesUpdate(pThis->pHashes, p SgBuf->paSegs[iSeg].pvSeg, cbSeg);312 static void rtManifestPtIos_UpdateHashes(PRTMANIFESTPTIOS pThis, PRTSGBUF pSgBuf, size_t cbLeft) 313 { 314 while (cbLeft > 0) 315 { 316 Assert(!RTSgBufIsAtEnd(pSgBuf)); 317 size_t cbSeg = cbLeft; 318 void const * const pvSeg = RTSgBufGetNextSegment(pSgBuf, &cbSeg); 319 rtManifestHashesUpdate(pThis->pHashes, pvSeg, cbSeg); 319 320 cbLeft -= cbSeg; 320 if (!cbLeft)321 break;322 321 } 323 322 } … … 326 325 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 327 326 */ 328 static DECLCALLBACK(int) rtManifestPtIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)327 static DECLCALLBACK(int) rtManifestPtIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 329 328 { 330 329 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; … … 332 331 333 332 /* 333 * Clone the buffer for the manifest pass. 334 */ 335 RTSGBUF CloneSgBuf; 336 RTSgBufClone(&CloneSgBuf, pSgBuf); 337 338 /* 334 339 * To make sure we're continuing where we left off, we must have the exact 335 340 * stream position since a previous read using 'off' may change it. … … 338 343 if (offActual == pThis->offCurPos) 339 344 { 345 size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf); 340 346 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, off, pSgBuf, fBlocking, pcbRead); 341 347 if (RT_SUCCESS(rc)) 342 348 { 343 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbRead ? *pcbRead : ~(size_t)0); 344 if (!pcbRead) 345 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 346 pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg; 347 else 348 pThis->offCurPos += *pcbRead; 349 rtManifestPtIos_UpdateHashes(pThis, &CloneSgBuf, pcbRead ? *pcbRead : cbReq); 350 pThis->offCurPos += pcbRead ? *pcbRead : cbReq; 349 351 } 350 352 Assert(RTVfsIoStrmTell(pThis->hVfsIos) == pThis->offCurPos); … … 390 392 { 391 393 /* See if there is anything to update the hash with. */ 392 size_t cbLeft = pcbRead ? *pcbRead : ~(size_t)0;393 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)394 size_t cbLeft = pcbRead ? *pcbRead : RTSgBufCalcLengthLeft(&CloneSgBuf); 395 while (cbLeft > 0) 394 396 { 395 size_t cbThis = pSgBuf->paSegs[iSeg].cbSeg;396 if (cbThis > cbLeft)397 cbThis = cbLeft;397 Assert(!RTSgBufIsAtEnd(&CloneSgBuf)); 398 size_t cbSeg = cbLeft; 399 const uint8_t *pbSeg = (uint8_t const *)RTSgBufGetNextSegment(&CloneSgBuf, &cbSeg); 398 400 399 401 if ( offActual >= pThis->offCurPos 400 && pThis->offCurPos < offActual + (ssize_t)cb This)402 && pThis->offCurPos < offActual + (ssize_t)cbSeg) 401 403 { 402 404 size_t offSeg = (size_t)(offActual - pThis->offCurPos); 403 rtManifestHashesUpdate(pThis->pHashes, (uint8_t *)pSgBuf->paSegs[iSeg].pvSeg + offSeg, cbThis- offSeg);404 pThis->offCurPos += cb This- offSeg;405 rtManifestHashesUpdate(pThis->pHashes, &pbSeg[offSeg], cbSeg - offSeg); 406 pThis->offCurPos += cbSeg - offSeg; 405 407 } 406 408 407 cbLeft -= cbThis; 408 if (!cbLeft) 409 break; 410 offActual += cbThis; 409 cbLeft -= cbSeg; 411 410 } 412 411 } … … 419 418 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 420 419 */ 421 static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)420 static DECLCALLBACK(int) rtManifestPtIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 422 421 { 423 422 PRTMANIFESTPTIOS pThis = (PRTMANIFESTPTIOS)pvThis; … … 454 453 455 454 /* 455 * Clone the buffer for the manifest pass. 456 */ 457 RTSGBUF CloneSgBuf; 458 RTSgBufClone(&CloneSgBuf, pSgBuf); 459 size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf); 460 461 /* 456 462 * Do the writing. 457 463 */ … … 459 465 if (RT_SUCCESS(rc)) 460 466 { 461 rtManifestPtIos_UpdateHashes(pThis, pSgBuf, pcbWritten ? *pcbWritten : ~(size_t)0); 462 if (!pcbWritten) 463 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++) 464 pThis->offCurPos += pSgBuf->paSegs[iSeg].cbSeg; 465 else 466 pThis->offCurPos += *pcbWritten; 467 rtManifestPtIos_UpdateHashes(pThis, &CloneSgBuf, pcbWritten ? *pcbWritten : cbReq); 468 pThis->offCurPos += pcbWritten ? *pcbWritten : cbReq; 467 469 } 468 470 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.