SharedFolderImpl.cpp revision f12a1e07ff4d3e00748830d5ba8ba6dd85bac7af
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-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.
*/
#include "SharedFolderImpl.h"
#if !defined(VBOX_COM_INPROC)
# include "VirtualBoxImpl.h"
# include "MachineImpl.h"
#endif
#include "ConsoleImpl.h"
#include "AutoCaller.h"
#include "Logging.h"
/////////////////////////////////////////////////////////////////////////////
// SharedFolder::Data structure
/////////////////////////////////////////////////////////////////////////////
struct SharedFolder::Data
{
Data()
: fWritable(false),
fAutoMount(false)
{ }
const Utf8Str strHostPath;
bool fWritable;
bool fAutoMount;
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
#if !defined(VBOX_COM_INPROC)
#else
#endif
{
m = new Data;
}
{
delete m;
m = NULL;
}
{
return BaseFinalConstruct();
}
void SharedFolder::FinalRelease()
{
uninit();
}
// public initializer/uninitializer for internal purposes only
/////////////////////////////////////////////////////////////////////////////
#if !defined(VBOX_COM_INPROC)
/**
* Initializes the shared folder object.
*
* This variant initializes a machine instance that lives in the server address space.
*
* @param aMachine parent Machine object
* @param aName logical name of the shared folder
* @param aHostPath full path to the shared folder on the host
* @param aWritable writable if true, readonly otherwise
* @param aAutoMount if auto mounted by guest true, false otherwise
* @param fFailOnError Whether to fail with an error if the shared folder path is bad.
*
* @return COM result indicator
*/
bool aWritable,
bool aAutoMount,
bool fFailOnError)
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization when it's the case */
return rc;
}
/**
* Initializes the shared folder object given another object
* (a kind of copy constructor). This object makes a private copy of data
* of the original object passed as an argument.
*
* @param aMachine parent Machine object
* @param aThat shared folder object to copy
*
* @return COM result indicator
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
aThat->m->strHostPath,
aThat->m->fAutoMount,
false /* fFailOnError */ );
/* Confirm a successful initialization when it's the case */
return rc;
}
# if 0
/**
* Initializes the shared folder object.
*
* This variant initializes a global instance that lives in the server address space. It is not presently used.
*
* @param aVirtualBox VirtualBox parent object
* @param aName logical name of the shared folder
* @param aHostPath full path to the shared folder on the host
* @param aWritable writable if true, readonly otherwise
* @param fFailOnError Whether to fail with an error if the shared folder path is bad.
*
* @return COM result indicator
*/
bool aWritable,
bool aAutoMount,
bool fFailOnError)
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization when it's the case */
return rc;
}
# endif
#else
/**
* Initializes the shared folder object.
*
* This variant initializes an instance that lives in the console address space.
*
* @param aConsole Console parent object
* @param aName logical name of the shared folder
* @param aHostPath full path to the shared folder on the host
* @param aWritable writable if true, readonly otherwise
* @param fFailOnError Whether to fail with an error if the shared folder path is bad.
*
* @return COM result indicator
*/
bool aWritable,
bool aAutoMount,
bool fFailOnError)
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization when it's the case */
return rc;
}
#endif
/**
* Shared initialization code. Called from the other constructors.
*
* @note
* Must be called from under the object's lock!
*/
bool aWritable,
bool aAutoMount,
bool fFailOnError)
{
LogFlowThisFunc(("aName={%s}, aHostPath={%s}, aWritable={%d}, aAutoMount={%d}\n",
/* Remove the trailing slash unless it's a root directory
* (otherwise the comparison with the RTPathAbs() result will fail at least
* on Linux). Note that this isn't really necessary for the shared folder
* itself, since adding a mapping eventually results into a
* RTDirOpenFiltered() call (see HostServices/SharedFolders) that seems to
* accept both the slashified paths and not. */
#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
if (hostPathLen > 2 &&
;
#else
;
#endif
else
if (fFailOnError)
{
/* Check whether the path is full (absolute) */
char hostPathFull[RTPATH_MAX];
sizeof (hostPathFull));
if (RT_FAILURE(vrc))
return setError(E_INVALIDARG,
tr("Invalid shared folder path: '%s' (%Rrc)"),
return setError(E_INVALIDARG,
tr("Shared folder path '%s' is not absolute"),
}
m->fAutoMount = aAutoMount;
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
void SharedFolder::uninit()
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
#if !defined(VBOX_COM_INPROC)
#else
#endif
}
// ISharedFolder properties
/////////////////////////////////////////////////////////////////////////////
{
AutoCaller autoCaller(this);
/* mName is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* mHostPath is constant during life time, no need to lock */
return S_OK;
}
{
AutoCaller autoCaller(this);
/* mName and mHostPath are constant during life time, no need to lock */
/* check whether the host path exists */
char hostPathFull[RTPATH_MAX];
sizeof(hostPathFull))
if (RT_SUCCESS(vrc))
{
*aAccessible = TRUE;
return S_OK;
}
m->strHostPath.c_str(),
vrc);
*aAccessible = FALSE;
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
AutoCaller autoCaller(this);
*aAutoMount = !!m->fAutoMount;
return S_OK;
}
{
AutoCaller autoCaller(this);
return S_OK;
}
{
return m->strName;
}
{
return m->strHostPath;
}
bool SharedFolder::isWritable() const
{
return m->fWritable;
}
bool SharedFolder::isAutoMounted() const
{
return m->fAutoMount;
}
/* vi: set tabstop=4 shiftwidth=4 expandtab: */