VirtualBox

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

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

Main: INetworkAdapter separate properties for hostonly & bridged interface names

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