VBoxInternalManage.cpp revision 824ae3158a8b8f8233fec3f5a12c81f139933698
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VBoxManage - The 'internalcommands' command.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VBoxInternalManage used to be a second CLI for doing special tricks,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * not intended for general usage, only for assisting VBox developers.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * It is now integrated into VBoxManage.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Copyright (C) 2006-2010 Oracle Corporation
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * available from http://www.virtualbox.org. This file is free software;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * you can redistribute it and/or modify it under the terms of the GNU
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * General Public License (GPL) as published by the Free Software
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync/*******************************************************************************
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync* Header Files *
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync*******************************************************************************/
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/* Includes for the raw disk stuff. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync#elif defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) \
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync || defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD)
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#endif /* RT_OS_LINUX */
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#endif /* RT_OS_DARWIN */
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync#endif /* RT_OS_SOLARIS */
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync#endif /* RT_OS_FREEBSD */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncusing namespace com;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/** Macro for checking whether a partition is of extended type or not. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#define PARTTYPE_IS_EXTENDED(x) ((x) == 0x05 || (x) == 0x0f || (x) == 0x85)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/** Maximum number of partitions we can deal with.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Ridiculously large number, but the memory consumption is rather low so who
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * cares about never using most entries. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** partition type */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** CHS/cylinder of the first sector */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** CHS/head of the first sector */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** CHS/head of the first sector */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync /** CHS/cylinder of the last sector */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** CHS/head of the last sector */
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync /** CHS/sector of the last sector */
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync /** start sector of this partition relative to the beginning of the hard
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * disk or relative to the beginning of the extended partition table */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** numer of sectors of the partition */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** start sector of this partition _table_ */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /** numer of sectors of this partition _table_ */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync/** flag whether we're in internal mode */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Print the usage info.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncvoid printUsageInternal(USAGECATEGORY u64Cmd, PRTSTREAM pStrm)
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync "Usage: VBoxManage internalcommands <command> [command arguments]\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "Commands:\n"
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync "%s%s%s%s%s%s%s%s%s%s%s%s"
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync "WARNING: This is a development tool and shall only be used to analyse\n"
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync " problems. It is completely unsupported and will change in\n"
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync " incompatible ways without warning.\n",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " loadsyms <vmname>|<uuid> <symfile> [delta] [module] [module address]\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " This will instruct DBGF to load the given symbolfile\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " during initialization.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " unloadsyms <vmname>|<uuid> <symfile>\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Removes <symfile> from the list of symbol files that\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " should be loaded during DBF initialization.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " sethduuid <filepath> [<uuid>]\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Assigns a new UUID to the given image file. This way, multiple copies\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " of a container can be registered.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " sethdparentuuid <filepath> <uuid>\n"
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync " Assigns a new parent UUID to the given image file.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " dumphdinfo <filepath>\n"
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync " Prints information about the image at the given location.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " listpartitions -rawdisk <diskname>\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Lists all partitions on <diskname>.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " createrawvmdk -filename <filename> -rawdisk <diskname>\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " [-partitions <list of partition numbers> [-mbr <filename>] ]\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " [-register] [-relative]\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Creates a new VMDK image which gives access to an entite host disk (if\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " the parameter -partitions is not specified) or some partitions of a\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " host disk. If access to individual partitions is granted, then the\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " parameter -mbr can be used to specify an alternative MBR to be used\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " (the partitioning information in the MBR file is ignored).\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " The diskname is on Linux e.g. /dev/sda, and on Windows e.g.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " \\\\.\\PhysicalDrive0).\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " On Linux host the parameter -relative causes a VMDK file to be created\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " which refers to individual partitions instead to the entire disk.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Optionally the created image can be immediately registered.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " The necessary partition numbers can be queried with\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " VBoxManage internalcommands listpartitions\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " renamevmdk -from <filename> -to <filename>\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Renames an existing VMDK image, including the base file and all its extents.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " converttoraw [-format <fileformat>] <filename> <outputfile>"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync " Convert image to raw, writing to file"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " or stdout"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* ENABLE_CONVERT_RAW_TO_STDOUT */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " converthd [-srcformat VDI|VMDK|VHD|RAW]\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " [-dstformat VDI|VMDK|VHD|RAW]\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " <inputfile> <outputfile>\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " converts hard disk images between formats\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " modinstall\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Installs the neccessary driver for the host OS\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " moduninstall\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync " Deinstalls the driver\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync ? " debuglog <vmname>|<uuid> [--enable|--disable] [--flags todo]\n"
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync " [--groups todo] [--destinations todo]\n"
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync " Controls debug logging.\n"
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync/** @todo this is no longer necessary, we can enumerate extra data */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Finds a new unique key name.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * I don't think this is 100% race condition proof, but we assumes
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * the user is not trying to push this point.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @returns Result from the insert.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pMachine The Machine object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKeyBase The base key.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * @param rKey Reference to the string object in which we will return the key.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsyncstatic HRESULT NewUniqueKey(ComPtr<IMachine> pMachine, const char *pszKeyBase, Utf8Str &rKey)
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync HRESULT hrc = pMachine->GetExtraData(Bstr(pszKeyBase), Keys.asOutParam());
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* if there are no keys, it's simple. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync return pMachine->SetExtraData(Bstr(pszKeyBase), Bstr("1"));
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* find a unique number - brute force rulez. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync const char *pszKeys = RTStrStripL(KeysUtf8.c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync size_t cchKey = RTStrPrintf(szKey, sizeof(szKey), "%#x", i);
78df65edff21c11c537f38e736707ea434ab5623vboxsync return pMachine->SetExtraData(Bstr(pszKeyBase), Bstr(NewKeysUtf8));
78df65edff21c11c537f38e736707ea434ab5623vboxsync RTMsgError("Cannot find unique key for '%s'!", pszKeyBase);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * Remove a key.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * I don't think this isn't 100% race condition proof, but we assumes
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * the user is not trying to push this point.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * @returns Result from the insert.
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * @param pMachine The machine object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKeyBase The base key.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKey The key to remove.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic HRESULT RemoveKey(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT hrc = pMachine->GetExtraData(Bstr(pszKeyBase), Keys.asOutParam());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* if there are no keys, it's simple. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* locate it */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* remove it */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* update */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync hrc = pMachine->SetExtraData(Bstr(pszKeyBase), Bstr(psz));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Failed to delete key '%s' from '%s', string conversion error %Rrc!",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Sets a key value, does necessary error bitching.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @returns COM status code.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pMachine The Machine object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKeyBase The key base.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKey The key.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszAttribute The attribute name.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszValue The string value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic HRESULT SetString(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, const char *pszValue)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync HRESULT hrc = pMachine->SetExtraData(Bstr(Utf8StrFmt("%s/%s/%s", pszKeyBase, pszKey, pszAttribute)), Bstr(pszValue));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Failed to set '%s/%s/%s' to '%s'! hrc=%#x",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Sets a key value, does necessary error bitching.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @returns COM status code.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pMachine The Machine object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKeyBase The key base.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKey The key.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszAttribute The attribute name.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param u64Value The value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic HRESULT SetUInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, uint64_t u64Value)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTStrPrintf(szValue, sizeof(szValue), "%#RX64", u64Value);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return SetString(pMachine, pszKeyBase, pszKey, pszAttribute, szValue);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Sets a key value, does necessary error bitching.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @returns COM status code.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pMachine The Machine object.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKeyBase The key base.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszKey The key.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param pszAttribute The attribute name.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * @param i64Value The value.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic HRESULT SetInt64(ComPtr<IMachine> pMachine, const char *pszKeyBase, const char *pszKey, const char *pszAttribute, int64_t i64Value)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTStrPrintf(szValue, sizeof(szValue), "%RI64", i64Value);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return SetString(pMachine, pszKeyBase, pszKey, pszAttribute, szValue);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Identical to the 'loadsyms' command.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic int CmdLoadSyms(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Get the VM
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* assume it's a UUID */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = aVirtualBox->GetMachine(Bstr(argv[0]), machine.asOutParam());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* must be a name */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync CHECK_ERROR_RET(aVirtualBox, FindMachine(Bstr(argv[0]), machine.asOutParam()), 1);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Parse the command.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* filename */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorArgument("Missing the filename argument!\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* offDelta */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int irc = RTStrToInt64Ex(argv[2], NULL, 0, &offDelta);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorArgument(argv[0], "Failed to read delta '%s', rc=%Rrc\n", argv[2], rc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* pszModule */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* ModuleAddress */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int irc = RTStrToUInt64Ex(argv[4], NULL, 0, &ModuleAddress);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorArgument(argv[0], "Failed to read module address '%s', rc=%Rrc\n", argv[4], rc);
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync /* ModuleSize */
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync int irc = RTStrToUInt64Ex(argv[5], NULL, 0, &ModuleSize);
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync return errorArgument(argv[0], "Failed to read module size '%s', rc=%Rrc\n", argv[5], rc);
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync * Add extra data.
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync HRESULT hrc = NewUniqueKey(machine, "VBoxInternal/DBGF/loadsyms", KeyStr);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Filename", pszFilename);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync hrc = SetInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Delta", offDelta);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync hrc = SetString(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "Module", pszModule);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleAddress", ModuleAddress);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync hrc = SetUInt64(machine, "VBoxInternal/DBGF/loadsyms", KeyStr.c_str(), "ModuleSize", ModuleSize);
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsyncstatic DECLCALLBACK(void) handleVDError(void *pvUser, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync RTMsgError("Error code %Rrc at %s(%u) in function %s", rc, RT_SRC_POS_ARGS);
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsyncstatic int handleVDMessage(void *pvUser, const char *pszFormat, va_list va)
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsyncstatic int CmdSetHDUUID(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync return errorSyntax(USAGE_SETHDUUID, "Not enough parameters");
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync /* if specified, take UUID, otherwise generate a new one */
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync return errorSyntax(USAGE_SETHDUUID, "Invalid UUID parameter");
7fee49908ea4b9f6cb4f9cc745633c4969ed6318vboxsync return errorSyntax(USAGE_SETHDPARENTUUID, "Not enough parameters");
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync return errorSyntax(USAGE_SETHDPARENTUUID, "Invalid UUID parameter");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_SETHDUUID, "Invalid invocation");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* just try it */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int rc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.pfnError = handleVDError;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot create the virtual disk container: %Rrc", rc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Open the image */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = VDOpen(pDisk, pszFormat, argv[1], VD_OPEN_FLAGS_NORMAL, NULL);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = VDSetParentUuid(pDisk, VD_LAST_IMAGE, uuid.raw());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("UUID changed to: %s\n", uuid.toString().c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic int CmdDumpHDInfo(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* we need exactly one parameter: the image file */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_DUMPHDINFO, "Not enough parameters");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* just try it */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int rc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.pfnError = handleVDError;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot create the virtual disk container: %Rrc", rc);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync /* Open the image */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync rc = VDOpen(pDisk, pszFormat, argv[0], VD_OPEN_FLAGS_INFO, NULL);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsyncstatic int partRead(RTFILE File, PHOSTPARTITIONS pPart)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync memset(pPart->aPartitions, '\0', sizeof(pPart->aPartitions));
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync rc = RTFileReadAt(File, 0, &aBuffer, sizeof(aBuffer), NULL);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync for (unsigned i = 0; i < 4; i++)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (p[4] == 0)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pCP->uStartCylinder = (uint32_t)p[3] + ((uint32_t)(p[2] & 0xc0) << 2);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pCP->uEndCylinder = (uint32_t)p[7] + ((uint32_t)(p[6] & 0xc0) << 2);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pCP->uStart = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pCP->uSize = RT_MAKE_U32_FROM_U8(p[12], p[13], p[14], p[15]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pCP->uPartDataStart = 0; /* will be filled out later properly. */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync uint64_t uStart = pPart->aPartitions[uExtended].uStart;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Inconsistency for logical partition start");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync rc = RTFileReadAt(File, (uStart + uOffset) * 512, &aBuffer, sizeof(aBuffer), NULL);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (p[4] == 0)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync RTMsgError("Logical partition with type 0 encountered");
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync PHOSTPARTITION pCP = &pPart->aPartitions[pPart->cPartitions++];
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pCP->uStartCylinder = (uint32_t)p[3] + ((uint32_t)(p[2] & 0xc0) << 2);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pCP->uEndCylinder = (uint32_t)p[7] + ((uint32_t)(p[6] & 0xc0) << 2);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync uint32_t uStartOffset = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pCP->uSize = RT_MAKE_U32_FROM_U8(p[12], p[13], p[14], p[15]);
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync /* Fill out partitioning location info for EBR. */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync if (p[4] == 0)
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync uOffset = RT_MAKE_U32_FROM_U8(p[8], p[9], p[10], p[11]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Sort partitions in ascending order of start sector, plus a trivial
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * bit of consistency checking. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (unsigned i = 0; i < pPart->cPartitions-1; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned uMinIdx = i;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (unsigned j = i + 1; j < pPart->cPartitions; j++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Two partitions start at the same place");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Swap entries at index i and uMinIdx. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync &pPart->aPartitions[uMinIdx], sizeof(HOSTPARTITION));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync &pPart->aPartitions[pPart->cPartitions], sizeof(HOSTPARTITION));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Fill out partitioning location info for MBR. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pPart->aPartitions[0].cPartDataSectors = pPart->aPartitions[0].uStart;
ae5fc6ddd3d2ccdb941b1aacd23f6791fecc3354vboxsync /* Now do a some partition table consistency checking, to reject the most
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * obvious garbage which can lead to trouble later. */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync for (unsigned i = 0; i < pPart->cPartitions-1; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync uPrevEnd = pPart->aPartitions[i].uPartDataStart + pPart->aPartitions[i].cPartDataSectors;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!PARTTYPE_IS_EXTENDED(pPart->aPartitions[i].uType))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync uPrevEnd = pPart->aPartitions[i].uStart + pPart->aPartitions[i].uSize;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic int CmdListPartitions(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* let's have a closer look at the arguments */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (int i = 0; i < argc; i++)
0433783a793d5ced0dc7f9dcf102143b66e1cd2cvboxsync return errorArgument("Missing argument to '%s'", argv[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_LISTPARTITIONS, "Invalid parameter '%s'", argv[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_LISTPARTITIONS, "Mandatory parameter -rawdisk missing");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int vrc = RTFileOpen(&RawFile, rawdisk.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannnot open the raw disk: %Rrc", vrc);
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync /* Don't bail out on errors, print the table and return the result code. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("Number Type StartCHS EndCHS Size (MiB) Start (Sect)\n");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (unsigned i = 0; i < partitions.cPartitions; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Don't show the extended partition, otherwise users might think they
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * can add it to the list of partitions for raw partition access. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("%-7u %#04x %-4u/%-3u/%-2u %-4u/%-3u/%-2u %10llu %10llu\n",
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic PVBOXHDDRAWPARTDESC appendPartDesc(uint32_t *pcPartDescs, PVBOXHDDRAWPARTDESC *ppPartDescs)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync p = (PVBOXHDDRAWPARTDESC)RTMemRealloc(*ppPartDescs,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsyncstatic int CmdCreateRawVMDK(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync bool fRegister = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync bool fRelative = false;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* let's have a closer look at the arguments */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (int i = 0; i < argc; i++)
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync return errorArgument("Missing argument to '%s'", argv[i]);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync return errorArgument("Missing argument to '%s'", argv[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorArgument("Missing argument to '%s'", argv[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorArgument("Missing argument to '%s'", argv[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* RT_OS_LINUX */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_CREATERAWVMDK, "Invalid parameter '%s'", argv[i]);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_CREATERAWVMDK, "Mandatory parameter -filename missing");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_CREATERAWVMDK, "Mandatory parameter -rawdisk missing");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync return errorSyntax(USAGE_CREATERAWVMDK, "The parameter -mbr is only valid when the parameter -partitions is also present");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#endif /* RT_OS_DARWIN */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync int vrc = RTFileOpen(&RawFile, rawdisk.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot open the raw disk '%s': %Rrc", rawdisk.c_str(), vrc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Windows NT has no IOCTL_DISK_GET_LENGTH_INFORMATION ioctl. This was
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * added to Windows XP, so we have to use the available info from DriveGeo.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Note that we cannot simply use IOCTL_DISK_GET_DRIVE_GEOMETRY as it
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync * yields a slightly different result than IOCTL_DISK_GET_LENGTH_INFO.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * We call IOCTL_DISK_GET_DRIVE_GEOMETRY first as we need to check the media
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync * type anyway, and if IOCTL_DISK_GET_LENGTH_INFORMATION is supported
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * we will later override cbSize.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("File '%s' is no fixed/removable medium device", rawdisk.c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync &DiskLenInfo, sizeof(DiskLenInfo), &junk, (LPOVERLAPPED)NULL))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* IOCTL_DISK_GET_LENGTH_INFO is supported -- override cbSize. */
6abae205eac4f4a16f6ad5a2a71ed1f36d6a57b0vboxsync RTMsgError("Cannot get the geometry of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* BLKGETSIZE64 is broken up to 2.4.17 and in many 2.5.x. In 2.6.0
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * it works without problems. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync && ( (strncmp(utsname.release, "2.5.", 4) == 0 && atoi(&utsname.release[4]) >= 18)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync || (strncmp(utsname.release, "2.", 2) == 0 && atoi(&utsname.release[2]) >= 6)))
090c459b9e90ca46e2ce2b8c81533ade3b23f3e9vboxsync#endif /* BLKGETSIZE64 */
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync RTMsgError("Cannot get the size of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc);
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync RTMsgError("File '%s' is no block device", rawdisk.c_str());
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync if (!fstat(RawFile, &DevStat) && S_ISBLK(DevStat.st_mode))
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync RTMsgError("Cannot get the block size for file '%s': %Rrc", rawdisk.c_str(), vrc);
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync RTMsgError("Cannot get the block count for file '%s': %Rrc", rawdisk.c_str(), vrc);
04b02ffb8824a60fd37777bc1f7d2f35104a274cvboxsync RTMsgError("File '%s' is no block device", rawdisk.c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!fstat(RawFile, &DevStat) && ( S_ISBLK(DevStat.st_mode)
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync cbSize = mediainfo.dki_capacity * mediainfo.dki_lbsize;
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync RTMsgError("Cannot get the size of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc);
be9960565d2df0031f0e6c8a4610f5f0ae8c1845vboxsync RTMsgError("File '%s' is no block or char device", rawdisk.c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if (!fstat(RawFile, &DevStat) && S_ISCHR(DevStat.st_mode))
f45123ab6638fb0a030ffbfa96598635efd24a01vboxsync RTMsgError("Cannot get the block count for file '%s': %Rrc", rawdisk.c_str(), vrc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("File '%s' is no character device", rawdisk.c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync#else /* all unrecognized OSes */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Hopefully this works on all other hosts. If it doesn't, it'll just fail
a0a3a26a4065b9401681a8c99a11bd83e08f94ccvboxsync * creating the VMDK, so no real harm done. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot get the size of the raw disk '%s': %Rrc", rawdisk.c_str(), vrc);
78df65edff21c11c537f38e736707ea434ab5623vboxsync /* Check whether cbSize is actually sensible. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Detected size of raw disk '%s' is %s, an invalid value", rawdisk.c_str(), cbSize);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync const char *p = pszPartitions;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync while (*p != '\0')
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Incorrect value in partitions parameter");
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync if (*p == ',')
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync else if (*p != '\0')
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync RTMsgError("Incorrect separator in partitions parameter");
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot read the partition information from '%s'", rawdisk.c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (unsigned i = 0; i < partitions.cPartitions; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync if ( uPartitions & RT_BIT(partitions.aPartitions[i].uIndex)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync && PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Some ignorant user specified an extended partition.
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * Bad idea, as this would trigger an overlapping
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * partitions error later during VMDK creation. So warn
37a7e3e6f9ce5f6cabeb3f734044e9e8ca9cb1bfvboxsync * here and ignore what the user requested. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgWarning("It is not possible (and necessary) to explicitly give access to the "
0433783a793d5ced0dc7f9dcf102143b66e1cd2cvboxsync "extended partition %u. If required, enable access to all logical "
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync "partitions inside this extended partition.",
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync uPartitions &= ~RT_BIT(partitions.aPartitions[i].uIndex);
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync for (unsigned i = 0; i < partitions.cPartitions; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* first dump the MBR/EPT data area */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync pPartDesc = appendPartDesc(&RawDescriptor.cPartDescs,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Out of memory allocating the partition list for '%s'", rawdisk.c_str());
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /** @todo the clipping below isn't 100% accurate, as it should
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * actually clip to the track size. However that's easier said
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * than done as figuring out the track size is heuristics. In
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * any case the clipping is adjusted later after sorting, to
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * prevent overlapping data areas on the resulting image. */
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync pPartDesc->cbData = RT_MIN(partitions.aPartitions[i].cPartDataSectors, 63) * 512;
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync pPartDesc->uStart = partitions.aPartitions[i].uPartDataStart * 512;
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync Assert(pPartDesc->cbData - (size_t)pPartDesc->cbData == 0);
ed82223f8f7be1435bf9b203a0ee4fbdfc856dc8vboxsync void *pPartData = RTMemAlloc((size_t)pPartDesc->cbData);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Out of memory allocating the partition descriptor for '%s'", rawdisk.c_str());
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vrc = RTFileReadAt(RawFile, partitions.aPartitions[i].uPartDataStart * 512,
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot read partition data from raw device '%s': %Rrc", rawdisk.c_str(), vrc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Splice in the replacement MBR code if specified. */
f3abe19bdaeea1b354674327ee95707281a6ad83vboxsync vrc = RTFileOpen(&MBRFile, pszMBRFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot open replacement MBR file '%s' specified with -mbr: %Rrc", pszMBRFilename, vrc);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vrc = RTFileReadAt(MBRFile, 0, pPartData, 0x1be, NULL);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot read replacement MBR file '%s': %Rrc", pszMBRFilename, vrc);
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync if (PARTTYPE_IS_EXTENDED(partitions.aPartitions[i].uType))
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Suppress exporting the actual extended partition. Only
b2e90826ea719b22452d1ff7b977d4f40995b428vboxsync * logical partitions should be processed. However completely
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync * ignoring it leads to leaving out the EBR data. */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* set up values for non-relative device names */
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync uint64_t uStartOffset = partitions.aPartitions[i].uStart * 512;
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync pPartDesc = appendPartDesc(&RawDescriptor.cPartDescs,
03493c32c4a1ce2b083405efe6f3b070bead1be6vboxsync RTMsgError("Out of memory allocating the partition list for '%s'", rawdisk.c_str());
03493c32c4a1ce2b083405efe6f3b070bead1be6vboxsync if (uPartitions & RT_BIT(partitions.aPartitions[i].uIndex))
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Refer to the correct partition and use offset 0. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot create reference to individual partition %u, rc=%Rrc",
f632be0ea31134f1ce343e84c90d7984d2bf96b2vboxsync /* Refer to the correct partition and use offset 0. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTMsgError("Cannot create reference to individual partition %u, rc=%Rrc",
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync /** @todo not implemented for other hosts. Treat just like
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync * not specified (this code is actually never reached). */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pPartDesc->uStart = partitions.aPartitions[i].uStart * 512;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync pPartDesc->cbData = partitions.aPartitions[i].uSize * 512;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Sort data areas in ascending order of start. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (unsigned i = 0; i < RawDescriptor.cPartDescs-1; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync unsigned uMinIdx = i;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync uint64_t uMinVal = RawDescriptor.pPartDescs[i].uStart;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (unsigned j = i + 1; j < RawDescriptor.cPartDescs; j++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Swap entries at index i and uMinIdx. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync memcpy(&tmp, &RawDescriptor.pPartDescs[i], sizeof(tmp));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync memcpy(&RawDescriptor.pPartDescs[i], &RawDescriptor.pPartDescs[uMinIdx], sizeof(tmp));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync memcpy(&RawDescriptor.pPartDescs[uMinIdx], &tmp, sizeof(tmp));
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync /* Have a second go at MBR/EPT area clipping. Now that the data areas
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync * are sorted this is much easier to get 100% right. */
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync for (unsigned i = 0; i < RawDescriptor.cPartDescs-1; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RawDescriptor.pPartDescs[i].cbData = RT_MIN(RawDescriptor.pPartDescs[i+1].uStart - RawDescriptor.pPartDescs[i].uStart, RawDescriptor.pPartDescs[i].cbData);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("# start length startoffset partdataptr device\n");
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync for (unsigned i = 0; i < RawDescriptor.cPartDescs; i++)
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync RTPrintf("%2u %14RU64 %14RU64 %14RU64 %#18p %s\n", i,
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync vdInterfaceErrorCallbacks.cbSize = sizeof(VDINTERFACEERROR);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync vdInterfaceErrorCallbacks.enmInterface = VDINTERFACETYPE_ERROR;
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vdInterfaceErrorCallbacks.pfnError = handleVDError;
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync vdInterfaceErrorCallbacks.pfnMessage = handleVDMessage;
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync vrc = VDInterfaceAdd(&vdInterfaceError, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync RTMsgError("Cannot create the virtual disk container: %Rrc", vrc);
b14965bee0bfb359e6ce9db6beaa4add9935fe3cvboxsync (unsigned int)RT_MIN(cbSize / 512 / 16 / 63, 16383) == 0);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync PCHS.cCylinders = (unsigned int)RT_MIN(cbSize / 512 / 16 / 63, 16383);
30a23dfc653298a09d77d3045cf873b1bd6ddecfvboxsync vrc = VDCreateBase(pDisk, "VMDK", filename.c_str(), cbSize,
goto out;
if (pszPartitions)
if (fRegister)
CHECK_ERROR(aVirtualBox, OpenMedium(Bstr(filename), DeviceType_HardDisk, AccessMode_ReadWrite, hardDisk.asOutParam()));
out:
static int CmdRenameVMDK(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
for (int i = 0; i < argc; i++)
return vrc;
vrc = VDCopy(pDisk, 0, pDisk, "VMDK", dst.c_str(), true, 0, VD_IMAGE_FLAGS_NONE, NULL, NULL, NULL, NULL);
return vrc;
static int CmdConvertToRaw(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
bool fWriteToStdOut = false;
for (int i = 0; i < argc; i++)
#ifdef ENABLE_CONVERT_RAW_TO_STDOUT
fWriteToStdOut = true;
if (fWriteToStdOut)
if (!fWriteToStdOut)
if (!fWriteToStdOut)
if (pvBuf)
RTStrmPrintf(g_pStdErr, "Converting image \"%s\" with size %RU64 bytes (%RU64MB) to raw...\n", src.c_str(), cbSize, (cbSize + _1M - 1) / _1M);
if (!fWriteToStdOut)
if (!fWriteToStdOut)
if (!fWriteToStdOut)
static int CmdConvertHardDisk(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
int vrc;
for (int i = 0; i < argc; i++)
RTStrmPrintf(g_pStdErr, "Converting image \"%s\" with size %RU64 bytes (%RU64MB)...\n", src.c_str(), cbSize, (cbSize + _1M - 1) / _1M);
if (pDstDisk)
if (pSrcDisk)
int CmdModUninstall(void)
int rc;
return E_FAIL;
int CmdModInstall(void)
int rc;
return E_FAIL;
bool fEnablePresent = false;
bool fEnable = false;
bool fFlagsPresent = false;
bool fGroupsPresent = false;
bool fDestsPresent = false;
int ch;
switch (ch)
fEnablePresent = true;
fEnable = true;
fEnablePresent = true;
fEnable = false;
fFlagsPresent = true;
fGroupsPresent = true;
fDestsPresent = true;
g_fInternalMode = true;
return CmdModInstall();
return CmdModUninstall();