VirtualBox

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

Last change on this file since 14792 was 14784, checked in by vboxsync, 16 years ago

VBoxManage: Resurrected addiscsidisk command (note that iSCSI hard disks are still unavailable for VMs yet).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 198.0 KB
Line 
1/* $Id: VBoxManage.cpp 14784 2008-11-28 14:57:31Z vboxsync $ */
2/** @file
3 * VBoxManage - VirtualBox's command-line interface.
4 */
5
6/*
7 * Copyright (C) 2006-2007 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
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#ifndef VBOX_ONLY_DOCS
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/EventQueue.h>
33
34#include <VBox/com/VirtualBox.h>
35
36#include <vector>
37#include <list>
38#endif /* !VBOX_ONLY_DOCS */
39
40#include <iprt/asm.h>
41#include <iprt/cidr.h>
42#include <iprt/ctype.h>
43#include <iprt/dir.h>
44#include <iprt/env.h>
45#include <VBox/err.h>
46#include <iprt/file.h>
47#include <iprt/initterm.h>
48#include <iprt/param.h>
49#include <iprt/path.h>
50#include <iprt/stream.h>
51#include <iprt/string.h>
52#include <iprt/stdarg.h>
53#include <iprt/thread.h>
54#include <iprt/uuid.h>
55#include <VBox/version.h>
56#include <VBox/VBoxHDD.h>
57
58#include "VBoxManage.h"
59
60#ifndef VBOX_ONLY_DOCS
61using namespace com;
62
63/* missing XPCOM <-> COM wrappers */
64#ifndef STDMETHOD_
65# define STDMETHOD_(ret, meth) NS_IMETHOD_(ret) meth
66#endif
67#ifndef NS_GET_IID
68# define NS_GET_IID(I) IID_##I
69#endif
70#ifndef RT_OS_WINDOWS
71#define IUnknown nsISupports
72#endif
73
74/** command handler type */
75typedef int (*PFNHANDLER)(int argc, char *argv[], ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession);
76
77#ifdef USE_XPCOM_QUEUE
78/** A pointer to the event queue, set by main() before calling any handlers. */
79nsCOMPtr<nsIEventQueue> g_pEventQ;
80#endif
81
82/**
83 * Quick IUSBDevice implementation for detaching / attaching
84 * devices to the USB Controller.
85 */
86class MyUSBDevice : public IUSBDevice
87{
88public:
89 // public initializer/uninitializer for internal purposes only
90 MyUSBDevice(uint16_t a_u16VendorId, uint16_t a_u16ProductId, uint16_t a_bcdRevision, uint64_t a_u64SerialHash, const char *a_pszComment)
91 : m_usVendorId(a_u16VendorId), m_usProductId(a_u16ProductId),
92 m_bcdRevision(a_bcdRevision), m_u64SerialHash(a_u64SerialHash),
93 m_bstrComment(a_pszComment),
94 m_cRefs(0)
95 {
96 }
97
98 STDMETHOD_(ULONG, AddRef)(void)
99 {
100 return ASMAtomicIncU32(&m_cRefs);
101 }
102 STDMETHOD_(ULONG, Release)(void)
103 {
104 ULONG cRefs = ASMAtomicDecU32(&m_cRefs);
105 if (!cRefs)
106 delete this;
107 return cRefs;
108 }
109 STDMETHOD(QueryInterface)(const IID &iid, void **ppvObject)
110 {
111 Guid guid(iid);
112 if (guid == Guid(NS_GET_IID(IUnknown)))
113 *ppvObject = (IUnknown *)this;
114 else if (guid == Guid(NS_GET_IID(IUSBDevice)))
115 *ppvObject = (IUSBDevice *)this;
116 else
117 return E_NOINTERFACE;
118 AddRef();
119 return S_OK;
120 }
121
122 STDMETHOD(COMGETTER(Id))(GUIDPARAMOUT a_pId) { return E_NOTIMPL; }
123 STDMETHOD(COMGETTER(VendorId))(USHORT *a_pusVendorId) { *a_pusVendorId = m_usVendorId; return S_OK; }
124 STDMETHOD(COMGETTER(ProductId))(USHORT *a_pusProductId) { *a_pusProductId = m_usProductId; return S_OK; }
125 STDMETHOD(COMGETTER(Revision))(USHORT *a_pusRevision) { *a_pusRevision = m_bcdRevision; return S_OK; }
126 STDMETHOD(COMGETTER(SerialHash))(ULONG64 *a_pullSerialHash) { *a_pullSerialHash = m_u64SerialHash; return S_OK; }
127 STDMETHOD(COMGETTER(Manufacturer))(BSTR *a_pManufacturer) { return E_NOTIMPL; }
128 STDMETHOD(COMGETTER(Product))(BSTR *a_pProduct) { return E_NOTIMPL; }
129 STDMETHOD(COMGETTER(SerialNumber))(BSTR *a_pSerialNumber) { return E_NOTIMPL; }
130 STDMETHOD(COMGETTER(Address))(BSTR *a_pAddress) { return E_NOTIMPL; }
131
132private:
133 /** The vendor id of this USB device. */
134 USHORT m_usVendorId;
135 /** The product id of this USB device. */
136 USHORT m_usProductId;
137 /** The product revision number of this USB device.
138 * (high byte = integer; low byte = decimal) */
139 USHORT m_bcdRevision;
140 /** The USB serial hash of the device. */
141 uint64_t m_u64SerialHash;
142 /** The user comment string. */
143 Bstr m_bstrComment;
144 /** Reference counter. */
145 uint32_t volatile m_cRefs;
146};
147
148
149// types
150///////////////////////////////////////////////////////////////////////////////
151
152template <typename T>
153class Nullable
154{
155public:
156
157 Nullable() : mIsNull (true) {}
158 Nullable (const T &aValue, bool aIsNull = false)
159 : mIsNull (aIsNull), mValue (aValue) {}
160
161 bool isNull() const { return mIsNull; };
162 void setNull (bool aIsNull = true) { mIsNull = aIsNull; }
163
164 operator const T&() const { return mValue; }
165
166 Nullable &operator= (const T &aValue)
167 {
168 mValue = aValue;
169 mIsNull = false;
170 return *this;
171 }
172
173private:
174
175 bool mIsNull;
176 T mValue;
177};
178
179/** helper structure to encapsulate USB filter manipulation commands */
180struct USBFilterCmd
181{
182 struct USBFilter
183 {
184 USBFilter ()
185 : mAction (USBDeviceFilterAction_Null)
186 {}
187
188 Bstr mName;
189 Nullable <bool> mActive;
190 Bstr mVendorId;
191 Bstr mProductId;
192 Bstr mRevision;
193 Bstr mManufacturer;
194 Bstr mProduct;
195 Bstr mRemote;
196 Bstr mSerialNumber;
197 Nullable <ULONG> mMaskedInterfaces;
198 USBDeviceFilterAction_T mAction;
199 };
200
201 enum Action { Invalid, Add, Modify, Remove };
202
203 USBFilterCmd() : mAction (Invalid), mIndex (0), mGlobal (false) {}
204
205 Action mAction;
206 uint32_t mIndex;
207 /** flag whether the command target is a global filter */
208 bool mGlobal;
209 /** machine this command is targeted at (null for global filters) */
210 ComPtr<IMachine> mMachine;
211 USBFilter mFilter;
212};
213#endif /* !VBOX_ONLY_DOCS */
214
215// funcs
216///////////////////////////////////////////////////////////////////////////////
217
218static void showLogo(void)
219{
220 static bool fShown; /* show only once */
221
222 if (!fShown)
223 {
224 RTPrintf("VirtualBox Command Line Management Interface Version "
225 VBOX_VERSION_STRING "\n"
226 "(C) 2005-2008 Sun Microsystems, Inc.\n"
227 "All rights reserved.\n"
228 "\n");
229 fShown = true;
230 }
231}
232
233static void printUsage(USAGECATEGORY u64Cmd)
234{
235#ifdef RT_OS_LINUX
236 bool fLinux = true;
237#else
238 bool fLinux = false;
239#endif
240#ifdef RT_OS_WINDOWS
241 bool fWin = true;
242#else
243 bool fWin = false;
244#endif
245#ifdef RT_OS_SOLARIS
246 bool fSolaris = true;
247#else
248 bool fSolaris = false;
249#endif
250#ifdef RT_OS_DARWIN
251 bool fDarwin = true;
252#else
253 bool fDarwin = false;
254#endif
255#ifdef VBOX_WITH_VRDP
256 bool fVRDP = true;
257#else
258 bool fVRDP = false;
259#endif
260
261 if (u64Cmd == USAGE_DUMPOPTS)
262 {
263 fLinux = true;
264 fWin = true;
265 fSolaris = true;
266 fDarwin = true;
267 fVRDP = true;
268 u64Cmd = USAGE_ALL;
269 }
270
271 RTPrintf("Usage:\n"
272 "\n");
273
274 if (u64Cmd == USAGE_ALL)
275 {
276 RTPrintf("VBoxManage [-v|-version] print version number and exit\n"
277 "VBoxManage -nologo ... suppress the logo\n"
278 "\n"
279 "VBoxManage -convertSettings ... allow to auto-convert settings files\n"
280 "VBoxManage -convertSettingsBackup ... allow to auto-convert settings files\n"
281 " but create backup copies before\n"
282 "VBoxManage -convertSettingsIgnore ... allow to auto-convert settings files\n"
283 " but don't explicitly save the results\n"
284 "\n");
285 }
286
287 if (u64Cmd & USAGE_LIST)
288 {
289 RTPrintf("VBoxManage list vms|runningvms|ostypes|hostdvds|hostfloppies|\n"
290 " hostifs|hostinfo|hddbackends|hdds|dvds|floppies|\n"
291 " usbhost|usbfilters|systemproperties\n"
292 "\n");
293 }
294
295 if (u64Cmd & USAGE_SHOWVMINFO)
296 {
297 RTPrintf("VBoxManage showvminfo <uuid>|<name>\n"
298 " [-details]\n"
299 " [-statistics]\n"
300 " [-machinereadable]\n"
301 "\n");
302 }
303
304 if (u64Cmd & USAGE_REGISTERVM)
305 {
306 RTPrintf("VBoxManage registervm <filename>\n"
307 "\n");
308 }
309
310 if (u64Cmd & USAGE_UNREGISTERVM)
311 {
312 RTPrintf("VBoxManage unregistervm <uuid>|<name>\n"
313 " [-delete]\n"
314 "\n");
315 }
316
317 if (u64Cmd & USAGE_CREATEVM)
318 {
319 RTPrintf("VBoxManage createvm -name <name>\n"
320 " [-ostype <ostype>]\n"
321 " [-register]\n"
322 " [-basefolder <path> | -settingsfile <path>]\n"
323 " [-uuid <uuid>]\n"
324 " \n"
325 "\n");
326 }
327
328 if (u64Cmd & USAGE_MODIFYVM)
329 {
330 RTPrintf("VBoxManage modifyvm <uuid|name>\n"
331 " [-name <name>]\n"
332 " [-ostype <ostype>]\n"
333 " [-memory <memorysize in MB>]\n"
334 " [-vram <vramsize in MB>]\n"
335 " [-acpi on|off]\n"
336 " [-ioapic on|off]\n"
337 " [-pae on|off]\n"
338 " [-hwvirtex on|off|default]\n"
339 " [-nestedpaging on|off]\n"
340 " [-vtxvpid on|off]\n"
341 " [-monitorcount <number>]\n"
342 " [-accelerate3d <on|off>]\n"
343 " [-bioslogofadein on|off]\n"
344 " [-bioslogofadeout on|off]\n"
345 " [-bioslogodisplaytime <msec>]\n"
346 " [-bioslogoimagepath <imagepath>]\n"
347 " [-biosbootmenu disabled|menuonly|messageandmenu]\n"
348 " [-biossystemtimeoffset <msec>]\n"
349 " [-biospxedebug on|off]\n"
350 " [-boot<1-4> none|floppy|dvd|disk|net>]\n"
351 " [-hd<a|b|d> none|<uuid>|<filename>]\n"
352 " [-idecontroller PIIX3|PIIX4]\n"
353#ifdef VBOX_WITH_AHCI
354 " [-sata on|off]\n"
355 " [-sataportcount <1-30>]\n"
356 " [-sataport<1-30> none|<uuid>|<filename>]\n"
357 " [-sataideemulation<1-4> <1-30>]\n"
358#endif
359 " [-dvd none|<uuid>|<filename>|host:<drive>]\n"
360 " [-dvdpassthrough on|off]\n"
361 " [-floppy disabled|empty|<uuid>|\n"
362 " <filename>|host:<drive>]\n"
363 " [-nic<1-N> none|null|nat|hostif|intnet]\n"
364 " [-nictype<1-N> Am79C970A|Am79C973"
365#ifdef VBOX_WITH_E1000
366 "|82540EM|82543GC"
367#endif
368 "]\n"
369 " [-cableconnected<1-N> on|off]\n"
370 " [-nictrace<1-N> on|off]\n"
371 " [-nictracefile<1-N> <filename>]\n"
372 " [-nicspeed<1-N> <kbps>]\n"
373 " [-hostifdev<1-N> none|<devicename>]\n"
374 " [-intnet<1-N> <network name>]\n"
375 " [-natnet<1-N> <network>|default]\n"
376 " [-macaddress<1-N> auto|<mac>]\n"
377 " [-uart<1-N> off|<I/O base> <IRQ>]\n"
378 " [-uartmode<1-N> disconnected|\n"
379 " server <pipe>|\n"
380 " client <pipe>|\n"
381 " <devicename>]\n"
382#ifdef VBOX_WITH_MEM_BALLOONING
383 " [-guestmemoryballoon <balloonsize in MB>]\n"
384#endif
385 " [-gueststatisticsinterval <seconds>]\n"
386 );
387 if (fLinux)
388 {
389 RTPrintf(" [-tapsetup<1-N> none|<application>]\n"
390 " [-tapterminate<1-N> none|<application>]\n");
391 }
392 RTPrintf(" [-audio none|null");
393 if (fWin)
394 {
395#ifdef VBOX_WITH_WINMM
396 RTPrintf( "|winmm|dsound");
397#else
398 RTPrintf( "|dsound");
399#endif
400 }
401 if (fSolaris)
402 {
403 RTPrintf( "|solaudio");
404 }
405 if (fLinux)
406 {
407 RTPrintf( "|oss"
408#ifdef VBOX_WITH_ALSA
409 "|alsa"
410#endif
411#ifdef VBOX_WITH_PULSE
412 "|pulse"
413#endif
414 );
415 }
416 if (fDarwin)
417 {
418 RTPrintf( "|coreaudio");
419 }
420 RTPrintf( "]\n");
421 RTPrintf(" [-audiocontroller ac97|sb16]\n"
422 " [-clipboard disabled|hosttoguest|guesttohost|\n"
423 " bidirectional]\n");
424 if (fVRDP)
425 {
426 RTPrintf(" [-vrdp on|off]\n"
427 " [-vrdpport default|<port>]\n"
428 " [-vrdpaddress <host>]\n"
429 " [-vrdpauthtype null|external|guest]\n"
430 " [-vrdpmulticon on|off]\n"
431 " [-vrdpreusecon on|off]\n");
432 }
433 RTPrintf(" [-usb on|off]\n"
434 " [-usbehci on|off]\n"
435 " [-snapshotfolder default|<path>]\n");
436 RTPrintf("\n");
437 }
438
439 if (u64Cmd & USAGE_STARTVM)
440 {
441 RTPrintf("VBoxManage startvm <uuid>|<name>\n");
442 if (fVRDP)
443 RTPrintf(" [-type gui|vrdp]\n");
444 RTPrintf("\n");
445 }
446
447 if (u64Cmd & USAGE_CONTROLVM)
448 {
449 RTPrintf("VBoxManage controlvm <uuid>|<name>\n"
450 " pause|resume|reset|poweroff|savestate|\n"
451 " acpipowerbutton|acpisleepbutton|\n"
452 " keyboardputscancode <hex> [<hex> ...]|\n"
453 " injectnmi|\n"
454 " setlinkstate<1-4> on|off |\n"
455 " usbattach <uuid>|<address> |\n"
456 " usbdetach <uuid>|<address> |\n"
457 " dvdattach none|<uuid>|<filename>|host:<drive> |\n"
458 " floppyattach none|<uuid>|<filename>|host:<drive> |\n"
459 " setvideomodehint <xres> <yres> <bpp> [display]|\n"
460 " setcredentials <username> <password> <domain>\n"
461 " [-allowlocallogon <yes|no>]\n"
462 "\n");
463 }
464
465 if (u64Cmd & USAGE_DISCARDSTATE)
466 {
467 RTPrintf("VBoxManage discardstate <uuid>|<name>\n"
468 "\n");
469 }
470
471 if (u64Cmd & USAGE_ADOPTSTATE)
472 {
473 RTPrintf("VBoxManage adoptstate <uuid>|<name> <state_file>\n"
474 "\n");
475 }
476
477 if (u64Cmd & USAGE_SNAPSHOT)
478 {
479 RTPrintf("VBoxManage snapshot <uuid>|<name>\n"
480 " take <name> [-desc <desc>] |\n"
481 " discard <uuid>|<name> |\n"
482 " discardcurrent -state|-all |\n"
483 " edit <uuid>|<name>|-current\n"
484 " [-newname <name>]\n"
485 " [-newdesc <desc>] |\n"
486 " showvminfo <uuid>|<name>\n"
487 "\n");
488 }
489
490 if (u64Cmd & USAGE_REGISTERIMAGE)
491 {
492 RTPrintf("VBoxManage openmedium disk|dvd|floppy <filename>\n"
493 " [-type normal|immutable|writethrough] (disk only)\n"
494 "\n");
495 }
496
497 if (u64Cmd & USAGE_UNREGISTERIMAGE)
498 {
499 RTPrintf("VBoxManage closemedium disk|dvd|floppy <uuid>|<filename>\n"
500 "\n");
501 }
502
503 if (u64Cmd & USAGE_SHOWHDINFO)
504 {
505 RTPrintf("VBoxManage showhdinfo <uuid>|<filename>\n"
506 "\n");
507 }
508
509 if (u64Cmd & USAGE_CREATEHD)
510 {
511 /// @todo NEWMEDIA add -format to specify the hard disk backend
512 RTPrintf("VBoxManage createhd -filename <filename>\n"
513 " -size <megabytes>\n"
514 " [-static]\n"
515 " [-comment <comment>]\n"
516 " [-register]\n"
517 " [-type normal|writethrough] (default: normal)\n"
518 "\n");
519 }
520
521 if (u64Cmd & USAGE_MODIFYHD)
522 {
523 RTPrintf("VBoxManage modifyhd <uuid>|<filename>\n"
524 " settype normal|writethrough|immutable |\n"
525 " compact\n"
526 "\n");
527 }
528
529 if (u64Cmd & USAGE_CLONEHD)
530 {
531 RTPrintf("VBoxManage clonehd <uuid>|<filename> <outputfile>\n"
532 "\n");
533 }
534
535 if (u64Cmd & USAGE_CONVERTDD)
536 {
537 RTPrintf("VBoxManage convertdd [-static] <filename> <outputfile>\n"
538 "VBoxManage convertdd [-static] stdin <outputfile> <bytes>\n"
539 "\n");
540 }
541
542 if (u64Cmd & USAGE_ADDISCSIDISK)
543 {
544 RTPrintf("VBoxManage addiscsidisk -server <name>|<ip>\n"
545 " -target <target>\n"
546 " [-port <port>]\n"
547 " [-lun <lun>]\n"
548 " [-encodedlun <lun>]\n"
549 " [-username <username>]\n"
550 " [-password <password>]\n"
551 " [-comment <comment>]\n"
552 "\n");
553 }
554
555 if (u64Cmd & USAGE_CREATEHOSTIF && fWin)
556 {
557 RTPrintf("VBoxManage createhostif <name>\n"
558 "\n");
559 }
560
561 if (u64Cmd & USAGE_REMOVEHOSTIF && fWin)
562 {
563 RTPrintf("VBoxManage removehostif <uuid>|<name>\n"
564 "\n");
565 }
566
567 if (u64Cmd & USAGE_GETEXTRADATA)
568 {
569 RTPrintf("VBoxManage getextradata global|<uuid>|<name>\n"
570 " <key>|enumerate\n"
571 "\n");
572 }
573
574 if (u64Cmd & USAGE_SETEXTRADATA)
575 {
576 RTPrintf("VBoxManage setextradata global|<uuid>|<name>\n"
577 " <key>\n"
578 " [<value>] (no value deletes key)\n"
579 "\n");
580 }
581
582 if (u64Cmd & USAGE_SETPROPERTY)
583 {
584 RTPrintf("VBoxManage setproperty hdfolder default|<folder> |\n"
585 " machinefolder default|<folder> |\n"
586 " vrdpauthlibrary default|<library> |\n"
587 " websrvauthlibrary default|null|<library> |\n"
588 " hwvirtexenabled yes|no\n"
589 " loghistorycount <value>\n"
590 "\n");
591 }
592
593 if (u64Cmd & USAGE_USBFILTER_ADD)
594 {
595 RTPrintf("VBoxManage usbfilter add <index,0-N>\n"
596 " -target <uuid>|<name>|global\n"
597 " -name <string>\n"
598 " -action ignore|hold (global filters only)\n"
599 " [-active yes|no] (yes)\n"
600 " [-vendorid <XXXX>] (null)\n"
601 " [-productid <XXXX>] (null)\n"
602 " [-revision <IIFF>] (null)\n"
603 " [-manufacturer <string>] (null)\n"
604 " [-product <string>] (null)\n"
605 " [-remote yes|no] (null, VM filters only)\n"
606 " [-serialnumber <string>] (null)\n"
607 " [-maskedinterfaces <XXXXXXXX>]\n"
608 "\n");
609 }
610
611 if (u64Cmd & USAGE_USBFILTER_MODIFY)
612 {
613 RTPrintf("VBoxManage usbfilter modify <index,0-N>\n"
614 " -target <uuid>|<name>|global\n"
615 " [-name <string>]\n"
616 " [-action ignore|hold] (global filters only)\n"
617 " [-active yes|no]\n"
618 " [-vendorid <XXXX>|\"\"]\n"
619 " [-productid <XXXX>|\"\"]\n"
620 " [-revision <IIFF>|\"\"]\n"
621 " [-manufacturer <string>|\"\"]\n"
622 " [-product <string>|\"\"]\n"
623 " [-remote yes|no] (null, VM filters only)\n"
624 " [-serialnumber <string>|\"\"]\n"
625 " [-maskedinterfaces <XXXXXXXX>]\n"
626 "\n");
627 }
628
629 if (u64Cmd & USAGE_USBFILTER_REMOVE)
630 {
631 RTPrintf("VBoxManage usbfilter remove <index,0-N>\n"
632 " -target <uuid>|<name>|global\n"
633 "\n");
634 }
635
636 if (u64Cmd & USAGE_SHAREDFOLDER_ADD)
637 {
638 RTPrintf("VBoxManage sharedfolder add <vmname>|<uuid>\n"
639 " -name <name> -hostpath <hostpath>\n"
640 " [-transient] [-readonly]\n"
641 "\n");
642 }
643
644 if (u64Cmd & USAGE_SHAREDFOLDER_REMOVE)
645 {
646 RTPrintf("VBoxManage sharedfolder remove <vmname>|<uuid>\n"
647 " -name <name> [-transient]\n"
648 "\n");
649 }
650
651 if (u64Cmd & USAGE_VM_STATISTICS)
652 {
653 RTPrintf("VBoxManage vmstatistics <vmname>|<uuid> [-reset]\n"
654 " [-pattern <pattern>] [-descriptions]\n"
655 "\n");
656 }
657
658#ifdef VBOX_WITH_GUEST_PROPS
659 if (u64Cmd & USAGE_GUESTPROPERTY)
660 usageGuestProperty();
661#endif /* VBOX_WITH_GUEST_PROPS defined */
662
663 if (u64Cmd & USAGE_METRICS)
664 {
665 RTPrintf("VBoxManage metrics list [*|host|<vmname> [<metric_list>]] (comma-separated)\n\n"
666 "VBoxManage metrics setup\n"
667 " [-period <seconds>]\n"
668 " [-samples <count>]\n"
669 " [-list]\n"
670 " [*|host|<vmname> [<metric_list>]]\n\n"
671 "VBoxManage metrics query [*|host|<vmname> [<metric_list>]]\n\n"
672 "VBoxManage metrics collect\n"
673 " [-period <seconds>]\n"
674 " [-samples <count>]\n"
675 " [-list]\n"
676 " [-detach]\n"
677 " [*|host|<vmname> [<metric_list>]]\n"
678 "\n");
679 }
680
681}
682
683/**
684 * Print a usage synopsis and the syntax error message.
685 */
686int errorSyntax(USAGECATEGORY u64Cmd, const char *pszFormat, ...)
687{
688 va_list args;
689 showLogo(); // show logo even if suppressed
690#ifndef VBOX_ONLY_DOCS
691 if (g_fInternalMode)
692 printUsageInternal(u64Cmd);
693 else
694 printUsage(u64Cmd);
695#endif /* !VBOX_ONLY_DOCS */
696 va_start(args, pszFormat);
697 RTPrintf("\n"
698 "Syntax error: %N\n", pszFormat, &args);
699 va_end(args);
700 return 1;
701}
702
703/**
704 * Print an error message without the syntax stuff.
705 */
706int errorArgument(const char *pszFormat, ...)
707{
708 va_list args;
709 va_start(args, pszFormat);
710 RTPrintf("error: %N\n", pszFormat, &args);
711 va_end(args);
712 return 1;
713}
714
715#ifndef VBOX_ONLY_DOCS
716/**
717 * Print out progress on the console
718 */
719static void showProgress(ComPtr<IProgress> progress)
720{
721 BOOL fCompleted;
722 LONG currentPercent;
723 LONG lastPercent = 0;
724
725 RTPrintf("0%%...");
726 RTStrmFlush(g_pStdOut);
727 while (SUCCEEDED(progress->COMGETTER(Completed(&fCompleted))))
728 {
729 progress->COMGETTER(Percent(&currentPercent));
730
731 /* did we cross a 10% mark? */
732 if (((currentPercent / 10) > (lastPercent / 10)))
733 {
734 /* make sure to also print out missed steps */
735 for (LONG curVal = (lastPercent / 10) * 10 + 10; curVal <= (currentPercent / 10) * 10; curVal += 10)
736 {
737 if (curVal < 100)
738 {
739 RTPrintf("%ld%%...", curVal);
740 RTStrmFlush(g_pStdOut);
741 }
742 }
743 lastPercent = (currentPercent / 10) * 10;
744 }
745 if (fCompleted)
746 break;
747
748 /* make sure the loop is not too tight */
749 progress->WaitForCompletion(100);
750 }
751
752 /* complete the line. */
753 HRESULT rc;
754 if (SUCCEEDED(progress->COMGETTER(ResultCode)(&rc)))
755 {
756 if (SUCCEEDED(rc))
757 RTPrintf("100%%\n");
758 else
759 RTPrintf("FAILED\n");
760 }
761 else
762 RTPrintf("\n");
763 RTStrmFlush(g_pStdOut);
764}
765
766static int handleRegisterVM(int argc, char *argv[],
767 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
768{
769 HRESULT rc;
770
771 if (argc != 1)
772 return errorSyntax(USAGE_REGISTERVM, "Incorrect number of parameters");
773
774 ComPtr<IMachine> machine;
775 CHECK_ERROR(virtualBox, OpenMachine(Bstr(argv[0]), machine.asOutParam()));
776 if (SUCCEEDED(rc))
777 {
778 ASSERT(machine);
779 CHECK_ERROR(virtualBox, RegisterMachine(machine));
780 }
781 return SUCCEEDED(rc) ? 0 : 1;
782}
783
784static int handleUnregisterVM(int argc, char *argv[],
785 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
786{
787 HRESULT rc;
788
789 if ((argc != 1) && (argc != 2))
790 return errorSyntax(USAGE_UNREGISTERVM, "Incorrect number of parameters");
791
792 ComPtr<IMachine> machine;
793 /* assume it's a UUID */
794 rc = virtualBox->GetMachine(Guid(argv[0]), machine.asOutParam());
795 if (FAILED(rc) || !machine)
796 {
797 /* must be a name */
798 CHECK_ERROR(virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
799 }
800 if (machine)
801 {
802 Guid uuid;
803 machine->COMGETTER(Id)(uuid.asOutParam());
804 machine = NULL;
805 CHECK_ERROR(virtualBox, UnregisterMachine(uuid, machine.asOutParam()));
806 if (SUCCEEDED(rc) && machine)
807 {
808 /* are we supposed to delete the config file? */
809 if ((argc == 2) && (strcmp(argv[1], "-delete") == 0))
810 {
811 CHECK_ERROR(machine, DeleteSettings());
812 }
813 }
814 }
815 return SUCCEEDED(rc) ? 0 : 1;
816}
817
818static int handleCreateHardDisk(int argc, char *argv[],
819 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
820{
821 HRESULT rc;
822 Bstr filename;
823 uint64_t sizeMB = 0;
824 bool fStatic = false;
825 Bstr comment;
826 bool fRegister = false;
827 const char *type = "normal";
828
829 /* let's have a closer look at the arguments */
830 for (int i = 0; i < argc; i++)
831 {
832 if (strcmp(argv[i], "-filename") == 0)
833 {
834 if (argc <= i + 1)
835 return errorArgument("Missing argument to '%s'", argv[i]);
836 i++;
837 filename = argv[i];
838 }
839 else if (strcmp(argv[i], "-size") == 0)
840 {
841 if (argc <= i + 1)
842 return errorArgument("Missing argument to '%s'", argv[i]);
843 i++;
844 sizeMB = RTStrToUInt64(argv[i]);
845 }
846 else if (strcmp(argv[i], "-static") == 0)
847 {
848 fStatic = true;
849 }
850 else if (strcmp(argv[i], "-comment") == 0)
851 {
852 if (argc <= i + 1)
853 return errorArgument("Missing argument to '%s'", argv[i]);
854 i++;
855 comment = argv[i];
856 }
857 else if (strcmp(argv[i], "-register") == 0)
858 {
859 fRegister = true;
860 }
861 else if (strcmp(argv[i], "-type") == 0)
862 {
863 if (argc <= i + 1)
864 return errorArgument("Missing argument to '%s'", argv[i]);
865 i++;
866 type = argv[i];
867 }
868 else
869 return errorSyntax(USAGE_CREATEHD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
870 }
871 /* check the outcome */
872 if (!filename || (sizeMB == 0))
873 return errorSyntax(USAGE_CREATEHD, "Parameters -filename and -size are required");
874
875 if (strcmp(type, "normal") && strcmp(type, "writethrough"))
876 return errorArgument("Invalid hard disk type '%s' specified", Utf8Str(type).raw());
877
878 ComPtr<IHardDisk2> hardDisk;
879 CHECK_ERROR(virtualBox, CreateHardDisk2(Bstr("VDI"), filename, hardDisk.asOutParam()));
880 if (SUCCEEDED(rc) && hardDisk)
881 {
882 /* we will close the hard disk after the storage has been successfully
883 * created unless fRegister is set */
884 bool doClose = false;
885
886 CHECK_ERROR(hardDisk,COMSETTER(Description)(comment));
887 ComPtr<IProgress> progress;
888 if (fStatic)
889 {
890 CHECK_ERROR(hardDisk, CreateFixedStorage(sizeMB, progress.asOutParam()));
891 }
892 else
893 {
894 CHECK_ERROR(hardDisk, CreateDynamicStorage(sizeMB, progress.asOutParam()));
895 }
896 if (SUCCEEDED(rc) && progress)
897 {
898 if (fStatic)
899 showProgress(progress);
900 else
901 CHECK_ERROR(progress, WaitForCompletion(-1));
902 if (SUCCEEDED(rc))
903 {
904 progress->COMGETTER(ResultCode)(&rc);
905 if (FAILED(rc))
906 {
907 com::ProgressErrorInfo info(progress);
908 if (info.isBasicAvailable())
909 RTPrintf("Error: failed to create hard disk. Error message: %lS\n", info.getText().raw());
910 else
911 RTPrintf("Error: failed to create hard disk. No error message available!\n");
912 }
913 else
914 {
915 doClose = !fRegister;
916
917 Guid uuid;
918 CHECK_ERROR(hardDisk, COMGETTER(Id)(uuid.asOutParam()));
919
920 if (strcmp(type, "normal") == 0)
921 {
922 /* nothing required, default */
923 }
924 else if (strcmp(type, "writethrough") == 0)
925 {
926 CHECK_ERROR(hardDisk, COMSETTER(Type)(HardDiskType_Writethrough));
927 }
928
929 RTPrintf("Disk image created. UUID: %s\n", uuid.toString().raw());
930 }
931 }
932 }
933 if (doClose)
934 {
935 CHECK_ERROR(hardDisk, Close());
936 }
937 }
938 return SUCCEEDED(rc) ? 0 : 1;
939}
940
941static DECLCALLBACK(int) hardDiskProgressCallback(PVM pVM, unsigned uPercent, void *pvUser)
942{
943 unsigned *pPercent = (unsigned *)pvUser;
944
945 if (*pPercent != uPercent)
946 {
947 *pPercent = uPercent;
948 RTPrintf(".");
949 if ((uPercent % 10) == 0 && uPercent)
950 RTPrintf("%d%%", uPercent);
951 RTStrmFlush(g_pStdOut);
952 }
953
954 return VINF_SUCCESS;
955}
956
957
958static int handleModifyHardDisk(int argc, char *argv[],
959 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
960{
961 HRESULT rc;
962
963 /* The uuid/filename and a command */
964 if (argc < 2)
965 return errorSyntax(USAGE_MODIFYHD, "Incorrect number of parameters");
966
967 ComPtr<IHardDisk2> hardDisk;
968 Bstr filepath;
969
970 /* first guess is that it's a UUID */
971 Guid uuid(argv[0]);
972 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
973 /* no? then it must be a filename */
974 if (!hardDisk)
975 {
976 filepath = argv[0];
977 CHECK_ERROR(virtualBox, FindHardDisk2(filepath, hardDisk.asOutParam()));
978 }
979
980 /* let's find out which command */
981 if (strcmp(argv[1], "settype") == 0)
982 {
983 /* hard disk must be registered */
984 if (SUCCEEDED(rc) && hardDisk)
985 {
986 char *type = NULL;
987
988 if (argc <= 2)
989 return errorArgument("Missing argument to for settype");
990
991 type = argv[2];
992
993 HardDiskType_T hddType;
994 CHECK_ERROR(hardDisk, COMGETTER(Type)(&hddType));
995
996 if (strcmp(type, "normal") == 0)
997 {
998 if (hddType != HardDiskType_Normal)
999 CHECK_ERROR(hardDisk, COMSETTER(Type)(HardDiskType_Normal));
1000 }
1001 else if (strcmp(type, "writethrough") == 0)
1002 {
1003 if (hddType != HardDiskType_Writethrough)
1004 CHECK_ERROR(hardDisk, COMSETTER(Type)(HardDiskType_Writethrough));
1005
1006 }
1007 else if (strcmp(type, "immutable") == 0)
1008 {
1009 if (hddType != HardDiskType_Immutable)
1010 CHECK_ERROR(hardDisk, COMSETTER(Type)(HardDiskType_Immutable));
1011 }
1012 else
1013 {
1014 return errorArgument("Invalid hard disk type '%s' specified", Utf8Str(type).raw());
1015 }
1016 }
1017 else
1018 return errorArgument("Hard disk image not registered");
1019 }
1020 else if (strcmp(argv[1], "compact") == 0)
1021 {
1022 /* the hard disk image might not be registered */
1023 if (!hardDisk)
1024 {
1025 virtualBox->OpenHardDisk2(Bstr(argv[0]), hardDisk.asOutParam());
1026 if (!hardDisk)
1027 return errorArgument("Hard disk image not found");
1028 }
1029
1030 Bstr format;
1031 hardDisk->COMGETTER(Format)(format.asOutParam());
1032 if (format != "VDI")
1033 return errorArgument("Invalid hard disk type. The command only works on VDI files\n");
1034
1035 Bstr fileName;
1036 hardDisk->COMGETTER(Location)(fileName.asOutParam());
1037
1038 /* make sure the object reference is released */
1039 hardDisk = NULL;
1040
1041 unsigned uProcent;
1042
1043 RTPrintf("Shrinking '%lS': 0%%", fileName.raw());
1044 int vrc = VDIShrinkImage(Utf8Str(fileName).raw(), hardDiskProgressCallback, &uProcent);
1045 if (RT_FAILURE(vrc))
1046 {
1047 RTPrintf("Error while shrinking hard disk image: %Rrc\n", vrc);
1048 rc = E_FAIL;
1049 }
1050 }
1051 else
1052 return errorSyntax(USAGE_MODIFYHD, "Invalid parameter '%s'", Utf8Str(argv[1]).raw());
1053
1054 return SUCCEEDED(rc) ? 0 : 1;
1055}
1056
1057static int handleCloneHardDisk(int argc, char *argv[],
1058 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
1059{
1060#if 1
1061 RTPrintf("Error: Clone hard disk operation is temporarily unavailable!\n");
1062 return 1;
1063#else
1064 /// @todo NEWMEDIA use IHardDisk2::cloneTo/flattenTo (not yet implemented)
1065 HRESULT rc;
1066
1067 /* source hard disk and target path */
1068 if (argc != 2)
1069 return errorSyntax(USAGE_CLONEHD, "Incorrect number of parameters");
1070
1071 /* first guess is that it's a UUID */
1072 Guid uuid(argv[0]);
1073 ComPtr<IHardDisk2> hardDisk;
1074 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
1075 if (!hardDisk)
1076 {
1077 /* not successful? Then it must be a filename */
1078 CHECK_ERROR(virtualBox, OpenHardDisk2(Bstr(argv[0]), hardDisk.asOutParam()));
1079 }
1080 if (hardDisk)
1081 {
1082 ComPtr<IProgress> progress;
1083 CHECK_ERROR(hardDisk, CloneToImage(Bstr(argv[1]), hardDisk.asOutParam(), progress.asOutParam()));
1084 if (SUCCEEDED(rc))
1085 {
1086 showProgress(progress);
1087 progress->COMGETTER(ResultCode)(&rc);
1088 if (FAILED(rc))
1089 {
1090 com::ProgressErrorInfo info(progress);
1091 if (info.isBasicAvailable())
1092 {
1093 RTPrintf("Error: failed to clone disk image. Error message: %lS\n", info.getText().raw());
1094 }
1095 else
1096 {
1097 RTPrintf("Error: failed to clone disk image. No error message available!\n");
1098 }
1099 }
1100 }
1101 }
1102 return SUCCEEDED(rc) ? 0 : 1;
1103#endif
1104}
1105
1106static int handleConvertDDImage(int argc, char *argv[])
1107{
1108 int arg = 0;
1109 VDIIMAGETYPE enmImgType = VDI_IMAGE_TYPE_NORMAL;
1110 if (argc >= 1 && !strcmp(argv[arg], "-static"))
1111 {
1112 arg++;
1113 enmImgType = VDI_IMAGE_TYPE_FIXED;
1114 }
1115
1116#if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
1117 const bool fReadFromStdIn = (argc >= arg + 1) && !strcmp(argv[arg], "stdin");
1118#else
1119 const bool fReadFromStdIn = false;
1120#endif
1121
1122 if ((!fReadFromStdIn && argc != arg + 2) || (fReadFromStdIn && argc != arg + 3))
1123 return errorSyntax(USAGE_CONVERTDD, "Incorrect number of parameters");
1124
1125 RTPrintf("Converting VDI: from DD image file=\"%s\" to file=\"%s\"...\n",
1126 argv[arg], argv[arg + 1]);
1127
1128 /* open raw image file. */
1129 RTFILE File;
1130 int rc = VINF_SUCCESS;
1131 if (fReadFromStdIn)
1132 File = 0;
1133 else
1134 rc = RTFileOpen(&File, argv[arg], RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
1135 if (RT_FAILURE(rc))
1136 {
1137 RTPrintf("File=\"%s\" open error: %Rrf\n", argv[arg], rc);
1138 return rc;
1139 }
1140
1141 uint64_t cbFile;
1142 /* get image size. */
1143 if (fReadFromStdIn)
1144 cbFile = RTStrToUInt64(argv[arg + 2]);
1145 else
1146 rc = RTFileGetSize(File, &cbFile);
1147 if (RT_SUCCESS(rc))
1148 {
1149 RTPrintf("Creating %s image with size %RU64 bytes (%RU64MB)...\n", (enmImgType == VDI_IMAGE_TYPE_FIXED) ? "fixed" : "dynamic", cbFile, (cbFile + _1M - 1) / _1M);
1150 char pszComment[256];
1151 RTStrPrintf(pszComment, sizeof(pszComment), "Converted image from %s", argv[arg]);
1152 rc = VDICreateBaseImage(argv[arg + 1],
1153 enmImgType,
1154 cbFile,
1155 pszComment, NULL, NULL);
1156 if (RT_SUCCESS(rc))
1157 {
1158 PVDIDISK pVdi = VDIDiskCreate();
1159 rc = VDIDiskOpenImage(pVdi, argv[arg + 1], VDI_OPEN_FLAGS_NORMAL);
1160 if (RT_SUCCESS(rc))
1161 {
1162 /* alloc work buffer. */
1163 size_t cbBuffer = VDIDiskGetBufferSize(pVdi);
1164 void *pvBuf = RTMemAlloc(cbBuffer);
1165 if (pvBuf)
1166 {
1167 uint64_t offFile = 0;
1168 while (offFile < cbFile)
1169 {
1170 size_t cbRead = 0;
1171 size_t cbToRead = cbFile - offFile >= (uint64_t) cbBuffer ?
1172 cbBuffer : (size_t) (cbFile - offFile);
1173 rc = RTFileRead(File, pvBuf, cbToRead, &cbRead);
1174 if (RT_FAILURE(rc) || !cbRead)
1175 break;
1176 rc = VDIDiskWrite(pVdi, offFile, pvBuf, cbRead);
1177 if (RT_FAILURE(rc))
1178 break;
1179 offFile += cbRead;
1180 }
1181
1182 RTMemFree(pvBuf);
1183 }
1184 else
1185 rc = VERR_NO_MEMORY;
1186
1187 VDIDiskCloseImage(pVdi);
1188 }
1189
1190 if (RT_FAILURE(rc))
1191 {
1192 /* delete image on error */
1193 RTPrintf("Failed (%Rrc)!\n", rc);
1194 VDIDeleteImage(argv[arg + 1]);
1195 }
1196 }
1197 else
1198 RTPrintf("Failed to create output file (%Rrc)!\n", rc);
1199 }
1200 RTFileClose(File);
1201
1202 return rc;
1203}
1204
1205static int handleAddiSCSIDisk(int argc, char *argv[],
1206 ComPtr <IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
1207{
1208 HRESULT rc;
1209 Bstr server;
1210 Bstr target;
1211 Bstr port;
1212 Bstr lun;
1213 Bstr username;
1214 Bstr password;
1215 Bstr comment;
1216
1217 /* at least server and target */
1218 if (argc < 4)
1219 return errorSyntax(USAGE_ADDISCSIDISK, "Not enough parameters");
1220
1221 /* let's have a closer look at the arguments */
1222 for (int i = 0; i < argc; i++)
1223 {
1224 if (strcmp(argv[i], "-server") == 0)
1225 {
1226 if (argc <= i + 1)
1227 return errorArgument("Missing argument to '%s'", argv[i]);
1228 i++;
1229 server = argv[i];
1230 }
1231 else if (strcmp(argv[i], "-target") == 0)
1232 {
1233 if (argc <= i + 1)
1234 return errorArgument("Missing argument to '%s'", argv[i]);
1235 i++;
1236 target = argv[i];
1237 }
1238 else if (strcmp(argv[i], "-port") == 0)
1239 {
1240 if (argc <= i + 1)
1241 return errorArgument("Missing argument to '%s'", argv[i]);
1242 i++;
1243 port = argv[i];
1244 }
1245 else if (strcmp(argv[i], "-lun") == 0)
1246 {
1247 /// @todo is the below todo still relevant? Note that we do a
1248 /// strange string->int->string conversion here.
1249
1250 /** @todo move the LUN encoding algorithm into IISCSIHardDisk, add decoding */
1251
1252 if (argc <= i + 1)
1253 return errorArgument("Missing argument to '%s'", argv[i]);
1254 i++;
1255 char *pszNext;
1256 uint64_t lunNum;
1257 int rc = RTStrToUInt64Ex(argv[i], &pszNext, 0, &lunNum);
1258 if (RT_FAILURE(rc) || *pszNext != '\0' || lunNum >= 16384)
1259 return errorArgument("Invalid LUN number '%s'", argv[i]);
1260 if (lunNum <= 255)
1261 {
1262 /* Assume bus identifier = 0. */
1263 lunNum = (lunNum << 48); /* uses peripheral device addressing method */
1264 }
1265 else
1266 {
1267 /* Check above already limited the LUN to 14 bits. */
1268 lunNum = (lunNum << 48) | RT_BIT_64(62); /* uses flat space addressing method */
1269 }
1270
1271 lun = BstrFmt ("%llu", lunNum);
1272 }
1273 else if (strcmp(argv[i], "-encodedlun") == 0)
1274 {
1275 if (argc <= i + 1)
1276 return errorArgument("Missing argument to '%s'", argv[i]);
1277 i++;
1278 lun = argv[i];
1279 }
1280 else if (strcmp(argv[i], "-username") == 0)
1281 {
1282 if (argc <= i + 1)
1283 return errorArgument("Missing argument to '%s'", argv[i]);
1284 i++;
1285 username = argv[i];
1286 }
1287 else if (strcmp(argv[i], "-password") == 0)
1288 {
1289 if (argc <= i + 1)
1290 return errorArgument("Missing argument to '%s'", argv[i]);
1291 i++;
1292 password = argv[i];
1293 }
1294 else if (strcmp(argv[i], "-comment") == 0)
1295 {
1296 if (argc <= i + 1)
1297 return errorArgument("Missing argument to '%s'", argv[i]);
1298 i++;
1299 comment = argv[i];
1300 }
1301 else
1302 return errorSyntax(USAGE_ADDISCSIDISK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1303 }
1304
1305 /* check for required options */
1306 if (!server || !target)
1307 return errorSyntax(USAGE_ADDISCSIDISK, "Parameters -server and -target are required");
1308
1309 do
1310 {
1311 ComPtr<IHardDisk2> hardDisk;
1312 CHECK_ERROR_BREAK (aVirtualBox,
1313 CreateHardDisk2(Bstr ("iSCSI"),
1314 BstrFmt ("%ls/%ls", server.raw(), target.raw()),
1315 hardDisk.asOutParam()));
1316 CheckComRCBreakRC (rc);
1317
1318 if (!comment.isNull())
1319 CHECK_ERROR_BREAK(hardDisk, COMSETTER(Description)(comment));
1320
1321 if (!port.isNull())
1322 server = BstrFmt ("%ls:%ls", server.raw(), port.raw());
1323 CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("TargetAddress"), server));
1324 CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("TargetName"), target));
1325
1326 if (!lun.isNull())
1327 CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("LUN"), lun));
1328 if (!username.isNull())
1329 CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("InitiatorUsername"), username));
1330 if (!password.isNull())
1331 CHECK_ERROR_BREAK(hardDisk, SetProperty(Bstr("InitiatorSecret"), password));
1332
1333 /// @todo add -initiator option
1334 CHECK_ERROR_BREAK(hardDisk,
1335 SetProperty(Bstr("InitiatorName"),
1336 Bstr("iqn.2008-04.com.sun.virtualbox.initiator")));
1337
1338 /// @todo add -targetName and -targetPassword options
1339
1340 Guid guid;
1341 CHECK_ERROR(hardDisk, COMGETTER(Id)(guid.asOutParam()));
1342 RTPrintf("iSCSI disk created. UUID: %s\n", guid.toString().raw());
1343 }
1344 while (0);
1345
1346 return SUCCEEDED(rc) ? 0 : 1;
1347}
1348
1349static int handleCreateVM(int argc, char *argv[],
1350 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
1351{
1352 HRESULT rc;
1353 Bstr baseFolder;
1354 Bstr settingsFile;
1355 Bstr name;
1356 Bstr osTypeId;
1357 RTUUID id;
1358 bool fRegister = false;
1359
1360 RTUuidClear(&id);
1361 for (int i = 0; i < argc; i++)
1362 {
1363 if (strcmp(argv[i], "-basefolder") == 0)
1364 {
1365 if (argc <= i + 1)
1366 return errorArgument("Missing argument to '%s'", argv[i]);
1367 i++;
1368 baseFolder = argv[i];
1369 }
1370 else if (strcmp(argv[i], "-settingsfile") == 0)
1371 {
1372 if (argc <= i + 1)
1373 return errorArgument("Missing argument to '%s'", argv[i]);
1374 i++;
1375 settingsFile = argv[i];
1376 }
1377 else if (strcmp(argv[i], "-name") == 0)
1378 {
1379 if (argc <= i + 1)
1380 return errorArgument("Missing argument to '%s'", argv[i]);
1381 i++;
1382 name = argv[i];
1383 }
1384 else if (strcmp(argv[i], "-ostype") == 0)
1385 {
1386 if (argc <= i + 1)
1387 return errorArgument("Missing argument to '%s'", argv[i]);
1388 i++;
1389 osTypeId = argv[i];
1390 }
1391 else if (strcmp(argv[i], "-uuid") == 0)
1392 {
1393 if (argc <= i + 1)
1394 return errorArgument("Missing argument to '%s'", argv[i]);
1395 i++;
1396 if (RT_FAILURE(RTUuidFromStr(&id, argv[i])))
1397 return errorArgument("Invalid UUID format %s\n", argv[i]);
1398 }
1399 else if (strcmp(argv[i], "-register") == 0)
1400 {
1401 fRegister = true;
1402 }
1403 else
1404 return errorSyntax(USAGE_CREATEVM, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1405 }
1406 if (!name)
1407 return errorSyntax(USAGE_CREATEVM, "Parameter -name is required");
1408
1409 if (!!baseFolder && !!settingsFile)
1410 return errorSyntax(USAGE_CREATEVM, "Either -basefolder or -settingsfile must be specified");
1411
1412 do
1413 {
1414 ComPtr<IMachine> machine;
1415
1416 if (!settingsFile)
1417 CHECK_ERROR_BREAK(virtualBox,
1418 CreateMachine(name, osTypeId, baseFolder, Guid(id), machine.asOutParam()));
1419 else
1420 CHECK_ERROR_BREAK(virtualBox,
1421 CreateLegacyMachine(name, osTypeId, settingsFile, Guid(id), machine.asOutParam()));
1422
1423 CHECK_ERROR_BREAK(machine, SaveSettings());
1424 if (fRegister)
1425 {
1426 CHECK_ERROR_BREAK(virtualBox, RegisterMachine(machine));
1427 }
1428 Guid uuid;
1429 CHECK_ERROR_BREAK(machine, COMGETTER(Id)(uuid.asOutParam()));
1430 CHECK_ERROR_BREAK(machine, COMGETTER(SettingsFilePath)(settingsFile.asOutParam()));
1431 RTPrintf("Virtual machine '%ls' is created%s.\n"
1432 "UUID: %s\n"
1433 "Settings file: '%ls'\n",
1434 name.raw(), fRegister ? " and registered" : "",
1435 uuid.toString().raw(), settingsFile.raw());
1436 }
1437 while (0);
1438
1439 return SUCCEEDED(rc) ? 0 : 1;
1440}
1441
1442/**
1443 * Parses a number.
1444 *
1445 * @returns Valid number on success.
1446 * @returns 0 if invalid number. All necesary bitching has been done.
1447 * @param psz Pointer to the nic number.
1448 */
1449static unsigned parseNum(const char *psz, unsigned cMaxNum, const char *name)
1450{
1451 uint32_t u32;
1452 char *pszNext;
1453 int rc = RTStrToUInt32Ex(psz, &pszNext, 10, &u32);
1454 if ( RT_SUCCESS(rc)
1455 && *pszNext == '\0'
1456 && u32 >= 1
1457 && u32 <= cMaxNum)
1458 return (unsigned)u32;
1459 errorArgument("Invalid %s number '%s'", name, psz);
1460 return 0;
1461}
1462
1463/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
1464#if defined(_MSC_VER)
1465# pragma optimize("g", off)
1466#endif
1467
1468static int handleModifyVM(int argc, char *argv[],
1469 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
1470{
1471 HRESULT rc;
1472 Bstr name;
1473 Bstr ostype;
1474 uint32_t memorySize = 0;
1475 uint32_t vramSize = 0;
1476 char *acpi = NULL;
1477 char *hwvirtex = NULL;
1478 char *nestedpaging = NULL;
1479 char *vtxvpid = NULL;
1480 char *pae = NULL;
1481 char *ioapic = NULL;
1482 uint32_t monitorcount = ~0;
1483 char *accelerate3d = NULL;
1484 char *bioslogofadein = NULL;
1485 char *bioslogofadeout = NULL;
1486 uint32_t bioslogodisplaytime = ~0;
1487 char *bioslogoimagepath = NULL;
1488 char *biosbootmenumode = NULL;
1489 char *biossystemtimeoffset = NULL;
1490 char *biospxedebug = NULL;
1491 DeviceType_T bootDevice[4];
1492 int bootDeviceChanged[4] = { false };
1493 char *hdds[34] = {0};
1494 char *dvd = NULL;
1495 char *dvdpassthrough = NULL;
1496 char *idecontroller = NULL;
1497 char *floppy = NULL;
1498 char *audio = NULL;
1499 char *audiocontroller = NULL;
1500 char *clipboard = NULL;
1501#ifdef VBOX_WITH_VRDP
1502 char *vrdp = NULL;
1503 uint16_t vrdpport = UINT16_MAX;
1504 char *vrdpaddress = NULL;
1505 char *vrdpauthtype = NULL;
1506 char *vrdpmulticon = NULL;
1507 char *vrdpreusecon = NULL;
1508#endif
1509 int fUsbEnabled = -1;
1510 int fUsbEhciEnabled = -1;
1511 char *snapshotFolder = NULL;
1512 ULONG guestMemBalloonSize = (ULONG)-1;
1513 ULONG guestStatInterval = (ULONG)-1;
1514 int fSataEnabled = -1;
1515 int sataPortCount = -1;
1516 int sataBootDevices[4] = {-1,-1,-1,-1};
1517
1518 /* VM ID + at least one parameter. Parameter arguments are checked
1519 * individually. */
1520 if (argc < 2)
1521 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
1522
1523 /* Get the number of network adapters */
1524 ULONG NetworkAdapterCount = 0;
1525 {
1526 ComPtr <ISystemProperties> info;
1527 CHECK_ERROR_RET (virtualBox, COMGETTER(SystemProperties) (info.asOutParam()), 1);
1528 CHECK_ERROR_RET (info, COMGETTER(NetworkAdapterCount) (&NetworkAdapterCount), 1);
1529 }
1530 ULONG SerialPortCount = 0;
1531 {
1532 ComPtr <ISystemProperties> info;
1533 CHECK_ERROR_RET (virtualBox, COMGETTER(SystemProperties) (info.asOutParam()), 1);
1534 CHECK_ERROR_RET (info, COMGETTER(SerialPortCount) (&SerialPortCount), 1);
1535 }
1536
1537 std::vector <char *> nics (NetworkAdapterCount, 0);
1538 std::vector <char *> nictype (NetworkAdapterCount, 0);
1539 std::vector <char *> cableconnected (NetworkAdapterCount, 0);
1540 std::vector <char *> nictrace (NetworkAdapterCount, 0);
1541 std::vector <char *> nictracefile (NetworkAdapterCount, 0);
1542 std::vector <char *> nicspeed (NetworkAdapterCount, 0);
1543 std::vector <char *> hostifdev (NetworkAdapterCount, 0);
1544 std::vector <const char *> intnet (NetworkAdapterCount, 0);
1545 std::vector <const char *> natnet (NetworkAdapterCount, 0);
1546#ifdef RT_OS_LINUX
1547 std::vector <char *> tapsetup (NetworkAdapterCount, 0);
1548 std::vector <char *> tapterm (NetworkAdapterCount, 0);
1549#endif
1550 std::vector <char *> macs (NetworkAdapterCount, 0);
1551 std::vector <char *> uarts_mode (SerialPortCount, 0);
1552 std::vector <ULONG> uarts_base (SerialPortCount, 0);
1553 std::vector <ULONG> uarts_irq (SerialPortCount, 0);
1554 std::vector <char *> uarts_path (SerialPortCount, 0);
1555
1556 for (int i = 1; i < argc; i++)
1557 {
1558 if (strcmp(argv[i], "-name") == 0)
1559 {
1560 if (argc <= i + 1)
1561 return errorArgument("Missing argument to '%s'", argv[i]);
1562 i++;
1563 name = argv[i];
1564 }
1565 else if (strcmp(argv[i], "-ostype") == 0)
1566 {
1567 if (argc <= i + 1)
1568 return errorArgument("Missing argument to '%s'", argv[i]);
1569 i++;
1570 ostype = argv[i];
1571 }
1572 else if (strcmp(argv[i], "-memory") == 0)
1573 {
1574 if (argc <= i + 1)
1575 return errorArgument("Missing argument to '%s'", argv[i]);
1576 i++;
1577 memorySize = RTStrToUInt32(argv[i]);
1578 }
1579 else if (strcmp(argv[i], "-vram") == 0)
1580 {
1581 if (argc <= i + 1)
1582 return errorArgument("Missing argument to '%s'", argv[i]);
1583 i++;
1584 vramSize = RTStrToUInt32(argv[i]);
1585 }
1586 else if (strcmp(argv[i], "-acpi") == 0)
1587 {
1588 if (argc <= i + 1)
1589 return errorArgument("Missing argument to '%s'", argv[i]);
1590 i++;
1591 acpi = argv[i];
1592 }
1593 else if (strcmp(argv[i], "-ioapic") == 0)
1594 {
1595 if (argc <= i + 1)
1596 return errorArgument("Missing argument to '%s'", argv[i]);
1597 i++;
1598 ioapic = argv[i];
1599 }
1600 else if (strcmp(argv[i], "-hwvirtex") == 0)
1601 {
1602 if (argc <= i + 1)
1603 return errorArgument("Missing argument to '%s'", argv[i]);
1604 i++;
1605 hwvirtex = argv[i];
1606 }
1607 else if (strcmp(argv[i], "-nestedpaging") == 0)
1608 {
1609 if (argc <= i + 1)
1610 return errorArgument("Missing argument to '%s'", argv[i]);
1611 i++;
1612 nestedpaging = argv[i];
1613 }
1614 else if (strcmp(argv[i], "-vtxvpid") == 0)
1615 {
1616 if (argc <= i + 1)
1617 return errorArgument("Missing argument to '%s'", argv[i]);
1618 i++;
1619 vtxvpid = argv[i];
1620 }
1621 else if (strcmp(argv[i], "-pae") == 0)
1622 {
1623 if (argc <= i + 1)
1624 return errorArgument("Missing argument to '%s'", argv[i]);
1625 i++;
1626 pae = argv[i];
1627 }
1628 else if (strcmp(argv[i], "-monitorcount") == 0)
1629 {
1630 if (argc <= i + 1)
1631 return errorArgument("Missing argument to '%s'", argv[i]);
1632 i++;
1633 monitorcount = RTStrToUInt32(argv[i]);
1634 }
1635 else if (strcmp(argv[i], "-accelerate3d") == 0)
1636 {
1637 if (argc <= i + 1)
1638 return errorArgument("Missing argument to '%s'", argv[i]);
1639 i++;
1640 accelerate3d = argv[i];
1641 }
1642 else if (strcmp(argv[i], "-bioslogofadein") == 0)
1643 {
1644 if (argc <= i + 1)
1645 return errorArgument("Missing argument to '%s'", argv[i]);
1646 i++;
1647 bioslogofadein = argv[i];
1648 }
1649 else if (strcmp(argv[i], "-bioslogofadeout") == 0)
1650 {
1651 if (argc <= i + 1)
1652 return errorArgument("Missing argument to '%s'", argv[i]);
1653 i++;
1654 bioslogofadeout = argv[i];
1655 }
1656 else if (strcmp(argv[i], "-bioslogodisplaytime") == 0)
1657 {
1658 if (argc <= i + 1)
1659 return errorArgument("Missing argument to '%s'", argv[i]);
1660 i++;
1661 bioslogodisplaytime = RTStrToUInt32(argv[i]);
1662 }
1663 else if (strcmp(argv[i], "-bioslogoimagepath") == 0)
1664 {
1665 if (argc <= i + 1)
1666 return errorArgument("Missing argument to '%s'", argv[i]);
1667 i++;
1668 bioslogoimagepath = argv[i];
1669 }
1670 else if (strcmp(argv[i], "-biosbootmenu") == 0)
1671 {
1672 if (argc <= i + 1)
1673 return errorArgument("Missing argument to '%s'", argv[i]);
1674 i++;
1675 biosbootmenumode = argv[i];
1676 }
1677 else if (strcmp(argv[i], "-biossystemtimeoffset") == 0)
1678 {
1679 if (argc <= i + 1)
1680 return errorArgument("Missing argument to '%s'", argv[i]);
1681 i++;
1682 biossystemtimeoffset = argv[i];
1683 }
1684 else if (strcmp(argv[i], "-biospxedebug") == 0)
1685 {
1686 if (argc <= i + 1)
1687 return errorArgument("Missing argument to '%s'", argv[i]);
1688 i++;
1689 biospxedebug = argv[i];
1690 }
1691 else if (strncmp(argv[i], "-boot", 5) == 0)
1692 {
1693 uint32_t n = 0;
1694 if (!argv[i][5])
1695 return errorSyntax(USAGE_MODIFYVM, "Missing boot slot number in '%s'", argv[i]);
1696 if (VINF_SUCCESS != RTStrToUInt32Full(&argv[i][5], 10, &n))
1697 return errorSyntax(USAGE_MODIFYVM, "Invalid boot slot number in '%s'", argv[i]);
1698 if (argc <= i + 1)
1699 return errorArgument("Missing argument to '%s'", argv[i]);
1700 i++;
1701 if (strcmp(argv[i], "none") == 0)
1702 {
1703 bootDevice[n - 1] = DeviceType_Null;
1704 }
1705 else if (strcmp(argv[i], "floppy") == 0)
1706 {
1707 bootDevice[n - 1] = DeviceType_Floppy;
1708 }
1709 else if (strcmp(argv[i], "dvd") == 0)
1710 {
1711 bootDevice[n - 1] = DeviceType_DVD;
1712 }
1713 else if (strcmp(argv[i], "disk") == 0)
1714 {
1715 bootDevice[n - 1] = DeviceType_HardDisk;
1716 }
1717 else if (strcmp(argv[i], "net") == 0)
1718 {
1719 bootDevice[n - 1] = DeviceType_Network;
1720 }
1721 else
1722 return errorArgument("Invalid boot device '%s'", argv[i]);
1723
1724 bootDeviceChanged[n - 1] = true;
1725 }
1726 else if (strcmp(argv[i], "-hda") == 0)
1727 {
1728 if (argc <= i + 1)
1729 return errorArgument("Missing argument to '%s'", argv[i]);
1730 i++;
1731 hdds[0] = argv[i];
1732 }
1733 else if (strcmp(argv[i], "-hdb") == 0)
1734 {
1735 if (argc <= i + 1)
1736 return errorArgument("Missing argument to '%s'", argv[i]);
1737 i++;
1738 hdds[1] = argv[i];
1739 }
1740 else if (strcmp(argv[i], "-hdd") == 0)
1741 {
1742 if (argc <= i + 1)
1743 return errorArgument("Missing argument to '%s'", argv[i]);
1744 i++;
1745 hdds[2] = argv[i];
1746 }
1747 else if (strcmp(argv[i], "-dvd") == 0)
1748 {
1749 if (argc <= i + 1)
1750 return errorArgument("Missing argument to '%s'", argv[i]);
1751 i++;
1752 dvd = argv[i];
1753 }
1754 else if (strcmp(argv[i], "-dvdpassthrough") == 0)
1755 {
1756 if (argc <= i + 1)
1757 return errorArgument("Missing argument to '%s'", argv[i]);
1758 i++;
1759 dvdpassthrough = argv[i];
1760 }
1761 else if (strcmp(argv[i], "-idecontroller") == 0)
1762 {
1763 if (argc <= i + 1)
1764 return errorArgument("Missing argument to '%s'", argv[i]);
1765 i++;
1766 idecontroller = argv[i];
1767 }
1768 else if (strcmp(argv[i], "-floppy") == 0)
1769 {
1770 if (argc <= i + 1)
1771 return errorArgument("Missing argument to '%s'", argv[i]);
1772 i++;
1773 floppy = argv[i];
1774 }
1775 else if (strcmp(argv[i], "-audio") == 0)
1776 {
1777 if (argc <= i + 1)
1778 return errorArgument("Missing argument to '%s'", argv[i]);
1779 i++;
1780 audio = argv[i];
1781 }
1782 else if (strcmp(argv[i], "-audiocontroller") == 0)
1783 {
1784 if (argc <= i + 1)
1785 return errorArgument("Missing argument to '%s'", argv[i]);
1786 i++;
1787 audiocontroller = argv[i];
1788 }
1789 else if (strcmp(argv[i], "-clipboard") == 0)
1790 {
1791 if (argc <= i + 1)
1792 return errorArgument("Missing argument to '%s'", argv[i]);
1793 i++;
1794 clipboard = argv[i];
1795 }
1796 else if (strncmp(argv[i], "-cableconnected", 15) == 0)
1797 {
1798 unsigned n = parseNum(&argv[i][15], NetworkAdapterCount, "NIC");
1799 if (!n)
1800 return 1;
1801
1802 if (argc <= i + 1)
1803 return errorArgument("Missing argument to '%s'", argv[i]);
1804
1805 cableconnected[n - 1] = argv[i + 1];
1806 i++;
1807 }
1808 /* watch for the right order of these -nic* comparisons! */
1809 else if (strncmp(argv[i], "-nictracefile", 13) == 0)
1810 {
1811 unsigned n = parseNum(&argv[i][13], NetworkAdapterCount, "NIC");
1812 if (!n)
1813 return 1;
1814 if (argc <= i + 1)
1815 {
1816 return errorArgument("Missing argument to '%s'", argv[i]);
1817 }
1818 nictracefile[n - 1] = argv[i + 1];
1819 i++;
1820 }
1821 else if (strncmp(argv[i], "-nictrace", 9) == 0)
1822 {
1823 unsigned n = parseNum(&argv[i][9], NetworkAdapterCount, "NIC");
1824 if (!n)
1825 return 1;
1826 if (argc <= i + 1)
1827 return errorArgument("Missing argument to '%s'", argv[i]);
1828 nictrace[n - 1] = argv[i + 1];
1829 i++;
1830 }
1831 else if (strncmp(argv[i], "-nictype", 8) == 0)
1832 {
1833 unsigned n = parseNum(&argv[i][8], NetworkAdapterCount, "NIC");
1834 if (!n)
1835 return 1;
1836 if (argc <= i + 1)
1837 return errorArgument("Missing argument to '%s'", argv[i]);
1838 nictype[n - 1] = argv[i + 1];
1839 i++;
1840 }
1841 else if (strncmp(argv[i], "-nicspeed", 9) == 0)
1842 {
1843 unsigned n = parseNum(&argv[i][9], NetworkAdapterCount, "NIC");
1844 if (!n)
1845 return 1;
1846 if (argc <= i + 1)
1847 return errorArgument("Missing argument to '%s'", argv[i]);
1848 nicspeed[n - 1] = argv[i + 1];
1849 i++;
1850 }
1851 else if (strncmp(argv[i], "-nic", 4) == 0)
1852 {
1853 unsigned n = parseNum(&argv[i][4], NetworkAdapterCount, "NIC");
1854 if (!n)
1855 return 1;
1856 if (argc <= i + 1)
1857 return errorArgument("Missing argument to '%s'", argv[i]);
1858 nics[n - 1] = argv[i + 1];
1859 i++;
1860 }
1861 else if (strncmp(argv[i], "-hostifdev", 10) == 0)
1862 {
1863 unsigned n = parseNum(&argv[i][10], NetworkAdapterCount, "NIC");
1864 if (!n)
1865 return 1;
1866 if (argc <= i + 1)
1867 return errorArgument("Missing argument to '%s'", argv[i]);
1868 hostifdev[n - 1] = argv[i + 1];
1869 i++;
1870 }
1871 else if (strncmp(argv[i], "-intnet", 7) == 0)
1872 {
1873 unsigned n = parseNum(&argv[i][7], NetworkAdapterCount, "NIC");
1874 if (!n)
1875 return 1;
1876 if (argc <= i + 1)
1877 return errorArgument("Missing argument to '%s'", argv[i]);
1878 intnet[n - 1] = argv[i + 1];
1879 i++;
1880 }
1881 else if (strncmp(argv[i], "-natnet", 7) == 0)
1882 {
1883 unsigned n = parseNum(&argv[i][7], NetworkAdapterCount, "NIC");
1884 if (!n)
1885 return 1;
1886 if (argc <= i + 1)
1887 return errorArgument("Missing argument to '%s'", argv[i]);
1888
1889 if (!strcmp(argv[i + 1], "default"))
1890 natnet[n - 1] = "";
1891 else
1892 {
1893 RTIPV4ADDR Network;
1894 RTIPV4ADDR Netmask;
1895 int rc = RTCidrStrToIPv4(argv[i + 1], &Network, &Netmask);
1896 if (RT_FAILURE(rc))
1897 return errorArgument("Invalid IPv4 network '%s' specified -- CIDR notation expected.\n", argv[i + 1]);
1898 if (Netmask & 0x1f)
1899 return errorArgument("Prefix length of the NAT network must be less than 28.\n");
1900 natnet[n - 1] = argv[i + 1];
1901 }
1902 i++;
1903 }
1904#ifdef RT_OS_LINUX
1905 else if (strncmp(argv[i], "-tapsetup", 9) == 0)
1906 {
1907 unsigned n = parseNum(&argv[i][9], NetworkAdapterCount, "NIC");
1908 if (!n)
1909 return 1;
1910 if (argc <= i + 1)
1911 return errorArgument("Missing argument to '%s'", argv[i]);
1912 tapsetup[n - 1] = argv[i + 1];
1913 i++;
1914 }
1915 else if (strncmp(argv[i], "-tapterminate", 13) == 0)
1916 {
1917 unsigned n = parseNum(&argv[i][13], NetworkAdapterCount, "NIC");
1918 if (!n)
1919 return 1;
1920 if (argc <= i + 1)
1921 return errorArgument("Missing argument to '%s'", argv[i]);
1922 tapterm[n - 1] = argv[i + 1];
1923 i++;
1924 }
1925#endif /* RT_OS_LINUX */
1926 else if (strncmp(argv[i], "-macaddress", 11) == 0)
1927 {
1928 unsigned n = parseNum(&argv[i][11], NetworkAdapterCount, "NIC");
1929 if (!n)
1930 return 1;
1931 if (argc <= i + 1)
1932 return errorArgument("Missing argument to '%s'", argv[i]);
1933 macs[n - 1] = argv[i + 1];
1934 i++;
1935 }
1936#ifdef VBOX_WITH_VRDP
1937 else if (strcmp(argv[i], "-vrdp") == 0)
1938 {
1939 if (argc <= i + 1)
1940 return errorArgument("Missing argument to '%s'", argv[i]);
1941 i++;
1942 vrdp = argv[i];
1943 }
1944 else if (strcmp(argv[i], "-vrdpport") == 0)
1945 {
1946 if (argc <= i + 1)
1947 return errorArgument("Missing argument to '%s'", argv[i]);
1948 i++;
1949 if (strcmp(argv[i], "default") == 0)
1950 vrdpport = 0;
1951 else
1952 vrdpport = RTStrToUInt16(argv[i]);
1953 }
1954 else if (strcmp(argv[i], "-vrdpaddress") == 0)
1955 {
1956 if (argc <= i + 1)
1957 return errorArgument("Missing argument to '%s'", argv[i]);
1958 i++;
1959 vrdpaddress = argv[i];
1960 }
1961 else if (strcmp(argv[i], "-vrdpauthtype") == 0)
1962 {
1963 if (argc <= i + 1)
1964 return errorArgument("Missing argument to '%s'", argv[i]);
1965 i++;
1966 vrdpauthtype = argv[i];
1967 }
1968 else if (strcmp(argv[i], "-vrdpmulticon") == 0)
1969 {
1970 if (argc <= i + 1)
1971 return errorArgument("Missing argument to '%s'", argv[i]);
1972 i++;
1973 vrdpmulticon = argv[i];
1974 }
1975 else if (strcmp(argv[i], "-vrdpreusecon") == 0)
1976 {
1977 if (argc <= i + 1)
1978 return errorArgument("Missing argument to '%s'", argv[i]);
1979 i++;
1980 vrdpreusecon = argv[i];
1981 }
1982#endif /* VBOX_WITH_VRDP */
1983 else if (strcmp(argv[i], "-usb") == 0)
1984 {
1985 if (argc <= i + 1)
1986 return errorArgument("Missing argument to '%s'", argv[i]);
1987 i++;
1988 if (strcmp(argv[i], "on") == 0 || strcmp(argv[i], "enable") == 0)
1989 fUsbEnabled = 1;
1990 else if (strcmp(argv[i], "off") == 0 || strcmp(argv[i], "disable") == 0)
1991 fUsbEnabled = 0;
1992 else
1993 return errorArgument("Invalid -usb argument '%s'", argv[i]);
1994 }
1995 else if (strcmp(argv[i], "-usbehci") == 0)
1996 {
1997 if (argc <= i + 1)
1998 return errorArgument("Missing argument to '%s'", argv[i]);
1999 i++;
2000 if (strcmp(argv[i], "on") == 0 || strcmp(argv[i], "enable") == 0)
2001 fUsbEhciEnabled = 1;
2002 else if (strcmp(argv[i], "off") == 0 || strcmp(argv[i], "disable") == 0)
2003 fUsbEhciEnabled = 0;
2004 else
2005 return errorArgument("Invalid -usbehci argument '%s'", argv[i]);
2006 }
2007 else if (strcmp(argv[i], "-snapshotfolder") == 0)
2008 {
2009 if (argc <= i + 1)
2010 return errorArgument("Missing argument to '%s'", argv[i]);
2011 i++;
2012 snapshotFolder = argv[i];
2013 }
2014 else if (strncmp(argv[i], "-uartmode", 9) == 0)
2015 {
2016 unsigned n = parseNum(&argv[i][9], SerialPortCount, "UART");
2017 if (!n)
2018 return 1;
2019 i++;
2020 if (strcmp(argv[i], "disconnected") == 0)
2021 {
2022 uarts_mode[n - 1] = argv[i];
2023 }
2024 else
2025 {
2026 if (strcmp(argv[i], "server") == 0 || strcmp(argv[i], "client") == 0)
2027 {
2028 uarts_mode[n - 1] = argv[i];
2029 i++;
2030#ifdef RT_OS_WINDOWS
2031 if (strncmp(argv[i], "\\\\.\\pipe\\", 9))
2032 return errorArgument("Uart pipe must start with \\\\.\\pipe\\");
2033#endif
2034 }
2035 else
2036 {
2037 uarts_mode[n - 1] = (char*)"device";
2038 }
2039 if (argc <= i)
2040 return errorArgument("Missing argument to -uartmode");
2041 uarts_path[n - 1] = argv[i];
2042 }
2043 }
2044 else if (strncmp(argv[i], "-uart", 5) == 0)
2045 {
2046 unsigned n = parseNum(&argv[i][5], SerialPortCount, "UART");
2047 if (!n)
2048 return 1;
2049 if (argc <= i + 1)
2050 return errorArgument("Missing argument to '%s'", argv[i]);
2051 i++;
2052 if (strcmp(argv[i], "off") == 0 || strcmp(argv[i], "disable") == 0)
2053 {
2054 uarts_base[n - 1] = (ULONG)-1;
2055 }
2056 else
2057 {
2058 if (argc <= i + 1)
2059 return errorArgument("Missing argument to '%s'", argv[i-1]);
2060 uint32_t uVal;
2061 int vrc;
2062 vrc = RTStrToUInt32Ex(argv[i], NULL, 0, &uVal);
2063 if (vrc != VINF_SUCCESS || uVal == 0)
2064 return errorArgument("Error parsing UART I/O base '%s'", argv[i]);
2065 uarts_base[n - 1] = uVal;
2066 i++;
2067 vrc = RTStrToUInt32Ex(argv[i], NULL, 0, &uVal);
2068 if (vrc != VINF_SUCCESS)
2069 return errorArgument("Error parsing UART IRQ '%s'", argv[i]);
2070 uarts_irq[n - 1] = uVal;
2071 }
2072 }
2073#ifdef VBOX_WITH_MEM_BALLOONING
2074 else if (strncmp(argv[i], "-guestmemoryballoon", 19) == 0)
2075 {
2076 if (argc <= i + 1)
2077 return errorArgument("Missing argument to '%s'", argv[i]);
2078 i++;
2079 uint32_t uVal;
2080 int vrc;
2081 vrc = RTStrToUInt32Ex(argv[i], NULL, 0, &uVal);
2082 if (vrc != VINF_SUCCESS)
2083 return errorArgument("Error parsing guest memory balloon size '%s'", argv[i]);
2084 guestMemBalloonSize = uVal;
2085 }
2086#endif
2087 else if (strncmp(argv[i], "-gueststatisticsinterval", 24) == 0)
2088 {
2089 if (argc <= i + 1)
2090 return errorArgument("Missing argument to '%s'", argv[i]);
2091 i++;
2092 uint32_t uVal;
2093 int vrc;
2094 vrc = RTStrToUInt32Ex(argv[i], NULL, 0, &uVal);
2095 if (vrc != VINF_SUCCESS)
2096 return errorArgument("Error parsing guest statistics interval '%s'", argv[i]);
2097 guestStatInterval = uVal;
2098 }
2099 else if (strcmp(argv[i], "-sata") == 0)
2100 {
2101 if (argc <= i + 1)
2102 return errorArgument("Missing argument to '%s'", argv[i]);
2103 i++;
2104 if (strcmp(argv[i], "on") == 0 || strcmp(argv[i], "enable") == 0)
2105 fSataEnabled = 1;
2106 else if (strcmp(argv[i], "off") == 0 || strcmp(argv[i], "disable") == 0)
2107 fSataEnabled = 0;
2108 else
2109 return errorArgument("Invalid -usb argument '%s'", argv[i]);
2110 }
2111 else if (strcmp(argv[i], "-sataportcount") == 0)
2112 {
2113 unsigned n;
2114
2115 if (argc <= i + 1)
2116 return errorArgument("Missing arguments to '%s'", argv[i]);
2117 i++;
2118
2119 n = parseNum(argv[i], 30, "SATA");
2120 if (!n)
2121 return 1;
2122 sataPortCount = n;
2123 }
2124 else if (strncmp(argv[i], "-sataport", 9) == 0)
2125 {
2126 unsigned n = parseNum(&argv[i][9], 30, "SATA");
2127 if (!n)
2128 return 1;
2129 if (argc <= i + 1)
2130 return errorArgument("Missing argument to '%s'", argv[i]);
2131 i++;
2132 hdds[n-1+4] = argv[i];
2133 }
2134 else if (strncmp(argv[i], "-sataideemulation", 17) == 0)
2135 {
2136 unsigned bootDevicePos = 0;
2137 unsigned n;
2138
2139 bootDevicePos = parseNum(&argv[i][17], 4, "SATA");
2140 if (!bootDevicePos)
2141 return 1;
2142 bootDevicePos--;
2143
2144 if (argc <= i + 1)
2145 return errorArgument("Missing arguments to '%s'", argv[i]);
2146 i++;
2147
2148 n = parseNum(argv[i], 30, "SATA");
2149 if (!n)
2150 return 1;
2151
2152 sataBootDevices[bootDevicePos] = n-1;
2153 }
2154 else
2155 return errorSyntax(USAGE_MODIFYVM, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
2156 }
2157
2158 /* try to find the given machine */
2159 ComPtr <IMachine> machine;
2160 Guid uuid (argv[0]);
2161 if (!uuid.isEmpty())
2162 {
2163 CHECK_ERROR (virtualBox, GetMachine (uuid, machine.asOutParam()));
2164 }
2165 else
2166 {
2167 CHECK_ERROR (virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
2168 if (SUCCEEDED (rc))
2169 machine->COMGETTER(Id)(uuid.asOutParam());
2170 }
2171 if (FAILED (rc))
2172 return 1;
2173
2174 /* open a session for the VM */
2175 CHECK_ERROR_RET (virtualBox, OpenSession(session, uuid), 1);
2176
2177 do
2178 {
2179 /* get the mutable session machine */
2180 session->COMGETTER(Machine)(machine.asOutParam());
2181
2182 ComPtr <IBIOSSettings> biosSettings;
2183 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
2184
2185 if (name)
2186 CHECK_ERROR(machine, COMSETTER(Name)(name));
2187 if (ostype)
2188 {
2189 ComPtr<IGuestOSType> guestOSType;
2190 CHECK_ERROR(virtualBox, GetGuestOSType(ostype, guestOSType.asOutParam()));
2191 if (SUCCEEDED(rc) && guestOSType)
2192 {
2193 CHECK_ERROR(machine, COMSETTER(OSTypeId)(ostype));
2194 }
2195 else
2196 {
2197 errorArgument("Invalid guest OS type '%s'", Utf8Str(ostype).raw());
2198 rc = E_FAIL;
2199 break;
2200 }
2201 }
2202 if (memorySize > 0)
2203 CHECK_ERROR(machine, COMSETTER(MemorySize)(memorySize));
2204 if (vramSize > 0)
2205 CHECK_ERROR(machine, COMSETTER(VRAMSize)(vramSize));
2206 if (acpi)
2207 {
2208 if (strcmp(acpi, "on") == 0)
2209 {
2210 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(true));
2211 }
2212 else if (strcmp(acpi, "off") == 0)
2213 {
2214 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(false));
2215 }
2216 else
2217 {
2218 errorArgument("Invalid -acpi argument '%s'", acpi);
2219 rc = E_FAIL;
2220 break;
2221 }
2222 }
2223 if (ioapic)
2224 {
2225 if (strcmp(ioapic, "on") == 0)
2226 {
2227 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(true));
2228 }
2229 else if (strcmp(ioapic, "off") == 0)
2230 {
2231 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(false));
2232 }
2233 else
2234 {
2235 errorArgument("Invalid -ioapic argument '%s'", ioapic);
2236 rc = E_FAIL;
2237 break;
2238 }
2239 }
2240 if (hwvirtex)
2241 {
2242 if (strcmp(hwvirtex, "on") == 0)
2243 {
2244 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_True));
2245 }
2246 else if (strcmp(hwvirtex, "off") == 0)
2247 {
2248 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_False));
2249 }
2250 else if (strcmp(hwvirtex, "default") == 0)
2251 {
2252 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_Default));
2253 }
2254 else
2255 {
2256 errorArgument("Invalid -hwvirtex argument '%s'", hwvirtex);
2257 rc = E_FAIL;
2258 break;
2259 }
2260 }
2261 if (nestedpaging)
2262 {
2263 if (strcmp(nestedpaging, "on") == 0)
2264 {
2265 CHECK_ERROR(machine, COMSETTER(HWVirtExNestedPagingEnabled)(true));
2266 }
2267 else if (strcmp(nestedpaging, "off") == 0)
2268 {
2269 CHECK_ERROR(machine, COMSETTER(HWVirtExNestedPagingEnabled)(false));
2270 }
2271 else
2272 {
2273 errorArgument("Invalid -nestedpaging argument '%s'", ioapic);
2274 rc = E_FAIL;
2275 break;
2276 }
2277 }
2278 if (vtxvpid)
2279 {
2280 if (strcmp(vtxvpid, "on") == 0)
2281 {
2282 CHECK_ERROR(machine, COMSETTER(HWVirtExVPIDEnabled)(true));
2283 }
2284 else if (strcmp(vtxvpid, "off") == 0)
2285 {
2286 CHECK_ERROR(machine, COMSETTER(HWVirtExVPIDEnabled)(false));
2287 }
2288 else
2289 {
2290 errorArgument("Invalid -vtxvpid argument '%s'", ioapic);
2291 rc = E_FAIL;
2292 break;
2293 }
2294 }
2295 if (pae)
2296 {
2297 if (strcmp(pae, "on") == 0)
2298 {
2299 CHECK_ERROR(machine, COMSETTER(PAEEnabled)(true));
2300 }
2301 else if (strcmp(pae, "off") == 0)
2302 {
2303 CHECK_ERROR(machine, COMSETTER(PAEEnabled)(false));
2304 }
2305 else
2306 {
2307 errorArgument("Invalid -pae argument '%s'", ioapic);
2308 rc = E_FAIL;
2309 break;
2310 }
2311 }
2312 if (monitorcount != ~0U)
2313 {
2314 CHECK_ERROR(machine, COMSETTER(MonitorCount)(monitorcount));
2315 }
2316 if (accelerate3d)
2317 {
2318 if (strcmp(accelerate3d, "on") == 0)
2319 {
2320 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(true));
2321 }
2322 else if (strcmp(accelerate3d, "off") == 0)
2323 {
2324 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(false));
2325 }
2326 else
2327 {
2328 errorArgument("Invalid -accelerate3d argument '%s'", ioapic);
2329 rc = E_FAIL;
2330 break;
2331 }
2332 }
2333 if (bioslogofadein)
2334 {
2335 if (strcmp(bioslogofadein, "on") == 0)
2336 {
2337 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(true));
2338 }
2339 else if (strcmp(bioslogofadein, "off") == 0)
2340 {
2341 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(false));
2342 }
2343 else
2344 {
2345 errorArgument("Invalid -bioslogofadein argument '%s'", bioslogofadein);
2346 rc = E_FAIL;
2347 break;
2348 }
2349 }
2350 if (bioslogofadeout)
2351 {
2352 if (strcmp(bioslogofadeout, "on") == 0)
2353 {
2354 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(true));
2355 }
2356 else if (strcmp(bioslogofadeout, "off") == 0)
2357 {
2358 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(false));
2359 }
2360 else
2361 {
2362 errorArgument("Invalid -bioslogofadeout argument '%s'", bioslogofadeout);
2363 rc = E_FAIL;
2364 break;
2365 }
2366 }
2367 if (bioslogodisplaytime != ~0U)
2368 {
2369 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(bioslogodisplaytime));
2370 }
2371 if (bioslogoimagepath)
2372 {
2373 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(bioslogoimagepath)));
2374 }
2375 if (biosbootmenumode)
2376 {
2377 if (strcmp(biosbootmenumode, "disabled") == 0)
2378 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
2379 else if (strcmp(biosbootmenumode, "menuonly") == 0)
2380 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
2381 else if (strcmp(biosbootmenumode, "messageandmenu") == 0)
2382 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
2383 else
2384 {
2385 errorArgument("Invalid -biosbootmenu argument '%s'", biosbootmenumode);
2386 rc = E_FAIL;
2387 break;
2388 }
2389
2390 }
2391 if (biossystemtimeoffset)
2392 {
2393 LONG64 timeOffset = RTStrToInt64(biossystemtimeoffset);
2394 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(timeOffset));
2395 }
2396 if (biospxedebug)
2397 {
2398 if (strcmp(biospxedebug, "on") == 0)
2399 {
2400 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(true));
2401 }
2402 else if (strcmp(biospxedebug, "off") == 0)
2403 {
2404 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(false));
2405 }
2406 else
2407 {
2408 errorArgument("Invalid -biospxedebug argument '%s'", biospxedebug);
2409 rc = E_FAIL;
2410 break;
2411 }
2412 }
2413 for (int curBootDev = 0; curBootDev < 4; curBootDev++)
2414 {
2415 if (bootDeviceChanged[curBootDev])
2416 CHECK_ERROR(machine, SetBootOrder (curBootDev + 1, bootDevice[curBootDev]));
2417 }
2418 if (hdds[0])
2419 {
2420 if (strcmp(hdds[0], "none") == 0)
2421 {
2422 machine->DetachHardDisk2(StorageBus_IDE, 0, 0);
2423 }
2424 else
2425 {
2426 /* first guess is that it's a UUID */
2427 Guid uuid(hdds[0]);
2428 ComPtr<IHardDisk2> hardDisk;
2429 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
2430 /* not successful? Then it must be a filename */
2431 if (!hardDisk)
2432 {
2433 CHECK_ERROR(virtualBox, FindHardDisk2(Bstr(hdds[0]), hardDisk.asOutParam()));
2434 if (FAILED(rc))
2435 {
2436 /* open the new hard disk object */
2437 CHECK_ERROR(virtualBox, OpenHardDisk2(Bstr(hdds[0]), hardDisk.asOutParam()));
2438 }
2439 }
2440 if (hardDisk)
2441 {
2442 hardDisk->COMGETTER(Id)(uuid.asOutParam());
2443 CHECK_ERROR(machine, AttachHardDisk2(uuid, StorageBus_IDE, 0, 0));
2444 }
2445 else
2446 rc = E_FAIL;
2447 if (FAILED(rc))
2448 break;
2449 }
2450 }
2451 if (hdds[1])
2452 {
2453 if (strcmp(hdds[1], "none") == 0)
2454 {
2455 machine->DetachHardDisk2(StorageBus_IDE, 0, 1);
2456 }
2457 else
2458 {
2459 /* first guess is that it's a UUID */
2460 Guid uuid(hdds[1]);
2461 ComPtr<IHardDisk2> hardDisk;
2462 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
2463 /* not successful? Then it must be a filename */
2464 if (!hardDisk)
2465 {
2466 CHECK_ERROR(virtualBox, FindHardDisk2(Bstr(hdds[1]), hardDisk.asOutParam()));
2467 if (FAILED(rc))
2468 {
2469 /* open the new hard disk object */
2470 CHECK_ERROR(virtualBox, OpenHardDisk2(Bstr(hdds[1]), hardDisk.asOutParam()));
2471 }
2472 }
2473 if (hardDisk)
2474 {
2475 hardDisk->COMGETTER(Id)(uuid.asOutParam());
2476 CHECK_ERROR(machine, AttachHardDisk2(uuid, StorageBus_IDE, 0, 1));
2477 }
2478 else
2479 rc = E_FAIL;
2480 if (FAILED(rc))
2481 break;
2482 }
2483 }
2484 if (hdds[2])
2485 {
2486 if (strcmp(hdds[2], "none") == 0)
2487 {
2488 machine->DetachHardDisk2(StorageBus_IDE, 1, 1);
2489 }
2490 else
2491 {
2492 /* first guess is that it's a UUID */
2493 Guid uuid(hdds[2]);
2494 ComPtr<IHardDisk2> hardDisk;
2495 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
2496 /* not successful? Then it must be a filename */
2497 if (!hardDisk)
2498 {
2499 CHECK_ERROR(virtualBox, FindHardDisk2(Bstr(hdds[2]), hardDisk.asOutParam()));
2500 if (FAILED(rc))
2501 {
2502 /* open the new hard disk object */
2503 CHECK_ERROR(virtualBox, OpenHardDisk2(Bstr(hdds[2]), hardDisk.asOutParam()));
2504 }
2505 }
2506 if (hardDisk)
2507 {
2508 hardDisk->COMGETTER(Id)(uuid.asOutParam());
2509 CHECK_ERROR(machine, AttachHardDisk2(uuid, StorageBus_IDE, 1, 1));
2510 }
2511 else
2512 rc = E_FAIL;
2513 if (FAILED(rc))
2514 break;
2515 }
2516 }
2517 if (dvd)
2518 {
2519 ComPtr<IDVDDrive> dvdDrive;
2520 machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
2521 ASSERT(dvdDrive);
2522
2523 /* unmount? */
2524 if (strcmp(dvd, "none") == 0)
2525 {
2526 CHECK_ERROR(dvdDrive, Unmount());
2527 }
2528 /* host drive? */
2529 else if (strncmp(dvd, "host:", 5) == 0)
2530 {
2531 ComPtr<IHost> host;
2532 CHECK_ERROR(virtualBox, COMGETTER(Host)(host.asOutParam()));
2533 ComPtr<IHostDVDDriveCollection> hostDVDs;
2534 CHECK_ERROR(host, COMGETTER(DVDDrives)(hostDVDs.asOutParam()));
2535 ComPtr<IHostDVDDrive> hostDVDDrive;
2536 rc = hostDVDs->FindByName(Bstr(dvd + 5), hostDVDDrive.asOutParam());
2537 if (!hostDVDDrive)
2538 {
2539 /* 2nd try: try with the real name, important on Linux+libhal */
2540 char szPathReal[RTPATH_MAX];
2541 if (RT_FAILURE(RTPathReal(dvd + 5, szPathReal, sizeof(szPathReal))))
2542 {
2543 errorArgument("Invalid host DVD drive name");
2544 rc = E_FAIL;
2545 break;
2546 }
2547 rc = hostDVDs->FindByName(Bstr(szPathReal), hostDVDDrive.asOutParam());
2548 if (!hostDVDDrive)
2549 {
2550 errorArgument("Invalid host DVD drive name");
2551 rc = E_FAIL;
2552 break;
2553 }
2554 }
2555 CHECK_ERROR(dvdDrive, CaptureHostDrive(hostDVDDrive));
2556 }
2557 else
2558 {
2559 /* first assume it's a UUID */
2560 Guid uuid(dvd);
2561 ComPtr<IDVDImage2> dvdImage;
2562 rc = virtualBox->GetDVDImage(uuid, dvdImage.asOutParam());
2563 if (FAILED(rc) || !dvdImage)
2564 {
2565 /* must be a filename, check if it's in the collection */
2566 rc = virtualBox->FindDVDImage(Bstr(dvd), dvdImage.asOutParam());
2567 /* not registered, do that on the fly */
2568 if (!dvdImage)
2569 {
2570 Guid emptyUUID;
2571 CHECK_ERROR(virtualBox, OpenDVDImage(Bstr(dvd), emptyUUID, dvdImage.asOutParam()));
2572 }
2573 }
2574 if (!dvdImage)
2575 {
2576 rc = E_FAIL;
2577 break;
2578 }
2579
2580 dvdImage->COMGETTER(Id)(uuid.asOutParam());
2581 CHECK_ERROR(dvdDrive, MountImage(uuid));
2582 }
2583 }
2584 if (dvdpassthrough)
2585 {
2586 ComPtr<IDVDDrive> dvdDrive;
2587 machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
2588 ASSERT(dvdDrive);
2589
2590 CHECK_ERROR(dvdDrive, COMSETTER(Passthrough)(strcmp(dvdpassthrough, "on") == 0));
2591 }
2592 if (idecontroller)
2593 {
2594 if (RTStrICmp(idecontroller, "PIIX3") == 0)
2595 {
2596 CHECK_ERROR(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX3));
2597 }
2598 else if (RTStrICmp(idecontroller, "PIIX4") == 0)
2599 {
2600 CHECK_ERROR(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX4));
2601 }
2602 else
2603 {
2604 errorArgument("Invalid -idecontroller argument '%s'", idecontroller);
2605 rc = E_FAIL;
2606 break;
2607 }
2608 }
2609 if (floppy)
2610 {
2611 ComPtr<IFloppyDrive> floppyDrive;
2612 machine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
2613 ASSERT(floppyDrive);
2614
2615 /* disable? */
2616 if (strcmp(floppy, "disabled") == 0)
2617 {
2618 /* disable the controller */
2619 CHECK_ERROR(floppyDrive, COMSETTER(Enabled)(false));
2620 }
2621 else
2622 {
2623 /* enable the controller */
2624 CHECK_ERROR(floppyDrive, COMSETTER(Enabled)(true));
2625
2626 /* unmount? */
2627 if (strcmp(floppy, "empty") == 0)
2628 {
2629 CHECK_ERROR(floppyDrive, Unmount());
2630 }
2631 /* host drive? */
2632 else if (strncmp(floppy, "host:", 5) == 0)
2633 {
2634 ComPtr<IHost> host;
2635 CHECK_ERROR(virtualBox, COMGETTER(Host)(host.asOutParam()));
2636 ComPtr<IHostFloppyDriveCollection> hostFloppies;
2637 CHECK_ERROR(host, COMGETTER(FloppyDrives)(hostFloppies.asOutParam()));
2638 ComPtr<IHostFloppyDrive> hostFloppyDrive;
2639 rc = hostFloppies->FindByName(Bstr(floppy + 5), hostFloppyDrive.asOutParam());
2640 if (!hostFloppyDrive)
2641 {
2642 errorArgument("Invalid host floppy drive name");
2643 rc = E_FAIL;
2644 break;
2645 }
2646 CHECK_ERROR(floppyDrive, CaptureHostDrive(hostFloppyDrive));
2647 }
2648 else
2649 {
2650 /* first assume it's a UUID */
2651 Guid uuid(floppy);
2652 ComPtr<IFloppyImage2> floppyImage;
2653 rc = virtualBox->GetFloppyImage(uuid, floppyImage.asOutParam());
2654 if (FAILED(rc) || !floppyImage)
2655 {
2656 /* must be a filename, check if it's in the collection */
2657 rc = virtualBox->FindFloppyImage(Bstr(floppy), floppyImage.asOutParam());
2658 /* not registered, do that on the fly */
2659 if (!floppyImage)
2660 {
2661 Guid emptyUUID;
2662 CHECK_ERROR(virtualBox, OpenFloppyImage(Bstr(floppy), emptyUUID, floppyImage.asOutParam()));
2663 }
2664 }
2665 if (!floppyImage)
2666 {
2667 rc = E_FAIL;
2668 break;
2669 }
2670
2671 floppyImage->COMGETTER(Id)(uuid.asOutParam());
2672 CHECK_ERROR(floppyDrive, MountImage(uuid));
2673 }
2674 }
2675 }
2676 if (audio || audiocontroller)
2677 {
2678 ComPtr<IAudioAdapter> audioAdapter;
2679 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
2680 ASSERT(audioAdapter);
2681
2682 if (audio)
2683 {
2684 /* disable? */
2685 if (strcmp(audio, "none") == 0)
2686 {
2687 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
2688 }
2689 else if (strcmp(audio, "null") == 0)
2690 {
2691 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
2692 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2693 }
2694#ifdef RT_OS_WINDOWS
2695#ifdef VBOX_WITH_WINMM
2696 else if (strcmp(audio, "winmm") == 0)
2697 {
2698 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
2699 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2700 }
2701#endif
2702 else if (strcmp(audio, "dsound") == 0)
2703 {
2704 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
2705 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2706 }
2707#endif /* RT_OS_WINDOWS */
2708#ifdef RT_OS_LINUX
2709 else if (strcmp(audio, "oss") == 0)
2710 {
2711 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
2712 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2713 }
2714# ifdef VBOX_WITH_ALSA
2715 else if (strcmp(audio, "alsa") == 0)
2716 {
2717 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
2718 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2719 }
2720# endif
2721# ifdef VBOX_WITH_PULSE
2722 else if (strcmp(audio, "pulse") == 0)
2723 {
2724 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
2725 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2726 }
2727# endif
2728#endif /* !RT_OS_LINUX */
2729#ifdef RT_OS_SOLARIS
2730 else if (strcmp(audio, "solaudio") == 0)
2731 {
2732 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
2733 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2734 }
2735
2736#endif /* !RT_OS_SOLARIS */
2737#ifdef RT_OS_DARWIN
2738 else if (strcmp(audio, "coreaudio") == 0)
2739 {
2740 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
2741 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2742 }
2743
2744#endif /* !RT_OS_DARWIN */
2745 else
2746 {
2747 errorArgument("Invalid -audio argument '%s'", audio);
2748 rc = E_FAIL;
2749 break;
2750 }
2751 }
2752 if (audiocontroller)
2753 {
2754 if (strcmp(audiocontroller, "sb16") == 0)
2755 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
2756 else if (strcmp(audiocontroller, "ac97") == 0)
2757 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
2758 else
2759 {
2760 errorArgument("Invalid -audiocontroller argument '%s'", audiocontroller);
2761 rc = E_FAIL;
2762 break;
2763 }
2764 }
2765 }
2766 /* Shared clipboard state */
2767 if (clipboard)
2768 {
2769/* ComPtr<IClipboardMode> clipboardMode;
2770 machine->COMGETTER(ClipboardMode)(clipboardMode.asOutParam());
2771 ASSERT(clipboardMode);
2772*/
2773 if (strcmp(clipboard, "disabled") == 0)
2774 {
2775 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Disabled));
2776 }
2777 else if (strcmp(clipboard, "hosttoguest") == 0)
2778 {
2779 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_HostToGuest));
2780 }
2781 else if (strcmp(clipboard, "guesttohost") == 0)
2782 {
2783 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_GuestToHost));
2784 }
2785 else if (strcmp(clipboard, "bidirectional") == 0)
2786 {
2787 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Bidirectional));
2788 }
2789 else
2790 {
2791 errorArgument("Invalid -clipboard argument '%s'", clipboard);
2792 rc = E_FAIL;
2793 break;
2794 }
2795 }
2796 /* iterate through all possible NICs */
2797 for (ULONG n = 0; n < NetworkAdapterCount; n ++)
2798 {
2799 ComPtr<INetworkAdapter> nic;
2800 CHECK_ERROR_RET (machine, GetNetworkAdapter (n, nic.asOutParam()), 1);
2801
2802 ASSERT(nic);
2803
2804 /* something about the NIC? */
2805 if (nics[n])
2806 {
2807 if (strcmp(nics[n], "none") == 0)
2808 {
2809 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (FALSE), 1);
2810 }
2811 else if (strcmp(nics[n], "null") == 0)
2812 {
2813 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
2814 CHECK_ERROR_RET(nic, Detach(), 1);
2815 }
2816 else if (strcmp(nics[n], "nat") == 0)
2817 {
2818 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
2819 CHECK_ERROR_RET(nic, AttachToNAT(), 1);
2820 }
2821 else if (strcmp(nics[n], "hostif") == 0)
2822 {
2823 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
2824 CHECK_ERROR_RET(nic, AttachToHostInterface(), 1);
2825 }
2826 else if (strcmp(nics[n], "intnet") == 0)
2827 {
2828 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
2829 CHECK_ERROR_RET(nic, AttachToInternalNetwork(), 1);
2830 }
2831 else
2832 {
2833 errorArgument("Invalid type '%s' specfied for NIC %lu", nics[n], n + 1);
2834 rc = E_FAIL;
2835 break;
2836 }
2837 }
2838
2839 /* something about the NIC type? */
2840 if (nictype[n])
2841 {
2842 if (strcmp(nictype[n], "Am79C970A") == 0)
2843 {
2844 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A), 1);
2845 }
2846 else if (strcmp(nictype[n], "Am79C973") == 0)
2847 {
2848 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973), 1);
2849 }
2850#ifdef VBOX_WITH_E1000
2851 else if (strcmp(nictype[n], "82540EM") == 0)
2852 {
2853 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM), 1);
2854 }
2855 else if (strcmp(nictype[n], "82543GC") == 0)
2856 {
2857 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC), 1);
2858 }
2859#endif
2860 else
2861 {
2862 errorArgument("Invalid NIC type '%s' specified for NIC %lu", nictype[n], n + 1);
2863 rc = E_FAIL;
2864 break;
2865 }
2866 }
2867
2868 /* something about the MAC address? */
2869 if (macs[n])
2870 {
2871 /* generate one? */
2872 if (strcmp(macs[n], "auto") == 0)
2873 {
2874 CHECK_ERROR_RET(nic, COMSETTER(MACAddress)(NULL), 1);
2875 }
2876 else
2877 {
2878 CHECK_ERROR_RET(nic, COMSETTER(MACAddress)(Bstr(macs[n])), 1);
2879 }
2880 }
2881
2882 /* something about the reported link speed? */
2883 if (nicspeed[n])
2884 {
2885 uint32_t u32LineSpeed;
2886
2887 u32LineSpeed = RTStrToUInt32(nicspeed[n]);
2888
2889 if (u32LineSpeed < 1000 || u32LineSpeed > 4000000)
2890 {
2891 errorArgument("Invalid -nicspeed%lu argument '%s'", n + 1, nicspeed[n]);
2892 rc = E_FAIL;
2893 break;
2894 }
2895 CHECK_ERROR_RET(nic, COMSETTER(LineSpeed)(u32LineSpeed), 1);
2896 }
2897
2898 /* the link status flag? */
2899 if (cableconnected[n])
2900 {
2901 if (strcmp(cableconnected[n], "on") == 0)
2902 {
2903 CHECK_ERROR_RET(nic, COMSETTER(CableConnected)(TRUE), 1);
2904 }
2905 else if (strcmp(cableconnected[n], "off") == 0)
2906 {
2907 CHECK_ERROR_RET(nic, COMSETTER(CableConnected)(FALSE), 1);
2908 }
2909 else
2910 {
2911 errorArgument("Invalid -cableconnected%lu argument '%s'", n + 1, cableconnected[n]);
2912 rc = E_FAIL;
2913 break;
2914 }
2915 }
2916
2917 /* the trace flag? */
2918 if (nictrace[n])
2919 {
2920 if (strcmp(nictrace[n], "on") == 0)
2921 {
2922 CHECK_ERROR_RET(nic, COMSETTER(TraceEnabled)(TRUE), 1);
2923 }
2924 else if (strcmp(nictrace[n], "off") == 0)
2925 {
2926 CHECK_ERROR_RET(nic, COMSETTER(TraceEnabled)(FALSE), 1);
2927 }
2928 else
2929 {
2930 errorArgument("Invalid -nictrace%lu argument '%s'", n + 1, nictrace[n]);
2931 rc = E_FAIL;
2932 break;
2933 }
2934 }
2935
2936 /* the tracefile flag? */
2937 if (nictracefile[n])
2938 {
2939 CHECK_ERROR_RET(nic, COMSETTER(TraceFile)(Bstr(nictracefile[n])), 1);
2940 }
2941
2942 /* the host interface device? */
2943 if (hostifdev[n])
2944 {
2945 /* remove it? */
2946 if (strcmp(hostifdev[n], "none") == 0)
2947 {
2948 CHECK_ERROR_RET(nic, COMSETTER(HostInterface)(NULL), 1);
2949 }
2950 else
2951 {
2952 CHECK_ERROR_RET(nic, COMSETTER(HostInterface)(Bstr(hostifdev[n])), 1);
2953 }
2954 }
2955
2956 /* the internal network name? */
2957 if (intnet[n])
2958 {
2959 /* remove it? */
2960 if (strcmp(intnet[n], "none") == 0)
2961 {
2962 CHECK_ERROR_RET(nic, COMSETTER(InternalNetwork)(NULL), 1);
2963 }
2964 else
2965 {
2966 CHECK_ERROR_RET(nic, COMSETTER(InternalNetwork)(Bstr(intnet[n])), 1);
2967 }
2968 }
2969 /* the network of the NAT */
2970 if (natnet[n])
2971 {
2972 CHECK_ERROR_RET(nic, COMSETTER(NATNetwork)(Bstr(natnet[n])), 1);
2973 }
2974#ifdef RT_OS_LINUX
2975 /* the TAP setup application? */
2976 if (tapsetup[n])
2977 {
2978 /* remove it? */
2979 if (strcmp(tapsetup[n], "none") == 0)
2980 {
2981 CHECK_ERROR_RET(nic, COMSETTER(TAPSetupApplication)(NULL), 1);
2982 }
2983 else
2984 {
2985 CHECK_ERROR_RET(nic, COMSETTER(TAPSetupApplication)(Bstr(tapsetup[n])), 1);
2986 }
2987 }
2988
2989 /* the TAP terminate application? */
2990 if (tapterm[n])
2991 {
2992 /* remove it? */
2993 if (strcmp(tapterm[n], "none") == 0)
2994 {
2995 CHECK_ERROR_RET(nic, COMSETTER(TAPTerminateApplication)(NULL), 1);
2996 }
2997 else
2998 {
2999 CHECK_ERROR_RET(nic, COMSETTER(TAPTerminateApplication)(Bstr(tapterm[n])), 1);
3000 }
3001 }
3002#endif /* RT_OS_LINUX */
3003
3004 }
3005 if (FAILED(rc))
3006 break;
3007
3008 /* iterate through all possible serial ports */
3009 for (ULONG n = 0; n < SerialPortCount; n ++)
3010 {
3011 ComPtr<ISerialPort> uart;
3012 CHECK_ERROR_RET (machine, GetSerialPort (n, uart.asOutParam()), 1);
3013
3014 ASSERT(uart);
3015
3016 if (uarts_base[n])
3017 {
3018 if (uarts_base[n] == (ULONG)-1)
3019 {
3020 CHECK_ERROR_RET(uart, COMSETTER(Enabled) (FALSE), 1);
3021 }
3022 else
3023 {
3024 CHECK_ERROR_RET(uart, COMSETTER(IOBase) (uarts_base[n]), 1);
3025 CHECK_ERROR_RET(uart, COMSETTER(IRQ) (uarts_irq[n]), 1);
3026 CHECK_ERROR_RET(uart, COMSETTER(Enabled) (TRUE), 1);
3027 }
3028 }
3029 if (uarts_mode[n])
3030 {
3031 if (strcmp(uarts_mode[n], "disconnected") == 0)
3032 {
3033 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_Disconnected), 1);
3034 }
3035 else
3036 {
3037 CHECK_ERROR_RET(uart, COMSETTER(Path) (Bstr(uarts_path[n])), 1);
3038 if (strcmp(uarts_mode[n], "server") == 0)
3039 {
3040 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostPipe), 1);
3041 CHECK_ERROR_RET(uart, COMSETTER(Server) (TRUE), 1);
3042 }
3043 else if (strcmp(uarts_mode[n], "client") == 0)
3044 {
3045 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostPipe), 1);
3046 CHECK_ERROR_RET(uart, COMSETTER(Server) (FALSE), 1);
3047 }
3048 else
3049 {
3050 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostDevice), 1);
3051 }
3052 }
3053 }
3054 }
3055 if (FAILED(rc))
3056 break;
3057
3058#ifdef VBOX_WITH_VRDP
3059 if (vrdp || (vrdpport != UINT16_MAX) || vrdpaddress || vrdpauthtype || vrdpmulticon || vrdpreusecon)
3060 {
3061 ComPtr<IVRDPServer> vrdpServer;
3062 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
3063 ASSERT(vrdpServer);
3064 if (vrdpServer)
3065 {
3066 if (vrdp)
3067 {
3068 if (strcmp(vrdp, "on") == 0)
3069 {
3070 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(true));
3071 }
3072 else if (strcmp(vrdp, "off") == 0)
3073 {
3074 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(false));
3075 }
3076 else
3077 {
3078 errorArgument("Invalid -vrdp argument '%s'", vrdp);
3079 rc = E_FAIL;
3080 break;
3081 }
3082 }
3083 if (vrdpport != UINT16_MAX)
3084 {
3085 CHECK_ERROR(vrdpServer, COMSETTER(Port)(vrdpport));
3086 }
3087 if (vrdpaddress)
3088 {
3089 CHECK_ERROR(vrdpServer, COMSETTER(NetAddress)(Bstr(vrdpaddress)));
3090 }
3091 if (vrdpauthtype)
3092 {
3093 if (strcmp(vrdpauthtype, "null") == 0)
3094 {
3095 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Null));
3096 }
3097 else if (strcmp(vrdpauthtype, "external") == 0)
3098 {
3099 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_External));
3100 }
3101 else if (strcmp(vrdpauthtype, "guest") == 0)
3102 {
3103 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Guest));
3104 }
3105 else
3106 {
3107 errorArgument("Invalid -vrdpauthtype argument '%s'", vrdpauthtype);
3108 rc = E_FAIL;
3109 break;
3110 }
3111 }
3112 if (vrdpmulticon)
3113 {
3114 if (strcmp(vrdpmulticon, "on") == 0)
3115 {
3116 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(true));
3117 }
3118 else if (strcmp(vrdpmulticon, "off") == 0)
3119 {
3120 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(false));
3121 }
3122 else
3123 {
3124 errorArgument("Invalid -vrdpmulticon argument '%s'", vrdpmulticon);
3125 rc = E_FAIL;
3126 break;
3127 }
3128 }
3129 if (vrdpreusecon)
3130 {
3131 if (strcmp(vrdpreusecon, "on") == 0)
3132 {
3133 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(true));
3134 }
3135 else if (strcmp(vrdpreusecon, "off") == 0)
3136 {
3137 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(false));
3138 }
3139 else
3140 {
3141 errorArgument("Invalid -vrdpreusecon argument '%s'", vrdpreusecon);
3142 rc = E_FAIL;
3143 break;
3144 }
3145 }
3146 }
3147 }
3148#endif /* VBOX_WITH_VRDP */
3149
3150 /*
3151 * USB enable/disable
3152 */
3153 if (fUsbEnabled != -1)
3154 {
3155 ComPtr<IUSBController> UsbCtl;
3156 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
3157 if (SUCCEEDED(rc))
3158 {
3159 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(!!fUsbEnabled));
3160 }
3161 }
3162 /*
3163 * USB EHCI enable/disable
3164 */
3165 if (fUsbEhciEnabled != -1)
3166 {
3167 ComPtr<IUSBController> UsbCtl;
3168 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
3169 if (SUCCEEDED(rc))
3170 {
3171 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEhci)(!!fUsbEhciEnabled));
3172 }
3173 }
3174
3175 if (snapshotFolder)
3176 {
3177 if (strcmp(snapshotFolder, "default") == 0)
3178 {
3179 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(NULL));
3180 }
3181 else
3182 {
3183 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(snapshotFolder)));
3184 }
3185 }
3186
3187 if (guestMemBalloonSize != (ULONG)-1)
3188 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(guestMemBalloonSize));
3189
3190 if (guestStatInterval != (ULONG)-1)
3191 CHECK_ERROR(machine, COMSETTER(StatisticsUpdateInterval)(guestStatInterval));
3192
3193 /*
3194 * SATA controller enable/disable
3195 */
3196 if (fSataEnabled != -1)
3197 {
3198 ComPtr<ISATAController> SataCtl;
3199 CHECK_ERROR(machine, COMGETTER(SATAController)(SataCtl.asOutParam()));
3200 if (SUCCEEDED(rc))
3201 {
3202 CHECK_ERROR(SataCtl, COMSETTER(Enabled)(!!fSataEnabled));
3203 }
3204 }
3205
3206 for (uint32_t i = 4; i < 34; i++)
3207 {
3208 if (hdds[i])
3209 {
3210 if (strcmp(hdds[i], "none") == 0)
3211 {
3212 machine->DetachHardDisk2(StorageBus_SATA, i-4, 0);
3213 }
3214 else
3215 {
3216 /* first guess is that it's a UUID */
3217 Guid uuid(hdds[i]);
3218 ComPtr<IHardDisk2> hardDisk;
3219 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
3220 /* not successful? Then it must be a filename */
3221 if (!hardDisk)
3222 {
3223 CHECK_ERROR(virtualBox, FindHardDisk2(Bstr(hdds[i]), hardDisk.asOutParam()));
3224 if (FAILED(rc))
3225 {
3226 /* open the new hard disk object */
3227 CHECK_ERROR(virtualBox, OpenHardDisk2(Bstr(hdds[i]), hardDisk.asOutParam()));
3228 }
3229 }
3230 if (hardDisk)
3231 {
3232 hardDisk->COMGETTER(Id)(uuid.asOutParam());
3233 CHECK_ERROR(machine, AttachHardDisk2(uuid, StorageBus_SATA, i-4, 0));
3234 }
3235 else
3236 rc = E_FAIL;
3237 if (FAILED(rc))
3238 break;
3239 }
3240 }
3241 }
3242
3243 for (uint32_t i = 0; i < 4; i++)
3244 {
3245 if (sataBootDevices[i] != -1)
3246 {
3247 ComPtr<ISATAController> SataCtl;
3248 CHECK_ERROR(machine, COMGETTER(SATAController)(SataCtl.asOutParam()));
3249 if (SUCCEEDED(rc))
3250 {
3251 CHECK_ERROR(SataCtl, SetIDEEmulationPort(i, sataBootDevices[i]));
3252 }
3253 }
3254 }
3255
3256 if (sataPortCount != -1)
3257 {
3258 ComPtr<ISATAController> SataCtl;
3259 CHECK_ERROR(machine, COMGETTER(SATAController)(SataCtl.asOutParam()));
3260 if (SUCCEEDED(rc))
3261 {
3262 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(sataPortCount));
3263 }
3264 }
3265
3266 /* commit changes */
3267 CHECK_ERROR(machine, SaveSettings());
3268 }
3269 while (0);
3270
3271 /* it's important to always close sessions */
3272 session->Close();
3273
3274 return SUCCEEDED(rc) ? 0 : 1;
3275}
3276
3277/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
3278#if defined(_MSC_VER)
3279# pragma optimize("", on)
3280#endif
3281
3282static int handleStartVM(int argc, char *argv[],
3283 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
3284{
3285 HRESULT rc;
3286
3287 if (argc < 1)
3288 return errorSyntax(USAGE_STARTVM, "Not enough parameters");
3289
3290 ComPtr<IMachine> machine;
3291 /* assume it's a UUID */
3292 rc = virtualBox->GetMachine(Guid(argv[0]), machine.asOutParam());
3293 if (FAILED(rc) || !machine)
3294 {
3295 /* must be a name */
3296 CHECK_ERROR(virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
3297 }
3298 if (machine)
3299 {
3300 Guid uuid;
3301 machine->COMGETTER(Id)(uuid.asOutParam());
3302
3303 /* default to GUI session type */
3304 Bstr sessionType = "gui";
3305 /* has a session type been specified? */
3306 if ((argc > 2) && (strcmp(argv[1], "-type") == 0))
3307 {
3308 if (strcmp(argv[2], "gui") == 0)
3309 {
3310 sessionType = "gui";
3311 }
3312 else if (strcmp(argv[2], "vrdp") == 0)
3313 {
3314 sessionType = "vrdp";
3315 }
3316 else if (strcmp(argv[2], "capture") == 0)
3317 {
3318 sessionType = "capture";
3319 }
3320 else
3321 return errorArgument("Invalid session type argument '%s'", argv[2]);
3322 }
3323
3324 Bstr env;
3325#ifdef RT_OS_LINUX
3326 /* make sure the VM process will start on the same display as VBoxManage */
3327 {
3328 const char *display = RTEnvGet ("DISPLAY");
3329 if (display)
3330 env = Utf8StrFmt ("DISPLAY=%s", display);
3331 }
3332#endif
3333 ComPtr<IProgress> progress;
3334 CHECK_ERROR_RET(virtualBox, OpenRemoteSession(session, uuid, sessionType,
3335 env, progress.asOutParam()), rc);
3336 RTPrintf("Waiting for the remote session to open...\n");
3337 CHECK_ERROR_RET(progress, WaitForCompletion (-1), 1);
3338
3339 BOOL completed;
3340 CHECK_ERROR_RET(progress, COMGETTER(Completed)(&completed), rc);
3341 ASSERT(completed);
3342
3343 HRESULT resultCode;
3344 CHECK_ERROR_RET(progress, COMGETTER(ResultCode)(&resultCode), rc);
3345 if (FAILED(resultCode))
3346 {
3347 ComPtr <IVirtualBoxErrorInfo> errorInfo;
3348 CHECK_ERROR_RET(progress, COMGETTER(ErrorInfo)(errorInfo.asOutParam()), 1);
3349 ErrorInfo info (errorInfo);
3350 PRINT_ERROR_INFO(info);
3351 }
3352 else
3353 {
3354 RTPrintf("Remote session has been successfully opened.\n");
3355 }
3356 }
3357
3358 /* it's important to always close sessions */
3359 session->Close();
3360
3361 return SUCCEEDED(rc) ? 0 : 1;
3362}
3363
3364static int handleControlVM(int argc, char *argv[],
3365 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
3366{
3367 HRESULT rc;
3368
3369 if (argc < 2)
3370 return errorSyntax(USAGE_CONTROLVM, "Not enough parameters");
3371
3372 /* try to find the given machine */
3373 ComPtr <IMachine> machine;
3374 Guid uuid (argv[0]);
3375 if (!uuid.isEmpty())
3376 {
3377 CHECK_ERROR (virtualBox, GetMachine (uuid, machine.asOutParam()));
3378 }
3379 else
3380 {
3381 CHECK_ERROR (virtualBox, FindMachine (Bstr(argv[0]), machine.asOutParam()));
3382 if (SUCCEEDED (rc))
3383 machine->COMGETTER(Id) (uuid.asOutParam());
3384 }
3385 if (FAILED (rc))
3386 return 1;
3387
3388 /* open a session for the VM */
3389 CHECK_ERROR_RET (virtualBox, OpenExistingSession (session, uuid), 1);
3390
3391 do
3392 {
3393 /* get the associated console */
3394 ComPtr<IConsole> console;
3395 CHECK_ERROR_BREAK (session, COMGETTER(Console)(console.asOutParam()));
3396 /* ... and session machine */
3397 ComPtr<IMachine> sessionMachine;
3398 CHECK_ERROR_BREAK (session, COMGETTER(Machine)(sessionMachine.asOutParam()));
3399
3400 /* which command? */
3401 if (strcmp(argv[1], "pause") == 0)
3402 {
3403 CHECK_ERROR_BREAK (console, Pause());
3404 }
3405 else if (strcmp(argv[1], "resume") == 0)
3406 {
3407 CHECK_ERROR_BREAK (console, Resume());
3408 }
3409 else if (strcmp(argv[1], "reset") == 0)
3410 {
3411 CHECK_ERROR_BREAK (console, Reset());
3412 }
3413 else if (strcmp(argv[1], "poweroff") == 0)
3414 {
3415 CHECK_ERROR_BREAK (console, PowerDown());
3416 }
3417 else if (strcmp(argv[1], "savestate") == 0)
3418 {
3419 ComPtr<IProgress> progress;
3420 CHECK_ERROR_BREAK (console, SaveState(progress.asOutParam()));
3421
3422 showProgress(progress);
3423
3424 progress->COMGETTER(ResultCode)(&rc);
3425 if (FAILED(rc))
3426 {
3427 com::ProgressErrorInfo info(progress);
3428 if (info.isBasicAvailable())
3429 {
3430 RTPrintf("Error: failed to save machine state. Error message: %lS\n", info.getText().raw());
3431 }
3432 else
3433 {
3434 RTPrintf("Error: failed to save machine state. No error message available!\n");
3435 }
3436 }
3437 }
3438 else if (strcmp(argv[1], "acpipowerbutton") == 0)
3439 {
3440 CHECK_ERROR_BREAK (console, PowerButton());
3441 }
3442 else if (strcmp(argv[1], "acpisleepbutton") == 0)
3443 {
3444 CHECK_ERROR_BREAK (console, SleepButton());
3445 }
3446 else if (strcmp(argv[1], "injectnmi") == 0)
3447 {
3448 /* get the machine debugger. */
3449 ComPtr <IMachineDebugger> debugger;
3450 CHECK_ERROR_BREAK(console, COMGETTER(Debugger)(debugger.asOutParam()));
3451 CHECK_ERROR_BREAK(debugger, InjectNMI());
3452 }
3453 else if (strcmp(argv[1], "keyboardputscancode") == 0)
3454 {
3455 ComPtr<IKeyboard> keyboard;
3456 CHECK_ERROR_BREAK(console, COMGETTER(Keyboard)(keyboard.asOutParam()));
3457
3458 if (argc <= 1 + 1)
3459 {
3460 errorArgument("Missing argument to '%s'. Expected IBM PC AT set 2 keyboard scancode(s) as hex byte(s).", argv[1]);
3461 rc = E_FAIL;
3462 break;
3463 }
3464
3465 /* Arbitrary restrict the length of a sequence of scancodes to 1024. */
3466 LONG alScancodes[1024];
3467 int cScancodes = 0;
3468
3469 /* Process the command line. */
3470 int i;
3471 for (i = 1 + 1; i < argc && cScancodes < (int)RT_ELEMENTS(alScancodes); i++, cScancodes++)
3472 {
3473 if ( RT_C_IS_XDIGIT (argv[i][0])
3474 && RT_C_IS_XDIGIT (argv[i][1])
3475 && argv[i][2] == 0)
3476 {
3477 uint8_t u8Scancode;
3478 int rc = RTStrToUInt8Ex(argv[i], NULL, 16, &u8Scancode);
3479 if (RT_FAILURE (rc))
3480 {
3481 RTPrintf("Error: converting '%s' returned %Rrc!\n", argv[i], rc);
3482 rc = E_FAIL;
3483 break;
3484 }
3485
3486 alScancodes[cScancodes] = u8Scancode;
3487 }
3488 else
3489 {
3490 RTPrintf("Error: '%s' is not a hex byte!\n", argv[i]);
3491 rc = E_FAIL;
3492 break;
3493 }
3494 }
3495
3496 if (FAILED(rc))
3497 break;
3498
3499 if ( cScancodes == RT_ELEMENTS(alScancodes)
3500 && i < argc)
3501 {
3502 RTPrintf("Error: too many scancodes, maximum %d allowed!\n", RT_ELEMENTS(alScancodes));
3503 rc = E_FAIL;
3504 break;
3505 }
3506
3507 /* Send scancodes to the VM.
3508 * Note: 'PutScancodes' did not work here. Only the first scancode was transmitted.
3509 */
3510 for (i = 0; i < cScancodes; i++)
3511 {
3512 CHECK_ERROR_BREAK(keyboard, PutScancode(alScancodes[i]));
3513 RTPrintf("Scancode[%d]: 0x%02X\n", i, alScancodes[i]);
3514 }
3515 }
3516 else if (strncmp(argv[1], "setlinkstate", 12) == 0)
3517 {
3518 /* Get the number of network adapters */
3519 ULONG NetworkAdapterCount = 0;
3520 ComPtr <ISystemProperties> info;
3521 CHECK_ERROR_BREAK (virtualBox, COMGETTER(SystemProperties) (info.asOutParam()));
3522 CHECK_ERROR_BREAK (info, COMGETTER(NetworkAdapterCount) (&NetworkAdapterCount));
3523
3524 unsigned n = parseNum(&argv[1][12], NetworkAdapterCount, "NIC");
3525 if (!n)
3526 {
3527 rc = E_FAIL;
3528 break;
3529 }
3530 if (argc <= 1 + 1)
3531 {
3532 errorArgument("Missing argument to '%s'", argv[1]);
3533 rc = E_FAIL;
3534 break;
3535 }
3536 /* get the corresponding network adapter */
3537 ComPtr<INetworkAdapter> adapter;
3538 CHECK_ERROR_BREAK (sessionMachine, GetNetworkAdapter(n - 1, adapter.asOutParam()));
3539 if (adapter)
3540 {
3541 if (strcmp(argv[2], "on") == 0)
3542 {
3543 CHECK_ERROR_BREAK (adapter, COMSETTER(CableConnected)(TRUE));
3544 }
3545 else if (strcmp(argv[2], "off") == 0)
3546 {
3547 CHECK_ERROR_BREAK (adapter, COMSETTER(CableConnected)(FALSE));
3548 }
3549 else
3550 {
3551 errorArgument("Invalid link state '%s'", Utf8Str(argv[2]).raw());
3552 rc = E_FAIL;
3553 break;
3554 }
3555 }
3556 }
3557 else if (strcmp (argv[1], "usbattach") == 0 ||
3558 strcmp (argv[1], "usbdetach") == 0)
3559 {
3560 if (argc < 3)
3561 {
3562 errorSyntax(USAGE_CONTROLVM, "Not enough parameters");
3563 rc = E_FAIL;
3564 break;
3565 }
3566
3567 bool attach = strcmp (argv[1], "usbattach") == 0;
3568
3569 Guid usbId = argv [2];
3570 if (usbId.isEmpty())
3571 {
3572 // assume address
3573 if (attach)
3574 {
3575 ComPtr <IHost> host;
3576 CHECK_ERROR_BREAK (virtualBox, COMGETTER(Host) (host.asOutParam()));
3577 ComPtr <IHostUSBDeviceCollection> coll;
3578 CHECK_ERROR_BREAK (host, COMGETTER(USBDevices) (coll.asOutParam()));
3579 ComPtr <IHostUSBDevice> dev;
3580 CHECK_ERROR_BREAK (coll, FindByAddress (Bstr (argv [2]), dev.asOutParam()));
3581 CHECK_ERROR_BREAK (dev, COMGETTER(Id) (usbId.asOutParam()));
3582 }
3583 else
3584 {
3585 ComPtr <IUSBDeviceCollection> coll;
3586 CHECK_ERROR_BREAK (console, COMGETTER(USBDevices)(coll.asOutParam()));
3587 ComPtr <IUSBDevice> dev;
3588 CHECK_ERROR_BREAK (coll, FindByAddress (Bstr (argv [2]), dev.asOutParam()));
3589 CHECK_ERROR_BREAK (dev, COMGETTER(Id) (usbId.asOutParam()));
3590 }
3591 }
3592
3593 if (attach)
3594 CHECK_ERROR_BREAK (console, AttachUSBDevice (usbId));
3595 else
3596 {
3597 ComPtr <IUSBDevice> dev;
3598 CHECK_ERROR_BREAK (console, DetachUSBDevice (usbId, dev.asOutParam()));
3599 }
3600 }
3601 else if (strcmp(argv[1], "setvideomodehint") == 0)
3602 {
3603 if (argc != 5 && argc != 6)
3604 {
3605 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
3606 rc = E_FAIL;
3607 break;
3608 }
3609 uint32_t xres = RTStrToUInt32(argv[2]);
3610 uint32_t yres = RTStrToUInt32(argv[3]);
3611 uint32_t bpp = RTStrToUInt32(argv[4]);
3612 uint32_t displayIdx = 0;
3613 if (argc == 6)
3614 displayIdx = RTStrToUInt32(argv[5]);
3615
3616 ComPtr<IDisplay> display;
3617 CHECK_ERROR_BREAK(console, COMGETTER(Display)(display.asOutParam()));
3618 CHECK_ERROR_BREAK(display, SetVideoModeHint(xres, yres, bpp, displayIdx));
3619 }
3620 else if (strcmp(argv[1], "setcredentials") == 0)
3621 {
3622 bool fAllowLocalLogon = true;
3623 if (argc == 7)
3624 {
3625 if (strcmp(argv[5], "-allowlocallogon") != 0)
3626 {
3627 errorArgument("Invalid parameter '%s'", argv[5]);
3628 rc = E_FAIL;
3629 break;
3630 }
3631 if (strcmp(argv[6], "no") == 0)
3632 fAllowLocalLogon = false;
3633 }
3634 else if (argc != 5)
3635 {
3636 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
3637 rc = E_FAIL;
3638 break;
3639 }
3640
3641 ComPtr<IGuest> guest;
3642 CHECK_ERROR_BREAK(console, COMGETTER(Guest)(guest.asOutParam()));
3643 CHECK_ERROR_BREAK(guest, SetCredentials(Bstr(argv[2]), Bstr(argv[3]), Bstr(argv[4]), fAllowLocalLogon));
3644 }
3645 else if (strcmp(argv[1], "dvdattach") == 0)
3646 {
3647 if (argc != 3)
3648 {
3649 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
3650 rc = E_FAIL;
3651 break;
3652 }
3653 ComPtr<IDVDDrive> dvdDrive;
3654 sessionMachine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
3655 ASSERT(dvdDrive);
3656
3657 /* unmount? */
3658 if (strcmp(argv[2], "none") == 0)
3659 {
3660 CHECK_ERROR(dvdDrive, Unmount());
3661 }
3662 /* host drive? */
3663 else if (strncmp(argv[2], "host:", 5) == 0)
3664 {
3665 ComPtr<IHost> host;
3666 CHECK_ERROR(virtualBox, COMGETTER(Host)(host.asOutParam()));
3667 ComPtr<IHostDVDDriveCollection> hostDVDs;
3668 CHECK_ERROR(host, COMGETTER(DVDDrives)(hostDVDs.asOutParam()));
3669 ComPtr<IHostDVDDrive> hostDVDDrive;
3670 rc = hostDVDs->FindByName(Bstr(argv[2] + 5), hostDVDDrive.asOutParam());
3671 if (!hostDVDDrive)
3672 {
3673 errorArgument("Invalid host DVD drive name");
3674 rc = E_FAIL;
3675 break;
3676 }
3677 CHECK_ERROR(dvdDrive, CaptureHostDrive(hostDVDDrive));
3678 }
3679 else
3680 {
3681 /* first assume it's a UUID */
3682 Guid uuid(argv[2]);
3683 ComPtr<IDVDImage2> dvdImage;
3684 rc = virtualBox->GetDVDImage(uuid, dvdImage.asOutParam());
3685 if (FAILED(rc) || !dvdImage)
3686 {
3687 /* must be a filename, check if it's in the collection */
3688 rc = virtualBox->FindDVDImage(Bstr(argv[2]), dvdImage.asOutParam());
3689 /* not registered, do that on the fly */
3690 if (!dvdImage)
3691 {
3692 Guid emptyUUID;
3693 CHECK_ERROR(virtualBox, OpenDVDImage(Bstr(argv[2]), emptyUUID, dvdImage.asOutParam()));
3694 }
3695 }
3696 if (!dvdImage)
3697 {
3698 rc = E_FAIL;
3699 break;
3700 }
3701 dvdImage->COMGETTER(Id)(uuid.asOutParam());
3702 CHECK_ERROR(dvdDrive, MountImage(uuid));
3703 }
3704 }
3705 else if (strcmp(argv[1], "floppyattach") == 0)
3706 {
3707 if (argc != 3)
3708 {
3709 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
3710 rc = E_FAIL;
3711 break;
3712 }
3713
3714 ComPtr<IFloppyDrive> floppyDrive;
3715 sessionMachine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
3716 ASSERT(floppyDrive);
3717
3718 /* unmount? */
3719 if (strcmp(argv[2], "none") == 0)
3720 {
3721 CHECK_ERROR(floppyDrive, Unmount());
3722 }
3723 /* host drive? */
3724 else if (strncmp(argv[2], "host:", 5) == 0)
3725 {
3726 ComPtr<IHost> host;
3727 CHECK_ERROR(virtualBox, COMGETTER(Host)(host.asOutParam()));
3728 ComPtr<IHostFloppyDriveCollection> hostFloppies;
3729 CHECK_ERROR(host, COMGETTER(FloppyDrives)(hostFloppies.asOutParam()));
3730 ComPtr<IHostFloppyDrive> hostFloppyDrive;
3731 rc = hostFloppies->FindByName(Bstr(argv[2] + 5), hostFloppyDrive.asOutParam());
3732 if (!hostFloppyDrive)
3733 {
3734 errorArgument("Invalid host floppy drive name");
3735 rc = E_FAIL;
3736 break;
3737 }
3738 CHECK_ERROR(floppyDrive, CaptureHostDrive(hostFloppyDrive));
3739 }
3740 else
3741 {
3742 /* first assume it's a UUID */
3743 Guid uuid(argv[2]);
3744 ComPtr<IFloppyImage2> floppyImage;
3745 rc = virtualBox->GetFloppyImage(uuid, floppyImage.asOutParam());
3746 if (FAILED(rc) || !floppyImage)
3747 {
3748 /* must be a filename, check if it's in the collection */
3749 rc = virtualBox->FindFloppyImage(Bstr(argv[2]), floppyImage.asOutParam());
3750 /* not registered, do that on the fly */
3751 if (!floppyImage)
3752 {
3753 Guid emptyUUID;
3754 CHECK_ERROR(virtualBox, OpenFloppyImage(Bstr(argv[2]), emptyUUID, floppyImage.asOutParam()));
3755 }
3756 }
3757 if (!floppyImage)
3758 {
3759 rc = E_FAIL;
3760 break;
3761 }
3762 floppyImage->COMGETTER(Id)(uuid.asOutParam());
3763 CHECK_ERROR(floppyDrive, MountImage(uuid));
3764 }
3765 }
3766#ifdef VBOX_WITH_MEM_BALLOONING
3767 else if (strncmp(argv[1], "-guestmemoryballoon", 19) == 0)
3768 {
3769 if (argc != 3)
3770 {
3771 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
3772 rc = E_FAIL;
3773 break;
3774 }
3775 uint32_t uVal;
3776 int vrc;
3777 vrc = RTStrToUInt32Ex(argv[2], NULL, 0, &uVal);
3778 if (vrc != VINF_SUCCESS)
3779 {
3780 errorArgument("Error parsing guest memory balloon size '%s'", argv[2]);
3781 rc = E_FAIL;
3782 break;
3783 }
3784
3785 /* guest is running; update IGuest */
3786 ComPtr <IGuest> guest;
3787
3788 rc = console->COMGETTER(Guest)(guest.asOutParam());
3789 if (SUCCEEDED(rc))
3790 CHECK_ERROR(guest, COMSETTER(MemoryBalloonSize)(uVal));
3791 }
3792#endif
3793 else if (strncmp(argv[1], "-gueststatisticsinterval", 24) == 0)
3794 {
3795 if (argc != 3)
3796 {
3797 errorSyntax(USAGE_CONTROLVM, "Incorrect number of parameters");
3798 rc = E_FAIL;
3799 break;
3800 }
3801 uint32_t uVal;
3802 int vrc;
3803 vrc = RTStrToUInt32Ex(argv[2], NULL, 0, &uVal);
3804 if (vrc != VINF_SUCCESS)
3805 {
3806 errorArgument("Error parsing guest statistics interval '%s'", argv[2]);
3807 rc = E_FAIL;
3808 break;
3809 }
3810
3811 /* guest is running; update IGuest */
3812 ComPtr <IGuest> guest;
3813
3814 rc = console->COMGETTER(Guest)(guest.asOutParam());
3815 if (SUCCEEDED(rc))
3816 CHECK_ERROR(guest, COMSETTER(StatisticsUpdateInterval)(uVal));
3817 }
3818 else
3819 {
3820 errorSyntax(USAGE_CONTROLVM, "Invalid parameter '%s'", Utf8Str(argv[1]).raw());
3821 rc = E_FAIL;
3822 }
3823 }
3824 while (0);
3825
3826 session->Close();
3827
3828 return SUCCEEDED (rc) ? 0 : 1;
3829}
3830
3831static int handleDiscardState(int argc, char *argv[],
3832 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
3833{
3834 HRESULT rc;
3835
3836 if (argc != 1)
3837 return errorSyntax(USAGE_DISCARDSTATE, "Incorrect number of parameters");
3838
3839 ComPtr<IMachine> machine;
3840 /* assume it's a UUID */
3841 rc = virtualBox->GetMachine(Guid(argv[0]), machine.asOutParam());
3842 if (FAILED(rc) || !machine)
3843 {
3844 /* must be a name */
3845 CHECK_ERROR(virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
3846 }
3847 if (machine)
3848 {
3849 do
3850 {
3851 /* we have to open a session for this task */
3852 Guid guid;
3853 machine->COMGETTER(Id)(guid.asOutParam());
3854 CHECK_ERROR_BREAK(virtualBox, OpenSession(session, guid));
3855 do
3856 {
3857 ComPtr<IConsole> console;
3858 CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
3859 CHECK_ERROR_BREAK(console, DiscardSavedState());
3860 }
3861 while (0);
3862 CHECK_ERROR_BREAK(session, Close());
3863 }
3864 while (0);
3865 }
3866
3867 return SUCCEEDED(rc) ? 0 : 1;
3868}
3869
3870static int handleAdoptdState(int argc, char *argv[],
3871 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
3872{
3873 HRESULT rc;
3874
3875 if (argc != 2)
3876 return errorSyntax(USAGE_ADOPTSTATE, "Incorrect number of parameters");
3877
3878 ComPtr<IMachine> machine;
3879 /* assume it's a UUID */
3880 rc = virtualBox->GetMachine(Guid(argv[0]), machine.asOutParam());
3881 if (FAILED(rc) || !machine)
3882 {
3883 /* must be a name */
3884 CHECK_ERROR(virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
3885 }
3886 if (machine)
3887 {
3888 do
3889 {
3890 /* we have to open a session for this task */
3891 Guid guid;
3892 machine->COMGETTER(Id)(guid.asOutParam());
3893 CHECK_ERROR_BREAK(virtualBox, OpenSession(session, guid));
3894 do
3895 {
3896 ComPtr<IConsole> console;
3897 CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
3898 CHECK_ERROR_BREAK(console, AdoptSavedState (Bstr (argv[1])));
3899 }
3900 while (0);
3901 CHECK_ERROR_BREAK(session, Close());
3902 }
3903 while (0);
3904 }
3905
3906 return SUCCEEDED(rc) ? 0 : 1;
3907}
3908
3909static int handleSnapshot(int argc, char *argv[],
3910 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
3911{
3912 HRESULT rc;
3913
3914 /* we need at least a VM and a command */
3915 if (argc < 2)
3916 return errorSyntax(USAGE_SNAPSHOT, "Not enough parameters");
3917
3918 /* the first argument must be the VM */
3919 ComPtr<IMachine> machine;
3920 /* assume it's a UUID */
3921 rc = virtualBox->GetMachine(Guid(argv[0]), machine.asOutParam());
3922 if (FAILED(rc) || !machine)
3923 {
3924 /* must be a name */
3925 CHECK_ERROR(virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
3926 }
3927 if (!machine)
3928 return 1;
3929 Guid guid;
3930 machine->COMGETTER(Id)(guid.asOutParam());
3931
3932 do
3933 {
3934 /* we have to open a session for this task. First try an existing session */
3935 rc = virtualBox->OpenExistingSession(session, guid);
3936 if (FAILED(rc))
3937 CHECK_ERROR_BREAK(virtualBox, OpenSession(session, guid));
3938 ComPtr<IConsole> console;
3939 CHECK_ERROR_BREAK(session, COMGETTER(Console)(console.asOutParam()));
3940
3941 /* switch based on the command */
3942 if (strcmp(argv[1], "take") == 0)
3943 {
3944 /* there must be a name */
3945 if (argc < 3)
3946 {
3947 errorSyntax(USAGE_SNAPSHOT, "Missing snapshot name");
3948 rc = E_FAIL;
3949 break;
3950 }
3951 Bstr name(argv[2]);
3952 if ((argc > 3) && ((argc != 5) || (strcmp(argv[3], "-desc") != 0)))
3953 {
3954 errorSyntax(USAGE_SNAPSHOT, "Incorrect description format");
3955 rc = E_FAIL;
3956 break;
3957 }
3958 Bstr desc;
3959 if (argc == 5)
3960 desc = argv[4];
3961 ComPtr<IProgress> progress;
3962 CHECK_ERROR_BREAK(console, TakeSnapshot(name, desc, progress.asOutParam()));
3963
3964 showProgress(progress);
3965 progress->COMGETTER(ResultCode)(&rc);
3966 if (FAILED(rc))
3967 {
3968 com::ProgressErrorInfo info(progress);
3969 if (info.isBasicAvailable())
3970 RTPrintf("Error: failed to take snapshot. Error message: %lS\n", info.getText().raw());
3971 else
3972 RTPrintf("Error: failed to take snapshot. No error message available!\n");
3973 }
3974 }
3975 else if (strcmp(argv[1], "discard") == 0)
3976 {
3977 /* exactly one parameter: snapshot name */
3978 if (argc != 3)
3979 {
3980 errorSyntax(USAGE_SNAPSHOT, "Expecting snapshot name only");
3981 rc = E_FAIL;
3982 break;
3983 }
3984
3985 ComPtr<ISnapshot> snapshot;
3986
3987 /* assume it's a UUID */
3988 Guid guid(argv[2]);
3989 if (!guid.isEmpty())
3990 {
3991 CHECK_ERROR_BREAK(machine, GetSnapshot(guid, snapshot.asOutParam()));
3992 }
3993 else
3994 {
3995 /* then it must be a name */
3996 CHECK_ERROR_BREAK(machine, FindSnapshot(Bstr(argv[2]), snapshot.asOutParam()));
3997 }
3998
3999 snapshot->COMGETTER(Id)(guid.asOutParam());
4000
4001 ComPtr<IProgress> progress;
4002 CHECK_ERROR_BREAK(console, DiscardSnapshot(guid, progress.asOutParam()));
4003
4004 showProgress(progress);
4005 progress->COMGETTER(ResultCode)(&rc);
4006 if (FAILED(rc))
4007 {
4008 com::ProgressErrorInfo info(progress);
4009 if (info.isBasicAvailable())
4010 RTPrintf("Error: failed to discard snapshot. Error message: %lS\n", info.getText().raw());
4011 else
4012 RTPrintf("Error: failed to discard snapshot. No error message available!\n");
4013 }
4014 }
4015 else if (strcmp(argv[1], "discardcurrent") == 0)
4016 {
4017 if ( (argc != 3)
4018 || ( (strcmp(argv[2], "-state") != 0)
4019 && (strcmp(argv[2], "-all") != 0)))
4020 {
4021 errorSyntax(USAGE_SNAPSHOT, "Invalid parameter '%s'", Utf8Str(argv[2]).raw());
4022 rc = E_FAIL;
4023 break;
4024 }
4025 bool fAll = false;
4026 if (strcmp(argv[2], "-all") == 0)
4027 fAll = true;
4028
4029 ComPtr<IProgress> progress;
4030
4031 if (fAll)
4032 {
4033 CHECK_ERROR_BREAK(console, DiscardCurrentSnapshotAndState(progress.asOutParam()));
4034 }
4035 else
4036 {
4037 CHECK_ERROR_BREAK(console, DiscardCurrentState(progress.asOutParam()));
4038 }
4039
4040 showProgress(progress);
4041 progress->COMGETTER(ResultCode)(&rc);
4042 if (FAILED(rc))
4043 {
4044 com::ProgressErrorInfo info(progress);
4045 if (info.isBasicAvailable())
4046 RTPrintf("Error: failed to discard. Error message: %lS\n", info.getText().raw());
4047 else
4048 RTPrintf("Error: failed to discard. No error message available!\n");
4049 }
4050
4051 }
4052 else if (strcmp(argv[1], "edit") == 0)
4053 {
4054 if (argc < 3)
4055 {
4056 errorSyntax(USAGE_SNAPSHOT, "Missing snapshot name");
4057 rc = E_FAIL;
4058 break;
4059 }
4060
4061 ComPtr<ISnapshot> snapshot;
4062
4063 if (strcmp(argv[2], "-current") == 0)
4064 {
4065 CHECK_ERROR_BREAK(machine, COMGETTER(CurrentSnapshot)(snapshot.asOutParam()));
4066 }
4067 else
4068 {
4069 /* assume it's a UUID */
4070 Guid guid(argv[2]);
4071 if (!guid.isEmpty())
4072 {
4073 CHECK_ERROR_BREAK(machine, GetSnapshot(guid, snapshot.asOutParam()));
4074 }
4075 else
4076 {
4077 /* then it must be a name */
4078 CHECK_ERROR_BREAK(machine, FindSnapshot(Bstr(argv[2]), snapshot.asOutParam()));
4079 }
4080 }
4081
4082 /* parse options */
4083 for (int i = 3; i < argc; i++)
4084 {
4085 if (strcmp(argv[i], "-newname") == 0)
4086 {
4087 if (argc <= i + 1)
4088 {
4089 errorArgument("Missing argument to '%s'", argv[i]);
4090 rc = E_FAIL;
4091 break;
4092 }
4093 i++;
4094 snapshot->COMSETTER(Name)(Bstr(argv[i]));
4095 }
4096 else if (strcmp(argv[i], "-newdesc") == 0)
4097 {
4098 if (argc <= i + 1)
4099 {
4100 errorArgument("Missing argument to '%s'", argv[i]);
4101 rc = E_FAIL;
4102 break;
4103 }
4104 i++;
4105 snapshot->COMSETTER(Description)(Bstr(argv[i]));
4106 }
4107 else
4108 {
4109 errorSyntax(USAGE_SNAPSHOT, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
4110 rc = E_FAIL;
4111 break;
4112 }
4113 }
4114
4115 }
4116 else if (strcmp(argv[1], "showvminfo") == 0)
4117 {
4118 /* exactly one parameter: snapshot name */
4119 if (argc != 3)
4120 {
4121 errorSyntax(USAGE_SNAPSHOT, "Expecting snapshot name only");
4122 rc = E_FAIL;
4123 break;
4124 }
4125
4126 ComPtr<ISnapshot> snapshot;
4127
4128 /* assume it's a UUID */
4129 Guid guid(argv[2]);
4130 if (!guid.isEmpty())
4131 {
4132 CHECK_ERROR_BREAK(machine, GetSnapshot(guid, snapshot.asOutParam()));
4133 }
4134 else
4135 {
4136 /* then it must be a name */
4137 CHECK_ERROR_BREAK(machine, FindSnapshot(Bstr(argv[2]), snapshot.asOutParam()));
4138 }
4139
4140 /* get the machine of the given snapshot */
4141 ComPtr<IMachine> machine;
4142 snapshot->COMGETTER(Machine)(machine.asOutParam());
4143 showVMInfo(virtualBox, machine, console);
4144 }
4145 else
4146 {
4147 errorSyntax(USAGE_SNAPSHOT, "Invalid parameter '%s'", Utf8Str(argv[1]).raw());
4148 rc = E_FAIL;
4149 }
4150 } while (0);
4151
4152 session->Close();
4153
4154 return SUCCEEDED(rc) ? 0 : 1;
4155}
4156
4157static int handleShowHardDiskInfo(int argc, char *argv[],
4158 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4159{
4160 HRESULT rc;
4161
4162 if (argc != 1)
4163 return errorSyntax(USAGE_SHOWHDINFO, "Incorrect number of parameters");
4164
4165 ComPtr<IHardDisk2> hardDisk;
4166 Bstr filepath;
4167
4168 bool unknown = false;
4169
4170 /* first guess is that it's a UUID */
4171 Guid uuid(argv[0]);
4172 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
4173 /* no? then it must be a filename */
4174 if (FAILED (rc))
4175 {
4176 filepath = argv[0];
4177 rc = virtualBox->FindHardDisk2(filepath, hardDisk.asOutParam());
4178 /* no? well, then it's an unkwnown image */
4179 if (FAILED (rc))
4180 {
4181 CHECK_ERROR(virtualBox, OpenHardDisk2(filepath, hardDisk.asOutParam()));
4182 if (SUCCEEDED (rc))
4183 {
4184 unknown = true;
4185 }
4186 }
4187 }
4188 do
4189 {
4190 if (!SUCCEEDED(rc))
4191 break;
4192
4193 hardDisk->COMGETTER(Id)(uuid.asOutParam());
4194 RTPrintf("UUID: %s\n", uuid.toString().raw());
4195
4196 /* check for accessibility */
4197 /// @todo NEWMEDIA check accessibility of all parents
4198 /// @todo NEWMEDIA print the full state value
4199 MediaState_T state;
4200 CHECK_ERROR_BREAK (hardDisk, COMGETTER(State)(&state));
4201 RTPrintf("Accessible: %s\n", state != MediaState_Inaccessible ? "yes" : "no");
4202
4203 if (state == MediaState_Inaccessible)
4204 {
4205 Bstr err;
4206 CHECK_ERROR_BREAK (hardDisk, COMGETTER(LastAccessError)(err.asOutParam()));
4207 RTPrintf("Access Error: %lS\n", err.raw());
4208 }
4209
4210 Bstr description;
4211 hardDisk->COMGETTER(Description)(description.asOutParam());
4212 if (description)
4213 {
4214 RTPrintf("Description: %lS\n", description.raw());
4215 }
4216
4217 ULONG64 logicalSize;
4218 hardDisk->COMGETTER(LogicalSize)(&logicalSize);
4219 RTPrintf("Logical size: %llu MBytes\n", logicalSize);
4220 ULONG64 actualSize;
4221 hardDisk->COMGETTER(Size)(&actualSize);
4222 RTPrintf("Current size on disk: %llu MBytes\n", actualSize >> 20);
4223
4224 HardDiskType_T type;
4225 hardDisk->COMGETTER(Type)(&type);
4226 const char *typeStr = "unknown";
4227 switch (type)
4228 {
4229 case HardDiskType_Normal:
4230 typeStr = "normal";
4231 break;
4232 case HardDiskType_Immutable:
4233 typeStr = "immutable";
4234 break;
4235 case HardDiskType_Writethrough:
4236 typeStr = "writethrough";
4237 break;
4238 }
4239 RTPrintf("Type: %s\n", typeStr);
4240
4241 Bstr format;
4242 hardDisk->COMGETTER(Format)(format.asOutParam());
4243 RTPrintf("Storage format: %lS\n", format.raw());
4244
4245 if (!unknown)
4246 {
4247 com::SafeGUIDArray machineIds;
4248 hardDisk->COMGETTER(MachineIds)(ComSafeArrayAsOutParam(machineIds));
4249 for (size_t j = 0; j < machineIds.size(); ++ j)
4250 {
4251 ComPtr<IMachine> machine;
4252 CHECK_ERROR(virtualBox, GetMachine(machineIds[j], machine.asOutParam()));
4253 ASSERT(machine);
4254 Bstr name;
4255 machine->COMGETTER(Name)(name.asOutParam());
4256 machine->COMGETTER(Id)(uuid.asOutParam());
4257 RTPrintf("%s%lS (UUID: %RTuuid)\n",
4258 j == 0 ? "In use by VMs: " : " ",
4259 name.raw(), &machineIds[j]);
4260 }
4261 /// @todo NEWMEDIA check usage in snapshots too
4262 /// @todo NEWMEDIA also list children and say 'differencing' for
4263 /// hard disks with the parent or 'base' otherwise.
4264 }
4265
4266 Bstr loc;
4267 hardDisk->COMGETTER(Location)(loc.asOutParam());
4268 RTPrintf("Location: %lS\n", loc.raw());
4269 }
4270 while (0);
4271
4272 if (unknown)
4273 {
4274 /* close the unknown hard disk to forget it again */
4275 hardDisk->Close();
4276 }
4277
4278 return SUCCEEDED(rc) ? 0 : 1;
4279}
4280
4281static int handleOpenMedium(int argc, char *argv[],
4282 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4283{
4284 HRESULT rc;
4285
4286 if (argc < 2)
4287 return errorSyntax(USAGE_REGISTERIMAGE, "Not enough parameters");
4288
4289 Bstr filepath(argv[1]);
4290
4291 if (strcmp(argv[0], "disk") == 0)
4292 {
4293 const char *type = NULL;
4294 /* there can be a type parameter */
4295 if ((argc > 2) && (argc != 4))
4296 return errorSyntax(USAGE_REGISTERIMAGE, "Incorrect number of parameters");
4297 if (argc == 4)
4298 {
4299 if (strcmp(argv[2], "-type") != 0)
4300 return errorSyntax(USAGE_REGISTERIMAGE, "Invalid parameter '%s'", Utf8Str(argv[2]).raw());
4301 if ( (strcmp(argv[3], "normal") != 0)
4302 && (strcmp(argv[3], "immutable") != 0)
4303 && (strcmp(argv[3], "writethrough") != 0))
4304 return errorArgument("Invalid hard disk type '%s' specified", Utf8Str(argv[3]).raw());
4305 type = argv[3];
4306 }
4307
4308 ComPtr<IHardDisk2> hardDisk;
4309 CHECK_ERROR(virtualBox, OpenHardDisk2(filepath, hardDisk.asOutParam()));
4310 if (SUCCEEDED(rc) && hardDisk)
4311 {
4312 /* change the type if requested */
4313 if (type)
4314 {
4315 if (strcmp(type, "normal") == 0)
4316 CHECK_ERROR(hardDisk, COMSETTER(Type)(HardDiskType_Normal));
4317 else if (strcmp(type, "immutable") == 0)
4318 CHECK_ERROR(hardDisk, COMSETTER(Type)(HardDiskType_Immutable));
4319 else if (strcmp(type, "writethrough") == 0)
4320 CHECK_ERROR(hardDisk, COMSETTER(Type)(HardDiskType_Writethrough));
4321 }
4322 }
4323 }
4324 else if (strcmp(argv[0], "dvd") == 0)
4325 {
4326 ComPtr<IDVDImage2> dvdImage;
4327 CHECK_ERROR(virtualBox, OpenDVDImage(filepath, Guid(), dvdImage.asOutParam()));
4328 }
4329 else if (strcmp(argv[0], "floppy") == 0)
4330 {
4331 ComPtr<IFloppyImage2> floppyImage;
4332 CHECK_ERROR(virtualBox, OpenFloppyImage(filepath, Guid(), floppyImage.asOutParam()));
4333 }
4334 else
4335 return errorSyntax(USAGE_REGISTERIMAGE, "Invalid parameter '%s'", Utf8Str(argv[1]).raw());
4336
4337 return SUCCEEDED(rc) ? 0 : 1;
4338}
4339
4340static int handleCloseMedium(int argc, char *argv[],
4341 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4342{
4343 HRESULT rc;
4344
4345 if (argc != 2)
4346 return errorSyntax(USAGE_UNREGISTERIMAGE, "Incorrect number of parameters");
4347
4348 /* first guess is that it's a UUID */
4349 Guid uuid(argv[1]);
4350
4351 if (strcmp(argv[0], "disk") == 0)
4352 {
4353 ComPtr<IHardDisk2> hardDisk;
4354 rc = virtualBox->GetHardDisk2(uuid, hardDisk.asOutParam());
4355 /* not a UUID or not registered? Then it must be a filename */
4356 if (!hardDisk)
4357 {
4358 CHECK_ERROR(virtualBox, FindHardDisk2(Bstr(argv[1]), hardDisk.asOutParam()));
4359 }
4360 if (SUCCEEDED(rc) && hardDisk)
4361 {
4362 CHECK_ERROR(hardDisk, Close());
4363 }
4364 }
4365 else
4366 if (strcmp(argv[0], "dvd") == 0)
4367 {
4368 ComPtr<IDVDImage2> dvdImage;
4369 rc = virtualBox->GetDVDImage(uuid, dvdImage.asOutParam());
4370 /* not a UUID or not registered? Then it must be a filename */
4371 if (!dvdImage)
4372 {
4373 CHECK_ERROR(virtualBox, FindDVDImage(Bstr(argv[1]), dvdImage.asOutParam()));
4374 }
4375 if (SUCCEEDED(rc) && dvdImage)
4376 {
4377 CHECK_ERROR(dvdImage, Close());
4378 }
4379 }
4380 else
4381 if (strcmp(argv[0], "floppy") == 0)
4382 {
4383 ComPtr<IFloppyImage2> floppyImage;
4384 rc = virtualBox->GetFloppyImage(uuid, floppyImage.asOutParam());
4385 /* not a UUID or not registered? Then it must be a filename */
4386 if (!floppyImage)
4387 {
4388 CHECK_ERROR(virtualBox, FindFloppyImage(Bstr(argv[1]), floppyImage.asOutParam()));
4389 }
4390 if (SUCCEEDED(rc) && floppyImage)
4391 {
4392 CHECK_ERROR(floppyImage, Close());
4393 }
4394 }
4395 else
4396 return errorSyntax(USAGE_UNREGISTERIMAGE, "Invalid parameter '%s'", Utf8Str(argv[1]).raw());
4397
4398 return SUCCEEDED(rc) ? 0 : 1;
4399}
4400
4401#ifdef RT_OS_WINDOWS
4402static int handleCreateHostIF(int argc, char *argv[],
4403 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4404{
4405 if (argc != 1)
4406 return errorSyntax(USAGE_CREATEHOSTIF, "Incorrect number of parameters");
4407
4408 HRESULT rc = S_OK;
4409
4410 do
4411 {
4412 ComPtr<IHost> host;
4413 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
4414
4415 ComPtr<IHostNetworkInterface> hostif;
4416 ComPtr<IProgress> progress;
4417 CHECK_ERROR_BREAK(host,
4418 CreateHostNetworkInterface(Bstr(argv[0]),
4419 hostif.asOutParam(),
4420 progress.asOutParam()));
4421
4422 showProgress(progress);
4423 HRESULT result;
4424 CHECK_ERROR_BREAK(progress, COMGETTER(ResultCode)(&result));
4425 if (FAILED(result))
4426 {
4427 com::ProgressErrorInfo info(progress);
4428 PRINT_ERROR_INFO(info);
4429 rc = result;
4430 }
4431 }
4432 while (0);
4433
4434 return SUCCEEDED(rc) ? 0 : 1;
4435}
4436
4437static int handleRemoveHostIF(int argc, char *argv[],
4438 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4439{
4440 if (argc != 1)
4441 return errorSyntax(USAGE_REMOVEHOSTIF, "Incorrect number of parameters");
4442
4443 HRESULT rc = S_OK;
4444
4445 do
4446 {
4447 ComPtr<IHost> host;
4448 CHECK_ERROR_BREAK(virtualBox, COMGETTER(Host)(host.asOutParam()));
4449
4450 ComPtr<IHostNetworkInterface> hostif;
4451
4452 /* first guess is that it's a UUID */
4453 Guid uuid(argv[0]);
4454 if (uuid.isEmpty())
4455 {
4456 /* not a valid UUID, search for it */
4457 ComPtr<IHostNetworkInterfaceCollection> coll;
4458 CHECK_ERROR_BREAK(host, COMGETTER(NetworkInterfaces)(coll.asOutParam()));
4459 CHECK_ERROR_BREAK(coll, FindByName(Bstr(argv[0]), hostif.asOutParam()));
4460 CHECK_ERROR_BREAK(hostif, COMGETTER(Id)(uuid.asOutParam()));
4461 }
4462
4463 ComPtr<IProgress> progress;
4464 CHECK_ERROR_BREAK(host,
4465 RemoveHostNetworkInterface(uuid,
4466 hostif.asOutParam(),
4467 progress.asOutParam()));
4468
4469 showProgress(progress);
4470 HRESULT result;
4471 CHECK_ERROR_BREAK(progress, COMGETTER(ResultCode)(&result));
4472 if (FAILED(result))
4473 {
4474 com::ProgressErrorInfo info(progress);
4475 PRINT_ERROR_INFO(info);
4476 rc = result;
4477 }
4478 }
4479 while (0);
4480
4481 return SUCCEEDED(rc) ? 0 : 1;
4482}
4483#endif /* RT_OS_WINDOWS */
4484
4485static int handleGetExtraData(int argc, char *argv[],
4486 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4487{
4488 HRESULT rc = S_OK;
4489
4490 if (argc != 2)
4491 return errorSyntax(USAGE_GETEXTRADATA, "Incorrect number of parameters");
4492
4493 /* global data? */
4494 if (strcmp(argv[0], "global") == 0)
4495 {
4496 /* enumeration? */
4497 if (strcmp(argv[1], "enumerate") == 0)
4498 {
4499 Bstr extraDataKey;
4500
4501 do
4502 {
4503 Bstr nextExtraDataKey;
4504 Bstr nextExtraDataValue;
4505 HRESULT rcEnum = virtualBox->GetNextExtraDataKey(extraDataKey, nextExtraDataKey.asOutParam(),
4506 nextExtraDataValue.asOutParam());
4507 extraDataKey = nextExtraDataKey;
4508
4509 if (SUCCEEDED(rcEnum) && extraDataKey)
4510 RTPrintf("Key: %lS, Value: %lS\n", nextExtraDataKey.raw(), nextExtraDataValue.raw());
4511 } while (extraDataKey);
4512 }
4513 else
4514 {
4515 Bstr value;
4516 CHECK_ERROR(virtualBox, GetExtraData(Bstr(argv[1]), value.asOutParam()));
4517 if (value)
4518 RTPrintf("Value: %lS\n", value.raw());
4519 else
4520 RTPrintf("No value set!\n");
4521 }
4522 }
4523 else
4524 {
4525 ComPtr<IMachine> machine;
4526 /* assume it's a UUID */
4527 rc = virtualBox->GetMachine(Guid(argv[0]), machine.asOutParam());
4528 if (FAILED(rc) || !machine)
4529 {
4530 /* must be a name */
4531 CHECK_ERROR(virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
4532 }
4533 if (machine)
4534 {
4535 /* enumeration? */
4536 if (strcmp(argv[1], "enumerate") == 0)
4537 {
4538 Bstr extraDataKey;
4539
4540 do
4541 {
4542 Bstr nextExtraDataKey;
4543 Bstr nextExtraDataValue;
4544 HRESULT rcEnum = machine->GetNextExtraDataKey(extraDataKey, nextExtraDataKey.asOutParam(),
4545 nextExtraDataValue.asOutParam());
4546 extraDataKey = nextExtraDataKey;
4547
4548 if (SUCCEEDED(rcEnum) && extraDataKey)
4549 {
4550 RTPrintf("Key: %lS, Value: %lS\n", nextExtraDataKey.raw(), nextExtraDataValue.raw());
4551 }
4552 } while (extraDataKey);
4553 }
4554 else
4555 {
4556 Bstr value;
4557 CHECK_ERROR(machine, GetExtraData(Bstr(argv[1]), value.asOutParam()));
4558 if (value)
4559 RTPrintf("Value: %lS\n", value.raw());
4560 else
4561 RTPrintf("No value set!\n");
4562 }
4563 }
4564 }
4565 return SUCCEEDED(rc) ? 0 : 1;
4566}
4567
4568static int handleSetExtraData(int argc, char *argv[],
4569 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4570{
4571 HRESULT rc = S_OK;
4572
4573 if (argc < 2)
4574 return errorSyntax(USAGE_SETEXTRADATA, "Not enough parameters");
4575
4576 /* global data? */
4577 if (strcmp(argv[0], "global") == 0)
4578 {
4579 if (argc < 3)
4580 CHECK_ERROR(virtualBox, SetExtraData(Bstr(argv[1]), NULL));
4581 else if (argc == 3)
4582 CHECK_ERROR(virtualBox, SetExtraData(Bstr(argv[1]), Bstr(argv[2])));
4583 else
4584 return errorSyntax(USAGE_SETEXTRADATA, "Too many parameters");
4585 }
4586 else
4587 {
4588 ComPtr<IMachine> machine;
4589 /* assume it's a UUID */
4590 rc = virtualBox->GetMachine(Guid(argv[0]), machine.asOutParam());
4591 if (FAILED(rc) || !machine)
4592 {
4593 /* must be a name */
4594 CHECK_ERROR(virtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
4595 }
4596 if (machine)
4597 {
4598 if (argc < 3)
4599 CHECK_ERROR(machine, SetExtraData(Bstr(argv[1]), NULL));
4600 else if (argc == 3)
4601 CHECK_ERROR(machine, SetExtraData(Bstr(argv[1]), Bstr(argv[2])));
4602 else
4603 return errorSyntax(USAGE_SETEXTRADATA, "Too many parameters");
4604 }
4605 }
4606 return SUCCEEDED(rc) ? 0 : 1;
4607}
4608
4609static int handleSetProperty(int argc, char *argv[],
4610 ComPtr<IVirtualBox> virtualBox, ComPtr<ISession> session)
4611{
4612 HRESULT rc;
4613
4614 /* there must be two arguments: property name and value */
4615 if (argc != 2)
4616 return errorSyntax(USAGE_SETPROPERTY, "Incorrect number of parameters");
4617
4618 ComPtr<ISystemProperties> systemProperties;
4619 virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam());
4620
4621 if (strcmp(argv[0], "hdfolder") == 0)
4622 {
4623 /* reset to default? */
4624 if (strcmp(argv[1], "default") == 0)
4625 CHECK_ERROR(systemProperties, COMSETTER(DefaultHardDiskFolder)(NULL));
4626 else
4627 CHECK_ERROR(systemProperties, COMSETTER(DefaultHardDiskFolder)(Bstr(argv[1])));
4628 }
4629 else if (strcmp(argv[0], "machinefolder") == 0)
4630 {
4631 /* reset to default? */
4632 if (strcmp(argv[1], "default") == 0)
4633 CHECK_ERROR(systemProperties, COMSETTER(DefaultMachineFolder)(NULL));
4634 else
4635 CHECK_ERROR(systemProperties, COMSETTER(DefaultMachineFolder)(Bstr(argv[1])));
4636 }
4637 else if (strcmp(argv[0], "vrdpauthlibrary") == 0)
4638 {
4639 /* reset to default? */
4640 if (strcmp(argv[1], "default") == 0)
4641 CHECK_ERROR(systemProperties, COMSETTER(RemoteDisplayAuthLibrary)(NULL));
4642 else
4643 CHECK_ERROR(systemProperties, COMSETTER(RemoteDisplayAuthLibrary)(Bstr(argv[1])));
4644 }
4645 else if (strcmp(argv[0], "websrvauthlibrary") == 0)
4646 {
4647 /* reset to default? */
4648 if (strcmp(argv[1], "default") == 0)
4649 CHECK_ERROR(systemProperties, COMSETTER(WebServiceAuthLibrary)(NULL));
4650 else
4651 CHECK_ERROR(systemProperties, COMSETTER(WebServiceAuthLibrary)(Bstr(argv[1])));
4652 }
4653 else if (strcmp(argv[0], "hwvirtexenabled") == 0)
4654 {
4655 if (strcmp(argv[1], "yes") == 0)
4656 CHECK_ERROR(systemProperties, COMSETTER(HWVirtExEnabled)(TRUE));
4657 else if (strcmp(argv[1], "no") == 0)
4658 CHECK_ERROR(systemProperties, COMSETTER(HWVirtExEnabled)(FALSE));
4659 else
4660 return errorArgument("Invalid value '%s' for hardware virtualization extension flag", argv[1]);
4661 }
4662 else if (strcmp(argv[0], "loghistorycount") == 0)
4663 {
4664 uint32_t uVal;
4665 int vrc;
4666 vrc = RTStrToUInt32Ex(argv[1], NULL, 0, &uVal);
4667 if (vrc != VINF_SUCCESS)
4668 return errorArgument("Error parsing Log history count '%s'", argv[1]);
4669 CHECK_ERROR(systemProperties, COMSETTER(LogHistoryCount)(uVal));
4670 }
4671 else
4672 return errorSyntax(USAGE_SETPROPERTY, "Invalid parameter '%s'", argv[0]);
4673
4674 return SUCCEEDED(rc) ? 0 : 1;
4675}
4676
4677static int handleUSBFilter (int argc, char *argv[],
4678 ComPtr <IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
4679{
4680 HRESULT rc = S_OK;
4681 USBFilterCmd cmd;
4682
4683 /* at least: 0: command, 1: index, 2: -target, 3: <target value> */
4684 if (argc < 4)
4685 return errorSyntax(USAGE_USBFILTER, "Not enough parameters");
4686
4687 /* which command? */
4688 cmd.mAction = USBFilterCmd::Invalid;
4689 if (strcmp (argv [0], "add") == 0) cmd.mAction = USBFilterCmd::Add;
4690 else if (strcmp (argv [0], "modify") == 0) cmd.mAction = USBFilterCmd::Modify;
4691 else if (strcmp (argv [0], "remove") == 0) cmd.mAction = USBFilterCmd::Remove;
4692
4693 if (cmd.mAction == USBFilterCmd::Invalid)
4694 return errorSyntax(USAGE_USBFILTER, "Invalid parameter '%s'", argv[0]);
4695
4696 /* which index? */
4697 if (VINF_SUCCESS != RTStrToUInt32Full (argv[1], 10, &cmd.mIndex))
4698 return errorSyntax(USAGE_USBFILTER, "Invalid index '%s'", argv[1]);
4699
4700 switch (cmd.mAction)
4701 {
4702 case USBFilterCmd::Add:
4703 case USBFilterCmd::Modify:
4704 {
4705 /* at least: 0: command, 1: index, 2: -target, 3: <target value>, 4: -name, 5: <name value> */
4706 if (argc < 6)
4707 {
4708 if (cmd.mAction == USBFilterCmd::Add)
4709 return errorSyntax(USAGE_USBFILTER_ADD, "Not enough parameters");
4710
4711 return errorSyntax(USAGE_USBFILTER_MODIFY, "Not enough parameters");
4712 }
4713
4714 // set Active to true by default
4715 // (assuming that the user sets up all necessary attributes
4716 // at once and wants the filter to be active immediately)
4717 if (cmd.mAction == USBFilterCmd::Add)
4718 cmd.mFilter.mActive = true;
4719
4720 for (int i = 2; i < argc; i++)
4721 {
4722 if (strcmp(argv [i], "-target") == 0)
4723 {
4724 if (argc <= i + 1 || !*argv[i+1])
4725 return errorArgument("Missing argument to '%s'", argv[i]);
4726 i++;
4727 if (strcmp (argv [i], "global") == 0)
4728 cmd.mGlobal = true;
4729 else
4730 {
4731 /* assume it's a UUID of a machine */
4732 rc = aVirtualBox->GetMachine(Guid(argv[i]), cmd.mMachine.asOutParam());
4733 if (FAILED(rc) || !cmd.mMachine)
4734 {
4735 /* must be a name */
4736 CHECK_ERROR_RET(aVirtualBox, FindMachine(Bstr(argv[i]), cmd.mMachine.asOutParam()), 1);
4737 }
4738 }
4739 }
4740 else if (strcmp(argv [i], "-name") == 0)
4741 {
4742 if (argc <= i + 1 || !*argv[i+1])
4743 return errorArgument("Missing argument to '%s'", argv[i]);
4744 i++;
4745 cmd.mFilter.mName = argv [i];
4746 }
4747 else if (strcmp(argv [i], "-active") == 0)
4748 {
4749 if (argc <= i + 1)
4750 return errorArgument("Missing argument to '%s'", argv[i]);
4751 i++;
4752 if (strcmp (argv [i], "yes") == 0)
4753 cmd.mFilter.mActive = true;
4754 else if (strcmp (argv [i], "no") == 0)
4755 cmd.mFilter.mActive = false;
4756 else
4757 return errorArgument("Invalid -active argument '%s'", argv[i]);
4758 }
4759 else if (strcmp(argv [i], "-vendorid") == 0)
4760 {
4761 if (argc <= i + 1)
4762 return errorArgument("Missing argument to '%s'", argv[i]);
4763 i++;
4764 cmd.mFilter.mVendorId = argv [i];
4765 }
4766 else if (strcmp(argv [i], "-productid") == 0)
4767 {
4768 if (argc <= i + 1)
4769 return errorArgument("Missing argument to '%s'", argv[i]);
4770 i++;
4771 cmd.mFilter.mProductId = argv [i];
4772 }
4773 else if (strcmp(argv [i], "-revision") == 0)
4774 {
4775 if (argc <= i + 1)
4776 return errorArgument("Missing argument to '%s'", argv[i]);
4777 i++;
4778 cmd.mFilter.mRevision = argv [i];
4779 }
4780 else if (strcmp(argv [i], "-manufacturer") == 0)
4781 {
4782 if (argc <= i + 1)
4783 return errorArgument("Missing argument to '%s'", argv[i]);
4784 i++;
4785 cmd.mFilter.mManufacturer = argv [i];
4786 }
4787 else if (strcmp(argv [i], "-product") == 0)
4788 {
4789 if (argc <= i + 1)
4790 return errorArgument("Missing argument to '%s'", argv[i]);
4791 i++;
4792 cmd.mFilter.mProduct = argv [i];
4793 }
4794 else if (strcmp(argv [i], "-remote") == 0)
4795 {
4796 if (argc <= i + 1)
4797 return errorArgument("Missing argument to '%s'", argv[i]);
4798 i++;
4799 cmd.mFilter.mRemote = argv[i];
4800 }
4801 else if (strcmp(argv [i], "-serialnumber") == 0)
4802 {
4803 if (argc <= i + 1)
4804 return errorArgument("Missing argument to '%s'", argv[i]);
4805 i++;
4806 cmd.mFilter.mSerialNumber = argv [i];
4807 }
4808 else if (strcmp(argv [i], "-maskedinterfaces") == 0)
4809 {
4810 if (argc <= i + 1)
4811 return errorArgument("Missing argument to '%s'", argv[i]);
4812 i++;
4813 uint32_t u32;
4814 rc = RTStrToUInt32Full(argv[i], 0, &u32);
4815 if (RT_FAILURE(rc))
4816 return errorArgument("Failed to convert the -maskedinterfaces value '%s' to a number, rc=%Rrc", argv[i], rc);
4817 cmd.mFilter.mMaskedInterfaces = u32;
4818 }
4819 else if (strcmp(argv [i], "-action") == 0)
4820 {
4821 if (argc <= i + 1)
4822 return errorArgument("Missing argument to '%s'", argv[i]);
4823 i++;
4824 if (strcmp (argv [i], "ignore") == 0)
4825 cmd.mFilter.mAction = USBDeviceFilterAction_Ignore;
4826 else if (strcmp (argv [i], "hold") == 0)
4827 cmd.mFilter.mAction = USBDeviceFilterAction_Hold;
4828 else
4829 return errorArgument("Invalid USB filter action '%s'", argv[i]);
4830 }
4831 else
4832 return errorSyntax(cmd.mAction == USBFilterCmd::Add ? USAGE_USBFILTER_ADD : USAGE_USBFILTER_MODIFY,
4833 "Unknown option '%s'", argv[i]);
4834 }
4835
4836 if (cmd.mAction == USBFilterCmd::Add)
4837 {
4838 // mandatory/forbidden options
4839 if ( cmd.mFilter.mName.isEmpty()
4840 ||
4841 ( cmd.mGlobal
4842 && cmd.mFilter.mAction == USBDeviceFilterAction_Null
4843 )
4844 || ( !cmd.mGlobal
4845 && !cmd.mMachine)
4846 || ( cmd.mGlobal
4847 && cmd.mFilter.mRemote)
4848 )
4849 {
4850 return errorSyntax(USAGE_USBFILTER_ADD, "Mandatory options not supplied");
4851 }
4852 }
4853 break;
4854 }
4855
4856 case USBFilterCmd::Remove:
4857 {
4858 /* at least: 0: command, 1: index, 2: -target, 3: <target value> */
4859 if (argc < 4)
4860 return errorSyntax(USAGE_USBFILTER_REMOVE, "Not enough parameters");
4861
4862 for (int i = 2; i < argc; i++)
4863 {
4864 if (strcmp(argv [i], "-target") == 0)
4865 {
4866 if (argc <= i + 1 || !*argv[i+1])
4867 return errorArgument("Missing argument to '%s'", argv[i]);
4868 i++;
4869 if (strcmp (argv [i], "global") == 0)
4870 cmd.mGlobal = true;
4871 else
4872 {
4873 /* assume it's a UUID of a machine */
4874 rc = aVirtualBox->GetMachine(Guid(argv[i]), cmd.mMachine.asOutParam());
4875 if (FAILED(rc) || !cmd.mMachine)
4876 {
4877 /* must be a name */
4878 CHECK_ERROR_RET(aVirtualBox, FindMachine(Bstr(argv[i]), cmd.mMachine.asOutParam()), 1);
4879 }
4880 }
4881 }
4882 }
4883
4884 // mandatory options
4885 if (!cmd.mGlobal && !cmd.mMachine)
4886 return errorSyntax(USAGE_USBFILTER_REMOVE, "Mandatory options not supplied");
4887
4888 break;
4889 }
4890
4891 default: break;
4892 }
4893
4894 USBFilterCmd::USBFilter &f = cmd.mFilter;
4895
4896 ComPtr <IHost> host;
4897 ComPtr <IUSBController> ctl;
4898 if (cmd.mGlobal)
4899 CHECK_ERROR_RET (aVirtualBox, COMGETTER(Host) (host.asOutParam()), 1);
4900 else
4901 {
4902 Guid uuid;
4903 cmd.mMachine->COMGETTER(Id)(uuid.asOutParam());
4904 /* open a session for the VM */
4905 CHECK_ERROR_RET (aVirtualBox, OpenSession(aSession, uuid), 1);
4906 /* get the mutable session machine */
4907 aSession->COMGETTER(Machine)(cmd.mMachine.asOutParam());
4908 /* and get the USB controller */
4909 CHECK_ERROR_RET (cmd.mMachine, COMGETTER(USBController) (ctl.asOutParam()), 1);
4910 }
4911
4912 switch (cmd.mAction)
4913 {
4914 case USBFilterCmd::Add:
4915 {
4916 if (cmd.mGlobal)
4917 {
4918 ComPtr <IHostUSBDeviceFilter> flt;
4919 CHECK_ERROR_BREAK (host, CreateUSBDeviceFilter (f.mName, flt.asOutParam()));
4920
4921 if (!f.mActive.isNull())
4922 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive));
4923 if (!f.mVendorId.isNull())
4924 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId.setNullIfEmpty()));
4925 if (!f.mProductId.isNull())
4926 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId.setNullIfEmpty()));
4927 if (!f.mRevision.isNull())
4928 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision.setNullIfEmpty()));
4929 if (!f.mManufacturer.isNull())
4930 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer.setNullIfEmpty()));
4931 if (!f.mSerialNumber.isNull())
4932 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber.setNullIfEmpty()));
4933 if (!f.mMaskedInterfaces.isNull())
4934 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces));
4935
4936 if (f.mAction != USBDeviceFilterAction_Null)
4937 CHECK_ERROR_BREAK (flt, COMSETTER(Action) (f.mAction));
4938
4939 CHECK_ERROR_BREAK (host, InsertUSBDeviceFilter (cmd.mIndex, flt));
4940 }
4941 else
4942 {
4943 ComPtr <IUSBDeviceFilter> flt;
4944 CHECK_ERROR_BREAK (ctl, CreateDeviceFilter (f.mName, flt.asOutParam()));
4945
4946 if (!f.mActive.isNull())
4947 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive));
4948 if (!f.mVendorId.isNull())
4949 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId.setNullIfEmpty()));
4950 if (!f.mProductId.isNull())
4951 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId.setNullIfEmpty()));
4952 if (!f.mRevision.isNull())
4953 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision.setNullIfEmpty()));
4954 if (!f.mManufacturer.isNull())
4955 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer.setNullIfEmpty()));
4956 if (!f.mRemote.isNull())
4957 CHECK_ERROR_BREAK (flt, COMSETTER(Remote) (f.mRemote.setNullIfEmpty()));
4958 if (!f.mSerialNumber.isNull())
4959 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber.setNullIfEmpty()));
4960 if (!f.mMaskedInterfaces.isNull())
4961 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces));
4962
4963 CHECK_ERROR_BREAK (ctl, InsertDeviceFilter (cmd.mIndex, flt));
4964 }
4965 break;
4966 }
4967 case USBFilterCmd::Modify:
4968 {
4969 if (cmd.mGlobal)
4970 {
4971 ComPtr <IHostUSBDeviceFilterCollection> coll;
4972 CHECK_ERROR_BREAK (host, COMGETTER(USBDeviceFilters) (coll.asOutParam()));
4973 ComPtr <IHostUSBDeviceFilter> flt;
4974 CHECK_ERROR_BREAK (coll, GetItemAt (cmd.mIndex, flt.asOutParam()));
4975
4976 if (!f.mName.isNull())
4977 CHECK_ERROR_BREAK (flt, COMSETTER(Name) (f.mName.setNullIfEmpty()));
4978 if (!f.mActive.isNull())
4979 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive));
4980 if (!f.mVendorId.isNull())
4981 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId.setNullIfEmpty()));
4982 if (!f.mProductId.isNull())
4983 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId.setNullIfEmpty()));
4984 if (!f.mRevision.isNull())
4985 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision.setNullIfEmpty()));
4986 if (!f.mManufacturer.isNull())
4987 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer.setNullIfEmpty()));
4988 if (!f.mSerialNumber.isNull())
4989 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber.setNullIfEmpty()));
4990 if (!f.mMaskedInterfaces.isNull())
4991 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces));
4992
4993 if (f.mAction != USBDeviceFilterAction_Null)
4994 CHECK_ERROR_BREAK (flt, COMSETTER(Action) (f.mAction));
4995 }
4996 else
4997 {
4998 ComPtr <IUSBDeviceFilterCollection> coll;
4999 CHECK_ERROR_BREAK (ctl, COMGETTER(DeviceFilters) (coll.asOutParam()));
5000
5001 ComPtr <IUSBDeviceFilter> flt;
5002 CHECK_ERROR_BREAK (coll, GetItemAt (cmd.mIndex, flt.asOutParam()));
5003
5004 if (!f.mName.isNull())
5005 CHECK_ERROR_BREAK (flt, COMSETTER(Name) (f.mName.setNullIfEmpty()));
5006 if (!f.mActive.isNull())
5007 CHECK_ERROR_BREAK (flt, COMSETTER(Active) (f.mActive));
5008 if (!f.mVendorId.isNull())
5009 CHECK_ERROR_BREAK (flt, COMSETTER(VendorId) (f.mVendorId.setNullIfEmpty()));
5010 if (!f.mProductId.isNull())
5011 CHECK_ERROR_BREAK (flt, COMSETTER(ProductId) (f.mProductId.setNullIfEmpty()));
5012 if (!f.mRevision.isNull())
5013 CHECK_ERROR_BREAK (flt, COMSETTER(Revision) (f.mRevision.setNullIfEmpty()));
5014 if (!f.mManufacturer.isNull())
5015 CHECK_ERROR_BREAK (flt, COMSETTER(Manufacturer) (f.mManufacturer.setNullIfEmpty()));
5016 if (!f.mRemote.isNull())
5017 CHECK_ERROR_BREAK (flt, COMSETTER(Remote) (f.mRemote.setNullIfEmpty()));
5018 if (!f.mSerialNumber.isNull())
5019 CHECK_ERROR_BREAK (flt, COMSETTER(SerialNumber) (f.mSerialNumber.setNullIfEmpty()));
5020 if (!f.mMaskedInterfaces.isNull())
5021 CHECK_ERROR_BREAK (flt, COMSETTER(MaskedInterfaces) (f.mMaskedInterfaces));
5022 }
5023 break;
5024 }
5025 case USBFilterCmd::Remove:
5026 {
5027 if (cmd.mGlobal)
5028 {
5029 ComPtr <IHostUSBDeviceFilter> flt;
5030 CHECK_ERROR_BREAK (host, RemoveUSBDeviceFilter (cmd.mIndex, flt.asOutParam()));
5031 }
5032 else
5033 {
5034 ComPtr <IUSBDeviceFilter> flt;
5035 CHECK_ERROR_BREAK (ctl, RemoveDeviceFilter (cmd.mIndex, flt.asOutParam()));
5036 }
5037 break;
5038 }
5039 default:
5040 break;
5041 }
5042
5043 if (cmd.mMachine)
5044 {
5045 /* commit and close the session */
5046 CHECK_ERROR(cmd.mMachine, SaveSettings());
5047 aSession->Close();
5048 }
5049
5050 return SUCCEEDED (rc) ? 0 : 1;
5051}
5052
5053static int handleSharedFolder (int argc, char *argv[],
5054 ComPtr <IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
5055{
5056 HRESULT rc;
5057
5058 /* we need at least a command and target */
5059 if (argc < 2)
5060 return errorSyntax(USAGE_SHAREDFOLDER, "Not enough parameters");
5061
5062 ComPtr<IMachine> machine;
5063 /* assume it's a UUID */
5064 rc = aVirtualBox->GetMachine(Guid(argv[1]), machine.asOutParam());
5065 if (FAILED(rc) || !machine)
5066 {
5067 /* must be a name */
5068 CHECK_ERROR(aVirtualBox, FindMachine(Bstr(argv[1]), machine.asOutParam()));
5069 }
5070 if (!machine)
5071 return 1;
5072 Guid uuid;
5073 machine->COMGETTER(Id)(uuid.asOutParam());
5074
5075 if (strcmp(argv[0], "add") == 0)
5076 {
5077 /* we need at least four more parameters */
5078 if (argc < 5)
5079 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Not enough parameters");
5080
5081 char *name = NULL;
5082 char *hostpath = NULL;
5083 bool fTransient = false;
5084 bool fWritable = true;
5085
5086 for (int i = 2; i < argc; i++)
5087 {
5088 if (strcmp(argv[i], "-name") == 0)
5089 {
5090 if (argc <= i + 1 || !*argv[i+1])
5091 return errorArgument("Missing argument to '%s'", argv[i]);
5092 i++;
5093 name = argv[i];
5094 }
5095 else if (strcmp(argv[i], "-hostpath") == 0)
5096 {
5097 if (argc <= i + 1 || !*argv[i+1])
5098 return errorArgument("Missing argument to '%s'", argv[i]);
5099 i++;
5100 hostpath = argv[i];
5101 }
5102 else if (strcmp(argv[i], "-readonly") == 0)
5103 {
5104 fWritable = false;
5105 }
5106 else if (strcmp(argv[i], "-transient") == 0)
5107 {
5108 fTransient = true;
5109 }
5110 else
5111 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
5112 }
5113
5114 if (NULL != strstr(name, " "))
5115 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "No spaces allowed in parameter '-name'!");
5116
5117 /* required arguments */
5118 if (!name || !hostpath)
5119 {
5120 return errorSyntax(USAGE_SHAREDFOLDER_ADD, "Parameters -name and -hostpath are required");
5121 }
5122
5123 if (fTransient)
5124 {
5125 ComPtr <IConsole> console;
5126
5127 /* open an existing session for the VM */
5128 CHECK_ERROR_RET(aVirtualBox, OpenExistingSession (aSession, uuid), 1);
5129 /* get the session machine */
5130 CHECK_ERROR_RET(aSession, COMGETTER(Machine)(machine.asOutParam()), 1);
5131 /* get the session console */
5132 CHECK_ERROR_RET(aSession, COMGETTER(Console)(console.asOutParam()), 1);
5133
5134 CHECK_ERROR(console, CreateSharedFolder(Bstr(name), Bstr(hostpath), fWritable));
5135
5136 if (console)
5137 aSession->Close();
5138 }
5139 else
5140 {
5141 /* open a session for the VM */
5142 CHECK_ERROR_RET (aVirtualBox, OpenSession(aSession, uuid), 1);
5143
5144 /* get the mutable session machine */
5145 aSession->COMGETTER(Machine)(machine.asOutParam());
5146
5147 CHECK_ERROR(machine, CreateSharedFolder(Bstr(name), Bstr(hostpath), fWritable));
5148
5149 if (SUCCEEDED(rc))
5150 CHECK_ERROR(machine, SaveSettings());
5151
5152 aSession->Close();
5153 }
5154 }
5155 else if (strcmp(argv[0], "remove") == 0)
5156 {
5157 /* we need at least two more parameters */
5158 if (argc < 3)
5159 return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Not enough parameters");
5160
5161 char *name = NULL;
5162 bool fTransient = false;
5163
5164 for (int i = 2; i < argc; i++)
5165 {
5166 if (strcmp(argv[i], "-name") == 0)
5167 {
5168 if (argc <= i + 1 || !*argv[i+1])
5169 return errorArgument("Missing argument to '%s'", argv[i]);
5170 i++;
5171 name = argv[i];
5172 }
5173 else if (strcmp(argv[i], "-transient") == 0)
5174 {
5175 fTransient = true;
5176 }
5177 else
5178 return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
5179 }
5180
5181 /* required arguments */
5182 if (!name)
5183 return errorSyntax(USAGE_SHAREDFOLDER_REMOVE, "Parameter -name is required");
5184
5185 if (fTransient)
5186 {
5187 ComPtr <IConsole> console;
5188
5189 /* open an existing session for the VM */
5190 CHECK_ERROR_RET(aVirtualBox, OpenExistingSession (aSession, uuid), 1);
5191 /* get the session machine */
5192 CHECK_ERROR_RET(aSession, COMGETTER(Machine)(machine.asOutParam()), 1);
5193 /* get the session console */
5194 CHECK_ERROR_RET(aSession, COMGETTER(Console)(console.asOutParam()), 1);
5195
5196 CHECK_ERROR(console, RemoveSharedFolder(Bstr(name)));
5197
5198 if (console)
5199 aSession->Close();
5200 }
5201 else
5202 {
5203 /* open a session for the VM */
5204 CHECK_ERROR_RET (aVirtualBox, OpenSession(aSession, uuid), 1);
5205
5206 /* get the mutable session machine */
5207 aSession->COMGETTER(Machine)(machine.asOutParam());
5208
5209 CHECK_ERROR(machine, RemoveSharedFolder(Bstr(name)));
5210
5211 /* commit and close the session */
5212 CHECK_ERROR(machine, SaveSettings());
5213 aSession->Close();
5214 }
5215 }
5216 else
5217 return errorSyntax(USAGE_SETPROPERTY, "Invalid parameter '%s'", Utf8Str(argv[0]).raw());
5218
5219 return 0;
5220}
5221
5222static int handleVMStatistics(int argc, char *argv[],
5223 ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
5224{
5225 HRESULT rc;
5226
5227 /* at least one option: the UUID or name of the VM */
5228 if (argc < 1)
5229 return errorSyntax(USAGE_VM_STATISTICS, "Incorrect number of parameters");
5230
5231 /* try to find the given machine */
5232 ComPtr <IMachine> machine;
5233 Guid uuid (argv[0]);
5234 if (!uuid.isEmpty())
5235 CHECK_ERROR(aVirtualBox, GetMachine(uuid, machine.asOutParam()));
5236 else
5237 {
5238 CHECK_ERROR(aVirtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()));
5239 if (SUCCEEDED (rc))
5240 machine->COMGETTER(Id)(uuid.asOutParam());
5241 }
5242 if (FAILED(rc))
5243 return 1;
5244
5245 /* parse arguments. */
5246 bool fReset = false;
5247 bool fWithDescriptions = false;
5248 const char *pszPattern = NULL; /* all */
5249 for (int i = 1; i < argc; i++)
5250 {
5251 if (!strcmp(argv[i], "-pattern"))
5252 {
5253 if (pszPattern)
5254 return errorSyntax(USAGE_VM_STATISTICS, "Multiple -patterns options is not permitted");
5255 if (i + 1 >= argc)
5256 return errorArgument("Missing argument to '%s'", argv[i]);
5257 pszPattern = argv[++i];
5258 }
5259 else if (!strcmp(argv[i], "-descriptions"))
5260 fWithDescriptions = true;
5261 /* add: -file <filename> and -formatted */
5262 else if (!strcmp(argv[i], "-reset"))
5263 fReset = true;
5264 else
5265 return errorSyntax(USAGE_VM_STATISTICS, "Unknown option '%s'", argv[i]);
5266 }
5267 if (fReset && fWithDescriptions)
5268 return errorSyntax(USAGE_VM_STATISTICS, "The -reset and -descriptions options does not mix");
5269
5270
5271 /* open an existing session for the VM. */
5272 CHECK_ERROR(aVirtualBox, OpenExistingSession(aSession, uuid));
5273 if (SUCCEEDED(rc))
5274 {
5275 /* get the session console. */
5276 ComPtr <IConsole> console;
5277 CHECK_ERROR(aSession, COMGETTER(Console)(console.asOutParam()));
5278 if (SUCCEEDED(rc))
5279 {
5280 /* get the machine debugger. */
5281 ComPtr <IMachineDebugger> debugger;
5282 CHECK_ERROR(console, COMGETTER(Debugger)(debugger.asOutParam()));
5283 if (SUCCEEDED(rc))
5284 {
5285 if (fReset)
5286 CHECK_ERROR(debugger, ResetStats(Bstr(pszPattern).raw()));
5287 else
5288 {
5289 Bstr stats;
5290 CHECK_ERROR(debugger, GetStats(Bstr(pszPattern).raw(), fWithDescriptions, stats.asOutParam()));
5291 if (SUCCEEDED(rc))
5292 {
5293 /* if (fFormatted)
5294 { big mess }
5295 else
5296 */
5297 RTPrintf("%ls\n", stats.raw());
5298 }
5299 }
5300 }
5301 aSession->Close();
5302 }
5303 }
5304
5305 return SUCCEEDED(rc) ? 0 : 1;
5306}
5307#endif /* !VBOX_ONLY_DOCS */
5308
5309enum ConvertSettings
5310{
5311 ConvertSettings_No = 0,
5312 ConvertSettings_Yes = 1,
5313 ConvertSettings_Backup = 2,
5314 ConvertSettings_Ignore = 3,
5315};
5316
5317#ifndef VBOX_ONLY_DOCS
5318/**
5319 * Checks if any of the settings files were auto-converted and informs the
5320 * user if so.
5321 *
5322 * @return @false if the program should terminate and @true otherwise.
5323 */
5324static bool checkForAutoConvertedSettings (ComPtr<IVirtualBox> virtualBox,
5325 ComPtr<ISession> session,
5326 ConvertSettings fConvertSettings)
5327{
5328 /* return early if nothing to do */
5329 if (fConvertSettings == ConvertSettings_Ignore)
5330 return true;
5331
5332 HRESULT rc;
5333
5334 do
5335 {
5336 Bstr formatVersion;
5337 CHECK_RC_BREAK (virtualBox->
5338 COMGETTER(SettingsFormatVersion) (formatVersion.asOutParam()));
5339
5340 bool isGlobalConverted = false;
5341 std::list <ComPtr <IMachine> > cvtMachines;
5342 std::list <Utf8Str> fileList;
5343 Bstr version;
5344 Bstr filePath;
5345
5346 com::SafeIfaceArray <IMachine> machines;
5347 CHECK_RC_BREAK (virtualBox->
5348 COMGETTER(Machines2) (ComSafeArrayAsOutParam (machines)));
5349
5350 for (size_t i = 0; i < machines.size(); ++ i)
5351 {
5352 BOOL accessible;
5353 CHECK_RC_BREAK (machines [i]->
5354 COMGETTER(Accessible) (&accessible));
5355 if (!accessible)
5356 continue;
5357
5358 CHECK_RC_BREAK (machines [i]->
5359 COMGETTER(SettingsFileVersion) (version.asOutParam()));
5360
5361 if (version != formatVersion)
5362 {
5363 cvtMachines.push_back (machines [i]);
5364 Bstr filePath;
5365 CHECK_RC_BREAK (machines [i]->
5366 COMGETTER(SettingsFilePath) (filePath.asOutParam()));
5367 fileList.push_back (Utf8StrFmt ("%ls (%ls)", filePath.raw(),
5368 version.raw()));
5369 }
5370 }
5371
5372 CHECK_RC_BREAK (rc);
5373
5374 CHECK_RC_BREAK (virtualBox->
5375 COMGETTER(SettingsFileVersion) (version.asOutParam()));
5376 if (version != formatVersion)
5377 {
5378 isGlobalConverted = true;
5379 CHECK_RC_BREAK (virtualBox->
5380 COMGETTER(SettingsFilePath) (filePath.asOutParam()));
5381 fileList.push_back (Utf8StrFmt ("%ls (%ls)", filePath.raw(),
5382 version.raw()));
5383 }
5384
5385 if (fileList.size() > 0)
5386 {
5387 switch (fConvertSettings)
5388 {
5389 case ConvertSettings_No:
5390 {
5391 RTPrintf (
5392"WARNING! The following VirtualBox settings files have been automatically\n"
5393"converted to the new settings file format version '%ls':\n"
5394"\n",
5395 formatVersion.raw());
5396
5397 for (std::list <Utf8Str>::const_iterator f = fileList.begin();
5398 f != fileList.end(); ++ f)
5399 RTPrintf (" %S\n", (*f).raw());
5400 RTPrintf (
5401"\n"
5402"The current command was aborted to prevent overwriting the above settings\n"
5403"files with the results of the auto-conversion without your permission.\n"
5404"Please put one of the following command line switches to the beginning of\n"
5405"the VBoxManage command line and repeat the command:\n"
5406"\n"
5407" -convertSettings - to save all auto-converted files (it will not\n"
5408" be possible to use these settings files with an\n"
5409" older version of VirtualBox in the future);\n"
5410" -convertSettingsBackup - to create backup copies of the settings files in\n"
5411" the old format before saving them in the new format;\n"
5412" -convertSettingsIgnore - to not save the auto-converted settings files.\n"
5413"\n"
5414"Note that if you use -convertSettingsIgnore, the auto-converted settings files\n"
5415"will be implicitly saved in the new format anyway once you change a setting or\n"
5416"start a virtual machine, but NO backup copies will be created in this case.\n");
5417 return false;
5418 }
5419 case ConvertSettings_Yes:
5420 case ConvertSettings_Backup:
5421 {
5422 break;
5423 }
5424 default:
5425 AssertFailedReturn (false);
5426 }
5427
5428 for (std::list <ComPtr <IMachine> >::const_iterator m = cvtMachines.begin();
5429 m != cvtMachines.end(); ++ m)
5430 {
5431 Guid id;
5432 CHECK_RC_BREAK ((*m)->COMGETTER(Id) (id.asOutParam()));
5433
5434 /* open a session for the VM */
5435 CHECK_ERROR_BREAK (virtualBox, OpenSession (session, id));
5436
5437 ComPtr <IMachine> sm;
5438 CHECK_RC_BREAK (session->COMGETTER(Machine) (sm.asOutParam()));
5439
5440 Bstr bakFileName;
5441 if (fConvertSettings == ConvertSettings_Backup)
5442 CHECK_ERROR (sm, SaveSettingsWithBackup (bakFileName.asOutParam()));
5443 else
5444 CHECK_ERROR (sm, SaveSettings());
5445
5446 session->Close();
5447
5448 CHECK_RC_BREAK (rc);
5449 }
5450
5451 CHECK_RC_BREAK (rc);
5452
5453 if (isGlobalConverted)
5454 {
5455 Bstr bakFileName;
5456 if (fConvertSettings == ConvertSettings_Backup)
5457 CHECK_ERROR (virtualBox, SaveSettingsWithBackup (bakFileName.asOutParam()));
5458 else
5459 CHECK_ERROR (virtualBox, SaveSettings());
5460 }
5461
5462 CHECK_RC_BREAK (rc);
5463 }
5464 }
5465 while (0);
5466
5467 return SUCCEEDED (rc);
5468}
5469#endif /* !VBOX_ONLY_DOCS */
5470
5471// main
5472///////////////////////////////////////////////////////////////////////////////
5473
5474int main(int argc, char *argv[])
5475{
5476 /*
5477 * Before we do anything, init the runtime without loading
5478 * the support driver.
5479 */
5480 RTR3Init();
5481
5482 bool fShowLogo = true;
5483 int iCmd = 1;
5484 int iCmdArg;
5485
5486 ConvertSettings fConvertSettings = ConvertSettings_No;
5487
5488 /* global options */
5489 for (int i = 1; i < argc || argc <= iCmd; i++)
5490 {
5491 if ( argc <= iCmd
5492 || (strcmp(argv[i], "help") == 0)
5493 || (strcmp(argv[i], "-?") == 0)
5494 || (strcmp(argv[i], "-h") == 0)
5495 || (strcmp(argv[i], "-help") == 0)
5496 || (strcmp(argv[i], "--help") == 0))
5497 {
5498 showLogo();
5499 printUsage(USAGE_ALL);
5500 return 0;
5501 }
5502 else if ( strcmp(argv[i], "-v") == 0
5503 || strcmp(argv[i], "-version") == 0
5504 || strcmp(argv[i], "-Version") == 0
5505 || strcmp(argv[i], "--version") == 0)
5506 {
5507 /* Print version number, and do nothing else. */
5508 RTPrintf("%sr%d\n", VBOX_VERSION_STRING, VBoxSVNRev ());
5509 return 0;
5510 }
5511 else if (strcmp(argv[i], "-dumpopts") == 0)
5512 {
5513 /* Special option to dump really all commands,
5514 * even the ones not understood on this platform. */
5515 printUsage(USAGE_DUMPOPTS);
5516 return 0;
5517 }
5518 else if (strcmp(argv[i], "-nologo") == 0)
5519 {
5520 /* suppress the logo */
5521 fShowLogo = false;
5522 iCmd++;
5523 }
5524 else if (strcmp(argv[i], "-convertSettings") == 0)
5525 {
5526 fConvertSettings = ConvertSettings_Yes;
5527 iCmd++;
5528 }
5529 else if (strcmp(argv[i], "-convertSettingsBackup") == 0)
5530 {
5531 fConvertSettings = ConvertSettings_Backup;
5532 iCmd++;
5533 }
5534 else if (strcmp(argv[i], "-convertSettingsIgnore") == 0)
5535 {
5536 fConvertSettings = ConvertSettings_Ignore;
5537 iCmd++;
5538 }
5539 else
5540 {
5541 break;
5542 }
5543 }
5544
5545 iCmdArg = iCmd + 1;
5546
5547 if (fShowLogo)
5548 showLogo();
5549
5550
5551#ifdef VBOX_ONLY_DOCS
5552 int rc = 0;
5553#else /* !VBOX_ONLY_DOCS */
5554 HRESULT rc = 0;
5555
5556 CHECK_RC_RET (com::Initialize());
5557
5558 /*
5559 * The input is in the host OS'es codepage (NT guarantees ACP).
5560 * For VBox we use UTF-8 and convert to UCS-2 when calling (XP)COM APIs.
5561 * For simplicity, just convert the argv[] array here.
5562 */
5563 for (int i = iCmdArg; i < argc; i++)
5564 {
5565 char *converted;
5566 RTStrCurrentCPToUtf8(&converted, argv[i]);
5567 argv[i] = converted;
5568 }
5569
5570 do
5571 {
5572 // scopes all the stuff till shutdown
5573 ////////////////////////////////////////////////////////////////////////////
5574
5575 /* convertdd: does not need a VirtualBox instantiation) */
5576 if (argc >= iCmdArg && (strcmp(argv[iCmd], "convertdd") == 0))
5577 {
5578 rc = handleConvertDDImage(argc - iCmdArg, argv + iCmdArg);
5579 break;
5580 }
5581
5582 ComPtr <IVirtualBox> virtualBox;
5583 ComPtr <ISession> session;
5584
5585 rc = virtualBox.createLocalObject (CLSID_VirtualBox);
5586 if (FAILED(rc))
5587 {
5588 RTPrintf ("[!] Failed to create the VirtualBox object!\n");
5589 PRINT_RC_MESSAGE (rc);
5590
5591 com::ErrorInfo info;
5592 if (!info.isFullAvailable() && !info.isBasicAvailable())
5593 RTPrintf ("[!] Most likely, the VirtualBox COM server is not running "
5594 "or failed to start.\n");
5595 else
5596 PRINT_ERROR_INFO (info);
5597 break;
5598 }
5599
5600 CHECK_RC_BREAK (session.createInprocObject (CLSID_Session));
5601
5602 /* create the event queue
5603 * (here it is necessary only to process remaining XPCOM/IPC events
5604 * after the session is closed) */
5605
5606#ifdef USE_XPCOM_QUEUE
5607 NS_GetMainEventQ(getter_AddRefs(g_pEventQ));
5608#endif
5609
5610 if (!checkForAutoConvertedSettings (virtualBox, session, fConvertSettings))
5611 break;
5612
5613 /*
5614 * All registered command handlers
5615 */
5616 struct
5617 {
5618 const char *command;
5619 PFNHANDLER handler;
5620 } commandHandlers[] =
5621 {
5622 { "internalcommands", handleInternalCommands },
5623 { "list", handleList },
5624 { "showvminfo", handleShowVMInfo },
5625 { "registervm", handleRegisterVM },
5626 { "unregistervm", handleUnregisterVM },
5627 { "createhd", handleCreateHardDisk },
5628 { "createvdi", handleCreateHardDisk }, /* backward compatiblity */
5629 { "modifyhd", handleModifyHardDisk },
5630 { "modifyvdi", handleModifyHardDisk }, /* backward compatiblity */
5631 { "addiscsidisk", handleAddiSCSIDisk },
5632 { "createvm", handleCreateVM },
5633 { "modifyvm", handleModifyVM },
5634 { "clonehd", handleCloneHardDisk },
5635 { "clonevdi", handleCloneHardDisk }, /* backward compatiblity */
5636 { "startvm", handleStartVM },
5637 { "controlvm", handleControlVM },
5638 { "discardstate", handleDiscardState },
5639 { "adoptstate", handleAdoptdState },
5640 { "snapshot", handleSnapshot },
5641 { "openmedium", handleOpenMedium },
5642 { "registerimage", handleOpenMedium }, /* backward compatiblity */
5643 { "closemedium", handleCloseMedium },
5644 { "unregisterimage", handleCloseMedium }, /* backward compatiblity */
5645 { "showhdinfo", handleShowHardDiskInfo },
5646 { "showvdiinfo", handleShowHardDiskInfo }, /* backward compatiblity */
5647#ifdef RT_OS_WINDOWS
5648 { "createhostif", handleCreateHostIF },
5649 { "removehostif", handleRemoveHostIF },
5650#endif
5651 { "getextradata", handleGetExtraData },
5652 { "setextradata", handleSetExtraData },
5653 { "setproperty", handleSetProperty },
5654 { "usbfilter", handleUSBFilter },
5655 { "sharedfolder", handleSharedFolder },
5656 { "vmstatistics", handleVMStatistics },
5657#ifdef VBOX_WITH_GUEST_PROPS
5658 { "guestproperty", handleGuestProperty },
5659#endif /* VBOX_WITH_GUEST_PROPS defined */
5660 { "metrics", handleMetrics },
5661 { NULL, NULL }
5662 };
5663
5664 int commandIndex;
5665 for (commandIndex = 0; commandHandlers[commandIndex].command != NULL; commandIndex++)
5666 {
5667 if (strcmp(commandHandlers[commandIndex].command, argv[iCmd]) == 0)
5668 {
5669 rc = commandHandlers[commandIndex].handler(argc - iCmdArg, &argv[iCmdArg], virtualBox, session);
5670 break;
5671 }
5672 }
5673 if (!commandHandlers[commandIndex].command)
5674 {
5675 rc = errorSyntax(USAGE_ALL, "Invalid command '%s'", Utf8Str(argv[iCmd]).raw());
5676 }
5677
5678 /* Although all handlers should always close the session if they open it,
5679 * we do it here just in case if some of the handlers contains a bug --
5680 * leaving the direct session not closed will turn the machine state to
5681 * Aborted which may have unwanted side effects like killing the saved
5682 * state file (if the machine was in the Saved state before). */
5683 session->Close();
5684
5685#ifdef USE_XPCOM_QUEUE
5686 g_pEventQ->ProcessPendingEvents();
5687#endif
5688
5689 // end "all-stuff" scope
5690 ////////////////////////////////////////////////////////////////////////////
5691 }
5692 while (0);
5693
5694 com::Shutdown();
5695#endif /* !VBOX_ONLY_DOCS */
5696
5697 /*
5698 * Free converted argument vector
5699 */
5700 for (int i = iCmdArg; i < argc; i++)
5701 RTStrFree(argv[i]);
5702
5703 return rc != 0;
5704}
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