Changeset 44028 in vbox
- Timestamp:
- Dec 4, 2012 8:03:41 AM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
r42460 r44028 199 199 ComPtr<ISnapshot> ¤tSnapshot, 200 200 VMINFO_DETAILS details, 201 const com:: Bstr &prefix = "",201 const com::Utf8Str &prefix = "", 202 202 int level = 0); 203 203 int handleShowVMInfo(HandlerArg *a); … … 231 231 232 232 /* VBoxManageDisk.cpp */ 233 HRESULT findMedium(HandlerArg *a, const char *pszFilenameOrUuid, 234 DeviceType_T enmDevType, bool fSilent, 235 ComPtr<IMedium> &pMedium); 236 HRESULT findOrOpenMedium(HandlerArg *a, const char *pszFilenameOrUuid, 237 DeviceType_T enmDevType, AccessMode_T enmAccessMode, 238 ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen, 239 bool *pfWasUnknown); 233 HRESULT openMedium(HandlerArg *a, const char *pszFilenameOrUuid, 234 DeviceType_T enmDevType, AccessMode_T enmAccessMode, 235 ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen, 236 bool fSilent); 240 237 int handleCreateHardDisk(HandlerArg *a); 241 238 int handleModifyHardDisk(HandlerArg *a); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageDisk.cpp
r43862 r44028 149 149 } 150 150 151 HRESULT findMedium(HandlerArg *a, const char *pszFilenameOrUuid, 152 DeviceType_T enmDevType, bool fSilent, 153 ComPtr<IMedium> &pMedium) 151 HRESULT openMedium(HandlerArg *a, const char *pszFilenameOrUuid, 152 DeviceType_T enmDevType, AccessMode_T enmAccessMode, 153 ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen, 154 bool fSilent) 154 155 { 155 156 HRESULT rc; … … 171 172 172 173 if (!fSilent) 173 CHECK_ERROR(a->virtualBox, OpenMedium(Bstr(pszFilenameOrUuid).raw(),174 enmDevType,175 AccessMode_ReadWrite,176 /*fForceNewUidOnOpen */ false,177 pMedium.asOutParam()));178 else179 rc = a->virtualBox->OpenMedium(Bstr(pszFilenameOrUuid).raw(),180 enmDevType,181 AccessMode_ReadWrite,182 /*fForceNewUidOnOpen */ false,183 pMedium.asOutParam());184 return rc;185 }186 187 HRESULT findOrOpenMedium(HandlerArg *a, const char *pszFilenameOrUuid,188 DeviceType_T enmDevType, AccessMode_T enmAccessMode,189 ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen,190 bool *pfWasUnknown)191 {192 HRESULT rc;193 bool fWasUnknown = false;194 Guid id(pszFilenameOrUuid);195 char szFilenameAbs[RTPATH_MAX] = "";196 197 /* If it is no UUID, convert the filename to an absolute one. */198 if (id.isEmpty())199 {200 int irc = RTPathAbs(pszFilenameOrUuid, szFilenameAbs, sizeof(szFilenameAbs));201 if (RT_FAILURE(irc))202 {203 RTMsgError("Cannot convert filename \"%s\" to absolute path", pszFilenameOrUuid);204 return E_FAIL;205 }206 pszFilenameOrUuid = szFilenameAbs;207 }208 209 rc = a->virtualBox->OpenMedium(Bstr(pszFilenameOrUuid).raw(),210 enmDevType,211 enmAccessMode,212 /*fForceNewUidOnOpen */ false,213 pMedium.asOutParam());214 /* If the medium is unknown try to open it. */215 if (!pMedium)216 {217 174 CHECK_ERROR(a->virtualBox, OpenMedium(Bstr(pszFilenameOrUuid).raw(), 218 enmDevType, enmAccessMode, 175 enmDevType, 176 enmAccessMode, 219 177 fForceNewUuidOnOpen, 220 178 pMedium.asOutParam())); 221 if (SUCCEEDED(rc)) 222 fWasUnknown = true; 223 } 224 if (RT_VALID_PTR(pfWasUnknown)) 225 *pfWasUnknown = fWasUnknown; 179 else 180 rc = a->virtualBox->OpenMedium(Bstr(pszFilenameOrUuid).raw(), 181 enmDevType, 182 enmAccessMode, 183 fForceNewUuidOnOpen, 184 pMedium.asOutParam()); 185 226 186 return rc; 227 187 } … … 344 304 345 305 /* check the outcome */ 346 bool fUnknownParent = false;347 306 ComPtr<IMedium> parentHardDisk; 348 307 if (fBase) … … 373 332 format = pszExt; 374 333 } 375 rc = findOrOpenMedium(a, diffparent, DeviceType_HardDisk, AccessMode_ReadWrite,376 parentHardDisk, false /* fForceNewUuidOnOpen */,377 &fUnknownParent);334 rc = openMedium(a, diffparent, DeviceType_HardDisk, 335 AccessMode_ReadWrite, parentHardDisk, 336 false /* fForceNewUuidOnOpen */, false /* fSilent */); 378 337 if (FAILED(rc)) 379 338 return 1; … … 431 390 432 391 CHECK_ERROR(hardDisk, Close()); 433 if (!fBase && fUnknownParent)434 CHECK_ERROR(parentHardDisk, Close());435 392 } 436 393 return SUCCEEDED(rc) ? 0 : 1; … … 463 420 uint64_t cbResize = 0; 464 421 const char *FilenameOrUuid = NULL; 465 bool unknown = false;466 422 467 423 int c; … … 533 489 return errorSyntax(USAGE_MODIFYHD, "No operation specified"); 534 490 535 /* Depending on the operation the medium must be in the registry or 536 * may be opened on demand. */ 537 if (fModifyDiskType || fModifyAutoReset) 538 rc = findMedium(a, FilenameOrUuid, DeviceType_HardDisk, false /* fSilent */, hardDisk); 539 else 540 rc = findOrOpenMedium(a, FilenameOrUuid, DeviceType_HardDisk, AccessMode_ReadWrite, 541 hardDisk, false /* fForceNewUuidOnOpen */, &unknown); 491 /* Always open the medium if necessary, there is no other way. */ 492 rc = openMedium(a, FilenameOrUuid, DeviceType_HardDisk, 493 AccessMode_ReadWrite, hardDisk, 494 false /* fForceNewUuidOnOpen */, false /* fSilent */); 542 495 if (FAILED(rc)) 543 496 return 1; … … 597 550 } 598 551 } 599 600 if (unknown)601 hardDisk->Close();602 552 603 553 return SUCCEEDED(rc) ? 0 : 1; … … 692 642 ComPtr<IMedium> srcDisk; 693 643 ComPtr<IMedium> dstDisk; 694 bool fSrcUnknown = false; 695 bool fDstUnknown = false; 696 697 rc = findOrOpenMedium(a, pszSrc, DeviceType_HardDisk, AccessMode_ReadOnly, 698 srcDisk, false /* fForceNewUuidOnOpen */, &fSrcUnknown); 644 645 rc = openMedium(a, pszSrc, DeviceType_HardDisk, AccessMode_ReadOnly, 646 srcDisk, false /* fForceNewUuidOnOpen */, 647 false /* fSilent */); 699 648 if (FAILED(rc)) 700 649 return 1; … … 705 654 if (fExisting) 706 655 { 707 rc = findOrOpenMedium(a, pszDst, DeviceType_HardDisk, AccessMode_ReadWrite, 708 dstDisk, false /* fForceNewUuidOnOpen */, &fDstUnknown); 656 rc = openMedium(a, pszDst, DeviceType_HardDisk, 657 AccessMode_ReadWrite, dstDisk, 658 false /* fForceNewUuidOnOpen */, 659 false /* fSilent */); 709 660 if (FAILED(rc)) 710 661 break; … … 723 674 if (FAILED(rc)) 724 675 break; 725 fDstUnknown = true;726 676 } 727 677 … … 739 689 } 740 690 while (0); 741 742 if (fDstUnknown && !dstDisk.isNull())743 {744 /* forget the created clone */745 dstDisk->Close();746 }747 if (fSrcUnknown)748 {749 /* close the unknown hard disk to forget it again */750 srcDisk->Close();751 }752 691 753 692 return SUCCEEDED(rc) ? 0 : 1; … … 986 925 987 926 ComPtr<IMedium> hardDisk; 988 bool unknown = false; 989 990 rc = findOrOpenMedium(a, FilenameOrUuid, DeviceType_HardDisk, AccessMode_ReadOnly,991 hardDisk, false /* fForceNewUuidOnOpen */, &unknown);927 928 rc = openMedium(a, FilenameOrUuid, DeviceType_HardDisk, 929 AccessMode_ReadOnly, hardDisk, 930 false /* fForceNewUuidOnOpen */, false /* fSilent */); 992 931 if (FAILED(rc)) 993 932 return 1; … … 1089 1028 /// @todo also dump config parameters (iSCSI) 1090 1029 1091 if (!unknown) 1092 { 1093 com::SafeArray<BSTR> machineIds; 1094 hardDisk->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds)); 1095 for (size_t j = 0; j < machineIds.size(); ++ j) 1096 { 1097 ComPtr<IMachine> machine; 1098 CHECK_ERROR(a->virtualBox, FindMachine(machineIds[j], machine.asOutParam())); 1099 ASSERT(machine); 1100 Bstr name; 1101 machine->COMGETTER(Name)(name.asOutParam()); 1102 machine->COMGETTER(Id)(uuid.asOutParam()); 1103 RTPrintf("%s%ls (UUID: %ls)\n", 1104 j == 0 ? "In use by VMs: " : " ", 1105 name.raw(), machineIds[j]); 1106 } 1107 /// @todo NEWMEDIA check usage in snapshots too 1108 /// @todo NEWMEDIA also list children 1109 } 1030 com::SafeArray<BSTR> machineIds; 1031 hardDisk->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds)); 1032 for (size_t j = 0; j < machineIds.size(); ++ j) 1033 { 1034 ComPtr<IMachine> machine; 1035 CHECK_ERROR(a->virtualBox, FindMachine(machineIds[j], machine.asOutParam())); 1036 ASSERT(machine); 1037 Bstr name; 1038 machine->COMGETTER(Name)(name.asOutParam()); 1039 machine->COMGETTER(Id)(uuid.asOutParam()); 1040 RTPrintf("%s%ls (UUID: %ls)\n", 1041 j == 0 ? "In use by VMs: " : " ", 1042 name.raw(), machineIds[j]); 1043 } 1044 /// @todo NEWMEDIA check usage in snapshots too 1045 /// @todo NEWMEDIA also list children 1110 1046 1111 1047 Bstr loc; … … 1122 1058 } 1123 1059 while (0); 1124 1125 if (unknown)1126 {1127 /* close the unknown hard disk to forget it again */1128 hardDisk->Close();1129 }1130 1060 1131 1061 return SUCCEEDED(rc) ? 0 : 1; … … 1217 1147 1218 1148 if (cmd == CMD_DISK) 1219 rc = findMedium(a, FilenameOrUuid, DeviceType_HardDisk, false /* fSilent */, medium); 1149 rc = openMedium(a, FilenameOrUuid, DeviceType_HardDisk, 1150 AccessMode_ReadWrite, medium, 1151 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1220 1152 else if (cmd == CMD_DVD) 1221 rc = findMedium(a, FilenameOrUuid, DeviceType_DVD, false /* fSilent */, medium); 1153 rc = openMedium(a, FilenameOrUuid, DeviceType_DVD, 1154 AccessMode_ReadOnly, medium, 1155 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1222 1156 else if (cmd == CMD_FLOPPY) 1223 rc = findMedium(a, FilenameOrUuid, DeviceType_Floppy, false /* fSilent */, medium); 1157 rc = openMedium(a, FilenameOrUuid, DeviceType_Floppy, 1158 AccessMode_ReadWrite, medium, 1159 false /* fForceNewUuidOnOpen */, false /* fSilent */); 1224 1160 1225 1161 if (SUCCEEDED(rc) && medium) -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp
r43635 r44028 51 51 ComPtr<ISnapshot> ¤tSnapshot, 52 52 VMINFO_DETAILS details, 53 const Bstr &prefix /* = ""*/,53 const Utf8Str &prefix /* = ""*/, 54 54 int level /*= 0*/) 55 55 { … … 57 57 Bstr name; 58 58 Bstr uuid; 59 CHECK_ERROR2_RET(rootSnapshot,COMGETTER(Name)(name.asOutParam()), hrcCheck); 60 CHECK_ERROR2_RET(rootSnapshot,COMGETTER(Id)(uuid.asOutParam()), hrcCheck); 59 Bstr description; 60 CHECK_ERROR2_RET(rootSnapshot, COMGETTER(Name)(name.asOutParam()), hrcCheck); 61 CHECK_ERROR2_RET(rootSnapshot, COMGETTER(Id)(uuid.asOutParam()), hrcCheck); 62 CHECK_ERROR2_RET(rootSnapshot, COMGETTER(Description)(description.asOutParam()), hrcCheck); 63 bool fCurrent = (rootSnapshot == currentSnapshot); 61 64 if (details == VMINFO_MACHINEREADABLE) 62 65 { 63 66 /* print with hierarchical numbering */ 64 RTPrintf("SnapshotName%ls=\"%ls\"\n", prefix.raw(), name.raw()); 65 RTPrintf("SnapshotUUID%ls=\"%s\"\n", prefix.raw(), Utf8Str(uuid).c_str()); 67 RTPrintf("SnapshotName%s=\"%ls\"\n", prefix.c_str(), name.raw()); 68 RTPrintf("SnapshotUUID%s=\"%s\"\n", prefix.c_str(), Utf8Str(uuid).c_str()); 69 if (!description.isEmpty()) 70 RTPrintf("SnapshotDescription%s=\"%ls\"\n", prefix.c_str(), description.raw()); 71 if (fCurrent) 72 { 73 RTPrintf("CurrentSnapshotName=\"%ls\"\n", name.raw()); 74 RTPrintf("CurrentSnapshotUUID=\"%s\"\n", Utf8Str(uuid).c_str()); 75 RTPrintf("CurrentSnapshotNode=\"SnapshotName%s\"\n", prefix.c_str()); 76 } 66 77 } 67 78 else 68 79 { 69 80 /* print with indentation */ 70 bool fCurrent = (rootSnapshot == currentSnapshot); 71 RTPrintf(" %lsName: %ls (UUID: %s)%s\n", 72 prefix.raw(), 81 RTPrintf(" %sName: %ls (UUID: %s)%s\n", 82 prefix.c_str(), 73 83 name.raw(), 74 84 Utf8Str(uuid).c_str(), 75 85 (fCurrent) ? " *" : ""); 86 if (!description.isEmpty()) 87 RTPrintf(" %sDescription:\n%ls\n", prefix.c_str(), description.raw()); 76 88 } 77 89 … … 87 99 if (snapshot) 88 100 { 89 Bstr newPrefix;101 Utf8Str newPrefix; 90 102 if (details == VMINFO_MACHINEREADABLE) 91 newPrefix = Utf8StrFmt("% ls-%d", prefix.raw(), index + 1);103 newPrefix = Utf8StrFmt("%s-%d", prefix.c_str(), index + 1); 92 104 else 93 105 { 94 newPrefix = Utf8StrFmt("% ls ", prefix.raw());106 newPrefix = Utf8StrFmt("%s ", prefix.c_str()); 95 107 } 96 108 … … 2285 2297 } 2286 2298 2287 2288 2299 if (details != VMINFO_MACHINEREADABLE) 2289 2300 RTPrintf("Guest:\n\n"); -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageModifyVM.cpp
r43023 r44028 770 770 { 771 771 ComPtr<IMedium> hardDisk; 772 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk, 773 AccessMode_ReadWrite, hardDisk, 774 false /* fForceNewUuidOnOpen */, NULL); 772 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk, 773 AccessMode_ReadWrite, hardDisk, 774 false /* fForceNewUuidOnOpen */, 775 false /* fSilent */); 775 776 if (FAILED(rc)) 776 777 break; … … 855 856 { 856 857 ComPtr<IMedium> hardDisk; 857 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk, 858 AccessMode_ReadWrite, hardDisk, 859 false /* fForceNewUuidOnOpen */, NULL); 858 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk, 859 AccessMode_ReadWrite, hardDisk, 860 false /* fForceNewUuidOnOpen */, 861 false /* fSilent */); 860 862 if (FAILED(rc)) 861 863 break; … … 983 985 else 984 986 { 985 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_DVD, 986 AccessMode_ReadOnly, dvdMedium, 987 false /* fForceNewUuidOnOpen */, NULL); 987 rc = openMedium(a, ValueUnion.psz, DeviceType_DVD, 988 AccessMode_ReadOnly, dvdMedium, 989 false /* fForceNewUuidOnOpen */, 990 false /* fSilent */); 988 991 if (FAILED(rc)) 989 992 break; … … 1047 1050 else 1048 1051 { 1049 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_Floppy, 1050 AccessMode_ReadWrite, floppyMedium, 1051 false /* fForceNewUuidOnOpen */, NULL); 1052 rc = openMedium(a, ValueUnion.psz, DeviceType_Floppy, 1053 AccessMode_ReadWrite, floppyMedium, 1054 false /* fForceNewUuidOnOpen */, 1055 false /* fSilent */); 1052 1056 if (FAILED(rc)) 1053 1057 break; -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageStorageController.cpp
r43914 r44028 484 484 { 485 485 ComPtr<IMedium> pExistingMedium; 486 rc = findMedium(a, pszMedium, deviceType, true /* fSilent */, 487 pExistingMedium); 486 rc = openMedium(a, pszMedium, deviceType, 487 AccessMode_ReadWrite, 488 pExistingMedium, 489 false /* fForceNewUuidOnOpen */, 490 true /* fSilent */); 488 491 if (SUCCEEDED(rc) && pExistingMedium) 489 492 { … … 638 641 { 639 642 Bstr bstrMedium(pszMedium); 640 rc = findOrOpenMedium(a, pszMedium, devTypeRequested,641 642 fSetNewUuid, NULL);643 rc = openMedium(a, pszMedium, devTypeRequested, 644 AccessMode_ReadWrite, pMedium2Mount, 645 fSetNewUuid, false /* fSilent */); 643 646 if (FAILED(rc) || !pMedium2Mount) 644 647 throw Utf8StrFmt("Invalid UUID or filename \"%s\"", pszMedium);
Note:
See TracChangeset
for help on using the changeset viewer.