VirtualBox

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

Last change on this file since 78228 was 77857, checked in by vboxsync, 6 years ago

Main/MediumImpl: Remove the TCP/NET interface implementation and reuse the VD provided one

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