SharedFolderImpl.cpp revision 0010ccca43c2554000fdd0572c7b9cf5ad17ac91
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * VirtualBox COM class implementation
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Copyright (C) 2006-2007 innotek GmbH
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * available from http://www.virtualbox.org. This file is free software;
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * you can redistribute it and/or modify it under the terms of the GNU
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * General Public License as published by the Free Software Foundation,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * If you received this file as part of a commercial VirtualBox
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * distribution, then only the terms of your commercial VirtualBox
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * license agreement apply instead of the previous paragraph.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync// constructor / destructor
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/////////////////////////////////////////////////////////////////////////////
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync// public initializer/uninitializer for internal purposes only
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/////////////////////////////////////////////////////////////////////////////
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Initializes the shared folder object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aMachine parent Machine object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aName logical name of the shared folder
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aHostPath full path to the shared folder on the host
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @return COM result indicator
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Initializes the shared folder object given another object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * (a kind of copy constructor). This object makes a private copy of data
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * of the original object passed as an argument.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aMachine parent Machine object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aThat shared folder object to copy
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @return COM result indicator
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncHRESULT SharedFolder::initCopy (Machine *aMachine, SharedFolder *aThat)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return protectedInit (aMachine, aThat->mName, aThat->mHostPath);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Initializes the shared folder object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aConsole Console parent object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aName logical name of the shared folder
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aHostPath full path to the shared folder on the host
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @return COM result indicator
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Initializes the shared folder object.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aVirtualBox VirtualBox parent object
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aName logical name of the shared folder
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @param aHostPath full path to the shared folder on the host
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * @return COM result indicator
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncHRESULT SharedFolder::init (VirtualBox *aVirtualBox,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync return protectedInit (aVirtualBox, aName, aHostPath);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Helper for init() methods.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Must be called from under the object's lock!
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncHRESULT SharedFolder::protectedInit (VirtualBoxBaseWithChildren *aParent,
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync LogFlowThisFunc (("aName={%ls}, aHostPath={%ls}\n", aName, aHostPath));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync ComAssertRet (aParent && aName && aHostPath, E_INVALIDARG);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Remove the trailng slash unless it's a root directory
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * (otherwise the comparison with the RTPathAbs() result will fail at least
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * on Linux). Note that this isn't really necessary for the shared folder
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * itself, since adding a mapping eventually results into a
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * RTDirOpenFiltered() call (see HostServices/SharedFolders) that seems to
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * accept both the slashified paths and not. */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync RTPATH_IS_VOLSEP (hostPath.raw()[hostPathLen - 2]))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync if (hostPathLen == 1 && RTPATH_IS_SEP (hostPath[0]))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync /* Check whether the path is full (absolute) */
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync tr ("Invalid shared folder path: '%s' (%Vrc)"), hostPath.raw(), vrc);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync tr ("Shared folder path '%s' is not absolute"), hostPath.raw());
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Uninitializes the instance and sets the ready flag to FALSE.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync * Called either from FinalRelease() or by the parent when it gets destroyed.
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync LogFlowMember (("SharedFolder::uninit(): isReady=%d\n", isReady()));
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync// ISharedFolder properties
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync/////////////////////////////////////////////////////////////////////////////
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP SharedFolder::COMGETTER(Name) (BSTR *aName)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP SharedFolder::COMGETTER(HostPath) (BSTR *aHostPath)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsyncSTDMETHODIMP SharedFolder::COMGETTER(Accessible) (BOOL *aAccessible)
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync // check whether the host path exists
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync int vrc = RTPathExists(hostPath) ? RTPathReal (hostPath, hostPathFull, sizeof (hostPathFull))
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync tr ("Invalid shared folder path: '%s' (%Vrc)"), hostPath.raw(), vrc);
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync Log (("SharedFolder::COMGETTER(Accessible): WARNING: '%s' "
3194da424708abdd288b28d96892b3a5f3f7df0bvboxsync "is not accessible (%Vrc)\n", hostPath.raw(), vrc));