VirtualBox

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

Last change on this file since 86605 was 86142, checked in by vboxsync, 4 years ago

VBoxManage/list hostdrives: Plain text explanation why some IHostDrive properties aren't always available. Only assume limited-mode if we get E_ACCESSDENIED, other errors should be reported properly. Reworked the error reporting just for fun. :-) bugref:9224

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