VirtualBox

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


Ignore:
Timestamp:
Jun 29, 2009 2:48:34 PM (15 years ago)
Author:
vboxsync
Message:

Storage/VBoxHDD: modify VDCopy so that it can copy to existing images

File:
1 edited

Legend:

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

    r20418 r21025  
    19591959        }
    19601960
    1961         /* When moving an image pszFilename is allowed to be NULL, so do the parameter check here. */
    1962         AssertMsgBreakStmt(VALID_PTR(pszFilename) && *pszFilename,
     1961        /* pszFilename is allowed to be NULL, as this indicates copy to the existing image. */
     1962        AssertMsgBreakStmt(pszFilename == NULL || (VALID_PTR(pszFilename) && *pszFilename),
    19631963                           ("pszFilename=%#p \"%s\"\n", pszFilename, pszFilename),
    19641964                           rc = VERR_INVALID_PARAMETER);
     
    19711971            break;
    19721972        }
    1973 
    1974         if (cbSize == 0)
    1975             cbSize = cbSizeFrom;
    19761973
    19771974        PDMMEDIAGEOMETRY PCHSGeometryFrom = {0, 0, 0};
     
    20152012        uOpenFlagsFrom = pImageFrom->Backend->pfnGetOpenFlags(pImageFrom->pvBackendData);
    20162013
    2017         /* Create destination image with the properties of the source image. */
    2018         /** @todo replace the VDCreateDiff/VDCreateBase calls by direct
    2019          * calls to the backend. Unifies the code and reduces the API
    2020          * dependencies. */
    2021         if (uImageFlags & VD_IMAGE_FLAGS_DIFF)
    2022         {
    2023             rc = VDCreateDiff(pDiskTo, pszBackend, pszFilename, uImageFlags,
    2024                               szComment, &ImageUuid, &ParentUuid, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
    2025         } else {
    2026             /** @todo Please, review this! It's an ugly hack I think... */
    2027             if (!RTStrICmp(pszBackend, "RAW"))
    2028                 uImageFlags |= VD_IMAGE_FLAGS_FIXED;
    2029 
    2030             rc = VDCreateBase(pDiskTo, pszBackend, pszFilename, cbSize,
    2031                               uImageFlags, szComment,
    2032                               &PCHSGeometryFrom, &LCHSGeometryFrom,
    2033                               NULL, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
    2034             if (RT_SUCCESS(rc) && !RTUuidIsNull(&ImageUuid))
    2035                  pDiskTo->pLast->Backend->pfnSetUuid(pDiskTo->pLast->pvBackendData, &ImageUuid);
    2036             if (RT_SUCCESS(rc) && !RTUuidIsNull(&ParentUuid))
    2037                  pDiskTo->pLast->Backend->pfnSetParentUuid(pDiskTo->pLast->pvBackendData, &ParentUuid);
    2038         }
    2039         if (RT_FAILURE(rc))
    2040             break;
    2041 
    2042         pImageTo = pDiskTo->pLast;
    2043         AssertPtrBreakStmt(pImageTo, rc = VERR_VD_IMAGE_NOT_FOUND);
     2014        if (pszFilename)
     2015        {
     2016            if (cbSize == 0)
     2017                cbSize = cbSizeFrom;
     2018
     2019            /* Create destination image with the properties of the source image. */
     2020            /** @todo replace the VDCreateDiff/VDCreateBase calls by direct
     2021             * calls to the backend. Unifies the code and reduces the API
     2022             * dependencies. */
     2023            if (uImageFlags & VD_IMAGE_FLAGS_DIFF)
     2024            {
     2025                rc = VDCreateDiff(pDiskTo, pszBackend, pszFilename, uImageFlags,
     2026                                  szComment, &ImageUuid, &ParentUuid, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
     2027            } else {
     2028                /** @todo Please, review this! It's an ugly hack I think... */
     2029                if (!RTStrICmp(pszBackend, "RAW"))
     2030                    uImageFlags |= VD_IMAGE_FLAGS_FIXED;
     2031
     2032                rc = VDCreateBase(pDiskTo, pszBackend, pszFilename, cbSize,
     2033                                  uImageFlags, szComment,
     2034                                  &PCHSGeometryFrom, &LCHSGeometryFrom,
     2035                                  NULL, uOpenFlagsFrom & ~VD_OPEN_FLAGS_READONLY, NULL, NULL);
     2036                if (RT_SUCCESS(rc) && !RTUuidIsNull(&ImageUuid))
     2037                     pDiskTo->pLast->Backend->pfnSetUuid(pDiskTo->pLast->pvBackendData, &ImageUuid);
     2038                if (RT_SUCCESS(rc) && !RTUuidIsNull(&ParentUuid))
     2039                     pDiskTo->pLast->Backend->pfnSetParentUuid(pDiskTo->pLast->pvBackendData, &ParentUuid);
     2040            }
     2041            if (RT_FAILURE(rc))
     2042                break;
     2043
     2044            pImageTo = pDiskTo->pLast;
     2045            AssertPtrBreakStmt(pImageTo, rc = VERR_VD_IMAGE_NOT_FOUND);
     2046        }
     2047        else
     2048        {
     2049            pImageTo = pDiskTo->pLast;
     2050            AssertPtrBreakStmt(pImageTo, rc = VERR_VD_IMAGE_NOT_FOUND);
     2051
     2052            uint64_t cbSizeTo;
     2053            cbSizeTo = pImageTo->Backend->pfnGetSize(pImageTo->pvBackendData);
     2054            if (cbSizeTo == 0)
     2055            {
     2056                rc = VERR_VD_VALUE_NOT_FOUND;
     2057                break;
     2058            }
     2059
     2060            if (cbSize == 0)
     2061                cbSize = RT_MIN(cbSizeFrom, cbSizeTo);
     2062        }
    20442063
    20452064        /* Allocate tmp buffer. */
     
    20932112        {
    20942113            pImageTo->Backend->pfnSetModificationUuid(pImageTo->pvBackendData, &ImageModificationUuid);
    2095             pImageTo->Backend->pfnGetParentModificationUuid(pImageTo->pvBackendData, &ParentModificationUuid);
    2096         }
    2097     } while (0);
    2098 
    2099     if (RT_FAILURE(rc) && pImageTo)
     2114            /** @todo double-check this - it makes little sense to copy over the parent modification uuid,
     2115             * as the destination image can have a totally different parent. */
     2116#if 0
     2117            pImageTo->Backend->pfnSetParentModificationUuid(pImageTo->pvBackendData, &ParentModificationUuid);
     2118#endif
     2119        }
     2120    } while (0);
     2121
     2122    if (RT_FAILURE(rc) && pImageTo && pszFilename)
    21002123    {
    21012124        /* Error detected, but new image created. Remove image from list. */
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