Changeset 54438 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 24, 2015 11:09:17 AM (10 years ago)
- Location:
- trunk/src/VBox/Frontends
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.cpp
r53354 r54438 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 480 480 { "unregistervm", USAGE_UNREGISTERVM, handleUnregisterVM }, 481 481 { "clonevm", USAGE_CLONEVM, handleCloneVM }, 482 { "hdproperty", USAGE_HDPROPERTY, handleMediumProperty }, 483 { "createdvd", USAGE_CREATEDVD, handleCreateDVD }, 484 { "createfloppy", USAGE_CREATEFLOPPY, handleCreateFloppy }, 485 { "createhd", USAGE_CREATEHD, handleCreateHardDisk }, 486 { "createvdi", USAGE_CREATEHD, handleCreateHardDisk }, /* backward compatibility */ 487 { "modifyhd", USAGE_MODIFYHD, handleModifyHardDisk }, 488 { "modifyvdi", USAGE_MODIFYHD, handleModifyHardDisk }, /* backward compatibility */ 489 { "clonehd", USAGE_CLONEHD, handleCloneHardDisk }, 490 { "clonevdi", USAGE_CLONEHD, handleCloneHardDisk }, /* backward compatibility */ 482 { "mediumproperty", USAGE_MEDIUMPROPERTY, handleMediumProperty }, 483 { "hdproperty", USAGE_MEDIUMPROPERTY, handleMediumProperty }, /* backward compatibility */ 484 { "createmedium", USAGE_CREATEMEDIUM, handleCreateMedium }, 485 { "createhd", USAGE_CREATEMEDIUM, handleCreateMedium }, /* backward compatibility */ 486 { "createvdi", USAGE_CREATEMEDIUM, handleCreateMedium }, /* backward compatibility */ 487 { "modifymedium", USAGE_MODIFYMEDIUM, handleModifyMedium }, 488 { "modifyhd", USAGE_MODIFYMEDIUM, handleModifyMedium }, /* backward compatibility */ 489 { "modifyvdi", USAGE_MODIFYMEDIUM, handleModifyMedium }, /* backward compatibility */ 490 { "clonemedium", USAGE_CLONEMEDIUM, handleCloneMedium }, 491 { "clonehd", USAGE_CLONEMEDIUM, handleCloneMedium }, /* backward compatibility */ 492 { "clonevdi", USAGE_CLONEMEDIUM, handleCloneMedium }, /* backward compatibility */ 491 493 { "createvm", USAGE_CREATEVM, handleCreateVM }, 492 494 { "modifyvm", USAGE_MODIFYVM, handleModifyVM }, … … 499 501 { "storageattach", USAGE_STORAGEATTACH, handleStorageAttach }, 500 502 { "storagectl", USAGE_STORAGECONTROLLER, handleStorageController }, 501 { "showhdinfo", USAGE_SHOWHDINFO, handleShowHardDiskInfo }, 502 { "showvdiinfo", USAGE_SHOWHDINFO, handleShowHardDiskInfo }, /* backward compatibility */ 503 { "showmediuminfo", USAGE_SHOWMEDIUMINFO, handleShowMediumInfo }, 504 { "showhdinfo", USAGE_SHOWMEDIUMINFO, handleShowMediumInfo }, /* backward compatibility */ 505 { "showvdiinfo", USAGE_SHOWMEDIUMINFO, handleShowMediumInfo }, /* backward compatibility */ 503 506 { "getextradata", USAGE_GETEXTRADATA, handleGetExtraData }, 504 507 { "setextradata", USAGE_SETEXTRADATA, handleSetExtraData }, -
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r53354 r54438 5 5 6 6 /* 7 * Copyright (C) 2006-201 4Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 53 53 #define USAGE_SNAPSHOT RT_BIT_64(10) 54 54 #define USAGE_CLOSEMEDIUM RT_BIT_64(11) 55 #define USAGE_SHOW HDINFORT_BIT_64(12)56 #define USAGE_CREATE HDRT_BIT_64(13)57 #define USAGE_MODIFY HDRT_BIT_64(14)58 #define USAGE_CLONE HDRT_BIT_64(15)55 #define USAGE_SHOWMEDIUMINFO RT_BIT_64(12) 56 #define USAGE_CREATEMEDIUM RT_BIT_64(13) 57 #define USAGE_MODIFYMEDIUM RT_BIT_64(14) 58 #define USAGE_CLONEMEDIUM RT_BIT_64(15) 59 59 #define USAGE_CREATEHOSTIF RT_BIT_64(17) 60 60 #define USAGE_REMOVEHOSTIF RT_BIT_64(18) … … 104 104 #define USAGE_REPAIRHD RT_BIT_64(58) 105 105 #define USAGE_NATNETWORK RT_BIT_64(59) 106 #define USAGE_HDPROPERTY RT_BIT_64(60) 107 #define USAGE_CREATEFLOPPY RT_BIT_64(61) 108 #define USAGE_CREATEDVD RT_BIT_64(62) 106 #define USAGE_MEDIUMPROPERTY RT_BIT_64(60) 109 107 #define USAGE_ALL (~(uint64_t)0) 110 108 /** @} */ … … 260 258 ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen, 261 259 bool fSilent); 262 int handleCreateHardDisk(HandlerArg *a); 263 int handleCreateDVD(HandlerArg *a); 264 int handleCreateFloppy(HandlerArg *a); 265 int handleModifyHardDisk(HandlerArg *a); 266 int handleCloneHardDisk(HandlerArg *a); 260 int handleCreateMedium(HandlerArg *a); 261 int handleModifyMedium(HandlerArg *a); 262 int handleCloneMedium(HandlerArg *a); 267 263 int handleMediumProperty(HandlerArg *a); 268 264 RTEXITCODE handleConvertFromRaw(int argc, char *argv[]); … … 271 267 const char *pszParentUUID, 272 268 bool fOptLong); 273 int handleShow HardDiskInfo(HandlerArg *a);269 int handleShowMediumInfo(HandlerArg *a); 274 270 int handleCloseMedium(HandlerArg *a); 275 int parse DiskType(const char *psz, MediumType_T *pDiskType);271 int parseMediumType(const char *psz, MediumType_T *penmMediumType); 276 272 int parseBool(const char *psz, bool *pb); 277 273 -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r53354 r54438 1 1 /* $Id$ */ 2 2 /** @file 3 * VBoxManage - The disk related commands.3 * VBoxManage - The disk/medium related commands. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2006-201 3Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 53 53 54 54 55 static int parse DiskVariant(const char *psz, MediumVariant_T *pDiskVariant)55 static int parseMediumVariant(const char *psz, MediumVariant_T *pMediumVariant) 56 56 { 57 57 int rc = VINF_SUCCESS; 58 unsigned DiskVariant = (unsigned)(*pDiskVariant);58 unsigned MediumVariant = (unsigned)(*pMediumVariant); 59 59 while (psz && *psz && RT_SUCCESS(rc)) 60 60 { … … 70 70 // variant, whereas the other flags are cumulative. 71 71 if (!RTStrNICmp(psz, "standard", len)) 72 DiskVariant = MediumVariant_Standard;72 MediumVariant = MediumVariant_Standard; 73 73 else if ( !RTStrNICmp(psz, "fixed", len) 74 74 || !RTStrNICmp(psz, "static", len)) 75 DiskVariant |= MediumVariant_Fixed;75 MediumVariant |= MediumVariant_Fixed; 76 76 else if (!RTStrNICmp(psz, "Diff", len)) 77 DiskVariant |= MediumVariant_Diff;77 MediumVariant |= MediumVariant_Diff; 78 78 else if (!RTStrNICmp(psz, "split2g", len)) 79 DiskVariant |= MediumVariant_VmdkSplit2G;79 MediumVariant |= MediumVariant_VmdkSplit2G; 80 80 else if ( !RTStrNICmp(psz, "stream", len) 81 81 || !RTStrNICmp(psz, "streamoptimized", len)) 82 DiskVariant |= MediumVariant_VmdkStreamOptimized;82 MediumVariant |= MediumVariant_VmdkStreamOptimized; 83 83 else if (!RTStrNICmp(psz, "esx", len)) 84 DiskVariant |= MediumVariant_VmdkESX;84 MediumVariant |= MediumVariant_VmdkESX; 85 85 else 86 86 rc = VERR_PARSE_ERROR; … … 93 93 94 94 if (RT_SUCCESS(rc)) 95 *p DiskVariant = (MediumVariant_T)DiskVariant;95 *pMediumVariant = (MediumVariant_T)MediumVariant; 96 96 return rc; 97 97 } 98 98 99 int parse DiskType(const char *psz, MediumType_T *pDiskType)99 int parseMediumType(const char *psz, MediumType_T *penmMediumType) 100 100 { 101 101 int rc = VINF_SUCCESS; 102 MediumType_T DiskType = MediumType_Normal;102 MediumType_T enmMediumType = MediumType_Normal; 103 103 if (!RTStrICmp(psz, "normal")) 104 DiskType = MediumType_Normal;104 enmMediumType = MediumType_Normal; 105 105 else if (!RTStrICmp(psz, "immutable")) 106 DiskType = MediumType_Immutable;106 enmMediumType = MediumType_Immutable; 107 107 else if (!RTStrICmp(psz, "writethrough")) 108 DiskType = MediumType_Writethrough;108 enmMediumType = MediumType_Writethrough; 109 109 else if (!RTStrICmp(psz, "shareable")) 110 DiskType = MediumType_Shareable;110 enmMediumType = MediumType_Shareable; 111 111 else if (!RTStrICmp(psz, "readonly")) 112 DiskType = MediumType_Readonly;112 enmMediumType = MediumType_Readonly; 113 113 else if (!RTStrICmp(psz, "multiattach")) 114 DiskType = MediumType_MultiAttach;114 enmMediumType = MediumType_MultiAttach; 115 115 else 116 116 rc = VERR_PARSE_ERROR; 117 117 118 118 if (RT_SUCCESS(rc)) 119 *p DiskType = DiskType;119 *penmMediumType = enmMediumType; 120 120 return rc; 121 121 } … … 187 187 } 188 188 189 static HRESULT createFloppy(HandlerArg *a, const char *pszFormat, 190 const char *pszFilename, ComPtr<IMedium> &pMedium) 189 static HRESULT createMedium(HandlerArg *a, const char *pszFormat, 190 const char *pszFilename, DeviceType_T enmDevType, 191 AccessMode_T enmAccessMode, ComPtr<IMedium> &pMedium) 191 192 { 192 193 HRESULT rc; … … 207 208 CHECK_ERROR(a->virtualBox, CreateMedium(Bstr(pszFormat).raw(), 208 209 Bstr(pszFilename).raw(), 209 AccessMode_ReadWrite, 210 TRUE, 211 DeviceType_Floppy, 210 enmAccessMode, 211 enmDevType, 212 212 pMedium.asOutParam())); 213 213 return rc; 214 214 } 215 215 216 static HRESULT createDVD(HandlerArg *a, const char *pszFormat, 217 const char *pszFilename, ComPtr<IMedium> &pMedium) 218 { 219 HRESULT rc; 220 char szFilenameAbs[RTPATH_MAX] = ""; 221 222 /** @todo laziness shortcut. should really check the MediumFormatCapabilities */ 223 if (RTStrICmp(pszFormat, "iSCSI")) 224 { 225 int irc = RTPathAbs(pszFilename, szFilenameAbs, sizeof(szFilenameAbs)); 226 if (RT_FAILURE(irc)) 227 { 228 RTMsgError("Cannot convert filename \"%s\" to absolute path", pszFilename); 229 return E_FAIL; 230 } 231 pszFilename = szFilenameAbs; 232 } 233 234 CHECK_ERROR(a->virtualBox, CreateMedium(Bstr(pszFormat).raw(), 235 Bstr(pszFilename).raw(), 236 AccessMode_ReadWrite, 237 TRUE, 238 DeviceType_DVD, 239 pMedium.asOutParam())); 240 return rc; 241 } 242 243 static HRESULT createHardDisk(HandlerArg *a, const char *pszFormat, 244 const char *pszFilename, ComPtr<IMedium> &pMedium) 245 { 246 HRESULT rc; 247 char szFilenameAbs[RTPATH_MAX] = ""; 248 249 /** @todo laziness shortcut. should really check the MediumFormatCapabilities */ 250 if (RTStrICmp(pszFormat, "iSCSI")) 251 { 252 int irc = RTPathAbs(pszFilename, szFilenameAbs, sizeof(szFilenameAbs)); 253 if (RT_FAILURE(irc)) 254 { 255 RTMsgError("Cannot convert filename \"%s\" to absolute path", pszFilename); 256 return E_FAIL; 257 } 258 pszFilename = szFilenameAbs; 259 } 260 261 CHECK_ERROR(a->virtualBox, CreateHardDisk(Bstr(pszFormat).raw(), 262 Bstr(pszFilename).raw(), 263 pMedium.asOutParam())); 264 return rc; 265 } 266 267 static const RTGETOPTDEF g_aCreateHardDiskOptions[] = 268 { 216 static const RTGETOPTDEF g_aCreateMediumOptions[] = 217 { 218 { "disk", 'H', RTGETOPT_REQ_NOTHING }, 219 { "dvd", 'D', RTGETOPT_REQ_NOTHING }, 220 { "floppy", 'L', RTGETOPT_REQ_NOTHING }, 269 221 { "--filename", 'f', RTGETOPT_REQ_STRING }, 270 222 { "-filename", 'f', RTGETOPT_REQ_STRING }, // deprecated … … 281 233 }; 282 234 283 int handleCreate HardDisk(HandlerArg *a)235 int handleCreateMedium(HandlerArg *a) 284 236 { 285 237 HRESULT rc; … … 288 240 const char *diffparent = NULL; 289 241 uint64_t size = 0; 242 enum { 243 CMD_NONE, 244 CMD_DISK, 245 CMD_DVD, 246 CMD_FLOPPY 247 } cmd = CMD_NONE; 290 248 const char *format = NULL; 291 249 bool fBase = true; 292 MediumVariant_T DiskVariant = MediumVariant_Standard;250 MediumVariant_T enmMediumVariant = MediumVariant_Standard; 293 251 294 252 int c; … … 296 254 RTGETOPTSTATE GetState; 297 255 // start at 0 because main() has hacked both the argc and argv given to us 298 RTGetOptInit(&GetState, a->argc, a->argv, g_aCreate HardDiskOptions, RT_ELEMENTS(g_aCreateHardDiskOptions),256 RTGetOptInit(&GetState, a->argc, a->argv, g_aCreateMediumOptions, RT_ELEMENTS(g_aCreateMediumOptions), 299 257 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 300 258 while ((c = RTGetOpt(&GetState, &ValueUnion))) … … 302 260 switch (c) 303 261 { 262 case 'H': // disk 263 if (cmd != CMD_NONE) 264 return errorSyntax(USAGE_CREATEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 265 cmd = CMD_DISK; 266 break; 267 268 case 'D': // DVD 269 if (cmd != CMD_NONE) 270 return errorSyntax(USAGE_CREATEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 271 cmd = CMD_DVD; 272 break; 273 274 case 'L': // floppy 275 if (cmd != CMD_NONE) 276 return errorSyntax(USAGE_CREATEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 277 cmd = CMD_FLOPPY; 278 break; 279 304 280 case 'f': // --filename 305 281 filename = ValueUnion.psz; … … 325 301 case 'F': // --static ("fixed"/"flat") 326 302 { 327 unsigned u DiskVariant = (unsigned)DiskVariant;328 u DiskVariant |= MediumVariant_Fixed;329 DiskVariant = (MediumVariant_T)uDiskVariant;303 unsigned uMediumVariant = (unsigned)enmMediumVariant; 304 uMediumVariant |= MediumVariant_Fixed; 305 enmMediumVariant = (MediumVariant_T)uMediumVariant; 330 306 break; 331 307 } 332 308 333 309 case 'm': // --variant 334 vrc = parse DiskVariant(ValueUnion.psz, &DiskVariant);310 vrc = parseMediumVariant(ValueUnion.psz, &enmMediumVariant); 335 311 if (RT_FAILURE(vrc)) 336 return errorArgument("Invalid hard diskvariant '%s'", ValueUnion.psz);312 return errorArgument("Invalid medium variant '%s'", ValueUnion.psz); 337 313 break; 338 314 339 315 case VINF_GETOPT_NOT_OPTION: 340 return errorSyntax(USAGE_CREATE HD, "Invalid parameter '%s'", ValueUnion.psz);316 return errorSyntax(USAGE_CREATEMEDIUM, "Invalid parameter '%s'", ValueUnion.psz); 341 317 342 318 default: … … 344 320 { 345 321 if (RT_C_IS_PRINT(c)) 346 return errorSyntax(USAGE_CREATE HD, "Invalid option -%c", c);322 return errorSyntax(USAGE_CREATEMEDIUM, "Invalid option -%c", c); 347 323 else 348 return errorSyntax(USAGE_CREATE HD, "Invalid option case %i", c);324 return errorSyntax(USAGE_CREATEMEDIUM, "Invalid option case %i", c); 349 325 } 350 326 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 351 return errorSyntax(USAGE_CREATE HD, "unknown option: %s\n", ValueUnion.psz);327 return errorSyntax(USAGE_CREATEMEDIUM, "unknown option: %s\n", ValueUnion.psz); 352 328 else if (ValueUnion.pDef) 353 return errorSyntax(USAGE_CREATE HD, "%s: %Rrs", ValueUnion.pDef->pszLong, c);329 return errorSyntax(USAGE_CREATEMEDIUM, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 354 330 else 355 return errorSyntax(USAGE_CREATE HD, "error: %Rrs", c);331 return errorSyntax(USAGE_CREATEMEDIUM, "error: %Rrs", c); 356 332 } 357 333 } 358 334 359 335 /* check the outcome */ 360 ComPtr<IMedium> parentHardDisk; 336 if (cmd == CMD_NONE) 337 cmd = CMD_DISK; 338 ComPtr<IMedium> pParentMedium; 361 339 if (fBase) 362 340 { … … 364 342 || !*filename 365 343 || size == 0) 366 return errorSyntax(USAGE_CREATE HD, "Parameters --filename and --size are required");344 return errorSyntax(USAGE_CREATEMEDIUM, "Parameters --filename and --size are required"); 367 345 if (!format || !*format) 368 format = "VDI"; 346 { 347 if (cmd == CMD_DISK) 348 format = "VDI"; 349 else if (cmd == CMD_DVD || cmd == CMD_FLOPPY) 350 { 351 format = "RAW"; 352 unsigned uMediumVariant = (unsigned)enmMediumVariant; 353 uMediumVariant |= MediumVariant_Fixed; 354 enmMediumVariant = (MediumVariant_T)uMediumVariant; 355 } 356 } 369 357 } 370 358 else … … 372 360 if ( !filename 373 361 || !*filename) 374 return errorSyntax(USAGE_CREATE HD, "Parameters --filename is required");362 return errorSyntax(USAGE_CREATEMEDIUM, "Parameters --filename is required"); 375 363 size = 0; 376 DiskVariant = MediumVariant_Diff; 364 if (cmd != CMD_DISK) 365 return errorSyntax(USAGE_CREATEMEDIUM, "Creating a differencing medium is only supported for hard disks"); 366 enmMediumVariant = MediumVariant_Diff; 377 367 if (!format || !*format) 378 368 { … … 387 377 } 388 378 rc = openMedium(a, diffparent, DeviceType_HardDisk, 389 AccessMode_ReadWrite, p arentHardDisk,379 AccessMode_ReadWrite, pParentMedium, 390 380 false /* fForceNewUuidOnOpen */, false /* fSilent */); 391 381 if (FAILED(rc)) 392 382 return 1; 393 if (p arentHardDisk.isNull())383 if (pParentMedium.isNull()) 394 384 { 395 385 RTMsgError("Invalid parent hard disk reference, avoiding crash"); … … 397 387 } 398 388 MediumState_T state; 399 CHECK_ERROR(p arentHardDisk, COMGETTER(State)(&state));389 CHECK_ERROR(pParentMedium, COMGETTER(State)(&state)); 400 390 if (FAILED(rc)) 401 391 return 1; 402 392 if (state == MediumState_Inaccessible) 403 393 { 404 CHECK_ERROR(p arentHardDisk, RefreshState(&state));394 CHECK_ERROR(pParentMedium, RefreshState(&state)); 405 395 if (FAILED(rc)) 406 396 return 1; … … 413 403 { 414 404 Utf8Str strFormat(format); 415 if (strFormat.compare("vmdk", RTCString::CaseInsensitive) == 0) 416 strName.append(".vmdk"); 417 else if (strFormat.compare("vhd", RTCString::CaseInsensitive) == 0) 418 strName.append(".vhd"); 419 else 420 strName.append(".vdi"); 405 if (cmd == CMD_DISK) 406 { 407 if (strFormat.compare("vmdk", RTCString::CaseInsensitive) == 0) 408 strName.append(".vmdk"); 409 else if (strFormat.compare("vhd", RTCString::CaseInsensitive) == 0) 410 strName.append(".vhd"); 411 else 412 strName.append(".vdi"); 413 } else if (cmd == CMD_DVD) 414 strName.append(".iso"); 415 else if (cmd == CMD_FLOPPY) 416 strName.append(".img"); 421 417 filename = strName.c_str(); 422 418 } 423 419 424 ComPtr<IMedium> hardDisk; 425 rc = createHardDisk(a, format, filename, hardDisk); 426 if (SUCCEEDED(rc) && hardDisk) 427 { 428 ComPtr<IProgress> progress; 420 ComPtr<IMedium> pMedium; 421 if (cmd == CMD_DISK) 422 rc = createMedium(a, format, filename, DeviceType_HardDisk, 423 AccessMode_ReadWrite, pMedium); 424 else if (cmd == CMD_DVD) 425 rc = createMedium(a, format, filename, DeviceType_DVD, 426 AccessMode_ReadOnly, pMedium); 427 else if (cmd == CMD_FLOPPY) 428 rc = createMedium(a, format, filename, DeviceType_Floppy, 429 AccessMode_ReadWrite, pMedium); 430 431 if (SUCCEEDED(rc) && pMedium) 432 { 433 ComPtr<IProgress> pProgress; 429 434 com::SafeArray<MediumVariant_T> l_variants(sizeof(MediumVariant_T)*8); 430 435 431 436 for (ULONG i = 0; i < l_variants.size(); ++i) 432 437 { 433 ULONG temp = DiskVariant;438 ULONG temp = enmMediumVariant; 434 439 temp &= 1<<i; 435 440 l_variants [i] = (MediumVariant_T)temp; … … 437 442 438 443 if (fBase) 439 CHECK_ERROR( hardDisk, CreateBaseStorage(size, ComSafeArrayAsInParam(l_variants), progress.asOutParam()));444 CHECK_ERROR(pMedium, CreateBaseStorage(size, ComSafeArrayAsInParam(l_variants), pProgress.asOutParam())); 440 445 else 441 CHECK_ERROR(parentHardDisk, CreateDiffStorage(hardDisk, ComSafeArrayAsInParam(l_variants), progress.asOutParam())); 442 if (SUCCEEDED(rc) && progress) 443 { 444 rc = showProgress(progress); 445 CHECK_PROGRESS_ERROR(progress, ("Failed to create hard disk")); 446 if (SUCCEEDED(rc)) 447 { 448 Bstr uuid; 449 CHECK_ERROR(hardDisk, COMGETTER(Id)(uuid.asOutParam())); 450 RTPrintf("Disk image created. UUID: %s\n", Utf8Str(uuid).c_str()); 451 } 452 } 453 454 CHECK_ERROR(hardDisk, Close()); 446 CHECK_ERROR(pParentMedium, CreateDiffStorage(pMedium, ComSafeArrayAsInParam(l_variants), pProgress.asOutParam())); 447 if (SUCCEEDED(rc) && pProgress) 448 { 449 rc = showProgress(pProgress); 450 CHECK_PROGRESS_ERROR(pProgress, ("Failed to create medium")); 451 } 452 } 453 454 if (SUCCEEDED(rc) && pMedium) 455 { 456 Bstr uuid; 457 CHECK_ERROR(pMedium, COMGETTER(Id)(uuid.asOutParam())); 458 RTPrintf("Medium created. UUID: %s\n", Utf8Str(uuid).c_str()); 459 460 //CHECK_ERROR(pMedium, Close()); 455 461 } 456 462 return SUCCEEDED(rc) ? 0 : 1; 457 463 } 458 464 459 int handleCreateFloppy(HandlerArg *a) 460 { 461 HRESULT rc; 462 int vrc; 463 const char *filename = NULL; 464 const char *diffparent = NULL; 465 uint64_t size = 0; 466 const char *format = NULL; 467 bool fBase = true; 468 MediumVariant_T DiskVariant = MediumVariant_Standard; 469 470 int c; 471 RTGETOPTUNION ValueUnion; 472 RTGETOPTSTATE GetState; 473 // start at 0 because main() has hacked both the argc and argv given to us 474 RTGetOptInit(&GetState, a->argc, a->argv, g_aCreateHardDiskOptions, RT_ELEMENTS(g_aCreateHardDiskOptions), 475 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 476 while ((c = RTGetOpt(&GetState, &ValueUnion))) 477 { 478 switch (c) 479 { 480 case 'f': // --filename 481 filename = ValueUnion.psz; 482 break; 483 484 case 'd': // --diffparent 485 diffparent = ValueUnion.psz; 486 fBase = false; 487 break; 488 489 case 's': // --size 490 size = ValueUnion.u64 * _1M; 491 break; 492 493 case 'S': // --sizebyte 494 size = ValueUnion.u64; 495 break; 496 497 case 'o': // --format 498 format = ValueUnion.psz; 499 break; 500 501 case 'F': // --static ("fixed"/"flat") 502 { 503 unsigned uDiskVariant = (unsigned)DiskVariant; 504 uDiskVariant |= MediumVariant_Fixed; 505 DiskVariant = (MediumVariant_T)uDiskVariant; 506 break; 507 } 508 509 case 'm': // --variant 510 vrc = parseDiskVariant(ValueUnion.psz, &DiskVariant); 511 if (RT_FAILURE(vrc)) 512 return errorArgument("Invalid medium variant '%s'", ValueUnion.psz); 513 break; 514 515 case VINF_GETOPT_NOT_OPTION: 516 return errorSyntax(USAGE_CREATEFLOPPY, "Invalid parameter '%s'", ValueUnion.psz); 517 518 default: 519 if (c > 0) 520 { 521 if (RT_C_IS_PRINT(c)) 522 return errorSyntax(USAGE_CREATEFLOPPY, "Invalid option -%c", c); 523 else 524 return errorSyntax(USAGE_CREATEFLOPPY, "Invalid option case %i", c); 525 } 526 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 527 return errorSyntax(USAGE_CREATEFLOPPY, "unknown option: %s\n", ValueUnion.psz); 528 else if (ValueUnion.pDef) 529 return errorSyntax(USAGE_CREATEFLOPPY, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 530 else 531 return errorSyntax(USAGE_CREATEFLOPPY, "error: %Rrs", c); 532 } 533 } 534 535 /* check the outcome */ 536 ComPtr<IMedium> parentMedium; 537 if (fBase) 538 { 539 if ( !filename 540 || !*filename 541 || size == 0) 542 return errorSyntax(USAGE_CREATEHD, "Parameters --filename and --size are required"); 543 if (!format || !*format) 544 format = "RAW"; 545 } 546 else 547 { 548 if ( !filename 549 || !*filename) 550 return errorSyntax(USAGE_CREATEHD, "Parameters --filename is required"); 551 size = 0; 552 DiskVariant = MediumVariant_Diff; 553 if (!format || !*format) 554 { 555 const char *pszExt = RTPathSuffix(filename); 556 /* Skip over . if there is an extension. */ 557 if (pszExt) 558 pszExt++; 559 if (!pszExt || !*pszExt) 560 format = "RAW"; 561 else 562 format = pszExt; 563 } 564 rc = openMedium(a, diffparent, DeviceType_Floppy, 565 AccessMode_ReadWrite, parentMedium, 566 false /* fForceNewUuidOnOpen */, false /* fSilent */); 567 if (FAILED(rc)) 568 return 1; 569 if (parentMedium.isNull()) 570 { 571 RTMsgError("Invalid parent medium reference, avoiding crash"); 572 return 1; 573 } 574 MediumState_T state; 575 CHECK_ERROR(parentMedium, COMGETTER(State)(&state)); 576 if (FAILED(rc)) 577 return 1; 578 if (state == MediumState_Inaccessible) 579 { 580 CHECK_ERROR(parentMedium, RefreshState(&state)); 581 if (FAILED(rc)) 582 return 1; 583 } 584 } 585 /* check for filename extension */ 586 /** @todo use IMediumFormat to cover all extensions generically */ 587 Utf8Str strName(filename); 588 if (!RTPathHasSuffix(strName.c_str())) 589 { 590 Utf8Str strFormat(format); 591 strName.append(".raw"); 592 filename = strName.c_str(); 593 } 594 595 ComPtr<IMedium> medium; 596 rc = createFloppy(a, format, filename, medium); 597 if (SUCCEEDED(rc) && medium) 598 { 599 ComPtr<IProgress> progress; 600 com::SafeArray<MediumVariant_T> l_variants(sizeof(MediumVariant_T)*8); 601 602 for (ULONG i = 0; i < l_variants.size(); ++i) 603 { 604 ULONG temp = DiskVariant; 605 temp &= 1<<i; 606 l_variants [i] = (MediumVariant_T)temp; 607 } 608 609 if (fBase) 610 CHECK_ERROR(medium, CreateBaseStorage(size, ComSafeArrayAsInParam(l_variants), progress.asOutParam())); 611 else 612 CHECK_ERROR(parentMedium, CreateDiffStorage(medium, ComSafeArrayAsInParam(l_variants), progress.asOutParam())); 613 if (SUCCEEDED(rc) && progress) 614 { 615 rc = showProgress(progress); 616 CHECK_PROGRESS_ERROR(progress, ("Failed to create Floppy")); 617 if (SUCCEEDED(rc)) 618 { 619 Bstr uuid; 620 CHECK_ERROR(medium, COMGETTER(Id)(uuid.asOutParam())); 621 RTPrintf("Disk image created. UUID: %s\n", Utf8Str(uuid).c_str()); 622 } 623 } 624 625 CHECK_ERROR(medium, Close()); 626 } 627 return SUCCEEDED(rc) ? 0 : 1; 628 } 629 630 int handleCreateDVD(HandlerArg *a) 631 { 632 HRESULT rc; 633 int vrc; 634 const char *filename = NULL; 635 const char *diffparent = NULL; 636 uint64_t size = 0; 637 const char *format = NULL; 638 bool fBase = true; 639 MediumVariant_T DiskVariant = MediumVariant_Standard; 640 641 int c; 642 RTGETOPTUNION ValueUnion; 643 RTGETOPTSTATE GetState; 644 // start at 0 because main() has hacked both the argc and argv given to us 645 RTGetOptInit(&GetState, a->argc, a->argv, g_aCreateHardDiskOptions, RT_ELEMENTS(g_aCreateHardDiskOptions), 646 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 647 while ((c = RTGetOpt(&GetState, &ValueUnion))) 648 { 649 switch (c) 650 { 651 case 'f': // --filename 652 filename = ValueUnion.psz; 653 break; 654 655 case 'd': // --diffparent 656 diffparent = ValueUnion.psz; 657 fBase = false; 658 break; 659 660 case 's': // --size 661 size = ValueUnion.u64 * _1M; 662 break; 663 664 case 'S': // --sizebyte 665 size = ValueUnion.u64; 666 break; 667 668 case 'o': // --format 669 format = ValueUnion.psz; 670 break; 671 672 case 'F': // --static ("fixed"/"flat") 673 { 674 unsigned uDiskVariant = (unsigned)DiskVariant; 675 uDiskVariant |= MediumVariant_Fixed; 676 DiskVariant = (MediumVariant_T)uDiskVariant; 677 break; 678 } 679 680 case 'm': // --variant 681 vrc = parseDiskVariant(ValueUnion.psz, &DiskVariant); 682 if (RT_FAILURE(vrc)) 683 return errorArgument("Invalid medium variant '%s'", ValueUnion.psz); 684 break; 685 686 case VINF_GETOPT_NOT_OPTION: 687 return errorSyntax(USAGE_CREATEDVD, "Invalid parameter '%s'", ValueUnion.psz); 688 689 default: 690 if (c > 0) 691 { 692 if (RT_C_IS_PRINT(c)) 693 return errorSyntax(USAGE_CREATEDVD, "Invalid option -%c", c); 694 else 695 return errorSyntax(USAGE_CREATEDVD, "Invalid option case %i", c); 696 } 697 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 698 return errorSyntax(USAGE_CREATEDVD, "unknown option: %s\n", ValueUnion.psz); 699 else if (ValueUnion.pDef) 700 return errorSyntax(USAGE_CREATEDVD, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 701 else 702 return errorSyntax(USAGE_CREATEDVD, "error: %Rrs", c); 703 } 704 } 705 706 /* check the outcome */ 707 ComPtr<IMedium> parentMedium; 708 if (fBase) 709 { 710 if ( !filename 711 || !*filename 712 || size == 0) 713 return errorSyntax(USAGE_CREATEHD, "Parameters --filename and --size are required"); 714 if (!format || !*format) 715 format = "ISO"; 716 } 717 else 718 { 719 if ( !filename 720 || !*filename) 721 return errorSyntax(USAGE_CREATEHD, "Parameters --filename is required"); 722 size = 0; 723 DiskVariant = MediumVariant_Diff; 724 if (!format || !*format) 725 { 726 const char *pszExt = RTPathSuffix(filename); 727 /* Skip over . if there is an extension. */ 728 if (pszExt) 729 pszExt++; 730 if (!pszExt || !*pszExt) 731 format = "ISO"; 732 else 733 format = pszExt; 734 } 735 rc = openMedium(a, diffparent, DeviceType_DVD, 736 AccessMode_ReadWrite, parentMedium, 737 false /* fForceNewUuidOnOpen */, false /* fSilent */); 738 if (FAILED(rc)) 739 return 1; 740 if (parentMedium.isNull()) 741 { 742 RTMsgError("Invalid parent hard disk reference, avoiding crash"); 743 return 1; 744 } 745 MediumState_T state; 746 CHECK_ERROR(parentMedium, COMGETTER(State)(&state)); 747 if (FAILED(rc)) 748 return 1; 749 if (state == MediumState_Inaccessible) 750 { 751 CHECK_ERROR(parentMedium, RefreshState(&state)); 752 if (FAILED(rc)) 753 return 1; 754 } 755 } 756 /* check for filename extension */ 757 /** @todo use IMediumFormat to cover all extensions generically */ 758 Utf8Str strName(filename); 759 if (!RTPathHasSuffix(strName.c_str())) 760 { 761 Utf8Str strFormat(format); 762 strName.append(".iso"); 763 filename = strName.c_str(); 764 } 765 766 ComPtr<IMedium> medium; 767 rc = createDVD(a, format, filename, medium); 768 if (SUCCEEDED(rc) && medium) 769 { 770 ComPtr<IProgress> progress; 771 com::SafeArray<MediumVariant_T> l_variants(sizeof(MediumVariant_T)*8); 772 773 for (ULONG i = 0; i < l_variants.size(); ++i) 774 { 775 ULONG temp = DiskVariant; 776 temp &= 1<<i; 777 l_variants [i] = (MediumVariant_T)temp; 778 } 779 780 if (fBase) 781 CHECK_ERROR(medium, CreateBaseStorage(size, ComSafeArrayAsInParam(l_variants), progress.asOutParam())); 782 else 783 CHECK_ERROR(parentMedium, CreateDiffStorage(medium, ComSafeArrayAsInParam(l_variants), progress.asOutParam())); 784 if (SUCCEEDED(rc) && progress) 785 { 786 rc = showProgress(progress); 787 CHECK_PROGRESS_ERROR(progress, ("Failed to create DVD")); 788 if (SUCCEEDED(rc)) 789 { 790 Bstr uuid; 791 CHECK_ERROR(medium, COMGETTER(Id)(uuid.asOutParam())); 792 RTPrintf("Disk image created. UUID: %s\n", Utf8Str(uuid).c_str()); 793 } 794 } 795 796 CHECK_ERROR(medium, Close()); 797 } 798 return SUCCEEDED(rc) ? 0 : 1; 799 } 800 801 static const RTGETOPTDEF g_aModifyHardDiskOptions[] = 802 { 465 static const RTGETOPTDEF g_aModifyMediumOptions[] = 466 { 467 { "disk", 'H', RTGETOPT_REQ_NOTHING }, 468 { "dvd", 'D', RTGETOPT_REQ_NOTHING }, 469 { "floppy", 'L', RTGETOPT_REQ_NOTHING }, 803 470 { "--type", 't', RTGETOPT_REQ_STRING }, 804 471 { "-type", 't', RTGETOPT_REQ_STRING }, // deprecated … … 815 482 }; 816 483 817 int handleModify HardDisk(HandlerArg *a)484 int handleModifyMedium(HandlerArg *a) 818 485 { 819 486 HRESULT rc; 820 487 int vrc; 821 ComPtr<IMedium> hardDisk; 822 MediumType_T DiskType; 488 enum { 489 CMD_NONE, 490 CMD_DISK, 491 CMD_DVD, 492 CMD_FLOPPY 493 } cmd = CMD_NONE; 494 ComPtr<IMedium> pMedium; 495 MediumType_T enmMediumType; 823 496 bool AutoReset = false; 824 497 SafeArray<BSTR> mediumPropNames; 825 498 SafeArray<BSTR> mediumPropValues; 826 bool fModify DiskType = false;499 bool fModifyMediumType = false; 827 500 bool fModifyAutoReset = false; 828 501 bool fModifyProperties = false; … … 830 503 bool fModifyResize = false; 831 504 uint64_t cbResize = 0; 832 const char * FilenameOrUuid = NULL;505 const char *pszFilenameOrUuid = NULL; 833 506 834 507 int c; … … 836 509 RTGETOPTSTATE GetState; 837 510 // start at 0 because main() has hacked both the argc and argv given to us 838 RTGetOptInit(&GetState, a->argc, a->argv, g_aModify HardDiskOptions, RT_ELEMENTS(g_aModifyHardDiskOptions),511 RTGetOptInit(&GetState, a->argc, a->argv, g_aModifyMediumOptions, RT_ELEMENTS(g_aModifyMediumOptions), 839 512 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 840 513 while ((c = RTGetOpt(&GetState, &ValueUnion))) … … 842 515 switch (c) 843 516 { 517 case 'H': // disk 518 if (cmd != CMD_NONE) 519 return errorSyntax(USAGE_MODIFYMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 520 cmd = CMD_DISK; 521 break; 522 523 case 'D': // DVD 524 if (cmd != CMD_NONE) 525 return errorSyntax(USAGE_MODIFYMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 526 cmd = CMD_DVD; 527 break; 528 529 case 'L': // floppy 530 if (cmd != CMD_NONE) 531 return errorSyntax(USAGE_MODIFYMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 532 cmd = CMD_FLOPPY; 533 break; 534 844 535 case 't': // --type 845 vrc = parse DiskType(ValueUnion.psz, &DiskType);536 vrc = parseMediumType(ValueUnion.psz, &enmMediumType); 846 537 if (RT_FAILURE(vrc)) 847 return errorArgument("Invalid hard disktype '%s'", ValueUnion.psz);848 fModify DiskType = true;538 return errorArgument("Invalid medium type '%s'", ValueUnion.psz); 539 fModifyMediumType = true; 849 540 break; 850 541 … … 903 594 904 595 case VINF_GETOPT_NOT_OPTION: 905 if (! FilenameOrUuid)906 FilenameOrUuid = ValueUnion.psz;596 if (!pszFilenameOrUuid) 597 pszFilenameOrUuid = ValueUnion.psz; 907 598 else 908 return errorSyntax(USAGE_MODIFY HD, "Invalid parameter '%s'", ValueUnion.psz);599 return errorSyntax(USAGE_MODIFYMEDIUM, "Invalid parameter '%s'", ValueUnion.psz); 909 600 break; 910 601 … … 913 604 { 914 605 if (RT_C_IS_PRINT(c)) 915 return errorSyntax(USAGE_MODIFY HD, "Invalid option -%c", c);606 return errorSyntax(USAGE_MODIFYMEDIUM, "Invalid option -%c", c); 916 607 else 917 return errorSyntax(USAGE_MODIFY HD, "Invalid option case %i", c);608 return errorSyntax(USAGE_MODIFYMEDIUM, "Invalid option case %i", c); 918 609 } 919 610 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 920 return errorSyntax(USAGE_MODIFY HD, "unknown option: %s\n", ValueUnion.psz);611 return errorSyntax(USAGE_MODIFYMEDIUM, "unknown option: %s\n", ValueUnion.psz); 921 612 else if (ValueUnion.pDef) 922 return errorSyntax(USAGE_MODIFY HD, "%s: %Rrs", ValueUnion.pDef->pszLong, c);613 return errorSyntax(USAGE_MODIFYMEDIUM, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 923 614 else 924 return errorSyntax(USAGE_MODIFYHD, "error: %Rrs", c); 925 } 926 } 927 928 if (!FilenameOrUuid) 929 return errorSyntax(USAGE_MODIFYHD, "Disk name or UUID required"); 930 931 if (!fModifyDiskType && !fModifyAutoReset && !fModifyProperties && !fModifyCompact && !fModifyResize) 932 return errorSyntax(USAGE_MODIFYHD, "No operation specified"); 615 return errorSyntax(USAGE_MODIFYMEDIUM, "error: %Rrs", c); 616 } 617 } 618 619 if (cmd == CMD_NONE) 620 cmd = CMD_DISK; 621 622 if (!pszFilenameOrUuid) 623 return errorSyntax(USAGE_MODIFYMEDIUM, "Medium name or UUID required"); 624 625 if (!fModifyMediumType && !fModifyAutoReset && !fModifyProperties && !fModifyCompact && !fModifyResize) 626 return errorSyntax(USAGE_MODIFYMEDIUM, "No operation specified"); 933 627 934 628 /* Always open the medium if necessary, there is no other way. */ 935 rc = openMedium(a, FilenameOrUuid, DeviceType_HardDisk, 936 AccessMode_ReadWrite, hardDisk, 937 false /* fForceNewUuidOnOpen */, false /* fSilent */); 629 if (cmd == CMD_DISK) 630 rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk, 631 AccessMode_ReadWrite, pMedium, 632 false /* fForceNewUuidOnOpen */, false /* fSilent */); 633 else if (cmd == CMD_DVD) 634 rc = openMedium(a, pszFilenameOrUuid, DeviceType_DVD, 635 AccessMode_ReadOnly, pMedium, 636 false /* fForceNewUuidOnOpen */, false /* fSilent */); 637 else if (cmd == CMD_FLOPPY) 638 rc = openMedium(a, pszFilenameOrUuid, DeviceType_Floppy, 639 AccessMode_ReadWrite, pMedium, 640 false /* fForceNewUuidOnOpen */, false /* fSilent */); 938 641 if (FAILED(rc)) 939 642 return 1; 940 if ( hardDisk.isNull())941 { 942 RTMsgError("Invalid hard diskreference, avoiding crash");643 if (pMedium.isNull()) 644 { 645 RTMsgError("Invalid medium reference, avoiding crash"); 943 646 return 1; 944 647 } 945 648 946 if (fModify DiskType)947 { 948 MediumType_T hddType;949 CHECK_ERROR( hardDisk, COMGETTER(Type)(&hddType));950 951 if ( hddType != DiskType)952 CHECK_ERROR( hardDisk, COMSETTER(Type)(DiskType));649 if (fModifyMediumType) 650 { 651 MediumType_T enmCurrMediumType; 652 CHECK_ERROR(pMedium, COMGETTER(Type)(&enmCurrMediumType)); 653 654 if (enmCurrMediumType != enmMediumType) 655 CHECK_ERROR(pMedium, COMSETTER(Type)(enmMediumType)); 953 656 } 954 657 955 658 if (fModifyAutoReset) 956 659 { 957 CHECK_ERROR( hardDisk, COMSETTER(AutoReset)(AutoReset));660 CHECK_ERROR(pMedium, COMSETTER(AutoReset)(AutoReset)); 958 661 } 959 662 960 663 if (fModifyProperties) 961 664 { 962 CHECK_ERROR( hardDisk, SetProperties(ComSafeArrayAsInParam(mediumPropNames), ComSafeArrayAsInParam(mediumPropValues)));665 CHECK_ERROR(pMedium, SetProperties(ComSafeArrayAsInParam(mediumPropNames), ComSafeArrayAsInParam(mediumPropValues))); 963 666 } 964 667 965 668 if (fModifyCompact) 966 669 { 967 ComPtr<IProgress> p rogress;968 CHECK_ERROR( hardDisk, Compact(progress.asOutParam()));670 ComPtr<IProgress> pProgress; 671 CHECK_ERROR(pMedium, Compact(pProgress.asOutParam())); 969 672 if (SUCCEEDED(rc)) 970 rc = showProgress(p rogress);673 rc = showProgress(pProgress); 971 674 if (FAILED(rc)) 972 675 { 973 676 if (rc == E_NOTIMPL) 974 RTMsgError("Compact hard diskoperation is not implemented!");677 RTMsgError("Compact medium operation is not implemented!"); 975 678 else if (rc == VBOX_E_NOT_SUPPORTED) 976 RTMsgError("Compact hard diskoperation for this format is not implemented yet!");977 else if (!p rogress.isNull())978 CHECK_PROGRESS_ERROR(p rogress, ("Failed to compact hard disk"));679 RTMsgError("Compact medium operation for this format is not implemented yet!"); 680 else if (!pProgress.isNull()) 681 CHECK_PROGRESS_ERROR(pProgress, ("Failed to compact medium")); 979 682 else 980 RTMsgError("Failed to compact hard disk!");683 RTMsgError("Failed to compact medium!"); 981 684 } 982 685 } … … 984 687 if (fModifyResize) 985 688 { 986 ComPtr<IProgress> p rogress;987 CHECK_ERROR( hardDisk, Resize(cbResize, progress.asOutParam()));689 ComPtr<IProgress> pProgress; 690 CHECK_ERROR(pMedium, Resize(cbResize, pProgress.asOutParam())); 988 691 if (SUCCEEDED(rc)) 989 rc = showProgress(p rogress);692 rc = showProgress(pProgress); 990 693 if (FAILED(rc)) 991 694 { 992 695 if (rc == E_NOTIMPL) 993 RTMsgError("Resize hard diskoperation is not implemented!");696 RTMsgError("Resize medium operation is not implemented!"); 994 697 else if (rc == VBOX_E_NOT_SUPPORTED) 995 RTMsgError("Resize hard diskoperation for this format is not implemented yet!");698 RTMsgError("Resize medium operation for this format is not implemented yet!"); 996 699 else 997 CHECK_PROGRESS_ERROR(p rogress, ("Failed to resize hard disk"));700 CHECK_PROGRESS_ERROR(pProgress, ("Failed to resize medium")); 998 701 } 999 702 } … … 1002 705 } 1003 706 1004 static const RTGETOPTDEF g_aCloneHardDiskOptions[] = 1005 { 707 static const RTGETOPTDEF g_aCloneMediumOptions[] = 708 { 709 { "disk", 'd', RTGETOPT_REQ_NOTHING }, 710 { "dvd", 'D', RTGETOPT_REQ_NOTHING }, 711 { "floppy", 'f', RTGETOPT_REQ_NOTHING }, 1006 712 { "--format", 'o', RTGETOPT_REQ_STRING }, 1007 713 { "-format", 'o', RTGETOPT_REQ_STRING }, … … 1013 719 }; 1014 720 1015 int handleClone HardDisk(HandlerArg *a)721 int handleCloneMedium(HandlerArg *a) 1016 722 { 1017 723 HRESULT rc; 1018 724 int vrc; 725 enum { 726 CMD_NONE, 727 CMD_DISK, 728 CMD_DVD, 729 CMD_FLOPPY 730 } cmd = CMD_NONE; 1019 731 const char *pszSrc = NULL; 1020 732 const char *pszDst = NULL; 1021 733 Bstr format; 1022 MediumVariant_T DiskVariant = MediumVariant_Standard;734 MediumVariant_T enmMediumVariant = MediumVariant_Standard; 1023 735 bool fExisting = false; 1024 736 … … 1027 739 RTGETOPTSTATE GetState; 1028 740 // start at 0 because main() has hacked both the argc and argv given to us 1029 RTGetOptInit(&GetState, a->argc, a->argv, g_aClone HardDiskOptions, RT_ELEMENTS(g_aCloneHardDiskOptions),741 RTGetOptInit(&GetState, a->argc, a->argv, g_aCloneMediumOptions, RT_ELEMENTS(g_aCloneMediumOptions), 1030 742 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 1031 743 while ((c = RTGetOpt(&GetState, &ValueUnion))) … … 1033 745 switch (c) 1034 746 { 747 case 'd': // disk 748 if (cmd != CMD_NONE) 749 return errorSyntax(USAGE_CLONEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 750 cmd = CMD_DISK; 751 break; 752 753 case 'D': // DVD 754 if (cmd != CMD_NONE) 755 return errorSyntax(USAGE_CLONEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 756 cmd = CMD_DVD; 757 break; 758 759 case 'f': // floppy 760 if (cmd != CMD_NONE) 761 return errorSyntax(USAGE_CLONEMEDIUM, "Only one command can be specified: '%s'", ValueUnion.psz); 762 cmd = CMD_FLOPPY; 763 break; 764 1035 765 case 'o': // --format 1036 766 format = ValueUnion.psz; … … 1039 769 case 'F': // --static 1040 770 { 1041 unsigned u DiskVariant = (unsigned)DiskVariant;1042 u DiskVariant |= MediumVariant_Fixed;1043 DiskVariant = (MediumVariant_T)uDiskVariant;771 unsigned uMediumVariant = (unsigned)enmMediumVariant; 772 uMediumVariant |= MediumVariant_Fixed; 773 enmMediumVariant = (MediumVariant_T)uMediumVariant; 1044 774 break; 1045 775 } … … 1050 780 1051 781 case 'm': // --variant 1052 vrc = parse DiskVariant(ValueUnion.psz, &DiskVariant);782 vrc = parseMediumVariant(ValueUnion.psz, &enmMediumVariant); 1053 783 if (RT_FAILURE(vrc)) 1054 return errorArgument("Invalid hard diskvariant '%s'", ValueUnion.psz);784 return errorArgument("Invalid medium variant '%s'", ValueUnion.psz); 1055 785 break; 1056 786 … … 1061 791 pszDst = ValueUnion.psz; 1062 792 else 1063 return errorSyntax(USAGE_CLONE HD, "Invalid parameter '%s'", ValueUnion.psz);793 return errorSyntax(USAGE_CLONEMEDIUM, "Invalid parameter '%s'", ValueUnion.psz); 1064 794 break; 1065 795 … … 1068 798 { 1069 799 if (RT_C_IS_GRAPH(c)) 1070 return errorSyntax(USAGE_CLONE HD, "unhandled option: -%c", c);800 return errorSyntax(USAGE_CLONEMEDIUM, "unhandled option: -%c", c); 1071 801 else 1072 return errorSyntax(USAGE_CLONE HD, "unhandled option: %i", c);802 return errorSyntax(USAGE_CLONEMEDIUM, "unhandled option: %i", c); 1073 803 } 1074 804 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 1075 return errorSyntax(USAGE_CLONE HD, "unknown option: %s", ValueUnion.psz);805 return errorSyntax(USAGE_CLONEMEDIUM, "unknown option: %s", ValueUnion.psz); 1076 806 else if (ValueUnion.pDef) 1077 return errorSyntax(USAGE_CLONE HD, "%s: %Rrs", ValueUnion.pDef->pszLong, c);807 return errorSyntax(USAGE_CLONEMEDIUM, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 1078 808 else 1079 return errorSyntax(USAGE_CLONEHD, "error: %Rrs", c); 1080 } 1081 } 1082 809 return errorSyntax(USAGE_CLONEMEDIUM, "error: %Rrs", c); 810 } 811 } 812 813 if (cmd == CMD_NONE) 814 cmd = CMD_DISK; 1083 815 if (!pszSrc) 1084 return errorSyntax(USAGE_CLONE HD, "Mandatory UUID or input file parameter missing");816 return errorSyntax(USAGE_CLONEMEDIUM, "Mandatory UUID or input file parameter missing"); 1085 817 if (!pszDst) 1086 return errorSyntax(USAGE_CLONEHD, "Mandatory output file parameter missing"); 1087 if (fExisting && (!format.isEmpty() || DiskVariant != MediumType_Normal)) 1088 return errorSyntax(USAGE_CLONEHD, "Specified options which cannot be used with --existing"); 1089 1090 ComPtr<IMedium> srcDisk; 1091 ComPtr<IMedium> dstDisk; 1092 1093 rc = openMedium(a, pszSrc, DeviceType_HardDisk, AccessMode_ReadOnly, 1094 srcDisk, false /* fForceNewUuidOnOpen */, 1095 false /* fSilent */); 818 return errorSyntax(USAGE_CLONEMEDIUM, "Mandatory output file parameter missing"); 819 if (fExisting && (!format.isEmpty() || enmMediumVariant != MediumType_Normal)) 820 return errorSyntax(USAGE_CLONEMEDIUM, "Specified options which cannot be used with --existing"); 821 822 ComPtr<IMedium> pSrcMedium; 823 ComPtr<IMedium> pDstMedium; 824 825 if (cmd == CMD_DISK) 826 rc = openMedium(a, pszSrc, DeviceType_HardDisk, AccessMode_ReadOnly, pSrcMedium, 827 false /* fForceNewUuidOnOpen */, false /* fSilent */); 828 else if (cmd == CMD_DVD) 829 rc = openMedium(a, pszSrc, DeviceType_DVD, AccessMode_ReadOnly, pSrcMedium, 830 false /* fForceNewUuidOnOpen */, false /* fSilent */); 831 else if (cmd == CMD_FLOPPY) 832 rc = openMedium(a, pszSrc, DeviceType_Floppy, AccessMode_ReadOnly, pSrcMedium, 833 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1096 834 if (FAILED(rc)) 1097 835 return 1; … … 1099 837 do 1100 838 { 1101 /* open/create destination hard disk*/839 /* open/create destination medium */ 1102 840 if (fExisting) 1103 841 { 1104 rc = openMedium(a, pszDst, DeviceType_HardDisk, 1105 AccessMode_ReadWrite, dstDisk, 1106 false /* fForceNewUuidOnOpen */, 1107 false /* fSilent */); 842 if (cmd == CMD_DISK) 843 rc = openMedium(a, pszDst, DeviceType_HardDisk, AccessMode_ReadWrite, pDstMedium, 844 false /* fForceNewUuidOnOpen */, false /* fSilent */); 845 else if (cmd == CMD_DVD) 846 rc = openMedium(a, pszDst, DeviceType_DVD, AccessMode_ReadOnly, pDstMedium, 847 false /* fForceNewUuidOnOpen */, false /* fSilent */); 848 else if (cmd == CMD_FLOPPY) 849 rc = openMedium(a, pszDst, DeviceType_Floppy, AccessMode_ReadWrite, pDstMedium, 850 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1108 851 if (FAILED(rc)) 1109 852 break; … … 1111 854 /* Perform accessibility check now. */ 1112 855 MediumState_T state; 1113 CHECK_ERROR_BREAK( dstDisk, RefreshState(&state));1114 CHECK_ERROR_BREAK( dstDisk, COMGETTER(Format)(format.asOutParam()));856 CHECK_ERROR_BREAK(pDstMedium, RefreshState(&state)); 857 CHECK_ERROR_BREAK(pDstMedium, COMGETTER(Format)(format.asOutParam())); 1115 858 } 1116 859 else 1117 860 { 1118 /* use the format of the source hard diskif unspecified */861 /* use the format of the source medium if unspecified */ 1119 862 if (format.isEmpty()) 1120 CHECK_ERROR_BREAK(srcDisk, COMGETTER(Format)(format.asOutParam())); 1121 rc = createHardDisk(a, Utf8Str(format).c_str(), pszDst, dstDisk); 863 CHECK_ERROR_BREAK(pSrcMedium, COMGETTER(Format)(format.asOutParam())); 864 Utf8Str strFormat(format); 865 if (cmd == CMD_DISK) 866 rc = createMedium(a, strFormat.c_str(), pszDst, DeviceType_HardDisk, 867 AccessMode_ReadWrite, pDstMedium); 868 else if (cmd == CMD_DVD) 869 rc = createMedium(a, strFormat.c_str(), pszDst, DeviceType_DVD, 870 AccessMode_ReadOnly, pDstMedium); 871 else if (cmd == CMD_FLOPPY) 872 rc = createMedium(a, strFormat.c_str(), pszDst, DeviceType_Floppy, 873 AccessMode_ReadWrite, pDstMedium); 1122 874 if (FAILED(rc)) 1123 875 break; 1124 876 } 1125 877 1126 ComPtr<IProgress> p rogress;878 ComPtr<IProgress> pProgress; 1127 879 com::SafeArray<MediumVariant_T> l_variants(sizeof(MediumVariant_T)*8); 1128 880 1129 881 for (ULONG i = 0; i < l_variants.size(); ++i) 1130 882 { 1131 ULONG temp = DiskVariant;883 ULONG temp = enmMediumVariant; 1132 884 temp &= 1<<i; 1133 885 l_variants [i] = (MediumVariant_T)temp; 1134 886 } 1135 887 1136 CHECK_ERROR_BREAK( srcDisk, CloneTo(dstDisk, ComSafeArrayAsInParam(l_variants), NULL, progress.asOutParam()));1137 1138 rc = showProgress(p rogress);1139 CHECK_PROGRESS_ERROR_BREAK(p rogress, ("Failed to clone hard disk"));888 CHECK_ERROR_BREAK(pSrcMedium, CloneTo(pDstMedium, ComSafeArrayAsInParam(l_variants), NULL, pProgress.asOutParam())); 889 890 rc = showProgress(pProgress); 891 CHECK_PROGRESS_ERROR_BREAK(pProgress, ("Failed to clone medium")); 1140 892 1141 893 Bstr uuid; 1142 CHECK_ERROR_BREAK( dstDisk, COMGETTER(Id)(uuid.asOutParam()));1143 1144 RTPrintf("Clone hard diskcreated in format '%ls'. UUID: %s\n",894 CHECK_ERROR_BREAK(pDstMedium, COMGETTER(Id)(uuid.asOutParam())); 895 896 RTPrintf("Clone medium created in format '%ls'. UUID: %s\n", 1145 897 format.raw(), Utf8Str(uuid).c_str()); 1146 898 } … … 1195 947 case 'm': // --variant 1196 948 { 1197 MediumVariant_T DiskVariant = MediumVariant_Standard;1198 rc = parse DiskVariant(ValueUnion.psz, &DiskVariant);949 MediumVariant_T enmMediumVariant = MediumVariant_Standard; 950 rc = parseMediumVariant(ValueUnion.psz, &enmMediumVariant); 1199 951 if (RT_FAILURE(rc)) 1200 return errorArgument("Invalid hard diskvariant '%s'", ValueUnion.psz);952 return errorArgument("Invalid medium variant '%s'", ValueUnion.psz); 1201 953 /// @todo cleaner solution than assuming 1:1 mapping? 1202 uImageFlags = (unsigned) DiskVariant;954 uImageFlags = (unsigned)enmMediumVariant; 1203 955 break; 1204 956 } … … 1422 1174 RTPrintf("Type: %s\n", typeStr); 1423 1175 1424 /* print out information specific for differencing hard disks*/1176 /* print out information specific for differencing media */ 1425 1177 if (fOptLong && pszParentUUID && Guid(pszParentUUID).isValid()) 1426 1178 { … … 1507 1259 for (size_t i = 0; i < machineIds.size(); i++) 1508 1260 { 1509 ComPtr<IMachine> machine;1510 CHECK_ERROR(pVirtualBox, FindMachine(machineIds[i], machine.asOutParam()));1511 if ( machine)1261 ComPtr<IMachine> pMachine; 1262 CHECK_ERROR(pVirtualBox, FindMachine(machineIds[i], pMachine.asOutParam())); 1263 if (pMachine) 1512 1264 { 1513 1265 Bstr name; 1514 machine->COMGETTER(Name)(name.asOutParam());1515 machine->COMGETTER(Id)(uuid.asOutParam());1266 pMachine->COMGETTER(Name)(name.asOutParam()); 1267 pMachine->COMGETTER(Id)(uuid.asOutParam()); 1516 1268 RTPrintf("%s%ls (UUID: %ls)", 1517 1269 fFirst ? "In use by VMs: " : " ", … … 1523 1275 for (size_t j = 0; j < snapshotIds.size(); j++) 1524 1276 { 1525 ComPtr<ISnapshot> snapshot;1526 machine->FindSnapshot(snapshotIds[j], snapshot.asOutParam());1527 if ( snapshot)1277 ComPtr<ISnapshot> pSnapshot; 1278 pMachine->FindSnapshot(snapshotIds[j], pSnapshot.asOutParam()); 1279 if (pSnapshot) 1528 1280 { 1529 1281 Bstr snapshotName; 1530 snapshot->COMGETTER(Name)(snapshotName.asOutParam());1282 pSnapshot->COMGETTER(Name)(snapshotName.asOutParam()); 1531 1283 RTPrintf(" [%ls (UUID: %ls)]", snapshotName.raw(), snapshotIds[j]); 1532 1284 } … … 1562 1314 } 1563 1315 1564 static const RTGETOPTDEF g_aShowHardDiskInfoOptions[] = 1565 { 1566 { "--dummy", 256, RTGETOPT_REQ_NOTHING }, // placeholder for C++ 1316 static const RTGETOPTDEF g_aShowMediumInfoOptions[] = 1317 { 1318 { "disk", 'd', RTGETOPT_REQ_NOTHING }, 1319 { "dvd", 'D', RTGETOPT_REQ_NOTHING }, 1320 { "floppy", 'f', RTGETOPT_REQ_NOTHING }, 1567 1321 }; 1568 1322 1569 int handleShow HardDiskInfo(HandlerArg *a)1323 int handleShowMediumInfo(HandlerArg *a) 1570 1324 { 1571 1325 HRESULT rc; 1572 const char *FilenameOrUuid = NULL; 1326 enum { 1327 CMD_NONE, 1328 CMD_DISK, 1329 CMD_DVD, 1330 CMD_FLOPPY 1331 } cmd = CMD_NONE; 1332 const char *pszFilenameOrUuid = NULL; 1573 1333 1574 1334 int c; … … 1576 1336 RTGETOPTSTATE GetState; 1577 1337 // start at 0 because main() has hacked both the argc and argv given to us 1578 RTGetOptInit(&GetState, a->argc, a->argv, g_aShow HardDiskInfoOptions, RT_ELEMENTS(g_aShowHardDiskInfoOptions),1338 RTGetOptInit(&GetState, a->argc, a->argv, g_aShowMediumInfoOptions, RT_ELEMENTS(g_aShowMediumInfoOptions), 1579 1339 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS); 1580 1340 while ((c = RTGetOpt(&GetState, &ValueUnion))) … … 1582 1342 switch (c) 1583 1343 { 1344 case 'd': // disk 1345 if (cmd != CMD_NONE) 1346 return errorSyntax(USAGE_SHOWMEDIUMINFO, "Only one command can be specified: '%s'", ValueUnion.psz); 1347 cmd = CMD_DISK; 1348 break; 1349 1350 case 'D': // DVD 1351 if (cmd != CMD_NONE) 1352 return errorSyntax(USAGE_SHOWMEDIUMINFO, "Only one command can be specified: '%s'", ValueUnion.psz); 1353 cmd = CMD_DVD; 1354 break; 1355 1356 case 'f': // floppy 1357 if (cmd != CMD_NONE) 1358 return errorSyntax(USAGE_SHOWMEDIUMINFO, "Only one command can be specified: '%s'", ValueUnion.psz); 1359 cmd = CMD_FLOPPY; 1360 break; 1361 1584 1362 case VINF_GETOPT_NOT_OPTION: 1585 if (! FilenameOrUuid)1586 FilenameOrUuid = ValueUnion.psz;1363 if (!pszFilenameOrUuid) 1364 pszFilenameOrUuid = ValueUnion.psz; 1587 1365 else 1588 return errorSyntax(USAGE_SHOW HDINFO, "Invalid parameter '%s'", ValueUnion.psz);1366 return errorSyntax(USAGE_SHOWMEDIUMINFO, "Invalid parameter '%s'", ValueUnion.psz); 1589 1367 break; 1590 1368 … … 1593 1371 { 1594 1372 if (RT_C_IS_PRINT(c)) 1595 return errorSyntax(USAGE_SHOW HDINFO, "Invalid option -%c", c);1373 return errorSyntax(USAGE_SHOWMEDIUMINFO, "Invalid option -%c", c); 1596 1374 else 1597 return errorSyntax(USAGE_SHOW HDINFO, "Invalid option case %i", c);1375 return errorSyntax(USAGE_SHOWMEDIUMINFO, "Invalid option case %i", c); 1598 1376 } 1599 1377 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 1600 return errorSyntax(USAGE_SHOW HDINFO, "unknown option: %s\n", ValueUnion.psz);1378 return errorSyntax(USAGE_SHOWMEDIUMINFO, "unknown option: %s\n", ValueUnion.psz); 1601 1379 else if (ValueUnion.pDef) 1602 return errorSyntax(USAGE_SHOW HDINFO, "%s: %Rrs", ValueUnion.pDef->pszLong, c);1380 return errorSyntax(USAGE_SHOWMEDIUMINFO, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 1603 1381 else 1604 return errorSyntax(USAGE_SHOWHDINFO, "error: %Rrs", c); 1605 } 1606 } 1382 return errorSyntax(USAGE_SHOWMEDIUMINFO, "error: %Rrs", c); 1383 } 1384 } 1385 1386 if (cmd == CMD_NONE) 1387 cmd = CMD_DISK; 1607 1388 1608 1389 /* check for required options */ 1609 if (!FilenameOrUuid) 1610 return errorSyntax(USAGE_SHOWHDINFO, "Disk name or UUID required"); 1611 1612 ComPtr<IMedium> hardDisk; 1613 rc = openMedium(a, FilenameOrUuid, DeviceType_HardDisk, 1614 AccessMode_ReadOnly, hardDisk, 1615 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1390 if (!pszFilenameOrUuid) 1391 return errorSyntax(USAGE_SHOWMEDIUMINFO, "Medium name or UUID required"); 1392 1393 ComPtr<IMedium> pMedium; 1394 if (cmd == CMD_DISK) 1395 rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk, 1396 AccessMode_ReadOnly, pMedium, 1397 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1398 else if (cmd == CMD_DVD) 1399 rc = openMedium(a, pszFilenameOrUuid, DeviceType_DVD, 1400 AccessMode_ReadOnly, pMedium, 1401 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1402 else if (cmd == CMD_FLOPPY) 1403 rc = openMedium(a, pszFilenameOrUuid, DeviceType_Floppy, 1404 AccessMode_ReadOnly, pMedium, 1405 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1616 1406 if (FAILED(rc)) 1617 1407 return 1; 1618 1408 1619 1409 Utf8Str strParentUUID("base"); 1620 ComPtr<IMedium> p arent;1621 hardDisk->COMGETTER(Parent)(parent.asOutParam());1622 if (!p arent.isNull())1410 ComPtr<IMedium> pParent; 1411 pMedium->COMGETTER(Parent)(pParent.asOutParam()); 1412 if (!pParent.isNull()) 1623 1413 { 1624 1414 Bstr bstrParentUUID; 1625 p arent->COMGETTER(Id)(bstrParentUUID.asOutParam());1415 pParent->COMGETTER(Id)(bstrParentUUID.asOutParam()); 1626 1416 strParentUUID = bstrParentUUID; 1627 1417 } 1628 1418 1629 rc = showMediumInfo(a->virtualBox, hardDisk, strParentUUID.c_str(), true);1419 rc = showMediumInfo(a->virtualBox, pMedium, strParentUUID.c_str(), true); 1630 1420 1631 1421 return SUCCEEDED(rc) ? 0 : 1; … … 1649 1439 CMD_FLOPPY 1650 1440 } cmd = CMD_NONE; 1651 const char * FilenameOrUuid = NULL;1441 const char *pszFilenameOrUuid = NULL; 1652 1442 bool fDelete = false; 1653 1443 … … 1685 1475 1686 1476 case VINF_GETOPT_NOT_OPTION: 1687 if (! FilenameOrUuid)1688 FilenameOrUuid = ValueUnion.psz;1477 if (!pszFilenameOrUuid) 1478 pszFilenameOrUuid = ValueUnion.psz; 1689 1479 else 1690 1480 return errorSyntax(USAGE_CLOSEMEDIUM, "Invalid parameter '%s'", ValueUnion.psz); … … 1710 1500 /* check for required options */ 1711 1501 if (cmd == CMD_NONE) 1712 return errorSyntax(USAGE_CLOSEMEDIUM, "Command variant disk/dvd/floppy required"); 1713 if (!FilenameOrUuid) 1714 return errorSyntax(USAGE_CLOSEMEDIUM, "Disk name or UUID required"); 1715 1716 ComPtr<IMedium> medium; 1717 1502 cmd = CMD_DISK; 1503 if (!pszFilenameOrUuid) 1504 return errorSyntax(USAGE_CLOSEMEDIUM, "Medium name or UUID required"); 1505 1506 ComPtr<IMedium> pMedium; 1718 1507 if (cmd == CMD_DISK) 1719 rc = openMedium(a, FilenameOrUuid, DeviceType_HardDisk,1720 AccessMode_ReadWrite, medium,1508 rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk, 1509 AccessMode_ReadWrite, pMedium, 1721 1510 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1722 1511 else if (cmd == CMD_DVD) 1723 rc = openMedium(a, FilenameOrUuid, DeviceType_DVD,1724 AccessMode_ReadOnly, medium,1512 rc = openMedium(a, pszFilenameOrUuid, DeviceType_DVD, 1513 AccessMode_ReadOnly, pMedium, 1725 1514 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1726 1515 else if (cmd == CMD_FLOPPY) 1727 rc = openMedium(a, FilenameOrUuid, DeviceType_Floppy,1728 AccessMode_ReadWrite, medium,1516 rc = openMedium(a, pszFilenameOrUuid, DeviceType_Floppy, 1517 AccessMode_ReadWrite, pMedium, 1729 1518 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1730 1519 1731 if (SUCCEEDED(rc) && medium)1520 if (SUCCEEDED(rc) && pMedium) 1732 1521 { 1733 1522 if (fDelete) 1734 1523 { 1735 ComPtr<IProgress> p rogress;1736 CHECK_ERROR( medium, DeleteStorage(progress.asOutParam()));1524 ComPtr<IProgress> pProgress; 1525 CHECK_ERROR(pMedium, DeleteStorage(pProgress.asOutParam())); 1737 1526 if (SUCCEEDED(rc)) 1738 1527 { 1739 rc = showProgress(p rogress);1740 CHECK_PROGRESS_ERROR(p rogress, ("Failed to delete medium"));1528 rc = showProgress(pProgress); 1529 CHECK_PROGRESS_ERROR(pProgress, ("Failed to delete medium")); 1741 1530 } 1742 1531 else 1743 1532 RTMsgError("Failed to delete medium. Error code %Rrc", rc); 1744 1533 } 1745 CHECK_ERROR( medium, Close());1534 CHECK_ERROR(pMedium, Close()); 1746 1535 } 1747 1536 … … 1752 1541 { 1753 1542 HRESULT rc = S_OK; 1543 const char *pszCmd = NULL; 1544 enum { 1545 CMD_NONE, 1546 CMD_DISK, 1547 CMD_DVD, 1548 CMD_FLOPPY 1549 } cmd = CMD_NONE; 1754 1550 const char *pszAction = NULL; 1755 1551 const char *pszFilenameOrUuid = NULL; … … 1757 1553 ComPtr<IMedium> pMedium; 1758 1554 1555 pszCmd = (a->argc > 0) ? a->argv[0] : ""; 1556 if ( !RTStrICmp(pszCmd, "disk") 1557 || !RTStrICmp(pszCmd, "dvd") 1558 || !RTStrICmp(pszCmd, "floppy")) 1559 { 1560 if (!RTStrICmp(pszCmd, "disk")) 1561 cmd = CMD_DISK; 1562 else if (!RTStrICmp(pszCmd, "dvd")) 1563 cmd = CMD_DVD; 1564 else if (!RTStrICmp(pszCmd, "floppy")) 1565 cmd = CMD_FLOPPY; 1566 else 1567 { 1568 AssertMsgFailed(("unexpected parameter %s\n", pszCmd)); 1569 cmd = CMD_DISK; 1570 } 1571 a->argv++; 1572 a->argc--; 1573 } 1574 else 1575 { 1576 pszCmd = NULL; 1577 cmd = CMD_DISK; 1578 } 1579 1759 1580 if (a->argc == 0) 1760 return errorSyntax(USAGE_ HDPROPERTY, "Missing action");1581 return errorSyntax(USAGE_MEDIUMPROPERTY, "Missing action"); 1761 1582 1762 1583 pszAction = a->argv[0]; … … 1764 1585 && RTStrICmp(pszAction, "get") 1765 1586 && RTStrICmp(pszAction, "delete")) 1766 return errorSyntax(USAGE_ HDPROPERTY, "Invalid action given: %s", pszAction);1587 return errorSyntax(USAGE_MEDIUMPROPERTY, "Invalid action given: %s", pszAction); 1767 1588 1768 1589 if ( ( !RTStrICmp(pszAction, "set") … … 1770 1591 || ( RTStrICmp(pszAction, "set") 1771 1592 && a->argc != 3)) 1772 return errorSyntax(USAGE_ HDPROPERTY, "Invalid number of arguments given for action: %s", pszAction);1593 return errorSyntax(USAGE_MEDIUMPROPERTY, "Invalid number of arguments given for action: %s", pszAction); 1773 1594 1774 1595 pszFilenameOrUuid = a->argv[1]; 1775 1596 pszProperty = a->argv[2]; 1776 1597 1777 rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk, 1778 AccessMode_ReadWrite, pMedium, 1779 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1598 if (cmd == CMD_DISK) 1599 rc = openMedium(a, pszFilenameOrUuid, DeviceType_HardDisk, 1600 AccessMode_ReadWrite, pMedium, 1601 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1602 else if (cmd == CMD_DVD) 1603 rc = openMedium(a, pszFilenameOrUuid, DeviceType_DVD, 1604 AccessMode_ReadOnly, pMedium, 1605 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1606 else if (cmd == CMD_FLOPPY) 1607 rc = openMedium(a, pszFilenameOrUuid, DeviceType_Floppy, 1608 AccessMode_ReadWrite, pMedium, 1609 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1780 1610 if (SUCCEEDED(rc) && !pMedium.isNull()) 1781 1611 { … … 1794 1624 else if (!RTStrICmp(pszAction, "delete")) 1795 1625 { 1626 const char *pszValue = a->argv[3]; 1627 CHECK_ERROR(pMedium, SetProperty(Bstr(pszProperty).raw(), Bstr().raw())); 1796 1628 /** @todo */ 1797 1629 } -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r54400 r54438 524 524 if (fCategory & USAGE_CLOSEMEDIUM) 525 525 RTStrmPrintf(pStrm, 526 "%s closemedium %s disk|dvd|floppy<uuid|filename>\n"526 "%s closemedium %s [disk|dvd|floppy] <uuid|filename>\n" 527 527 " [--delete]\n" 528 528 "\n", SEP); … … 586 586 "\n", SEP); 587 587 588 if (fCategory & USAGE_SHOW HDINFO)589 RTStrmPrintf(pStrm, 590 "%s show hdinfo %s<uuid|filename>\n"591 "\n", SEP); 592 593 if (fCategory & USAGE_CREATE HD)594 RTStrmPrintf(pStrm, 595 "%s create hd %s--filename <filename>\n"588 if (fCategory & USAGE_SHOWMEDIUMINFO) 589 RTStrmPrintf(pStrm, 590 "%s showmediuminfo %s [disk|dvd|floppy] <uuid|filename>\n" 591 "\n", SEP); 592 593 if (fCategory & USAGE_CREATEMEDIUM) 594 RTStrmPrintf(pStrm, 595 "%s createmedium %s [disk|dvd|floppy] --filename <filename>\n" 596 596 " [--size <megabytes>|--sizebyte <bytes>]\n" 597 597 " [--diffparent <uuid>|<filename>\n" … … 600 600 "\n", SEP); 601 601 602 if (fCategory & USAGE_MODIFY HD)603 RTStrmPrintf(pStrm, 604 "%s modify hd %s<uuid|filename>\n"602 if (fCategory & USAGE_MODIFYMEDIUM) 603 RTStrmPrintf(pStrm, 604 "%s modifymedium %s [disk|dvd|floppy] <uuid|filename>\n" 605 605 " [--type normal|writethrough|immutable|shareable|\n" 606 606 " readonly|multiattach]\n" … … 611 611 "\n", SEP); 612 612 613 if (fCategory & USAGE_CLONE HD)614 RTStrmPrintf(pStrm, 615 "%s clone hd %s<uuid|inputfile> <uuid|outputfile>\n"613 if (fCategory & USAGE_CLONEMEDIUM) 614 RTStrmPrintf(pStrm, 615 "%s clonemedium %s [disk|dvd|floppy] <uuid|inputfile> <uuid|outputfile>\n" 616 616 " [--format VDI|VMDK|VHD|RAW|<other>]\n" 617 617 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n" … … 619 619 "\n", SEP); 620 620 621 if (fCategory & USAGE_ HDPROPERTY)622 RTStrmPrintf(pStrm, 623 "%s hdproperty %sset <uuid|filename>\n"621 if (fCategory & USAGE_MEDIUMPROPERTY) 622 RTStrmPrintf(pStrm, 623 "%s mediumproperty %s [disk|dvd|floppy] set <uuid|filename>\n" 624 624 " <property> <value>\n" 625 625 "\n" 626 " get <uuid|filename>\n"626 " [disk|dvd|floppy] get <uuid|filename>\n" 627 627 " <property>\n" 628 628 "\n" 629 " delete <uuid|filename>\n"629 " [disk|dvd|floppy] delete <uuid|filename>\n" 630 630 " <property>\n" 631 631 "\n", SEP); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp
r51259 r54438 5 5 6 6 /* 7 * Copyright (C) 2006-201 2Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 83 83 bool fSetNewUuid = false; 84 84 bool fSetNewParentUuid = false; 85 MediumType_T mediumType = MediumType_Normal;85 MediumType_T enmMediumType = MediumType_Normal; 86 86 Bstr bstrComment; 87 87 const char *pszCtl = NULL; … … 291 291 case 'M': // --type 292 292 { 293 int vrc = parse DiskType(ValueUnion.psz, &mediumType);293 int vrc = parseMediumType(ValueUnion.psz, &enmMediumType); 294 294 if (RT_FAILURE(vrc)) 295 return errorArgument("Invalid hard disktype '%s'", ValueUnion.psz);295 return errorArgument("Invalid medium type '%s'", ValueUnion.psz); 296 296 fSetMediumType = true; 297 297 break; … … 601 601 bstrISCSIMedium = BstrFmt("%ls|%ls|%ls", bstrServer.raw(), bstrTarget.raw(), bstrLun.raw()); 602 602 603 CHECK_ERROR(a->virtualBox, CreateHardDisk(Bstr("iSCSI").raw(), 604 bstrISCSIMedium.raw(), 605 pMedium2Mount.asOutParam())); 603 CHECK_ERROR(a->virtualBox, CreateMedium(Bstr("iSCSI").raw(), 604 bstrISCSIMedium.raw(), 605 AccessMode_ReadWrite, 606 DeviceType_HardDisk, 607 pMedium2Mount.asOutParam())); 606 608 if (FAILED(rc)) goto leave; 607 609 if (!bstrPort.isEmpty()) … … 687 689 if (pMedium2Mount && fSetMediumType) 688 690 { 689 CHECK_ERROR(pMedium2Mount, COMSETTER(Type)( mediumType));691 CHECK_ERROR(pMedium2Mount, COMSETTER(Type)(enmMediumType)); 690 692 if (FAILED(rc)) 691 693 throw Utf8Str("Failed to set the medium type"); -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevd/UIWizardCloneVD.cpp
r52730 r54438 5 5 6 6 /* 7 * Copyright (C) 2006-201 3Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 68 68 69 69 /* Create new virtual hard-disk: */ 70 CMedium virtualDisk = vbox.Create HardDisk(mediumFormat.GetName(), strMediumPath);70 CMedium virtualDisk = vbox.CreateMedium(mediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk); 71 71 if (!vbox.isOk()) 72 72 { -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvd/UIWizardNewVD.cpp
r52730 r54438 5 5 6 6 /* 7 * Copyright (C) 2006-201 3Oracle Corporation7 * Copyright (C) 2006-2015 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 72 72 73 73 /* Create new virtual hard-disk: */ 74 CMedium virtualDisk = vbox.Create HardDisk(mediumFormat.GetName(), strMediumPath);74 CMedium virtualDisk = vbox.CreateMedium(mediumFormat.GetName(), strMediumPath, KAccessMode_ReadWrite, KDeviceType_HardDisk); 75 75 if (!vbox.isOk()) 76 76 {
Note:
See TracChangeset
for help on using the changeset viewer.