VirtualBox

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

Last change on this file since 35761 was 35761, checked in by vboxsync, 14 years ago

Main, frontends: proper description for maximal number of NICs per VM

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 86.1 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 35761 2011-01-28 13:19:26Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2010 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/EventQueue.h>
27
28#include <VBox/com/VirtualBox.h>
29#endif /* !VBOX_ONLY_DOCS */
30
31#include <iprt/cidr.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
39#include "VBoxManage.h"
40
41#ifndef VBOX_ONLY_DOCS
42using namespace com;
43
44
45/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
46#if defined(_MSC_VER)
47# pragma optimize("g", off)
48#endif
49
50enum
51{
52 MODIFYVM_NAME = 1000,
53 MODIFYVM_OSTYPE,
54 MODIFYVM_MEMORY,
55 MODIFYVM_PAGEFUSION,
56 MODIFYVM_VRAM,
57 MODIFYVM_FIRMWARE,
58 MODIFYVM_ACPI,
59 MODIFYVM_IOAPIC,
60 MODIFYVM_PAE,
61 MODIFYVM_SYNTHCPU,
62 MODIFYVM_HWVIRTEX,
63 MODIFYVM_HWVIRTEXEXCLUSIVE,
64 MODIFYVM_NESTEDPAGING,
65 MODIFYVM_LARGEPAGES,
66 MODIFYVM_VTXVPID,
67 MODIFYVM_CPUS,
68 MODIFYVM_CPUHOTPLUG,
69 MODIFYVM_PLUGCPU,
70 MODIFYVM_UNPLUGCPU,
71 MODIFYVM_SETCPUID,
72 MODIFYVM_DELCPUID,
73 MODIFYVM_DELALLCPUID,
74 MODIFYVM_MONITORCOUNT,
75 MODIFYVM_ACCELERATE3D,
76#ifdef VBOX_WITH_VIDEOHWACCEL
77 MODIFYVM_ACCELERATE2DVIDEO,
78#endif
79 MODIFYVM_BIOSLOGOFADEIN,
80 MODIFYVM_BIOSLOGOFADEOUT,
81 MODIFYVM_BIOSLOGODISPLAYTIME,
82 MODIFYVM_BIOSLOGOIMAGEPATH,
83 MODIFYVM_BIOSBOOTMENU,
84 MODIFYVM_BIOSSYSTEMTIMEOFFSET,
85 MODIFYVM_BIOSPXEDEBUG,
86 MODIFYVM_BOOT,
87 MODIFYVM_HDA, // deprecated
88 MODIFYVM_HDB, // deprecated
89 MODIFYVM_HDD, // deprecated
90 MODIFYVM_IDECONTROLLER, // deprecated
91 MODIFYVM_SATAIDEEMULATION, // deprecated
92 MODIFYVM_SATAPORTCOUNT, // deprecated
93 MODIFYVM_SATAPORT, // deprecated
94 MODIFYVM_SATA, // deprecated
95 MODIFYVM_SCSIPORT, // deprecated
96 MODIFYVM_SCSITYPE, // deprecated
97 MODIFYVM_SCSI, // deprecated
98 MODIFYVM_DVDPASSTHROUGH, // deprecated
99 MODIFYVM_DVD, // deprecated
100 MODIFYVM_FLOPPY, // deprecated
101 MODIFYVM_NICTRACEFILE,
102 MODIFYVM_NICTRACE,
103 MODIFYVM_NICTYPE,
104 MODIFYVM_NICSPEED,
105 MODIFYVM_NICBOOTPRIO,
106 MODIFYVM_NIC,
107 MODIFYVM_CABLECONNECTED,
108 MODIFYVM_BRIDGEADAPTER,
109 MODIFYVM_HOSTONLYADAPTER,
110 MODIFYVM_INTNET,
111 MODIFYVM_NATNET,
112#ifdef VBOX_WITH_VDE
113 MODIFYVM_VDENET,
114#endif
115 MODIFYVM_NATBINDIP,
116 MODIFYVM_NATSETTINGS,
117 MODIFYVM_NATPF,
118 MODIFYVM_NATALIASMODE,
119 MODIFYVM_NATTFTPPREFIX,
120 MODIFYVM_NATTFTPFILE,
121 MODIFYVM_NATTFTPSERVER,
122 MODIFYVM_NATDNSPASSDOMAIN,
123 MODIFYVM_NATDNSPROXY,
124 MODIFYVM_NATDNSHOSTRESOLVER,
125 MODIFYVM_MACADDRESS,
126 MODIFYVM_HIDPTR,
127 MODIFYVM_HIDKBD,
128 MODIFYVM_UARTMODE,
129 MODIFYVM_UART,
130 MODIFYVM_GUESTMEMORYBALLOON,
131 MODIFYVM_AUDIOCONTROLLER,
132 MODIFYVM_AUDIO,
133 MODIFYVM_CLIPBOARD,
134 MODIFYVM_VRDPPORT, /* VRDE: deprecated */
135 MODIFYVM_VRDPADDRESS, /* VRDE: deprecated */
136 MODIFYVM_VRDPAUTHTYPE, /* VRDE: deprecated */
137 MODIFYVM_VRDPMULTICON, /* VRDE: deprecated */
138 MODIFYVM_VRDPREUSECON, /* VRDE: deprecated */
139 MODIFYVM_VRDPVIDEOCHANNEL, /* VRDE: deprecated */
140 MODIFYVM_VRDPVIDEOCHANNELQUALITY, /* VRDE: deprecated */
141 MODIFYVM_VRDP, /* VRDE: deprecated */
142 MODIFYVM_VRDEPROPERTY,
143 MODIFYVM_VRDEPORT,
144 MODIFYVM_VRDEADDRESS,
145 MODIFYVM_VRDEAUTHTYPE,
146 MODIFYVM_VRDEAUTHLIBRARY,
147 MODIFYVM_VRDEMULTICON,
148 MODIFYVM_VRDEREUSECON,
149 MODIFYVM_VRDEVIDEOCHANNEL,
150 MODIFYVM_VRDEVIDEOCHANNELQUALITY,
151 MODIFYVM_VRDE_EXTPACK,
152 MODIFYVM_VRDE,
153 MODIFYVM_RTCUSEUTC,
154 MODIFYVM_USBEHCI,
155 MODIFYVM_USB,
156 MODIFYVM_SNAPSHOTFOLDER,
157 MODIFYVM_TELEPORTER_ENABLED,
158 MODIFYVM_TELEPORTER_PORT,
159 MODIFYVM_TELEPORTER_ADDRESS,
160 MODIFYVM_TELEPORTER_PASSWORD,
161 MODIFYVM_HARDWARE_UUID,
162 MODIFYVM_HPET,
163 MODIFYVM_IOCACHE,
164 MODIFYVM_IOCACHESIZE,
165 MODIFYVM_FAULT_TOLERANCE,
166 MODIFYVM_FAULT_TOLERANCE_ADDRESS,
167 MODIFYVM_FAULT_TOLERANCE_PORT,
168 MODIFYVM_FAULT_TOLERANCE_PASSWORD,
169 MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL,
170 MODIFYVM_CPU_EXECTUION_CAP,
171 MODIFYVM_CHIPSET
172};
173
174static const RTGETOPTDEF g_aModifyVMOptions[] =
175{
176 { "--name", MODIFYVM_NAME, RTGETOPT_REQ_STRING },
177 { "--ostype", MODIFYVM_OSTYPE, RTGETOPT_REQ_STRING },
178 { "--memory", MODIFYVM_MEMORY, RTGETOPT_REQ_UINT32 },
179 { "--pagefusion", MODIFYVM_PAGEFUSION, RTGETOPT_REQ_BOOL_ONOFF },
180 { "--vram", MODIFYVM_VRAM, RTGETOPT_REQ_UINT32 },
181 { "--firmware", MODIFYVM_FIRMWARE, RTGETOPT_REQ_STRING },
182 { "--acpi", MODIFYVM_ACPI, RTGETOPT_REQ_BOOL_ONOFF },
183 { "--ioapic", MODIFYVM_IOAPIC, RTGETOPT_REQ_BOOL_ONOFF },
184 { "--pae", MODIFYVM_PAE, RTGETOPT_REQ_BOOL_ONOFF },
185 { "--synthcpu", MODIFYVM_SYNTHCPU, RTGETOPT_REQ_BOOL_ONOFF },
186 { "--hwvirtex", MODIFYVM_HWVIRTEX, RTGETOPT_REQ_BOOL_ONOFF },
187 { "--hwvirtexexcl", MODIFYVM_HWVIRTEXEXCLUSIVE, RTGETOPT_REQ_BOOL_ONOFF },
188 { "--nestedpaging", MODIFYVM_NESTEDPAGING, RTGETOPT_REQ_BOOL_ONOFF },
189 { "--largepages", MODIFYVM_LARGEPAGES, RTGETOPT_REQ_BOOL_ONOFF },
190 { "--vtxvpid", MODIFYVM_VTXVPID, RTGETOPT_REQ_BOOL_ONOFF },
191 { "--cpuidset", MODIFYVM_SETCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
192 { "--cpuidremove", MODIFYVM_DELCPUID, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX},
193 { "--cpuidremoveall", MODIFYVM_DELALLCPUID, RTGETOPT_REQ_NOTHING},
194 { "--cpus", MODIFYVM_CPUS, RTGETOPT_REQ_UINT32 },
195 { "--cpuhotplug", MODIFYVM_CPUHOTPLUG, RTGETOPT_REQ_BOOL_ONOFF },
196 { "--plugcpu", MODIFYVM_PLUGCPU, RTGETOPT_REQ_UINT32 },
197 { "--unplugcpu", MODIFYVM_UNPLUGCPU, RTGETOPT_REQ_UINT32 },
198 { "--cpuexecutioncap", MODIFYVM_CPU_EXECTUION_CAP, RTGETOPT_REQ_UINT32 },
199 { "--rtcuseutc", MODIFYVM_RTCUSEUTC, RTGETOPT_REQ_BOOL_ONOFF },
200 { "--monitorcount", MODIFYVM_MONITORCOUNT, RTGETOPT_REQ_UINT32 },
201 { "--accelerate3d", MODIFYVM_ACCELERATE3D, RTGETOPT_REQ_BOOL_ONOFF },
202#ifdef VBOX_WITH_VIDEOHWACCEL
203 { "--accelerate2dvideo", MODIFYVM_ACCELERATE2DVIDEO, RTGETOPT_REQ_BOOL_ONOFF },
204#endif
205 { "--bioslogofadein", MODIFYVM_BIOSLOGOFADEIN, RTGETOPT_REQ_BOOL_ONOFF },
206 { "--bioslogofadeout", MODIFYVM_BIOSLOGOFADEOUT, RTGETOPT_REQ_BOOL_ONOFF },
207 { "--bioslogodisplaytime", MODIFYVM_BIOSLOGODISPLAYTIME, RTGETOPT_REQ_UINT32 },
208 { "--bioslogoimagepath", MODIFYVM_BIOSLOGOIMAGEPATH, RTGETOPT_REQ_STRING },
209 { "--biosbootmenu", MODIFYVM_BIOSBOOTMENU, RTGETOPT_REQ_STRING },
210 { "--biossystemtimeoffset", MODIFYVM_BIOSSYSTEMTIMEOFFSET, RTGETOPT_REQ_INT64 },
211 { "--biospxedebug", MODIFYVM_BIOSPXEDEBUG, RTGETOPT_REQ_BOOL_ONOFF },
212 { "--boot", MODIFYVM_BOOT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
213 { "--hda", MODIFYVM_HDA, RTGETOPT_REQ_STRING },
214 { "--hdb", MODIFYVM_HDB, RTGETOPT_REQ_STRING },
215 { "--hdd", MODIFYVM_HDD, RTGETOPT_REQ_STRING },
216 { "--idecontroller", MODIFYVM_IDECONTROLLER, RTGETOPT_REQ_STRING },
217 { "--sataideemulation", MODIFYVM_SATAIDEEMULATION, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
218 { "--sataportcount", MODIFYVM_SATAPORTCOUNT, RTGETOPT_REQ_UINT32 },
219 { "--sataport", MODIFYVM_SATAPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
220 { "--sata", MODIFYVM_SATA, RTGETOPT_REQ_STRING },
221 { "--scsiport", MODIFYVM_SCSIPORT, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
222 { "--scsitype", MODIFYVM_SCSITYPE, RTGETOPT_REQ_STRING },
223 { "--scsi", MODIFYVM_SCSI, RTGETOPT_REQ_STRING },
224 { "--dvdpassthrough", MODIFYVM_DVDPASSTHROUGH, RTGETOPT_REQ_STRING },
225 { "--dvd", MODIFYVM_DVD, RTGETOPT_REQ_STRING },
226 { "--floppy", MODIFYVM_FLOPPY, RTGETOPT_REQ_STRING },
227 { "--nictracefile", MODIFYVM_NICTRACEFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
228 { "--nictrace", MODIFYVM_NICTRACE, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
229 { "--nictype", MODIFYVM_NICTYPE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
230 { "--nicspeed", MODIFYVM_NICSPEED, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
231 { "--nicbootprio", MODIFYVM_NICBOOTPRIO, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_INDEX },
232 { "--nic", MODIFYVM_NIC, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
233 { "--cableconnected", MODIFYVM_CABLECONNECTED, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
234 { "--bridgeadapter", MODIFYVM_BRIDGEADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
235 { "--hostonlyadapter", MODIFYVM_HOSTONLYADAPTER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
236 { "--intnet", MODIFYVM_INTNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
237 { "--natnet", MODIFYVM_NATNET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
238#ifdef VBOX_WITH_VDE
239 { "--vdenet", MODIFYVM_VDENET, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
240#endif
241 { "--natbindip", MODIFYVM_NATBINDIP, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
242 { "--natsettings", MODIFYVM_NATSETTINGS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
243 { "--natpf", MODIFYVM_NATPF, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
244 { "--nataliasmode", MODIFYVM_NATALIASMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
245 { "--nattftpprefix", MODIFYVM_NATTFTPPREFIX, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
246 { "--nattftpfile", MODIFYVM_NATTFTPFILE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
247 { "--nattftpserver", MODIFYVM_NATTFTPSERVER, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
248 { "--natdnspassdomain", MODIFYVM_NATDNSPASSDOMAIN, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
249 { "--natdnsproxy", MODIFYVM_NATDNSPROXY, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
250 { "--natdnshostresolver", MODIFYVM_NATDNSHOSTRESOLVER, RTGETOPT_REQ_BOOL_ONOFF | RTGETOPT_FLAG_INDEX },
251 { "--macaddress", MODIFYVM_MACADDRESS, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
252 { "--mouse", MODIFYVM_HIDPTR, RTGETOPT_REQ_STRING },
253 { "--keyboard", MODIFYVM_HIDKBD, RTGETOPT_REQ_STRING },
254 { "--uartmode", MODIFYVM_UARTMODE, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
255 { "--uart", MODIFYVM_UART, RTGETOPT_REQ_STRING | RTGETOPT_FLAG_INDEX },
256 { "--guestmemoryballoon", MODIFYVM_GUESTMEMORYBALLOON, RTGETOPT_REQ_UINT32 },
257 { "--audiocontroller", MODIFYVM_AUDIOCONTROLLER, RTGETOPT_REQ_STRING },
258 { "--audio", MODIFYVM_AUDIO, RTGETOPT_REQ_STRING },
259 { "--clipboard", MODIFYVM_CLIPBOARD, RTGETOPT_REQ_STRING },
260 { "--vrdpport", MODIFYVM_VRDPPORT, RTGETOPT_REQ_STRING }, /* deprecated */
261 { "--vrdpaddress", MODIFYVM_VRDPADDRESS, RTGETOPT_REQ_STRING }, /* deprecated */
262 { "--vrdpauthtype", MODIFYVM_VRDPAUTHTYPE, RTGETOPT_REQ_STRING }, /* deprecated */
263 { "--vrdpmulticon", MODIFYVM_VRDPMULTICON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
264 { "--vrdpreusecon", MODIFYVM_VRDPREUSECON, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
265 { "--vrdpvideochannel", MODIFYVM_VRDPVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
266 { "--vrdpvideochannelquality", MODIFYVM_VRDPVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING }, /* deprecated */
267 { "--vrdp", MODIFYVM_VRDP, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
268 { "--vrdeproperty", MODIFYVM_VRDEPROPERTY, RTGETOPT_REQ_STRING },
269 { "--vrdeport", MODIFYVM_VRDEPORT, RTGETOPT_REQ_STRING },
270 { "--vrdeaddress", MODIFYVM_VRDEADDRESS, RTGETOPT_REQ_STRING },
271 { "--vrdeauthtype", MODIFYVM_VRDEAUTHTYPE, RTGETOPT_REQ_STRING },
272 { "--vrdeauthlibrary", MODIFYVM_VRDEAUTHLIBRARY, RTGETOPT_REQ_STRING },
273 { "--vrdemulticon", MODIFYVM_VRDEMULTICON, RTGETOPT_REQ_BOOL_ONOFF },
274 { "--vrdereusecon", MODIFYVM_VRDEREUSECON, RTGETOPT_REQ_BOOL_ONOFF },
275 { "--vrdevideochannel", MODIFYVM_VRDEVIDEOCHANNEL, RTGETOPT_REQ_BOOL_ONOFF },
276 { "--vrdevideochannelquality", MODIFYVM_VRDEVIDEOCHANNELQUALITY, RTGETOPT_REQ_STRING },
277 { "--vrdeextpack", MODIFYVM_VRDE_EXTPACK, RTGETOPT_REQ_STRING },
278 { "--vrde", MODIFYVM_VRDE, RTGETOPT_REQ_BOOL_ONOFF },
279 { "--usbehci", MODIFYVM_USBEHCI, RTGETOPT_REQ_BOOL_ONOFF },
280 { "--usb", MODIFYVM_USB, RTGETOPT_REQ_BOOL_ONOFF },
281 { "--snapshotfolder", MODIFYVM_SNAPSHOTFOLDER, RTGETOPT_REQ_STRING },
282 { "--teleporter", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF },
283 { "--teleporterenabled", MODIFYVM_TELEPORTER_ENABLED, RTGETOPT_REQ_BOOL_ONOFF }, /* deprecated */
284 { "--teleporterport", MODIFYVM_TELEPORTER_PORT, RTGETOPT_REQ_UINT32 },
285 { "--teleporteraddress", MODIFYVM_TELEPORTER_ADDRESS, RTGETOPT_REQ_STRING },
286 { "--teleporterpassword", MODIFYVM_TELEPORTER_PASSWORD, RTGETOPT_REQ_STRING },
287 { "--hardwareuuid", MODIFYVM_HARDWARE_UUID, RTGETOPT_REQ_STRING },
288 { "--hpet", MODIFYVM_HPET, RTGETOPT_REQ_BOOL_ONOFF },
289 { "--iocache", MODIFYVM_IOCACHE, RTGETOPT_REQ_BOOL_ONOFF },
290 { "--iocachesize", MODIFYVM_IOCACHESIZE, RTGETOPT_REQ_UINT32 },
291 { "--faulttolerance", MODIFYVM_FAULT_TOLERANCE, RTGETOPT_REQ_STRING },
292 { "--faulttoleranceaddress", MODIFYVM_FAULT_TOLERANCE_ADDRESS, RTGETOPT_REQ_STRING },
293 { "--faulttoleranceport", MODIFYVM_FAULT_TOLERANCE_PORT, RTGETOPT_REQ_UINT32 },
294 { "--faulttolerancepassword", MODIFYVM_FAULT_TOLERANCE_PASSWORD, RTGETOPT_REQ_STRING },
295 { "--faulttolerancesyncinterval", MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL, RTGETOPT_REQ_UINT32 },
296 { "--chipset", MODIFYVM_CHIPSET, RTGETOPT_REQ_STRING },
297};
298
299static void vrdeWarningDeprecatedOption(const char *pszOption)
300{
301 RTStrmPrintf(g_pStdErr, "Warning: '--vrdp%s' is deprecated. Use '--vrde%s'.\n", pszOption, pszOption);
302}
303
304
305int handleModifyVM(HandlerArg *a)
306{
307 int c;
308 HRESULT rc;
309 Bstr name;
310 RTGETOPTUNION ValueUnion;
311 RTGETOPTSTATE GetOptState;
312 ComPtr <IMachine> machine;
313 ComPtr <IBIOSSettings> biosSettings;
314
315 /* VM ID + at least one parameter. Parameter arguments are checked
316 * individually. */
317 if (a->argc < 2)
318 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
319
320 ULONG SerialPortCount = 0;
321 {
322 ComPtr <ISystemProperties> info;
323 CHECK_ERROR_RET(a->virtualBox, COMGETTER(SystemProperties)(info.asOutParam()), 1);
324 CHECK_ERROR_RET(info, COMGETTER(SerialPortCount)(&SerialPortCount), 1);
325 }
326
327 /* try to find the given machine */
328 CHECK_ERROR_RET(a->virtualBox, FindMachine(Bstr(a->argv[0]).raw(),
329 machine.asOutParam()), 1);
330
331
332 /* Get the number of network adapters */
333 ULONG NetworkAdapterCount = getMaxNics(a->virtualBox, machine);
334
335 /* open a session for the VM */
336 CHECK_ERROR_RET(machine, LockMachine(a->session, LockType_Write), 1);
337
338 /* get the mutable session machine */
339 a->session->COMGETTER(Machine)(machine.asOutParam());
340 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
341
342 RTGetOptInit(&GetOptState, a->argc, a->argv, g_aModifyVMOptions,
343 RT_ELEMENTS(g_aModifyVMOptions), 1, RTGETOPTINIT_FLAGS_NO_STD_OPTS);
344
345 while ( SUCCEEDED (rc)
346 && (c = RTGetOpt(&GetOptState, &ValueUnion)))
347 {
348 switch (c)
349 {
350 case MODIFYVM_NAME:
351 {
352 CHECK_ERROR(machine, COMSETTER(Name)(Bstr(ValueUnion.psz).raw()));
353 break;
354 }
355 case MODIFYVM_OSTYPE:
356 {
357 ComPtr<IGuestOSType> guestOSType;
358 CHECK_ERROR(a->virtualBox, GetGuestOSType(Bstr(ValueUnion.psz).raw(),
359 guestOSType.asOutParam()));
360 if (SUCCEEDED(rc) && guestOSType)
361 {
362 CHECK_ERROR(machine, COMSETTER(OSTypeId)(Bstr(ValueUnion.psz).raw()));
363 }
364 else
365 {
366 errorArgument("Invalid guest OS type '%s'", Utf8Str(ValueUnion.psz).c_str());
367 rc = E_FAIL;
368 }
369 break;
370 }
371
372 case MODIFYVM_MEMORY:
373 {
374 CHECK_ERROR(machine, COMSETTER(MemorySize)(ValueUnion.u32));
375 break;
376 }
377
378 case MODIFYVM_PAGEFUSION:
379 {
380 CHECK_ERROR(machine, COMSETTER(PageFusionEnabled)(ValueUnion.f));
381 break;
382 }
383
384 case MODIFYVM_VRAM:
385 {
386 CHECK_ERROR(machine, COMSETTER(VRAMSize)(ValueUnion.u32));
387 break;
388 }
389
390 case MODIFYVM_FIRMWARE:
391 {
392 if (!strcmp(ValueUnion.psz, "efi"))
393 {
394 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI));
395 }
396 else if (!strcmp(ValueUnion.psz, "efi32"))
397 {
398 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI32));
399 }
400 else if (!strcmp(ValueUnion.psz, "efi64"))
401 {
402 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFI64));
403 }
404 else if (!strcmp(ValueUnion.psz, "efidual"))
405 {
406 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_EFIDUAL));
407 }
408 else if (!strcmp(ValueUnion.psz, "bios"))
409 {
410 CHECK_ERROR(machine, COMSETTER(FirmwareType)(FirmwareType_BIOS));
411 }
412 else
413 {
414 errorArgument("Invalid --firmware argument '%s'", ValueUnion.psz);
415 rc = E_FAIL;
416 }
417 break;
418 }
419
420 case MODIFYVM_ACPI:
421 {
422 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(ValueUnion.f));
423 break;
424 }
425
426 case MODIFYVM_IOAPIC:
427 {
428 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(ValueUnion.f));
429 break;
430 }
431
432 case MODIFYVM_PAE:
433 {
434 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_PAE, ValueUnion.f));
435 break;
436 }
437
438 case MODIFYVM_SYNTHCPU:
439 {
440 CHECK_ERROR(machine, SetCPUProperty(CPUPropertyType_Synthetic, ValueUnion.f));
441 break;
442 }
443
444 case MODIFYVM_HWVIRTEX:
445 {
446 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Enabled, ValueUnion.f));
447 break;
448 }
449
450 case MODIFYVM_HWVIRTEXEXCLUSIVE:
451 {
452 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_Exclusive, ValueUnion.f));
453 break;
454 }
455
456 case MODIFYVM_SETCPUID:
457 {
458 uint32_t id = ValueUnion.u32;
459 uint32_t aValue[4];
460
461 for (unsigned i = 0 ; i < 4 ; i++)
462 {
463 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_HEX);
464 if (RT_FAILURE(vrc))
465 return errorSyntax(USAGE_MODIFYVM,
466 "Missing or Invalid argument to '%s'",
467 GetOptState.pDef->pszLong);
468 aValue[i] = ValueUnion.u32;
469 }
470 CHECK_ERROR(machine, SetCPUIDLeaf(id, aValue[0], aValue[1], aValue[2], aValue[3]));
471 break;
472 }
473
474 case MODIFYVM_DELCPUID:
475 {
476 CHECK_ERROR(machine, RemoveCPUIDLeaf(ValueUnion.u32));
477 break;
478 }
479
480 case MODIFYVM_DELALLCPUID:
481 {
482 CHECK_ERROR(machine, RemoveAllCPUIDLeaves());
483 break;
484 }
485
486 case MODIFYVM_NESTEDPAGING:
487 {
488 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, ValueUnion.f));
489 break;
490 }
491
492 case MODIFYVM_LARGEPAGES:
493 {
494 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_LargePages, ValueUnion.f));
495 break;
496 }
497
498 case MODIFYVM_VTXVPID:
499 {
500 CHECK_ERROR(machine, SetHWVirtExProperty(HWVirtExPropertyType_VPID, ValueUnion.f));
501 break;
502 }
503
504 case MODIFYVM_CPUS:
505 {
506 CHECK_ERROR(machine, COMSETTER(CPUCount)(ValueUnion.u32));
507 break;
508 }
509
510 case MODIFYVM_RTCUSEUTC:
511 {
512 CHECK_ERROR(machine, COMSETTER(RTCUseUTC)(ValueUnion.f));
513 break;
514 }
515
516 case MODIFYVM_CPUHOTPLUG:
517 {
518 CHECK_ERROR(machine, COMSETTER(CPUHotPlugEnabled)(ValueUnion.f));
519 break;
520 }
521
522 case MODIFYVM_PLUGCPU:
523 {
524 CHECK_ERROR(machine, HotPlugCPU(ValueUnion.u32));
525 break;
526 }
527
528 case MODIFYVM_UNPLUGCPU:
529 {
530 CHECK_ERROR(machine, HotUnplugCPU(ValueUnion.u32));
531 break;
532 }
533
534 case MODIFYVM_CPU_EXECTUION_CAP:
535 {
536 CHECK_ERROR(machine, COMSETTER(CPUExecutionCap)(ValueUnion.u32));
537 break;
538 }
539
540 case MODIFYVM_MONITORCOUNT:
541 {
542 CHECK_ERROR(machine, COMSETTER(MonitorCount)(ValueUnion.u32));
543 break;
544 }
545
546 case MODIFYVM_ACCELERATE3D:
547 {
548 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(ValueUnion.f));
549 break;
550 }
551
552#ifdef VBOX_WITH_VIDEOHWACCEL
553 case MODIFYVM_ACCELERATE2DVIDEO:
554 {
555 CHECK_ERROR(machine, COMSETTER(Accelerate2DVideoEnabled)(ValueUnion.f));
556 break;
557 }
558#endif
559
560 case MODIFYVM_BIOSLOGOFADEIN:
561 {
562 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(ValueUnion.f));
563 break;
564 }
565
566 case MODIFYVM_BIOSLOGOFADEOUT:
567 {
568 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(ValueUnion.f));
569 break;
570 }
571
572 case MODIFYVM_BIOSLOGODISPLAYTIME:
573 {
574 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(ValueUnion.u32));
575 break;
576 }
577
578 case MODIFYVM_BIOSLOGOIMAGEPATH:
579 {
580 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(ValueUnion.psz).raw()));
581 break;
582 }
583
584 case MODIFYVM_BIOSBOOTMENU:
585 {
586 if (!strcmp(ValueUnion.psz, "disabled"))
587 {
588 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
589 }
590 else if (!strcmp(ValueUnion.psz, "menuonly"))
591 {
592 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
593 }
594 else if (!strcmp(ValueUnion.psz, "messageandmenu"))
595 {
596 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
597 }
598 else
599 {
600 errorArgument("Invalid --biosbootmenu argument '%s'", ValueUnion.psz);
601 rc = E_FAIL;
602 }
603 break;
604 }
605
606 case MODIFYVM_BIOSSYSTEMTIMEOFFSET:
607 {
608 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(ValueUnion.i64));
609 break;
610 }
611
612 case MODIFYVM_BIOSPXEDEBUG:
613 {
614 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(ValueUnion.f));
615 break;
616 }
617
618 case MODIFYVM_BOOT:
619 {
620 if (!strcmp(ValueUnion.psz, "none"))
621 {
622 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Null));
623 }
624 else if (!strcmp(ValueUnion.psz, "floppy"))
625 {
626 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Floppy));
627 }
628 else if (!strcmp(ValueUnion.psz, "dvd"))
629 {
630 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_DVD));
631 }
632 else if (!strcmp(ValueUnion.psz, "disk"))
633 {
634 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_HardDisk));
635 }
636 else if (!strcmp(ValueUnion.psz, "net"))
637 {
638 CHECK_ERROR(machine, SetBootOrder(GetOptState.uIndex, DeviceType_Network));
639 }
640 else
641 return errorArgument("Invalid boot device '%s'", ValueUnion.psz);
642 break;
643 }
644
645 case MODIFYVM_HDA: // deprecated
646 case MODIFYVM_HDB: // deprecated
647 case MODIFYVM_HDD: // deprecated
648 case MODIFYVM_SATAPORT: // deprecated
649 {
650 uint32_t u1 = 0, u2 = 0;
651 Bstr bstrController = L"IDE Controller";
652
653 switch (c)
654 {
655 case MODIFYVM_HDA: // deprecated
656 u1 = 0;
657 break;
658
659 case MODIFYVM_HDB: // deprecated
660 u1 = 0;
661 u2 = 1;
662 break;
663
664 case MODIFYVM_HDD: // deprecated
665 u1 = 1;
666 u2 = 1;
667 break;
668
669 case MODIFYVM_SATAPORT: // deprecated
670 u1 = GetOptState.uIndex;
671 bstrController = L"SATA";
672 break;
673 }
674
675 if (!strcmp(ValueUnion.psz, "none"))
676 {
677 machine->DetachDevice(bstrController.raw(), u1, u2);
678 }
679 else
680 {
681 ComPtr<IMedium> hardDisk;
682 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk,
683 hardDisk, NULL);
684 if (FAILED(rc))
685 break;
686 if (hardDisk)
687 {
688 CHECK_ERROR(machine, AttachDevice(bstrController.raw(),
689 u1, u2,
690 DeviceType_HardDisk,
691 hardDisk));
692 }
693 else
694 rc = E_FAIL;
695 }
696 break;
697 }
698
699 case MODIFYVM_IDECONTROLLER: // deprecated
700 {
701 ComPtr<IStorageController> storageController;
702 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("IDE Controller").raw(),
703 storageController.asOutParam()));
704
705 if (!RTStrICmp(ValueUnion.psz, "PIIX3"))
706 {
707 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX3));
708 }
709 else if (!RTStrICmp(ValueUnion.psz, "PIIX4"))
710 {
711 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_PIIX4));
712 }
713 else if (!RTStrICmp(ValueUnion.psz, "ICH6"))
714 {
715 CHECK_ERROR(storageController, COMSETTER(ControllerType)(StorageControllerType_ICH6));
716 }
717 else
718 {
719 errorArgument("Invalid --idecontroller argument '%s'", ValueUnion.psz);
720 rc = E_FAIL;
721 }
722 break;
723 }
724
725 case MODIFYVM_SATAIDEEMULATION: // deprecated
726 {
727 ComPtr<IStorageController> SataCtl;
728 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA").raw(),
729 SataCtl.asOutParam()));
730
731 if (SUCCEEDED(rc))
732 CHECK_ERROR(SataCtl, SetIDEEmulationPort(GetOptState.uIndex, ValueUnion.u32));
733 break;
734 }
735
736 case MODIFYVM_SATAPORTCOUNT: // deprecated
737 {
738 ComPtr<IStorageController> SataCtl;
739 CHECK_ERROR(machine, GetStorageControllerByName(Bstr("SATA").raw(),
740 SataCtl.asOutParam()));
741
742 if (SUCCEEDED(rc) && ValueUnion.u32 > 0)
743 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(ValueUnion.u32));
744 break;
745 }
746
747 case MODIFYVM_SATA: // deprecated
748 {
749 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
750 {
751 ComPtr<IStorageController> ctl;
752 CHECK_ERROR(machine, AddStorageController(Bstr("SATA").raw(),
753 StorageBus_SATA,
754 ctl.asOutParam()));
755 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_IntelAhci));
756 }
757 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
758 CHECK_ERROR(machine, RemoveStorageController(Bstr("SATA").raw()));
759 else
760 return errorArgument("Invalid --usb argument '%s'", ValueUnion.psz);
761 break;
762 }
763
764 case MODIFYVM_SCSIPORT: // deprecated
765 {
766 if (!strcmp(ValueUnion.psz, "none"))
767 {
768 rc = machine->DetachDevice(Bstr("LsiLogic").raw(),
769 GetOptState.uIndex, 0);
770 if (FAILED(rc))
771 CHECK_ERROR(machine, DetachDevice(Bstr("BusLogic").raw(),
772 GetOptState.uIndex, 0));
773 }
774 else
775 {
776 ComPtr<IMedium> hardDisk;
777 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_HardDisk,
778 hardDisk, NULL);
779 if (FAILED(rc))
780 break;
781 if (hardDisk)
782 {
783 rc = machine->AttachDevice(Bstr("LsiLogic").raw(),
784 GetOptState.uIndex, 0,
785 DeviceType_HardDisk,
786 hardDisk);
787 if (FAILED(rc))
788 CHECK_ERROR(machine,
789 AttachDevice(Bstr("BusLogic").raw(),
790 GetOptState.uIndex, 0,
791 DeviceType_HardDisk,
792 hardDisk));
793 }
794 else
795 rc = E_FAIL;
796 }
797 break;
798 }
799
800 case MODIFYVM_SCSITYPE: // deprecated
801 {
802 ComPtr<IStorageController> ctl;
803
804 if (!RTStrICmp(ValueUnion.psz, "LsiLogic"))
805 {
806 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
807 if (FAILED(rc))
808 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
809
810 CHECK_ERROR(machine,
811 AddStorageController(Bstr("LsiLogic").raw(),
812 StorageBus_SCSI,
813 ctl.asOutParam()));
814
815 if (SUCCEEDED(rc))
816 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_LsiLogic));
817 }
818 else if (!RTStrICmp(ValueUnion.psz, "BusLogic"))
819 {
820 rc = machine->RemoveStorageController(Bstr("LsiLogic").raw());
821 if (FAILED(rc))
822 CHECK_ERROR(machine, RemoveStorageController(Bstr("BusLogic").raw()));
823
824 CHECK_ERROR(machine,
825 AddStorageController(Bstr("BusLogic").raw(),
826 StorageBus_SCSI,
827 ctl.asOutParam()));
828
829 if (SUCCEEDED(rc))
830 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
831 }
832 else
833 return errorArgument("Invalid --scsitype argument '%s'", ValueUnion.psz);
834 break;
835 }
836
837 case MODIFYVM_SCSI: // deprecated
838 {
839 if (!strcmp(ValueUnion.psz, "on") || !strcmp(ValueUnion.psz, "enable"))
840 {
841 ComPtr<IStorageController> ctl;
842
843 CHECK_ERROR(machine, AddStorageController(Bstr("BusLogic").raw(),
844 StorageBus_SCSI,
845 ctl.asOutParam()));
846 if (SUCCEEDED(rc))
847 CHECK_ERROR(ctl, COMSETTER(ControllerType)(StorageControllerType_BusLogic));
848 }
849 else if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
850 {
851 rc = machine->RemoveStorageController(Bstr("BusLogic").raw());
852 if (FAILED(rc))
853 CHECK_ERROR(machine, RemoveStorageController(Bstr("LsiLogic").raw()));
854 }
855 break;
856 }
857
858 case MODIFYVM_DVDPASSTHROUGH: // deprecated
859 {
860 CHECK_ERROR(machine, PassthroughDevice(Bstr("IDE Controller").raw(),
861 1, 0,
862 !strcmp(ValueUnion.psz, "on")));
863 break;
864 }
865
866 case MODIFYVM_DVD: // deprecated
867 {
868 ComPtr<IMedium> dvdMedium;
869
870 /* unmount? */
871 if (!strcmp(ValueUnion.psz, "none"))
872 {
873 /* nothing to do, NULL object will cause unmount */
874 }
875 /* host drive? */
876 else if (!strncmp(ValueUnion.psz, "host:", 5))
877 {
878 ComPtr<IHost> host;
879 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
880 rc = host->FindHostDVDDrive(Bstr(ValueUnion.psz + 5).raw(),
881 dvdMedium.asOutParam());
882 if (!dvdMedium)
883 {
884 /* 2nd try: try with the real name, important on Linux+libhal */
885 char szPathReal[RTPATH_MAX];
886 if (RT_FAILURE(RTPathReal(ValueUnion.psz + 5, szPathReal, sizeof(szPathReal))))
887 {
888 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
889 rc = E_FAIL;
890 break;
891 }
892 rc = host->FindHostDVDDrive(Bstr(szPathReal).raw(),
893 dvdMedium.asOutParam());
894 if (!dvdMedium)
895 {
896 errorArgument("Invalid host DVD drive name \"%s\"", ValueUnion.psz + 5);
897 rc = E_FAIL;
898 break;
899 }
900 }
901 }
902 else
903 {
904 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_DVD,
905 dvdMedium, NULL);
906 if (FAILED(rc))
907 break;
908 if (!dvdMedium)
909 {
910 rc = E_FAIL;
911 break;
912 }
913 }
914
915 CHECK_ERROR(machine, MountMedium(Bstr("IDE Controller").raw(),
916 1, 0,
917 dvdMedium,
918 FALSE /* aForce */));
919 break;
920 }
921
922 case MODIFYVM_FLOPPY: // deprecated
923 {
924 ComPtr<IMedium> floppyMedium;
925 ComPtr<IMediumAttachment> floppyAttachment;
926 machine->GetMediumAttachment(Bstr("Floppy Controller").raw(),
927 0, 0, floppyAttachment.asOutParam());
928
929 /* disable? */
930 if (!strcmp(ValueUnion.psz, "disabled"))
931 {
932 /* disable the controller */
933 if (floppyAttachment)
934 CHECK_ERROR(machine, DetachDevice(Bstr("Floppy Controller").raw(),
935 0, 0));
936 }
937 else
938 {
939 /* enable the controller */
940 if (!floppyAttachment)
941 CHECK_ERROR(machine, AttachDevice(Bstr("Floppy Controller").raw(),
942 0, 0,
943 DeviceType_Floppy, NULL));
944
945 /* unmount? */
946 if ( !strcmp(ValueUnion.psz, "none")
947 || !strcmp(ValueUnion.psz, "empty")) // deprecated
948 {
949 /* nothing to do, NULL object will cause unmount */
950 }
951 /* host drive? */
952 else if (!strncmp(ValueUnion.psz, "host:", 5))
953 {
954 ComPtr<IHost> host;
955 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
956 rc = host->FindHostFloppyDrive(Bstr(ValueUnion.psz + 5).raw(),
957 floppyMedium.asOutParam());
958 if (!floppyMedium)
959 {
960 errorArgument("Invalid host floppy drive name \"%s\"", ValueUnion.psz + 5);
961 rc = E_FAIL;
962 break;
963 }
964 }
965 else
966 {
967 rc = findOrOpenMedium(a, ValueUnion.psz, DeviceType_Floppy,
968 floppyMedium, NULL);
969 if (FAILED(rc))
970 break;
971 if (!floppyMedium)
972 {
973 rc = E_FAIL;
974 break;
975 }
976 }
977 CHECK_ERROR(machine, MountMedium(Bstr("Floppy Controller").raw(),
978 0, 0,
979 floppyMedium,
980 FALSE /* aForce */));
981 }
982 break;
983 }
984
985 case MODIFYVM_NICTRACEFILE:
986 {
987 ComPtr<INetworkAdapter> nic;
988
989 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
990 ASSERT(nic);
991
992 CHECK_ERROR(nic, COMSETTER(TraceFile)(Bstr(ValueUnion.psz).raw()));
993 break;
994 }
995
996 case MODIFYVM_NICTRACE:
997 {
998 ComPtr<INetworkAdapter> nic;
999
1000 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1001 ASSERT(nic);
1002
1003 CHECK_ERROR(nic, COMSETTER(TraceEnabled)(ValueUnion.f));
1004 break;
1005 }
1006
1007 case MODIFYVM_NICTYPE:
1008 {
1009 ComPtr<INetworkAdapter> nic;
1010
1011 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1012 ASSERT(nic);
1013
1014 if (!strcmp(ValueUnion.psz, "Am79C970A"))
1015 {
1016 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A));
1017 }
1018 else if (!strcmp(ValueUnion.psz, "Am79C973"))
1019 {
1020 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973));
1021 }
1022#ifdef VBOX_WITH_E1000
1023 else if (!strcmp(ValueUnion.psz, "82540EM"))
1024 {
1025 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM));
1026 }
1027 else if (!strcmp(ValueUnion.psz, "82543GC"))
1028 {
1029 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC));
1030 }
1031 else if (!strcmp(ValueUnion.psz, "82545EM"))
1032 {
1033 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82545EM));
1034 }
1035#endif
1036#ifdef VBOX_WITH_VIRTIO
1037 else if (!strcmp(ValueUnion.psz, "virtio"))
1038 {
1039 CHECK_ERROR(nic, COMSETTER(AdapterType)(NetworkAdapterType_Virtio));
1040 }
1041#endif /* VBOX_WITH_VIRTIO */
1042 else
1043 {
1044 errorArgument("Invalid NIC type '%s' specified for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1045 rc = E_FAIL;
1046 }
1047 break;
1048 }
1049
1050 case MODIFYVM_NICSPEED:
1051 {
1052 ComPtr<INetworkAdapter> nic;
1053
1054 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1055 ASSERT(nic);
1056
1057 CHECK_ERROR(nic, COMSETTER(LineSpeed)(ValueUnion.u32));
1058 break;
1059 }
1060
1061 case MODIFYVM_NICBOOTPRIO:
1062 {
1063 ComPtr<INetworkAdapter> nic;
1064
1065 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1066 ASSERT(nic);
1067
1068 /* Somewhat arbitrary limitation - we can pass a list of up to 4 PCI devices
1069 * to the PXE ROM, hence only boot priorities 1-4 are allowed (in addition to
1070 * 0 for the default lowest priority).
1071 */
1072 if (ValueUnion.u32 > 4)
1073 {
1074 errorArgument("Invalid boot priority '%u' specfied for NIC %u", ValueUnion.u32, GetOptState.uIndex);
1075 rc = E_FAIL;
1076 }
1077 else
1078 {
1079 CHECK_ERROR(nic, COMSETTER(BootPriority)(ValueUnion.u32));
1080 }
1081 break;
1082 }
1083
1084 case MODIFYVM_NIC:
1085 {
1086 ComPtr<INetworkAdapter> nic;
1087
1088 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1089 ASSERT(nic);
1090
1091 if (!strcmp(ValueUnion.psz, "none"))
1092 {
1093 CHECK_ERROR(nic, COMSETTER(Enabled)(FALSE));
1094 }
1095 else if (!strcmp(ValueUnion.psz, "null"))
1096 {
1097 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1098 CHECK_ERROR(nic, Detach());
1099 }
1100 else if (!strcmp(ValueUnion.psz, "nat"))
1101 {
1102 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1103 CHECK_ERROR(nic, AttachToNAT());
1104 }
1105 else if ( !strcmp(ValueUnion.psz, "bridged")
1106 || !strcmp(ValueUnion.psz, "hostif")) /* backward compatibility */
1107 {
1108 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1109 CHECK_ERROR(nic, AttachToBridgedInterface());
1110 }
1111 else if (!strcmp(ValueUnion.psz, "intnet"))
1112 {
1113 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1114 CHECK_ERROR(nic, AttachToInternalNetwork());
1115 }
1116#if defined(VBOX_WITH_NETFLT)
1117 else if (!strcmp(ValueUnion.psz, "hostonly"))
1118 {
1119
1120 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1121 CHECK_ERROR(nic, AttachToHostOnlyInterface());
1122 }
1123#endif
1124#ifdef VBOX_WITH_VDE
1125 else if (!strcmp(ValueUnion.psz, "vde"))
1126 {
1127
1128 CHECK_ERROR(nic, COMSETTER(Enabled)(TRUE));
1129 CHECK_ERROR(nic, AttachToVDE());
1130 }
1131#endif
1132 else
1133 {
1134 errorArgument("Invalid type '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1135 rc = E_FAIL;
1136 }
1137 break;
1138 }
1139
1140 case MODIFYVM_CABLECONNECTED:
1141 {
1142 ComPtr<INetworkAdapter> nic;
1143
1144 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1145 ASSERT(nic);
1146
1147 CHECK_ERROR(nic, COMSETTER(CableConnected)(ValueUnion.f));
1148 break;
1149 }
1150
1151 case MODIFYVM_BRIDGEADAPTER:
1152 case MODIFYVM_HOSTONLYADAPTER:
1153 {
1154 ComPtr<INetworkAdapter> nic;
1155
1156 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1157 ASSERT(nic);
1158
1159 /** @todo NULL string deprecated */
1160 /* remove it? */
1161 if (!strcmp(ValueUnion.psz, "none"))
1162 {
1163 CHECK_ERROR(nic, COMSETTER(HostInterface)(NULL));
1164 }
1165 else
1166 {
1167 CHECK_ERROR(nic, COMSETTER(HostInterface)(Bstr(ValueUnion.psz).raw()));
1168 }
1169 break;
1170 }
1171
1172 case MODIFYVM_INTNET:
1173 {
1174 ComPtr<INetworkAdapter> nic;
1175
1176 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1177 ASSERT(nic);
1178
1179 /** @todo NULL string deprecated */
1180 /* remove it? */
1181 if (!strcmp(ValueUnion.psz, "none"))
1182 {
1183 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(NULL));
1184 }
1185 else
1186 {
1187 CHECK_ERROR(nic, COMSETTER(InternalNetwork)(Bstr(ValueUnion.psz).raw()));
1188 }
1189 break;
1190 }
1191
1192#ifdef VBOX_WITH_VDE
1193 case MODIFYVM_VDENET:
1194 {
1195 ComPtr<INetworkAdapter> nic;
1196
1197 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1198 ASSERT(nic);
1199
1200 /** @todo NULL string deprecated */
1201 /* remove it? */
1202 if (!strcmp(ValueUnion.psz, "default"))
1203 {
1204 CHECK_ERROR(nic, COMSETTER(VDENetwork)(NULL));
1205 }
1206 else
1207 {
1208 CHECK_ERROR(nic, COMSETTER(VDENetwork)(Bstr(ValueUnion.psz).raw()));
1209 }
1210 break;
1211 }
1212#endif
1213 case MODIFYVM_NATNET:
1214 {
1215 ComPtr<INetworkAdapter> nic;
1216 ComPtr<INATEngine> driver;
1217
1218 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1219 ASSERT(nic);
1220
1221 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1222
1223 const char *psz = ValueUnion.psz;
1224 if (!strcmp("default", psz))
1225 psz = "";
1226
1227 CHECK_ERROR(driver, COMSETTER(Network)(Bstr(psz).raw()));
1228 break;
1229 }
1230
1231 case MODIFYVM_NATBINDIP:
1232 {
1233 ComPtr<INetworkAdapter> nic;
1234 ComPtr<INATEngine> driver;
1235
1236 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1237 ASSERT(nic);
1238
1239 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1240 CHECK_ERROR(driver, COMSETTER(HostIP)(Bstr(ValueUnion.psz).raw()));
1241 break;
1242 }
1243
1244#define ITERATE_TO_NEXT_TERM(ch) \
1245 do { \
1246 while (*ch != ',') \
1247 { \
1248 if (*ch == 0) \
1249 { \
1250 return errorSyntax(USAGE_MODIFYVM, \
1251 "Missing or Invalid argument to '%s'", \
1252 GetOptState.pDef->pszLong); \
1253 } \
1254 ch++; \
1255 } \
1256 *ch = '\0'; \
1257 ch++; \
1258 } while(0)
1259
1260 case MODIFYVM_NATSETTINGS:
1261 {
1262 ComPtr<INetworkAdapter> nic;
1263 ComPtr<INATEngine> driver;
1264 char *strMtu;
1265 char *strSockSnd;
1266 char *strSockRcv;
1267 char *strTcpSnd;
1268 char *strTcpRcv;
1269 char *strRaw = RTStrDup(ValueUnion.psz);
1270 char *ch = strRaw;
1271 strMtu = RTStrStrip(ch);
1272 ITERATE_TO_NEXT_TERM(ch);
1273 strSockSnd = RTStrStrip(ch);
1274 ITERATE_TO_NEXT_TERM(ch);
1275 strSockRcv = RTStrStrip(ch);
1276 ITERATE_TO_NEXT_TERM(ch);
1277 strTcpSnd = RTStrStrip(ch);
1278 ITERATE_TO_NEXT_TERM(ch);
1279 strTcpRcv = RTStrStrip(ch);
1280
1281 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1282 ASSERT(nic);
1283
1284 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1285 CHECK_ERROR(driver, SetNetworkSettings(RTStrToUInt32(strMtu), RTStrToUInt32(strSockSnd), RTStrToUInt32(strSockRcv),
1286 RTStrToUInt32(strTcpSnd), RTStrToUInt32(strTcpRcv)));
1287 break;
1288 }
1289
1290
1291 case MODIFYVM_NATPF:
1292 {
1293 ComPtr<INetworkAdapter> nic;
1294 ComPtr<INATEngine> driver;
1295
1296 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1297 ASSERT(nic);
1298
1299 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1300 /* format name:proto:hostip:hostport:guestip:guestport*/
1301 if (RTStrCmp(ValueUnion.psz, "delete") != 0)
1302 {
1303 char *strName;
1304 char *strProto;
1305 char *strHostIp;
1306 char *strHostPort;
1307 char *strGuestIp;
1308 char *strGuestPort;
1309 char *strRaw = RTStrDup(ValueUnion.psz);
1310 char *ch = strRaw;
1311 strName = RTStrStrip(ch);
1312 ITERATE_TO_NEXT_TERM(ch);
1313 strProto = RTStrStrip(ch);
1314 ITERATE_TO_NEXT_TERM(ch);
1315 strHostIp = RTStrStrip(ch);
1316 ITERATE_TO_NEXT_TERM(ch);
1317 strHostPort = RTStrStrip(ch);
1318 ITERATE_TO_NEXT_TERM(ch);
1319 strGuestIp = RTStrStrip(ch);
1320 ITERATE_TO_NEXT_TERM(ch);
1321 strGuestPort = RTStrStrip(ch);
1322 NATProtocol_T proto;
1323 if (RTStrICmp(strProto, "udp") == 0)
1324 proto = NATProtocol_UDP;
1325 else if (RTStrICmp(strProto, "tcp") == 0)
1326 proto = NATProtocol_TCP;
1327 else
1328 {
1329 errorArgument("Invalid proto '%s' specfied for NIC %u", ValueUnion.psz, GetOptState.uIndex);
1330 rc = E_FAIL;
1331 break;
1332 }
1333 CHECK_ERROR(driver, AddRedirect(Bstr(strName).raw(), proto,
1334 Bstr(strHostIp).raw(),
1335 RTStrToUInt16(strHostPort),
1336 Bstr(strGuestIp).raw(),
1337 RTStrToUInt16(strGuestPort)));
1338 }
1339 else
1340 {
1341 /* delete NAT Rule operation */
1342 int vrc;
1343 vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1344 if (RT_FAILURE(vrc))
1345 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
1346 CHECK_ERROR(driver, RemoveRedirect(Bstr(ValueUnion.psz).raw()));
1347 }
1348 break;
1349 }
1350 #undef ITERATE_TO_NEXT_TERM
1351 case MODIFYVM_NATALIASMODE:
1352 {
1353 ComPtr<INetworkAdapter> nic;
1354 ComPtr<INATEngine> driver;
1355 uint32_t aliasMode = 0;
1356
1357 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1358 ASSERT(nic);
1359
1360 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1361 if (RTStrCmp(ValueUnion.psz,"default") == 0)
1362 {
1363 aliasMode = 0;
1364 }
1365 else
1366 {
1367 char *token = (char *)ValueUnion.psz;
1368 while(token)
1369 {
1370 if (RTStrNCmp(token, "log", 3) == 0)
1371 aliasMode |= 0x1;
1372 else if (RTStrNCmp(token, "proxyonly", 9) == 0)
1373 aliasMode |= 0x2;
1374 else if (RTStrNCmp(token, "sameports", 9) == 0)
1375 aliasMode |= 0x4;
1376 token = RTStrStr(token, ",");
1377 if (token == NULL)
1378 break;
1379 token++;
1380 }
1381 }
1382 CHECK_ERROR(driver, COMSETTER(AliasMode)(aliasMode));
1383 break;
1384 }
1385
1386 case MODIFYVM_NATTFTPPREFIX:
1387 {
1388 ComPtr<INetworkAdapter> nic;
1389 ComPtr<INATEngine> driver;
1390
1391 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1392 ASSERT(nic);
1393
1394 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1395 CHECK_ERROR(driver, COMSETTER(TftpPrefix)(Bstr(ValueUnion.psz).raw()));
1396 break;
1397 }
1398
1399 case MODIFYVM_NATTFTPFILE:
1400 {
1401 ComPtr<INetworkAdapter> nic;
1402 ComPtr<INATEngine> driver;
1403
1404 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1405 ASSERT(nic);
1406
1407 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1408 CHECK_ERROR(driver, COMSETTER(TftpBootFile)(Bstr(ValueUnion.psz).raw()));
1409 break;
1410 }
1411
1412 case MODIFYVM_NATTFTPSERVER:
1413 {
1414 ComPtr<INetworkAdapter> nic;
1415 ComPtr<INATEngine> driver;
1416
1417 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1418 ASSERT(nic);
1419
1420 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1421 CHECK_ERROR(driver, COMSETTER(TftpNextServer)(Bstr(ValueUnion.psz).raw()));
1422 break;
1423 }
1424 case MODIFYVM_NATDNSPASSDOMAIN:
1425 {
1426 ComPtr<INetworkAdapter> nic;
1427 ComPtr<INATEngine> driver;
1428
1429 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1430 ASSERT(nic);
1431
1432 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1433 CHECK_ERROR(driver, COMSETTER(DnsPassDomain)(ValueUnion.f));
1434 break;
1435 }
1436
1437 case MODIFYVM_NATDNSPROXY:
1438 {
1439 ComPtr<INetworkAdapter> nic;
1440 ComPtr<INATEngine> driver;
1441
1442 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1443 ASSERT(nic);
1444
1445 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1446 CHECK_ERROR(driver, COMSETTER(DnsProxy)(ValueUnion.f));
1447 break;
1448 }
1449
1450 case MODIFYVM_NATDNSHOSTRESOLVER:
1451 {
1452 ComPtr<INetworkAdapter> nic;
1453 ComPtr<INATEngine> driver;
1454
1455 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1456 ASSERT(nic);
1457
1458 CHECK_ERROR(nic, COMGETTER(NatDriver)(driver.asOutParam()));
1459 CHECK_ERROR(driver, COMSETTER(DnsUseHostResolver)(ValueUnion.f));
1460 break;
1461 }
1462 case MODIFYVM_MACADDRESS:
1463 {
1464 ComPtr<INetworkAdapter> nic;
1465
1466 CHECK_ERROR_BREAK(machine, GetNetworkAdapter(GetOptState.uIndex - 1, nic.asOutParam()));
1467 ASSERT(nic);
1468
1469 /* generate one? */
1470 if (!strcmp(ValueUnion.psz, "auto"))
1471 {
1472 CHECK_ERROR(nic, COMSETTER(MACAddress)(NULL));
1473 }
1474 else
1475 {
1476 CHECK_ERROR(nic, COMSETTER(MACAddress)(Bstr(ValueUnion.psz).raw()));
1477 }
1478 break;
1479 }
1480
1481 case MODIFYVM_HIDPTR:
1482 {
1483 bool fEnableUsb = false;
1484 if (!strcmp(ValueUnion.psz, "ps2"))
1485 {
1486 CHECK_ERROR(machine, COMSETTER(PointingHidType)(PointingHidType_PS2Mouse));
1487 }
1488 else if (!strcmp(ValueUnion.psz, "usb"))
1489 {
1490 CHECK_ERROR(machine, COMSETTER(PointingHidType)(PointingHidType_USBMouse));
1491 if (SUCCEEDED(rc))
1492 fEnableUsb = true;
1493 }
1494 else if (!strcmp(ValueUnion.psz, "usbtablet"))
1495 {
1496 CHECK_ERROR(machine, COMSETTER(PointingHidType)(PointingHidType_USBTablet));
1497 if (SUCCEEDED(rc))
1498 fEnableUsb = true;
1499 }
1500 else
1501 {
1502 errorArgument("Invalid type '%s' specfied for pointing device", ValueUnion.psz);
1503 rc = E_FAIL;
1504 }
1505 if (fEnableUsb)
1506 {
1507 /* Make sure the OHCI controller is enabled. */
1508 ComPtr<IUSBController> UsbCtl;
1509 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1510 if (SUCCEEDED(rc))
1511 {
1512 BOOL fEnabled;
1513 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1514 if (FAILED(rc))
1515 fEnabled = false;
1516 if (!fEnabled)
1517 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1518 }
1519 }
1520 break;
1521 }
1522
1523 case MODIFYVM_HIDKBD:
1524 {
1525 bool fEnableUsb = false;
1526 if (!strcmp(ValueUnion.psz, "ps2"))
1527 {
1528 CHECK_ERROR(machine, COMSETTER(KeyboardHidType)(KeyboardHidType_PS2Keyboard));
1529 }
1530 else if (!strcmp(ValueUnion.psz, "usb"))
1531 {
1532 CHECK_ERROR(machine, COMSETTER(KeyboardHidType)(KeyboardHidType_USBKeyboard));
1533 if (SUCCEEDED(rc))
1534 fEnableUsb = true;
1535 }
1536 else
1537 {
1538 errorArgument("Invalid type '%s' specfied for keyboard", ValueUnion.psz);
1539 rc = E_FAIL;
1540 }
1541 if (fEnableUsb)
1542 {
1543 /* Make sure the OHCI controller is enabled. */
1544 ComPtr<IUSBController> UsbCtl;
1545 rc = machine->COMGETTER(USBController)(UsbCtl.asOutParam());
1546 if (SUCCEEDED(rc))
1547 {
1548 BOOL fEnabled;
1549 rc = UsbCtl->COMGETTER(Enabled)(&fEnabled);
1550 if (FAILED(rc))
1551 fEnabled = false;
1552 if (!fEnabled)
1553 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(true));
1554 }
1555 }
1556 break;
1557 }
1558
1559 case MODIFYVM_UARTMODE:
1560 {
1561 ComPtr<ISerialPort> uart;
1562 char *pszIRQ = NULL;
1563
1564 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1565 ASSERT(uart);
1566
1567 if (!strcmp(ValueUnion.psz, "disconnected"))
1568 {
1569 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_Disconnected));
1570 }
1571 else if ( !strcmp(ValueUnion.psz, "server")
1572 || !strcmp(ValueUnion.psz, "client")
1573 || !strcmp(ValueUnion.psz, "file"))
1574 {
1575 const char *pszMode = ValueUnion.psz;
1576
1577 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_STRING);
1578 if (RT_FAILURE(vrc))
1579 return errorSyntax(USAGE_MODIFYVM,
1580 "Missing or Invalid argument to '%s'",
1581 GetOptState.pDef->pszLong);
1582
1583 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1584
1585 if (!strcmp(pszMode, "server"))
1586 {
1587 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1588 CHECK_ERROR(uart, COMSETTER(Server)(TRUE));
1589 }
1590 else if (!strcmp(pszMode, "client"))
1591 {
1592 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostPipe));
1593 CHECK_ERROR(uart, COMSETTER(Server)(FALSE));
1594 }
1595 else if (!strcmp(pszMode, "file"))
1596 {
1597 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_RawFile));
1598 }
1599 }
1600 else
1601 {
1602 CHECK_ERROR(uart, COMSETTER(Path)(Bstr(ValueUnion.psz).raw()));
1603 CHECK_ERROR(uart, COMSETTER(HostMode)(PortMode_HostDevice));
1604 }
1605 break;
1606 }
1607
1608 case MODIFYVM_UART:
1609 {
1610 ComPtr<ISerialPort> uart;
1611
1612 CHECK_ERROR_BREAK(machine, GetSerialPort(GetOptState.uIndex - 1, uart.asOutParam()));
1613 ASSERT(uart);
1614
1615 if (!strcmp(ValueUnion.psz, "off") || !strcmp(ValueUnion.psz, "disable"))
1616 CHECK_ERROR(uart, COMSETTER(Enabled)(FALSE));
1617 else
1618 {
1619 const char *pszIOBase = ValueUnion.psz;
1620 uint32_t uVal = 0;
1621
1622 int vrc = RTGetOptFetchValue(&GetOptState, &ValueUnion, RTGETOPT_REQ_UINT32) != MODIFYVM_UART;
1623 if (RT_FAILURE(vrc))
1624 return errorSyntax(USAGE_MODIFYVM,
1625 "Missing or Invalid argument to '%s'",
1626 GetOptState.pDef->pszLong);
1627
1628 CHECK_ERROR(uart, COMSETTER(IRQ)(ValueUnion.u32));
1629
1630 vrc = RTStrToUInt32Ex(pszIOBase, NULL, 0, &uVal);
1631 if (vrc != VINF_SUCCESS || uVal == 0)
1632 return errorArgument("Error parsing UART I/O base '%s'", pszIOBase);
1633 CHECK_ERROR(uart, COMSETTER(IOBase)(uVal));
1634
1635 CHECK_ERROR(uart, COMSETTER(Enabled)(TRUE));
1636 }
1637 break;
1638 }
1639
1640 case MODIFYVM_GUESTMEMORYBALLOON:
1641 {
1642 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(ValueUnion.u32));
1643 break;
1644 }
1645
1646 case MODIFYVM_AUDIOCONTROLLER:
1647 {
1648 ComPtr<IAudioAdapter> audioAdapter;
1649 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1650 ASSERT(audioAdapter);
1651
1652 if (!strcmp(ValueUnion.psz, "sb16"))
1653 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1654 else if (!strcmp(ValueUnion.psz, "ac97"))
1655 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1656 else if (!strcmp(ValueUnion.psz, "hda"))
1657 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_HDA));
1658 else
1659 {
1660 errorArgument("Invalid --audiocontroller argument '%s'", ValueUnion.psz);
1661 rc = E_FAIL;
1662 }
1663 break;
1664 }
1665
1666 case MODIFYVM_AUDIO:
1667 {
1668 ComPtr<IAudioAdapter> audioAdapter;
1669 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1670 ASSERT(audioAdapter);
1671
1672 /* disable? */
1673 if (!strcmp(ValueUnion.psz, "none"))
1674 {
1675 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1676 }
1677 else if (!strcmp(ValueUnion.psz, "null"))
1678 {
1679 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1680 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1681 }
1682#ifdef RT_OS_WINDOWS
1683#ifdef VBOX_WITH_WINMM
1684 else if (!strcmp(ValueUnion.psz, "winmm"))
1685 {
1686 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1687 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1688 }
1689#endif
1690 else if (!strcmp(ValueUnion.psz, "dsound"))
1691 {
1692 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1693 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1694 }
1695#endif /* RT_OS_WINDOWS */
1696#ifdef RT_OS_LINUX
1697# ifdef VBOX_WITH_ALSA
1698 else if (!strcmp(ValueUnion.psz, "alsa"))
1699 {
1700 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1701 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1702 }
1703# endif
1704# ifdef VBOX_WITH_PULSE
1705 else if (!strcmp(ValueUnion.psz, "pulse"))
1706 {
1707 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1708 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1709 }
1710# endif
1711#endif /* !RT_OS_LINUX */
1712#ifdef RT_OS_SOLARIS
1713 else if (!strcmp(ValueUnion.psz, "solaudio"))
1714 {
1715 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1716 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1717 }
1718#endif /* !RT_OS_SOLARIS */
1719#ifdef RT_OS_FREEBSD
1720 else if (!strcmp(ValueUnion.psz, "oss"))
1721 {
1722 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1723 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1724 }
1725# ifdef VBOX_WITH_PULSE
1726 else if (!strcmp(ValueUnion.psz, "pulse"))
1727 {
1728 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1729 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1730 }
1731# endif
1732#endif /* !RT_OS_FREEBSD */
1733#ifdef RT_OS_DARWIN
1734 else if (!strcmp(ValueUnion.psz, "coreaudio"))
1735 {
1736 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1737 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1738 }
1739
1740#endif /* !RT_OS_DARWIN */
1741# if defined(RT_OS_FREEBSD) || defined(RT_OS_LINUX) || defined(VBOX_WITH_SOLARIS_OSS)
1742 else if (!strcmp(ValueUnion.psz, "oss"))
1743 {
1744 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1745 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1746 }
1747# endif
1748 else
1749 {
1750 errorArgument("Invalid --audio argument '%s'", ValueUnion.psz);
1751 rc = E_FAIL;
1752 }
1753 break;
1754 }
1755
1756 case MODIFYVM_CLIPBOARD:
1757 {
1758 if (!strcmp(ValueUnion.psz, "disabled"))
1759 {
1760 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Disabled));
1761 }
1762 else if (!strcmp(ValueUnion.psz, "hosttoguest"))
1763 {
1764 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_HostToGuest));
1765 }
1766 else if (!strcmp(ValueUnion.psz, "guesttohost"))
1767 {
1768 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_GuestToHost));
1769 }
1770 else if (!strcmp(ValueUnion.psz, "bidirectional"))
1771 {
1772 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Bidirectional));
1773 }
1774 else
1775 {
1776 errorArgument("Invalid --clipboard argument '%s'", ValueUnion.psz);
1777 rc = E_FAIL;
1778 }
1779 break;
1780 }
1781
1782 case MODIFYVM_VRDE_EXTPACK:
1783 {
1784 ComPtr<IVRDEServer> vrdeServer;
1785 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1786 ASSERT(vrdeServer);
1787
1788 if (vrdeServer)
1789 {
1790 if (strcmp(ValueUnion.psz, "default") != 0)
1791 {
1792 Bstr bstr(ValueUnion.psz);
1793 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(bstr.raw()));
1794 }
1795 else
1796 CHECK_ERROR(vrdeServer, COMSETTER(VRDEExtPack)(NULL));
1797 }
1798 break;
1799 }
1800
1801 case MODIFYVM_VRDEPROPERTY:
1802 {
1803 ComPtr<IVRDEServer> vrdeServer;
1804 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1805 ASSERT(vrdeServer);
1806
1807 if (vrdeServer)
1808 {
1809 /* Parse 'name=value' */
1810 char *pszProperty = RTStrDup(ValueUnion.psz);
1811 if (pszProperty)
1812 {
1813 char *pDelimiter = strchr(pszProperty, '=');
1814 if (pDelimiter)
1815 {
1816 *pDelimiter = '\0';
1817
1818 Bstr bstrName = pszProperty;
1819 Bstr bstrValue = &pDelimiter[1];
1820 CHECK_ERROR(vrdeServer, SetVRDEProperty(bstrName.raw(), bstrValue.raw()));
1821 }
1822 else
1823 {
1824 RTStrFree(pszProperty);
1825
1826 errorArgument("Invalid --vrdeproperty argument '%s'", ValueUnion.psz);
1827 rc = E_FAIL;
1828 break;
1829 }
1830 RTStrFree(pszProperty);
1831 }
1832 else
1833 {
1834 RTStrmPrintf(g_pStdErr, "Error: Failed to allocate memory for VRDE property '%s'\n", ValueUnion.psz);
1835 rc = E_FAIL;
1836 }
1837 }
1838 break;
1839 }
1840
1841 case MODIFYVM_VRDPPORT:
1842 vrdeWarningDeprecatedOption("port");
1843
1844 case MODIFYVM_VRDEPORT:
1845 {
1846 ComPtr<IVRDEServer> vrdeServer;
1847 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1848 ASSERT(vrdeServer);
1849
1850 if (!strcmp(ValueUnion.psz, "default"))
1851 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr("0").raw()));
1852 else
1853 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Ports").raw(), Bstr(ValueUnion.psz).raw()));
1854 break;
1855 }
1856
1857 case MODIFYVM_VRDPADDRESS:
1858 vrdeWarningDeprecatedOption("address");
1859
1860 case MODIFYVM_VRDEADDRESS:
1861 {
1862 ComPtr<IVRDEServer> vrdeServer;
1863 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1864 ASSERT(vrdeServer);
1865
1866 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("TCP/Address").raw(), Bstr(ValueUnion.psz).raw()));
1867 break;
1868 }
1869
1870 case MODIFYVM_VRDPAUTHTYPE:
1871 vrdeWarningDeprecatedOption("authtype");
1872 case MODIFYVM_VRDEAUTHTYPE:
1873 {
1874 ComPtr<IVRDEServer> vrdeServer;
1875 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1876 ASSERT(vrdeServer);
1877
1878 if (!strcmp(ValueUnion.psz, "null"))
1879 {
1880 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Null));
1881 }
1882 else if (!strcmp(ValueUnion.psz, "external"))
1883 {
1884 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_External));
1885 }
1886 else if (!strcmp(ValueUnion.psz, "guest"))
1887 {
1888 CHECK_ERROR(vrdeServer, COMSETTER(AuthType)(AuthType_Guest));
1889 }
1890 else
1891 {
1892 errorArgument("Invalid --vrdeauthtype argument '%s'", ValueUnion.psz);
1893 rc = E_FAIL;
1894 }
1895 break;
1896 }
1897
1898 case MODIFYVM_VRDEAUTHLIBRARY:
1899 {
1900 ComPtr<IVRDEServer> vrdeServer;
1901 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1902 ASSERT(vrdeServer);
1903
1904 if (vrdeServer)
1905 {
1906 if (strcmp(ValueUnion.psz, "default") != 0)
1907 {
1908 Bstr bstr(ValueUnion.psz);
1909 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(bstr.raw()));
1910 }
1911 else
1912 CHECK_ERROR(vrdeServer, COMSETTER(AuthLibrary)(NULL));
1913 }
1914 break;
1915 }
1916
1917 case MODIFYVM_VRDPMULTICON:
1918 vrdeWarningDeprecatedOption("multicon");
1919 case MODIFYVM_VRDEMULTICON:
1920 {
1921 ComPtr<IVRDEServer> vrdeServer;
1922 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1923 ASSERT(vrdeServer);
1924
1925 CHECK_ERROR(vrdeServer, COMSETTER(AllowMultiConnection)(ValueUnion.f));
1926 break;
1927 }
1928
1929 case MODIFYVM_VRDPREUSECON:
1930 vrdeWarningDeprecatedOption("reusecon");
1931 case MODIFYVM_VRDEREUSECON:
1932 {
1933 ComPtr<IVRDEServer> vrdeServer;
1934 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1935 ASSERT(vrdeServer);
1936
1937 CHECK_ERROR(vrdeServer, COMSETTER(ReuseSingleConnection)(ValueUnion.f));
1938 break;
1939 }
1940
1941 case MODIFYVM_VRDPVIDEOCHANNEL:
1942 vrdeWarningDeprecatedOption("videochannel");
1943 case MODIFYVM_VRDEVIDEOCHANNEL:
1944 {
1945 ComPtr<IVRDEServer> vrdeServer;
1946 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1947 ASSERT(vrdeServer);
1948
1949 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Enabled").raw(),
1950 ValueUnion.f? Bstr("true").raw(): Bstr("false").raw()));
1951 break;
1952 }
1953
1954 case MODIFYVM_VRDPVIDEOCHANNELQUALITY:
1955 vrdeWarningDeprecatedOption("videochannelquality");
1956 case MODIFYVM_VRDEVIDEOCHANNELQUALITY:
1957 {
1958 ComPtr<IVRDEServer> vrdeServer;
1959 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1960 ASSERT(vrdeServer);
1961
1962 CHECK_ERROR(vrdeServer, SetVRDEProperty(Bstr("VideoChannel/Quality").raw(),
1963 Bstr(ValueUnion.psz).raw()));
1964 break;
1965 }
1966
1967 case MODIFYVM_VRDP:
1968 vrdeWarningDeprecatedOption("");
1969 case MODIFYVM_VRDE:
1970 {
1971 ComPtr<IVRDEServer> vrdeServer;
1972 machine->COMGETTER(VRDEServer)(vrdeServer.asOutParam());
1973 ASSERT(vrdeServer);
1974
1975 CHECK_ERROR(vrdeServer, COMSETTER(Enabled)(ValueUnion.f));
1976 break;
1977 }
1978
1979 case MODIFYVM_USBEHCI:
1980 {
1981 ComPtr<IUSBController> UsbCtl;
1982 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1983 if (SUCCEEDED(rc))
1984 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEhci)(ValueUnion.f));
1985 break;
1986 }
1987
1988 case MODIFYVM_USB:
1989 {
1990 ComPtr<IUSBController> UsbCtl;
1991 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1992 if (SUCCEEDED(rc))
1993 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(ValueUnion.f));
1994 break;
1995 }
1996
1997 case MODIFYVM_SNAPSHOTFOLDER:
1998 {
1999 if (!strcmp(ValueUnion.psz, "default"))
2000 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(NULL));
2001 else
2002 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(ValueUnion.psz).raw()));
2003 break;
2004 }
2005
2006 case MODIFYVM_TELEPORTER_ENABLED:
2007 {
2008 CHECK_ERROR(machine, COMSETTER(TeleporterEnabled)(ValueUnion.f));
2009 break;
2010 }
2011
2012 case MODIFYVM_TELEPORTER_PORT:
2013 {
2014 CHECK_ERROR(machine, COMSETTER(TeleporterPort)(ValueUnion.u32));
2015 break;
2016 }
2017
2018 case MODIFYVM_TELEPORTER_ADDRESS:
2019 {
2020 CHECK_ERROR(machine, COMSETTER(TeleporterAddress)(Bstr(ValueUnion.psz).raw()));
2021 break;
2022 }
2023
2024 case MODIFYVM_TELEPORTER_PASSWORD:
2025 {
2026 CHECK_ERROR(machine, COMSETTER(TeleporterPassword)(Bstr(ValueUnion.psz).raw()));
2027 break;
2028 }
2029
2030 case MODIFYVM_FAULT_TOLERANCE:
2031 {
2032 if (!strcmp(ValueUnion.psz, "master"))
2033 {
2034 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Master)));
2035 }
2036 else
2037 if (!strcmp(ValueUnion.psz, "standby"))
2038 {
2039 CHECK_ERROR(machine, COMSETTER(FaultToleranceState(FaultToleranceState_Standby)));
2040 }
2041 else
2042 {
2043 errorArgument("Invalid --faulttolerance argument '%s'", ValueUnion.psz);
2044 rc = E_FAIL;
2045 }
2046 break;
2047 }
2048
2049 case MODIFYVM_FAULT_TOLERANCE_ADDRESS:
2050 {
2051 CHECK_ERROR(machine, COMSETTER(FaultToleranceAddress)(Bstr(ValueUnion.psz).raw()));
2052 break;
2053 }
2054
2055 case MODIFYVM_FAULT_TOLERANCE_PORT:
2056 {
2057 CHECK_ERROR(machine, COMSETTER(FaultTolerancePort)(ValueUnion.u32));
2058 break;
2059 }
2060
2061 case MODIFYVM_FAULT_TOLERANCE_PASSWORD:
2062 {
2063 CHECK_ERROR(machine, COMSETTER(FaultTolerancePassword)(Bstr(ValueUnion.psz).raw()));
2064 break;
2065 }
2066
2067 case MODIFYVM_FAULT_TOLERANCE_SYNC_INTERVAL:
2068 {
2069 CHECK_ERROR(machine, COMSETTER(FaultToleranceSyncInterval)(ValueUnion.u32));
2070 break;
2071 }
2072
2073 case MODIFYVM_HARDWARE_UUID:
2074 {
2075 CHECK_ERROR(machine, COMSETTER(HardwareUUID)(Bstr(ValueUnion.psz).raw()));
2076 break;
2077 }
2078
2079 case MODIFYVM_HPET:
2080 {
2081 CHECK_ERROR(machine, COMSETTER(HpetEnabled)(ValueUnion.f));
2082 break;
2083 }
2084
2085 case MODIFYVM_IOCACHE:
2086 {
2087 CHECK_ERROR(machine, COMSETTER(IoCacheEnabled)(ValueUnion.f));
2088 break;
2089 }
2090
2091 case MODIFYVM_IOCACHESIZE:
2092 {
2093 CHECK_ERROR(machine, COMSETTER(IoCacheSize)(ValueUnion.u32));
2094 break;
2095 }
2096
2097 case MODIFYVM_CHIPSET:
2098 {
2099 if (!strcmp(ValueUnion.psz, "piix3"))
2100 {
2101 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_PIIX3));
2102 }
2103 else if (!strcmp(ValueUnion.psz, "ich9"))
2104 {
2105 CHECK_ERROR(machine, COMSETTER(ChipsetType)(ChipsetType_ICH9));
2106 BOOL fIoApic = FALSE;
2107 CHECK_ERROR(biosSettings, COMGETTER(IOAPICEnabled)(&fIoApic));
2108 if (!fIoApic)
2109 {
2110 RTStrmPrintf(g_pStdErr, "*** I/O APIC must be enabled for ICH9, enabling. ***\n");
2111 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(TRUE));
2112 }
2113 }
2114 else
2115 {
2116 errorArgument("Invalid --chipset argument '%s' (valid: piix3,ich9)", ValueUnion.psz);
2117 rc = E_FAIL;
2118 }
2119 break;
2120 }
2121
2122 default:
2123 {
2124 errorGetOpt(USAGE_MODIFYVM, c, &ValueUnion);
2125 rc = E_FAIL;
2126 break;
2127 }
2128 }
2129 }
2130
2131 /* commit changes */
2132 if (SUCCEEDED(rc))
2133 CHECK_ERROR(machine, SaveSettings());
2134
2135 /* it's important to always close sessions */
2136 a->session->UnlockMachine();
2137
2138 return SUCCEEDED(rc) ? 0 : 1;
2139}
2140
2141#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