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