VirtualBox

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

Last change on this file since 38499 was 38499, checked in by vboxsync, 13 years ago

Main/Machine+Medium: fix medium registry association when attaching a device or mounting a medium, when there is a chain of parent images which are not associated with any media registry, including the necessary locking adjustments

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.0 KB
Line 
1/* $Id: MediumImpl.h 38499 2011-08-19 12:02:55Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2011 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#ifndef ____H_MEDIUMIMPL
21#define ____H_MEDIUMIMPL
22
23#include <VBox/vd.h>
24
25#include "VirtualBoxBase.h"
26#include "MediumLock.h"
27
28class Progress;
29class MediumFormat;
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 VirtualBoxBase,
43 VBOX_SCRIPTABLE_IMPL(IMedium)
44{
45public:
46 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium, IMedium)
47
48 DECLARE_NOT_AGGREGATABLE(Medium)
49
50 DECLARE_PROTECT_FINAL_CONSTRUCT()
51
52 BEGIN_COM_MAP(Medium)
53 VBOX_DEFAULT_INTERFACE_ENTRIES(IMedium)
54 END_COM_MAP()
55
56 DECLARE_EMPTY_CTOR_DTOR(Medium)
57
58 HRESULT FinalConstruct();
59 void FinalRelease();
60
61 enum HDDOpenMode { OpenReadWrite, OpenReadOnly };
62 // have to use a special enum for the overloaded init() below;
63 // can't use AccessMode_T from XIDL because that's mapped to an int
64 // and would be ambiguous
65
66 // public initializer/uninitializer for internal purposes only
67
68 // initializer to create empty medium (VirtualBox::CreateHardDisk())
69 HRESULT init(VirtualBox *aVirtualBox,
70 const Utf8Str &aFormat,
71 const Utf8Str &aLocation,
72 const Guid &uuidMachineRegistry,
73 GuidList *pllRegistriesThatNeedSaving);
74
75 // initializer for opening existing media
76 // (VirtualBox::OpenMedium(); Machine::AttachDevice())
77 HRESULT init(VirtualBox *aVirtualBox,
78 const Utf8Str &aLocation,
79 HDDOpenMode enOpenMode,
80 bool fForceNewUuid,
81 DeviceType_T aDeviceType);
82
83 // initializer used when loading settings
84 HRESULT init(VirtualBox *aVirtualBox,
85 Medium *aParent,
86 DeviceType_T aDeviceType,
87 const Guid &uuidMachineRegistry,
88 const settings::Medium &data,
89 const Utf8Str &strMachineFolder);
90
91 // initializer for host floppy/DVD
92 HRESULT init(VirtualBox *aVirtualBox,
93 DeviceType_T aDeviceType,
94 const Utf8Str &aLocation,
95 const Utf8Str &aDescription = Utf8Str::Empty);
96
97 void uninit();
98
99 void deparent();
100 void setParent(const ComObjPtr<Medium> &pParent);
101
102 // IMedium properties
103 STDMETHOD(COMGETTER(Id))(BSTR *aId);
104 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
105 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
106 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
107 STDMETHOD(COMGETTER(Variant))(ULONG *aVariant);
108 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
109 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
110 STDMETHOD(COMGETTER(Name))(BSTR *aName);
111 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
112 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
113 STDMETHOD(COMGETTER(Size))(LONG64 *aSize);
114 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
115 STDMETHOD(COMGETTER(MediumFormat))(IMediumFormat **aMediumFormat);
116 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
117 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
118 STDMETHOD(COMGETTER(AllowedTypes))(ComSafeArrayOut(MediumType_T, aAllowedTypes));
119 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
120 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
121 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
122 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
123 STDMETHOD(COMGETTER(LogicalSize))(LONG64 *aLogicalSize);
124 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
125 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
126 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
127 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
128
129 // IMedium methods
130 STDMETHOD(SetIDs)(BOOL aSetImageId, IN_BSTR aImageId,
131 BOOL aSetParentId, IN_BSTR aParentId);
132 STDMETHOD(RefreshState)(MediumState_T *aState);
133 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
134 ComSafeArrayOut(BSTR, aSnapshotIds));
135 STDMETHOD(LockRead)(MediumState_T *aState);
136 STDMETHOD(UnlockRead)(MediumState_T *aState);
137 STDMETHOD(LockWrite)(MediumState_T *aState);
138 STDMETHOD(UnlockWrite)(MediumState_T *aState);
139 STDMETHOD(Close)();
140 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
141 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
142 STDMETHOD(GetProperties)(IN_BSTR aNames,
143 ComSafeArrayOut(BSTR, aReturnNames),
144 ComSafeArrayOut(BSTR, aReturnValues));
145 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
146 ComSafeArrayIn(IN_BSTR, aValues));
147 STDMETHOD(CreateBaseStorage)(LONG64 aLogicalSize,
148 ULONG aVariant,
149 IProgress **aProgress);
150 STDMETHOD(DeleteStorage)(IProgress **aProgress);
151 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
152 ULONG aVariant,
153 IProgress **aProgress);
154 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
155 STDMETHOD(CloneTo)(IMedium *aTarget, ULONG aVariant,
156 IMedium *aParent, IProgress **aProgress);
157 STDMETHOD(Compact)(IProgress **aProgress);
158 STDMETHOD(Resize)(LONG64 aLogicalSize, IProgress **aProgress);
159 STDMETHOD(Reset)(IProgress **aProgress);
160
161 // unsafe methods for internal purposes only (ensure there is
162 // a caller and a read lock before calling them!)
163 const ComObjPtr<Medium>& getParent() const;
164 const MediaList& getChildren() const;
165
166 const Guid& getId() const;
167 MediumState_T getState() const;
168 MediumVariant_T getVariant() const;
169 bool isHostDrive() const;
170 const Utf8Str& getLocationFull() const;
171 const Utf8Str& getFormat() const;
172 const ComObjPtr<MediumFormat> & getMediumFormat() const;
173 bool isMediumFormatFile() const;
174 uint64_t getSize() const;
175 DeviceType_T getDeviceType() const;
176 MediumType_T getType() const;
177 Utf8Str getName();
178
179 /* handles caller/locking itself */
180 bool addRegistry(const Guid& id, bool fRecurse);
181 /* handles caller/locking itself */
182 bool removeRegistry(const Guid& id, bool fRecurse);
183 bool isInRegistry(const Guid& id);
184 bool getFirstRegistryMachineId(Guid &uuid) const;
185 HRESULT addToRegistryIDList(GuidList &llRegistryIDs);
186
187 HRESULT addBackReference(const Guid &aMachineId,
188 const Guid &aSnapshotId = Guid::Empty);
189 HRESULT removeBackReference(const Guid &aMachineId,
190 const Guid &aSnapshotId = Guid::Empty);
191
192 const Guid* getFirstMachineBackrefId() const;
193 const Guid* getAnyMachineBackref() const;
194 const Guid* getFirstMachineBackrefSnapshotId() const;
195 size_t getMachineBackRefCount() const;
196
197#ifdef DEBUG
198 void dumpBackRefs();
199#endif
200
201 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
202
203 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
204
205 bool isReadOnly();
206 void updateId(const Guid &id);
207
208 HRESULT saveSettings(settings::Medium &data,
209 const Utf8Str &strHardDiskFolder);
210
211 HRESULT createMediumLockList(bool fFailIfInaccessible,
212 bool fMediumLockWrite,
213 Medium *pToBeParent,
214 MediumLockList &mediumLockList);
215
216 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
217 MediumVariant_T aVariant,
218 MediumLockList *pMediumLockList,
219 ComObjPtr<Progress> *aProgress,
220 bool aWait,
221 GuidList *pllRegistriesThatNeedSaving);
222 Utf8Str getPreferredDiffFormat();
223
224 HRESULT close(GuidList *pllRegistriesThatNeedSaving, AutoCaller &autoCaller);
225 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, GuidList *pllRegistriesThatNeedSaving);
226 HRESULT markForDeletion();
227 HRESULT unmarkForDeletion();
228 HRESULT markLockedForDeletion();
229 HRESULT unmarkLockedForDeletion();
230
231 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
232 const Guid *aMachineId,
233 const Guid *aSnapshotId,
234 bool fLockMedia,
235 bool &fMergeForward,
236 ComObjPtr<Medium> &pParentForTarget,
237 MediaList &aChildrenToReparent,
238 MediumLockList * &aMediumLockList);
239 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
240 bool fMergeForward,
241 const ComObjPtr<Medium> &pParentForTarget,
242 const MediaList &aChildrenToReparent,
243 MediumLockList *aMediumLockList,
244 ComObjPtr<Progress> *aProgress,
245 bool aWait,
246 GuidList *pllRegistriesThatNeedSaving);
247 void cancelMergeTo(const MediaList &aChildrenToReparent,
248 MediumLockList *aMediumLockList);
249
250 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
251
252 HRESULT exportFile(const char *aFilename,
253 const ComObjPtr<MediumFormat> &aFormat,
254 MediumVariant_T aVariant,
255 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
256 const ComObjPtr<Progress> &aProgress);
257 HRESULT importFile(const char *aFilename,
258 const ComObjPtr<MediumFormat> &aFormat,
259 MediumVariant_T aVariant,
260 PVDINTERFACEIO aVDImageIOIf, void *aVDImageIOUser,
261 const ComObjPtr<Medium> &aParent,
262 const ComObjPtr<Progress> &aProgress);
263
264 HRESULT cloneToEx(const ComObjPtr<Medium> &aTarget, ULONG aVariant,
265 const ComObjPtr<Medium> &aParent, IProgress **aProgress,
266 uint32_t idxSrcImageSame, uint32_t idxDstImageSame);
267
268private:
269
270 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
271
272 HRESULT canClose();
273 HRESULT unregisterWithVirtualBox(GuidList *pllRegistriesThatNeedSaving);
274
275 HRESULT setStateError();
276
277 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
278 HRESULT setFormat(const Utf8Str &aFormat);
279
280 VDTYPE convertDeviceType();
281 DeviceType_T convertToDeviceType(VDTYPE enmType);
282
283 Utf8Str vdError(int aVRC);
284
285 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
286 const char *pszFormat, va_list va);
287
288 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
289 const char *pszzValid);
290 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
291 size_t *pcbValue);
292 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
293 char *pszValue, size_t cchValue);
294
295 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
296 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
297 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
298 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
299 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
300 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
301 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
302 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
303 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
304 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
305 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
306 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
307 static DECLCALLBACK(int) vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
308
309 class Task;
310 class CreateBaseTask;
311 class CreateDiffTask;
312 class CloneTask;
313 class CompactTask;
314 class ResizeTask;
315 class ResetTask;
316 class DeleteTask;
317 class MergeTask;
318 class ExportTask;
319 class ImportTask;
320 friend class Task;
321 friend class CreateBaseTask;
322 friend class CreateDiffTask;
323 friend class CloneTask;
324 friend class CompactTask;
325 friend class ResizeTask;
326 friend class ResetTask;
327 friend class DeleteTask;
328 friend class MergeTask;
329 friend class ExportTask;
330 friend class ImportTask;
331
332 HRESULT startThread(Medium::Task *pTask);
333 HRESULT runNow(Medium::Task *pTask, GuidList *pllRegistriesThatNeedSaving);
334
335 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
336 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
337 HRESULT taskMergeHandler(Medium::MergeTask &task);
338 HRESULT taskCloneHandler(Medium::CloneTask &task);
339 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
340 HRESULT taskResetHandler(Medium::ResetTask &task);
341 HRESULT taskCompactHandler(Medium::CompactTask &task);
342 HRESULT taskResizeHandler(Medium::ResizeTask &task);
343 HRESULT taskExportHandler(Medium::ExportTask &task);
344 HRESULT taskImportHandler(Medium::ImportTask &task);
345
346 struct Data; // opaque data struct, defined in MediumImpl.cpp
347 Data *m;
348};
349
350#endif /* ____H_MEDIUMIMPL */
351
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