1 | /* $Id: VBoxManage.h 94210 2022-03-13 20:25:00Z 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_NATNETWORK,
|
---|
122 | USAGE_USBDEVSOURCE,
|
---|
123 | /* Insert new entries before this line, but only if it is not an option
|
---|
124 | * to go for the new style command and help handling (see e.g. extpack,
|
---|
125 | * unattend or mediumio. */
|
---|
126 | USAGE_S_NEWCMD = 10000, /**< new style command with no old help support */
|
---|
127 | USAGE_S_ALL,
|
---|
128 | USAGE_S_DUMPOPTS
|
---|
129 | } USAGECATEGORY;
|
---|
130 | /** @} */
|
---|
131 |
|
---|
132 |
|
---|
133 | /** command handler argument */
|
---|
134 | struct HandlerArg
|
---|
135 | {
|
---|
136 | int argc;
|
---|
137 | char **argv;
|
---|
138 |
|
---|
139 | #ifndef VBOX_ONLY_DOCS
|
---|
140 | ComPtr<IVirtualBox> virtualBox;
|
---|
141 | ComPtr<ISession> session;
|
---|
142 | #endif
|
---|
143 | };
|
---|
144 |
|
---|
145 | /** flag whether we're in internal mode */
|
---|
146 | extern bool g_fInternalMode;
|
---|
147 |
|
---|
148 | /** showVMInfo details */
|
---|
149 | typedef enum
|
---|
150 | {
|
---|
151 | VMINFO_NONE = 0,
|
---|
152 | VMINFO_STANDARD = 1, /**< standard details */
|
---|
153 | VMINFO_FULL = 2, /**< both */
|
---|
154 | VMINFO_MACHINEREADABLE = 3, /**< both, and make it machine readable */
|
---|
155 | VMINFO_COMPACT = 4
|
---|
156 | } VMINFO_DETAILS;
|
---|
157 |
|
---|
158 |
|
---|
159 | ////////////////////////////////////////////////////////////////////////////////
|
---|
160 | //
|
---|
161 | // global variables
|
---|
162 | //
|
---|
163 | ////////////////////////////////////////////////////////////////////////////////
|
---|
164 |
|
---|
165 | extern bool g_fDetailedProgress; // in VBoxManage.cpp
|
---|
166 |
|
---|
167 |
|
---|
168 | ////////////////////////////////////////////////////////////////////////////////
|
---|
169 | //
|
---|
170 | // prototypes
|
---|
171 | //
|
---|
172 | ////////////////////////////////////////////////////////////////////////////////
|
---|
173 |
|
---|
174 | /* VBoxManageHelp.cpp */
|
---|
175 |
|
---|
176 | /* Legacy help infrastructure, to be replaced by new one using generated help. */
|
---|
177 | void printUsage(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, PRTSTREAM pStrm);
|
---|
178 | RTEXITCODE errorSyntax(USAGECATEGORY enmCommand, const char *pszFormat, ...);
|
---|
179 | RTEXITCODE errorSyntaxEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, const char *pszFormat, ...);
|
---|
180 | RTEXITCODE errorGetOpt(USAGECATEGORY enmCommand, int rc, union RTGETOPTUNION const *pValueUnion);
|
---|
181 | RTEXITCODE errorGetOptEx(USAGECATEGORY enmCommand, uint64_t fSubcommandScope, int rc, union RTGETOPTUNION const *pValueUnion);
|
---|
182 |
|
---|
183 | void printUsageInternal(USAGECATEGORY enmCommand, PRTSTREAM pStrm);
|
---|
184 |
|
---|
185 | #ifndef VBOX_ONLY_DOCS
|
---|
186 | void setCurrentCommand(enum HELP_CMD_VBOXMANAGE enmCommand);
|
---|
187 | void setCurrentSubcommand(uint64_t fCurSubcommandScope);
|
---|
188 |
|
---|
189 | void printUsage(PRTSTREAM pStrm);
|
---|
190 | void printHelp(PRTSTREAM pStrm);
|
---|
191 | RTEXITCODE errorNoSubcommand(void);
|
---|
192 | RTEXITCODE errorUnknownSubcommand(const char *pszSubCmd);
|
---|
193 | RTEXITCODE errorTooManyParameters(char **papszArgs);
|
---|
194 | RTEXITCODE errorGetOpt(int rcGetOpt, union RTGETOPTUNION const *pValueUnion);
|
---|
195 | RTEXITCODE errorFetchValue(int iValueNo, const char *pszOption, int rcGetOptFetchValue, union RTGETOPTUNION const *pValueUnion);
|
---|
196 | RTEXITCODE errorSyntax(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
197 | RTEXITCODE errorSyntaxV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
|
---|
198 | HRESULT errorSyntaxHr(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
199 | RTEXITCODE errorArgument(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
200 | HRESULT errorArgumentHr(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
|
---|
201 |
|
---|
202 | # define SHOW_PROGRESS_NONE 0
|
---|
203 | # define SHOW_PROGRESS_DESC RT_BIT_32(0)
|
---|
204 | # define SHOW_PROGRESS RT_BIT_32(1)
|
---|
205 | # define SHOW_PROGRESS_DETAILS RT_BIT_32(2)
|
---|
206 | HRESULT showProgress(ComPtr<IProgress> progress, uint32_t fFlags = SHOW_PROGRESS);
|
---|
207 | #endif
|
---|
208 |
|
---|
209 | /* VBoxManage.cpp */
|
---|
210 | void showLogo(PRTSTREAM pStrm);
|
---|
211 |
|
---|
212 | #ifndef VBOX_ONLY_DOCS
|
---|
213 | RTEXITCODE handleInternalCommands(HandlerArg *a);
|
---|
214 | #endif /* !VBOX_ONLY_DOCS */
|
---|
215 |
|
---|
216 | /* VBoxManageControlVM.cpp */
|
---|
217 | RTEXITCODE handleControlVM(HandlerArg *a);
|
---|
218 |
|
---|
219 | /* VBoxManageModifyVM.cpp */
|
---|
220 | #ifndef VBOX_ONLY_DOCS
|
---|
221 | void parseGroups(const char *pcszGroups, com::SafeArray<BSTR> *pGroups);
|
---|
222 | # ifdef VBOX_WITH_RECORDING
|
---|
223 | int parseScreens(const char *pcszScreens, com::SafeArray<BOOL> *pScreens);
|
---|
224 | # endif
|
---|
225 | #endif
|
---|
226 | RTEXITCODE handleModifyVM(HandlerArg *a);
|
---|
227 |
|
---|
228 | /* VBoxManageDebugVM.cpp */
|
---|
229 | RTEXITCODE handleDebugVM(HandlerArg *a);
|
---|
230 |
|
---|
231 | #ifndef VBOX_ONLY_DOCS
|
---|
232 | /* VBoxManageGuestProp.cpp */
|
---|
233 | RTEXITCODE handleGuestProperty(HandlerArg *a);
|
---|
234 |
|
---|
235 | /* VBoxManageGuestCtrl.cpp */
|
---|
236 | RTEXITCODE handleGuestControl(HandlerArg *a);
|
---|
237 |
|
---|
238 | /* VBoxManageVMInfo.cpp */
|
---|
239 | HRESULT showSnapshots(ComPtr<ISnapshot> &rootSnapshot,
|
---|
240 | ComPtr<ISnapshot> ¤tSnapshot,
|
---|
241 | VMINFO_DETAILS details,
|
---|
242 | const com::Utf8Str &prefix = "",
|
---|
243 | int level = 0);
|
---|
244 | RTEXITCODE handleShowVMInfo(HandlerArg *a);
|
---|
245 | HRESULT showVMInfo(ComPtr<IVirtualBox> pVirtualBox,
|
---|
246 | ComPtr<IMachine> pMachine,
|
---|
247 | ComPtr<ISession> pSession,
|
---|
248 | VMINFO_DETAILS details = VMINFO_NONE);
|
---|
249 | const char *machineStateToName(MachineState_T machineState, bool fShort);
|
---|
250 | HRESULT showBandwidthGroups(ComPtr<IBandwidthControl> &bwCtrl,
|
---|
251 | VMINFO_DETAILS details);
|
---|
252 | void outputMachineReadableString(const char *pszName, const char *pszValue, bool fQuoteName = false, bool fNewline = true);
|
---|
253 | void outputMachineReadableString(const char *pszName, com::Bstr const *pbstrValue, bool fQuoteName = false, bool fNewline = true);
|
---|
254 | void outputMachineReadableStringWithFmtName(const char *pszValue, bool fQuoteName, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
255 | void outputMachineReadableStringWithFmtName(com::Bstr const *pbstrValue, bool fQuoteName, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(3, 4);
|
---|
256 | void outputMachineReadableBool(const char *pszName, BOOL const *pfValue);
|
---|
257 | void outputMachineReadableBool(const char *pszName, bool const *pfValue);
|
---|
258 | void outputMachineReadableULong(const char *pszName, ULONG *uValue);
|
---|
259 | void outputMachineReadableLong64(const char *pszName, LONG64 *uValue);
|
---|
260 |
|
---|
261 | /* VBoxManageList.cpp */
|
---|
262 | RTEXITCODE handleList(HandlerArg *a);
|
---|
263 |
|
---|
264 | /* VBoxManageMetrics.cpp */
|
---|
265 | RTEXITCODE handleMetrics(HandlerArg *a);
|
---|
266 |
|
---|
267 | /* VBoxManageMisc.cpp */
|
---|
268 | RTEXITCODE handleRegisterVM(HandlerArg *a);
|
---|
269 | RTEXITCODE handleUnregisterVM(HandlerArg *a);
|
---|
270 | RTEXITCODE handleCreateVM(HandlerArg *a);
|
---|
271 | RTEXITCODE handleCloneVM(HandlerArg *a);
|
---|
272 | RTEXITCODE handleStartVM(HandlerArg *a);
|
---|
273 | RTEXITCODE handleDiscardState(HandlerArg *a);
|
---|
274 | RTEXITCODE handleAdoptState(HandlerArg *a);
|
---|
275 | RTEXITCODE handleGetExtraData(HandlerArg *a);
|
---|
276 | RTEXITCODE handleSetExtraData(HandlerArg *a);
|
---|
277 | RTEXITCODE handleSetProperty(HandlerArg *a);
|
---|
278 | RTEXITCODE handleSharedFolder(HandlerArg *a);
|
---|
279 | RTEXITCODE handleExtPack(HandlerArg *a);
|
---|
280 | RTEXITCODE handleUnattended(HandlerArg *a);
|
---|
281 | RTEXITCODE handleMoveVM(HandlerArg *a);
|
---|
282 | RTEXITCODE handleCloudProfile(HandlerArg *a);
|
---|
283 |
|
---|
284 | /* VBoxManageDisk.cpp */
|
---|
285 | HRESULT openMedium(HandlerArg *a, const char *pszFilenameOrUuid,
|
---|
286 | DeviceType_T enmDevType, AccessMode_T enmAccessMode,
|
---|
287 | ComPtr<IMedium> &pMedium, bool fForceNewUuidOnOpen,
|
---|
288 | bool fSilent);
|
---|
289 | RTEXITCODE handleCreateMedium(HandlerArg *a);
|
---|
290 | RTEXITCODE handleModifyMedium(HandlerArg *a);
|
---|
291 | RTEXITCODE handleCloneMedium(HandlerArg *a);
|
---|
292 | RTEXITCODE handleMediumProperty(HandlerArg *a);
|
---|
293 | RTEXITCODE handleEncryptMedium(HandlerArg *a);
|
---|
294 | RTEXITCODE handleCheckMediumPassword(HandlerArg *a);
|
---|
295 | RTEXITCODE handleConvertFromRaw(HandlerArg *a);
|
---|
296 | HRESULT showMediumInfo(const ComPtr<IVirtualBox> &pVirtualBox,
|
---|
297 | const ComPtr<IMedium> &pMedium,
|
---|
298 | const char *pszParentUUID,
|
---|
299 | bool fOptLong);
|
---|
300 | RTEXITCODE handleShowMediumInfo(HandlerArg *a);
|
---|
301 | RTEXITCODE handleCloseMedium(HandlerArg *a);
|
---|
302 | RTEXITCODE handleMediumIO(HandlerArg *a);
|
---|
303 | int parseMediumType(const char *psz, MediumType_T *penmMediumType);
|
---|
304 | int parseBool(const char *psz, bool *pb);
|
---|
305 |
|
---|
306 | /* VBoxManageStorageController.cpp */
|
---|
307 | RTEXITCODE handleStorageAttach(HandlerArg *a);
|
---|
308 | RTEXITCODE handleStorageController(HandlerArg *a);
|
---|
309 |
|
---|
310 | // VBoxManageAppliance.cpp
|
---|
311 | RTEXITCODE handleImportAppliance(HandlerArg *a);
|
---|
312 | RTEXITCODE handleExportAppliance(HandlerArg *a);
|
---|
313 | RTEXITCODE handleSignAppliance(HandlerArg *a);
|
---|
314 |
|
---|
315 | // VBoxManageSnapshot.cpp
|
---|
316 | RTEXITCODE handleSnapshot(HandlerArg *a);
|
---|
317 |
|
---|
318 | /* VBoxManageUSB.cpp */
|
---|
319 | RTEXITCODE handleUSBFilter(HandlerArg *a);
|
---|
320 | RTEXITCODE handleUSBDevSource(HandlerArg *a);
|
---|
321 |
|
---|
322 | /* VBoxManageHostonly.cpp */
|
---|
323 | RTEXITCODE handleHostonlyIf(HandlerArg *a);
|
---|
324 | #ifdef VBOX_WITH_VMNET
|
---|
325 | RTEXITCODE handleHostonlyNet(HandlerArg *a);
|
---|
326 | #endif /* VBOX_WITH_VMNET */
|
---|
327 |
|
---|
328 | /* VBoxManageDHCPServer.cpp */
|
---|
329 | RTEXITCODE handleDHCPServer(HandlerArg *a);
|
---|
330 |
|
---|
331 | /* VBoxManageNATNetwork.cpp */
|
---|
332 | RTEXITCODE handleNATNetwork(HandlerArg *a);
|
---|
333 | RTEXITCODE listNATNetworks(bool fLong, bool fSorted,
|
---|
334 | const ComPtr<IVirtualBox> &pVirtualBox);
|
---|
335 |
|
---|
336 | /* VBoxManageBandwidthControl.cpp */
|
---|
337 | RTEXITCODE handleBandwidthControl(HandlerArg *a);
|
---|
338 |
|
---|
339 | /* VBoxManageCloud.cpp */
|
---|
340 | RTEXITCODE handleCloud(HandlerArg *a);
|
---|
341 |
|
---|
342 | /* VBoxManageCloudMachine.cpp */
|
---|
343 | RTEXITCODE handleCloudMachine(HandlerArg *a, int iFirst,
|
---|
344 | const char *pcszProviderName,
|
---|
345 | const char *pcszProfileName);
|
---|
346 | RTEXITCODE listCloudMachines(HandlerArg *a, int iFirst,
|
---|
347 | const char *pcszProviderName,
|
---|
348 | const char *pcszProfileName);
|
---|
349 | RTEXITCODE handleCloudShowVMInfo(HandlerArg *a, int iFirst,
|
---|
350 | const char *pcszProviderName,
|
---|
351 | const char *pcszProfileName);
|
---|
352 |
|
---|
353 | /* VBoxManageUpdateCheck.cpp */
|
---|
354 | RTEXITCODE handleUpdateCheck(HandlerArg *a);
|
---|
355 |
|
---|
356 | /* VBoxManageModifyNvram.cpp */
|
---|
357 | RTEXITCODE handleModifyNvram(HandlerArg *a);
|
---|
358 |
|
---|
359 | #endif /* !VBOX_ONLY_DOCS */
|
---|
360 |
|
---|
361 | #endif /* !VBOX_INCLUDED_SRC_VBoxManage_VBoxManage_h */
|
---|