VirtualBox

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

Last change on this file since 71054 was 70712, checked in by vboxsync, 7 years ago

Main,VBoxManage: Added CPUPropertyType_HWVirt. Translates to --nested-hw-virt in VBoxManage/modifyvm

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