VirtualBox

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

Last change on this file since 45846 was 45838, checked in by vboxsync, 12 years ago

VPX: plugged memory leak; introduced rate parameter; clear artefacts from previous frames after resize; cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 103.7 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 45838 2013-04-30 13:54:20Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2013 Oracle Corporation
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
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#ifndef VBOX_ONLY_DOCS
22#include <VBox/com/com.h>
23#include <VBox/com/array.h>
24#include <VBox/com/ErrorInfo.h>
25#include <VBox/com/errorprint.h>
26#include <VBox/com/EventQueue.h>
27
28#include <VBox/com/VirtualBox.h>
29#endif /* !VBOX_ONLY_DOCS */
30
31#include <iprt/cidr.h>
32#include <iprt/ctype.h>
33#include <iprt/file.h>
34#include <iprt/param.h>
35#include <iprt/path.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38#include <iprt/getopt.h>
39#include <VBox/log.h>
40#include "VBoxManage.h"
41
42#ifndef VBOX_ONLY_DOCS
43using namespace com;
44/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
45#if defined(_MSC_VER)
46# pragma optimize("g", off)
47#endif
48
49enum
50{
51 MODIFYVM_NAME = 1000,
52 MODIFYVM_GROUPS,
53 MODIFYVM_OSTYPE,
54 MODIFYVM_MEMORY,
55 MODIFYVM_PAGEFUSION,
56 MODIFYVM_VRAM,
57 MODIFYVM_FIRMWARE,
58 MODIFYVM_ACPI,
59 MODIFYVM_IOAPIC,
60 MODIFYVM_PAE,
61 MODIFYVM_SYNTHCPU,
62 MODIFYVM_HWVIRTEX,
63 MODIFYVM_HWVIRTEXEXCLUSIVE,
64 MODIFYVM_NESTEDPAGING,
65 MODIFYVM_LARGEPAGES,
66 MODIFYVM_VTXVPID,
67 MODIFYVM_CPUS,
68 MODIFYVM_CPUHOTPLUG,
69 MODIFYVM_PLUGCPU,
70 MODIFYVM_UNPLUGCPU,
71 MODIFYVM_SETCPUID,
72 MODIFYVM_DELCPUID,
73 MODIFYVM_DELALLCPUID,
74 MODIFYVM_GRAPHICSCONTROLLER,
75 MODIFYVM_MONITORCOUNT,
76 MODIFYVM_ACCELERATE3D,
77#ifdef VBOX_WITH_VIDEOHWACCEL
78 MODIFYVM_ACCELERATE2DVIDEO,
79#endif
80 MODIFYVM_BIOSLOGOFADEIN,
81 MODIFYVM_BIOSLOGOFADEOUT,
82 MODIFYVM_BIOSLOGODISPLAYTIME,
83 MODIFYVM_BIOSLOGOIMAGEPATH,
84 MODIFYVM_BIOSBOOTMENU,
85 MODIFYVM_BIOSSYSTEMTIMEOFFSET,
86 MODIFYVM_BIOSPXEDEBUG,
87 MODIFYVM_BOOT,
88 MODIFYVM_HDA, // deprecated
89 MODIFYVM_HDB, // deprecated
90 MODIFYVM_HDD, // deprecated
91 MODIFYVM_IDECONTROLLER, // deprecated
92 MODIFYVM_SATAPORTCOUNT, // deprecated
93 MODIFYVM_SATAPORT, // deprecated
94 MODIFYVM_SATA, // deprecated
95 MODIFYVM_SCSIPORT, // deprecated
96 MODIFYVM_SCSITYPE, // deprecated
97 MODIFYVM_SCSI, // deprecated
98 MODIFYVM_DVDPASSTHROUGH, // deprecated
99 MODIFYVM_DVD, // deprecated
100 MODIFYVM_FLOPPY, // deprecated
101 MODIFYVM_NICTRACEFILE,
102 MODIFYVM_NICTRACE,
103 MODIFYVM_NICPROPERTY,
104 MODIFYVM_NICTYPE,
105 MODIFYVM_NICSPEED,
106 MODIFYVM_NICBOOTPRIO,
107 MODIFYVM_NICPROMISC,
108 MODIFYVM_NICBWGROUP,
109 MODIFYVM_NIC,
110 MODIFYVM_CABLECONNECTED,
111 MODIFYVM_BRIDGEADAPTER,
112 MODIFYVM_HOSTONLYADAPTER,
113 MODIFYVM_INTNET,
114 MODIFYVM_NATNET,
115 MODIFYVM_GENERICDRV,
116 MODIFYVM_NATBINDIP,
117 MODIFYVM_NATSETTINGS,
118 MODIFYVM_NATPF,
119 MODIFYVM_NATALIASMODE,
120 MODIFYVM_NATTFTPPREFIX,
121 MODIFYVM_NATTFTPFILE,
122 MODIFYVM_NATTFTPSERVER,
123 MODIFYVM_NATDNSPASSDOMAIN,
124 MODIFYVM_NATDNSPROXY,
125 MODIFYVM_NATDNSHOSTRESOLVER,
126 MODIFYVM_MACADDRESS,
127 MODIFYVM_HIDPTR,
128 MODIFYVM_HIDKBD,
129 MODIFYVM_UARTMODE,
130 MODIFYVM_UART,
131#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
132 MODIFYVM_LPTMODE,
133 MODIFYVM_LPT,
134#endif
135 MODIFYVM_GUESTMEMORYBALLOON,
136 MODIFYVM_AUDIOCONTROLLER,
137 MODIFYVM_AUDIO,
138 MODIFYVM_CLIPBOARD,
139 MODIFYVM_DRAGANDDROP,
140 MODIFYVM_VRDPPORT, /* VRDE: deprecated */
141 MODIFYVM_VRDPADDRESS, /* VRDE: deprecated */
142 MODIFYVM_VRDPAUTHTYPE, /* VRDE: deprecated */
143 MODIFYVM_VRDPMULTICON, /* VRDE: deprecated */
144 MODIFYVM_VRDPREUSECON, /* VRDE: deprecated */
145 MODIFYVM_VRDPVIDEOCHANNEL, /* VRDE: deprecated */
146 MODIFYVM_VRDPVIDEOCHANNELQUALITY, /* VRDE: deprecated */
147 MODIFYVM_VRDP, /* VRDE: deprecated */
148 MODIFYVM_VRDEPROPERTY,
149 MODIFYVM_VRDEPORT,
150 MODIFYVM_VRDEADDRESS,
151 MODIFYVM_VRDEAUTHTYPE,
152 MODIFYVM_VRDEAUTHLIBRARY,
153 MODIFYVM_VRDEMULTICON,
154 MODIFYVM_VRDEREUSECON,
155 MODIFYVM_VRDEVIDEOCHANNEL,
156 MODIFYVM_VRDEVIDEOCHANNELQUALITY,
157 MODIFYVM_VRDE_EXTPACK,
158 MODIFYVM_VRDE,
159 MODIFYVM_RTCUSEUTC,
160 MODIFYVM_USBEHCI,
161 MODIFYVM_USB,
162 MODIFYVM_SNAPSHOTFOLDER,
163 MODIFYVM_TELEPORTER_ENABLED,
164 MODIFYVM_TELEPORTER_PORT,
165 MODIFYVM_TELEPORTER_ADDRESS,
166 MODIFYVM_TELEPORTER_PASSWORD,
167 MODIFYVM_TELEPORTER_PASSWORD_FILE,
168 MODIFYVM_TRACING_ENABLED,
169 MODIFYVM_TRACING_CONFIG,
170 MODIFYVM_TRACING_ALLOW_VM_ACCESS,
171 MODIFYVM_HARDWARE_UUID,
172 MODIFYVM_HPET,
173 MODIFYVM_IOCACHE,
174 MODIFYVM_IOCACHESIZE,
175 MODIFYVM_FAULT_TOLERANCE,
176 MODIFYVM_FAULT_TOLERANCE_ADDRESS,
177 MODIFYVM_FAULT_TOLERANCE_PORT,
178 MODIFYVM_FAULT_TOLERANCE_PASSWORD,
179 MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL,
180 MODIFYVM_CPU_EXECTUION_CAP,
181 MODIFYVM_AUTOSTART_ENABLED,
182 MODIFYVM_AUTOSTART_DELAY,
183 MODIFYVM_AUTOSTOP_TYPE,
184#ifdef VBOX_WITH_PCI_PASSTHROUGH
185 MODIFYVM_ATTACH_PCI,
186 MODIFYVM_DETACH_PCI,
187#endif
188#ifdef VBOX_WITH_USB_VIDEO
189 MODIFYVM_USBWEBCAM,
190#endif
191#ifdef VBOX_WITH_USB_CARDREADER
192 MODIFYVM_USBCARDREADER,
193#endif
194#ifdef VBOX_WITH_VPX
195 MODIFYVM_VCP,
196 MODIFYVM_VCP_FILENAME,
197 MODIFYVM_VCP_WIDTH,
198 MODIFYVM_VCP_HEIGHT,
199 MODIFYVM_VCP_RATE,
200#endif
201 MODIFYVM_CHIPSET,
202 MODIFYVM_DEFAULTFRONTEND
203};
204
205static const RTGETOPTDEF g_aModifyVMOptions[] =
206{
207 { "--name", MODIFYVM_NAME, RTGETOPT_REQ_STRING },
208 { "--groups", MODIFYVM_GROUPS, RTGETOPT_REQ_STRING },
209 { "--ostype", MODIFYVM_OSTYPE, RTGETOPT_REQ_STRING },
210 { "--memory", MODIFYVM_MEMORY, RTGETOPT_REQ_UINT32 },
211 { "--pagefusion", MODIFYVM_PAGEFUSION, RTGETOPT_REQ_BOOL_ONOFF },
212 { "--vram", MODIFYVM_VRAM, RTGETOPT_REQ_UINT32 },
213 { "--firmware", MODIFYVM_FIRMWARE, RTGETOPT_REQ_STRING },
214 { "--acpi", MODIFYVM_ACPI, RTGETOPT_REQ_BOOL_ONOFF },
215 { "--ioapic", MODIFYVM_IOAPIC, RTGETOPT_REQ_BOOL_ONOFF },
216 { "--pae", MODIFYVM_PAE, RTGETOPT_REQ_BOOL_ONOFF },
217 { "--synthcpu", MODIFYVM_SYNTHCPU, RTGETOPT_REQ_BOOL_ONOFF },
218 { "--hwvirtex", MODIFYVM_HWVIRTEX, RTGETOPT_REQ_BOOL_ONOFF },
219 { "--hwvirtexexcl", MODIFYVM_HWVIRTEXEXCLUSIVE, RTGETOPT_REQ_BOOL_ONOFF },
220 { "--nestedpaging", MODIFYVM_NESTEDPAGING, RTGETOPT_REQ_BOOL_ONOFF },
221 { "--largepages", MODIFYVM_LARGEPAGES, RTGETOPT_REQ_BOOL_ONOFF },
222 { "--vtxvpid", MODIFYVM_VTXVPID, RTGETOPT_REQ_BOOL_ONOFF },
223 { "--cpuidset", MODIFYVM_SETCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
224 { "--cpuidremove", MODIFYVM_DELCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
225 { "--cpuidremoveall", MODIFYVM_DELALLCPUID, RTGETOPT_REQ_NOTHING},
226 { "--cpus", MODIFYVM_CPUS, RTGETOPT_REQ_UINT32 },
227 { "--cpuhotplug", MODIFYVM_CPUHOTPLUG, RTGETOPT_REQ_BOOL_ONOFF },
228 { "--plugcpu", MODIFYVM_PLUGCPU, RTGETOPT_REQ_UINT32 },
229 { "--unplugcpu", MODIFYVM_UNPLUGCPU, RTGETOPT_REQ_UINT32 },
230 { "--cpuexecutioncap", MODIFYVM_CPU_EXECTUION_CAP, RTGETOPT_REQ_UINT32 },
231 { "--rtcuseutc", MODIFYVM_RTCUSEUTC, RTGETOPT_REQ_BOOL_ONOFF },
232 { "--graphicscontroller", MODIFYVM_GRAPHICSCONTROLLER, RTGETOPT_REQ_STRING },
233 { "--monitorcount", MODIFYVM_MONITORCOUNT, RTGETOPT_REQ_UINT32 },
234 { "--accelerate3d", MODIFYVM_ACCELERATE3D, RTGETOPT_REQ_BOOL_ONOFF },
235#ifdef VBOX_WITH_VIDEOHWACCEL
236 { "--accelerate2dvideo", MODIFYVM_ACCELERATE2DVIDEO, RTGETOPT_REQ_BOOL_ONOFF },
237#endif
238 { "--bioslogofadein", MODIFYVM_BIOSLOGOFADEIN, RTGETOPT_REQ_BOOL_ONOFF },
239 { "--bioslogofadeout", MODIFYVM_BIOSLOGOFADEOUT, RTGETOPT_REQ_BOOL_ONOFF },
240 { "--bioslogodisplaytime", MODIFYVM_BIOSLOGODISPLAYTIME, RTGETOPT_REQ_UINT32 },
241 { "--bioslogoimagepath", MODIFYVM_BIOSLOGOIMAGEPATH, RTGETOPT_REQ_STRING },
242 { "--biosbootmenu", MODIFYVM_BIOSBOOTMENU, RTGETOPT_REQ_STRING },
243 { "--biossystemtimeoffset", MODIFYVM_BIOSSYSTEMTIMEOFFSET, RTGETOPT_REQ_INT64 },
244 { "--biospxedebug", MODIFYVM_BIOSPXEDEBUG, RTGETOPT_REQ_BOOL_ONOFF },
245 { "--boot", MODIFYVM_BOOT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
246 { "--hda", MODIFYVM_HDA, RTGETOPT_REQ_STRING },
247 { "--hdb", MODIFYVM_HDB, RTGETOPT_REQ_STRING },
248 { "--hdd", MODIFYVM_HDD, RTGETOPT_REQ_STRING },
249 { "--idecontroller", MODIFYVM_IDECONTROLLER, RTGETOPT_REQ_STRING },
250 { "--sataportcount", MODIFYVM_SATAPORTCOUNT, RTGETOPT_REQ_UINT32 },
251 { "--sataport", MODIFYVM_SATAPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
252 { "--sata", MODIFYVM_SATA, RTGETOPT_REQ_STRING },
253 { "--scsiport", MODIFYVM_SCSIPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
254 { "--scsitype", MODIFYVM_SCSITYPE, RTGETOPT_REQ_STRING },
255 { "--scsi", MODIFYVM_SCSI, RTGETOPT_REQ_STRING },
256 { "--dvdpassthrough", MODIFYVM_DVDPASSTHROUGH, RTGETOPT_REQ_STRING },
257 { "--dvd", MODIFYVM_DVD, RTGETOPT_REQ_STRING },
258 { "--floppy", MODIFYVM_FLOPPY, RTGETOPT_REQ_STRING },
259 { "--nictracefile", MODIFYVM_NICTRACEFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
260 { "--nictrace", MODIFYVM_NICTRACE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
261 { "--nicproperty", MODIFYVM_NICPROPERTY, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
262 { "--nictype", MODIFYVM_NICTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
263 { "--nicspeed", MODIFYVM_NICSPEED, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
264 { "--nicbootprio", MODIFYVM_NICBOOTPRIO, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
265 { "--nicpromisc", MODIFYVM_NICPROMISC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
266 { "--nicbandwidthgroup", MODIFYVM_NICBWGROUP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
267 { "--nic", MODIFYVM_NIC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
268 { "--cableconnected", MODIFYVM_CABLECONNECTED, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
269 { "--bridgeadapter", MODIFYVM_BRIDGEADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
270 { "--hostonlyadapter", MODIFYVM_HOSTONLYADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
271 { "--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
272 { "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
273 { "--nicgenericdrv", MODIFYVM_GENERICDRV, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
274 { "--natbindip", MODIFYVM_NATBINDIP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
275 { "--natsettings", MODIFYVM_NATSETTINGS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
276 { "--natpf", MODIFYVM_NATPF, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
277 { "--nataliasmode", MODIFYVM_NATALIASMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
278 { "--nattftpprefix", MODIFYVM_NATTFTPPREFIX, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
279 { "--nattftpfile", MODIFYVM_NATTFTPFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
280 { "--nattftpserver", MODIFYVM_NATTFTPSERVER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
281 { "--natdnspassdomain", MODIFYVM_NATDNSPASSDOMAIN, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
282 { "--natdnsproxy", MODIFYVM_NATDNSPROXY, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
283 { "--natdnshostresolver", MODIFYVM_NATDNSHOSTRESOLVER, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
284 { "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
285 { "--mouse", MODIFYVM_HIDPTR, RTGETOPT_REQ_STRING },
286 { "--keyboard", MODIFYVM_HIDKBD, RTGETOPT_REQ_STRING },
287 { "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
288 { "--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
289#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
290 { "--lptmode", MODIFYVM_LPTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
291 { "--lpt", MODIFYVM_LPT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
292#endif
293 { "--guestmemoryballoon", MODIFYVM_GUESTMEMORYBALLOON, RTGETOPT_REQ_UINT32 },
294 { "--audiocontroller", MODIFYVM_AUDIOCONTROLLER, RTGETOPT_REQ_STRING },
295 { "--audio", MODIFYVM_AUDIO, RTGETOPT_REQ_STRING },
296 { "--clipboard", MODIFYVM_CLIPBOARD, RTGETOPT_REQ_STRING },
297 { "--draganddrop", MODIFYVM_DRAGANDDROP, RTGETOPT_REQ_STRING },
298 { "--vrdpport", MODIFYVM_VRDPPORT, RTGETOPT_REQ_STRING }, /* deprecated */
299 { "--vrdpaddress", MODIFYVM_VRDPADDRESS, RTGETOPT_REQ_STRING }, /* deprecated */
300 { "--vrdpauthtype", MODIFYVM_VRDPAUTHTYPE, RTGETOPT_REQ_STRING }, /* deprecated */
301 { "--vrdpmulticon", MODIFYVM_VRDPMULTICON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
302 { "--vrdpreusecon", MODIFYVM_VRDPREUSECON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
303 { "--vrdpvideochannel", MODIFYVM_VRDPVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
304 { "--vrdpvideochannelquality", MODIFYVM_VRDPVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING }, /* deprecated */
305 { "--vrdp", MODIFYVM_VRDP, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
306 { "--vrdeproperty", MODIFYVM_VRDEPROPERTY, RTGETOPT_REQ_STRING },
307 { "--vrdeport", MODIFYVM_VRDEPORT, RTGETOPT_REQ_STRING },
308 { "--vrdeaddress", MODIFYVM_VRDEADDRESS, RTGETOPT_REQ_STRING },
309 { "--vrdeauthtype", MODIFYVM_VRDEAUTHTYPE, RTGETOPT_REQ_STRING },
310 { "--vrdeauthlibrary", MODIFYVM_VRDEAUTHLIBRARY, RTGETOPT_REQ_STRING },
311 { "--vrdemulticon", MODIFYVM_VRDEMULTICON, RTGETOPT_REQ_BOOL_ONOFF },
312 { "--vrdereusecon", MODIFYVM_VRDEREUSECON, RTGETOPT_REQ_BOOL_ONOFF },
313 { "--vrdevideochannel", MODIFYVM_VRDEVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF },
314 { "--vrdevideochannelquality", MODIFYVM_VRDEVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING },
315 { "--vrdeextpack", MODIFYVM_VRDE_EXTPACK, RTGETOPT_REQ_STRING },
316 { "--vrde", MODIFYVM_VRDE, RTGETOPT_REQ_BOOL_ONOFF },
317 { "--usbehci", MODIFYVM_USBEHCI, RTGETOPT_REQ_BOOL_ONOFF },
318 { "--usb", MODIFYVM_USB, RTGETOPT_REQ_BOOL_ONOFF },
319 { "--snapshotfolder", MODIFYVM_SNAPSHOTFOLDER, RTGETOPT_REQ_STRING },
320 { "--teleporter", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
321 { "--teleporterenabled", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
322 { "--teleporterport", MODIFYVM_TELEPORTER_PORT, RTGETOPT_REQ_UINT32 },
323 { "--teleporteraddress", MODIFYVM_TELEPORTER_ADDRESS, RTGETOPT_REQ_STRING },
324 { "--teleporterpassword", MODIFYVM_TELEPORTER_PASSWORD, RTGETOPT_REQ_STRING },
325 { "--teleporterpasswordfile", MODIFYVM_TELEPORTER_PASSWORD_FILE, RTGETOPT_REQ_STRING },
326 { "--tracing-enabled", MODIFYVM_TRACING_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
327 { "--tracing-config", MODIFYVM_TRACING_CONFIG, RTGETOPT_REQ_STRING },
328 { "--tracing-allow-vm-access", MODIFYVM_TRACING_ALLOW_VM_ACCESS, RTGETOPT_REQ_BOOL_ONOFF },
329 { "--hardwareuuid", MODIFYVM_HARDWARE_UUID, RTGETOPT_REQ_STRING },
330 { "--hpet", MODIFYVM_HPET, RTGETOPT_REQ_BOOL_ONOFF },
331 { "--iocache", MODIFYVM_IOCACHE, RTGETOPT_REQ_BOOL_ONOFF },
332 { "--iocachesize", MODIFYVM_IOCACHESIZE, RTGETOPT_REQ_UINT32 },
333 { "--faulttolerance", MODIFYVM_FAULT_TOLERANCE, RTGETOPT_REQ_STRING },
334 { "--faulttoleranceaddress", MODIFYVM_FAULT_TOLERANCE_ADDRESS, RTGETOPT_REQ_STRING },
335 { "--faulttoleranceport", MODIFYVM_FAULT_TOLERANCE_PORT, RTGETOPT_REQ_UINT32 },
336 { "--faulttolerancepassword", MODIFYVM_FAULT_TOLERANCE_PASSWORD, RTGETOPT_REQ_STRING },
337 { "--faulttolerancesyncinterval", MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL, RTGETOPT_REQ_UINT32 },
338 { "--chipset", MODIFYVM_CHIPSET, RTGETOPT_REQ_STRING },
339#ifdef VBOX_WITH_VPX
340 { "--vcpenabled", MODIFYVM_VCP, RTGETOPT_REQ_BOOL_ONOFF },
341 { "--vcpfile", MODIFYVM_VCP_FILENAME, RTGETOPT_REQ_STRING },
342 { "--vcpwidth", MODIFYVM_VCP_WIDTH, RTGETOPT_REQ_UINT32 },
343 { "--vcpheight", MODIFYVM_VCP_HEIGHT, RTGETOPT_REQ_UINT32 },
344 { "--vcprate", MODIFYVM_VCP_RATE, RTGETOPT_REQ_UINT32 },
345#endif
346 { "--autostart-enabled", MODIFYVM_AUTOSTART_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
347 { "--autostart-delay", MODIFYVM_AUTOSTART_DELAY, RTGETOPT_REQ_UINT32 },
348 { "--autostop-type", MODIFYVM_AUTOSTOP_TYPE, RTGETOPT_REQ_STRING },
349#ifdef VBOX_WITH_PCI_PASSTHROUGH
350 { "--pciattach", MODIFYVM_ATTACH_PCI, RTGETOPT_REQ_STRING },
351 { "--pcidetach", MODIFYVM_DETACH_PCI, RTGETOPT_REQ_STRING },
352#endif
353#ifdef VBOX_WITH_USB_VIDEO
354 { "--usbwebcam", MODIFYVM_USBWEBCAM, RTGETOPT_REQ_BOOL_ONOFF },
355#endif
356#ifdef VBOX_WITH_USB_CARDREADER
357 { "--usbcardreader", MODIFYVM_USBCARDREADER, RTGETOPT_REQ_BOOL_ONOFF },
358#endif
359 { "--defaultfrontend", MODIFYVM_DEFAULTFRONTEND, RTGETOPT_REQ_STRING },
360};
361
362static void vrdeWarningDeprecatedOption(const char *pszOption)
363{
364 RTStrmPrintf(g_pStdErr, "Warning: '--vrdp%s' is deprecated. Use '--vrde%s'.\n", pszOption, pszOption);
365}
366
367/** Parse PCI address in format 01:02.03 and convert it to the numeric representation. */
368static int32_t parsePci(const char* szPciAddr)
369{
370 char* pszNext = (char*)szPciAddr;
371 int rc;
372 uint8_t aVals[3] = {0, 0, 0};
373
374 rc = RTStrToUInt8Ex(pszNext, &pszNext, 16, &aVals[0]);
375 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != ':')
376 return -1;
377
378 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[1]);
379 if (RT_FAILURE(rc) || pszNext == NULL || *pszNext != '.')
380 return -1;
381
382 rc = RTStrToUInt8Ex(pszNext+1, &pszNext, 16, &aVals[2]);
383 if (RT_FAILURE(rc) || pszNext == NULL)
384 return -1;
385
386 return (aVals[0] << 8) | (aVals[1] << 3) | (aVals[2] << 0);
387}
388
389void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups)
390{
391 while (pcszGroups)
392 {
393 char *pComma = RTStrStr(pcszGroups, ",");
394 if (pComma)
395 {
396 Bstr(pcszGroups, pComma - pcszGroups).detachTo(pGroups->appendedRaw());
397 pcszGroups = pComma + 1;
398 }
399 else
400 {
401 Bstr(pcszGroups).detachTo(pGroups->appendedRaw());
402 pcszGroups = NULL;
403 }
404 }
405}
406
407int handleModifyVM(HandlerArg *a)
408{
409 int c;
410 HRESULT rc;
411 Bstr name;
412 RTGETOPTUNION ValueUnion;
413 RTGETOPTSTATE GetOptState;
414 ComPtr <IMachine> machine;
415 ComPtr <IBIOSSettings> biosSettings;
416
417 /* VM ID + at least one parameter. Parameter arguments are checked
418 * individually. */
419 if (a->argc < 2)
420 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
421
422 /* try to find the given machine */
423 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
424 machine.asOutParam()), 1);
425
426
427 /* Get the number of network adapters */
428 ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, machine);
429
430 /* open a session for the VM */
431 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), 1);
432
433 /* get the mutable session machine */
434 CHECK_ERROR_RET(a->session, COMGETTER(Machine)(machine.asOutParam()), 1);
435 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
436
437 RTGetOptInit(&GetOptState, a->argc, a->argv, g_aModifyVMOptions,
438 RT_ELEMENTS(g_aModifyVMOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
439
440 while ( SUCCEEDED (rc)
441 && (c = RTGetOpt(&GetOptState, &ValueUnion)))
442 {
443 switch (c)
444 {
445 case MODIFYVM_NAME:
446 {
447 CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz).raw()));
448 break;
449 }
450 case MODIFYVM_GROUPS:
451 {
452 com::SafeArray<BSTR> groups;
453 parseGroups(ValueUnion.psz, &groups);
454 CHECK_ERROR(machine, COMSETTER(Groups)(ComSafeArrayAsInParam(groups)));
455 break;
456 }
457 case MODIFYVM_OSTYPE:
458 {
459 ComPtr<IGuestOSType> guestOSType;
460 CHECK_ERROR(a->virtualBox, GetGuestOSType(Bstr(ValueUnion.psz).raw(),
461 guestOSType.asOutParam()));
462 if (SUCCEEDED(rc) && guestOSType)
463 {
464 CHECK_ERROR(machine, COMSETTER(OSTypeId)(Bstr(ValueUnion.psz).raw()));
465 }
466 else
467 {
468 errorArgument("Invalid guest OS type '%s'", Utf8Str(ValueUnion.psz).c_str());
469 rc = E_FAIL;
470 }
471 break;
472 }
473
474 case MODIFYVM_MEMORY:
475 {
476 CHECK_ERROR(machine, COMSETTER(MemorySize)(ValueUnion.u32));
477 break;
478 }
479
480 case MODIFYVM_PAGEFUSION:
481 {
482 CHECK_ERROR(machine, COMSETTER(PageFusionEnabled)(ValueUnion.f));
483 break;
484 }
485
486 case MODIFYVM_VRAM:
487 {
488 CHECK_ERROR(machine, COMSETTER(VRAMSize)(ValueUnion.u32));
489 break;
490 }
491
492 case MODIFYVM_FIRMWARE:
493 {
494 if (!RTStrICmp(ValueUnion.psz, "efi"))
495 {
496 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI));
497 }
498 else if (!RTStrICmp(ValueUnion.psz, "efi32"))
499 {
500 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI32));
501 }
502 else if (!RTStrICmp(ValueUnion.psz, "efi64"))
503 {
504 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI64));
505 }
506 else if (!RTStrICmp(ValueUnion.psz, "efidual"))
507 {
508 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFIDUAL));
509 }
510 else if (!RTStrICmp(ValueUnion.psz, "bios"))
511 {
512 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_BIOS));
513 }
514 else
515 {
516 errorArgument("Invalid --firmware argument '%s'", ValueUnion.psz);
517 rc = E_FAIL;
518 }
519 break;
520 }
521
522 case MODIFYVM_ACPI:
523 {
524 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(ValueUnion.f));
525 break;
526 }
527
528 case MODIFYVM_IOAPIC:
529 {
530 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(ValueUnion.f));
531 break;
532 }
533
534 case MODIFYVM_PAE:
535 {
536 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_PAE, ValueUnion.f));
537 break;
538 }
539
540 case MODIFYVM_SYNTHCPU:
541 {
542 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_Synthetic, ValueUnion.f));
543 break;
544 }
545
546 case MODIFYVM_HWVIRTEX:
547 {
548 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Enabled, ValueUnion.f));
549 break;
550 }
551
552 case MODIFYVM_HWVIRTEXEXCLUSIVE:
553 {
554 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Exclusive, ValueUnion.f));
555 break;
556 }
557
558 case MODIFYVM_SETCPUID:
559 {
560 uint32_t id = ValueUnion.u32;
561 uint32_t aValue[4];
562
563 for (unsigned i = 0 ; i < 4 ; i++)
564 {
565 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX);
566 if (RT_FAILURE(vrc))
567 return errorSyntax(USAGE_MODIFYVM,
568 "Missing or Invalid argument to '%s'",
569 GetOptState.pDef->pszLong);
570 aValue[i] = ValueUnion.u32;
571 }
572 CHECK_ERROR(machine, SetCPUIDLeaf(id, aValue[0], aValue[1], aValue[2], aValue[3]));
573 break;
574 }
575
576 case MODIFYVM_DELCPUID:
577 {
578 CHECK_ERROR(machine, RemoveCPUIDLeaf(ValueUnion.u32));
579 break;
580 }
581
582 case MODIFYVM_DELALLCPUID:
583 {
584 CHECK_ERROR(machine, RemoveAllCPUIDLeaves());
585 break;
586 }
587
588 case MODIFYVM_NESTEDPAGING:
589 {
590 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, ValueUnion.f));
591 break;
592 }
593
594 case MODIFYVM_LARGEPAGES:
595 {
596 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_LargePages, ValueUnion.f));
597 break;
598 }
599
600 case MODIFYVM_VTXVPID:
601 {
602 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_VPID, ValueUnion.f));
603 break;
604 }
605
606 case MODIFYVM_CPUS:
607 {
608 CHECK_ERROR(machine, COMSETTER(CPUCount)(ValueUnion.u32));
609 break;
610 }
611
612 case MODIFYVM_RTCUSEUTC:
613 {
614 CHECK_ERROR(machine, COMSETTER(RTCUseUTC)(ValueUnion.f));
615 break;
616 }
617
618 case MODIFYVM_CPUHOTPLUG:
619 {
620 CHECK_ERROR(machine, COMSETTER(CPUHotPlugEnabled)(ValueUnion.f));
621 break;
622 }
623
624 case MODIFYVM_PLUGCPU:
625 {
626 CHECK_ERROR(machine, HotPlugCPU(ValueUnion.u32));
627 break;
628 }
629
630 case MODIFYVM_UNPLUGCPU:
631 {
632 CHECK_ERROR(machine, HotUnplugCPU(ValueUnion.u32));
633 break;
634 }
635
636 case MODIFYVM_CPU_EXECTUION_CAP:
637 {
638 CHECK_ERROR(machine, COMSETTER(CPUExecutionCap)(ValueUnion.u32));
639 break;
640 }
641
642 case MODIFYVM_GRAPHICSCONTROLLER:
643 {
644 if ( !RTStrICmp(ValueUnion.psz, "none")
645 || !RTStrICmp(ValueUnion.psz, "disabled"))
646 CHECK_ERROR(machine, COMSETTER(GraphicsControllerType)(GraphicsControllerType_Null));
647 else if ( !RTStrICmp(ValueUnion.psz, "vboxvga")
648 || !RTStrICmp(ValueUnion.psz, "vbox")
649 || !RTStrICmp(ValueUnion.psz, "vga")
650 || !RTStrICmp(ValueUnion.psz, "vesa"))
651 CHECK_ERROR(machine, COMSETTER(GraphicsControllerType)(GraphicsControllerType_VBoxVGA));
652 else
653 {
654 errorArgument("Invalid --graphicscontroller argument '%s'", ValueUnion.psz);
655 rc = E_FAIL;
656 }
657 break;
658 }
659
660 case MODIFYVM_MONITORCOUNT:
661 {
662 CHECK_ERROR(machine, COMSETTER(MonitorCount)(ValueUnion.u32));
663 break;
664 }
665
666 case MODIFYVM_ACCELERATE3D:
667 {
668 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(ValueUnion.f));
669 break;
670 }
671
672#ifdef VBOX_WITH_VIDEOHWACCEL
673 case MODIFYVM_ACCELERATE2DVIDEO:
674 {
675 CHECK_ERROR(machine, COMSETTER(Accelerate2DVideoEnabled)(ValueUnion.f));
676 break;
677 }
678#endif
679
680 case MODIFYVM_BIOSLOGOFADEIN:
681 {
682 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(ValueUnion.f));
683 break;
684 }
685
686 case MODIFYVM_BIOSLOGOFADEOUT:
687 {
688 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(ValueUnion.f));
689 break;
690 }
691
692 case MODIFYVM_BIOSLOGODISPLAYTIME:
693 {
694 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(ValueUnion.u32));
695 break;
696 }
697
698 case MODIFYVM_BIOSLOGOIMAGEPATH:
699 {
700 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(ValueUnion.psz).raw()));
701 break;
702 }
703
704 case MODIFYVM_BIOSBOOTMENU:
705 {
706 if (!RTStrICmp(ValueUnion.psz, "disabled"))
707 {
708 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
709 }
710 else if (!RTStrICmp(ValueUnion.psz, "menuonly"))
711 {
712 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
713 }
714 else if (!RTStrICmp(ValueUnion.psz, "messageandmenu"))
715 {
716 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
717 }
718 else
719 {
720 errorArgument("Invalid --biosbootmenu argument '%s'", ValueUnion.psz);
721 rc = E_FAIL;
722 }
723 break;
724 }
725
726 case MODIFYVM_BIOSSYSTEMTIMEOFFSET:
727 {
728 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(ValueUnion.i64));
729 break;
730 }
731
732 case MODIFYVM_BIOSPXEDEBUG:
733 {
734 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(ValueUnion.f));
735 break;
736 }
737
738 case MODIFYVM_BOOT:
739 {
740 if (!RTStrICmp(ValueUnion.psz, "none"))
741 {
742 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Null));
743 }
744 else if (!RTStrICmp(ValueUnion.psz, "floppy"))
745 {
746 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Floppy));
747 }
748 else if (!RTStrICmp(ValueUnion.psz, "dvd"))
749 {
750 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_DVD));
751 }
752 else if (!RTStrICmp(ValueUnion.psz, "disk"))
753 {
754 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_HardDisk));
755 }
756 else if (!RTStrICmp(ValueUnion.psz, "net"))
757 {
758 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Network));
759 }
760 else
761 return errorArgument("Invalid boot device '%s'", ValueUnion.psz);
762 break;
763 }
764
765 case MODIFYVM_HDA: // deprecated
766 case MODIFYVM_HDB: // deprecated
767 case MODIFYVM_HDD: // deprecated
768 case MODIFYVM_SATAPORT: // deprecated
769 {
770 uint32_t u1 = 0, u2 = 0;
771 Bstr bstrController = L"IDE Controller";
772
773 switch (c)
774 {
775 case MODIFYVM_HDA: // deprecated
776 u1 = 0;
777 break;
778
779 case MODIFYVM_HDB: // deprecated
780 u1 = 0;
781 u2 = 1;
782 break;
783
784 case MODIFYVM_HDD: // deprecated
785 u1 = 1;
786 u2 = 1;
787 break;
788
789 case MODIFYVM_SATAPORT: // deprecated
790 u1 = GetOptState.uIndex;
791 bstrController = L"SATA";
792 break;
793 }
794
795 if (!RTStrICmp(ValueUnion.psz, "none"))
796 {
797 machine->DetachDevice(bstrController.raw(), u1, u2);
798 }
799 else
800 {
801 ComPtr<IMedium> hardDisk;
802 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk,
803 AccessMode_ReadWrite, hardDisk,
804 false /* fForceNewUuidOnOpen */,
805 false /* fSilent */);
806 if (FAILED(rc))
807 break;
808 if (hardDisk)
809 {
810 CHECK_ERROR(machine, AttachDevice(bstrController.raw(),
811 u1, u2,
812 DeviceType_HardDisk,
813 hardDisk));
814 }
815 else
816 rc = E_FAIL;
817 }
818 break;
819 }
820
821 case MODIFYVM_IDECONTROLLER: // deprecated
822 {
823 ComPtr<IStorageController> storageController;
824 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("IDE Controller").raw(),
825 storageController.asOutParam()));
826
827 if (!RTStrICmp(ValueUnion.psz, "PIIX3"))
828 {
829 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
830 }
831 else if (!RTStrICmp(ValueUnion.psz, "PIIX4"))
832 {
833 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
834 }
835 else if (!RTStrICmp(ValueUnion.psz, "ICH6"))
836 {
837 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
838 }
839 else
840 {
841 errorArgument("Invalid --idecontroller argument '%s'", ValueUnion.psz);
842 rc = E_FAIL;
843 }
844 break;
845 }
846
847 case MODIFYVM_SATAPORTCOUNT: // deprecated
848 {
849 ComPtr<IStorageController> SataCtl;
850 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA").raw(),
851 SataCtl.asOutParam()));
852
853 if (SUCCEEDED(rc) && ValueUnion.u32 > 0)
854 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(ValueUnion.u32));
855 break;
856 }
857
858 case MODIFYVM_SATA: // deprecated
859 {
860 if (!RTStrICmp(ValueUnion.psz, "on") || !RTStrICmp(ValueUnion.psz, "enable"))
861 {
862 ComPtr<IStorageController> ctl;
863 CHECK_ERROR(machine, AddStorageController(Bstr("SATA").raw(),
864 StorageBus_SATA,
865 ctl.asOutParam()));
866 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
867 }
868 else if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
869 CHECK_ERROR(machine, RemoveStorageController(Bstr("SATA").raw()));
870 else
871 return errorArgument("Invalid --usb argument '%s'", ValueUnion.psz);
872 break;
873 }
874
875 case MODIFYVM_SCSIPORT: // deprecated
876 {
877 if (!RTStrICmp(ValueUnion.psz, "none"))
878 {
879 rc = machine->DetachDevice(Bstr("LsiLogic").raw(),
880 GetOptState.uIndex, 0);
881 if (FAILED(rc))
882 CHECK_ERROR(machine, DetachDevice(Bstr("BusLogic").raw(),
883 GetOptState.uIndex, 0));
884 }
885 else
886 {
887 ComPtr<IMedium> hardDisk;
888 rc = openMedium(a, ValueUnion.psz, DeviceType_HardDisk,
889 AccessMode_ReadWrite, hardDisk,
890 false /* fForceNewUuidOnOpen */,
891 false /* fSilent */);
892 if (FAILED(rc))
893 break;
894 if (hardDisk)
895 {
896 rc = machine->AttachDevice(Bstr("LsiLogic").raw(),
897 GetOptState.uIndex, 0,
898 DeviceType_HardDisk,
899 hardDisk);
900 if (FAILED(rc))
901 CHECK_ERROR(machine,
902 AttachDevice(Bstr("BusLogic").raw(),
903 GetOptState.uIndex, 0,
904 DeviceType_HardDisk,
905 hardDisk));
906 }
907 else
908 rc = E_FAIL;
909 }
910 break;
911 }
912
913 case MODIFYVM_SCSITYPE: // deprecated
914 {
915 ComPtr<IStorageController> ctl;
916
917 if (!RTStrICmp(ValueUnion.psz, "LsiLogic"))
918 {
919 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
920 if (FAILED(rc))
921 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
922
923 CHECK_ERROR(machine,
924 AddStorageController(Bstr("LsiLogic").raw(),
925 StorageBus_SCSI,
926 ctl.asOutParam()));
927
928 if (SUCCEEDED(rc))
929 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
930 }
931 else if (!RTStrICmp(ValueUnion.psz, "BusLogic"))
932 {
933 rc = machine->RemoveStorageController(Bstr("LsiLogic").raw());
934 if (FAILED(rc))
935 CHECK_ERROR(machine, RemoveStorageController(Bstr("BusLogic").raw()));
936
937 CHECK_ERROR(machine,
938 AddStorageController(Bstr("BusLogic").raw(),
939 StorageBus_SCSI,
940 ctl.asOutParam()));
941
942 if (SUCCEEDED(rc))
943 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
944 }
945 else
946 return errorArgument("Invalid --scsitype argument '%s'", ValueUnion.psz);
947 break;
948 }
949
950 case MODIFYVM_SCSI: // deprecated
951 {
952 if (!RTStrICmp(ValueUnion.psz, "on") || !RTStrICmp(ValueUnion.psz, "enable"))
953 {
954 ComPtr<IStorageController> ctl;
955
956 CHECK_ERROR(machine, AddStorageController(Bstr("BusLogic").raw(),
957 StorageBus_SCSI,
958 ctl.asOutParam()));
959 if (SUCCEEDED(rc))
960 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
961 }
962 else if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
963 {
964 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
965 if (FAILED(rc))
966 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
967 }
968 break;
969 }
970
971 case MODIFYVM_DVDPASSTHROUGH: // deprecated
972 {
973 CHECK_ERROR(machine, PassthroughDevice(Bstr("IDE Controller").raw(),
974 1, 0,
975 !RTStrICmp(ValueUnion.psz, "on")));
976 break;
977 }
978
979 case MODIFYVM_DVD: // deprecated
980 {
981 ComPtr<IMedium> dvdMedium;
982
983 /* unmount? */
984 if (!RTStrICmp(ValueUnion.psz, "none"))
985 {
986 /* nothing to do, NULL object will cause unmount */
987 }
988 /* host drive? */
989 else if (!RTStrNICmp(ValueUnion.psz, "host:", 5))
990 {
991 ComPtr<IHost> host;
992 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
993 rc = host->FindHostDVDDrive(Bstr(ValueUnion.psz + 5).raw(),
994 dvdMedium.asOutParam());
995 if (!dvdMedium)
996 {
997 /* 2nd try: try with the real name, important on Linux+libhal */
998 char szPathReal[RTPATH_MAX];
999 if (RT_FAILURE(RTPathReal(ValueUnion.psz + 5, szPathReal, sizeof(szPathReal))))
1000 {
1001 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
1002 rc = E_FAIL;
1003 break;
1004 }
1005 rc = host->FindHostDVDDrive(Bstr(szPathReal).raw(),
1006 dvdMedium.asOutParam());
1007 if (!dvdMedium)
1008 {
1009 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
1010 rc = E_FAIL;
1011 break;
1012 }
1013 }
1014 }
1015 else
1016 {
1017 rc = openMedium(a, ValueUnion.psz, DeviceType_DVD,
1018 AccessMode_ReadOnly, dvdMedium,
1019 false /* fForceNewUuidOnOpen */,
1020 false /* fSilent */);
1021 if (FAILED(rc))
1022 break;
1023 if (!dvdMedium)
1024 {
1025 rc = E_FAIL;
1026 break;
1027 }
1028 }
1029
1030 CHECK_ERROR(machine, MountMedium(Bstr("IDE Controller").raw(),
1031 1, 0,
1032 dvdMedium,
1033 FALSE /* aForce */));
1034 break;
1035 }
1036
1037 case MODIFYVM_FLOPPY: // deprecated
1038 {
1039 ComPtr<IMedium> floppyMedium;
1040 ComPtr<IMediumAttachment> floppyAttachment;
1041 machine->GetMediumAttachment(Bstr("Floppy Controller").raw(),
1042 0, 0, floppyAttachment.asOutParam());
1043
1044 /* disable? */
1045 if (!RTStrICmp(ValueUnion.psz, "disabled"))
1046 {
1047 /* disable the controller */
1048 if (floppyAttachment)
1049 CHECK_ERROR(machine, DetachDevice(Bstr("Floppy Controller").raw(),
1050 0, 0));
1051 }
1052 else
1053 {
1054 /* enable the controller */
1055 if (!floppyAttachment)
1056 CHECK_ERROR(machine, AttachDeviceWithoutMedium(Bstr("Floppy Controller").raw(),
1057 0, 0,
1058 DeviceType_Floppy));
1059
1060 /* unmount? */
1061 if ( !RTStrICmp(ValueUnion.psz, "none")
1062 || !RTStrICmp(ValueUnion.psz, "empty")) // deprecated
1063 {
1064 /* nothing to do, NULL object will cause unmount */
1065 }
1066 /* host drive? */
1067 else if (!RTStrNICmp(ValueUnion.psz, "host:", 5))
1068 {
1069 ComPtr<IHost> host;
1070 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1071 rc = host->FindHostFloppyDrive(Bstr(ValueUnion.psz + 5).raw(),
1072 floppyMedium.asOutParam());
1073 if (!floppyMedium)
1074 {
1075 errorArgument("Invalid host floppy drive name \"%s\"", ValueUnion.psz + 5);
1076 rc = E_FAIL;
1077 break;
1078 }
1079 }
1080 else
1081 {
1082 rc = openMedium(a, ValueUnion.psz, DeviceType_Floppy,
1083 AccessMode_ReadWrite, floppyMedium,
1084 false /* fForceNewUuidOnOpen */,
1085 false /* fSilent */);
1086 if (FAILED(rc))
1087 break;
1088 if (!floppyMedium)
1089 {
1090 rc = E_FAIL;
1091 break;
1092 }
1093 }
1094 CHECK_ERROR(machine, MountMedium(Bstr("Floppy Controller").raw(),
1095 0, 0,
1096 floppyMedium,
1097 FALSE /* aForce */));
1098 }
1099 break;
1100 }
1101
1102 case MODIFYVM_NICTRACEFILE:
1103 {
1104 ComPtr<INetworkAdapter> nic;
1105
1106 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1107 ASSERT(nic);
1108
1109 CHECK_ERROR(nic, COMSETTER(TraceFile)(Bstr(ValueUnion.psz).raw()));
1110 break;
1111 }
1112
1113 case MODIFYVM_NICTRACE:
1114 {
1115 ComPtr<INetworkAdapter> nic;
1116
1117 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1118 ASSERT(nic);
1119
1120 CHECK_ERROR(nic, COMSETTER(TraceEnabled)(ValueUnion.f));
1121 break;
1122 }
1123
1124 case MODIFYVM_NICPROPERTY:
1125 {
1126 ComPtr<INetworkAdapter> nic;
1127
1128 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1129 ASSERT(nic);
1130
1131 if (nic)
1132 {
1133 /* Parse 'name=value' */
1134 char *pszProperty = RTStrDup(ValueUnion.psz);
1135 if (pszProperty)
1136 {
1137 char *pDelimiter = strchr(pszProperty, '=');
1138 if (pDelimiter)
1139 {
1140 *pDelimiter = '\0';
1141
1142 Bstr bstrName = pszProperty;
1143 Bstr bstrValue = &pDelimiter[1];
1144 CHECK_ERROR(nic, SetProperty(bstrName.raw(), bstrValue.raw()));
1145 }
1146 else
1147 {
1148 errorArgument("Invalid --nicproperty%d argument '%s'", GetOptState.uIndex, ValueUnion.psz);
1149 rc = E_FAIL;
1150 }
1151 RTStrFree(pszProperty);
1152 }
1153 else
1154 {
1155 RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for --nicproperty%d '%s'\n", GetOptState.uIndex, ValueUnion.psz);
1156 rc = E_FAIL;
1157 }
1158 }
1159 break;
1160 }
1161 case MODIFYVM_NICTYPE:
1162 {
1163 ComPtr<INetworkAdapter> nic;
1164
1165 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1166 ASSERT(nic);
1167
1168 if (!RTStrICmp(ValueUnion.psz, "Am79C970A"))
1169 {
1170 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A));
1171 }
1172 else if (!RTStrICmp(ValueUnion.psz, "Am79C973"))
1173 {
1174 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973));
1175 }
1176#ifdef VBOX_WITH_E1000
1177 else if (!RTStrICmp(ValueUnion.psz, "82540EM"))
1178 {
1179 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM));
1180 }
1181 else if (!RTStrICmp(ValueUnion.psz, "82543GC"))
1182 {
1183 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC));
1184 }
1185 else if (!RTStrICmp(ValueUnion.psz, "82545EM"))
1186 {
1187 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82545EM));
1188 }
1189#endif
1190#ifdef VBOX_WITH_VIRTIO
1191 else if (!RTStrICmp(ValueUnion.psz, "virtio"))
1192 {
1193 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio));
1194 }
1195#endif /* VBOX_WITH_VIRTIO */
1196 else
1197 {
1198 errorArgument("Invalid NIC type '%s' specified for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1199 rc = E_FAIL;
1200 }
1201 break;
1202 }
1203
1204 case MODIFYVM_NICSPEED:
1205 {
1206 ComPtr<INetworkAdapter> nic;
1207
1208 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1209 ASSERT(nic);
1210
1211 CHECK_ERROR(nic, COMSETTER(LineSpeed)(ValueUnion.u32));
1212 break;
1213 }
1214
1215 case MODIFYVM_NICBOOTPRIO:
1216 {
1217 ComPtr<INetworkAdapter> nic;
1218
1219 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1220 ASSERT(nic);
1221
1222 /* Somewhat arbitrary limitation - we can pass a list of up to 4 PCI devices
1223 * to the PXE ROM, hence only boot priorities 1-4 are allowed (in addition to
1224 * 0 for the default lowest priority).
1225 */
1226 if (ValueUnion.u32 > 4)
1227 {
1228 errorArgument("Invalid boot priority '%u' specfied for NIC %u", ValueUnion.u32, GetOptState.uIndex);
1229 rc = E_FAIL;
1230 }
1231 else
1232 {
1233 CHECK_ERROR(nic, COMSETTER(BootPriority)(ValueUnion.u32));
1234 }
1235 break;
1236 }
1237
1238 case MODIFYVM_NICPROMISC:
1239 {
1240 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
1241 if (!RTStrICmp(ValueUnion.psz, "deny"))
1242 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_Deny;
1243 else if ( !RTStrICmp(ValueUnion.psz, "allow-vms")
1244 || !RTStrICmp(ValueUnion.psz, "allow-network"))
1245 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowNetwork;
1246 else if (!RTStrICmp(ValueUnion.psz, "allow-all"))
1247 enmPromiscModePolicy = NetworkAdapterPromiscModePolicy_AllowAll;
1248 else
1249 {
1250 errorArgument("Unknown promiscuous mode policy '%s'", ValueUnion.psz);
1251 rc = E_INVALIDARG;
1252 break;
1253 }
1254
1255 ComPtr<INetworkAdapter> nic;
1256 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1257 ASSERT(nic);
1258
1259 CHECK_ERROR(nic, COMSETTER(PromiscModePolicy)(enmPromiscModePolicy));
1260 break;
1261 }
1262
1263 case MODIFYVM_NICBWGROUP:
1264 {
1265 ComPtr<INetworkAdapter> nic;
1266 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1267 ASSERT(nic);
1268
1269 if (!RTStrICmp(ValueUnion.psz, "none"))
1270 {
1271 /* Just remove the bandwidth group. */
1272 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(NULL));
1273 }
1274 else
1275 {
1276 ComPtr<IBandwidthControl> bwCtrl;
1277 ComPtr<IBandwidthGroup> bwGroup;
1278
1279 CHECK_ERROR(machine, COMGETTER(BandwidthControl)(bwCtrl.asOutParam()));
1280
1281 if (SUCCEEDED(rc))
1282 {
1283 CHECK_ERROR(bwCtrl, GetBandwidthGroup(Bstr(ValueUnion.psz).raw(), bwGroup.asOutParam()));
1284 if (SUCCEEDED(rc))
1285 {
1286 CHECK_ERROR(nic, COMSETTER(BandwidthGroup)(bwGroup));
1287 }
1288 }
1289 }
1290 break;
1291 }
1292
1293 case MODIFYVM_NIC:
1294 {
1295 ComPtr<INetworkAdapter> nic;
1296
1297 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1298 ASSERT(nic);
1299
1300 if (!RTStrICmp(ValueUnion.psz, "none"))
1301 {
1302 CHECK_ERROR(nic, COMSETTER(Enabled)(FALSE));
1303 }
1304 else if (!RTStrICmp(ValueUnion.psz, "null"))
1305 {
1306 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1307 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Null));
1308 }
1309 else if (!RTStrICmp(ValueUnion.psz, "nat"))
1310 {
1311 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1312 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_NAT));
1313 }
1314 else if ( !RTStrICmp(ValueUnion.psz, "bridged")
1315 || !RTStrICmp(ValueUnion.psz, "hostif")) /* backward compatibility */
1316 {
1317 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1318 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Bridged));
1319 }
1320 else if (!RTStrICmp(ValueUnion.psz, "intnet"))
1321 {
1322 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1323 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Internal));
1324 }
1325 else if (!RTStrICmp(ValueUnion.psz, "hostonly"))
1326 {
1327
1328 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1329 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_HostOnly));
1330 }
1331 else if (!RTStrICmp(ValueUnion.psz, "generic"))
1332 {
1333
1334 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1335 CHECK_ERROR(nic, COMSETTER(AttachmentType)(NetworkAttachmentType_Generic));
1336 }
1337 else
1338 {
1339 errorArgument("Invalid type '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1340 rc = E_FAIL;
1341 }
1342 break;
1343 }
1344
1345 case MODIFYVM_CABLECONNECTED:
1346 {
1347 ComPtr<INetworkAdapter> nic;
1348
1349 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1350 ASSERT(nic);
1351
1352 CHECK_ERROR(nic, COMSETTER(CableConnected)(ValueUnion.f));
1353 break;
1354 }
1355
1356 case MODIFYVM_BRIDGEADAPTER:
1357 {
1358 ComPtr<INetworkAdapter> nic;
1359
1360 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1361 ASSERT(nic);
1362
1363 /* remove it? */
1364 if (!RTStrICmp(ValueUnion.psz, "none"))
1365 {
1366 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr().raw()));
1367 }
1368 else
1369 {
1370 CHECK_ERROR(nic, COMSETTER(BridgedInterface)(Bstr(ValueUnion.psz).raw()));
1371 }
1372 break;
1373 }
1374
1375 case MODIFYVM_HOSTONLYADAPTER:
1376 {
1377 ComPtr<INetworkAdapter> nic;
1378
1379 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1380 ASSERT(nic);
1381
1382 /* remove it? */
1383 if (!RTStrICmp(ValueUnion.psz, "none"))
1384 {
1385 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr().raw()));
1386 }
1387 else
1388 {
1389 CHECK_ERROR(nic, COMSETTER(HostOnlyInterface)(Bstr(ValueUnion.psz).raw()));
1390 }
1391 break;
1392 }
1393
1394 case MODIFYVM_INTNET:
1395 {
1396 ComPtr<INetworkAdapter> nic;
1397
1398 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1399 ASSERT(nic);
1400
1401 /* remove it? */
1402 if (!RTStrICmp(ValueUnion.psz, "none"))
1403 {
1404 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr().raw()));
1405 }
1406 else
1407 {
1408 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr(ValueUnion.psz).raw()));
1409 }
1410 break;
1411 }
1412
1413 case MODIFYVM_GENERICDRV:
1414 {
1415 ComPtr<INetworkAdapter> nic;
1416
1417 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1418 ASSERT(nic);
1419
1420 CHECK_ERROR(nic, COMSETTER(GenericDriver)(Bstr(ValueUnion.psz).raw()));
1421 break;
1422 }
1423
1424 case MODIFYVM_NATNET:
1425 {
1426 ComPtr<INetworkAdapter> nic;
1427 ComPtr<INATEngine> engine;
1428
1429 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1430 ASSERT(nic);
1431
1432 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1433
1434 const char *psz = ValueUnion.psz;
1435 if (!RTStrICmp("default", psz))
1436 psz = "";
1437
1438 CHECK_ERROR(engine, COMSETTER(Network)(Bstr(psz).raw()));
1439 break;
1440 }
1441
1442 case MODIFYVM_NATBINDIP:
1443 {
1444 ComPtr<INetworkAdapter> nic;
1445 ComPtr<INATEngine> engine;
1446
1447 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1448 ASSERT(nic);
1449
1450 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1451 CHECK_ERROR(engine, COMSETTER(HostIP)(Bstr(ValueUnion.psz).raw()));
1452 break;
1453 }
1454
1455#define ITERATE_TO_NEXT_TERM(ch) \
1456 do { \
1457 while (*ch != ',') \
1458 { \
1459 if (*ch == 0) \
1460 { \
1461 return errorSyntax(USAGE_MODIFYVM, \
1462 "Missing or Invalid argument to '%s'", \
1463 GetOptState.pDef->pszLong); \
1464 } \
1465 ch++; \
1466 } \
1467 *ch = '\0'; \
1468 ch++; \
1469 } while(0)
1470
1471 case MODIFYVM_NATSETTINGS:
1472 {
1473 ComPtr<INetworkAdapter> nic;
1474 ComPtr<INATEngine> engine;
1475 char *strMtu;
1476 char *strSockSnd;
1477 char *strSockRcv;
1478 char *strTcpSnd;
1479 char *strTcpRcv;
1480 char *strRaw = RTStrDup(ValueUnion.psz);
1481 char *ch = strRaw;
1482 strMtu = RTStrStrip(ch);
1483 ITERATE_TO_NEXT_TERM(ch);
1484 strSockSnd = RTStrStrip(ch);
1485 ITERATE_TO_NEXT_TERM(ch);
1486 strSockRcv = RTStrStrip(ch);
1487 ITERATE_TO_NEXT_TERM(ch);
1488 strTcpSnd = RTStrStrip(ch);
1489 ITERATE_TO_NEXT_TERM(ch);
1490 strTcpRcv = RTStrStrip(ch);
1491
1492 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1493 ASSERT(nic);
1494
1495 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1496 CHECK_ERROR(engine, SetNetworkSettings(RTStrToUInt32(strMtu), RTStrToUInt32(strSockSnd), RTStrToUInt32(strSockRcv),
1497 RTStrToUInt32(strTcpSnd), RTStrToUInt32(strTcpRcv)));
1498 break;
1499 }
1500
1501
1502 case MODIFYVM_NATPF:
1503 {
1504 ComPtr<INetworkAdapter> nic;
1505 ComPtr<INATEngine> engine;
1506
1507 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1508 ASSERT(nic);
1509
1510 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1511 /* format name:proto:hostip:hostport:guestip:guestport*/
1512 if (RTStrCmp(ValueUnion.psz, "delete") != 0)
1513 {
1514 char *strName;
1515 char *strProto;
1516 char *strHostIp;
1517 char *strHostPort;
1518 char *strGuestIp;
1519 char *strGuestPort;
1520 char *strRaw = RTStrDup(ValueUnion.psz);
1521 char *ch = strRaw;
1522 strName = RTStrStrip(ch);
1523 ITERATE_TO_NEXT_TERM(ch);
1524 strProto = RTStrStrip(ch);
1525 ITERATE_TO_NEXT_TERM(ch);
1526 strHostIp = RTStrStrip(ch);
1527 ITERATE_TO_NEXT_TERM(ch);
1528 strHostPort = RTStrStrip(ch);
1529 ITERATE_TO_NEXT_TERM(ch);
1530 strGuestIp = RTStrStrip(ch);
1531 ITERATE_TO_NEXT_TERM(ch);
1532 strGuestPort = RTStrStrip(ch);
1533 NATProtocol_T proto;
1534 if (RTStrICmp(strProto, "udp") == 0)
1535 proto = NATProtocol_UDP;
1536 else if (RTStrICmp(strProto, "tcp") == 0)
1537 proto = NATProtocol_TCP;
1538 else
1539 {
1540 errorArgument("Invalid proto '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1541 rc = E_FAIL;
1542 break;
1543 }
1544 CHECK_ERROR(engine, AddRedirect(Bstr(strName).raw(), proto,
1545 Bstr(strHostIp).raw(),
1546 RTStrToUInt16(strHostPort),
1547 Bstr(strGuestIp).raw(),
1548 RTStrToUInt16(strGuestPort)));
1549 }
1550 else
1551 {
1552 /* delete NAT Rule operation */
1553 int vrc;
1554 vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1555 if (RT_FAILURE(vrc))
1556 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
1557 CHECK_ERROR(engine, RemoveRedirect(Bstr(ValueUnion.psz).raw()));
1558 }
1559 break;
1560 }
1561 #undef ITERATE_TO_NEXT_TERM
1562 case MODIFYVM_NATALIASMODE:
1563 {
1564 ComPtr<INetworkAdapter> nic;
1565 ComPtr<INATEngine> engine;
1566 uint32_t aliasMode = 0;
1567
1568 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1569 ASSERT(nic);
1570
1571 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1572 if (RTStrCmp(ValueUnion.psz, "default") == 0)
1573 {
1574 aliasMode = 0;
1575 }
1576 else
1577 {
1578 char *token = (char *)ValueUnion.psz;
1579 while(token)
1580 {
1581 if (RTStrNCmp(token, "log", 3) == 0)
1582 aliasMode |= 0x1;
1583 else if (RTStrNCmp(token, "proxyonly", 9) == 0)
1584 aliasMode |= 0x2;
1585 else if (RTStrNCmp(token, "sameports", 9) == 0)
1586 aliasMode |= 0x4;
1587 token = RTStrStr(token, ",");
1588 if (token == NULL)
1589 break;
1590 token++;
1591 }
1592 }
1593 CHECK_ERROR(engine, COMSETTER(AliasMode)(aliasMode));
1594 break;
1595 }
1596
1597 case MODIFYVM_NATTFTPPREFIX:
1598 {
1599 ComPtr<INetworkAdapter> nic;
1600 ComPtr<INATEngine> engine;
1601
1602 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1603 ASSERT(nic);
1604
1605 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1606 CHECK_ERROR(engine, COMSETTER(TFTPPrefix)(Bstr(ValueUnion.psz).raw()));
1607 break;
1608 }
1609
1610 case MODIFYVM_NATTFTPFILE:
1611 {
1612 ComPtr<INetworkAdapter> nic;
1613 ComPtr<INATEngine> engine;
1614
1615 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1616 ASSERT(nic);
1617
1618 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1619 CHECK_ERROR(engine, COMSETTER(TFTPBootFile)(Bstr(ValueUnion.psz).raw()));
1620 break;
1621 }
1622
1623 case MODIFYVM_NATTFTPSERVER:
1624 {
1625 ComPtr<INetworkAdapter> nic;
1626 ComPtr<INATEngine> engine;
1627
1628 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1629 ASSERT(nic);
1630
1631 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1632 CHECK_ERROR(engine, COMSETTER(TFTPNextServer)(Bstr(ValueUnion.psz).raw()));
1633 break;
1634 }
1635 case MODIFYVM_NATDNSPASSDOMAIN:
1636 {
1637 ComPtr<INetworkAdapter> nic;
1638 ComPtr<INATEngine> engine;
1639
1640 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1641 ASSERT(nic);
1642
1643 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1644 CHECK_ERROR(engine, COMSETTER(DNSPassDomain)(ValueUnion.f));
1645 break;
1646 }
1647
1648 case MODIFYVM_NATDNSPROXY:
1649 {
1650 ComPtr<INetworkAdapter> nic;
1651 ComPtr<INATEngine> engine;
1652
1653 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1654 ASSERT(nic);
1655
1656 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1657 CHECK_ERROR(engine, COMSETTER(DNSProxy)(ValueUnion.f));
1658 break;
1659 }
1660
1661 case MODIFYVM_NATDNSHOSTRESOLVER:
1662 {
1663 ComPtr<INetworkAdapter> nic;
1664 ComPtr<INATEngine> engine;
1665
1666 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1667 ASSERT(nic);
1668
1669 CHECK_ERROR(nic, COMGETTER(NATEngine)(engine.asOutParam()));
1670 CHECK_ERROR(engine, COMSETTER(DNSUseHostResolver)(ValueUnion.f));
1671 break;
1672 }
1673 case MODIFYVM_MACADDRESS:
1674 {
1675 ComPtr<INetworkAdapter> nic;
1676
1677 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1678 ASSERT(nic);
1679
1680 /* generate one? */
1681 if (!RTStrICmp(ValueUnion.psz, "auto"))
1682 {
1683 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr().raw()));
1684 }
1685 else
1686 {
1687 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr(ValueUnion.psz).raw()));
1688 }
1689 break;
1690 }
1691
1692 case MODIFYVM_HIDPTR:
1693 {
1694 bool fEnableUsb = false;
1695 if (!RTStrICmp(ValueUnion.psz, "ps2"))
1696 {
1697 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_PS2Mouse));
1698 }
1699 else if (!RTStrICmp(ValueUnion.psz, "usb"))
1700 {
1701 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_USBMouse));
1702 if (SUCCEEDED(rc))
1703 fEnableUsb = true;
1704 }
1705 else if (!RTStrICmp(ValueUnion.psz, "usbtablet"))
1706 {
1707 CHECK_ERROR(machine, COMSETTER(PointingHIDType)(PointingHIDType_USBTablet));
1708 if (SUCCEEDED(rc))
1709 fEnableUsb = true;
1710 }
1711 else
1712 {
1713 errorArgument("Invalid type '%s' specfied for pointing device", ValueUnion.psz);
1714 rc = E_FAIL;
1715 }
1716 if (fEnableUsb)
1717 {
1718 /* Make sure the OHCI controller is enabled. */
1719 ComPtr<IUSBController> UsbCtl;
1720 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1721 if (SUCCEEDED(rc))
1722 {
1723 BOOL fEnabled;
1724 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1725 if (FAILED(rc))
1726 fEnabled = false;
1727 if (!fEnabled)
1728 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1729 }
1730 }
1731 break;
1732 }
1733
1734 case MODIFYVM_HIDKBD:
1735 {
1736 bool fEnableUsb = false;
1737 if (!RTStrICmp(ValueUnion.psz, "ps2"))
1738 {
1739 CHECK_ERROR(machine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_PS2Keyboard));
1740 }
1741 else if (!RTStrICmp(ValueUnion.psz, "usb"))
1742 {
1743 CHECK_ERROR(machine, COMSETTER(KeyboardHIDType)(KeyboardHIDType_USBKeyboard));
1744 if (SUCCEEDED(rc))
1745 fEnableUsb = true;
1746 }
1747 else
1748 {
1749 errorArgument("Invalid type '%s' specfied for keyboard", ValueUnion.psz);
1750 rc = E_FAIL;
1751 }
1752 if (fEnableUsb)
1753 {
1754 /* Make sure the OHCI controller is enabled. */
1755 ComPtr<IUSBController> UsbCtl;
1756 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1757 if (SUCCEEDED(rc))
1758 {
1759 BOOL fEnabled;
1760 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1761 if (FAILED(rc))
1762 fEnabled = false;
1763 if (!fEnabled)
1764 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1765 }
1766 }
1767 break;
1768 }
1769
1770 case MODIFYVM_UARTMODE:
1771 {
1772 ComPtr<ISerialPort> uart;
1773 char *pszIRQ = NULL;
1774
1775 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1776 ASSERT(uart);
1777
1778 if (!RTStrICmp(ValueUnion.psz, "disconnected"))
1779 {
1780 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
1781 }
1782 else if ( !RTStrICmp(ValueUnion.psz, "server")
1783 || !RTStrICmp(ValueUnion.psz, "client")
1784 || !RTStrICmp(ValueUnion.psz, "file"))
1785 {
1786 const char *pszMode = ValueUnion.psz;
1787
1788 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1789 if (RT_FAILURE(vrc))
1790 return errorSyntax(USAGE_MODIFYVM,
1791 "Missing or Invalid argument to '%s'",
1792 GetOptState.pDef->pszLong);
1793
1794 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1795
1796 if (!RTStrICmp(pszMode, "server"))
1797 {
1798 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1799 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
1800 }
1801 else if (!RTStrICmp(pszMode, "client"))
1802 {
1803 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1804 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
1805 }
1806 else if (!RTStrICmp(pszMode, "file"))
1807 {
1808 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
1809 }
1810 }
1811 else
1812 {
1813 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1814 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
1815 }
1816 break;
1817 }
1818
1819 case MODIFYVM_UART:
1820 {
1821 ComPtr<ISerialPort> uart;
1822
1823 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1824 ASSERT(uart);
1825
1826 if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
1827 CHECK_ERROR(uart, COMSETTER(Enabled)(FALSE));
1828 else
1829 {
1830 const char *pszIOBase = ValueUnion.psz;
1831 uint32_t uVal = 0;
1832
1833 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_UART;
1834 if (RT_FAILURE(vrc))
1835 return errorSyntax(USAGE_MODIFYVM,
1836 "Missing or Invalid argument to '%s'",
1837 GetOptState.pDef->pszLong);
1838
1839 CHECK_ERROR(uart, COMSETTER(IRQ)(ValueUnion.u32));
1840
1841 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1842 if (vrc != VINF_SUCCESS || uVal == 0)
1843 return errorArgument("Error parsing UART I/O base '%s'", pszIOBase);
1844 CHECK_ERROR(uart, COMSETTER(IOBase)(uVal));
1845
1846 CHECK_ERROR(uart, COMSETTER(Enabled)(TRUE));
1847 }
1848 break;
1849 }
1850
1851#if defined(RT_OS_LINUX) || defined(RT_OS_WINDOWS)
1852 case MODIFYVM_LPTMODE:
1853 {
1854 ComPtr<IParallelPort> lpt;
1855 char *pszIRQ = NULL;
1856
1857 CHECK_ERROR_BREAK(machine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
1858 ASSERT(lpt);
1859
1860 CHECK_ERROR(lpt, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1861 break;
1862 }
1863
1864 case MODIFYVM_LPT:
1865 {
1866 ComPtr<IParallelPort> lpt;
1867
1868 CHECK_ERROR_BREAK(machine, GetParallelPort(GetOptState.uIndex - 1, lpt.asOutParam()));
1869 ASSERT(lpt);
1870
1871 if (!RTStrICmp(ValueUnion.psz, "off") || !RTStrICmp(ValueUnion.psz, "disable"))
1872 CHECK_ERROR(lpt, COMSETTER(Enabled)(FALSE));
1873 else
1874 {
1875 const char *pszIOBase = ValueUnion.psz;
1876 uint32_t uVal = 0;
1877
1878 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_LPT;
1879 if (RT_FAILURE(vrc))
1880 return errorSyntax(USAGE_MODIFYVM,
1881 "Missing or Invalid argument to '%s'",
1882 GetOptState.pDef->pszLong);
1883
1884 CHECK_ERROR(lpt, COMSETTER(IRQ)(ValueUnion.u32));
1885
1886 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1887 if (vrc != VINF_SUCCESS || uVal == 0)
1888 return errorArgument("Error parsing LPT I/O base '%s'", pszIOBase);
1889 CHECK_ERROR(lpt, COMSETTER(IOBase)(uVal));
1890
1891 CHECK_ERROR(lpt, COMSETTER(Enabled)(TRUE));
1892 }
1893 break;
1894 }
1895#endif
1896
1897 case MODIFYVM_GUESTMEMORYBALLOON:
1898 {
1899 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(ValueUnion.u32));
1900 break;
1901 }
1902
1903 case MODIFYVM_AUDIOCONTROLLER:
1904 {
1905 ComPtr<IAudioAdapter> audioAdapter;
1906 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1907 ASSERT(audioAdapter);
1908
1909 if (!RTStrICmp(ValueUnion.psz, "sb16"))
1910 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1911 else if (!RTStrICmp(ValueUnion.psz, "ac97"))
1912 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1913 else if (!RTStrICmp(ValueUnion.psz, "hda"))
1914 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_HDA));
1915 else
1916 {
1917 errorArgument("Invalid --audiocontroller argument '%s'", ValueUnion.psz);
1918 rc = E_FAIL;
1919 }
1920 break;
1921 }
1922
1923 case MODIFYVM_AUDIO:
1924 {
1925 ComPtr<IAudioAdapter> audioAdapter;
1926 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1927 ASSERT(audioAdapter);
1928
1929 /* disable? */
1930 if (!RTStrICmp(ValueUnion.psz, "none"))
1931 {
1932 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1933 }
1934 else if (!RTStrICmp(ValueUnion.psz, "null"))
1935 {
1936 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1937 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1938 }
1939#ifdef RT_OS_WINDOWS
1940#ifdef VBOX_WITH_WINMM
1941 else if (!RTStrICmp(ValueUnion.psz, "winmm"))
1942 {
1943 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1944 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1945 }
1946#endif
1947 else if (!RTStrICmp(ValueUnion.psz, "dsound"))
1948 {
1949 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1950 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1951 }
1952#endif /* RT_OS_WINDOWS */
1953#ifdef RT_OS_LINUX
1954# ifdef VBOX_WITH_ALSA
1955 else if (!RTStrICmp(ValueUnion.psz, "alsa"))
1956 {
1957 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1958 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1959 }
1960# endif
1961# ifdef VBOX_WITH_PULSE
1962 else if (!RTStrICmp(ValueUnion.psz, "pulse"))
1963 {
1964 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1965 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1966 }
1967# endif
1968#endif /* !RT_OS_LINUX */
1969#ifdef RT_OS_SOLARIS
1970 else if (!RTStrICmp(ValueUnion.psz, "solaudio"))
1971 {
1972 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1973 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1974 }
1975#endif /* !RT_OS_SOLARIS */
1976#ifdef RT_OS_FREEBSD
1977 else if (!RTStrICmp(ValueUnion.psz, "oss"))
1978 {
1979 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1980 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1981 }
1982# ifdef VBOX_WITH_PULSE
1983 else if (!RTStrICmp(ValueUnion.psz, "pulse"))
1984 {
1985 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1986 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1987 }
1988# endif
1989#endif /* !RT_OS_FREEBSD */
1990#ifdef RT_OS_DARWIN
1991 else if (!RTStrICmp(ValueUnion.psz, "coreaudio"))
1992 {
1993 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1994 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1995 }
1996
1997#endif /* !RT_OS_DARWIN */
1998# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS)
1999 else if (!RTStrICmp(ValueUnion.psz, "oss"))
2000 {
2001 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
2002 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
2003 }
2004# endif
2005 else
2006 {
2007 errorArgument("Invalid --audio argument '%s'", ValueUnion.psz);
2008 rc = E_FAIL;
2009 }
2010 break;
2011 }
2012
2013 case MODIFYVM_CLIPBOARD:
2014 {
2015 ClipboardMode_T mode;
2016 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2017 mode = ClipboardMode_Disabled;
2018 else if (!RTStrICmp(ValueUnion.psz, "hosttoguest"))
2019 mode = ClipboardMode_HostToGuest;
2020 else if (!RTStrICmp(ValueUnion.psz, "guesttohost"))
2021 mode = ClipboardMode_GuestToHost;
2022 else if (!RTStrICmp(ValueUnion.psz, "bidirectional"))
2023 mode = ClipboardMode_Bidirectional;
2024 else
2025 {
2026 errorArgument("Invalid --clipboard argument '%s'", ValueUnion.psz);
2027 rc = E_FAIL;
2028 }
2029 if (SUCCEEDED(rc))
2030 {
2031 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(mode));
2032 }
2033 break;
2034 }
2035
2036 case MODIFYVM_DRAGANDDROP:
2037 {
2038 DragAndDropMode_T mode;
2039 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2040 mode = DragAndDropMode_Disabled;
2041 else if (!RTStrICmp(ValueUnion.psz, "hosttoguest"))
2042 mode = DragAndDropMode_HostToGuest;
2043 else if (!RTStrICmp(ValueUnion.psz, "guesttohost"))
2044 mode = DragAndDropMode_GuestToHost;
2045 else if (!RTStrICmp(ValueUnion.psz, "bidirectional"))
2046 mode = DragAndDropMode_Bidirectional;
2047 else
2048 {
2049 errorArgument("Invalid --draganddrop argument '%s'", ValueUnion.psz);
2050 rc = E_FAIL;
2051 }
2052 if (SUCCEEDED(rc))
2053 {
2054 CHECK_ERROR(machine, COMSETTER(DragAndDropMode)(mode));
2055 }
2056 break;
2057 }
2058
2059 case MODIFYVM_VRDE_EXTPACK:
2060 {
2061 ComPtr<IVRDEServer> vrdeServer;
2062 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2063 ASSERT(vrdeServer);
2064
2065 if (vrdeServer)
2066 {
2067 if (RTStrICmp(ValueUnion.psz, "default") != 0)
2068 {
2069 Bstr bstr(ValueUnion.psz);
2070 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(bstr.raw()));
2071 }
2072 else
2073 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(Bstr().raw()));
2074 }
2075 break;
2076 }
2077
2078 case MODIFYVM_VRDEPROPERTY:
2079 {
2080 ComPtr<IVRDEServer> vrdeServer;
2081 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2082 ASSERT(vrdeServer);
2083
2084 if (vrdeServer)
2085 {
2086 /* Parse 'name=value' */
2087 char *pszProperty = RTStrDup(ValueUnion.psz);
2088 if (pszProperty)
2089 {
2090 char *pDelimiter = strchr(pszProperty, '=');
2091 if (pDelimiter)
2092 {
2093 *pDelimiter = '\0';
2094
2095 Bstr bstrName = pszProperty;
2096 Bstr bstrValue = &pDelimiter[1];
2097 CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
2098 }
2099 else
2100 {
2101 RTStrFree(pszProperty);
2102
2103 errorArgument("Invalid --vrdeproperty argument '%s'", ValueUnion.psz);
2104 rc = E_FAIL;
2105 break;
2106 }
2107 RTStrFree(pszProperty);
2108 }
2109 else
2110 {
2111 RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for VRDE property '%s'\n", ValueUnion.psz);
2112 rc = E_FAIL;
2113 }
2114 }
2115 break;
2116 }
2117
2118 case MODIFYVM_VRDPPORT:
2119 vrdeWarningDeprecatedOption("port");
2120
2121 case MODIFYVM_VRDEPORT:
2122 {
2123 ComPtr<IVRDEServer> vrdeServer;
2124 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2125 ASSERT(vrdeServer);
2126
2127 if (!RTStrICmp(ValueUnion.psz, "default"))
2128 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr("0").raw()));
2129 else
2130 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr(ValueUnion.psz).raw()));
2131 break;
2132 }
2133
2134 case MODIFYVM_VRDPADDRESS:
2135 vrdeWarningDeprecatedOption("address");
2136
2137 case MODIFYVM_VRDEADDRESS:
2138 {
2139 ComPtr<IVRDEServer> vrdeServer;
2140 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2141 ASSERT(vrdeServer);
2142
2143 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Address").raw(), Bstr(ValueUnion.psz).raw()));
2144 break;
2145 }
2146
2147 case MODIFYVM_VRDPAUTHTYPE:
2148 vrdeWarningDeprecatedOption("authtype");
2149 case MODIFYVM_VRDEAUTHTYPE:
2150 {
2151 ComPtr<IVRDEServer> vrdeServer;
2152 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2153 ASSERT(vrdeServer);
2154
2155 if (!RTStrICmp(ValueUnion.psz, "null"))
2156 {
2157 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Null));
2158 }
2159 else if (!RTStrICmp(ValueUnion.psz, "external"))
2160 {
2161 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_External));
2162 }
2163 else if (!RTStrICmp(ValueUnion.psz, "guest"))
2164 {
2165 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Guest));
2166 }
2167 else
2168 {
2169 errorArgument("Invalid --vrdeauthtype argument '%s'", ValueUnion.psz);
2170 rc = E_FAIL;
2171 }
2172 break;
2173 }
2174
2175 case MODIFYVM_VRDEAUTHLIBRARY:
2176 {
2177 ComPtr<IVRDEServer> vrdeServer;
2178 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2179 ASSERT(vrdeServer);
2180
2181 if (vrdeServer)
2182 {
2183 if (RTStrICmp(ValueUnion.psz, "default") != 0)
2184 {
2185 Bstr bstr(ValueUnion.psz);
2186 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(bstr.raw()));
2187 }
2188 else
2189 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(Bstr().raw()));
2190 }
2191 break;
2192 }
2193
2194 case MODIFYVM_VRDPMULTICON:
2195 vrdeWarningDeprecatedOption("multicon");
2196 case MODIFYVM_VRDEMULTICON:
2197 {
2198 ComPtr<IVRDEServer> vrdeServer;
2199 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2200 ASSERT(vrdeServer);
2201
2202 CHECK_ERROR(vrdeServer, COMSETTER(AllowMultiConnection)(ValueUnion.f));
2203 break;
2204 }
2205
2206 case MODIFYVM_VRDPREUSECON:
2207 vrdeWarningDeprecatedOption("reusecon");
2208 case MODIFYVM_VRDEREUSECON:
2209 {
2210 ComPtr<IVRDEServer> vrdeServer;
2211 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2212 ASSERT(vrdeServer);
2213
2214 CHECK_ERROR(vrdeServer, COMSETTER(ReuseSingleConnection)(ValueUnion.f));
2215 break;
2216 }
2217
2218 case MODIFYVM_VRDPVIDEOCHANNEL:
2219 vrdeWarningDeprecatedOption("videochannel");
2220 case MODIFYVM_VRDEVIDEOCHANNEL:
2221 {
2222 ComPtr<IVRDEServer> vrdeServer;
2223 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2224 ASSERT(vrdeServer);
2225
2226 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Enabled").raw(),
2227 ValueUnion.f? Bstr("true").raw(): Bstr("false").raw()));
2228 break;
2229 }
2230
2231 case MODIFYVM_VRDPVIDEOCHANNELQUALITY:
2232 vrdeWarningDeprecatedOption("videochannelquality");
2233 case MODIFYVM_VRDEVIDEOCHANNELQUALITY:
2234 {
2235 ComPtr<IVRDEServer> vrdeServer;
2236 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2237 ASSERT(vrdeServer);
2238
2239 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(),
2240 Bstr(ValueUnion.psz).raw()));
2241 break;
2242 }
2243
2244 case MODIFYVM_VRDP:
2245 vrdeWarningDeprecatedOption("");
2246 case MODIFYVM_VRDE:
2247 {
2248 ComPtr<IVRDEServer> vrdeServer;
2249 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
2250 ASSERT(vrdeServer);
2251
2252 CHECK_ERROR(vrdeServer, COMSETTER(Enabled)(ValueUnion.f));
2253 break;
2254 }
2255
2256 case MODIFYVM_USBEHCI:
2257 {
2258 ComPtr<IUSBController> UsbCtl;
2259 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
2260 if (SUCCEEDED(rc))
2261 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEHCI)(ValueUnion.f));
2262 break;
2263 }
2264
2265 case MODIFYVM_USB:
2266 {
2267 ComPtr<IUSBController> UsbCtl;
2268 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
2269 if (SUCCEEDED(rc))
2270 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(ValueUnion.f));
2271 break;
2272 }
2273
2274 case MODIFYVM_SNAPSHOTFOLDER:
2275 {
2276 if (!RTStrICmp(ValueUnion.psz, "default"))
2277 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr().raw()));
2278 else
2279 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(ValueUnion.psz).raw()));
2280 break;
2281 }
2282
2283 case MODIFYVM_TELEPORTER_ENABLED:
2284 {
2285 CHECK_ERROR(machine, COMSETTER(TeleporterEnabled)(ValueUnion.f));
2286 break;
2287 }
2288
2289 case MODIFYVM_TELEPORTER_PORT:
2290 {
2291 CHECK_ERROR(machine, COMSETTER(TeleporterPort)(ValueUnion.u32));
2292 break;
2293 }
2294
2295 case MODIFYVM_TELEPORTER_ADDRESS:
2296 {
2297 CHECK_ERROR(machine, COMSETTER(TeleporterAddress)(Bstr(ValueUnion.psz).raw()));
2298 break;
2299 }
2300
2301 case MODIFYVM_TELEPORTER_PASSWORD:
2302 {
2303 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(ValueUnion.psz).raw()));
2304 break;
2305 }
2306
2307 case MODIFYVM_TELEPORTER_PASSWORD_FILE:
2308 {
2309 Utf8Str password;
2310 RTEXITCODE rcExit = readPasswordFile(ValueUnion.psz, &password);
2311 if (rcExit != RTEXITCODE_SUCCESS)
2312 rc = E_FAIL;
2313 else
2314 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(password).raw()));
2315 break;
2316 }
2317
2318 case MODIFYVM_TRACING_ENABLED:
2319 {
2320 CHECK_ERROR(machine, COMSETTER(TracingEnabled)(ValueUnion.f));
2321 break;
2322 }
2323
2324 case MODIFYVM_TRACING_CONFIG:
2325 {
2326 CHECK_ERROR(machine, COMSETTER(TracingConfig)(Bstr(ValueUnion.psz).raw()));
2327 break;
2328 }
2329
2330 case MODIFYVM_TRACING_ALLOW_VM_ACCESS:
2331 {
2332 CHECK_ERROR(machine, COMSETTER(AllowTracingToAccessVM)(ValueUnion.f));
2333 break;
2334 }
2335
2336 case MODIFYVM_FAULT_TOLERANCE:
2337 {
2338 if (!RTStrICmp(ValueUnion.psz, "master"))
2339 {
2340 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Master)));
2341 }
2342 else
2343 if (!RTStrICmp(ValueUnion.psz, "standby"))
2344 {
2345 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Standby)));
2346 }
2347 else
2348 {
2349 errorArgument("Invalid --faulttolerance argument '%s'", ValueUnion.psz);
2350 rc = E_FAIL;
2351 }
2352 break;
2353 }
2354
2355 case MODIFYVM_FAULT_TOLERANCE_ADDRESS:
2356 {
2357 CHECK_ERROR(machine, COMSETTER(FaultToleranceAddress)(Bstr(ValueUnion.psz).raw()));
2358 break;
2359 }
2360
2361 case MODIFYVM_FAULT_TOLERANCE_PORT:
2362 {
2363 CHECK_ERROR(machine, COMSETTER(FaultTolerancePort)(ValueUnion.u32));
2364 break;
2365 }
2366
2367 case MODIFYVM_FAULT_TOLERANCE_PASSWORD:
2368 {
2369 CHECK_ERROR(machine, COMSETTER(FaultTolerancePassword)(Bstr(ValueUnion.psz).raw()));
2370 break;
2371 }
2372
2373 case MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL:
2374 {
2375 CHECK_ERROR(machine, COMSETTER(FaultToleranceSyncInterval)(ValueUnion.u32));
2376 break;
2377 }
2378
2379 case MODIFYVM_HARDWARE_UUID:
2380 {
2381 CHECK_ERROR(machine, COMSETTER(HardwareUUID)(Bstr(ValueUnion.psz).raw()));
2382 break;
2383 }
2384
2385 case MODIFYVM_HPET:
2386 {
2387 CHECK_ERROR(machine, COMSETTER(HPETEnabled)(ValueUnion.f));
2388 break;
2389 }
2390
2391 case MODIFYVM_IOCACHE:
2392 {
2393 CHECK_ERROR(machine, COMSETTER(IOCacheEnabled)(ValueUnion.f));
2394 break;
2395 }
2396
2397 case MODIFYVM_IOCACHESIZE:
2398 {
2399 CHECK_ERROR(machine, COMSETTER(IOCacheSize)(ValueUnion.u32));
2400 break;
2401 }
2402
2403 case MODIFYVM_CHIPSET:
2404 {
2405 if (!RTStrICmp(ValueUnion.psz, "piix3"))
2406 {
2407 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_PIIX3));
2408 }
2409 else if (!RTStrICmp(ValueUnion.psz, "ich9"))
2410 {
2411 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_ICH9));
2412 BOOL fIoApic = FALSE;
2413 CHECK_ERROR(biosSettings, COMGETTER(IOAPICEnabled)(&fIoApic));
2414 if (!fIoApic)
2415 {
2416 RTStrmPrintf(g_pStdErr, "*** I/O APIC must be enabled for ICH9, enabling. ***\n");
2417 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(TRUE));
2418 }
2419 }
2420 else
2421 {
2422 errorArgument("Invalid --chipset argument '%s' (valid: piix3,ich9)", ValueUnion.psz);
2423 rc = E_FAIL;
2424 }
2425 break;
2426 }
2427#ifdef VBOX_WITH_VPX
2428 case MODIFYVM_VCP:
2429 {
2430 CHECK_ERROR(machine, COMSETTER(VideoCaptureEnabled)(ValueUnion.f));
2431 break;
2432 }
2433 case MODIFYVM_VCP_FILENAME:
2434 {
2435 Bstr bstr(ValueUnion.psz);
2436 CHECK_ERROR(machine, COMSETTER(VideoCaptureFile)(bstr.raw()));
2437 break;
2438 }
2439 case MODIFYVM_VCP_WIDTH:
2440 {
2441 CHECK_ERROR(machine, COMSETTER(VideoCaptureWidth)(ValueUnion.u32));
2442 break;
2443 }
2444 case MODIFYVM_VCP_HEIGHT:
2445 {
2446 CHECK_ERROR(machine, COMSETTER(VideoCaptureHeight)(ValueUnion.u32));
2447 break;
2448 }
2449 case MODIFYVM_VCP_RATE:
2450 {
2451 CHECK_ERROR(machine, COMSETTER(VideoCaptureRate)(ValueUnion.u32));
2452 break;
2453 }
2454#endif
2455 case MODIFYVM_AUTOSTART_ENABLED:
2456 {
2457 CHECK_ERROR(machine, COMSETTER(AutostartEnabled)(ValueUnion.f));
2458 break;
2459 }
2460
2461 case MODIFYVM_AUTOSTART_DELAY:
2462 {
2463 CHECK_ERROR(machine, COMSETTER(AutostartDelay)(ValueUnion.u32));
2464 break;
2465 }
2466
2467 case MODIFYVM_AUTOSTOP_TYPE:
2468 {
2469 AutostopType_T enmAutostopType = AutostopType_Disabled;
2470
2471 if (!RTStrICmp(ValueUnion.psz, "disabled"))
2472 enmAutostopType = AutostopType_Disabled;
2473 else if (!RTStrICmp(ValueUnion.psz, "savestate"))
2474 enmAutostopType = AutostopType_SaveState;
2475 else if (!RTStrICmp(ValueUnion.psz, "poweroff"))
2476 enmAutostopType = AutostopType_PowerOff;
2477 else if (!RTStrICmp(ValueUnion.psz, "acpishutdown"))
2478 enmAutostopType = AutostopType_AcpiShutdown;
2479 else
2480 {
2481 errorArgument("Invalid --autostop-type argument '%s' (valid: disabled, savestate, poweroff, acpishutdown)", ValueUnion.psz);
2482 rc = E_FAIL;
2483 }
2484
2485 if (SUCCEEDED(rc))
2486 CHECK_ERROR(machine, COMSETTER(AutostopType)(enmAutostopType));
2487 break;
2488 }
2489#ifdef VBOX_WITH_PCI_PASSTHROUGH
2490 case MODIFYVM_ATTACH_PCI:
2491 {
2492 const char* pAt = strchr(ValueUnion.psz, '@');
2493 int32_t iHostAddr, iGuestAddr;
2494
2495 iHostAddr = parsePci(ValueUnion.psz);
2496 iGuestAddr = pAt != NULL ? parsePci(pAt + 1) : iHostAddr;
2497
2498 if (iHostAddr == -1 || iGuestAddr == -1)
2499 {
2500 errorArgument("Invalid --pciattach argument '%s' (valid: 'HB:HD.HF@GB:GD.GF' or just 'HB:HD.HF')", ValueUnion.psz);
2501 rc = E_FAIL;
2502 }
2503 else
2504 {
2505 CHECK_ERROR(machine, AttachHostPCIDevice(iHostAddr, iGuestAddr, TRUE));
2506 }
2507
2508 break;
2509 }
2510 case MODIFYVM_DETACH_PCI:
2511 {
2512 int32_t iHostAddr;
2513
2514 iHostAddr = parsePci(ValueUnion.psz);
2515 if (iHostAddr == -1)
2516 {
2517 errorArgument("Invalid --pcidetach argument '%s' (valid: 'HB:HD.HF')", ValueUnion.psz);
2518 rc = E_FAIL;
2519 }
2520 else
2521 {
2522 CHECK_ERROR(machine, DetachHostPCIDevice(iHostAddr));
2523 }
2524
2525 break;
2526 }
2527#endif
2528
2529#ifdef VBOX_WITH_USB_VIDEO
2530 case MODIFYVM_USBWEBCAM:
2531 {
2532 CHECK_ERROR(machine, COMSETTER(EmulatedUSBWebcameraEnabled)(ValueUnion.f));
2533 break;
2534 }
2535#endif /* VBOX_WITH_USB_VIDEO */
2536
2537#ifdef VBOX_WITH_USB_CARDREADER
2538 case MODIFYVM_USBCARDREADER:
2539 {
2540 CHECK_ERROR(machine, COMSETTER(EmulatedUSBCardReaderEnabled)(ValueUnion.f));
2541 break;
2542 }
2543#endif /* VBOX_WITH_USB_CARDREADER */
2544
2545 case MODIFYVM_DEFAULTFRONTEND:
2546 {
2547 Bstr bstr(ValueUnion.psz);
2548 if (bstr == "default")
2549 bstr = Bstr::Empty;
2550 CHECK_ERROR(machine, COMSETTER(DefaultFrontend)(bstr.raw()));
2551 break;
2552 }
2553
2554 default:
2555 {
2556 errorGetOpt(USAGE_MODIFYVM, c, &ValueUnion);
2557 rc = E_FAIL;
2558 break;
2559 }
2560 }
2561 }
2562
2563 /* commit changes */
2564 if (SUCCEEDED(rc))
2565 CHECK_ERROR(machine, SaveSettings());
2566
2567 /* it's important to always close sessions */
2568 a->session->UnlockMachine();
2569
2570 return SUCCEEDED(rc) ? 0 : 1;
2571}
2572
2573#endif /* !VBOX_ONLY_DOCS */
Note: See TracBrowser for help on using the repository browser.

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