VirtualBox

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

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

VBoxManage showvminfo --machinereadable: added VMStateFile

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

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