VirtualBox

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

Last change on this file since 49762 was 49069, checked in by vboxsync, 11 years ago

API: Control and propagate triple fault reset/guru setting.

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