VirtualBox

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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,
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