VirtualBox

Changeset 32610 in vbox


Ignore:
Timestamp:
Sep 17, 2010 2:58:23 PM (14 years ago)
Author:
vboxsync
Message:

Storage/VMDK: some fixes to get the special streamOptimized header 100% right

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp

    r32598 r32610  
    14191419    }
    14201420    pExtent->pGD = pGD;
    1421     pRGD = (uint32_t *)RTMemAllocZ(cbGD);
    1422     if (!pRGD)
    1423     {
    1424         rc = VERR_NO_MEMORY;
    1425         goto out;
    1426     }
    1427     pExtent->pRGD = pRGD;
     1421    if (!(pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED))
     1422    {
     1423        pRGD = (uint32_t *)RTMemAllocZ(cbGD);
     1424        if (!pRGD)
     1425        {
     1426            rc = VERR_NO_MEMORY;
     1427            goto out;
     1428        }
     1429        pExtent->pRGD = pRGD;
     1430    }
     1431    else
     1432        pExtent->pRGD = NULL;
    14281433
    14291434    if (uStartSector != VMDK_GD_AT_END)
    14301435    {
    1431         cbOverhead = RT_ALIGN_64(VMDK_SECTOR2BYTE(uStartSector) + 2 * (cbGDRounded + cbGTRounded), VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));
    1432         /* For streamOptimized extents put the end-of-stream marker at the end. */
     1436        cbOverhead = VMDK_SECTOR2BYTE(uStartSector) + cbGDRounded + cbGTRounded;
     1437        /* For streamOptimized extents there is only one grain directory,
     1438         * and for all others take redundant grain directory into account. */
    14331439        if (pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED)
    1434             rc = vmdkFileSetSize(pImage, pExtent->pFile, cbOverhead + 512);
     1440        {
     1441            cbOverhead = RT_ALIGN_64(cbOverhead,
     1442                                     VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));
     1443            if (pExtent->fFooter)
     1444                rc = vmdkFileSetSize(pImage, pExtent->pFile, cbOverhead);
     1445            else
     1446                rc = vmdkFileSetSize(pImage, pExtent->pFile, cbOverhead + 512);
     1447        }
    14351448        else
     1449        {
     1450            cbOverhead += cbGDRounded + cbGTRounded;
     1451            cbOverhead = RT_ALIGN_64(cbOverhead,
     1452                                     VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));
    14361453            rc = vmdkFileSetSize(pImage, pExtent->pFile, cbOverhead);
     1454        }
    14371455        if (RT_FAILURE(rc))
    14381456            goto out;
     
    14421460    else
    14431461    {
    1444         cbOverhead =  VMDK_SECTOR2BYTE(uStartSector);
    1445         pExtent->uSectorRGD = uStartSector;
     1462        cbOverhead = 512 + pImage->cbDescAlloc;
    14461463        pExtent->uSectorGD = uStartSector;
    14471464    }
     
    40724089    rc = vmdkFileGetSize(pImage, pExtent->pFile, &uFileOffset);
    40734090    AssertRC(rc);
     4091    /* Align to sector, as the previous write could have been any size. */
    40744092    uFileOffset = RT_ALIGN_64(uFileOffset, 512);
    40754093
     
    43314349
    43324350    pExtent->enmAccess = VMDKACCESS_READONLY;
    4333     pExtent->fUncleanShutdown = true;
     4351    pExtent->fUncleanShutdown = false;
    43344352    pExtent->cNominalSectors = VMDK_BYTE2SECTOR(cbSize);
    43354353    pExtent->uSectorOffset = 0;
     
    44454463        pfnProgress(pvUser, uPercentStart + uPercentSpan * 50 / 100);
    44464464
     4465    /* Now that all descriptor entries are complete, shrink it to the minimum
     4466     * size. It will never be changed afterwards anyway. */
     4467    pExtent->cDescriptorSectors = VMDK_BYTE2SECTOR(RT_ALIGN_64(  pImage->Descriptor.aLines[pImage->Descriptor.cLines]
     4468                                                               - pImage->Descriptor.aLines[0], 512));
    44474469    rc = vmdkWriteMetaSparseExtent(pImage, &pImage->pExtents[0], 0);
    44484470    if (RT_FAILURE(rc))
     
    56375659    /* Always return failure, to avoid opening other VMDK files via this
    56385660     * special VMDK streamOptimized format backend. */
    5639     rc = VERR_VD_VMDK_INVALID_HEADER;
     5661    rc = VERR_NOT_SUPPORTED;
    56405662
    56415663out:
     
    58735895    if (RT_FAILURE(rc))
    58745896        goto out;
    5875     if (uFileOffset % 512)
    5876     {
    5877         rc = VERR_INTERNAL_ERROR;
    5878         goto out;
    5879     }
     5897    /* Align to sector, as the previous write could have been any size. */
     5898    uFileOffset = RT_ALIGN_64(uFileOffset, 512);
    58805899
    58815900    /* Paranoia check: extent type, grain table buffer presence and
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