VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp@ 23249

Last change on this file since 23249 was 23223, checked in by vboxsync, 15 years ago

API: big medium handling change and lots of assorted other cleanups and fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 60.7 KB
Line 
1/* $Id: VBoxInternalManage.cpp 23223 2009-09-22 15:50:03Z vboxsync $ */
2/** @file
3 * VBoxManage - The 'internalcommands' command.
4 *
5 * VBoxInternalManage used to be a second CLI for doing special tricks,
6 * not intended for general usage, only for assisting VBox developers.
7 * It is now integrated into VBoxManage.
8 */
9
10/*
11 * Copyright (C) 2006-2009 Sun Microsystems, Inc.
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License (GPL) as published by the Free Software
17 * Foundation, in version 2 as it comes in the "COPYING" file of the
18 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22 * Clara, CA 95054 USA or visit http://www.sun.com if you need
23 * additional information or have any questions.
24 */
25
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <VBox/com/com.h>
32#include <VBox/com/string.h>
33#include <VBox/com/Guid.h>
34#include <VBox/com/ErrorInfo.h>
35#include <VBox/com/errorprint.h>
36
37#include <VBox/com/VirtualBox.h>
38
39#include <VBox/VBoxHDD.h>
40#include <VBox/sup.h>
41#include <VBox/err.h>
42#include <VBox/log.h>
43
44#include <iprt/file.h>
45#include <iprt/initterm.h>
46#include <iprt/stream.h>
47#include <iprt/string.h>
48#include <iprt/uuid.h>
49
50
51#include "VBoxManage.h"
52
53/* Includes for the raw disk stuff. */
54#ifdef RT_OS_WINDOWS
55# include <windows.h>
56# include <winioctl.h>
57#elif defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_SOLARIS)
58# include <errno.h>
59# include <sys/ioctl.h>
60# include <sys/types.h>
61# include <sys/stat.h>
62# include <fcntl.h>
63# include <unistd.h>
64#endif
65#ifdef RT_OS_LINUX
66# include <sys/utsname.h>
67# include <linux/hdreg.h>
68# include <linux/fs.h>
69# include <stdlib.h> /* atoi() */
70#endif /* RT_OS_LINUX */
71#ifdef RT_OS_DARWIN
72# include <sys/disk.h>
73#endif /* RT_OS_DARWIN */
74#ifdef RT_OS_SOLARIS
75# include <stropts.h>
76# include <sys/dkio.h>
77# include <sys/vtoc.h>
78#endif /* RT_OS_SOLARIS */
79
80using namespace com;
81
82
83/** Macro for checking whether a partition is of extended type or not. */
84#define PARTTYPE_IS_EXTENDED(x) ((x) == 0x05 || (x) == 0x0f || (x) == 0x85)
85
86/* Maximum number of partitions we can deal with. Ridiculously large number,
87 * but the memory consumption is rather low so who cares about never using
88 * most entries. */
89#define HOSTPARTITION_MAX 100
90
91
92typedef struct HOSTPARTITION
93{
94 unsigned uIndex;
95 /** partition type */
96 unsigned uType;
97 /** CHS/cylinder of the first sector */
98 unsigned uStartCylinder;
99 /** CHS/head of the first sector */
100 unsigned uStartHead;
101 /** CHS/head of the first sector */
102 unsigned uStartSector;
103 /** CHS/cylinder of the last sector */
104 unsigned uEndCylinder;
105 /** CHS/head of the last sector */
106 unsigned uEndHead;
107 /** CHS/sector of the last sector */
108 unsigned uEndSector;
109 /** start sector of this partition relative to the beginning of the hard
110 * disk or relative to the beginning of the extended partition table */
111 uint64_t uStart;
112 /** numer of sectors of the partition */
113 uint64_t uSize;
114 /** start sector of this partition _table_ */
115 uint64_t uPartDataStart;
116 /** numer of sectors of this partition _table_ */
117 uint64_t cPartDataSectors;
118} HOSTPARTITION, *PHOSTPARTITION;
119
120typedef struct HOSTPARTITIONS
121{
122 unsigned cPartitions;
123 HOSTPARTITION aPartitions[HOSTPARTITION_MAX];
124} HOSTPARTITIONS, *PHOSTPARTITIONS;
125
126/** flag whether we're in internal mode */
127bool g_fInternalMode;
128
129/**
130 * Print the usage info.
131 */
132void printUsageInternal(USAGECATEGORY u64Cmd)
133{
134 RTPrintf("Usage: VBoxManage internalcommands <command> [command arguments]\n"
135 "\n"
136 "Commands:\n"
137 "\n"
138 "%s%s%s%s%s%s%s%s%s"
139 "WARNING: This is a development tool and shall only be used to analyse\n"
140 " problems. It is completely unsupported and will change in\n"
141 " incompatible ways without warning.\n",
142 (u64Cmd & USAGE_LOADSYMS) ?
143 " loadsyms <vmname>|<uuid> <symfile> [delta] [module] [module address]\n"
144 " This will instruct DBGF to load the given symbolfile\n"
145 " during initialization.\n"
146 "\n"
147 : "",
148 (u64Cmd & USAGE_UNLOADSYMS) ?
149 " unloadsyms <vmname>|<uuid> <symfile>\n"
150 " Removes <symfile> from the list of symbol files that\n"
151 " should be loaded during DBF initialization.\n"
152 "\n"
153 : "",
154 (u64Cmd & USAGE_SETHDUUID) ?
155 " sethduuid <filepath>\n"
156 " Assigns a new UUID to the given image file. This way, multiple copies\n"
157 " of a container can be registered.\n"
158 "\n"
159 : "",
160 (u64Cmd & USAGE_DUMPHDINFO) ?
161 " dumphdinfo <filepath>\n"
162 " Prints information about the image at the given location.\n"
163 "\n"
164 : "",
165 (u64Cmd & USAGE_LISTPARTITIONS) ?
166 " listpartitions -rawdisk <diskname>\n"
167 " Lists all partitions on <diskname>.\n"
168 "\n"
169 : "",
170 (u64Cmd & USAGE_CREATERAWVMDK) ?
171 " createrawvmdk -filename <filename> -rawdisk <diskname>\n"
172 " [-partitions <list of partition numbers> [-mbr <filename>] ]\n"
173 " [-register] [-relative]\n"
174 " Creates a new VMDK image which gives access to an entite host disk (if\n"
175 " the parameter -partitions is not specified) or some partitions of a\n"
176 " host disk. If access to individual partitions is granted, then the\n"
177 " parameter -mbr can be used to specify an alternative MBR to be used\n"
178 " (the partitioning information in the MBR file is ignored).\n"
179 " The diskname is on Linux e.g. /dev/sda, and on Windows e.g.\n"
180 " \\\\.\\PhysicalDrive0).\n"
181 " On Linux host the parameter -relative causes a VMDK file to be created\n"
182 " which refers to individual partitions instead to the entire disk.\n"
183 " Optionally the created image can be immediately registered.\n"
184 " The necessary partition numbers can be queried with\n"
185 " VBoxManage internalcommands listpartitions\n"
186 "\n"
187 : "",
188 (u64Cmd & USAGE_RENAMEVMDK) ?
189 " renamevmdk -from <filename> -to <filename>\n"
190 " Renames an existing VMDK image, including the base file and all its extents.\n"
191 "\n"
192 : "",
193 (u64Cmd & USAGE_CONVERTTORAW) ?
194 " converttoraw [-format <fileformat>] <filename> <outputfile>"
195#ifdef ENABLE_CONVERT_RAW_TO_STDOUT
196 "|stdout"
197#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
198 "\n"
199 " Convert image to raw, writing to file"
200#ifdef ENABLE_CONVERT_RAW_TO_STDOUT
201 " or stdout"
202#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
203 ".\n"
204 "\n"
205 : "",
206 (u64Cmd & USAGE_CONVERTHD) ?
207 " converthd [-srcformat VDI|VMDK|VHD|RAW]\n"
208 " [-dstformat VDI|VMDK|VHD|RAW]\n"
209 " <inputfile> <outputfile>\n"
210 " converts hard disk images between formats\n"
211 "\n"
212 : "",
213#ifdef RT_OS_WINDOWS
214 (u64Cmd & USAGE_MODINSTALL) ?
215 " modinstall\n"
216 " Installs the neccessary driver for the host OS\n"
217 "\n"
218 : "",
219 (u64Cmd & USAGE_MODUNINSTALL) ?
220 " moduninstall\n"
221 " Deinstalls the driver\n"
222 "\n"
223 : ""
224#else
225 "",
226 ""
227#endif
228 );
229}
230
231/** @todo this is no longer necessary, we can enumerate extra data */
232/**
233 * Finds a new unique key name.
234 *
235 * I don't think this is 100% race condition proof, but we assumes
236 * the user is not trying to push this point.
237 *
238 * @returns Result from the insert.
239 * @param pMachine The Machine object.
240 * @param pszKeyBase The base key.
241 * @param rKey Reference to the string object in which we will return the key.
242 */
243static HRESULT NewUniqueKey(ComPtr<IMachine> pMachine, const char *pszKeyBase, Utf8Str &rKey)
244{
245 Bstr Keys;
246 HRESULT hrc = pMachine->GetExtraData(Bstr(pszKeyBase), Keys.asOutParam());
247 if (FAILED(hrc))
248 return hrc;
249
250 /* if there are no keys, it's simple. */
251 if (Keys.isEmpty())
252 {
253 rKey = "1";
254 return pMachine->SetExtraData(Bstr(pszKeyBase), Bstr("1"));
255 }
256
257 /* find a unique number - brute force rulez. */
258 Utf8Str KeysUtf8(Keys);
259 const char *pszKeys = RTStrStripL(KeysUtf8.raw());
260 for (unsigned i = 1; i < 1000000; i++)
261 {
262 char szKey[32];
263 size_t cchKey = RTStrPrintf(szKey, sizeof(szKey), "%#x", i);
264 const char *psz = strstr(pszKeys, szKey);
265 while (psz)
266 {
267 if ( ( psz == pszKeys
268 || psz[-1] == ' ')
269 && ( psz[cchKey] == ' '
270 || !psz[cchKey])
271 )
272 break;
273 psz = strstr(psz + cchKey, szKey);
274 }
275 if (!psz)
276 {
277 rKey = szKey;
278 Utf8StrFmt NewKeysUtf8("%s %s", pszKeys, szKey);
279 return pMachine->SetExtraData(Bstr(pszKeyBase), Bstr(NewKeysUtf8));
280 }
281 }
282 RTPrintf("Error: Cannot find unique key for '%s'!\n", pszKeyBase);
283 return E_FAIL;
284}
285
286
287#if 0
288/**
289 * Remove a key.
290 *
291 * I don't think this isn't 100% race condition proof, but we assumes
292 * the user is not trying to push this point.
293 *
294 * @returns Result from the insert.
295 * @param pMachine The machine object.
296 * @param pszKeyBase The base key.
297 * @param pszKey The key to remove.
298 */
299static HRESULT RemoveKey(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey)
300{
301 Bstr Keys;
302 HRESULT hrc = pMachine->GetExtraData(Bstr(pszKeyBase), Keys.asOutParam());
303 if (FAILED(hrc))
304 return hrc;
305
306 /* if there are no keys, it's simple. */
307 if (Keys.isEmpty())
308 return S_OK;
309
310 char *pszKeys;
311 int rc = RTUtf16ToUtf8(Keys.raw(), &pszKeys);
312 if (RT_SUCCESS(rc))
313 {
314 /* locate it */
315 size_t cchKey = strlen(pszKey);
316 char *psz = strstr(pszKeys, pszKey);
317 while (psz)
318 {
319 if ( ( psz == pszKeys
320 || psz[-1] == ' ')
321 && ( psz[cchKey] == ' '
322 || !psz[cchKey])
323 )
324 break;
325 psz = strstr(psz + cchKey, pszKey);
326 }
327 if (psz)
328 {
329 /* remove it */
330 char *pszNext = RTStrStripL(psz + cchKey);
331 if (*pszNext)
332 memmove(psz, pszNext, strlen(pszNext) + 1);
333 else
334 *psz = '\0';
335 psz = RTStrStrip(pszKeys);
336
337 /* update */
338 hrc = pMachine->SetExtraData(Bstr(pszKeyBase), Bstr(psz));
339 }
340
341 RTStrFree(pszKeys);
342 return hrc;
343 }
344 else
345 RTPrintf("error: failed to delete key '%s' from '%s', string conversion error %Rrc!\n",
346 pszKey, pszKeyBase, rc);
347
348 return E_FAIL;
349}
350#endif
351
352
353/**
354 * Sets a key value, does necessary error bitching.
355 *
356 * @returns COM status code.
357 * @param pMachine The Machine object.
358 * @param pszKeyBase The key base.
359 * @param pszKey The key.
360 * @param pszAttribute The attribute name.
361 * @param pszValue The string value.
362 */
363static HRESULT SetString(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, const char *pszValue)
364{
365 HRESULT hrc = pMachine->SetExtraData(Bstr(Utf8StrFmt("%s/%s/%s", pszKeyBase, pszKey, pszAttribute)), Bstr(pszValue));
366 if (FAILED(hrc))
367 RTPrintf("error: Failed to set '%s/%s/%s' to '%s'! hrc=%#x\n",
368 pszKeyBase, pszKey, pszAttribute, pszValue, hrc);
369 return hrc;
370}
371
372
373/**
374 * Sets a key value, does necessary error bitching.
375 *
376 * @returns COM status code.
377 * @param pMachine The Machine object.
378 * @param pszKeyBase The key base.
379 * @param pszKey The key.
380 * @param pszAttribute The attribute name.
381 * @param u64Value The value.
382 */
383static HRESULT SetUInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, uint64_t u64Value)
384{
385 char szValue[64];
386 RTStrPrintf(szValue, sizeof(szValue), "%#RX64", u64Value);
387 return SetString(pMachine, pszKeyBase, pszKey, pszAttribute, szValue);
388}
389
390
391/**
392 * Sets a key value, does necessary error bitching.
393 *
394 * @returns COM status code.
395 * @param pMachine The Machine object.
396 * @param pszKeyBase The key base.
397 * @param pszKey The key.
398 * @param pszAttribute The attribute name.
399 * @param i64Value The value.
400 */
401static HRESULT SetInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, int64_t i64Value)
402{
403 char szValue[64];
404 RTStrPrintf(szValue, sizeof(szValue), "%RI64", i64Value);
405 return SetString(pMachine, pszKeyBase, pszKey, pszAttribute, szValue);
406}
407
408
409/**
410 * Identical to the 'loadsyms' command.
411 */
412static int CmdLoadSyms(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
413{
414 HRESULT rc;
415
416 /*
417 * Get the VM
418 */
419 ComPtr<IMachine> machine;
420 /* assume it's a UUID */
421 rc = aVirtualBox->GetMachine(Bstr(argv[0]), machine.asOutParam());
422 if (FAILED(rc) || !machine)
423 {
424 /* must be a name */
425 CHECK_ERROR_RET(aVirtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()), 1);
426 }
427
428 /*
429 * Parse the command.
430 */
431 const char *pszFilename;
432 int64_t offDelta = 0;
433 const char *pszModule = NULL;
434 uint64_t ModuleAddress = ~0;
435 uint64_t ModuleSize = 0;
436
437 /* filename */
438 if (argc < 2)
439 return errorArgument("Missing the filename argument!\n");
440 pszFilename = argv[1];
441
442 /* offDelta */
443 if (argc >= 3)
444 {
445 int rc = RTStrToInt64Ex(argv[2], NULL, 0, &offDelta);
446 if (RT_FAILURE(rc))
447 return errorArgument(argv[0], "Failed to read delta '%s', rc=%Rrc\n", argv[2], rc);
448 }
449
450 /* pszModule */
451 if (argc >= 4)
452 pszModule = argv[3];
453
454 /* ModuleAddress */
455 if (argc >= 5)
456 {
457 int rc = RTStrToUInt64Ex(argv[4], NULL, 0, &ModuleAddress);
458 if (RT_FAILURE(rc))
459 return errorArgument(argv[0], "Failed to read module address '%s', rc=%Rrc\n", argv[4], rc);
460 }
461
462 /* ModuleSize */
463 if (argc >= 6)
464 {
465 int rc = RTStrToUInt64Ex(argv[5], NULL, 0, &ModuleSize);
466 if (RT_FAILURE(rc))
467 return errorArgument(argv[0], "Failed to read module size '%s', rc=%Rrc\n", argv[5], rc);
468 }
469
470 /*
471 * Add extra data.
472 */
473 Utf8Str KeyStr;
474 HRESULT hrc = NewUniqueKey(machine, "VBoxInternal/DBGF/loadsyms", KeyStr);
475 if (SUCCEEDED(hrc))
476 hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Filename", pszFilename);
477 if (SUCCEEDED(hrc) && argc >= 3)
478 hrc = SetInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Delta", offDelta);
479 if (SUCCEEDED(hrc) && argc >= 4)
480 hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Module", pszModule);
481 if (SUCCEEDED(hrc) && argc >= 5)
482 hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleAddress", ModuleAddress);
483 if (SUCCEEDED(hrc) && argc >= 6)
484 hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleSize", ModuleSize);
485
486 return FAILED(hrc);
487}
488
489
490static DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
491{
492 RTPrintf("ERROR: ");
493 RTPrintfV(pszFormat, va);
494 RTPrintf("\n");
495 RTPrintf("Error code %Rrc at %s(%u) in function %s\n", rc, RT_SRC_POS_ARGS);
496}
497
498static int CmdSetHDUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
499{
500 /* we need exactly one parameter: the image file */
501 if (argc != 1)
502 {
503 return errorSyntax(USAGE_SETHDUUID, "Not enough parameters");
504 }
505
506 /* generate a new UUID */
507 Guid uuid;
508 uuid.create();
509
510 /* just try it */
511 char *pszFormat = NULL;
512 int rc = VDGetFormat(NULL, argv[0], &pszFormat);
513 if (RT_FAILURE(rc))
514 {
515 RTPrintf("Format autodetect failed: %Rrc\n", rc);
516 return 1;
517 }
518
519 PVBOXHDD pDisk = NULL;
520
521 PVDINTERFACE pVDIfs = NULL;
522 VDINTERFACE vdInterfaceError;
523 VDINTERFACEERROR vdInterfaceErrorCallbacks;
524 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
525 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
526 vdInterfaceErrorCallbacks.pfnError = handleVDError;
527 vdInterfaceErrorCallbacks.pfnMessage = NULL;
528
529 rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
530 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
531 AssertRC(rc);
532
533 rc = VDCreate(pVDIfs, &pDisk);
534 if (RT_FAILURE(rc))
535 {
536 RTPrintf("Error while creating the virtual disk container: %Rrc\n", rc);
537 return 1;
538 }
539
540 /* Open the image */
541 rc = VDOpen(pDisk, pszFormat, argv[0], VD_OPEN_FLAGS_NORMAL, NULL);
542 if (RT_FAILURE(rc))
543 {
544 RTPrintf("Error while opening the image: %Rrc\n", rc);
545 return 1;
546 }
547
548 rc = VDSetUuid(pDisk, VD_LAST_IMAGE, uuid.raw());
549 if (RT_FAILURE(rc))
550 RTPrintf("Error while setting a new UUID: %Rrc\n", rc);
551 else
552 RTPrintf("UUID changed to: %s\n", uuid.toString().raw());
553
554 VDCloseAll(pDisk);
555
556 return RT_FAILURE(rc);
557}
558
559
560static int handleVDMessage(void *pvUser, const char *pszFormat, ...)
561{
562 NOREF(pvUser);
563 va_list args;
564 va_start(args, pszFormat);
565 int rc = RTPrintfV(pszFormat, args);
566 va_end(args);
567 return rc;
568}
569
570static int CmdDumpHDInfo(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
571{
572 /* we need exactly one parameter: the image file */
573 if (argc != 1)
574 {
575 return errorSyntax(USAGE_SETHDUUID, "Not enough parameters");
576 }
577
578 /* just try it */
579 char *pszFormat = NULL;
580 int rc = VDGetFormat(NULL, argv[0], &pszFormat);
581 if (RT_FAILURE(rc))
582 {
583 RTPrintf("Format autodetect failed: %Rrc\n", rc);
584 return 1;
585 }
586
587 PVBOXHDD pDisk = NULL;
588
589 PVDINTERFACE pVDIfs = NULL;
590 VDINTERFACE vdInterfaceError;
591 VDINTERFACEERROR vdInterfaceErrorCallbacks;
592 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
593 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
594 vdInterfaceErrorCallbacks.pfnError = handleVDError;
595 vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage;
596
597 rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
598 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
599 AssertRC(rc);
600
601 rc = VDCreate(pVDIfs, &pDisk);
602 if (RT_FAILURE(rc))
603 {
604 RTPrintf("Error while creating the virtual disk container: %Rrc\n", rc);
605 return 1;
606 }
607
608 /* Open the image */
609 rc = VDOpen(pDisk, pszFormat, argv[0], VD_OPEN_FLAGS_NORMAL, NULL);
610 if (RT_FAILURE(rc))
611 {
612 RTPrintf("Error while opening the image: %Rrc\n", rc);
613 return 1;
614 }
615
616 VDDumpImages(pDisk);
617
618 VDCloseAll(pDisk);
619
620 return RT_FAILURE(rc);
621}
622
623static int partRead(RTFILE File, PHOSTPARTITIONS pPart)
624{
625 uint8_t aBuffer[512];
626 int rc;
627
628 pPart->cPartitions = 0;
629 memset(pPart->aPartitions, '\0', sizeof(pPart->aPartitions));
630 rc = RTFileReadAt(File, 0, &aBuffer, sizeof(aBuffer), NULL);
631 if (RT_FAILURE(rc))
632 return rc;
633 if (aBuffer[510] != 0x55 || aBuffer[511] != 0xaa)
634 return VERR_INVALID_PARAMETER;
635
636 unsigned uExtended = (unsigned)-1;
637
638 for (unsigned i = 0; i < 4; i++)
639 {
640 uint8_t *p = &aBuffer[0x1be + i * 16];
641 if (p[4] == 0)
642 continue;
643 PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
644 pCP->uIndex = i + 1;
645 pCP->uType = p[4];
646 pCP->uStartCylinder = (uint32_t)p[3] + ((uint32_t)(p[2] & 0xc0) << 2);
647 pCP->uStartHead = p[1];
648 pCP->uStartSector = p[2] & 0x3f;
649 pCP->uEndCylinder = (uint32_t)p[7] + ((uint32_t)(p[6] & 0xc0) << 2);
650 pCP->uEndHead = p[5];
651 pCP->uEndSector = p[6] & 0x3f;
652 pCP->uStart = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
653 pCP->uSize = RT_MAKE_U32_FROM_U8(p[12], p[13], p[14], p[15]);
654 pCP->uPartDataStart = 0; /* will be filled out later properly. */
655 pCP->cPartDataSectors = 0;
656
657 if (PARTTYPE_IS_EXTENDED(p[4]))
658 {
659 if (uExtended == (unsigned)-1)
660 uExtended = (unsigned)(pCP - pPart->aPartitions);
661 else
662 {
663 RTPrintf("More than one extended partition. Aborting\n");
664 return VERR_INVALID_PARAMETER;
665 }
666 }
667 }
668
669 if (uExtended != (unsigned)-1)
670 {
671 unsigned uIndex = 5;
672 uint64_t uStart = pPart->aPartitions[uExtended].uStart;
673 uint64_t uOffset = 0;
674 if (!uStart)
675 {
676 RTPrintf("Inconsistency for logical partition start. Aborting\n");
677 return VERR_INVALID_PARAMETER;
678 }
679
680 do
681 {
682 rc = RTFileReadAt(File, (uStart + uOffset) * 512, &aBuffer, sizeof(aBuffer), NULL);
683 if (RT_FAILURE(rc))
684 return rc;
685
686 if (aBuffer[510] != 0x55 || aBuffer[511] != 0xaa)
687 {
688 RTPrintf("Logical partition without magic. Aborting\n");
689 return VERR_INVALID_PARAMETER;
690 }
691 uint8_t *p = &aBuffer[0x1be];
692
693 if (p[4] == 0)
694 {
695 RTPrintf("Logical partition with type 0 encountered. Aborting\n");
696 return VERR_INVALID_PARAMETER;
697 }
698
699 PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
700 pCP->uIndex = uIndex;
701 pCP->uType = p[4];
702 pCP->uStartCylinder = (uint32_t)p[3] + ((uint32_t)(p[2] & 0xc0) << 2);
703 pCP->uStartHead = p[1];
704 pCP->uStartSector = p[2] & 0x3f;
705 pCP->uEndCylinder = (uint32_t)p[7] + ((uint32_t)(p[6] & 0xc0) << 2);
706 pCP->uEndHead = p[5];
707 pCP->uEndSector = p[6] & 0x3f;
708 uint32_t uStartOffset = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
709 if (!uStartOffset)
710 {
711 RTPrintf("Invalid partition start offset. Aborting\n");
712 return VERR_INVALID_PARAMETER;
713 }
714 pCP->uStart = uStart + uOffset + uStartOffset;
715 pCP->uSize = RT_MAKE_U32_FROM_U8(p[12], p[13], p[14], p[15]);
716 /* Fill out partitioning location info for EBR. */
717 pCP->uPartDataStart = uStart + uOffset;
718 pCP->cPartDataSectors = uStartOffset;
719 p += 16;
720 if (p[4] == 0)
721 uExtended = (unsigned)-1;
722 else if (PARTTYPE_IS_EXTENDED(p[4]))
723 {
724 uExtended = uIndex++;
725 uOffset = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
726 }
727 else
728 {
729 RTPrintf("Logical partition chain broken. Aborting\n");
730 return VERR_INVALID_PARAMETER;
731 }
732 } while (uExtended != (unsigned)-1);
733 }
734
735 /* Sort partitions in ascending order of start sector, plus a trivial
736 * bit of consistency checking. */
737 for (unsigned i = 0; i < pPart->cPartitions-1; i++)
738 {
739 unsigned uMinIdx = i;
740 uint64_t uMinVal = pPart->aPartitions[i].uStart;
741 for (unsigned j = i + 1; j < pPart->cPartitions; j++)
742 {
743 if (pPart->aPartitions[j].uStart < uMinVal)
744 {
745 uMinIdx = j;
746 uMinVal = pPart->aPartitions[j].uStart;
747 }
748 else if (pPart->aPartitions[j].uStart == uMinVal)
749 {
750 RTPrintf("Two partitions start at the same place. Aborting\n");
751 return VERR_INVALID_PARAMETER;
752 }
753 else if (pPart->aPartitions[j].uStart == 0)
754 {
755 RTPrintf("Partition starts at sector 0. Aborting\n");
756 return VERR_INVALID_PARAMETER;
757 }
758 }
759 if (uMinIdx != i)
760 {
761 /* Swap entries at index i and uMinIdx. */
762 memcpy(&pPart->aPartitions[pPart->cPartitions],
763 &pPart->aPartitions[i], sizeof(HOSTPARTITION));
764 memcpy(&pPart->aPartitions[i],
765 &pPart->aPartitions[uMinIdx], sizeof(HOSTPARTITION));
766 memcpy(&pPart->aPartitions[uMinIdx],
767 &pPart->aPartitions[pPart->cPartitions], sizeof(HOSTPARTITION));
768 }
769 }
770
771 /* Now do a lot of consistency checking. */
772 uint64_t uPrevEnd = 0;
773 for (unsigned i = 0; i < pPart->cPartitions-1; i++)
774 {
775 if (pPart->aPartitions[i].cPartDataSectors)
776 {
777 if (pPart->aPartitions[i].uPartDataStart < uPrevEnd)
778 {
779 RTPrintf("Overlapping partition description areas. Aborting\n");
780 return VERR_INVALID_PARAMETER;
781 }
782 uPrevEnd = pPart->aPartitions[i].uPartDataStart + pPart->aPartitions[i].cPartDataSectors;
783 }
784 if (pPart->aPartitions[i].uStart < uPrevEnd)
785 {
786 RTPrintf("Overlapping partitions. Aborting\n");
787 return VERR_INVALID_PARAMETER;
788 }
789 if (!PARTTYPE_IS_EXTENDED(pPart->aPartitions[i].uType))
790 uPrevEnd = pPart->aPartitions[i].uStart + pPart->aPartitions[i].uSize;
791 }
792
793 /* Fill out partitioning location info for MBR. */
794 pPart->aPartitions[0].uPartDataStart = 0;
795 pPart->aPartitions[0].cPartDataSectors = pPart->aPartitions[0].uStart;
796
797 return VINF_SUCCESS;
798}
799
800static int CmdListPartitions(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
801{
802 Utf8Str rawdisk;
803
804 /* let's have a closer look at the arguments */
805 for (int i = 0; i < argc; i++)
806 {
807 if (strcmp(argv[i], "-rawdisk") == 0)
808 {
809 if (argc <= i + 1)
810 {
811 return errorArgument("Missing argument to '%s'", argv[i]);
812 }
813 i++;
814 rawdisk = argv[i];
815 }
816 else
817 {
818 return errorSyntax(USAGE_LISTPARTITIONS, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
819 }
820 }
821
822 if (rawdisk.isEmpty())
823 return errorSyntax(USAGE_LISTPARTITIONS, "Mandatory parameter -rawdisk missing");
824
825 RTFILE RawFile;
826 int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
827 if (RT_FAILURE(vrc))
828 {
829 RTPrintf("Error opening the raw disk: %Rrc\n", vrc);
830 return vrc;
831 }
832
833 HOSTPARTITIONS partitions;
834 vrc = partRead(RawFile, &partitions);
835 if (RT_FAILURE(vrc))
836 return vrc;
837
838 RTPrintf("Number Type StartCHS EndCHS Size (MiB) Start (Sect)\n");
839 for (unsigned i = 0; i < partitions.cPartitions; i++)
840 {
841 /* Suppress printing the extended partition. Otherwise people
842 * might add it to the list of partitions for raw partition
843 * access (which is not good). */
844 if (PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
845 continue;
846
847 RTPrintf("%-7u %#04x %-4u/%-3u/%-2u %-4u/%-3u/%-2u %10llu %10llu\n",
848 partitions.aPartitions[i].uIndex,
849 partitions.aPartitions[i].uType,
850 partitions.aPartitions[i].uStartCylinder,
851 partitions.aPartitions[i].uStartHead,
852 partitions.aPartitions[i].uStartSector,
853 partitions.aPartitions[i].uEndCylinder,
854 partitions.aPartitions[i].uEndHead,
855 partitions.aPartitions[i].uEndSector,
856 partitions.aPartitions[i].uSize / 2048,
857 partitions.aPartitions[i].uStart);
858 }
859
860 return 0;
861}
862
863static int CmdCreateRawVMDK(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
864{
865 HRESULT rc = S_OK;
866 Bstr filename;
867 const char *pszMBRFilename = NULL;
868 Utf8Str rawdisk;
869 const char *pszPartitions = NULL;
870 bool fRegister = false;
871 bool fRelative = false;
872
873 uint64_t cbSize = 0;
874 PVBOXHDD pDisk = NULL;
875 VBOXHDDRAW RawDescriptor;
876 HOSTPARTITIONS partitions;
877 uint32_t uPartitions = 0;
878 PVDINTERFACE pVDIfs = NULL;
879
880 /* let's have a closer look at the arguments */
881 for (int i = 0; i < argc; i++)
882 {
883 if (strcmp(argv[i], "-filename") == 0)
884 {
885 if (argc <= i + 1)
886 {
887 return errorArgument("Missing argument to '%s'", argv[i]);
888 }
889 i++;
890 filename = argv[i];
891 }
892 else if (strcmp(argv[i], "-mbr") == 0)
893 {
894 if (argc <= i + 1)
895 {
896 return errorArgument("Missing argument to '%s'", argv[i]);
897 }
898 i++;
899 pszMBRFilename = argv[i];
900 }
901 else if (strcmp(argv[i], "-rawdisk") == 0)
902 {
903 if (argc <= i + 1)
904 {
905 return errorArgument("Missing argument to '%s'", argv[i]);
906 }
907 i++;
908 rawdisk = argv[i];
909 }
910 else if (strcmp(argv[i], "-partitions") == 0)
911 {
912 if (argc <= i + 1)
913 {
914 return errorArgument("Missing argument to '%s'", argv[i]);
915 }
916 i++;
917 pszPartitions = argv[i];
918 }
919 else if (strcmp(argv[i], "-register") == 0)
920 {
921 fRegister = true;
922 }
923#ifdef RT_OS_LINUX
924 else if (strcmp(argv[i], "-relative") == 0)
925 {
926 fRelative = true;
927 }
928#endif /* RT_OS_LINUX */
929 else
930 {
931 return errorSyntax(USAGE_CREATERAWVMDK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
932 }
933 }
934
935 if (filename.isEmpty())
936 return errorSyntax(USAGE_CREATERAWVMDK, "Mandatory parameter -filename missing");
937 if (rawdisk.isEmpty())
938 return errorSyntax(USAGE_CREATERAWVMDK, "Mandatory parameter -rawdisk missing");
939 if (!pszPartitions && pszMBRFilename)
940 return errorSyntax(USAGE_CREATERAWVMDK, "The parameter -mbr is only valid when the parameter -partitions is also present");
941
942#ifdef RT_OS_DARWIN
943 fRelative = true;
944#endif /* RT_OS_DARWIN */
945 RTFILE RawFile;
946 int vrc = RTFileOpen(&RawFile, rawdisk.raw(), RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
947 if (RT_FAILURE(vrc))
948 {
949 RTPrintf("Error opening the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
950 goto out;
951 }
952
953#ifdef RT_OS_WINDOWS
954 /* Windows NT has no IOCTL_DISK_GET_LENGTH_INFORMATION ioctl. This was
955 * added to Windows XP, so we have to use the available info from DriveGeo.
956 * Note that we cannot simply use IOCTL_DISK_GET_DRIVE_GEOMETRY as it
957 * yields a slightly different result than IOCTL_DISK_GET_LENGTH_INFO.
958 * We call IOCTL_DISK_GET_DRIVE_GEOMETRY first as we need to check the media
959 * type anyway, and if IOCTL_DISK_GET_LENGTH_INFORMATION is supported
960 * we will later override cbSize.
961 */
962 DISK_GEOMETRY DriveGeo;
963 DWORD cbDriveGeo;
964 if (DeviceIoControl((HANDLE)RawFile,
965 IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0,
966 &DriveGeo, sizeof(DriveGeo), &cbDriveGeo, NULL))
967 {
968 if ( DriveGeo.MediaType == FixedMedia
969 || DriveGeo.MediaType == RemovableMedia)
970 {
971 cbSize = DriveGeo.Cylinders.QuadPart
972 * DriveGeo.TracksPerCylinder
973 * DriveGeo.SectorsPerTrack
974 * DriveGeo.BytesPerSector;
975 }
976 else
977 {
978 RTPrintf("File '%s' is no fixed/removable medium device\n", rawdisk.raw());
979 vrc = VERR_INVALID_PARAMETER;
980 goto out;
981 }
982
983 GET_LENGTH_INFORMATION DiskLenInfo;
984 DWORD junk;
985 if (DeviceIoControl((HANDLE)RawFile,
986 IOCTL_DISK_GET_LENGTH_INFO, NULL, 0,
987 &DiskLenInfo, sizeof(DiskLenInfo), &junk, (LPOVERLAPPED)NULL))
988 {
989 /* IOCTL_DISK_GET_LENGTH_INFO is supported -- override cbSize. */
990 cbSize = DiskLenInfo.Length.QuadPart;
991 }
992 }
993 else
994 {
995 vrc = RTErrConvertFromWin32(GetLastError());
996 RTPrintf("Error getting the geometry of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
997 goto out;
998 }
999#elif defined(RT_OS_LINUX)
1000 struct stat DevStat;
1001 if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode))
1002 {
1003#ifdef BLKGETSIZE64
1004 /* BLKGETSIZE64 is broken up to 2.4.17 and in many 2.5.x. In 2.6.0
1005 * it works without problems. */
1006 struct utsname utsname;
1007 if ( uname(&utsname) == 0
1008 && ( (strncmp(utsname.release, "2.5.", 4) == 0 && atoi(&utsname.release[4]) >= 18)
1009 || (strncmp(utsname.release, "2.", 2) == 0 && atoi(&utsname.release[2]) >= 6)))
1010 {
1011 uint64_t cbBlk;
1012 if (!ioctl(RawFile, BLKGETSIZE64, &cbBlk))
1013 cbSize = cbBlk;
1014 }
1015#endif /* BLKGETSIZE64 */
1016 if (!cbSize)
1017 {
1018 long cBlocks;
1019 if (!ioctl(RawFile, BLKGETSIZE, &cBlocks))
1020 cbSize = (uint64_t)cBlocks << 9;
1021 else
1022 {
1023 vrc = RTErrConvertFromErrno(errno);
1024 RTPrintf("Error getting the size of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
1025 goto out;
1026 }
1027 }
1028 }
1029 else
1030 {
1031 RTPrintf("File '%s' is no block device\n", rawdisk.raw());
1032 vrc = VERR_INVALID_PARAMETER;
1033 goto out;
1034 }
1035#elif defined(RT_OS_DARWIN)
1036 struct stat DevStat;
1037 if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode))
1038 {
1039 uint64_t cBlocks;
1040 uint32_t cbBlock;
1041 if (!ioctl(RawFile, DKIOCGETBLOCKCOUNT, &cBlocks))
1042 {
1043 if (!ioctl(RawFile, DKIOCGETBLOCKSIZE, &cbBlock))
1044 cbSize = cBlocks * cbBlock;
1045 else
1046 {
1047 RTPrintf("Cannot get the block size for file '%s': %Rrc", rawdisk.raw(), vrc);
1048 vrc = RTErrConvertFromErrno(errno);
1049 goto out;
1050 }
1051 }
1052 else
1053 {
1054 vrc = RTErrConvertFromErrno(errno);
1055 RTPrintf("Cannot get the block count for file '%s': %Rrc", rawdisk.raw(), vrc);
1056 goto out;
1057 }
1058 }
1059 else
1060 {
1061 RTPrintf("File '%s' is no block device\n", rawdisk.raw());
1062 vrc = VERR_INVALID_PARAMETER;
1063 goto out;
1064 }
1065#elif defined(RT_OS_SOLARIS)
1066 struct stat DevStat;
1067 if (!fstat(RawFile, &DevStat) && ( S_ISBLK(DevStat.st_mode)
1068 || S_ISCHR(DevStat.st_mode)))
1069 {
1070 struct dk_minfo mediainfo;
1071 if (!ioctl(RawFile, DKIOCGMEDIAINFO, &mediainfo))
1072 cbSize = mediainfo.dki_capacity * mediainfo.dki_lbsize;
1073 else
1074 {
1075 vrc = RTErrConvertFromErrno(errno);
1076 RTPrintf("Error getting the size of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
1077 goto out;
1078 }
1079 }
1080 else
1081 {
1082 RTPrintf("File '%s' is no block or char device\n", rawdisk.raw());
1083 vrc = VERR_INVALID_PARAMETER;
1084 goto out;
1085 }
1086#else /* all unrecognized OSes */
1087 /* Hopefully this works on all other hosts. If it doesn't, it'll just fail
1088 * creating the VMDK, so no real harm done. */
1089 vrc = RTFileGetSize(RawFile, &cbSize);
1090 if (RT_FAILURE(vrc))
1091 {
1092 RTPrintf("Error getting the size of the raw disk '%s': %Rrc\n", rawdisk.raw(), vrc);
1093 goto out;
1094 }
1095#endif
1096
1097 /* Check whether cbSize is actually sensible. */
1098 if (!cbSize || cbSize % 512)
1099 {
1100 RTPrintf("Detected size of raw disk '%s' is %s, an invalid value\n", rawdisk.raw(), cbSize);
1101 vrc = VERR_INVALID_PARAMETER;
1102 goto out;
1103 }
1104
1105 RawDescriptor.szSignature[0] = 'R';
1106 RawDescriptor.szSignature[1] = 'A';
1107 RawDescriptor.szSignature[2] = 'W';
1108 RawDescriptor.szSignature[3] = '\0';
1109 if (!pszPartitions)
1110 {
1111 RawDescriptor.fRawDisk = true;
1112 RawDescriptor.pszRawDisk = rawdisk.raw();
1113 }
1114 else
1115 {
1116 RawDescriptor.fRawDisk = false;
1117 RawDescriptor.pszRawDisk = NULL;
1118 RawDescriptor.cPartitions = 0;
1119
1120 const char *p = pszPartitions;
1121 char *pszNext;
1122 uint32_t u32;
1123 while (*p != '\0')
1124 {
1125 vrc = RTStrToUInt32Ex(p, &pszNext, 0, &u32);
1126 if (RT_FAILURE(vrc))
1127 {
1128 RTPrintf("Incorrect value in partitions parameter\n");
1129 goto out;
1130 }
1131 uPartitions |= RT_BIT(u32);
1132 p = pszNext;
1133 if (*p == ',')
1134 p++;
1135 else if (*p != '\0')
1136 {
1137 RTPrintf("Incorrect separator in partitions parameter\n");
1138 vrc = VERR_INVALID_PARAMETER;
1139 goto out;
1140 }
1141 }
1142
1143 vrc = partRead(RawFile, &partitions);
1144 if (RT_FAILURE(vrc))
1145 {
1146 RTPrintf("Error reading the partition information from '%s'\n", rawdisk.raw());
1147 goto out;
1148 }
1149
1150 for (unsigned i = 0; i < partitions.cPartitions; i++)
1151 {
1152 if ( uPartitions & RT_BIT(partitions.aPartitions[i].uIndex)
1153 && PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
1154 {
1155 /* Some ignorant user specified an extended partition.
1156 * Bad idea, as this would trigger an overlapping
1157 * partitions error later during VMDK creation. So warn
1158 * here and ignore what the user requested. */
1159 RTPrintf("Warning: it is not possible (and necessary) to explicitly give access to the\n"
1160 " extended partition %u. If required, enable access to all logical\n"
1161 " partitions inside this extended partition.\n", partitions.aPartitions[i].uIndex);
1162 uPartitions &= ~RT_BIT(partitions.aPartitions[i].uIndex);
1163 }
1164 }
1165
1166 RawDescriptor.cPartitions = partitions.cPartitions;
1167 RawDescriptor.pPartitions = (PVBOXHDDRAWPART)RTMemAllocZ(partitions.cPartitions * sizeof(VBOXHDDRAWPART));
1168 if (!RawDescriptor.pPartitions)
1169 {
1170 RTPrintf("Out of memory allocating the partition list for '%s'\n", rawdisk.raw());
1171 vrc = VERR_NO_MEMORY;
1172 goto out;
1173 }
1174 for (unsigned i = 0; i < partitions.cPartitions; i++)
1175 {
1176 if (uPartitions & RT_BIT(partitions.aPartitions[i].uIndex))
1177 {
1178 if (fRelative)
1179 {
1180#ifdef RT_OS_LINUX
1181 /* Refer to the correct partition and use offset 0. */
1182 char *pszRawName;
1183 vrc = RTStrAPrintf(&pszRawName, "%s%u", rawdisk.raw(),
1184 partitions.aPartitions[i].uIndex);
1185 if (RT_FAILURE(vrc))
1186 {
1187 RTPrintf("Error creating reference to individual partition %u, rc=%Rrc\n",
1188 partitions.aPartitions[i].uIndex, vrc);
1189 goto out;
1190 }
1191 RawDescriptor.pPartitions[i].pszRawDevice = pszRawName;
1192 RawDescriptor.pPartitions[i].uPartitionStartOffset = 0;
1193 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1194#elif defined(RT_OS_DARWIN)
1195 /* Refer to the correct partition and use offset 0. */
1196 char *pszRawName;
1197 vrc = RTStrAPrintf(&pszRawName, "%ss%u", rawdisk.raw(),
1198 partitions.aPartitions[i].uIndex);
1199 if (RT_FAILURE(vrc))
1200 {
1201 RTPrintf("Error creating reference to individual partition %u, rc=%Rrc\n",
1202 partitions.aPartitions[i].uIndex, vrc);
1203 goto out;
1204 }
1205 RawDescriptor.pPartitions[i].pszRawDevice = pszRawName;
1206 RawDescriptor.pPartitions[i].uPartitionStartOffset = 0;
1207 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1208#else
1209 /** @todo not implemented yet for Windows host. Treat just
1210 * like not specified (this code is actually never reached). */
1211 RawDescriptor.pPartitions[i].pszRawDevice = rawdisk.raw();
1212 RawDescriptor.pPartitions[i].uPartitionStartOffset = partitions.aPartitions[i].uStart * 512;
1213 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1214#endif
1215 }
1216 else
1217 {
1218 /* This is the "everything refers to the base raw device"
1219 * variant. This requires opening the base device in RW
1220 * mode even for creation. */
1221 RawDescriptor.pPartitions[i].pszRawDevice = rawdisk.raw();
1222 RawDescriptor.pPartitions[i].uPartitionStartOffset = partitions.aPartitions[i].uStart * 512;
1223 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1224 }
1225 }
1226 else
1227 {
1228 /* Suppress access to this partition. */
1229 RawDescriptor.pPartitions[i].pszRawDevice = NULL;
1230 RawDescriptor.pPartitions[i].uPartitionStartOffset = 0;
1231 /* This is used in the plausibility check in the creation
1232 * code. In theory it's a dummy, but I don't want to make
1233 * the VMDK creatiion any more complicated than what it needs
1234 * to be. */
1235 RawDescriptor.pPartitions[i].uPartitionStart = partitions.aPartitions[i].uStart * 512;
1236 }
1237 if (PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
1238 {
1239 /* Suppress exporting the actual extended partition. Only
1240 * logical partitions should be processed. However completely
1241 * ignoring it leads to leaving out the MBR data. */
1242 RawDescriptor.pPartitions[i].cbPartition = 0;
1243 }
1244 else
1245 RawDescriptor.pPartitions[i].cbPartition = partitions.aPartitions[i].uSize * 512;
1246 RawDescriptor.pPartitions[i].uPartitionDataStart = partitions.aPartitions[i].uPartDataStart * 512;
1247 /** @todo the clipping below isn't 100% accurate, as it should
1248 * actually clip to the track size. However that's easier said
1249 * than done as figuring out the track size is heuristics. */
1250 RawDescriptor.pPartitions[i].cbPartitionData = RT_MIN(partitions.aPartitions[i].cPartDataSectors, 63) * 512;
1251 if (RawDescriptor.pPartitions[i].cbPartitionData)
1252 {
1253 Assert (RawDescriptor.pPartitions[i].cbPartitionData -
1254 (size_t)RawDescriptor.pPartitions[i].cbPartitionData == 0);
1255 void *pPartData = RTMemAlloc((size_t)RawDescriptor.pPartitions[i].cbPartitionData);
1256 if (!pPartData)
1257 {
1258 RTPrintf("Out of memory allocating the partition descriptor for '%s'\n", rawdisk.raw());
1259 vrc = VERR_NO_MEMORY;
1260 goto out;
1261 }
1262 vrc = RTFileReadAt(RawFile, partitions.aPartitions[i].uPartDataStart * 512, pPartData, (size_t)RawDescriptor.pPartitions[i].cbPartitionData, NULL);
1263 if (RT_FAILURE(vrc))
1264 {
1265 RTPrintf("Cannot read partition data from raw device '%s': %Rrc\n", rawdisk.raw(), vrc);
1266 goto out;
1267 }
1268 /* Splice in the replacement MBR code if specified. */
1269 if ( partitions.aPartitions[i].uPartDataStart == 0
1270 && pszMBRFilename)
1271 {
1272 RTFILE MBRFile;
1273 vrc = RTFileOpen(&MBRFile, pszMBRFilename, RTFILE_O_OPEN | RTFILE_O_READ | RTFILE_O_DENY_WRITE);
1274 if (RT_FAILURE(vrc))
1275 {
1276 RTPrintf("Cannot open replacement MBR file '%s' specified with -mbr: %Rrc\n", pszMBRFilename, vrc);
1277 goto out;
1278 }
1279 vrc = RTFileReadAt(MBRFile, 0, pPartData, 0x1be, NULL);
1280 RTFileClose(MBRFile);
1281 if (RT_FAILURE(vrc))
1282 {
1283 RTPrintf("Cannot read replacement MBR file '%s': %Rrc\n", pszMBRFilename, vrc);
1284 goto out;
1285 }
1286 }
1287 RawDescriptor.pPartitions[i].pvPartitionData = pPartData;
1288 }
1289 }
1290 }
1291
1292 RTFileClose(RawFile);
1293
1294 VDINTERFACE vdInterfaceError;
1295 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1296 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1297 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1298 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1299 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1300
1301 vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1302 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1303 AssertRC(vrc);
1304
1305 vrc = VDCreate(pVDIfs, &pDisk);
1306 if (RT_FAILURE(vrc))
1307 {
1308 RTPrintf("Error while creating the virtual disk container: %Rrc\n", vrc);
1309 goto out;
1310 }
1311
1312 Assert(RT_MIN(cbSize / 512 / 16 / 63, 16383) -
1313 (unsigned int)RT_MIN(cbSize / 512 / 16 / 63, 16383) == 0);
1314 PDMMEDIAGEOMETRY PCHS, LCHS;
1315 PCHS.cCylinders = (unsigned int)RT_MIN(cbSize / 512 / 16 / 63, 16383);
1316 PCHS.cHeads = 16;
1317 PCHS.cSectors = 63;
1318 LCHS.cCylinders = 0;
1319 LCHS.cHeads = 0;
1320 LCHS.cSectors = 0;
1321 vrc = VDCreateBase(pDisk, "VMDK", Utf8Str(filename).raw(), cbSize,
1322 VD_IMAGE_FLAGS_FIXED | VD_VMDK_IMAGE_FLAGS_RAWDISK,
1323 (char *)&RawDescriptor, &PCHS, &LCHS, NULL,
1324 VD_OPEN_FLAGS_NORMAL, NULL, NULL);
1325 if (RT_FAILURE(vrc))
1326 {
1327 RTPrintf("Error while creating the raw disk VMDK: %Rrc\n", vrc);
1328 goto out;
1329 }
1330 RTPrintf("RAW host disk access VMDK file %s created successfully.\n", Utf8Str(filename).raw());
1331
1332 VDCloseAll(pDisk);
1333
1334 /* Clean up allocated memory etc. */
1335 if (pszPartitions)
1336 {
1337 for (unsigned i = 0; i < partitions.cPartitions; i++)
1338 {
1339 if (uPartitions & RT_BIT(partitions.aPartitions[i].uIndex))
1340 {
1341 if (fRelative)
1342 {
1343#ifdef RT_OS_LINUX
1344 /* Free memory allocated above. */
1345 RTStrFree((char *)(void *)RawDescriptor.pPartitions[i].pszRawDevice);
1346#endif /* RT_OS_LINUX */
1347 }
1348 }
1349 }
1350 }
1351
1352 if (fRegister)
1353 {
1354 ComPtr<IMedium> hardDisk;
1355 CHECK_ERROR(aVirtualBox, OpenHardDisk(filename, AccessMode_ReadWrite, false, Bstr(""), false, Bstr(""), hardDisk.asOutParam()));
1356 }
1357
1358 return SUCCEEDED(rc) ? 0 : 1;
1359
1360out:
1361 RTPrintf("The raw disk vmdk file was not created\n");
1362 return RT_SUCCESS(vrc) ? 0 : 1;
1363}
1364
1365static int CmdRenameVMDK(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
1366{
1367 Bstr src;
1368 Bstr dst;
1369 /* Parse the arguments. */
1370 for (int i = 0; i < argc; i++)
1371 {
1372 if (strcmp(argv[i], "-from") == 0)
1373 {
1374 if (argc <= i + 1)
1375 {
1376 return errorArgument("Missing argument to '%s'", argv[i]);
1377 }
1378 i++;
1379 src = argv[i];
1380 }
1381 else if (strcmp(argv[i], "-to") == 0)
1382 {
1383 if (argc <= i + 1)
1384 {
1385 return errorArgument("Missing argument to '%s'", argv[i]);
1386 }
1387 i++;
1388 dst = argv[i];
1389 }
1390 else
1391 {
1392 return errorSyntax(USAGE_RENAMEVMDK, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1393 }
1394 }
1395
1396 if (src.isEmpty())
1397 return errorSyntax(USAGE_RENAMEVMDK, "Mandatory parameter -from missing");
1398 if (dst.isEmpty())
1399 return errorSyntax(USAGE_RENAMEVMDK, "Mandatory parameter -to missing");
1400
1401 PVBOXHDD pDisk = NULL;
1402
1403 PVDINTERFACE pVDIfs = NULL;
1404 VDINTERFACE vdInterfaceError;
1405 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1406 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1407 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1408 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1409 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1410
1411 int vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1412 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1413 AssertRC(vrc);
1414
1415 vrc = VDCreate(pVDIfs, &pDisk);
1416 if (RT_FAILURE(vrc))
1417 {
1418 RTPrintf("Error while creating the virtual disk container: %Rrc\n", vrc);
1419 return vrc;
1420 }
1421 else
1422 {
1423 vrc = VDOpen(pDisk, "VMDK", Utf8Str(src).raw(), VD_OPEN_FLAGS_NORMAL, NULL);
1424 if (RT_FAILURE(vrc))
1425 {
1426 RTPrintf("Error while opening the source image: %Rrc\n", vrc);
1427 }
1428 else
1429 {
1430 vrc = VDCopy(pDisk, 0, pDisk, "VMDK", Utf8Str(dst).raw(), true, 0, VD_IMAGE_FLAGS_NONE, NULL, NULL, NULL, NULL);
1431 if (RT_FAILURE(vrc))
1432 {
1433 RTPrintf("Error while renaming the image: %Rrc\n", vrc);
1434 }
1435 }
1436 }
1437 VDCloseAll(pDisk);
1438 return vrc;
1439}
1440
1441static int CmdConvertToRaw(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
1442{
1443 Bstr srcformat;
1444 Bstr src;
1445 Bstr dst;
1446 bool fWriteToStdOut = false;
1447
1448 /* Parse the arguments. */
1449 for (int i = 0; i < argc; i++)
1450 {
1451 if (strcmp(argv[i], "-format") == 0)
1452 {
1453 if (argc <= i + 1)
1454 {
1455 return errorArgument("Missing argument to '%s'", argv[i]);
1456 }
1457 i++;
1458 srcformat = argv[i];
1459 }
1460 else if (src.isEmpty())
1461 {
1462 src = argv[i];
1463 }
1464 else if (dst.isEmpty())
1465 {
1466 dst = argv[i];
1467#ifdef ENABLE_CONVERT_RAW_TO_STDOUT
1468 if (!strcmp(argv[i], "stdout"))
1469 fWriteToStdOut = true;
1470#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
1471 }
1472 else
1473 {
1474 return errorSyntax(USAGE_CONVERTTORAW, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1475 }
1476 }
1477
1478 if (src.isEmpty())
1479 return errorSyntax(USAGE_CONVERTTORAW, "Mandatory filename parameter missing");
1480 if (dst.isEmpty())
1481 return errorSyntax(USAGE_CONVERTTORAW, "Mandatory outputfile parameter missing");
1482
1483 PVBOXHDD pDisk = NULL;
1484
1485 PVDINTERFACE pVDIfs = NULL;
1486 VDINTERFACE vdInterfaceError;
1487 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1488 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1489 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1490 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1491 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1492
1493 int vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1494 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1495 AssertRC(vrc);
1496
1497 vrc = VDCreate(pVDIfs, &pDisk);
1498 if (RT_FAILURE(vrc))
1499 {
1500 RTPrintf("Error while creating the virtual disk container: %Rrc\n", vrc);
1501 return 1;
1502 }
1503
1504 /* Open raw output file. */
1505 RTFILE outFile;
1506 vrc = VINF_SUCCESS;
1507 if (fWriteToStdOut)
1508 outFile = 1;
1509 else
1510 vrc = RTFileOpen(&outFile, Utf8Str(dst).raw(), RTFILE_O_OPEN | RTFILE_O_CREATE | RTFILE_O_WRITE | RTFILE_O_DENY_ALL);
1511 if (RT_FAILURE(vrc))
1512 {
1513 VDCloseAll(pDisk);
1514 RTPrintf("Error while creating destination file \"%s\": %Rrc\n", Utf8Str(dst).raw(), vrc);
1515 return 1;
1516 }
1517
1518 if (srcformat.isEmpty())
1519 {
1520 char *pszFormat = NULL;
1521 vrc = VDGetFormat(NULL, Utf8Str(src).raw(), &pszFormat);
1522 if (RT_FAILURE(vrc))
1523 {
1524 VDCloseAll(pDisk);
1525 if (!fWriteToStdOut)
1526 {
1527 RTFileClose(outFile);
1528 RTFileDelete(Utf8Str(dst).raw());
1529 }
1530 RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc);
1531 return 1;
1532 }
1533 srcformat = pszFormat;
1534 RTStrFree(pszFormat);
1535 }
1536 vrc = VDOpen(pDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL);
1537 if (RT_FAILURE(vrc))
1538 {
1539 VDCloseAll(pDisk);
1540 if (!fWriteToStdOut)
1541 {
1542 RTFileClose(outFile);
1543 RTFileDelete(Utf8Str(dst).raw());
1544 }
1545 RTPrintf("Error while opening the source image: %Rrc\n", vrc);
1546 return 1;
1547 }
1548
1549 uint64_t cbSize = VDGetSize(pDisk, VD_LAST_IMAGE);
1550 uint64_t offFile = 0;
1551#define RAW_BUFFER_SIZE _128K
1552 uint64_t cbBuf = RAW_BUFFER_SIZE;
1553 void *pvBuf = RTMemAlloc(cbBuf);
1554 if (pvBuf)
1555 {
1556 RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB) to raw...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M);
1557 while (offFile < cbSize)
1558 {
1559 size_t cb = cbSize - offFile >= (uint64_t)cbBuf ? cbBuf : (size_t)(cbSize - offFile);
1560 vrc = VDRead(pDisk, offFile, pvBuf, cb);
1561 if (RT_FAILURE(vrc))
1562 break;
1563 vrc = RTFileWrite(outFile, pvBuf, cb, NULL);
1564 if (RT_FAILURE(vrc))
1565 break;
1566 offFile += cb;
1567 }
1568 if (RT_FAILURE(vrc))
1569 {
1570 VDCloseAll(pDisk);
1571 if (!fWriteToStdOut)
1572 {
1573 RTFileClose(outFile);
1574 RTFileDelete(Utf8Str(dst).raw());
1575 }
1576 RTPrintf("Error copying image data: %Rrc\n", vrc);
1577 return 1;
1578 }
1579 }
1580 else
1581 {
1582 vrc = VERR_NO_MEMORY;
1583 VDCloseAll(pDisk);
1584 if (!fWriteToStdOut)
1585 {
1586 RTFileClose(outFile);
1587 RTFileDelete(Utf8Str(dst).raw());
1588 }
1589 RTPrintf("Error allocating read buffer: %Rrc\n", vrc);
1590 return 1;
1591 }
1592
1593 if (!fWriteToStdOut)
1594 RTFileClose(outFile);
1595 VDCloseAll(pDisk);
1596 return 0;
1597}
1598
1599static int CmdConvertHardDisk(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
1600{
1601 Bstr srcformat;
1602 Bstr dstformat;
1603 Bstr src;
1604 Bstr dst;
1605 int vrc;
1606 PVBOXHDD pSrcDisk = NULL;
1607 PVBOXHDD pDstDisk = NULL;
1608
1609 /* Parse the arguments. */
1610 for (int i = 0; i < argc; i++)
1611 {
1612 if (strcmp(argv[i], "-srcformat") == 0)
1613 {
1614 if (argc <= i + 1)
1615 {
1616 return errorArgument("Missing argument to '%s'", argv[i]);
1617 }
1618 i++;
1619 srcformat = argv[i];
1620 }
1621 else if (strcmp(argv[i], "-dstformat") == 0)
1622 {
1623 if (argc <= i + 1)
1624 {
1625 return errorArgument("Missing argument to '%s'", argv[i]);
1626 }
1627 i++;
1628 dstformat = argv[i];
1629 }
1630 else if (src.isEmpty())
1631 {
1632 src = argv[i];
1633 }
1634 else if (dst.isEmpty())
1635 {
1636 dst = argv[i];
1637 }
1638 else
1639 {
1640 return errorSyntax(USAGE_CONVERTHD, "Invalid parameter '%s'", Utf8Str(argv[i]).raw());
1641 }
1642 }
1643
1644 if (src.isEmpty())
1645 return errorSyntax(USAGE_CONVERTHD, "Mandatory input image parameter missing");
1646 if (dst.isEmpty())
1647 return errorSyntax(USAGE_CONVERTHD, "Mandatory output image parameter missing");
1648
1649
1650 PVDINTERFACE pVDIfs = NULL;
1651 VDINTERFACE vdInterfaceError;
1652 VDINTERFACEERROR vdInterfaceErrorCallbacks;
1653 vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
1654 vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
1655 vdInterfaceErrorCallbacks.pfnError = handleVDError;
1656 vdInterfaceErrorCallbacks.pfnMessage = NULL;
1657
1658 vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
1659 &vdInterfaceErrorCallbacks, NULL, &pVDIfs);
1660 AssertRC(vrc);
1661
1662 do
1663 {
1664 /* Try to determine input image format */
1665 if (srcformat.isEmpty())
1666 {
1667 char *pszFormat = NULL;
1668 vrc = VDGetFormat(NULL, Utf8Str(src).raw(), &pszFormat);
1669 if (RT_FAILURE(vrc))
1670 {
1671 RTPrintf("No file format specified and autodetect failed - please specify format: %Rrc\n", vrc);
1672 break;
1673 }
1674 srcformat = pszFormat;
1675 RTStrFree(pszFormat);
1676 }
1677
1678 vrc = VDCreate(pVDIfs, &pSrcDisk);
1679 if (RT_FAILURE(vrc))
1680 {
1681 RTPrintf("Error while creating the source virtual disk container: %Rrc\n", vrc);
1682 break;
1683 }
1684
1685 /* Open the input image */
1686 vrc = VDOpen(pSrcDisk, Utf8Str(srcformat).raw(), Utf8Str(src).raw(), VD_OPEN_FLAGS_READONLY, NULL);
1687 if (RT_FAILURE(vrc))
1688 {
1689 RTPrintf("Error while opening the source image: %Rrc\n", vrc);
1690 break;
1691 }
1692
1693 /* Output format defaults to VDI */
1694 if (dstformat.isEmpty())
1695 dstformat = "VDI";
1696
1697 vrc = VDCreate(pVDIfs, &pDstDisk);
1698 if (RT_FAILURE(vrc))
1699 {
1700 RTPrintf("Error while creating the destination virtual disk container: %Rrc\n", vrc);
1701 break;
1702 }
1703
1704 uint64_t cbSize = VDGetSize(pSrcDisk, VD_LAST_IMAGE);
1705 RTPrintf("Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", Utf8Str(src).raw(), cbSize, (cbSize + _1M - 1) / _1M);
1706
1707 /* Create the output image */
1708 vrc = VDCopy(pSrcDisk, VD_LAST_IMAGE, pDstDisk, Utf8Str(dstformat).raw(),
1709 Utf8Str(dst).raw(), false, 0, VD_VMDK_IMAGE_FLAGS_STREAM_OPTIMIZED, NULL, NULL, NULL, NULL);
1710 if (RT_FAILURE(vrc))
1711 {
1712 RTPrintf("Error while copying the image: %Rrc\n", vrc);
1713 break;
1714 }
1715 }
1716 while (0);
1717 if (pDstDisk)
1718 VDCloseAll(pDstDisk);
1719 if (pSrcDisk)
1720 VDCloseAll(pSrcDisk);
1721
1722 return RT_SUCCESS(vrc) ? 0 : 1;
1723}
1724
1725/**
1726 * Unloads the neccessary driver.
1727 *
1728 * @returns VBox status code
1729 */
1730int CmdModUninstall(void)
1731{
1732 int rc;
1733
1734 rc = SUPR3Uninstall();
1735 if (RT_SUCCESS(rc))
1736 return 0;
1737 if (rc == VERR_NOT_IMPLEMENTED)
1738 return 0;
1739 return E_FAIL;
1740}
1741
1742/**
1743 * Loads the neccessary driver.
1744 *
1745 * @returns VBox status code
1746 */
1747int CmdModInstall(void)
1748{
1749 int rc;
1750
1751 rc = SUPR3Install();
1752 if (RT_SUCCESS(rc))
1753 return 0;
1754 if (rc == VERR_NOT_IMPLEMENTED)
1755 return 0;
1756 return E_FAIL;
1757}
1758
1759/**
1760 * Wrapper for handling internal commands
1761 */
1762int handleInternalCommands(HandlerArg *a)
1763{
1764 g_fInternalMode = true;
1765
1766 /* at least a command is required */
1767 if (a->argc < 1)
1768 return errorSyntax(USAGE_ALL, "Command missing");
1769
1770 /*
1771 * The 'string switch' on command name.
1772 */
1773 const char *pszCmd = a->argv[0];
1774 if (!strcmp(pszCmd, "loadsyms"))
1775 return CmdLoadSyms(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1776 //if (!strcmp(pszCmd, "unloadsyms"))
1777 // return CmdUnloadSyms(argc - 1 , &a->argv[1]);
1778 if (!strcmp(pszCmd, "sethduuid") || !strcmp(pszCmd, "setvdiuuid"))
1779 return CmdSetHDUUID(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1780 if (!strcmp(pszCmd, "dumphdinfo"))
1781 return CmdDumpHDInfo(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1782 if (!strcmp(pszCmd, "listpartitions"))
1783 return CmdListPartitions(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1784 if (!strcmp(pszCmd, "createrawvmdk"))
1785 return CmdCreateRawVMDK(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1786 if (!strcmp(pszCmd, "renamevmdk"))
1787 return CmdRenameVMDK(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1788 if (!strcmp(pszCmd, "converttoraw"))
1789 return CmdConvertToRaw(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1790 if (!strcmp(pszCmd, "converthd"))
1791 return CmdConvertHardDisk(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
1792
1793 if (!strcmp(pszCmd, "modinstall"))
1794 return CmdModInstall();
1795 if (!strcmp(pszCmd, "moduninstall"))
1796 return CmdModUninstall();
1797
1798 /* default: */
1799 return errorSyntax(USAGE_ALL, "Invalid command '%s'", Utf8Str(a->argv[0]).raw());
1800}
1801
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