GuestFileImpl.cpp revision ecf100db90e8e3af96312908282d3c20e754fbe8
/* $Id$ */
/** @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;
* 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.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "GuestErrorInfoImpl.h"
#include "GuestFileImpl.h"
#include "GuestSessionImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "ConsoleImpl.h"
#include "Global.h"
#include "AutoCaller.h"
#include "VBoxEvents.h"
#ifdef LOG_GROUP
#endif
#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
/**
* Internal listener class to serve events in an
* active manner, e.g. without polling delays.
*/
class GuestFileListener
{
public:
GuestFileListener(void)
{
}
{
return S_OK;
}
void uninit(void)
{
}
{
switch (aType)
{
{
#ifdef DEBUG_andy
LogFlowFunc(("Signalling events of type=%ld, file=%p resulted in rc=%Rrc\n",
#endif
break;
}
default:
break;
}
return S_OK;
}
private:
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
LogFlowThisFunc(("\n"));
return BaseFinalConstruct();
}
void GuestFile::FinalRelease(void)
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes a file object but does *not* open the file on the guest
* yet. This is done in the dedidcated openFile call.
*
* @return IPRT status code.
* @param pConsole Pointer to console object.
* @param pSession Pointer to session object.
* @param uFileID Host-based file ID (part of the context ID).
* @param openInfo File opening information.
*/
{
LogFlowThisFunc(("pConsole=%p, pSession=%p, uFileID=%RU32, strPath=%s\n",
/* Enclose the state transition NotReady->InInit->Ready. */
AutoInitSpan autoInitSpan(this);
#ifndef VBOX_WITH_GUEST_CONTROL
return VINF_SUCCESS;
#else
if (RT_SUCCESS(vrc))
{
mData.mInitialSize = 0;
}
if (RT_SUCCESS(vrc))
{
try
{
{
TRUE /* Active listener */);
{
}
else
}
else
}
{
}
}
if (RT_SUCCESS(vrc))
{
/* Confirm a successful initialization when it's the case. */
}
else
return vrc;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
/**
* Uninitializes the instance.
* Called from FinalRelease().
*/
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady. */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
}
/////////////////////////////////////////////////////////////////////////////
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
/** @todo For 4.3: Change ULONG* to BSTR* ?*/
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
// no need to lock - lifetime constant
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
/** @todo For 4.3: Change ULONG* to BSTR* ?*/
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
int GuestFile::callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
{
#ifdef DEBUG
LogFlowThisFunc(("strName=%s, uContextID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
#endif
int vrc;
{
case GUEST_DISCONNECTED:
break;
case GUEST_FILE_NOTIFY:
break;
default:
/* Silently ignore not implemented functions. */
break;
}
#ifdef DEBUG
#endif
return vrc;
}
{
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
NULL /* FileStatus */);
return vrc;
}
/* static */
{
return 0; /** @todo Implement me! */
}
/* static */
{
while (*pc != '\0')
{
switch (*pc++)
{
case 'r':
break;
case 'w':
break;
default:
/* Silently skip unknown values. */
break;
}
}
return uOpenMode;
}
/* static */
{
/** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
switch (guestRc)
{
case VERR_INVALID_VM_HANDLE:
break;
break;
case VERR_TIMEOUT:
break;
case VERR_CANCELLED:
break;
case VERR_MAX_PROCS_REACHED:
break;
case VERR_NOT_EQUAL: /** @todo Imprecise to the user; can mean anything and all. */
break;
case VERR_NOT_FOUND:
break;
default:
break;
}
return strError;
}
{
return VERR_INVALID_PARAMETER;
int vrc = VINF_SUCCESS;
int idx = 0; /* Current parameter index. */
/* pSvcCb->mpaParms[0] always contains the context ID. */
{
{
break;
}
{
{
/* Set the process status. */
if (RT_SUCCESS(vrc))
}
else
break;
}
{
break;
}
{
if (cbRead)
{
}
}
else
break;
{
}
else
break;
{
}
else
break;
{
{
}
}
else
break;
default:
break;
}
LogFlowThisFunc(("strName=%s, uType=%RU32, guestRc=%Rrc\n",
if (RT_SUCCESS(vrc))
{
/* Nothing to do here yet. */
}
else if (vrc == VERR_NOT_SUPPORTED)
{
/* Also let the callback know. */
}
return vrc;
}
int GuestFile::onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
{
LogFlowThisFunc(("strFile=%s\n",
return vrc;
}
{
LogFlowThisFunc(("strFile=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%RU32\n",
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
NULL /* FileStatus */);
return vrc;
}
{
LogFlowThisFunc(("uSize=%RU32, uTimeoutMS=%RU32, pvData=%p, cbData=%zu\n",
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
if (pcbRead)
}
return vrc;
}
{
LogFlowThisFunc(("uOffset=%RU64, uSize=%RU32, uTimeoutMS=%RU32, pvData=%p, cbData=%zu\n",
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
if (pcbRead)
}
return vrc;
}
{
LogFlowThisFunc(("uOffset=%RU64, uTimeoutMS=%RU32\n",
uOffset, uTimeoutMS));
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
return vrc;
}
/* static */
{
}
/* Does not do locking; caller is responsible for that! */
{
LogFlowThisFunc(("oldStatus=%ld, newStatus=%ld, fileRc=%Rrc\n",
#ifdef VBOX_STRICT
if (fileStatus == FileStatus_Error)
{
}
else
#endif
{
if (RT_FAILURE(fileRc))
{
}
}
return VINF_SUCCESS;
}
{
if (RT_SUCCESS(vrc))
{
{
if (puOffset)
{
}
}
else
}
return vrc;
}
{
if (RT_SUCCESS(vrc))
{
if (evtType == VBoxEventType_OnGuestFileRead)
{
if (pvData)
{
if ( cbRead
{
}
else
}
if (pcbRead)
{
}
}
else
}
return vrc;
}
{
if (RT_SUCCESS(vrc))
{
}
return vrc;
}
{
if (RT_SUCCESS(vrc))
{
{
if (pcbWritten)
{
}
}
else
}
return vrc;
}
{
LogFlowThisFunc(("uTimeoutMS=%RU32, pvData=%p, cbData=%zu\n",
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
if (cbWritten)
*pcbWritten = cbWritten;
}
return vrc;
}
{
LogFlowThisFunc(("uOffset=%RU64, uTimeoutMS=%RU32, pvData=%p, cbData=%zu\n",
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
if (RT_SUCCESS(vrc))
{
if (cbWritten)
*pcbWritten = cbWritten;
}
return vrc;
}
// implementation of public methods
/////////////////////////////////////////////////////////////////////////////
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
/* Close file on guest. */
int guestRc;
/* On failure don't return here, instead do all the cleanup
* work first and then return an error. */
if (RT_SUCCESS(rc))
/*
* Release autocaller before calling uninit.
*/
uninit();
if (RT_FAILURE(rc))
{
if (rc == VERR_GSTCTL_GUEST_ERROR)
return setError(VBOX_E_IPRT_ERROR,
}
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
if (aToRead == 0)
AutoCaller autoCaller(this);
if (RT_SUCCESS(vrc))
{
}
else
{
switch (vrc)
{
default:
tr("Reading from file \"%s\" failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestFile::ReadAt(LONG64 aOffset, ULONG aToRead, ULONG aTimeoutMS, ComSafeArrayOut(BYTE, aData))
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
if (aToRead == 0)
AutoCaller autoCaller(this);
if (RT_SUCCESS(vrc))
{
}
else
{
switch (vrc)
{
default:
tr("Reading from file \"%s\" (at offset %RU64) failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
switch (aType)
{
case FileSeekType_Set:
break;
case FileSeekType_Current:
break;
default:
break;
}
if (RT_FAILURE(vrc))
{
switch (vrc)
{
default:
tr("Seeking file \"%s\" (to offset %RU64) failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (RT_FAILURE(vrc))
{
switch (vrc)
{
default:
tr("Writing %zubytes to file \"%s\" failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
STDMETHODIMP GuestFile::WriteAt(LONG64 aOffset, ComSafeArrayIn(BYTE, aData), ULONG aTimeoutMS, ULONG *aWritten)
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
AutoCaller autoCaller(this);
if (RT_FAILURE(vrc))
{
switch (vrc)
{
default:
tr("Writing %zubytes to file \"%s\" (at offset %RU64) failed: %Rrc"),
break;
}
}
return hr;
#endif /* VBOX_WITH_GUEST_CONTROL */
}