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/Main/HardDiskImpl.cpp

    r17911 r17970  
    5858struct HardDisk::Task : public com::SupportErrorInfoBase
    5959{
    60     enum Operation { CreateDynamic, CreateFixed, CreateDiff,
     60    enum Operation { CreateBase, CreateDiff,
    6161                     Merge, Clone, Delete, Reset };
    6262
     
    9898        Data() : size (0) {}
    9999
    100         /* CreateDynamic, CreateStatic */
     100        /* CreateBase */
    101101
    102102        uint64_t size;
    103103
    104         /* CreateDynamic, CreateStatic, CreateDiff, Clone */
     104        /* CreateBase, CreateDiff, Clone */
    105105
    106106        HardDiskVariant_T variant;
     
    11781178}
    11791179
    1180 STDMETHODIMP HardDisk::CreateDynamicStorage(ULONG64 aLogicalSize,
    1181                                             HardDiskVariant_T aVariant,
    1182                                             IProgress **aProgress)
     1180STDMETHODIMP HardDisk::CreateBaseStorage(ULONG64 aLogicalSize,
     1181                                         HardDiskVariant_T aVariant,
     1182                                         IProgress **aProgress)
    11831183{
    11841184    CheckComArgOutPointerValid (aProgress);
     
    11891189    AutoWriteLock alock (this);
    11901190
    1191     if (!(mm.formatObj->capabilities() &
    1192           HardDiskFormatCapabilities_CreateDynamic))
     1191    aVariant &= ~HardDiskVariant_Diff;
     1192    if (    !(aVariant & HardDiskVariant_Fixed)
     1193        &&  !(mm.formatObj->capabilities() & HardDiskFormatCapabilities_CreateDynamic))
    11931194        return setError (VBOX_E_NOT_SUPPORTED,
    11941195            tr ("Hard disk format '%ls' does not support dynamic storage "
     1196                "creation"), mm.format.raw());
     1197    if (    (aVariant & HardDiskVariant_Fixed)
     1198        &&  !(mm.formatObj->capabilities() & HardDiskFormatCapabilities_CreateDynamic))
     1199        return setError (VBOX_E_NOT_SUPPORTED,
     1200            tr ("Hard disk format '%ls' does not support fixed storage "
    11951201                "creation"), mm.format.raw());
    11961202
     
    12051211    ComObjPtr <Progress> progress;
    12061212    progress.createObject();
     1213    /// @todo include fixed/dynamic
    12071214    HRESULT rc = progress->init (mVirtualBox, static_cast<IHardDisk*>(this),
    1208         BstrFmt (tr ("Creating dynamic hard disk storage unit '%ls'"),
    1209                  m.locationFull.raw()),
     1215        (aVariant & HardDiskVariant_Fixed)
     1216          ? BstrFmt (tr ("Creating fixed hard disk storage unit '%ls'"), m.locationFull.raw())
     1217          : BstrFmt (tr ("Creating dynamic hard disk storage unit '%ls'"), m.locationFull.raw()),
    12101218        FALSE /* aCancelable */);
    12111219    CheckComRCReturnRC (rc);
     
    12141222     * asynchronously */
    12151223
    1216     std::auto_ptr <Task> task (new Task (this, progress, Task::CreateDynamic));
    1217     AssertComRCReturnRC (task->autoCaller.rc());
    1218 
    1219     task->d.size = aLogicalSize;
    1220     task->d.variant = aVariant;
    1221 
    1222     rc = task->startThread();
    1223     CheckComRCReturnRC (rc);
    1224 
    1225     /* go to Creating state on success */
    1226     m.state = MediaState_Creating;
    1227 
    1228     /* task is now owned by taskThread() so release it */
    1229     task.release();
    1230 
    1231     /* return progress to the caller */
    1232     progress.queryInterfaceTo (aProgress);
    1233 
    1234     return S_OK;
    1235 }
    1236 
    1237 STDMETHODIMP HardDisk::CreateFixedStorage(ULONG64 aLogicalSize,
    1238                                           HardDiskVariant_T aVariant,
    1239                                           IProgress **aProgress)
    1240 {
    1241     CheckComArgOutPointerValid (aProgress);
    1242 
    1243     AutoCaller autoCaller (this);
    1244     CheckComRCReturnRC (autoCaller.rc());
    1245 
    1246     AutoWriteLock alock (this);
    1247 
    1248     if (!(mm.formatObj->capabilities() &
    1249           HardDiskFormatCapabilities_CreateFixed))
    1250         return setError (VBOX_E_NOT_SUPPORTED,
    1251             tr ("Hard disk format '%ls' does not support fixed storage "
    1252                 "creation"), mm.format.raw());
    1253 
    1254     switch (m.state)
    1255     {
    1256         case MediaState_NotCreated:
    1257             break;
    1258         default:
    1259             return setStateError();
    1260     }
    1261 
    1262     ComObjPtr <Progress> progress;
    1263     progress.createObject();
    1264     HRESULT rc = progress->init (mVirtualBox, static_cast<IHardDisk*>(this),
    1265         BstrFmt (tr ("Creating fixed hard disk storage unit '%ls'"),
    1266                  m.locationFull.raw()),
    1267         FALSE /* aCancelable */);
    1268     CheckComRCReturnRC (rc);
    1269 
    1270     /* setup task object and thread to carry out the operation
    1271      * asynchronously */
    1272 
    1273     std::auto_ptr <Task> task (new Task (this, progress, Task::CreateFixed));
     1224    std::auto_ptr <Task> task (new Task (this, progress, Task::CreateBase));
    12741225    AssertComRCReturnRC (task->autoCaller.rc());
    12751226
     
    29872938
    29882939            /* check the type */
    2989             VDIMAGETYPE type;
    2990             vrc = VDGetImageType (hdd, 0, &type);
     2940            unsigned uImageFlags;
     2941            vrc = VDGetImageFlags (hdd, 0, &uImageFlags);
    29912942            ComAssertRCThrow (vrc, E_FAIL);
    29922943
    2993             if (type == VD_IMAGE_TYPE_DIFF)
     2944            if (uImageFlags & VD_IMAGE_FLAGS_DIFF)
    29942945            {
    29952946                RTUUID parentId;
     
    33973348        ////////////////////////////////////////////////////////////////////////
    33983349
    3399         case Task::CreateDynamic:
    3400         case Task::CreateFixed:
     3350        case Task::CreateBase:
    34013351        {
    34023352            /* The lock is also used as a signal from the task initiator (which
     
    34443394
    34453395                    vrc = VDCreateBase (hdd, format, location,
    3446                                         task->operation == Task::CreateDynamic ?
    3447                                             VD_IMAGE_TYPE_NORMAL :
    3448                                             VD_IMAGE_TYPE_FIXED,
    34493396                                        task->d.size * _1M,
    34503397                                        task->d.variant,
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