VirtualBox

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

Last change on this file since 24152 was 24136, checked in by vboxsync, 16 years ago

Main,VBoxManage,xml: Added a HardwareUUID property for reporting the original machine UUID after cloning or teleporting a VM.

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