VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxManageInfo.cpp@ 24672

Last change on this file since 24672 was 24601, checked in by vboxsync, 15 years ago

Frontends/VBoxManage: fix the storage controller output of "VBoxManage showvminfo --machinereadable" to use = as separator

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 79.8 KB
Line 
1/* $Id: VBoxManageInfo.cpp 24601 2009-11-11 19:33:28Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'showvminfo' command and helper routines.
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/time.h>
39#include <iprt/string.h>
40#include <iprt/getopt.h>
41#include <iprt/ctype.h>
42
43#include "VBoxManage.h"
44using namespace com;
45
46
47// funcs
48///////////////////////////////////////////////////////////////////////////////
49
50void showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
51 ComPtr<ISnapshot> &currentSnapshot,
52 VMINFO_DETAILS details,
53 const Bstr &prefix /* = ""*/,
54 int level /*= 0*/)
55{
56 /* start with the root */
57 Bstr name;
58 Bstr uuid;
59 rootSnapshot->COMGETTER(Name)(name.asOutParam());
60 rootSnapshot->COMGETTER(Id)(uuid.asOutParam());
61 if (details == VMINFO_MACHINEREADABLE)
62 {
63 /* print with hierarchical numbering */
64 RTPrintf("SnapshotName%lS=\"%lS\"\n", prefix.raw(), name.raw());
65 RTPrintf("SnapshotUUID%lS=\"%s\"\n", prefix.raw(), Utf8Str(uuid).raw());
66 }
67 else
68 {
69 /* print with indentation */
70 bool fCurrent = (rootSnapshot == currentSnapshot);
71 RTPrintf(" %lSName: %lS (UUID: %s)%s\n",
72 prefix.raw(),
73 name.raw(),
74 Utf8Str(uuid).raw(),
75 (fCurrent) ? " *" : "");
76 }
77
78 /* get the children */
79 SafeIfaceArray <ISnapshot> coll;
80 rootSnapshot->COMGETTER(Children)(ComSafeArrayAsOutParam(coll));
81 if (!coll.isNull())
82 {
83 for (size_t index = 0; index < coll.size(); ++index)
84 {
85 ComPtr<ISnapshot> snapshot = coll[index];
86 if (snapshot)
87 {
88 Bstr newPrefix;
89 if (details == VMINFO_MACHINEREADABLE)
90 newPrefix = Utf8StrFmt("%lS-%d", prefix.raw(), index + 1);
91 else
92 {
93 newPrefix = Utf8StrFmt("%lS ", prefix.raw());
94 }
95
96 /* recursive call */
97 showSnapshots(snapshot, currentSnapshot, details, newPrefix, level + 1);
98 }
99 }
100 }
101}
102
103static void makeTimeStr (char *s, int cb, int64_t millies)
104{
105 RTTIME t;
106 RTTIMESPEC ts;
107
108 RTTimeSpecSetMilli(&ts, millies);
109
110 RTTimeExplode (&t, &ts);
111
112 RTStrPrintf(s, cb, "%04d/%02d/%02d %02d:%02d:%02d UTC",
113 t.i32Year, t.u8Month, t.u8MonthDay,
114 t.u8Hour, t.u8Minute, t.u8Second);
115}
116
117/* Disable global optimizations for MSC 8.0/64 to make it compile in reasonable
118 time. MSC 7.1/32 doesn't have quite as much trouble with it, but still
119 sufficient to qualify for this hack as well since this code isn't performance
120 critical and probably won't gain much from the extra optimizing in real life. */
121#if defined(_MSC_VER)
122# pragma optimize("g", off)
123#endif
124
125HRESULT showVMInfo (ComPtr<IVirtualBox> virtualBox,
126 ComPtr<IMachine> machine,
127 VMINFO_DETAILS details /*= VMINFO_NONE*/,
128 ComPtr<IConsole> console /*= ComPtr <IConsole> ()*/)
129{
130 HRESULT rc;
131
132 /*
133 * The rules for output in -argdump format:
134 * 1) the key part (the [0-9a-zA-Z_]+ string before the '=' delimiter)
135 * is all lowercase for "VBoxManage modifyvm" parameters. Any
136 * other values printed are in CamelCase.
137 * 2) strings (anything non-decimal) are printed surrounded by
138 * double quotes '"'. If the strings themselves contain double
139 * quotes, these characters are escaped by '\'. Any '\' character
140 * in the original string is also escaped by '\'.
141 * 3) numbers (containing just [0-9\-]) are written out unchanged.
142 */
143
144 /** @todo the quoting is not yet implemented! */
145 /** @todo error checking! */
146
147 BOOL accessible = FALSE;
148 CHECK_ERROR(machine, COMGETTER(Accessible)(&accessible));
149 CheckComRCReturnRC(rc);
150
151 Bstr uuid;
152 rc = machine->COMGETTER(Id)(uuid.asOutParam());
153
154 if (!accessible)
155 {
156 if (details == VMINFO_COMPACT)
157 RTPrintf("\"<inaccessible>\" {%s}\n", Utf8Str(uuid).raw());
158 else
159 {
160 if (details == VMINFO_MACHINEREADABLE)
161 RTPrintf("name=\"<inaccessible>\"\n");
162 else
163 RTPrintf("Name: <inaccessible!>\n");
164 if (details == VMINFO_MACHINEREADABLE)
165 RTPrintf("UUID=\"%s\"\n", Utf8Str(uuid).raw());
166 else
167 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
168 if (details != VMINFO_MACHINEREADABLE)
169 {
170 Bstr settingsFilePath;
171 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
172 RTPrintf("Config file: %lS\n", settingsFilePath.raw());
173 ComPtr<IVirtualBoxErrorInfo> accessError;
174 rc = machine->COMGETTER(AccessError)(accessError.asOutParam());
175 RTPrintf("Access error details:\n");
176 ErrorInfo ei(accessError);
177 GluePrintErrorInfo(ei);
178 RTPrintf("\n");
179 }
180 }
181 return S_OK;
182 }
183
184 Bstr machineName;
185 rc = machine->COMGETTER(Name)(machineName.asOutParam());
186
187 if (details == VMINFO_COMPACT)
188 {
189 RTPrintf("\"%lS\" {%s}\n", machineName.raw(), Utf8Str(uuid).raw());
190 return S_OK;
191 }
192
193 if (details == VMINFO_MACHINEREADABLE)
194 RTPrintf("name=\"%lS\"\n", machineName.raw());
195 else
196 RTPrintf("Name: %lS\n", machineName.raw());
197
198 Bstr osTypeId;
199 rc = machine->COMGETTER(OSTypeId)(osTypeId.asOutParam());
200 ComPtr<IGuestOSType> osType;
201 rc = virtualBox->GetGuestOSType (osTypeId, osType.asOutParam());
202 Bstr osName;
203 rc = osType->COMGETTER(Description)(osName.asOutParam());
204 if (details == VMINFO_MACHINEREADABLE)
205 RTPrintf("ostype=\"%lS\"\n", osTypeId.raw());
206 else
207 RTPrintf("Guest OS: %lS\n", osName.raw());
208
209 if (details == VMINFO_MACHINEREADABLE)
210 RTPrintf("UUID=\"%s\"\n", Utf8Str(uuid).raw());
211 else
212 RTPrintf("UUID: %s\n", Utf8Str(uuid).raw());
213
214 Bstr settingsFilePath;
215 rc = machine->COMGETTER(SettingsFilePath)(settingsFilePath.asOutParam());
216 if (details == VMINFO_MACHINEREADABLE)
217 RTPrintf("CfgFile=\"%lS\"\n", settingsFilePath.raw());
218 else
219 RTPrintf("Config file: %lS\n", settingsFilePath.raw());
220
221 Bstr strHardwareUuid;
222 rc = machine->COMGETTER(HardwareUUID)(strHardwareUuid.asOutParam());
223 if (details == VMINFO_MACHINEREADABLE)
224 RTPrintf("HardwareUUID=\"%s\"\n", strHardwareUuid.raw());
225 else
226 RTPrintf("Hardware UUID: %lS\n", strHardwareUuid.raw());
227
228 ULONG memorySize;
229 rc = machine->COMGETTER(MemorySize)(&memorySize);
230 if (details == VMINFO_MACHINEREADABLE)
231 RTPrintf("memory=%u\n", memorySize);
232 else
233 RTPrintf("Memory size: %uMB\n", memorySize);
234
235 ULONG vramSize;
236 rc = machine->COMGETTER(VRAMSize)(&vramSize);
237 if (details == VMINFO_MACHINEREADABLE)
238 RTPrintf("vram=%u\n", vramSize);
239 else
240 RTPrintf("VRAM size: %uMB\n", vramSize);
241
242 ULONG numCpus;
243 rc = machine->COMGETTER(CPUCount)(&numCpus);
244 if (details == VMINFO_MACHINEREADABLE)
245 RTPrintf("cpus=%u\n", numCpus);
246 else
247 RTPrintf("Number of CPUs: %u\n", numCpus);
248
249 BOOL fSyntheticCpu;
250 machine->GetCpuProperty(CpuPropertyType_Synthetic, &fSyntheticCpu);
251 if (details == VMINFO_MACHINEREADABLE)
252 RTPrintf("synthcpu=\"%s\"\n", fSyntheticCpu ? "on" : "off");
253 else
254 RTPrintf("Synthetic Cpu: %s\n", fSyntheticCpu ? "on" : "off");
255
256 if (details != VMINFO_MACHINEREADABLE)
257 RTPrintf("CPUID overrides: ");
258 ULONG cFound = 0;
259 static uint32_t const s_auCpuIdRanges[] =
260 {
261 UINT32_C(0x00000000), UINT32_C(0x0000000a),
262 UINT32_C(0x80000000), UINT32_C(0x8000000a)
263 };
264 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
265 for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
266 {
267 ULONG uEAX, uEBX, uECX, uEDX;
268 rc = machine->GetCpuIdLeaf(uLeaf, &uEAX, &uEBX, &uECX, &uEDX);
269 if (SUCCEEDED(rc))
270 {
271 if (details == VMINFO_MACHINEREADABLE)
272 RTPrintf("cpuid=%08x,%08x,%08x,%08x,%08x", uLeaf, uEAX, uEBX, uECX, uEDX);
273 else
274 {
275 if (!cFound)
276 RTPrintf("Leaf no. EAX EBX ECX EDX\n");
277 RTPrintf(" %08x %08x %08x %08x %08x\n", uLeaf, uEAX, uEBX, uECX, uEDX);
278 }
279 cFound++;
280 }
281 }
282 if (!cFound && details != VMINFO_MACHINEREADABLE)
283 RTPrintf("None\n");
284
285 ComPtr <IBIOSSettings> biosSettings;
286 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
287
288 BIOSBootMenuMode_T bootMenuMode;
289 biosSettings->COMGETTER(BootMenuMode)(&bootMenuMode);
290 const char *pszBootMenu = NULL;
291 switch (bootMenuMode)
292 {
293 case BIOSBootMenuMode_Disabled:
294 pszBootMenu = "disabled";
295 break;
296 case BIOSBootMenuMode_MenuOnly:
297 if (details == VMINFO_MACHINEREADABLE)
298 pszBootMenu = "menuonly";
299 else
300 pszBootMenu = "menu only";
301 break;
302 default:
303 if (details == VMINFO_MACHINEREADABLE)
304 pszBootMenu = "messageandmenu";
305 else
306 pszBootMenu = "message and menu";
307 }
308 if (details == VMINFO_MACHINEREADABLE)
309 RTPrintf("bootmenu=\"%s\"\n", pszBootMenu);
310 else
311 RTPrintf("Boot menu mode: %s\n", pszBootMenu);
312
313 ULONG maxBootPosition = 0;
314 ComPtr<ISystemProperties> systemProperties;
315 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
316 systemProperties->COMGETTER(MaxBootPosition)(&maxBootPosition);
317 for (ULONG i = 1; i <= maxBootPosition; i++)
318 {
319 DeviceType_T bootOrder;
320 machine->GetBootOrder(i, &bootOrder);
321 if (bootOrder == DeviceType_Floppy)
322 {
323 if (details == VMINFO_MACHINEREADABLE)
324 RTPrintf("boot%d=\"floppy\"\n", i);
325 else
326 RTPrintf("Boot Device (%d): Floppy\n", i);
327 }
328 else if (bootOrder == DeviceType_DVD)
329 {
330 if (details == VMINFO_MACHINEREADABLE)
331 RTPrintf("boot%d=\"dvd\"\n", i);
332 else
333 RTPrintf("Boot Device (%d): DVD\n", i);
334 }
335 else if (bootOrder == DeviceType_HardDisk)
336 {
337 if (details == VMINFO_MACHINEREADABLE)
338 RTPrintf("boot%d=\"disk\"\n", i);
339 else
340 RTPrintf("Boot Device (%d): HardDisk\n", i);
341 }
342 else if (bootOrder == DeviceType_Network)
343 {
344 if (details == VMINFO_MACHINEREADABLE)
345 RTPrintf("boot%d=\"net\"\n", i);
346 else
347 RTPrintf("Boot Device (%d): Network\n", i);
348 }
349 else if (bootOrder == DeviceType_USB)
350 {
351 if (details == VMINFO_MACHINEREADABLE)
352 RTPrintf("boot%d=\"usb\"\n", i);
353 else
354 RTPrintf("Boot Device (%d): USB\n", i);
355 }
356 else if (bootOrder == DeviceType_SharedFolder)
357 {
358 if (details == VMINFO_MACHINEREADABLE)
359 RTPrintf("boot%d=\"sharedfolder\"\n", i);
360 else
361 RTPrintf("Boot Device (%d): Shared Folder\n", i);
362 }
363 else
364 {
365 if (details == VMINFO_MACHINEREADABLE)
366 RTPrintf("boot%d=\"none\"\n", i);
367 else
368 RTPrintf("Boot Device (%d): Not Assigned\n", i);
369 }
370 }
371
372 BOOL acpiEnabled;
373 biosSettings->COMGETTER(ACPIEnabled)(&acpiEnabled);
374 if (details == VMINFO_MACHINEREADABLE)
375 RTPrintf("acpi=\"%s\"\n", acpiEnabled ? "on" : "off");
376 else
377 RTPrintf("ACPI: %s\n", acpiEnabled ? "on" : "off");
378
379 BOOL ioapicEnabled;
380 biosSettings->COMGETTER(IOAPICEnabled)(&ioapicEnabled);
381 if (details == VMINFO_MACHINEREADABLE)
382 RTPrintf("ioapic=\"%s\"\n", ioapicEnabled ? "on" : "off");
383 else
384 RTPrintf("IOAPIC: %s\n", ioapicEnabled ? "on" : "off");
385
386 BOOL PAEEnabled;
387 machine->GetCpuProperty(CpuPropertyType_PAE, &PAEEnabled);
388 if (details == VMINFO_MACHINEREADABLE)
389 RTPrintf("pae=\"%s\"\n", PAEEnabled ? "on" : "off");
390 else
391 RTPrintf("PAE: %s\n", PAEEnabled ? "on" : "off");
392
393 LONG64 timeOffset;
394 biosSettings->COMGETTER(TimeOffset)(&timeOffset);
395 if (details == VMINFO_MACHINEREADABLE)
396 RTPrintf("biossystemtimeoffset=%lld\n", timeOffset);
397 else
398 RTPrintf("Time offset: %lld ms\n", timeOffset);
399
400 BOOL hwVirtExEnabled;
401 machine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &hwVirtExEnabled);
402 if (details == VMINFO_MACHINEREADABLE)
403 RTPrintf("hwvirtex=\"%s\"\n", hwVirtExEnabled ? "on" : "off");
404 else
405 RTPrintf("Hardw. virt.ext: %s\n", hwVirtExEnabled ? "on" : "off");
406
407 BOOL hwVirtExExclusive;
408 machine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &hwVirtExExclusive);
409 if (details == VMINFO_MACHINEREADABLE)
410 RTPrintf("hwvirtexexcl=\"%s\"\n", hwVirtExExclusive ? "on" : "off");
411 else
412 RTPrintf("Hardw. virt.ext exclusive: %s\n", hwVirtExExclusive ? "on" : "off");
413
414 BOOL HWVirtExNestedPagingEnabled;
415 machine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &HWVirtExNestedPagingEnabled);
416 if (details == VMINFO_MACHINEREADABLE)
417 RTPrintf("nestedpaging=\"%s\"\n", HWVirtExNestedPagingEnabled ? "on" : "off");
418 else
419 RTPrintf("Nested Paging: %s\n", HWVirtExNestedPagingEnabled ? "on" : "off");
420
421 BOOL HWVirtExVPIDEnabled;
422 machine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &HWVirtExVPIDEnabled);
423 if (details == VMINFO_MACHINEREADABLE)
424 RTPrintf("vtxvpid=\"%s\"\n", HWVirtExVPIDEnabled ? "on" : "off");
425 else
426 RTPrintf("VT-x VPID: %s\n", HWVirtExVPIDEnabled ? "on" : "off");
427
428 MachineState_T machineState;
429 const char *pszState = NULL;
430 rc = machine->COMGETTER(State)(&machineState);
431 switch (machineState)
432 {
433 case MachineState_PoweredOff:
434 pszState = details == VMINFO_MACHINEREADABLE ? "poweroff" : "powered off";
435 break;
436 case MachineState_Saved:
437 pszState = "saved";
438 break;
439 case MachineState_Aborted:
440 pszState = "aborted";
441 break;
442 case MachineState_Teleported:
443 pszState = "teleported";
444 break;
445 case MachineState_Running:
446 pszState = "running";
447 break;
448 case MachineState_Paused:
449 pszState = "paused";
450 break;
451 case MachineState_Stuck:
452 pszState = details == VMINFO_MACHINEREADABLE ? "gurumeditation" : "guru meditation";
453 break;
454 case MachineState_LiveSnapshotting:
455 pszState = details == VMINFO_MACHINEREADABLE ? "livesnapshotting" : "live snapshotting";
456 break;
457 case MachineState_Teleporting:
458 pszState = "teleporting";
459 break;
460 case MachineState_Starting:
461 pszState = "starting";
462 break;
463 case MachineState_Stopping:
464 pszState = "stopping";
465 break;
466 case MachineState_Saving:
467 pszState = "saving";
468 break;
469 case MachineState_Restoring:
470 pszState = "restoring";
471 break;
472 case MachineState_TeleportingPausedVM:
473 pszState = details == VMINFO_MACHINEREADABLE ? "teleportingpausedvm" : "teleporting paused vm";
474 break;
475 case MachineState_TeleportingIn:
476 pszState = details == VMINFO_MACHINEREADABLE ? "teleportingin" : "teleporting (incoming)";
477 break;
478 case MachineState_RestoringSnapshot:
479 pszState = details == VMINFO_MACHINEREADABLE ? "restoringsnapshot" : "restoring snapshot";
480 case MachineState_DeletingSnapshot:
481 pszState = details == VMINFO_MACHINEREADABLE ? "deletingsnapshot" : "deleting snapshot";
482 case MachineState_SettingUp:
483 pszState = details == VMINFO_MACHINEREADABLE ? "settingup" : "setting up";
484 break;
485 default:
486 pszState = "unknown";
487 break;
488 }
489 LONG64 stateSince;
490 machine->COMGETTER(LastStateChange)(&stateSince);
491 RTTIMESPEC timeSpec;
492 RTTimeSpecSetMilli(&timeSpec, stateSince);
493 char pszTime[30] = {0};
494 RTTimeSpecToString(&timeSpec, pszTime, sizeof(pszTime));
495 Bstr stateFile;
496 machine->COMGETTER(StateFilePath)(stateFile.asOutParam());
497 if (details == VMINFO_MACHINEREADABLE)
498 {
499 RTPrintf("VMState=\"%s\"\n", pszState);
500 RTPrintf("VMStateChangeTime=\"%s\"\n", pszTime);
501 if (!stateFile.isEmpty())
502 RTPrintf("VMStateFile=\"%lS\"\n", stateFile.raw());
503 }
504 else
505 RTPrintf("State: %s (since %s)\n", pszState, pszTime);
506
507 ULONG numMonitors;
508 machine->COMGETTER(MonitorCount)(&numMonitors);
509 if (details == VMINFO_MACHINEREADABLE)
510 RTPrintf("monitorcount=%d\n", numMonitors);
511 else
512 RTPrintf("Monitor count: %d\n", numMonitors);
513
514 BOOL accelerate3d;
515 machine->COMGETTER(Accelerate3DEnabled)(&accelerate3d);
516 if (details == VMINFO_MACHINEREADABLE)
517 RTPrintf("accelerate3d=\"%s\"\n", accelerate3d ? "on" : "off");
518 else
519 RTPrintf("3D Acceleration: %s\n", accelerate3d ? "on" : "off");
520
521#ifdef VBOX_WITH_VIDEOHWACCEL
522 BOOL accelerate2dVideo;
523 machine->COMGETTER(Accelerate2DVideoEnabled)(&accelerate2dVideo);
524 if (details == VMINFO_MACHINEREADABLE)
525 RTPrintf("accelerate2dvideo=\"%s\"\n", accelerate2dVideo ? "on" : "off");
526 else
527 RTPrintf("2D Video Acceleration: %s\n", accelerate2dVideo ? "on" : "off");
528#endif
529
530 BOOL teleporterEnabled;
531 machine->COMGETTER(TeleporterEnabled)(&teleporterEnabled);
532 if (details == VMINFO_MACHINEREADABLE)
533 RTPrintf("teleporterenabled=\"%s\"\n", teleporterEnabled ? "on" : "off");
534 else
535 RTPrintf("Teleporter Enabled: %s\n", teleporterEnabled ? "on" : "off");
536
537 ULONG teleporterPort;
538 machine->COMGETTER(TeleporterPort)(&teleporterPort);
539 if (details == VMINFO_MACHINEREADABLE)
540 RTPrintf("teleporterport=%u\n", teleporterPort);
541 else
542 RTPrintf("Teleporter Port: %u\n", teleporterPort);
543
544 Bstr teleporterAddress;
545 machine->COMGETTER(TeleporterAddress)(teleporterAddress.asOutParam());
546 if (details == VMINFO_MACHINEREADABLE)
547 RTPrintf("teleporteraddress=\"%lS\"\n", teleporterAddress.raw());
548 else
549 RTPrintf("Teleporter Address: %lS\n", teleporterAddress.raw());
550
551 Bstr teleporterPassword;
552 machine->COMGETTER(TeleporterPassword)(teleporterPassword.asOutParam());
553 if (details == VMINFO_MACHINEREADABLE)
554 RTPrintf("teleporterpassword=\"%lS\"\n", teleporterPassword.raw());
555 else
556 RTPrintf("Teleporter Password: %lS\n", teleporterPassword.raw());
557
558 /*
559 * Storage Controllers and their attached Mediums.
560 */
561 com::SafeIfaceArray<IStorageController> storageCtls;
562 CHECK_ERROR(machine, COMGETTER(StorageControllers)(ComSafeArrayAsOutParam (storageCtls)));
563 for (size_t i = 0; i < storageCtls.size(); ++ i)
564 {
565 ComPtr<IStorageController> storageCtl = storageCtls[i];
566 StorageControllerType_T enmCtlType = StorageControllerType_Null;
567 const char *pszCtl = NULL;
568 ULONG ulValue = 0;
569 Bstr storageCtlName;
570
571 storageCtl->COMGETTER(Name)(storageCtlName.asOutParam());
572 if (details == VMINFO_MACHINEREADABLE)
573 RTPrintf("storagecontrollername%u=\"%lS\"\n", i, storageCtlName.raw());
574 else
575 RTPrintf("Storage Controller Name (%u): %lS\n", i, storageCtlName.raw());
576
577 storageCtl->COMGETTER(ControllerType)(&enmCtlType);
578 switch (enmCtlType)
579 {
580 case StorageControllerType_LsiLogic:
581 pszCtl = "LsiLogic";
582 break;
583 case StorageControllerType_BusLogic:
584 pszCtl = "BusLogic";
585 break;
586 case StorageControllerType_IntelAhci:
587 pszCtl = "IntelAhci";
588 break;
589 case StorageControllerType_PIIX3:
590 pszCtl = "PIIX3";
591 break;
592 case StorageControllerType_PIIX4:
593 pszCtl = "PIIX4";
594 break;
595 case StorageControllerType_ICH6:
596 pszCtl = "ICH6";
597 break;
598 case StorageControllerType_I82078:
599 pszCtl = "I82078";
600 break;
601
602 default:
603 pszCtl = "unknown";
604 }
605 if (details == VMINFO_MACHINEREADABLE)
606 RTPrintf("storagecontrollertype%u=\"%s\"\n", i, pszCtl);
607 else
608 RTPrintf("Storage Controller Type (%u): %s\n", i, pszCtl);
609
610 storageCtl->COMGETTER(Instance)(&ulValue);
611 if (details == VMINFO_MACHINEREADABLE)
612 RTPrintf("storagecontrollerinstance%u=\"%lu\"\n", i, ulValue);
613 else
614 RTPrintf("Storage Controller Instance Number (%u): %lu\n", i, ulValue);
615
616 storageCtl->COMGETTER(MaxPortCount)(&ulValue);
617 if (details == VMINFO_MACHINEREADABLE)
618 RTPrintf("storagecontrollermaxportcount%u=\"%lu\"\n", i, ulValue);
619 else
620 RTPrintf("Storage Controller Max Port Count (%u): %lu\n", i, ulValue);
621
622 storageCtl->COMGETTER(PortCount)(&ulValue);
623 if (details == VMINFO_MACHINEREADABLE)
624 RTPrintf("storagecontrollerportcount%u=\"%lu\"\n", i, ulValue);
625 else
626 RTPrintf("Storage Controller Port Count (%u): %lu\n", i, ulValue);
627 }
628
629 for (size_t j = 0; j < storageCtls.size(); ++ j)
630 {
631 ComPtr<IStorageController> storageCtl = storageCtls[j];
632 ComPtr<IMedium> medium;
633 Bstr storageCtlName;
634 Bstr filePath;
635 ULONG cDevices;
636 ULONG cPorts;
637
638 storageCtl->COMGETTER(Name)(storageCtlName.asOutParam());
639 storageCtl->COMGETTER(MaxDevicesPerPortCount)(&cDevices);
640 storageCtl->COMGETTER(PortCount)(&cPorts);
641
642 for (ULONG i = 0; i < cPorts; ++ i)
643 {
644 for (ULONG k = 0; k < cDevices; ++ k)
645 {
646 rc = machine->GetMedium(storageCtlName, i, k, medium.asOutParam());
647 if (SUCCEEDED(rc) && medium)
648 {
649 BOOL fPassthrough;
650 ComPtr<IMediumAttachment> mediumAttach;
651
652 rc = machine->GetMediumAttachment(storageCtlName, i, k, mediumAttach.asOutParam());
653 if (SUCCEEDED(rc) && mediumAttach)
654 mediumAttach->COMGETTER(Passthrough)(&fPassthrough);
655
656 medium->COMGETTER(Location)(filePath.asOutParam());
657 medium->COMGETTER(Id)(uuid.asOutParam());
658
659 if (details == VMINFO_MACHINEREADABLE)
660 {
661 RTPrintf("\"%lS-%d-%d\"=\"%lS\"\n", storageCtlName.raw(),
662 i, k, filePath.raw());
663 RTPrintf("\"%lS-ImageUUID-%d-%d\"=\"%s\"\n",
664 storageCtlName.raw(), i, k, Utf8Str(uuid).raw());
665 if (fPassthrough)
666 RTPrintf("\"%lS-dvdpassthrough\"=\"%s\"\n", storageCtlName.raw(),
667 fPassthrough ? "on" : "off");
668 }
669 else
670 {
671 RTPrintf("%lS (%d, %d): %lS (UUID: %s)",
672 storageCtlName.raw(), i, k, filePath.raw(),
673 Utf8Str(uuid).raw());
674 if (fPassthrough)
675 RTPrintf(" (passthrough enabled)");
676 RTPrintf("\n");
677 }
678 }
679 else
680 {
681 if (details == VMINFO_MACHINEREADABLE)
682 RTPrintf("\"%lS-%d-%d\"=\"none\"\n", storageCtlName.raw(), i, k);
683 }
684 }
685 }
686 }
687
688 /* get the maximum amount of NICS */
689 ComPtr<ISystemProperties> sysProps;
690 virtualBox->COMGETTER(SystemProperties)(sysProps.asOutParam());
691 ULONG maxNICs = 0;
692 sysProps->COMGETTER(NetworkAdapterCount)(&maxNICs);
693 for (ULONG currentNIC = 0; currentNIC < maxNICs; currentNIC++)
694 {
695 ComPtr<INetworkAdapter> nic;
696 rc = machine->GetNetworkAdapter(currentNIC, nic.asOutParam());
697 if (SUCCEEDED(rc) && nic)
698 {
699 BOOL fEnabled;
700 nic->COMGETTER(Enabled)(&fEnabled);
701 if (!fEnabled)
702 {
703 if (details == VMINFO_MACHINEREADABLE)
704 RTPrintf("nic%d=\"none\"\n", currentNIC + 1);
705 else
706 RTPrintf("NIC %d: disabled\n", currentNIC + 1);
707 }
708 else
709 {
710 Bstr strMACAddress;
711 nic->COMGETTER(MACAddress)(strMACAddress.asOutParam());
712 Utf8Str strAttachment;
713 NetworkAttachmentType_T attachment;
714 nic->COMGETTER(AttachmentType)(&attachment);
715 switch (attachment)
716 {
717 case NetworkAttachmentType_Null:
718 if (details == VMINFO_MACHINEREADABLE)
719 strAttachment = "null";
720 else
721 strAttachment = "none";
722 break;
723 case NetworkAttachmentType_NAT:
724 {
725 Bstr strNetwork;
726 nic->COMGETTER(NATNetwork)(strNetwork.asOutParam());
727 if (details == VMINFO_MACHINEREADABLE)
728 {
729 RTPrintf("natnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
730 strAttachment = "nat";
731 }
732 else if (!strNetwork.isEmpty())
733 strAttachment = Utf8StrFmt("NAT (%lS)", strNetwork.raw());
734 else
735 strAttachment = "NAT";
736 break;
737 }
738 case NetworkAttachmentType_Bridged:
739 {
740 Bstr strBridgeAdp;
741 nic->COMGETTER(HostInterface)(strBridgeAdp.asOutParam());
742 if (details == VMINFO_MACHINEREADABLE)
743 {
744 RTPrintf("bridgeadapter%d=\"%lS\"\n", currentNIC + 1, strBridgeAdp.raw());
745 strAttachment = "bridged";
746 }
747 else
748 strAttachment = Utf8StrFmt("Bridged Interface '%lS'", strBridgeAdp.raw());
749 break;
750 }
751 case NetworkAttachmentType_Internal:
752 {
753 Bstr strNetwork;
754 nic->COMGETTER(InternalNetwork)(strNetwork.asOutParam());
755 if (details == VMINFO_MACHINEREADABLE)
756 {
757 RTPrintf("intnet%d=\"%lS\"\n", currentNIC + 1, strNetwork.raw());
758 strAttachment = "intnet";
759 }
760 else
761 strAttachment = Utf8StrFmt("Internal Network '%s'", Utf8Str(strNetwork).raw());
762 break;
763 }
764#if defined(VBOX_WITH_NETFLT)
765 case NetworkAttachmentType_HostOnly:
766 {
767 Bstr strHostonlyAdp;
768 nic->COMGETTER(HostInterface)(strHostonlyAdp.asOutParam());
769 if (details == VMINFO_MACHINEREADABLE)
770 {
771 RTPrintf("hostonlyadapter%d=\"%lS\"\n", currentNIC + 1, strHostonlyAdp.raw());
772 strAttachment = "hostonly";
773 }
774 else
775 strAttachment = Utf8StrFmt("Host-only Interface '%lS'", strHostonlyAdp.raw());
776 break;
777 }
778#endif
779 default:
780 strAttachment = "unknown";
781 break;
782 }
783
784 /* cable connected */
785 BOOL fConnected;
786 nic->COMGETTER(CableConnected)(&fConnected);
787
788 /* trace stuff */
789 BOOL fTraceEnabled;
790 nic->COMGETTER(TraceEnabled)(&fTraceEnabled);
791 Bstr traceFile;
792 nic->COMGETTER(TraceFile)(traceFile.asOutParam());
793
794 /* NIC type */
795 Utf8Str strNICType;
796 NetworkAdapterType_T NICType;
797 nic->COMGETTER(AdapterType)(&NICType);
798 switch (NICType) {
799 case NetworkAdapterType_Am79C970A:
800 strNICType = "Am79C970A";
801 break;
802 case NetworkAdapterType_Am79C973:
803 strNICType = "Am79C973";
804 break;
805#ifdef VBOX_WITH_E1000
806 case NetworkAdapterType_I82540EM:
807 strNICType = "82540EM";
808 break;
809 case NetworkAdapterType_I82543GC:
810 strNICType = "82543GC";
811 break;
812 case NetworkAdapterType_I82545EM:
813 strNICType = "82545EM";
814 break;
815#endif
816#ifdef VBOX_WITH_VIRTIO
817 case NetworkAdapterType_Virtio:
818 strNICType = "virtio";
819 break;
820#endif /* VBOX_WITH_VIRTIO */
821 default:
822 strNICType = "unknown";
823 break;
824 }
825
826 /* reported line speed */
827 ULONG ulLineSpeed;
828 nic->COMGETTER(LineSpeed)(&ulLineSpeed);
829
830 if (details == VMINFO_MACHINEREADABLE)
831 {
832 RTPrintf("macaddress%d=\"%lS\"\n", currentNIC + 1, strMACAddress.raw());
833 RTPrintf("cableconnected%d=\"%s\"\n", currentNIC + 1, fConnected ? "on" : "off");
834 RTPrintf("nic%d=\"%s\"\n", currentNIC + 1, strAttachment.raw());
835 }
836 else
837 RTPrintf("NIC %d: MAC: %lS, Attachment: %s, Cable connected: %s, Trace: %s (file: %lS), Type: %s, Reported speed: %d Mbps\n",
838 currentNIC + 1, strMACAddress.raw(), strAttachment.raw(),
839 fConnected ? "on" : "off",
840 fTraceEnabled ? "on" : "off",
841 traceFile.isEmpty() ? Bstr("none").raw() : traceFile.raw(),
842 strNICType.raw(),
843 ulLineSpeed / 1000);
844 }
845 }
846 }
847
848 /* get the maximum amount of UARTs */
849 ULONG maxUARTs = 0;
850 sysProps->COMGETTER(SerialPortCount)(&maxUARTs);
851 for (ULONG currentUART = 0; currentUART < maxUARTs; currentUART++)
852 {
853 ComPtr<ISerialPort> uart;
854 rc = machine->GetSerialPort(currentUART, uart.asOutParam());
855 if (SUCCEEDED(rc) && uart)
856 {
857 BOOL fEnabled;
858 uart->COMGETTER(Enabled)(&fEnabled);
859 if (!fEnabled)
860 {
861 if (details == VMINFO_MACHINEREADABLE)
862 RTPrintf("uart%d=\"off\"\n", currentUART + 1);
863 else
864 RTPrintf("UART %d: disabled\n", currentUART + 1);
865 }
866 else
867 {
868 ULONG ulIRQ, ulIOBase;
869 PortMode_T HostMode;
870 Bstr path;
871 BOOL fServer;
872 uart->COMGETTER(IRQ)(&ulIRQ);
873 uart->COMGETTER(IOBase)(&ulIOBase);
874 uart->COMGETTER(Path)(path.asOutParam());
875 uart->COMGETTER(Server)(&fServer);
876 uart->COMGETTER(HostMode)(&HostMode);
877
878 if (details == VMINFO_MACHINEREADABLE)
879 RTPrintf("uart%d=\"%#06x,%d\"\n", currentUART + 1,
880 ulIOBase, ulIRQ);
881 else
882 RTPrintf("UART %d: I/O base: 0x%04x, IRQ: %d",
883 currentUART + 1, ulIOBase, ulIRQ);
884 switch (HostMode)
885 {
886 default:
887 case PortMode_Disconnected:
888 if (details == VMINFO_MACHINEREADABLE)
889 RTPrintf("uartmode%d=\"disconnected\"\n", currentUART + 1);
890 else
891 RTPrintf(", disconnected\n");
892 break;
893 case PortMode_RawFile:
894 if (details == VMINFO_MACHINEREADABLE)
895 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
896 path.raw());
897 else
898 RTPrintf(", attached to raw file '%lS'\n",
899 path.raw());
900 break;
901 case PortMode_HostPipe:
902 if (details == VMINFO_MACHINEREADABLE)
903 RTPrintf("uartmode%d=\"%s,%lS\"\n", currentUART + 1,
904 fServer ? "server" : "client", path.raw());
905 else
906 RTPrintf(", attached to pipe (%s) '%lS'\n",
907 fServer ? "server" : "client", path.raw());
908 break;
909 case PortMode_HostDevice:
910 if (details == VMINFO_MACHINEREADABLE)
911 RTPrintf("uartmode%d=\"%lS\"\n", currentUART + 1,
912 path.raw());
913 else
914 RTPrintf(", attached to device '%lS'\n", path.raw());
915 break;
916 }
917 }
918 }
919 }
920
921 ComPtr<IAudioAdapter> AudioAdapter;
922 rc = machine->COMGETTER(AudioAdapter)(AudioAdapter.asOutParam());
923 if (SUCCEEDED(rc))
924 {
925 const char *pszDrv = "Unknown";
926 const char *pszCtrl = "Unknown";
927 BOOL fEnabled;
928 rc = AudioAdapter->COMGETTER(Enabled)(&fEnabled);
929 if (SUCCEEDED(rc) && fEnabled)
930 {
931 AudioDriverType_T enmDrvType;
932 rc = AudioAdapter->COMGETTER(AudioDriver)(&enmDrvType);
933 switch (enmDrvType)
934 {
935 case AudioDriverType_Null:
936 if (details == VMINFO_MACHINEREADABLE)
937 pszDrv = "null";
938 else
939 pszDrv = "Null";
940 break;
941 case AudioDriverType_WinMM:
942 if (details == VMINFO_MACHINEREADABLE)
943 pszDrv = "winmm";
944 else
945 pszDrv = "WINMM";
946 break;
947 case AudioDriverType_DirectSound:
948 if (details == VMINFO_MACHINEREADABLE)
949 pszDrv = "dsound";
950 else
951 pszDrv = "DSOUND";
952 break;
953 case AudioDriverType_OSS:
954 if (details == VMINFO_MACHINEREADABLE)
955 pszDrv = "oss";
956 else
957 pszDrv = "OSS";
958 break;
959 case AudioDriverType_ALSA:
960 if (details == VMINFO_MACHINEREADABLE)
961 pszDrv = "alsa";
962 else
963 pszDrv = "ALSA";
964 break;
965 case AudioDriverType_Pulse:
966 if (details == VMINFO_MACHINEREADABLE)
967 pszDrv = "pulse";
968 else
969 pszDrv = "PulseAudio";
970 break;
971 case AudioDriverType_CoreAudio:
972 if (details == VMINFO_MACHINEREADABLE)
973 pszDrv = "coreaudio";
974 else
975 pszDrv = "CoreAudio";
976 break;
977 case AudioDriverType_SolAudio:
978 if (details == VMINFO_MACHINEREADABLE)
979 pszDrv = "solaudio";
980 else
981 pszDrv = "SolAudio";
982 break;
983 default:
984 if (details == VMINFO_MACHINEREADABLE)
985 pszDrv = "unknown";
986 break;
987 }
988 AudioControllerType_T enmCtrlType;
989 rc = AudioAdapter->COMGETTER(AudioController)(&enmCtrlType);
990 switch (enmCtrlType)
991 {
992 case AudioControllerType_AC97:
993 if (details == VMINFO_MACHINEREADABLE)
994 pszCtrl = "ac97";
995 else
996 pszCtrl = "AC97";
997 break;
998 case AudioControllerType_SB16:
999 if (details == VMINFO_MACHINEREADABLE)
1000 pszCtrl = "sb16";
1001 else
1002 pszCtrl = "SB16";
1003 break;
1004 }
1005 }
1006 else
1007 fEnabled = FALSE;
1008 if (details == VMINFO_MACHINEREADABLE)
1009 {
1010 if (fEnabled)
1011 RTPrintf("audio=\"%s\"\n", pszDrv);
1012 else
1013 RTPrintf("audio=\"none\"\n");
1014 }
1015 else
1016 {
1017 RTPrintf("Audio: %s",
1018 fEnabled ? "enabled" : "disabled");
1019 if (fEnabled)
1020 RTPrintf(" (Driver: %s, Controller: %s)",
1021 pszDrv, pszCtrl);
1022 RTPrintf("\n");
1023 }
1024 }
1025
1026 /* Shared clipboard */
1027 {
1028 const char *psz = "Unknown";
1029 ClipboardMode_T enmMode;
1030 rc = machine->COMGETTER(ClipboardMode)(&enmMode);
1031 switch (enmMode)
1032 {
1033 case ClipboardMode_Disabled:
1034 if (details == VMINFO_MACHINEREADABLE)
1035 psz = "disabled";
1036 else
1037 psz = "disabled";
1038 break;
1039 case ClipboardMode_HostToGuest:
1040 if (details == VMINFO_MACHINEREADABLE)
1041 psz = "hosttoguest";
1042 else
1043 psz = "HostToGuest";
1044 break;
1045 case ClipboardMode_GuestToHost:
1046 if (details == VMINFO_MACHINEREADABLE)
1047 psz = "guesttohost";
1048 else
1049 psz = "GuestToHost";
1050 break;
1051 case ClipboardMode_Bidirectional:
1052 if (details == VMINFO_MACHINEREADABLE)
1053 psz = "bidirectional";
1054 else
1055 psz = "Bidirectional";
1056 break;
1057 default:
1058 if (details == VMINFO_MACHINEREADABLE)
1059 psz = "unknown";
1060 break;
1061 }
1062 if (details == VMINFO_MACHINEREADABLE)
1063 RTPrintf("clipboard=\"%s\"\n", psz);
1064 else
1065 RTPrintf("Clipboard Mode: %s\n", psz);
1066 }
1067
1068 if (console)
1069 {
1070 ComPtr<IDisplay> display;
1071 CHECK_ERROR_RET(console, COMGETTER(Display)(display.asOutParam()), rc);
1072 do
1073 {
1074 ULONG xRes, yRes, bpp;
1075 rc = display->COMGETTER(Width)(&xRes);
1076 if (rc == E_ACCESSDENIED)
1077 break; /* VM not powered up */
1078 if (FAILED(rc))
1079 {
1080 com::ErrorInfo info (display);
1081 GluePrintErrorInfo(info);
1082 return rc;
1083 }
1084 rc = display->COMGETTER(Height)(&yRes);
1085 if (rc == E_ACCESSDENIED)
1086 break; /* VM not powered up */
1087 if (FAILED(rc))
1088 {
1089 com::ErrorInfo info (display);
1090 GluePrintErrorInfo(info);
1091 return rc;
1092 }
1093 rc = display->COMGETTER(BitsPerPixel)(&bpp);
1094 if (rc == E_ACCESSDENIED)
1095 break; /* VM not powered up */
1096 if (FAILED(rc))
1097 {
1098 com::ErrorInfo info (display);
1099 GluePrintErrorInfo(info);
1100 return rc;
1101 }
1102 if (details == VMINFO_MACHINEREADABLE)
1103 RTPrintf("VideoMode=\"%d,%d,%d\"\n", xRes, yRes, bpp);
1104 else
1105 RTPrintf("Video mode: %dx%dx%d\n", xRes, yRes, bpp);
1106 }
1107 while (0);
1108 }
1109
1110 /*
1111 * VRDP
1112 */
1113 ComPtr<IVRDPServer> vrdpServer;
1114 rc = machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1115 if (SUCCEEDED(rc) && vrdpServer)
1116 {
1117 BOOL fEnabled = false;
1118 vrdpServer->COMGETTER(Enabled)(&fEnabled);
1119 if (fEnabled)
1120 {
1121 LONG vrdpPort = -1;
1122 Bstr ports;
1123 vrdpServer->COMGETTER(Ports)(ports.asOutParam());
1124 Bstr address;
1125 vrdpServer->COMGETTER(NetAddress)(address.asOutParam());
1126 BOOL fMultiCon;
1127 vrdpServer->COMGETTER(AllowMultiConnection)(&fMultiCon);
1128 BOOL fReuseCon;
1129 vrdpServer->COMGETTER(ReuseSingleConnection)(&fReuseCon);
1130 VRDPAuthType_T vrdpAuthType;
1131 const char *strAuthType;
1132 vrdpServer->COMGETTER(AuthType)(&vrdpAuthType);
1133 switch (vrdpAuthType)
1134 {
1135 case VRDPAuthType_Null:
1136 strAuthType = "null";
1137 break;
1138 case VRDPAuthType_External:
1139 strAuthType = "external";
1140 break;
1141 case VRDPAuthType_Guest:
1142 strAuthType = "guest";
1143 break;
1144 default:
1145 strAuthType = "unknown";
1146 break;
1147 }
1148 if (console)
1149 {
1150 ComPtr<IRemoteDisplayInfo> remoteDisplayInfo;
1151 CHECK_ERROR_RET(console, COMGETTER(RemoteDisplayInfo)(remoteDisplayInfo.asOutParam()), rc);
1152 rc = remoteDisplayInfo->COMGETTER(Port)(&vrdpPort);
1153 if (rc == E_ACCESSDENIED)
1154 {
1155 vrdpPort = -1; /* VM not powered up */
1156 }
1157 if (FAILED(rc))
1158 {
1159 com::ErrorInfo info (remoteDisplayInfo);
1160 GluePrintErrorInfo(info);
1161 return rc;
1162 }
1163 }
1164 if (details == VMINFO_MACHINEREADABLE)
1165 {
1166 RTPrintf("vrdp=\"on\"\n");
1167 RTPrintf("vrdpport=%d\n", vrdpPort);
1168 RTPrintf("vrdpports=\"%lS\"\n", ports.raw());
1169 RTPrintf("vrdpaddress=\"%lS\"\n", address.raw());
1170 RTPrintf("vrdpauthtype=\"%s\"\n", strAuthType);
1171 RTPrintf("vrdpmulticon=\"%s\"\n", fMultiCon ? "on" : "off");
1172 RTPrintf("vrdpreusecon=\"%s\"\n", fReuseCon ? "on" : "off");
1173 }
1174 else
1175 {
1176 if (address.isEmpty())
1177 address = "0.0.0.0";
1178 RTPrintf("VRDP: enabled (Address %lS, Ports %lS, MultiConn: %s, ReuseSingleConn: %s, Authentication type: %s)\n", address.raw(), ports.raw(), fMultiCon ? "on" : "off", fReuseCon ? "on" : "off", strAuthType);
1179 if (console && vrdpPort != -1 && vrdpPort != 0)
1180 RTPrintf("VRDP port: %d\n", vrdpPort);
1181 }
1182 }
1183 else
1184 {
1185 if (details == VMINFO_MACHINEREADABLE)
1186 RTPrintf("vrdp=\"off\"\n");
1187 else
1188 RTPrintf("VRDP: disabled\n");
1189 }
1190 }
1191
1192 /*
1193 * USB.
1194 */
1195 ComPtr<IUSBController> USBCtl;
1196 rc = machine->COMGETTER(USBController)(USBCtl.asOutParam());
1197 if (SUCCEEDED(rc))
1198 {
1199 BOOL fEnabled;
1200 rc = USBCtl->COMGETTER(Enabled)(&fEnabled);
1201 if (FAILED(rc))
1202 fEnabled = false;
1203 if (details == VMINFO_MACHINEREADABLE)
1204 RTPrintf("usb=\"%s\"\n", fEnabled ? "on" : "off");
1205 else
1206 RTPrintf("USB: %s\n", fEnabled ? "enabled" : "disabled");
1207
1208 if (details != VMINFO_MACHINEREADABLE)
1209 RTPrintf("\nUSB Device Filters:\n\n");
1210
1211 SafeIfaceArray <IUSBDeviceFilter> Coll;
1212 CHECK_ERROR_RET (USBCtl, COMGETTER(DeviceFilters)(ComSafeArrayAsOutParam(Coll)), rc);
1213
1214 if (Coll.size() == 0)
1215 {
1216 if (details != VMINFO_MACHINEREADABLE)
1217 RTPrintf("<none>\n\n");
1218 }
1219 else
1220 {
1221 for (size_t index = 0; index < Coll.size(); ++index)
1222 {
1223 ComPtr<IUSBDeviceFilter> DevPtr = Coll[index];
1224
1225 /* Query info. */
1226
1227 if (details != VMINFO_MACHINEREADABLE)
1228 RTPrintf("Index: %zu\n", index);
1229
1230 BOOL bActive = FALSE;
1231 CHECK_ERROR_RET (DevPtr, COMGETTER (Active) (&bActive), rc);
1232 if (details == VMINFO_MACHINEREADABLE)
1233 RTPrintf("USBFilterActive%zu=\"%s\"\n", index + 1, bActive ? "on" : "off");
1234 else
1235 RTPrintf("Active: %s\n", bActive ? "yes" : "no");
1236
1237 Bstr bstr;
1238 CHECK_ERROR_RET (DevPtr, COMGETTER (Name) (bstr.asOutParam()), rc);
1239 if (details == VMINFO_MACHINEREADABLE)
1240 RTPrintf("USBFilterName%zu=\"%lS\"\n", index + 1, bstr.raw());
1241 else
1242 RTPrintf("Name: %lS\n", bstr.raw());
1243 CHECK_ERROR_RET (DevPtr, COMGETTER (VendorId) (bstr.asOutParam()), rc);
1244 if (details == VMINFO_MACHINEREADABLE)
1245 RTPrintf("USBFilterVendorId%zu=\"%lS\"\n", index + 1, bstr.raw());
1246 else
1247 RTPrintf("VendorId: %lS\n", bstr.raw());
1248 CHECK_ERROR_RET (DevPtr, COMGETTER (ProductId) (bstr.asOutParam()), rc);
1249 if (details == VMINFO_MACHINEREADABLE)
1250 RTPrintf("USBFilterProductId%zu=\"%lS\"\n", index + 1, bstr.raw());
1251 else
1252 RTPrintf("ProductId: %lS\n", bstr.raw());
1253 CHECK_ERROR_RET (DevPtr, COMGETTER (Revision) (bstr.asOutParam()), rc);
1254 if (details == VMINFO_MACHINEREADABLE)
1255 RTPrintf("USBFilterRevision%zu=\"%lS\"\n", index + 1, bstr.raw());
1256 else
1257 RTPrintf("Revision: %lS\n", bstr.raw());
1258 CHECK_ERROR_RET (DevPtr, COMGETTER (Manufacturer) (bstr.asOutParam()), rc);
1259 if (details == VMINFO_MACHINEREADABLE)
1260 RTPrintf("USBFilterManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1261 else
1262 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1263 CHECK_ERROR_RET (DevPtr, COMGETTER (Product) (bstr.asOutParam()), rc);
1264 if (details == VMINFO_MACHINEREADABLE)
1265 RTPrintf("USBFilterProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1266 else
1267 RTPrintf("Product: %lS\n", bstr.raw());
1268 CHECK_ERROR_RET (DevPtr, COMGETTER (Remote) (bstr.asOutParam()), rc);
1269 if (details == VMINFO_MACHINEREADABLE)
1270 RTPrintf("USBFilterRemote%zu=\"%lS\"\n", index + 1, bstr.raw());
1271 else
1272 RTPrintf("Remote: %lS\n", bstr.raw());
1273 CHECK_ERROR_RET (DevPtr, COMGETTER (SerialNumber) (bstr.asOutParam()), rc);
1274 if (details == VMINFO_MACHINEREADABLE)
1275 RTPrintf("USBFilterSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1276 else
1277 RTPrintf("Serial Number: %lS\n", bstr.raw());
1278 if (details != VMINFO_MACHINEREADABLE)
1279 {
1280 ULONG fMaskedIfs;
1281 CHECK_ERROR_RET (DevPtr, COMGETTER (MaskedInterfaces) (&fMaskedIfs), rc);
1282 if (fMaskedIfs)
1283 RTPrintf("Masked Interfaces: 0x%08x\n", fMaskedIfs);
1284 RTPrintf("\n");
1285 }
1286 }
1287 }
1288
1289 if (console)
1290 {
1291 /* scope */
1292 {
1293 if (details != VMINFO_MACHINEREADABLE)
1294 RTPrintf("Available remote USB devices:\n\n");
1295
1296 SafeIfaceArray <IHostUSBDevice> coll;
1297 CHECK_ERROR_RET (console, COMGETTER(RemoteUSBDevices) (ComSafeArrayAsOutParam(coll)), rc);
1298
1299 if (coll.size() == 0)
1300 {
1301 if (details != VMINFO_MACHINEREADABLE)
1302 RTPrintf("<none>\n\n");
1303 }
1304 else
1305 {
1306 for (size_t index = 0; index < coll.size(); ++index)
1307 {
1308 ComPtr <IHostUSBDevice> dev = coll[index];
1309
1310 /* Query info. */
1311 Bstr id;
1312 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1313 USHORT usVendorId;
1314 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1315 USHORT usProductId;
1316 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1317 USHORT bcdRevision;
1318 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1319
1320 if (details == VMINFO_MACHINEREADABLE)
1321 RTPrintf("USBRemoteUUID%zu=\"%S\"\n"
1322 "USBRemoteVendorId%zu=\"%#06x\"\n"
1323 "USBRemoteProductId%zu=\"%#06x\"\n"
1324 "USBRemoteRevision%zu=\"%#04x%02x\"\n",
1325 index + 1, Utf8Str(id).raw(),
1326 index + 1, usVendorId,
1327 index + 1, usProductId,
1328 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1329 else
1330 RTPrintf("UUID: %S\n"
1331 "VendorId: 0x%04x (%04X)\n"
1332 "ProductId: 0x%04x (%04X)\n"
1333 "Revision: %u.%u (%02u%02u)\n",
1334 Utf8Str(id).raw(),
1335 usVendorId, usVendorId, usProductId, usProductId,
1336 bcdRevision >> 8, bcdRevision & 0xff,
1337 bcdRevision >> 8, bcdRevision & 0xff);
1338
1339 /* optional stuff. */
1340 Bstr bstr;
1341 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1342 if (!bstr.isEmpty())
1343 {
1344 if (details == VMINFO_MACHINEREADABLE)
1345 RTPrintf("USBRemoteManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1346 else
1347 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1348 }
1349 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1350 if (!bstr.isEmpty())
1351 {
1352 if (details == VMINFO_MACHINEREADABLE)
1353 RTPrintf("USBRemoteProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1354 else
1355 RTPrintf("Product: %lS\n", bstr.raw());
1356 }
1357 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1358 if (!bstr.isEmpty())
1359 {
1360 if (details == VMINFO_MACHINEREADABLE)
1361 RTPrintf("USBRemoteSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1362 else
1363 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1364 }
1365 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1366 if (!bstr.isEmpty())
1367 {
1368 if (details == VMINFO_MACHINEREADABLE)
1369 RTPrintf("USBRemoteAddress%zu=\"%lS\"\n", index + 1, bstr.raw());
1370 else
1371 RTPrintf("Address: %lS\n", bstr.raw());
1372 }
1373
1374 if (details != VMINFO_MACHINEREADABLE)
1375 RTPrintf("\n");
1376 }
1377 }
1378 }
1379
1380 /* scope */
1381 {
1382 if (details != VMINFO_MACHINEREADABLE)
1383 RTPrintf ("Currently Attached USB Devices:\n\n");
1384
1385 SafeIfaceArray <IUSBDevice> coll;
1386 CHECK_ERROR_RET (console, COMGETTER(USBDevices) (ComSafeArrayAsOutParam(coll)), rc);
1387
1388 if (coll.size() == 0)
1389 {
1390 if (details != VMINFO_MACHINEREADABLE)
1391 RTPrintf("<none>\n\n");
1392 }
1393 else
1394 {
1395 for (size_t index = 0; index < coll.size(); ++index)
1396 {
1397 ComPtr <IUSBDevice> dev = coll[index];
1398
1399 /* Query info. */
1400 Bstr id;
1401 CHECK_ERROR_RET (dev, COMGETTER(Id)(id.asOutParam()), rc);
1402 USHORT usVendorId;
1403 CHECK_ERROR_RET (dev, COMGETTER(VendorId)(&usVendorId), rc);
1404 USHORT usProductId;
1405 CHECK_ERROR_RET (dev, COMGETTER(ProductId)(&usProductId), rc);
1406 USHORT bcdRevision;
1407 CHECK_ERROR_RET (dev, COMGETTER(Revision)(&bcdRevision), rc);
1408
1409 if (details == VMINFO_MACHINEREADABLE)
1410 RTPrintf("USBAttachedUUID%zu=\"%S\"\n"
1411 "USBAttachedVendorId%zu=\"%#06x\"\n"
1412 "USBAttachedProductId%zu=\"%#06x\"\n"
1413 "USBAttachedRevision%zu=\"%#04x%02x\"\n",
1414 index + 1, Utf8Str(id).raw(),
1415 index + 1, usVendorId,
1416 index + 1, usProductId,
1417 index + 1, bcdRevision >> 8, bcdRevision & 0xff);
1418 else
1419 RTPrintf("UUID: %S\n"
1420 "VendorId: 0x%04x (%04X)\n"
1421 "ProductId: 0x%04x (%04X)\n"
1422 "Revision: %u.%u (%02u%02u)\n",
1423 Utf8Str(id).raw(),
1424 usVendorId, usVendorId, usProductId, usProductId,
1425 bcdRevision >> 8, bcdRevision & 0xff,
1426 bcdRevision >> 8, bcdRevision & 0xff);
1427
1428 /* optional stuff. */
1429 Bstr bstr;
1430 CHECK_ERROR_RET (dev, COMGETTER(Manufacturer)(bstr.asOutParam()), rc);
1431 if (!bstr.isEmpty())
1432 {
1433 if (details == VMINFO_MACHINEREADABLE)
1434 RTPrintf("USBAttachedManufacturer%zu=\"%lS\"\n", index + 1, bstr.raw());
1435 else
1436 RTPrintf("Manufacturer: %lS\n", bstr.raw());
1437 }
1438 CHECK_ERROR_RET (dev, COMGETTER(Product)(bstr.asOutParam()), rc);
1439 if (!bstr.isEmpty())
1440 {
1441 if (details == VMINFO_MACHINEREADABLE)
1442 RTPrintf("USBAttachedProduct%zu=\"%lS\"\n", index + 1, bstr.raw());
1443 else
1444 RTPrintf("Product: %lS\n", bstr.raw());
1445 }
1446 CHECK_ERROR_RET (dev, COMGETTER(SerialNumber)(bstr.asOutParam()), rc);
1447 if (!bstr.isEmpty())
1448 {
1449 if (details == VMINFO_MACHINEREADABLE)
1450 RTPrintf("USBAttachedSerialNumber%zu=\"%lS\"\n", index + 1, bstr.raw());
1451 else
1452 RTPrintf("SerialNumber: %lS\n", bstr.raw());
1453 }
1454 CHECK_ERROR_RET (dev, COMGETTER(Address)(bstr.asOutParam()), rc);
1455 if (!bstr.isEmpty())
1456 {
1457 if (details == VMINFO_MACHINEREADABLE)
1458 RTPrintf("USBAttachedAddress%zu=\"%lS\"\n", index + 1, bstr.raw());
1459 else
1460 RTPrintf("Address: %lS\n", bstr.raw());
1461 }
1462
1463 if (details != VMINFO_MACHINEREADABLE)
1464 RTPrintf("\n");
1465 }
1466 }
1467 }
1468 }
1469 } /* USB */
1470
1471 /*
1472 * Shared folders
1473 */
1474 if (details != VMINFO_MACHINEREADABLE)
1475 RTPrintf("Shared folders: ");
1476 uint32_t numSharedFolders = 0;
1477#if 0 // not yet implemented
1478 /* globally shared folders first */
1479 {
1480 SafeIfaceArray <ISharedFolder> sfColl;
1481 CHECK_ERROR_RET(virtualBox, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(sfColl)), rc);
1482 for (size_t i = 0; i < sfColl.size(); ++i)
1483 {
1484 ComPtr<ISharedFolder> sf = sfColl[i];
1485 Bstr name, hostPath;
1486 sf->COMGETTER(Name)(name.asOutParam());
1487 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1488 RTPrintf("Name: '%lS', Host path: '%lS' (global mapping)\n", name.raw(), hostPath.raw());
1489 ++numSharedFolders;
1490 }
1491 }
1492#endif
1493 /* now VM mappings */
1494 {
1495 com::SafeIfaceArray <ISharedFolder> folders;
1496
1497 CHECK_ERROR_RET(machine, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1498
1499 for (size_t i = 0; i < folders.size(); ++i)
1500 {
1501 ComPtr <ISharedFolder> sf = folders[i];
1502
1503 Bstr name, hostPath;
1504 BOOL writable;
1505 sf->COMGETTER(Name)(name.asOutParam());
1506 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1507 sf->COMGETTER(Writable)(&writable);
1508 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1509 RTPrintf("\n\n");
1510 if (details == VMINFO_MACHINEREADABLE)
1511 {
1512 RTPrintf("SharedFolderNameMachineMapping%zu=\"%lS\"\n", i + 1,
1513 name.raw());
1514 RTPrintf("SharedFolderPathMachineMapping%zu=\"%lS\"\n", i + 1,
1515 hostPath.raw());
1516 }
1517 else
1518 RTPrintf("Name: '%lS', Host path: '%lS' (machine mapping), %s\n",
1519 name.raw(), hostPath.raw(), writable ? "writable" : "readonly");
1520 ++numSharedFolders;
1521 }
1522 }
1523 /* transient mappings */
1524 if (console)
1525 {
1526 com::SafeIfaceArray <ISharedFolder> folders;
1527
1528 CHECK_ERROR_RET(console, COMGETTER(SharedFolders)(ComSafeArrayAsOutParam(folders)), rc);
1529
1530 for (size_t i = 0; i < folders.size(); ++i)
1531 {
1532 ComPtr <ISharedFolder> sf = folders[i];
1533
1534 Bstr name, hostPath;
1535 sf->COMGETTER(Name)(name.asOutParam());
1536 sf->COMGETTER(HostPath)(hostPath.asOutParam());
1537 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1538 RTPrintf("\n\n");
1539 if (details == VMINFO_MACHINEREADABLE)
1540 {
1541 RTPrintf("SharedFolderNameTransientMapping%zu=\"%lS\"\n", i + 1,
1542 name.raw());
1543 RTPrintf("SharedFolderPathTransientMapping%zu=\"%lS\"\n", i + 1,
1544 hostPath.raw());
1545 }
1546 else
1547 RTPrintf("Name: '%lS', Host path: '%lS' (transient mapping)\n", name.raw(), hostPath.raw());
1548 ++numSharedFolders;
1549 }
1550 }
1551 if (!numSharedFolders && details != VMINFO_MACHINEREADABLE)
1552 RTPrintf("<none>\n");
1553 if (details != VMINFO_MACHINEREADABLE)
1554 RTPrintf("\n");
1555
1556 if (console)
1557 {
1558 /*
1559 * Live VRDP info.
1560 */
1561 ComPtr<IRemoteDisplayInfo> remoteDisplayInfo;
1562 CHECK_ERROR_RET(console, COMGETTER(RemoteDisplayInfo)(remoteDisplayInfo.asOutParam()), rc);
1563 BOOL Active;
1564 ULONG NumberOfClients;
1565 LONG64 BeginTime;
1566 LONG64 EndTime;
1567 ULONG64 BytesSent;
1568 ULONG64 BytesSentTotal;
1569 ULONG64 BytesReceived;
1570 ULONG64 BytesReceivedTotal;
1571 Bstr User;
1572 Bstr Domain;
1573 Bstr ClientName;
1574 Bstr ClientIP;
1575 ULONG ClientVersion;
1576 ULONG EncryptionStyle;
1577
1578 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Active) (&Active), rc);
1579 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(NumberOfClients) (&NumberOfClients), rc);
1580 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BeginTime) (&BeginTime), rc);
1581 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EndTime) (&EndTime), rc);
1582 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSent) (&BytesSent), rc);
1583 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesSentTotal) (&BytesSentTotal), rc);
1584 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceived) (&BytesReceived), rc);
1585 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(BytesReceivedTotal) (&BytesReceivedTotal), rc);
1586 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(User) (User.asOutParam ()), rc);
1587 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(Domain) (Domain.asOutParam ()), rc);
1588 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientName) (ClientName.asOutParam ()), rc);
1589 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientIP) (ClientIP.asOutParam ()), rc);
1590 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(ClientVersion) (&ClientVersion), rc);
1591 CHECK_ERROR_RET(remoteDisplayInfo, COMGETTER(EncryptionStyle) (&EncryptionStyle), rc);
1592
1593 if (details == VMINFO_MACHINEREADABLE)
1594 RTPrintf("VRDPActiveConnection=\"%s\"\n", Active ? "on": "off");
1595 else
1596 RTPrintf("VRDP Connection: %s\n", Active? "active": "not active");
1597
1598 if (details == VMINFO_MACHINEREADABLE)
1599 RTPrintf("VRDPClients=%d\n", NumberOfClients);
1600 else
1601 RTPrintf("Clients so far: %d\n", NumberOfClients);
1602
1603 if (NumberOfClients > 0)
1604 {
1605 char timestr[128];
1606
1607 if (Active)
1608 {
1609 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1610 if (details == VMINFO_MACHINEREADABLE)
1611 RTPrintf("VRDPStartTime=\"%s\"\n", timestr);
1612 else
1613 RTPrintf("Start time: %s\n", timestr);
1614 }
1615 else
1616 {
1617 makeTimeStr (timestr, sizeof (timestr), BeginTime);
1618 if (details == VMINFO_MACHINEREADABLE)
1619 RTPrintf("VRDPLastStartTime=\"%s\"\n", timestr);
1620 else
1621 RTPrintf("Last started: %s\n", timestr);
1622 makeTimeStr (timestr, sizeof (timestr), EndTime);
1623 if (details == VMINFO_MACHINEREADABLE)
1624 RTPrintf("VRDPLastEndTime=\"%s\"\n", timestr);
1625 else
1626 RTPrintf("Last ended: %s\n", timestr);
1627 }
1628
1629 uint64_t ThroughputSend = 0;
1630 uint64_t ThroughputReceive = 0;
1631 if (EndTime != BeginTime)
1632 {
1633 ThroughputSend = (BytesSent * 1000) / (EndTime - BeginTime);
1634 ThroughputReceive = (BytesReceived * 1000) / (EndTime - BeginTime);
1635 }
1636
1637 if (details == VMINFO_MACHINEREADABLE)
1638 {
1639 RTPrintf("VRDPBytesSent=%llu\n", BytesSent);
1640 RTPrintf("VRDPThroughputSend=%llu\n", ThroughputSend);
1641 RTPrintf("VRDPBytesSentTotal=%llu\n", BytesSentTotal);
1642
1643 RTPrintf("VRDPBytesReceived=%llu\n", BytesReceived);
1644 RTPrintf("VRDPThroughputReceive=%llu\n", ThroughputReceive);
1645 RTPrintf("VRDPBytesReceivedTotal=%llu\n", BytesReceivedTotal);
1646 }
1647 else
1648 {
1649 RTPrintf("Sent: %llu Bytes\n", BytesSent);
1650 RTPrintf("Average speed: %llu B/s\n", ThroughputSend);
1651 RTPrintf("Sent total: %llu Bytes\n", BytesSentTotal);
1652
1653 RTPrintf("Received: %llu Bytes\n", BytesReceived);
1654 RTPrintf("Speed: %llu B/s\n", ThroughputReceive);
1655 RTPrintf("Received total: %llu Bytes\n", BytesReceivedTotal);
1656 }
1657
1658 if (Active)
1659 {
1660 if (details == VMINFO_MACHINEREADABLE)
1661 {
1662 RTPrintf("VRDPUserName=\"%lS\"\n", User.raw());
1663 RTPrintf("VRDPDomain=\"%lS\"\n", Domain.raw());
1664 RTPrintf("VRDPClientName=\"%lS\"\n", ClientName.raw());
1665 RTPrintf("VRDPClientIP=\"%lS\"\n", ClientIP.raw());
1666 RTPrintf("VRDPClientVersion=%d\n", ClientVersion);
1667 RTPrintf("VRDPEncryption=\"%s\"\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1668 }
1669 else
1670 {
1671 RTPrintf("User name: %lS\n", User.raw());
1672 RTPrintf("Domain: %lS\n", Domain.raw());
1673 RTPrintf("Client name: %lS\n", ClientName.raw());
1674 RTPrintf("Client IP: %lS\n", ClientIP.raw());
1675 RTPrintf("Client version: %d\n", ClientVersion);
1676 RTPrintf("Encryption: %s\n", EncryptionStyle == 0? "RDP4": "RDP5 (X.509)");
1677 }
1678 }
1679 }
1680
1681 if (details != VMINFO_MACHINEREADABLE)
1682 RTPrintf("\n");
1683 }
1684
1685 if ( details == VMINFO_STANDARD
1686 || details == VMINFO_FULL
1687 || details == VMINFO_MACHINEREADABLE)
1688 {
1689 Bstr description;
1690 machine->COMGETTER(Description)(description.asOutParam());
1691 if (!description.isEmpty())
1692 {
1693 if (details == VMINFO_MACHINEREADABLE)
1694 RTPrintf("description=\"%lS\"\n", description.raw());
1695 else
1696 RTPrintf("Description:\n%lS\n", description.raw());
1697 }
1698 }
1699
1700 ULONG guestVal;
1701 if (details != VMINFO_MACHINEREADABLE)
1702 RTPrintf("Guest:\n\n");
1703
1704#ifdef VBOX_WITH_MEM_BALLOONING
1705 rc = machine->COMGETTER(MemoryBalloonSize)(&guestVal);
1706 if (SUCCEEDED(rc))
1707 {
1708 if (details == VMINFO_MACHINEREADABLE)
1709 RTPrintf("GuestMemoryBalloon=%d\n", guestVal);
1710 else
1711 RTPrintf("Configured memory balloon size: %d MB\n", guestVal);
1712 }
1713#endif
1714 rc = machine->COMGETTER(StatisticsUpdateInterval)(&guestVal);
1715 if (SUCCEEDED(rc))
1716 {
1717 if (details == VMINFO_MACHINEREADABLE)
1718 RTPrintf("GuestStatisticsUpdateInterval=%d\n", guestVal);
1719 else
1720 {
1721 if (guestVal == 0)
1722 RTPrintf("Statistics update: disabled\n");
1723 else
1724 RTPrintf("Statistics update interval: %d seconds\n", guestVal);
1725 }
1726 }
1727 if (details != VMINFO_MACHINEREADABLE)
1728 RTPrintf("\n");
1729
1730 if ( console
1731 && ( details == VMINFO_STATISTICS
1732 || details == VMINFO_FULL
1733 || details == VMINFO_MACHINEREADABLE))
1734 {
1735 ComPtr <IGuest> guest;
1736
1737 rc = console->COMGETTER(Guest)(guest.asOutParam());
1738 if (SUCCEEDED(rc))
1739 {
1740 ULONG statVal;
1741
1742 rc = guest->GetStatistic(0, GuestStatisticType_SampleNumber, &statVal);
1743 if (SUCCEEDED(rc))
1744 {
1745 if (details == VMINFO_MACHINEREADABLE)
1746 RTPrintf("StatGuestSample=%d\n", statVal);
1747 else
1748 RTPrintf("Guest statistics for sample %d:\n\n", statVal);
1749 }
1750
1751 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Idle, &statVal);
1752 if (SUCCEEDED(rc))
1753 {
1754 if (details == VMINFO_MACHINEREADABLE)
1755 RTPrintf("StatGuestLoadIdleCPU%d=%d\n", 0, statVal);
1756 else
1757 RTPrintf("CPU%d: CPU Load Idle %-3d%%\n", 0, statVal);
1758 }
1759
1760 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_Kernel, &statVal);
1761 if (SUCCEEDED(rc))
1762 {
1763 if (details == VMINFO_MACHINEREADABLE)
1764 RTPrintf("StatGuestLoadKernelCPU%d=%d\n", 0, statVal);
1765 else
1766 RTPrintf("CPU%d: CPU Load Kernel %-3d%%\n", 0, statVal);
1767 }
1768
1769 rc = guest->GetStatistic(0, GuestStatisticType_CPULoad_User, &statVal);
1770 if (SUCCEEDED(rc))
1771 {
1772 if (details == VMINFO_MACHINEREADABLE)
1773 RTPrintf("StatGuestLoadUserCPU%d=%d\n", 0, statVal);
1774 else
1775 RTPrintf("CPU%d: CPU Load User %-3d%%\n", 0, statVal);
1776 }
1777
1778 rc = guest->GetStatistic(0, GuestStatisticType_Threads, &statVal);
1779 if (SUCCEEDED(rc))
1780 {
1781 if (details == VMINFO_MACHINEREADABLE)
1782 RTPrintf("StatGuestThreadsCPU%d=%d\n", 0, statVal);
1783 else
1784 RTPrintf("CPU%d: Threads %d\n", 0, statVal);
1785 }
1786
1787 rc = guest->GetStatistic(0, GuestStatisticType_Processes, &statVal);
1788 if (SUCCEEDED(rc))
1789 {
1790 if (details == VMINFO_MACHINEREADABLE)
1791 RTPrintf("StatGuestProcessesCPU%d=%d\n", 0, statVal);
1792 else
1793 RTPrintf("CPU%d: Processes %d\n", 0, statVal);
1794 }
1795
1796 rc = guest->GetStatistic(0, GuestStatisticType_Handles, &statVal);
1797 if (SUCCEEDED(rc))
1798 {
1799 if (details == VMINFO_MACHINEREADABLE)
1800 RTPrintf("StatGuestHandlesCPU%d=%d\n", 0, statVal);
1801 else
1802 RTPrintf("CPU%d: Handles %d\n", 0, statVal);
1803 }
1804
1805 rc = guest->GetStatistic(0, GuestStatisticType_MemoryLoad, &statVal);
1806 if (SUCCEEDED(rc))
1807 {
1808 if (details == VMINFO_MACHINEREADABLE)
1809 RTPrintf("StatGuestMemoryLoadCPU%d=%d\n", 0, statVal);
1810 else
1811 RTPrintf("CPU%d: Memory Load %d%%\n", 0, statVal);
1812 }
1813
1814 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemTotal, &statVal);
1815 if (SUCCEEDED(rc))
1816 {
1817 if (details == VMINFO_MACHINEREADABLE)
1818 RTPrintf("StatGuestMemoryTotalPhysCPU%d=%d\n", 0, statVal);
1819 else
1820 RTPrintf("CPU%d: Total physical memory %-4d MB\n", 0, statVal);
1821 }
1822
1823 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemAvailable, &statVal);
1824 if (SUCCEEDED(rc))
1825 {
1826 if (details == VMINFO_MACHINEREADABLE)
1827 RTPrintf("StatGuestMemoryFreePhysCPU%d=%d\n", 0, statVal);
1828 else
1829 RTPrintf("CPU%d: Free physical memory %-4d MB\n", 0, statVal);
1830 }
1831
1832#ifdef VBOX_WITH_MEM_BALLOONING
1833 rc = guest->GetStatistic(0, GuestStatisticType_PhysMemBalloon, &statVal);
1834 if (SUCCEEDED(rc))
1835 {
1836 if (details == VMINFO_MACHINEREADABLE)
1837 RTPrintf("StatGuestMemoryBalloonCPU%d=%d\n", 0, statVal);
1838 else
1839 RTPrintf("CPU%d: Memory balloon size %-4d MB\n", 0, statVal);
1840 }
1841#endif
1842 rc = guest->GetStatistic(0, GuestStatisticType_MemCommitTotal, &statVal);
1843 if (SUCCEEDED(rc))
1844 {
1845 if (details == VMINFO_MACHINEREADABLE)
1846 RTPrintf("StatGuestMemoryCommittedCPU%d=%d\n", 0, statVal);
1847 else
1848 RTPrintf("CPU%d: Committed memory %-4d MB\n", 0, statVal);
1849 }
1850
1851 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelTotal, &statVal);
1852 if (SUCCEEDED(rc))
1853 {
1854 if (details == VMINFO_MACHINEREADABLE)
1855 RTPrintf("StatGuestMemoryTotalKernelCPU%d=%d\n", 0, statVal);
1856 else
1857 RTPrintf("CPU%d: Total kernel memory %-4d MB\n", 0, statVal);
1858 }
1859
1860 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelPaged, &statVal);
1861 if (SUCCEEDED(rc))
1862 {
1863 if (details == VMINFO_MACHINEREADABLE)
1864 RTPrintf("StatGuestMemoryPagedKernelCPU%d=%d\n", 0, statVal);
1865 else
1866 RTPrintf("CPU%d: Paged kernel memory %-4d MB\n", 0, statVal);
1867 }
1868
1869 rc = guest->GetStatistic(0, GuestStatisticType_MemKernelNonpaged, &statVal);
1870 if (SUCCEEDED(rc))
1871 {
1872 if (details == VMINFO_MACHINEREADABLE)
1873 RTPrintf("StatGuestMemoryNonpagedKernelCPU%d=%d\n", 0, statVal);
1874 else
1875 RTPrintf("CPU%d: Nonpaged kernel memory %-4d MB\n", 0, statVal);
1876 }
1877
1878 rc = guest->GetStatistic(0, GuestStatisticType_MemSystemCache, &statVal);
1879 if (SUCCEEDED(rc))
1880 {
1881 if (details == VMINFO_MACHINEREADABLE)
1882 RTPrintf("StatGuestSystemCacheSizeCPU%d=%d\n", 0, statVal);
1883 else
1884 RTPrintf("CPU%d: System cache size %-4d MB\n", 0, statVal);
1885 }
1886
1887 rc = guest->GetStatistic(0, GuestStatisticType_PageFileSize, &statVal);
1888 if (SUCCEEDED(rc))
1889 {
1890 if (details == VMINFO_MACHINEREADABLE)
1891 RTPrintf("StatGuestPageFileSizeCPU%d=%d\n", 0, statVal);
1892 else
1893 RTPrintf("CPU%d: Page file size %-4d MB\n", 0, statVal);
1894 }
1895
1896 RTPrintf("\n");
1897 }
1898 else
1899 {
1900 if (details != VMINFO_MACHINEREADABLE)
1901 {
1902 RTPrintf("[!] FAILED calling console->getGuest at line %d!\n", __LINE__);
1903 GluePrintRCMessage(rc);
1904 }
1905 }
1906 }
1907
1908 /*
1909 * snapshots
1910 */
1911 ComPtr<ISnapshot> snapshot;
1912 rc = machine->GetSnapshot(Bstr(), snapshot.asOutParam());
1913 if (SUCCEEDED(rc) && snapshot)
1914 {
1915 ComPtr<ISnapshot> currentSnapshot;
1916 rc = machine->COMGETTER(CurrentSnapshot)(currentSnapshot.asOutParam());
1917 if (SUCCEEDED(rc))
1918 {
1919 if (details != VMINFO_MACHINEREADABLE)
1920 RTPrintf("Snapshots:\n\n");
1921 showSnapshots(snapshot, currentSnapshot, details);
1922 }
1923 }
1924
1925 if (details != VMINFO_MACHINEREADABLE)
1926 RTPrintf("\n");
1927 return S_OK;
1928}
1929
1930#if defined(_MSC_VER)
1931# pragma optimize("", on)
1932#endif
1933
1934static const RTGETOPTDEF g_aShowVMInfoOptions[] =
1935{
1936 { "--details", 'D', RTGETOPT_REQ_NOTHING },
1937 { "-details", 'D', RTGETOPT_REQ_NOTHING }, // deprecated
1938 { "--statistics", 'S', RTGETOPT_REQ_NOTHING },
1939 { "-statistics", 'S', RTGETOPT_REQ_NOTHING }, // deprecated
1940 { "--machinereadable", 'M', RTGETOPT_REQ_NOTHING },
1941 { "-machinereadable", 'M', RTGETOPT_REQ_NOTHING }, // deprecated
1942};
1943
1944int handleShowVMInfo(HandlerArg *a)
1945{
1946 HRESULT rc;
1947 const char *VMNameOrUuid = NULL;
1948 bool fDetails = false;
1949 bool fStatistics = false;
1950 bool fMachinereadable = false;
1951
1952 int c;
1953 RTGETOPTUNION ValueUnion;
1954 RTGETOPTSTATE GetState;
1955 // start at 0 because main() has hacked both the argc and argv given to us
1956 RTGetOptInit(&GetState, a->argc, a->argv, g_aShowVMInfoOptions, RT_ELEMENTS(g_aShowVMInfoOptions), 0, 0 /* fFlags */);
1957 while ((c = RTGetOpt(&GetState, &ValueUnion)))
1958 {
1959 switch (c)
1960 {
1961 case 'D': // --details
1962 fDetails = true;
1963 break;
1964
1965 case 'S': // --statistics
1966 fStatistics = true;
1967 break;
1968
1969 case 'M': // --machinereadable
1970 fMachinereadable = true;
1971 break;
1972
1973 case VINF_GETOPT_NOT_OPTION:
1974 if (!VMNameOrUuid)
1975 VMNameOrUuid = ValueUnion.psz;
1976 else
1977 return errorSyntax(USAGE_SHOWVMINFO, "Invalid parameter '%s'", ValueUnion.psz);
1978 break;
1979
1980 default:
1981 if (c > 0)
1982 {
1983 if (RT_C_IS_PRINT(c))
1984 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option -%c", c);
1985 else
1986 return errorSyntax(USAGE_SHOWVMINFO, "Invalid option case %i", c);
1987 }
1988 else if (c == VERR_GETOPT_UNKNOWN_OPTION)
1989 return errorSyntax(USAGE_SHOWVMINFO, "unknown option: %s\n", ValueUnion.psz);
1990 else if (ValueUnion.pDef)
1991 return errorSyntax(USAGE_SHOWVMINFO, "%s: %Rrs", ValueUnion.pDef->pszLong, c);
1992 else
1993 return errorSyntax(USAGE_SHOWVMINFO, "error: %Rrs", c);
1994 }
1995 }
1996
1997 /* check for required options */
1998 if (!VMNameOrUuid)
1999 return errorSyntax(USAGE_SHOWVMINFO, "VM name or UUID required");
2000
2001 /* try to find the given machine */
2002 ComPtr <IMachine> machine;
2003 Bstr uuid (VMNameOrUuid);
2004 if (!Guid (VMNameOrUuid).isEmpty())
2005 {
2006 CHECK_ERROR (a->virtualBox, GetMachine (uuid, machine.asOutParam()));
2007 }
2008 else
2009 {
2010 CHECK_ERROR (a->virtualBox, FindMachine (Bstr(VMNameOrUuid), machine.asOutParam()));
2011 if (SUCCEEDED (rc))
2012 machine->COMGETTER(Id) (uuid.asOutParam());
2013 }
2014 if (FAILED (rc))
2015 return 1;
2016
2017 /* 2nd option can be -details, -statistics or -argdump */
2018 VMINFO_DETAILS details = VMINFO_NONE;
2019 if (fMachinereadable)
2020 details = VMINFO_MACHINEREADABLE;
2021 else
2022 if (fDetails && fStatistics)
2023 details = VMINFO_FULL;
2024 else
2025 if (fDetails)
2026 details = VMINFO_STANDARD;
2027 else
2028 if (fStatistics)
2029 details = VMINFO_STATISTICS;
2030
2031 ComPtr <IConsole> console;
2032
2033 /* open an existing session for the VM */
2034 rc = a->virtualBox->OpenExistingSession (a->session, uuid);
2035 if (SUCCEEDED(rc))
2036 /* get the session machine */
2037 rc = a->session->COMGETTER(Machine)(machine.asOutParam());
2038 if (SUCCEEDED(rc))
2039 /* get the session console */
2040 rc = a->session->COMGETTER(Console)(console.asOutParam());
2041
2042 rc = showVMInfo(a->virtualBox, machine, details, console);
2043
2044 if (console)
2045 a->session->Close();
2046
2047 return SUCCEEDED (rc) ? 0 : 1;
2048}
2049
2050#endif /* !VBOX_ONLY_DOCS */
2051/* 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