1 | /* $Id: GuestFileImpl.h 78666 2019-05-22 15:27:27Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox Main - Guest file handling implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2019 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef MAIN_INCLUDED_GuestFileImpl_h
|
---|
19 | #define MAIN_INCLUDED_GuestFileImpl_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include "VirtualBoxBase.h"
|
---|
25 | #include "EventImpl.h"
|
---|
26 |
|
---|
27 | #include "GuestCtrlImplPrivate.h"
|
---|
28 | #include "GuestFileWrap.h"
|
---|
29 |
|
---|
30 | class Console;
|
---|
31 | class GuestSession;
|
---|
32 | class GuestProcess;
|
---|
33 |
|
---|
34 | class ATL_NO_VTABLE GuestFile :
|
---|
35 | public GuestFileWrap,
|
---|
36 | public GuestObject
|
---|
37 | {
|
---|
38 | public:
|
---|
39 | /** @name COM and internal init/term/mapping cruft.
|
---|
40 | * @{ */
|
---|
41 | DECLARE_EMPTY_CTOR_DTOR(GuestFile)
|
---|
42 |
|
---|
43 | int init(Console *pConsole, GuestSession *pSession, ULONG uFileID, const GuestFileOpenInfo &openInfo);
|
---|
44 | void uninit(void);
|
---|
45 |
|
---|
46 | HRESULT FinalConstruct(void);
|
---|
47 | void FinalRelease(void);
|
---|
48 | /** @} */
|
---|
49 |
|
---|
50 | public:
|
---|
51 | /** @name Implemented virtual methods from GuestObject.
|
---|
52 | * @{ */
|
---|
53 | int i_callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
54 | int i_onUnregister(void);
|
---|
55 | int i_onSessionStatusChange(GuestSessionStatus_T enmSessionStatus);
|
---|
56 | /** @} */
|
---|
57 |
|
---|
58 | public:
|
---|
59 | /** @name Public internal methods.
|
---|
60 | * @{ */
|
---|
61 | int i_closeFile(int *pGuestRc);
|
---|
62 | EventSource *i_getEventSource(void) { return mEventSource; }
|
---|
63 | static const char *i_guestVrcToString(int guestRc);
|
---|
64 | static Utf8Str i_guestErrorToString(int guestRc);
|
---|
65 | int i_onFileNotify(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
66 | int i_onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
67 | int i_openFile(uint32_t uTimeoutMS, int *pGuestRc);
|
---|
68 | int i_queryInfo(GuestFsObjData &objData, int *prcGuest);
|
---|
69 | int i_readData(uint32_t uSize, uint32_t uTimeoutMS, void* pvData, uint32_t cbData, uint32_t* pcbRead);
|
---|
70 | int i_readDataAt(uint64_t uOffset, uint32_t uSize, uint32_t uTimeoutMS,
|
---|
71 | void* pvData, size_t cbData, size_t* pcbRead);
|
---|
72 | int i_seekAt(int64_t iOffset, GUEST_FILE_SEEKTYPE eSeekType, uint32_t uTimeoutMS, uint64_t *puOffset);
|
---|
73 | static HRESULT i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
|
---|
74 | int i_setFileStatus(FileStatus_T fileStatus, int fileRc);
|
---|
75 | int i_waitForOffsetChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint64_t *puOffset);
|
---|
76 | int i_waitForRead(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead);
|
---|
77 | int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, FileStatus_T *pFileStatus, int *pGuestRc);
|
---|
78 | int i_waitForWrite(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint32_t *pcbWritten);
|
---|
79 | int i_writeData(uint32_t uTimeoutMS, const void *pvData, uint32_t cbData, uint32_t *pcbWritten);
|
---|
80 | int i_writeDataAt(uint64_t uOffset, uint32_t uTimeoutMS, const void *pvData, uint32_t cbData, uint32_t *pcbWritten);
|
---|
81 | /** @} */
|
---|
82 |
|
---|
83 | private:
|
---|
84 |
|
---|
85 | /** @name Wrapped IGuestFile properties.
|
---|
86 | * @{ */
|
---|
87 | HRESULT getCreationMode(ULONG *aCreationMode);
|
---|
88 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
89 | HRESULT getId(ULONG *aId);
|
---|
90 | HRESULT getInitialSize(LONG64 *aInitialSize);
|
---|
91 | HRESULT getOffset(LONG64 *aOffset);
|
---|
92 | HRESULT getStatus(FileStatus_T *aStatus);
|
---|
93 | HRESULT getFilename(com::Utf8Str &aFilename);
|
---|
94 | HRESULT getAccessMode(FileAccessMode_T *aAccessMode);
|
---|
95 | HRESULT getOpenAction(FileOpenAction_T *aOpenAction);
|
---|
96 | /** @} */
|
---|
97 |
|
---|
98 | /** @name Wrapped IGuestFile methods.
|
---|
99 | * @{ */
|
---|
100 | HRESULT close();
|
---|
101 | HRESULT queryInfo(ComPtr<IFsObjInfo> &aObjInfo);
|
---|
102 | HRESULT querySize(LONG64 *aSize);
|
---|
103 | HRESULT read(ULONG aToRead,
|
---|
104 | ULONG aTimeoutMS,
|
---|
105 | std::vector<BYTE> &aData);
|
---|
106 | HRESULT readAt(LONG64 aOffset,
|
---|
107 | ULONG aToRead,
|
---|
108 | ULONG aTimeoutMS,
|
---|
109 | std::vector<BYTE> &aData);
|
---|
110 | HRESULT seek(LONG64 aOffset,
|
---|
111 | FileSeekOrigin_T aWhence,
|
---|
112 | LONG64 *aNewOffset);
|
---|
113 | HRESULT setACL(const com::Utf8Str &aAcl,
|
---|
114 | ULONG aMode);
|
---|
115 | HRESULT setSize(LONG64 aSize);
|
---|
116 | HRESULT write(const std::vector<BYTE> &aData,
|
---|
117 | ULONG aTimeoutMS,
|
---|
118 | ULONG *aWritten);
|
---|
119 | HRESULT writeAt(LONG64 aOffset,
|
---|
120 | const std::vector<BYTE> &aData,
|
---|
121 | ULONG aTimeoutMS,
|
---|
122 | ULONG *aWritten);
|
---|
123 | /** @} */
|
---|
124 |
|
---|
125 | /** This can safely be used without holding any locks.
|
---|
126 | * An AutoCaller suffices to prevent it being destroy while in use and
|
---|
127 | * internally there is a lock providing the necessary serialization. */
|
---|
128 | const ComObjPtr<EventSource> mEventSource;
|
---|
129 |
|
---|
130 | struct Data
|
---|
131 | {
|
---|
132 | /** The file's open info. */
|
---|
133 | GuestFileOpenInfo mOpenInfo;
|
---|
134 | /** The file's initial size on open. */
|
---|
135 | uint64_t mInitialSize;
|
---|
136 | /** The current file status. */
|
---|
137 | FileStatus_T mStatus;
|
---|
138 | /** The last returned process status
|
---|
139 | * returned from the guest side. */
|
---|
140 | int mLastError;
|
---|
141 | /** The file's current offset. */
|
---|
142 | uint64_t mOffCurrent;
|
---|
143 | } mData;
|
---|
144 | };
|
---|
145 |
|
---|
146 | #endif /* !MAIN_INCLUDED_GuestFileImpl_h */
|
---|
147 |
|
---|