- Timestamp:
- Oct 4, 2010 12:16:19 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 66364
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
r32882 r32883 538 538 *******************************************************************************/ 539 539 540 static void vmdkFreeGrainDirectory(PVMDKEXTENT pExtent);541 542 540 static void vmdkFreeExtentData(PVMDKIMAGE pImage, PVMDKEXTENT pExtent, 543 541 bool fDelete); … … 999 997 DeflateState.pvCompGrain = pExtent->pvCompGrain; 1000 998 1001 rc = RTZipCompCreate(&pZip, &DeflateState, vmdkFileDeflateHelper, RTZIPTYPE_ZLIB, RTZIPLEVEL_DEFAULT); 999 rc = RTZipCompCreate(&pZip, &DeflateState, vmdkFileDeflateHelper, 1000 RTZIPTYPE_ZLIB, RTZIPLEVEL_DEFAULT); 1002 1001 if (RT_FAILURE(rc)) 1003 1002 return rc; … … 1034 1033 return rc; 1035 1034 1035 /** @todo remove this code */ 1036 1036 /* Set the file size to remove old garbage in case the block is 1037 1037 * rewritten. Cannot cause data loss as the code calling this … … 1167 1167 } 1168 1168 1169 /** 1170 * Internal: free all buffers associated with grain directories. 1171 */ 1172 static void vmdkFreeGrainDirectory(PVMDKEXTENT pExtent) 1173 { 1174 if (pExtent->pGD) 1175 { 1176 RTMemFree(pExtent->pGD); 1177 pExtent->pGD = NULL; 1178 } 1179 if (pExtent->pRGD) 1180 { 1181 RTMemFree(pExtent->pRGD); 1182 pExtent->pRGD = NULL; 1183 } 1184 if (pExtent->pvCompGrain) 1185 { 1186 RTMemFree(pExtent->pvCompGrain); 1187 pExtent->pvCompGrain = NULL; 1188 } 1189 if (pExtent->pvGrain) 1190 { 1191 RTMemFree(pExtent->pvGrain); 1192 pExtent->pvGrain = NULL; 1193 } 1194 } 1195 1196 /** 1197 * Internal: allocate all buffers associated with grain directories. This 1198 * includes the compressed/uncompressed buffers for streamOptimized images. 1199 */ 1200 static int vmdkAllocGrainDirectory(PVMDKIMAGE pImage, PVMDKEXTENT pExtent) 1201 { 1202 size_t cbGD = pExtent->cGDEntries * sizeof(uint32_t); 1203 uint32_t *pGD = NULL, *pRGD = NULL; 1204 1205 pGD = (uint32_t *)RTMemAllocZ(cbGD); 1206 if (!pGD) 1207 { 1208 rc = VERR_NO_MEMORY; 1209 goto out; 1210 } 1211 pExtent->pGD = pGD; 1212 1213 if (pExtent->uSectorRGD) 1214 { 1215 pRGD = (uint32_t *)RTMemAllocZ(cbGD); 1216 if (!pRGD) 1217 { 1218 rc = VERR_NO_MEMORY; 1219 goto out; 1220 } 1221 pExtent->pRGD = pRGD; 1222 } 1223 1224 if (pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED) 1225 { 1226 /* streamOptimized extents need a compressed grain buffer, which must 1227 * be big enough to hold uncompressible data (which needs ~8 bytes 1228 * more than the uncompressed data), the marker and padding. */ 1229 pExtent->cbCompGrain = RT_ALIGN_Z( VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain) 1230 + 8 + sizeof(VMDKMARKER), 512); 1231 pExtent->pvCompGrain = RTMemAlloc(pExtent->cbCompGrain); 1232 if (!pExtent->pvCompGrain) 1233 { 1234 rc = VERR_NO_MEMORY; 1235 goto out; 1236 } 1237 1238 /* streamOptimized extents need a decompressed grain buffer. */ 1239 pExtent->pvGrain = RTMemAlloc(VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain)); 1240 if (!pExtent->pvGrain) 1241 { 1242 rc = VERR_NO_MEMORY; 1243 goto out; 1244 } 1245 } 1246 1247 out: 1248 if (RT_FAILURE(rc)) 1249 vmdkFreeGrainDirectory(pExtent); 1250 return rc; 1251 } 1252 1169 1253 static int vmdkReadGrainDirectory(PVMDKIMAGE pImage, PVMDKEXTENT pExtent) 1170 1254 { 1171 1255 int rc = VINF_SUCCESS; 1172 1256 unsigned i; 1173 uint32_t *pGD = NULL, *pRGD = NULL, *pGDTmp, *pRGDTmp;1257 uint32_t *pGDTmp, *pRGDTmp; 1174 1258 size_t cbGD = pExtent->cGDEntries * sizeof(uint32_t); 1175 1259 … … 1177 1261 goto out; 1178 1262 1179 pGD = (uint32_t *)RTMemAllocZ(cbGD); 1180 if (!pGD) 1181 { 1182 rc = VERR_NO_MEMORY; 1183 goto out; 1184 } 1185 pExtent->pGD = pGD; 1263 rc = vmdkAllocGrainDirectory(pImage, pExtent); 1264 if (RT_FAILED(rc)) 1265 goto out; 1266 1186 1267 /* The VMDK 1.1 spec seems to talk about compressed grain directories, 1187 1268 * but in reality they are not compressed. */ … … 1200 1281 if (pExtent->uSectorRGD) 1201 1282 { 1202 pRGD = (uint32_t *)RTMemAllocZ(cbGD);1203 if (!pRGD)1204 {1205 rc = VERR_NO_MEMORY;1206 goto out;1207 }1208 1283 pExtent->pRGD = pRGD; 1209 1284 /* The VMDK 1.1 spec seems to talk about compressed grain directories, … … 1343 1418 RTMemTmpFree(pTmpGT); 1344 1419 1345 /* streamOptimized extents need a compressed grain buffer, which must1346 * be big enough to hold uncompressible data (which needs ~8 bytes1347 * more than the uncompressed data), the marker and padding. */1348 pExtent->cbCompGrain = RT_ALIGN_Z( VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain)1349 + 8 + sizeof(VMDKMARKER), 512);1350 pExtent->pvCompGrain = RTMemAlloc(pExtent->cbCompGrain);1351 if (!pExtent->pvCompGrain)1352 {1353 rc = VERR_NO_MEMORY;1354 goto out;1355 }1356 1357 /* streamOptimized extents need a decompressed grain buffer. */1358 pExtent->pvGrain = RTMemAlloc(VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));1359 if (!pExtent->pvGrain)1360 {1361 rc = VERR_NO_MEMORY;1362 goto out;1363 }1364 1365 1420 if (uLastGrainSector) 1366 1421 { … … 1394 1449 int rc = VINF_SUCCESS; 1395 1450 unsigned i; 1396 uint32_t *pGD = NULL, *pRGD = NULL;1397 1451 size_t cbGD = pExtent->cGDEntries * sizeof(uint32_t); 1398 1452 size_t cbGDRounded = RT_ALIGN_64(pExtent->cGDEntries * sizeof(uint32_t), 512); … … 1405 1459 cbGTRounded = 0; 1406 1460 1407 pGD = (uint32_t *)RTMemAllocZ(cbGD);1408 if (!pGD)1409 {1410 rc = VERR_NO_MEMORY;1411 goto out;1412 }1413 pExtent->pGD = pGD;1414 if (!(pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED))1415 {1416 pRGD = (uint32_t *)RTMemAllocZ(cbGD);1417 if (!pRGD)1418 {1419 rc = VERR_NO_MEMORY;1420 goto out;1421 }1422 pExtent->pRGD = pRGD;1423 }1424 else1425 pExtent->pRGD = NULL;1426 1427 1461 if (uStartSector != VMDK_GD_AT_END) 1428 1462 { … … 1462 1496 pExtent->uSectorGD = uStartSector; 1463 1497 } 1498 1499 rc = vmdkAllocGrainDirectory(pImage, pExtent); 1500 if (RT_FAILED(rc)) 1501 goto out; 1464 1502 1465 1503 if (fPreAlloc) … … 1507 1545 pExtent->cOverheadSectors = VMDK_BYTE2SECTOR(cbOverhead); 1508 1546 1509 /* streamOptimized extents need a compressed grain buffer, which must1510 * be big enough to hold uncompressible data (which needs ~8 bytes1511 * more than the uncompressed data), the marker and padding. */1512 pExtent->cbCompGrain = RT_ALIGN_Z( VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain)1513 + 8 + sizeof(VMDKMARKER), 512);1514 pExtent->pvCompGrain = RTMemAlloc(pExtent->cbCompGrain);1515 if (!pExtent->pvCompGrain)1516 {1517 rc = VERR_NO_MEMORY;1518 goto out;1519 }1520 1521 /* streamOptimized extents need a grain decompress buffer. */1522 if (pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED)1523 {1524 pExtent->pvGrain = RTMemAlloc(VMDK_SECTOR2BYTE(pExtent->cSectorsPerGrain));1525 if (!pExtent->pvGrain)1526 {1527 rc = VERR_NO_MEMORY;1528 goto out;1529 }1530 }1531 1532 1547 out: 1533 1548 if (RT_FAILURE(rc)) 1534 1549 vmdkFreeGrainDirectory(pExtent); 1535 1550 return rc; 1536 }1537 1538 static void vmdkFreeGrainDirectory(PVMDKEXTENT pExtent)1539 {1540 if (pExtent->pGD)1541 {1542 RTMemFree(pExtent->pGD);1543 pExtent->pGD = NULL;1544 }1545 if (pExtent->pRGD)1546 {1547 RTMemFree(pExtent->pRGD);1548 pExtent->pRGD = NULL;1549 }1550 1551 } 1551 1552 … … 4519 4520 } 4520 4521 4522 if (pfnProgress) 4523 pfnProgress(pvUser, uPercentStart + uPercentSpan * 70 / 100); 4524 4525 rc = vmdkWriteDescriptor(pImage); 4526 if (RT_FAILURE(rc)) 4527 { 4528 rc = vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: cannot write VMDK descriptor in '%s'"), pImage->pszFilename); 4529 goto out; 4530 } 4531 4521 4532 /* Skip over the overhead area. */ 4522 4533 rc = vmdkFileSetSize(pImage, pExtent->pFile, 4523 4534 VMDK_SECTOR2BYTE(pExtent->cOverheadSectors)); 4524 4525 if (pfnProgress)4526 pfnProgress(pvUser, uPercentStart + uPercentSpan * 70 / 100);4527 4528 rc = vmdkWriteDescriptor(pImage);4529 if (RT_FAILURE(rc))4530 {4531 rc = vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: cannot write VMDK descriptor in '%s'"), pImage->pszFilename);4532 goto out;4533 }4534 4535 4535 4536 out:
Note:
See TracChangeset
for help on using the changeset viewer.