VirtualBox

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

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

VBoxManage: Get and set CPUCount.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette