VirtualBox

Changeset 17970 in vbox for trunk/src/VBox/Devices


Ignore:
Timestamp:
Mar 16, 2009 7:08:16 PM (16 years ago)
Author:
vboxsync
Message:

API/HardDisk, Storage/VBoxHDD, Frontend/VBoxManage: eliminated base image type, which led to much unnecessary code duplication. Was triggered by VBoxManage finally being able to create all image variants the backends can support.

Location:
trunk/src/VBox/Devices/Storage
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/ISCSIHDDCore.cpp

    r17798 r17970  
    26492649
    26502650/** @copydoc VBOXHDDBACKEND::pfnCreate */
    2651 static int iscsiCreate(const char *pszFilename, VDIMAGETYPE enmType,
    2652                        uint64_t cbSize, unsigned uImageFlags,
    2653                        const char *pszComment,
     2651static int iscsiCreate(const char *pszFilename, uint64_t cbSize,
     2652                       unsigned uImageFlags, const char *pszComment,
    26542653                       PCPDMMEDIAGEOMETRY pPCHSGeometry,
    26552654                       PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    26592658                       void **ppBackendData)
    26602659{
    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));
    26622661    int rc = VERR_NOT_SUPPORTED;
    26632662
     
    28832882
    28842883
    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     else
    2898         rc = VERR_VD_NOT_OPENED;
    2899 
    2900     LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));
    2901     return rc;
    2902 }
    2903 
    2904 
    29052884/** @copydoc VBOXHDDBACKEND::pfnGetSize */
    29062885static uint64_t iscsiGetSize(void *pBackendData)
     
    30122991    NOREF(pImage);
    30132992
    3014     uImageFlags = VD_IMAGE_FLAGS_NONE;
     2993    uImageFlags = VD_IMAGE_FLAGS_FIXED;
    30152994
    30162995    LogFlowFunc(("returns %#x\n", uImageFlags));
     
    34883467    /* pfnGetVersion */
    34893468    iscsiGetVersion,
    3490     /* pfnGetImageType */
    3491     iscsiGetImageType,
    34923469    /* pfnGetSize */
    34933470    iscsiGetSize,
  • trunk/src/VBox/Devices/Storage/RawHDDCore.cpp

    r16873 r17970  
    5757    /** Open flags passed by VBoxHD layer. */
    5858    unsigned        uOpenFlags;
    59     /** Image type. */
    60     VDIMAGETYPE     enmImageType;
    6159    /** Image flags defined during creation or determined during open. */
    6260    unsigned        uImageFlags;
     
    146144        goto out;
    147145    }
    148     pImage->enmImageType = VD_IMAGE_TYPE_FIXED;
     146    pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED;
    149147
    150148out:
     
    157155 * Internal: Create a raw image.
    158156 */
    159 static int rawCreateImage(PRAWIMAGE pImage, VDIMAGETYPE enmType,
    160                           uint64_t cbSize, unsigned uImageFlags,
    161                           const char *pszComment,
     157static int rawCreateImage(PRAWIMAGE pImage, uint64_t cbSize,
     158                          unsigned uImageFlags, const char *pszComment,
    162159                          PCPDMMEDIAGEOMETRY pPCHSGeometry,
    163160                          PCPDMMEDIAGEOMETRY pLCHSGeometry,
     
    172169    void *pvBuf = NULL;
    173170
    174     if (enmType != VD_IMAGE_TYPE_FIXED)
     171    if (uImageFlags & VD_IMAGE_FLAGS_DIFF)
    175172    {
    176173        rc = rawError(pImage, VERR_VD_RAW_INVALID_TYPE, RT_SRC_POS, N_("Raw: cannot create diff image '%s'"), pImage->pszFilename);
    177174        goto out;
    178175    }
    179 
    180     pImage->enmImageType = enmType;
     176    uImageFlags |= VD_IMAGE_FLAGS_FIXED;
     177
    181178    pImage->uImageFlags = uImageFlags;
    182179    pImage->PCHSGeometry = *pPCHSGeometry;
     
    256253                    uPercentStart + uPercentSpan * 98 / 100, pvUser);
    257254
    258     pImage->enmImageType = enmType;
    259255    pImage->cbSize = cbSize;
    260256
     
    279275    Assert(pImage);
    280276
    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);
    286279    if (pImage->File != NIL_RTFILE)
    287280    {
     
    374367
    375368/** @copydoc VBOXHDDBACKEND::pfnCreate */
    376 static int rawCreate(const char *pszFilename, VDIMAGETYPE enmType,
    377                      uint64_t cbSize, unsigned uImageFlags,
    378                      const char *pszComment,
     369static int rawCreate(const char *pszFilename, uint64_t cbSize,
     370                     unsigned uImageFlags, const char *pszComment,
    379371                     PCPDMMEDIAGEOMETRY pPCHSGeometry,
    380372                     PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    384376                     void **ppBackendData)
    385377{
    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));
    387379    int rc;
    388380    PRAWIMAGE pImage;
     
    411403    if (   !VALID_PTR(pszFilename)
    412404        || !*pszFilename
    413         || (enmType != VD_IMAGE_TYPE_FIXED)
    414405        || !VALID_PTR(pPCHSGeometry)
    415406        || !VALID_PTR(pLCHSGeometry))
     
    429420    pImage->pVDIfsDisk = pVDIfsDisk;
    430421
    431     rc = rawCreateImage(pImage, enmType, cbSize, uImageFlags, pszComment,
     422    rc = rawCreateImage(pImage, cbSize, uImageFlags, pszComment,
    432423                        pPCHSGeometry, pLCHSGeometry,
    433424                        pfnProgress, pvUser, uPercentStart, uPercentSpan);
     
    563554    else
    564555        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     else
    580         rc = VERR_VD_NOT_OPENED;
    581 
    582     LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));
    583     return rc;
    584556}
    585557
     
    11101082    /* pfnGetVersion */
    11111083    rawGetVersion,
    1112     /* pfnGetImageType */
    1113     rawGetImageType,
    11141084    /* pfnGetSize */
    11151085    rawGetSize,
  • trunk/src/VBox/Devices/Storage/VBoxHDD-Internal.h

    r16873 r17970  
    105105     * @param   pszFilename     Name of the image file to create. Guaranteed to be available and
    106106     *                          unchanged during the lifetime of this image.
    107      * @param   enmType         Image type. Both base and diff image types are valid.
    108107     * @param   cbSize          Image size in bytes.
    109108     * @param   uImageFlags     Flags specifying special image features.
     
    120119     * @param   ppvBackendData  Opaque state data for this image.
    121120     */
    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,
    125123                                          PCPDMMEDIAGEOMETRY pPCHSGeometry,
    126124                                          PCPDMMEDIAGEOMETRY pLCHSGeometry,
     
    222220
    223221    /**
    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     /**
    233222     * Get the capacity of a disk image.
    234223     *
  • trunk/src/VBox/Devices/Storage/VBoxHDD.cpp

    r17836 r17970  
    6161    /** Data managed by the backend which keeps the actual info. */
    6262    void            *pvBackendData;
    63     /** Cached sanitized image type. */
    64     VDIMAGETYPE     enmImageType;
     63    /** Cached sanitized image flags. */
     64    unsigned        uImageFlags;
    6565    /** Image open flags (only those handled generically in this code and which
    6666     * the backends will never ever see). */
     
    10521052        }
    10531053
    1054         VDIMAGETYPE enmImageType;
    1055         rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData,
    1056                                               &enmImageType);
     1054        unsigned uImageFlags;
     1055        uImageFlags = pImage->Backend->pfnGetImageFlags(pImage->pvBackendData);
    10571056        /* Check image type. As the image itself has only partial knowledge
    10581057         * whether it's a base image or not, this info is derived here. The
     
    10611060         * and diff images, so this must be corrected here. */
    10621061        if (RT_FAILURE(rc))
    1063             enmImageType = VD_IMAGE_TYPE_INVALID;
     1062            uImageFlags = VD_IMAGE_FLAGS_NONE;
    10641063        if (    RT_SUCCESS(rc)
    10651064            &&  !(uOpenFlags & VD_OPEN_FLAGS_INFO))
    10661065        {
    10671066            if (    pDisk->cImages == 0
    1068                 &&  enmImageType != VD_IMAGE_TYPE_FIXED
    1069                 &&  enmImageType != VD_IMAGE_TYPE_NORMAL)
     1067                &&  (uImageFlags & VD_IMAGE_FLAGS_DIFF))
    10701068            {
    10711069                rc = VERR_VD_INVALID_TYPE;
     
    10741072            else if (pDisk->cImages != 0)
    10751073            {
    1076                 if (    enmImageType != VD_IMAGE_TYPE_NORMAL
    1077                     &&  enmImageType != VD_IMAGE_TYPE_DIFF)
     1074                if (uImageFlags & VD_IMAGE_FLAGS_FIXED)
    10781075                {
    10791076                    rc = VERR_VD_INVALID_TYPE;
     
    10811078                }
    10821079                else
    1083                     enmImageType = VD_IMAGE_TYPE_DIFF;
     1080                    uImageFlags |= VD_IMAGE_FLAGS_DIFF;
    10841081            }
    10851082        }
    1086         pImage->enmImageType = enmImageType;
     1083        pImage->uImageFlags = uImageFlags;
    10871084
    10881085        /* Force sane optimization settings. It's not worth avoiding writes
    10891086         * 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)
    10911088            pImage->uOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME;
    10921089
     
    11821179 * @param   pszBackend      Name of the image file backend to use.
    11831180 * @param   pszFilename     Name of the image file to create.
    1184  * @param   enmType         Image type, only base image types are acceptable.
    11851181 * @param   cbSize          Image size in bytes.
    11861182 * @param   uImageFlags     Flags specifying special image features.
     
    11941190 */
    11951191VBOXDDU_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,
    11991194                               PCPDMMEDIAGEOMETRY pPCHSGeometry,
    12001195                               PCPDMMEDIAGEOMETRY pLCHSGeometry,
     
    12071202    RTUUID uuid;
    12081203
    1209     LogFlowFunc(("pDisk=%#p pszBackend=\"%s\" pszFilename=\"%s\" enmType=%#x cbSize=%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,
    12111206                 pPCHSGeometry->cCylinders, pPCHSGeometry->cHeads,
    12121207                 pPCHSGeometry->cSectors, pLCHSGeometry->cCylinders,
     
    12331228                           ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
    12341229                           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);
    12381230        AssertMsgBreakStmt(cbSize,
    12391231                           ("cbSize=%llu\n", cbSize),
    12401232                           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),
    12421235                           ("uImageFlags=%#x\n", uImageFlags),
    12431236                           rc = VERR_INVALID_PARAMETER);
     
    13131306
    13141307        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,
    13161310                                        uImageFlags, pszComment, pPCHSGeometry,
    13171311                                        pLCHSGeometry, pUuid,
     
    13251319        if (RT_SUCCESS(rc))
    13261320        {
    1327             pImage->enmImageType = enmType;
     1321            pImage->uImageFlags = uImageFlags;
    13281322
    13291323            /* Force sane optimization settings. It's not worth avoiding writes
    13301324             * 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)
    13321326                pImage->uOpenFlags |= VD_OPEN_FLAGS_HONOR_SAME;
    13331327
     
    15181512
    15191513        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,
    15221515                                        uImageFlags, pszComment,
    15231516                                        &pDisk->PCHSGeometry,
     
    15321525        if (RT_SUCCESS(rc) && pDisk->cImages != 0)
    15331526        {
    1534             pImage->enmImageType = VD_IMAGE_TYPE_DIFF;
     1527            pImage->uImageFlags |= VD_IMAGE_FLAGS_DIFF;
    15351528
    15361529            /* Switch previous image to read-only mode. */
     
    19521945                           rc = VERR_INVALID_PARAMETER);
    19531946
    1954         /* Collect properties of source image. */
    1955         VDIMAGETYPE enmTypeFrom = pImageFrom->enmImageType;
    1956 
    19571947        uint64_t cbSizeFrom;
    19581948        cbSizeFrom = pImageFrom->Backend->pfnGetSize(pImageFrom->pvBackendData);
     
    20102000         * calls to the backend. Unifies the code and reduces the API
    20112001         * dependencies. */
    2012         if (enmTypeFrom == VD_IMAGE_TYPE_DIFF)
     2002        if (uImageFlags & VD_IMAGE_FLAGS_DIFF)
    20132003        {
    20142004            rc = VDCreateDiff(pDiskTo, pszBackend, pszFilename, uImageFlags,
    20152005                              szComment, &ImageUuid, &ParentUuid, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
    20162006        } 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,
    20242013                              &PCHSGeometryFrom, &LCHSGeometryFrom,
    20252014                              NULL, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
     
    28142803
    28152804/**
    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     do
    2832     {
    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_FIRST
    2846             &&  pImage->enmImageType <= VD_IMAGE_TYPE_DIFF)
    2847         {
    2848             *penmType = pImage->enmImageType;
    2849             rc = VINF_SUCCESS;
    2850         }
    2851         else
    2852             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 /**
    28612805 * List the capabilities of image backend in HDD container.
    28622806 *
     
    28722816    int rc = VINF_SUCCESS;
    28732817
    2874     LogFlowFunc(("pDisk=%#p nImage=%u penmType=%#p\n",
     2818    LogFlowFunc(("pDisk=%#p nImage=%u pBackendInfo=%#p\n",
    28752819                 pDisk, nImage, pBackendInfo));
    28762820    do
     
    28882832        AssertPtrBreakStmt(pImage, rc = VERR_VD_IMAGE_NOT_FOUND);
    28892833
    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;
    29012838    } while (0);
    29022839
  • trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp

    r16873 r17970  
    5555static void vdiInitPreHeader(PVDIPREHEADER pPreHdr);
    5656static 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);
     57static void vdiInitHeader(PVDIHEADER pHeader, uint32_t uImageFlags,
     58                          const char *pszComment, uint64_t cbDisk,
     59                          uint32_t cbBlock, uint32_t cbBlockExtra);
    6160static int  vdiValidateHeader(PVDIHEADER pHeader);
    6261static void vdiSetupImageDesc(PVDIIMAGEDESC pImage);
     
    127126
    128127/**
    129  * Internal: translate VD image type enum to VDI image type enum.
     128 * Internal: translate VD image flags to VDI image type enum.
    130129 */
    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     }
     130static 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;
    147138}
    148139
     
    150141 * Internal: translate VDI image type enum to VD image type enum.
    151142 */
    152 static VDIMAGETYPE vdiTranslateTypeVDI2VD(VDIIMAGETYPE enmType)
     143static unsigned vdiTranslateVDI2ImageFlags(VDIIMAGETYPE enmType)
    153144{
    154145    switch (enmType)
    155146    {
    156147        case VDI_IMAGE_TYPE_NORMAL:
    157             return VD_IMAGE_TYPE_NORMAL;
     148            return VD_IMAGE_FLAGS_NONE;
    158149        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;
    162151        case VDI_IMAGE_TYPE_DIFF:
    163             return VD_IMAGE_TYPE_DIFF;
     152            return VD_IMAGE_FLAGS_DIFF;
    164153        default:
    165154            AssertMsgFailed(("invalid VDIIMAGETYPE enmType=%d\n", (int)enmType));
    166             return VD_IMAGE_TYPE_INVALID;
     155            return VD_IMAGE_FLAGS_NONE;
    167156    }
    168157}
     
    172161 * @param   pHeader     Assumes it was initially initialized to all zeros.
    173162 */
    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)
     163static void vdiInitHeader(PVDIHEADER pHeader, uint32_t uImageFlags,
     164                          const char *pszComment, uint64_t cbDisk,
     165                          uint32_t cbBlock, uint32_t cbBlockExtra)
    178166{
    179167    pHeader->uVersion = VDI_IMAGE_VERSION;
    180168    pHeader->u.v1.cbHeader = sizeof(VDIHEADER1);
    181     pHeader->u.v1.u32Type = (uint32_t)vdiTranslateTypeVD2VDI(enmType);
     169    pHeader->u.v1.u32Type = (uint32_t)vdiTranslateImageFlags2VDI(uImageFlags);
    182170    pHeader->u.v1.fFlags = (uImageFlags & VD_VDI_IMAGE_FLAGS_ZERO_EXPAND) ? 1 : 0;
    183171#ifdef VBOX_STRICT
     
    351339{
    352340    pImage->uImageFlags        = getImageFlags(&pImage->Header);
     341    pImage->uImageFlags       |= vdiTranslateVDI2ImageFlags(getImageType(&pImage->Header));
    353342    pImage->offStartBlocks     = getImageBlocksOffset(&pImage->Header);
    354343    pImage->offStartData       = getImageDataOffset(&pImage->Header);
     
    363352 * Internal: Create VDI image file.
    364353 */
    365 static int vdiCreateImage(PVDIIMAGEDESC pImage, VDIMAGETYPE enmType,
    366                           uint64_t cbSize, unsigned uImageFlags,
    367                           const char *pszComment,
     354static int vdiCreateImage(PVDIIMAGEDESC pImage, uint64_t cbSize,
     355                          unsigned uImageFlags, const char *pszComment,
    368356                          PCPDMMEDIAGEOMETRY pPCHSGeometry,
    369357                          PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    392380
    393381    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);
    395383    /* Save PCHS geometry. Not much work, and makes the flow of information
    396384     * quite a bit clearer - relying on the higher level isn't obvious. */
     
    409397    }
    410398
    411     if (enmType != VD_IMAGE_TYPE_FIXED)
     399    if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED))
    412400    {
    413401        /* for growing images mark all blocks in paBlocks as free. */
     
    439427              + (uint64_t)getImageBlocks(&pImage->Header) * pImage->cbTotalBlockData;
    440428
    441     if (enmType == VD_IMAGE_TYPE_FIXED)
     429    if (uImageFlags & VD_IMAGE_FLAGS_FIXED)
    442430    {
    443431        /* Check the free space on the disk and leave early if there is not
     
    452440    }
    453441
    454     if (enmType == VD_IMAGE_TYPE_FIXED)
     442    if (uImageFlags & VD_IMAGE_FLAGS_FIXED)
    455443    {
    456444        /*
     
    503491    }
    504492
    505     if (enmType == VD_IMAGE_TYPE_FIXED)
     493    if (uImageFlags & VD_IMAGE_FLAGS_FIXED)
    506494    {
    507495        /* Fill image with zeroes. We do this for every fixed-size image since on some systems
     
    853841
    854842/** @copydoc VBOXHDDBACKEND::pfnCreate */
    855 static int vdiCreate(const char *pszFilename, VDIMAGETYPE enmType,
    856                      uint64_t cbSize, unsigned uImageFlags,
    857                      const char *pszComment,
     843static int vdiCreate(const char *pszFilename, uint64_t cbSize,
     844                     unsigned uImageFlags, const char *pszComment,
    858845                     PCPDMMEDIAGEOMETRY pPCHSGeometry,
    859846                     PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    863850                     void **ppBackendData)
    864851{
    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));
    866853    int rc;
    867854    PVDIIMAGEDESC pImage;
     
    890877    if (   !VALID_PTR(pszFilename)
    891878        || !*pszFilename
    892         || (enmType != VD_IMAGE_TYPE_NORMAL && enmType != VD_IMAGE_TYPE_FIXED
    893             && enmType != VD_IMAGE_TYPE_DIFF)
    894879        || cbSize < VDI_IMAGE_DEFAULT_BLOCK_SIZE
    895880        || !VALID_PTR(pPCHSGeometry)
     
    911896    pImage->pVDIfsDisk = pVDIfsDisk;
    912897
    913     rc = vdiCreateImage(pImage, enmType, cbSize, uImageFlags, pszComment,
     898    rc = vdiCreateImage(pImage, cbSize, uImageFlags, pszComment,
    914899                        pPCHSGeometry, pLCHSGeometry, pUuid,
    915900                        pfnProgress, pvUser, uPercentStart, uPercentSpan);
     
    11901175    LogFlowFunc(("returns %#x\n", uVersion));
    11911176    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     else
    1207         rc = VERR_VD_NOT_OPENED;
    1208 
    1209     LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));
    1210     return rc;
    12111177}
    12121178
     
    18931859    /* pfnGetVersion */
    18941860    vdiGetVersion,
    1895     /* pfnGetImageType */
    1896     vdiGetImageType,
    18971861    /* pfnGetSize */
    18981862    vdiGetSize,
  • trunk/src/VBox/Devices/Storage/VHDHDDCore.cpp

    r16873 r17970  
    141141    /** Open flags passed by VBoxHD layer. */
    142142    unsigned        uOpenFlags;
    143     /** Image type. */
    144     VDIMAGETYPE     enmImageType;
    145143    /** Image flags defined during creation or determined during open. */
    146144    unsigned        uImageFlags;
     
    430428        case VHD_FOOTER_DISK_TYPE_FIXED:
    431429            {
    432                 pImage->enmImageType = VD_IMAGE_TYPE_FIXED;
     430                pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED;
    433431            }
    434432            break;
    435433        case VHD_FOOTER_DISK_TYPE_DYNAMIC:
    436434            {
    437                 pImage->enmImageType = VD_IMAGE_TYPE_NORMAL;
     435                pImage->uImageFlags &= ~VD_IMAGE_FLAGS_FIXED;
    438436            }
    439437            break;
    440438        case VHD_FOOTER_DISK_TYPE_DIFFERENCING:
    441439            {
    442                 pImage->enmImageType = VD_IMAGE_TYPE_DIFF;
     440                pImage->uImageFlags |= VD_IMAGE_FLAGS_DIFF;
     441                pImage->uImageFlags &= ~VD_IMAGE_FLAGS_FIXED;
    443442            }
    444443            break;
     
    470469    LogFlowFunc(("DataOffset=%llu\n", pImage->u64DataOffset));
    471470
    472     if (pImage->enmImageType == VD_IMAGE_TYPE_NORMAL || pImage->enmImageType == VD_IMAGE_TYPE_DIFF)
     471    if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED))
    473472        rc = vhdLoadDynamicDisk(pImage, pImage->u64DataOffset);
    474473
     
    573572    RTMemFree(pBlockAllocationTable);
    574573
    575     if (pImage->enmImageType == VD_IMAGE_TYPE_DIFF)
     574    if (pImage->uImageFlags & VD_IMAGE_FLAGS_DIFF)
    576575        memcpy(pImage->ParentUuid.au8, vhdDynamicDiskHeader.ParentUuid, sizeof(pImage->ParentUuid));
    577576
     
    618617    else
    619618        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     else
    633         rc = VERR_VD_NOT_OPENED;
    634 
    635     return rc;
    636619}
    637620
     
    13131296    if (pImage && pImage->File != NIL_RTFILE)
    13141297    {
    1315         if (pImage->enmImageType != VD_IMAGE_TYPE_FIXED)
     1298        if (!(pImage->uImageFlags & VD_IMAGE_FLAGS_FIXED))
    13161299        {
    13171300            pImage->ParentUuid = *pUuid;
     
    15251508 * Internal: The actual code for VHD image creation, both fixed and dynamic.
    15261509 */
    1527 static int vhdCreateImage(PVHDIMAGE pImage, VDIMAGETYPE enmType,
    1528                           uint64_t cbSize, unsigned uImageFlags,
    1529                           const char *pszComment,
     1510static int vhdCreateImage(PVHDIMAGE pImage, uint64_t cbSize,
     1511                          unsigned uImageFlags, const char *pszComment,
    15301512                          PCPDMMEDIAGEOMETRY pPCHSGeometry,
    15311513                          PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    15401522
    15411523    pImage->uOpenFlags = uOpenFlags;
     1524    pImage->uImageFlags = uImageFlags;
    15421525
    15431526    pImage->pInterfaceError = VDInterfaceGet(pImage->pVDIfsDisk, VDINTERFACETYPE_ERROR);
     
    15521535    pImage->File = File;
    15531536
    1554     pImage->enmImageType = enmType;
    15551537    pImage->cbSize = cbSize;
    15561538    pImage->ImageUuid = *pUuid;
     
    15791561    Footer.SavedState = 0;
    15801562
    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;
    16321607    }
    16331608
     
    16481623
    16491624    /* 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))
    16511626    {
    16521627        /* Write the copy of the footer. */
     
    16661641}
    16671642
    1668 static int vhdCreate(const char *pszFilename, VDIMAGETYPE enmType,
    1669                      uint64_t cbSize, unsigned uImageFlags,
    1670                      const char *pszComment,
     1643static int vhdCreate(const char *pszFilename, uint64_t cbSize,
     1644                     unsigned uImageFlags, const char *pszComment,
    16711645                     PCPDMMEDIAGEOMETRY pPCHSGeometry,
    16721646                     PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    17111685    pImage->pVDIfsDisk = NULL;
    17121686
    1713     rc = vhdCreateImage(pImage, enmType, cbSize, uImageFlags, pszComment,
     1687    rc = vhdCreateImage(pImage, cbSize, uImageFlags, pszComment,
    17141688                        pPCHSGeometry, pLCHSGeometry, pUuid, uOpenFlags,
    17151689                        pfnProgress, pvUser, uPercentStart, uPercentSpan);
     
    18951869    /* pfnGetVersion */
    18961870    vhdGetVersion,
    1897     /* pfnGetImageType */
    1898     vhdGetImageType,
    18991871    /* pfnGetSize */
    19001872    vhdGetSize,
  • trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp

    r17852 r17970  
    439439    /** Open flags passed by VBoxHD layer. */
    440440    unsigned        uOpenFlags;
    441     /** Image type. */
    442     VDIMAGETYPE     enmImageType;
    443441    /** Image flags defined during creation or determined during open. */
    444442    unsigned        uImageFlags;
     
    20572055    if (    !strcmp(pszCreateType, "twoGbMaxExtentSparse")
    20582056        ||  !strcmp(pszCreateType, "twoGbMaxExtentFlat"))
    2059         pImage->uImageFlags = VD_VMDK_IMAGE_FLAGS_SPLIT_2G;
     2057        pImage->uImageFlags |= VD_VMDK_IMAGE_FLAGS_SPLIT_2G;
    20602058    else if (   !strcmp(pszCreateType, "partitionedDevice")
    20612059             || !strcmp(pszCreateType, "fullDevice"))
    2062         pImage->uImageFlags = VD_VMDK_IMAGE_FLAGS_RAWDISK;
     2060        pImage->uImageFlags |= VD_VMDK_IMAGE_FLAGS_RAWDISK;
    20632061    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;
    20672063    RTStrFree((char *)(void *)pszCreateType);
    20682064
     
    31153111    }
    31163112
    3117     pImage->enmImageType = VD_IMAGE_TYPE_NORMAL;
    31183113    for (unsigned i = 0; i < pImage->cExtents; i++)
    31193114    {
     
    31223117            ||  pImage->pExtents[i].enmType == VMDKETYPE_ZERO)
    31233118        {
    3124             pImage->enmImageType = VD_IMAGE_TYPE_FIXED;
     3119            pImage->uImageFlags |= VD_IMAGE_FLAGS_FIXED;
    31253120            break;
    31263121        }
     
    33913386 * Internal: create a regular (i.e. file-backed) VMDK image.
    33923387 */
    3393 static int vmdkCreateRegularImage(PVMDKIMAGE pImage, VDIMAGETYPE enmType,
    3394                                   uint64_t cbSize, unsigned uImageFlags,
     3388static int vmdkCreateRegularImage(PVMDKIMAGE pImage, uint64_t cbSize,
     3389                                  unsigned uImageFlags,
    33953390                                  PFNVMPROGRESS pfnProgress, void *pvUser,
    33963391                                  unsigned uPercentStart, unsigned uPercentSpan)
     
    34193414
    34203415    /* Create searate descriptor file if necessary. */
    3421     if (cExtents != 1 || enmType == VD_IMAGE_TYPE_FIXED)
     3416    if (cExtents != 1 || (uImageFlags & VD_IMAGE_FLAGS_FIXED))
    34223417    {
    34233418        rc = vmdkFileOpen(pImage, &pImage->pFile, pImage->pszFilename,
     
    34403435         * with RTMemTmpFree, which must be used as in other code paths
    34413436         * StrDup is not usable. */
    3442         if (cExtents == 1 && enmType != VD_IMAGE_TYPE_FIXED)
     3437        if (cExtents == 1 && !(uImageFlags & VD_IMAGE_FLAGS_FIXED))
    34433438        {
    34443439            char *pszBasename = (char *)RTMemTmpAlloc(cbBasenameSubstr);
     
    34553450            char *pszTmp;
    34563451            size_t cbTmp;
    3457             if (enmType == VD_IMAGE_TYPE_FIXED)
     3452            if (uImageFlags & VD_IMAGE_FLAGS_FIXED)
    34583453            {
    34593454                if (cExtents == 1)
     
    34963491        if (RT_FAILURE(rc))
    34973492            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)
    34993494        {
    35003495            rc = vmdkFileSetSize(pExtent->pFile, cbExtent);
     
    35463541
    35473542        /* Place descriptor file information (where integrated). */
    3548         if (cExtents == 1 && enmType != VD_IMAGE_TYPE_FIXED)
     3543        if (cExtents == 1 && !(uImageFlags & VD_IMAGE_FLAGS_FIXED))
    35493544        {
    35503545            pExtent->uDescriptorSector = 1;
     
    35553550        }
    35563551
    3557         if (enmType == VD_IMAGE_TYPE_NORMAL)
     3552        if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED))
    35583553        {
    35593554            uint64_t cSectorsPerGDE, cSectorsPerGD;
     
    35783573        pExtent->fMetaDirty = true;
    35793574
    3580         if (enmType == VD_IMAGE_TYPE_NORMAL)
     3575        if (!(uImageFlags & VD_IMAGE_FLAGS_FIXED))
    35813576        {
    35823577            rc = vmdkCreateGrainDirectory(pExtent,
     
    35993594
    36003595    const char *pszDescType = NULL;
    3601     if (enmType == VD_IMAGE_TYPE_FIXED)
     3596    if (uImageFlags & VD_IMAGE_FLAGS_FIXED)
    36023597    {
    36033598        pszDescType =   (cExtents == 1)
    36043599                      ? "monolithicFlat" : "twoGbMaxExtentFlat";
    36053600    }
    3606     else if (enmType == VD_IMAGE_TYPE_NORMAL)
     3601    else
    36073602    {
    36083603        if (pImage->uImageFlags & VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED)
     
    36143609        }
    36153610    }
    3616     else
    3617         AssertMsgFailed(("invalid image type %d\n", enmType));
    36183611    rc = vmdkDescBaseSetStr(pImage, &pImage->Descriptor, "createType",
    36193612                            pszDescType);
     
    36273620 * existence on hosted environments.
    36283621 */
    3629 static int vmdkCreateImage(PVMDKIMAGE pImage, VDIMAGETYPE enmType,
    3630                            uint64_t cbSize, unsigned uImageFlags,
    3631                            const char *pszComment,
     3622static int vmdkCreateImage(PVMDKIMAGE pImage, uint64_t cbSize,
     3623                           unsigned uImageFlags, const char *pszComment,
    36323624                           PCPDMMEDIAGEOMETRY pPCHSGeometry,
    36333625                           PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    36573649    }
    36583650
    3659     if (    enmType == VD_IMAGE_TYPE_FIXED
     3651    if (    (uImageFlags & VD_IMAGE_FLAGS_FIXED)
    36603652        &&  (uImageFlags & VD_VMDK_IMAGE_FLAGS_RAWDISK))
    36613653    {
     
    36673659        rc = vmdkCreateRawImage(pImage, pRaw, cbSize);
    36683660    }
    3669     else if (   enmType == VD_IMAGE_TYPE_FIXED
    3670              || enmType == VD_IMAGE_TYPE_NORMAL)
     3661    else
    36713662    {
    36723663        /* Regular fixed or sparse image (monolithic or split). */
    3673         rc = vmdkCreateRegularImage(pImage, enmType, cbSize, uImageFlags,
     3664        rc = vmdkCreateRegularImage(pImage, cbSize, uImageFlags,
    36743665                                    pfnProgress, pvUser, uPercentStart,
    36753666                                    uPercentSpan * 95 / 100);
    3676     }
    3677     else
    3678     {
    3679         /* Unknown/invalid image type. */
    3680         rc = VERR_NOT_IMPLEMENTED;
    36813667    }
    36823668
     
    36883674                    uPercentStart + uPercentSpan * 98 / 100, pvUser);
    36893675
    3690     pImage->enmImageType = enmType;
    36913676    pImage->cbSize = cbSize;
    36923677
     
    38193804    AssertPtr(pImage);
    38203805
    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)
    38273817            {
    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;
    38383820            }
    38393821        }
    3840         (void)vmdkFlushImage(pImage);
    3841     }
     3822    }
     3823    (void)vmdkFlushImage(pImage);
     3824
    38423825    if (pImage->pExtents != NULL)
    38433826    {
     
    43524335
    43534336/** @copydoc VBOXHDDBACKEND::pfnCreate */
    4354 static int vmdkCreate(const char *pszFilename, VDIMAGETYPE enmType,
    4355                       uint64_t cbSize, unsigned uImageFlags,
    4356                       const char *pszComment,
     4337static int vmdkCreate(const char *pszFilename, uint64_t cbSize,
     4338                      unsigned uImageFlags, const char *pszComment,
    43574339                      PCPDMMEDIAGEOMETRY pPCHSGeometry,
    43584340                      PCPDMMEDIAGEOMETRY pLCHSGeometry, PCRTUUID pUuid,
     
    43624344                      void **ppBackendData)
    43634345{
    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));
    43654347    int rc;
    43664348    PVMDKIMAGE pImage;
     
    43854367    }
    43864368
    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 
    43914369    /* Check remaining arguments. */
    43924370    if (   !VALID_PTR(pszFilename)
    43934371        || !*pszFilename
    43944372        || strchr(pszFilename, '"')
    4395         || (enmType != VD_IMAGE_TYPE_NORMAL && enmType != VD_IMAGE_TYPE_FIXED)
    43964373        || !VALID_PTR(pPCHSGeometry)
    43974374        || !VALID_PTR(pLCHSGeometry)
    43984375        || (   (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))))
    44014377    {
    44024378        rc = VERR_INVALID_PARAMETER;
     
    44254401    }
    44264402
    4427     rc = vmdkCreateImage(pImage, enmType, cbSize, uImageFlags, pszComment,
     4403    rc = vmdkCreateImage(pImage, cbSize, uImageFlags, pszComment,
    44284404                         pPCHSGeometry, pLCHSGeometry, pUuid,
    44294405                         pfnProgress, pvUser, uPercentStart, uPercentSpan);
     
    50455021}
    50465022
    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     else
    5060         rc = VERR_VD_NOT_OPENED;
    5061 
    5062     LogFlowFunc(("returns %Rrc enmImageType=%u\n", rc, *penmImageType));
    5063     return rc;
    5064 }
    5065 
    50665023/** @copydoc VBOXHDDBACKEND::pfnGetSize */
    50675024static uint64_t vmdkGetSize(void *pBackendData)
     
    59435900    /* pfnGetVersion */
    59445901    vmdkGetVersion,
    5945     /* pfnGetImageType */
    5946     vmdkGetImageType,
    59475902    /* pfnGetSize */
    59485903    vmdkGetSize,
  • trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp

    r17836 r17970  
    5656
    5757static 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)
    6059{
    6160    int rc;
     
    9089    CHECK("VDCreate()");
    9190
    92     rc = VDCreateBase(pVD, pszBackend, pszFilename, enmType, cbSize,
     91    rc = VDCreateBase(pVD, pszBackend, pszFilename, cbSize,
    9392                      uFlags, "Test image", &PCHS, &LCHS, NULL,
    9493                      VD_OPEN_FLAGS_NORMAL, NULL, NULL);
     
    556555    else
    557556    {
    558         rc = VDCreateBase(pVD, pszBackend, pszBaseFilename,
    559                           VD_IMAGE_TYPE_NORMAL, u64DiskSize,
     557        rc = VDCreateBase(pVD, pszBackend, pszBaseFilename, u64DiskSize,
    560558                          VD_IMAGE_FLAGS_NONE, "Test image",
    561559                          &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL,
     
    667665    }
    668666
    669     rc = VDCreateBase(pVD, pszBackend, pszFilename,
    670                       VD_IMAGE_TYPE_NORMAL, u64DiskSize,
     667    rc = VDCreateBase(pVD, pszBackend, pszFilename, u64DiskSize,
    671668                      VD_IMAGE_FLAGS_NONE, "Test image",
    672669                      &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL,
     
    744741
    745742static 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);
    750746    if (RT_FAILURE(rc))
    751747        return rc;
     
    802798{
    803799    int rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", "tmpVDRename.vmdk", _4G,
    804                                  VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE);
     800                                     VD_IMAGE_FLAGS_NONE);
    805801    if (RT_FAILURE(rc))
    806802    {
     
    809805    }
    810806    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);
    812808    if (RT_FAILURE(rc))
    813809    {
     
    816812    }
    817813    rc = tstVmdkCreateRenameOpen("tmpVDCreate.vmdk", DST_PATH, _4G,
    818                                  VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE);
     814                                 VD_IMAGE_FLAGS_NONE);
    819815    if (RT_FAILURE(rc))
    820816    {
     
    823819    }
    824820    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);
    826822    if (RT_FAILURE(rc))
    827823    {
     
    836832
    837833    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);
    839835    if (RT_SUCCESS(rc))
    840836    {
     
    902898#ifdef VMDK_TEST
    903899    rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G,
    904                            VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE,
    905                            true);
     900                           VD_IMAGE_FLAGS_NONE, true);
    906901    if (RT_FAILURE(rc))
    907902    {
     
    910905    }
    911906    rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G,
    912                            VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE,
    913                            false);
     907                           VD_IMAGE_FLAGS_NONE, false);
    914908    if (RT_FAILURE(rc))
    915909    {
     
    928922#ifdef VDI_TEST
    929923    rc = tstVDCreateDelete("VDI", "tmpVDCreate.vdi", 2 * _4G,
    930                            VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE,
    931                            true);
     924                           VD_IMAGE_FLAGS_NONE, true);
    932925    if (RT_FAILURE(rc))
    933926    {
     
    936929    }
    937930    rc = tstVDCreateDelete("VDI", "tmpVDCreate.vdi", 2 * _4G,
    938                            VD_IMAGE_TYPE_FIXED, VD_IMAGE_FLAGS_NONE,
    939                            true);
     931                           VD_IMAGE_FLAGS_NONE, true);
    940932    if (RT_FAILURE(rc))
    941933    {
     
    946938#ifdef VMDK_TEST
    947939    rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G,
    948                            VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE,
    949                            true);
     940                           VD_IMAGE_FLAGS_NONE, true);
    950941    if (RT_FAILURE(rc))
    951942    {
     
    954945    }
    955946    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);
    958948    if (RT_FAILURE(rc))
    959949    {
     
    962952    }
    963953    rc = tstVDCreateDelete("VMDK", "tmpVDCreate.vmdk", 2 * _4G,
    964                            VD_IMAGE_TYPE_FIXED, VD_IMAGE_FLAGS_NONE,
    965                            true);
     954                           VD_IMAGE_FLAGS_FIXED, true);
    966955    if (RT_FAILURE(rc))
    967956    {
     
    970959    }
    971960    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,
    973962                           true);
    974963    if (RT_FAILURE(rc))
     
    980969#ifdef VHD_TEST
    981970    rc = tstVDCreateDelete("VHD", "tmpVDCreate.vhd", 2 * _4G,
    982                            VD_IMAGE_TYPE_NORMAL, VD_IMAGE_FLAGS_NONE,
    983                            true);
     971                           VD_IMAGE_FLAGS_NONE, true);
    984972    if (RT_FAILURE(rc))
    985973    {
     
    988976    }
    989977    rc = tstVDCreateDelete("VHD", "tmpVDCreate.vhd", 2 * _4G,
    990                            VD_IMAGE_TYPE_FIXED, VD_IMAGE_FLAGS_NONE,
    991                            true);
     978                           VD_IMAGE_FLAGS_FIXED, true);
    992979    if (RT_FAILURE(rc))
    993980    {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette