VirtualBox

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

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

Frontends/VBoxManage: add a way to set the VM icon

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