Changeset 21032 in vbox for trunk/src/VBox
- Timestamp:
- Jun 29, 2009 3:27:38 PM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r20928 r21032 501 501 { "--static", 'F', RTGETOPT_REQ_NOTHING }, 502 502 { "-static", 'F', RTGETOPT_REQ_NOTHING }, 503 { "--existing", 'E', RTGETOPT_REQ_NOTHING }, 503 504 { "--variant", 'm', RTGETOPT_REQ_STRING }, 504 505 { "-variant", 'm', RTGETOPT_REQ_STRING }, … … 518 519 Bstr format; 519 520 HardDiskVariant_T DiskVariant = HardDiskVariant_Standard; 521 bool fExisting = false; 520 522 bool fRemember = false; 523 bool fSetDiskType = false; 521 524 HardDiskType_T DiskType = HardDiskType_Normal; 522 525 … … 534 537 break; 535 538 539 case 'F': // --static 540 DiskVariant |= HardDiskVariant_Fixed; 541 break; 542 543 case 'E': // --existing 544 fExisting = true; 545 break; 546 536 547 case 'm': // --variant 537 548 vrc = parseDiskVariant(ValueUnion.psz, &DiskVariant); … … 548 559 if (RT_FAILURE(vrc)) 549 560 return errorArgument("Invalid hard disk type '%s'", ValueUnion.psz); 561 fSetDiskType = true; 550 562 break; 551 563 … … 580 592 if (dst.isEmpty()) 581 593 return errorSyntax(USAGE_CLONEHD, "Mandatory output file parameter missing"); 594 if (fExisting && (!format.isEmpty() || DiskVariant != HardDiskType_Normal)) 595 return errorSyntax(USAGE_CLONEHD, "Specified options which cannot be used with --existing"); 582 596 583 597 ComPtr<IHardDisk> srcDisk; 584 598 ComPtr<IHardDisk> dstDisk; 585 bool unknown = false; 599 bool fSrcUnknown = false; 600 bool fDstUnknown = false; 586 601 587 602 /* first guess is that it's a UUID */ … … 589 604 /* no? then it must be a filename */ 590 605 if (FAILED (rc)) 591 {592 606 rc = a->virtualBox->FindHardDisk(src, srcDisk.asOutParam()); 593 /* no? well, then it's an unknown image */ 594 if (FAILED (rc)) 595 { 596 rc = a->virtualBox->OpenHardDisk(src, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam()); 597 if (rc == VBOX_E_FILE_ERROR) 607 /* no? well, then it's an unknown image */ 608 if (FAILED (rc)) 609 { 610 rc = a->virtualBox->OpenHardDisk(src, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam()); 611 if (rc == VBOX_E_FILE_ERROR) 612 { 613 char szFilenameAbs[RTPATH_MAX] = ""; 614 int vrc = RTPathAbs(Utf8Str(src), szFilenameAbs, sizeof(szFilenameAbs)); 615 if (RT_FAILURE(vrc)) 598 616 { 599 char szFilenameAbs[RTPATH_MAX] = ""; 600 int vrc = RTPathAbs(Utf8Str(src), szFilenameAbs, sizeof(szFilenameAbs)); 601 if (RT_FAILURE(vrc)) 602 { 603 RTPrintf("Cannot convert filename \"%s\" to absolute path\n", Utf8Str(src).raw()); 604 return 1; 605 } 606 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam())); 617 RTPrintf("Cannot convert filename \"%s\" to absolute path\n", Utf8Str(src).raw()); 618 return 1; 607 619 } 608 else if (FAILED(rc)) 609 CHECK_ERROR(a->virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam())); 610 if (SUCCEEDED (rc)) 611 { 612 unknown = true; 613 } 614 } 620 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam())); 621 } 622 else if (FAILED(rc)) 623 CHECK_ERROR(a->virtualBox, OpenHardDisk(src, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), srcDisk.asOutParam())); 624 if (SUCCEEDED (rc)) 625 fSrcUnknown = true; 615 626 } 616 627 … … 620 631 break; 621 632 622 if (format.isEmpty()) 623 { 624 /* get the format of the source hard disk */ 625 CHECK_ERROR_BREAK(srcDisk, COMGETTER(Format) (format.asOutParam())); 626 } 627 628 CHECK_ERROR_BREAK(a->virtualBox, CreateHardDisk(format, dst, dstDisk.asOutParam())); 633 /* open/create destination hard disk */ 634 if (fExisting) 635 { 636 /* first guess is that it's a UUID */ 637 rc = a->virtualBox->GetHardDisk(dst, dstDisk.asOutParam()); 638 /* no? then it must be a filename */ 639 if (FAILED (rc)) 640 rc = a->virtualBox->FindHardDisk(dst, dstDisk.asOutParam()); 641 /* no? well, then it's an unknown image */ 642 if (FAILED (rc)) 643 { 644 rc = a->virtualBox->OpenHardDisk(dst, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), dstDisk.asOutParam()); 645 if (rc == VBOX_E_FILE_ERROR) 646 { 647 char szFilenameAbs[RTPATH_MAX] = ""; 648 int vrc = RTPathAbs(Utf8Str(dst), szFilenameAbs, sizeof(szFilenameAbs)); 649 if (RT_FAILURE(vrc)) 650 { 651 RTPrintf("Cannot convert filename \"%s\" to absolute path\n", Utf8Str(dst).raw()); 652 return 1; 653 } 654 CHECK_ERROR_BREAK(a->virtualBox, OpenHardDisk(Bstr(szFilenameAbs), AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), dstDisk.asOutParam())); 655 } 656 else if (FAILED(rc)) 657 CHECK_ERROR_BREAK(a->virtualBox, OpenHardDisk(dst, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), dstDisk.asOutParam())); 658 if (SUCCEEDED (rc)) 659 fDstUnknown = true; 660 } 661 else 662 fRemember = true; 663 if (SUCCEEDED(rc)) 664 { 665 /* Perform accessibility check now. */ 666 MediaState_T state; 667 CHECK_ERROR_BREAK(dstDisk, COMGETTER(State)(&state)); 668 } 669 CHECK_ERROR_BREAK(dstDisk, COMGETTER(Format) (format.asOutParam())); 670 } 671 else 672 { 673 /* use the format of the source hard disk if unspecified */ 674 if (format.isEmpty()) 675 CHECK_ERROR_BREAK(srcDisk, COMGETTER(Format) (format.asOutParam())); 676 CHECK_ERROR_BREAK(a->virtualBox, CreateHardDisk(format, dst, dstDisk.asOutParam())); 677 } 629 678 630 679 ComPtr<IProgress> progress; … … 658 707 dstDisk->Close(); 659 708 } 660 661 if (unknown) 709 else if (fSetDiskType) 710 { 711 CHECK_ERROR(dstDisk, COMSETTER(Type)(DiskType)); 712 } 713 714 if (fSrcUnknown) 662 715 { 663 716 /* close the unknown hard disk to forget it again */ -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp
r21013 r21032 380 380 " [--variant Standard,Fixed,Split2G,Stream,ESX]\n" 381 381 " [--type normal|writethrough|immutable]\n" 382 " [--remember] \n"382 " [--remember] [--existing]\n" 383 383 "\n"); 384 384 }
Note:
See TracChangeset
for help on using the changeset viewer.