1 | /* $Id: HardDiskImpl.h 10715 2008-07-16 22:38:23Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * VirtualBox COM class implementation
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
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 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
20 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
21 | * additional information or have any questions.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #ifndef ____H_HARDDISKIMPL
|
---|
25 | #define ____H_HARDDISKIMPL
|
---|
26 |
|
---|
27 | #include "VirtualBoxBase.h"
|
---|
28 | #include "Collection.h"
|
---|
29 |
|
---|
30 | #include <VBox/VBoxHDD-new.h>
|
---|
31 |
|
---|
32 | #include <iprt/semaphore.h>
|
---|
33 |
|
---|
34 | #include <list>
|
---|
35 |
|
---|
36 | class VirtualBox;
|
---|
37 | class Progress;
|
---|
38 | class HVirtualDiskImage;
|
---|
39 |
|
---|
40 | ////////////////////////////////////////////////////////////////////////////////
|
---|
41 |
|
---|
42 | class ATL_NO_VTABLE HardDisk :
|
---|
43 | public VirtualBoxSupportErrorInfoImpl <HardDisk, IHardDisk>,
|
---|
44 | public VirtualBoxSupportTranslation <HardDisk>,
|
---|
45 | public VirtualBoxBaseWithTypedChildren <HardDisk>,
|
---|
46 | public IHardDisk
|
---|
47 | {
|
---|
48 |
|
---|
49 | public:
|
---|
50 |
|
---|
51 | typedef VirtualBoxBaseWithTypedChildren <HardDisk>::DependentChildren
|
---|
52 | HardDiskList;
|
---|
53 |
|
---|
54 | DECLARE_NOT_AGGREGATABLE(HardDisk)
|
---|
55 |
|
---|
56 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
57 |
|
---|
58 | BEGIN_COM_MAP(HardDisk)
|
---|
59 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
60 | COM_INTERFACE_ENTRY(IHardDisk)
|
---|
61 | END_COM_MAP()
|
---|
62 |
|
---|
63 | NS_DECL_ISUPPORTS
|
---|
64 |
|
---|
65 | HRESULT FinalConstruct();
|
---|
66 | void FinalRelease();
|
---|
67 |
|
---|
68 | protected:
|
---|
69 |
|
---|
70 | // protected initializer/uninitializer for internal purposes only
|
---|
71 | HRESULT protectedInit (VirtualBox *aVirtualBox, HardDisk *aParent);
|
---|
72 | void protectedUninit (AutoWriteLock &alock);
|
---|
73 |
|
---|
74 | public:
|
---|
75 |
|
---|
76 | // IHardDisk properties
|
---|
77 | STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
|
---|
78 | STDMETHOD(COMGETTER(StorageType)) (HardDiskStorageType_T *aStorageType);
|
---|
79 | STDMETHOD(COMGETTER(Location)) (BSTR *aLocation);
|
---|
80 | STDMETHOD(COMGETTER(Type)) (HardDiskType_T *aType);
|
---|
81 | STDMETHOD(COMSETTER(Type)) (HardDiskType_T aType);
|
---|
82 | STDMETHOD(COMGETTER(Parent)) (IHardDisk **aParent);
|
---|
83 | STDMETHOD(COMGETTER(Children)) (IHardDiskCollection **aChildren);
|
---|
84 | STDMETHOD(COMGETTER(Root)) (IHardDisk **aRoot);
|
---|
85 | STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
|
---|
86 | STDMETHOD(COMGETTER(AllAccessible)) (BOOL *aAllAccessible);
|
---|
87 | STDMETHOD(COMGETTER(LastAccessError)) (BSTR *aLastAccessError);
|
---|
88 | STDMETHOD(COMGETTER(MachineId)) (GUIDPARAMOUT aMachineId);
|
---|
89 | STDMETHOD(COMGETTER(SnapshotId)) (GUIDPARAMOUT aSnapshotId);
|
---|
90 |
|
---|
91 | // IHardDisk methods
|
---|
92 | STDMETHOD(CloneToImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage,
|
---|
93 | IProgress **aProgress);
|
---|
94 |
|
---|
95 | // public methods for internal purposes only
|
---|
96 |
|
---|
97 | const Guid &id() const { return mId; }
|
---|
98 | HardDiskStorageType_T storageType() const { return mStorageType; }
|
---|
99 | HardDiskType_T type() const { return mType; }
|
---|
100 | const Guid &machineId() const { return mMachineId; }
|
---|
101 | const Guid &snapshotId() const { return mSnapshotId; }
|
---|
102 |
|
---|
103 | void setMachineId (const Guid &aId) { mMachineId = aId; }
|
---|
104 | void setSnapshotId (const Guid &aId) { mSnapshotId = aId; }
|
---|
105 |
|
---|
106 | bool isDifferencing() const
|
---|
107 | {
|
---|
108 | return mType == HardDiskType_Normal &&
|
---|
109 | mStorageType == HardDiskStorageType_VirtualDiskImage &&
|
---|
110 | !mParent.isNull();
|
---|
111 | }
|
---|
112 | bool isParentImmutable() const
|
---|
113 | {
|
---|
114 | AutoWriteLock parentLock (mParent);
|
---|
115 | return !mParent.isNull() && mParent->type() == HardDiskType_Immutable;
|
---|
116 | }
|
---|
117 |
|
---|
118 | inline HVirtualDiskImage *asVDI();
|
---|
119 |
|
---|
120 | ComObjPtr <HardDisk> parent() const { return static_cast <HardDisk *> (mParent); }
|
---|
121 |
|
---|
122 | /** Shortcut to #dependentChildrenLock() */
|
---|
123 | RWLockHandle *childrenLock() const { return dependentChildrenLock(); }
|
---|
124 |
|
---|
125 | /**
|
---|
126 | * Shortcut to #dependentChildren().
|
---|
127 | * Do |AutoWriteLock alock (childrenLock());| before acceessing the returned list!
|
---|
128 | */
|
---|
129 | const HardDiskList &children() const { return dependentChildren(); }
|
---|
130 |
|
---|
131 | ComObjPtr <HardDisk> root() const;
|
---|
132 |
|
---|
133 | HRESULT getBaseAccessible (Bstr &aAccessError, bool aCheckBusy = false,
|
---|
134 | bool aCheckReaders = false);
|
---|
135 |
|
---|
136 | // virtual methods that need to be [re]implemented by every subclass
|
---|
137 |
|
---|
138 | virtual HRESULT trySetRegistered (BOOL aRegistered);
|
---|
139 | virtual HRESULT getAccessible (Bstr &aAccessError) = 0;
|
---|
140 |
|
---|
141 | virtual HRESULT saveSettings (settings::Key &aHDNode, settings::Key &aStorageNode) = 0;
|
---|
142 |
|
---|
143 | virtual void updatePath (const char *aOldPath, const char *aNewPath) {}
|
---|
144 |
|
---|
145 | virtual Bstr toString (bool aShort = false) = 0;
|
---|
146 | virtual bool sameAs (HardDisk *that);
|
---|
147 |
|
---|
148 | virtual HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
149 | Progress *aProgress, bool &aDeleteTarget) = 0;
|
---|
150 | virtual HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
151 | Progress *aProgress) = 0;
|
---|
152 | public:
|
---|
153 |
|
---|
154 | void setBusy();
|
---|
155 | void clearBusy();
|
---|
156 | void addReader();
|
---|
157 | void releaseReader();
|
---|
158 | void addReaderOnAncestors();
|
---|
159 | void releaseReaderOnAncestors();
|
---|
160 | bool hasForeignChildren();
|
---|
161 |
|
---|
162 | HRESULT setBusyWithChildren();
|
---|
163 | void clearBusyWithChildren();
|
---|
164 | HRESULT getAccessibleWithChildren (Bstr &aAccessError);
|
---|
165 |
|
---|
166 | HRESULT checkConsistency();
|
---|
167 |
|
---|
168 | HRESULT createDiffHardDisk (const Bstr &aFolder, const Guid &aMachineId,
|
---|
169 | ComObjPtr <HVirtualDiskImage> &aHardDisk,
|
---|
170 | Progress *aProgress);
|
---|
171 |
|
---|
172 | void updatePaths (const char *aOldPath, const char *aNewPath);
|
---|
173 |
|
---|
174 | /* the following must be called from under the lock */
|
---|
175 | bool isBusy() { isWriteLockOnCurrentThread(); return mBusy; }
|
---|
176 | unsigned readers() { isWriteLockOnCurrentThread(); return mReaders; }
|
---|
177 | const Bstr &lastAccessError() const { return mLastAccessError; }
|
---|
178 |
|
---|
179 | static HRESULT openHardDisk (VirtualBox *aVirtualBox, INPTR BSTR aLocation,
|
---|
180 | ComObjPtr <HardDisk> &hardDisk);
|
---|
181 |
|
---|
182 | // for VirtualBoxSupportErrorInfoImpl
|
---|
183 | static const wchar_t *getComponentName() { return L"HardDisk"; }
|
---|
184 |
|
---|
185 | protected:
|
---|
186 |
|
---|
187 | HRESULT loadSettings (const settings::Key &aHDNode);
|
---|
188 | HRESULT saveSettings (settings::Key &aHDNode);
|
---|
189 |
|
---|
190 | /** weak VirualBox parent */
|
---|
191 | ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
|
---|
192 |
|
---|
193 | BOOL mRegistered;
|
---|
194 |
|
---|
195 | ComObjPtr <HardDisk, ComWeakRef> mParent;
|
---|
196 |
|
---|
197 | Guid mId;
|
---|
198 | HardDiskStorageType_T mStorageType;
|
---|
199 | HardDiskType_T mType;
|
---|
200 | Guid mMachineId;
|
---|
201 | Guid mSnapshotId;
|
---|
202 |
|
---|
203 | private:
|
---|
204 |
|
---|
205 | Bstr mLastAccessError;
|
---|
206 |
|
---|
207 | bool mBusy;
|
---|
208 | unsigned mReaders;
|
---|
209 | };
|
---|
210 |
|
---|
211 | ////////////////////////////////////////////////////////////////////////////////
|
---|
212 |
|
---|
213 | class ATL_NO_VTABLE HVirtualDiskImage :
|
---|
214 | public HardDisk,
|
---|
215 | public VirtualBoxSupportTranslation <HVirtualDiskImage>,
|
---|
216 | public IVirtualDiskImage
|
---|
217 | {
|
---|
218 |
|
---|
219 | public:
|
---|
220 |
|
---|
221 | VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HVirtualDiskImage)
|
---|
222 |
|
---|
223 | DECLARE_NOT_AGGREGATABLE(HVirtualDiskImage)
|
---|
224 |
|
---|
225 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
226 |
|
---|
227 | BEGIN_COM_MAP(HVirtualDiskImage)
|
---|
228 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
229 | COM_INTERFACE_ENTRY(IHardDisk)
|
---|
230 | COM_INTERFACE_ENTRY(IVirtualDiskImage)
|
---|
231 | END_COM_MAP()
|
---|
232 |
|
---|
233 | NS_DECL_ISUPPORTS
|
---|
234 |
|
---|
235 | HRESULT FinalConstruct();
|
---|
236 | void FinalRelease();
|
---|
237 |
|
---|
238 | // public initializer/uninitializer for internal purposes only
|
---|
239 |
|
---|
240 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
241 | const settings::Key &aHDNode, const settings::Key &aVDINode);
|
---|
242 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
243 | const BSTR aFilePath, BOOL aRegistered = FALSE);
|
---|
244 | void uninit();
|
---|
245 |
|
---|
246 | // IHardDisk properties
|
---|
247 | STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
|
---|
248 | STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
|
---|
249 | STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
|
---|
250 | STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
|
---|
251 |
|
---|
252 | // IVirtualDiskImage properties
|
---|
253 | STDMETHOD(COMGETTER(FilePath)) (BSTR *aFilePath);
|
---|
254 | STDMETHOD(COMSETTER(FilePath)) (INPTR BSTR aFilePath);
|
---|
255 | STDMETHOD(COMGETTER(Created)) (BOOL *aCreated);
|
---|
256 |
|
---|
257 | // IVirtualDiskImage methods
|
---|
258 | STDMETHOD(CreateDynamicImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
259 | STDMETHOD(CreateFixedImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
260 | STDMETHOD(DeleteImage)();
|
---|
261 |
|
---|
262 | // public methods for internal purposes only
|
---|
263 |
|
---|
264 | const Bstr &filePath() const { return mFilePath; }
|
---|
265 | const Bstr &filePathFull() const { return mFilePathFull; }
|
---|
266 |
|
---|
267 | HRESULT trySetRegistered (BOOL aRegistered);
|
---|
268 | HRESULT getAccessible (Bstr &aAccessError);
|
---|
269 |
|
---|
270 | HRESULT saveSettings (settings::Key &aHDNode, settings::Key &aStorageNode);
|
---|
271 |
|
---|
272 | void updatePath (const char *aOldPath, const char *aNewPath);
|
---|
273 |
|
---|
274 | Bstr toString (bool aShort = false);
|
---|
275 |
|
---|
276 | HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
277 | Progress *aProgress, bool &aDeleteTarget);
|
---|
278 | HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
279 | Progress *aProgress);
|
---|
280 |
|
---|
281 | HRESULT cloneDiffImage (const Bstr &aFolder, const Guid &aMachineId,
|
---|
282 | ComObjPtr <HVirtualDiskImage> &aHardDisk,
|
---|
283 | Progress *aProgress);
|
---|
284 |
|
---|
285 | HRESULT mergeImageToParent (Progress *aProgress);
|
---|
286 | HRESULT mergeImageToChildren (Progress *aProgress);
|
---|
287 |
|
---|
288 | HRESULT wipeOutImage();
|
---|
289 | HRESULT deleteImage (bool aIgnoreErrors = false);
|
---|
290 |
|
---|
291 | // for VirtualBoxSupportErrorInfoImpl
|
---|
292 | static const wchar_t *getComponentName() { return L"VirtualDiskImage"; }
|
---|
293 |
|
---|
294 | private:
|
---|
295 |
|
---|
296 | HRESULT setFilePath (const BSTR aFilePath);
|
---|
297 | HRESULT queryInformation (Bstr *aAccessError);
|
---|
298 | HRESULT createImage (ULONG64 aSize, BOOL aDynamic, IProgress **aProgress);
|
---|
299 |
|
---|
300 | /** VDI asynchronous operation thread function */
|
---|
301 | static DECLCALLBACK(int) VDITaskThread (RTTHREAD thread, void *pvUser);
|
---|
302 |
|
---|
303 | enum State
|
---|
304 | {
|
---|
305 | NotCreated,
|
---|
306 | Created,
|
---|
307 | /* the following must be greater than Created */
|
---|
308 | Accessible,
|
---|
309 | };
|
---|
310 |
|
---|
311 | State mState;
|
---|
312 |
|
---|
313 | RTSEMEVENTMULTI mStateCheckSem;
|
---|
314 | ULONG mStateCheckWaiters;
|
---|
315 |
|
---|
316 | Bstr mDescription;
|
---|
317 |
|
---|
318 | ULONG64 mSize;
|
---|
319 | ULONG64 mActualSize;
|
---|
320 |
|
---|
321 | Bstr mFilePath;
|
---|
322 | Bstr mFilePathFull;
|
---|
323 |
|
---|
324 | friend class HardDisk;
|
---|
325 | };
|
---|
326 |
|
---|
327 | // dependent inline members
|
---|
328 | ////////////////////////////////////////////////////////////////////////////////
|
---|
329 |
|
---|
330 | inline HVirtualDiskImage *HardDisk::asVDI()
|
---|
331 | {
|
---|
332 | AssertReturn (mStorageType == HardDiskStorageType_VirtualDiskImage, 0);
|
---|
333 | return static_cast <HVirtualDiskImage *> (this);
|
---|
334 | }
|
---|
335 |
|
---|
336 | ////////////////////////////////////////////////////////////////////////////////
|
---|
337 |
|
---|
338 | class ATL_NO_VTABLE HISCSIHardDisk :
|
---|
339 | public HardDisk,
|
---|
340 | public VirtualBoxSupportTranslation <HISCSIHardDisk>,
|
---|
341 | public IISCSIHardDisk
|
---|
342 | {
|
---|
343 |
|
---|
344 | public:
|
---|
345 |
|
---|
346 | VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HISCSIHardDisk)
|
---|
347 |
|
---|
348 | DECLARE_NOT_AGGREGATABLE(HISCSIHardDisk)
|
---|
349 |
|
---|
350 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
351 |
|
---|
352 | BEGIN_COM_MAP(HISCSIHardDisk)
|
---|
353 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
354 | COM_INTERFACE_ENTRY(IHardDisk)
|
---|
355 | COM_INTERFACE_ENTRY(IISCSIHardDisk)
|
---|
356 | END_COM_MAP()
|
---|
357 |
|
---|
358 | NS_DECL_ISUPPORTS
|
---|
359 |
|
---|
360 | HRESULT FinalConstruct();
|
---|
361 | void FinalRelease();
|
---|
362 |
|
---|
363 | // public initializer/uninitializer for internal purposes only
|
---|
364 |
|
---|
365 | HRESULT init (VirtualBox *aVirtualBox,
|
---|
366 | const settings::Key &aHDNode, const settings::Key &aISCSINode);
|
---|
367 | HRESULT init (VirtualBox *aVirtualBox);
|
---|
368 | void uninit();
|
---|
369 |
|
---|
370 | // IHardDisk properties
|
---|
371 | STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
|
---|
372 | STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
|
---|
373 | STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
|
---|
374 | STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
|
---|
375 |
|
---|
376 | // IISCSIHardDisk properties
|
---|
377 | STDMETHOD(COMGETTER(Server)) (BSTR *aServer);
|
---|
378 | STDMETHOD(COMSETTER(Server)) (INPTR BSTR aServer);
|
---|
379 | STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
|
---|
380 | STDMETHOD(COMSETTER(Port)) (USHORT aPort);
|
---|
381 | STDMETHOD(COMGETTER(Target)) (BSTR *aTarget);
|
---|
382 | STDMETHOD(COMSETTER(Target)) (INPTR BSTR aTarget);
|
---|
383 | STDMETHOD(COMGETTER(Lun)) (ULONG64 *aLun);
|
---|
384 | STDMETHOD(COMSETTER(Lun)) (ULONG64 aLun);
|
---|
385 | STDMETHOD(COMGETTER(UserName)) (BSTR *aUserName);
|
---|
386 | STDMETHOD(COMSETTER(UserName)) (INPTR BSTR aUserName);
|
---|
387 | STDMETHOD(COMGETTER(Password)) (BSTR *aPassword);
|
---|
388 | STDMETHOD(COMSETTER(Password)) (INPTR BSTR aPassword);
|
---|
389 |
|
---|
390 | // public methods for internal purposes only
|
---|
391 |
|
---|
392 | const Bstr &server() const { return mServer; }
|
---|
393 | USHORT port() const { return mPort; }
|
---|
394 | const Bstr &target() const { return mTarget; }
|
---|
395 | ULONG64 lun() const { return mLun; }
|
---|
396 | const Bstr &userName() const { return mUserName; }
|
---|
397 | const Bstr &password() const { return mPassword; }
|
---|
398 |
|
---|
399 | HRESULT trySetRegistered (BOOL aRegistered);
|
---|
400 | HRESULT getAccessible (Bstr &aAccessError);
|
---|
401 |
|
---|
402 | HRESULT saveSettings (settings::Key &aHDNode, settings::Key &aStorageNode);
|
---|
403 |
|
---|
404 | Bstr toString (bool aShort = false);
|
---|
405 |
|
---|
406 | HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
407 | Progress *aProgress, bool &aDeleteTarget);
|
---|
408 | HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
409 | Progress *aProgress);
|
---|
410 |
|
---|
411 | public:
|
---|
412 |
|
---|
413 | // for VirtualBoxSupportErrorInfoImpl
|
---|
414 | static const wchar_t *getComponentName() { return L"ISCSIHardDisk"; }
|
---|
415 |
|
---|
416 | private:
|
---|
417 |
|
---|
418 | HRESULT queryInformation (Bstr &aAccessError);
|
---|
419 |
|
---|
420 | Bstr mDescription;
|
---|
421 |
|
---|
422 | ULONG64 mSize;
|
---|
423 | ULONG64 mActualSize;
|
---|
424 |
|
---|
425 | Bstr mServer;
|
---|
426 | USHORT mPort;
|
---|
427 | Bstr mTarget;
|
---|
428 | ULONG64 mLun;
|
---|
429 | Bstr mUserName;
|
---|
430 | Bstr mPassword;
|
---|
431 | };
|
---|
432 |
|
---|
433 | ////////////////////////////////////////////////////////////////////////////////
|
---|
434 |
|
---|
435 | class ATL_NO_VTABLE HVMDKImage :
|
---|
436 | public HardDisk,
|
---|
437 | public VirtualBoxSupportTranslation <HVMDKImage>,
|
---|
438 | public IVMDKImage
|
---|
439 | {
|
---|
440 |
|
---|
441 | public:
|
---|
442 |
|
---|
443 | VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HVMDKImage)
|
---|
444 |
|
---|
445 | DECLARE_NOT_AGGREGATABLE(HVMDKImage)
|
---|
446 |
|
---|
447 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
448 |
|
---|
449 | BEGIN_COM_MAP(HVMDKImage)
|
---|
450 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
451 | COM_INTERFACE_ENTRY(IHardDisk)
|
---|
452 | COM_INTERFACE_ENTRY(IVMDKImage)
|
---|
453 | END_COM_MAP()
|
---|
454 |
|
---|
455 | NS_DECL_ISUPPORTS
|
---|
456 |
|
---|
457 | HRESULT FinalConstruct();
|
---|
458 | void FinalRelease();
|
---|
459 |
|
---|
460 | // public initializer/uninitializer for internal purposes only
|
---|
461 |
|
---|
462 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
463 | const settings::Key &aHDNode, const settings::Key &aVMDKNode);
|
---|
464 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
465 | INPTR BSTR aFilePath, BOOL aRegistered = FALSE);
|
---|
466 | void uninit();
|
---|
467 |
|
---|
468 | // IHardDisk properties
|
---|
469 | STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
|
---|
470 | STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
|
---|
471 | STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
|
---|
472 | STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
|
---|
473 |
|
---|
474 | // IVirtualDiskImage properties
|
---|
475 | STDMETHOD(COMGETTER(FilePath)) (BSTR *aFilePath);
|
---|
476 | STDMETHOD(COMSETTER(FilePath)) (INPTR BSTR aFilePath);
|
---|
477 | STDMETHOD(COMGETTER(Created)) (BOOL *aCreated);
|
---|
478 |
|
---|
479 | // IVirtualDiskImage methods
|
---|
480 | STDMETHOD(CreateDynamicImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
481 | STDMETHOD(CreateFixedImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
482 | STDMETHOD(DeleteImage)();
|
---|
483 |
|
---|
484 | // public methods for internal purposes only
|
---|
485 |
|
---|
486 | const Bstr &filePath() const { return mFilePath; }
|
---|
487 | const Bstr &filePathFull() const { return mFilePathFull; }
|
---|
488 |
|
---|
489 | HRESULT trySetRegistered (BOOL aRegistered);
|
---|
490 | HRESULT getAccessible (Bstr &aAccessError);
|
---|
491 |
|
---|
492 | HRESULT saveSettings (settings::Key &aHDNode, settings::Key &aStorageNode);
|
---|
493 |
|
---|
494 | void updatePath (const char *aOldPath, const char *aNewPath);
|
---|
495 |
|
---|
496 | Bstr toString (bool aShort = false);
|
---|
497 |
|
---|
498 | HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
499 | Progress *aProgress, bool &aDeleteTarget);
|
---|
500 | HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
501 | Progress *aProgress);
|
---|
502 |
|
---|
503 | // for VirtualBoxSupportErrorInfoImpl
|
---|
504 | static const wchar_t *getComponentName() { return L"VMDKImage"; }
|
---|
505 |
|
---|
506 | private:
|
---|
507 |
|
---|
508 | HRESULT setFilePath (const BSTR aFilePath);
|
---|
509 | HRESULT queryInformation (Bstr *aAccessError);
|
---|
510 | HRESULT createImage (ULONG64 aSize, BOOL aDynamic, IProgress **aProgress);
|
---|
511 |
|
---|
512 | /** VDI asynchronous operation thread function */
|
---|
513 | static DECLCALLBACK(int) VDITaskThread (RTTHREAD thread, void *pvUser);
|
---|
514 |
|
---|
515 | static DECLCALLBACK(void) VDError (void *pvUser, int rc, RT_SRC_POS_DECL,
|
---|
516 | const char *pszFormat, va_list va);
|
---|
517 |
|
---|
518 | enum State
|
---|
519 | {
|
---|
520 | NotCreated,
|
---|
521 | Created,
|
---|
522 | /* the following must be greater than Created */
|
---|
523 | Accessible,
|
---|
524 | };
|
---|
525 |
|
---|
526 | State mState;
|
---|
527 |
|
---|
528 | RTSEMEVENTMULTI mStateCheckSem;
|
---|
529 | ULONG mStateCheckWaiters;
|
---|
530 |
|
---|
531 | Bstr mDescription;
|
---|
532 |
|
---|
533 | ULONG64 mSize;
|
---|
534 | ULONG64 mActualSize;
|
---|
535 |
|
---|
536 | Bstr mFilePath;
|
---|
537 | Bstr mFilePathFull;
|
---|
538 |
|
---|
539 | PVBOXHDD mContainer;
|
---|
540 |
|
---|
541 | VDINTERFACE mInterfaceError;
|
---|
542 | VDINTERFACEERROR mInterfaceErrorCallbacks;
|
---|
543 |
|
---|
544 | Utf8Str mLastVDError;
|
---|
545 |
|
---|
546 | friend class HardDisk;
|
---|
547 | };
|
---|
548 |
|
---|
549 | ////////////////////////////////////////////////////////////////////////////////
|
---|
550 |
|
---|
551 | class ATL_NO_VTABLE HCustomHardDisk :
|
---|
552 | public HardDisk,
|
---|
553 | public VirtualBoxSupportTranslation <HCustomHardDisk>,
|
---|
554 | public ICustomHardDisk
|
---|
555 | {
|
---|
556 |
|
---|
557 | public:
|
---|
558 |
|
---|
559 | VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HCustomHardDisk)
|
---|
560 |
|
---|
561 | DECLARE_NOT_AGGREGATABLE(HCustomHardDisk)
|
---|
562 |
|
---|
563 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
564 |
|
---|
565 | BEGIN_COM_MAP(HCustomHardDisk)
|
---|
566 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
567 | COM_INTERFACE_ENTRY(IHardDisk)
|
---|
568 | COM_INTERFACE_ENTRY(ICustomHardDisk)
|
---|
569 | END_COM_MAP()
|
---|
570 |
|
---|
571 | NS_DECL_ISUPPORTS
|
---|
572 |
|
---|
573 | HRESULT FinalConstruct();
|
---|
574 | void FinalRelease();
|
---|
575 |
|
---|
576 | // public initializer/uninitializer for internal purposes only
|
---|
577 |
|
---|
578 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
579 | const settings::Key &aHDNode, const settings::Key &aCustomNode);
|
---|
580 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
581 | INPTR BSTR aLocation, BOOL aRegistered = FALSE);
|
---|
582 | void uninit();
|
---|
583 |
|
---|
584 | // IHardDisk properties
|
---|
585 | STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
|
---|
586 | STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
|
---|
587 | STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
|
---|
588 | STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
|
---|
589 |
|
---|
590 | // IVirtualDiskImage properties
|
---|
591 | STDMETHOD(COMGETTER(Location)) (BSTR *aLocation);
|
---|
592 | STDMETHOD(COMSETTER(Location)) (INPTR BSTR aLocation);
|
---|
593 | STDMETHOD(COMGETTER(Format)) (BSTR *aFormat);
|
---|
594 | STDMETHOD(COMGETTER(Created)) (BOOL *aCreated);
|
---|
595 |
|
---|
596 | // IVirtualDiskImage methods
|
---|
597 | STDMETHOD(CreateDynamicImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
598 | STDMETHOD(CreateFixedImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
599 | STDMETHOD(DeleteImage)();
|
---|
600 |
|
---|
601 | // public methods for internal purposes only
|
---|
602 |
|
---|
603 | const Bstr &Location() const { return mLocation; }
|
---|
604 |
|
---|
605 | HRESULT trySetRegistered (BOOL aRegistered);
|
---|
606 | HRESULT getAccessible (Bstr &aAccessError);
|
---|
607 |
|
---|
608 | HRESULT saveSettings (settings::Key &aHDNode, settings::Key &aStorageNode);
|
---|
609 |
|
---|
610 | Bstr toString (bool aShort = false);
|
---|
611 |
|
---|
612 | HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
613 | Progress *aProgress, bool &aDeleteTarget);
|
---|
614 | HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
615 | Progress *aProgress);
|
---|
616 |
|
---|
617 | // for VirtualBoxSupportErrorInfoImpl
|
---|
618 | static const wchar_t *getComponentName() { return L"CustomHardDisk"; }
|
---|
619 |
|
---|
620 | private:
|
---|
621 |
|
---|
622 | HRESULT setLocation (const BSTR aLocation);
|
---|
623 | HRESULT queryInformation (Bstr *aAccessError);
|
---|
624 | HRESULT createImage (ULONG64 aSize, BOOL aDynamic, IProgress **aProgress);
|
---|
625 |
|
---|
626 | /** VDI asynchronous operation thread function */
|
---|
627 | static DECLCALLBACK(int) VDITaskThread (RTTHREAD thread, void *pvUser);
|
---|
628 |
|
---|
629 | static DECLCALLBACK(void) VDError (void *pvUser, int rc, RT_SRC_POS_DECL,
|
---|
630 | const char *pszFormat, va_list va);
|
---|
631 |
|
---|
632 | enum State
|
---|
633 | {
|
---|
634 | NotCreated,
|
---|
635 | Created,
|
---|
636 | /* the following must be greater than Created */
|
---|
637 | Accessible,
|
---|
638 | };
|
---|
639 |
|
---|
640 | State mState;
|
---|
641 |
|
---|
642 | RTSEMEVENTMULTI mStateCheckSem;
|
---|
643 | ULONG mStateCheckWaiters;
|
---|
644 |
|
---|
645 | Bstr mDescription;
|
---|
646 |
|
---|
647 | ULONG64 mSize;
|
---|
648 | ULONG64 mActualSize;
|
---|
649 |
|
---|
650 | Bstr mLocation;
|
---|
651 | Bstr mLocationFull;
|
---|
652 | Bstr mFormat;
|
---|
653 |
|
---|
654 | PVBOXHDD mContainer;
|
---|
655 |
|
---|
656 | VDINTERFACE mInterfaceError;
|
---|
657 | VDINTERFACEERROR mInterfaceErrorCallbacks;
|
---|
658 |
|
---|
659 | Utf8Str mLastVDError;
|
---|
660 |
|
---|
661 | friend class HardDisk;
|
---|
662 | };
|
---|
663 |
|
---|
664 | ////////////////////////////////////////////////////////////////////////////////
|
---|
665 |
|
---|
666 | class ATL_NO_VTABLE HVHDImage :
|
---|
667 | public HardDisk,
|
---|
668 | public VirtualBoxSupportTranslation <HVHDImage>,
|
---|
669 | public IVHDImage
|
---|
670 | {
|
---|
671 |
|
---|
672 | public:
|
---|
673 |
|
---|
674 | VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HVHDImage)
|
---|
675 |
|
---|
676 | DECLARE_NOT_AGGREGATABLE(HVHDImage)
|
---|
677 |
|
---|
678 | DECLARE_PROTECT_FINAL_CONSTRUCT()
|
---|
679 |
|
---|
680 | BEGIN_COM_MAP(HVHDImage)
|
---|
681 | COM_INTERFACE_ENTRY(ISupportErrorInfo)
|
---|
682 | COM_INTERFACE_ENTRY(IHardDisk)
|
---|
683 | COM_INTERFACE_ENTRY(IVHDImage)
|
---|
684 | END_COM_MAP()
|
---|
685 |
|
---|
686 | NS_DECL_ISUPPORTS
|
---|
687 |
|
---|
688 | HRESULT FinalConstruct();
|
---|
689 | void FinalRelease();
|
---|
690 |
|
---|
691 | // public initializer/uninitializer for internal purposes only
|
---|
692 |
|
---|
693 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
694 | const settings::Key &aHDNode, const settings::Key &aVHDNode);
|
---|
695 | HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
|
---|
696 | INPTR BSTR aFilePath, BOOL aRegistered = FALSE);
|
---|
697 | void uninit();
|
---|
698 |
|
---|
699 | // IHardDisk properties
|
---|
700 | STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
|
---|
701 | STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
|
---|
702 | STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
|
---|
703 | STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
|
---|
704 |
|
---|
705 | // IVirtualDiskImage properties
|
---|
706 | STDMETHOD(COMGETTER(FilePath)) (BSTR *aFilePath);
|
---|
707 | STDMETHOD(COMSETTER(FilePath)) (INPTR BSTR aFilePath);
|
---|
708 | STDMETHOD(COMGETTER(Created)) (BOOL *aCreated);
|
---|
709 |
|
---|
710 | // IVirtualDiskImage methods
|
---|
711 | STDMETHOD(CreateDynamicImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
712 | STDMETHOD(CreateFixedImage) (ULONG64 aSize, IProgress **aProgress);
|
---|
713 | STDMETHOD(DeleteImage)();
|
---|
714 |
|
---|
715 | // public methods for internal purposes only
|
---|
716 |
|
---|
717 | const Bstr &filePath() const { return mFilePath; }
|
---|
718 | const Bstr &filePathFull() const { return mFilePathFull; }
|
---|
719 |
|
---|
720 | HRESULT trySetRegistered (BOOL aRegistered);
|
---|
721 | HRESULT getAccessible (Bstr &aAccessError);
|
---|
722 |
|
---|
723 | HRESULT saveSettings (settings::Key &aHDNode, settings::Key &aStorageNode);
|
---|
724 |
|
---|
725 | void updatePath (const char *aOldPath, const char *aNewPath);
|
---|
726 |
|
---|
727 | Bstr toString (bool aShort = false);
|
---|
728 |
|
---|
729 | HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
730 | Progress *aProgress, bool &aDeleteTarget);
|
---|
731 | HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
|
---|
732 | Progress *aProgress);
|
---|
733 |
|
---|
734 | // for VirtualBoxSupportErrorInfoImpl
|
---|
735 | static const wchar_t *getComponentName() { return L"VHDImage"; }
|
---|
736 |
|
---|
737 | private:
|
---|
738 |
|
---|
739 | HRESULT setFilePath (const BSTR aFilePath);
|
---|
740 | HRESULT queryInformation (Bstr *aAccessError);
|
---|
741 | HRESULT createImage (ULONG64 aSize, BOOL aDynamic, IProgress **aProgress);
|
---|
742 |
|
---|
743 | /** VDI asynchronous operation thread function */
|
---|
744 | static DECLCALLBACK(int) VDITaskThread (RTTHREAD thread, void *pvUser);
|
---|
745 |
|
---|
746 | static DECLCALLBACK(void) VDError (void *pvUser, int rc, RT_SRC_POS_DECL,
|
---|
747 | const char *pszFormat, va_list va);
|
---|
748 |
|
---|
749 | enum State
|
---|
750 | {
|
---|
751 | NotCreated,
|
---|
752 | Created,
|
---|
753 | /* the following must be greater than Created */
|
---|
754 | Accessible,
|
---|
755 | };
|
---|
756 |
|
---|
757 | State mState;
|
---|
758 |
|
---|
759 | RTSEMEVENTMULTI mStateCheckSem;
|
---|
760 | ULONG mStateCheckWaiters;
|
---|
761 |
|
---|
762 | Bstr mDescription;
|
---|
763 |
|
---|
764 | ULONG64 mSize;
|
---|
765 | ULONG64 mActualSize;
|
---|
766 |
|
---|
767 | Bstr mFilePath;
|
---|
768 | Bstr mFilePathFull;
|
---|
769 |
|
---|
770 | PVBOXHDD mContainer;
|
---|
771 |
|
---|
772 | VDINTERFACE mInterfaceError;
|
---|
773 | VDINTERFACEERROR mInterfaceErrorCallbacks;
|
---|
774 |
|
---|
775 | Utf8Str mLastVDError;
|
---|
776 |
|
---|
777 | friend class HardDisk;
|
---|
778 | };
|
---|
779 |
|
---|
780 |
|
---|
781 | COM_DECL_READONLY_ENUM_AND_COLLECTION (HardDisk)
|
---|
782 |
|
---|
783 | #endif // ____H_HARDDISKIMPL
|
---|