VirtualBox

Changeset 3038 in vbox for trunk/src


Ignore:
Timestamp:
Jun 4, 2007 7:31:36 PM (18 years ago)
Author:
vboxsync
Message:

Main: Added basic VMDK property support via the new API (retrieving UUIDs and virtual size).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/HardDiskImpl.cpp

    r3007 r3038  
    13691369 *  Initializes the VDI hard disk object using the given image file name.
    13701370 *
    1371  *  @param aFilePath    path to the image file (can be NULL to create an
    1372  *                      imageless object)
    1373  *  @param aRegistered  whether to mark this disk as registered or not
    1374  *                      (ignored when \a aFilePath is NULL, assuming FALSE)
     1371 *  @param aVirtualBox  VirtualBox parent.
     1372 *  @param aParent      Parent hard disk.
     1373 *  @param aFilePath    Path to the image file, or @c NULL to create an
     1374 *                      image-less object.
     1375 *  @param aRegistered  Whether to mark this disk as registered or not
     1376 *                      (ignored when @a aFilePath is @c NULL, assuming @c FALSE)
    13751377 */
    13761378HRESULT HVirtualDiskImage::init (VirtualBox *aVirtualBox, HardDisk *aParent,
     
    33933395 *
    33943396 *  @param aVirtualBox  VirtualBox parent.
    3395  *  @param aParent      Currently, must always be NULL.
    3396  *  @param aFilePath    path to the image file (can be NULL to create an
    3397  *                      imageless object)
    3398  *  @param aRegistered  whether to mark this disk as registered or not
    3399  *                      (ignored when \a aFilePath is NULL, assuming FALSE)
     3397 *  @param aParent      Currently, must always be @c NULL.
     3398 *  @param aFilePath    Path to the image file, or @c NULL to create an
     3399 *                      image-less object.
     3400 *  @param aRegistered  Whether to mark this disk as registered or not
     3401 *                      (ignored when @a aFilePath is @c NULL, assuming @c FALSE)
    34003402 */
    34013403HRESULT HVMDKImage::init (VirtualBox *aVirtualBox, HardDisk *aParent,
     
    39113913}
    39123914
     3915DECLCALLBACK(void) VDError (void *pvUser, int rc, RT_SRC_POS_DECL,
     3916                            const char *pszFormat, va_list va)
     3917{
     3918    /// @todo pass the error message to the operation initiator
     3919}
     3920
    39133921/**
    39143922 *  Helper to query information about the VDI hard disk.
     
    39503958    Bstr errMsg;
    39513959
     3960    PVBOXHDD hdd = NULL;
     3961
    39523962    do
    39533963    {
    3954         /// @todo remove when the code below is implemented
    3955         if (mId.isEmpty())
    3956             mId.create();
    3957 
    3958 /// @todo  implement
    3959 //
    3960 //         /* check the image file */
    3961 //         Guid id, parentId;
    3962 //         vrc = VDICheckImage (filePath, NULL, NULL, NULL,
    3963 //                              id.ptr(), parentId.ptr(), NULL, 0);
    3964 //
    3965 //         if (VBOX_FAILURE (vrc))
    3966 //             break;
    3967 //
    3968 //         if (!mId.isEmpty())
    3969 //         {
    3970 //             /* check that the actual UUID of the image matches the stored UUID */
    3971 //             if (mId != id)
    3972 //             {
    3973 //                 errMsg = Utf8StrFmt (
    3974 //                     tr ("Actual UUID {%Vuuid} of the hard disk image '%s' doesn't "
    3975 //                         "match UUID {%Vuuid} stored in the registry"),
    3976 //                     id.ptr(), filePath.raw(), mId.ptr());
    3977 //                 break;
    3978 //             }
    3979 //         }
    3980 //         else
    3981 //         {
    3982 //             /* assgn an UUID read from the image file */
    3983 //             mId = id;
    3984 //         }
    3985 //
    3986 //         if (mParent)
    3987 //         {
    3988 //             /* check parent UUID */
    3989 //             AutoLock parentLock (mParent);
    3990 //             if (mParent->id() != parentId)
    3991 //             {
    3992 //                 errMsg = Utf8StrFmt (
    3993 //                     tr ("UUID {%Vuuid} of the parent image '%ls' stored in "
    3994 //                         "the hard disk image file '%s' doesn't match "
    3995 //                         "UUID {%Vuuid} stored in the registry"),
    3996 //                     parentId.raw(), mParent->toString().raw(),
    3997 //                     filePath.raw(), mParent->id().raw());
    3998 //                 break;
    3999 //             }
    4000 //         }
    4001 //         else if (!parentId.isEmpty())
    4002 //         {
    4003 //             errMsg = Utf8StrFmt (
    4004 //                 tr ("Hard disk image '%s' is a differencing image that is linked "
    4005 //                     "to a hard disk with UUID {%Vuuid} and cannot be used "
    4006 //                     "directly as a base hard disk"),
    4007 //                 filePath.raw(), parentId.raw());
    4008 //             break;
    4009 //         }
    4010 //
    4011 //         {
    4012 //             RTFILE file = NIL_RTFILE;
    4013 //             vrc = RTFileOpen (&file, filePath, RTFILE_O_READ);
    4014 //             if (VBOX_SUCCESS (vrc))
    4015 //             {
    4016 //                 uint64_t size = 0;
    4017 //                 vrc = RTFileGetSize (file, &size);
    4018 //                 if (VBOX_SUCCESS (vrc))
    4019 //                     mActualSize = size;
    4020 //                 RTFileClose (file);
    4021 //             }
    4022 //             if (VBOX_FAILURE (vrc))
    4023 //                 break;
    4024 //         }
    4025 //
    4026 //         if (!mParent)
    4027 //         {
    4028 //             /* query logical size only for non-differencing images */
    4029 //
    4030 //             PVDIDISK disk = VDIDiskCreate();
    4031 //             vrc = VDIDiskOpenImage (disk, Utf8Str (mFilePathFull),
    4032 //                                     VDI_OPEN_FLAGS_READONLY);
    4033 //             if (VBOX_SUCCESS (vrc))
    4034 //             {
    4035 //                 uint64_t size = VDIDiskGetSize (disk);
    4036 //                 /* convert to MBytes */
    4037 //                 mSize = size / 1024 / 1024;
    4038 //             }
    4039 //
    4040 //             VDIDiskDestroy (disk);
    4041 //             if (VBOX_FAILURE (vrc))
    4042 //                 break;
    4043 //         }
     3964        Guid id, parentId;
     3965
     3966        /// @todo make PVBOXHDD a member variable and init/destroy it upon
     3967        /// image creation/deletion instead of doing that here every time.
     3968
     3969        vrc = VDCreate ("VMDK", err, NULL, &hdd);
     3970        if (VBOX_FAILURE (vrc))
     3971            break;
     3972
     3973        vrc = VDOpen (hdd, filePath, VD_OPEN_FLAGS_READONLY);
     3974        if (VBOX_FAILURE (vrc))
     3975            break;
     3976
     3977        vrc = VDGetUuid (hdd, 0, id.ptr());
     3978        if (VBOX_FAILURE (vrc))
     3979            break;
     3980        vrc = VDGetParentUuid (hdd, 0, parentId.ptr());
     3981        if (VBOX_FAILURE (vrc))
     3982            break;
     3983
     3984        if (!mId.isEmpty())
     3985        {
     3986            /* check that the actual UUID of the image matches the stored UUID */
     3987            if (mId != id)
     3988            {
     3989                errMsg = Utf8StrFmt (
     3990                    tr ("Actual UUID {%Vuuid} of the hard disk image '%s' doesn't "
     3991                        "match UUID {%Vuuid} stored in the registry"),
     3992                    id.ptr(), filePath.raw(), mId.ptr());
     3993                break;
     3994            }
     3995        }
     3996        else
     3997        {
     3998            /* assgn an UUID read from the image file */
     3999            mId = id;
     4000        }
     4001
     4002        if (mParent)
     4003        {
     4004            /* check parent UUID */
     4005            AutoLock parentLock (mParent);
     4006            if (mParent->id() != parentId)
     4007            {
     4008                errMsg = Utf8StrFmt (
     4009                    tr ("UUID {%Vuuid} of the parent image '%ls' stored in "
     4010                        "the hard disk image file '%s' doesn't match "
     4011                        "UUID {%Vuuid} stored in the registry"),
     4012                    parentId.raw(), mParent->toString().raw(),
     4013                    filePath.raw(), mParent->id().raw());
     4014                break;
     4015            }
     4016        }
     4017        else if (!parentId.isEmpty())
     4018        {
     4019            errMsg = Utf8StrFmt (
     4020                tr ("Hard disk image '%s' is a differencing image that is linked "
     4021                    "to a hard disk with UUID {%Vuuid} and cannot be used "
     4022                    "directly as a base hard disk"),
     4023                filePath.raw(), parentId.raw());
     4024            break;
     4025        }
     4026
     4027        /* get actual file size */
     4028        /// @todo is there a direct method in RT?
     4029        {
     4030            RTFILE file = NIL_RTFILE;
     4031            vrc = RTFileOpen (&file, filePath, RTFILE_O_READ);
     4032            if (VBOX_SUCCESS (vrc))
     4033            {
     4034                uint64_t size = 0;
     4035                vrc = RTFileGetSize (file, &size);
     4036                if (VBOX_SUCCESS (vrc))
     4037                    mActualSize = size;
     4038                RTFileClose (file);
     4039            }
     4040            if (VBOX_FAILURE (vrc))
     4041                break;
     4042        }
     4043
     4044        /* query logical size only for non-differencing images */
     4045        if (!mParent)
     4046        {
     4047            uint64_t size = VDGetSize (hdd);
     4048            /* convert to MBytes */
     4049            mSize = size / 1024 / 1024;
     4050        }
    40444051    }
    40454052    while (0);
     4053
     4054    if (hdd)
     4055        VDDestroy (hdd);
    40464056
    40474057    /* enter the lock again */
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