[42084] | 1 | /* $Id: GuestFileImpl.h 104001 2024-03-22 16:03:33Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[51321] | 3 | * VirtualBox Main - Guest file handling implementation.
|
---|
[42084] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[42084] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[42084] | 26 | */
|
---|
| 27 |
|
---|
[76562] | 28 | #ifndef MAIN_INCLUDED_GuestFileImpl_h
|
---|
| 29 | #define MAIN_INCLUDED_GuestFileImpl_h
|
---|
[76487] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
[42084] | 33 |
|
---|
| 34 | #include "VirtualBoxBase.h"
|
---|
[45415] | 35 | #include "EventImpl.h"
|
---|
[42084] | 36 |
|
---|
[44863] | 37 | #include "GuestCtrlImplPrivate.h"
|
---|
[50618] | 38 | #include "GuestFileWrap.h"
|
---|
[42084] | 39 |
|
---|
[44863] | 40 | class Console;
|
---|
[42611] | 41 | class GuestSession;
|
---|
| 42 | class GuestProcess;
|
---|
| 43 |
|
---|
[42084] | 44 | class ATL_NO_VTABLE GuestFile :
|
---|
[50618] | 45 | public GuestFileWrap,
|
---|
| 46 | public GuestObject
|
---|
[42084] | 47 | {
|
---|
| 48 | public:
|
---|
| 49 | /** @name COM and internal init/term/mapping cruft.
|
---|
| 50 | * @{ */
|
---|
[90828] | 51 | DECLARE_COMMON_CLASS_METHODS(GuestFile)
|
---|
[42084] | 52 |
|
---|
[44863] | 53 | int init(Console *pConsole, GuestSession *pSession, ULONG uFileID, const GuestFileOpenInfo &openInfo);
|
---|
[42084] | 54 | void uninit(void);
|
---|
[50618] | 55 |
|
---|
[42084] | 56 | HRESULT FinalConstruct(void);
|
---|
| 57 | void FinalRelease(void);
|
---|
| 58 | /** @} */
|
---|
| 59 |
|
---|
[42611] | 60 | public:
|
---|
[77587] | 61 | /** @name Implemented virtual methods from GuestObject.
|
---|
| 62 | * @{ */
|
---|
| 63 | int i_callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
|
---|
| 64 | int i_onUnregister(void);
|
---|
| 65 | int i_onSessionStatusChange(GuestSessionStatus_T enmSessionStatus);
|
---|
| 66 | /** @} */
|
---|
| 67 |
|
---|
| 68 | public:
|
---|
[42611] | 69 | /** @name Public internal methods.
|
---|
| 70 | * @{ */
|
---|
[104001] | 71 | int i_close(int *pGuestRc);
|
---|
[50618] | 72 | EventSource *i_getEventSource(void) { return mEventSource; }
|
---|
[104001] | 73 | int i_onNotify(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
[50618] | 74 | int i_onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
|
---|
[104001] | 75 | int i_open(uint32_t uTimeoutMS, int *pGuestRc);
|
---|
[71782] | 76 | int i_queryInfo(GuestFsObjData &objData, int *prcGuest);
|
---|
[50618] | 77 | int i_readData(uint32_t uSize, uint32_t uTimeoutMS, void* pvData, uint32_t cbData, uint32_t* pcbRead);
|
---|
[50874] | 78 | int i_readDataAt(uint64_t uOffset, uint32_t uSize, uint32_t uTimeoutMS,
|
---|
| 79 | void* pvData, size_t cbData, size_t* pcbRead);
|
---|
[50618] | 80 | int i_seekAt(int64_t iOffset, GUEST_FILE_SEEKTYPE eSeekType, uint32_t uTimeoutMS, uint64_t *puOffset);
|
---|
[98278] | 81 | int i_setFileStatus(FileStatus_T fileStatus, int vrcFile);
|
---|
[50618] | 82 | int i_waitForOffsetChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint64_t *puOffset);
|
---|
| 83 | int i_waitForRead(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead);
|
---|
| 84 | int i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, FileStatus_T *pFileStatus, int *pGuestRc);
|
---|
| 85 | int i_waitForWrite(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint32_t *pcbWritten);
|
---|
[77387] | 86 | int i_writeData(uint32_t uTimeoutMS, const void *pvData, uint32_t cbData, uint32_t *pcbWritten);
|
---|
| 87 | int i_writeDataAt(uint64_t uOffset, uint32_t uTimeoutMS, const void *pvData, uint32_t cbData, uint32_t *pcbWritten);
|
---|
[42611] | 88 | /** @} */
|
---|
| 89 |
|
---|
[84648] | 90 | /** @name Static helper methods.
|
---|
| 91 | * @{ */
|
---|
| 92 | static Utf8Str i_guestErrorToString(int guestRc, const char *pcszWhat);
|
---|
| 93 | /** @} */
|
---|
| 94 |
|
---|
[97626] | 95 | public:
|
---|
[42084] | 96 |
|
---|
[55631] | 97 | /** @name Wrapped IGuestFile properties.
|
---|
[51321] | 98 | * @{ */
|
---|
[50618] | 99 | HRESULT getCreationMode(ULONG *aCreationMode);
|
---|
| 100 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
| 101 | HRESULT getId(ULONG *aId);
|
---|
| 102 | HRESULT getInitialSize(LONG64 *aInitialSize);
|
---|
| 103 | HRESULT getOffset(LONG64 *aOffset);
|
---|
| 104 | HRESULT getStatus(FileStatus_T *aStatus);
|
---|
[75926] | 105 | HRESULT getFilename(com::Utf8Str &aFilename);
|
---|
[55631] | 106 | HRESULT getAccessMode(FileAccessMode_T *aAccessMode);
|
---|
| 107 | HRESULT getOpenAction(FileOpenAction_T *aOpenAction);
|
---|
[51321] | 108 | /** @} */
|
---|
[50618] | 109 |
|
---|
[55631] | 110 | /** @name Wrapped IGuestFile methods.
|
---|
[51321] | 111 | * @{ */
|
---|
[50618] | 112 | HRESULT close();
|
---|
| 113 | HRESULT queryInfo(ComPtr<IFsObjInfo> &aObjInfo);
|
---|
[55631] | 114 | HRESULT querySize(LONG64 *aSize);
|
---|
[50618] | 115 | HRESULT read(ULONG aToRead,
|
---|
| 116 | ULONG aTimeoutMS,
|
---|
| 117 | std::vector<BYTE> &aData);
|
---|
| 118 | HRESULT readAt(LONG64 aOffset,
|
---|
| 119 | ULONG aToRead,
|
---|
| 120 | ULONG aTimeoutMS,
|
---|
| 121 | std::vector<BYTE> &aData);
|
---|
| 122 | HRESULT seek(LONG64 aOffset,
|
---|
[55631] | 123 | FileSeekOrigin_T aWhence,
|
---|
| 124 | LONG64 *aNewOffset);
|
---|
| 125 | HRESULT setACL(const com::Utf8Str &aAcl,
|
---|
| 126 | ULONG aMode);
|
---|
| 127 | HRESULT setSize(LONG64 aSize);
|
---|
[50618] | 128 | HRESULT write(const std::vector<BYTE> &aData,
|
---|
| 129 | ULONG aTimeoutMS,
|
---|
| 130 | ULONG *aWritten);
|
---|
| 131 | HRESULT writeAt(LONG64 aOffset,
|
---|
| 132 | const std::vector<BYTE> &aData,
|
---|
| 133 | ULONG aTimeoutMS,
|
---|
| 134 | ULONG *aWritten);
|
---|
[51321] | 135 | /** @} */
|
---|
[50618] | 136 |
|
---|
[97626] | 137 | private:
|
---|
| 138 |
|
---|
[45415] | 139 | /** This can safely be used without holding any locks.
|
---|
| 140 | * An AutoCaller suffices to prevent it being destroy while in use and
|
---|
| 141 | * internally there is a lock providing the necessary serialization. */
|
---|
| 142 | const ComObjPtr<EventSource> mEventSource;
|
---|
| 143 |
|
---|
[42084] | 144 | struct Data
|
---|
| 145 | {
|
---|
[44863] | 146 | /** The file's open info. */
|
---|
| 147 | GuestFileOpenInfo mOpenInfo;
|
---|
| 148 | /** The file's initial size on open. */
|
---|
| 149 | uint64_t mInitialSize;
|
---|
[45415] | 150 | /** The current file status. */
|
---|
| 151 | FileStatus_T mStatus;
|
---|
[47817] | 152 | /** The last returned process status
|
---|
| 153 | * returned from the guest side. */
|
---|
| 154 | int mLastError;
|
---|
[44863] | 155 | /** The file's current offset. */
|
---|
| 156 | uint64_t mOffCurrent;
|
---|
[42084] | 157 | } mData;
|
---|
| 158 | };
|
---|
| 159 |
|
---|
[76562] | 160 | #endif /* !MAIN_INCLUDED_GuestFileImpl_h */
|
---|
[42084] | 161 |
|
---|