VirtualBox

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

Last change on this file since 78354 was 78064, checked in by vboxsync, 6 years ago

Recording/VBoxManage: Getting and controlling the recording settings needs SessionMachine to work.

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