VirtualBox

source: vbox/trunk/src/VBox/Main/include/HardDiskImpl.h@ 255

Last change on this file since 255 was 132, checked in by vboxsync, 18 years ago

Main:

  • Prototyped IConsoleCallback::onRuntimeError();
  • All size parameters in IHardDisk are now ULONG64.

Frontends:

  • Updated according to the above.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.8 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung GmbH
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22#ifndef ____H_HARDDISKIMPL
23#define ____H_HARDDISKIMPL
24
25#include "VirtualBoxBase.h"
26#include "Collection.h"
27
28#include <VBox/cfgldr.h>
29
30#include <list>
31
32class VirtualBox;
33class Progress;
34class HVirtualDiskImage;
35
36////////////////////////////////////////////////////////////////////////////////
37
38class ATL_NO_VTABLE HardDisk :
39 public VirtualBoxSupportErrorInfoImpl <HardDisk, IHardDisk>,
40 public VirtualBoxSupportTranslation <HardDisk>,
41 public VirtualBoxBaseWithTypedChildren <HardDisk>,
42 public IHardDisk
43{
44
45public:
46
47 typedef VirtualBoxBaseWithTypedChildren <HardDisk>::DependentChildren
48 HardDiskList;
49
50 DECLARE_NOT_AGGREGATABLE(HardDisk)
51
52 DECLARE_PROTECT_FINAL_CONSTRUCT()
53
54 BEGIN_COM_MAP(HardDisk)
55 COM_INTERFACE_ENTRY(ISupportErrorInfo)
56 COM_INTERFACE_ENTRY(IHardDisk)
57 END_COM_MAP()
58
59 NS_DECL_ISUPPORTS
60
61 HRESULT FinalConstruct();
62 void FinalRelease();
63
64 /// @todo (dmik) remove
65 enum InitMode { Init_New, Init_Existing, Init_Registered };
66
67protected:
68
69 // protected initializer/uninitializer for internal purposes only
70 HRESULT protectedInit (VirtualBox *aVirtualBox, HardDisk *aParent);
71 void protectedUninit (AutoLock &alock);
72
73public:
74
75 // IHardDisk properties
76 STDMETHOD(COMGETTER(Id)) (GUIDPARAMOUT aId);
77 STDMETHOD(COMGETTER(StorageType)) (HardDiskStorageType_T *aStorageType);
78 STDMETHOD(COMGETTER(Location)) (BSTR *aLocation);
79 STDMETHOD(COMGETTER(Type)) (HardDiskType_T *aType);
80 STDMETHOD(COMSETTER(Type)) (HardDiskType_T aType);
81 STDMETHOD(COMGETTER(Parent)) (IHardDisk **aParent);
82 STDMETHOD(COMGETTER(Children)) (IHardDiskCollection **aChildren);
83 STDMETHOD(COMGETTER(Root)) (IHardDisk **aRoot);
84 STDMETHOD(COMGETTER(Accessible)) (BOOL *aAccessible);
85 STDMETHOD(COMGETTER(AllAccessible)) (BOOL *aAllAccessible);
86 STDMETHOD(COMGETTER(LastAccessError)) (BSTR *aLastAccessError);
87 STDMETHOD(COMGETTER(MachineId)) (GUIDPARAMOUT aMachineId);
88 STDMETHOD(COMGETTER(SnapshotId)) (GUIDPARAMOUT aSnapshotId);
89
90 // IHardDisk methods
91 STDMETHOD(CloneToImage) (INPTR BSTR aFilePath, IVirtualDiskImage **aImage,
92 IProgress **aProgress);
93
94 // public methods for internal purposes only
95
96 const Guid &id() const { return mId; }
97 HardDiskStorageType_T storageType() const { return mStorageType; }
98 HardDiskType_T type() const { return mType; }
99 const Guid &machineId() const { return mMachineId; }
100 const Guid &snapshotId() const { return mSnapshotId; }
101
102 void setMachineId (const Guid &aId) { mMachineId = aId; }
103 void setSnapshotId (const Guid &aId) { mSnapshotId = aId; }
104
105 bool isDifferencing() const
106 {
107 return mType == HardDiskType_NormalHardDisk &&
108 mStorageType == HardDiskStorageType_VirtualDiskImage &&
109 !mParent.isNull();
110 }
111 bool isParentImmutable() const
112 {
113 AutoLock parentLock (mParent);
114 return !mParent.isNull() && mParent->type() == HardDiskType_ImmutableHardDisk;
115 }
116
117 inline HVirtualDiskImage *asVDI();
118
119 ComObjPtr <HardDisk> parent() const { return static_cast <HardDisk *> (mParent); }
120
121 /** Shortcut to #dependentChildrenLock() */
122 AutoLock::Handle &childrenLock() const { return dependentChildrenLock(); }
123
124 /**
125 * Shortcut to #dependentChildren().
126 * Do |AutoLock alock (childrenLock());| before acceessing the returned list!
127 */
128 const HardDiskList &children() const { return dependentChildren(); }
129
130 ComObjPtr <HardDisk> root() const;
131
132 // virtual methods that need to be [re]implemented by every subclass
133
134 virtual HRESULT trySetRegistered (BOOL aRegistered);
135 virtual HRESULT getAccessible (Bstr &aAccessError);
136
137 virtual HRESULT saveSettings (CFGNODE aHDNode, CFGNODE aStorageNode) = 0;
138
139 virtual void updatePath (const char *aOldPath, const char *aNewPath) {}
140
141 virtual Bstr toString (bool aShort = false) = 0;
142 virtual bool sameAs (HardDisk *that);
143
144 virtual HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
145 Progress *aProgress) = 0;
146 virtual HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
147 Progress *aProgress) = 0;
148public:
149
150 void setBusy();
151 void clearBusy();
152 void addReader();
153 void releaseReader();
154 void addReaderOnAncestors();
155 void releaseReaderOnAncestors();
156 bool hasForeignChildren();
157
158 HRESULT setBusyWithChildren();
159 void clearBusyWithChildren();
160 HRESULT getAccessibleWithChildren (Bstr &aAccessError);
161
162 HRESULT checkConsistency();
163
164 HRESULT createDiffHardDisk (const Bstr &aFolder, const Guid &aMachineId,
165 ComObjPtr <HVirtualDiskImage> &aHardDisk,
166 Progress *aProgress);
167
168 void updatePaths (const char *aOldPath, const char *aNewPath);
169
170 bool isBusy() { AutoLock alock (this); return mBusy; }
171 unsigned readers() { AutoLock alock (this); return mReaders; }
172
173 // for VirtualBoxSupportErrorInfoImpl
174 static const wchar_t *getComponentName() { return L"HardDisk"; }
175
176protected:
177
178 HRESULT loadSettings (CFGNODE aHDNode);
179 HRESULT saveSettings (CFGNODE aHDNode);
180
181 /** weak VirualBox parent */
182 ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox;
183
184 BOOL mRegistered;
185
186 ComObjPtr <HardDisk, ComWeakRef> mParent;
187
188 Guid mId;
189 HardDiskStorageType_T mStorageType;
190 HardDiskType_T mType;
191 Guid mMachineId;
192 Guid mSnapshotId;
193
194private:
195
196 Bstr mLastAccessError;
197
198 bool mBusy;
199 unsigned mReaders;
200};
201
202////////////////////////////////////////////////////////////////////////////////
203
204class ATL_NO_VTABLE HVirtualDiskImage :
205 public HardDisk,
206 public VirtualBoxSupportTranslation <HVirtualDiskImage>,
207 public IVirtualDiskImage
208{
209
210public:
211
212 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HVirtualDiskImage)
213
214 DECLARE_NOT_AGGREGATABLE(HVirtualDiskImage)
215
216 DECLARE_PROTECT_FINAL_CONSTRUCT()
217
218 BEGIN_COM_MAP(HVirtualDiskImage)
219 COM_INTERFACE_ENTRY(ISupportErrorInfo)
220 COM_INTERFACE_ENTRY(IHardDisk)
221 COM_INTERFACE_ENTRY(IVirtualDiskImage)
222 END_COM_MAP()
223
224 NS_DECL_ISUPPORTS
225
226 HRESULT FinalConstruct();
227 void FinalRelease();
228
229 // public initializer/uninitializer for internal purposes only
230
231 HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
232 CFGNODE aHDNode, CFGNODE aVDINode);
233 HRESULT init (VirtualBox *aVirtualBox, HardDisk *aParent,
234 const BSTR aFilePath, BOOL aRegistered = FALSE);
235 void uninit();
236
237 // IHardDisk properties
238 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
239 STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
240 STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
241 STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
242
243 // IVirtualDiskImage properties
244 STDMETHOD(COMGETTER(FilePath)) (BSTR *aFilePath);
245 STDMETHOD(COMSETTER(FilePath)) (INPTR BSTR aFilePath);
246 STDMETHOD(COMGETTER(Created)) (BOOL *aCreated);
247
248 // IVirtualDiskImage methods
249 STDMETHOD(CreateDynamicImage) (ULONG64 aSize, IProgress **aProgress);
250 STDMETHOD(CreateFixedImage) (ULONG64 aSize, IProgress **aProgress);
251 STDMETHOD(DeleteImage)();
252
253 // public methods for internal purposes only
254
255 const Bstr &filePath() const { return mFilePath; }
256 const Bstr &filePathFull() const { return mFilePathFull; }
257
258 HRESULT trySetRegistered (BOOL aRegistered);
259 HRESULT getAccessible (Bstr &aAccessError);
260
261 HRESULT saveSettings (CFGNODE aHDNode, CFGNODE aStorageNode);
262
263 void updatePath (const char *aOldPath, const char *aNewPath);
264
265 Bstr toString (bool aShort = false);
266
267 HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
268 Progress *aProgress);
269 HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
270 Progress *aProgress);
271
272 HRESULT cloneDiffImage (const Bstr &aFolder, const Guid &aMachineId,
273 ComObjPtr <HVirtualDiskImage> &aHardDisk,
274 Progress *aProgress);
275
276 HRESULT mergeImageToParent (Progress *aProgress);
277 HRESULT mergeImageToChildren (Progress *aProgress);
278
279 HRESULT wipeOutImage();
280
281 // for VirtualBoxSupportErrorInfoImpl
282 static const wchar_t *getComponentName() { return L"VirtualDiskImage"; }
283
284private:
285
286 HRESULT setFilePath (const BSTR aFilePath);
287 HRESULT queryInformation (Bstr *aAccessError);
288 HRESULT createImage (ULONG64 aSize, BOOL aDynamic, IProgress **aProgress);
289
290 /** VDI asynchronous operation thread function */
291 static DECLCALLBACK(int) vdiTaskThread (RTTHREAD thread, void *pvUser);
292
293 enum State
294 {
295 NotCreated,
296 Created,
297 Accessible, // must be greater than Created
298 };
299
300 State mState;
301
302 Bstr mDescription;
303
304 ULONG64 mSize;
305 ULONG64 mActualSize;
306
307 Bstr mFilePath;
308 Bstr mFilePathFull;
309
310 friend class HardDisk;
311};
312
313// dependent inline members
314////////////////////////////////////////////////////////////////////////////////
315
316inline HVirtualDiskImage *HardDisk::asVDI()
317{
318 AssertReturn (mStorageType == HardDiskStorageType_VirtualDiskImage, 0);
319 return static_cast <HVirtualDiskImage *> (this);
320}
321
322////////////////////////////////////////////////////////////////////////////////
323
324class ATL_NO_VTABLE HISCSIHardDisk :
325 public HardDisk,
326 public VirtualBoxSupportTranslation <HISCSIHardDisk>,
327 public IISCSIHardDisk
328{
329
330public:
331
332 VIRTUALBOXSUPPORTTRANSLATION_OVERRIDE(HISCSIHardDisk)
333
334 DECLARE_NOT_AGGREGATABLE(HISCSIHardDisk)
335
336 DECLARE_PROTECT_FINAL_CONSTRUCT()
337
338 BEGIN_COM_MAP(HISCSIHardDisk)
339 COM_INTERFACE_ENTRY(ISupportErrorInfo)
340 COM_INTERFACE_ENTRY(IHardDisk)
341 COM_INTERFACE_ENTRY(IISCSIHardDisk)
342 END_COM_MAP()
343
344 NS_DECL_ISUPPORTS
345
346 HRESULT FinalConstruct();
347 void FinalRelease();
348
349 // public initializer/uninitializer for internal purposes only
350
351 HRESULT init (VirtualBox *aVirtualBox,
352 CFGNODE aHDNode, CFGNODE aISCSINode);
353 HRESULT init (VirtualBox *aVirtualBox);
354 void uninit();
355
356 // IHardDisk properties
357 STDMETHOD(COMGETTER(Description)) (BSTR *aDescription);
358 STDMETHOD(COMSETTER(Description)) (INPTR BSTR aDescription);
359 STDMETHOD(COMGETTER(Size)) (ULONG64 *aSize);
360 STDMETHOD(COMGETTER(ActualSize)) (ULONG64 *aActualSize);
361
362 // IISCSIHardDisk properties
363 STDMETHOD(COMGETTER(Server)) (BSTR *aServer);
364 STDMETHOD(COMSETTER(Server)) (INPTR BSTR aServer);
365 STDMETHOD(COMGETTER(Port)) (USHORT *aPort);
366 STDMETHOD(COMSETTER(Port)) (USHORT aPort);
367 STDMETHOD(COMGETTER(Target)) (BSTR *aTarget);
368 STDMETHOD(COMSETTER(Target)) (INPTR BSTR aTarget);
369 STDMETHOD(COMGETTER(Lun)) (ULONG64 *aLun);
370 STDMETHOD(COMSETTER(Lun)) (ULONG64 aLun);
371 STDMETHOD(COMGETTER(UserName)) (BSTR *aUserName);
372 STDMETHOD(COMSETTER(UserName)) (INPTR BSTR aUserName);
373 STDMETHOD(COMGETTER(Password)) (BSTR *aPassword);
374 STDMETHOD(COMSETTER(Password)) (INPTR BSTR aPassword);
375
376 // public methods for internal purposes only
377
378 const Bstr &server() const { return mServer; }
379 USHORT port() const { return mPort; }
380 const Bstr &target() const { return mTarget; }
381 ULONG64 lun() const { return mLun; }
382 const Bstr &userName() const { return mUserName; }
383 const Bstr &password() const { return mPassword; }
384
385 HRESULT trySetRegistered (BOOL aRegistered);
386 HRESULT getAccessible (Bstr &aAccessError);
387
388 HRESULT saveSettings (CFGNODE aHDNode, CFGNODE aStorageNode);
389
390 Bstr toString (bool aShort = false);
391
392 HRESULT cloneToImage (const Guid &aId, const Utf8Str &aTargetPath,
393 Progress *aProgress);
394 HRESULT createDiffImage (const Guid &aId, const Utf8Str &aTargetPath,
395 Progress *aProgress);
396
397public:
398
399 // for VirtualBoxSupportErrorInfoImpl
400 static const wchar_t *getComponentName() { return L"ISCSIHardDisk"; }
401
402private:
403
404 HRESULT queryInformation (Bstr &aAccessError);
405
406 Bstr mDescription;
407
408 ULONG64 mSize;
409 ULONG64 mActualSize;
410
411 Bstr mServer;
412 USHORT mPort;
413 Bstr mTarget;
414 ULONG64 mLun;
415 Bstr mUserName;
416 Bstr mPassword;
417};
418
419
420COM_DECL_READONLY_ENUM_AND_COLLECTION (HardDisk)
421
422#endif // ____H_HARDDISKIMPL
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