VirtualBox

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

Last change on this file since 86103 was 85929, checked in by vboxsync, 4 years ago

Main: bugref:9224: Main+VBoxManageDisk+doc part

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 92.8 KB
Line 
1/* $Id: VBoxManageList.cpp 85929 2020-08-28 14:40:55Z 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_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 com::Bstr bstrDrivePath;
1606 CHECK_ERROR(pHostDrive,COMGETTER(DrivePath)(bstrDrivePath.asOutParam()));
1607 RTPrintf("%sDrive: %ls\n", i > 0 ? "\n" : "", bstrDrivePath.raw());
1608
1609 com::Bstr bstrModel;
1610 com::Bstr bstrUuidDisk;
1611 ULONG cbSectorSize = 0;
1612 LONG64 cbSize = 0;
1613 PartitioningType_T partitioningType;
1614 HRESULT hrc;
1615 if ( SUCCEEDED(hrc = pHostDrive->COMGETTER(Model)(bstrModel.asOutParam()))
1616 && SUCCEEDED(hrc = pHostDrive->COMGETTER(Uuid)(bstrUuidDisk.asOutParam()))
1617 && SUCCEEDED(hrc = pHostDrive->COMGETTER(SectorSize)(&cbSectorSize))
1618 && SUCCEEDED(hrc = pHostDrive->COMGETTER(Size)(&cbSize))
1619 && SUCCEEDED(hrc = pHostDrive->COMGETTER(PartitioningType)(&partitioningType)))
1620 {
1621 if (bstrModel.isNotEmpty())
1622 RTPrintf("Model: %ls\n", bstrModel.raw());
1623 else
1624 RTPrintf("Model: Unknown\n");
1625
1626 if (partitioningType == PartitioningType_GPT || com::Guid(bstrUuidDisk).isZero())
1627 RTPrintf("UUID: %ls\n", bstrUuidDisk.raw());
1628 if (fOptLong)
1629 RTPrintf("Size: %llu bytes (%Rhcb)\n", cbSize, cbSize);
1630 else
1631 RTPrintf("Size: %Rhcb\n", cbSize);
1632 RTPrintf("Sector Size: %u bytes\n", cbSectorSize);
1633 RTPrintf("Scheme: %s\n", partitioningType == PartitioningType_MBR ? "MBR" : "GPT");
1634
1635 com::SafeIfaceArray<IHostDrivePartition> apHostDrivesPartitions;
1636 CHECK_ERROR(pHostDrive, COMGETTER(Partitions)(ComSafeArrayAsOutParam(apHostDrivesPartitions)));
1637
1638 if (partitioningType == PartitioningType_MBR)
1639 {
1640 if (fOptLong)
1641 RTPrintf("Partitions: First Last\n"
1642 "## Type Byte Size Byte Offset Cyl/Head/Sec Cyl/Head/Sec Active\n");
1643 else
1644 RTPrintf("Partitions: First Last\n"
1645 "## Type Size Start Cyl/Head/Sec Cyl/Head/Sec Active\n");
1646 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j)
1647 {
1648 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j];
1649
1650 ULONG idx = 0;
1651 CHECK_ERROR(pHostDrivePartition, COMGETTER(Number)(&idx));
1652 ULONG uType = 0;
1653 CHECK_ERROR(pHostDrivePartition, COMGETTER(TypeMBR)(&uType));
1654 ULONG uStartCylinder = 0;
1655 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartCylinder)(&uStartCylinder));
1656 ULONG uStartHead = 0;
1657 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartHead)(&uStartHead));
1658 ULONG uStartSector = 0;
1659 CHECK_ERROR(pHostDrivePartition, COMGETTER(StartSector)(&uStartSector));
1660 ULONG uEndCylinder = 0;
1661 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndCylinder)(&uEndCylinder));
1662 ULONG uEndHead = 0;
1663 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndHead)(&uEndHead));
1664 ULONG uEndSector = 0;
1665 CHECK_ERROR(pHostDrivePartition, COMGETTER(EndSector)(&uEndSector));
1666 cbSize = 0;
1667 CHECK_ERROR(pHostDrivePartition, COMGETTER(Size)(&cbSize));
1668 LONG64 offStart = 0;
1669 CHECK_ERROR(pHostDrivePartition, COMGETTER(Start)(&offStart));
1670 BOOL fActive = 0;
1671 CHECK_ERROR(pHostDrivePartition, COMGETTER(Active)(&fActive));
1672 PartitionType_T enmType = PartitionType_Unknown;
1673 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType));
1674
1675 /* Max size & offset here is around 16TiB with 4KiB sectors. */
1676 if (fOptLong) /* cb/off: max 16TiB; idx: max 64. */
1677 RTPrintf("%2u %02x %14llu %14llu %4u/%3u/%2u %4u/%3u/%2u %s %s\n",
1678 idx, uType, cbSize, offStart,
1679 uStartCylinder, uStartHead, uStartSector, uEndCylinder, uEndHead, uEndSector,
1680 fActive ? "yes" : "no", PartitionTypeToString(enmType, ""));
1681 else
1682 RTPrintf("%2u %02x %8Rhcb %8Rhcb %4u/%3u/%2u %4u/%3u/%2u %s %s\n",
1683 idx, uType, (uint64_t)cbSize, (uint64_t)offStart,
1684 uStartCylinder, uStartHead, uStartSector, uEndCylinder, uEndHead, uEndSector,
1685 fActive ? "yes" : "no", PartitionTypeToString(enmType, ""));
1686 }
1687 }
1688 else /* GPT */
1689 {
1690 /* Determin the max partition type length to try reduce the table width: */
1691 size_t cchMaxType = 0;
1692 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j)
1693 {
1694 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j];
1695 PartitionType_T enmType = PartitionType_Unknown;
1696 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType));
1697 size_t const cchTypeNm = strlen(PartitionTypeToString(enmType, "e530bf6d-2754-4e9d-b260-60a5d0b80457"));
1698 cchMaxType = RT_MAX(cchTypeNm, cchMaxType);
1699 }
1700 cchMaxType = RT_MIN(cchMaxType, RTUUID_STR_LENGTH);
1701
1702 if (fOptLong)
1703 RTPrintf("Partitions:\n"
1704 "## %-*s Uuid Byte Size Byte Offset Active Name\n",
1705 (int)cchMaxType, "Type");
1706 else
1707 RTPrintf("Partitions:\n"
1708 "## %-*s Uuid Size Start Active Name\n",
1709 (int)cchMaxType, "Type");
1710
1711 for (size_t j = 0; j < apHostDrivesPartitions.size(); ++j)
1712 {
1713 ComPtr<IHostDrivePartition> pHostDrivePartition = apHostDrivesPartitions[j];
1714
1715 ULONG idx = 0;
1716 CHECK_ERROR(pHostDrivePartition, COMGETTER(Number)(&idx));
1717 com::Bstr bstrUuidType;
1718 CHECK_ERROR(pHostDrivePartition, COMGETTER(TypeUuid)(bstrUuidType.asOutParam()));
1719 com::Bstr bstrUuidPartition;
1720 CHECK_ERROR(pHostDrivePartition, COMGETTER(Uuid)(bstrUuidPartition.asOutParam()));
1721 cbSize = 0;
1722 CHECK_ERROR(pHostDrivePartition, COMGETTER(Size)(&cbSize));
1723 LONG64 offStart = 0;
1724 CHECK_ERROR(pHostDrivePartition, COMGETTER(Start)(&offStart));
1725 BOOL fActive = 0;
1726 CHECK_ERROR(pHostDrivePartition, COMGETTER(Active)(&fActive));
1727 com::Bstr bstrName;
1728 CHECK_ERROR(pHostDrivePartition, COMGETTER(Name)(bstrName.asOutParam()));
1729
1730 PartitionType_T enmType = PartitionType_Unknown;
1731 CHECK_ERROR(pHostDrivePartition, COMGETTER(Type)(&enmType));
1732
1733 Utf8Str strTypeConv;
1734 const char *pszTypeNm = PartitionTypeToString(enmType, NULL);
1735 if (!pszTypeNm)
1736 pszTypeNm = (strTypeConv = bstrUuidType).c_str();
1737 else if (strlen(pszTypeNm) >= RTUUID_STR_LENGTH /* includes '\0' */)
1738 pszTypeNm -= RTUUID_STR_LENGTH - 1 - strlen(pszTypeNm);
1739
1740 if (fOptLong)
1741 RTPrintf("%2u %-*s %36ls %19llu %19llu %-3s %ls\n", idx, cchMaxType, pszTypeNm,
1742 bstrUuidPartition.raw(), cbSize, offStart, fActive ? "on" : "off", bstrName.raw());
1743 else
1744 RTPrintf("%2u %-*s %36ls %8Rhcb %8Rhcb %-3s %ls\n", idx, cchMaxType, pszTypeNm,
1745 bstrUuidPartition.raw(), cbSize, offStart, fActive ? "on" : "off", bstrName.raw());
1746 }
1747 }
1748 }
1749 else
1750 RTPrintf("Partitions and disk info for the drive %ls are not available. Error %Rhrc (%#RX32)\n",
1751 bstrDrivePath.raw(), hrc, hrc);
1752 }
1753 return rc;
1754}
1755
1756
1757/**
1758 * The type of lists we can produce.
1759 */
1760enum ListType_T
1761{
1762 kListNotSpecified = 1000,
1763 kListVMs,
1764 kListRunningVMs,
1765 kListOsTypes,
1766 kListHostDvds,
1767 kListHostFloppies,
1768 kListInternalNetworks,
1769 kListBridgedInterfaces,
1770#if defined(VBOX_WITH_NETFLT)
1771 kListHostOnlyInterfaces,
1772#endif
1773#if defined(VBOX_WITH_CLOUD_NET)
1774 kListCloudNetworks,
1775#endif
1776 kListHostCpuIDs,
1777 kListHostInfo,
1778 kListHddBackends,
1779 kListHdds,
1780 kListDvds,
1781 kListFloppies,
1782 kListUsbHost,
1783 kListUsbFilters,
1784 kListSystemProperties,
1785 kListDhcpServers,
1786 kListExtPacks,
1787 kListGroups,
1788 kListNatNetworks,
1789 kListVideoInputDevices,
1790 kListScreenShotFormats,
1791 kListCloudProviders,
1792 kListCloudProfiles,
1793 kListCPUProfiles,
1794 kListHostDrives
1795};
1796
1797
1798/**
1799 * Produces the specified listing.
1800 *
1801 * @returns S_OK or some COM error code that has been reported in full.
1802 * @param enmList The list to produce.
1803 * @param fOptLong Long (@c true) or short list format.
1804 * @param pVirtualBox Reference to the IVirtualBox smart pointer.
1805 */
1806static HRESULT produceList(enum ListType_T enmCommand, bool fOptLong, bool fOptSorted, const ComPtr<IVirtualBox> &pVirtualBox)
1807{
1808 HRESULT rc = S_OK;
1809 switch (enmCommand)
1810 {
1811 case kListNotSpecified:
1812 AssertFailed();
1813 return E_FAIL;
1814
1815 case kListVMs:
1816 {
1817 /*
1818 * Get the list of all registered VMs
1819 */
1820 com::SafeIfaceArray<IMachine> machines;
1821 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1822 if (SUCCEEDED(rc))
1823 {
1824 /*
1825 * Display it.
1826 */
1827 if (!fOptSorted)
1828 {
1829 for (size_t i = 0; i < machines.size(); ++i)
1830 if (machines[i])
1831 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1832 }
1833 else
1834 {
1835 /*
1836 * Sort the list by name before displaying it.
1837 */
1838 std::vector<std::pair<com::Bstr, IMachine *> > sortedMachines;
1839 for (size_t i = 0; i < machines.size(); ++i)
1840 {
1841 IMachine *pMachine = machines[i];
1842 if (pMachine) /* no idea why we need to do this... */
1843 {
1844 Bstr bstrName;
1845 pMachine->COMGETTER(Name)(bstrName.asOutParam());
1846 sortedMachines.push_back(std::pair<com::Bstr, IMachine *>(bstrName, pMachine));
1847 }
1848 }
1849
1850 std::sort(sortedMachines.begin(), sortedMachines.end());
1851
1852 for (size_t i = 0; i < sortedMachines.size(); ++i)
1853 rc = showVMInfo(pVirtualBox, sortedMachines[i].second, NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1854 }
1855 }
1856 break;
1857 }
1858
1859 case kListRunningVMs:
1860 {
1861 /*
1862 * Get the list of all _running_ VMs
1863 */
1864 com::SafeIfaceArray<IMachine> machines;
1865 rc = pVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
1866 com::SafeArray<MachineState_T> states;
1867 if (SUCCEEDED(rc))
1868 rc = pVirtualBox->GetMachineStates(ComSafeArrayAsInParam(machines), ComSafeArrayAsOutParam(states));
1869 if (SUCCEEDED(rc))
1870 {
1871 /*
1872 * Iterate through the collection
1873 */
1874 for (size_t i = 0; i < machines.size(); ++i)
1875 {
1876 if (machines[i])
1877 {
1878 MachineState_T machineState = states[i];
1879 switch (machineState)
1880 {
1881 case MachineState_Running:
1882 case MachineState_Teleporting:
1883 case MachineState_LiveSnapshotting:
1884 case MachineState_Paused:
1885 case MachineState_TeleportingPausedVM:
1886 rc = showVMInfo(pVirtualBox, machines[i], NULL, fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
1887 break;
1888 default: break; /* Shut up MSC */
1889 }
1890 }
1891 }
1892 }
1893 break;
1894 }
1895
1896 case kListOsTypes:
1897 {
1898 com::SafeIfaceArray<IGuestOSType> coll;
1899 rc = pVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
1900 if (SUCCEEDED(rc))
1901 {
1902 /*
1903 * Iterate through the collection.
1904 */
1905 for (size_t i = 0; i < coll.size(); ++i)
1906 {
1907 ComPtr<IGuestOSType> guestOS;
1908 guestOS = coll[i];
1909 Bstr guestId;
1910 guestOS->COMGETTER(Id)(guestId.asOutParam());
1911 RTPrintf("ID: %ls\n", guestId.raw());
1912 Bstr guestDescription;
1913 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
1914 RTPrintf("Description: %ls\n", guestDescription.raw());
1915 Bstr familyId;
1916 guestOS->COMGETTER(FamilyId)(familyId.asOutParam());
1917 RTPrintf("Family ID: %ls\n", familyId.raw());
1918 Bstr familyDescription;
1919 guestOS->COMGETTER(FamilyDescription)(familyDescription.asOutParam());
1920 RTPrintf("Family Desc: %ls\n", familyDescription.raw());
1921 BOOL is64Bit;
1922 guestOS->COMGETTER(Is64Bit)(&is64Bit);
1923 RTPrintf("64 bit: %RTbool\n", is64Bit);
1924 RTPrintf("\n");
1925 }
1926 }
1927 break;
1928 }
1929
1930 case kListHostDvds:
1931 {
1932 ComPtr<IHost> host;
1933 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1934 com::SafeIfaceArray<IMedium> coll;
1935 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
1936 if (SUCCEEDED(rc))
1937 {
1938 for (size_t i = 0; i < coll.size(); ++i)
1939 {
1940 ComPtr<IMedium> dvdDrive = coll[i];
1941 Bstr uuid;
1942 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
1943 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1944 Bstr location;
1945 dvdDrive->COMGETTER(Location)(location.asOutParam());
1946 RTPrintf("Name: %ls\n\n", location.raw());
1947 }
1948 }
1949 break;
1950 }
1951
1952 case kListHostFloppies:
1953 {
1954 ComPtr<IHost> host;
1955 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(host.asOutParam()));
1956 com::SafeIfaceArray<IMedium> coll;
1957 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
1958 if (SUCCEEDED(rc))
1959 {
1960 for (size_t i = 0; i < coll.size(); ++i)
1961 {
1962 ComPtr<IMedium> floppyDrive = coll[i];
1963 Bstr uuid;
1964 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
1965 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
1966 Bstr location;
1967 floppyDrive->COMGETTER(Location)(location.asOutParam());
1968 RTPrintf("Name: %ls\n\n", location.raw());
1969 }
1970 }
1971 break;
1972 }
1973
1974 case kListInternalNetworks:
1975 rc = listInternalNetworks(pVirtualBox);
1976 break;
1977
1978 case kListBridgedInterfaces:
1979#if defined(VBOX_WITH_NETFLT)
1980 case kListHostOnlyInterfaces:
1981#endif
1982 rc = listNetworkInterfaces(pVirtualBox, enmCommand == kListBridgedInterfaces);
1983 break;
1984
1985#if defined(VBOX_WITH_CLOUD_NET)
1986 case kListCloudNetworks:
1987 rc = listCloudNetworks(pVirtualBox);
1988 break;
1989#endif
1990 case kListHostInfo:
1991 rc = listHostInfo(pVirtualBox);
1992 break;
1993
1994 case kListHostCpuIDs:
1995 {
1996 ComPtr<IHost> Host;
1997 CHECK_ERROR(pVirtualBox, COMGETTER(Host)(Host.asOutParam()));
1998
1999 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
2000 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
2001 static uint32_t const s_auCpuIdRanges[] =
2002 {
2003 UINT32_C(0x00000000), UINT32_C(0x0000007f),
2004 UINT32_C(0x80000000), UINT32_C(0x8000007f),
2005 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
2006 };
2007 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
2008 {
2009 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
2010 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
2011 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
2012 continue;
2013 cLeafs++;
2014 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
2015 {
2016 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
2017 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
2018 }
2019 }
2020 break;
2021 }
2022
2023 case kListHddBackends:
2024 rc = listHddBackends(pVirtualBox);
2025 break;
2026
2027 case kListHdds:
2028 {
2029 com::SafeIfaceArray<IMedium> hdds;
2030 CHECK_ERROR(pVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
2031 rc = listMedia(pVirtualBox, hdds, "base", fOptLong);
2032 break;
2033 }
2034
2035 case kListDvds:
2036 {
2037 com::SafeIfaceArray<IMedium> dvds;
2038 CHECK_ERROR(pVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
2039 rc = listMedia(pVirtualBox, dvds, NULL, fOptLong);
2040 break;
2041 }
2042
2043 case kListFloppies:
2044 {
2045 com::SafeIfaceArray<IMedium> floppies;
2046 CHECK_ERROR(pVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
2047 rc = listMedia(pVirtualBox, floppies, NULL, fOptLong);
2048 break;
2049 }
2050
2051 case kListUsbHost:
2052 rc = listUsbHost(pVirtualBox);
2053 break;
2054
2055 case kListUsbFilters:
2056 rc = listUsbFilters(pVirtualBox);
2057 break;
2058
2059 case kListSystemProperties:
2060 rc = listSystemProperties(pVirtualBox);
2061 break;
2062
2063 case kListDhcpServers:
2064 rc = listDhcpServers(pVirtualBox);
2065 break;
2066
2067 case kListExtPacks:
2068 rc = listExtensionPacks(pVirtualBox);
2069 break;
2070
2071 case kListGroups:
2072 rc = listGroups(pVirtualBox);
2073 break;
2074
2075 case kListNatNetworks:
2076 {
2077 com::SafeIfaceArray<INATNetwork> nets;
2078 CHECK_ERROR(pVirtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(nets)));
2079 for (size_t i = 0; i < nets.size(); ++i)
2080 {
2081 ComPtr<INATNetwork> net = nets[i];
2082 Bstr netName;
2083 net->COMGETTER(NetworkName)(netName.asOutParam());
2084 RTPrintf("NetworkName: %ls\n", netName.raw());
2085 Bstr gateway;
2086 net->COMGETTER(Gateway)(gateway.asOutParam());
2087 RTPrintf("IP: %ls\n", gateway.raw());
2088 Bstr network;
2089 net->COMGETTER(Network)(network.asOutParam());
2090 RTPrintf("Network: %ls\n", network.raw());
2091 BOOL fEnabled;
2092 net->COMGETTER(IPv6Enabled)(&fEnabled);
2093 RTPrintf("IPv6 Enabled: %s\n", fEnabled ? "Yes" : "No");
2094 Bstr ipv6prefix;
2095 net->COMGETTER(IPv6Prefix)(ipv6prefix.asOutParam());
2096 RTPrintf("IPv6 Prefix: %ls\n", ipv6prefix.raw());
2097 net->COMGETTER(NeedDhcpServer)(&fEnabled);
2098 RTPrintf("DHCP Enabled: %s\n", fEnabled ? "Yes" : "No");
2099 net->COMGETTER(Enabled)(&fEnabled);
2100 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
2101
2102#define PRINT_STRING_ARRAY(title) \
2103 if (strs.size() > 0) \
2104 { \
2105 RTPrintf(title); \
2106 size_t j = 0; \
2107 for (;j < strs.size(); ++j) \
2108 RTPrintf(" %s\n", Utf8Str(strs[j]).c_str()); \
2109 }
2110
2111 com::SafeArray<BSTR> strs;
2112
2113 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(strs)));
2114 PRINT_STRING_ARRAY("Port-forwarding (ipv4)\n");
2115 strs.setNull();
2116
2117 CHECK_ERROR(nets[i], COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(strs)));
2118 PRINT_STRING_ARRAY("Port-forwarding (ipv6)\n");
2119 strs.setNull();
2120
2121 CHECK_ERROR(nets[i], COMGETTER(LocalMappings)(ComSafeArrayAsOutParam(strs)));
2122 PRINT_STRING_ARRAY("loopback mappings (ipv4)\n");
2123 strs.setNull();
2124
2125#undef PRINT_STRING_ARRAY
2126 RTPrintf("\n");
2127 }
2128 break;
2129 }
2130
2131 case kListVideoInputDevices:
2132 rc = listVideoInputDevices(pVirtualBox);
2133 break;
2134
2135 case kListScreenShotFormats:
2136 rc = listScreenShotFormats(pVirtualBox);
2137 break;
2138
2139 case kListCloudProviders:
2140 rc = listCloudProviders(pVirtualBox);
2141 break;
2142
2143 case kListCloudProfiles:
2144 rc = listCloudProfiles(pVirtualBox, fOptLong);
2145 break;
2146
2147 case kListCPUProfiles:
2148 rc = listCPUProfiles(pVirtualBox, fOptLong, fOptSorted);
2149 break;
2150
2151 case kListHostDrives:
2152 rc = listHostDrives(pVirtualBox, fOptLong);
2153 break;
2154 /* No default here, want gcc warnings. */
2155
2156 } /* end switch */
2157
2158 return rc;
2159}
2160
2161/**
2162 * Handles the 'list' command.
2163 *
2164 * @returns Appropriate exit code.
2165 * @param a Handler argument.
2166 */
2167RTEXITCODE handleList(HandlerArg *a)
2168{
2169 bool fOptLong = false;
2170 bool fOptMultiple = false;
2171 bool fOptSorted = false;
2172 enum ListType_T enmOptCommand = kListNotSpecified;
2173
2174 static const RTGETOPTDEF s_aListOptions[] =
2175 {
2176 { "--long", 'l', RTGETOPT_REQ_NOTHING },
2177 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
2178 { "--sorted", 's', RTGETOPT_REQ_NOTHING },
2179 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
2180 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
2181 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
2182 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
2183 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
2184 { "intnets", kListInternalNetworks, RTGETOPT_REQ_NOTHING },
2185 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
2186 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
2187#if defined(VBOX_WITH_NETFLT)
2188 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
2189#endif
2190#if defined(VBOX_WITH_CLOUD_NET)
2191 { "cloudnets", kListCloudNetworks, RTGETOPT_REQ_NOTHING },
2192#endif
2193 { "natnetworks", kListNatNetworks, RTGETOPT_REQ_NOTHING },
2194 { "natnets", kListNatNetworks, RTGETOPT_REQ_NOTHING },
2195 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
2196 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
2197 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
2198 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
2199 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
2200 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
2201 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
2202 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
2203 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
2204 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
2205 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
2206 { "groups", kListGroups, RTGETOPT_REQ_NOTHING },
2207 { "webcams", kListVideoInputDevices, RTGETOPT_REQ_NOTHING },
2208 { "screenshotformats", kListScreenShotFormats, RTGETOPT_REQ_NOTHING },
2209 { "cloudproviders", kListCloudProviders, RTGETOPT_REQ_NOTHING },
2210 { "cloudprofiles", kListCloudProfiles, RTGETOPT_REQ_NOTHING },
2211 { "cpu-profiles", kListCPUProfiles, RTGETOPT_REQ_NOTHING },
2212 { "hostdrives", kListHostDrives, RTGETOPT_REQ_NOTHING },
2213 };
2214
2215 int ch;
2216 RTGETOPTUNION ValueUnion;
2217 RTGETOPTSTATE GetState;
2218 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
2219 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
2220 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
2221 {
2222 switch (ch)
2223 {
2224 case 'l': /* --long */
2225 fOptLong = true;
2226 break;
2227
2228 case 's':
2229 fOptSorted = true;
2230 break;
2231
2232 case 'm':
2233 fOptMultiple = true;
2234 if (enmOptCommand == kListNotSpecified)
2235 break;
2236 ch = enmOptCommand;
2237 RT_FALL_THRU();
2238
2239 case kListVMs:
2240 case kListRunningVMs:
2241 case kListOsTypes:
2242 case kListHostDvds:
2243 case kListHostFloppies:
2244 case kListInternalNetworks:
2245 case kListBridgedInterfaces:
2246#if defined(VBOX_WITH_NETFLT)
2247 case kListHostOnlyInterfaces:
2248#endif
2249#if defined(VBOX_WITH_CLOUD_NET)
2250 case kListCloudNetworks:
2251#endif
2252 case kListHostInfo:
2253 case kListHostCpuIDs:
2254 case kListHddBackends:
2255 case kListHdds:
2256 case kListDvds:
2257 case kListFloppies:
2258 case kListUsbHost:
2259 case kListUsbFilters:
2260 case kListSystemProperties:
2261 case kListDhcpServers:
2262 case kListExtPacks:
2263 case kListGroups:
2264 case kListNatNetworks:
2265 case kListVideoInputDevices:
2266 case kListScreenShotFormats:
2267 case kListCloudProviders:
2268 case kListCloudProfiles:
2269 case kListCPUProfiles:
2270 case kListHostDrives:
2271 enmOptCommand = (enum ListType_T)ch;
2272 if (fOptMultiple)
2273 {
2274 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
2275 if (FAILED(hrc))
2276 return RTEXITCODE_FAILURE;
2277 }
2278 break;
2279
2280 case VINF_GETOPT_NOT_OPTION:
2281 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
2282
2283 default:
2284 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
2285 }
2286 }
2287
2288 /*
2289 * If not in multiple list mode, we have to produce the list now.
2290 */
2291 if (enmOptCommand == kListNotSpecified)
2292 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
2293 if (!fOptMultiple)
2294 {
2295 HRESULT hrc = produceList(enmOptCommand, fOptLong, fOptSorted, a->virtualBox);
2296 if (FAILED(hrc))
2297 return RTEXITCODE_FAILURE;
2298 }
2299
2300 return RTEXITCODE_SUCCESS;
2301}
2302
2303#endif /* !VBOX_ONLY_DOCS */
2304/* 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