Changeset 34888 in vbox for trunk/src/VBox
- Timestamp:
- Dec 9, 2010 2:17:58 PM (14 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r34829 r34888 289 289 { "-compact", 'c', RTGETOPT_REQ_NOTHING }, // deprecated 290 290 { "compact", 'c', RTGETOPT_REQ_NOTHING }, // deprecated 291 { "--resize", 'r', RTGETOPT_REQ_UINT64 } 291 { "--resize", 'r', RTGETOPT_REQ_UINT64 }, 292 { "--resizebyte", 'R', RTGETOPT_REQ_UINT64 } 292 293 }; 293 294 … … 301 302 bool fModifyDiskType = false, fModifyAutoReset = false, fModifyCompact = false; 302 303 bool fModifyResize = false; 303 uint64_t resizeMB= 0;304 uint64_t cbResize = 0; 304 305 const char *FilenameOrUuid = NULL; 306 bool unknown = false; 305 307 306 308 int c; … … 333 335 334 336 case 'r': // --resize 335 resizeMB = ValueUnion.u64; 337 cbResize = ValueUnion.u64 * _1M; 338 fModifyResize = true; 339 break; 340 341 case 'R': // --resizebyte 342 cbResize = ValueUnion.u64; 336 343 fModifyResize = true; 337 344 break; … … 367 374 return errorSyntax(USAGE_MODIFYHD, "No operation specified"); 368 375 369 /* first guess is that it's a UUID */ 370 CHECK_ERROR(a->virtualBox, FindMedium(Bstr(FilenameOrUuid).raw(), 371 DeviceType_HardDisk, 372 hardDisk.asOutParam())); 373 if (FAILED(rc)) 374 return 1; 375 376 if (fModifyDiskType) 377 { 378 /* hard disk must be registered */ 379 if (SUCCEEDED(rc) && hardDisk) 380 { 381 MediumType_T hddType; 382 CHECK_ERROR(hardDisk, COMGETTER(Type)(&hddType)); 383 384 if (hddType != DiskType) 385 CHECK_ERROR(hardDisk, COMSETTER(Type)(DiskType)); 386 } 387 else 388 return errorArgument("Hard disk image not registered"); 389 } 390 391 if (fModifyAutoReset) 392 { 393 CHECK_ERROR(hardDisk, COMSETTER(AutoReset)(AutoReset)); 394 } 395 396 if (fModifyCompact) 397 { 398 bool unknown = false; 376 /* Depending on the operation the medium must be in the registry or 377 * may be opened on demand. */ 378 if (fModifyDiskType || fModifyAutoReset) 379 { 380 CHECK_ERROR(a->virtualBox, FindMedium(Bstr(FilenameOrUuid).raw(), 381 DeviceType_HardDisk, 382 hardDisk.asOutParam())); 383 } 384 else 385 { 386 rc = a->virtualBox->FindMedium(Bstr(FilenameOrUuid).raw(), 387 DeviceType_HardDisk, 388 hardDisk.asOutParam()); 399 389 /* the hard disk image might not be registered */ 400 390 if (!hardDisk) … … 420 410 } 421 411 } 422 if (SUCCEEDED(rc) && hardDisk) 423 { 424 ComPtr<IProgress> progress; 425 CHECK_ERROR(hardDisk, Compact(progress.asOutParam())); 426 if (SUCCEEDED(rc)) 427 rc = showProgress(progress); 428 if (FAILED(rc)) 429 { 430 if (rc == E_NOTIMPL) 431 RTMsgError("Compact hard disk operation is not implemented!"); 432 else if (rc == VBOX_E_NOT_SUPPORTED) 433 RTMsgError("Compact hard disk operation for this format is not implemented yet!"); 434 else 435 com::GluePrintRCMessage(rc); 436 } 437 if (unknown) 438 hardDisk->Close(); 412 } 413 if (FAILED(rc)) 414 return 1; 415 if (hardDisk.isNull()) 416 { 417 RTMsgError("Invalid hard disk reference, avoiding crash"); 418 return 1; 419 } 420 421 if (fModifyDiskType) 422 { 423 MediumType_T hddType; 424 CHECK_ERROR(hardDisk, COMGETTER(Type)(&hddType)); 425 426 if (hddType != DiskType) 427 CHECK_ERROR(hardDisk, COMSETTER(Type)(DiskType)); 428 } 429 430 if (fModifyAutoReset) 431 { 432 CHECK_ERROR(hardDisk, COMSETTER(AutoReset)(AutoReset)); 433 } 434 435 if (fModifyCompact) 436 { 437 ComPtr<IProgress> progress; 438 CHECK_ERROR(hardDisk, Compact(progress.asOutParam())); 439 if (SUCCEEDED(rc)) 440 rc = showProgress(progress); 441 if (FAILED(rc)) 442 { 443 if (rc == E_NOTIMPL) 444 RTMsgError("Compact hard disk operation is not implemented!"); 445 else if (rc == VBOX_E_NOT_SUPPORTED) 446 RTMsgError("Compact hard disk operation for this format is not implemented yet!"); 447 else 448 com::GluePrintRCMessage(rc); 439 449 } 440 450 } … … 442 452 if (fModifyResize) 443 453 { 444 bool unknown = false; 445 /* the hard disk image might not be registered */ 446 if (!hardDisk) 447 { 448 unknown = true; 449 rc = a->virtualBox->OpenMedium(Bstr(FilenameOrUuid).raw(), 450 DeviceType_HardDisk, 451 AccessMode_ReadWrite, 452 hardDisk.asOutParam()); 453 if (rc == VBOX_E_FILE_ERROR) 454 { 455 char szFilenameAbs[RTPATH_MAX] = ""; 456 int irc = RTPathAbs(FilenameOrUuid, szFilenameAbs, sizeof(szFilenameAbs)); 457 if (RT_FAILURE(irc)) 458 { 459 RTMsgError("Cannot convert filename \"%s\" to absolute path", FilenameOrUuid); 460 return 1; 461 } 462 CHECK_ERROR(a->virtualBox, OpenMedium(Bstr(szFilenameAbs).raw(), 463 DeviceType_HardDisk, 464 AccessMode_ReadWrite, 465 hardDisk.asOutParam())); 466 } 467 } 468 if (SUCCEEDED(rc) && hardDisk) 469 { 470 ComPtr<IProgress> progress; 471 CHECK_ERROR(hardDisk, Resize(resizeMB, progress.asOutParam())); 472 if (SUCCEEDED(rc)) 473 rc = showProgress(progress); 474 if (FAILED(rc)) 475 { 476 if (rc == E_NOTIMPL) 477 RTMsgError("Resize hard disk operation is not implemented!"); 478 else if (rc == VBOX_E_NOT_SUPPORTED) 479 RTMsgError("Resize hard disk operation for this format is not implemented yet!"); 480 else 481 com::GluePrintRCMessage(rc); 482 } 483 if (unknown) 484 hardDisk->Close(); 485 } 486 } 454 ComPtr<IProgress> progress; 455 CHECK_ERROR(hardDisk, Resize(cbResize, progress.asOutParam())); 456 if (SUCCEEDED(rc)) 457 rc = showProgress(progress); 458 if (FAILED(rc)) 459 { 460 if (rc == E_NOTIMPL) 461 RTMsgError("Resize hard disk operation is not implemented!"); 462 else if (rc == VBOX_E_NOT_SUPPORTED) 463 RTMsgError("Resize hard disk operation for this format is not implemented yet!"); 464 else 465 com::GluePrintRCMessage(rc); 466 } 467 } 468 469 if (unknown) 470 hardDisk->Close(); 487 471 488 472 return SUCCEEDED(rc) ? 0 : 1; -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r34663 r34888 495 495 " [--autoreset on|off]\n" 496 496 " [--compact]\n" 497 " [--resize <megabytes> ]\n"497 " [--resize <megabytes>|--resizebyte <bytes>]\n" 498 498 "\n"); 499 499
Note:
See TracChangeset
for help on using the changeset viewer.