VirtualBox

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

Last change on this file since 56743 was 56479, checked in by vboxsync, 10 years ago

VBoxManage: Added audio codec setting support.

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