Changeset 13268 in vbox for trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
- Timestamp:
- Oct 14, 2008 3:15:54 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
r12928 r13268 2288 2288 if (pExtent->pFile != NULL) 2289 2289 { 2290 /* Do not delete raw extents, these have full and base names equal. */ 2290 2291 vmdkFileClose(pImage, &pExtent->pFile, 2291 2292 fDelete … … 2428 2429 pExtent->pFile = pFile; 2429 2430 pImage->pFile = NULL; 2430 pExtent->pszFullname = RT StrDup(pImage->pszFilename);2431 pExtent->pszFullname = RTPathAbsDup(pImage->pszFilename); 2431 2432 if (!pExtent->pszFullname) 2432 2433 { … … 3393 3394 pImage->pExtents = NULL; 3394 3395 } 3396 pImage->cExtents = 0; 3395 3397 if (pImage->pFile != NULL) 3396 3398 vmdkFileClose(pImage, &pImage->pFile, fDelete); … … 3956 3958 bool fEmbeddedDesc = false; 3957 3959 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; 3960 3965 unsigned i, line; 3961 3966 VMDKDESCRIPTOR DescriptorCopy; … … 4013 4018 4014 4019 /* 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); 4019 4029 4020 4030 /* --- Up to this point we have not done any damage yet. --- */ … … 4022 4032 /* Save the old name for easy access to the old descriptor file. */ 4023 4033 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. */ 4026 4038 for (i = 0, line = pImage->Descriptor.uFirstExtent; 4027 4039 i < cExtents; 4028 4040 i++, line = pImage->Descriptor.aNextLines[line]) 4029 4041 { 4030 PVMDKEXTENT pExtent = &pImage->pExtents[i];4031 4042 /* Assume that vmdkStrReplace will fail. */ 4032 4043 rc = VERR_NO_MEMORY; 4033 4044 /* Update the descriptor. */ 4034 4045 apszNewLines[i] = vmdkStrReplace(pImage->Descriptor.aLines[line], 4035 pszOldBase name, pszNewBasename);4046 pszOldBaseName, pszNewBaseName); 4036 4047 if (!apszNewLines[i]) 4037 4048 goto rollback; 4038 4049 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]; 4039 4060 /* Compose new name for the extent. */ 4040 4061 apszNewName[i] = vmdkStrReplace(pExtent->pszFullname, 4041 pszOld Basename, pszNewBasename);4062 pszOldFullName, pszNewFullName); 4042 4063 if (!apszNewName[i]) 4043 4064 goto rollback; … … 4051 4072 apszOldName[i] = RTStrDup(pExtent->pszFullname); 4052 4073 } 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. */ 4057 4075 vmdkFreeImage(pImage, false); 4058 4076 … … 4062 4080 * storing descriptor's names. 4063 4081 */ 4064 apszNewName[cExtents] = RT PathFilename(pszFilename);4082 apszNewName[cExtents] = RTStrDup(pszFilename); 4065 4083 /* Rename the descriptor file if it's separate. */ 4066 4084 if (!fEmbeddedDesc) … … 4094 4112 vmdkFreeImage(pImage, false); 4095 4113 } 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++) 4098 4116 { 4099 4117 if (apszOldName[i]) … … 4101 4119 rrc = RTFileMove(apszNewName[i], apszOldName[i], 0); 4102 4120 AssertRC(rrc); 4103 RTStrFree(apszOldName[i]);4104 4121 } 4105 if (apszNewName[i])4106 RTStrFree(apszNewName[i]);4107 if (apszNewLines[i])4108 RTStrFree(apszNewLines[i]);4109 4122 } 4110 4123 /* Restore the old descriptor. */ … … 4123 4136 vmdkWriteDescriptor(pImage); 4124 4137 vmdkFileClose(pImage, &pFile, false); 4125 RTStrFree(pszOldDescName); 4138 /* Get rid of the stuff we implanted. */ 4139 pImage->pExtents = NULL; 4140 pImage->pFile = NULL; 4126 4141 /* Re-open the image back. */ 4142 pImage->pszFilename = pszOldImageName; 4127 4143 rrc = vmdkOpenImage(pImage, pImage->uOpenFlags); 4128 4144 AssertRC(rrc); … … 4134 4150 RTStrFree(DescriptorCopy.aLines[i]); 4135 4151 if (apszOldName) 4152 { 4153 for (i = 0; i <= cExtents; i++) 4154 if (apszOldName[i]) 4155 RTStrFree(apszOldName[i]); 4136 4156 RTMemTmpFree(apszOldName); 4157 } 4137 4158 if (apszNewName) 4159 { 4160 for (i = 0; i <= cExtents; i++) 4161 if (apszNewName[i]) 4162 RTStrFree(apszNewName[i]); 4138 4163 RTMemTmpFree(apszNewName); 4164 } 4139 4165 if (apszNewLines) 4166 { 4167 for (i = 0; i < cExtents; i++) 4168 if (apszNewLines[i]) 4169 RTStrFree(apszNewLines[i]); 4140 4170 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); 4141 4182 LogFlowFunc(("returns %Rrc\n", rc)); 4142 4183 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.