VirtualBox

Changeset 103524 in vbox


Ignore:
Timestamp:
Feb 22, 2024 11:17:44 AM (11 months ago)
Author:
vboxsync
Message:

Storage/VDI.cpp: Some unused variable and macro double expansion fixes, bugref:3409

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Storage/VDI.cpp

    r103501 r103524  
    16351635
    16361636    /* 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);
    16381639    Assert(!(cbToRead % 512));
    16391640
     
    16451646
    16461647        cbSet = vdIfIoIntIoCtxSet(pImage->pIfIo, pIoCtx, 0, cbToRead);
    1647         Assert(cbSet == cbToRead);
     1648        Assert(cbSet == cbToRead); RT_NOREF(cbSet);
    16481649    }
    16491650    else
     
    17001701
    17011702        /* 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);
    17031705        Assert(!(cbToWrite % 512));
    17041706
     
    19881990    PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;
    19891991    int rc;
    1990     const char *pszFilename;
    19911992
    19921993    /* Image must be opened and the new flags must be valid. */
     
    19992000    {
    20002001        /* Implement this operation via reopening the image. */
    2001         pszFilename = pImage->pszFilename;
    20022002        rc = vdiFreeImage(pImage, false);
    20032003        if (RT_SUCCESS(rc))
     
    25032503                rc = vdIfIoIntFileReadSync(pImage->pIfIo, pImage->pStorage, u64Offset,
    25042504                                           pvTmp, cbBlock);
     2505                if (RT_FAILURE(rc))
     2506                    break;
     2507
    25052508                u64Offset = (uint64_t)i * pImage->cbTotalBlockData
    25062509                          + (pImage->offStartData + pImage->offStartBlockData);
    25072510                rc = vdIfIoIntFileWriteSync(pImage->pIfIo, pImage->pStorage, u64Offset,
    25082511                                            pvTmp, cbBlock);
     2512                if (RT_FAILURE(rc))
     2513                    break;
     2514
    25092515                pImage->paBlocks[uBlockData] = i;
    25102516                setImageBlocksAllocated(&pImage->Header, cBlocksAllocated - cBlocksMoved);
     
    25812587    {
    25822588        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);
    25842590        uint32_t cBlocksNew = cbSize / cbBlock;                               /** < New number of blocks in the image after the resize */
    25852591        if (cbSize % cbBlock)
     
    27202726                for (unsigned idxBlock = cBlocksOld; idxBlock < cBlocksNew; idxBlock++)
    27212727                    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                }
    27222753            }
    27232754            else
    27242755                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             }
    27502756        }
    27512757
     
    28022808
    28032809        /* 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);
    28052812        Assert(!(cbDiscard % 512));
    28062813
     
    28132820        if (IS_VDI_IMAGE_BLOCK_ALLOCATED(pImage->paBlocks[uBlock]))
    28142821        {
    2815             unsigned const cbBlock = RT_MAX(getImageBlockSize(&pImage->Header), 1);
     2822            unsigned const cbBlock = getImageBlockSize(&pImage->Header);
    28162823            size_t const cbPreAllocated = offDiscard % cbBlock;
    28172824            size_t const cbPostAllocated = getImageBlockSize(&pImage->Header) - cbDiscard - cbPreAllocated;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette