VirtualBox

vbox的更動 9560 路徑 trunk/src/VBox/Devices/Storage


忽略:
時間撮記:
2008-6-9 下午06:52:18 (16 年 以前)
作者:
vboxsync
訊息:

Straighten handling of image types in the generic code. Also cleanup here and there.

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Devices/Storage/VBoxHDD-new.cpp

    r9528 r9560  
    6060    /** Data managed by the backend which keeps the actual info. */
    6161    void            *pvBackendData;
     62    /** Cached sanitized image type. */
     63    VDIMAGETYPE     enmImageType;
    6264    /** Image open flags (only those handled generically in this code and which
    6365     * the backends will never ever see). */
     
    11011103        rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData,
    11021104                                              &enmImageType);
    1103         /* Check image type. As the image itself has no idea whether it's a
    1104          * base image or not, this info is derived here. Image 0 can be fixed
    1105          * or normal, all others must be normal images. */
     1105        /* Check image type. As the image itself has only partial knowledge
     1106         * whether it's a base image or not, this info is derived here. The
     1107         * base image can be fixed or normal, all others must be normal or
     1108         * diff images. Some image formats don't distinguish between normal
     1109         * and diff images, so this must be corrected here. */
    11061110        if (    VBOX_SUCCESS(rc)
    1107             &&  !(uOpenFlags & VD_OPEN_FLAGS_INFO)
    1108             &&  pDisk->cImages != 0
    1109             &&  enmImageType != VD_IMAGE_TYPE_NORMAL)
     1111            &&  !(uOpenFlags & VD_OPEN_FLAGS_INFO))
    11101112        {
    11111113            rc = VERR_VDI_INVALID_TYPE;
    11121114            break;
    11131115        }
     1116        if (    pDisk->cImages == 0
     1117            &&  (   enmImageType != VD_IMAGE_TYPE_FIXED
     1118                 || enmImageType != VD_IMAGE_TYPE_NORMAL))
     1119        {
     1120            rc = VERR_VDI_INVALID_TYPE;
     1121            break;
     1122        }
     1123        else if (pDisk->cImages != 0)
     1124        {
     1125            if (    enmImageType != VD_IMAGE_TYPE_NORMAL
     1126                ||  enmImageType != VD_IMAGE_TYPE_DIFF)
     1127            {
     1128                rc = VERR_VDI_INVALID_TYPE;
     1129                break;
     1130            }
     1131            else
     1132                enmImageType = VD_IMAGE_TYPE_DIFF;
     1133        }
     1134        pImage->enmImageType = enmImageType;
    11141135
    11151136        /* Force sane optimization settings. It's not worth avoiding writes
     
    13241345        if (VBOX_SUCCESS(rc))
    13251346        {
     1347            pImage->enmImageType = enmType;
     1348
    13261349            /* Force sane optimization settings. It's not worth avoiding writes
    13271350             * to fixed size images. The overhead would have almost no payback. */
     
    14951518        if (VBOX_SUCCESS(rc) && pDisk->cImages != 0)
    14961519        {
     1520            pImage->enmImageType = VD_IMAGE_TYPE_DIFF;
     1521
    14971522            /* Switch previous image to read-only mode. */
    14981523            unsigned uOpenFlagsPrevImg;
     
    18771902            rc2 = VDOpen(pDiskFrom, pImageFrom->Backend->pszBackendName, pImageFrom->pszFilename, pImageFrom->uOpenFlags);
    18781903            if (VBOX_FAILURE(rc2))
    1879                 /* @todo Uncertain what to do on error. If this happens pImageFrom and pImageTo are both closed. */
     1904                /** @todo Uncertain what to do on error. If this happens pImageFrom and pImageTo are both closed. */
    18801905                rc = rc2;
    18811906            break;
     
    18881913
    18891914        /* Collect properties of source image. */
    1890         VDIMAGETYPE enmTypeFrom;
    1891         rc = VDGetImageType(pDiskFrom, nImage, &enmTypeFrom);
    1892         if (VBOX_FAILURE(rc))
    1893             break;
    1894 
    1895         uint64_t cbSizeFrom = VDGetSize(pDiskFrom, nImage);
     1915        VDIMAGETYPE enmTypeFrom = pImageFrom->enmImageType;
     1916
     1917        uint64_t cbSizeFrom;
     1918        cbSizeFrom = pImageFrom->Backend->pfnGetSize(pImageFrom->pvBackendData);
    18961919        if (cbSizeFrom == 0)
    18971920        {
     
    19041927
    19051928        unsigned uImageFlagsFrom;
    1906         rc = VDGetImageFlags(pDiskFrom, nImage, &uImageFlagsFrom);
    1907         if (VBOX_FAILURE(rc))
    1908             break;
    1909 
    1910         /* @todo Get this from the source image. */
     1929        uImageFlagsFrom = pImageFrom->Backend->pfnGetImageFlags(pImageFrom->pvBackendData);
     1930
     1931        /** @todo Get this from the source image. */
    19111932        PDMMEDIAGEOMETRY PCHSGeometryFrom = {0, 0, 0};
    19121933        PDMMEDIAGEOMETRY LCHSGeometryFrom = {0, 0, 0};
    19131934
    19141935        unsigned uOpenFlagsFrom;
    1915         rc = VDGetOpenFlags(pDiskFrom, nImage, &uOpenFlagsFrom);
    1916         if (VBOX_FAILURE(rc))
    1917             break;
     1936        uOpenFlagsFrom = pImageFrom->Backend->pfnGetOpenFlags(pImageFrom->pvBackendData);
    19181937
    19191938        /* Create destination image with the properties of the source image. */
    1920         /* @todo Copy the comment. */
     1939        /** @todo Copy the comment. */
     1940        /** @todo replace the VDCreateDiff/VDCreateBase calls by direct
     1941         * calls to the backend. Unifies the code and reduces the API
     1942         * dependencies. */
    19211943        if (enmTypeFrom == VD_IMAGE_TYPE_DIFF)
    19221944        {
     
    27372759                                 PVDIMAGETYPE penmType)
    27382760{
    2739     int rc;
     2761    int rc = VINF_SUCCESS;
    27402762
    27412763    LogFlowFunc(("pDisk=%#p nImage=%u penmType=%#p\n",
     
    27552777        AssertPtrBreakStmt(pImage, rc = VERR_VDI_IMAGE_NOT_FOUND);
    27562778
    2757         rc = pImage->Backend->pfnGetImageType(pImage->pvBackendData,
    2758                                               penmType);
     2779        *penmType = pImage->enmImageType;
    27592780    } while (0);
    27602781
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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