1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/* $Id: GuestFileImpl.h $ */
/** @file
* VirtualBox Main - Guest file handling.
*/
/*
* Copyright (C) 2012-2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#ifndef ____H_GUESTFILEIMPL
#define ____H_GUESTFILEIMPL
#include "VirtualBoxBase.h"
#include "EventImpl.h"
#include "GuestFsObjInfoImpl.h"
#include "GuestCtrlImplPrivate.h"
class Console;
class GuestSession;
class GuestProcess;
/**
* TODO
*/
class ATL_NO_VTABLE GuestFile :
public VirtualBoxBase,
public GuestObject,
VBOX_SCRIPTABLE_IMPL(IGuestFile)
{
public:
/** @name COM and internal init/term/mapping cruft.
* @{ */
VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(GuestFile, IGuestFile)
DECLARE_NOT_AGGREGATABLE(GuestFile)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(GuestFile)
VBOX_DEFAULT_INTERFACE_ENTRIES(IGuestFile)
COM_INTERFACE_ENTRY(IFile)
END_COM_MAP()
DECLARE_EMPTY_CTOR_DTOR(GuestFile)
int init(Console *pConsole, GuestSession *pSession, ULONG uFileID, const GuestFileOpenInfo &openInfo);
void uninit(void);
HRESULT FinalConstruct(void);
void FinalRelease(void);
/** @} */
/** @name IFile interface.
* @{ */
STDMETHOD(COMGETTER(CreationMode))(ULONG *aCreationMode);
STDMETHOD(COMGETTER(Disposition))(BSTR *aDisposition);
STDMETHOD(COMGETTER(EventSource))(IEventSource ** aEventSource);
STDMETHOD(COMGETTER(FileName))(BSTR *aFileName);
STDMETHOD(COMGETTER(Id))(ULONG *aID);
STDMETHOD(COMGETTER(InitialSize))(LONG64 *aInitialSize);
STDMETHOD(COMGETTER(Offset))(LONG64 *aOffset);
STDMETHOD(COMGETTER(OpenMode))(BSTR *aOpenMode);
STDMETHOD(COMGETTER(Status))(FileStatus_T *aStatus);
STDMETHOD(Close)(void);
STDMETHOD(QueryInfo)(IFsObjInfo **aInfo);
STDMETHOD(Read)(ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData));
STDMETHOD(ReadAt)(LONG64 aOffset, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData));
STDMETHOD(Seek)(LONG64 aOffset, FileSeekType_T aType);
STDMETHOD(SetACL)(IN_BSTR aACL);
STDMETHOD(Write)(ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
STDMETHOD(WriteAt)(LONG64 aOffset, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten);
/** @} */
public:
/** @name Public internal methods.
* @{ */
int callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb);
int closeFile(int *pGuestRc);
EventSource *getEventSource(void) { return mEventSource; }
static Utf8Str guestErrorToString(int guestRc);
int onFileNotify(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
int onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData);
int onRemove(void);
int openFile(uint32_t uTimeoutMS, int *pGuestRc);
int readData(uint32_t uSize, uint32_t uTimeoutMS, void* pvData, uint32_t cbData, uint32_t* pcbRead);
int readDataAt(uint64_t uOffset, uint32_t uSize, uint32_t uTimeoutMS, void* pvData, size_t cbData, size_t* pcbRead);
int seekAt(int64_t iOffset, GUEST_FILE_SEEKTYPE eSeekType, uint32_t uTimeoutMS, uint64_t *puOffset);
static HRESULT setErrorExternal(VirtualBoxBase *pInterface, int guestRc);
int setFileStatus(FileStatus_T fileStatus, int fileRc);
int waitForOffsetChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint64_t *puOffset);
int waitForRead(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, void *pvData, size_t cbData, uint32_t *pcbRead);
int waitForStatusChange(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, FileStatus_T *pFileStatus, int *pGuestRc);
int waitForWrite(GuestWaitEvent *pEvent, uint32_t uTimeoutMS, uint32_t *pcbWritten);
int writeData(uint32_t uTimeoutMS, void *pvData, uint32_t cbData, uint32_t *pcbWritten);
int writeDataAt(uint64_t uOffset, uint32_t uTimeoutMS, void *pvData, uint32_t cbData, uint32_t *pcbWritten);
/** @} */
private:
/** This can safely be used without holding any locks.
* An AutoCaller suffices to prevent it being destroy while in use and
* internally there is a lock providing the necessary serialization. */
const ComObjPtr<EventSource> mEventSource;
struct Data
{
/** The file's open info. */
GuestFileOpenInfo mOpenInfo;
/** The file's initial size on open. */
uint64_t mInitialSize;
/** The file's ID. */
uint32_t mID;
/** The current file status. */
FileStatus_T mStatus;
/** The last returned process status
* returned from the guest side. */
int mLastError;
/** The file's current offset. */
uint64_t mOffCurrent;
} mData;
};
#endif /* !____H_GUESTFILEIMPL */
|