Changeset 30313 in vbox
- Timestamp:
- Jun 18, 2010 1:20:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VBoxHDD.cpp
r30044 r30313 534 534 */ 535 535 static int vdReadHelper(PVBOXHDD pDisk, PVDIMAGE pImage, PVDIMAGE pImageParentOverride, 536 uint64_t uOffset, void *pvBuf, size_t cbRead )536 uint64_t uOffset, void *pvBuf, size_t cbRead, bool fHandleFreeBlocks) 537 537 { 538 538 int rc; 539 539 size_t cbThisRead; 540 bool fAllFree = true; 541 size_t cbBufClear = 0; 540 542 541 543 /* Loop until all read. */ … … 570 572 if (rc == VERR_VD_BLOCK_FREE) 571 573 { 572 memset(pvBuf, '\0', cbThisRead); 574 /* Fill the free space with 0 if we are told to do so. */ 575 if (fHandleFreeBlocks) 576 memset(pvBuf, '\0', cbThisRead); 577 else 578 cbBufClear += cbThisRead; 579 573 580 rc = VINF_SUCCESS; 581 } 582 else if (RT_SUCCESS(rc)) 583 { 584 /* First not free block, fill the space before with 0. */ 585 if (!fHandleFreeBlocks) 586 { 587 memset((char *)pvBuf - cbBufClear, '\0', cbBufClear); 588 cbBufClear = 0; 589 fAllFree = false; 590 } 574 591 } 575 592 … … 579 596 } while (cbRead != 0 && RT_SUCCESS(rc)); 580 597 581 return rc;598 return (!fHandleFreeBlocks && fAllFree) ? VERR_VD_BLOCK_FREE : rc; 582 599 } 583 600 … … 891 908 PVDPARENTSTATEDESC pParentState = (PVDPARENTSTATEDESC)pvUser; 892 909 return vdReadHelper(pParentState->pDisk, pParentState->pImage, NULL, uOffset, 893 pvBuf, cbRead );910 pvBuf, cbRead, true); 894 911 } 895 912 … … 952 969 { 953 970 rc = vdReadHelper(pDisk, pImage, pImageParentOverride, 954 uOffset - cbPreRead, pvTmp, cbPreRead );971 uOffset - cbPreRead, pvTmp, cbPreRead, true); 955 972 if (RT_FAILURE(rc)) 956 973 return rc; … … 989 1006 uOffset + cbThisWrite + cbWriteCopy, 990 1007 (char *)pvTmp + cbPreRead + cbThisWrite + cbWriteCopy, 991 cbReadImage );1008 cbReadImage, true); 992 1009 if (RT_FAILURE(rc)) 993 1010 return rc; … … 1049 1066 * be modified by the write or not. */ 1050 1067 rc = vdReadHelper(pDisk, pImage, pImageParentOverride, uOffset - cbPreRead, pvTmp, 1051 cbPreRead + cbThisWrite + cbPostRead - cbFill );1068 cbPreRead + cbThisWrite + cbPostRead - cbFill, true); 1052 1069 if (RT_FAILURE(rc)) 1053 1070 return rc; … … 4076 4093 } 4077 4094 4095 /* Whether we can take the optimized copy path (false) or not. 4096 * Don't optimize if the image existed or if it is a child image. */ 4097 bool fRegularRead = (pszFilename == NULL) || (cImagesTo > 0); 4098 4078 4099 /* Copy the data. */ 4079 4100 uint64_t uOffset = 0; … … 4094 4115 4095 4116 rc = vdReadHelper(pDiskFrom, pImageFrom, NULL, uOffset, pvBuf, 4096 cbThisRead );4097 if (RT_FAILURE(rc) )4117 cbThisRead, fRegularRead); 4118 if (RT_FAILURE(rc) && rc != VERR_VD_BLOCK_FREE) 4098 4119 break; 4099 4120 … … 4102 4123 fLockReadFrom = false; 4103 4124 4104 rc2 = vdThreadStartWrite(pDiskTo); 4105 AssertRC(rc2); 4106 fLockWriteTo = true; 4107 4108 rc = vdWriteHelper(pDiskTo, pImageTo, NULL, uOffset, pvBuf, 4109 cbThisRead); 4110 if (RT_FAILURE(rc)) 4111 break; 4112 4113 rc2 = vdThreadFinishWrite(pDiskTo); 4114 AssertRC(rc2); 4115 fLockWriteTo = false; 4125 if (rc != VERR_VD_BLOCK_FREE) 4126 { 4127 rc2 = vdThreadStartWrite(pDiskTo); 4128 AssertRC(rc2); 4129 fLockWriteTo = true; 4130 4131 rc = vdWriteHelper(pDiskTo, pImageTo, NULL, uOffset, pvBuf, 4132 cbThisRead); 4133 if (RT_FAILURE(rc)) 4134 break; 4135 4136 rc2 = vdThreadFinishWrite(pDiskTo); 4137 AssertRC(rc2); 4138 fLockWriteTo = false; 4139 } 4116 4140 4117 4141 uOffset += cbThisRead; … … 4531 4555 AssertPtrBreakStmt(pImage, rc = VERR_VD_NOT_OPENED); 4532 4556 4533 rc = vdReadHelper(pDisk, pImage, NULL, uOffset, pvBuf, cbRead );4557 rc = vdReadHelper(pDisk, pImage, NULL, uOffset, pvBuf, cbRead, true); 4534 4558 } while (0); 4535 4559
Note:
See TracChangeset
for help on using the changeset viewer.