VirtualBox

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

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

warning

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