Changeset 100908 in vbox
- Timestamp:
- Aug 19, 2023 2:57:05 AM (20 months ago)
- svn:sync-xref-src-repo-rev:
- 158845
- Location:
- trunk
- Files:
-
- 1 added
- 28 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/vfs.h
r98103 r100908 1133 1133 * @sa RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking 1134 1134 */ 1135 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);1135 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead); 1136 1136 1137 1137 /** … … 1152 1152 * @sa RTFileSgWrite, RTSocketSgWrite 1153 1153 */ 1154 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);1154 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten); 1155 1155 1156 1156 /** … … 1456 1456 * @sa RTFileSgRead, RTSocketSgRead, RTPipeRead, RTPipeReadBlocking 1457 1457 */ 1458 RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead);1458 RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead); 1459 1459 1460 1460 /** … … 1475 1475 * @sa RTFileSgWrite, RTSocketSgWrite 1476 1476 */ 1477 RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten);1477 RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten); 1478 1478 1479 1479 /** -
trunk/include/iprt/vfslowlevel.h
r98103 r100908 922 922 * @param pvThis The implementation specific file data. 923 923 * @param off Where to read at, -1 for the current position. 924 * @param pSgBuf Gather buffer describing the bytes that are to be 925 * written. 924 * @param pSgBuf Gather buffer for the bytes that are to be read. 926 925 * @param fBlocking If @c true, the call is blocking, if @c false it 927 926 * should not block. … … 932 931 * RTVfsFileReadAt, RTFileRead, RTFileReadAt. 933 932 */ 934 DECLCALLBACKMEMBER(int, pfnRead,(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead));933 DECLCALLBACKMEMBER(int, pfnRead,(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)); 935 934 936 935 /** … … 951 950 * @sa RTFileWrite, RTFileWriteAt. 952 951 */ 953 DECLCALLBACKMEMBER(int, pfnWrite,(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten));952 DECLCALLBACKMEMBER(int, pfnWrite,(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)); 954 953 955 954 /** -
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; -
trunk/src/VBox/Runtime/common/dvm/dvmvfs.cpp
r98103 r100908 246 246 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 247 247 */ 248 static DECLCALLBACK(int) rtDvmVfsFile_Read(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 249 { 250 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis; 251 int rc = VINF_SUCCESS; 248 static DECLCALLBACK(int) rtDvmVfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 249 { 250 PRTVFSDVMFILE const pThis = (PRTVFSDVMFILE)pvThis; 252 251 253 252 Assert(pSgBuf->cSegs == 1); … … 257 256 * Find the current position and check if it's within the volume. 258 257 */ 258 uint64_t const cbVol = RTDvmVolumeGetSize(pThis->hVol); 259 259 uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off; 260 if (offUnsigned >= RTDvmVolumeGetSize(pThis->hVol))260 if (offUnsigned >= cbVol) 261 261 { 262 262 if (pcbRead) … … 269 269 } 270 270 271 size_t cbLeftToRead; 272 if (offUnsigned + pSgBuf->paSegs[0].cbSeg > RTDvmVolumeGetSize(pThis->hVol)) 273 { 274 if (!pcbRead) 275 return VERR_EOF; 276 *pcbRead = cbLeftToRead = (size_t)(RTDvmVolumeGetSize(pThis->hVol) - offUnsigned); 271 size_t cbSeg = 0; 272 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 273 274 int rcRet = VINF_SUCCESS; 275 size_t cbToRead; 276 if (cbSeg <= cbVol - offUnsigned) 277 cbToRead = cbSeg; 278 else if (pcbRead) 279 { 280 rcRet = VINF_EOF; 281 cbToRead = (size_t)(cbVol - offUnsigned); 277 282 } 278 283 else 279 { 280 cbLeftToRead = pSgBuf->paSegs[0].cbSeg; 281 if (pcbRead) 282 *pcbRead = cbLeftToRead; 283 } 284 return VERR_EOF; 284 285 285 286 /* 286 287 * Ok, we've got a valid stretch within the file. Do the reading. 287 288 */ 288 if (cbLeftToRead > 0) 289 { 290 rc = RTDvmVolumeRead(pThis->hVol, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToRead); 291 if (RT_SUCCESS(rc)) 292 offUnsigned += cbLeftToRead; 289 if (cbToRead > 0) 290 { 291 int rc2 = RTDvmVolumeRead(pThis->hVol, offUnsigned, pvSeg, cbToRead); 292 if (RT_SUCCESS(rc2)) 293 { 294 offUnsigned += cbToRead; 295 RTSgBufAdvance(pSgBuf, cbToRead); 296 } 297 else 298 { 299 cbToRead = 0; 300 rcRet = rc2; 301 } 293 302 } 294 303 295 304 pThis->offCurPos = offUnsigned; 296 return rc; 305 if (pcbRead) 306 *pcbRead = cbToRead; 307 return rcRet; 297 308 } 298 309 … … 301 312 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 302 313 */ 303 static DECLCALLBACK(int) rtDvmVfsFile_Write(void *pvThis, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 304 { 305 PRTVFSDVMFILE pThis = (PRTVFSDVMFILE)pvThis; 306 int rc = VINF_SUCCESS; 314 static DECLCALLBACK(int) rtDvmVfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 315 { 316 PRTVFSDVMFILE const pThis = (PRTVFSDVMFILE)pvThis; 307 317 308 318 Assert(pSgBuf->cSegs == 1); … … 313 323 * Writing beyond the end of a volume is not supported. 314 324 */ 325 uint64_t const cbVol = RTDvmVolumeGetSize(pThis->hVol); 315 326 uint64_t offUnsigned = off < 0 ? pThis->offCurPos : (uint64_t)off; 316 if (offUnsigned >= RTDvmVolumeGetSize(pThis->hVol))327 if (offUnsigned >= cbVol) 317 328 { 318 329 if (pcbWritten) … … 321 332 pThis->offCurPos = offUnsigned; 322 333 } 323 return VERR_NOT_SUPPORTED; 324 } 325 326 size_t cbLeftToWrite; 327 if (offUnsigned + pSgBuf->paSegs[0].cbSeg > RTDvmVolumeGetSize(pThis->hVol)) 328 { 329 if (!pcbWritten) 330 return VERR_EOF; 331 *pcbWritten = cbLeftToWrite = (size_t)(RTDvmVolumeGetSize(pThis->hVol) - offUnsigned); 332 } 334 return VERR_DISK_FULL; /** @todo VERR_DISK_FULL is not the best status code. */ 335 } 336 337 size_t cbSeg = 0; 338 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 339 340 size_t cbToWrite; 341 if (cbSeg <= cbVol - offUnsigned) 342 cbToWrite = cbSeg; 343 else if (pcbWritten) 344 cbToWrite = (size_t)(cbVol - offUnsigned); 333 345 else 334 { 335 cbLeftToWrite = pSgBuf->paSegs[0].cbSeg; 336 if (pcbWritten) 337 *pcbWritten = cbLeftToWrite; 338 } 346 return VERR_EOF; /** @todo status to use above? or rather use VERR_DISK_FULL? */ 339 347 340 348 /* 341 349 * Ok, we've got a valid stretch within the file. Do the reading. 342 350 */ 343 if (cbLeftToWrite > 0) 344 { 345 rc = RTDvmVolumeWrite(pThis->hVol, offUnsigned, pSgBuf->paSegs[0].pvSeg, cbLeftToWrite); 351 int rc = VINF_SUCCESS; 352 if (cbToWrite > 0) 353 { 354 rc = RTDvmVolumeWrite(pThis->hVol, offUnsigned, pvSeg, cbToWrite); 346 355 if (RT_SUCCESS(rc)) 347 offUnsigned += cbLeftToWrite; 356 { 357 offUnsigned += cbToWrite; 358 RTSgBufAdvance(pSgBuf, cbToWrite); 359 } 360 else 361 cbToWrite = 0; 348 362 } 349 363 350 364 pThis->offCurPos = offUnsigned; 365 if (pcbWritten) 366 *pcbWritten = cbToWrite; 351 367 return rc; 352 368 } -
trunk/src/VBox/Runtime/common/efi/efivarstorevfs.cpp
r99739 r100908 557 557 * @returns IPRT status code. 558 558 * @param pThis The EFI variable file instance. 559 * @param p vData Pointer to the start of the data.559 * @param pbData Pointer to the start of the data. 560 560 * @param cbData Size of the variable data in bytes. 561 561 * @param off Where to start reading relative from the data start offset. … … 563 563 * @param pcbRead Where to return the number of bytes read, optional. 564 564 */ 565 static int rtEfiVarStoreFile_ReadMem(PRTEFIVARFILE pThis, const void *pvData, size_t cbData,566 RTFOFF off, P CRTSGBUF pSgBuf, size_t *pcbRead)567 { 568 int rc = VINF_SUCCESS;569 size_t cbRead = pSgBuf->paSegs[0].cbSeg;570 size_t cbThisRead = RT_MIN(cbData - off, cbRead);571 const uint8_t *pbData = (const uint8_t *)pvData;565 static int rtEfiVarStoreFile_ReadMem(PRTEFIVARFILE pThis, const uint8_t *pbData, size_t cbData, 566 RTFOFF off, PRTSGBUF pSgBuf, size_t *pcbRead) 567 { 568 int rc; 569 size_t cbSeg = 0; 570 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 571 size_t const cbDataLeft = (uint64_t)off < cbData ? cbData - (size_t)off : 0; 572 572 if (!pcbRead) 573 573 { 574 if (cbThisRead == cbRead) 575 memcpy(pSgBuf->paSegs[0].pvSeg, &pbData[off], cbThisRead); 574 if (cbSeg <= cbDataLeft) 575 { 576 memcpy(pvSeg, &pbData[off], cbSeg); 577 pThis->offFile = off + cbSeg; 578 Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> VINF_SUCCESS\n", off, cbSeg)); 579 RTSgBufAdvance(pSgBuf, cbSeg); 580 rc = VINF_SUCCESS; 581 } 576 582 else 583 { 584 Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> VERR_EOF (cbDataLeft=%#x)\n", off, cbSeg, cbDataLeft)); 577 585 rc = VERR_EOF; 578 579 if (RT_SUCCESS(rc)) 580 pThis->offFile = off + cbThisRead; 581 Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc)); 586 } 587 } 588 else if (cbDataLeft == 0) 589 { 590 Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> VINF_EOF *pcbRead=0\n", off, cbSeg)); 591 *pcbRead = 0; 592 rc = VINF_EOF; 582 593 } 583 594 else 584 595 { 585 if ((uint64_t)off >= cbData) 586 { 587 *pcbRead = 0; 588 rc = VINF_EOF; 589 } 590 else 591 { 592 memcpy(pSgBuf->paSegs[0].pvSeg, &pbData[off], cbThisRead); 593 /* Return VINF_EOF if beyond end-of-file. */ 594 if (cbThisRead < cbRead) 595 rc = VINF_EOF; 596 pThis->offFile = off + cbThisRead; 597 *pcbRead = cbThisRead; 598 } 599 Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, pSgBuf->paSegs[0].cbSeg, rc, *pcbRead)); 596 size_t const cbThisRead = RT_MAX(cbSeg, cbDataLeft); 597 memcpy(pvSeg, &pbData[off], cbThisRead); 598 599 pThis->offFile = off + cbThisRead; 600 *pcbRead = cbThisRead; 601 RTSgBufAdvance(pSgBuf, cbThisRead); 602 603 /* Return VINF_EOF if beyond end-of-file. */ 604 rc = cbThisRead == cbSeg ? VINF_SUCCESS : VINF_EOF; 605 Log6(("rtEfiVarStoreFile_ReadMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, cbSeg, rc, cbThisRead)); 600 606 } 601 607 … … 609 615 * @returns IPRT status code. 610 616 * @param pThis The EFI variable file instance. 611 * @param p vData Pointer to the start of the data.617 * @param pbData Pointer to the start of the data. 612 618 * @param cbData Size of the variable data in bytes. 613 619 * @param off Where to start writing relative from the data start offset. … … 615 621 * @param pcbWritten Where to return the number of bytes written, optional. 616 622 */ 617 static int rtEfiVarStoreFile_WriteMem(PRTEFIVARFILE pThis, void *pvData, size_t cbData,618 RTFOFF off, P CRTSGBUF pSgBuf, size_t *pcbWritten)619 { 620 int rc = VINF_SUCCESS;621 size_t cbWrite = pSgBuf->paSegs[0].cbSeg;622 size_t cbThisWrite = RT_MIN(cbData - off, cbWrite);623 uint8_t *pbData = (uint8_t *)pvData;623 static int rtEfiVarStoreFile_WriteMem(PRTEFIVARFILE pThis, uint8_t *pbData, size_t cbData, 624 RTFOFF off, PRTSGBUF pSgBuf, size_t *pcbWritten) 625 { 626 int rc; 627 size_t cbSeg = 0; 628 void const * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 629 size_t const cbDataLeft = (uint64_t)off < cbData ? cbData - (size_t)off : 0; 624 630 if (!pcbWritten) 625 631 { 626 if (cbThisWrite == cbWrite) 627 memcpy(&pbData[off], pSgBuf->paSegs[0].pvSeg, cbThisWrite); 632 if (cbSeg <= cbDataLeft) 633 { 634 memcpy(&pbData[off], pvSeg, cbSeg); 635 pThis->offFile = off + cbSeg; 636 RTSgBufAdvance(pSgBuf, cbSeg); 637 Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> VINF_SUCCESS\n", off, cbSeg)); 638 rc = VINF_SUCCESS; 639 } 628 640 else 629 rc = VERR_EOF; 630 631 if (RT_SUCCESS(rc)) 632 pThis->offFile = off + cbThisWrite; 633 Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc)); 641 { 642 Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> VERR_EOF\n", off, cbSeg)); 643 rc = VERR_EOF; /** @todo r=bird: This status seems bogus. Use VERR_FILE_TOO_BIG instead? */ 644 } 645 } 646 else if (cbDataLeft == 0) 647 { 648 *pcbWritten = 0; 649 rc = VINF_EOF; /** @todo r=bird: This is weird. Implementing the read EOF protocol for a write... */ 634 650 } 635 651 else 636 652 { 637 if ((uint64_t)off >= cbData) 638 { 639 *pcbWritten = 0; 640 rc = VINF_EOF; 641 } 642 else 643 { 644 memcpy(&pbData[off], pSgBuf->paSegs[0].pvSeg, cbThisWrite); 645 /* Return VINF_EOF if beyond end-of-file. */ 646 if (cbThisWrite < cbWrite) 647 rc = VINF_EOF; 648 pThis->offFile = off + cbThisWrite; 649 *pcbWritten = cbThisWrite; 650 } 651 Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbWritten=%#x\n", off, pSgBuf->paSegs[0].cbSeg, rc, *pcbWritten)); 652 } 653 653 size_t const cbThisWrite = RT_MAX(cbSeg, cbDataLeft); 654 memcpy(&pbData[off], pvSeg, cbThisWrite); 655 656 pThis->offFile = off + cbThisWrite; 657 *pcbWritten = cbThisWrite; 658 RTSgBufAdvance(pSgBuf, cbThisWrite); 659 660 /* Return VINF_EOF if beyond end-of-file. */ 661 /** @todo r=bird: This is weird. Implementing the read EOF protocol for a write... */ 662 rc = cbThisWrite == cbSeg ? VINF_SUCCESS : VINF_EOF; 663 Log6(("rtEfiVarStoreFile_WriteMem: off=%#RX64 cbSeg=%#x -> %Rrc *pcbWritten=%#x\n", off, cbSeg, rc, cbThisWrite)); 664 } 654 665 return rc; 655 666 } … … 668 679 */ 669 680 static int rtEfiVarStoreFile_ReadFile(PRTEFIVARFILE pThis, uint64_t offData, size_t cbData, 670 RTFOFF off, PCRTSGBUF pSgBuf, size_t *pcbRead) 671 { 672 int rc; 673 PRTEFIVARSTORE pVarStore = pThis->pVarStore; 674 size_t cbRead = pSgBuf->paSegs[0].cbSeg; 675 size_t cbThisRead = RT_MIN(cbData - off, cbRead); 676 uint64_t offStart = offData + off; 681 RTFOFF off, PRTSGBUF pSgBuf, size_t *pcbRead) 682 { 683 int rc; 684 PRTEFIVARSTORE const pVarStore = pThis->pVarStore; 685 size_t cbSeg = 0; 686 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 687 size_t const cbDataLeft = (uint64_t)off < cbData ? cbData - (size_t)off : 0; 688 uint64_t const offBacking = offData + off; 677 689 if (!pcbRead) 678 690 { 679 if (cbThisRead == cbRead) 680 rc = RTVfsFileReadAt(pVarStore->hVfsBacking, offStart, pSgBuf->paSegs[0].pvSeg, cbThisRead, NULL); 691 if (cbSeg <= cbDataLeft) 692 { 693 rc = RTVfsFileSgRead(pVarStore->hVfsBacking, offBacking, pSgBuf, true /*fBlocking*/, NULL /*pcbRead*/); 694 if (RT_SUCCESS(rc)) 695 pThis->offFile = off + cbSeg; 696 Log6(("rtEfiVarStoreFile_ReadFile: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, cbSeg, rc)); 697 } 681 698 else 699 { 700 Log6(("rtEfiVarStoreFile_ReadFile: off=%#RX64 cbSeg=%#x cbDataLeft=%#zx -> VERR_EOF\n", off, cbSeg, cbDataLeft)); 682 701 rc = VERR_EOF; 683 702 } 703 } 704 else if (cbDataLeft == 0) 705 { 706 Log6(("rtEfiVarStoreFile_ReadFile: off=%#RX64 cbSeg=%#x -> VINF_EOF\n", off, cbSeg)); 707 *pcbRead = 0; 708 rc = VINF_EOF; 709 } 710 else 711 { 712 size_t const cbThisRead = RT_MAX(cbSeg, cbDataLeft); 713 rc = RTVfsFileReadAt(pVarStore->hVfsBacking, offBacking, pvSeg, cbThisRead, NULL /*pcbRead*/); 684 714 if (RT_SUCCESS(rc)) 715 { 685 716 pThis->offFile = off + cbThisRead; 686 Log6(("rtFsEfiVarStore_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc)); 687 } 688 else 689 { 690 if ((uint64_t)off >= cbData) 691 { 717 *pcbRead = cbThisRead; 718 RTSgBufAdvance(pSgBuf, cbThisRead); 719 720 /* Return VINF_EOF if beyond end-of-file. */ 721 rc = cbThisRead == cbSeg ? VINF_SUCCESS : VINF_EOF; 722 } 723 else 692 724 *pcbRead = 0; 693 rc = VINF_EOF; 694 } 695 else 696 { 697 rc = RTVfsFileReadAt(pVarStore->hVfsBacking, offStart, pSgBuf->paSegs[0].pvSeg, cbThisRead, NULL); 698 if (RT_SUCCESS(rc)) 699 { 700 /* Return VINF_EOF if beyond end-of-file. */ 701 if (cbThisRead < cbRead) 702 rc = VINF_EOF; 703 pThis->offFile = off + cbThisRead; 704 *pcbRead = cbThisRead; 705 } 706 else 707 *pcbRead = 0; 708 } 709 Log6(("rtFsEfiVarStore_Read: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, pSgBuf->paSegs[0].cbSeg, rc, *pcbRead)); 710 } 711 725 Log6(("rtFsEfiVarStore_Read: off=%#RX64 cbSeg=%#x -> %Rrc *pcbRead=%#x\n", off, cbSeg, rc, *pcbRead)); 726 } 712 727 return rc; 713 728 } … … 1065 1080 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 1066 1081 */ 1067 static DECLCALLBACK(int) rtEfiVarStoreFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)1082 static DECLCALLBACK(int) rtEfiVarStoreFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 1068 1083 { 1069 1084 PRTEFIVARFILE pThis = (PRTEFIVARFILE)pvThis; … … 1079 1094 int rc; 1080 1095 if (pThis->pEntry->cbObject) 1081 rc = rtEfiVarStoreFile_ReadMem(pThis, (const uint8_t *)pVar + pThis->pEntry->offObject, pThis->pEntry->cbObject, off, pSgBuf, pcbRead); 1096 rc = rtEfiVarStoreFile_ReadMem(pThis, (const uint8_t *)pVar + pThis->pEntry->offObject, pThis->pEntry->cbObject, off, 1097 pSgBuf, pcbRead); 1082 1098 else 1083 1099 { 1084 1100 /* Data section. */ 1085 1101 if (!pVar->offVarData) 1086 rc = rtEfiVarStoreFile_ReadMem(pThis, pVar->pvData, pVar->cbData, off, pSgBuf, pcbRead);1102 rc = rtEfiVarStoreFile_ReadMem(pThis, (const uint8_t *)pVar->pvData, pVar->cbData, off, pSgBuf, pcbRead); 1087 1103 else 1088 1104 rc = rtEfiVarStoreFile_ReadFile(pThis, pVar->offVarData, pVar->cbData, off, pSgBuf, pcbRead); … … 1096 1112 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 1097 1113 */ 1098 static DECLCALLBACK(int) rtEfiVarStoreFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)1114 static DECLCALLBACK(int) rtEfiVarStoreFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 1099 1115 { 1100 1116 PRTEFIVARFILE pThis = (PRTEFIVARFILE)pvThis; … … 1125 1141 rc = rtEfiVarStore_VarEnsureDataSz(pVar, off + pSgBuf->paSegs[0].cbSeg); 1126 1142 if (RT_SUCCESS(rc)) 1127 rc = rtEfiVarStoreFile_WriteMem(pThis, pVar->pvData, pVar->cbData, off, pSgBuf, pcbWritten);1143 rc = rtEfiVarStoreFile_WriteMem(pThis, (uint8_t *)pVar->pvData, pVar->cbData, off, pSgBuf, pcbWritten); 1128 1144 } 1129 1145 } -
trunk/src/VBox/Runtime/common/fs/extvfs.cpp
r99739 r100908 1716 1716 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 1717 1717 */ 1718 static DECLCALLBACK(int) rtFsExtFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)1718 static DECLCALLBACK(int) rtFsExtFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 1719 1719 { 1720 1720 PRTFSEXTFILE pThis = (PRTFSEXTFILE)pvThis; … … 1733 1733 rc = rtFsExtInode_Read(pThis->pVol, pThis->pInode, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbRead, NULL); 1734 1734 if (RT_SUCCESS(rc)) 1735 { 1735 1736 pThis->offFile = off + cbRead; 1737 RTSgBufAdvance(pSgBuf, cbRead); 1738 } 1736 1739 Log6(("rtFsExtFile_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc)); 1737 1740 } … … 1760 1763 pThis->offFile = off + cbRead; 1761 1764 *pcbRead = cbRead; 1765 RTSgBufAdvance(pSgBuf, cbRead); 1762 1766 } 1763 1767 else … … 1774 1778 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 1775 1779 */ 1776 static DECLCALLBACK(int) rtFsExtFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)1780 static DECLCALLBACK(int) rtFsExtFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 1777 1781 { 1778 1782 RT_NOREF(pvThis, off, pSgBuf, fBlocking, pcbWritten); -
trunk/src/VBox/Runtime/common/fs/fatvfs.cpp
r98103 r100908 2165 2165 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 2166 2166 */ 2167 static DECLCALLBACK(int) rtFsFatFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)2167 static DECLCALLBACK(int) rtFsFatFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 2168 2168 { 2169 2169 PRTFSFATFILE pThis = (PRTFSFATFILE)pvThis; … … 2230 2230 if (pcbRead) 2231 2231 *pcbRead = cbRead; 2232 RTSgBufAdvance(pSgBuf, cbRead); 2232 2233 return rc; 2233 2234 } … … 2327 2328 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 2328 2329 */ 2329 static DECLCALLBACK(int) rtFsFatFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)2330 static DECLCALLBACK(int) rtFsFatFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 2330 2331 { 2331 2332 PRTFSFATFILE pThis = (PRTFSFATFILE)pvThis; … … 2401 2402 if (pcbWritten) 2402 2403 *pcbWritten = cbWritten; 2404 RTSgBufAdvance(pSgBuf, cbWritten); 2403 2405 return rc; 2404 2406 } -
trunk/src/VBox/Runtime/common/fs/isomaker.cpp
r98103 r100908 7280 7280 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 7281 7281 */ 7282 static DECLCALLBACK(int) rtFsIsoMakerOutFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)7282 static DECLCALLBACK(int) rtFsIsoMakerOutFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 7283 7283 { 7284 7284 PRTFSISOMAKEROUTPUTFILE pThis = (PRTFSISOMAKEROUTPUTFILE)pvThis; … … 7396 7396 if (pcbRead) 7397 7397 *pcbRead = cbRead; 7398 RTSgBufAdvance(pSgBuf, cbRead); 7398 7399 return rc; 7399 7400 } -
trunk/src/VBox/Runtime/common/fs/isovfs.cpp
r98103 r100908 2119 2119 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 2120 2120 */ 2121 static DECLCALLBACK(int) rtFsIsoFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)2121 static DECLCALLBACK(int) rtFsIsoFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 2122 2122 { 2123 2123 PRTFSISOFILEOBJ pThis = (PRTFSISOFILEOBJ)pvThis; … … 2140 2140 /* Update the file position and return. */ 2141 2141 pThis->offFile = off + offDelta; 2142 RTSgBufAdvance(pSgBuf, offDelta); 2143 2142 2144 return rc; 2143 2145 #else -
trunk/src/VBox/Runtime/common/fs/ntfsvfs.cpp
r98103 r100908 2374 2374 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 2375 2375 */ 2376 static DECLCALLBACK(int) rtFsNtfsFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)2376 static DECLCALLBACK(int) rtFsNtfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 2377 2377 { 2378 2378 PRTFSNTFSFILE pThis = (PRTFSNTFSFILE)pvThis; … … 2391 2391 rc = rtFsNtfsAttr_Read(pThis->pShared->pData, off, pSgBuf->paSegs[0].pvSeg, cbRead); 2392 2392 if (RT_SUCCESS(rc)) 2393 { 2393 2394 pThis->offFile = off + cbRead; 2395 RTSgBufAdvance(pSgBuf, cbRead); 2396 } 2394 2397 Log6(("rtFsNtfsFile_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc)); 2395 2398 } … … 2418 2421 pThis->offFile = off + cbRead; 2419 2422 *pcbRead = cbRead; 2423 RTSgBufAdvance(pSgBuf, cbRead); 2420 2424 } 2421 2425 else … … 2432 2436 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 2433 2437 */ 2434 static DECLCALLBACK(int) rtFsNtfsFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)2438 static DECLCALLBACK(int) rtFsNtfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 2435 2439 { 2436 2440 PRTFSNTFSFILE pThis = (PRTFSNTFSFILE)pvThis; … … 2451 2455 Log6(("rtFsNtfsFile_Write: off=%#RX64 cbToWrite=%#zx -> %Rrc\n", off, cbToWrite, rc)); 2452 2456 if (RT_SUCCESS(rc)) 2457 { 2453 2458 pThis->offFile = off + cbToWrite; 2459 RTSgBufAdvance(pSgBuf, cbToWrite); 2460 } 2454 2461 if (pcbWritten) 2455 2462 *pcbWritten = RT_SUCCESS(rc) ? cbToWrite : 0; … … 2466 2473 if (pcbWritten) 2467 2474 *pcbWritten = cbWritten; 2475 RTSgBufAdvance(pSgBuf, cbWritten); 2468 2476 rc = VERR_EOF; 2469 2477 } -
trunk/src/VBox/Runtime/common/fs/xfsvfs.cpp
r99739 r100908 1474 1474 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 1475 1475 */ 1476 static DECLCALLBACK(int) rtFsXfsFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)1476 static DECLCALLBACK(int) rtFsXfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 1477 1477 { 1478 1478 PRTFSXFSFILE pThis = (PRTFSXFSFILE)pvThis; … … 1491 1491 rc = rtFsXfsInode_Read(pThis->pVol, pThis->pInode, (uint64_t)off, pSgBuf->paSegs[0].pvSeg, cbRead, NULL); 1492 1492 if (RT_SUCCESS(rc)) 1493 { 1493 1494 pThis->offFile = off + cbRead; 1495 RTSgBufAdvance(pSgBuf, cbRead); 1496 } 1494 1497 Log6(("rtFsXfsFile_Read: off=%#RX64 cbSeg=%#x -> %Rrc\n", off, pSgBuf->paSegs[0].cbSeg, rc)); 1495 1498 } … … 1518 1521 pThis->offFile = off + cbRead; 1519 1522 *pcbRead = cbRead; 1523 RTSgBufAdvance(pSgBuf, cbRead); 1520 1524 } 1521 1525 else … … 1532 1536 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 1533 1537 */ 1534 static DECLCALLBACK(int) rtFsXfsFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)1538 static DECLCALLBACK(int) rtFsXfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 1535 1539 { 1536 1540 RT_NOREF(pvThis, off, pSgBuf, fBlocking, pcbWritten); -
trunk/src/VBox/Runtime/common/misc/sg.cpp
r99961 r100908 439 439 size_t cbLeft = cbAdvance; 440 440 441 while (cbLeft) 441 while ( cbLeft 442 || ( pSgBuf->cbSegLeft == 0 443 && pSgBuf->idxSeg > pSgBuf->cSegs)) 442 444 { 443 445 size_t cbThisAdvance = cbLeft; -
trunk/src/VBox/Runtime/common/vfs/vfsbase.cpp
r98103 r100908 110 110 AssertPtrNull((pDirOps)->pfnCreateDir); \ 111 111 AssertPtrNull((pDirOps)->pfnOpenSymlink); \ 112 AssertPtr((pDirOps)->pfnCreateSymlink); \ 113 AssertPtr((pDirOps)->pfnUnlinkEntry); \ 112 AssertPtrNull((pDirOps)->pfnCreateSymlink); \ 113 AssertPtrNull((pDirOps)->pfnUnlinkEntry); \ 114 AssertPtrNull((pDirOps)->pfnRenameEntry); \ 114 115 AssertPtr((pDirOps)->pfnRewindDir); \ 115 116 AssertPtr((pDirOps)->pfnReadDir); \ … … 3241 3242 3242 3243 RTVfsLockAcquireWrite(pVfsParentDir->Base.hLock); 3243 rc = pVfsParentDir->pOps->pfnUnlinkEntry(pVfsParentDir->Base.pvThis, pszEntryName, RTFS_TYPE_DIRECTORY); 3244 if (pVfsParentDir->pOps->pfnUnlinkEntry) 3245 rc = pVfsParentDir->pOps->pfnUnlinkEntry(pVfsParentDir->Base.pvThis, pszEntryName, RTFS_TYPE_DIRECTORY); 3246 else 3247 rc = VERR_NOT_SUPPORTED; 3244 3248 RTVfsLockReleaseWrite(pVfsParentDir->Base.hLock); 3245 3249 … … 3612 3616 int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbRead); 3613 3617 RTVfsLockReleaseWrite(pThis->Base.hLock); 3618 Assert(rc != VINF_SUCCESS || RTSgBufIsAtEnd(&SgBuf)); 3614 3619 return rc; 3615 3620 } … … 3635 3640 int rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbRead); 3636 3641 RTVfsLockReleaseWrite(pThis->Base.hLock); 3642 Assert(rc != VINF_SUCCESS || RTSgBufIsAtEnd(&SgBuf)); 3637 3643 return rc; 3638 3644 } … … 3660 3666 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, -1 /*off*/, &SgBuf, fBlocking, pcbWritten); 3661 3667 RTVfsLockReleaseWrite(pThis->Base.hLock); 3668 Assert(!pcbWritten || *pcbWritten + RTSgBufCalcLengthLeft(&SgBuf) == cbToWrite || RT_FAILURE(rc)); 3662 3669 } 3663 3670 else … … 3689 3696 rc = pThis->pOps->pfnWrite(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbWritten); 3690 3697 RTVfsLockReleaseWrite(pThis->Base.hLock); 3698 Assert(!pcbWritten || *pcbWritten + RTSgBufCalcLengthLeft(&SgBuf) == cbToWrite || RT_FAILURE(rc)); 3691 3699 } 3692 3700 else … … 3696 3704 3697 3705 3698 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)3706 RTDECL(int) RTVfsIoStrmSgRead(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 3699 3707 { 3700 3708 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); … … 3717 3725 rc = VINF_SUCCESS; 3718 3726 3719 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)3727 while (!RTSgBufIsAtEnd(pSgBuf)) 3720 3728 { 3721 3729 RTSGBUF SgBuf; 3722 RTSgBufInit(&SgBuf, &pSgBuf->paSegs[iSeg], 1); 3723 3724 size_t cbReadSeg = pcbRead ? 0 : pSgBuf->paSegs[iSeg].cbSeg; 3730 RTSGSEG SgSeg; 3731 SgSeg.pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &SgSeg.cbSeg); 3732 RTSgBufInit(&SgBuf, &SgSeg, 1); 3733 3734 size_t cbReadSeg = pcbRead ? 0 : SgSeg.cbSeg; 3725 3735 rc = pThis->pOps->pfnRead(pThis->Base.pvThis, off, &SgBuf, fBlocking, pcbRead ? &cbReadSeg : NULL); 3726 3736 if (RT_FAILURE(rc)) 3727 3737 break; 3728 3738 cbRead += cbReadSeg; 3729 if ((pcbRead && cbReadSeg != SgBuf.paSegs[0].cbSeg) || rc != VINF_SUCCESS) 3739 RTSgBufAdvance(pSgBuf, cbReadSeg); 3740 if ((pcbRead && cbReadSeg != SgSeg.cbSeg) || rc != VINF_SUCCESS) 3730 3741 break; 3731 3742 if (off != -1) … … 3737 3748 } 3738 3749 RTVfsLockReleaseWrite(pThis->Base.hLock); 3739 return rc; 3740 } 3741 3742 3743 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PCRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 3750 Assert(rc != VINF_SUCCESS || RTSgBufIsAtEnd(pSgBuf)); 3751 return rc; 3752 } 3753 3754 3755 RTDECL(int) RTVfsIoStrmSgWrite(RTVFSIOSTREAM hVfsIos, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 3744 3756 { 3745 3757 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); … … 3764 3776 rc = VINF_SUCCESS; 3765 3777 3766 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)3778 while (!RTSgBufIsAtEnd(pSgBuf)) 3767 3779 { 3768 3780 RTSGBUF SgBuf; 3769 RTSgBufInit(&SgBuf, &pSgBuf->paSegs[iSeg], 1); 3781 RTSGSEG SgSeg; 3782 SgSeg.pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &SgSeg.cbSeg); 3783 RTSgBufInit(&SgBuf, &SgSeg, 1); 3770 3784 3771 3785 size_t cbWrittenSeg = 0; … … 3776 3790 { 3777 3791 cbWritten += cbWrittenSeg; 3778 if (cbWrittenSeg != SgBuf.paSegs[0].cbSeg) 3792 RTSgBufAdvance(pSgBuf, cbWrittenSeg); 3793 if (cbWrittenSeg != SgSeg.cbSeg) 3779 3794 break; 3780 3795 if (off != -1) 3781 3796 off += cbWrittenSeg; 3782 3797 } 3783 else if (off != -1) 3784 off += pSgBuf->paSegs[iSeg].cbSeg; 3798 else 3799 { 3800 RTSgBufAdvance(pSgBuf, SgSeg.cbSeg); 3801 if (off != -1) 3802 off += SgSeg.cbSeg; 3803 } 3785 3804 } 3786 3805 … … 4232 4251 4233 4252 4234 RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)4253 RTDECL(int) RTVfsFileSgRead(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 4235 4254 { 4236 4255 AssertPtrNullReturn(pcbRead, VERR_INVALID_POINTER); … … 4245 4264 4246 4265 4247 RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)4266 RTDECL(int) RTVfsFileSgWrite(RTVFSFILE hVfsFile, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 4248 4267 { 4249 4268 AssertPtrNullReturn(pcbWritten, VERR_INVALID_POINTER); -
trunk/src/VBox/Runtime/common/vfs/vfsmemory.cpp
r98103 r100908 264 264 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 265 265 */ 266 static DECLCALLBACK(int) rtVfsMemFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)266 static DECLCALLBACK(int) rtVfsMemFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 267 267 { 268 268 PRTVFSMEMFILE pThis = (PRTVFSMEMFILE)pvThis; … … 305 305 if (cbLeftToRead > 0) 306 306 { 307 RTSgBufAdvance(pSgBuf, cbLeftToRead); 308 307 309 uint8_t *pbDst = (uint8_t *)pSgBuf->paSegs[0].pvSeg; 308 310 bool fHit; … … 458 460 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 459 461 */ 460 static DECLCALLBACK(int) rtVfsMemFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)462 static DECLCALLBACK(int) rtVfsMemFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 461 463 { 462 464 PRTVFSMEMFILE pThis = (PRTVFSMEMFILE)pvThis; … … 551 553 pThis->Base.ObjInfo.cbObject = offUnsigned; 552 554 555 size_t const cbWritten = pSgBuf->paSegs[0].cbSeg - cbLeftToWrite; 553 556 if (pcbWritten) 554 *pcbWritten = pSgBuf->paSegs[0].cbSeg - cbLeftToWrite; 557 *pcbWritten = cbWritten; 558 RTSgBufAdvance(pSgBuf, cbWritten); 555 559 return rc; 556 560 } -
trunk/src/VBox/Runtime/common/vfs/vfsprogress.cpp
r98103 r100908 149 149 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 150 150 */ 151 static DECLCALLBACK(int) rtVfsProgressFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)151 static DECLCALLBACK(int) rtVfsProgressFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 152 152 { 153 153 PRTVFSPROGRESSFILE pThis = (PRTVFSPROGRESSFILE)pvThis; … … 166 166 167 167 /* Calc the request before calling down the stack. */ 168 size_t cbReq = 0; 169 unsigned i = pSgBuf->cSegs; 170 while (i-- > 0) 171 cbReq += pSgBuf->paSegs[i].cbSeg; 168 size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf); 172 169 173 170 /* Do the read. */ … … 188 185 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 189 186 */ 190 static DECLCALLBACK(int) rtVfsProgressFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)187 static DECLCALLBACK(int) rtVfsProgressFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 191 188 { 192 189 PRTVFSPROGRESSFILE pThis = (PRTVFSPROGRESSFILE)pvThis; … … 205 202 206 203 /* Calc the request before calling down the stack. */ 207 size_t cbReq = 0; 208 unsigned i = pSgBuf->cSegs; 209 while (i-- > 0) 210 cbReq += pSgBuf->paSegs[i].cbSeg; 204 size_t const cbReq = RTSgBufCalcLengthLeft(pSgBuf); 211 205 212 206 /* Do the read. */ -
trunk/src/VBox/Runtime/common/vfs/vfsreadahead.cpp
r98103 r100908 212 212 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 213 213 */ 214 static DECLCALLBACK(int) rtVfsReadAhead_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)214 static DECLCALLBACK(int) rtVfsReadAhead_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 215 215 { 216 216 PRTVFSREADAHEAD pThis = (PRTVFSREADAHEAD)pvThis; … … 348 348 *pcbRead = cbTotalRead; 349 349 Assert(cbTotalRead <= pSgBuf->paSegs[0].cbSeg); 350 RTSgBufAdvance(pSgBuf, cbTotalRead); 350 351 351 352 return rc; … … 356 357 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 357 358 */ 358 static DECLCALLBACK(int) rtVfsReadAhead_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)359 static DECLCALLBACK(int) rtVfsReadAhead_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 359 360 { 360 361 RT_NOREF_PV(pvThis); RT_NOREF_PV(off); RT_NOREF_PV(pSgBuf); RT_NOREF_PV(fBlocking); RT_NOREF_PV(pcbWritten); -
trunk/src/VBox/Runtime/common/vfs/vfsstdfile.cpp
r98103 r100908 142 142 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 143 143 */ 144 static DECLCALLBACK(int) rtVfsStdFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)144 static DECLCALLBACK(int) rtVfsStdFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 145 145 { 146 146 PRTVFSSTDFILE pThis = (PRTVFSSTDFILE)pvThis; … … 150 150 if (pSgBuf->cSegs == 1) 151 151 { 152 size_t cbToRead = 0; 153 void * const pvDst = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbToRead); 154 152 155 if (off < 0) 153 rc = RTFileRead( pThis->hFile, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead);156 rc = RTFileRead(pThis->hFile, pvDst, cbToRead, pcbRead); 154 157 else 155 158 { 156 rc = RTFileReadAt(pThis->hFile, off, p SgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead);159 rc = RTFileReadAt(pThis->hFile, off, pvDst, cbToRead, pcbRead); 157 160 if (RT_SUCCESS(rc)) /* RTFileReadAt() doesn't increment the file-position indicator on some platforms */ 158 rc = RTFileSeek(pThis->hFile, off + (pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg), RTFILE_SEEK_BEGIN, NULL);161 rc = RTFileSeek(pThis->hFile, off + (pcbRead ? *pcbRead : cbToRead), RTFILE_SEEK_BEGIN, NULL); 159 162 } 160 163 if (rc == VINF_SUCCESS && pcbRead) 161 rc = rtVfsStdFile_ReadFixRC(pThis, off, pSgBuf->paSegs[0].cbSeg, *pcbRead); 164 rc = rtVfsStdFile_ReadFixRC(pThis, off, cbToRead, *pcbRead); 165 if (RT_SUCCESS(rc)) 166 RTSgBufAdvance(pSgBuf, pcbRead ? *pcbRead : cbToRead); 162 167 } 163 168 else 164 169 { 165 size_t cbSeg = 0; 166 size_t cbRead = 0; 167 size_t cbReadSeg = 0; 170 size_t cbSeg = 0; 171 size_t cbRead = 0; 168 172 rc = VINF_SUCCESS; 169 173 170 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)174 while (!RTSgBufIsAtEnd(pSgBuf)) 171 175 { 172 void *pvSeg = pSgBuf->paSegs[iSeg].pvSeg; 173 cbSeg = pSgBuf->paSegs[iSeg].cbSeg; 174 175 cbReadSeg = cbSeg; 176 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 177 178 size_t cbReadSeg = cbSeg; 176 179 if (off < 0) 177 180 rc = RTFileRead( pThis->hFile, pvSeg, cbSeg, pcbRead ? &cbReadSeg : NULL); … … 184 187 if (RT_FAILURE(rc)) 185 188 break; 189 186 190 if (off >= 0) 187 191 off += cbReadSeg; 188 192 cbRead += cbReadSeg; 193 RTSgBufAdvance(pSgBuf, cbReadSeg); 194 189 195 if ((pcbRead && cbReadSeg != cbSeg) || rc != VINF_SUCCESS) 190 196 break; … … 195 201 *pcbRead = cbRead; 196 202 if (rc == VINF_SUCCESS) 197 rc = rtVfsStdFile_ReadFixRC(pThis, off, cbSeg, cbRead Seg);203 rc = rtVfsStdFile_ReadFixRC(pThis, off, cbSeg, cbRead); 198 204 } 199 205 } … … 206 212 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 207 213 */ 208 static DECLCALLBACK(int) rtVfsStdFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)214 static DECLCALLBACK(int) rtVfsStdFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 209 215 { 210 216 PRTVFSSTDFILE pThis = (PRTVFSSTDFILE)pvThis; … … 214 220 if (pSgBuf->cSegs == 1) 215 221 { 222 size_t cbToWrite = 0; 223 void const * const pvSrc = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbToWrite); 224 216 225 if (off < 0) 217 rc = RTFileWrite(pThis->hFile, p SgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbWritten);226 rc = RTFileWrite(pThis->hFile, pvSrc, cbToWrite, pcbWritten); 218 227 else 219 228 { 220 rc = RTFileWriteAt(pThis->hFile, off, p SgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbWritten);229 rc = RTFileWriteAt(pThis->hFile, off, pvSrc, cbToWrite, pcbWritten); 221 230 if (RT_SUCCESS(rc)) /* RTFileWriteAt() doesn't increment the file-position indicator on some platforms */ 222 rc = RTFileSeek(pThis->hFile, off + (pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg), RTFILE_SEEK_BEGIN, 223 NULL); 231 rc = RTFileSeek(pThis->hFile, off + (pcbWritten ? *pcbWritten : cbToWrite), RTFILE_SEEK_BEGIN, NULL); 224 232 } 233 if (RT_SUCCESS(rc)) 234 RTSgBufAdvance(pSgBuf, pcbWritten ? *pcbWritten : cbToWrite); 225 235 } 226 236 else … … 231 241 rc = VINF_SUCCESS; 232 242 233 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)243 while (!RTSgBufIsAtEnd(pSgBuf)) 234 244 { 235 void *pvSeg = pSgBuf->paSegs[iSeg].pvSeg;236 size_t cbSeg = pSgBuf->paSegs[iSeg].cbSeg;245 size_t cbSeg = 0; 246 void const * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 237 247 238 248 cbWrittenSeg = 0; … … 253 263 if (pcbWritten) 254 264 { 265 RTSgBufAdvance(pSgBuf, cbWrittenSeg); 255 266 cbWritten += cbWrittenSeg; 256 267 if (cbWrittenSeg != cbSeg) 257 268 break; 258 269 } 270 else 271 RTSgBufAdvance(pSgBuf, cbSeg); 259 272 } 260 273 -
trunk/src/VBox/Runtime/common/vfs/vfsstdpipe.cpp
r98103 r100908 97 97 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 98 98 */ 99 static DECLCALLBACK(int) rtVfsStdPipe_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)99 static DECLCALLBACK(int) rtVfsStdPipe_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 100 100 { 101 101 PRTVFSSTDPIPE pThis = (PRTVFSSTDPIPE)pvThis; … … 111 111 rc = RTPipeRead( pThis->hPipe, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbRead); 112 112 if (RT_SUCCESS(rc)) 113 pThis->offFakePos += pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg; 113 { 114 size_t const cbAdv = pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg; 115 pThis->offFakePos += cbAdv; 116 RTSgBufAdvance(pSgBuf, cbAdv); 117 } 114 118 } 115 119 else 116 120 { 117 size_t cbSeg = 0;118 121 size_t cbRead = 0; 119 122 size_t cbReadSeg = 0; … … 121 124 rc = VINF_SUCCESS; 122 125 123 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)126 while (!RTSgBufIsAtEnd(pSgBuf)) 124 127 { 125 void *pvSeg = pSgBuf->paSegs[iSeg].pvSeg;126 cbSeg = pSgBuf->paSegs[iSeg].cbSeg;128 size_t cbSeg = 0; 129 void *pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 127 130 128 131 cbReadSeg = cbSeg; … … 133 136 if (RT_FAILURE(rc)) 134 137 break; 135 pThis->offFakePos += pcbRead ? cbReadSeg : cbSeg; 136 cbRead += cbReadSeg; 138 139 pThis->offFakePos += cbReadSeg; 140 cbRead += cbReadSeg; 141 RTSgBufAdvance(pSgBuf, cbReadSeg); 137 142 if (rc != VINF_SUCCESS) 138 143 break; … … 151 156 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 152 157 */ 153 static DECLCALLBACK(int) rtVfsStdPipe_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)158 static DECLCALLBACK(int) rtVfsStdPipe_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 154 159 { 155 160 PRTVFSSTDPIPE pThis = (PRTVFSSTDPIPE)pvThis; … … 164 169 rc = RTPipeWrite( pThis->hPipe, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, pcbWritten); 165 170 if (RT_SUCCESS(rc)) 166 pThis->offFakePos += pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg; 171 { 172 size_t const cbAdv = pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg; 173 pThis->offFakePos += cbAdv; 174 RTSgBufAdvance(pSgBuf, cbAdv); 175 } 167 176 } 168 177 else … … 173 182 rc = VINF_SUCCESS; 174 183 175 for (uint32_t iSeg = 0; iSeg < pSgBuf->cSegs; iSeg++)184 while (!RTSgBufIsAtEnd(pSgBuf)) 176 185 { 177 void *pvSeg = pSgBuf->paSegs[iSeg].pvSeg;178 size_t cbSeg = pSgBuf->paSegs[iSeg].cbSeg;186 size_t cbSeg = 0; 187 void const *pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 179 188 180 189 cbWrittenSeg = 0; … … 185 194 if (RT_FAILURE(rc)) 186 195 break; 187 pThis->offFakePos += pcbWritten ? cbWrittenSeg : cbSeg; 196 197 size_t const cbAdv = pcbWritten ? cbWrittenSeg : cbSeg; 198 pThis->offFakePos += cbAdv; 199 RTSgBufAdvance(pSgBuf, cbAdv); 200 188 201 if (pcbWritten) 189 202 { -
trunk/src/VBox/Runtime/common/zip/cpiovfs.cpp
r98103 r100908 484 484 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 485 485 */ 486 static DECLCALLBACK(int) rtZipCpioFssIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)486 static DECLCALLBACK(int) rtZipCpioFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 487 487 { 488 488 PRTZIPCPIOIOSTREAM pThis = (PRTZIPCPIOIOSTREAM)pvThis; … … 518 518 int rc = RTVfsIoStrmReadAt(pThis->hVfsIos, pThis->offStart + off, pSgBuf->paSegs[0].pvSeg, cbToRead, fBlocking, pcbRead); 519 519 pThis->offFile = off + *pcbRead; 520 RTSgBufAdvance(pSgBuf, *pcbRead); 521 520 522 if (pThis->offFile >= pThis->cbFile) 521 523 { … … 532 534 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 533 535 */ 534 static DECLCALLBACK(int) rtZipCpioFssIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)536 static DECLCALLBACK(int) rtZipCpioFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 535 537 { 536 538 /* Cannot write to a read-only I/O stream. */ -
trunk/src/VBox/Runtime/common/zip/gzipvfs.cpp
r98103 r100908 289 289 * @param fBlocking Whether to block or not. 290 290 * @param pcbRead Where to store the number of bytes actually read. 291 */ 292 static int rtZipGzip_ReadOneSeg(PRTZIPGZIPSTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead) 291 * @param pSgBuf The segment buffer descriptor, for advancing. 292 */ 293 static int rtZipGzip_ReadOneSeg(PRTZIPGZIPSTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking, 294 size_t *pcbRead, PRTSGBUF pSgBuf) 293 295 { 294 296 /* … … 324 326 { 325 327 size_t cbReadIn = ~(size_t)0; 328 RTSgBufReset(&pThis->SgBuf); 326 329 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, -1 /*off*/, &pThis->SgBuf, fBlocking, &cbReadIn); 327 330 if (rc != VINF_SUCCESS) … … 375 378 if (pcbRead) 376 379 *pcbRead = cbRead; 380 RTSgBufAdvance(pSgBuf, cbRead); 377 381 378 382 return rc; … … 383 387 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 384 388 */ 385 static DECLCALLBACK(int) rtZipGzip_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)389 static DECLCALLBACK(int) rtZipGzip_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 386 390 { 387 391 PRTZIPGZIPSTREAM pThis = (PRTZIPGZIPSTREAM)pvThis; … … 392 396 AssertReturn(off == -1 || off == pThis->offStream , VERR_INVALID_PARAMETER); 393 397 394 return rtZipGzip_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead );398 return rtZipGzip_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead, pSgBuf); 395 399 } 396 400 … … 517 521 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 518 522 */ 519 static DECLCALLBACK(int) rtZipGzip_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)523 static DECLCALLBACK(int) rtZipGzip_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 520 524 { 521 525 PRTZIPGZIPSTREAM pThis = (PRTZIPGZIPSTREAM)pvThis; … … 554 558 if (pcbWritten) 555 559 *pcbWritten = cbWritten; 560 RTSgBufAdvance(pSgBuf, cbWritten); 556 561 return rc; 557 562 } -
trunk/src/VBox/Runtime/common/zip/lzmavfs.cpp
r98766 r100908 215 215 * @param fBlocking Whether to block or not. 216 216 * @param pcbRead Where to store the number of bytes actually read. 217 */ 218 static int rtZipLzma_ReadOneSeg(PRTZIPLZMASTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking, size_t *pcbRead) 217 * @param pSgBuf The S/G buffer descriptor, for advancing. 218 */ 219 static int rtZipLzma_ReadOneSeg(PRTZIPLZMASTREAM pThis, void *pvBuf, size_t cbToRead, bool fBlocking, 220 size_t *pcbRead, PRTSGBUF pSgBuf) 219 221 { 220 222 /* … … 243 245 { 244 246 size_t cbReadIn = ~(size_t)0; 247 RTSgBufReset(&pThis->SgBuf); 245 248 rc = RTVfsIoStrmSgRead(pThis->hVfsIos, -1 /*off*/, &pThis->SgBuf, fBlocking, &cbReadIn); 246 249 if (rc != VINF_SUCCESS) … … 298 301 if (pcbRead) 299 302 *pcbRead = cbRead; 303 RTSgBufAdvance(pSgBuf, cbRead); 300 304 301 305 return rc; … … 306 310 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 307 311 */ 308 static DECLCALLBACK(int) rtZipLzma_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)312 static DECLCALLBACK(int) rtZipLzma_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 309 313 { 310 314 PRTZIPLZMASTREAM pThis = (PRTZIPLZMASTREAM)pvThis; … … 315 319 AssertReturn(off == -1 || off == pThis->offStream , VERR_INVALID_PARAMETER); 316 320 317 return rtZipLzma_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead );321 return rtZipLzma_ReadOneSeg(pThis, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, fBlocking, pcbRead, pSgBuf); 318 322 } 319 323 … … 440 444 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 441 445 */ 442 static DECLCALLBACK(int) rtZipLzma_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)446 static DECLCALLBACK(int) rtZipLzma_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 443 447 { 444 448 PRTZIPLZMASTREAM pThis = (PRTZIPLZMASTREAM)pvThis; … … 477 481 if (pcbWritten) 478 482 *pcbWritten = cbWritten; 483 RTSgBufAdvance(pSgBuf, cbWritten); 484 479 485 return rc; 480 486 } -
trunk/src/VBox/Runtime/common/zip/pkzip.cpp
r98103 r100908 99 99 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 100 100 */ 101 static DECLCALLBACK(int) memFssIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)101 static DECLCALLBACK(int) memFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 102 102 { 103 103 PMEMIOSTREAM pThis = (PMEMIOSTREAM)pvThis; … … 123 123 if (pcbRead) 124 124 *pcbRead = cbToRead; 125 RTSgBufAdvance(pSgBuf, cbToRead); 125 126 126 127 return VINF_SUCCESS; … … 130 131 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 131 132 */ 132 static DECLCALLBACK(int) memFssIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)133 static DECLCALLBACK(int) memFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 133 134 { 134 135 RT_NOREF_PV(pvThis); RT_NOREF_PV(off); RT_NOREF_PV(pSgBuf); RT_NOREF_PV(fBlocking); RT_NOREF_PV(pcbWritten); -
trunk/src/VBox/Runtime/common/zip/pkzipvfs.cpp
r98103 r100908 907 907 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 908 908 */ 909 static DECLCALLBACK(int) rtZipPkzipFssIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)909 static DECLCALLBACK(int) rtZipPkzipFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 910 910 { 911 911 PRTZIPPKZIPIOSTREAM pThis = (PRTZIPPKZIPIOSTREAM)pvThis; … … 986 986 int rc = RTZipDecompress(pThis->pZip, pSgBuf->paSegs[0].pvSeg, cbToRead, pcbRead); 987 987 pThis->offFile = off + *pcbRead; 988 RTSgBufAdvance(pSgBuf, *pcbRead); 989 988 990 if (pThis->offFile >= pThis->cbFile) 989 991 { … … 995 997 } 996 998 997 static DECLCALLBACK(int) rtZipPkzipFssIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)999 static DECLCALLBACK(int) rtZipPkzipFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 998 1000 { 999 1001 RT_NOREF_PV(pvThis); RT_NOREF_PV(off); RT_NOREF_PV(pSgBuf); RT_NOREF_PV(fBlocking); RT_NOREF_PV(pcbWritten); -
trunk/src/VBox/Runtime/common/zip/tarvfs.cpp
r98325 r100908 872 872 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 873 873 */ 874 static DECLCALLBACK(int) rtZipTarFssIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)874 static DECLCALLBACK(int) rtZipTarFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 875 875 { 876 876 PRTZIPTARIOSTREAM pThis = (PRTZIPTARIOSTREAM)pvThis; … … 906 906 int rc = RTVfsIoStrmReadAt(pThis->hVfsIos, pThis->offStart + off, pSgBuf->paSegs[0].pvSeg, cbToRead, fBlocking, pcbRead); 907 907 pThis->offFile = off + *pcbRead; 908 RTSgBufAdvance(pSgBuf, *pcbRead); 909 908 910 if (pThis->offFile >= pThis->cbFile) 909 911 { … … 920 922 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 921 923 */ 922 static DECLCALLBACK(int) rtZipTarFssIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)924 static DECLCALLBACK(int) rtZipTarFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 923 925 { 924 926 /* Cannot write to a read-only I/O stream. */ -
trunk/src/VBox/Runtime/common/zip/tarvfswriter.cpp
r99739 r100908 753 753 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 754 754 */ 755 static DECLCALLBACK(int) rtZipTarWriterPush_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)755 static DECLCALLBACK(int) rtZipTarWriterPush_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 756 756 { 757 757 /* No read support, sorry. */ … … 765 765 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 766 766 */ 767 static DECLCALLBACK(int) rtZipTarWriterPush_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)767 static DECLCALLBACK(int) rtZipTarWriterPush_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 768 768 { 769 769 PRTZIPTARFSSTREAMWRITERPUSH pPush = (PRTZIPTARFSSTREAMWRITERPUSH)pvThis; … … 810 810 if (pcbWritten) 811 811 *pcbWritten = cbWritten; 812 RTSgBufAdvance(pSgBuf, cbWritten); 812 813 } 813 814 } -
trunk/src/VBox/Runtime/common/zip/xarvfs.cpp
r98103 r100908 854 854 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 855 855 */ 856 static DECLCALLBACK(int) rtZipXarFssIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)856 static DECLCALLBACK(int) rtZipXarFssIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 857 857 { 858 858 PRTZIPXARIOSTREAM pThis = (PRTZIPXARIOSTREAM)pvThis; … … 918 918 /* Update the file position. */ 919 919 pThis->offCurPos += cbActuallyRead; 920 RTSgBufAdvance(pSgBuf, cbActuallyRead); 920 921 921 922 /* … … 963 964 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 964 965 */ 965 static DECLCALLBACK(int) rtZipXarFssIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)966 static DECLCALLBACK(int) rtZipXarFssIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 966 967 { 967 968 /* Cannot write to a read-only I/O stream. */ … … 1226 1227 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 1227 1228 */ 1228 static DECLCALLBACK(int) rtZipXarFssDecompIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)1229 static DECLCALLBACK(int) rtZipXarFssDecompIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 1229 1230 { 1230 1231 PRTZIPXARDECOMPIOS pThis = (PRTZIPXARDECOMPIOS)pvThis; … … 1243 1244 * validate off wrt data digest updating. 1244 1245 */ 1245 int rc = RTVfsIoStrmReadAt(pThis->hVfsIosDecompressor, off, pSgBuf->paSegs[0].pvSeg, pSgBuf->paSegs[0].cbSeg, 1246 fBlocking, pcbRead); 1246 size_t cbSeg = 0; 1247 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 1248 int rc = RTVfsIoStrmReadAt(pThis->hVfsIosDecompressor, off, pvSeg, cbSeg, fBlocking, pcbRead); 1247 1249 if (RT_FAILURE(rc)) 1248 1250 return rc; … … 1251 1253 * Hash the data. When reaching the end match against the expected digest. 1252 1254 */ 1253 size_t c bActuallyRead = pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg;1255 size_t const cbActuallyRead = pcbRead ? *pcbRead : cbSeg; 1254 1256 pThis->offCurPos += cbActuallyRead; 1257 RTSgBufAdvance(pSgBuf, cbActuallyRead); 1255 1258 rtZipXarHashUpdate(&pThis->CtxExtracted, pThis->uHashFunExtracted, pSgBuf->paSegs[0].pvSeg, cbActuallyRead); 1259 1256 1260 if (rc == VINF_EOF) 1257 1261 { … … 1295 1299 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 1296 1300 */ 1297 static DECLCALLBACK(int) rtZipXarFssDecompIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)1301 static DECLCALLBACK(int) rtZipXarFssDecompIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 1298 1302 { 1299 1303 /* Cannot write to a read-only I/O stream. */ -
trunk/src/VBox/Storage/VDIfVfs.cpp
r98103 r100908 95 95 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 96 96 */ 97 static DECLCALLBACK(int) vdIfVfsIos_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)97 static DECLCALLBACK(int) vdIfVfsIos_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 98 98 { 99 99 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; 100 100 Assert(pSgBuf->cSegs == 1); NOREF(fBlocking); 101 101 Assert(off >= -1); 102 103 size_t cbSeg = 0; 104 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 102 105 103 106 /* … … 108 111 int rc; 109 112 if (pThis->pVDIfsIo) 110 rc = vdIfIoFileReadSync(pThis->pVDIfsIo, pThis->pStorage, off, p SgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbRead);113 rc = vdIfIoFileReadSync(pThis->pVDIfsIo, pThis->pStorage, off, pvSeg, cbSeg, pcbRead); 111 114 else 112 115 { 113 rc = vdIfIoIntFileReadSync(pThis->pVDIfsIoInt, (PVDIOSTORAGE)pThis->pStorage, off, p SgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg);116 rc = vdIfIoIntFileReadSync(pThis->pVDIfsIoInt, (PVDIOSTORAGE)pThis->pStorage, off, pvSeg, cbSeg); 114 117 if (pcbRead) 115 *pcbRead = RT_SUCCESS(rc) ? pSgBuf->paSegs[0].cbSeg : 0;118 *pcbRead = RT_SUCCESS(rc) ? cbSeg : 0; 116 119 } 117 120 if (RT_SUCCESS(rc)) 118 121 { 119 size_t c bAdvance = pcbRead ? *pcbRead : pSgBuf->paSegs[0].cbSeg;122 size_t const cbAdvance = pcbRead ? *pcbRead : cbSeg; 120 123 pThis->offCurPos = off + cbAdvance; 124 RTSgBufAdvance(pSgBuf, cbAdvance); 121 125 if (pcbRead && !cbAdvance) 122 126 rc = VINF_EOF; … … 129 133 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 130 134 */ 131 static DECLCALLBACK(int) vdIfVfsIos_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)135 static DECLCALLBACK(int) vdIfVfsIos_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 132 136 { 133 137 PVDIFVFSIOSFILE pThis = (PVDIFVFSIOSFILE)pvThis; … … 135 139 Assert(off >= -1); 136 140 141 size_t cbSeg = 0; 142 void const * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 143 137 144 /* 138 * This may end up being a little more complicated, esp. wrt VERR_EOF.145 * Do the writing. 139 146 */ 140 147 if (off == -1) … … 142 149 int rc; 143 150 if (pThis->pVDIfsIo) 144 rc = vdIfIoFileWriteSync(pThis->pVDIfsIo, pThis->pStorage, off, p SgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg, pcbWritten);151 rc = vdIfIoFileWriteSync(pThis->pVDIfsIo, pThis->pStorage, off, pvSeg, cbSeg, pcbWritten); 145 152 else 146 153 { 147 rc = vdIfIoIntFileWriteSync(pThis->pVDIfsIoInt, pThis->pStorage, off, p SgBuf[0].pvSegCur, pSgBuf->paSegs[0].cbSeg);154 rc = vdIfIoIntFileWriteSync(pThis->pVDIfsIoInt, pThis->pStorage, off, pvSeg, cbSeg); 148 155 if (pcbWritten) 149 *pcbWritten = RT_SUCCESS(rc) ? pSgBuf->paSegs[0].cbSeg : 0;156 *pcbWritten = RT_SUCCESS(rc) ? cbSeg : 0; 150 157 } 151 158 if (RT_SUCCESS(rc)) 152 pThis->offCurPos = off + (pcbWritten ? *pcbWritten : pSgBuf->paSegs[0].cbSeg); 159 { 160 size_t const cbAdvance = pcbWritten ? *pcbWritten : cbSeg; 161 pThis->offCurPos = off + cbAdvance; 162 RTSgBufAdvance(pSgBuf, cbAdvance); 163 } 153 164 return rc; 154 165 } -
trunk/src/VBox/Storage/VDVfs.cpp
r98103 r100908 341 341 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnRead} 342 342 */ 343 static DECLCALLBACK(int) vdVfsFile_Read(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead)344 { 345 PVDVFSFILE pThis = (PVDVFSFILE)pvThis;343 static DECLCALLBACK(int) vdVfsFile_Read(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbRead) 344 { 345 PVDVFSFILE const pThis = (PVDVFSFILE)pvThis; 346 346 347 347 Assert(pSgBuf->cSegs == 1); … … 364 364 } 365 365 366 int rc = VINF_SUCCESS; 367 size_t cbLeftToRead = pSgBuf->paSegs[0].cbSeg; 368 if (offUnsigned + cbLeftToRead <= cbImage) 369 { 370 if (pcbRead) 371 *pcbRead = cbLeftToRead; 366 size_t cbSeg = 0; 367 void * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 368 369 int rcRet = VINF_SUCCESS; 370 size_t cbToRead; 371 if (cbSeg <= cbImage - offUnsigned) 372 cbToRead = cbSeg; 373 else if (pcbRead) 374 { 375 cbToRead = (size_t)(cbImage - offUnsigned); 376 rcRet = VINF_EOF; 372 377 } 373 378 else 374 { 375 if (!pcbRead) 376 return VERR_EOF; 377 *pcbRead = cbLeftToRead = (size_t)(cbImage - offUnsigned); 378 rc = VINF_EOF; 379 } 379 return VERR_EOF; 380 380 381 381 /* 382 382 * Ok, we've got a valid stretch within the file. Do the reading. 383 383 */ 384 if (cb LeftToRead > 0)385 { 386 int rc2 = vdReadHelper(pThis->pDisk, offUnsigned, p SgBuf->paSegs[0].pvSeg, cbLeftToRead);384 if (cbToRead > 0) 385 { 386 int rc2 = vdReadHelper(pThis->pDisk, offUnsigned, pvSeg, cbToRead); 387 387 if (RT_SUCCESS(rc2)) 388 offUnsigned += cbLeftToRead; 388 { 389 offUnsigned += cbToRead; 390 RTSgBufAdvance(pSgBuf, cbToRead); 391 } 389 392 else 390 rc = rc2; 393 { 394 cbToRead = 0; 395 rcRet = rc2; 396 } 391 397 } 392 398 393 399 pThis->offCurPos = offUnsigned; 394 return rc; 400 if (pcbRead) 401 *pcbRead = cbToRead; 402 return rcRet; 395 403 } 396 404 … … 399 407 * @interface_method_impl{RTVFSIOSTREAMOPS,pfnWrite} 400 408 */ 401 static DECLCALLBACK(int) vdVfsFile_Write(void *pvThis, RTFOFF off, P CRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten)402 { 403 PVDVFSFILE pThis = (PVDVFSFILE)pvThis;409 static DECLCALLBACK(int) vdVfsFile_Write(void *pvThis, RTFOFF off, PRTSGBUF pSgBuf, bool fBlocking, size_t *pcbWritten) 410 { 411 PVDVFSFILE const pThis = (PVDVFSFILE)pvThis; 404 412 405 413 Assert(pSgBuf->cSegs == 1); … … 422 430 } 423 431 424 size_t cbLeftToWrite; 425 if (offUnsigned + pSgBuf->paSegs[0].cbSeg <= cbImage) 426 { 427 cbLeftToWrite = pSgBuf->paSegs[0].cbSeg; 428 if (pcbWritten) 429 *pcbWritten = cbLeftToWrite; 430 } 432 size_t cbSeg = 0; 433 void const * const pvSeg = RTSgBufGetCurrentSegment(pSgBuf, ~(size_t)0, &cbSeg); 434 435 size_t cbToWrite; 436 if (cbSeg <= cbImage - offUnsigned) 437 cbToWrite = cbSeg; 438 else if (pcbWritten) 439 cbToWrite = (size_t)(cbImage - offUnsigned); 431 440 else 432 { 433 if (!pcbWritten) 434 return VERR_EOF; 435 *pcbWritten = cbLeftToWrite = (size_t)(cbImage - offUnsigned); 436 } 441 return VERR_EOF; 437 442 438 443 /* … … 440 445 */ 441 446 int rc = VINF_SUCCESS; 442 if (cb LeftToWrite > 0)443 { 444 rc = vdWriteHelper(pThis->pDisk, offUnsigned, p SgBuf->paSegs[0].pvSeg, cbLeftToWrite);447 if (cbToWrite > 0) 448 { 449 rc = vdWriteHelper(pThis->pDisk, offUnsigned, pvSeg, cbToWrite); 445 450 if (RT_SUCCESS(rc)) 446 offUnsigned += cbLeftToWrite; 451 { 452 offUnsigned += cbToWrite; 453 RTSgBufAdvance(pSgBuf, cbToWrite); 454 } 455 else 456 cbToWrite = 0; 447 457 } 448 458 449 459 pThis->offCurPos = offUnsigned; 460 if (pcbWritten) 461 *pcbWritten = cbToWrite; 450 462 return rc; 451 463 }
Note:
See TracChangeset
for help on using the changeset viewer.