VirtualBox

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

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

Main: have Machine::MountMedium() behave like AttachDevice (use IMedium* pointer instead of UUID); add missing saveSettings calls there

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