VirtualBox

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

最後變更 在這個檔案從35903是 35903,由 vboxsync 提交於 14 年 前

Main: before unregistering a machine, move media shared with another machine to that machine's media registry to prevent that machine from becoming inaccessible

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 13.4 KB
 
1/* $Id: MediumImpl.h 35903 2011-02-08 16:46:25Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2008-2010 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.alldomusa.eu.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 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(Parent))(IMedium **aParent);
118 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
119 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
120 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
121 STDMETHOD(COMGETTER(LogicalSize))(LONG64 *aLogicalSize);
122 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
123 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
124 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
125 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
126
127 // IMedium methods
128 STDMETHOD(SetIDs)(BOOL aSetImageId, IN_BSTR aImageId,
129 BOOL aSetParentId, IN_BSTR aParentId);
130 STDMETHOD(RefreshState)(MediumState_T *aState);
131 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
132 ComSafeArrayOut(BSTR, aSnapshotIds));
133 STDMETHOD(LockRead)(MediumState_T *aState);
134 STDMETHOD(UnlockRead)(MediumState_T *aState);
135 STDMETHOD(LockWrite)(MediumState_T *aState);
136 STDMETHOD(UnlockWrite)(MediumState_T *aState);
137 STDMETHOD(Close)();
138 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
139 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
140 STDMETHOD(GetProperties)(IN_BSTR aNames,
141 ComSafeArrayOut(BSTR, aReturnNames),
142 ComSafeArrayOut(BSTR, aReturnValues));
143 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
144 ComSafeArrayIn(IN_BSTR, aValues));
145 STDMETHOD(CreateBaseStorage)(LONG64 aLogicalSize,
146 ULONG aVariant,
147 IProgress **aProgress);
148 STDMETHOD(DeleteStorage)(IProgress **aProgress);
149 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
150 ULONG aVariant,
151 IProgress **aProgress);
152 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
153 STDMETHOD(CloneTo)(IMedium *aTarget, ULONG aVariant,
154 IMedium *aParent, IProgress **aProgress);
155 STDMETHOD(Compact)(IProgress **aProgress);
156 STDMETHOD(Resize)(LONG64 aLogicalSize, IProgress **aProgress);
157 STDMETHOD(Reset)(IProgress **aProgress);
158
159 // unsafe methods for internal purposes only (ensure there is
160 // a caller and a read lock before calling them!)
161 const ComObjPtr<Medium>& getParent() const;
162 const MediaList& getChildren() const;
163
164 const Guid& getId() const;
165 MediumState_T getState() const;
166 MediumVariant_T getVariant() const;
167 bool isHostDrive() const;
168 const Utf8Str& getLocationFull() const;
169 const Utf8Str& getFormat() const;
170 const ComObjPtr<MediumFormat> & getMediumFormat() const;
171 bool isMediumFormatFile() const;
172 uint64_t getSize() const;
173 DeviceType_T getDeviceType() const;
174 MediumType_T getType() const;
175 Utf8Str getName();
176
177 bool addRegistry(const Guid& id);
178 bool removeRegistry(const Guid& id);
179 bool isInRegistry(const Guid& id);
180 bool getFirstRegistryMachineId(Guid &uuid) const;
181 HRESULT addToRegistryIDList(GuidList &llRegistryIDs);
182
183 HRESULT addBackReference(const Guid &aMachineId,
184 const Guid &aSnapshotId = Guid::Empty);
185 HRESULT removeBackReference(const Guid &aMachineId,
186 const Guid &aSnapshotId = Guid::Empty);
187
188 const Guid* getFirstMachineBackrefId() const;
189 const Guid* getFirstMachineBackrefSnapshotId() const;
190
191#ifdef DEBUG
192 void dumpBackRefs();
193#endif
194
195 HRESULT updatePath(const Utf8Str &strOldPath, const Utf8Str &strNewPath);
196
197 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
198
199 bool isReadOnly();
200
201 HRESULT saveSettings(settings::Medium &data,
202 const Utf8Str &strHardDiskFolder);
203
204 HRESULT createMediumLockList(bool fFailIfInaccessible,
205 bool fMediumLockWrite,
206 Medium *pToBeParent,
207 MediumLockList &mediumLockList);
208
209 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
210 MediumVariant_T aVariant,
211 MediumLockList *pMediumLockList,
212 ComObjPtr<Progress> *aProgress,
213 bool aWait,
214 GuidList *pllRegistriesThatNeedSaving);
215 Utf8Str getPreferredDiffFormat();
216
217 HRESULT close(GuidList *pllRegistriesThatNeedSaving, AutoCaller &autoCaller);
218 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, GuidList *pllRegistriesThatNeedSaving);
219 HRESULT markForDeletion();
220 HRESULT unmarkForDeletion();
221 HRESULT markLockedForDeletion();
222 HRESULT unmarkLockedForDeletion();
223
224 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
225 const Guid *aMachineId,
226 const Guid *aSnapshotId,
227 bool fLockMedia,
228 bool &fMergeForward,
229 ComObjPtr<Medium> &pParentForTarget,
230 MediaList &aChildrenToReparent,
231 MediumLockList * &aMediumLockList);
232 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
233 bool fMergeForward,
234 const ComObjPtr<Medium> &pParentForTarget,
235 const MediaList &aChildrenToReparent,
236 MediumLockList *aMediumLockList,
237 ComObjPtr<Progress> *aProgress,
238 bool aWait,
239 GuidList *pllRegistriesThatNeedSaving);
240 void cancelMergeTo(const MediaList &aChildrenToReparent,
241 MediumLockList *aMediumLockList);
242
243 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
244
245 HRESULT exportFile(const char *aFilename,
246 const ComObjPtr<MediumFormat> &aFormat,
247 MediumVariant_T aVariant,
248 void *aVDImageIOCallbacks, void *aVDImageIOUser,
249 const ComObjPtr<Progress> &aProgress);
250 HRESULT importFile(const char *aFilename,
251 const ComObjPtr<MediumFormat> &aFormat,
252 MediumVariant_T aVariant,
253 void *aVDImageIOCallbacks, void *aVDImageIOUser,
254 const ComObjPtr<Medium> &aParent,
255 const ComObjPtr<Progress> &aProgress);
256
257private:
258
259 HRESULT queryInfo(bool fSetImageId, bool fSetParentId);
260
261 HRESULT canClose();
262 HRESULT unregisterWithVirtualBox(GuidList *pllRegistriesThatNeedSaving);
263
264 HRESULT setStateError();
265
266 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str::Empty);
267 HRESULT setFormat(const Utf8Str &aFormat);
268
269 VDTYPE convertDeviceType();
270 DeviceType_T convertToDeviceType(VDTYPE enmType);
271
272 Utf8Str vdError(int aVRC);
273
274 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
275 const char *pszFormat, va_list va);
276
277 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
278 const char *pszzValid);
279 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
280 size_t *pcbValue);
281 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
282 char *pszValue, size_t cchValue);
283
284 static DECLCALLBACK(int) vdTcpSocketCreate(uint32_t fFlags, PVDSOCKET pSock);
285 static DECLCALLBACK(int) vdTcpSocketDestroy(VDSOCKET Sock);
286 static DECLCALLBACK(int) vdTcpClientConnect(VDSOCKET Sock, const char *pszAddress, uint32_t uPort);
287 static DECLCALLBACK(int) vdTcpClientClose(VDSOCKET Sock);
288 static DECLCALLBACK(bool) vdTcpIsClientConnected(VDSOCKET Sock);
289 static DECLCALLBACK(int) vdTcpSelectOne(VDSOCKET Sock, RTMSINTERVAL cMillies);
290 static DECLCALLBACK(int) vdTcpRead(VDSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
291 static DECLCALLBACK(int) vdTcpWrite(VDSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
292 static DECLCALLBACK(int) vdTcpSgWrite(VDSOCKET Sock, PCRTSGBUF pSgBuf);
293 static DECLCALLBACK(int) vdTcpFlush(VDSOCKET Sock);
294 static DECLCALLBACK(int) vdTcpSetSendCoalescing(VDSOCKET Sock, bool fEnable);
295 static DECLCALLBACK(int) vdTcpGetLocalAddress(VDSOCKET Sock, PRTNETADDR pAddr);
296 static DECLCALLBACK(int) vdTcpGetPeerAddress(VDSOCKET Sock, PRTNETADDR pAddr);
297
298 class Task;
299 class CreateBaseTask;
300 class CreateDiffTask;
301 class CloneTask;
302 class CompactTask;
303 class ResizeTask;
304 class ResetTask;
305 class DeleteTask;
306 class MergeTask;
307 class ExportTask;
308 class ImportTask;
309 friend class Task;
310 friend class CreateBaseTask;
311 friend class CreateDiffTask;
312 friend class CloneTask;
313 friend class CompactTask;
314 friend class ResizeTask;
315 friend class ResetTask;
316 friend class DeleteTask;
317 friend class MergeTask;
318 friend class ExportTask;
319 friend class ImportTask;
320
321 HRESULT startThread(Medium::Task *pTask);
322 HRESULT runNow(Medium::Task *pTask, GuidList *pllRegistriesThatNeedSaving);
323
324 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
325 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
326 HRESULT taskMergeHandler(Medium::MergeTask &task);
327 HRESULT taskCloneHandler(Medium::CloneTask &task);
328 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
329 HRESULT taskResetHandler(Medium::ResetTask &task);
330 HRESULT taskCompactHandler(Medium::CompactTask &task);
331 HRESULT taskResizeHandler(Medium::ResizeTask &task);
332 HRESULT taskExportHandler(Medium::ExportTask &task);
333 HRESULT taskImportHandler(Medium::ImportTask &task);
334
335 struct Data; // opaque data struct, defined in MediumImpl.cpp
336 Data *m;
337};
338
339#endif /* ____H_MEDIUMIMPL */
340
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette