VirtualBox

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

Last change on this file since 91616 was 91416, checked in by vboxsync, 3 years ago

Devices: bugref:9932 DrvVMNet and host-only network initial implementation

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

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