VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageList.cpp@ 86134

最後變更 在這個檔案從86134是 86134,由 vboxsync 提交於 5 年 前

Main: bugref:9224: Added NVME drives enumeration on Linux. Fixed the showing the model of the drive if additional info is not available

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 93.0 KB
 
1/* $Id: VBoxManageList.cpp 86134 2020-09-16 15:39:09Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#ifndef VBOX_ONLY_DOCS
19
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#include <VBox/com/com.h>
25#include <VBox/com/string.h>
26#include <VBox/com/Guid.h>
27#include <VBox/com/array.h>
28#include <VBox/com/ErrorInfo.h>
29#include <VBox/com/errorprint.h>
30
31#include <VBox/com/VirtualBox.h>
32
33#include <VBox/log.h>
34#include <iprt/stream.h>
35#include <iprt/string.h>
36#include <iprt/time.h>
37#include <iprt/getopt.h>
38#include <iprt/ctype.h>
39
40#include <vector>
41#include <algorithm>
42
43#include "VBoxManage.h"
44using namespace com;
45
46#ifdef VBOX_WITH_HOSTNETIF_API
47static const char *getHostIfMediumTypeText(HostNetworkInterfaceMediumType_T enmType)
48{
49 switch (enmType)
50 {
51 case HostNetworkInterfaceMediumType_Ethernet: return "Ethernet";
52 case HostNetworkInterfaceMediumType_PPP: return "PPP";
53 case HostNetworkInterfaceMediumType_SLIP: return "SLIP";
54 case HostNetworkInterfaceMediumType_Unknown: return "Unknown";
55#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
56 case HostNetworkInterfaceMediumType_32BitHack: break; /* Shut up compiler warnings. */
57#endif
58 }
59 return "unknown";
60}
61
62static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
63{
64 switch (enmStatus)
65 {
66 case HostNetworkInterfaceStatus_Up: return "Up";
67 case HostNetworkInterfaceStatus_Down: return "Down";
68 case HostNetworkInterfaceStatus_Unknown: return "Unknown";
69#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
70 case HostNetworkInterfaceStatus_32BitHack: break; /* Shut up compiler warnings. */
71#endif
72 }
73 return "unknown";
74}
75#endif /* VBOX_WITH_HOSTNETIF_API */
76
77static const char*getDeviceTypeText(DeviceType_T enmType)
78{
79 switch (enmType)
80 {
81 case DeviceType_HardDisk: return "HardDisk";
82 case DeviceType_DVD: return "DVD";
83 case DeviceType_Floppy: return "Floppy";
84 /* Make MSC happy */
85 case DeviceType_Null: return "Null";
86 case DeviceType_Network: return "Network";
87 case DeviceType_USB: return "USB";
88 case DeviceType_SharedFolder: return "SharedFolder";
89 case DeviceType_Graphics3D: return "Graphics3D";
90#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
91 case DeviceType_32BitHack: break; /* Shut up compiler warnings. */
92#endif
93 }
94 return "Unknown";
95}
96
97
98/**
99 * List internal networks.
100 *
101 * @returns See produceList.
102 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
103 */
104static HRESULT listInternalNetworks(const ComPtr<IVirtualBox> pVirtualBox)
105{
106 HRESULT rc;
107 com::SafeArray<BSTR> internalNetworks;
108 CHECK_ERROR(pVirtualBox, COMGETTER(InternalNetworks)(ComSafeArrayAsOutParam(internalNetworks)));
109 for (size_t i = 0; i < internalNetworks.size(); ++i)
110 {
111 RTPrintf("Name: %ls\n", internalNetworks[i]);
112 }
113 return rc;
114}
115
116
117/**
118 * List network interfaces information (bridged/host only).
119 *
120 * @returns See produceList.
121 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
122 * @param fIsBridged Selects between listing host interfaces (for
123 * use with bridging) or host only interfaces.
124 */
125static HRESULT listNetworkInterfaces(const ComPtr<IVirtualBox> pVirtualBox,
126 bool fIsBridged)
127{
128 HRESULT rc;
129 ComPtr<IHost> host;
130 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
131 com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
132#if defined(VBOX_WITH_NETFLT)
133 if (fIsBridged)
134 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
135 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
136 else
137 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
138 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
139#else
140 RT_NOREF(fIsBridged);
141 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
142#endif
143 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
144 {
145 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
146#ifndef VBOX_WITH_HOSTNETIF_API
147 Bstr interfaceName;
148 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
149 RTPrintf("Name: %ls\n", interfaceName.raw());
150 Guid interfaceGuid;
151 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
152 RTPrintf("GUID: %ls\n\n", Bstr(interfaceGuid.toString()).raw());
153#else /* VBOX_WITH_HOSTNETIF_API */
154 Bstr interfaceName;
155 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
156 RTPrintf("Name: %ls\n", interfaceName.raw());
157 Bstr interfaceGuid;
158 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
159 RTPrintf("GUID: %ls\n", interfaceGuid.raw());
160 BOOL fDHCPEnabled = FALSE;
161 networkInterface->COMGETTER(DHCPEnabled)(&fDHCPEnabled);
162 RTPrintf("DHCP: %s\n", fDHCPEnabled ? "Enabled" : "Disabled");
163
164 Bstr IPAddress;
165 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
166 RTPrintf("IPAddress: %ls\n", IPAddress.raw());
167 Bstr NetworkMask;
168 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
169 RTPrintf("NetworkMask: %ls\n", NetworkMask.raw());
170 Bstr IPV6Address;
171 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
172 RTPrintf("IPV6Address: %ls\n", IPV6Address.raw());
173 ULONG IPV6NetworkMaskPrefixLength;
174 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
175 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
176 Bstr HardwareAddress;
177 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
178 RTPrintf("HardwareAddress: %ls\n", HardwareAddress.raw());
179 HostNetworkInterfaceMediumType_T Type;
180 networkInterface->COMGETTER(MediumType)(&Type);
181 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
182 BOOL fWireless = FALSE;
183 networkInterface->COMGETTER(Wireless)(&fWireless);
184 RTPrintf("Wireless: %s\n", fWireless ? "Yes" : "No");
185 HostNetworkInterfaceStatus_T Status;
186 networkInterface->COMGETTER(Status)(&Status);
187 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
188 Bstr netName;
189 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
190 RTPrintf("VBoxNetworkName: %ls\n\n", netName.raw());
191#endif
192 }
193 return rc;
194}
195
196
197#ifdef VBOX_WITH_CLOUD_NET
198/**
199 * List configured cloud network attachments.
200 *
201 * @returns See produceList.
202 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
203 * @param Reserved Placeholder!
204 */
205static HRESULT listCloudNetworks(const ComPtr<IVirtualBox> pVirtualBox)
206{
207 HRESULT rc;
208 com::SafeIfaceArray<ICloudNetwork> cloudNetworks;
209 CHECK_ERROR(pVirtualBox, COMGETTER(CloudNetworks)(ComSafeArrayAsOutParam(cloudNetworks)));
210 for (size_t i = 0; i < cloudNetworks.size(); ++i)
211 {
212 ComPtr<ICloudNetwork> cloudNetwork = cloudNetworks[i];
213 Bstr networkName;
214 cloudNetwork->COMGETTER(NetworkName)(networkName.asOutParam());
215 RTPrintf("Name: %ls\n", networkName.raw());
216 // Guid interfaceGuid;
217 // cloudNetwork->COMGETTER(Id)(interfaceGuid.asOutParam());
218 // RTPrintf("GUID: %ls\n\n", Bstr(interfaceGuid.toString()).raw());
219 BOOL fEnabled = FALSE;
220 cloudNetwork->COMGETTER(Enabled)(&fEnabled);
221 RTPrintf("State: %s\n", fEnabled ? "Enabled" : "Disabled");
222
223 Bstr Provider;
224 cloudNetwork->COMGETTER(Provider)(Provider.asOutParam());
225 RTPrintf("CloudProvider: %ls\n", Provider.raw());
226 Bstr Profile;
227 cloudNetwork->COMGETTER(Profile)(Profile.asOutParam());
228 RTPrintf("CloudProfile: %ls\n", Profile.raw());
229 Bstr NetworkId;
230 cloudNetwork->COMGETTER(NetworkId)(NetworkId.asOutParam());
231 RTPrintf("CloudNetworkId: %ls\n", NetworkId.raw());
232 Bstr netName = BstrFmt("cloud-%ls", networkName.raw());
233 RTPrintf("VBoxNetworkName: %ls\n\n", netName.raw());
234 }
235 return rc;
236}
237#endif /* VBOX_WITH_CLOUD_NET */
238
239
240/**
241 * List host information.
242 *
243 * @returns See produceList.
244 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
245 */
246static HRESULT listHostInfo(const ComPtr<IVirtualBox> pVirtualBox)
247{
248 static struct
249 {
250 ProcessorFeature_T feature;
251 const char *pszName;
252 } features[]
253 =
254 {
255 { ProcessorFeature_HWVirtEx, "HW virtualization" },
256 { ProcessorFeature_PAE, "PAE" },
257 { ProcessorFeature_LongMode, "long mode" },
258 { ProcessorFeature_NestedPaging, "nested paging" },
259 { ProcessorFeature_UnrestrictedGuest, "unrestricted guest" },
260 { ProcessorFeature_NestedHWVirt, "nested HW virtualization" },
261 { ProcessorFeature_VirtVmsaveVmload, "virt. vmsave/vmload" },
262 };
263 HRESULT rc;
264 ComPtr<IHost> Host;
265 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
266
267 RTPrintf("Host Information:\n\n");
268
269 LONG64 u64UtcTime = 0;
270 CHECK_ERROR(Host, COMGETTER(UTCTime)(&u64UtcTime));
271 RTTIMESPEC timeSpec;
272 char szTime[32];
273 RTPrintf("Host time: %s\n", RTTimeSpecToString(RTTimeSpecSetMilli(&timeSpec, u64UtcTime), szTime, sizeof(szTime)));
274
275 ULONG processorOnlineCount = 0;
276 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
277 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
278 ULONG processorCount = 0;
279 CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
280 RTPrintf("Processor count: %lu\n", processorCount);
281 ULONG processorOnlineCoreCount = 0;
282 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCoreCount)(&processorOnlineCoreCount));
283 RTPrintf("Processor online core count: %lu\n", processorOnlineCoreCount);
284 ULONG processorCoreCount = 0;
285 CHECK_ERROR(Host, COMGETTER(ProcessorCoreCount)(&processorCoreCount));
286 RTPrintf("Processor core count: %lu\n", processorCoreCount);
287 for (unsigned i = 0; i < RT_ELEMENTS(features); i++)
288 {
289 BOOL supported;
290 CHECK_ERROR(Host, GetProcessorFeature(features[i].feature, &supported));
291 RTPrintf("Processor supports %s: %s\n", features[i].pszName, supported ? "yes" : "no");
292 }
293 for (ULONG i = 0; i < processorCount; i++)
294 {
295 ULONG processorSpeed = 0;
296 CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
297 if (processorSpeed)
298 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
299 else
300 RTPrintf("Processor#%u speed: unknown\n", i);
301 Bstr processorDescription;
302 CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
303 RTPrintf("Processor#%u description: %ls\n", i, processorDescription.raw());
304 }
305
306 ULONG memorySize = 0;
307 CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
308 RTPrintf("Memory size: %lu MByte\n", memorySize);
309
310 ULONG memoryAvailable = 0;
311 CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
312 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
313
314 Bstr operatingSystem;
315 CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
316 RTPrintf("Operating system: %ls\n", operatingSystem.raw());
317
318 Bstr oSVersion;
319 CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
320 RTPrintf("Operating system version: %ls\n", oSVersion.raw());
321 return rc;
322}
323
324
325/**
326 * List media information.
327 *
328 * @returns See produceList.
329 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
330 * @param aMedia Medium objects to list information for.
331 * @param pszParentUUIDStr String with the parent UUID string (or "base").
332 * @param fOptLong Long (@c true) or short list format.
333 */
334static HRESULT listMedia(const ComPtr<IVirtualBox> pVirtualBox,
335 const com::SafeIfaceArray<IMedium> &aMedia,
336 const char *pszParentUUIDStr,
337 bool fOptLong)
338{
339 HRESULT rc = S_OK;
340 for (size_t i = 0; i < aMedia.size(); ++i)
341 {
342 ComPtr<IMedium> pMedium = aMedia[i];
343
344 rc = showMediumInfo(pVirtualBox, pMedium, pszParentUUIDStr, fOptLong);
345
346 RTPrintf("\n");
347
348 com::SafeIfaceArray<IMedium> children;
349 CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
350 if (children.size() > 0)
351 {
352 Bstr uuid;
353 pMedium->COMGETTER(Id)(uuid.asOutParam());
354
355 // depth first listing of child media
356 rc = listMedia(pVirtualBox, children, Utf8Str(uuid).c_str(), fOptLong);
357 }
358 }
359
360 return rc;
361}
362
363
364/**
365 * List virtual image backends.
366 *
367 * @returns See produceList.
368 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
369 */
370static HRESULT listHddBackends(const ComPtr<IVirtualBox> pVirtualBox)
371{
372 HRESULT rc;
373 ComPtr<ISystemProperties> systemProperties;
374 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
375 com::SafeIfaceArray<IMediumFormat> mediumFormats;
376 CHECK_ERROR(systemProperties, COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
377
378 RTPrintf("Supported hard disk backends:\n\n");
379 for (size_t i = 0; i < mediumFormats.size(); ++i)
380 {
381 /* General information */
382 Bstr id;
383 CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
384
385 Bstr description;
386 CHECK_ERROR(mediumFormats[i],
387 COMGETTER(Name)(description.asOutParam()));
388
389 ULONG caps = 0;
390 com::SafeArray <MediumFormatCapabilities_T> mediumFormatCap;
391 CHECK_ERROR(mediumFormats[i],
392 COMGETTER(Capabilities)(ComSafeArrayAsOutParam(mediumFormatCap)));
393 for (ULONG j = 0; j < mediumFormatCap.size(); j++)
394 caps |= mediumFormatCap[j];
395
396
397 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
398 i, id.raw(), description.raw(), caps);
399
400 /* File extensions */
401 com::SafeArray<BSTR> fileExtensions;
402 com::SafeArray<DeviceType_T> deviceTypes;
403 CHECK_ERROR(mediumFormats[i],
404 DescribeFileExtensions(ComSafeArrayAsOutParam(fileExtensions), ComSafeArrayAsOutParam(deviceTypes)));
405 for (size_t j = 0; j < fileExtensions.size(); ++j)
406 {
407 RTPrintf("%ls (%s)", Bstr(fileExtensions[j]).raw(), getDeviceTypeText(deviceTypes[j]));
408 if (j != fileExtensions.size()-1)
409 RTPrintf(",");
410 }
411 RTPrintf("'");
412
413 /* Configuration keys */
414 com::SafeArray<BSTR> propertyNames;
415 com::SafeArray<BSTR> propertyDescriptions;
416 com::SafeArray<DataType_T> propertyTypes;
417 com::SafeArray<ULONG> propertyFlags;
418 com::SafeArray<BSTR> propertyDefaults;
419 CHECK_ERROR(mediumFormats[i],
420 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
421 ComSafeArrayAsOutParam(propertyDescriptions),
422 ComSafeArrayAsOutParam(propertyTypes),
423 ComSafeArrayAsOutParam(propertyFlags),
424 ComSafeArrayAsOutParam(propertyDefaults)));
425
426 RTPrintf(" properties=(");
427 if (propertyNames.size() > 0)
428 {
429 for (size_t j = 0; j < propertyNames.size(); ++j)
430 {
431 RTPrintf("\n name='%ls' desc='%ls' type=",
432 Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
433 switch (propertyTypes[j])
434 {
435 case DataType_Int32: RTPrintf("int"); break;
436 case DataType_Int8: RTPrintf("byte"); break;
437 case DataType_String: RTPrintf("string"); break;
438#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
439 case DataType_32BitHack: break; /* Shut up compiler warnings. */
440#endif
441 }
442 RTPrintf(" flags=%#04x", propertyFlags[j]);
443 RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
444 if (j != propertyNames.size()-1)
445 RTPrintf(", ");
446 }
447 }
448 RTPrintf(")\n");
449 }
450 return rc;
451}
452
453
454/**
455 * List USB devices attached to the host.
456 *
457 * @returns See produceList.
458 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
459 */
460static HRESULT listUsbHost(const ComPtr<IVirtualBox> &pVirtualBox)
461{
462 HRESULT rc;
463 ComPtr<IHost> Host;
464 CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
465
466 SafeIfaceArray<IHostUSBDevice> CollPtr;
467 CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
468
469 RTPrintf("Host USB Devices:\n\n");
470
471 if (CollPtr.size() == 0)
472 {
473 RTPrintf("<none>\n\n");
474 }
475 else
476 {
477 for (size_t i = 0; i < CollPtr.size(); ++i)
478 {
479 ComPtr<IHostUSBDevice> dev = CollPtr[i];
480
481 /* Query info. */
482 Bstr id;
483 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
484 USHORT usVendorId;
485 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
486 USHORT usProductId;
487 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
488 USHORT bcdRevision;
489 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
490 USHORT usPort;
491 CHECK_ERROR_RET(dev, COMGETTER(Port)(&usPort), 1);
492 USHORT usVersion;
493 CHECK_ERROR_RET(dev, COMGETTER(Version)(&usVersion), 1);
494 USBConnectionSpeed_T enmSpeed;
495 CHECK_ERROR_RET(dev, COMGETTER(Speed)(&enmSpeed), 1);
496
497 RTPrintf("UUID: %s\n"
498 "VendorId: %#06x (%04X)\n"
499 "ProductId: %#06x (%04X)\n"
500 "Revision: %u.%u (%02u%02u)\n"
501 "Port: %u\n",
502 Utf8Str(id).c_str(),
503 usVendorId, usVendorId, usProductId, usProductId,
504 bcdRevision >> 8, bcdRevision & 0xff,
505 bcdRevision >> 8, bcdRevision & 0xff,
506 usPort);
507
508 const char *pszSpeed = "?";
509 switch (enmSpeed)
510 {
511 case USBConnectionSpeed_Low:
512 pszSpeed = "Low";
513 break;
514 case USBConnectionSpeed_Full:
515 pszSpeed = "Full";
516 break;
517 case USBConnectionSpeed_High:
518 pszSpeed = "High";
519 break;
520 case USBConnectionSpeed_Super:
521 pszSpeed = "Super";
522 break;
523 case USBConnectionSpeed_SuperPlus:
524 pszSpeed = "SuperPlus";
525 break;
526 default:
527 ASSERT(false);
528 break;
529 }
530
531 RTPrintf("USB version/speed: %u/%s\n", usVersion, pszSpeed);
532
533 /* optional stuff. */
534 SafeArray<BSTR> CollDevInfo;
535 Bstr bstr;
536 CHECK_ERROR_RET(dev, COMGETTER(DeviceInfo)(ComSafeArrayAsOutParam(CollDevInfo)), 1);
537 if (CollDevInfo.size() >= 1)
538 bstr = Bstr(CollDevInfo[0]);
539 if (!bstr.isEmpty())
540 RTPrintf("Manufacturer: %ls\n", bstr.raw());
541 if (CollDevInfo.size() >= 2)
542 bstr = Bstr(CollDevInfo[1]);
543 if (!bstr.isEmpty())
544 RTPrintf("Product: %ls\n", bstr.raw());
545 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
546 if (!bstr.isEmpty())
547 RTPrintf("SerialNumber: %ls\n", bstr.raw());
548 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
549 if (!bstr.isEmpty())
550 RTPrintf("Address: %ls\n", bstr.raw());
551 CHECK_ERROR_RET(dev, COMGETTER(PortPath)(bstr.asOutParam()), 1);
552 if (!bstr.isEmpty())
553 RTPrintf("Port path: %ls\n", bstr.raw());
554
555 /* current state */
556 USBDeviceState_T state;
557 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
558 const char *pszState = "?";
559 switch (state)
560 {
561 case USBDeviceState_NotSupported:
562 pszState = "Not supported";
563 break;
564 case USBDeviceState_Unavailable:
565 pszState = "Unavailable";
566 break;
567 case USBDeviceState_Busy:
568 pszState = "Busy";
569 break;
570 case USBDeviceState_Available:
571 pszState = "Available";
572 break;
573 case USBDeviceState_Held:
574 pszState = "Held";
575 break;
576 case USBDeviceState_Captured:
577 pszState = "Captured";
578 break;
579 default:
580 ASSERT(false);
581 break;
582 }
583 RTPrintf("Current State: %s\n\n", pszState);
584 }
585 }
586 return rc;
587}
588
589
590/**
591 * List USB filters.
592 *
593 * @returns See produceList.
594 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
595 */
596static HRESULT listUsbFilters(const ComPtr<IVirtualBox> &pVirtualBox)
597{
598 HRESULT rc;
599
600 RTPrintf("Global USB Device Filters:\n\n");
601
602 ComPtr<IHost> host;
603 CHECK_ERROR_RET(pVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
604
605 SafeIfaceArray<IHostUSBDeviceFilter> coll;
606 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
607
608 if (coll.size() == 0)
609 {
610 RTPrintf("<none>\n\n");
611 }
612 else
613 {
614 for (size_t index = 0; index < coll.size(); ++index)
615 {
616 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
617
618 /* Query info. */
619
620 RTPrintf("Index: %zu\n", index);
621
622 BOOL active = FALSE;
623 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
624 RTPrintf("Active: %s\n", active ? "yes" : "no");
625
626 USBDeviceFilterAction_T action;
627 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
628 const char *pszAction = "<invalid>";
629 switch (action)
630 {
631 case USBDeviceFilterAction_Ignore:
632 pszAction = "Ignore";
633 break;
634 case USBDeviceFilterAction_Hold:
635 pszAction = "Hold";
636 break;
637 default:
638 break;
639 }
640 RTPrintf("Action: %s\n", pszAction);
641
642 Bstr bstr;
643 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
644 RTPrintf("Name: %ls\n", bstr.raw());
645 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
646 RTPrintf("VendorId: %ls\n", bstr.raw());
647 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
648 RTPrintf("ProductId: %ls\n", bstr.raw());
649 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
650 RTPrintf("Revision: %ls\n", bstr.raw());
651 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
652 RTPrintf("Manufacturer: %ls\n", bstr.raw());
653 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
654 RTPrintf("Product: %ls\n", bstr.raw());
655 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
656 RTPrintf("Serial Number: %ls\n\n", bstr.raw());
657 }
658 }
659 return rc;
660}
661
662
663/**
664 * List system properties.
665 *
666 * @returns See produceList.
667 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
668 */
669static HRESULT listSystemProperties(const ComPtr<IVirtualBox> &pVirtualBox)
670{
671 ComPtr<ISystemProperties> systemProperties;
672 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()), hrcCheck);
673
674 Bstr str;
675 ULONG ulValue;
676 LONG64 i64Value;
677 BOOL fValue;
678 const char *psz;
679
680 pVirtualBox->COMGETTER(APIVersion)(str.asOutParam());
681 RTPrintf("API version: %ls\n", str.raw());
682
683 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
684 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
685 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
686 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
687 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
688 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
689 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
690 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
691 systemProperties->COMGETTER(MaxGuestMonitors)(&ulValue);
692 RTPrintf("Maximum guest monitor count: %u\n", ulValue);
693 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
694 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
695 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
696 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
697 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
698 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
699 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
700 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
701 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
702 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
703 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
704 RTPrintf("Maximum Boot Position: %u\n", ulValue);
705 systemProperties->GetMaxNetworkAdapters(ChipsetType_PIIX3, &ulValue);
706 RTPrintf("Maximum PIIX3 Network Adapter count: %u\n", ulValue);
707 systemProperties->GetMaxNetworkAdapters(ChipsetType_ICH9, &ulValue);
708 RTPrintf("Maximum ICH9 Network Adapter count: %u\n", ulValue);
709 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
710 RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
711 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
712 RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
713 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
714 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
715 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
716 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
717 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
718 RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
719 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
720 RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
721 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
722 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
723 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
724 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
725 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
726 RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
727 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
728 RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
729 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
730 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
731 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
732 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
733 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
734 RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
735 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
736 RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
737 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
738 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
739 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
740 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
741 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_PCIe, &ulValue);
742 RTPrintf("Maximum NVMe PIIX3 Controllers: %u\n", ulValue);
743 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_PCIe, &ulValue);
744 RTPrintf("Maximum NVMe ICH9 Controllers: %u\n", ulValue);
745 systemProperties->GetMaxPortCountForStorageBus(StorageBus_PCIe, &ulValue);
746 RTPrintf("Maximum NVMe Port count: %u\n", ulValue);
747 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_PCIe, &ulValue);
748 RTPrintf("Maximum Devices per NVMe Port: %u\n", ulValue);
749 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_VirtioSCSI, &ulValue);
750 RTPrintf("Maximum virtio-scsi PIIX3 Controllers: %u\n", ulValue);
751 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_VirtioSCSI, &ulValue);
752 RTPrintf("Maximum virtio-scsi ICH9 Controllers: %u\n", ulValue);
753 systemProperties->GetMaxPortCountForStorageBus(StorageBus_VirtioSCSI, &ulValue);
754 RTPrintf("Maximum virtio-scsi Port count: %u\n", ulValue);
755 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_VirtioSCSI, &ulValue);
756 RTPrintf("Maximum Devices per virtio-scsi Port: %u\n", ulValue);
757 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
758 RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
759 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
760 RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
761 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
762 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
763 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
764 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
765#if 0
766 systemProperties->GetFreeDiskSpaceWarning(&i64Value);
767 RTPrintf("Free disk space warning at: %u Bytes\n", i64Value);
768 systemProperties->GetFreeDiskSpacePercentWarning(&ulValue);
769 RTPrintf("Free disk space warning at: %u %%\n", ulValue);
770 systemProperties->GetFreeDiskSpaceError(&i64Value);
771 RTPrintf("Free disk space error at: %u Bytes\n", i64Value);
772 systemProperties->GetFreeDiskSpacePercentError(&ulValue);
773 RTPrintf("Free disk space error at: %u %%\n", ulValue);
774#endif
775 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
776 RTPrintf("Default machine folder: %ls\n", str.raw());
777 systemProperties->COMGETTER(RawModeSupported)(&fValue);
778 RTPrintf("Raw-mode Supported: %s\n", fValue ? "yes" : "no");
779 systemProperties->COMGETTER(ExclusiveHwVirt)(&fValue);
780 RTPrintf("Exclusive HW virtualization use: %s\n", fValue ? "on" : "off");
781 systemProperties->COMGETTER(DefaultHardDiskFormat)(str.asOutParam());
782 RTPrintf("Default hard disk format: %ls\n", str.raw());
783 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
784 RTPrintf("VRDE auth library: %ls\n", str.raw());
785 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
786 RTPrintf("Webservice auth. library: %ls\n", str.raw());
787 systemProperties->COMGETTER(DefaultVRDEExtPack)(str.asOutParam());
788 RTPrintf("Remote desktop ExtPack: %ls\n", str.raw());
789 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
790 RTPrintf("Log history count: %u\n", ulValue);
791 systemProperties->COMGETTER(DefaultFrontend)(str.asOutParam());
792 RTPrintf("Default frontend: %ls\n", str.raw());
793 AudioDriverType_T enmAudio;
794 systemProperties->COMGETTER(DefaultAudioDriver)(&enmAudio);
795 switch (enmAudio)
796 {
797 case AudioDriverType_Null: psz = "Null"; break;
798 case AudioDriverType_WinMM: psz = "WinMM"; break;
799 case AudioDriverType_OSS: psz = "OSS"; break;
800 case AudioDriverType_ALSA: psz = "ALSA"; break;
801 case AudioDriverType_DirectSound: psz = "DirectSound"; break;
802 case AudioDriverType_CoreAudio: psz = "CoreAudio"; break;
803 case AudioDriverType_MMPM: psz = "MMPM"; break;
804 case AudioDriverType_Pulse: psz = "Pulse"; break;
805 case AudioDriverType_SolAudio: psz = "SolAudio"; break;
806 default: psz = "Unknown";
807 }
808 RTPrintf("Default audio driver: %s\n", psz);
809 systemProperties->COMGETTER(AutostartDatabasePath)(str.asOutParam());
810 RTPrintf("Autostart database path: %ls\n", str.raw());
811 systemProperties->COMGETTER(DefaultAdditionsISO)(str.asOutParam());
812 RTPrintf("Default Guest Additions ISO: %ls\n", str.raw());
813 systemProperties->COMGETTER(LoggingLevel)(str.asOutParam());
814 RTPrintf("Logging Level: %ls\n", str.raw());
815 ProxyMode_T enmProxyMode = (ProxyMode_T)42;
816 systemProperties->COMGETTER(ProxyMode)(&enmProxyMode);
817 psz = "Unknown";
818 switch (enmProxyMode)
819 {
820 case ProxyMode_System: psz = "System"; break;
821 case ProxyMode_NoProxy: psz = "NoProxy"; break;
822 case ProxyMode_Manual: psz = "Manual"; break;
823#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
824 case ProxyMode_32BitHack: break; /* Shut up compiler warnings. */
825#endif
826 }
827 RTPrintf("Proxy Mode: %s\n", psz);
828 systemProperties->COMGETTER(ProxyURL)(str.asOutParam());
829 RTPrintf("Proxy URL: %ls\n", str.raw());
830 systemProperties->COMGETTER(VBoxUpdateEnabled)(&fValue);
831 RTPrintf("Update check enabled: %s\n", fValue ? "yes" : "no");
832 systemProperties->COMGETTER(VBoxUpdateCount)(&ulValue);
833 RTPrintf("Update check count: %u\n", ulValue);
834 systemProperties->COMGETTER(VBoxUpdateFrequency)(&ulValue);
835 if (ulValue == 0)
836 RTPrintf("Update check frequency: never\n");
837 else if (ulValue == 1)
838 RTPrintf("Update check frequency: every day\n");
839 else
840 RTPrintf("Update check frequency: every %u days\n", ulValue);
841 VBoxUpdateTarget_T enmVBoxUpdateTarget;
842 systemProperties->COMGETTER(VBoxUpdateTarget)(&enmVBoxUpdateTarget);
843 switch (enmVBoxUpdateTarget)
844 {
845 case VBoxUpdateTarget_Stable:
846 psz = "Stable: new minor and maintenance releases";
847 break;
848 case VBoxUpdateTarget_AllReleases:
849 psz = "All releases: new minor, maintenance, and major releases";
850 break;
851 case VBoxUpdateTarget_WithBetas:
852 psz = "With Betas: new minor, maintenance, major, and beta releases";
853 break;
854 default:
855 psz = "Unset";
856 break;
857 }
858 RTPrintf("Update check target: %s\n", psz);
859 systemProperties->COMGETTER(VBoxUpdateLastCheckDate)(str.asOutParam());
860 RTPrintf("Last check date: %ls\n", str.raw());
861
862 return S_OK;
863}
864
865
866/**
867 * Helper for listDhcpServers() that shows a DHCP configuration.
868 */
869static HRESULT showDhcpConfig(ComPtr<IDHCPConfig> ptrConfig)
870{
871 HRESULT hrcRet = S_OK;
872
873 ULONG secs = 0;
874 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MinLeaseTime)(&secs), hrcRet = hrcCheck);
875 if (secs == 0)
876 RTPrintf(" minLeaseTime: default\n");
877 else
878 RTPrintf(" minLeaseTime: %u sec\n", secs);
879
880 secs = 0;
881 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(DefaultLeaseTime)(&secs), hrcRet = hrcCheck);
882 if (secs == 0)
883 RTPrintf(" defaultLeaseTime: default\n");
884 else
885 RTPrintf(" defaultLeaseTime: %u sec\n", secs);
886
887 secs = 0;
888 CHECK_ERROR2I_STMT(ptrConfig, COMGETTER(MaxLeaseTime)(&secs), hrcRet = hrcCheck);
889 if (secs == 0)
890 RTPrintf(" maxLeaseTime: default\n");
891 else
892 RTPrintf(" maxLeaseTime: %u sec\n", secs);
893
894 com::SafeArray<DHCPOption_T> Options;
895 HRESULT hrc;
896 CHECK_ERROR2_STMT(hrc, ptrConfig, COMGETTER(ForcedOptions(ComSafeArrayAsOutParam(Options))), hrcRet = hrc);
897 if (FAILED(hrc))
898 RTPrintf(" Forced options: %Rhrc\n", hrc);
899 else if (Options.size() == 0)
900 RTPrintf(" Forced options: None\n");
901 else
902 {
903 RTPrintf(" Forced options: ");
904 for (size_t i = 0; i < Options.size(); i++)
905 RTPrintf(i ? ", %u" : "%u", Options[i]);
906 RTPrintf("\n");
907 }
908
909 CHECK_ERROR2_STMT(hrc, ptrConfig, COMGETTER(SuppressedOptions(ComSafeArrayAsOutParam(Options))), hrcRet = hrc);
910 if (FAILED(hrc))
911 RTPrintf(" Suppressed opt.s: %Rhrc\n", hrc);
912 else if (Options.size() == 0)
913 RTPrintf(" Suppressed opts.: None\n");
914 else
915 {
916 RTPrintf(" Suppressed opts.: ");
917 for (size_t i = 0; i < Options.size(); i++)
918 RTPrintf(i ? ", %u" : "%u", Options[i]);
919 RTPrintf("\n");
920 }
921
922 com::SafeArray<DHCPOptionEncoding_T> Encodings;
923 com::SafeArray<BSTR> Values;
924 CHECK_ERROR2_STMT(hrc, ptrConfig, GetAllOptions(ComSafeArrayAsOutParam(Options),
925 ComSafeArrayAsOutParam(Encodings),
926 ComSafeArrayAsOutParam(Values)), hrcRet = hrc);
927 if (FAILED(hrc))
928 RTPrintf(" DHCP options: %Rhrc\n", hrc);
929 else if (Options.size() != Encodings.size() || Options.size() != Values.size())
930 {
931 RTPrintf(" DHCP options: Return count mismatch: %zu, %zu, %zu\n", Options.size(), Encodings.size(), Values.size());
932 hrcRet = E_FAIL;
933 }
934 else if (Options.size() == 0)
935 RTPrintf(" DHCP options: None\n");
936 else
937 for (size_t i = 0; i < Options.size(); i++)
938 {
939 switch (Encodings[i])
940 {
941 case DHCPOptionEncoding_Normal:
942 RTPrintf(" %3d/legacy: %ls\n", Options[i], Values[i]);
943 break;
944 case DHCPOptionEncoding_Hex:
945 RTPrintf(" %3d/hex: %ls\n", Options[i], Values[i]);
946 break;
947 default:
948 RTPrintf(" %3d/%u?: %ls\n", Options[i], Encodings[i], Values[i]);
949 break;
950 }
951 }
952
953 return S_OK;
954}
955
956
957/**
958 * List DHCP servers.
959 *
960 * @returns See produceList.
961 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
962 */
963static HRESULT listDhcpServers(const ComPtr<IVirtualBox> &pVirtualBox)
964{
965 HRESULT hrcRet = S_OK;
966 com::SafeIfaceArray<IDHCPServer> DHCPServers;
967 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(DHCPServers)), hrcCheck);
968 for (size_t i = 0; i < DHCPServers.size(); ++i)
969 {
970 if (i > 0)
971 RTPrintf("\n");
972
973 ComPtr<IDHCPServer> ptrDHCPServer = DHCPServers[i];
974 Bstr bstr;
975 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(NetworkName)(bstr.asOutParam()), hrcRet = hrcCheck);
976 RTPrintf("NetworkName: %ls\n", bstr.raw());
977
978 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(IPAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
979 RTPrintf("Dhcpd IP: %ls\n", bstr.raw());
980
981 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(LowerIP)(bstr.asOutParam()), hrcRet = hrcCheck);
982 RTPrintf("LowerIPAddress: %ls\n", bstr.raw());
983
984 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(UpperIP)(bstr.asOutParam()), hrcRet = hrcCheck);
985 RTPrintf("UpperIPAddress: %ls\n", bstr.raw());
986
987 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(NetworkMask)(bstr.asOutParam()), hrcRet = hrcCheck);
988 RTPrintf("NetworkMask: %ls\n", bstr.raw());
989
990 BOOL fEnabled = FALSE;
991 CHECK_ERROR2I_STMT(ptrDHCPServer, COMGETTER(Enabled)(&fEnabled), hrcRet = hrcCheck);
992 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
993
994 /* Global configuration: */
995 RTPrintf("Global Configuration:\n");
996 HRESULT hrc;
997 ComPtr<IDHCPGlobalConfig> ptrGlobal;
998 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(GlobalConfig)(ptrGlobal.asOutParam()), hrcRet = hrc);
999 if (SUCCEEDED(hrc))
1000 {
1001 hrc = showDhcpConfig(ptrGlobal);
1002 if (FAILED(hrc))
1003 hrcRet = hrc;
1004 }
1005
1006 /* Group configurations: */
1007 com::SafeIfaceArray<IDHCPGroupConfig> Groups;
1008 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(GroupConfigs)(ComSafeArrayAsOutParam(Groups)), hrcRet = hrc);
1009 if (FAILED(hrc))
1010 RTPrintf("Groups: %Rrc\n", hrc);
1011 else if (Groups.size() == 0)
1012 RTPrintf("Groups: None\n");
1013 else
1014 {
1015 for (size_t iGrp = 0; iGrp < Groups.size(); iGrp++)
1016 {
1017 CHECK_ERROR2I_STMT(Groups[iGrp], COMGETTER(Name)(bstr.asOutParam()), hrcRet = hrcCheck);
1018 RTPrintf("Group: %ls\n", bstr.raw());
1019
1020 com::SafeIfaceArray<IDHCPGroupCondition> Conditions;
1021 CHECK_ERROR2_STMT(hrc, Groups[iGrp], COMGETTER(Conditions)(ComSafeArrayAsOutParam(Conditions)), hrcRet = hrc);
1022 if (FAILED(hrc))
1023 RTPrintf(" Conditions: %Rhrc\n", hrc);
1024 else if (Conditions.size() == 0)
1025 RTPrintf(" Conditions: None\n");
1026 else
1027 for (size_t iCond = 0; iCond < Conditions.size(); iCond++)
1028 {
1029 BOOL fInclusive = TRUE;
1030 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Inclusive)(&fInclusive), hrcRet = hrc);
1031 DHCPGroupConditionType_T enmType = DHCPGroupConditionType_MAC;
1032 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Type)(&enmType), hrcRet = hrc);
1033 CHECK_ERROR2_STMT(hrc, Conditions[iCond], COMGETTER(Value)(bstr.asOutParam()), hrcRet = hrc);
1034
1035 RTPrintf(" Conditions: %s %s %ls\n",
1036 fInclusive ? "include" : "exclude",
1037 enmType == DHCPGroupConditionType_MAC ? "MAC "
1038 : enmType == DHCPGroupConditionType_MACWildcard ? "MAC* "
1039 : enmType == DHCPGroupConditionType_vendorClassID ? "VendorCID "
1040 : enmType == DHCPGroupConditionType_vendorClassIDWildcard ? "VendorCID*"
1041 : enmType == DHCPGroupConditionType_userClassID ? "UserCID "
1042 : enmType == DHCPGroupConditionType_userClassIDWildcard ? "UserCID* "
1043 : "!UNKNOWN! ",
1044 bstr.raw());
1045 }
1046
1047 hrc = showDhcpConfig(Groups[iGrp]);
1048 if (FAILED(hrc))
1049 hrcRet = hrc;
1050 }
1051 Groups.setNull();
1052 }
1053
1054 /* Individual host / NIC configurations: */
1055 com::SafeIfaceArray<IDHCPIndividualConfig> Hosts;
1056 CHECK_ERROR2_STMT(hrc, ptrDHCPServer, COMGETTER(IndividualConfigs)(ComSafeArrayAsOutParam(Hosts)), hrcRet = hrc);
1057 if (FAILED(hrc))
1058 RTPrintf("Individual Configs: %Rrc\n", hrc);
1059 else if (Hosts.size() == 0)
1060 RTPrintf("Individual Configs: None\n");
1061 else
1062 {
1063 for (size_t iHost = 0; iHost < Hosts.size(); iHost++)
1064 {
1065 DHCPConfigScope_T enmScope = DHCPConfigScope_MAC;
1066 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(Scope)(&enmScope), hrcRet = hrcCheck);
1067
1068 if (enmScope == DHCPConfigScope_MAC)
1069 {
1070 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(MACAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
1071 RTPrintf("Individual Config: MAC %ls\n", bstr.raw());
1072 }
1073 else
1074 {
1075 ULONG uSlot = 0;
1076 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(Slot)(&uSlot), hrcRet = hrcCheck);
1077 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(MachineId)(bstr.asOutParam()), hrcRet = hrcCheck);
1078 Bstr bstrMACAddress;
1079 hrc = Hosts[iHost]->COMGETTER(MACAddress)(bstrMACAddress.asOutParam()); /* No CHECK_ERROR2 stuff! */
1080 if (SUCCEEDED(hrc))
1081 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %ls\n", bstr.raw(), uSlot, bstrMACAddress.raw());
1082 else
1083 RTPrintf("Individual Config: VM NIC: %ls slot %u, MAC %Rhrc\n", bstr.raw(), uSlot, hrc);
1084 }
1085
1086 CHECK_ERROR2I_STMT(Hosts[iHost], COMGETTER(FixedAddress)(bstr.asOutParam()), hrcRet = hrcCheck);
1087 if (bstr.isNotEmpty())
1088 RTPrintf(" Fixed Address: %ls\n", bstr.raw());
1089 else
1090 RTPrintf(" Fixed Address: dynamic\n");
1091
1092 hrc = showDhcpConfig(Hosts[iHost]);
1093 if (FAILED(hrc))
1094 hrcRet = hrc;
1095 }
1096 Hosts.setNull();
1097 }
1098 }
1099
1100 return hrcRet;
1101}
1102
1103/**
1104 * List extension packs.
1105 *
1106 * @returns See produceList.
1107 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1108 */
1109static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &pVirtualBox)
1110{
1111 ComObjPtr<IExtPackManager> ptrExtPackMgr;
1112 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
1113
1114 SafeIfaceArray<IExtPack> extPacks;
1115 CHECK_ERROR2I_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
1116 RTPrintf("Extension Packs: %u\n", extPacks.size());
1117
1118 HRESULT hrc = S_OK;
1119 for (size_t i = 0; i < extPacks.size(); i++)
1120 {
1121 /* Read all the properties. */
1122 Bstr bstrName;
1123 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
1124 Bstr bstrDesc;
1125 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
1126 Bstr bstrVersion;
1127 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
1128 ULONG uRevision;
1129 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
1130 Bstr bstrEdition;
1131 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Edition)(bstrEdition.asOutParam()), hrc = hrcCheck; bstrEdition.setNull());
1132 Bstr bstrVrdeModule;
1133 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(VRDEModule)(bstrVrdeModule.asOutParam()),hrc=hrcCheck; bstrVrdeModule.setNull());
1134 BOOL fUsable;
1135 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
1136 Bstr bstrWhy;
1137 CHECK_ERROR2I_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
1138
1139 /* Display them. */
1140 if (i)
1141 RTPrintf("\n");
1142 RTPrintf("Pack no.%2zu: %ls\n"
1143 "Version: %ls\n"
1144 "Revision: %u\n"
1145 "Edition: %ls\n"
1146 "Description: %ls\n"
1147 "VRDE Module: %ls\n"
1148 "Usable: %RTbool\n"
1149 "Why unusable: %ls\n",
1150 i, bstrName.raw(),
1151 bstrVersion.raw(),
1152 uRevision,
1153 bstrEdition.raw(),
1154 bstrDesc.raw(),
1155 bstrVrdeModule.raw(),
1156 fUsable != FALSE,
1157 bstrWhy.raw());
1158
1159 /* Query plugins and display them. */
1160 }
1161 return hrc;
1162}
1163
1164
1165/**
1166 * List machine groups.
1167 *
1168 * @returns See produceList.
1169 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1170 */
1171static HRESULT listGroups(const ComPtr<IVirtualBox> &pVirtualBox)
1172{
1173 SafeArray<BSTR> groups;
1174 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(MachineGroups)(ComSafeArrayAsOutParam(groups)), hrcCheck);
1175
1176 for (size_t i = 0; i < groups.size(); i++)
1177 {
1178 RTPrintf("\"%ls\"\n", groups[i]);
1179 }
1180 return S_OK;
1181}
1182
1183
1184/**
1185 * List video capture devices.
1186 *
1187 * @returns See produceList.
1188 * @param pVirtualBox Reference to the IVirtualBox pointer.
1189 */
1190static HRESULT listVideoInputDevices(const ComPtr<IVirtualBox> &pVirtualBox)
1191{
1192 HRESULT rc;
1193 ComPtr<IHost> host;
1194 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1195 com::SafeIfaceArray<IHostVideoInputDevice> hostVideoInputDevices;
1196 CHECK_ERROR(host, COMGETTER(VideoInputDevices)(ComSafeArrayAsOutParam(hostVideoInputDevices)));
1197 RTPrintf("Video Input Devices: %u\n", hostVideoInputDevices.size());
1198 for (size_t i = 0; i < hostVideoInputDevices.size(); ++i)
1199 {
1200 ComPtr<IHostVideoInputDevice> p = hostVideoInputDevices[i];
1201 Bstr name;
1202 p->COMGETTER(Name)(name.asOutParam());
1203 Bstr path;
1204 p->COMGETTER(Path)(path.asOutParam());
1205 Bstr alias;
1206 p->COMGETTER(Alias)(alias.asOutParam());
1207 RTPrintf("%ls \"%ls\"\n%ls\n", alias.raw(), name.raw(), path.raw());
1208 }
1209 return rc;
1210}
1211
1212/**
1213 * List supported screen shot formats.
1214 *
1215 * @returns See produceList.
1216 * @param pVirtualBox Reference to the IVirtualBox pointer.
1217 */
1218static HRESULT listScreenShotFormats(const ComPtr<IVirtualBox> &pVirtualBox)
1219{
1220 HRESULT rc = S_OK;
1221 ComPtr<ISystemProperties> systemProperties;
1222 CHECK_ERROR(pVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
1223 com::SafeArray<BitmapFormat_T> formats;
1224 CHECK_ERROR(systemProperties, COMGETTER(ScreenShotFormats)(ComSafeArrayAsOutParam(formats)));
1225
1226 RTPrintf("Supported %d screen shot formats:\n", formats.size());
1227 for (size_t i = 0; i < formats.size(); ++i)
1228 {
1229 uint32_t u32Format = (uint32_t)formats[i];
1230 char szFormat[5];
1231 szFormat[0] = RT_BYTE1(u32Format);
1232 szFormat[1] = RT_BYTE2(u32Format);
1233 szFormat[2] = RT_BYTE3(u32Format);
1234 szFormat[3] = RT_BYTE4(u32Format);
1235 szFormat[4] = 0;
1236 RTPrintf(" BitmapFormat_%s (0x%08X)\n", szFormat, u32Format);
1237 }
1238 return rc;
1239}
1240
1241/**
1242 * List available cloud providers.
1243 *
1244 * @returns See produceList.
1245 * @param pVirtualBox Reference to the IVirtualBox pointer.
1246 */
1247static HRESULT listCloudProviders(const ComPtr<IVirtualBox> &pVirtualBox)
1248{
1249 HRESULT rc = S_OK;
1250 ComPtr<ICloudProviderManager> pCloudProviderManager;
1251 CHECK_ERROR(pVirtualBox, COMGETTER(CloudProviderManager)(pCloudProviderManager.asOutParam()));
1252 com::SafeIfaceArray<ICloudProvider> apCloudProviders;
1253 CHECK_ERROR(pCloudProviderManager, COMGETTER(Providers)(ComSafeArrayAsOutParam(apCloudProviders)));
1254
1255 RTPrintf("Supported %d cloud providers:\n", apCloudProviders.size());
1256 for (size_t i = 0; i < apCloudProviders.size(); ++i)
1257 {
1258 ComPtr<ICloudProvider> pCloudProvider = apCloudProviders[i];
1259 Bstr bstrProviderName;
1260 pCloudProvider->COMGETTER(Name)(bstrProviderName.asOutParam());
1261 RTPrintf("Name: %ls\n", bstrProviderName.raw());
1262 pCloudProvider->COMGETTER(ShortName)(bstrProviderName.asOutParam());
1263 RTPrintf("Short Name: %ls\n", bstrProviderName.raw());
1264 Bstr bstrProviderID;
1265 pCloudProvider->COMGETTER(Id)(bstrProviderID.asOutParam());
1266 RTPrintf("GUID: %ls\n", bstrProviderID.raw());
1267
1268 RTPrintf("\n");
1269 }
1270 return rc;
1271}
1272
1273
1274/**
1275 * List all available cloud profiles (by iterating over the cloud providers).
1276 *
1277 * @returns See produceList.
1278 * @param pVirtualBox Reference to the IVirtualBox pointer.
1279 * @param fOptLong If true, list all profile properties.
1280 */
1281static HRESULT listCloudProfiles(const ComPtr<IVirtualBox> &pVirtualBox, bool fOptLong)
1282{
1283 HRESULT rc = S_OK;
1284 ComPtr<ICloudProviderManager> pCloudProviderManager;
1285 CHECK_ERROR(pVirtualBox, COMGETTER(CloudProviderManager)(pCloudProviderManager.asOutParam()));
1286 com::SafeIfaceArray<ICloudProvider> apCloudProviders;
1287 CHECK_ERROR(pCloudProviderManager, COMGETTER(Providers)(ComSafeArrayAsOutParam(apCloudProviders)));
1288
1289 for (size_t i = 0; i < apCloudProviders.size(); ++i)
1290 {
1291 ComPtr<ICloudProvider> pCloudProvider = apCloudProviders[i];
1292 com::SafeIfaceArray<ICloudProfile> apCloudProfiles;
1293 CHECK_ERROR(pCloudProvider, COMGETTER(Profiles)(ComSafeArrayAsOutParam(apCloudProfiles)));
1294 for (size_t j = 0; j < apCloudProfiles.size(); ++j)
1295 {
1296 ComPtr<ICloudProfile> pCloudProfile = apCloudProfiles[j];
1297 Bstr bstrProfileName;
1298 pCloudProfile->COMGETTER(Name)(bstrProfileName.asOutParam());
1299 RTPrintf("Name: %ls\n", bstrProfileName.raw());
1300 Bstr bstrProviderID;
1301 pCloudProfile->COMGETTER(ProviderId)(bstrProviderID.asOutParam());
1302 RTPrintf("Provider GUID: %ls\n", bstrProviderID.raw());
1303
1304 if (fOptLong)
1305 {
1306 com::SafeArray<BSTR> names;
1307 com::SafeArray<BSTR> values;
1308 pCloudProfile->GetProperties(Bstr().raw(), ComSafeArrayAsOutParam(names), ComSafeArrayAsOutParam(values));
1309 size_t cNames = names.size();
1310 size_t cValues = values.size();
1311 bool fFirst = true;
1312 for (size_t k = 0; k < cNames; k++)
1313 {
1314 Bstr value;
1315 if (k < cValues)
1316 value = values[k];
1317 RTPrintf("%s%ls=%ls\n",
1318 fFirst ? "Property: " : " ",
1319 names[k], value.raw());
1320 fFirst = false;
1321 }
1322 }
1323
1324 RTPrintf("\n");
1325 }
1326 }
1327 return rc;
1328}
1329
1330static HRESULT displayCPUProfile(ICPUProfile *pProfile, size_t idx, int cchIdx, bool fOptLong, HRESULT hrc)
1331{
1332 /* Retrieve the attributes needed for both long and short display. */
1333 Bstr bstrName;
1334 CHECK_ERROR2I_RET(pProfile, COMGETTER(Name)(bstrName.asOutParam()), hrcCheck);
1335
1336 CPUArchitecture_T enmArchitecture = CPUArchitecture_Any;
1337 CHECK_ERROR2I_RET(pProfile, COMGETTER(Architecture)(&enmArchitecture), hrcCheck);
1338 const char *pszArchitecture = "???";
1339 switch (enmArchitecture)
1340 {
1341 case CPUArchitecture_x86: pszArchitecture = "x86"; break;
1342 case CPUArchitecture_AMD64: pszArchitecture = "AMD64"; break;
1343
1344#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
1345 case CPUArchitecture_32BitHack:
1346#endif
1347 case CPUArchitecture_Any:
1348 break;
1349 }
1350
1351 /* Print what we've got. */
1352 if (!fOptLong)
1353 RTPrintf("#%0*zu: %ls [%s]\n", cchIdx, idx, bstrName.raw(), pszArchitecture);
1354 else
1355 {
1356 RTPrintf("CPU Profile #%02zu:\n", idx);
1357 RTPrintf(" Architecture: %s\n", pszArchitecture);
1358 RTPrintf(" Name: %ls\n", bstrName.raw());
1359 CHECK_ERROR2I_RET(pProfile, COMGETTER(FullName)(bstrName.asOutParam()), hrcCheck);
1360 RTPrintf(" Full Name: %ls\n", bstrName.raw());
1361 }
1362 return hrc;
1363}
1364
1365
1366/**
1367 * List all CPU profiles.
1368 *
1369 * @returns See produceList.
1370 * @param ptrVirtualBox Reference to the smart IVirtualBox pointer.
1371 * @param fOptLong If true, list all profile properties.
1372 * @param fOptSorted Sort the output if true, otherwise display in
1373 * system order.
1374 */
1375static HRESULT listCPUProfiles(const ComPtr<IVirtualBox> &ptrVirtualBox, bool fOptLong, bool fOptSorted)
1376{
1377 ComPtr<ISystemProperties> ptrSysProps;
1378 CHECK_ERROR2I_RET(ptrVirtualBox, COMGETTER(SystemProperties)(ptrSysProps.asOutParam()), hrcCheck);
1379 com::SafeIfaceArray<ICPUProfile> aCPUProfiles;
1380 CHECK_ERROR2I_RET(ptrSysProps, GetCPUProfiles(CPUArchitecture_Any, Bstr().raw(),
1381 ComSafeArrayAsOutParam(aCPUProfiles)), hrcCheck);
1382
1383 int const cchIdx = 1 + (aCPUProfiles.size() >= 10) + (aCPUProfiles.size() >= 100);
1384
1385 HRESULT hrc = S_OK;
1386 if (!fOptSorted)
1387 for (size_t i = 0; i < aCPUProfiles.size(); i++)
1388 hrc = displayCPUProfile(aCPUProfiles[i], i, cchIdx, fOptLong, hrc);
1389 else
1390 {
1391 std::vector<std::pair<com::Bstr, ICPUProfile *> > vecSortedProfiles;
1392 for (size_t i = 0; i < aCPUProfiles.size(); ++i)
1393 {
1394 Bstr bstrName;
1395 CHECK_ERROR2I_RET(aCPUProfiles[i], COMGETTER(Name)(bstrName.asOutParam()), hrcCheck);
1396 try
1397 {
1398 vecSortedProfiles.push_back(std::pair<com::Bstr, ICPUProfile *>(bstrName, aCPUProfiles[i]));
1399 }
1400 catch (std::bad_alloc &)
1401 {
1402 return E_OUTOFMEMORY;
1403 }
1404 }
1405
1406 std::sort(vecSortedProfiles.begin(), vecSortedProfiles.end());
1407
1408 for (size_t i = 0; i < vecSortedProfiles.size(); i++)
1409 hrc = displayCPUProfile(vecSortedProfiles[i].second, i, cchIdx, fOptLong, hrc);
1410 }
1411
1412 return hrc;
1413}
1414
1415
1416/**
1417 * Translates PartitionType_T to a string if possible.
1418 * @returns read-only string if known value, @a pszUnknown if not.
1419 */
1420static const char *PartitionTypeToString(PartitionType_T enmType, const char *pszUnknown)
1421{
1422#define MY_CASE_STR(a_Type) case RT_CONCAT(PartitionType_,a_Type): return #a_Type
1423 switch (enmType)
1424 {
1425 MY_CASE_STR(Empty);
1426 MY_CASE_STR(FAT12);
1427 MY_CASE_STR(FAT16);
1428 MY_CASE_STR(FAT);
1429 MY_CASE_STR(IFS);
1430 MY_CASE_STR(FAT32CHS);
1431 MY_CASE_STR(FAT32LBA);
1432 MY_CASE_STR(FAT16B);
1433 MY_CASE_STR(Extended);
1434 MY_CASE_STR(WindowsRE);
1435 MY_CASE_STR(LinuxSwapOld);
1436 MY_CASE_STR(LinuxOld);
1437 MY_CASE_STR(DragonFlyBSDSlice);
1438 MY_CASE_STR(LinuxSwap);
1439 MY_CASE_STR(Linux);
1440 MY_CASE_STR(LinuxExtended);
1441 MY_CASE_STR(LinuxLVM);
1442 MY_CASE_STR(BSDSlice);
1443 MY_CASE_STR(AppleUFS);
1444 MY_CASE_STR(AppleHFS);
1445 MY_CASE_STR(Solaris);
1446 MY_CASE_STR(GPT);
1447 MY_CASE_STR(EFI);
1448 MY_CASE_STR(Unknown);
1449 MY_CASE_STR(MBR);
1450 MY_CASE_STR(iFFS);
1451 MY_CASE_STR(SonyBoot);
1452 MY_CASE_STR(LenovoBoot);
1453 MY_CASE_STR(WindowsMSR);
1454 MY_CASE_STR(WindowsBasicData);
1455 MY_CASE_STR(WindowsLDMMeta);
1456 MY_CASE_STR(WindowsLDMData);
1457 MY_CASE_STR(WindowsRecovery);
1458 MY_CASE_STR(WindowsStorageSpaces);
1459 MY_CASE_STR(WindowsStorageReplica);
1460 MY_CASE_STR(IBMGPFS);
1461 MY_CASE_STR(LinuxData);
1462 MY_CASE_STR(LinuxRAID);
1463 MY_CASE_STR(LinuxRootX86);
1464 MY_CASE_STR(LinuxRootAMD64);
1465 MY_CASE_STR(LinuxRootARM32);
1466 MY_CASE_STR(LinuxRootARM64);
1467 MY_CASE_STR(LinuxHome);
1468 MY_CASE_STR(LinuxSrv);
1469 MY_CASE_STR(LinuxPlainDmCrypt);
1470 MY_CASE_STR(LinuxLUKS);
1471 MY_CASE_STR(LinuxReserved);
1472 MY_CASE_STR(FreeBSDBoot);
1473 MY_CASE_STR(FreeBSDData);
1474 MY_CASE_STR(FreeBSDSwap);
1475 MY_CASE_STR(FreeBSDUFS);
1476 MY_CASE_STR(FreeBSDVinum);
1477 MY_CASE_STR(FreeBSDZFS);
1478 MY_CASE_STR(FreeBSDUnknown);
1479 MY_CASE_STR(AppleHFSPlus);
1480 MY_CASE_STR(AppleAPFS);
1481 MY_CASE_STR(AppleRAID);
1482 MY_CASE_STR(AppleRAIDOffline);
1483 MY_CASE_STR(AppleBoot);
1484 MY_CASE_STR(AppleLabel);
1485 MY_CASE_STR(AppleTvRecovery);
1486 MY_CASE_STR(AppleCoreStorage);
1487 MY_CASE_STR(SoftRAIDStatus);
1488 MY_CASE_STR(SoftRAIDScratch);
1489 MY_CASE_STR(SoftRAIDVolume);
1490 MY_CASE_STR(SoftRAIDCache);
1491 MY_CASE_STR(AppleUnknown);
1492 MY_CASE_STR(SolarisBoot);
1493 MY_CASE_STR(SolarisRoot);
1494 MY_CASE_STR(SolarisSwap);
1495 MY_CASE_STR(SolarisBackup);
1496 MY_CASE_STR(SolarisUsr);
1497 MY_CASE_STR(SolarisVar);
1498 MY_CASE_STR(SolarisHome);
1499 MY_CASE_STR(SolarisAltSector);
1500 MY_CASE_STR(SolarisReserved);
1501 MY_CASE_STR(SolarisUnknown);
1502 MY_CASE_STR(NetBSDSwap);
1503 MY_CASE_STR(NetBSDFFS);
1504 MY_CASE_STR(NetBSDLFS);
1505 MY_CASE_STR(NetBSDRAID);
1506 MY_CASE_STR(NetBSDConcatenated);
1507 MY_CASE_STR(NetBSDEncrypted);
1508 MY_CASE_STR(NetBSDUnknown);
1509 MY_CASE_STR(ChromeOSKernel);
1510 MY_CASE_STR(ChromeOSRootFS);
1511 MY_CASE_STR(ChromeOSFuture);
1512 MY_CASE_STR(ContLnxUsr);
1513 MY_CASE_STR(ContLnxRoot);
1514 MY_CASE_STR(ContLnxReserved);
1515 MY_CASE_STR(ContLnxRootRAID);
1516 MY_CASE_STR(HaikuBFS);
1517 MY_CASE_STR(MidntBSDBoot);
1518 MY_CASE_STR(MidntBSDData);
1519 MY_CASE_STR(MidntBSDSwap);
1520 MY_CASE_STR(MidntBSDUFS);
1521 MY_CASE_STR(MidntBSDVium);
1522 MY_CASE_STR(MidntBSDZFS);
1523 MY_CASE_STR(MidntBSDUnknown);
1524 MY_CASE_STR(OpenBSDData);
1525 MY_CASE_STR(QNXPowerSafeFS);
1526 MY_CASE_STR(Plan9);
1527 MY_CASE_STR(VMWareVMKCore);
1528 MY_CASE_STR(VMWareVMFS);
1529 MY_CASE_STR(VMWareReserved);
1530 MY_CASE_STR(VMWareUnknown);
1531 MY_CASE_STR(AndroidX86Bootloader);
1532 MY_CASE_STR(AndroidX86Bootloader2);
1533 MY_CASE_STR(AndroidX86Boot);
1534 MY_CASE_STR(AndroidX86Recovery);
1535 MY_CASE_STR(AndroidX86Misc);
1536 MY_CASE_STR(AndroidX86Metadata);
1537 MY_CASE_STR(AndroidX86System);
1538 MY_CASE_STR(AndroidX86Cache);
1539 MY_CASE_STR(AndroidX86Data);
1540 MY_CASE_STR(AndroidX86Persistent);
1541 MY_CASE_STR(AndroidX86Vendor);
1542 MY_CASE_STR(AndroidX86Config);
1543 MY_CASE_STR(AndroidX86Factory);
1544 MY_CASE_STR(AndroidX86FactoryAlt);
1545 MY_CASE_STR(AndroidX86Fastboot);
1546 MY_CASE_STR(AndroidX86OEM);
1547 MY_CASE_STR(AndroidARMMeta);
1548 MY_CASE_STR(AndroidARMExt);
1549 MY_CASE_STR(ONIEBoot);
1550 MY_CASE_STR(ONIEConfig);
1551 MY_CASE_STR(PowerPCPrep);
1552 MY_CASE_STR(XDGShrBootConfig);
1553 MY_CASE_STR(CephBlock);
1554 MY_CASE_STR(CephBlockDB);
1555 MY_CASE_STR(CephBlockDBDmc);
1556 MY_CASE_STR(CephBlockDBDmcLUKS);
1557 MY_CASE_STR(CephBlockDmc);
1558 MY_CASE_STR(CephBlockDmcLUKS);
1559 MY_CASE_STR(CephBlockWALog);
1560 MY_CASE_STR(CephBlockWALogDmc);
1561 MY_CASE_STR(CephBlockWALogDmcLUKS);
1562 MY_CASE_STR(CephDisk);
1563 MY_CASE_STR(CephDiskDmc);
1564 MY_CASE_STR(CephJournal);
1565 MY_CASE_STR(CephJournalDmc);
1566 MY_CASE_STR(CephJournalDmcLUKS);
1567 MY_CASE_STR(CephLockbox);
1568 MY_CASE_STR(CephMultipathBlock1);
1569 MY_CASE_STR(CephMultipathBlock2);
1570 MY_CASE_STR(CephMultipathBlockDB);
1571 MY_CASE_STR(CephMultipathBLockWALog);
1572 MY_CASE_STR(CephMultipathJournal);
1573 MY_CASE_STR(CephMultipathOSD);
1574 MY_CASE_STR(CephOSD);
1575 MY_CASE_STR(CephOSDDmc);
1576 MY_CASE_STR(CephOSDDmcLUKS);
1577#ifdef VBOX_WITH_XPCOM_CPP_ENUM_HACK
1578 case PartitionType_32BitHack: break;
1579#endif
1580 /* no default! */
1581 }
1582#undef MY_CASE_STR
1583 return pszUnknown;
1584}
1585
1586
1587/**
1588 * List all available host drives with their partitions.
1589 *
1590 * @returns See produceList.
1591 * @param pVirtualBox Reference to the IVirtualBox pointer.
1592 * @param fOptLong Long listing or human readable.
1593 */
1594static HRESULT listHostDrives(const ComPtr<IVirtualBox> pVirtualBox, bool fOptLong)
1595{
1596 HRESULT rc = S_OK;
1597 ComPtr<IHost> pHost;
1598 CHECK_ERROR2I_RET(pVirtualBox, COMGETTER(Host)(pHost.asOutParam()), hrcCheck);
1599 com::SafeIfaceArray<IHostDrive> apHostDrives;
1600 CHECK_ERROR2I_RET(pHost, COMGETTER(HostDrives)(ComSafeArrayAsOutParam(apHostDrives)), hrcCheck);
1601 for (size_t i = 0; i < apHostDrives.size(); ++i)
1602 {
1603 ComPtr<IHostDrive> pHostDrive = apHostDrives[i];
1604 /*
1605 * The drive path and the model are obtained using different way
1606 * outside of the IHostDrive object, therefore, they are defined
1607 * even if another info is not available.
1608 */
1609 com::Bstr bstrDrivePath;
1610 CHECK_ERROR(pHostDrive,COMGETTER(DrivePath)(bstrDrivePath.asOutParam()));
1611 RTPrintf("%sDrive: %ls\n", i > 0 ? "\n" : "", bstrDrivePath.raw());
1612
1613 com::Bstr bstrModel;
1614 CHECK_ERROR(pHostDrive,COMGETTER(Model)(bstrModel.asOutParam()));
1615 if (bstrModel.isNotEmpty())
1616 RTPrintf("Model: %ls\n", bstrModel.raw());
1617 else
1618 RTPrintf("Model: Unknown\n");
1619
1620 com::Bstr bstrUuidDisk;
1621 ULONG cbSectorSize = 0;
1622 LONG64 cbSize = 0;
1623 PartitioningType_T partitioningType;
1624 HRESULT hrc;
1625 if ( SUCCEEDED(hrc = pHostDrive->COMGETTER(Uuid)(bstrUuidDisk.asOutParam()))
1626 && SUCCEEDED(hrc = pHostDrive->COMGETTER(SectorSize)(&cbSectorSize))
1627 && SUCCEEDED(hrc = pHostDrive->COMGETTER(Size)(&cbSize))
1628 && SUCCEEDED(hrc = pHostDrive->COMGETTER(PartitioningType)(&partitioningType)))
1629 {
1630 if (partitioningType == PartitioningType_GPT || com::Guid(bstrUuidDisk).isZero())
1631 RTPrintf("UUID: %ls\n", bstrUuidDisk.raw());
1632 if (fOptLong)
1633 RTPrintf("Size: %llu bytes (%Rhcb)\n", cbSize, cbSize);
1634 else
1635 RTPrintf("Size: %Rhcb\n", cbSize);
1636 RTPrintf("Sector Size: %u bytes\n", cbSectorSize);
1637 RTPrintf("Scheme: %s\n", partitioningType == PartitioningType_MBR ? "MBR" : "GPT");
1638
1639 com::SafeIfaceArray<IHostDrivePartition> apHostDrivesPartitions;
1640 CHECK_ERROR(pHostDrive, COMGETTER(Partitions)(ComSafeArrayAsOutParam(apHostDrivesPartitions)));
1641
1642 if (partitioningType == PartitioningType_MBR)
1643 {
1644 if (fOptLong)
1645 RTPrintf("Partitions: First Last\n"
1646 "## Type Byte Size Byte Offset Cyl/Head/Sec Cyl/Head/Sec Active\n");
1647 else
1648 RTPrintf("Partitions: First Last\n"
1649 "## Type Size Start Cyl/Head/Sec Cyl/Head/Sec Active\n");
1650 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j)
1651 {
1652 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j];
1653
1654 ULONG idx = 0;
1655 CHECK_ERROR(pHostDrivePartition, COMGETTER(Number)(&idx));
1656 ULONG uType = 0;
1657 CHECK_ERROR(pHostDrivePartition, COMGETTER(TypeMBR)(&uType));
1658 ULONG uStartCylinder = 0;
1659 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartCylinder)(&uStartCylinder));
1660 ULONG uStartHead = 0;
1661 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartHead)(&uStartHead));
1662 ULONG uStartSector = 0;
1663 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartSector)(&uStartSector));
1664 ULONG uEndCylinder = 0;
1665 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndCylinder)(&uEndCylinder));
1666 ULONG uEndHead = 0;
1667 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndHead)(&uEndHead));
1668 ULONG uEndSector = 0;
1669 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndSector)(&uEndSector));
1670 cbSize = 0;
1671 CHECK_ERROR(pHostDrivePartition, COMGETTER(Size)(&cbSize));
1672 LONG64 offStart = 0;
1673 CHECK_ERROR(pHostDrivePartition, COMGETTER(Start)(&offStart));
1674 BOOL fActive = 0;
1675 CHECK_ERROR(pHostDrivePartition, COMGETTER(Active)(&fActive));
1676 PartitionType_T enmType = PartitionType_Unknown;
1677 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType));
1678
1679 /* Max size & offset here is around 16TiB with 4KiB sectors. */
1680 if (fOptLong) /* cb/off: max 16TiB; idx: max 64. */
1681 RTPrintf("%2u %02x %14llu %14llu %4u/%3u/%2u %4u/%3u/%2u %s %s\n",
1682 idx, uType, cbSize, offStart,
1683 uStartCylinder, uStartHead, uStartSector, uEndCylinder, uEndHead, uEndSector,
1684 fActive ? "yes" : "no", PartitionTypeToString(enmType, ""));
1685 else
1686 RTPrintf("%2u %02x %8Rhcb %8Rhcb %4u/%3u/%2u %4u/%3u/%2u %s %s\n",
1687 idx, uType, (uint64_t)cbSize, (uint64_t)offStart,
1688 uStartCylinder, uStartHead, uStartSector, uEndCylinder, uEndHead, uEndSector,
1689 fActive ? "yes" : "no", PartitionTypeToString(enmType, ""));
1690 }
1691 }
1692 else /* GPT */
1693 {
1694 /* Determin the max partition type length to try reduce the table width: */
1695 size_t cchMaxType = 0;
1696 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j)
1697 {
1698 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j];
1699 PartitionType_T enmType = PartitionType_Unknown;
1700 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType));
1701 size_t const cchTypeNm = strlen(PartitionTypeToString(enmType, "e530bf6d-2754-4e9d-b260-60a5d0b80457"));
1702 cchMaxType = RT_MAX(cchTypeNm, cchMaxType);
1703 }
1704 cchMaxType = RT_MIN(cchMaxType, RTUUID_STR_LENGTH);
1705
1706 if (fOptLong)
1707 RTPrintf("Partitions:\n"
1708 "## %-*s Uuid Byte Size Byte Offset Active Name\n",
1709 (int)cchMaxType, "Type");
1710 else
1711 RTPrintf("Partitions:\n"
1712 "## %-*s Uuid Size Start Active Name\n",
1713 (int)cchMaxType, "Type");
1714
1715 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j)
1716 {
1717 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j];
1718
1719 ULONG idx = 0;
1720 CHECK_ERROR(pHostDrivePartition, COMGETTER(Number)(&idx));
1721 com::Bstr bstrUuidType;
1722 CHECK_ERROR(pHostDrivePartition, COMGETTER(TypeUuid)(bstrUuidType.asOutParam()));
1723 com::Bstr bstrUuidPartition;
1724 CHECK_ERROR(pHostDrivePartition, COMGETTER(Uuid)(bstrUuidPartition.asOutParam()));
1725 cbSize = 0;
1726 CHECK_ERROR(pHostDrivePartition, COMGETTER(Size)(&cbSize));
1727 LONG64 offStart = 0;
1728 CHECK_ERROR(pHostDrivePartition, COMGETTER(Start)(&offStart));
1729 BOOL fActive = 0;
1730 CHECK_ERROR(pHostDrivePartition, COMGETTER(Active)(&fActive));
1731 com::Bstr bstrName;
1732 CHECK_ERROR(pHostDrivePartition, COMGETTER(Name)(bstrName.asOutParam()));
1733
1734 PartitionType_T enmType = PartitionType_Unknown;
1735 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType));
1736
1737 Utf8Str strTypeConv;
1738 const char *pszTypeNm = PartitionTypeToString(enmType, NULL);
1739 if (!pszTypeNm)
1740 pszTypeNm = (strTypeConv = bstrUuidType).c_str();
1741 else if (strlen(pszTypeNm) >= RTUUID_STR_LENGTH /* includes '\0' */)
1742 pszTypeNm -= RTUUID_STR_LENGTH - 1 - strlen(pszTypeNm);
1743
1744 if (fOptLong)
1745 RTPrintf("%2u %-*s %36ls %19llu %19llu %-3s %ls\n", idx, cchMaxType, pszTypeNm,
1746 bstrUuidPartition.raw(), cbSize, offStart, fActive ? "on" : "off", bstrName.raw());
1747 else
1748 RTPrintf("%2u %-*s %36ls %8Rhcb %8Rhcb %-3s %ls\n", idx, cchMaxType, pszTypeNm,
1749 bstrUuidPartition.raw(), cbSize, offStart, fActive ? "on" : "off", bstrName.raw());
1750 }
1751 }
1752 }
1753 else
1754 RTPrintf("Partitions and disk info for the drive %ls are not available. Error %Rhrc (%#RX32)\n",
1755 bstrDrivePath.raw(), hrc, hrc);
1756 }
1757 return rc;
1758}
1759
1760
1761/**
1762 * The type of lists we can produce.
1763 */
1764enum ListType_T
1765{
1766 kListNotSpecified = 1000,
1767 kListVMs,
1768 kListRunningVMs,
1769 kListOsTypes,
1770 kListHostDvds,
1771 kListHostFloppies,
1772 kListInternalNetworks,
1773 kListBridgedInterfaces,
1774#if defined(VBOX_WITH_NETFLT)
1775 kListHostOnlyInterfaces,
1776#endif
1777#if defined(VBOX_WITH_CLOUD_NET)
1778 kListCloudNetworks,
1779#endif
1780 kListHostCpuIDs,
1781 kListHostInfo,
1782 kListHddBackends,
1783 kListHdds,
1784 kListDvds,
1785 kListFloppies,
1786 kListUsbHost,
1787 kListUsbFilters,
1788 kListSystemProperties,
1789 kListDhcpServers,
1790 kListExtPacks,
1791 kListGroups,
1792 kListNatNetworks,
1793 kListVideoInputDevices,
1794 kListScreenShotFormats,
1795 kListCloudProviders,
1796 kListCloudProfiles,
1797 kListCPUProfiles,
1798 kListHostDrives
1799};
1800
1801
1802/**
1803 * Produces the specified listing.
1804 *
1805 * @returns S_OK or some COM error code that has been reported in full.
1806 * @param enmList The list to produce.
1807 * @param fOptLong Long (@c true) or short list format.
1808 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1809 */
1810static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
1811{
1812 HRESULT rc = S_OK;
1813 switch (enmCommand)
1814 {
1815 case kListNotSpecified:
1816 AssertFailed();
1817 return E_FAIL;
1818
1819 case kListVMs:
1820 {
1821 /*
1822 * Get the list of all registered VMs
1823 */
1824 com::SafeIfaceArray<IMachine> machines;
1825 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1826 if (SUCCEEDED(rc))
1827 {
1828 /*
1829 * Display it.
1830 */
1831 if (!fOptSorted)
1832 {
1833 for (size_t i = 0; i < machines.size(); ++i)
1834 if (machines[i])
1835 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1836 }
1837 else
1838 {
1839 /*
1840 * Sort the list by name before displaying it.
1841 */
1842 std::vector<std::pair<com::Bstr, IMachine *> > sortedMachines;
1843 for (size_t i = 0; i < machines.size(); ++i)
1844 {
1845 IMachine *pMachine = machines[i];
1846 if (pMachine) /* no idea why we need to do this... */
1847 {
1848 Bstr bstrName;
1849 pMachine->COMGETTER(Name)(bstrName.asOutParam());
1850 sortedMachines.push_back(std::pair<com::Bstr, IMachine *>(bstrName, pMachine));
1851 }
1852 }
1853
1854 std::sort(sortedMachines.begin(), sortedMachines.end());
1855
1856 for (size_t i = 0; i < sortedMachines.size(); ++i)
1857 rc = showVMInfo(pVirtualBox, sortedMachines[i].second, NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1858 }
1859 }
1860 break;
1861 }
1862
1863 case kListRunningVMs:
1864 {
1865 /*
1866 * Get the list of all _running_ VMs
1867 */
1868 com::SafeIfaceArray<IMachine> machines;
1869 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1870 com::SafeArray<MachineState_T> states;
1871 if (SUCCEEDED(rc))
1872 rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
1873 if (SUCCEEDED(rc))
1874 {
1875 /*
1876 * Iterate through the collection
1877 */
1878 for (size_t i = 0; i < machines.size(); ++i)
1879 {
1880 if (machines[i])
1881 {
1882 MachineState_T machineState = states[i];
1883 switch (machineState)
1884 {
1885 case MachineState_Running:
1886 case MachineState_Teleporting:
1887 case MachineState_LiveSnapshotting:
1888 case MachineState_Paused:
1889 case MachineState_TeleportingPausedVM:
1890 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1891 break;
1892 default: break; /* Shut up MSC */
1893 }
1894 }
1895 }
1896 }
1897 break;
1898 }
1899
1900 case kListOsTypes:
1901 {
1902 com::SafeIfaceArray<IGuestOSType> coll;
1903 rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
1904 if (SUCCEEDED(rc))
1905 {
1906 /*
1907 * Iterate through the collection.
1908 */
1909 for (size_t i = 0; i < coll.size(); ++i)
1910 {
1911 ComPtr<IGuestOSType> guestOS;
1912 guestOS = coll[i];
1913 Bstr guestId;
1914 guestOS->COMGETTER(Id)(guestId.asOutParam());
1915 RTPrintf("ID: %ls\n", guestId.raw());
1916 Bstr guestDescription;
1917 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
1918 RTPrintf("Description: %ls\n", guestDescription.raw());
1919 Bstr familyId;
1920 guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
1921 RTPrintf("Family ID: %ls\n", familyId.raw());
1922 Bstr familyDescription;
1923 guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
1924 RTPrintf("Family Desc: %ls\n", familyDescription.raw());
1925 BOOL is64Bit;
1926 guestOS->COMGETTER(Is64Bit)(&is64Bit);
1927 RTPrintf("64 bit: %RTbool\n", is64Bit);
1928 RTPrintf("\n");
1929 }
1930 }
1931 break;
1932 }
1933
1934 case kListHostDvds:
1935 {
1936 ComPtr<IHost> host;
1937 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1938 com::SafeIfaceArray<IMedium> coll;
1939 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
1940 if (SUCCEEDED(rc))
1941 {
1942 for (size_t i = 0; i < coll.size(); ++i)
1943 {
1944 ComPtr<IMedium> dvdDrive = coll[i];
1945 Bstr uuid;
1946 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
1947 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1948 Bstr location;
1949 dvdDrive->COMGETTER(Location)(location.asOutParam());
1950 RTPrintf("Name: %ls\n\n", location.raw());
1951 }
1952 }
1953 break;
1954 }
1955
1956 case kListHostFloppies:
1957 {
1958 ComPtr<IHost> host;
1959 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1960 com::SafeIfaceArray<IMedium> coll;
1961 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
1962 if (SUCCEEDED(rc))
1963 {
1964 for (size_t i = 0; i < coll.size(); ++i)
1965 {
1966 ComPtr<IMedium> floppyDrive = coll[i];
1967 Bstr uuid;
1968 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
1969 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1970 Bstr location;
1971 floppyDrive->COMGETTER(Location)(location.asOutParam());
1972 RTPrintf("Name: %ls\n\n", location.raw());
1973 }
1974 }
1975 break;
1976 }
1977
1978 case kListInternalNetworks:
1979 rc = listInternalNetworks(pVirtualBox);
1980 break;
1981
1982 case kListBridgedInterfaces:
1983#if defined(VBOX_WITH_NETFLT)
1984 case kListHostOnlyInterfaces:
1985#endif
1986 rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
1987 break;
1988
1989#if defined(VBOX_WITH_CLOUD_NET)
1990 case kListCloudNetworks:
1991 rc = listCloudNetworks(pVirtualBox);
1992 break;
1993#endif
1994 case kListHostInfo:
1995 rc = listHostInfo(pVirtualBox);
1996 break;
1997
1998 case kListHostCpuIDs:
1999 {
2000 ComPtr<IHost> Host;
2001 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
2002
2003 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
2004 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
2005 static uint32_t const s_auCpuIdRanges[] =
2006 {
2007 UINT32_C(0x00000000), UINT32_C(0x0000007f),
2008 UINT32_C(0x80000000), UINT32_C(0x8000007f),
2009 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
2010 };
2011 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
2012 {
2013 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
2014 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
2015 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
2016 continue;
2017 cLeafs++;
2018 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
2019 {
2020 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
2021 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
2022 }
2023 }
2024 break;
2025 }
2026
2027 case kListHddBackends:
2028 rc = listHddBackends(pVirtualBox);
2029 break;
2030
2031 case kListHdds:
2032 {
2033 com::SafeIfaceArray<IMedium> hdds;
2034 CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
2035 rc = listMedia(pVirtualBox, hdds, "base", fOptLong);
2036 break;
2037 }
2038
2039 case kListDvds:
2040 {
2041 com::SafeIfaceArray<IMedium> dvds;
2042 CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
2043 rc = listMedia(pVirtualBox, dvds, NULL, fOptLong);
2044 break;
2045 }
2046
2047 case kListFloppies:
2048 {
2049 com::SafeIfaceArray<IMedium> floppies;
2050 CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
2051 rc = listMedia(pVirtualBox, floppies, NULL, fOptLong);
2052 break;
2053 }
2054
2055 case kListUsbHost:
2056 rc = listUsbHost(pVirtualBox);
2057 break;
2058
2059 case kListUsbFilters:
2060 rc = listUsbFilters(pVirtualBox);
2061 break;
2062
2063 case kListSystemProperties:
2064 rc = listSystemProperties(pVirtualBox);
2065 break;
2066
2067 case kListDhcpServers:
2068 rc = listDhcpServers(pVirtualBox);
2069 break;
2070
2071 case kListExtPacks:
2072 rc = listExtensionPacks(pVirtualBox);
2073 break;
2074
2075 case kListGroups:
2076 rc = listGroups(pVirtualBox);
2077 break;
2078
2079 case kListNatNetworks:
2080 {
2081 com::SafeIfaceArray<INATNetwork> nets;
2082 CHECK_ERROR(pVirtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(nets)));
2083 for (size_t i = 0; i < nets.size(); ++i)
2084 {
2085 ComPtr<INATNetwork> net = nets[i];
2086 Bstr netName;
2087 net->COMGETTER(NetworkName)(netName.asOutParam());
2088 RTPrintf("NetworkName: %ls\n", netName.raw());
2089 Bstr gateway;
2090 net->COMGETTER(Gateway)(gateway.asOutParam());
2091 RTPrintf("IP: %ls\n", gateway.raw());
2092 Bstr network;
2093 net->COMGETTER(Network)(network.asOutParam());
2094 RTPrintf("Network: %ls\n", network.raw());
2095 BOOL fEnabled;
2096 net->COMGETTER(IPv6Enabled)(&fEnabled);
2097 RTPrintf("IPv6 Enabled: %s\n", fEnabled ? "Yes" : "No");
2098 Bstr ipv6prefix;
2099 net->COMGETTER(IPv6Prefix)(ipv6prefix.asOutParam());
2100 RTPrintf("IPv6 Prefix: %ls\n", ipv6prefix.raw());
2101 net->COMGETTER(NeedDhcpServer)(&fEnabled);
2102 RTPrintf("DHCP Enabled: %s\n", fEnabled ? "Yes" : "No");
2103 net->COMGETTER(Enabled)(&fEnabled);
2104 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
2105
2106#define PRINT_STRING_ARRAY(title) \
2107 if (strs.size() > 0) \
2108 { \
2109 RTPrintf(title); \
2110 size_t j = 0; \
2111 for (;j < strs.size(); ++j) \
2112 RTPrintf(" %s\n", Utf8Str(strs[j]).c_str()); \
2113 }
2114
2115 com::SafeArray<BSTR> strs;
2116
2117 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(strs)));
2118 PRINT_STRING_ARRAY("Port-forwarding (ipv4)\n");
2119 strs.setNull();
2120
2121 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(strs)));
2122 PRINT_STRING_ARRAY("Port-forwarding (ipv6)\n");
2123 strs.setNull();
2124
2125 CHECK_ERROR(nets[i], COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)));
2126 PRINT_STRING_ARRAY("loopback mappings (ipv4)\n");
2127 strs.setNull();
2128
2129#undef PRINT_STRING_ARRAY
2130 RTPrintf("\n");
2131 }
2132 break;
2133 }
2134
2135 case kListVideoInputDevices:
2136 rc = listVideoInputDevices(pVirtualBox);
2137 break;
2138
2139 case kListScreenShotFormats:
2140 rc = listScreenShotFormats(pVirtualBox);
2141 break;
2142
2143 case kListCloudProviders:
2144 rc = listCloudProviders(pVirtualBox);
2145 break;
2146
2147 case kListCloudProfiles:
2148 rc = listCloudProfiles(pVirtualBox, fOptLong);
2149 break;
2150
2151 case kListCPUProfiles:
2152 rc = listCPUProfiles(pVirtualBox, fOptLong, fOptSorted);
2153 break;
2154
2155 case kListHostDrives:
2156 rc = listHostDrives(pVirtualBox, fOptLong);
2157 break;
2158 /* No default here, want gcc warnings. */
2159
2160 } /* end switch */
2161
2162 return rc;
2163}
2164
2165/**
2166 * Handles the 'list' command.
2167 *
2168 * @returns Appropriate exit code.
2169 * @param a Handler argument.
2170 */
2171RTEXITCODE handleList(HandlerArg *a)
2172{
2173 bool fOptLong = false;
2174 bool fOptMultiple = false;
2175 bool fOptSorted = false;
2176 enum ListType_T enmOptCommand = kListNotSpecified;
2177
2178 static const RTGETOPTDEF s_aListOptions[] =
2179 {
2180 { "--long", 'l', RTGETOPT_REQ_NOTHING },
2181 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
2182 { "--sorted", 's', RTGETOPT_REQ_NOTHING },
2183 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
2184 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
2185 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
2186 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
2187 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
2188 { "intnets", kListInternalNetworks, RTGETOPT_REQ_NOTHING },
2189 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
2190 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
2191#if defined(VBOX_WITH_NETFLT)
2192 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
2193#endif
2194#if defined(VBOX_WITH_CLOUD_NET)
2195 { "cloudnets", kListCloudNetworks, RTGETOPT_REQ_NOTHING },
2196#endif
2197 { "natnetworks", kListNatNetworks, RTGETOPT_REQ_NOTHING },
2198 { "natnets", kListNatNetworks, RTGETOPT_REQ_NOTHING },
2199 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
2200 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
2201 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
2202 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
2203 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
2204 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
2205 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
2206 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
2207 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
2208 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
2209 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
2210 { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
2211 { "webcams", kListVideoInputDevices, RTGETOPT_REQ_NOTHING },
2212 { "screenshotformats", kListScreenShotFormats, RTGETOPT_REQ_NOTHING },
2213 { "cloudproviders", kListCloudProviders, RTGETOPT_REQ_NOTHING },
2214 { "cloudprofiles", kListCloudProfiles, RTGETOPT_REQ_NOTHING },
2215 { "cpu-profiles", kListCPUProfiles, RTGETOPT_REQ_NOTHING },
2216 { "hostdrives", kListHostDrives, RTGETOPT_REQ_NOTHING },
2217 };
2218
2219 int ch;
2220 RTGETOPTUNION ValueUnion;
2221 RTGETOPTSTATE GetState;
2222 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
2223 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
2224 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
2225 {
2226 switch (ch)
2227 {
2228 case 'l': /* --long */
2229 fOptLong = true;
2230 break;
2231
2232 case 's':
2233 fOptSorted = true;
2234 break;
2235
2236 case 'm':
2237 fOptMultiple = true;
2238 if (enmOptCommand == kListNotSpecified)
2239 break;
2240 ch = enmOptCommand;
2241 RT_FALL_THRU();
2242
2243 case kListVMs:
2244 case kListRunningVMs:
2245 case kListOsTypes:
2246 case kListHostDvds:
2247 case kListHostFloppies:
2248 case kListInternalNetworks:
2249 case kListBridgedInterfaces:
2250#if defined(VBOX_WITH_NETFLT)
2251 case kListHostOnlyInterfaces:
2252#endif
2253#if defined(VBOX_WITH_CLOUD_NET)
2254 case kListCloudNetworks:
2255#endif
2256 case kListHostInfo:
2257 case kListHostCpuIDs:
2258 case kListHddBackends:
2259 case kListHdds:
2260 case kListDvds:
2261 case kListFloppies:
2262 case kListUsbHost:
2263 case kListUsbFilters:
2264 case kListSystemProperties:
2265 case kListDhcpServers:
2266 case kListExtPacks:
2267 case kListGroups:
2268 case kListNatNetworks:
2269 case kListVideoInputDevices:
2270 case kListScreenShotFormats:
2271 case kListCloudProviders:
2272 case kListCloudProfiles:
2273 case kListCPUProfiles:
2274 case kListHostDrives:
2275 enmOptCommand = (enum ListType_T)ch;
2276 if (fOptMultiple)
2277 {
2278 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
2279 if (FAILED(hrc))
2280 return RTEXITCODE_FAILURE;
2281 }
2282 break;
2283
2284 case VINF_GETOPT_NOT_OPTION:
2285 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
2286
2287 default:
2288 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
2289 }
2290 }
2291
2292 /*
2293 * If not in multiple list mode, we have to produce the list now.
2294 */
2295 if (enmOptCommand == kListNotSpecified)
2296 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
2297 if (!fOptMultiple)
2298 {
2299 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
2300 if (FAILED(hrc))
2301 return RTEXITCODE_FAILURE;
2302 }
2303
2304 return RTEXITCODE_SUCCESS;
2305}
2306
2307#endif /* !VBOX_ONLY_DOCS */
2308/* vi: set tabstop=4 shiftwidth=4 expandtab: */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette