GuestFileImpl.cpp revision e86baafe99d1f1eb37adcca5fdecfd06e7f13bc5
/* $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 "GuestFileImpl.h"
#include "GuestSessionImpl.h"
#include "GuestCtrlImplPrivate.h"
#include "ConsoleImpl.h"
#include "VirtualBoxErrorInfoImpl.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=%RU32, file=%p resulted in rc=%Rrc\n",
#endif
break;
}
default:
break;
}
return S_OK;
}
private:
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
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 */);
{
if (RT_SUCCESS(vrc))
{
}
}
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().
*/
{
/* Enclose the state transition Ready->InUninit->NotReady. */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
#ifdef VBOX_WITH_GUEST_CONTROL
baseUninit();
#endif
}
/////////////////////////////////////////////////////////////////////////////
{
#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);
/* 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 */
}
{
#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 */
}
// private methods
/////////////////////////////////////////////////////////////////////////////
int GuestFile::callbackDispatcher(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
{
LogFlowThisFunc(("strName=%s, uContextID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
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))
return vrc;
}
/* static */
{
/** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
switch (guestRc)
{
case VERR_ALREADY_EXISTS:
break;
case VERR_FILE_NOT_FOUND:
break;
case VERR_NET_HOST_NOT_FOUND:
break;
case VERR_SHARING_VIOLATION:
break;
default:
break;
}
return strError;
}
{
return VERR_INVALID_PARAMETER;
int vrc = VINF_SUCCESS;
/* pSvcCb->mpaParms[0] always contains the context ID. */
LogFlowFunc(("uType=%RU32, guestRc=%Rrc\n",
if (RT_FAILURE(guestRc))
{
return VINF_SUCCESS; /* Report to the guest. */
}
{
{
break;
}
{
{
{
/* Set the initial offset. On the guest the whole opening operation
* would fail if an initial seek isn't possible. */
}
/* Set the process status. */
}
else
break;
}
{
break;
}
{
{
}
else
break;
}
{
{
}
else
break;
}
{
{
}
else
break;
}
{
{
}
else
break;
}
default:
break;
}
if (RT_SUCCESS(vrc))
{
}
LogFlowThisFunc(("uType=%RU32, guestRc=%Rrc\n",
return vrc;
}
int GuestFile::onGuestDisconnected(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
{
return vrc;
}
/**
* Called by IGuestSession right before this file gets removed
* from the public file list.
*/
{
int vrc = VINF_SUCCESS;
/*
* Note: The event source stuff holds references to this object,
* so make sure that this is cleaned up *before* calling uninit().
*/
if (!mEventSource.isNull())
{
}
return vrc;
}
{
LogFlowThisFunc(("strFile=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%RU32, uOffset=%RU64\n",
mData.mOpenInfo.mDisposition.c_str(), mData.mOpenInfo.mCreationMode, mData.mOpenInfo.mInitialOffset));
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
if (RT_SUCCESS(vrc))
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(("iOffset=%RI64, uTimeoutMS=%RU32\n",
iOffset, uTimeoutMS));
int vrc;
try
{
}
{
}
if (RT_FAILURE(vrc))
return vrc;
/* Prepare HGCM call. */
int i = 0;
/** @todo uint64_t vs. int64_t! */
if (RT_SUCCESS(vrc))
return vrc;
}
/* static */
{
}
{
LogFlowThisFunc(("oldStatus=%RU32, newStatus=%RU32, fileRc=%Rrc\n",
#ifdef VBOX_STRICT
if (fileStatus == FileStatus_Error)
{
}
else
#endif
{
if (RT_FAILURE(fileRc))
{
}
this, fileStatus, errorInfo);
}
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;
}
{
/* pFileStatus is optional. */
if (RT_SUCCESS(vrc))
{
if (pFileStatus)
{
}
LogFlowThisFunc(("resultDetail=%RI32 (%Rrc)\n",
if (RT_FAILURE((int)lGuestRc))
if (pGuestRc)
}
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))
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; /* Never reached. */
}
if (RT_FAILURE(vrc))
{
switch (vrc)
{
default:
tr("Seeking file \"%s\" (to offset %RI64) 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 */
}