VirtualBox

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

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

Main: Implemenation of per-machine media registries; VirtualBox::openMedium() no longer adds media to the global registry, instead a media are stored in a machine XML registry after Machine::AttachDevice() has been called; Machine::AttachDevice() now takes an IMedium object instead of a UUID; also make Machine::Unregister() work again for inaccessible machines

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