VirtualBox

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

Last change on this file since 24412 was 24404, checked in by vboxsync, 16 years ago

VBoxManage: list hostcpuids; showvm nows shows the cpuid overrides.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 38.7 KB
Line 
1/* $Id: VBoxManageList.cpp 24404 2009-11-05 17:14:23Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'list' command.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef VBOX_ONLY_DOCS
23
24/*******************************************************************************
25* Header Files *
26*******************************************************************************/
27#include <VBox/com/com.h>
28#include <VBox/com/string.h>
29#include <VBox/com/Guid.h>
30#include <VBox/com/array.h>
31#include <VBox/com/ErrorInfo.h>
32#include <VBox/com/errorprint.h>
33
34#include <VBox/com/VirtualBox.h>
35
36#include <VBox/log.h>
37#include <iprt/stream.h>
38#include <iprt/string.h>
39#include <iprt/time.h>
40#include <iprt/getopt.h>
41#include <iprt/ctype.h>
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 }
55 return "Unknown";
56}
57
58static const char *getHostIfStatusText(HostNetworkInterfaceStatus_T enmStatus)
59{
60 switch (enmStatus)
61 {
62 case HostNetworkInterfaceStatus_Up: return "Up";
63 case HostNetworkInterfaceStatus_Down: return "Down";
64 }
65 return "Unknown";
66}
67#endif
68
69enum enOptionCodes
70{
71 LISTVMS = 1000,
72 LISTRUNNINGVMS,
73 LISTOSTYPES,
74 LISTHOSTDVDS,
75 LISTHOSTFLOPPIES,
76 LISTBRIDGEDIFS,
77#if defined(VBOX_WITH_NETFLT)
78 LISTHOSTONLYIFS,
79#endif
80 LISTHOSTCPUIDS,
81 LISTHOSTINFO,
82 LISTHDDBACKENDS,
83 LISTHDDS,
84 LISTDVDS,
85 LISTFLOPPIES,
86 LISTUSBHOST,
87 LISTUSBFILTERS,
88 LISTSYSTEMPROPERTIES,
89 LISTDHCPSERVERS
90};
91
92static const RTGETOPTDEF g_aListOptions[]
93 = {
94 { "--long", 'l', RTGETOPT_REQ_NOTHING },
95 { "vms", LISTVMS, RTGETOPT_REQ_NOTHING },
96 { "runningvms", LISTRUNNINGVMS, RTGETOPT_REQ_NOTHING },
97 { "ostypes", LISTOSTYPES, RTGETOPT_REQ_NOTHING },
98 { "hostdvds", LISTHOSTDVDS, RTGETOPT_REQ_NOTHING },
99 { "hostfloppies", LISTHOSTFLOPPIES, RTGETOPT_REQ_NOTHING },
100 { "hostifs", LISTBRIDGEDIFS, RTGETOPT_REQ_NOTHING }, /* backward compatibility */
101 { "bridgedifs", LISTBRIDGEDIFS, RTGETOPT_REQ_NOTHING },
102#if defined(VBOX_WITH_NETFLT)
103 { "hostonlyifs", LISTHOSTONLYIFS, RTGETOPT_REQ_NOTHING },
104#endif
105 { "hostinfo", LISTHOSTINFO, RTGETOPT_REQ_NOTHING },
106 { "hostcpuids", LISTHOSTCPUIDS, RTGETOPT_REQ_NOTHING },
107 { "hddbackends", LISTHDDBACKENDS, RTGETOPT_REQ_NOTHING },
108 { "hdds", LISTHDDS, RTGETOPT_REQ_NOTHING },
109 { "dvds", LISTDVDS, RTGETOPT_REQ_NOTHING },
110 { "floppies", LISTFLOPPIES, RTGETOPT_REQ_NOTHING },
111 { "usbhost", LISTUSBHOST, RTGETOPT_REQ_NOTHING },
112 { "usbfilters", LISTUSBFILTERS, RTGETOPT_REQ_NOTHING },
113 { "systemproperties", LISTSYSTEMPROPERTIES, RTGETOPT_REQ_NOTHING },
114 { "dhcpservers", LISTDHCPSERVERS, RTGETOPT_REQ_NOTHING }
115 };
116
117int handleList(HandlerArg *a)
118{
119 HRESULT rc = S_OK;
120
121 bool fOptLong = false;
122
123 int command = 0;
124 int c;
125
126 RTGETOPTUNION ValueUnion;
127 RTGETOPTSTATE GetState;
128 RTGetOptInit(&GetState, a->argc, a->argv, g_aListOptions, RT_ELEMENTS(g_aListOptions), 0, 0 /* fFlags */);
129 while ((c = RTGetOpt(&GetState, &ValueUnion)))
130 {
131 switch (c)
132 {
133 case 'l': // --long
134 fOptLong = true;
135 break;
136
137 case LISTVMS:
138 case LISTRUNNINGVMS:
139 case LISTOSTYPES:
140 case LISTHOSTDVDS:
141 case LISTHOSTFLOPPIES:
142 case LISTBRIDGEDIFS:
143#if defined(VBOX_WITH_NETFLT)
144 case LISTHOSTONLYIFS:
145#endif
146 case LISTHOSTINFO:
147 case LISTHOSTCPUIDS:
148 case LISTHDDBACKENDS:
149 case LISTHDDS:
150 case LISTDVDS:
151 case LISTFLOPPIES:
152 case LISTUSBHOST:
153 case LISTUSBFILTERS:
154 case LISTSYSTEMPROPERTIES:
155 case LISTDHCPSERVERS:
156 if (command)
157 return errorSyntax(USAGE_LIST, "Too many subcommands for \"list\" command.\n");
158
159 command = c;
160 break;
161
162 case VINF_GETOPT_NOT_OPTION:
163 return errorSyntax(USAGE_LIST, "Unknown subcommand \"%s\".", ValueUnion.psz);
164 break;
165
166 default:
167 if (c > 0)
168 {
169 if (RT_C_IS_GRAPH(c))
170 return errorSyntax(USAGE_LIST, "unhandled option: -%c", c);
171 else
172 return errorSyntax(USAGE_LIST, "unhandled option: %i", c);
173 }
174 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
175 return errorSyntax(USAGE_LIST, "unknown option: %s", ValueUnion.psz);
176 else if (ValueUnion.pDef)
177 return errorSyntax(USAGE_LIST, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
178 else
179 return errorSyntax(USAGE_LIST, "%Rrs", c);
180 }
181 }
182
183 if (!command)
184 return errorSyntax(USAGE_LIST, "Missing subcommand for \"list\" command.\n");
185
186 /* which object? */
187 switch (command)
188 {
189 case LISTVMS:
190 {
191 /*
192 * Get the list of all registered VMs
193 */
194 com::SafeIfaceArray <IMachine> machines;
195 rc = a->virtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam (machines));
196 if (SUCCEEDED(rc))
197 {
198 /*
199 * Iterate through the collection
200 */
201 for (size_t i = 0; i < machines.size(); ++ i)
202 {
203 if (machines[i])
204 rc = showVMInfo(a->virtualBox,
205 machines[i],
206 (fOptLong) ? VMINFO_STANDARD : VMINFO_COMPACT);
207 }
208 }
209 }
210 break;
211
212 case LISTRUNNINGVMS:
213 {
214 /*
215 * Get the list of all _running_ VMs
216 */
217 com::SafeIfaceArray <IMachine> machines;
218 rc = a->virtualBox->COMGETTER(Machines)(ComSafeArrayAsOutParam (machines));
219 if (SUCCEEDED(rc))
220 {
221 /*
222 * Iterate through the collection
223 */
224 for (size_t i = 0; i < machines.size(); ++ i)
225 {
226 if (machines[i])
227 {
228 MachineState_T machineState;
229 rc = machines [i]->COMGETTER(State)(&machineState);
230 if (SUCCEEDED(rc))
231 {
232 switch (machineState)
233 {
234 case MachineState_Running:
235 case MachineState_Teleporting:
236 case MachineState_LiveSnapshotting:
237 case MachineState_Paused:
238 case MachineState_TeleportingPausedVM:
239 rc = showVMInfo(a->virtualBox,
240 machines[i],
241 (fOptLong) ? VMINFO_STANDARD : VMINFO_COMPACT);
242 }
243 }
244 }
245 }
246 }
247 }
248 break;
249
250 case LISTOSTYPES:
251 {
252 com::SafeIfaceArray <IGuestOSType> coll;
253 rc = a->virtualBox->COMGETTER(GuestOSTypes)(ComSafeArrayAsOutParam(coll));
254 if (SUCCEEDED(rc))
255 {
256 /*
257 * Iterate through the collection.
258 */
259 for (size_t i = 0; i < coll.size(); ++ i)
260 {
261 ComPtr<IGuestOSType> guestOS;
262 guestOS = coll[i];
263 Bstr guestId;
264 guestOS->COMGETTER(Id)(guestId.asOutParam());
265 RTPrintf("ID: %lS\n", guestId.raw());
266 Bstr guestDescription;
267 guestOS->COMGETTER(Description)(guestDescription.asOutParam());
268 RTPrintf("Description: %lS\n\n", guestDescription.raw());
269 }
270 }
271 }
272 break;
273
274 case LISTHOSTDVDS:
275 {
276 ComPtr<IHost> host;
277 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
278 com::SafeIfaceArray <IMedium> coll;
279 CHECK_ERROR(host, COMGETTER(DVDDrives)(ComSafeArrayAsOutParam(coll)));
280 if (SUCCEEDED(rc))
281 {
282 for (size_t i = 0; i < coll.size(); ++ i)
283 {
284 ComPtr<IMedium> dvdDrive = coll[i];
285 Bstr uuid;
286 dvdDrive->COMGETTER(Id)(uuid.asOutParam());
287 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
288 Bstr name;
289 dvdDrive->COMGETTER(Name)(name.asOutParam());
290 RTPrintf("Name: %lS\n\n", name.raw());
291 }
292 }
293 }
294 break;
295
296 case LISTHOSTFLOPPIES:
297 {
298 ComPtr<IHost> host;
299 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
300 com::SafeIfaceArray <IMedium> coll;
301 CHECK_ERROR(host, COMGETTER(FloppyDrives)(ComSafeArrayAsOutParam(coll)));
302 if (SUCCEEDED(rc))
303 {
304 for (size_t i = 0; i < coll.size(); ++i)
305 {
306 ComPtr<IMedium> floppyDrive = coll[i];
307 Bstr uuid;
308 floppyDrive->COMGETTER(Id)(uuid.asOutParam());
309 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
310 Bstr name;
311 floppyDrive->COMGETTER(Name)(name.asOutParam());
312 RTPrintf("Name: %lS\n\n", name.raw());
313 }
314 }
315 }
316 break;
317
318 case LISTBRIDGEDIFS:
319#if defined(VBOX_WITH_NETFLT)
320 case LISTHOSTONLYIFS:
321#endif
322 {
323 ComPtr<IHost> host;
324 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
325 com::SafeIfaceArray <IHostNetworkInterface> hostNetworkInterfaces;
326#if defined(VBOX_WITH_NETFLT)
327 if (command == LISTBRIDGEDIFS)
328 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_Bridged,
329 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
330 else
331 CHECK_ERROR(host, FindHostNetworkInterfacesOfType(HostNetworkInterfaceType_HostOnly,
332 ComSafeArrayAsOutParam(hostNetworkInterfaces)));
333#else
334 CHECK_ERROR(host, COMGETTER(NetworkInterfaces)(ComSafeArrayAsOutParam(hostNetworkInterfaces)));
335#endif
336 for (size_t i = 0; i < hostNetworkInterfaces.size(); ++i)
337 {
338 ComPtr<IHostNetworkInterface> networkInterface = hostNetworkInterfaces[i];
339#ifndef VBOX_WITH_HOSTNETIF_API
340 Bstr interfaceName;
341 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
342 RTPrintf("Name: %lS\n", interfaceName.raw());
343 Guid interfaceGuid;
344 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
345 RTPrintf("GUID: %lS\n\n", Bstr(interfaceGuid.toString()).raw());
346#else /* VBOX_WITH_HOSTNETIF_API */
347 Bstr interfaceName;
348 networkInterface->COMGETTER(Name)(interfaceName.asOutParam());
349 RTPrintf("Name: %lS\n", interfaceName.raw());
350 Bstr interfaceGuid;
351 networkInterface->COMGETTER(Id)(interfaceGuid.asOutParam());
352 RTPrintf("GUID: %lS\n", interfaceGuid.raw());
353 BOOL bDhcpEnabled;
354 networkInterface->COMGETTER(DhcpEnabled)(&bDhcpEnabled);
355 RTPrintf("Dhcp: %s\n", bDhcpEnabled ? "Enabled" : "Disabled");
356
357 Bstr IPAddress;
358 networkInterface->COMGETTER(IPAddress)(IPAddress.asOutParam());
359 RTPrintf("IPAddress: %lS\n", IPAddress.raw());
360 Bstr NetworkMask;
361 networkInterface->COMGETTER(NetworkMask)(NetworkMask.asOutParam());
362 RTPrintf("NetworkMask: %lS\n", NetworkMask.raw());
363 Bstr IPV6Address;
364 networkInterface->COMGETTER(IPV6Address)(IPV6Address.asOutParam());
365 RTPrintf("IPV6Address: %lS\n", IPV6Address.raw());
366 ULONG IPV6NetworkMaskPrefixLength;
367 networkInterface->COMGETTER(IPV6NetworkMaskPrefixLength)(&IPV6NetworkMaskPrefixLength);
368 RTPrintf("IPV6NetworkMaskPrefixLength: %d\n", IPV6NetworkMaskPrefixLength);
369 Bstr HardwareAddress;
370 networkInterface->COMGETTER(HardwareAddress)(HardwareAddress.asOutParam());
371 RTPrintf("HardwareAddress: %lS\n", HardwareAddress.raw());
372 HostNetworkInterfaceMediumType_T Type;
373 networkInterface->COMGETTER(MediumType)(&Type);
374 RTPrintf("MediumType: %s\n", getHostIfMediumTypeText(Type));
375 HostNetworkInterfaceStatus_T Status;
376 networkInterface->COMGETTER(Status)(&Status);
377 RTPrintf("Status: %s\n", getHostIfStatusText(Status));
378 Bstr netName;
379 networkInterface->COMGETTER(NetworkName)(netName.asOutParam());
380 RTPrintf("VBoxNetworkName: %lS\n\n", netName.raw());
381
382#endif
383 }
384 }
385 break;
386
387 case LISTHOSTINFO:
388 {
389 ComPtr<IHost> Host;
390 CHECK_ERROR (a->virtualBox, COMGETTER(Host)(Host.asOutParam()));
391
392 RTPrintf("Host Information:\n\n");
393
394 LONG64 uTCTime = 0;
395 CHECK_ERROR (Host, COMGETTER(UTCTime)(&uTCTime));
396 RTTIMESPEC timeSpec;
397 RTTimeSpecSetMilli(&timeSpec, uTCTime);
398 char szTime[32] = {0};
399 RTTimeSpecToString(&timeSpec, szTime, sizeof(szTime));
400 RTPrintf("Host time: %s\n", szTime);
401
402 ULONG processorOnlineCount = 0;
403 CHECK_ERROR (Host, COMGETTER(ProcessorOnlineCount)(&processorOnlineCount));
404 RTPrintf("Processor online count: %lu\n", processorOnlineCount);
405 ULONG processorCount = 0;
406 CHECK_ERROR (Host, COMGETTER(ProcessorCount)(&processorCount));
407 RTPrintf("Processor count: %lu\n", processorCount);
408 ULONG processorSpeed = 0;
409 Bstr processorDescription;
410 for (ULONG i = 0; i < processorCount; i++)
411 {
412 CHECK_ERROR (Host, GetProcessorSpeed(i, &processorSpeed));
413 if (processorSpeed)
414 RTPrintf("Processor#%u speed: %lu MHz\n", i, processorSpeed);
415 else
416 RTPrintf("Processor#%u speed: unknown\n", i, processorSpeed);
417 CHECK_ERROR (Host, GetProcessorDescription(i, processorDescription.asOutParam()));
418 RTPrintf("Processor#%u description: %lS\n", i, processorDescription.raw());
419 }
420
421 ULONG memorySize = 0;
422 CHECK_ERROR (Host, COMGETTER(MemorySize)(&memorySize));
423 RTPrintf("Memory size: %lu MByte\n", memorySize);
424
425 ULONG memoryAvailable = 0;
426 CHECK_ERROR (Host, COMGETTER(MemoryAvailable)(&memoryAvailable));
427 RTPrintf("Memory available: %lu MByte\n", memoryAvailable);
428
429 Bstr operatingSystem;
430 CHECK_ERROR (Host, COMGETTER(OperatingSystem)(operatingSystem.asOutParam()));
431 RTPrintf("Operating system: %lS\n", operatingSystem.raw());
432
433 Bstr oSVersion;
434 CHECK_ERROR (Host, COMGETTER(OSVersion)(oSVersion.asOutParam()));
435 RTPrintf("Operating system version: %lS\n", oSVersion.raw());
436 }
437 break;
438
439 case LISTHOSTCPUIDS:
440 {
441 ComPtr<IHost> Host;
442 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(Host.asOutParam()));
443
444 RTPrintf("Host CPUIDs:\n\nLeaf no. EAX EBX ECX EDX\n");
445 ULONG uCpuNo = 0; /* ASSUMES that CPU#0 is online. */
446 ULONG uEAX, uEBX, uECX, uEDX;
447 ULONG cLeafs;
448
449 /* Standard */
450 CHECK_ERROR(Host, GetProcessorCpuIdLeaf(uCpuNo, 0, 0, &cLeafs, &uEBX, &uECX, &uEDX));
451 if (cLeafs > UINT32_C(0x00000000) && cLeafs <= UINT32_C(0x0000007f))
452 for (ULONG iLeaf = 0; iLeaf < cLeafs; iLeaf++)
453 {
454 CHECK_ERROR(Host, GetProcessorCpuIdLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
455 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
456 }
457
458 /* Extended */
459 CHECK_ERROR(Host, GetProcessorCpuIdLeaf(uCpuNo, UINT32_C(0x80000000), 0, &cLeafs, &uEBX, &uECX, &uEDX));
460 if (cLeafs > UINT32_C(0x80000000) && cLeafs <= UINT32_C(0x8000007f))
461 for (ULONG iLeaf = UINT32_C(0x80000000); iLeaf < cLeafs; iLeaf++)
462 {
463 CHECK_ERROR(Host, GetProcessorCpuIdLeaf(uCpuNo, iLeaf, 0, &uEAX, &uEBX, &uECX, &uEDX));
464 RTPrintf("%08x %08x %08x %08x %08x\n", iLeaf, uEAX, uEBX, uECX, uEDX);
465 }
466 }
467 break;
468
469 case LISTHDDBACKENDS:
470 {
471 ComPtr<ISystemProperties> systemProperties;
472 CHECK_ERROR(a->virtualBox,
473 COMGETTER(SystemProperties) (systemProperties.asOutParam()));
474 com::SafeIfaceArray <IMediumFormat> mediumFormats;
475 CHECK_ERROR(systemProperties,
476 COMGETTER(MediumFormats) (ComSafeArrayAsOutParam (mediumFormats)));
477
478 RTPrintf("Supported hard disk backends:\n\n");
479 for (size_t i = 0; i < mediumFormats.size(); ++ i)
480 {
481 /* General information */
482 Bstr id;
483 CHECK_ERROR(mediumFormats [i],
484 COMGETTER(Id) (id.asOutParam()));
485
486 Bstr description;
487 CHECK_ERROR(mediumFormats [i],
488 COMGETTER(Id) (description.asOutParam()));
489
490 ULONG caps;
491 CHECK_ERROR(mediumFormats [i],
492 COMGETTER(Capabilities) (&caps));
493
494 RTPrintf("Backend %u: id='%ls' description='%ls' capabilities=%#06x extensions='",
495 i, id.raw(), description.raw(), caps);
496
497 /* File extensions */
498 com::SafeArray <BSTR> fileExtensions;
499 CHECK_ERROR(mediumFormats [i],
500 COMGETTER(FileExtensions) (ComSafeArrayAsOutParam (fileExtensions)));
501 for (size_t a = 0; a < fileExtensions.size(); ++ a)
502 {
503 RTPrintf ("%ls", Bstr (fileExtensions [a]).raw());
504 if (a != fileExtensions.size()-1)
505 RTPrintf (",");
506 }
507 RTPrintf ("'");
508
509 /* Configuration keys */
510 com::SafeArray <BSTR> propertyNames;
511 com::SafeArray <BSTR> propertyDescriptions;
512 com::SafeArray <DataType_T> propertyTypes;
513 com::SafeArray <ULONG> propertyFlags;
514 com::SafeArray <BSTR> propertyDefaults;
515 CHECK_ERROR(mediumFormats [i],
516 DescribeProperties (ComSafeArrayAsOutParam (propertyNames),
517 ComSafeArrayAsOutParam (propertyDescriptions),
518 ComSafeArrayAsOutParam (propertyTypes),
519 ComSafeArrayAsOutParam (propertyFlags),
520 ComSafeArrayAsOutParam (propertyDefaults)));
521
522 RTPrintf (" properties=(");
523 if (propertyNames.size() > 0)
524 {
525 for (size_t a = 0; a < propertyNames.size(); ++ a)
526 {
527 RTPrintf ("\n name='%ls' desc='%ls' type=",
528 Bstr (propertyNames [a]).raw(), Bstr (propertyDescriptions [a]).raw());
529 switch (propertyTypes [a])
530 {
531 case DataType_Int32: RTPrintf ("int"); break;
532 case DataType_Int8: RTPrintf ("byte"); break;
533 case DataType_String: RTPrintf ("string"); break;
534 }
535 RTPrintf (" flags=%#04x", propertyFlags [a]);
536 RTPrintf (" default='%ls'", Bstr (propertyDefaults [a]).raw());
537 if (a != propertyNames.size()-1)
538 RTPrintf (", ");
539 }
540 }
541 RTPrintf (")\n");
542 }
543 }
544 break;
545
546 case LISTHDDS:
547 {
548 com::SafeIfaceArray<IMedium> hdds;
549 CHECK_ERROR(a->virtualBox, COMGETTER(HardDisks)(ComSafeArrayAsOutParam (hdds)));
550 for (size_t i = 0; i < hdds.size(); ++ i)
551 {
552 ComPtr<IMedium> hdd = hdds[i];
553 Bstr uuid;
554 hdd->COMGETTER(Id)(uuid.asOutParam());
555 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
556 Bstr format;
557 hdd->COMGETTER(Format)(format.asOutParam());
558 RTPrintf("Format: %lS\n", format.raw());
559 Bstr filepath;
560 hdd->COMGETTER(Location)(filepath.asOutParam());
561 RTPrintf("Location: %lS\n", filepath.raw());
562 MediumState_T enmState;
563 /// @todo NEWMEDIA check accessibility of all parents
564 /// @todo NEWMEDIA print the full state value
565 hdd->RefreshState(&enmState);
566 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
567
568 MediumType_T type;
569 hdd->COMGETTER(Type)(&type);
570 const char *typeStr = "unknown";
571 switch (type)
572 {
573 case MediumType_Normal:
574 typeStr = "normal";
575 break;
576 case MediumType_Immutable:
577 typeStr = "immutable";
578 break;
579 case MediumType_Writethrough:
580 typeStr = "writethrough";
581 break;
582 }
583 RTPrintf("Type: %s\n", typeStr);
584
585 com::SafeArray<BSTR> machineIds;
586 hdd->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
587 for (size_t j = 0; j < machineIds.size(); ++ j)
588 {
589 ComPtr<IMachine> machine;
590 CHECK_ERROR(a->virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
591 ASSERT(machine);
592 Bstr name;
593 machine->COMGETTER(Name)(name.asOutParam());
594 machine->COMGETTER(Id)(uuid.asOutParam());
595 RTPrintf("%s%lS (UUID: %lS)\n",
596 j == 0 ? "Usage: " : " ",
597 name.raw(), machineIds[j]);
598 }
599 /// @todo NEWMEDIA check usage in snapshots too
600 /// @todo NEWMEDIA also list children and say 'differencing' for
601 /// hard disks with the parent or 'base' otherwise.
602 RTPrintf("\n");
603 }
604 }
605 break;
606
607 case LISTDVDS:
608 {
609 com::SafeIfaceArray<IMedium> dvds;
610 CHECK_ERROR(a->virtualBox, COMGETTER(DVDImages)(ComSafeArrayAsOutParam(dvds)));
611 for (size_t i = 0; i < dvds.size(); ++ i)
612 {
613 ComPtr<IMedium> dvdImage = dvds[i];
614 Bstr uuid;
615 dvdImage->COMGETTER(Id)(uuid.asOutParam());
616 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
617 Bstr filePath;
618 dvdImage->COMGETTER(Location)(filePath.asOutParam());
619 RTPrintf("Path: %lS\n", filePath.raw());
620 MediumState_T enmState;
621 dvdImage->RefreshState(&enmState);
622 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
623 /** @todo usage */
624 RTPrintf("\n");
625 }
626 }
627 break;
628
629 case LISTFLOPPIES:
630 {
631 com::SafeIfaceArray<IMedium> floppies;
632 CHECK_ERROR(a->virtualBox, COMGETTER(FloppyImages)(ComSafeArrayAsOutParam(floppies)));
633 for (size_t i = 0; i < floppies.size(); ++ i)
634 {
635 ComPtr<IMedium> floppyImage = floppies[i];
636 Bstr uuid;
637 floppyImage->COMGETTER(Id)(uuid.asOutParam());
638 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
639 Bstr filePath;
640 floppyImage->COMGETTER(Location)(filePath.asOutParam());
641 RTPrintf("Path: %lS\n", filePath.raw());
642 MediumState_T enmState;
643 floppyImage->RefreshState(&enmState);
644 RTPrintf("Accessible: %s\n", enmState != MediumState_Inaccessible ? "yes" : "no");
645 /** @todo usage */
646 RTPrintf("\n");
647 }
648 }
649 break;
650
651 case LISTUSBHOST:
652 {
653 ComPtr<IHost> Host;
654 CHECK_ERROR_RET (a->virtualBox, COMGETTER(Host)(Host.asOutParam()), 1);
655
656 SafeIfaceArray <IHostUSBDevice> CollPtr;
657 CHECK_ERROR_RET (Host, COMGETTER(USBDevices)(ComSafeArrayAsOutParam(CollPtr)), 1);
658
659 RTPrintf("Host USB Devices:\n\n");
660
661 if (CollPtr.size() == 0)
662 {
663 RTPrintf("<none>\n\n");
664 }
665 else
666 {
667 for (size_t i = 0; i < CollPtr.size(); ++i)
668 {
669 ComPtr <IHostUSBDevice> dev = CollPtr[i];
670
671 /* Query info. */
672 Bstr id;
673 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), 1);
674 USHORT usVendorId;
675 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), 1);
676 USHORT usProductId;
677 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), 1);
678 USHORT bcdRevision;
679 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), 1);
680
681 RTPrintf("UUID: %S\n"
682 "VendorId: 0x%04x (%04X)\n"
683 "ProductId: 0x%04x (%04X)\n"
684 "Revision: %u.%u (%02u%02u)\n",
685 Utf8Str(id).raw(),
686 usVendorId, usVendorId, usProductId, usProductId,
687 bcdRevision >> 8, bcdRevision & 0xff,
688 bcdRevision >> 8, bcdRevision & 0xff);
689
690 /* optional stuff. */
691 Bstr bstr;
692 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), 1);
693 if (!bstr.isEmpty())
694 RTPrintf("Manufacturer: %lS\n", bstr.raw());
695 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), 1);
696 if (!bstr.isEmpty())
697 RTPrintf("Product: %lS\n", bstr.raw());
698 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), 1);
699 if (!bstr.isEmpty())
700 RTPrintf("SerialNumber: %lS\n", bstr.raw());
701 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), 1);
702 if (!bstr.isEmpty())
703 RTPrintf("Address: %lS\n", bstr.raw());
704
705 /* current state */
706 USBDeviceState_T state;
707 CHECK_ERROR_RET (dev, COMGETTER(State)(&state), 1);
708 const char *pszState = "?";
709 switch (state)
710 {
711 case USBDeviceState_NotSupported:
712 pszState = "Not supported"; break;
713 case USBDeviceState_Unavailable:
714 pszState = "Unavailable"; break;
715 case USBDeviceState_Busy:
716 pszState = "Busy"; break;
717 case USBDeviceState_Available:
718 pszState = "Available"; break;
719 case USBDeviceState_Held:
720 pszState = "Held"; break;
721 case USBDeviceState_Captured:
722 pszState = "Captured"; break;
723 default:
724 ASSERT (false);
725 break;
726 }
727 RTPrintf("Current State: %s\n\n", pszState);
728 }
729 }
730 }
731 break;
732
733 case LISTUSBFILTERS:
734 {
735 RTPrintf("Global USB Device Filters:\n\n");
736
737 ComPtr <IHost> host;
738 CHECK_ERROR_RET (a->virtualBox, COMGETTER(Host) (host.asOutParam()), 1);
739
740 SafeIfaceArray <IHostUSBDeviceFilter> coll;
741 CHECK_ERROR_RET (host, COMGETTER (USBDeviceFilters)(ComSafeArrayAsOutParam(coll)), 1);
742
743 if (coll.size() == 0)
744 {
745 RTPrintf("<none>\n\n");
746 }
747 else
748 {
749 for (size_t index = 0; index < coll.size(); ++index)
750 {
751 ComPtr<IHostUSBDeviceFilter> flt = coll[index];
752
753 /* Query info. */
754
755 RTPrintf("Index: %zu\n", index);
756
757 BOOL active = FALSE;
758 CHECK_ERROR_RET (flt, COMGETTER (Active) (&active), 1);
759 RTPrintf("Active: %s\n", active ? "yes" : "no");
760
761 USBDeviceFilterAction_T action;
762 CHECK_ERROR_RET (flt, COMGETTER (Action) (&action), 1);
763 const char *pszAction = "<invalid>";
764 switch (action)
765 {
766 case USBDeviceFilterAction_Ignore:
767 pszAction = "Ignore";
768 break;
769 case USBDeviceFilterAction_Hold:
770 pszAction = "Hold";
771 break;
772 default:
773 break;
774 }
775 RTPrintf("Action: %s\n", pszAction);
776
777 Bstr bstr;
778 CHECK_ERROR_RET (flt, COMGETTER (Name) (bstr.asOutParam()), 1);
779 RTPrintf("Name: %lS\n", bstr.raw());
780 CHECK_ERROR_RET (flt, COMGETTER (VendorId) (bstr.asOutParam()), 1);
781 RTPrintf("VendorId: %lS\n", bstr.raw());
782 CHECK_ERROR_RET (flt, COMGETTER (ProductId) (bstr.asOutParam()), 1);
783 RTPrintf("ProductId: %lS\n", bstr.raw());
784 CHECK_ERROR_RET (flt, COMGETTER (Revision) (bstr.asOutParam()), 1);
785 RTPrintf("Revision: %lS\n", bstr.raw());
786 CHECK_ERROR_RET (flt, COMGETTER (Manufacturer) (bstr.asOutParam()), 1);
787 RTPrintf("Manufacturer: %lS\n", bstr.raw());
788 CHECK_ERROR_RET (flt, COMGETTER (Product) (bstr.asOutParam()), 1);
789 RTPrintf("Product: %lS\n", bstr.raw());
790 CHECK_ERROR_RET (flt, COMGETTER (SerialNumber) (bstr.asOutParam()), 1);
791 RTPrintf("Serial Number: %lS\n\n", bstr.raw());
792 }
793 }
794 }
795 break;
796
797 case LISTSYSTEMPROPERTIES:
798 {
799 ComPtr<ISystemProperties> systemProperties;
800 a->virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
801
802 Bstr str;
803 ULONG ulValue;
804 ULONG64 ul64Value;
805 BOOL flag;
806
807 systemProperties->COMGETTER(MinGuestRAM)(&ulValue);
808 RTPrintf("Minimum guest RAM size: %u Megabytes\n", ulValue);
809 systemProperties->COMGETTER(MaxGuestRAM)(&ulValue);
810 RTPrintf("Maximum guest RAM size: %u Megabytes\n", ulValue);
811 systemProperties->COMGETTER(MinGuestVRAM)(&ulValue);
812 RTPrintf("Minimum video RAM size: %u Megabytes\n", ulValue);
813 systemProperties->COMGETTER(MaxGuestVRAM)(&ulValue);
814 RTPrintf("Maximum video RAM size: %u Megabytes\n", ulValue);
815 systemProperties->COMGETTER(MinGuestCPUCount)(&ulValue);
816 RTPrintf("Minimum guest CPU count: %u\n", ulValue);
817 systemProperties->COMGETTER(MaxGuestCPUCount)(&ulValue);
818 RTPrintf("Maximum guest CPU count: %u\n", ulValue);
819 systemProperties->COMGETTER(MaxVDISize)(&ul64Value);
820 RTPrintf("Maximum VDI size: %lu Megabytes\n", ul64Value);
821 systemProperties->COMGETTER(NetworkAdapterCount)(&ulValue);
822 RTPrintf("Maximum Network Adapter count: %u\n", ulValue);
823 systemProperties->COMGETTER(SerialPortCount)(&ulValue);
824 RTPrintf("Maximum Serial Port count: %u\n", ulValue);
825 systemProperties->COMGETTER(ParallelPortCount)(&ulValue);
826 RTPrintf("Maximum Parallel Port count: %u\n", ulValue);
827 systemProperties->COMGETTER(MaxBootPosition)(&ulValue);
828 RTPrintf("Maximum Boot Position: %u\n", ulValue);
829 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_IDE, &ulValue);
830 RTPrintf("Maximum IDE Controllers: %u\n", ulValue);
831 systemProperties->GetMaxPortCountForStorageBus(StorageBus_IDE, &ulValue);
832 RTPrintf("Maximum IDE Port count: %u\n", ulValue);
833 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_IDE, &ulValue);
834 RTPrintf("Maximum Devices per IDE Port: %u\n", ulValue);
835 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SATA, &ulValue);
836 RTPrintf("Maximum SATA Controllers: %u\n", ulValue);
837 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SATA, &ulValue);
838 RTPrintf("Maximum SATA Port count: %u\n", ulValue);
839 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SATA, &ulValue);
840 RTPrintf("Maximum Devices per SATA Port: %u\n", ulValue);
841 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_SCSI, &ulValue);
842 RTPrintf("Maximum SCSI Controllers: %u\n", ulValue);
843 systemProperties->GetMaxPortCountForStorageBus(StorageBus_SCSI, &ulValue);
844 RTPrintf("Maximum SCSI Port count: %u\n", ulValue);
845 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_SCSI, &ulValue);
846 RTPrintf("Maximum Devices per SCSI Port: %u\n", ulValue);
847 systemProperties->GetMaxInstancesOfStorageBus(StorageBus_Floppy, &ulValue);
848 RTPrintf("Maximum Floppy Controllers: %u\n", ulValue);
849 systemProperties->GetMaxPortCountForStorageBus(StorageBus_Floppy, &ulValue);
850 RTPrintf("Maximum Floppy Port count: %u\n", ulValue);
851 systemProperties->GetMaxDevicesPerPortForStorageBus(StorageBus_Floppy, &ulValue);
852 RTPrintf("Maximum Devices per Floppy Port: %u\n", ulValue);
853 systemProperties->COMGETTER(DefaultMachineFolder)(str.asOutParam());
854 RTPrintf("Default machine folder: %lS\n", str.raw());
855 systemProperties->COMGETTER(DefaultHardDiskFolder)(str.asOutParam());
856 RTPrintf("Default hard disk folder: %lS\n", str.raw());
857 systemProperties->COMGETTER(RemoteDisplayAuthLibrary)(str.asOutParam());
858 RTPrintf("VRDP authentication library: %lS\n", str.raw());
859 systemProperties->COMGETTER(WebServiceAuthLibrary)(str.asOutParam());
860 RTPrintf("Webservice auth. library: %lS\n", str.raw());
861 systemProperties->COMGETTER(LogHistoryCount)(&ulValue);
862 RTPrintf("Log history count: %u\n", ulValue);
863
864 }
865 break;
866 case LISTDHCPSERVERS:
867 {
868 com::SafeIfaceArray<IDHCPServer> svrs;
869 CHECK_ERROR(a->virtualBox, COMGETTER(DHCPServers)(ComSafeArrayAsOutParam (svrs)));
870 for (size_t i = 0; i < svrs.size(); ++ i)
871 {
872 ComPtr<IDHCPServer> svr = svrs[i];
873 Bstr netName;
874 svr->COMGETTER(NetworkName)(netName.asOutParam());
875 RTPrintf("NetworkName: %lS\n", netName.raw());
876 Bstr ip;
877 svr->COMGETTER(IPAddress)(ip.asOutParam());
878 RTPrintf("IP: %lS\n", ip.raw());
879 Bstr netmask;
880 svr->COMGETTER(NetworkMask)(netmask.asOutParam());
881 RTPrintf("NetworkMask: %lS\n", netmask.raw());
882 Bstr lowerIp;
883 svr->COMGETTER(LowerIP)(lowerIp.asOutParam());
884 RTPrintf("lowerIPAddress: %lS\n", lowerIp.raw());
885 Bstr upperIp;
886 svr->COMGETTER(UpperIP)(upperIp.asOutParam());
887 RTPrintf("upperIPAddress: %lS\n", upperIp.raw());
888 BOOL bEnabled;
889 svr->COMGETTER(Enabled)(&bEnabled);
890 RTPrintf("Enabled: %s\n", bEnabled ? "Yes" : "No");
891 RTPrintf("\n");
892 }
893 }
894 break;
895 } // end switch
896
897 return SUCCEEDED(rc) ? 0 : 1;
898}
899
900#endif /* !VBOX_ONLY_DOCS */
901/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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