Changeset 17970 in vbox for trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp
- Timestamp:
- Mar 16, 2009 7:08:16 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp
r16873 r17970 55 55 static void vdiInitPreHeader(PVDIPREHEADER pPreHdr); 56 56 static int vdiValidatePreHeader(PVDIPREHEADER pPreHdr); 57 static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, 58 uint32_t uImageFlags, const char *pszComment, 59 uint64_t cbDisk, uint32_t cbBlock, 60 uint32_t cbBlockExtra); 57 static void vdiInitHeader(PVDIHEADER pHeader, uint32_t uImageFlags, 58 const char *pszComment, uint64_t cbDisk, 59 uint32_t cbBlock, uint32_t cbBlockExtra); 61 60 static int vdiValidateHeader(PVDIHEADER pHeader); 62 61 static void vdiSetupImageDesc(PVDIIMAGEDESC pImage); … … 127 126 128 127 /** 129 * Internal: translate VD image type enumto VDI image type enum.128 * Internal: translate VD image flags to VDI image type enum. 130 129 */ 131 static VDIIMAGETYPE vdiTranslateTypeVD2VDI(VDIMAGETYPE enmType) 132 { 133 switch (enmType) 134 { 135 case VD_IMAGE_TYPE_NORMAL: 136 return VDI_IMAGE_TYPE_NORMAL; 137 case VD_IMAGE_TYPE_FIXED: 138 return VDI_IMAGE_TYPE_FIXED; 139 case VD_IMAGE_TYPE_UNDO: 140 return VDI_IMAGE_TYPE_UNDO; 141 case VD_IMAGE_TYPE_DIFF: 142 return VDI_IMAGE_TYPE_DIFF; 143 default: 144 AssertMsgFailed(("invalid VDIMAGETYPE enmType=%d\n", (int)enmType)); 145 return VDI_IMAGE_TYPE_NORMAL; 146 } 130 static VDIIMAGETYPE vdiTranslateImageFlags2VDI(unsigned uImageFlags) 131 { 132 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 133 return VDI_IMAGE_TYPE_FIXED; 134 else if (uImageFlags & VD_IMAGE_FLAGS_DIFF) 135 return VDI_IMAGE_TYPE_DIFF; 136 else 137 return VDI_IMAGE_TYPE_NORMAL; 147 138 } 148 139 … … 150 141 * Internal: translate VDI image type enum to VD image type enum. 151 142 */ 152 static VDIMAGETYPE vdiTranslateTypeVDI2VD(VDIIMAGETYPE enmType)143 static unsigned vdiTranslateVDI2ImageFlags(VDIIMAGETYPE enmType) 153 144 { 154 145 switch (enmType) 155 146 { 156 147 case VDI_IMAGE_TYPE_NORMAL: 157 return VD_IMAGE_ TYPE_NORMAL;148 return VD_IMAGE_FLAGS_NONE; 158 149 case VDI_IMAGE_TYPE_FIXED: 159 return VD_IMAGE_TYPE_FIXED; 160 case VDI_IMAGE_TYPE_UNDO: 161 return VD_IMAGE_TYPE_UNDO; 150 return VD_IMAGE_FLAGS_FIXED; 162 151 case VDI_IMAGE_TYPE_DIFF: 163 return VD_IMAGE_ TYPE_DIFF;152 return VD_IMAGE_FLAGS_DIFF; 164 153 default: 165 154 AssertMsgFailed(("invalid VDIIMAGETYPE enmType=%d\n", (int)enmType)); 166 return VD_IMAGE_ TYPE_INVALID;155 return VD_IMAGE_FLAGS_NONE; 167 156 } 168 157 } … … 172 161 * @param pHeader Assumes it was initially initialized to all zeros. 173 162 */ 174 static void vdiInitHeader(PVDIHEADER pHeader, VDIMAGETYPE enmType, 175 uint32_t uImageFlags, const char *pszComment, 176 uint64_t cbDisk, uint32_t cbBlock, 177 uint32_t cbBlockExtra) 163 static void vdiInitHeader(PVDIHEADER pHeader, uint32_t uImageFlags, 164 const char *pszComment, uint64_t cbDisk, 165 uint32_t cbBlock, uint32_t cbBlockExtra) 178 166 { 179 167 pHeader->uVersion = VDI_IMAGE_VERSION; 180 168 pHeader->u.v1.cbHeader = sizeof(VDIHEADER1); 181 pHeader->u.v1.u32Type = (uint32_t)vdiTranslate TypeVD2VDI(enmType);169 pHeader->u.v1.u32Type = (uint32_t)vdiTranslateImageFlags2VDI(uImageFlags); 182 170 pHeader->u.v1.fFlags = (uImageFlags & VD_VDI_IMAGE_FLAGS_ZERO_EXPAND) ? 1 : 0; 183 171 #ifdef VBOX_STRICT … … 351 339 { 352 340 pImage->uImageFlags = getImageFlags(&pImage->Header); 341 pImage->uImageFlags |= vdiTranslateVDI2ImageFlags(getImageType(&pImage->Header)); 353 342 pImage->offStartBlocks = getImageBlocksOffset(&pImage->Header); 354 343 pImage->offStartData = getImageDataOffset(&pImage->Header); … … 363 352 * Internal: Create VDI image file. 364 353 */ 365 static int vdiCreateImage(PVDIIMAGEDESC pImage, VDIMAGETYPE enmType, 366 uint64_t cbSize, unsigned uImageFlags, 367 const char *pszComment, 354 static int vdiCreateImage(PVDIIMAGEDESC pImage, uint64_t cbSize, 355 unsigned uImageFlags, const char *pszComment, 368 356 PCPDMMEDIAGEOMETRY pPCHSGeometry, 369 357 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 392 380 393 381 vdiInitPreHeader(&pImage->PreHeader); 394 vdiInitHeader(&pImage->Header, enmType,uImageFlags, pszComment, cbSize, VDI_IMAGE_DEFAULT_BLOCK_SIZE, 0);382 vdiInitHeader(&pImage->Header, uImageFlags, pszComment, cbSize, VDI_IMAGE_DEFAULT_BLOCK_SIZE, 0); 395 383 /* Save PCHS geometry. Not much work, and makes the flow of information 396 384 * quite a bit clearer - relying on the higher level isn't obvious. */ … … 409 397 } 410 398 411 if ( enmType != VD_IMAGE_TYPE_FIXED)399 if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED)) 412 400 { 413 401 /* for growing images mark all blocks in paBlocks as free. */ … … 439 427 + (uint64_t)getImageBlocks(&pImage->Header) * pImage->cbTotalBlockData; 440 428 441 if ( enmType == VD_IMAGE_TYPE_FIXED)429 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 442 430 { 443 431 /* Check the free space on the disk and leave early if there is not … … 452 440 } 453 441 454 if ( enmType == VD_IMAGE_TYPE_FIXED)442 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 455 443 { 456 444 /* … … 503 491 } 504 492 505 if ( enmType == VD_IMAGE_TYPE_FIXED)493 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 506 494 { 507 495 /* Fill image with zeroes. We do this for every fixed-size image since on some systems … … 853 841 854 842 /** @copydoc VBOXHDDBACKEND::pfnCreate */ 855 static int vdiCreate(const char *pszFilename, VDIMAGETYPE enmType, 856 uint64_t cbSize, unsigned uImageFlags, 857 const char *pszComment, 843 static int vdiCreate(const char *pszFilename, uint64_t cbSize, 844 unsigned uImageFlags, const char *pszComment, 858 845 PCPDMMEDIAGEOMETRY pPCHSGeometry, 859 846 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 863 850 void **ppBackendData) 864 851 { 865 LogFlowFunc(("pszFilename=\"%s\" enmType=%d cbSize=%llu uImageFlags=%#x pszComment=\"%s\" pPCHSGeometry=%#p pLCHSGeometry=%#p Uuid=%RTuuid uOpenFlags=%#x uPercentStart=%u uPercentSpan=%u pVDIfsDisk=%#p pVDIfsImage=%#p pVDIfsOperation=%#p ppBackendData=%#p", pszFilename, enmType, cbSize, uImageFlags, pszComment, pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, uPercentStart, uPercentSpan, pVDIfsDisk, pVDIfsImage, pVDIfsOperation, ppBackendData));852 LogFlowFunc(("pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" pPCHSGeometry=%#p pLCHSGeometry=%#p Uuid=%RTuuid uOpenFlags=%#x uPercentStart=%u uPercentSpan=%u pVDIfsDisk=%#p pVDIfsImage=%#p pVDIfsOperation=%#p ppBackendData=%#p", pszFilename, cbSize, uImageFlags, pszComment, pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, uPercentStart, uPercentSpan, pVDIfsDisk, pVDIfsImage, pVDIfsOperation, ppBackendData)); 866 853 int rc; 867 854 PVDIIMAGEDESC pImage; … … 890 877 if ( !VALID_PTR(pszFilename) 891 878 || !*pszFilename 892 || (enmType != VD_IMAGE_TYPE_NORMAL && enmType != VD_IMAGE_TYPE_FIXED893 && enmType != VD_IMAGE_TYPE_DIFF)894 879 || cbSize < VDI_IMAGE_DEFAULT_BLOCK_SIZE 895 880 || !VALID_PTR(pPCHSGeometry) … … 911 896 pImage->pVDIfsDisk = pVDIfsDisk; 912 897 913 rc = vdiCreateImage(pImage, enmType,cbSize, uImageFlags, pszComment,898 rc = vdiCreateImage(pImage, cbSize, uImageFlags, pszComment, 914 899 pPCHSGeometry, pLCHSGeometry, pUuid, 915 900 pfnProgress, pvUser, uPercentStart, uPercentSpan); … … 1190 1175 LogFlowFunc(("returns %#x\n", uVersion)); 1191 1176 return uVersion; 1192 }1193 1194 /** @copydoc VBOXHDDBACKEND::pfnGetImageType */1195 static int vdiGetImageType(void *pBackendData, PVDIMAGETYPE penmImageType)1196 {1197 LogFlowFunc(("pBackendData=%#p penmImageType=%#p\n", pBackendData, penmImageType));1198 PVDIIMAGEDESC pImage = (PVDIIMAGEDESC)pBackendData;1199 int rc = VINF_SUCCESS;1200 1201 AssertPtr(pImage);1202 AssertPtr(penmImageType);1203 1204 if (pImage)1205 *penmImageType = vdiTranslateTypeVDI2VD(getImageType(&pImage->Header));1206 else1207 rc = VERR_VD_NOT_OPENED;1208 1209 LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));1210 return rc;1211 1177 } 1212 1178 … … 1893 1859 /* pfnGetVersion */ 1894 1860 vdiGetVersion, 1895 /* pfnGetImageType */1896 vdiGetImageType,1897 1861 /* pfnGetSize */ 1898 1862 vdiGetSize,
Note:
See TracChangeset
for help on using the changeset viewer.