VirtualBox

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

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

Main/NetworkAdapter+Machine+Appliance+SystemProperties+Medium+Console+Settings+IDL: make NAT networking a separate network attachment type which improves the user experience, store the necessary settings, plus changing the design of the methods which will move images and entire VMs, they lacked a progress object
Frontends/VirtualBox: adapted fully, can configure NAT networks with proper drop down list support
Frontends/VBoxManage: also supports NAT networks completely, and adds the long missing code to list intnets

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