Changeset 7900 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Apr 11, 2008 8:13:26 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp
r7824 r7900 343 343 { 344 344 /* generate new last-modified uuid */ 345 if (!(pDisk->uModified |VD_IMAGE_MODIFIED_DISABLE_UUID_UPDATE))345 if (!(pDisk->uModified & VD_IMAGE_MODIFIED_DISABLE_UUID_UPDATE)) 346 346 { 347 347 RTUUID Uuid; … … 453 453 /** 454 454 * internal: write a complete block (only used for diff images), taking the 455 * remaining data from parent images. This implementation optimize dout writes455 * remaining data from parent images. This implementation optimizes out writes 456 456 * that do not change the data relative to the state as of the parent images. 457 457 * All backends which support differential/growing images support this. … … 538 538 { 539 539 int rc; 540 unsigned fWrite; 540 541 size_t cbThisWrite; 541 542 size_t cbPreRead, cbPostRead; … … 546 547 /* Try to write the possibly partial block to the last opened image. 547 548 * This works when the block is already allocated in this image or 548 * if it is a full-block write, which automatically allocates a new 549 * block if needed. */ 549 * if it is a full-block write (and allocation isn't suppressed below). 550 * For image formats which don't support zero blocks, it's beneficial 551 * to avoid unnecessarily allocating unchanged blocks. This prevents 552 * unwanted expanding of images. VMDK is an example. */ 550 553 cbThisWrite = cbWrite; 554 fWrite = (pImage->uOpenFlags & VD_OPEN_FLAGS_HONOR_SAME) 555 ? 0 : VD_WRITE_NO_ALLOC; 551 556 rc = pImage->Backend->pfnWrite(pImage->pvBackendData, uOffset, pvBuf, 552 557 cbThisWrite, &cbThisWrite, &cbPreRead, 553 &cbPostRead, 0);558 &cbPostRead, fWrite); 554 559 if (rc == VERR_VDI_BLOCK_FREE) 555 560 { … … 830 835 * VINF_SUCCESS if a plugin was found. 831 836 * ppszFormat contains the string which can be used as backend name. 832 * VERR_NOT_SUPPORTED if no pluginwas found.837 * VERR_NOT_SUPPORTED if no backend was found. 833 838 * @param pszFilename Name of the image file for which the backend is queried. 834 839 * @param ppszFormat Receives pointer of the UTF-8 string which contains the format name. … … 873 878 } 874 879 } 880 if (fPluginFound) 881 break; 875 882 876 883 /* Then check if plugin backends support this file format. */ … … 978 985 break; 979 986 } 987 if (rc == VERR_NO_MORE_FILES) 988 rc = VERR_NOT_SUPPORTED; 989 980 990 RTStrFree(pszPluginFilter); 981 991 if (pPluginDirEntry) … … 1103 1113 } 1104 1114 1115 /* Force sane optimization settings. It's not worth avoiding writes 1116 * to fixed size images. The overhead would have almost no payback. */ 1117 if (enmImageType == VD_IMAGE_TYPE_FIXED) 1118 pImage->uOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME; 1119 1105 1120 /** @todo optionally check UUIDs */ 1106 1121 … … 1160 1175 /* Image successfully opened, make it the last image. */ 1161 1176 vdAddImageToList(pDisk, pImage); 1177 if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY)) 1178 pDisk->uModified = VD_IMAGE_MODIFIED_FIRST; 1162 1179 } 1163 1180 else … … 1296 1313 } 1297 1314 1315 pImage->uOpenFlags = uOpenFlags & VD_OPEN_FLAGS_HONOR_SAME; 1298 1316 rc = pImage->Backend->pfnCreate(pImage->pszFilename, enmType, cbSize, 1299 1317 uImageFlags, pszComment, pPCHSGeometry, 1300 pLCHSGeometry, uOpenFlags, pfnProgress, 1301 pvUser, 0, 99, pDisk->pfnError, 1302 pDisk->pvErrorUser, 1318 pLCHSGeometry, 1319 uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME, 1320 pfnProgress, pvUser, 0, 99, 1321 pDisk->pfnError, pDisk->pvErrorUser, 1303 1322 &pImage->pvBackendData); 1304 1323 1305 1324 if (VBOX_SUCCESS(rc)) 1306 1325 { 1326 /* Force sane optimization settings. It's not worth avoiding writes 1327 * to fixed size images. The overhead would have almost no payback. */ 1328 if (enmType == VD_IMAGE_TYPE_FIXED) 1329 pImage->uOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME; 1330 1307 1331 /** @todo optionally check UUIDs */ 1308 1332 … … 1351 1375 /* Image successfully opened, make it the last image. */ 1352 1376 vdAddImageToList(pDisk, pImage); 1377 if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY)) 1378 pDisk->uModified = VD_IMAGE_MODIFIED_FIRST; 1353 1379 } 1354 1380 else … … 1456 1482 } 1457 1483 1484 pImage->uOpenFlags = uOpenFlags & VD_OPEN_FLAGS_HONOR_SAME; 1458 1485 rc = pImage->Backend->pfnCreate(pImage->pszFilename, 1459 1486 VD_IMAGE_TYPE_NORMAL, pDisk->cbSize, 1460 1487 uImageFlags, pszComment, 1461 1488 &pDisk->PCHSGeometry, 1462 &pDisk->LCHSGeometry, uOpenFlags, 1489 &pDisk->LCHSGeometry, 1490 uOpenFlags & ~VD_OPEN_FLAGS_HONOR_SAME, 1463 1491 pfnProgress, pvUser, 0, 99, 1464 1492 pDisk->pfnError, pDisk->pvErrorUser, 1465 1493 &pImage->pvBackendData); 1466 1494 1495 if (VBOX_SUCCESS(rc) && pDisk->cImages != 0) 1496 { 1497 /* Switch previous image to read-only mode. */ 1498 unsigned uOpenFlagsPrevImg; 1499 uOpenFlagsPrevImg = pDisk->pLast->Backend->pfnGetOpenFlags(pDisk->pLast->pvBackendData); 1500 if (!(uOpenFlagsPrevImg & VD_OPEN_FLAGS_READONLY)) 1501 { 1502 uOpenFlagsPrevImg |= VD_OPEN_FLAGS_READONLY; 1503 rc = pDisk->pLast->Backend->pfnSetOpenFlags(pDisk->pLast->pvBackendData, uOpenFlagsPrevImg); 1504 } 1505 } 1506 1507 if (VBOX_SUCCESS(rc)) 1508 { 1509 RTUUID Uuid; 1510 int rc2; 1511 1512 rc2 = pDisk->pLast->Backend->pfnGetUuid(pDisk->pLast->pvBackendData, 1513 &Uuid); 1514 if (VBOX_SUCCESS(rc2)) 1515 pImage->Backend->pfnSetParentUuid(pImage->pvBackendData, &Uuid); 1516 rc2 = pDisk->pLast->Backend->pfnGetModificationUuid(pDisk->pLast->pvBackendData, 1517 &Uuid); 1518 if (VBOX_SUCCESS(rc2)) 1519 pImage->Backend->pfnSetParentModificationUuid(pImage->pvBackendData, 1520 &Uuid); 1521 } 1522 1467 1523 if (VBOX_SUCCESS(rc)) 1468 1524 { … … 1474 1530 /* Image successfully opened, make it the last image. */ 1475 1531 vdAddImageToList(pDisk, pImage); 1532 if (!(uOpenFlags & VD_OPEN_FLAGS_READONLY)) 1533 pDisk->uModified = VD_IMAGE_MODIFIED_FIRST; 1476 1534 } 1477 1535 else … … 1543 1601 AssertBreak(pImageFrom != pImageTo, rc = VERR_INVALID_PARAMETER); 1544 1602 1545 /* Check ifdestination image is writable. */1603 /* Make sure destination image is writable. */ 1546 1604 unsigned uOpenFlags = pImageTo->Backend->pfnGetOpenFlags(pImageTo->pvBackendData); 1547 1605 if (uOpenFlags & VD_OPEN_FLAGS_READONLY) 1548 1606 { 1549 rc = VERR_VDI_IMAGE_READ_ONLY; 1550 break; 1607 uOpenFlags &= ~VD_OPEN_FLAGS_READONLY; 1608 rc = pImageTo->Backend->pfnSetOpenFlags(pImageTo->pvBackendData, 1609 uOpenFlags); 1610 if (VBOX_FAILURE(rc)) 1611 break; 1551 1612 } 1552 1613 … … 1581 1642 uOffset, pvBuf, cbThisRead, 1582 1643 &cbThisRead); 1583 if (VBOX_FAILURE(rc))1584 break;1585 1644 if (rc == VERR_VDI_BLOCK_FREE) 1586 1645 { … … 1598 1657 &cbThisRead); 1599 1658 } 1600 if (VBOX_FAILURE(rc))1601 break;1602 1659 1603 1660 if (rc != VERR_VDI_BLOCK_FREE) 1604 1661 { 1662 if (VBOX_FAILURE(rc)) 1663 break; 1605 1664 rc = vdWriteHelper(pDisk, pImageTo, uOffset, pvBuf, 1606 1665 cbThisRead); … … 1608 1667 break; 1609 1668 } 1669 else 1670 rc = VINF_SUCCESS; 1610 1671 } 1672 else if (VBOX_FAILURE(rc)) 1673 break; 1611 1674 1612 1675 uOffset += cbThisRead; … … 1624 1687 { 1625 1688 size_t cbThisRead = RT_MIN(VD_MERGE_BUFFER_SIZE, cbRemaining); 1689 rc = VERR_VDI_BLOCK_FREE; 1626 1690 /* Search for image with allocated block. Do not attempt to 1627 1691 * read more than the previous reads marked as valid. Otherwise … … 1636 1700 cbThisRead, &cbThisRead); 1637 1701 } 1638 if (VBOX_FAILURE(rc))1639 break;1640 1702 1641 1703 if (rc != VERR_VDI_BLOCK_FREE) 1642 1704 { 1705 if (VBOX_FAILURE(rc)) 1706 break; 1643 1707 rc = vdWriteHelper(pDisk, pImageTo, uOffset, pvBuf, 1644 1708 cbThisRead); … … 1646 1710 break; 1647 1711 } 1712 else 1713 rc = VINF_SUCCESS; 1648 1714 1649 1715 uOffset += cbThisRead; … … 1679 1745 AssertRC(rc); 1680 1746 } 1747 } 1748 1749 /* Make sure destination image is back to read only if necessary. */ 1750 if (pImageTo != pDisk->pLast && pImageFrom != pDisk->pLast) 1751 { 1752 uOpenFlags = pImageTo->Backend->pfnGetOpenFlags(pImageTo->pvBackendData); 1753 uOpenFlags |= VD_OPEN_FLAGS_READONLY; 1754 rc = pImageTo->Backend->pfnSetOpenFlags(pImageTo->pvBackendData, 1755 uOpenFlags); 1756 if (VBOX_FAILURE(rc)) 1757 break; 1681 1758 } 1682 1759 … … 3185 3262 { 3186 3263 RTLogPrintf("Dumping VD image \"%s\" (Backend=%s)\n", 3187 pImage-> Backend->pszBackendName, pImage->pszFilename);3264 pImage->pszFilename, pImage->Backend->pszBackendName); 3188 3265 pImage->Backend->pfnDump(pImage->pvBackendData); 3189 3266 }
Note:
See TracChangeset
for help on using the changeset viewer.