Changeset 103524 in vbox
- Timestamp:
- Feb 22, 2024 11:17:44 AM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Storage/VDI.cpp
r103501 r103524 1635 1635 1636 1636 /* Clip read range to at most the rest of the block. */ 1637 cbToRead = RT_MIN(cbToRead, getImageBlockSize(&pImage->Header) - offRead); 1637 size_t cbBlockRem = getImageBlockSize(&pImage->Header) - offRead; 1638 cbToRead = RT_MIN(cbToRead, cbBlockRem); 1638 1639 Assert(!(cbToRead % 512)); 1639 1640 … … 1645 1646 1646 1647 cbSet = vdIfIoIntIoCtxSet(pImage->pIfIo, pIoCtx, 0, cbToRead); 1647 Assert(cbSet == cbToRead); 1648 Assert(cbSet == cbToRead); RT_NOREF(cbSet); 1648 1649 } 1649 1650 else … … 1700 1701 1701 1702 /* Clip write range to at most the rest of the block. */ 1702 cbToWrite = RT_MIN(cbToWrite, getImageBlockSize(&pImage->Header) - offWrite); 1703 size_t cbBlockRem = getImageBlockSize(&pImage->Header) - offWrite; 1704 cbToWrite = RT_MIN(cbToWrite, cbBlockRem); 1703 1705 Assert(!(cbToWrite % 512)); 1704 1706 … … 1988 1990 PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData; 1989 1991 int rc; 1990 const char *pszFilename;1991 1992 1992 1993 /* Image must be opened and the new flags must be valid. */ … … 1999 2000 { 2000 2001 /* Implement this operation via reopening the image. */ 2001 pszFilename = pImage->pszFilename;2002 2002 rc = vdiFreeImage(pImage, false); 2003 2003 if (RT_SUCCESS(rc)) … … 2503 2503 rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, u64Offset, 2504 2504 pvTmp, cbBlock); 2505 if (RT_FAILURE(rc)) 2506 break; 2507 2505 2508 u64Offset = (uint64_t)i * pImage->cbTotalBlockData 2506 2509 + (pImage->offStartData + pImage->offStartBlockData); 2507 2510 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, u64Offset, 2508 2511 pvTmp, cbBlock); 2512 if (RT_FAILURE(rc)) 2513 break; 2514 2509 2515 pImage->paBlocks[uBlockData] = i; 2510 2516 setImageBlocksAllocated(&pImage->Header, cBlocksAllocated - cBlocksMoved); … … 2581 2587 { 2582 2588 unsigned cBlocksAllocated = getImageBlocksAllocated(&pImage->Header); /** < Blocks currently allocated, doesn't change during resize */ 2583 unsigned const cbBlock = RT_MAX(getImageBlockSize(&pImage->Header), 1);2589 unsigned const cbBlock = getImageBlockSize(&pImage->Header); 2584 2590 uint32_t cBlocksNew = cbSize / cbBlock; /** < New number of blocks in the image after the resize */ 2585 2591 if (cbSize % cbBlock) … … 2720 2726 for (unsigned idxBlock = cBlocksOld; idxBlock < cBlocksNew; idxBlock++) 2721 2727 pImage->paBlocks[idxBlock] = VDI_IMAGE_BLOCK_FREE; 2728 2729 /* Write the block array before updating the rest. */ 2730 vdiConvBlocksEndianess(VDIECONV_H2F, pImage->paBlocks, cBlocksNew); 2731 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, pImage->offStartBlocks, 2732 pImage->paBlocks, cbBlockspaceNew); 2733 vdiConvBlocksEndianess(VDIECONV_F2H, pImage->paBlocks, cBlocksNew); 2734 2735 if (RT_SUCCESS(rc)) 2736 { 2737 /* Update size and new block count. */ 2738 setImageDiskSize(&pImage->Header, cbSize); 2739 setImageBlocks(&pImage->Header, cBlocksNew); 2740 /* Update geometry. */ 2741 pImage->PCHSGeometry = *pPCHSGeometry; 2742 pImage->cbImage = cbSize; 2743 2744 PVDIDISKGEOMETRY pGeometry = getImageLCHSGeometry(&pImage->Header); 2745 if (pGeometry) 2746 { 2747 pGeometry->cCylinders = pLCHSGeometry->cCylinders; 2748 pGeometry->cHeads = pLCHSGeometry->cHeads; 2749 pGeometry->cSectors = pLCHSGeometry->cSectors; 2750 pGeometry->cbSector = VDI_GEOMETRY_SECTOR_SIZE; 2751 } 2752 } 2722 2753 } 2723 2754 else 2724 2755 rc = VERR_NO_MEMORY; 2725 2726 /* Write the block array before updating the rest. */2727 vdiConvBlocksEndianess(VDIECONV_H2F, pImage->paBlocks, cBlocksNew);2728 rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, pImage->offStartBlocks,2729 pImage->paBlocks, cbBlockspaceNew);2730 vdiConvBlocksEndianess(VDIECONV_F2H, pImage->paBlocks, cBlocksNew);2731 2732 if (RT_SUCCESS(rc))2733 {2734 /* Update size and new block count. */2735 setImageDiskSize(&pImage->Header, cbSize);2736 setImageBlocks(&pImage->Header, cBlocksNew);2737 /* Update geometry. */2738 pImage->PCHSGeometry = *pPCHSGeometry;2739 pImage->cbImage = cbSize;2740 2741 PVDIDISKGEOMETRY pGeometry = getImageLCHSGeometry(&pImage->Header);2742 if (pGeometry)2743 {2744 pGeometry->cCylinders = pLCHSGeometry->cCylinders;2745 pGeometry->cHeads = pLCHSGeometry->cHeads;2746 pGeometry->cSectors = pLCHSGeometry->cSectors;2747 pGeometry->cbSector = VDI_GEOMETRY_SECTOR_SIZE;2748 }2749 }2750 2756 } 2751 2757 … … 2802 2808 2803 2809 /* Clip range to at most the rest of the block. */ 2804 cbDiscard = RT_MIN(cbDiscard, getImageBlockSize(&pImage->Header) - offDiscard); 2810 size_t cbBlockRem = getImageBlockSize(&pImage->Header) - offDiscard; 2811 cbDiscard = RT_MIN(cbDiscard, cbBlockRem); 2805 2812 Assert(!(cbDiscard % 512)); 2806 2813 … … 2813 2820 if (IS_VDI_IMAGE_BLOCK_ALLOCATED(pImage->paBlocks[uBlock])) 2814 2821 { 2815 unsigned const cbBlock = RT_MAX(getImageBlockSize(&pImage->Header), 1);2822 unsigned const cbBlock = getImageBlockSize(&pImage->Header); 2816 2823 size_t const cbPreAllocated = offDiscard % cbBlock; 2817 2824 size_t const cbPostAllocated = getImageBlockSize(&pImage->Header) - cbDiscard - cbPreAllocated;
Note:
See TracChangeset
for help on using the changeset viewer.