VirtualBox

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

Last change on this file since 33915 was 33915, checked in by vboxsync, 14 years ago

Main, QT/FE, VBoxManage: per-chipset controller count limits

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 44.5 KB
Line 
1/* $Id: VBoxManageList.cpp 33915 2010-11-09 16:44:39Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2010 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* Header Files *
22*******************************************************************************/
23#include <VBox/com/com.h>
24#include <VBox/com/string.h>
25#include <VBox/com/Guid.h>
26#include <VBox/com/array.h>
27#include <VBox/com/ErrorInfo.h>
28#include <VBox/com/errorprint.h>
29
30#include <VBox/com/VirtualBox.h>
31
32#include <VBox/log.h>
33#include <iprt/stream.h>
34#include <iprt/string.h>
35#include <iprt/time.h>
36#include <iprt/getopt.h>
37#include <iprt/ctype.h>
38
39#include "VBoxManage.h"
40using namespace com;
41
42#ifdef VBOX_WITH_HOSTNETIF_API
43static const char *getHostIfMediumTypeText(HostNetworkInterfaceMediumType_T enmType)
44{
45 switch (enmType)
46 {
47 case HostNetworkInterfaceMediumType_Ethernet: return "Ethernet";
48 case HostNetworkInterfaceMediumType_PPP: return "PPP";
49 case HostNetworkInterfaceMediumType_SLIP: return "SLIP";
50 }
51 return "Unknown";
52}
53
54static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
55{
56 switch (enmStatus)
57 {
58 case HostNetworkInterfaceStatus_Up: return "Up";
59 case HostNetworkInterfaceStatus_Down: return "Down";
60 }
61 return "Unknown";
62}
63#endif /* VBOX_WITH_HOSTNETIF_API */
64
65static const char*getDeviceTypeText(DeviceType_T enmType)
66{
67 switch (enmType)
68 {
69 case DeviceType_HardDisk: return "HardDisk";
70 case DeviceType_DVD: return "DVD";
71 case DeviceType_Floppy: return "Floppy";
72 }
73 return "Unknown";
74}
75
76static void listMedia(const ComPtr<IVirtualBox> aVirtualBox,
77 const com::SafeIfaceArray<IMedium> &aMedia,
78 const char *pszParentUUIDStr)
79{
80 HRESULT rc;
81 for (size_t i = 0; i < aMedia.size(); ++i)
82 {
83 ComPtr<IMedium> pMedium = aMedia[i];
84 Bstr uuid;
85 pMedium->COMGETTER(Id)(uuid.asOutParam());
86 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
87 if (pszParentUUIDStr)
88 RTPrintf("Parent UUID: %s\n", pszParentUUIDStr);
89 Bstr format;
90 pMedium->COMGETTER(Format)(format.asOutParam());
91 RTPrintf("Format: %lS\n", format.raw());
92 Bstr filepath;
93 pMedium->COMGETTER(Location)(filepath.asOutParam());
94 RTPrintf("Location: %lS\n", filepath.raw());
95
96 MediumState_T enmState;
97 pMedium->RefreshState(&enmState);
98 const char *stateStr = "unknown";
99 switch (enmState)
100 {
101 case MediumState_NotCreated:
102 stateStr = "not created";
103 break;
104 case MediumState_Created:
105 stateStr = "created";
106 break;
107 case MediumState_LockedRead:
108 stateStr = "locked read";
109 break;
110 case MediumState_LockedWrite:
111 stateStr = "locked write";
112 break;
113 case MediumState_Inaccessible:
114 stateStr = "inaccessible";
115 break;
116 case MediumState_Creating:
117 stateStr = "creating";
118 break;
119 case MediumState_Deleting:
120 stateStr = "deleting";
121 break;
122 }
123 RTPrintf("State: %s\n", stateStr);
124
125 MediumType_T type;
126 pMedium->COMGETTER(Type)(&type);
127 const char *typeStr = "unknown";
128 switch (type)
129 {
130 case MediumType_Normal:
131 typeStr = "normal";
132 break;
133 case MediumType_Immutable:
134 typeStr = "immutable";
135 break;
136 case MediumType_Writethrough:
137 typeStr = "writethrough";
138 break;
139 case MediumType_Shareable:
140 typeStr = "shareable";
141 break;
142 case MediumType_Readonly:
143 typeStr = "readonly";
144 break;
145 }
146 RTPrintf("Type: %s\n", typeStr);
147
148 com::SafeArray<BSTR> machineIds;
149 pMedium->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
150 for (size_t j = 0; j < machineIds.size(); ++j)
151 {
152 ComPtr<IMachine> machine;
153 CHECK_ERROR(aVirtualBox, FindMachine(machineIds[j], machine.asOutParam()));
154 ASSERT(machine);
155 Bstr name;
156 machine->COMGETTER(Name)(name.asOutParam());
157 RTPrintf("%s%lS (UUID: %lS)",
158 j == 0 ? "Usage: " : " ",
159 name.raw(), machineIds[j]);
160 com::SafeArray<BSTR> snapshotIds;
161 pMedium->GetSnapshotIds(machineIds[j],
162 ComSafeArrayAsOutParam(snapshotIds));
163 for (size_t k = 0; k < snapshotIds.size(); ++k)
164 {
165 ComPtr<ISnapshot> snapshot;
166 machine->FindSnapshot(snapshotIds[k], snapshot.asOutParam());
167 if (snapshot)
168 {
169 Bstr snapshotName;
170 snapshot->COMGETTER(Name)(snapshotName.asOutParam());
171 RTPrintf(" [%lS (UUID: %lS)]", snapshotName.raw(), snapshotIds[k]);
172 }
173 }
174 RTPrintf("\n");
175 }
176 RTPrintf("\n");
177
178 com::SafeIfaceArray<IMedium> children;
179 CHECK_ERROR(pMedium, COMGETTER(Children)(ComSafeArrayAsOutParam(children)));
180 if (children.size() > 0)
181 {
182 // depth first listing of child media
183 listMedia(aVirtualBox, children, Utf8Str(uuid).c_str());
184 }
185 }
186}
187
188
189/**
190 * List extension packs.
191 *
192 * @returns See produceList.
193 * @param rptrVirtualBox Reference to the IVirtualBox smart pointer.
194 */
195static HRESULT listExtensionPacks(const ComPtr<IVirtualBox> &rptrVirtualBox)
196{
197 ComObjPtr<IExtPackManager> ptrExtPackMgr;
198 CHECK_ERROR2_RET(rptrVirtualBox, COMGETTER(ExtensionPackManager)(ptrExtPackMgr.asOutParam()), hrcCheck);
199
200 SafeIfaceArray<IExtPack> extPacks;
201 CHECK_ERROR2_RET(ptrExtPackMgr, COMGETTER(InstalledExtPacks)(ComSafeArrayAsOutParam(extPacks)), hrcCheck);
202 RTPrintf("Extension Packs: %u\n", extPacks.size());
203
204 HRESULT hrc = S_OK;
205 for (size_t i = 0; i < extPacks.size(); i++)
206 {
207 /* Read all the properties. */
208 Bstr bstrName;
209 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Name)(bstrName.asOutParam()), hrc = hrcCheck; bstrName.setNull());
210 Bstr bstrDesc;
211 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Description)(bstrDesc.asOutParam()), hrc = hrcCheck; bstrDesc.setNull());
212 Bstr bstrVersion;
213 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Version)(bstrVersion.asOutParam()), hrc = hrcCheck; bstrVersion.setNull());
214 ULONG uRevision;
215 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Revision)(&uRevision), hrc = hrcCheck; uRevision = 0);
216 BOOL fUsable;
217 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(Usable)(&fUsable), hrc = hrcCheck; fUsable = FALSE);
218 Bstr bstrWhy;
219 CHECK_ERROR2_STMT(extPacks[i], COMGETTER(WhyUnusable)(bstrWhy.asOutParam()), hrc = hrcCheck; bstrWhy.setNull());
220
221 /* Display them. */
222 if (i)
223 RTPrintf("\n");
224 RTPrintf("Pack no.%2zu: %lS\n"
225 "Version: %lS\n"
226 "Revision: %u\n"
227 "Description: %lS\n"
228 "Usable: %RTbool\n"
229 "Why unusable: %lS\n",
230 i, bstrName.raw(),
231 bstrVersion.raw(),
232 uRevision,
233 bstrDesc.raw(),
234 fUsable != FALSE,
235 bstrWhy.raw());
236 }
237 return hrc;
238}
239
240
241/**
242 * The type of lists we can produce.
243 */
244enum enmListType
245{
246 kListNotSpecified = 1000,
247 kListVMs,
248 kListRunningVMs,
249 kListOsTypes,
250 kListHostDvds,
251 kListHostFloppies,
252 kListBridgedInterfaces,
253#if defined(VBOX_WITH_NETFLT)
254 kListHostOnlyInterfaces,
255#endif
256 kListHostCpuIDs,
257 kListHostInfo,
258 kListHddBackends,
259 kListHdds,
260 kListDvds,
261 kListFloppies,
262 kListUsbHost,
263 kListUsbFilters,
264 kListSystemProperties,
265 kListDhcpServers,
266 kListVrdeLibraries,
267 kListExtPacks
268};
269
270
271/**
272 * Produces the specified listing.
273 *
274 * @returns S_OK or some COM error code that has been reported in full.
275 * @param enmList The list to produce.
276 * @param fOptLong Long (@c true) or short list format.
277 * @param rptrVirtualBox Reference to the IVirtualBox smart pointer.
278 */
279static HRESULT produceList(enum enmListType enmCommand, bool fOptLong, const ComPtr<IVirtualBox> &rptrVirtualBox)
280{
281 HRESULT rc = S_OK;
282 switch (enmCommand)
283 {
284 case kListNotSpecified:
285 AssertFailed();
286 return E_FAIL;
287
288 case kListVMs:
289 {
290 /*
291 * Get the list of all registered VMs
292 */
293 com::SafeIfaceArray<IMachine> machines;
294 rc = rptrVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
295 if (SUCCEEDED(rc))
296 {
297 /*
298 * Iterate through the collection
299 */
300 for (size_t i = 0; i < machines.size(); ++i)
301 {
302 if (machines[i])
303 rc = showVMInfo(rptrVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
304 }
305 }
306 break;
307 }
308
309 case kListRunningVMs:
310 {
311 /*
312 * Get the list of all _running_ VMs
313 */
314 com::SafeIfaceArray<IMachine> machines;
315 rc = rptrVirtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam(machines));
316 if (SUCCEEDED(rc))
317 {
318 /*
319 * Iterate through the collection
320 */
321 for (size_t i = 0; i < machines.size(); ++i)
322 {
323 if (machines[i])
324 {
325 MachineState_T machineState;
326 rc = machines[i]->COMGETTER(State)(&machineState);
327 if (SUCCEEDED(rc))
328 {
329 switch (machineState)
330 {
331 case MachineState_Running:
332 case MachineState_Teleporting:
333 case MachineState_LiveSnapshotting:
334 case MachineState_Paused:
335 case MachineState_TeleportingPausedVM:
336 rc = showVMInfo(rptrVirtualBox, machines[i], fOptLong ? VMINFO_STANDARD : VMINFO_COMPACT);
337 break;
338 }
339 }
340 }
341 }
342 }
343 break;
344 }
345
346 case kListOsTypes:
347 {
348 com::SafeIfaceArray<IGuestOSType> coll;
349 rc = rptrVirtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
350 if (SUCCEEDED(rc))
351 {
352 /*
353 * Iterate through the collection.
354 */
355 for (size_t i = 0; i < coll.size(); ++i)
356 {
357 ComPtr<IGuestOSType> guestOS;
358 guestOS = coll[i];
359 Bstr guestId;
360 guestOS->COMGETTER(Id)(guestId.asOutParam());
361 RTPrintf("ID: %lS\n", guestId.raw());
362 Bstr guestDescription;
363 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
364 RTPrintf("Description: %lS\n\n", guestDescription.raw());
365 }
366 }
367 break;
368 }
369
370 case kListHostDvds:
371 {
372 ComPtr<IHost> host;
373 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
374 com::SafeIfaceArray<IMedium> coll;
375 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
376 if (SUCCEEDED(rc))
377 {
378 for (size_t i = 0; i < coll.size(); ++i)
379 {
380 ComPtr<IMedium> dvdDrive = coll[i];
381 Bstr uuid;
382 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
383 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
384 Bstr name;
385 dvdDrive->COMGETTER(Name)(name.asOutParam());
386 RTPrintf("Name: %lS\n\n", name.raw());
387 }
388 }
389 break;
390 }
391
392 case kListHostFloppies:
393 {
394 ComPtr<IHost> host;
395 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
396 com::SafeIfaceArray<IMedium> coll;
397 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
398 if (SUCCEEDED(rc))
399 {
400 for (size_t i = 0; i < coll.size(); ++i)
401 {
402 ComPtr<IMedium> floppyDrive = coll[i];
403 Bstr uuid;
404 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
405 RTPrintf("UUID: %s\n", Utf8Str(uuid).c_str());
406 Bstr name;
407 floppyDrive->COMGETTER(Name)(name.asOutParam());
408 RTPrintf("Name: %lS\n\n", name.raw());
409 }
410 }
411 break;
412 }
413
414 /** @todo function. */
415 case kListBridgedInterfaces:
416#if defined(VBOX_WITH_NETFLT)
417 case kListHostOnlyInterfaces:
418#endif
419 {
420 ComPtr<IHost> host;
421 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()));
422 com::SafeIfaceArray<IHostNetworkInterface> hostNetworkInterfaces;
423#if defined(VBOX_WITH_NETFLT)
424 if (enmCommand == kListBridgedInterfaces)
425 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
426 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
427 else
428 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
429 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
430#else
431 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
432#endif
433 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
434 {
435 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
436#ifndef VBOX_WITH_HOSTNETIF_API
437 Bstr interfaceName;
438 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
439 RTPrintf("Name: %lS\n", interfaceName.raw());
440 Guid interfaceGuid;
441 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
442 RTPrintf("GUID: %lS\n\n", Bstr(interfaceGuid.toString()).raw());
443#else /* VBOX_WITH_HOSTNETIF_API */
444 Bstr interfaceName;
445 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
446 RTPrintf("Name: %lS\n", interfaceName.raw());
447 Bstr interfaceGuid;
448 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
449 RTPrintf("GUID: %lS\n", interfaceGuid.raw());
450 BOOL bDhcpEnabled;
451 networkInterface->COMGETTER(DhcpEnabled)(&bDhcpEnabled);
452 RTPrintf("Dhcp: %s\n", bDhcpEnabled ? "Enabled" : "Disabled");
453
454 Bstr IPAddress;
455 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
456 RTPrintf("IPAddress: %lS\n", IPAddress.raw());
457 Bstr NetworkMask;
458 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
459 RTPrintf("NetworkMask: %lS\n", NetworkMask.raw());
460 Bstr IPV6Address;
461 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
462 RTPrintf("IPV6Address: %lS\n", IPV6Address.raw());
463 ULONG IPV6NetworkMaskPrefixLength;
464 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
465 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
466 Bstr HardwareAddress;
467 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
468 RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
469 HostNetworkInterfaceMediumType_T Type;
470 networkInterface->COMGETTER(MediumType)(&Type);
471 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
472 HostNetworkInterfaceStatus_T Status;
473 networkInterface->COMGETTER(Status)(&Status);
474 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
475 Bstr netName;
476 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
477 RTPrintf("VBoxNetworkName: %lS\n\n", netName.raw());
478#endif
479 }
480 break;
481 }
482
483 /** @todo function. */
484 case kListHostInfo:
485 {
486 ComPtr<IHost> Host;
487 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()));
488
489 RTPrintf("Host Information:\n\n");
490
491 LONG64 u64UtcTime = 0;
492 CHECK_ERROR(Host, COMGETTER(UTCTime)(&u64UtcTime));
493 RTTIMESPEC timeSpec;
494 char szTime[32];
495 RTPrintf("Host time: %s\n", RTTimeSpecToString(RTTimeSpecSetMilli(&timeSpec, u64UtcTime), szTime, sizeof(szTime)));
496
497 ULONG processorOnlineCount = 0;
498 CHECK_ERROR(Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
499 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
500 ULONG processorCount = 0;
501 CHECK_ERROR(Host, COMGETTER(ProcessorCount)(&processorCount));
502 RTPrintf("Processor count: %lu\n", processorCount);
503 ULONG processorSpeed = 0;
504 Bstr processorDescription;
505 for (ULONG i = 0; i < processorCount; i++)
506 {
507 CHECK_ERROR(Host, GetProcessorSpeed(i, &processorSpeed));
508 if (processorSpeed)
509 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
510 else
511 RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
512 CHECK_ERROR(Host, GetProcessorDescription(i, processorDescription.asOutParam()));
513 RTPrintf("Processor#%u description: %lS\n", i, processorDescription.raw());
514 }
515
516 ULONG memorySize = 0;
517 CHECK_ERROR(Host, COMGETTER(MemorySize)(&memorySize));
518 RTPrintf("Memory size: %lu MByte\n", memorySize);
519
520 ULONG memoryAvailable = 0;
521 CHECK_ERROR(Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
522 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
523
524 Bstr operatingSystem;
525 CHECK_ERROR(Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
526 RTPrintf("Operating system: %lS\n", operatingSystem.raw());
527
528 Bstr oSVersion;
529 CHECK_ERROR(Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
530 RTPrintf("Operating system version: %lS\n", oSVersion.raw());
531 break;
532 }
533
534 case kListHostCpuIDs:
535 {
536 ComPtr<IHost> Host;
537 CHECK_ERROR(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()));
538
539 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
540 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
541 static uint32_t const s_auCpuIdRanges[] =
542 {
543 UINT32_C(0x00000000), UINT32_C(0x0000007f),
544 UINT32_C(0x80000000), UINT32_C(0x8000007f),
545 UINT32_C(0xc0000000), UINT32_C(0xc000007f)
546 };
547 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
548 {
549 ULONG uEAX, uEBX, uECX, uEDX, cLeafs;
550 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, s_auCpuIdRanges[i], 0, &cLeafs, &uEBX, &uECX, &uEDX));
551 if (cLeafs < s_auCpuIdRanges[i] || cLeafs > s_auCpuIdRanges[i+1])
552 continue;
553 cLeafs++;
554 for (ULONG iLeaf = s_auCpuIdRanges[i]; iLeaf <= cLeafs; iLeaf++)
555 {
556 CHECK_ERROR(Host, GetProcessorCPUIDLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
557 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
558 }
559 }
560 break;
561 }
562
563 /** @todo function. */
564 case kListHddBackends:
565 {
566 ComPtr<ISystemProperties> systemProperties;
567 CHECK_ERROR(rptrVirtualBox, COMGETTER(SystemProperties)(systemProperties.asOutParam()));
568 com::SafeIfaceArray<IMediumFormat> mediumFormats;
569 CHECK_ERROR(systemProperties, COMGETTER(MediumFormats)(ComSafeArrayAsOutParam(mediumFormats)));
570
571 RTPrintf("Supported hard disk backends:\n\n");
572 for (size_t i = 0; i < mediumFormats.size(); ++i)
573 {
574 /* General information */
575 Bstr id;
576 CHECK_ERROR(mediumFormats[i], COMGETTER(Id)(id.asOutParam()));
577
578 Bstr description;
579 CHECK_ERROR(mediumFormats[i],
580 COMGETTER(Id)(description.asOutParam()));
581
582 ULONG caps;
583 CHECK_ERROR(mediumFormats[i],
584 COMGETTER(Capabilities)(&caps));
585
586 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
587 i, id.raw(), description.raw(), caps);
588
589 /* File extensions */
590 com::SafeArray <BSTR> fileExtensions;
591 com::SafeArray <DeviceType_T> deviceTypes;
592 CHECK_ERROR(mediumFormats[i],
593 DescribeFileExtensions(ComSafeArrayAsOutParam(fileExtensions), ComSafeArrayAsOutParam(deviceTypes)));
594 for (size_t j = 0; j < fileExtensions.size(); ++j)
595 {
596 RTPrintf("%ls (%s)", Bstr(fileExtensions[j]).raw(), getDeviceTypeText(deviceTypes[j]));
597 if (j != fileExtensions.size()-1)
598 RTPrintf(",");
599 }
600 RTPrintf("'");
601
602 /* Configuration keys */
603 com::SafeArray <BSTR> propertyNames;
604 com::SafeArray <BSTR> propertyDescriptions;
605 com::SafeArray <DataType_T> propertyTypes;
606 com::SafeArray <ULONG> propertyFlags;
607 com::SafeArray <BSTR> propertyDefaults;
608 CHECK_ERROR(mediumFormats[i],
609 DescribeProperties(ComSafeArrayAsOutParam(propertyNames),
610 ComSafeArrayAsOutParam(propertyDescriptions),
611 ComSafeArrayAsOutParam(propertyTypes),
612 ComSafeArrayAsOutParam(propertyFlags),
613 ComSafeArrayAsOutParam(propertyDefaults)));
614
615 RTPrintf(" properties=(");
616 if (propertyNames.size() > 0)
617 {
618 for (size_t j = 0; j < propertyNames.size(); ++j)
619 {
620 RTPrintf("\n name='%ls' desc='%ls' type=",
621 Bstr(propertyNames[j]).raw(), Bstr(propertyDescriptions[j]).raw());
622 switch (propertyTypes[j])
623 {
624 case DataType_Int32: RTPrintf("int"); break;
625 case DataType_Int8: RTPrintf("byte"); break;
626 case DataType_String: RTPrintf("string"); break;
627 }
628 RTPrintf(" flags=%#04x", propertyFlags[j]);
629 RTPrintf(" default='%ls'", Bstr(propertyDefaults[j]).raw());
630 if (j != propertyNames.size()-1)
631 RTPrintf(", ");
632 }
633 }
634 RTPrintf(")\n");
635 }
636 break;
637 }
638
639 case kListHdds:
640 {
641 com::SafeIfaceArray<IMedium> hdds;
642 CHECK_ERROR(rptrVirtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam(hdds)));
643 listMedia(rptrVirtualBox, hdds, "base");
644 break;
645 }
646
647 case kListDvds:
648 {
649 com::SafeIfaceArray<IMedium> dvds;
650 CHECK_ERROR(rptrVirtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
651 listMedia(rptrVirtualBox, dvds, NULL);
652 break;
653 }
654
655 case kListFloppies:
656 {
657 com::SafeIfaceArray<IMedium> floppies;
658 CHECK_ERROR(rptrVirtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
659 listMedia(rptrVirtualBox, floppies, NULL);
660 break;
661 }
662
663 /** @todo function. */
664 case kListUsbHost:
665 {
666 ComPtr<IHost> Host;
667 CHECK_ERROR_RET(rptrVirtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
668
669 SafeIfaceArray<IHostUSBDevice> CollPtr;
670 CHECK_ERROR_RET(Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
671
672 RTPrintf("Host USB Devices:\n\n");
673
674 if (CollPtr.size() == 0)
675 {
676 RTPrintf("<none>\n\n");
677 }
678 else
679 {
680 for (size_t i = 0; i < CollPtr.size(); ++i)
681 {
682 ComPtr <IHostUSBDevice> dev = CollPtr[i];
683
684 /* Query info. */
685 Bstr id;
686 CHECK_ERROR_RET(dev, COMGETTER(Id)(id.asOutParam()), 1);
687 USHORT usVendorId;
688 CHECK_ERROR_RET(dev, COMGETTER(VendorId)(&usVendorId), 1);
689 USHORT usProductId;
690 CHECK_ERROR_RET(dev, COMGETTER(ProductId)(&usProductId), 1);
691 USHORT bcdRevision;
692 CHECK_ERROR_RET(dev, COMGETTER(Revision)(&bcdRevision), 1);
693
694 RTPrintf("UUID: %S\n"
695 "VendorId: %#06x (%04X)\n"
696 "ProductId: %#06x (%04X)\n"
697 "Revision: %u.%u (%02u%02u)\n",
698 Utf8Str(id).c_str(),
699 usVendorId, usVendorId, usProductId, usProductId,
700 bcdRevision >> 8, bcdRevision & 0xff,
701 bcdRevision >> 8, bcdRevision & 0xff);
702
703 /* optional stuff. */
704 Bstr bstr;
705 CHECK_ERROR_RET(dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
706 if (!bstr.isEmpty())
707 RTPrintf("Manufacturer: %lS\n", bstr.raw());
708 CHECK_ERROR_RET(dev, COMGETTER(Product)(bstr.asOutParam()), 1);
709 if (!bstr.isEmpty())
710 RTPrintf("Product: %lS\n", bstr.raw());
711 CHECK_ERROR_RET(dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
712 if (!bstr.isEmpty())
713 RTPrintf("SerialNumber: %lS\n", bstr.raw());
714 CHECK_ERROR_RET(dev, COMGETTER(Address)(bstr.asOutParam()), 1);
715 if (!bstr.isEmpty())
716 RTPrintf("Address: %lS\n", bstr.raw());
717
718 /* current state */
719 USBDeviceState_T state;
720 CHECK_ERROR_RET(dev, COMGETTER(State)(&state), 1);
721 const char *pszState = "?";
722 switch (state)
723 {
724 case USBDeviceState_NotSupported:
725 pszState = "Not supported";
726 break;
727 case USBDeviceState_Unavailable:
728 pszState = "Unavailable";
729 break;
730 case USBDeviceState_Busy:
731 pszState = "Busy";
732 break;
733 case USBDeviceState_Available:
734 pszState = "Available";
735 break;
736 case USBDeviceState_Held:
737 pszState = "Held";
738 break;
739 case USBDeviceState_Captured:
740 pszState = "Captured";
741 break;
742 default:
743 ASSERT(false);
744 break;
745 }
746 RTPrintf("Current State: %s\n\n", pszState);
747 }
748 }
749 break;
750 }
751
752 /** @todo function. */
753 case kListUsbFilters:
754 {
755 RTPrintf("Global USB Device Filters:\n\n");
756
757 ComPtr<IHost> host;
758 CHECK_ERROR_RET(rptrVirtualBox, COMGETTER(Host)(host.asOutParam()), 1);
759
760 SafeIfaceArray<IHostUSBDeviceFilter> coll;
761 CHECK_ERROR_RET(host, COMGETTER(USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
762
763 if (coll.size() == 0)
764 {
765 RTPrintf("<none>\n\n");
766 }
767 else
768 {
769 for (size_t index = 0; index < coll.size(); ++index)
770 {
771 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
772
773 /* Query info. */
774
775 RTPrintf("Index: %zu\n", index);
776
777 BOOL active = FALSE;
778 CHECK_ERROR_RET(flt, COMGETTER(Active)(&active), 1);
779 RTPrintf("Active: %s\n", active ? "yes" : "no");
780
781 USBDeviceFilterAction_T action;
782 CHECK_ERROR_RET(flt, COMGETTER(Action)(&action), 1);
783 const char *pszAction = "<invalid>";
784 switch (action)
785 {
786 case USBDeviceFilterAction_Ignore:
787 pszAction = "Ignore";
788 break;
789 case USBDeviceFilterAction_Hold:
790 pszAction = "Hold";
791 break;
792 default:
793 break;
794 }
795 RTPrintf("Action: %s\n", pszAction);
796
797 Bstr bstr;
798 CHECK_ERROR_RET(flt, COMGETTER(Name)(bstr.asOutParam()), 1);
799 RTPrintf("Name: %lS\n", bstr.raw());
800 CHECK_ERROR_RET(flt, COMGETTER(VendorId)(bstr.asOutParam()), 1);
801 RTPrintf("VendorId: %lS\n", bstr.raw());
802 CHECK_ERROR_RET(flt, COMGETTER(ProductId)(bstr.asOutParam()), 1);
803 RTPrintf("ProductId: %lS\n", bstr.raw());
804 CHECK_ERROR_RET(flt, COMGETTER(Revision)(bstr.asOutParam()), 1);
805 RTPrintf("Revision: %lS\n", bstr.raw());
806 CHECK_ERROR_RET(flt, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
807 RTPrintf("Manufacturer: %lS\n", bstr.raw());
808 CHECK_ERROR_RET(flt, COMGETTER(Product)(bstr.asOutParam()), 1);
809 RTPrintf("Product: %lS\n", bstr.raw());
810 CHECK_ERROR_RET(flt, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
811 RTPrintf("Serial Number: %lS\n\n", bstr.raw());
812 }
813 }
814 break;
815 }
816
817 /** @todo function. */
818 case kListSystemProperties:
819 {
820 ComPtr<ISystemProperties> systemProperties;
821 rptrVirtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
822
823 Bstr str;
824 ULONG ulValue;
825 LONG64 i64Value;
826
827 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
828 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
829 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
830 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
831 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
832 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
833 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
834 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
835 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
836 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
837 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
838 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
839 systemProperties->COMGETTER(InfoVDSize)(&i64Value);
840 RTPrintf("Virtual disk limit (info): %lld Bytes\n", i64Value);
841 systemProperties->COMGETTER(NetworkAdapterCount)(&ulValue);
842 RTPrintf("Maximum Network Adapter count: %u\n", ulValue);
843 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
844 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
845 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
846 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
847 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
848 RTPrintf("Maximum Boot Position: %u\n", ulValue);
849 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_IDE, &ulValue);
850 RTPrintf("Maximum PIIX3 IDE Controllers: %u\n", ulValue);
851 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_IDE, &ulValue);
852 RTPrintf("Maximum ICH9 IDE Controllers: %u\n", ulValue);
853 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
854 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
855 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
856 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
857 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SATA, &ulValue);
858 RTPrintf("Maximum PIIX3 SATA Controllers: %u\n", ulValue);
859 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SATA, &ulValue);
860 RTPrintf("Maximum ICH9 SATA Controllers: %u\n", ulValue);
861 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
862 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
863 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
864 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
865 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SCSI, &ulValue);
866 RTPrintf("Maximum PIIX3 SCSI Controllers: %u\n", ulValue);
867 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SCSI, &ulValue);
868 RTPrintf("Maximum ICH9 SCSI Controllers: %u\n", ulValue);
869 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
870 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
871 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
872 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
873 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_SAS, &ulValue);
874 RTPrintf("Maximum SAS PIIX3 Controllers: %u\n", ulValue);
875 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_SAS, &ulValue);
876 RTPrintf("Maximum SAS ICH9 Controllers: %u\n", ulValue);
877 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SAS, &ulValue);
878 RTPrintf("Maximum SAS Port count: %u\n", ulValue);
879 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SAS, &ulValue);
880 RTPrintf("Maximum Devices per SAS Port: %u\n", ulValue);
881 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_PIIX3, StorageBus_Floppy, &ulValue);
882 RTPrintf("Maximum PIIX3 Floppy Controllers:%u\n", ulValue);
883 systemProperties->GetMaxInstancesOfStorageBus(ChipsetType_ICH9, StorageBus_Floppy, &ulValue);
884 RTPrintf("Maximum ICH9 Floppy Controllers: %u\n", ulValue);
885 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
886 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
887 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
888 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
889 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
890 RTPrintf("Default machine folder: %lS\n", str.raw());
891 systemProperties->COMGETTER(VRDEAuthLibrary)(str.asOutParam());
892 RTPrintf("VRDE auth library: %lS\n", str.raw());
893 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
894 RTPrintf("Webservice auth. library: %lS\n", str.raw());
895 systemProperties->COMGETTER(DefaultVRDELibrary)(str.asOutParam());
896 RTPrintf("Remote desktop library: %lS\n", str.raw());
897 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
898 RTPrintf("Log history count: %u\n", ulValue);
899 break;
900 }
901
902 case kListDhcpServers:
903 {
904 com::SafeIfaceArray<IDHCPServer> svrs;
905 CHECK_ERROR(rptrVirtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam(svrs)));
906 for (size_t i = 0; i < svrs.size(); ++i)
907 {
908 ComPtr<IDHCPServer> svr = svrs[i];
909 Bstr netName;
910 svr->COMGETTER(NetworkName)(netName.asOutParam());
911 RTPrintf("NetworkName: %lS\n", netName.raw());
912 Bstr ip;
913 svr->COMGETTER(IPAddress)(ip.asOutParam());
914 RTPrintf("IP: %lS\n", ip.raw());
915 Bstr netmask;
916 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
917 RTPrintf("NetworkMask: %lS\n", netmask.raw());
918 Bstr lowerIp;
919 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
920 RTPrintf("lowerIPAddress: %lS\n", lowerIp.raw());
921 Bstr upperIp;
922 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
923 RTPrintf("upperIPAddress: %lS\n", upperIp.raw());
924 BOOL fEnabled;
925 svr->COMGETTER(Enabled)(&fEnabled);
926 RTPrintf("Enabled: %s\n", fEnabled ? "Yes" : "No");
927 RTPrintf("\n");
928 }
929 break;
930 }
931
932 case kListVrdeLibraries:
933 {
934 SafeArray<BSTR> libs;
935 CHECK_ERROR(rptrVirtualBox, VRDEListLibraries(ComSafeArrayAsOutParam(libs)));
936 if (SUCCEEDED(rc))
937 {
938 for (size_t i = 0; i < libs.size(); ++i)
939 {
940 Bstr bstrName(libs[i]);
941 RTPrintf("%lS\n", bstrName.raw());
942 }
943 }
944 break;
945 }
946
947 case kListExtPacks:
948 rc = listExtensionPacks(rptrVirtualBox);
949 break;
950
951 /* No default here, want gcc warnings. */
952
953 } /* end switch */
954
955 return rc;
956}
957
958/**
959 * Handles the 'list' command.
960 *
961 * @returns Appropriate exit code.
962 * @param a Handler argument.
963 */
964int handleList(HandlerArg *a)
965{
966 bool fOptLong = false;
967 bool fOptMultiple = false;
968 enum enmListType enmOptCommand = kListNotSpecified;
969
970 static const RTGETOPTDEF s_aListOptions[] =
971 {
972 { "--long", 'l', RTGETOPT_REQ_NOTHING },
973 { "--multiple", 'm', RTGETOPT_REQ_NOTHING }, /* not offical yet */
974 { "vms", kListVMs, RTGETOPT_REQ_NOTHING },
975 { "runningvms", kListRunningVMs, RTGETOPT_REQ_NOTHING },
976 { "ostypes", kListOsTypes, RTGETOPT_REQ_NOTHING },
977 { "hostdvds", kListHostDvds, RTGETOPT_REQ_NOTHING },
978 { "hostfloppies", kListHostFloppies, RTGETOPT_REQ_NOTHING },
979 { "hostifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
980 { "bridgedifs", kListBridgedInterfaces, RTGETOPT_REQ_NOTHING },
981#if defined(VBOX_WITH_NETFLT)
982 { "hostonlyifs", kListHostOnlyInterfaces, RTGETOPT_REQ_NOTHING },
983#endif
984 { "hostinfo", kListHostInfo, RTGETOPT_REQ_NOTHING },
985 { "hostcpuids", kListHostCpuIDs, RTGETOPT_REQ_NOTHING },
986 { "hddbackends", kListHddBackends, RTGETOPT_REQ_NOTHING },
987 { "hdds", kListHdds, RTGETOPT_REQ_NOTHING },
988 { "dvds", kListDvds, RTGETOPT_REQ_NOTHING },
989 { "floppies", kListFloppies, RTGETOPT_REQ_NOTHING },
990 { "usbhost", kListUsbHost, RTGETOPT_REQ_NOTHING },
991 { "usbfilters", kListUsbFilters, RTGETOPT_REQ_NOTHING },
992 { "systemproperties", kListSystemProperties, RTGETOPT_REQ_NOTHING },
993 { "dhcpservers", kListDhcpServers, RTGETOPT_REQ_NOTHING },
994 { "vrdelibraries", kListVrdeLibraries, RTGETOPT_REQ_NOTHING },
995 { "extpacks", kListExtPacks, RTGETOPT_REQ_NOTHING },
996 };
997
998 int ch;
999 RTGETOPTUNION ValueUnion;
1000 RTGETOPTSTATE GetState;
1001 RTGetOptInit(&GetState, a->argc, a->argv, s_aListOptions, RT_ELEMENTS(s_aListOptions),
1002 0, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
1003 while ((ch = RTGetOpt(&GetState, &ValueUnion)))
1004 {
1005 switch (ch)
1006 {
1007 case 'l': /* --long */
1008 fOptLong = true;
1009 break;
1010
1011 case 'm':
1012 fOptMultiple = true;
1013 if (enmOptCommand == kListNotSpecified)
1014 break;
1015 ch = enmOptCommand;
1016 /* fall thru */
1017
1018 case kListVMs:
1019 case kListRunningVMs:
1020 case kListOsTypes:
1021 case kListHostDvds:
1022 case kListHostFloppies:
1023 case kListBridgedInterfaces:
1024#if defined(VBOX_WITH_NETFLT)
1025 case kListHostOnlyInterfaces:
1026#endif
1027 case kListHostInfo:
1028 case kListHostCpuIDs:
1029 case kListHddBackends:
1030 case kListHdds:
1031 case kListDvds:
1032 case kListFloppies:
1033 case kListUsbHost:
1034 case kListUsbFilters:
1035 case kListSystemProperties:
1036 case kListDhcpServers:
1037 case kListVrdeLibraries:
1038 case kListExtPacks:
1039 enmOptCommand = (enum enmListType)ch;
1040 if (fOptMultiple)
1041 {
1042 HRESULT hrc = produceList((enum enmListType)ch, fOptLong, a->virtualBox);
1043 if (FAILED(hrc))
1044 return 1;
1045 }
1046 break;
1047
1048 case VINF_GETOPT_NOT_OPTION:
1049 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
1050
1051 default:
1052 return errorGetOpt(USAGE_LIST, ch, &ValueUnion);
1053 }
1054 }
1055
1056 /*
1057 * If not in multiple list mode, we have to produce the list now.
1058 */
1059 if (enmOptCommand == kListNotSpecified)
1060 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
1061 if (!fOptMultiple)
1062 {
1063 HRESULT hrc = produceList(enmOptCommand, fOptLong, a->virtualBox);
1064 if (FAILED(hrc))
1065 return 1;
1066 }
1067
1068 return 0;
1069}
1070
1071#endif /* !VBOX_ONLY_DOCS */
1072/* 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