VirtualBox

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

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

Main: net if API fixes

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