Changeset 100908 in vbox for trunk/src/VBox/Storage
- Timestamp:
- Aug 19, 2023 2:57:05 AM (18 months ago)
- svn:sync-xref-src-repo-rev:
- 158845
- Location:
- trunk/src/VBox/Storage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.