1 |
|
---|
2 | /* $Id: GuestFileImpl.cpp 42848 2012-08-16 13:49:50Z vboxsync $ */
|
---|
3 | /** @file
|
---|
4 | * VirtualBox Main - XXX.
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2012 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 |
|
---|
20 | /*******************************************************************************
|
---|
21 | * Header Files *
|
---|
22 | *******************************************************************************/
|
---|
23 | #include "GuestFileImpl.h"
|
---|
24 | #include "GuestSessionImpl.h"
|
---|
25 | #include "GuestCtrlImplPrivate.h"
|
---|
26 |
|
---|
27 | #include "Global.h"
|
---|
28 | #include "AutoCaller.h"
|
---|
29 |
|
---|
30 | #include <VBox/com/array.h>
|
---|
31 |
|
---|
32 |
|
---|
33 | // constructor / destructor
|
---|
34 | /////////////////////////////////////////////////////////////////////////////
|
---|
35 |
|
---|
36 | DEFINE_EMPTY_CTOR_DTOR(GuestFile)
|
---|
37 |
|
---|
38 | HRESULT GuestFile::FinalConstruct()
|
---|
39 | {
|
---|
40 | LogFlowThisFunc(("\n"));
|
---|
41 | return BaseFinalConstruct();
|
---|
42 | }
|
---|
43 |
|
---|
44 | void GuestFile::FinalRelease(void)
|
---|
45 | {
|
---|
46 | LogFlowThisFuncEnter();
|
---|
47 | uninit();
|
---|
48 | BaseFinalRelease();
|
---|
49 | LogFlowThisFuncLeave();
|
---|
50 | }
|
---|
51 |
|
---|
52 | // public initializer/uninitializer for internal purposes only
|
---|
53 | /////////////////////////////////////////////////////////////////////////////
|
---|
54 |
|
---|
55 | int GuestFile::init(GuestSession *pSession, const Utf8Str &strPath,
|
---|
56 | const Utf8Str &strOpenMode, const Utf8Str &strDisposition, uint32_t uCreationMode,
|
---|
57 | int64_t iOffset)
|
---|
58 | {
|
---|
59 | /* Enclose the state transition NotReady->InInit->Ready. */
|
---|
60 | AutoInitSpan autoInitSpan(this);
|
---|
61 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
62 |
|
---|
63 | mData.mSession = pSession;
|
---|
64 | mData.mCreationMode = uCreationMode;
|
---|
65 | mData.mDisposition = GuestFile::getDispositionFromString(strDisposition);
|
---|
66 | mData.mFileName = strPath;
|
---|
67 | mData.mInitialSize = 0;
|
---|
68 | mData.mOpenMode = GuestFile::getOpenModeFromString(strOpenMode);
|
---|
69 | mData.mOffset = iOffset;
|
---|
70 |
|
---|
71 | /** @todo Validate parameters! */
|
---|
72 |
|
---|
73 | /* Confirm a successful initialization when it's the case. */
|
---|
74 | autoInitSpan.setSucceeded();
|
---|
75 |
|
---|
76 | return VINF_SUCCESS;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Uninitializes the instance.
|
---|
81 | * Called from FinalRelease().
|
---|
82 | */
|
---|
83 | void GuestFile::uninit(void)
|
---|
84 | {
|
---|
85 | LogFlowThisFunc(("\n"));
|
---|
86 |
|
---|
87 | /* Enclose the state transition Ready->InUninit->NotReady. */
|
---|
88 | AutoUninitSpan autoUninitSpan(this);
|
---|
89 | if (autoUninitSpan.uninitDone())
|
---|
90 | return;
|
---|
91 |
|
---|
92 | mData.mSession->fileClose(this);
|
---|
93 | }
|
---|
94 |
|
---|
95 | // implementation of public getters/setters for attributes
|
---|
96 | /////////////////////////////////////////////////////////////////////////////
|
---|
97 |
|
---|
98 | STDMETHODIMP GuestFile::COMGETTER(CreationMode)(ULONG *aCreationMode)
|
---|
99 | {
|
---|
100 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
101 | ReturnComNotImplemented();
|
---|
102 | #else
|
---|
103 | AutoCaller autoCaller(this);
|
---|
104 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
105 |
|
---|
106 | CheckComArgOutPointerValid(aCreationMode);
|
---|
107 |
|
---|
108 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
109 |
|
---|
110 | *aCreationMode = mData.mCreationMode;
|
---|
111 |
|
---|
112 | return S_OK;
|
---|
113 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
114 | }
|
---|
115 |
|
---|
116 | STDMETHODIMP GuestFile::COMGETTER(Disposition)(ULONG *aDisposition)
|
---|
117 | {
|
---|
118 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
119 | ReturnComNotImplemented();
|
---|
120 | #else
|
---|
121 | AutoCaller autoCaller(this);
|
---|
122 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
123 |
|
---|
124 | CheckComArgOutPointerValid(aDisposition);
|
---|
125 |
|
---|
126 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
127 |
|
---|
128 | *aDisposition = mData.mDisposition;
|
---|
129 |
|
---|
130 | return S_OK;
|
---|
131 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
132 | }
|
---|
133 |
|
---|
134 | STDMETHODIMP GuestFile::COMGETTER(FileName)(BSTR *aFileName)
|
---|
135 | {
|
---|
136 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
137 | ReturnComNotImplemented();
|
---|
138 | #else
|
---|
139 | AutoCaller autoCaller(this);
|
---|
140 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
141 |
|
---|
142 | CheckComArgOutPointerValid(aFileName);
|
---|
143 |
|
---|
144 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
145 |
|
---|
146 | mData.mFileName.cloneTo(aFileName);
|
---|
147 |
|
---|
148 | return S_OK;
|
---|
149 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
150 | }
|
---|
151 |
|
---|
152 | STDMETHODIMP GuestFile::COMGETTER(InitialSize)(LONG64 *aInitialSize)
|
---|
153 | {
|
---|
154 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
155 | ReturnComNotImplemented();
|
---|
156 | #else
|
---|
157 | AutoCaller autoCaller(this);
|
---|
158 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
159 |
|
---|
160 | CheckComArgOutPointerValid(aInitialSize);
|
---|
161 |
|
---|
162 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
163 |
|
---|
164 | *aInitialSize = mData.mInitialSize;
|
---|
165 |
|
---|
166 | return S_OK;
|
---|
167 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
168 | }
|
---|
169 |
|
---|
170 | STDMETHODIMP GuestFile::COMGETTER(Offset)(LONG64 *aOffset)
|
---|
171 | {
|
---|
172 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
173 | ReturnComNotImplemented();
|
---|
174 | #else
|
---|
175 | AutoCaller autoCaller(this);
|
---|
176 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
177 |
|
---|
178 | CheckComArgOutPointerValid(aOffset);
|
---|
179 |
|
---|
180 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
181 |
|
---|
182 | *aOffset = mData.mOffset;
|
---|
183 |
|
---|
184 | return S_OK;
|
---|
185 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
186 | }
|
---|
187 |
|
---|
188 | STDMETHODIMP GuestFile::COMGETTER(OpenMode)(ULONG *aOpenMode)
|
---|
189 | {
|
---|
190 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
191 | ReturnComNotImplemented();
|
---|
192 | #else
|
---|
193 | AutoCaller autoCaller(this);
|
---|
194 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
195 |
|
---|
196 | CheckComArgOutPointerValid(aOpenMode);
|
---|
197 |
|
---|
198 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
199 |
|
---|
200 | *aOpenMode = mData.mOpenMode;
|
---|
201 |
|
---|
202 | return S_OK;
|
---|
203 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
204 | }
|
---|
205 |
|
---|
206 | // private methods
|
---|
207 | /////////////////////////////////////////////////////////////////////////////
|
---|
208 |
|
---|
209 | /* static */
|
---|
210 | uint32_t GuestFile::getDispositionFromString(const Utf8Str &strDisposition)
|
---|
211 | {
|
---|
212 | return 0; /** @todo Implement me! */
|
---|
213 | }
|
---|
214 |
|
---|
215 | /* static */
|
---|
216 | uint32_t GuestFile::getOpenModeFromString(const Utf8Str &strOpenMode)
|
---|
217 | {
|
---|
218 | return 0; /** @todo Implement me! */
|
---|
219 | }
|
---|
220 |
|
---|
221 | // implementation of public methods
|
---|
222 | /////////////////////////////////////////////////////////////////////////////
|
---|
223 |
|
---|
224 | STDMETHODIMP GuestFile::Close(void)
|
---|
225 | {
|
---|
226 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
227 | ReturnComNotImplemented();
|
---|
228 | #else
|
---|
229 | LogFlowThisFuncEnter();
|
---|
230 |
|
---|
231 | uninit();
|
---|
232 |
|
---|
233 | LogFlowThisFuncLeave();
|
---|
234 | return S_OK;
|
---|
235 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
236 | }
|
---|
237 |
|
---|
238 | STDMETHODIMP GuestFile::QueryInfo(IFsObjInfo **aInfo)
|
---|
239 | {
|
---|
240 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
241 | ReturnComNotImplemented();
|
---|
242 | #else
|
---|
243 | AutoCaller autoCaller(this);
|
---|
244 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
245 |
|
---|
246 | ReturnComNotImplemented();
|
---|
247 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
248 | }
|
---|
249 |
|
---|
250 | STDMETHODIMP GuestFile::Read(ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData))
|
---|
251 | {
|
---|
252 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
253 | ReturnComNotImplemented();
|
---|
254 | #else
|
---|
255 | AutoCaller autoCaller(this);
|
---|
256 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
257 |
|
---|
258 | ReturnComNotImplemented();
|
---|
259 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
260 | }
|
---|
261 |
|
---|
262 | STDMETHODIMP GuestFile::ReadAt(LONG64 aOffset, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData))
|
---|
263 | {
|
---|
264 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
265 | ReturnComNotImplemented();
|
---|
266 | #else
|
---|
267 | AutoCaller autoCaller(this);
|
---|
268 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
269 |
|
---|
270 | ReturnComNotImplemented();
|
---|
271 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
272 | }
|
---|
273 |
|
---|
274 | STDMETHODIMP GuestFile::Seek(LONG64 aOffset, FileSeekType_T aType)
|
---|
275 | {
|
---|
276 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
277 | ReturnComNotImplemented();
|
---|
278 | #else
|
---|
279 | AutoCaller autoCaller(this);
|
---|
280 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
281 |
|
---|
282 | ReturnComNotImplemented();
|
---|
283 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
284 | }
|
---|
285 |
|
---|
286 | STDMETHODIMP GuestFile::SetACL(IN_BSTR aACL)
|
---|
287 | {
|
---|
288 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
289 | ReturnComNotImplemented();
|
---|
290 | #else
|
---|
291 | AutoCaller autoCaller(this);
|
---|
292 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
293 |
|
---|
294 | ReturnComNotImplemented();
|
---|
295 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
296 | }
|
---|
297 |
|
---|
298 | STDMETHODIMP GuestFile::Write(ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten)
|
---|
299 | {
|
---|
300 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
301 | ReturnComNotImplemented();
|
---|
302 | #else
|
---|
303 | AutoCaller autoCaller(this);
|
---|
304 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
305 |
|
---|
306 | ReturnComNotImplemented();
|
---|
307 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
308 | }
|
---|
309 |
|
---|
310 | STDMETHODIMP GuestFile::WriteAt(LONG64 aOffset, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten)
|
---|
311 | {
|
---|
312 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
313 | ReturnComNotImplemented();
|
---|
314 | #else
|
---|
315 | AutoCaller autoCaller(this);
|
---|
316 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
317 |
|
---|
318 | ReturnComNotImplemented();
|
---|
319 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
320 | }
|
---|
321 |
|
---|