VirtualBox

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

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

Main: Rearrange and rename parameters of IMedium::ChangeEncryption

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