Changeset 17970 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Mar 16, 2009 7:08:16 PM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Storage
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Storage/ISCSIHDDCore.cpp
r17798 r17970 2649 2649 2650 2650 /** @copydoc VBOXHDDBACKEND::pfnCreate */ 2651 static int iscsiCreate(const char *pszFilename, VDIMAGETYPE enmType, 2652 uint64_t cbSize, unsigned uImageFlags, 2653 const char *pszComment, 2651 static int iscsiCreate(const char *pszFilename, uint64_t cbSize, 2652 unsigned uImageFlags, const char *pszComment, 2654 2653 PCPDMMEDIAGEOMETRY pPCHSGeometry, 2655 2654 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 2659 2658 void **ppBackendData) 2660 2659 { 2661 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));2660 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)); 2662 2661 int rc = VERR_NOT_SUPPORTED; 2663 2662 … … 2883 2882 2884 2883 2885 /** @copydoc VBOXHDDBACKEND::pfnGetImageType */2886 static int iscsiGetImageType(void *pBackendData, PVDIMAGETYPE penmImageType)2887 {2888 LogFlowFunc(("pBackendData=%#p penmImageType=%#p\n", pBackendData, penmImageType));2889 PISCSIIMAGE pImage = (PISCSIIMAGE)pBackendData;2890 int rc = VINF_SUCCESS;2891 2892 Assert(pImage);2893 Assert(penmImageType);2894 2895 if (pImage)2896 *penmImageType = VD_IMAGE_TYPE_FIXED;2897 else2898 rc = VERR_VD_NOT_OPENED;2899 2900 LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));2901 return rc;2902 }2903 2904 2905 2884 /** @copydoc VBOXHDDBACKEND::pfnGetSize */ 2906 2885 static uint64_t iscsiGetSize(void *pBackendData) … … 3012 2991 NOREF(pImage); 3013 2992 3014 uImageFlags = VD_IMAGE_FLAGS_ NONE;2993 uImageFlags = VD_IMAGE_FLAGS_FIXED; 3015 2994 3016 2995 LogFlowFunc(("returns %#x\n", uImageFlags)); … … 3488 3467 /* pfnGetVersion */ 3489 3468 iscsiGetVersion, 3490 /* pfnGetImageType */3491 iscsiGetImageType,3492 3469 /* pfnGetSize */ 3493 3470 iscsiGetSize, -
trunk/src/VBox/Devices/Storage/RawHDDCore.cpp
r16873 r17970 57 57 /** Open flags passed by VBoxHD layer. */ 58 58 unsigned uOpenFlags; 59 /** Image type. */60 VDIMAGETYPE enmImageType;61 59 /** Image flags defined during creation or determined during open. */ 62 60 unsigned uImageFlags; … … 146 144 goto out; 147 145 } 148 pImage-> enmImageType = VD_IMAGE_TYPE_FIXED;146 pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED; 149 147 150 148 out: … … 157 155 * Internal: Create a raw image. 158 156 */ 159 static int rawCreateImage(PRAWIMAGE pImage, VDIMAGETYPE enmType, 160 uint64_t cbSize, unsigned uImageFlags, 161 const char *pszComment, 157 static int rawCreateImage(PRAWIMAGE pImage, uint64_t cbSize, 158 unsigned uImageFlags, const char *pszComment, 162 159 PCPDMMEDIAGEOMETRY pPCHSGeometry, 163 160 PCPDMMEDIAGEOMETRY pLCHSGeometry, … … 172 169 void *pvBuf = NULL; 173 170 174 if ( enmType != VD_IMAGE_TYPE_FIXED)171 if (uImageFlags & VD_IMAGE_FLAGS_DIFF) 175 172 { 176 173 rc = rawError(pImage, VERR_VD_RAW_INVALID_TYPE, RT_SRC_POS, N_("Raw: cannot create diff image '%s'"), pImage->pszFilename); 177 174 goto out; 178 175 } 179 180 pImage->enmImageType = enmType; 176 uImageFlags |= VD_IMAGE_FLAGS_FIXED; 177 181 178 pImage->uImageFlags = uImageFlags; 182 179 pImage->PCHSGeometry = *pPCHSGeometry; … … 256 253 uPercentStart + uPercentSpan * 98 / 100, pvUser); 257 254 258 pImage->enmImageType = enmType;259 255 pImage->cbSize = cbSize; 260 256 … … 279 275 Assert(pImage); 280 276 281 if (pImage->enmImageType) 282 { 283 if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)) 284 rawFlushImage(pImage); 285 } 277 if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)) 278 rawFlushImage(pImage); 286 279 if (pImage->File != NIL_RTFILE) 287 280 { … … 374 367 375 368 /** @copydoc VBOXHDDBACKEND::pfnCreate */ 376 static int rawCreate(const char *pszFilename, VDIMAGETYPE enmType, 377 uint64_t cbSize, unsigned uImageFlags, 378 const char *pszComment, 369 static int rawCreate(const char *pszFilename, uint64_t cbSize, 370 unsigned uImageFlags, const char *pszComment, 379 371 PCPDMMEDIAGEOMETRY pPCHSGeometry, 380 372 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 384 376 void **ppBackendData) 385 377 { 386 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));378 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)); 387 379 int rc; 388 380 PRAWIMAGE pImage; … … 411 403 if ( !VALID_PTR(pszFilename) 412 404 || !*pszFilename 413 || (enmType != VD_IMAGE_TYPE_FIXED)414 405 || !VALID_PTR(pPCHSGeometry) 415 406 || !VALID_PTR(pLCHSGeometry)) … … 429 420 pImage->pVDIfsDisk = pVDIfsDisk; 430 421 431 rc = rawCreateImage(pImage, enmType,cbSize, uImageFlags, pszComment,422 rc = rawCreateImage(pImage, cbSize, uImageFlags, pszComment, 432 423 pPCHSGeometry, pLCHSGeometry, 433 424 pfnProgress, pvUser, uPercentStart, uPercentSpan); … … 563 554 else 564 555 return 0; 565 }566 567 /** @copydoc VBOXHDDBACKEND::pfnGetImageType */568 static int rawGetImageType(void *pBackendData, PVDIMAGETYPE penmImageType)569 {570 LogFlowFunc(("pBackendData=%#p penmImageType=%#p\n", pBackendData, penmImageType));571 PRAWIMAGE pImage = (PRAWIMAGE)pBackendData;572 int rc = VINF_SUCCESS;573 574 Assert(pImage);575 Assert(penmImageType);576 577 if (pImage)578 *penmImageType = pImage->enmImageType;579 else580 rc = VERR_VD_NOT_OPENED;581 582 LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));583 return rc;584 556 } 585 557 … … 1110 1082 /* pfnGetVersion */ 1111 1083 rawGetVersion, 1112 /* pfnGetImageType */1113 rawGetImageType,1114 1084 /* pfnGetSize */ 1115 1085 rawGetSize, -
trunk/src/VBox/Devices/Storage/VBoxHDD-Internal.h
r16873 r17970 105 105 * @param pszFilename Name of the image file to create. Guaranteed to be available and 106 106 * unchanged during the lifetime of this image. 107 * @param enmType Image type. Both base and diff image types are valid.108 107 * @param cbSize Image size in bytes. 109 108 * @param uImageFlags Flags specifying special image features. … … 120 119 * @param ppvBackendData Opaque state data for this image. 121 120 */ 122 DECLR3CALLBACKMEMBER(int, pfnCreate, (const char *pszFilename, VDIMAGETYPE enmType, 123 uint64_t cbSize, unsigned uImageFlags, 124 const char *pszComment, 121 DECLR3CALLBACKMEMBER(int, pfnCreate, (const char *pszFilename, uint64_t cbSize, 122 unsigned uImageFlags, const char *pszComment, 125 123 PCPDMMEDIAGEOMETRY pPCHSGeometry, 126 124 PCPDMMEDIAGEOMETRY pLCHSGeometry, … … 222 220 223 221 /** 224 * Get the type information for a disk image.225 *226 * @returns VBox status code.227 * @param pvBackendData Opaque state data for this image.228 * @param penmType Image type of this image.229 */230 DECLR3CALLBACKMEMBER(int, pfnGetImageType, (void *pvBackendData, PVDIMAGETYPE penmType));231 232 /**233 222 * Get the capacity of a disk image. 234 223 * -
trunk/src/VBox/Devices/Storage/VBoxHDD.cpp
r17836 r17970 61 61 /** Data managed by the backend which keeps the actual info. */ 62 62 void *pvBackendData; 63 /** Cached sanitized image type. */64 VDIMAGETYPE enmImageType;63 /** Cached sanitized image flags. */ 64 unsigned uImageFlags; 65 65 /** Image open flags (only those handled generically in this code and which 66 66 * the backends will never ever see). */ … … 1052 1052 } 1053 1053 1054 VDIMAGETYPE enmImageType; 1055 rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData, 1056 &enmImageType); 1054 unsigned uImageFlags; 1055 uImageFlags = pImage->Backend->pfnGetImageFlags(pImage->pvBackendData); 1057 1056 /* Check image type. As the image itself has only partial knowledge 1058 1057 * whether it's a base image or not, this info is derived here. The … … 1061 1060 * and diff images, so this must be corrected here. */ 1062 1061 if (RT_FAILURE(rc)) 1063 enmImageType = VD_IMAGE_TYPE_INVALID;1062 uImageFlags = VD_IMAGE_FLAGS_NONE; 1064 1063 if ( RT_SUCCESS(rc) 1065 1064 && !(uOpenFlags & VD_OPEN_FLAGS_INFO)) 1066 1065 { 1067 1066 if ( pDisk->cImages == 0 1068 && enmImageType != VD_IMAGE_TYPE_FIXED 1069 && enmImageType != VD_IMAGE_TYPE_NORMAL) 1067 && (uImageFlags & VD_IMAGE_FLAGS_DIFF)) 1070 1068 { 1071 1069 rc = VERR_VD_INVALID_TYPE; … … 1074 1072 else if (pDisk->cImages != 0) 1075 1073 { 1076 if ( enmImageType != VD_IMAGE_TYPE_NORMAL 1077 && enmImageType != VD_IMAGE_TYPE_DIFF) 1074 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 1078 1075 { 1079 1076 rc = VERR_VD_INVALID_TYPE; … … 1081 1078 } 1082 1079 else 1083 enmImageType = VD_IMAGE_TYPE_DIFF;1080 uImageFlags |= VD_IMAGE_FLAGS_DIFF; 1084 1081 } 1085 1082 } 1086 pImage-> enmImageType = enmImageType;1083 pImage->uImageFlags = uImageFlags; 1087 1084 1088 1085 /* Force sane optimization settings. It's not worth avoiding writes 1089 1086 * to fixed size images. The overhead would have almost no payback. */ 1090 if ( enmImageType == VD_IMAGE_TYPE_FIXED)1087 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 1091 1088 pImage->uOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME; 1092 1089 … … 1182 1179 * @param pszBackend Name of the image file backend to use. 1183 1180 * @param pszFilename Name of the image file to create. 1184 * @param enmType Image type, only base image types are acceptable.1185 1181 * @param cbSize Image size in bytes. 1186 1182 * @param uImageFlags Flags specifying special image features. … … 1194 1190 */ 1195 1191 VBOXDDU_DECL(int) VDCreateBase(PVBOXHDD pDisk, const char *pszBackend, 1196 const char *pszFilename, VDIMAGETYPE enmType, 1197 uint64_t cbSize, unsigned uImageFlags, 1198 const char *pszComment, 1192 const char *pszFilename, uint64_t cbSize, 1193 unsigned uImageFlags, const char *pszComment, 1199 1194 PCPDMMEDIAGEOMETRY pPCHSGeometry, 1200 1195 PCPDMMEDIAGEOMETRY pLCHSGeometry, … … 1207 1202 RTUUID uuid; 1208 1203 1209 LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" enmType=%#xcbSize=%llu uImageFlags=%#x pszComment=\"%s\" PCHS=%u/%u/%u LCHS=%u/%u/%u Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n",1210 pDisk, pszBackend, pszFilename, enmType,cbSize, uImageFlags, pszComment,1204 LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" cbSize=%llu uImageFlags=%#x pszComment=\"%s\" PCHS=%u/%u/%u LCHS=%u/%u/%u Uuid=%RTuuid uOpenFlags=%#x pVDIfsImage=%#p pVDIfsOperation=%#p\n", 1205 pDisk, pszBackend, pszFilename, cbSize, uImageFlags, pszComment, 1211 1206 pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads, 1212 1207 pPCHSGeometry->cSectors, pLCHSGeometry->cCylinders, … … 1233 1228 ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename), 1234 1229 rc = VERR_INVALID_PARAMETER); 1235 AssertMsgBreakStmt(enmType == VD_IMAGE_TYPE_NORMAL || enmType == VD_IMAGE_TYPE_FIXED,1236 ("enmType=%#x\n", enmType),1237 rc = VERR_INVALID_PARAMETER);1238 1230 AssertMsgBreakStmt(cbSize, 1239 1231 ("cbSize=%llu\n", cbSize), 1240 1232 rc = VERR_INVALID_PARAMETER); 1241 AssertMsgBreakStmt((uImageFlags & ~VD_IMAGE_FLAGS_MASK) == 0, 1233 AssertMsgBreakStmt( ((uImageFlags & ~VD_IMAGE_FLAGS_MASK) == 0) 1234 || ((uImageFlags & (VD_IMAGE_FLAGS_FIXED | VD_IMAGE_FLAGS_DIFF)) != VD_IMAGE_FLAGS_FIXED), 1242 1235 ("uImageFlags=%#x\n", uImageFlags), 1243 1236 rc = VERR_INVALID_PARAMETER); … … 1313 1306 1314 1307 pImage->uOpenFlags = uOpenFlags & VD_OPEN_FLAGS_HONOR_SAME; 1315 rc = pImage->Backend->pfnCreate(pImage->pszFilename, enmType, cbSize, 1308 uImageFlags &= ~VD_IMAGE_FLAGS_DIFF; 1309 rc = pImage->Backend->pfnCreate(pImage->pszFilename, cbSize, 1316 1310 uImageFlags, pszComment, pPCHSGeometry, 1317 1311 pLCHSGeometry, pUuid, … … 1325 1319 if (RT_SUCCESS(rc)) 1326 1320 { 1327 pImage-> enmImageType = enmType;1321 pImage->uImageFlags = uImageFlags; 1328 1322 1329 1323 /* Force sane optimization settings. It's not worth avoiding writes 1330 1324 * to fixed size images. The overhead would have almost no payback. */ 1331 if ( enmType == VD_IMAGE_TYPE_FIXED)1325 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 1332 1326 pImage->uOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME; 1333 1327 … … 1518 1512 1519 1513 pImage->uOpenFlags = uOpenFlags & VD_OPEN_FLAGS_HONOR_SAME; 1520 rc = pImage->Backend->pfnCreate(pImage->pszFilename, 1521 VD_IMAGE_TYPE_DIFF, pDisk->cbSize, 1514 rc = pImage->Backend->pfnCreate(pImage->pszFilename, pDisk->cbSize, 1522 1515 uImageFlags, pszComment, 1523 1516 &pDisk->PCHSGeometry, … … 1532 1525 if (RT_SUCCESS(rc) && pDisk->cImages != 0) 1533 1526 { 1534 pImage-> enmImageType = VD_IMAGE_TYPE_DIFF;1527 pImage->uImageFlags |= VD_IMAGE_FLAGS_DIFF; 1535 1528 1536 1529 /* Switch previous image to read-only mode. */ … … 1952 1945 rc = VERR_INVALID_PARAMETER); 1953 1946 1954 /* Collect properties of source image. */1955 VDIMAGETYPE enmTypeFrom = pImageFrom->enmImageType;1956 1957 1947 uint64_t cbSizeFrom; 1958 1948 cbSizeFrom = pImageFrom->Backend->pfnGetSize(pImageFrom->pvBackendData); … … 2010 2000 * calls to the backend. Unifies the code and reduces the API 2011 2001 * dependencies. */ 2012 if ( enmTypeFrom == VD_IMAGE_TYPE_DIFF)2002 if (uImageFlags & VD_IMAGE_FLAGS_DIFF) 2013 2003 { 2014 2004 rc = VDCreateDiff(pDiskTo, pszBackend, pszFilename, uImageFlags, 2015 2005 szComment, &ImageUuid, &ParentUuid, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL); 2016 2006 } else { 2017 VDIMAGETYPE enmTypeTo = enmTypeFrom; /** @todo Please, review this! It's an ugly hack I think... */ 2018 if ( !strcmp(pszBackend, "RAW") 2019 && enmTypeTo != VD_IMAGE_TYPE_FIXED) 2020 enmTypeTo = VD_IMAGE_TYPE_FIXED; 2021 2022 rc = VDCreateBase(pDiskTo, pszBackend, pszFilename, enmTypeTo, 2023 cbSize, uImageFlags, szComment, 2007 /** @todo Please, review this! It's an ugly hack I think... */ 2008 if (!RTStrICmp(pszBackend, "RAW")) 2009 uImageFlags |= VD_IMAGE_FLAGS_FIXED; 2010 2011 rc = VDCreateBase(pDiskTo, pszBackend, pszFilename, cbSize, 2012 uImageFlags, szComment, 2024 2013 &PCHSGeometryFrom, &LCHSGeometryFrom, 2025 2014 NULL, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL); … … 2814 2803 2815 2804 /** 2816 * Get type of image in HDD container.2817 *2818 * @returns VBox status code.2819 * @returns VERR_VD_IMAGE_NOT_FOUND if image with specified number was not opened.2820 * @param pDisk Pointer to HDD container.2821 * @param nImage Image number, counts from 0. 0 is always base image of container.2822 * @param penmType Where to store the image type.2823 */2824 VBOXDDU_DECL(int) VDGetImageType(PVBOXHDD pDisk, unsigned nImage,2825 PVDIMAGETYPE penmType)2826 {2827 int rc = VINF_SUCCESS;2828 2829 LogFlowFunc(("pDisk=%#p nImage=%u penmType=%#p\n",2830 pDisk, nImage, penmType));2831 do2832 {2833 /* sanity check */2834 AssertPtrBreakStmt(pDisk, rc = VERR_INVALID_PARAMETER);2835 AssertMsg(pDisk->u32Signature == VBOXHDDDISK_SIGNATURE, ("u32Signature=%08x\n", pDisk->u32Signature));2836 2837 /* Check arguments. */2838 AssertMsgBreakStmt(VALID_PTR(penmType),2839 ("penmType=%#p\n", penmType),2840 rc = VERR_INVALID_PARAMETER);2841 2842 PVDIMAGE pImage = vdGetImageByNumber(pDisk, nImage);2843 AssertPtrBreakStmt(pImage, rc = VERR_VD_IMAGE_NOT_FOUND);2844 2845 if ( pImage->enmImageType >= VD_IMAGE_TYPE_FIRST2846 && pImage->enmImageType <= VD_IMAGE_TYPE_DIFF)2847 {2848 *penmType = pImage->enmImageType;2849 rc = VINF_SUCCESS;2850 }2851 else2852 rc = VERR_VD_INVALID_TYPE;2853 } while (0);2854 2855 LogFlowFunc(("returns %Rrc uenmType=%u\n", rc, *penmType));2856 return rc;2857 }2858 2859 2860 /**2861 2805 * List the capabilities of image backend in HDD container. 2862 2806 * … … 2872 2816 int rc = VINF_SUCCESS; 2873 2817 2874 LogFlowFunc(("pDisk=%#p nImage=%u p enmType=%#p\n",2818 LogFlowFunc(("pDisk=%#p nImage=%u pBackendInfo=%#p\n", 2875 2819 pDisk, nImage, pBackendInfo)); 2876 2820 do … … 2888 2832 AssertPtrBreakStmt(pImage, rc = VERR_VD_IMAGE_NOT_FOUND); 2889 2833 2890 if ( pImage->enmImageType >= VD_IMAGE_TYPE_FIRST 2891 && pImage->enmImageType <= VD_IMAGE_TYPE_DIFF) 2892 { 2893 pBackendInfo->pszBackend = RTStrDup(pImage->Backend->pszBackendName); 2894 pBackendInfo->uBackendCaps = pImage->Backend->uBackendCaps; 2895 pBackendInfo->papszFileExtensions = pImage->Backend->papszFileExtensions; 2896 pBackendInfo->paConfigInfo = pImage->Backend->paConfigInfo; 2897 rc = VINF_SUCCESS; 2898 } 2899 else 2900 rc = VERR_VD_INVALID_TYPE; 2834 pBackendInfo->pszBackend = RTStrDup(pImage->Backend->pszBackendName); 2835 pBackendInfo->uBackendCaps = pImage->Backend->uBackendCaps; 2836 pBackendInfo->papszFileExtensions = pImage->Backend->papszFileExtensions; 2837 pBackendInfo->paConfigInfo = pImage->Backend->paConfigInfo; 2901 2838 } while (0); 2902 2839 -
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, -
trunk/src/VBox/Devices/Storage/VHDHDDCore.cpp
r16873 r17970 141 141 /** Open flags passed by VBoxHD layer. */ 142 142 unsigned uOpenFlags; 143 /** Image type. */144 VDIMAGETYPE enmImageType;145 143 /** Image flags defined during creation or determined during open. */ 146 144 unsigned uImageFlags; … … 430 428 case VHD_FOOTER_DISK_TYPE_FIXED: 431 429 { 432 pImage-> enmImageType = VD_IMAGE_TYPE_FIXED;430 pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED; 433 431 } 434 432 break; 435 433 case VHD_FOOTER_DISK_TYPE_DYNAMIC: 436 434 { 437 pImage-> enmImageType = VD_IMAGE_TYPE_NORMAL;435 pImage->uImageFlags &= ~VD_IMAGE_FLAGS_FIXED; 438 436 } 439 437 break; 440 438 case VHD_FOOTER_DISK_TYPE_DIFFERENCING: 441 439 { 442 pImage->enmImageType = VD_IMAGE_TYPE_DIFF; 440 pImage->uImageFlags |= VD_IMAGE_FLAGS_DIFF; 441 pImage->uImageFlags &= ~VD_IMAGE_FLAGS_FIXED; 443 442 } 444 443 break; … … 470 469 LogFlowFunc(("DataOffset=%llu\n", pImage->u64DataOffset)); 471 470 472 if ( pImage->enmImageType == VD_IMAGE_TYPE_NORMAL || pImage->enmImageType == VD_IMAGE_TYPE_DIFF)471 if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED)) 473 472 rc = vhdLoadDynamicDisk(pImage, pImage->u64DataOffset); 474 473 … … 573 572 RTMemFree(pBlockAllocationTable); 574 573 575 if (pImage-> enmImageType == VD_IMAGE_TYPE_DIFF)574 if (pImage->uImageFlags & VD_IMAGE_FLAGS_DIFF) 576 575 memcpy(pImage->ParentUuid.au8, vhdDynamicDiskHeader.ParentUuid, sizeof(pImage->ParentUuid)); 577 576 … … 618 617 else 619 618 return 0; 620 }621 622 static int vhdGetImageType(void *pBackendData, PVDIMAGETYPE penmImageType)623 {624 PVHDIMAGE pImage = (PVHDIMAGE)pBackendData;625 int rc = VINF_SUCCESS;626 627 AssertPtr(pImage);628 AssertPtr(penmImageType);629 630 if (pImage)631 *penmImageType = pImage->enmImageType;632 else633 rc = VERR_VD_NOT_OPENED;634 635 return rc;636 619 } 637 620 … … 1313 1296 if (pImage && pImage->File != NIL_RTFILE) 1314 1297 { 1315 if ( pImage->enmImageType != VD_IMAGE_TYPE_FIXED)1298 if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED)) 1316 1299 { 1317 1300 pImage->ParentUuid = *pUuid; … … 1525 1508 * Internal: The actual code for VHD image creation, both fixed and dynamic. 1526 1509 */ 1527 static int vhdCreateImage(PVHDIMAGE pImage, VDIMAGETYPE enmType, 1528 uint64_t cbSize, unsigned uImageFlags, 1529 const char *pszComment, 1510 static int vhdCreateImage(PVHDIMAGE pImage, uint64_t cbSize, 1511 unsigned uImageFlags, const char *pszComment, 1530 1512 PCPDMMEDIAGEOMETRY pPCHSGeometry, 1531 1513 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 1540 1522 1541 1523 pImage->uOpenFlags = uOpenFlags; 1524 pImage->uImageFlags = uImageFlags; 1542 1525 1543 1526 pImage->pInterfaceError = VDInterfaceGet(pImage->pVDIfsDisk, VDINTERFACETYPE_ERROR); … … 1552 1535 pImage->File = File; 1553 1536 1554 pImage->enmImageType = enmType;1555 1537 pImage->cbSize = cbSize; 1556 1538 pImage->ImageUuid = *pUuid; … … 1579 1561 Footer.SavedState = 0; 1580 1562 1581 switch (enmType) 1582 { 1583 case VD_IMAGE_TYPE_FIXED: 1584 Footer.DiskType = RT_H2BE_U32(VHD_FOOTER_DISK_TYPE_FIXED); 1585 /* 1586 * Initialize fixed image. 1587 * "The size of the entire file is the size of the hard disk in 1588 * the guest operating system plus the size of the footer." 1589 */ 1590 pImage->u64DataOffset = VHD_FOOTER_DATA_OFFSET_FIXED; 1591 pImage->uCurrentEndOfFile = cbSize; 1592 rc = RTFileSetSize(File, pImage->uCurrentEndOfFile + sizeof(VHDFooter)); 1593 if (RT_FAILURE(rc)) 1594 { 1595 vhdError(pImage, rc, RT_SRC_POS, N_("VHD: cannot set the file size for '%s'"), pImage->pszFilename); 1596 goto out; 1597 } 1598 break; 1599 case VD_IMAGE_TYPE_NORMAL: 1600 case VD_IMAGE_TYPE_DIFF: 1601 /* 1602 * Initialize dynamic image. 1603 * 1604 * The overall structure of dynamic disk is: 1605 * 1606 * [Copy of hard disk footer (512 bytes)] 1607 * [Dynamic disk header (1024 bytes)] 1608 * [BAT (Block Allocation Table)] 1609 * [Parent Locators] 1610 * [Data block 1] 1611 * [Data block 2] 1612 * ... 1613 * [Data block N] 1614 * [Hard disk footer (512 bytes)] 1615 */ 1616 Footer.DiskType = enmType == VD_IMAGE_TYPE_DIFF ? 1617 RT_H2BE_U32(VHD_FOOTER_DISK_TYPE_DIFFERENCING) : 1618 RT_H2BE_U32(VHD_FOOTER_DISK_TYPE_DYNAMIC); 1619 /* We are half way thourgh with creation of image, let the caller know. */ 1620 if (pfnProgress) 1621 pfnProgress(NULL /* WARNING! pVM=NULL */, (uPercentStart + uPercentSpan) / 2, pvUser); 1622 1623 rc = vhdCreateDynamicImage(pImage, cbSize); 1624 if (RT_FAILURE(rc)) 1625 goto out; 1626 1627 break; 1628 default: 1629 /* Unknown/invalid image type. */ 1630 rc = VERR_NOT_IMPLEMENTED; 1631 break; 1563 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 1564 { 1565 Footer.DiskType = RT_H2BE_U32(VHD_FOOTER_DISK_TYPE_FIXED); 1566 /* 1567 * Initialize fixed image. 1568 * "The size of the entire file is the size of the hard disk in 1569 * the guest operating system plus the size of the footer." 1570 */ 1571 pImage->u64DataOffset = VHD_FOOTER_DATA_OFFSET_FIXED; 1572 pImage->uCurrentEndOfFile = cbSize; 1573 rc = RTFileSetSize(File, pImage->uCurrentEndOfFile + sizeof(VHDFooter)); 1574 if (RT_FAILURE(rc)) 1575 { 1576 vhdError(pImage, rc, RT_SRC_POS, N_("VHD: cannot set the file size for '%s'"), pImage->pszFilename); 1577 goto out; 1578 } 1579 } 1580 else 1581 { 1582 /* 1583 * Initialize dynamic image. 1584 * 1585 * The overall structure of dynamic disk is: 1586 * 1587 * [Copy of hard disk footer (512 bytes)] 1588 * [Dynamic disk header (1024 bytes)] 1589 * [BAT (Block Allocation Table)] 1590 * [Parent Locators] 1591 * [Data block 1] 1592 * [Data block 2] 1593 * ... 1594 * [Data block N] 1595 * [Hard disk footer (512 bytes)] 1596 */ 1597 Footer.DiskType = (uImageFlags & VD_IMAGE_FLAGS_DIFF) 1598 ? RT_H2BE_U32(VHD_FOOTER_DISK_TYPE_DIFFERENCING) 1599 : RT_H2BE_U32(VHD_FOOTER_DISK_TYPE_DYNAMIC); 1600 /* We are half way thourgh with creation of image, let the caller know. */ 1601 if (pfnProgress) 1602 pfnProgress(NULL /* WARNING! pVM=NULL */, (uPercentStart + uPercentSpan) / 2, pvUser); 1603 1604 rc = vhdCreateDynamicImage(pImage, cbSize); 1605 if (RT_FAILURE(rc)) 1606 goto out; 1632 1607 } 1633 1608 … … 1648 1623 1649 1624 /* Dynamic images contain a copy of the footer at the very beginning of the file. */ 1650 if ( enmType == VD_IMAGE_TYPE_NORMAL || enmType == VD_IMAGE_TYPE_DIFF)1625 if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED)) 1651 1626 { 1652 1627 /* Write the copy of the footer. */ … … 1666 1641 } 1667 1642 1668 static int vhdCreate(const char *pszFilename, VDIMAGETYPE enmType, 1669 uint64_t cbSize, unsigned uImageFlags, 1670 const char *pszComment, 1643 static int vhdCreate(const char *pszFilename, uint64_t cbSize, 1644 unsigned uImageFlags, const char *pszComment, 1671 1645 PCPDMMEDIAGEOMETRY pPCHSGeometry, 1672 1646 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 1711 1685 pImage->pVDIfsDisk = NULL; 1712 1686 1713 rc = vhdCreateImage(pImage, enmType,cbSize, uImageFlags, pszComment,1687 rc = vhdCreateImage(pImage, cbSize, uImageFlags, pszComment, 1714 1688 pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags, 1715 1689 pfnProgress, pvUser, uPercentStart, uPercentSpan); … … 1895 1869 /* pfnGetVersion */ 1896 1870 vhdGetVersion, 1897 /* pfnGetImageType */1898 vhdGetImageType,1899 1871 /* pfnGetSize */ 1900 1872 vhdGetSize, -
trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp
r17852 r17970 439 439 /** Open flags passed by VBoxHD layer. */ 440 440 unsigned uOpenFlags; 441 /** Image type. */442 VDIMAGETYPE enmImageType;443 441 /** Image flags defined during creation or determined during open. */ 444 442 unsigned uImageFlags; … … 2057 2055 if ( !strcmp(pszCreateType, "twoGbMaxExtentSparse") 2058 2056 || !strcmp(pszCreateType, "twoGbMaxExtentFlat")) 2059 pImage->uImageFlags = VD_VMDK_IMAGE_FLAGS_SPLIT_2G;2057 pImage->uImageFlags |= VD_VMDK_IMAGE_FLAGS_SPLIT_2G; 2060 2058 else if ( !strcmp(pszCreateType, "partitionedDevice") 2061 2059 || !strcmp(pszCreateType, "fullDevice")) 2062 pImage->uImageFlags = VD_VMDK_IMAGE_FLAGS_RAWDISK;2060 pImage->uImageFlags |= VD_VMDK_IMAGE_FLAGS_RAWDISK; 2063 2061 else if (!strcmp(pszCreateType, "streamOptimized")) 2064 pImage->uImageFlags = VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED; 2065 else 2066 pImage->uImageFlags = 0; 2062 pImage->uImageFlags |= VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED; 2067 2063 RTStrFree((char *)(void *)pszCreateType); 2068 2064 … … 3115 3111 } 3116 3112 3117 pImage->enmImageType = VD_IMAGE_TYPE_NORMAL;3118 3113 for (unsigned i = 0; i < pImage->cExtents; i++) 3119 3114 { … … 3122 3117 || pImage->pExtents[i].enmType == VMDKETYPE_ZERO) 3123 3118 { 3124 pImage-> enmImageType = VD_IMAGE_TYPE_FIXED;3119 pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED; 3125 3120 break; 3126 3121 } … … 3391 3386 * Internal: create a regular (i.e. file-backed) VMDK image. 3392 3387 */ 3393 static int vmdkCreateRegularImage(PVMDKIMAGE pImage, VDIMAGETYPE enmType,3394 u int64_t cbSize, unsigned uImageFlags,3388 static int vmdkCreateRegularImage(PVMDKIMAGE pImage, uint64_t cbSize, 3389 unsigned uImageFlags, 3395 3390 PFNVMPROGRESS pfnProgress, void *pvUser, 3396 3391 unsigned uPercentStart, unsigned uPercentSpan) … … 3419 3414 3420 3415 /* Create searate descriptor file if necessary. */ 3421 if (cExtents != 1 || enmType == VD_IMAGE_TYPE_FIXED)3416 if (cExtents != 1 || (uImageFlags & VD_IMAGE_FLAGS_FIXED)) 3422 3417 { 3423 3418 rc = vmdkFileOpen(pImage, &pImage->pFile, pImage->pszFilename, … … 3440 3435 * with RTMemTmpFree, which must be used as in other code paths 3441 3436 * StrDup is not usable. */ 3442 if (cExtents == 1 && enmType != VD_IMAGE_TYPE_FIXED)3437 if (cExtents == 1 && !(uImageFlags & VD_IMAGE_FLAGS_FIXED)) 3443 3438 { 3444 3439 char *pszBasename = (char *)RTMemTmpAlloc(cbBasenameSubstr); … … 3455 3450 char *pszTmp; 3456 3451 size_t cbTmp; 3457 if ( enmType == VD_IMAGE_TYPE_FIXED)3452 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 3458 3453 { 3459 3454 if (cExtents == 1) … … 3496 3491 if (RT_FAILURE(rc)) 3497 3492 return vmdkError(pImage, rc, RT_SRC_POS, N_("VMDK: could not create new file '%s'"), pExtent->pszFullname); 3498 if ( enmType == VD_IMAGE_TYPE_FIXED)3493 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 3499 3494 { 3500 3495 rc = vmdkFileSetSize(pExtent->pFile, cbExtent); … … 3546 3541 3547 3542 /* Place descriptor file information (where integrated). */ 3548 if (cExtents == 1 && enmType != VD_IMAGE_TYPE_FIXED)3543 if (cExtents == 1 && !(uImageFlags & VD_IMAGE_FLAGS_FIXED)) 3549 3544 { 3550 3545 pExtent->uDescriptorSector = 1; … … 3555 3550 } 3556 3551 3557 if ( enmType == VD_IMAGE_TYPE_NORMAL)3552 if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED)) 3558 3553 { 3559 3554 uint64_t cSectorsPerGDE, cSectorsPerGD; … … 3578 3573 pExtent->fMetaDirty = true; 3579 3574 3580 if ( enmType == VD_IMAGE_TYPE_NORMAL)3575 if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED)) 3581 3576 { 3582 3577 rc = vmdkCreateGrainDirectory(pExtent, … … 3599 3594 3600 3595 const char *pszDescType = NULL; 3601 if ( enmType == VD_IMAGE_TYPE_FIXED)3596 if (uImageFlags & VD_IMAGE_FLAGS_FIXED) 3602 3597 { 3603 3598 pszDescType = (cExtents == 1) 3604 3599 ? "monolithicFlat" : "twoGbMaxExtentFlat"; 3605 3600 } 3606 else if (enmType == VD_IMAGE_TYPE_NORMAL)3601 else 3607 3602 { 3608 3603 if (pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED) … … 3614 3609 } 3615 3610 } 3616 else3617 AssertMsgFailed(("invalid image type %d\n", enmType));3618 3611 rc = vmdkDescBaseSetStr(pImage, &pImage->Descriptor, "createType", 3619 3612 pszDescType); … … 3627 3620 * existence on hosted environments. 3628 3621 */ 3629 static int vmdkCreateImage(PVMDKIMAGE pImage, VDIMAGETYPE enmType, 3630 uint64_t cbSize, unsigned uImageFlags, 3631 const char *pszComment, 3622 static int vmdkCreateImage(PVMDKIMAGE pImage, uint64_t cbSize, 3623 unsigned uImageFlags, const char *pszComment, 3632 3624 PCPDMMEDIAGEOMETRY pPCHSGeometry, 3633 3625 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 3657 3649 } 3658 3650 3659 if ( enmType == VD_IMAGE_TYPE_FIXED3651 if ( (uImageFlags & VD_IMAGE_FLAGS_FIXED) 3660 3652 && (uImageFlags & VD_VMDK_IMAGE_FLAGS_RAWDISK)) 3661 3653 { … … 3667 3659 rc = vmdkCreateRawImage(pImage, pRaw, cbSize); 3668 3660 } 3669 else if ( enmType == VD_IMAGE_TYPE_FIXED 3670 || enmType == VD_IMAGE_TYPE_NORMAL) 3661 else 3671 3662 { 3672 3663 /* Regular fixed or sparse image (monolithic or split). */ 3673 rc = vmdkCreateRegularImage(pImage, enmType,cbSize, uImageFlags,3664 rc = vmdkCreateRegularImage(pImage, cbSize, uImageFlags, 3674 3665 pfnProgress, pvUser, uPercentStart, 3675 3666 uPercentSpan * 95 / 100); 3676 }3677 else3678 {3679 /* Unknown/invalid image type. */3680 rc = VERR_NOT_IMPLEMENTED;3681 3667 } 3682 3668 … … 3688 3674 uPercentStart + uPercentSpan * 98 / 100, pvUser); 3689 3675 3690 pImage->enmImageType = enmType;3691 3676 pImage->cbSize = cbSize; 3692 3677 … … 3819 3804 AssertPtr(pImage); 3820 3805 3821 if (pImage->enmImageType) 3822 { 3823 if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)) 3824 { 3825 /* Mark all extents as clean. */ 3826 for (unsigned i = 0; i < pImage->cExtents; i++) 3806 if (!(pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)) 3807 { 3808 /* Mark all extents as clean. */ 3809 for (unsigned i = 0; i < pImage->cExtents; i++) 3810 { 3811 if (( pImage->pExtents[i].enmType == VMDKETYPE_HOSTED_SPARSE 3812 #ifdef VBOX_WITH_VMDK_ESX 3813 || pImage->pExtents[i].enmType == VMDKETYPE_ESX_SPARSE 3814 #endif /* VBOX_WITH_VMDK_ESX */ 3815 ) 3816 && pImage->pExtents[i].fUncleanShutdown) 3827 3817 { 3828 if (( pImage->pExtents[i].enmType == VMDKETYPE_HOSTED_SPARSE 3829 #ifdef VBOX_WITH_VMDK_ESX 3830 || pImage->pExtents[i].enmType == VMDKETYPE_ESX_SPARSE 3831 #endif /* VBOX_WITH_VMDK_ESX */ 3832 ) 3833 && pImage->pExtents[i].fUncleanShutdown) 3834 { 3835 pImage->pExtents[i].fUncleanShutdown = false; 3836 pImage->pExtents[i].fMetaDirty = true; 3837 } 3818 pImage->pExtents[i].fUncleanShutdown = false; 3819 pImage->pExtents[i].fMetaDirty = true; 3838 3820 } 3839 3821 } 3840 (void)vmdkFlushImage(pImage); 3841 } 3822 } 3823 (void)vmdkFlushImage(pImage); 3824 3842 3825 if (pImage->pExtents != NULL) 3843 3826 { … … 4352 4335 4353 4336 /** @copydoc VBOXHDDBACKEND::pfnCreate */ 4354 static int vmdkCreate(const char *pszFilename, VDIMAGETYPE enmType, 4355 uint64_t cbSize, unsigned uImageFlags, 4356 const char *pszComment, 4337 static int vmdkCreate(const char *pszFilename, uint64_t cbSize, 4338 unsigned uImageFlags, const char *pszComment, 4357 4339 PCPDMMEDIAGEOMETRY pPCHSGeometry, 4358 4340 PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid, … … 4362 4344 void **ppBackendData) 4363 4345 { 4364 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));4346 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)); 4365 4347 int rc; 4366 4348 PVMDKIMAGE pImage; … … 4385 4367 } 4386 4368 4387 /* @todo A quick hack to support differencing images in VMDK. */4388 if (enmType == VD_IMAGE_TYPE_DIFF)4389 enmType = VD_IMAGE_TYPE_NORMAL;4390 4391 4369 /* Check remaining arguments. */ 4392 4370 if ( !VALID_PTR(pszFilename) 4393 4371 || !*pszFilename 4394 4372 || strchr(pszFilename, '"') 4395 || (enmType != VD_IMAGE_TYPE_NORMAL && enmType != VD_IMAGE_TYPE_FIXED)4396 4373 || !VALID_PTR(pPCHSGeometry) 4397 4374 || !VALID_PTR(pLCHSGeometry) 4398 4375 || ( (uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED) 4399 && ( (uImageFlags & ~VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED) 4400 || (enmType != VD_IMAGE_TYPE_NORMAL)))) 4376 && (uImageFlags & ~(VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED | VD_IMAGE_FLAGS_DIFF)))) 4401 4377 { 4402 4378 rc = VERR_INVALID_PARAMETER; … … 4425 4401 } 4426 4402 4427 rc = vmdkCreateImage(pImage, enmType,cbSize, uImageFlags, pszComment,4403 rc = vmdkCreateImage(pImage, cbSize, uImageFlags, pszComment, 4428 4404 pPCHSGeometry, pLCHSGeometry, pUuid, 4429 4405 pfnProgress, pvUser, uPercentStart, uPercentSpan); … … 5045 5021 } 5046 5022 5047 /** @copydoc VBOXHDDBACKEND::pfnGetImageType */5048 static int vmdkGetImageType(void *pBackendData, PVDIMAGETYPE penmImageType)5049 {5050 LogFlowFunc(("pBackendData=%#p penmImageType=%#p\n", pBackendData, penmImageType));5051 PVMDKIMAGE pImage = (PVMDKIMAGE)pBackendData;5052 int rc = VINF_SUCCESS;5053 5054 AssertPtr(pImage);5055 AssertPtr(penmImageType);5056 5057 if (pImage && pImage->cExtents != 0)5058 *penmImageType = pImage->enmImageType;5059 else5060 rc = VERR_VD_NOT_OPENED;5061 5062 LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));5063 return rc;5064 }5065 5066 5023 /** @copydoc VBOXHDDBACKEND::pfnGetSize */ 5067 5024 static uint64_t vmdkGetSize(void *pBackendData) … … 5943 5900 /* pfnGetVersion */ 5944 5901 vmdkGetVersion, 5945 /* pfnGetImageType */5946 vmdkGetImageType,5947 5902 /* pfnGetSize */ 5948 5903 vmdkGetSize, -
trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp
r17836 r17970 56 56 57 57 static int tstVDCreateDelete(const char *pszBackend, const char *pszFilename, 58 uint64_t cbSize, VDIMAGETYPE enmType, 59 unsigned uFlags, bool fDelete) 58 uint64_t cbSize, unsigned uFlags, bool fDelete) 60 59 { 61 60 int rc; … … 90 89 CHECK("VDCreate()"); 91 90 92 rc = VDCreateBase(pVD, pszBackend, pszFilename, enmType,cbSize,91 rc = VDCreateBase(pVD, pszBackend, pszFilename, cbSize, 93 92 uFlags, "Test image", &PCHS, &LCHS, NULL, 94 93 VD_OPEN_FLAGS_NORMAL, NULL, NULL); … … 556 555 else 557 556 { 558 rc = VDCreateBase(pVD, pszBackend, pszBaseFilename, 559 VD_IMAGE_TYPE_NORMAL, u64DiskSize, 557 rc = VDCreateBase(pVD, pszBackend, pszBaseFilename, u64DiskSize, 560 558 VD_IMAGE_FLAGS_NONE, "Test image", 561 559 &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL, … … 667 665 } 668 666 669 rc = VDCreateBase(pVD, pszBackend, pszFilename, 670 VD_IMAGE_TYPE_NORMAL, u64DiskSize, 667 rc = VDCreateBase(pVD, pszBackend, pszFilename, u64DiskSize, 671 668 VD_IMAGE_FLAGS_NONE, "Test image", 672 669 &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL, … … 744 741 745 742 static int tstVmdkCreateRenameOpen(const char *src, const char *dst, 746 uint64_t cbSize, VDIMAGETYPE enmType, 747 unsigned uFlags) 748 { 749 int rc = tstVDCreateDelete("VMDK", src, cbSize, enmType, uFlags, false); 743 uint64_t cbSize, unsigned uFlags) 744 { 745 int rc = tstVDCreateDelete("VMDK", src, cbSize, uFlags, false); 750 746 if (RT_FAILURE(rc)) 751 747 return rc; … … 802 798 { 803 799 int rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", "tmpVDRename.vmdk", _4G, 804 VD_IMAGE_TYPE_NORMAL,VD_IMAGE_FLAGS_NONE);800 VD_IMAGE_FLAGS_NONE); 805 801 if (RT_FAILURE(rc)) 806 802 { … … 809 805 } 810 806 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", "tmpVDRename.vmdk", _4G, 811 VD_ IMAGE_TYPE_NORMAL, VD_VMDK_IMAGE_FLAGS_SPLIT_2G);807 VD_VMDK_IMAGE_FLAGS_SPLIT_2G); 812 808 if (RT_FAILURE(rc)) 813 809 { … … 816 812 } 817 813 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", DST_PATH, _4G, 818 VD_IMAGE_ TYPE_NORMAL, VD_IMAGE_FLAGS_NONE);814 VD_IMAGE_FLAGS_NONE); 819 815 if (RT_FAILURE(rc)) 820 816 { … … 823 819 } 824 820 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", DST_PATH, _4G, 825 VD_ IMAGE_TYPE_NORMAL, VD_VMDK_IMAGE_FLAGS_SPLIT_2G);821 VD_VMDK_IMAGE_FLAGS_SPLIT_2G); 826 822 if (RT_FAILURE(rc)) 827 823 { … … 836 832 837 833 rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", DST_PATH, _4G, 838 VD_ IMAGE_TYPE_NORMAL, VD_VMDK_IMAGE_FLAGS_SPLIT_2G);834 VD_VMDK_IMAGE_FLAGS_SPLIT_2G); 839 835 if (RT_SUCCESS(rc)) 840 836 { … … 902 898 #ifdef VMDK_TEST 903 899 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 904 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 905 true); 900 VD_IMAGE_FLAGS_NONE, true); 906 901 if (RT_FAILURE(rc)) 907 902 { … … 910 905 } 911 906 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 912 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 913 false); 907 VD_IMAGE_FLAGS_NONE, false); 914 908 if (RT_FAILURE(rc)) 915 909 { … … 928 922 #ifdef VDI_TEST 929 923 rc = tstVDCreateDelete("VDI", "tmpVDCreate.vdi", 2 * _4G, 930 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 931 true); 924 VD_IMAGE_FLAGS_NONE, true); 932 925 if (RT_FAILURE(rc)) 933 926 { … … 936 929 } 937 930 rc = tstVDCreateDelete("VDI", "tmpVDCreate.vdi", 2 * _4G, 938 VD_IMAGE_TYPE_FIXED, VD_IMAGE_FLAGS_NONE, 939 true); 931 VD_IMAGE_FLAGS_NONE, true); 940 932 if (RT_FAILURE(rc)) 941 933 { … … 946 938 #ifdef VMDK_TEST 947 939 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 948 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 949 true); 940 VD_IMAGE_FLAGS_NONE, true); 950 941 if (RT_FAILURE(rc)) 951 942 { … … 954 945 } 955 946 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 956 VD_IMAGE_TYPE_NORMAL, VD_VMDK_IMAGE_FLAGS_SPLIT_2G, 957 true); 947 VD_VMDK_IMAGE_FLAGS_SPLIT_2G, true); 958 948 if (RT_FAILURE(rc)) 959 949 { … … 962 952 } 963 953 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 964 VD_IMAGE_TYPE_FIXED, VD_IMAGE_FLAGS_NONE, 965 true); 954 VD_IMAGE_FLAGS_FIXED, true); 966 955 if (RT_FAILURE(rc)) 967 956 { … … 970 959 } 971 960 rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G, 972 VD_IMAGE_ TYPE_FIXED,VD_VMDK_IMAGE_FLAGS_SPLIT_2G,961 VD_IMAGE_FLAGS_FIXED | VD_VMDK_IMAGE_FLAGS_SPLIT_2G, 973 962 true); 974 963 if (RT_FAILURE(rc)) … … 980 969 #ifdef VHD_TEST 981 970 rc = tstVDCreateDelete("VHD", "tmpVDCreate.vhd", 2 * _4G, 982 VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE, 983 true); 971 VD_IMAGE_FLAGS_NONE, true); 984 972 if (RT_FAILURE(rc)) 985 973 { … … 988 976 } 989 977 rc = tstVDCreateDelete("VHD", "tmpVDCreate.vhd", 2 * _4G, 990 VD_IMAGE_TYPE_FIXED, VD_IMAGE_FLAGS_NONE, 991 true); 978 VD_IMAGE_FLAGS_FIXED, true); 992 979 if (RT_FAILURE(rc)) 993 980 {
Note:
See TracChangeset
for help on using the changeset viewer.