VirtualBox

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

Last change on this file since 30929 was 30929, checked in by vboxsync, 15 years ago

Main: add option to UnregisterMachine() to automatically nuke all attached media

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.7 KB
Line 
1/* $Id: MediumImpl.h 30929 2010-07-20 14:11:51Z 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.215389.xyz. 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 "VirtualBoxBase.h"
24#include "MediumLock.h"
25
26class Progress;
27class MediumFormat;
28
29namespace settings
30{
31 struct Medium;
32}
33
34////////////////////////////////////////////////////////////////////////////////
35
36/**
37 * Medium component class for all media types.
38 */
39class ATL_NO_VTABLE Medium :
40 public VirtualBoxBase,
41 VBOX_SCRIPTABLE_IMPL(IMedium)
42{
43public:
44 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Medium, IMedium)
45
46 DECLARE_NOT_AGGREGATABLE(Medium)
47
48 DECLARE_PROTECT_FINAL_CONSTRUCT()
49
50 BEGIN_COM_MAP(Medium)
51 COM_INTERFACE_ENTRY(ISupportErrorInfo)
52 COM_INTERFACE_ENTRY(IMedium)
53 COM_INTERFACE_ENTRY(IDispatch)
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 HRESULT init(VirtualBox *aVirtualBox,
68 CBSTR aFormat,
69 CBSTR aLocation,
70 bool *pfNeedsSaveSettings);
71 HRESULT init(VirtualBox *aVirtualBox,
72 CBSTR aLocation,
73 HDDOpenMode enOpenMode,
74 DeviceType_T aDeviceType,
75 BOOL aSetImageId,
76 const Guid &aImageId,
77 BOOL aSetParentId,
78 const Guid &aParentId);
79 // initializer used when loading settings
80 HRESULT init(VirtualBox *aVirtualBox,
81 Medium *aParent,
82 DeviceType_T aDeviceType,
83 const settings::Medium &data);
84 // initializer for host floppy/DVD
85 HRESULT init(VirtualBox *aVirtualBox,
86 DeviceType_T aDeviceType,
87 CBSTR aLocation,
88 CBSTR aDescription = NULL);
89 void uninit();
90
91 void deparent();
92 void setParent(const ComObjPtr<Medium> &pParent);
93
94 // IMedium properties
95 STDMETHOD(COMGETTER(Id))(BSTR *aId);
96 STDMETHOD(COMGETTER(Description))(BSTR *aDescription);
97 STDMETHOD(COMSETTER(Description))(IN_BSTR aDescription);
98 STDMETHOD(COMGETTER(State))(MediumState_T *aState);
99 STDMETHOD(COMGETTER(Location))(BSTR *aLocation);
100 STDMETHOD(COMSETTER(Location))(IN_BSTR aLocation);
101 STDMETHOD(COMGETTER(Name))(BSTR *aName);
102 STDMETHOD(COMGETTER(DeviceType))(DeviceType_T *aDeviceType);
103 STDMETHOD(COMGETTER(HostDrive))(BOOL *aHostDrive);
104 STDMETHOD(COMGETTER(Size))(ULONG64 *aSize);
105 STDMETHOD(COMGETTER(Format))(BSTR *aFormat);
106 STDMETHOD(COMGETTER(MediumFormat))(IMediumFormat **aMediumFormat);
107 STDMETHOD(COMGETTER(Type))(MediumType_T *aType);
108 STDMETHOD(COMSETTER(Type))(MediumType_T aType);
109 STDMETHOD(COMGETTER(Parent))(IMedium **aParent);
110 STDMETHOD(COMGETTER(Children))(ComSafeArrayOut(IMedium *, aChildren));
111 STDMETHOD(COMGETTER(Base))(IMedium **aBase);
112 STDMETHOD(COMGETTER(ReadOnly))(BOOL *aReadOnly);
113 STDMETHOD(COMGETTER(LogicalSize))(ULONG64 *aLogicalSize);
114 STDMETHOD(COMGETTER(AutoReset))(BOOL *aAutoReset);
115 STDMETHOD(COMSETTER(AutoReset))(BOOL aAutoReset);
116 STDMETHOD(COMGETTER(LastAccessError))(BSTR *aLastAccessError);
117 STDMETHOD(COMGETTER(MachineIds))(ComSafeArrayOut(BSTR, aMachineIds));
118
119 // IMedium methods
120 STDMETHOD(RefreshState)(MediumState_T *aState);
121 STDMETHOD(GetSnapshotIds)(IN_BSTR aMachineId,
122 ComSafeArrayOut(BSTR, aSnapshotIds));
123 STDMETHOD(LockRead)(MediumState_T *aState);
124 STDMETHOD(UnlockRead)(MediumState_T *aState);
125 STDMETHOD(LockWrite)(MediumState_T *aState);
126 STDMETHOD(UnlockWrite)(MediumState_T *aState);
127 STDMETHOD(Close)();
128 STDMETHOD(GetProperty)(IN_BSTR aName, BSTR *aValue);
129 STDMETHOD(SetProperty)(IN_BSTR aName, IN_BSTR aValue);
130 STDMETHOD(GetProperties)(IN_BSTR aNames,
131 ComSafeArrayOut(BSTR, aReturnNames),
132 ComSafeArrayOut(BSTR, aReturnValues));
133 STDMETHOD(SetProperties)(ComSafeArrayIn(IN_BSTR, aNames),
134 ComSafeArrayIn(IN_BSTR, aValues));
135 STDMETHOD(CreateBaseStorage)(ULONG64 aLogicalSize,
136 MediumVariant_T aVariant,
137 IProgress **aProgress);
138 STDMETHOD(DeleteStorage)(IProgress **aProgress);
139 STDMETHOD(CreateDiffStorage)(IMedium *aTarget,
140 MediumVariant_T aVariant,
141 IProgress **aProgress);
142 STDMETHOD(MergeTo)(IMedium *aTarget, IProgress **aProgress);
143 STDMETHOD(CloneTo)(IMedium *aTarget, MediumVariant_T aVariant,
144 IMedium *aParent, IProgress **aProgress);
145 STDMETHOD(Compact)(IProgress **aProgress);
146 STDMETHOD(Resize)(ULONG64 aLogicalSize, IProgress **aProgress);
147 STDMETHOD(Reset)(IProgress **aProgress);
148
149 // public methods for internal purposes only
150 const ComObjPtr<Medium>& getParent() const;
151 const MediaList& getChildren() const;
152
153 // unsafe methods for internal purposes only (ensure there is
154 // a caller and a read lock before calling them!)
155 const Guid& getId() const;
156 MediumState_T getState() const;
157 const Utf8Str& getLocation() const;
158 const Utf8Str& getLocationFull() const;
159 const Utf8Str& getFormat() const;
160 const ComObjPtr<MediumFormat> & getMediumFormat() const;
161 uint64_t getSize() const;
162 MediumType_T getType() const;
163 Utf8Str getName();
164
165 HRESULT attachTo(const Guid &aMachineId,
166 const Guid &aSnapshotId = Guid::Empty);
167 HRESULT detachFrom(const Guid &aMachineId,
168 const Guid &aSnapshotId = Guid::Empty);
169
170 const Guid* getFirstMachineBackrefId() const;
171 const Guid* getFirstMachineBackrefSnapshotId() const;
172
173#ifdef DEBUG
174 void dumpBackRefs();
175#endif
176
177 HRESULT updatePath(const char *aOldPath, const char *aNewPath);
178 void updatePaths(const char *aOldPath, const char *aNewPath);
179
180 ComObjPtr<Medium> getBase(uint32_t *aLevel = NULL);
181
182 bool isReadOnly();
183
184 HRESULT saveSettings(settings::Medium &data);
185
186 HRESULT compareLocationTo(const char *aLocation, int &aResult);
187
188 HRESULT createMediumLockList(bool fFailIfInaccessible,
189 bool fMediumLockWrite,
190 Medium *pToBeParent,
191 MediumLockList &mediumLockList);
192
193 HRESULT createDiffStorage(ComObjPtr<Medium> &aTarget,
194 MediumVariant_T aVariant,
195 MediumLockList *pMediumLockList,
196 ComObjPtr<Progress> *aProgress,
197 bool aWait,
198 bool *pfNeedsSaveSettings);
199
200 HRESULT close(bool *pfNeedsSaveSettings, AutoCaller &autoCaller);
201 HRESULT deleteStorage(ComObjPtr<Progress> *aProgress, bool aWait, bool *pfNeedsSaveSettings);
202 HRESULT markForDeletion();
203 HRESULT unmarkForDeletion();
204 HRESULT markLockedForDeletion();
205 HRESULT unmarkLockedForDeletion();
206
207 HRESULT prepareMergeTo(const ComObjPtr<Medium> &pTarget,
208 const Guid *aMachineId,
209 const Guid *aSnapshotId,
210 bool fLockMedia,
211 bool &fMergeForward,
212 ComObjPtr<Medium> &pParentForTarget,
213 MediaList &aChildrenToReparent,
214 MediumLockList * &aMediumLockList);
215 HRESULT mergeTo(const ComObjPtr<Medium> &pTarget,
216 bool fMergeForward,
217 const ComObjPtr<Medium> &pParentForTarget,
218 const MediaList &aChildrenToReparent,
219 MediumLockList *aMediumLockList,
220 ComObjPtr<Progress> *aProgress,
221 bool aWait,
222 bool *pfNeedsSaveSettings);
223 void cancelMergeTo(const MediaList &aChildrenToReparent,
224 MediumLockList *aMediumLockList);
225
226 HRESULT fixParentUuidOfChildren(const MediaList &childrenToReparent);
227
228 /** Returns a preferred format for a differencing hard disk. */
229 Bstr preferredDiffFormat();
230
231private:
232
233 HRESULT queryInfo();
234
235 HRESULT canClose();
236 HRESULT unregisterWithVirtualBox(bool *pfNeedsSaveSettings);
237
238 HRESULT setStateError();
239
240 HRESULT setLocation(const Utf8Str &aLocation, const Utf8Str &aFormat = Utf8Str());
241 HRESULT setFormat(CBSTR aFormat);
242
243 Utf8Str vdError(int aVRC);
244
245 static DECLCALLBACK(void) vdErrorCall(void *pvUser, int rc, RT_SRC_POS_DECL,
246 const char *pszFormat, va_list va);
247
248 static DECLCALLBACK(bool) vdConfigAreKeysValid(void *pvUser,
249 const char *pszzValid);
250 static DECLCALLBACK(int) vdConfigQuerySize(void *pvUser, const char *pszName,
251 size_t *pcbValue);
252 static DECLCALLBACK(int) vdConfigQuery(void *pvUser, const char *pszName,
253 char *pszValue, size_t cchValue);
254
255 class Task;
256 class CreateBaseTask;
257 class CreateDiffTask;
258 class CloneTask;
259 class CompactTask;
260 class ResetTask;
261 class DeleteTask;
262 class MergeTask;
263 friend class Task;
264 friend class CreateBaseTask;
265 friend class CreateDiffTask;
266 friend class CloneTask;
267 friend class CompactTask;
268 friend class ResetTask;
269 friend class DeleteTask;
270 friend class MergeTask;
271
272 HRESULT startThread(Medium::Task *pTask);
273 HRESULT runNow(Medium::Task *pTask, bool *pfNeedsSaveSettings);
274
275 HRESULT taskCreateBaseHandler(Medium::CreateBaseTask &task);
276 HRESULT taskCreateDiffHandler(Medium::CreateDiffTask &task);
277 HRESULT taskMergeHandler(Medium::MergeTask &task);
278 HRESULT taskCloneHandler(Medium::CloneTask &task);
279 HRESULT taskDeleteHandler(Medium::DeleteTask &task);
280 HRESULT taskResetHandler(Medium::ResetTask &task);
281 HRESULT taskCompactHandler(Medium::CompactTask &task);
282
283 struct Data; // opaque data struct, defined in MediumImpl.cpp
284 Data *m;
285};
286
287#endif /* ____H_MEDIUMIMPL */
288
Note: See TracBrowser for help on using the repository browser.

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