1 | /* $Id: VBoxManage.h 94211 2022-03-13 20:40:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxManage - VirtualBox command-line interface, internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef VBOX_INCLUDED_SRC_VBoxManage_VBoxManage_h
|
---|
19 | #define VBOX_INCLUDED_SRC_VBoxManage_VBoxManage_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #ifndef VBOX_ONLY_DOCS
|
---|
25 | #include <VBox/com/com.h>
|
---|
26 | #include <VBox/com/ptr.h>
|
---|
27 | #include <VBox/com/VirtualBox.h>
|
---|
28 | #include <VBox/com/string.h>
|
---|
29 | #include <VBox/com/array.h>
|
---|
30 | #endif /* !VBOX_ONLY_DOCS */
|
---|
31 |
|
---|
32 | #include <iprt/types.h>
|
---|
33 | #include <iprt/message.h>
|
---|
34 | #include <iprt/stream.h>
|
---|
35 | #include <iprt/getopt.h>
|
---|
36 |
|
---|
37 | #ifndef VBOX_ONLY_DOCS
|
---|
38 | # include "VBoxManageBuiltInHelp.h"
|
---|
39 | # include "PasswordInput.h"
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #ifdef VBOX_WITH_VBOXMANAGE_NLS
|
---|
43 | # include "VirtualBoxTranslator.h"
|
---|
44 | #endif
|
---|
45 |
|
---|
46 |
|
---|
47 | ////////////////////////////////////////////////////////////////////////////////
|
---|
48 | //
|
---|
49 | // definitions
|
---|
50 | //
|
---|
51 | ////////////////////////////////////////////////////////////////////////////////
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * This defines a a_CtxName::tr function that gives the translator context as
|
---|
55 | * well as providing a shorter way to call VirtualBoxTranslator::translate.
|
---|
56 | */
|
---|
57 | #ifdef VBOX_WITH_VBOXMANAGE_NLS
|
---|
58 | # define DECLARE_TRANSLATION_CONTEXT(a_CtxName) \
|
---|
59 | struct a_CtxName \
|
---|
60 | { \
|
---|
61 | static const char *tr(const char *pszSource, const char *pszComment = NULL, const size_t uNum = ~(size_t)0) \
|
---|
62 | { \
|
---|
63 | return VirtualBoxTranslator::translate(NULL, #a_CtxName, pszSource, pszComment, uNum); \
|
---|
64 | } \
|
---|
65 | }
|
---|
66 | #else
|
---|
67 | # define DECLARE_TRANSLATION_CONTEXT(a_CtxName) \
|
---|
68 | struct a_CtxName \
|
---|
69 | { \
|
---|
70 | static const char *tr(const char *pszSource, const char *pszComment = NULL, const size_t uNum = ~(size_t)0) \
|
---|
71 | { \
|
---|
72 | RT_NOREF(pszComment, uNum); \
|
---|
73 | return pszSource; \
|
---|
74 | } \
|
---|
75 | }
|
---|
76 | #endif
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Defines an option with two variants, producing two RTGETOPTDEF entries.
|
---|
80 | *
|
---|
81 | * This is mainly for replacing character-soup option names like
|
---|
82 | * --natlocalhostreachable and --biossystemtimeoffset with more easily parsed
|
---|
83 | * ones, like --nat-localhost-reachable and --bios-system-time-offset, without
|
---|
84 | * removing the legacy name.
|
---|
85 | */
|
---|
86 | #define OPT2(a_pszWordDashWord, a_pszWordSoup, a_chOptOrValue, a_fFlags) \
|
---|
87 | { a_pszWordDashWord, a_chOptOrValue, a_fFlags }, \
|
---|
88 | { a_pszWordSoup, a_chOptOrValue, a_fFlags }
|
---|
89 |
|
---|
90 | /** A single option variant of OPT2 for better looking tables. */
|
---|
91 | #define OPT1(a_pszOption, a_chOptOrValue, a_fFlags) \
|
---|
92 | { a_pszOption, a_chOptOrValue, a_fFlags }
|
---|
93 |
|
---|
94 |
|
---|
95 | /** @name Syntax diagram category, i.e. the command.
|
---|
96 | * @{ */
|
---|
97 | typedef enum
|
---|
98 | {
|
---|
99 | USAGE_INVALID = 0,
|
---|
100 | USAGE_MODIFYMEDIUM,
|
---|
101 | USAGE_CREATEHOSTIF,
|
---|
102 | USAGE_REMOVEHOSTIF,
|
---|
103 | USAGE_I_LOADSYMS,
|
---|
104 | USAGE_I_LOADMAP,
|
---|
105 | USAGE_I_SETHDUUID,
|
---|
106 | USAGE_I_LISTPARTITIONS,
|
---|
107 | USAGE_I_CREATERAWVMDK,
|
---|
108 | USAGE_I_MODINSTALL,
|
---|
109 | USAGE_I_MODUNINSTALL,
|
---|
110 | USAGE_I_RENAMEVMDK,
|
---|
111 | USAGE_I_CONVERTTORAW,
|
---|
112 | USAGE_I_CONVERTHD,
|
---|
113 | USAGE_HOSTONLYIFS,
|
---|
114 | USAGE_I_DUMPHDINFO,
|
---|
115 | USAGE_STORAGEATTACH,
|
---|
116 | USAGE_I_DEBUGLOG,
|
---|
117 | USAGE_I_SETHDPARENTUUID,
|
---|
118 | USAGE_I_PASSWORDHASH,
|
---|
119 | USAGE_I_GUESTSTATS,
|
---|
120 | USAGE_I_REPAIRHD,
|
---|
121 | USAGE_USBDEVSOURCE,
|
---|
122 | /* Insert new entries before this line, but only if it is not an option
|
---|
123 | * to go for the new style command and help handling (see e.g. extpack,
|
---|
124 | * unattend or mediumio. */
|
---|
125 | USAGE_S_NEWCMD = 10000, /**< new style command with no old help support */
|
---|
126 | USAGE_S_ALL,
|
---|
127 | USAGE_S_DUMPOPTS
|
---|
128 | } USAGECATEGORY;
|
---|
129 | /** @} */
|
---|
130 |
|
---|
131 |
|
---|
132 | /** command handler argument */
|
---|
133 | struct HandlerArg
|
---|
134 | {
|
---|
135 | int argc;
|
---|
136 | char **argv;
|
---|
137 |
|
---|
138 | #ifndef VBOX_ONLY_DOCS
|
---|
139 | ComPtr<IVirtualBox> virtualBox;
|
---|
140 | ComPtr<ISession> session;
|
---|
141 | #endif
|
---|
142 | };
|
---|
143 |
|
---|
144 | /** flag whether we're in internal mode */
|
---|
145 | extern bool g_fInternalMode;
|
---|
146 |
|
---|
147 | /** showVMInfo details */
|
---|
148 | typedef enum
|
---|
149 | {
|
---|
150 | VMINFO_NONE = 0,
|
---|
151 | VMINFO_STANDARD = 1, /**< standard details */
|
---|
152 | VMINFO_FULL = 2, /**< both */
|
---|
153 | VMINFO_MACHINEREADABLE = 3, /**< both, and make it machine readable */
|
---|
154 | VMINFO_COMPACT = 4
|
---|
155 | } VMINFO_DETAILS;
|
---|
156 |
|
---|
157 |
|
---|
158 | ////////////////////////////////////////////////////////////////////////////////
|
---|
159 | //
|
---|
160 | // global variables
|
---|
161 | //
|
---|
162 | ////////////////////////////////////////////////////////////////////////////////
|
---|
163 |
|
---|
164 | extern bool g_fDetailedProgress; // in VBoxManage.cpp
|
---|
165 |
|
---|
166 |
|
---|
167 | ////////////////////////////////////////////////////////////////////////////////
|
---|
168 | //
|
---|
169 | // prototypes
|
---|
170 | //
|
---|
171 | ////////////////////////////////////////////////////////////////////////////////
|
---|
172 |
|
---|
173 | /* VBoxManageHelp.cpp */
|
---|
174 |
|
---|
175 | /* Legacy help infrastructure, to be replaced by new one using generated help. */
|
---|
176 | void printUsage(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm);
|
---|
177 | RTEXITCODE errorSyntax(USAGECATEGORY enmCommand, const char *pszFormat, ...);
|
---|
178 | RTEXITCODE errorSyntaxEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, const char *pszFormat, ...);
|
---|
179 | RTEXITCODE errorGetOpt(USAGECATEGORY enmCommand, int rc, union RTGETOPTUNION const *pValueUnion);
|
---|
180 | RTEXITCODE errorGetOptEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, int rc, union RTGETOPTUNION const *pValueUnion);
|
---|
181 |
|
---|
182 | void printUsageInternal(USAGECATEGORY enmCommand, PRTSTREAM pStrm);
|
---|
183 |
|
---|
184 | #ifndef VBOX_ONLY_DOCS
|
---|
185 | void setCurrentCommand(enum HELP_CMD_VBOXMANAGE enmCommand);
|
---|
186 | void setCurrentSubcommand(uint64_t fCurSubcommandScope);
|
---|
187 |
|
---|
188 | void printUsage(PRTSTREAM pStrm);
|
---|
189 | void printHelp(PRTSTREAM pStrm);
|
---|
190 | RTEXITCODE errorNoSubcommand(void);
|
---|
191 | RTEXITCODE errorUnknownSubcommand(const char *pszSubCmd);
|
---|
192 | RTEXITCODE errorTooManyParameters(char **papszArgs);
|
---|
193 | RTEXITCODE errorGetOpt(int rcGetOpt, union RTGETOPTUNION const *pValueUnion);
|
---|
194 | RTEXITCODE errorFetchValue(int iValueNo, const char *pszOption, int rcGetOptFetchValue, union RTGETOPTUNION const *pValueUnion);
|
---|
195 | RTEXITCODE errorSyntax(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
196 | RTEXITCODE errorSyntaxV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
|
---|
197 | HRESULT errorSyntaxHr(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
198 | RTEXITCODE errorArgument(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
199 | HRESULT errorArgumentHr(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
200 |
|
---|
201 | # define SHOW_PROGRESS_NONE 0
|
---|
202 | # define SHOW_PROGRESS_DESC RT_BIT_32(0)
|
---|
203 | # define SHOW_PROGRESS RT_BIT_32(1)
|
---|
204 | # define SHOW_PROGRESS_DETAILS RT_BIT_32(2)
|
---|
205 | HRESULT showProgress(ComPtr<IProgress> progress, uint32_t fFlags = SHOW_PROGRESS);
|
---|
206 | #endif
|
---|
207 |
|
---|
208 | /* VBoxManage.cpp */
|
---|
209 | void showLogo(PRTSTREAM pStrm);
|
---|
210 |
|
---|
211 | #ifndef VBOX_ONLY_DOCS
|
---|
212 | RTEXITCODE handleInternalCommands(HandlerArg *a);
|
---|
213 | #endif /* !VBOX_ONLY_DOCS */
|
---|
214 |
|
---|
215 | /* VBoxManageControlVM.cpp */
|
---|
216 | RTEXITCODE handleControlVM(HandlerArg *a);
|
---|
217 |
|
---|
218 | /* VBoxManageModifyVM.cpp */
|
---|
219 | #ifndef VBOX_ONLY_DOCS
|
---|
220 | void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups);
|
---|
221 | # ifdef VBOX_WITH_RECORDING
|
---|
222 | int parseScreens(const char *pcszScreens, com::SafeArray<BOOL> *pScreens);
|
---|
223 | # endif
|
---|
224 | #endif
|
---|
225 | RTEXITCODE handleModifyVM(HandlerArg *a);
|
---|
226 |
|
---|
227 | /* VBoxManageDebugVM.cpp */
|
---|
228 | RTEXITCODE handleDebugVM(HandlerArg *a);
|
---|
229 |
|
---|
230 | #ifndef VBOX_ONLY_DOCS
|
---|
231 | /* VBoxManageGuestProp.cpp */
|
---|
232 | RTEXITCODE handleGuestProperty(HandlerArg *a);
|
---|
233 |
|
---|
234 | /* VBoxManageGuestCtrl.cpp */
|
---|
235 | RTEXITCODE handleGuestControl(HandlerArg *a);
|
---|
236 |
|
---|
237 | /* VBoxManageVMInfo.cpp */
|
---|
238 | HRESULT showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
|
---|
239 | ComPtr<ISnapshot> ¤tSnapshot,
|
---|
240 | VMINFO_DETAILS details,
|
---|
241 | const com::Utf8Str &prefix = "",
|
---|
242 | int level = 0);
|
---|
243 | RTEXITCODE handleShowVMInfo(HandlerArg *a);
|
---|
244 | HRESULT showVMInfo(ComPtr<IVirtualBox> pVirtualBox,
|
---|
245 | ComPtr<IMachine> pMachine,
|
---|
246 | ComPtr<ISession> pSession,
|
---|
247 | VMINFO_DETAILS details = VMINFO_NONE);
|
---|
248 | const char *machineStateToName(MachineState_T machineState, bool fShort);
|
---|
249 | HRESULT showBandwidthGroups(ComPtr<IBandwidthControl> &bwCtrl,
|
---|
250 | VMINFO_DETAILS details);
|
---|
251 | void outputMachineReadableString(const char *pszName, const char *pszValue, bool fQuoteName = false, bool fNewline = true);
|
---|
252 | void outputMachineReadableString(const char *pszName, com::Bstr const *pbstrValue, bool fQuoteName = false, bool fNewline = true);
|
---|
253 | void outputMachineReadableStringWithFmtName(const char *pszValue, bool fQuoteName, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
254 | void outputMachineReadableStringWithFmtName(com::Bstr const *pbstrValue, bool fQuoteName, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
255 | void outputMachineReadableBool(const char *pszName, BOOL const *pfValue);
|
---|
256 | void outputMachineReadableBool(const char *pszName, bool const *pfValue);
|
---|
257 | void outputMachineReadableULong(const char *pszName, ULONG *uValue);
|
---|
258 | void outputMachineReadableLong64(const char *pszName, LONG64 *uValue);
|
---|
259 |
|
---|
260 | /* VBoxManageList.cpp */
|
---|
261 | RTEXITCODE handleList(HandlerArg *a);
|
---|
262 |
|
---|
263 | /* VBoxManageMetrics.cpp */
|
---|
264 | RTEXITCODE handleMetrics(HandlerArg *a);
|
---|
265 |
|
---|
266 | /* VBoxManageMisc.cpp */
|
---|
267 | RTEXITCODE handleRegisterVM(HandlerArg *a);
|
---|
268 | RTEXITCODE handleUnregisterVM(HandlerArg *a);
|
---|
269 | RTEXITCODE handleCreateVM(HandlerArg *a);
|
---|
270 | RTEXITCODE handleCloneVM(HandlerArg *a);
|
---|
271 | RTEXITCODE handleStartVM(HandlerArg *a);
|
---|
272 | RTEXITCODE handleDiscardState(HandlerArg *a);
|
---|
273 | RTEXITCODE handleAdoptState(HandlerArg *a);
|
---|
274 | RTEXITCODE handleGetExtraData(HandlerArg *a);
|
---|
275 | RTEXITCODE handleSetExtraData(HandlerArg *a);
|
---|
276 | RTEXITCODE handleSetProperty(HandlerArg *a);
|
---|
277 | RTEXITCODE handleSharedFolder(HandlerArg *a);
|
---|
278 | RTEXITCODE handleExtPack(HandlerArg *a);
|
---|
279 | RTEXITCODE handleUnattended(HandlerArg *a);
|
---|
280 | RTEXITCODE handleMoveVM(HandlerArg *a);
|
---|
281 | RTEXITCODE handleCloudProfile(HandlerArg *a);
|
---|
282 |
|
---|
283 | /* VBoxManageDisk.cpp */
|
---|
284 | HRESULT openMedium(HandlerArg *a, const char *pszFilenameOrUuid,
|
---|
285 | DeviceType_T enmDevType, AccessMode_T enmAccessMode,
|
---|
286 | ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen,
|
---|
287 | bool fSilent);
|
---|
288 | RTEXITCODE handleCreateMedium(HandlerArg *a);
|
---|
289 | RTEXITCODE handleModifyMedium(HandlerArg *a);
|
---|
290 | RTEXITCODE handleCloneMedium(HandlerArg *a);
|
---|
291 | RTEXITCODE handleMediumProperty(HandlerArg *a);
|
---|
292 | RTEXITCODE handleEncryptMedium(HandlerArg *a);
|
---|
293 | RTEXITCODE handleCheckMediumPassword(HandlerArg *a);
|
---|
294 | RTEXITCODE handleConvertFromRaw(HandlerArg *a);
|
---|
295 | HRESULT showMediumInfo(const ComPtr<IVirtualBox> &pVirtualBox,
|
---|
296 | const ComPtr<IMedium> &pMedium,
|
---|
297 | const char *pszParentUUID,
|
---|
298 | bool fOptLong);
|
---|
299 | RTEXITCODE handleShowMediumInfo(HandlerArg *a);
|
---|
300 | RTEXITCODE handleCloseMedium(HandlerArg *a);
|
---|
301 | RTEXITCODE handleMediumIO(HandlerArg *a);
|
---|
302 | int parseMediumType(const char *psz, MediumType_T *penmMediumType);
|
---|
303 | int parseBool(const char *psz, bool *pb);
|
---|
304 |
|
---|
305 | /* VBoxManageStorageController.cpp */
|
---|
306 | RTEXITCODE handleStorageAttach(HandlerArg *a);
|
---|
307 | RTEXITCODE handleStorageController(HandlerArg *a);
|
---|
308 |
|
---|
309 | // VBoxManageAppliance.cpp
|
---|
310 | RTEXITCODE handleImportAppliance(HandlerArg *a);
|
---|
311 | RTEXITCODE handleExportAppliance(HandlerArg *a);
|
---|
312 | RTEXITCODE handleSignAppliance(HandlerArg *a);
|
---|
313 |
|
---|
314 | // VBoxManageSnapshot.cpp
|
---|
315 | RTEXITCODE handleSnapshot(HandlerArg *a);
|
---|
316 |
|
---|
317 | /* VBoxManageUSB.cpp */
|
---|
318 | RTEXITCODE handleUSBFilter(HandlerArg *a);
|
---|
319 | RTEXITCODE handleUSBDevSource(HandlerArg *a);
|
---|
320 |
|
---|
321 | /* VBoxManageHostonly.cpp */
|
---|
322 | RTEXITCODE handleHostonlyIf(HandlerArg *a);
|
---|
323 | #ifdef VBOX_WITH_VMNET
|
---|
324 | RTEXITCODE handleHostonlyNet(HandlerArg *a);
|
---|
325 | #endif /* VBOX_WITH_VMNET */
|
---|
326 |
|
---|
327 | /* VBoxManageDHCPServer.cpp */
|
---|
328 | RTEXITCODE handleDHCPServer(HandlerArg *a);
|
---|
329 |
|
---|
330 | /* VBoxManageNATNetwork.cpp */
|
---|
331 | RTEXITCODE handleNATNetwork(HandlerArg *a);
|
---|
332 | RTEXITCODE listNATNetworks(bool fLong, bool fSorted,
|
---|
333 | const ComPtr<IVirtualBox> &pVirtualBox);
|
---|
334 |
|
---|
335 | /* VBoxManageBandwidthControl.cpp */
|
---|
336 | RTEXITCODE handleBandwidthControl(HandlerArg *a);
|
---|
337 |
|
---|
338 | /* VBoxManageCloud.cpp */
|
---|
339 | RTEXITCODE handleCloud(HandlerArg *a);
|
---|
340 |
|
---|
341 | /* VBoxManageCloudMachine.cpp */
|
---|
342 | RTEXITCODE handleCloudMachine(HandlerArg *a, int iFirst,
|
---|
343 | const char *pcszProviderName,
|
---|
344 | const char *pcszProfileName);
|
---|
345 | RTEXITCODE listCloudMachines(HandlerArg *a, int iFirst,
|
---|
346 | const char *pcszProviderName,
|
---|
347 | const char *pcszProfileName);
|
---|
348 | RTEXITCODE handleCloudShowVMInfo(HandlerArg *a, int iFirst,
|
---|
349 | const char *pcszProviderName,
|
---|
350 | const char *pcszProfileName);
|
---|
351 |
|
---|
352 | /* VBoxManageUpdateCheck.cpp */
|
---|
353 | RTEXITCODE handleUpdateCheck(HandlerArg *a);
|
---|
354 |
|
---|
355 | /* VBoxManageModifyNvram.cpp */
|
---|
356 | RTEXITCODE handleModifyNvram(HandlerArg *a);
|
---|
357 |
|
---|
358 | #endif /* !VBOX_ONLY_DOCS */
|
---|
359 |
|
---|
360 | #endif /* !VBOX_INCLUDED_SRC_VBoxManage_VBoxManage_h */
|
---|