VirtualBox

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

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

Frontends/VBoxManage: new option --longmode for modifyvm, for changing the corresponding guest CPU property, plus showing the current value with showvminfo.
doc/manual: document this option, the link is currently dangling as the GUI doesn't allow to control this setting yet

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