VirtualBox

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

Last change on this file since 16867 was 16867, checked in by vboxsync, 16 years ago

Main: rename IHardDiskImage2 to IHardDiskImage; rename IFloppyImage2 to IFloppyImage; rename all media-related methods with a '2' suffix

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 64.0 KB
Line 
1/* $Id: VBoxManageModifyVM.cpp 16867 2009-02-17 17:00:56Z vboxsync $ */
2/** @file
3 * VBoxManage - Implementation of -modifyvm command.
4 */
5
6/*
7 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#ifndef VBOX_ONLY_DOCS
26#include <VBox/com/com.h>
27#include <VBox/com/ErrorInfo.h>
28#include <VBox/com/errorprint2.h>
29#include <VBox/com/EventQueue.h>
30
31#include <VBox/com/VirtualBox.h>
32
33#include <vector>
34#include <list>
35#endif /* !VBOX_ONLY_DOCS */
36
37#include <iprt/cidr.h>
38#include <iprt/param.h>
39#include <iprt/path.h>
40#include <iprt/stream.h>
41#include <iprt/string.h>
42#include <VBox/log.h>
43
44#include "VBoxManage.h"
45
46#ifndef VBOX_ONLY_DOCS
47using namespace com;
48
49
50/** @todo refine this after HDD changes; MSC 8.0/64 has trouble with handleModifyVM. */
51#if defined(_MSC_VER)
52# pragma optimize("g", off)
53#endif
54
55int handleModifyVM(HandlerArg *a)
56{
57 HRESULT rc;
58 Bstr name;
59 Bstr ostype;
60 uint32_t memorySize = 0;
61 uint32_t vramSize = 0;
62 char *acpi = NULL;
63 char *hwvirtex = NULL;
64 char *nestedpaging = NULL;
65 char *vtxvpid = NULL;
66 char *pae = NULL;
67 char *ioapic = NULL;
68 uint32_t monitorcount = ~0;
69 char *accelerate3d = NULL;
70 char *bioslogofadein = NULL;
71 char *bioslogofadeout = NULL;
72 uint32_t bioslogodisplaytime = ~0;
73 char *bioslogoimagepath = NULL;
74 char *biosbootmenumode = NULL;
75 char *biossystemtimeoffset = NULL;
76 char *biospxedebug = NULL;
77 DeviceType_T bootDevice[4];
78 int bootDeviceChanged[4] = { false };
79 char *hdds[34] = {0};
80 char *dvd = NULL;
81 char *dvdpassthrough = NULL;
82 char *idecontroller = NULL;
83 char *floppy = NULL;
84 char *audio = NULL;
85 char *audiocontroller = NULL;
86 char *clipboard = NULL;
87#ifdef VBOX_WITH_VRDP
88 char *vrdp = NULL;
89 uint16_t vrdpport = UINT16_MAX;
90 char *vrdpaddress = NULL;
91 char *vrdpauthtype = NULL;
92 char *vrdpmulticon = NULL;
93 char *vrdpreusecon = NULL;
94#endif
95 int fUsbEnabled = -1;
96 int fUsbEhciEnabled = -1;
97 char *snapshotFolder = NULL;
98 ULONG guestMemBalloonSize = (ULONG)-1;
99 ULONG guestStatInterval = (ULONG)-1;
100 int fSataEnabled = -1;
101 int sataPortCount = -1;
102 int sataBootDevices[4] = {-1,-1,-1,-1};
103
104 /* VM ID + at least one parameter. Parameter arguments are checked
105 * individually. */
106 if (a->argc < 2)
107 return errorSyntax(USAGE_MODIFYVM, "Not enough parameters");
108
109 /* Get the number of network adapters */
110 ULONG NetworkAdapterCount = 0;
111 {
112 ComPtr <ISystemProperties> info;
113 CHECK_ERROR_RET (a->virtualBox, COMGETTER(SystemProperties) (info.asOutParam()), 1);
114 CHECK_ERROR_RET (info, COMGETTER(NetworkAdapterCount) (&NetworkAdapterCount), 1);
115 }
116 ULONG SerialPortCount = 0;
117 {
118 ComPtr <ISystemProperties> info;
119 CHECK_ERROR_RET (a->virtualBox, COMGETTER(SystemProperties) (info.asOutParam()), 1);
120 CHECK_ERROR_RET (info, COMGETTER(SerialPortCount) (&SerialPortCount), 1);
121 }
122
123 std::vector <char *> nics (NetworkAdapterCount, 0);
124 std::vector <char *> nictype (NetworkAdapterCount, 0);
125 std::vector <char *> cableconnected (NetworkAdapterCount, 0);
126 std::vector <char *> nictrace (NetworkAdapterCount, 0);
127 std::vector <char *> nictracefile (NetworkAdapterCount, 0);
128 std::vector <char *> nicspeed (NetworkAdapterCount, 0);
129 std::vector <char *> hostifdev (NetworkAdapterCount, 0);
130 std::vector <const char *> intnet (NetworkAdapterCount, 0);
131 std::vector <const char *> natnet (NetworkAdapterCount, 0);
132 std::vector <char *> macs (NetworkAdapterCount, 0);
133 std::vector <char *> uarts_mode (SerialPortCount, 0);
134 std::vector <ULONG> uarts_base (SerialPortCount, 0);
135 std::vector <ULONG> uarts_irq (SerialPortCount, 0);
136 std::vector <char *> uarts_path (SerialPortCount, 0);
137
138 for (int i = 1; i < a->argc; i++)
139 {
140 if (strcmp(a->argv[i], "-name") == 0)
141 {
142 if (a->argc <= i + 1)
143 return errorArgument("Missing argument to '%s'", a->argv[i]);
144 i++;
145 name = a->argv[i];
146 }
147 else if (strcmp(a->argv[i], "-ostype") == 0)
148 {
149 if (a->argc <= i + 1)
150 return errorArgument("Missing argument to '%s'", a->argv[i]);
151 i++;
152 ostype = a->argv[i];
153 }
154 else if (strcmp(a->argv[i], "-memory") == 0)
155 {
156 if (a->argc <= i + 1)
157 return errorArgument("Missing argument to '%s'", a->argv[i]);
158 i++;
159 memorySize = RTStrToUInt32(a->argv[i]);
160 }
161 else if (strcmp(a->argv[i], "-vram") == 0)
162 {
163 if (a->argc <= i + 1)
164 return errorArgument("Missing argument to '%s'", a->argv[i]);
165 i++;
166 vramSize = RTStrToUInt32(a->argv[i]);
167 }
168 else if (strcmp(a->argv[i], "-acpi") == 0)
169 {
170 if (a->argc <= i + 1)
171 return errorArgument("Missing argument to '%s'", a->argv[i]);
172 i++;
173 acpi = a->argv[i];
174 }
175 else if (strcmp(a->argv[i], "-ioapic") == 0)
176 {
177 if (a->argc <= i + 1)
178 return errorArgument("Missing argument to '%s'", a->argv[i]);
179 i++;
180 ioapic = a->argv[i];
181 }
182 else if (strcmp(a->argv[i], "-hwvirtex") == 0)
183 {
184 if (a->argc <= i + 1)
185 return errorArgument("Missing argument to '%s'", a->argv[i]);
186 i++;
187 hwvirtex = a->argv[i];
188 }
189 else if (strcmp(a->argv[i], "-nestedpaging") == 0)
190 {
191 if (a->argc <= i + 1)
192 return errorArgument("Missing argument to '%s'", a->argv[i]);
193 i++;
194 nestedpaging = a->argv[i];
195 }
196 else if (strcmp(a->argv[i], "-vtxvpid") == 0)
197 {
198 if (a->argc <= i + 1)
199 return errorArgument("Missing argument to '%s'", a->argv[i]);
200 i++;
201 vtxvpid = a->argv[i];
202 }
203 else if (strcmp(a->argv[i], "-pae") == 0)
204 {
205 if (a->argc <= i + 1)
206 return errorArgument("Missing argument to '%s'", a->argv[i]);
207 i++;
208 pae = a->argv[i];
209 }
210 else if (strcmp(a->argv[i], "-monitorcount") == 0)
211 {
212 if (a->argc <= i + 1)
213 return errorArgument("Missing argument to '%s'", a->argv[i]);
214 i++;
215 monitorcount = RTStrToUInt32(a->argv[i]);
216 }
217 else if (strcmp(a->argv[i], "-accelerate3d") == 0)
218 {
219 if (a->argc <= i + 1)
220 return errorArgument("Missing argument to '%s'", a->argv[i]);
221 i++;
222 accelerate3d = a->argv[i];
223 }
224 else if (strcmp(a->argv[i], "-bioslogofadein") == 0)
225 {
226 if (a->argc <= i + 1)
227 return errorArgument("Missing argument to '%s'", a->argv[i]);
228 i++;
229 bioslogofadein = a->argv[i];
230 }
231 else if (strcmp(a->argv[i], "-bioslogofadeout") == 0)
232 {
233 if (a->argc <= i + 1)
234 return errorArgument("Missing argument to '%s'", a->argv[i]);
235 i++;
236 bioslogofadeout = a->argv[i];
237 }
238 else if (strcmp(a->argv[i], "-bioslogodisplaytime") == 0)
239 {
240 if (a->argc <= i + 1)
241 return errorArgument("Missing argument to '%s'", a->argv[i]);
242 i++;
243 bioslogodisplaytime = RTStrToUInt32(a->argv[i]);
244 }
245 else if (strcmp(a->argv[i], "-bioslogoimagepath") == 0)
246 {
247 if (a->argc <= i + 1)
248 return errorArgument("Missing argument to '%s'", a->argv[i]);
249 i++;
250 bioslogoimagepath = a->argv[i];
251 }
252 else if (strcmp(a->argv[i], "-biosbootmenu") == 0)
253 {
254 if (a->argc <= i + 1)
255 return errorArgument("Missing argument to '%s'", a->argv[i]);
256 i++;
257 biosbootmenumode = a->argv[i];
258 }
259 else if (strcmp(a->argv[i], "-biossystemtimeoffset") == 0)
260 {
261 if (a->argc <= i + 1)
262 return errorArgument("Missing argument to '%s'", a->argv[i]);
263 i++;
264 biossystemtimeoffset = a->argv[i];
265 }
266 else if (strcmp(a->argv[i], "-biospxedebug") == 0)
267 {
268 if (a->argc <= i + 1)
269 return errorArgument("Missing argument to '%s'", a->argv[i]);
270 i++;
271 biospxedebug = a->argv[i];
272 }
273 else if (strncmp(a->argv[i], "-boot", 5) == 0)
274 {
275 uint32_t n = 0;
276 if (!a->argv[i][5])
277 return errorSyntax(USAGE_MODIFYVM, "Missing boot slot number in '%s'", a->argv[i]);
278 if (VINF_SUCCESS != RTStrToUInt32Full(&a->argv[i][5], 10, &n))
279 return errorSyntax(USAGE_MODIFYVM, "Invalid boot slot number in '%s'", a->argv[i]);
280 if (a->argc <= i + 1)
281 return errorArgument("Missing argument to '%s'", a->argv[i]);
282 i++;
283 if (strcmp(a->argv[i], "none") == 0)
284 {
285 bootDevice[n - 1] = DeviceType_Null;
286 }
287 else if (strcmp(a->argv[i], "floppy") == 0)
288 {
289 bootDevice[n - 1] = DeviceType_Floppy;
290 }
291 else if (strcmp(a->argv[i], "dvd") == 0)
292 {
293 bootDevice[n - 1] = DeviceType_DVD;
294 }
295 else if (strcmp(a->argv[i], "disk") == 0)
296 {
297 bootDevice[n - 1] = DeviceType_HardDisk;
298 }
299 else if (strcmp(a->argv[i], "net") == 0)
300 {
301 bootDevice[n - 1] = DeviceType_Network;
302 }
303 else
304 return errorArgument("Invalid boot device '%s'", a->argv[i]);
305
306 bootDeviceChanged[n - 1] = true;
307 }
308 else if (strcmp(a->argv[i], "-hda") == 0)
309 {
310 if (a->argc <= i + 1)
311 return errorArgument("Missing argument to '%s'", a->argv[i]);
312 i++;
313 hdds[0] = a->argv[i];
314 }
315 else if (strcmp(a->argv[i], "-hdb") == 0)
316 {
317 if (a->argc <= i + 1)
318 return errorArgument("Missing argument to '%s'", a->argv[i]);
319 i++;
320 hdds[1] = a->argv[i];
321 }
322 else if (strcmp(a->argv[i], "-hdd") == 0)
323 {
324 if (a->argc <= i + 1)
325 return errorArgument("Missing argument to '%s'", a->argv[i]);
326 i++;
327 hdds[2] = a->argv[i];
328 }
329 else if (strcmp(a->argv[i], "-dvd") == 0)
330 {
331 if (a->argc <= i + 1)
332 return errorArgument("Missing argument to '%s'", a->argv[i]);
333 i++;
334 dvd = a->argv[i];
335 }
336 else if (strcmp(a->argv[i], "-dvdpassthrough") == 0)
337 {
338 if (a->argc <= i + 1)
339 return errorArgument("Missing argument to '%s'", a->argv[i]);
340 i++;
341 dvdpassthrough = a->argv[i];
342 }
343 else if (strcmp(a->argv[i], "-idecontroller") == 0)
344 {
345 if (a->argc <= i + 1)
346 return errorArgument("Missing argument to '%s'", a->argv[i]);
347 i++;
348 idecontroller = a->argv[i];
349 }
350 else if (strcmp(a->argv[i], "-floppy") == 0)
351 {
352 if (a->argc <= i + 1)
353 return errorArgument("Missing argument to '%s'", a->argv[i]);
354 i++;
355 floppy = a->argv[i];
356 }
357 else if (strcmp(a->argv[i], "-audio") == 0)
358 {
359 if (a->argc <= i + 1)
360 return errorArgument("Missing argument to '%s'", a->argv[i]);
361 i++;
362 audio = a->argv[i];
363 }
364 else if (strcmp(a->argv[i], "-audiocontroller") == 0)
365 {
366 if (a->argc <= i + 1)
367 return errorArgument("Missing argument to '%s'", a->argv[i]);
368 i++;
369 audiocontroller = a->argv[i];
370 }
371 else if (strcmp(a->argv[i], "-clipboard") == 0)
372 {
373 if (a->argc <= i + 1)
374 return errorArgument("Missing argument to '%s'", a->argv[i]);
375 i++;
376 clipboard = a->argv[i];
377 }
378 else if (strncmp(a->argv[i], "-cableconnected", 15) == 0)
379 {
380 unsigned n = parseNum(&a->argv[i][15], NetworkAdapterCount, "NIC");
381 if (!n)
382 return 1;
383
384 if (a->argc <= i + 1)
385 return errorArgument("Missing argument to '%s'", a->argv[i]);
386
387 cableconnected[n - 1] = a->argv[i + 1];
388 i++;
389 }
390 /* watch for the right order of these -nic* comparisons! */
391 else if (strncmp(a->argv[i], "-nictracefile", 13) == 0)
392 {
393 unsigned n = parseNum(&a->argv[i][13], NetworkAdapterCount, "NIC");
394 if (!n)
395 return 1;
396 if (a->argc <= i + 1)
397 {
398 return errorArgument("Missing argument to '%s'", a->argv[i]);
399 }
400 nictracefile[n - 1] = a->argv[i + 1];
401 i++;
402 }
403 else if (strncmp(a->argv[i], "-nictrace", 9) == 0)
404 {
405 unsigned n = parseNum(&a->argv[i][9], NetworkAdapterCount, "NIC");
406 if (!n)
407 return 1;
408 if (a->argc <= i + 1)
409 return errorArgument("Missing argument to '%s'", a->argv[i]);
410 nictrace[n - 1] = a->argv[i + 1];
411 i++;
412 }
413 else if (strncmp(a->argv[i], "-nictype", 8) == 0)
414 {
415 unsigned n = parseNum(&a->argv[i][8], NetworkAdapterCount, "NIC");
416 if (!n)
417 return 1;
418 if (a->argc <= i + 1)
419 return errorArgument("Missing argument to '%s'", a->argv[i]);
420 nictype[n - 1] = a->argv[i + 1];
421 i++;
422 }
423 else if (strncmp(a->argv[i], "-nicspeed", 9) == 0)
424 {
425 unsigned n = parseNum(&a->argv[i][9], NetworkAdapterCount, "NIC");
426 if (!n)
427 return 1;
428 if (a->argc <= i + 1)
429 return errorArgument("Missing argument to '%s'", a->argv[i]);
430 nicspeed[n - 1] = a->argv[i + 1];
431 i++;
432 }
433 else if (strncmp(a->argv[i], "-nic", 4) == 0)
434 {
435 unsigned n = parseNum(&a->argv[i][4], NetworkAdapterCount, "NIC");
436 if (!n)
437 return 1;
438 if (a->argc <= i + 1)
439 return errorArgument("Missing argument to '%s'", a->argv[i]);
440 nics[n - 1] = a->argv[i + 1];
441 i++;
442 }
443 else if (strncmp(a->argv[i], "-hostifdev", 10) == 0)
444 {
445 unsigned n = parseNum(&a->argv[i][10], NetworkAdapterCount, "NIC");
446 if (!n)
447 return 1;
448 if (a->argc <= i + 1)
449 return errorArgument("Missing argument to '%s'", a->argv[i]);
450 hostifdev[n - 1] = a->argv[i + 1];
451 i++;
452 }
453 else if (strncmp(a->argv[i], "-intnet", 7) == 0)
454 {
455 unsigned n = parseNum(&a->argv[i][7], NetworkAdapterCount, "NIC");
456 if (!n)
457 return 1;
458 if (a->argc <= i + 1)
459 return errorArgument("Missing argument to '%s'", a->argv[i]);
460 intnet[n - 1] = a->argv[i + 1];
461 i++;
462 }
463 else if (strncmp(a->argv[i], "-natnet", 7) == 0)
464 {
465 unsigned n = parseNum(&a->argv[i][7], NetworkAdapterCount, "NIC");
466 if (!n)
467 return 1;
468 if (a->argc <= i + 1)
469 return errorArgument("Missing argument to '%s'", a->argv[i]);
470
471 if (!strcmp(a->argv[i + 1], "default"))
472 natnet[n - 1] = "";
473 else
474 {
475 RTIPV4ADDR Network;
476 RTIPV4ADDR Netmask;
477 int rc = RTCidrStrToIPv4(a->argv[i + 1], &Network, &Netmask);
478 if (RT_FAILURE(rc))
479 return errorArgument("Invalid IPv4 network '%s' specified -- CIDR notation expected.\n", a->argv[i + 1]);
480 if (Netmask & 0x1f)
481 return errorArgument("Prefix length of the NAT network must be less than 28.\n");
482 natnet[n - 1] = a->argv[i + 1];
483 }
484 i++;
485 }
486 else if (strncmp(a->argv[i], "-macaddress", 11) == 0)
487 {
488 unsigned n = parseNum(&a->argv[i][11], NetworkAdapterCount, "NIC");
489 if (!n)
490 return 1;
491 if (a->argc <= i + 1)
492 return errorArgument("Missing argument to '%s'", a->argv[i]);
493 macs[n - 1] = a->argv[i + 1];
494 i++;
495 }
496#ifdef VBOX_WITH_VRDP
497 else if (strcmp(a->argv[i], "-vrdp") == 0)
498 {
499 if (a->argc <= i + 1)
500 return errorArgument("Missing argument to '%s'", a->argv[i]);
501 i++;
502 vrdp = a->argv[i];
503 }
504 else if (strcmp(a->argv[i], "-vrdpport") == 0)
505 {
506 if (a->argc <= i + 1)
507 return errorArgument("Missing argument to '%s'", a->argv[i]);
508 i++;
509 if (strcmp(a->argv[i], "default") == 0)
510 vrdpport = 0;
511 else
512 vrdpport = RTStrToUInt16(a->argv[i]);
513 }
514 else if (strcmp(a->argv[i], "-vrdpaddress") == 0)
515 {
516 if (a->argc <= i + 1)
517 return errorArgument("Missing argument to '%s'", a->argv[i]);
518 i++;
519 vrdpaddress = a->argv[i];
520 }
521 else if (strcmp(a->argv[i], "-vrdpauthtype") == 0)
522 {
523 if (a->argc <= i + 1)
524 return errorArgument("Missing argument to '%s'", a->argv[i]);
525 i++;
526 vrdpauthtype = a->argv[i];
527 }
528 else if (strcmp(a->argv[i], "-vrdpmulticon") == 0)
529 {
530 if (a->argc <= i + 1)
531 return errorArgument("Missing argument to '%s'", a->argv[i]);
532 i++;
533 vrdpmulticon = a->argv[i];
534 }
535 else if (strcmp(a->argv[i], "-vrdpreusecon") == 0)
536 {
537 if (a->argc <= i + 1)
538 return errorArgument("Missing argument to '%s'", a->argv[i]);
539 i++;
540 vrdpreusecon = a->argv[i];
541 }
542#endif /* VBOX_WITH_VRDP */
543 else if (strcmp(a->argv[i], "-usb") == 0)
544 {
545 if (a->argc <= i + 1)
546 return errorArgument("Missing argument to '%s'", a->argv[i]);
547 i++;
548 if (strcmp(a->argv[i], "on") == 0 || strcmp(a->argv[i], "enable") == 0)
549 fUsbEnabled = 1;
550 else if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
551 fUsbEnabled = 0;
552 else
553 return errorArgument("Invalid -usb argument '%s'", a->argv[i]);
554 }
555 else if (strcmp(a->argv[i], "-usbehci") == 0)
556 {
557 if (a->argc <= i + 1)
558 return errorArgument("Missing argument to '%s'", a->argv[i]);
559 i++;
560 if (strcmp(a->argv[i], "on") == 0 || strcmp(a->argv[i], "enable") == 0)
561 fUsbEhciEnabled = 1;
562 else if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
563 fUsbEhciEnabled = 0;
564 else
565 return errorArgument("Invalid -usbehci argument '%s'", a->argv[i]);
566 }
567 else if (strcmp(a->argv[i], "-snapshotfolder") == 0)
568 {
569 if (a->argc <= i + 1)
570 return errorArgument("Missing argument to '%s'", a->argv[i]);
571 i++;
572 snapshotFolder = a->argv[i];
573 }
574 else if (strncmp(a->argv[i], "-uartmode", 9) == 0)
575 {
576 unsigned n = parseNum(&a->argv[i][9], SerialPortCount, "UART");
577 if (!n)
578 return 1;
579 i++;
580 if (strcmp(a->argv[i], "disconnected") == 0)
581 {
582 uarts_mode[n - 1] = a->argv[i];
583 }
584 else
585 {
586 if (strcmp(a->argv[i], "server") == 0 || strcmp(a->argv[i], "client") == 0)
587 {
588 uarts_mode[n - 1] = a->argv[i];
589 i++;
590#ifdef RT_OS_WINDOWS
591 if (strncmp(a->argv[i], "\\\\.\\pipe\\", 9))
592 return errorArgument("Uart pipe must start with \\\\.\\pipe\\");
593#endif
594 }
595 else
596 {
597 uarts_mode[n - 1] = (char*)"device";
598 }
599 if (a->argc <= i)
600 return errorArgument("Missing argument to -uartmode");
601 uarts_path[n - 1] = a->argv[i];
602 }
603 }
604 else if (strncmp(a->argv[i], "-uart", 5) == 0)
605 {
606 unsigned n = parseNum(&a->argv[i][5], SerialPortCount, "UART");
607 if (!n)
608 return 1;
609 if (a->argc <= i + 1)
610 return errorArgument("Missing argument to '%s'", a->argv[i]);
611 i++;
612 if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
613 {
614 uarts_base[n - 1] = (ULONG)-1;
615 }
616 else
617 {
618 if (a->argc <= i + 1)
619 return errorArgument("Missing argument to '%s'", a->argv[i-1]);
620 uint32_t uVal;
621 int vrc;
622 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
623 if (vrc != VINF_SUCCESS || uVal == 0)
624 return errorArgument("Error parsing UART I/O base '%s'", a->argv[i]);
625 uarts_base[n - 1] = uVal;
626 i++;
627 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
628 if (vrc != VINF_SUCCESS)
629 return errorArgument("Error parsing UART IRQ '%s'", a->argv[i]);
630 uarts_irq[n - 1] = uVal;
631 }
632 }
633#ifdef VBOX_WITH_MEM_BALLOONING
634 else if (strncmp(a->argv[i], "-guestmemoryballoon", 19) == 0)
635 {
636 if (a->argc <= i + 1)
637 return errorArgument("Missing argument to '%s'", a->argv[i]);
638 i++;
639 uint32_t uVal;
640 int vrc;
641 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
642 if (vrc != VINF_SUCCESS)
643 return errorArgument("Error parsing guest memory balloon size '%s'", a->argv[i]);
644 guestMemBalloonSize = uVal;
645 }
646#endif
647 else if (strncmp(a->argv[i], "-gueststatisticsinterval", 24) == 0)
648 {
649 if (a->argc <= i + 1)
650 return errorArgument("Missing argument to '%s'", a->argv[i]);
651 i++;
652 uint32_t uVal;
653 int vrc;
654 vrc = RTStrToUInt32Ex(a->argv[i], NULL, 0, &uVal);
655 if (vrc != VINF_SUCCESS)
656 return errorArgument("Error parsing guest statistics interval '%s'", a->argv[i]);
657 guestStatInterval = uVal;
658 }
659 else if (strcmp(a->argv[i], "-sata") == 0)
660 {
661 if (a->argc <= i + 1)
662 return errorArgument("Missing argument to '%s'", a->argv[i]);
663 i++;
664 if (strcmp(a->argv[i], "on") == 0 || strcmp(a->argv[i], "enable") == 0)
665 fSataEnabled = 1;
666 else if (strcmp(a->argv[i], "off") == 0 || strcmp(a->argv[i], "disable") == 0)
667 fSataEnabled = 0;
668 else
669 return errorArgument("Invalid -usb argument '%s'", a->argv[i]);
670 }
671 else if (strcmp(a->argv[i], "-sataportcount") == 0)
672 {
673 unsigned n;
674
675 if (a->argc <= i + 1)
676 return errorArgument("Missing arguments to '%s'", a->argv[i]);
677 i++;
678
679 n = parseNum(a->argv[i], 30, "SATA");
680 if (!n)
681 return 1;
682 sataPortCount = n;
683 }
684 else if (strncmp(a->argv[i], "-sataport", 9) == 0)
685 {
686 unsigned n = parseNum(&a->argv[i][9], 30, "SATA");
687 if (!n)
688 return 1;
689 if (a->argc <= i + 1)
690 return errorArgument("Missing argument to '%s'", a->argv[i]);
691 i++;
692 hdds[n-1+4] = a->argv[i];
693 }
694 else if (strncmp(a->argv[i], "-sataideemulation", 17) == 0)
695 {
696 unsigned bootDevicePos = 0;
697 unsigned n;
698
699 bootDevicePos = parseNum(&a->argv[i][17], 4, "SATA");
700 if (!bootDevicePos)
701 return 1;
702 bootDevicePos--;
703
704 if (a->argc <= i + 1)
705 return errorArgument("Missing arguments to '%s'", a->argv[i]);
706 i++;
707
708 n = parseNum(a->argv[i], 30, "SATA");
709 if (!n)
710 return 1;
711
712 sataBootDevices[bootDevicePos] = n-1;
713 }
714 else
715 return errorSyntax(USAGE_MODIFYVM, "Invalid parameter '%s'", Utf8Str(a->argv[i]).raw());
716 }
717
718 /* try to find the given machine */
719 ComPtr <IMachine> machine;
720 Guid uuid (a->argv[0]);
721 if (!uuid.isEmpty())
722 {
723 CHECK_ERROR (a->virtualBox, GetMachine (uuid, machine.asOutParam()));
724 }
725 else
726 {
727 CHECK_ERROR (a->virtualBox, FindMachine(Bstr(a->argv[0]), machine.asOutParam()));
728 if (SUCCEEDED (rc))
729 machine->COMGETTER(Id)(uuid.asOutParam());
730 }
731 if (FAILED (rc))
732 return 1;
733
734 /* open a session for the VM */
735 CHECK_ERROR_RET (a->virtualBox, OpenSession(a->session, uuid), 1);
736
737 do
738 {
739 /* get the mutable session machine */
740 a->session->COMGETTER(Machine)(machine.asOutParam());
741
742 ComPtr <IBIOSSettings> biosSettings;
743 machine->COMGETTER(BIOSSettings)(biosSettings.asOutParam());
744
745 if (name)
746 CHECK_ERROR(machine, COMSETTER(Name)(name));
747 if (ostype)
748 {
749 ComPtr<IGuestOSType> guestOSType;
750 CHECK_ERROR(a->virtualBox, GetGuestOSType(ostype, guestOSType.asOutParam()));
751 if (SUCCEEDED(rc) && guestOSType)
752 {
753 CHECK_ERROR(machine, COMSETTER(OSTypeId)(ostype));
754 }
755 else
756 {
757 errorArgument("Invalid guest OS type '%s'", Utf8Str(ostype).raw());
758 rc = E_FAIL;
759 break;
760 }
761 }
762 if (memorySize > 0)
763 CHECK_ERROR(machine, COMSETTER(MemorySize)(memorySize));
764 if (vramSize > 0)
765 CHECK_ERROR(machine, COMSETTER(VRAMSize)(vramSize));
766 if (acpi)
767 {
768 if (strcmp(acpi, "on") == 0)
769 {
770 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(true));
771 }
772 else if (strcmp(acpi, "off") == 0)
773 {
774 CHECK_ERROR(biosSettings, COMSETTER(ACPIEnabled)(false));
775 }
776 else
777 {
778 errorArgument("Invalid -acpi argument '%s'", acpi);
779 rc = E_FAIL;
780 break;
781 }
782 }
783 if (ioapic)
784 {
785 if (strcmp(ioapic, "on") == 0)
786 {
787 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(true));
788 }
789 else if (strcmp(ioapic, "off") == 0)
790 {
791 CHECK_ERROR(biosSettings, COMSETTER(IOAPICEnabled)(false));
792 }
793 else
794 {
795 errorArgument("Invalid -ioapic argument '%s'", ioapic);
796 rc = E_FAIL;
797 break;
798 }
799 }
800 if (hwvirtex)
801 {
802 if (strcmp(hwvirtex, "on") == 0)
803 {
804 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_True));
805 }
806 else if (strcmp(hwvirtex, "off") == 0)
807 {
808 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_False));
809 }
810 else if (strcmp(hwvirtex, "default") == 0)
811 {
812 CHECK_ERROR(machine, COMSETTER(HWVirtExEnabled)(TSBool_Default));
813 }
814 else
815 {
816 errorArgument("Invalid -hwvirtex argument '%s'", hwvirtex);
817 rc = E_FAIL;
818 break;
819 }
820 }
821 if (nestedpaging)
822 {
823 if (strcmp(nestedpaging, "on") == 0)
824 {
825 CHECK_ERROR(machine, COMSETTER(HWVirtExNestedPagingEnabled)(true));
826 }
827 else if (strcmp(nestedpaging, "off") == 0)
828 {
829 CHECK_ERROR(machine, COMSETTER(HWVirtExNestedPagingEnabled)(false));
830 }
831 else
832 {
833 errorArgument("Invalid -nestedpaging argument '%s'", ioapic);
834 rc = E_FAIL;
835 break;
836 }
837 }
838 if (vtxvpid)
839 {
840 if (strcmp(vtxvpid, "on") == 0)
841 {
842 CHECK_ERROR(machine, COMSETTER(HWVirtExVPIDEnabled)(true));
843 }
844 else if (strcmp(vtxvpid, "off") == 0)
845 {
846 CHECK_ERROR(machine, COMSETTER(HWVirtExVPIDEnabled)(false));
847 }
848 else
849 {
850 errorArgument("Invalid -vtxvpid argument '%s'", ioapic);
851 rc = E_FAIL;
852 break;
853 }
854 }
855 if (pae)
856 {
857 if (strcmp(pae, "on") == 0)
858 {
859 CHECK_ERROR(machine, COMSETTER(PAEEnabled)(true));
860 }
861 else if (strcmp(pae, "off") == 0)
862 {
863 CHECK_ERROR(machine, COMSETTER(PAEEnabled)(false));
864 }
865 else
866 {
867 errorArgument("Invalid -pae argument '%s'", ioapic);
868 rc = E_FAIL;
869 break;
870 }
871 }
872 if (monitorcount != ~0U)
873 {
874 CHECK_ERROR(machine, COMSETTER(MonitorCount)(monitorcount));
875 }
876 if (accelerate3d)
877 {
878 if (strcmp(accelerate3d, "on") == 0)
879 {
880 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(true));
881 }
882 else if (strcmp(accelerate3d, "off") == 0)
883 {
884 CHECK_ERROR(machine, COMSETTER(Accelerate3DEnabled)(false));
885 }
886 else
887 {
888 errorArgument("Invalid -accelerate3d argument '%s'", ioapic);
889 rc = E_FAIL;
890 break;
891 }
892 }
893 if (bioslogofadein)
894 {
895 if (strcmp(bioslogofadein, "on") == 0)
896 {
897 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(true));
898 }
899 else if (strcmp(bioslogofadein, "off") == 0)
900 {
901 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeIn)(false));
902 }
903 else
904 {
905 errorArgument("Invalid -bioslogofadein argument '%s'", bioslogofadein);
906 rc = E_FAIL;
907 break;
908 }
909 }
910 if (bioslogofadeout)
911 {
912 if (strcmp(bioslogofadeout, "on") == 0)
913 {
914 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(true));
915 }
916 else if (strcmp(bioslogofadeout, "off") == 0)
917 {
918 CHECK_ERROR(biosSettings, COMSETTER(LogoFadeOut)(false));
919 }
920 else
921 {
922 errorArgument("Invalid -bioslogofadeout argument '%s'", bioslogofadeout);
923 rc = E_FAIL;
924 break;
925 }
926 }
927 if (bioslogodisplaytime != ~0U)
928 {
929 CHECK_ERROR(biosSettings, COMSETTER(LogoDisplayTime)(bioslogodisplaytime));
930 }
931 if (bioslogoimagepath)
932 {
933 CHECK_ERROR(biosSettings, COMSETTER(LogoImagePath)(Bstr(bioslogoimagepath)));
934 }
935 if (biosbootmenumode)
936 {
937 if (strcmp(biosbootmenumode, "disabled") == 0)
938 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_Disabled));
939 else if (strcmp(biosbootmenumode, "menuonly") == 0)
940 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MenuOnly));
941 else if (strcmp(biosbootmenumode, "messageandmenu") == 0)
942 CHECK_ERROR(biosSettings, COMSETTER(BootMenuMode)(BIOSBootMenuMode_MessageAndMenu));
943 else
944 {
945 errorArgument("Invalid -biosbootmenu argument '%s'", biosbootmenumode);
946 rc = E_FAIL;
947 break;
948 }
949
950 }
951 if (biossystemtimeoffset)
952 {
953 LONG64 timeOffset = RTStrToInt64(biossystemtimeoffset);
954 CHECK_ERROR(biosSettings, COMSETTER(TimeOffset)(timeOffset));
955 }
956 if (biospxedebug)
957 {
958 if (strcmp(biospxedebug, "on") == 0)
959 {
960 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(true));
961 }
962 else if (strcmp(biospxedebug, "off") == 0)
963 {
964 CHECK_ERROR(biosSettings, COMSETTER(PXEDebugEnabled)(false));
965 }
966 else
967 {
968 errorArgument("Invalid -biospxedebug argument '%s'", biospxedebug);
969 rc = E_FAIL;
970 break;
971 }
972 }
973 for (int curBootDev = 0; curBootDev < 4; curBootDev++)
974 {
975 if (bootDeviceChanged[curBootDev])
976 CHECK_ERROR(machine, SetBootOrder (curBootDev + 1, bootDevice[curBootDev]));
977 }
978 if (hdds[0])
979 {
980 if (strcmp(hdds[0], "none") == 0)
981 {
982 machine->DetachHardDisk(StorageBus_IDE, 0, 0);
983 }
984 else
985 {
986 /* first guess is that it's a UUID */
987 Guid uuid(hdds[0]);
988 ComPtr<IHardDisk> hardDisk;
989 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
990 /* not successful? Then it must be a filename */
991 if (!hardDisk)
992 {
993 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[0]), hardDisk.asOutParam()));
994 if (FAILED(rc))
995 {
996 /* open the new hard disk object */
997 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[0]), hardDisk.asOutParam()));
998 }
999 }
1000 if (hardDisk)
1001 {
1002 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1003 CHECK_ERROR(machine, AttachHardDisk(uuid, StorageBus_IDE, 0, 0));
1004 }
1005 else
1006 rc = E_FAIL;
1007 if (FAILED(rc))
1008 break;
1009 }
1010 }
1011 if (hdds[1])
1012 {
1013 if (strcmp(hdds[1], "none") == 0)
1014 {
1015 machine->DetachHardDisk(StorageBus_IDE, 0, 1);
1016 }
1017 else
1018 {
1019 /* first guess is that it's a UUID */
1020 Guid uuid(hdds[1]);
1021 ComPtr<IHardDisk> hardDisk;
1022 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1023 /* not successful? Then it must be a filename */
1024 if (!hardDisk)
1025 {
1026 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[1]), hardDisk.asOutParam()));
1027 if (FAILED(rc))
1028 {
1029 /* open the new hard disk object */
1030 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[1]), hardDisk.asOutParam()));
1031 }
1032 }
1033 if (hardDisk)
1034 {
1035 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1036 CHECK_ERROR(machine, AttachHardDisk(uuid, StorageBus_IDE, 0, 1));
1037 }
1038 else
1039 rc = E_FAIL;
1040 if (FAILED(rc))
1041 break;
1042 }
1043 }
1044 if (hdds[2])
1045 {
1046 if (strcmp(hdds[2], "none") == 0)
1047 {
1048 machine->DetachHardDisk(StorageBus_IDE, 1, 1);
1049 }
1050 else
1051 {
1052 /* first guess is that it's a UUID */
1053 Guid uuid(hdds[2]);
1054 ComPtr<IHardDisk> hardDisk;
1055 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1056 /* not successful? Then it must be a filename */
1057 if (!hardDisk)
1058 {
1059 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[2]), hardDisk.asOutParam()));
1060 if (FAILED(rc))
1061 {
1062 /* open the new hard disk object */
1063 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[2]), hardDisk.asOutParam()));
1064 }
1065 }
1066 if (hardDisk)
1067 {
1068 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1069 CHECK_ERROR(machine, AttachHardDisk(uuid, StorageBus_IDE, 1, 1));
1070 }
1071 else
1072 rc = E_FAIL;
1073 if (FAILED(rc))
1074 break;
1075 }
1076 }
1077 if (dvd)
1078 {
1079 ComPtr<IDVDDrive> dvdDrive;
1080 machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
1081 ASSERT(dvdDrive);
1082
1083 /* unmount? */
1084 if (strcmp(dvd, "none") == 0)
1085 {
1086 CHECK_ERROR(dvdDrive, Unmount());
1087 }
1088 /* host drive? */
1089 else if (strncmp(dvd, "host:", 5) == 0)
1090 {
1091 ComPtr<IHost> host;
1092 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1093 ComPtr<IHostDVDDriveCollection> hostDVDs;
1094 CHECK_ERROR(host, COMGETTER(DVDDrives)(hostDVDs.asOutParam()));
1095 ComPtr<IHostDVDDrive> hostDVDDrive;
1096 rc = hostDVDs->FindByName(Bstr(dvd + 5), hostDVDDrive.asOutParam());
1097 if (!hostDVDDrive)
1098 {
1099 /* 2nd try: try with the real name, important on Linux+libhal */
1100 char szPathReal[RTPATH_MAX];
1101 if (RT_FAILURE(RTPathReal(dvd + 5, szPathReal, sizeof(szPathReal))))
1102 {
1103 errorArgument("Invalid host DVD drive name");
1104 rc = E_FAIL;
1105 break;
1106 }
1107 rc = hostDVDs->FindByName(Bstr(szPathReal), hostDVDDrive.asOutParam());
1108 if (!hostDVDDrive)
1109 {
1110 errorArgument("Invalid host DVD drive name");
1111 rc = E_FAIL;
1112 break;
1113 }
1114 }
1115 CHECK_ERROR(dvdDrive, CaptureHostDrive(hostDVDDrive));
1116 }
1117 else
1118 {
1119 /* first assume it's a UUID */
1120 Guid uuid(dvd);
1121 ComPtr<IDVDImage> dvdImage;
1122 rc = a->virtualBox->GetDVDImage(uuid, dvdImage.asOutParam());
1123 if (FAILED(rc) || !dvdImage)
1124 {
1125 /* must be a filename, check if it's in the collection */
1126 rc = a->virtualBox->FindDVDImage(Bstr(dvd), dvdImage.asOutParam());
1127 /* not registered, do that on the fly */
1128 if (!dvdImage)
1129 {
1130 Guid emptyUUID;
1131 CHECK_ERROR(a->virtualBox, OpenDVDImage(Bstr(dvd), emptyUUID, dvdImage.asOutParam()));
1132 }
1133 }
1134 if (!dvdImage)
1135 {
1136 rc = E_FAIL;
1137 break;
1138 }
1139
1140 dvdImage->COMGETTER(Id)(uuid.asOutParam());
1141 CHECK_ERROR(dvdDrive, MountImage(uuid));
1142 }
1143 }
1144 if (dvdpassthrough)
1145 {
1146 ComPtr<IDVDDrive> dvdDrive;
1147 machine->COMGETTER(DVDDrive)(dvdDrive.asOutParam());
1148 ASSERT(dvdDrive);
1149
1150 CHECK_ERROR(dvdDrive, COMSETTER(Passthrough)(strcmp(dvdpassthrough, "on") == 0));
1151 }
1152 if (idecontroller)
1153 {
1154 if (RTStrICmp(idecontroller, "PIIX3") == 0)
1155 {
1156 CHECK_ERROR(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX3));
1157 }
1158 else if (RTStrICmp(idecontroller, "PIIX4") == 0)
1159 {
1160 CHECK_ERROR(biosSettings, COMSETTER(IDEControllerType)(IDEControllerType_PIIX4));
1161 }
1162 else
1163 {
1164 errorArgument("Invalid -idecontroller argument '%s'", idecontroller);
1165 rc = E_FAIL;
1166 break;
1167 }
1168 }
1169 if (floppy)
1170 {
1171 ComPtr<IFloppyDrive> floppyDrive;
1172 machine->COMGETTER(FloppyDrive)(floppyDrive.asOutParam());
1173 ASSERT(floppyDrive);
1174
1175 /* disable? */
1176 if (strcmp(floppy, "disabled") == 0)
1177 {
1178 /* disable the controller */
1179 CHECK_ERROR(floppyDrive, COMSETTER(Enabled)(false));
1180 }
1181 else
1182 {
1183 /* enable the controller */
1184 CHECK_ERROR(floppyDrive, COMSETTER(Enabled)(true));
1185
1186 /* unmount? */
1187 if (strcmp(floppy, "empty") == 0)
1188 {
1189 CHECK_ERROR(floppyDrive, Unmount());
1190 }
1191 /* host drive? */
1192 else if (strncmp(floppy, "host:", 5) == 0)
1193 {
1194 ComPtr<IHost> host;
1195 CHECK_ERROR(a->virtualBox, COMGETTER(Host)(host.asOutParam()));
1196 ComPtr<IHostFloppyDriveCollection> hostFloppies;
1197 CHECK_ERROR(host, COMGETTER(FloppyDrives)(hostFloppies.asOutParam()));
1198 ComPtr<IHostFloppyDrive> hostFloppyDrive;
1199 rc = hostFloppies->FindByName(Bstr(floppy + 5), hostFloppyDrive.asOutParam());
1200 if (!hostFloppyDrive)
1201 {
1202 errorArgument("Invalid host floppy drive name");
1203 rc = E_FAIL;
1204 break;
1205 }
1206 CHECK_ERROR(floppyDrive, CaptureHostDrive(hostFloppyDrive));
1207 }
1208 else
1209 {
1210 /* first assume it's a UUID */
1211 Guid uuid(floppy);
1212 ComPtr<IFloppyImage> floppyImage;
1213 rc = a->virtualBox->GetFloppyImage(uuid, floppyImage.asOutParam());
1214 if (FAILED(rc) || !floppyImage)
1215 {
1216 /* must be a filename, check if it's in the collection */
1217 rc = a->virtualBox->FindFloppyImage(Bstr(floppy), floppyImage.asOutParam());
1218 /* not registered, do that on the fly */
1219 if (!floppyImage)
1220 {
1221 Guid emptyUUID;
1222 CHECK_ERROR(a->virtualBox, OpenFloppyImage(Bstr(floppy), emptyUUID, floppyImage.asOutParam()));
1223 }
1224 }
1225 if (!floppyImage)
1226 {
1227 rc = E_FAIL;
1228 break;
1229 }
1230
1231 floppyImage->COMGETTER(Id)(uuid.asOutParam());
1232 CHECK_ERROR(floppyDrive, MountImage(uuid));
1233 }
1234 }
1235 }
1236 if (audio || audiocontroller)
1237 {
1238 ComPtr<IAudioAdapter> audioAdapter;
1239 machine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam());
1240 ASSERT(audioAdapter);
1241
1242 if (audio)
1243 {
1244 /* disable? */
1245 if (strcmp(audio, "none") == 0)
1246 {
1247 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(false));
1248 }
1249 else if (strcmp(audio, "null") == 0)
1250 {
1251 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Null));
1252 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1253 }
1254#ifdef RT_OS_WINDOWS
1255#ifdef VBOX_WITH_WINMM
1256 else if (strcmp(audio, "winmm") == 0)
1257 {
1258 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_WinMM));
1259 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1260 }
1261#endif
1262 else if (strcmp(audio, "dsound") == 0)
1263 {
1264 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_DirectSound));
1265 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1266 }
1267#endif /* RT_OS_WINDOWS */
1268#ifdef RT_OS_LINUX
1269 else if (strcmp(audio, "oss") == 0)
1270 {
1271 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_OSS));
1272 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1273 }
1274# ifdef VBOX_WITH_ALSA
1275 else if (strcmp(audio, "alsa") == 0)
1276 {
1277 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_ALSA));
1278 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1279 }
1280# endif
1281# ifdef VBOX_WITH_PULSE
1282 else if (strcmp(audio, "pulse") == 0)
1283 {
1284 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_Pulse));
1285 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1286 }
1287# endif
1288#endif /* !RT_OS_LINUX */
1289#ifdef RT_OS_SOLARIS
1290 else if (strcmp(audio, "solaudio") == 0)
1291 {
1292 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_SolAudio));
1293 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1294 }
1295
1296#endif /* !RT_OS_SOLARIS */
1297#ifdef RT_OS_DARWIN
1298 else if (strcmp(audio, "coreaudio") == 0)
1299 {
1300 CHECK_ERROR(audioAdapter, COMSETTER(AudioDriver)(AudioDriverType_CoreAudio));
1301 CHECK_ERROR(audioAdapter, COMSETTER(Enabled)(true));
1302 }
1303
1304#endif /* !RT_OS_DARWIN */
1305 else
1306 {
1307 errorArgument("Invalid -audio argument '%s'", audio);
1308 rc = E_FAIL;
1309 break;
1310 }
1311 }
1312 if (audiocontroller)
1313 {
1314 if (strcmp(audiocontroller, "sb16") == 0)
1315 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_SB16));
1316 else if (strcmp(audiocontroller, "ac97") == 0)
1317 CHECK_ERROR(audioAdapter, COMSETTER(AudioController)(AudioControllerType_AC97));
1318 else
1319 {
1320 errorArgument("Invalid -audiocontroller argument '%s'", audiocontroller);
1321 rc = E_FAIL;
1322 break;
1323 }
1324 }
1325 }
1326 /* Shared clipboard state */
1327 if (clipboard)
1328 {
1329/* ComPtr<IClipboardMode> clipboardMode;
1330 machine->COMGETTER(ClipboardMode)(clipboardMode.asOutParam());
1331 ASSERT(clipboardMode);
1332*/
1333 if (strcmp(clipboard, "disabled") == 0)
1334 {
1335 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Disabled));
1336 }
1337 else if (strcmp(clipboard, "hosttoguest") == 0)
1338 {
1339 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_HostToGuest));
1340 }
1341 else if (strcmp(clipboard, "guesttohost") == 0)
1342 {
1343 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_GuestToHost));
1344 }
1345 else if (strcmp(clipboard, "bidirectional") == 0)
1346 {
1347 CHECK_ERROR(machine, COMSETTER(ClipboardMode)(ClipboardMode_Bidirectional));
1348 }
1349 else
1350 {
1351 errorArgument("Invalid -clipboard argument '%s'", clipboard);
1352 rc = E_FAIL;
1353 break;
1354 }
1355 }
1356 /* iterate through all possible NICs */
1357 for (ULONG n = 0; n < NetworkAdapterCount; n ++)
1358 {
1359 ComPtr<INetworkAdapter> nic;
1360 CHECK_ERROR_RET (machine, GetNetworkAdapter (n, nic.asOutParam()), 1);
1361
1362 ASSERT(nic);
1363
1364 /* something about the NIC? */
1365 if (nics[n])
1366 {
1367 if (strcmp(nics[n], "none") == 0)
1368 {
1369 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (FALSE), 1);
1370 }
1371 else if (strcmp(nics[n], "null") == 0)
1372 {
1373 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1374 CHECK_ERROR_RET(nic, Detach(), 1);
1375 }
1376 else if (strcmp(nics[n], "nat") == 0)
1377 {
1378 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1379 CHECK_ERROR_RET(nic, AttachToNAT(), 1);
1380 }
1381 else if (strcmp(nics[n], "hostif") == 0)
1382 {
1383 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1384 CHECK_ERROR_RET(nic, AttachToHostInterface(), 1);
1385 }
1386 else if (strcmp(nics[n], "intnet") == 0)
1387 {
1388 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1389 CHECK_ERROR_RET(nic, AttachToInternalNetwork(), 1);
1390 }
1391#ifdef RT_OS_LINUX
1392 else if (strcmp(nics[n], "hostonly") == 0)
1393 {
1394 CHECK_ERROR_RET(nic, COMSETTER(Enabled) (TRUE), 1);
1395 CHECK_ERROR_RET(nic, AttachToHostOnlyNetwork(), 1);
1396 }
1397#endif /* RT_OS_LINUX */
1398 else
1399 {
1400 errorArgument("Invalid type '%s' specfied for NIC %lu", nics[n], n + 1);
1401 rc = E_FAIL;
1402 break;
1403 }
1404 }
1405
1406 /* something about the NIC type? */
1407 if (nictype[n])
1408 {
1409 if (strcmp(nictype[n], "Am79C970A") == 0)
1410 {
1411 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C970A), 1);
1412 }
1413 else if (strcmp(nictype[n], "Am79C973") == 0)
1414 {
1415 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_Am79C973), 1);
1416 }
1417#ifdef VBOX_WITH_E1000
1418 else if (strcmp(nictype[n], "82540EM") == 0)
1419 {
1420 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82540EM), 1);
1421 }
1422 else if (strcmp(nictype[n], "82543GC") == 0)
1423 {
1424 CHECK_ERROR_RET(nic, COMSETTER(AdapterType)(NetworkAdapterType_I82543GC), 1);
1425 }
1426#endif
1427 else
1428 {
1429 errorArgument("Invalid NIC type '%s' specified for NIC %lu", nictype[n], n + 1);
1430 rc = E_FAIL;
1431 break;
1432 }
1433 }
1434
1435 /* something about the MAC address? */
1436 if (macs[n])
1437 {
1438 /* generate one? */
1439 if (strcmp(macs[n], "auto") == 0)
1440 {
1441 CHECK_ERROR_RET(nic, COMSETTER(MACAddress)(NULL), 1);
1442 }
1443 else
1444 {
1445 CHECK_ERROR_RET(nic, COMSETTER(MACAddress)(Bstr(macs[n])), 1);
1446 }
1447 }
1448
1449 /* something about the reported link speed? */
1450 if (nicspeed[n])
1451 {
1452 uint32_t u32LineSpeed;
1453
1454 u32LineSpeed = RTStrToUInt32(nicspeed[n]);
1455
1456 if (u32LineSpeed < 1000 || u32LineSpeed > 4000000)
1457 {
1458 errorArgument("Invalid -nicspeed%lu argument '%s'", n + 1, nicspeed[n]);
1459 rc = E_FAIL;
1460 break;
1461 }
1462 CHECK_ERROR_RET(nic, COMSETTER(LineSpeed)(u32LineSpeed), 1);
1463 }
1464
1465 /* the link status flag? */
1466 if (cableconnected[n])
1467 {
1468 if (strcmp(cableconnected[n], "on") == 0)
1469 {
1470 CHECK_ERROR_RET(nic, COMSETTER(CableConnected)(TRUE), 1);
1471 }
1472 else if (strcmp(cableconnected[n], "off") == 0)
1473 {
1474 CHECK_ERROR_RET(nic, COMSETTER(CableConnected)(FALSE), 1);
1475 }
1476 else
1477 {
1478 errorArgument("Invalid -cableconnected%lu argument '%s'", n + 1, cableconnected[n]);
1479 rc = E_FAIL;
1480 break;
1481 }
1482 }
1483
1484 /* the trace flag? */
1485 if (nictrace[n])
1486 {
1487 if (strcmp(nictrace[n], "on") == 0)
1488 {
1489 CHECK_ERROR_RET(nic, COMSETTER(TraceEnabled)(TRUE), 1);
1490 }
1491 else if (strcmp(nictrace[n], "off") == 0)
1492 {
1493 CHECK_ERROR_RET(nic, COMSETTER(TraceEnabled)(FALSE), 1);
1494 }
1495 else
1496 {
1497 errorArgument("Invalid -nictrace%lu argument '%s'", n + 1, nictrace[n]);
1498 rc = E_FAIL;
1499 break;
1500 }
1501 }
1502
1503 /* the tracefile flag? */
1504 if (nictracefile[n])
1505 {
1506 CHECK_ERROR_RET(nic, COMSETTER(TraceFile)(Bstr(nictracefile[n])), 1);
1507 }
1508
1509 /* the host interface device? */
1510 if (hostifdev[n])
1511 {
1512 /* remove it? */
1513 if (strcmp(hostifdev[n], "none") == 0)
1514 {
1515 CHECK_ERROR_RET(nic, COMSETTER(HostInterface)(NULL), 1);
1516 }
1517 else
1518 {
1519 CHECK_ERROR_RET(nic, COMSETTER(HostInterface)(Bstr(hostifdev[n])), 1);
1520 }
1521 }
1522
1523 /* the internal network name? */
1524 if (intnet[n])
1525 {
1526 /* remove it? */
1527 if (strcmp(intnet[n], "none") == 0)
1528 {
1529 CHECK_ERROR_RET(nic, COMSETTER(InternalNetwork)(NULL), 1);
1530 }
1531 else
1532 {
1533 CHECK_ERROR_RET(nic, COMSETTER(InternalNetwork)(Bstr(intnet[n])), 1);
1534 }
1535 }
1536 /* the network of the NAT */
1537 if (natnet[n])
1538 {
1539 CHECK_ERROR_RET(nic, COMSETTER(NATNetwork)(Bstr(natnet[n])), 1);
1540 }
1541 }
1542 if (FAILED(rc))
1543 break;
1544
1545 /* iterate through all possible serial ports */
1546 for (ULONG n = 0; n < SerialPortCount; n ++)
1547 {
1548 ComPtr<ISerialPort> uart;
1549 CHECK_ERROR_RET (machine, GetSerialPort (n, uart.asOutParam()), 1);
1550
1551 ASSERT(uart);
1552
1553 if (uarts_base[n])
1554 {
1555 if (uarts_base[n] == (ULONG)-1)
1556 {
1557 CHECK_ERROR_RET(uart, COMSETTER(Enabled) (FALSE), 1);
1558 }
1559 else
1560 {
1561 CHECK_ERROR_RET(uart, COMSETTER(IOBase) (uarts_base[n]), 1);
1562 CHECK_ERROR_RET(uart, COMSETTER(IRQ) (uarts_irq[n]), 1);
1563 CHECK_ERROR_RET(uart, COMSETTER(Enabled) (TRUE), 1);
1564 }
1565 }
1566 if (uarts_mode[n])
1567 {
1568 if (strcmp(uarts_mode[n], "disconnected") == 0)
1569 {
1570 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_Disconnected), 1);
1571 }
1572 else
1573 {
1574 CHECK_ERROR_RET(uart, COMSETTER(Path) (Bstr(uarts_path[n])), 1);
1575 if (strcmp(uarts_mode[n], "server") == 0)
1576 {
1577 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostPipe), 1);
1578 CHECK_ERROR_RET(uart, COMSETTER(Server) (TRUE), 1);
1579 }
1580 else if (strcmp(uarts_mode[n], "client") == 0)
1581 {
1582 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostPipe), 1);
1583 CHECK_ERROR_RET(uart, COMSETTER(Server) (FALSE), 1);
1584 }
1585 else
1586 {
1587 CHECK_ERROR_RET(uart, COMSETTER(HostMode) (PortMode_HostDevice), 1);
1588 }
1589 }
1590 }
1591 }
1592 if (FAILED(rc))
1593 break;
1594
1595#ifdef VBOX_WITH_VRDP
1596 if (vrdp || (vrdpport != UINT16_MAX) || vrdpaddress || vrdpauthtype || vrdpmulticon || vrdpreusecon)
1597 {
1598 ComPtr<IVRDPServer> vrdpServer;
1599 machine->COMGETTER(VRDPServer)(vrdpServer.asOutParam());
1600 ASSERT(vrdpServer);
1601 if (vrdpServer)
1602 {
1603 if (vrdp)
1604 {
1605 if (strcmp(vrdp, "on") == 0)
1606 {
1607 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(true));
1608 }
1609 else if (strcmp(vrdp, "off") == 0)
1610 {
1611 CHECK_ERROR(vrdpServer, COMSETTER(Enabled)(false));
1612 }
1613 else
1614 {
1615 errorArgument("Invalid -vrdp argument '%s'", vrdp);
1616 rc = E_FAIL;
1617 break;
1618 }
1619 }
1620 if (vrdpport != UINT16_MAX)
1621 {
1622 CHECK_ERROR(vrdpServer, COMSETTER(Port)(vrdpport));
1623 }
1624 if (vrdpaddress)
1625 {
1626 CHECK_ERROR(vrdpServer, COMSETTER(NetAddress)(Bstr(vrdpaddress)));
1627 }
1628 if (vrdpauthtype)
1629 {
1630 if (strcmp(vrdpauthtype, "null") == 0)
1631 {
1632 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Null));
1633 }
1634 else if (strcmp(vrdpauthtype, "external") == 0)
1635 {
1636 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_External));
1637 }
1638 else if (strcmp(vrdpauthtype, "guest") == 0)
1639 {
1640 CHECK_ERROR(vrdpServer, COMSETTER(AuthType)(VRDPAuthType_Guest));
1641 }
1642 else
1643 {
1644 errorArgument("Invalid -vrdpauthtype argument '%s'", vrdpauthtype);
1645 rc = E_FAIL;
1646 break;
1647 }
1648 }
1649 if (vrdpmulticon)
1650 {
1651 if (strcmp(vrdpmulticon, "on") == 0)
1652 {
1653 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(true));
1654 }
1655 else if (strcmp(vrdpmulticon, "off") == 0)
1656 {
1657 CHECK_ERROR(vrdpServer, COMSETTER(AllowMultiConnection)(false));
1658 }
1659 else
1660 {
1661 errorArgument("Invalid -vrdpmulticon argument '%s'", vrdpmulticon);
1662 rc = E_FAIL;
1663 break;
1664 }
1665 }
1666 if (vrdpreusecon)
1667 {
1668 if (strcmp(vrdpreusecon, "on") == 0)
1669 {
1670 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(true));
1671 }
1672 else if (strcmp(vrdpreusecon, "off") == 0)
1673 {
1674 CHECK_ERROR(vrdpServer, COMSETTER(ReuseSingleConnection)(false));
1675 }
1676 else
1677 {
1678 errorArgument("Invalid -vrdpreusecon argument '%s'", vrdpreusecon);
1679 rc = E_FAIL;
1680 break;
1681 }
1682 }
1683 }
1684 }
1685#endif /* VBOX_WITH_VRDP */
1686
1687 /*
1688 * USB enable/disable
1689 */
1690 if (fUsbEnabled != -1)
1691 {
1692 ComPtr<IUSBController> UsbCtl;
1693 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1694 if (SUCCEEDED(rc))
1695 {
1696 CHECK_ERROR(UsbCtl, COMSETTER(Enabled)(!!fUsbEnabled));
1697 }
1698 }
1699 /*
1700 * USB EHCI enable/disable
1701 */
1702 if (fUsbEhciEnabled != -1)
1703 {
1704 ComPtr<IUSBController> UsbCtl;
1705 CHECK_ERROR(machine, COMGETTER(USBController)(UsbCtl.asOutParam()));
1706 if (SUCCEEDED(rc))
1707 {
1708 CHECK_ERROR(UsbCtl, COMSETTER(EnabledEhci)(!!fUsbEhciEnabled));
1709 }
1710 }
1711
1712 if (snapshotFolder)
1713 {
1714 if (strcmp(snapshotFolder, "default") == 0)
1715 {
1716 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(NULL));
1717 }
1718 else
1719 {
1720 CHECK_ERROR(machine, COMSETTER(SnapshotFolder)(Bstr(snapshotFolder)));
1721 }
1722 }
1723
1724 if (guestMemBalloonSize != (ULONG)-1)
1725 CHECK_ERROR(machine, COMSETTER(MemoryBalloonSize)(guestMemBalloonSize));
1726
1727 if (guestStatInterval != (ULONG)-1)
1728 CHECK_ERROR(machine, COMSETTER(StatisticsUpdateInterval)(guestStatInterval));
1729
1730 /*
1731 * SATA controller enable/disable
1732 */
1733 if (fSataEnabled != -1)
1734 {
1735 ComPtr<ISATAController> SataCtl;
1736 CHECK_ERROR(machine, COMGETTER(SATAController)(SataCtl.asOutParam()));
1737 if (SUCCEEDED(rc))
1738 {
1739 CHECK_ERROR(SataCtl, COMSETTER(Enabled)(!!fSataEnabled));
1740 }
1741 }
1742
1743 for (uint32_t i = 4; i < 34; i++)
1744 {
1745 if (hdds[i])
1746 {
1747 if (strcmp(hdds[i], "none") == 0)
1748 {
1749 machine->DetachHardDisk(StorageBus_SATA, i-4, 0);
1750 }
1751 else
1752 {
1753 /* first guess is that it's a UUID */
1754 Guid uuid(hdds[i]);
1755 ComPtr<IHardDisk> hardDisk;
1756 rc = a->virtualBox->GetHardDisk(uuid, hardDisk.asOutParam());
1757 /* not successful? Then it must be a filename */
1758 if (!hardDisk)
1759 {
1760 CHECK_ERROR(a->virtualBox, FindHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
1761 if (FAILED(rc))
1762 {
1763 /* open the new hard disk object */
1764 CHECK_ERROR(a->virtualBox, OpenHardDisk(Bstr(hdds[i]), hardDisk.asOutParam()));
1765 }
1766 }
1767 if (hardDisk)
1768 {
1769 hardDisk->COMGETTER(Id)(uuid.asOutParam());
1770 CHECK_ERROR(machine, AttachHardDisk(uuid, StorageBus_SATA, i-4, 0));
1771 }
1772 else
1773 rc = E_FAIL;
1774 if (FAILED(rc))
1775 break;
1776 }
1777 }
1778 }
1779
1780 for (uint32_t i = 0; i < 4; i++)
1781 {
1782 if (sataBootDevices[i] != -1)
1783 {
1784 ComPtr<ISATAController> SataCtl;
1785 CHECK_ERROR(machine, COMGETTER(SATAController)(SataCtl.asOutParam()));
1786 if (SUCCEEDED(rc))
1787 {
1788 CHECK_ERROR(SataCtl, SetIDEEmulationPort(i, sataBootDevices[i]));
1789 }
1790 }
1791 }
1792
1793 if (sataPortCount != -1)
1794 {
1795 ComPtr<ISATAController> SataCtl;
1796 CHECK_ERROR(machine, COMGETTER(SATAController)(SataCtl.asOutParam()));
1797 if (SUCCEEDED(rc))
1798 {
1799 CHECK_ERROR(SataCtl, COMSETTER(PortCount)(sataPortCount));
1800 }
1801 }
1802
1803 /* commit changes */
1804 CHECK_ERROR(machine, SaveSettings());
1805 }
1806 while (0);
1807
1808 /* it's important to always close sessions */
1809 a->session->Close();
1810
1811 return SUCCEEDED(rc) ? 0 : 1;
1812}
1813
1814#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