VirtualBox

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

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

Main: make restoreSnapshot() work better, adjust VBoxManage

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