VirtualBox

Changeset 33524 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Oct 27, 2010 4:44:37 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67121
Message:

Storage: Implement offical support for other disk types like DVD and floppy images. DMG images can be used now without hacks

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

Legend:

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

    r33479 r33524  
    407407
    408408/** NULL-terminated array of supported file extensions. */
    409 static const char *const s_apszDmgFileExtensions[] =
    410 {
    411     "dmg",
    412     NULL
     409static const VDFILEEXTENSION s_aDmgFileExtensions[] =
     410{
     411    {"dmg", VDTYPE_DVD},
     412    {NULL, VDTYPE_INVALID}
    413413};
    414414
     
    15921592/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
    15931593static int dmgCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    1594                            PVDINTERFACE pVDIfsImage)
    1595 {
    1596     LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p\n", pszFilename, pVDIfsDisk, pVDIfsImage));
     1594                           PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
     1595{
     1596    LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p penmType=%#p\n",
     1597                 pszFilename, pVDIfsDisk, pVDIfsImage, penmType));
    15971598    int rc;
    15981599    PVDIOSTORAGE pStorage;
     
    16391640        {
    16401641            if (dmgUdifFtrIsValid(&Ftr, offFtr))
     1642            {
    16411643                rc = VINF_SUCCESS;
     1644                *penmType = VDTYPE_DVD;
     1645            }
    16421646            else
    16431647            {
     
    16591663static int dmgOpen(const char *pszFilename, unsigned uOpenFlags,
    16601664                   PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    1661                    void **ppBackendData)
     1665                   VDTYPE enmType, void **ppBackendData)
    16621666{
    16631667    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
     
    21362140{
    21372141    LogFlowFunc(("pBackendData=%#p pszComment=\"%s\"\n", pBackendData, pszComment));
    2138     PDMGIMAGE pThis = (PDMGIMAGE)pBackendData;
     2142    PDMGIMAGE pImage = (PDMGIMAGE)pBackendData;
    21392143    int rc;
    21402144
    2141     AssertPtr(pThis);
    2142 
    2143     if (pThis->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    2144     {
    2145         rc = VERR_VD_IMAGE_READ_ONLY;
    2146         goto out;
    2147     }
    2148 
    2149     if (pThis)
    2150         rc = VERR_NOT_SUPPORTED;
     2145    AssertPtr(pImage);
     2146
     2147    if (pImage)
     2148    {
     2149        if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2150            rc = VERR_VD_IMAGE_READ_ONLY;
     2151        else
     2152            rc = VERR_NOT_SUPPORTED;
     2153    }
    21512154    else
    21522155        rc = VERR_VD_NOT_OPENED;
     
    23462349    /* uBackendCaps */
    23472350    VD_CAP_FILE | VD_CAP_VFS,
    2348     /* papszFileExtensions */
    2349     s_apszDmgFileExtensions,
     2351    /* paFileExtensions */
     2352    s_aDmgFileExtensions,
    23502353    /* paConfigInfo */
    23512354    NULL,
  • trunk/src/VBox/Devices/Storage/DrvVD.cpp

    r33218 r33524  
    20042004    unsigned    iLevel = 0;
    20052005    PCFGMNODE   pCurNode = pCfg;
     2006    VDTYPE      enmType = VDTYPE_HDD;
    20062007
    20072008    for (;;)
     
    20172018                                          "ReadOnly\0MaybeReadOnly\0TempReadOnly\0Shareable\0HonorZeroWrites\0"
    20182019                                          "HostIPStack\0UseNewIo\0BootAcceleration\0BootAccelerationBuffer\0"
    2019                                           "SetupMerge\0MergeSource\0MergeTarget\0BwGroup\0");
     2020                                          "SetupMerge\0MergeSource\0MergeTarget\0BwGroup\0Type\0");
    20202021        }
    20212022        else
     
    21322133            else
    21332134                rc = VINF_SUCCESS;
     2135
     2136            char *psz;
     2137            rc = CFGMR3QueryStringAlloc(pCfg, "Type", &psz);
     2138            if (RT_FAILURE(rc))
     2139            {
     2140                rc = PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_BLOCK_NO_TYPE, N_("Failed to obtain the type"));
     2141                break;
     2142            }
     2143            else if (!strcmp(psz, "HardDisk"))
     2144                enmType = VDTYPE_HDD;
     2145            else if (!strcmp(psz, "DVD"))
     2146                enmType = VDTYPE_DVD;
     2147            else if (!strcmp(psz, "Floppy"))
     2148                enmType = VDTYPE_FLOPPY;
     2149            else
     2150            {
     2151                rc = PDMDrvHlpVMSetError(pDrvIns, VERR_PDM_BLOCK_UNKNOWN_TYPE, RT_SRC_POS,
     2152                                         N_("Unknown type \"%s\""), psz);
     2153                MMR3HeapFree(psz);
     2154                break;
     2155            }
     2156            MMR3HeapFree(psz); psz = NULL;
    21342157        }
    21352158
     
    22702293        if (RT_SUCCESS(rc))
    22712294        {
    2272             rc = VDCreate(pThis->pVDIfsDisk, &pThis->pDisk);
     2295            rc = VDCreate(pThis->pVDIfsDisk, enmType, &pThis->pDisk);
    22732296            /* Error message is already set correctly. */
    22742297        }
  • trunk/src/VBox/Devices/Storage/ISCSIHDDCore.cpp

    r33182 r33524  
    43694369/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
    43704370static int iscsiCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    4371                              PVDINTERFACE pVDIfsImage)
     4371                             PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
    43724372{
    43734373    LogFlowFunc(("pszFilename=\"%s\"\n", pszFilename));
     
    43844384static int iscsiOpen(const char *pszFilename, unsigned uOpenFlags,
    43854385                     PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    4386                      void **ppBackendData)
     4386                     VDTYPE enmType, void **ppBackendData)
    43874387{
    43884388    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
  • trunk/src/VBox/Devices/Storage/ParallelsHDDCore.cpp

    r33258 r33524  
    105105
    106106/** NULL-terminated array of supported file extensions. */
    107 static const char *const s_apszParallelsFileExtensions[] =
    108 {
    109     "hdd",
    110     NULL
     107static const VDFILEEXTENSION s_aParallelsFileExtensions[] =
     108{
     109    {"hdd", VDTYPE_HDD},
     110    {NULL, VDTYPE_INVALID}
    111111};
    112112
     
    415415/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
    416416static int parallelsCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    417                                  PVDINTERFACE pVDIfsImage)
     417                                 PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
    418418{
    419419    int rc;
     
    471471    }
    472472
     473    if (RT_SUCCESS(rc))
     474        *penmType = VDTYPE_HDD;
     475
    473476    pInterfaceIOCallbacks->pfnClose(pInterfaceIO->pvUser, pStorage);
    474477    return rc;
     
    478481static int parallelsOpen(const char *pszFilename, unsigned uOpenFlags,
    479482                         PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    480                          void **ppBackendData)
     483                         VDTYPE enmType, void **ppBackendData)
    481484{
    482485    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
     
    10011004    AssertPtr(pImage);
    10021005
    1003     if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    1004     {
    1005         rc = VERR_VD_IMAGE_READ_ONLY;
    1006         goto out;
    1007     }
    1008 
    1009     if (pImage)
    1010         rc = VERR_NOT_SUPPORTED;
     1006    if (pImage)
     1007    {
     1008        if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     1009            rc = VERR_VD_IMAGE_READ_ONLY;
     1010        else
     1011            rc = VERR_NOT_SUPPORTED;
     1012    }
    10111013    else
    10121014        rc = VERR_VD_NOT_OPENED;
     
    13571359    /* uBackendCaps */
    13581360    VD_CAP_FILE | VD_CAP_ASYNC | VD_CAP_VFS,
    1359     /* papszFileExtensions */
    1360     s_apszParallelsFileExtensions,
     1361    /* paFileExtensions */
     1362    s_aParallelsFileExtensions,
    13611363    /* paConfigInfo */
    13621364    NULL,
  • trunk/src/VBox/Devices/Storage/RawHDDCore.cpp

    r33234 r33524  
    2626#include <iprt/assert.h>
    2727#include <iprt/alloc.h>
    28 
     28#include <iprt/path.h>
    2929
    3030/*******************************************************************************
    3131*   Constants And Macros, Structures and Typedefs                              *
    3232*******************************************************************************/
     33/**
     34 * ISO volume descriptor.
     35 */
     36#pragma pack(1)
     37typedef struct ISOVOLDESC
     38{
     39    union
     40    {
     41        /** Byte view. */
     42        uint8_t au8[2048];
     43        /** Field view. */
     44        struct
     45        {
     46            /** Descriptor type. */
     47            uint8_t u8Type;
     48            /** Standard identifier */
     49            uint8_t au8Id[5];
     50            /** Descriptor version. */
     51            uint8_t u8Version;
     52            /** Rest depends on the descriptor type. */
     53        } fields;
     54    };
     55} ISOVOLDESC, *PISOVOLDESC;
     56#pragma pack()
     57AssertCompileSize(ISOVOLDESC, 2048);
    3358
    3459/**
     
    82107
    83108/** NULL-terminated array of supported file extensions. */
    84 static const char *const s_apszRawFileExtensions[] =
    85 {
    86     /** @todo At the moment this backend doesn't claim any extensions, but it might
    87      * be useful to add a few later. However this needs careful testing, as the
    88      * CheckIfValid function never returns success. */
    89     NULL
     109static const VDFILEEXTENSION s_aRawFileExtensions[] =
     110{
     111    {"iso", VDTYPE_DVD},
     112    {"img", VDTYPE_FLOPPY},
     113    {"ima", VDTYPE_FLOPPY},
     114    {NULL, VDTYPE_INVALID}
    90115};
    91116
     
    484509/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
    485510static int rawCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    486                            PVDINTERFACE pVDIfsImage)
    487 {
    488     LogFlowFunc(("pszFilename=\"%s\"\n", pszFilename));
     511                           PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
     512{
     513    LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p\n", pszFilename, pVDIfsDisk, pVDIfsImage));
     514    PVDIOSTORAGE pStorage = NULL;
     515    uint64_t cbFile;
    489516    int rc = VINF_SUCCESS;
     517    ISOVOLDESC IsoVolDesc;
     518    char *pszExtension = NULL;
     519
     520    /* Get I/O interface. */
     521    PVDINTERFACE pInterfaceIO = VDInterfaceGet(pVDIfsImage, VDINTERFACETYPE_IOINT);
     522    AssertPtrReturn(pInterfaceIO, VERR_INVALID_PARAMETER);
     523    PVDINTERFACEIOINT pInterfaceIOCallbacks = VDGetInterfaceIOInt(pInterfaceIO);
     524    AssertPtrReturn(pInterfaceIOCallbacks, VERR_INVALID_PARAMETER);
    490525
    491526    if (   !VALID_PTR(pszFilename)
     
    496531    }
    497532
    498     /* Always return failure, to avoid opening everything as a raw image. */
    499     rc = VERR_VD_RAW_INVALID_HEADER;
     533    pszExtension = RTPathExt(pszFilename);
     534
     535    /*
     536     * Open the file and read the footer.
     537     */
     538    rc = pInterfaceIOCallbacks->pfnOpen(pInterfaceIO->pvUser, pszFilename,
     539                                        VDOpenFlagsToFileOpenFlags(VD_OPEN_FLAGS_READONLY,
     540                                                                   false /* fCreate */),
     541                                        &pStorage);
     542    if (RT_SUCCESS(rc))
     543        rc = pInterfaceIOCallbacks->pfnGetSize(pInterfaceIO->pvUser, pStorage,
     544                                               &cbFile);
     545
     546    /* Try to guess the image type based on the extension. */
     547    if (   RT_SUCCESS(rc)
     548        && pszExtension)
     549    {
     550        if (!strcmp(pszExtension, ".iso")) /* DVD images. */
     551        {
     552            if (cbFile >= (32768 + sizeof(ISOVOLDESC)))
     553            {
     554                rc = pInterfaceIOCallbacks->pfnReadSync(pInterfaceIO->pvUser, pStorage,
     555                                                        32768, &IsoVolDesc, sizeof(IsoVolDesc), NULL);
     556            }
     557            else
     558                rc = VERR_VD_RAW_INVALID_HEADER;
     559
     560            if (RT_SUCCESS(rc))
     561            {
     562                /*
     563                 * Do we recognize this stuff?
     564                 */
     565                if (   !memcmp(IsoVolDesc.fields.au8Id, "BEA01", 5)
     566                    || !memcmp(IsoVolDesc.fields.au8Id, "BOOT2", 5)
     567                    || !memcmp(IsoVolDesc.fields.au8Id, "CD001", 5)
     568                    || !memcmp(IsoVolDesc.fields.au8Id, "CDW02", 5)
     569                    || !memcmp(IsoVolDesc.fields.au8Id, "NSR02", 5)
     570                    || !memcmp(IsoVolDesc.fields.au8Id, "NSR03", 5)
     571                    || !memcmp(IsoVolDesc.fields.au8Id, "TEA01", 5))
     572                {
     573                    *penmType = VDTYPE_DVD;
     574                    rc = VINF_SUCCESS;
     575                }
     576                else
     577                    rc = VERR_VD_RAW_INVALID_HEADER;
     578            }
     579        }
     580        else if (!strcmp(pszExtension, ".img") || !strcmp(pszExtension, ".ima")) /* Floppy images */
     581        {
     582            if (!(cbFile % 512))
     583            {
     584                *penmType = VDTYPE_FLOPPY;
     585                rc = VINF_SUCCESS;
     586            }
     587            else
     588                rc = VERR_VD_RAW_INVALID_HEADER;
     589        }
     590    }
     591    else
     592        rc = VERR_VD_RAW_INVALID_HEADER;
     593
     594    if (pStorage)
     595        pInterfaceIOCallbacks->pfnClose(pInterfaceIO->pvUser, pStorage);
    500596
    501597out:
     
    507603static int rawOpen(const char *pszFilename, unsigned uOpenFlags,
    508604                   PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    509                    void **ppBackendData)
     605                   VDTYPE enmType, void **ppBackendData)
    510606{
    511607    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
     
    10401136    AssertPtr(pImage);
    10411137
    1042     if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    1043     {
    1044         rc = VERR_VD_IMAGE_READ_ONLY;
    1045         goto out;
    1046     }
    1047 
    1048     if (pImage)
    1049         rc = VERR_NOT_SUPPORTED;
     1138    if (pImage)
     1139    {
     1140        if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     1141            rc = VERR_VD_IMAGE_READ_ONLY;
     1142        else
     1143            rc = VERR_NOT_SUPPORTED;
     1144    }
    10501145    else
    10511146        rc = VERR_VD_NOT_OPENED;
     
    12921387{
    12931388    /* pszBackendName */
    1294     "raw",
     1389    "RAW",
    12951390    /* cbSize */
    12961391    sizeof(VBOXHDDBACKEND),
    12971392    /* uBackendCaps */
    12981393    VD_CAP_CREATE_FIXED | VD_CAP_FILE | VD_CAP_ASYNC | VD_CAP_VFS,
    1299     /* papszFileExtensions */
    1300     s_apszRawFileExtensions,
     1394    /* paFileExtensions */
     1395    s_aRawFileExtensions,
    13011396    /* paConfigInfo */
    13021397    NULL,
  • trunk/src/VBox/Devices/Storage/VBoxHDD.cpp

    r33495 r33524  
    156156    /** Structure signature (VBOXHDDDISK_SIGNATURE). */
    157157    uint32_t            u32Signature;
     158
     159    /** Image type. */
     160    VDTYPE              enmType;
    158161
    159162    /** Number of opened images. */
     
    440443extern VBOXHDDBACKEND g_VhdBackend;
    441444extern VBOXHDDBACKEND g_ParallelsBackend;
    442 #ifdef VBOX_WITH_DMG
    443445extern VBOXHDDBACKEND g_DmgBackend;
    444 #endif
    445446#ifdef VBOX_WITH_ISCSI
    446447extern VBOXHDDBACKEND g_ISCSIBackend;
     
    451452static PVBOXHDDBACKEND aStaticBackends[] =
    452453{
    453     &g_RawBackend,
    454454    &g_VmdkBackend,
    455455    &g_VDIBackend,
    456456    &g_VhdBackend,
    457     &g_ParallelsBackend
    458 #ifdef VBOX_WITH_DMG
    459     ,&g_DmgBackend
    460 #endif
     457    &g_ParallelsBackend,
     458    &g_DmgBackend,
     459    &g_RawBackend
    461460#ifdef VBOX_WITH_ISCSI
    462461    ,&g_ISCSIBackend
     
    35843583        pEntries[i].pszBackend = g_apBackends[i]->pszBackendName;
    35853584        pEntries[i].uBackendCaps = g_apBackends[i]->uBackendCaps;
    3586         pEntries[i].papszFileExtensions = g_apBackends[i]->papszFileExtensions;
     3585        pEntries[i].paFileExtensions = g_apBackends[i]->paFileExtensions;
    35873586        pEntries[i].paConfigInfo = g_apBackends[i]->paConfigInfo;
    35883587        pEntries[i].pfnComposeLocation = g_apBackends[i]->pfnComposeLocation;
     
    36223621            pEntry->pszBackend = g_apBackends[i]->pszBackendName;
    36233622            pEntry->uBackendCaps = g_apBackends[i]->uBackendCaps;
    3624             pEntry->papszFileExtensions = g_apBackends[i]->papszFileExtensions;
     3623            pEntry->paFileExtensions = g_apBackends[i]->paFileExtensions;
    36253624            pEntry->paConfigInfo = g_apBackends[i]->paConfigInfo;
    36263625            return VINF_SUCCESS;
     
    36373636 * @returns VBox status code.
    36383637 * @param   pVDIfsDisk      Pointer to the per-disk VD interface list.
     3638 * @param   enmType         Type of the image container.
    36393639 * @param   ppDisk          Where to store the reference to HDD container.
    36403640 */
    3641 VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, PVBOXHDD *ppDisk)
     3641VBOXDDU_DECL(int) VDCreate(PVDINTERFACE pVDIfsDisk, VDTYPE enmType, PVBOXHDD *ppDisk)
    36423642{
    36433643    int rc = VINF_SUCCESS;
     
    36563656        {
    36573657            pDisk->u32Signature = VBOXHDDDISK_SIGNATURE;
     3658            pDisk->enmType      = enmType;
    36583659            pDisk->cImages      = 0;
    36593660            pDisk->pBase        = NULL;
     
    38093810 */
    38103811VBOXDDU_DECL(int) VDGetFormat(PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    3811                               const char *pszFilename, char **ppszFormat)
     3812                              const char *pszFilename, char **ppszFormat, VDTYPE *penmType)
    38123813{
    38133814    int rc = VERR_NOT_SUPPORTED;
     
    38253826    AssertMsgReturn(VALID_PTR(ppszFormat),
    38263827                    ("ppszFormat=%#p\n", ppszFormat),
     3828                    VERR_INVALID_PARAMETER);
     3829    AssertMsgReturn(VALID_PTR(ppszFormat),
     3830                    ("penmType=%#p\n", penmType),
    38273831                    VERR_INVALID_PARAMETER);
    38283832
     
    38863890        {
    38873891            rc = g_apBackends[i]->pfnCheckIfValid(pszFilename, pVDIfsDisk,
    3888                                                   pVDIfsImage);
     3892                                                  pVDIfsImage, penmType);
    38893893            if (    RT_SUCCESS(rc)
    38903894                /* The correct backend has been found, but there is a small
     
    40484052                                      pDisk->pVDIfsDisk,
    40494053                                      pImage->pVDIfsImage,
     4054                                      pDisk->enmType,
    40504055                                      &pImage->pBackendData);
    40514056        /* If the open in read-write mode failed, retry in read-only mode. */
     
    40634068                                               pDisk->pVDIfsDisk,
    40644069                                               pImage->pVDIfsImage,
     4070                                               pDisk->enmType,
    40654071                                               &pImage->pBackendData);
    40664072            if (RT_FAILURE(rc))
     
    71867192        pBackendInfo->pszBackend = pImage->Backend->pszBackendName;
    71877193        pBackendInfo->uBackendCaps = pImage->Backend->uBackendCaps;
    7188         pBackendInfo->papszFileExtensions = pImage->Backend->papszFileExtensions;
     7194        pBackendInfo->paFileExtensions = pImage->Backend->paFileExtensions;
    71897195        pBackendInfo->paConfigInfo = pImage->Backend->paConfigInfo;
    71907196    } while (0);
  • trunk/src/VBox/Devices/Storage/VCICacheCore.cpp

    r33522 r33524  
    19011901    AssertPtr(pCache);
    19021902
    1903     if (pCache->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    1904     {
    1905         rc = VERR_VD_IMAGE_READ_ONLY;
    1906         goto out;
    1907     }
    1908 
    19091903    if (pCache)
    1910         rc = VERR_NOT_SUPPORTED;
     1904    {
     1905        if (pCache->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     1906            rc = VERR_VD_IMAGE_READ_ONLY;
     1907        else
     1908            rc = VERR_NOT_SUPPORTED;
     1909    }
    19111910    else
    19121911        rc = VERR_VD_NOT_OPENED;
  • trunk/src/VBox/Devices/Storage/VDIHDDCore.cpp

    r33478 r33524  
    3838
    3939/** NULL-terminated array of supported file extensions. */
    40 static const char *const s_apszVdiFileExtensions[] =
    41 {
    42     "vdi",
    43     NULL
     40static const VDFILEEXTENSION s_aVdiFileExtensions[] =
     41{
     42    {"vdi", VDTYPE_HDD},
     43    {NULL, VDTYPE_INVALID}
    4444};
    4545
     
    999999/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
    10001000static int vdiCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    1001                            PVDINTERFACE pVDIfsImage)
     1001                           PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
    10021002{
    10031003    LogFlowFunc(("pszFilename=\"%s\"\n", pszFilename));
     
    10281028    RTMemFree(pImage);
    10291029
     1030    if (RT_SUCCESS(rc))
     1031        *penmType = VDTYPE_HDD;
     1032
    10301033out:
    10311034    LogFlowFunc(("returns %Rrc\n", rc));
     
    10361039static int vdiOpen(const char *pszFilename, unsigned uOpenFlags,
    10371040                   PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    1038                    void **ppBackendData)
     1041                   VDTYPE enmType, void **ppBackendData)
    10391042{
    10401043    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
     
    17011704    AssertPtr(pImage);
    17021705
    1703     if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    1704     {
    1705         rc = VERR_VD_IMAGE_READ_ONLY;
    1706         goto out;
    1707     }
    1708 
    17091706    if (pImage)
    17101707    {
    1711         size_t cchComment = pszComment ? strlen(pszComment) : 0;
    1712         if (cchComment >= VDI_IMAGE_COMMENT_SIZE)
    1713         {
    1714             LogFunc(("pszComment is too long, %d bytes!\n", cchComment));
    1715             rc = VERR_VD_VDI_COMMENT_TOO_LONG;
    1716             goto out;
    1717         }
    1718 
    1719         /* we don't support old style images */
    1720         if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 1)
    1721         {
    1722             /*
    1723              * Update the comment field, making sure to zero out all of the previous comment.
    1724              */
    1725             memset(pImage->Header.u.v1.szComment, '\0', VDI_IMAGE_COMMENT_SIZE);
    1726             memcpy(pImage->Header.u.v1.szComment, pszComment, cchComment);
    1727 
    1728             /* write out new the header */
    1729             rc = vdiUpdateHeader(pImage);
    1730         }
     1708        if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     1709            rc = VERR_VD_IMAGE_READ_ONLY;
    17311710        else
    1732             rc = VERR_VD_VDI_UNSUPPORTED_VERSION;
     1711        {
     1712            size_t cchComment = pszComment ? strlen(pszComment) : 0;
     1713            if (cchComment >= VDI_IMAGE_COMMENT_SIZE)
     1714            {
     1715                LogFunc(("pszComment is too long, %d bytes!\n", cchComment));
     1716                rc = VERR_VD_VDI_COMMENT_TOO_LONG;
     1717                goto out;
     1718            }
     1719
     1720            /* we don't support old style images */
     1721            if (GET_MAJOR_HEADER_VERSION(&pImage->Header) == 1)
     1722            {
     1723                /*
     1724                 * Update the comment field, making sure to zero out all of the previous comment.
     1725                 */
     1726                memset(pImage->Header.u.v1.szComment, '\0', VDI_IMAGE_COMMENT_SIZE);
     1727                memcpy(pImage->Header.u.v1.szComment, pszComment, cchComment);
     1728
     1729                /* write out new the header */
     1730                rc = vdiUpdateHeader(pImage);
     1731            }
     1732            else
     1733                rc = VERR_VD_VDI_UNSUPPORTED_VERSION;
     1734        }
    17331735    }
    17341736    else
     
    26572659      VD_CAP_UUID | VD_CAP_CREATE_FIXED | VD_CAP_CREATE_DYNAMIC
    26582660    | VD_CAP_DIFF | VD_CAP_FILE | VD_CAP_ASYNC | VD_CAP_VFS,
    2659     /* papszFileExtensions */
    2660     s_apszVdiFileExtensions,
     2661    /* paFileExtensions */
     2662    s_aVdiFileExtensions,
    26612663    /* paConfigInfo */
    26622664    NULL,
  • trunk/src/VBox/Devices/Storage/VHDHDDCore.cpp

    r33495 r33524  
    241241
    242242/** NULL-terminated array of supported file extensions. */
    243 static const char *const s_apszVhdFileExtensions[] =
    244 {
    245     "vhd",
    246     NULL
     243static const VDFILEEXTENSION s_aVhdFileExtensions[] =
     244{
     245    {"vhd", VDTYPE_HDD},
     246    {NULL, VDTYPE_INVALID}
    247247};
    248248
     
    13801380/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
    13811381static int vhdCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    1382                            PVDINTERFACE pVDIfsImage)
     1382                           PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
    13831383{
    13841384    LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p\n", pszFilename, pVDIfsDisk, pVDIfsImage));
     
    14161416        rc = VERR_VD_VHD_INVALID_HEADER;
    14171417    else
     1418    {
     1419        *penmType = VDTYPE_HDD;
    14181420        rc = VINF_SUCCESS;
     1421    }
    14191422
    14201423    pInterfaceIOCallbacks->pfnClose(pInterfaceIO->pvUser, pStorage);
     
    14281431static int vhdOpen(const char *pszFilename, unsigned uOpenFlags,
    14291432                   PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    1430                    void **ppBackendData)
     1433                   VDTYPE enmType, void **ppBackendData)
    14311434{
    14321435    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
     
    21372140    AssertPtr(pImage);
    21382141
    2139     if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
    2140     {
    2141         rc = VERR_VD_IMAGE_READ_ONLY;
    2142         goto out;
    2143     }
    2144 
    21452142    if (pImage)
    2146         rc = VERR_NOT_SUPPORTED;
     2143    {
     2144        if (pImage->uOpenFlags & VD_OPEN_FLAGS_READONLY)
     2145            rc = VERR_VD_IMAGE_READ_ONLY;
     2146        else
     2147            rc = VERR_NOT_SUPPORTED;
     2148    }
    21472149    else
    21482150        rc = VERR_VD_NOT_OPENED;
     
    30203022    VD_CAP_CREATE_FIXED | VD_CAP_CREATE_DYNAMIC |
    30213023    VD_CAP_ASYNC | VD_CAP_VFS,
    3022     /* papszFileExtensions */
    3023     s_apszVhdFileExtensions,
     3024    /* paFileExtensions */
     3025    s_aVhdFileExtensions,
    30243026    /* paConfigInfo */
    30253027    NULL,
  • trunk/src/VBox/Devices/Storage/VmdkHDDCore.cpp

    r33493 r33524  
    514514
    515515/** NULL-terminated array of supported file extensions. */
    516 static const char *const s_apszVmdkFileExtensions[] =
    517 {
    518     "vmdk",
    519     NULL
     516static const VDFILEEXTENSION s_aVmdkFileExtensions[] =
     517{
     518    {"vmdk", VDTYPE_HDD},
     519    {NULL, VDTYPE_INVALID}
    520520};
    521521
     
    57045704/** @copydoc VBOXHDDBACKEND::pfnCheckIfValid */
    57055705static int vmdkCheckIfValid(const char *pszFilename, PVDINTERFACE pVDIfsDisk,
    5706                             PVDINTERFACE pVDIfsImage)
    5707 {
    5708     LogFlowFunc(("pszFilename=\"%s\"\n", pszFilename));
     5706                            PVDINTERFACE pVDIfsImage, VDTYPE *penmType)
     5707{
     5708    LogFlowFunc(("pszFilename=\"%s\" pVDIfsDisk=%#p pVDIfsImage=%#p penmType=%#p\n",
     5709                 pszFilename, pVDIfsDisk, pVDIfsImage, penmType));
    57095710    int rc = VINF_SUCCESS;
    57105711    PVMDKIMAGE pImage;
     
    57385739    RTMemFree(pImage);
    57395740
     5741    if (RT_SUCCESS(rc))
     5742        *penmType = VDTYPE_HDD;
     5743
    57405744out:
    57415745    LogFlowFunc(("returns %Rrc\n", rc));
     
    57465750static int vmdkOpen(const char *pszFilename, unsigned uOpenFlags,
    57475751                    PVDINTERFACE pVDIfsDisk, PVDINTERFACE pVDIfsImage,
    5748                     void **ppBackendData)
     5752                    VDTYPE enmType, void **ppBackendData)
    57495753{
    57505754    LogFlowFunc(("pszFilename=\"%s\" uOpenFlags=%#x pVDIfsDisk=%#p pVDIfsImage=%#p ppBackendData=%#p\n", pszFilename, uOpenFlags, pVDIfsDisk, pVDIfsImage, ppBackendData));
     
    73227326    | VD_CAP_CREATE_SPLIT_2G | VD_CAP_DIFF | VD_CAP_FILE | VD_CAP_ASYNC
    73237327    | VD_CAP_VFS,
    7324     /* papszFileExtensions */
    7325     s_apszVmdkFileExtensions,
     7328    /* paFileExtensions */
     7329    s_aVmdkFileExtensions,
    73267330    /* paConfigInfo */
    73277331    NULL,
  • trunk/src/VBox/Devices/Storage/testcase/tstVD-2.cpp

    r28800 r33524  
    8686};
    8787
     88static const char *tstVDDeviceType(VDTYPE enmType)
     89{
     90    switch (enmType)
     91    {
     92        case VDTYPE_HDD:
     93            return "HardDisk";
     94        case VDTYPE_DVD:
     95            return "DVD";
     96        case VDTYPE_FLOPPY:
     97            return "Floppy";
     98        default:
     99            return "Unknown";
     100    }
     101}
     102
    88103static int tstVDBackendInfo(void)
    89104{
     
    108123        RTPrintf("Backend %u: name=%s capabilities=%#06x extensions=",
    109124                 i, aVDInfo[i].pszBackend, aVDInfo[i].uBackendCaps);
    110         if (aVDInfo[i].papszFileExtensions)
    111         {
    112             const char *const *papsz = aVDInfo[i].papszFileExtensions;
    113             while (*papsz != NULL)
    114             {
    115                 if (papsz != aVDInfo[i].papszFileExtensions)
     125        if (aVDInfo[i].paFileExtensions)
     126        {
     127            PCVDFILEEXTENSION pa = aVDInfo[i].paFileExtensions;
     128            while (pa->pszExtension != NULL)
     129            {
     130                if (pa != aVDInfo[i].paFileExtensions)
    116131                    RTPrintf(",");
    117                 RTPrintf("%s", *papsz);
    118                 papsz++;
    119             }
    120             if (papsz == aVDInfo[i].papszFileExtensions)
     132                RTPrintf("%s (%s)", pa->pszExtension, tstVDDeviceType(pa->enmType));
     133                pa++;
     134            }
     135            if (pa == aVDInfo[i].paFileExtensions)
    121136                RTPrintf("<EMPTY>");
    122137        }
  • trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp

    r33083 r33524  
    9292    AssertRC(rc);
    9393
    94     rc = VDCreate(&VDIError, &pVD);
     94    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
    9595    CHECK("VDCreate()");
    9696
     
    150150    AssertRC(rc);
    151151
    152     rc = VDCreate(&VDIError, &pVD);
     152    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
    153153    CHECK("VDCreate()");
    154154
     
    505505    PVBOXHDD pVD = NULL;
    506506    char *pszFormat;
     507    VDTYPE enmType = VDTYPE_INVALID;
    507508    VDGEOMETRY PCHS = { 0, 0, 0 };
    508509    VDGEOMETRY LCHS = { 0, 0, 0 };
     
    539540
    540541
    541     rc = VDCreate(&VDIError, &pVD);
     542    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
    542543    CHECK("VDCreate()");
    543544
     
    548549        RTFileClose(File);
    549550        rc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
    550                          pszBaseFilename, &pszFormat);
     551                         pszBaseFilename, &pszFormat, &enmType);
    551552        RTPrintf("VDGetFormat() pszFormat=%s rc=%Rrc\n", pszFormat, rc);
    552553        if (RT_SUCCESS(rc) && strcmp(pszFormat, pszBackend))
     
    664665
    665666
    666     rc = VDCreate(&VDIError, &pVD);
     667    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
    667668    CHECK("VDCreate()");
    668669
     
    738739    AssertRC(rc);
    739740
    740     rc = VDCreate(&VDIError, &pVD);
     741    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
    741742    CHECK("VDCreate()");
    742743
     
    789790    AssertRC(rc);
    790791
    791     rc = VDCreate(&VDIError, &pVD);
     792    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
    792793    CHECK("VDCreate()");
    793794
  • trunk/src/VBox/Devices/Storage/testcase/tstVDCopy.cpp

    r32536 r33524  
    7070    char *pbBuf1 = NULL;
    7171    char *pbBuf2 = NULL;
     72    VDTYPE enmTypeVD1 = VDTYPE_INVALID;
     73    VDTYPE enmTypeVD2 = VDTYPE_INVALID;
    7274
    7375#define CHECK(str) \
     
    98100
    99101    rc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
    100                      argv[1], &pszVD1);
     102                     argv[1], &pszVD1, &enmTypeVD1);
    101103    CHECK("VDGetFormat() hdd1");
    102104
    103105    rc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
    104                      argv[2], &pszVD2);
     106                     argv[2], &pszVD2, &enmTypeVD2);
    105107    CHECK("VDGetFormat() hdd2");
    106108
    107     rc = VDCreate(&VDIError, &pVD1);
     109    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD1);
    108110    CHECK("VDCreate() hdd1");
    109111
    110     rc = VDCreate(&VDIError, &pVD2);
     112    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD2);
    111113    CHECK("VDCreate() hdd1");
    112114
  • trunk/src/VBox/Devices/Storage/testcase/tstVDShareable.cpp

    r32536 r33524  
    9292    AssertRC(rc);
    9393
    94     rc = VDCreate(&VDIError, &pVD);
     94    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD);
    9595    CHECK("VDCreate()");
    96     rc = VDCreate(&VDIError, &pVD2);
     96    rc = VDCreate(&VDIError, VDTYPE_HDD, &pVD2);
    9797    CHECK("VDCreate() #2");
    9898
  • trunk/src/VBox/Devices/Storage/testcase/tstVDSnap.cpp

    r32536 r33524  
    276276
    277277
    278     rc = VDCreate(pVDIfs, &pVD);
     278    rc = VDCreate(pVDIfs, VDTYPE_HDD, &pVD);
    279279    CHECK("VDCreate()");
    280280
  • trunk/src/VBox/Devices/Storage/testcase/vbox-img.cpp

    r33288 r33524  
    124124    const char *pszFilename = NULL;
    125125    char *pszFormat = NULL;
     126    VDTYPE enmType = VDTYPE_INVALID;
    126127    RTUUID imageUuid;
    127128    RTUUID parentUuid;
     
    188189        /* Don't pass error interface, as that would triggers error messages
    189190         * because some backends fail to open the image. */
    190         rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat);
     191        rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType);
    191192        if (RT_FAILURE(rc))
    192193            return errorRuntime("Format autodetect failed: %Rrc\n", rc);
     
    194195
    195196    PVBOXHDD pVD = NULL;
    196     rc = VDCreate(pVDIfs, &pVD);
     197    rc = VDCreate(pVDIfs, enmType, &pVD);
    197198    if (RT_FAILURE(rc))
    198199        return errorRuntime("Cannot create the virtual disk container: %Rrc\n", rc);
     
    625626    bool fStdOut = false;
    626627    const char *pszSrcFormat = NULL;
     628    VDTYPE enmSrcType = VDTYPE_HDD;
    627629    const char *pszDstFormat = NULL;
    628630    const char *pszVariant = NULL;
     
    788790        if (!pszSrcFormat)
    789791        {
    790             char *pszFormat;
    791             rc = VDGetFormat(NULL, NULL, pszSrcFilename, &pszFormat);
     792            char *pszFormat = NULL;
     793            VDTYPE enmType = VDTYPE_INVALID;
     794            rc = VDGetFormat(NULL, NULL, pszSrcFilename, &pszFormat, &enmType);
    792795            if (RT_FAILURE(rc))
    793796            {
     
    796799            }
    797800            pszSrcFormat = pszFormat;
    798         }
    799 
    800         rc = VDCreate(pVDIfs, &pSrcDisk);
     801            enmSrcType = enmType;
     802        }
     803
     804        rc = VDCreate(pVDIfs, enmSrcType, &pSrcDisk);
    801805        if (RT_FAILURE(rc))
    802806        {
     
    814818        }
    815819
    816         rc = VDCreate(pVDIfs, &pDstDisk);
     820        rc = VDCreate(pVDIfs, VDTYPE_HDD, &pDstDisk);
    817821        if (RT_FAILURE(rc))
    818822        {
     
    883887    /* just try it */
    884888    char *pszFormat = NULL;
    885     rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat);
     889    VDTYPE enmType = VDTYPE_INVALID;
     890    rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType);
    886891    if (RT_FAILURE(rc))
    887892        return errorSyntax("Format autodetect failed: %Rrc\n", rc);
    888893
    889     rc = VDCreate(pVDIfs, &pDisk);
     894    rc = VDCreate(pVDIfs, enmType, &pDisk);
    890895    if (RT_FAILURE(rc))
    891896        return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc);
     
    940945    /* just try it */
    941946    char *pszFormat = NULL;
    942     rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat);
     947    VDTYPE enmType = VDTYPE_INVALID;
     948    rc = VDGetFormat(NULL, NULL, pszFilename, &pszFormat, &enmType);
    943949    if (RT_FAILURE(rc))
    944950        return errorSyntax("Format autodetect failed: %Rrc\n", rc);
    945951
    946     rc = VDCreate(pVDIfs, &pDisk);
     952    rc = VDCreate(pVDIfs, enmType, &pDisk);
    947953    if (RT_FAILURE(rc))
    948954        return errorRuntime("Error while creating the virtual disk container: %Rrc\n", rc);
  • trunk/src/VBox/Devices/Storage/testcase/vditool.cpp

    r32536 r33524  
    104104
    105105    PVBOXHDD hdd;
    106     rc = VDCreate(NULL, &hdd);
     106    rc = VDCreate(NULL, VDTYPE_HDD, &hdd);
    107107    if (RT_FAILURE(rc))
    108108        return PrintDone(rc);
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