VirtualBox

source: vbox/trunk/src/VBox/Main/include/MediumImpl.h@ 55355

Last change on this file since 55355 was 55182, checked in by vboxsync, 10 years ago

Main,FE/VBoxManage: Support exporting machines as appliances which have encrypted disks. Because the OVF standard doesn't support encrypted disks so far we always decrypt exported images which requires the password before starting the export proess

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 17.6 KB
Line 
1/* $Id: MediumImpl.h 55182 2015-04-10 14:26:59Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2008-2015 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
19#ifndef ____H_MEDIUMIMPL
20#define ____H_MEDIUMIMPL
21
22#include <VBox/vd.h>
23#include "MediumWrap.h"
24#include "VirtualBoxBase.h"
25#include "AutoCaller.h"
26#include "SecretKeyStore.h"
27class Progress;
28class MediumFormat;
29class MediumLockList;
30
31namespace settings
32{
33 struct Medium;
34}
35
36////////////////////////////////////////////////////////////////////////////////
37
38/**
39 * Medium component class for all media types.
40 */
41class ATL_NO_VTABLE Medium :
42 public MediumWrap
43{
44public:
45 DECLARE_EMPTY_CTOR_DTOR(Medium)
46
47 HRESULT FinalConstruct();
48 void FinalRelease();
49
50 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
51 // have to use a special enum for the overloaded init() below;
52 // can't use AccessMode_T from XIDL because that's mapped to an int
53 // and would be ambiguous
54
55 // public initializer/uninitializer for internal purposes only
56
57 // initializer to create empty medium (VirtualBox::CreateMedium())
58 HRESULT init(VirtualBox *aVirtualBox,
59 const Utf8Str &aFormat,
60 const Utf8Str &aLocation,
61 const Guid &uuidMachineRegistry,
62 const DeviceType_T aDeviceType);
63
64 // initializer for opening existing media
65 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
66 HRESULT init(VirtualBox *aVirtualBox,
67 const Utf8Str &aLocation,
68 HDDOpenMode enOpenMode,
69 bool fForceNewUuid,
70 DeviceType_T aDeviceType);
71
72 // initializer used when loading settings
73 HRESULT initOne(Medium *aParent,
74 DeviceType_T aDeviceType,
75 const Guid &uuidMachineRegistry,
76 const settings::Medium &data,
77 const Utf8Str &strMachineFolder);
78 HRESULT init(VirtualBox *aVirtualBox,
79 Medium *aParent,
80 DeviceType_T aDeviceType,
81 const Guid &uuidMachineRegistry,
82 const settings::Medium &data,
83 const Utf8Str &strMachineFolder,
84 AutoWriteLock &mediaTreeLock);
85
86 // initializer for host floppy/DVD
87 HRESULT init(VirtualBox *aVirtualBox,
88 DeviceType_T aDeviceType,
89 const Utf8Str &aLocation,
90 const Utf8Str &aDescription = Utf8Str::Empty);
91
92 void uninit();
93
94 void i_deparent();
95 void i_setParent(const ComObjPtr<Medium> &pParent);
96
97 // unsafe methods for internal purposes only (ensure there is
98 // a caller and a read lock before calling them!)
99 const ComObjPtr<Medium>& i_getParent() const;
100 const MediaList& i_getChildren() const;
101
102 const Guid& i_getId() const;
103 MediumState_T i_getState() const;
104 MediumVariant_T i_getVariant() const;
105 bool i_isHostDrive() const;
106 const Utf8Str& i_getLocationFull() const;
107 const Utf8Str& i_getFormat() const;
108 const ComObjPtr<MediumFormat> & i_getMediumFormat() const;
109 bool i_isMediumFormatFile() const;
110 uint64_t i_getSize() const;
111 DeviceType_T i_getDeviceType() const;
112 MediumType_T i_getType() const;
113 Utf8Str i_getName();
114
115 /* handles caller/locking itself */
116 bool i_addRegistry(const Guid &id);
117 /* handles caller/locking itself, caller is responsible for tree lock */
118 bool i_addRegistryRecursive(const Guid &id);
119 /* handles caller/locking itself */
120 bool i_removeRegistry(const Guid& id);
121 /* handles caller/locking itself, caller is responsible for tree lock */
122 bool i_removeRegistryRecursive(const Guid& id);
123 bool i_isInRegistry(const Guid& id);
124 bool i_getFirstRegistryMachineId(Guid &uuid) const;
125 void i_markRegistriesModified();
126
127 HRESULT i_setPropertyDirect(const Utf8Str &aName, const Utf8Str &aValue);
128
129 HRESULT i_addBackReference(const Guid &aMachineId,
130 const Guid &aSnapshotId = Guid::Empty);
131 HRESULT i_removeBackReference(const Guid &aMachineId,
132 const Guid &aSnapshotId = Guid::Empty);
133
134
135 const Guid* i_getFirstMachineBackrefId() const;
136 const Guid* i_getAnyMachineBackref() const;
137 const Guid* i_getFirstMachineBackrefSnapshotId() const;
138 size_t i_getMachineBackRefCount() const;
139
140#ifdef DEBUG
141 void i_dumpBackRefs();
142#endif
143
144 HRESULT i_updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
145
146 /* handles caller/locking itself */
147 ComObjPtr<Medium> i_getBase(uint32_t *aLevel = NULL);
148 /* handles caller/locking itself */
149 uint32_t i_getDepth();
150
151 bool i_isReadOnly();
152 void i_updateId(const Guid &id);
153
154 void i_saveSettingsOne(settings::Medium &data,
155 const Utf8Str &strHardDiskFolder);
156 HRESULT i_saveSettings(settings::Medium &data,
157 const Utf8Str &strHardDiskFolder);
158
159 HRESULT i_createMediumLockList(bool fFailIfInaccessible,
160 bool fMediumLockWrite,
161 bool fMediumLockWriteAll,
162 Medium *pToBeParent,
163 MediumLockList &mediumLockList);
164
165 HRESULT i_createDiffStorage(ComObjPtr<Medium> &aTarget,
166 MediumVariant_T aVariant,
167 MediumLockList *pMediumLockList,
168 ComObjPtr<Progress> *aProgress,
169 bool aWait);
170 Utf8Str i_getPreferredDiffFormat();
171
172 HRESULT i_close(AutoCaller &autoCaller);
173 HRESULT i_unlockRead(MediumState_T *aState);
174 HRESULT i_unlockWrite(MediumState_T *aState);
175 HRESULT i_deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait);
176 HRESULT i_markForDeletion();
177 HRESULT i_unmarkForDeletion();
178 HRESULT i_markLockedForDeletion();
179 HRESULT i_unmarkLockedForDeletion();
180
181 HRESULT i_queryPreferredMergeDirection(const ComObjPtr<Medium> &pOther,
182 bool &fMergeForward);
183
184 HRESULT i_prepareMergeTo(const ComObjPtr<Medium> &pTarget,
185 const Guid *aMachineId,
186 const Guid *aSnapshotId,
187 bool fLockMedia,
188 bool &fMergeForward,
189 ComObjPtr<Medium> &pParentForTarget,
190 MediumLockList * &aChildrenToReparent,
191 MediumLockList * &aMediumLockList);
192 HRESULT i_mergeTo(const ComObjPtr<Medium> &pTarget,
193 bool fMergeForward,
194 const ComObjPtr<Medium> &pParentForTarget,
195 MediumLockList *aChildrenToReparent,
196 MediumLockList *aMediumLockList,
197 ComObjPtr<Progress> *aProgress,
198 bool aWait);
199 void i_cancelMergeTo(MediumLockList *aChildrenToReparent,
200 MediumLockList *aMediumLockList);
201
202 HRESULT i_fixParentUuidOfChildren(MediumLockList *pChildrenToReparent);
203
204 HRESULT i_exportFile(const char *aFilename,
205 const ComObjPtr<MediumFormat> &aFormat,
206 MediumVariant_T aVariant,
207 SecretKeyStore *pKeyStore,
208 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
209 const ComObjPtr<Progress> &aProgress);
210 HRESULT i_importFile(const char *aFilename,
211 const ComObjPtr<MediumFormat> &aFormat,
212 MediumVariant_T aVariant,
213 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
214 const ComObjPtr<Medium> &aParent,
215 const ComObjPtr<Progress> &aProgress);
216
217 HRESULT i_cloneToEx(const ComObjPtr<Medium> &aTarget, ULONG aVariant,
218 const ComObjPtr<Medium> &aParent, IProgress **aProgress,
219 uint32_t idxSrcImageSame, uint32_t idxDstImageSame);
220
221 const Utf8Str& i_getKeyId();
222
223private:
224
225 // wrapped IMedium properties
226 HRESULT getId(com::Guid &aId);
227 HRESULT getDescription(com::Utf8Str &aDescription);
228 HRESULT setDescription(const com::Utf8Str &aDescription);
229 HRESULT getState(MediumState_T *aState);
230 HRESULT getVariant(std::vector<MediumVariant_T> &aVariant);
231 HRESULT getLocation(com::Utf8Str &aLocation);
232 HRESULT getName(com::Utf8Str &aName);
233 HRESULT getDeviceType(DeviceType_T *aDeviceType);
234 HRESULT getHostDrive(BOOL *aHostDrive);
235 HRESULT getSize(LONG64 *aSize);
236 HRESULT getFormat(com::Utf8Str &aFormat);
237 HRESULT getMediumFormat(ComPtr<IMediumFormat> &aMediumFormat);
238 HRESULT getType(MediumType_T *aType);
239 HRESULT setType(MediumType_T aType);
240 HRESULT getAllowedTypes(std::vector<MediumType_T> &aAllowedTypes);
241 HRESULT getParent(AutoCaller &autoCaller, ComPtr<IMedium> &aParent);
242 HRESULT getChildren(AutoCaller &autoCaller, std::vector<ComPtr<IMedium> > &aChildren);
243 HRESULT getBase(AutoCaller &autoCaller, ComPtr<IMedium> &aBase);
244 HRESULT getReadOnly(BOOL *aReadOnly);
245 HRESULT getLogicalSize(LONG64 *aLogicalSize);
246 HRESULT getAutoReset(BOOL *aAutoReset);
247 HRESULT setAutoReset(BOOL aAutoReset);
248 HRESULT getLastAccessError(com::Utf8Str &aLastAccessError);
249 HRESULT getMachineIds(std::vector<com::Guid> &aMachineIds);
250
251 // wrapped IMedium methods
252 HRESULT setIds(AutoCaller &aAutoCaller,
253 BOOL aSetImageId,
254 const com::Guid &aImageId,
255 BOOL aSetParentId,
256 const com::Guid &aParentId);
257 HRESULT refreshState(AutoCaller &aAutoCaller,
258 MediumState_T *aState);
259 HRESULT getSnapshotIds(const com::Guid &aMachineId,
260 std::vector<com::Guid> &aSnapshotIds);
261 HRESULT lockRead(ComPtr<IToken> &aToken);
262 HRESULT lockWrite(ComPtr<IToken> &aToken);
263 HRESULT close(AutoCaller &aAutoCaller);
264 HRESULT getProperty(const com::Utf8Str &aName,
265 com::Utf8Str &aValue);
266 HRESULT setProperty(const com::Utf8Str &aName,
267 const com::Utf8Str &aValue);
268 HRESULT getProperties(const com::Utf8Str &aNames,
269 std::vector<com::Utf8Str> &aReturnNames,
270 std::vector<com::Utf8Str> &aReturnValues);
271 HRESULT setProperties(const std::vector<com::Utf8Str> &aNames,
272 const std::vector<com::Utf8Str> &aValues);
273 HRESULT createBaseStorage(LONG64 aLogicalSize,
274 const std::vector<MediumVariant_T> &aVariant,
275 ComPtr<IProgress> &aProgress);
276 HRESULT deleteStorage(ComPtr<IProgress> &aProgress);
277 HRESULT createDiffStorage(const ComPtr<IMedium> &aTarget,
278 const std::vector<MediumVariant_T> &aVariant,
279 ComPtr<IProgress> &aProgress);
280 HRESULT mergeTo(const ComPtr<IMedium> &aTarget,
281 ComPtr<IProgress> &aProgress);
282 HRESULT cloneTo(const ComPtr<IMedium> &aTarget,
283 const std::vector<MediumVariant_T> &aVariant,
284 const ComPtr<IMedium> &aParent,
285 ComPtr<IProgress> &aProgress);
286 HRESULT cloneToBase(const ComPtr<IMedium> &aTarget,
287 const std::vector<MediumVariant_T> &aVariant,
288 ComPtr<IProgress> &aProgress);
289 HRESULT setLocation(const com::Utf8Str &aLocation,
290 ComPtr<IProgress> &aProgress);
291 HRESULT compact(ComPtr<IProgress> &aProgress);
292 HRESULT resize(LONG64 aLogicalSize,
293 ComPtr<IProgress> &aProgress);
294 HRESULT reset(ComPtr<IProgress> &aProgress);
295 HRESULT changeEncryption(const com::Utf8Str &aCurrentPassword, const com::Utf8Str &aCipher,
296 const com::Utf8Str &aNewPassword, const com::Utf8Str &aNewPasswordId,
297 ComPtr<IProgress> &aProgress);
298 HRESULT getEncryptionSettings(com::Utf8Str &aCipher, com::Utf8Str &aPasswordId);
299 HRESULT checkEncryptionPassword(const com::Utf8Str &aPassword);
300
301 // Private internal nmethods
302 HRESULT i_queryInfo(bool fSetImageId, bool fSetParentId, AutoCaller &autoCaller);
303 HRESULT i_canClose();
304 HRESULT i_unregisterWithVirtualBox();
305 HRESULT i_setStateError();
306 HRESULT i_setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
307 HRESULT i_setFormat(const Utf8Str &aFormat);
308 VDTYPE i_convertDeviceType();
309 DeviceType_T i_convertToDeviceType(VDTYPE enmType);
310 Utf8Str i_vdError(int aVRC);
311
312 bool i_isPropertyForFilter(const com::Utf8Str &aName);
313
314 static DECLCALLBACK(void) i_vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
315 const char *pszFormat, va_list va);
316 static DECLCALLBACK(bool) i_vdConfigAreKeysValid(void *pvUser,
317 const char *pszzValid);
318 static DECLCALLBACK(int) i_vdConfigQuerySize(void *pvUser, const char *pszName,
319 size_t *pcbValue);
320 static DECLCALLBACK(int) i_vdConfigQuery(void *pvUser, const char *pszName,
321 char *pszValue, size_t cchValue);
322 static DECLCALLBACK(int) i_vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
323 static DECLCALLBACK(int) i_vdTcpSocketDestroy(VDSOCKET Sock);
324 static DECLCALLBACK(int) i_vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort,
325 RTMSINTERVAL cMillies);
326 static DECLCALLBACK(int) i_vdTcpClientClose(VDSOCKET Sock);
327 static DECLCALLBACK(bool) i_vdTcpIsClientConnected(VDSOCKET Sock);
328 static DECLCALLBACK(int) i_vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
329 static DECLCALLBACK(int) i_vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
330 static DECLCALLBACK(int) i_vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
331 static DECLCALLBACK(int) i_vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
332 static DECLCALLBACK(int) i_vdTcpFlush(VDSOCKET Sock);
333 static DECLCALLBACK(int) i_vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
334 static DECLCALLBACK(int) i_vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
335 static DECLCALLBACK(int) i_vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
336
337 static DECLCALLBACK(bool) i_vdCryptoConfigAreKeysValid(void *pvUser,
338 const char *pszzValid);
339 static DECLCALLBACK(int) i_vdCryptoConfigQuerySize(void *pvUser, const char *pszName,
340 size_t *pcbValue);
341 static DECLCALLBACK(int) i_vdCryptoConfigQuery(void *pvUser, const char *pszName,
342 char *pszValue, size_t cchValue);
343
344 static DECLCALLBACK(int) i_vdCryptoKeyRetain(void *pvUser, const char *pszId,
345 const uint8_t **ppbKey, size_t *pcbKey);
346 static DECLCALLBACK(int) i_vdCryptoKeyRelease(void *pvUser, const char *pszId);
347 static DECLCALLBACK(int) i_vdCryptoKeyStorePasswordRetain(void *pvUser, const char *pszId, const char **ppszPassword);
348 static DECLCALLBACK(int) i_vdCryptoKeyStorePasswordRelease(void *pvUser, const char *pszId);
349 static DECLCALLBACK(int) i_vdCryptoKeyStoreSave(void *pvUser, const void *pvKeyStore, size_t cbKeyStore);
350 static DECLCALLBACK(int) i_vdCryptoKeyStoreReturnParameters(void *pvUser, const char *pszCipher,
351 const uint8_t *pbDek, size_t cbDek);
352
353 class Task;
354 class CreateBaseTask;
355 class CreateDiffTask;
356 class CloneTask;
357 class CompactTask;
358 class ResizeTask;
359 class ResetTask;
360 class DeleteTask;
361 class MergeTask;
362 class ExportTask;
363 class ImportTask;
364 class EncryptTask;
365 friend class Task;
366 friend class CreateBaseTask;
367 friend class CreateDiffTask;
368 friend class CloneTask;
369 friend class CompactTask;
370 friend class ResizeTask;
371 friend class ResetTask;
372 friend class DeleteTask;
373 friend class MergeTask;
374 friend class ExportTask;
375 friend class ImportTask;
376 friend class EncryptTask;
377
378 HRESULT i_startThread(Medium::Task *pTask);
379 HRESULT i_runNow(Medium::Task *pTask);
380
381 HRESULT i_taskCreateBaseHandler(Medium::CreateBaseTask &task);
382 HRESULT i_taskCreateDiffHandler(Medium::CreateDiffTask &task);
383 HRESULT i_taskMergeHandler(Medium::MergeTask &task);
384 HRESULT i_taskCloneHandler(Medium::CloneTask &task);
385 HRESULT i_taskDeleteHandler(Medium::DeleteTask &task);
386 HRESULT i_taskResetHandler(Medium::ResetTask &task);
387 HRESULT i_taskCompactHandler(Medium::CompactTask &task);
388 HRESULT i_taskResizeHandler(Medium::ResizeTask &task);
389 HRESULT i_taskExportHandler(Medium::ExportTask &task);
390 HRESULT i_taskImportHandler(Medium::ImportTask &task);
391 HRESULT i_taskEncryptHandler(Medium::EncryptTask &task);
392
393 struct CryptoFilterSettings;
394 void i_taskEncryptSettingsSetup(CryptoFilterSettings *pSettings, const char *pszCipher,
395 const char *pszKeyStore, const char *pszPassword,
396 bool fCreateKeyStore);
397
398 struct Data; // opaque data struct, defined in MediumImpl.cpp
399 Data *m;
400};
401
402#endif /* ____H_MEDIUMIMPL */
403
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