Changeset 7231 in vbox
- Timestamp:
- Mar 3, 2008 11:08:55 AM (17 years ago)
- Location:
- trunk/src/VBox/Devices/Storage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VDICore.h
r7152 r7231 539 539 /** Block shift value for converting byte hdd offset into paBlock index. */ 540 540 unsigned uShiftOffset2Index; 541 #ifndef VBOX_VDICORE_VD 541 542 /** Block shift value for converting block index into offset in image. */ 542 543 unsigned uShiftIndex2Offset; 544 #endif /* !VBOX_VDICORE_VD */ 543 545 /** Offset of data from the beginning of block. */ 544 546 unsigned offStartBlockData; 547 #ifndef VBOX_VDICORE_VD 545 548 /** Image is modified flags (VDI_IMAGE_MODIFIED*). */ 546 549 unsigned fModified; 547 #ifndef VBOX_VDICORE_VD548 550 /** Container filename. (UTF-8) 549 551 * @todo Make this variable length to save a bunch of bytes. (low prio) */ 550 552 char szFilename[RTPATH_MAX]; 551 #else /* !VBOX_VDICORE_VD */ 553 #else /* VBOX_VDICORE_VD */ 554 /** Total size of image block (including the extra data). */ 555 unsigned cbTotalBlockData; 552 556 /** Container filename. (UTF-8) */ 553 557 const char *pszFilename; … … 558 562 /** Opaque data for error callback. */ 559 563 void *pvErrorUser; 560 #endif /* !VBOX_VDICORE_VD */564 #endif /* VBOX_VDICORE_VD */ 561 565 } VDIIMAGEDESC, *PVDIIMAGEDESC; 562 566 -
trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp
r7159 r7231 40 40 static void vdiInitPreHeader(PVDIPREHEADER pPreHdr); 41 41 static int vdiValidatePreHeader(PVDIPREHEADER pPreHdr); 42 static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, uint32_t uImageFlags, 43 const char *pszComment, uint64_t cbDisk, uint32_t cbBlock, 42 static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, 43 uint32_t uImageFlags, const char *pszComment, 44 uint64_t cbDisk, uint32_t cbBlock, 44 45 uint32_t cbBlockExtra); 45 46 static int vdiValidateHeader(PVDIHEADER pHeader); … … 113 114 * @param pHeader Assumes it was initially initialized to all zeros. 114 115 */ 115 static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, uint32_t uImageFlags, 116 const char *pszComment, uint64_t cbDisk, uint32_t cbBlock, 116 static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, 117 uint32_t uImageFlags, const char *pszComment, 118 uint64_t cbDisk, uint32_t cbBlock, 117 119 uint32_t cbBlockExtra) 118 120 { … … 296 298 pImage->offStartData = getImageDataOffset(&pImage->Header); 297 299 pImage->uBlockMask = getImageBlockSize(&pImage->Header) - 1; 298 pImage->uShiftIndex2Offset =299 300 pImage->uShiftOffset2Index = getPowerOfTwo(getImageBlockSize(&pImage->Header)); 300 301 pImage->offStartBlockData = getImageExtraBlockSize(&pImage->Header); 301 if (pImage->offStartBlockData != 0)302 pImage->uShiftIndex2Offset += getPowerOfTwo(pImage->offStartBlockData);302 pImage->cbTotalBlockData = pImage->offStartBlockData 303 + getImageBlockSize(&pImage->Header); 303 304 } 304 305 … … 375 376 376 377 cbTotal = pImage->offStartData 377 + ( (uint64_t)getImageBlocks(&pImage->Header) << pImage->uShiftIndex2Offset);378 + (uint64_t)getImageBlocks(&pImage->Header) * pImage->cbTotalBlockData; 378 379 379 380 if (enmType == VD_IMAGE_TYPE_FIXED) … … 456 457 } 457 458 458 cbFill = (uint64_t)getImageBlocks(&pImage->Header) << pImage->uShiftIndex2Offset;459 cbFill = (uint64_t)getImageBlocks(&pImage->Header) * pImage->cbTotalBlockData; 459 460 uOff = 0; 460 461 /* do loop to fill all image. */ … … 684 685 static void vdiFreeImage(PVDIIMAGEDESC pImage, bool fDelete) 685 686 { 686 Assert( pImage);687 Assert(VALID_PTR(pImage)); 687 688 688 689 vdiFlushImage(pImage); … … 879 880 int rc; 880 881 881 Assert( pImage);882 Assert( uOffset % 512 == 0);883 Assert( cbToRead % 512 == 0);882 Assert(VALID_PTR(pImage)); 883 Assert(!(uOffset % 512)); 884 Assert(!(cbToRead % 512)); 884 885 885 886 if ( uOffset + cbToRead > getImageDiskSize(&pImage->Header) 886 || cbToRead == 0) 887 || !VALID_PTR(pvBuf) 888 || !cbToRead) 887 889 { 888 890 rc = VERR_INVALID_PARAMETER; … … 907 909 else 908 910 { 909 /* block present in image file*/910 uint64_t u64Offset = ( (uint64_t)pImage->paBlocks[uBlock] << pImage->uShiftIndex2Offset)911 /* Block present in image file, read relevant data. */ 912 uint64_t u64Offset = (uint64_t)pImage->paBlocks[uBlock] * pImage->cbTotalBlockData 911 913 + (pImage->offStartData + pImage->offStartBlockData + offRead); 912 914 rc = RTFileReadAt(pImage->File, u64Offset, pvBuf, cbToRead, NULL); … … 932 934 int rc = VINF_SUCCESS; 933 935 934 Assert( pImage);935 Assert( uOffset % 512 == 0);936 Assert( cbToWrite % 512 == 0);936 Assert(VALID_PTR(pImage)); 937 Assert(!(uOffset % 512)); 938 Assert(!(cbToWrite % 512)); 937 939 938 940 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY) … … 942 944 } 943 945 944 if ( cbToWrite == 0)946 if (!VALID_PTR(pvBuf) || !cbToWrite) 945 947 { 946 948 rc = VERR_INVALID_PARAMETER; … … 971 973 * (which also means that it's a zero block. Don't need to write 972 974 * anything to this block if the data consists of just zeroes. */ 973 Assert( cbToWrite % 4 == 0);975 Assert(!(cbToWrite % 4)); 974 976 Assert(cbToWrite * 8 <= UINT32_MAX); 975 977 if (ASMBitFirstSet((volatile void *)pvBuf, (uint32_t)cbToWrite * 8) == -1) … … 984 986 /* Full block write to previously unallocated block. 985 987 * Allocate block and write data. */ 988 Assert(!offWrite); 986 989 unsigned cBlocksAllocated = getImageBlocksAllocated(&pImage->Header); 987 rc = RTFileWriteAt(pImage->File, 988 ((uint64_t)cBlocksAllocated << pImage->uShiftIndex2Offset) 989 + pImage->offStartData, 990 pvBuf, cbToWrite, NULL); 990 uint64_t u64Offset = (uint64_t)cBlocksAllocated * pImage->cbTotalBlockData 991 + (pImage->offStartData + pImage->offStartBlockData); 992 rc = RTFileWriteAt(pImage->File, u64Offset, pvBuf, cbToWrite, NULL); 991 993 if (VBOX_FAILURE(rc)) 992 994 goto out; … … 1011 1013 } 1012 1014 else 1013 rc = RTFileWriteAt(pImage->File, 1014 ((uint64_t)pImage->paBlocks[uBlock] << pImage->uShiftIndex2Offset) 1015 + pImage->offStartData + pImage->offStartBlockData + offWrite, 1016 pvBuf, cbToWrite, NULL); 1015 { 1016 /* Block present in image file, write relevant data. */ 1017 uint64_t u64Offset = (uint64_t)pImage->paBlocks[uBlock] * pImage->cbTotalBlockData 1018 + (pImage->offStartData + pImage->offStartBlockData + offWrite); 1019 rc = RTFileWriteAt(pImage->File, u64Offset, pvBuf, cbToWrite, NULL); 1020 } 1017 1021 1018 1022 out: … … 1040 1044 unsigned uVersion; 1041 1045 1042 Assert( pImage);1046 Assert(VALID_PTR(pImage)); 1043 1047 1044 1048 if (pImage) … … 1058 1062 int rc = VINF_SUCCESS; 1059 1063 1060 Assert( pImage);1061 Assert( penmImageType);1064 Assert(VALID_PTR(pImage)); 1065 Assert(VALID_PTR(penmImageType)); 1062 1066 1063 1067 if (pImage) … … 1079 1083 uint64_t cbSize; 1080 1084 1081 Assert( pImage);1085 Assert(VALID_PTR(pImage)); 1082 1086 1083 1087 if (pImage) … … 1097 1101 uint64_t cb = 0; 1098 1102 1099 Assert( pImage);1103 Assert(VALID_PTR(pImage)); 1100 1104 1101 1105 if (pImage) … … 1122 1126 int rc; 1123 1127 1124 Assert( pImage);1128 Assert(VALID_PTR(pImage)); 1125 1129 1126 1130 if (pImage) … … 1149 1153 int rc; 1150 1154 1151 Assert( pImage);1155 Assert(VALID_PTR(pImage)); 1152 1156 1153 1157 if (pImage) … … 1178 1182 int rc; 1179 1183 1180 Assert( pImage);1184 Assert(VALID_PTR(pImage)); 1181 1185 1182 1186 if (pImage) … … 1215 1219 int rc; 1216 1220 1217 Assert( pImage);1221 Assert(VALID_PTR(pImage)); 1218 1222 1219 1223 if (pImage) … … 1253 1257 unsigned uImageFlags; 1254 1258 1255 Assert( pImage);1259 Assert(VALID_PTR(pImage)); 1256 1260 1257 1261 if (pImage) … … 1271 1275 unsigned uOpenFlags; 1272 1276 1273 Assert( pImage);1277 Assert(VALID_PTR(pImage)); 1274 1278 1275 1279 if (pImage) … … 1316 1320 int rc = VINF_SUCCESS; 1317 1321 1318 Assert( pImage);1322 Assert(VALID_PTR(pImage)); 1319 1323 1320 1324 if (pImage) … … 1344 1348 int rc; 1345 1349 1346 Assert( pImage);1350 Assert(VALID_PTR(pImage)); 1347 1351 1348 1352 if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY) … … 1392 1396 int rc; 1393 1397 1394 Assert( pImage);1398 Assert(VALID_PTR(pImage)); 1395 1399 1396 1400 if (pImage) … … 1413 1417 int rc = VINF_SUCCESS; 1414 1418 1415 Assert( pImage);1419 Assert(VALID_PTR(pImage)); 1416 1420 1417 1421 if (pImage) … … 1447 1451 int rc; 1448 1452 1449 Assert( pImage);1453 Assert(VALID_PTR(pImage)); 1450 1454 1451 1455 if (pImage) … … 1468 1472 int rc = VINF_SUCCESS; 1469 1473 1470 Assert( pImage);1474 Assert(VALID_PTR(pImage)); 1471 1475 1472 1476 if (pImage) … … 1502 1506 int rc; 1503 1507 1504 Assert( pImage);1508 Assert(VALID_PTR(pImage)); 1505 1509 1506 1510 if (pImage) … … 1523 1527 int rc = VINF_SUCCESS; 1524 1528 1525 Assert( pImage);1529 Assert(VALID_PTR(pImage)); 1526 1530 1527 1531 if (pImage) … … 1557 1561 int rc; 1558 1562 1559 Assert( pImage);1563 Assert(VALID_PTR(pImage)); 1560 1564 1561 1565 if (pImage) … … 1578 1582 int rc = VINF_SUCCESS; 1579 1583 1580 Assert( pImage);1584 Assert(VALID_PTR(pImage)); 1581 1585 1582 1586 if (pImage) … … 1636 1640 RTLogPrintf("Image: fFlags=%08X offStartBlocks=%u offStartData=%u\n", 1637 1641 pImage->uImageFlags, pImage->offStartBlocks, pImage->offStartData); 1638 RTLogPrintf("Image: uBlockMask=%08X uShiftIndex2Offset=%u uShiftOffset2Index=%u offStartBlockData=%u\n",1642 RTLogPrintf("Image: uBlockMask=%08X cbTotalBlockData=%u uShiftOffset2Index=%u offStartBlockData=%u\n", 1639 1643 pImage->uBlockMask, 1640 pImage-> uShiftIndex2Offset,1644 pImage->cbTotalBlockData, 1641 1645 pImage->uShiftOffset2Index, 1642 1646 pImage->offStartBlockData);
Note:
See TracChangeset
for help on using the changeset viewer.