VirtualBox

Ignore:
Timestamp:
Oct 14, 2008 3:15:54 PM (16 years ago)
Author:
vboxsync
Message:

#3230: First bunch of integrated VMDK backend fixes by xVM Server team. Fixes vmdk renaming issues, test cases included.

File:
1 edited

Legend:

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

    r12928 r13268  
    22882288    if (pExtent->pFile != NULL)
    22892289    {
     2290        /* Do not delete raw extents, these have full and base names equal. */
    22902291        vmdkFileClose(pImage, &pExtent->pFile,
    22912292                         fDelete
     
    24282429        pExtent->pFile = pFile;
    24292430        pImage->pFile = NULL;
    2430         pExtent->pszFullname = RTStrDup(pImage->pszFilename);
     2431        pExtent->pszFullname = RTPathAbsDup(pImage->pszFilename);
    24312432        if (!pExtent->pszFullname)
    24322433        {
     
    33933394        pImage->pExtents = NULL;
    33943395    }
     3396    pImage->cExtents = 0;
    33953397    if (pImage->pFile != NULL)
    33963398        vmdkFileClose(pImage, &pImage->pFile, fDelete);
     
    39563958    bool   fEmbeddedDesc = false;
    39573959    unsigned    cExtents = pImage->cExtents;
    3958     char *pszNewBasename;
    3959     char *pszOldBasename;
     3960    char *pszNewBaseName = NULL;
     3961    char *pszOldBaseName = NULL;
     3962    char *pszNewFullName = NULL;
     3963    char *pszOldFullName = NULL;
     3964    const char *pszOldImageName;
    39603965    unsigned i, line;
    39613966    VMDKDESCRIPTOR DescriptorCopy;
     
    40134018
    40144019    /* Prepare both old and new base names used for string replacement. */
    4015     pszNewBasename = RTStrDup(RTPathFilename(pszFilename));
    4016     RTPathStripExt(pszNewBasename);
    4017     pszOldBasename = RTStrDup(RTPathFilename(pImage->pszFilename));
    4018     RTPathStripExt(pszOldBasename);
     4020    pszNewBaseName = RTStrDup(RTPathFilename(pszFilename));
     4021    RTPathStripExt(pszNewBaseName);
     4022    pszOldBaseName = RTStrDup(RTPathFilename(pImage->pszFilename));
     4023    RTPathStripExt(pszOldBaseName);
     4024    /* Prepare both old and new full names used for string replacement. */
     4025    pszNewFullName = RTStrDup(pszFilename);
     4026    RTPathStripExt(pszNewFullName);
     4027    pszOldFullName = RTStrDup(pImage->pszFilename);
     4028    RTPathStripExt(pszOldFullName);
    40194029
    40204030    /* --- Up to this point we have not done any damage yet. --- */
     
    40224032    /* Save the old name for easy access to the old descriptor file. */
    40234033    pszOldDescName = RTStrDup(pImage->pszFilename);
    4024 
    4025     /* Rename the extents. */
     4034    /* Save old image name. */
     4035    pszOldImageName = pImage->pszFilename;
     4036
     4037    /* Update the descriptor with modified extent names. */
    40264038    for (i = 0, line = pImage->Descriptor.uFirstExtent;
    40274039        i < cExtents;
    40284040        i++, line = pImage->Descriptor.aNextLines[line])
    40294041    {
    4030         PVMDKEXTENT pExtent = &pImage->pExtents[i];
    40314042        /* Assume that vmdkStrReplace will fail. */
    40324043        rc = VERR_NO_MEMORY;
    40334044        /* Update the descriptor. */
    40344045        apszNewLines[i] = vmdkStrReplace(pImage->Descriptor.aLines[line],
    4035             pszOldBasename, pszNewBasename);
     4046            pszOldBaseName, pszNewBaseName);
    40364047        if (!apszNewLines[i])
    40374048            goto rollback;
    40384049        pImage->Descriptor.aLines[line] = apszNewLines[i];
     4050    }
     4051    /* Make sure the descriptor gets written back. */
     4052    pImage->Descriptor.fDirty = true;
     4053    /* Flush the descriptor now, in case it is embedded. */
     4054    vmdkFlushImage(pImage);
     4055
     4056    /* Close and rename/move extents. */
     4057    for (i = 0; i < cExtents; i++)
     4058    {
     4059        PVMDKEXTENT pExtent = &pImage->pExtents[i];
    40394060        /* Compose new name for the extent. */
    40404061        apszNewName[i] = vmdkStrReplace(pExtent->pszFullname,
    4041             pszOldBasename, pszNewBasename);
     4062            pszOldFullName, pszNewFullName);
    40424063        if (!apszNewName[i])
    40434064            goto rollback;
     
    40514072        apszOldName[i] = RTStrDup(pExtent->pszFullname);
    40524073    }
    4053 
    4054     /* Make sure the descriptor gets written back. */
    4055     pImage->Descriptor.fDirty = true;
    4056     /* Release all old stuff and write back the descriptor. */
     4074    /* Release all old stuff. */
    40574075    vmdkFreeImage(pImage, false);
    40584076
     
    40624080     * storing descriptor's names.
    40634081     */
    4064     apszNewName[cExtents] = RTPathFilename(pszFilename);
     4082    apszNewName[cExtents] = RTStrDup(pszFilename);
    40654083    /* Rename the descriptor file if it's separate. */
    40664084    if (!fEmbeddedDesc)
     
    40944112            vmdkFreeImage(pImage, false);
    40954113        }
    4096         /* Rename files back and free the memory. */
    4097         for (i = 0; i < cExtents + 1; i++)
     4114        /* Rename files back. */
     4115        for (i = 0; i <= cExtents; i++)
    40984116        {
    40994117            if (apszOldName[i])
     
    41014119                rrc = RTFileMove(apszNewName[i], apszOldName[i], 0);
    41024120                AssertRC(rrc);
    4103                 RTStrFree(apszOldName[i]);
    41044121            }
    4105             if (apszNewName[i])
    4106                 RTStrFree(apszNewName[i]);
    4107             if (apszNewLines[i])
    4108                 RTStrFree(apszNewLines[i]);
    41094122        }
    41104123        /* Restore the old descriptor. */
     
    41234136        vmdkWriteDescriptor(pImage);
    41244137        vmdkFileClose(pImage, &pFile, false);
    4125         RTStrFree(pszOldDescName);
     4138        /* Get rid of the stuff we implanted. */
     4139        pImage->pExtents = NULL;
     4140        pImage->pFile = NULL;
    41264141        /* Re-open the image back. */
     4142        pImage->pszFilename = pszOldImageName;
    41274143        rrc = vmdkOpenImage(pImage, pImage->uOpenFlags);
    41284144        AssertRC(rrc);
     
    41344150            RTStrFree(DescriptorCopy.aLines[i]);
    41354151    if (apszOldName)
     4152    {
     4153        for (i = 0; i <= cExtents; i++)
     4154            if (apszOldName[i])
     4155                RTStrFree(apszOldName[i]);
    41364156        RTMemTmpFree(apszOldName);
     4157    }
    41374158    if (apszNewName)
     4159    {
     4160        for (i = 0; i <= cExtents; i++)
     4161            if (apszNewName[i])
     4162                RTStrFree(apszNewName[i]);
    41384163        RTMemTmpFree(apszNewName);
     4164    }
    41394165    if (apszNewLines)
     4166    {
     4167        for (i = 0; i < cExtents; i++)
     4168            if (apszNewLines[i])
     4169                RTStrFree(apszNewLines[i]);
    41404170        RTMemTmpFree(apszNewLines);
     4171    }
     4172    if (pszOldDescName)
     4173        RTStrFree(pszOldDescName);
     4174    if (pszOldBaseName)
     4175        RTStrFree(pszOldBaseName);
     4176    if (pszNewBaseName)
     4177        RTStrFree(pszNewBaseName);
     4178    if (pszOldFullName)
     4179        RTStrFree(pszOldFullName);
     4180    if (pszNewFullName)
     4181        RTStrFree(pszNewFullName);
    41414182    LogFlowFunc(("returns %Rrc\n", rc));
    41424183    return rc;
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