VBoxServiceAutoMount.cpp revision b6517c5cc3b7a38889416706905a3cf2fd010785
/* $Id$ */
/** @file
* VBoxService - Auto-mounting for Shared Folders.
*/
/*
* Copyright (C) 2010 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 <iprt/semaphore.h>
#include <VBox/VBoxGuestLib.h>
#include "VBoxServiceInternal.h"
#include "VBoxServiceUtils.h"
#include <errno.h>
#ifdef RT_OS_SOLARIS
#endif
#include <unistd.h>
#ifdef RT_OS_LINUX
#include "../../linux/sharedfolders/vbsfmount.h"
#endif
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** The semaphore we're blocking on. */
/** @copydoc VBOXSERVICE::pfnPreInit */
static DECLCALLBACK(int) VBoxServiceAutoMountPreInit(void)
{
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnOption */
static DECLCALLBACK(int) VBoxServiceAutoMountOption(const char **ppszShort, int argc, char **argv, int *pi)
{
return VINF_SUCCESS;
}
/** @copydoc VBOXSERVICE::pfnInit */
static DECLCALLBACK(int) VBoxServiceAutoMountInit(void)
{
return rc;
}
{
struct vbsf_mount_opts opts =
{
0, /* uid */
0, /* gid */
0, /* ttl */
~0, /* dmode */
~0, /* fmode*/
0, /* dmask */
0, /* fmask */
0, /* ronly */
0, /* noexec */
0, /* nodev */
0, /* nosuid */
0, /* remount */
"\0", /* nls_name */
NULL, /* convertcp */
};
#ifdef RT_OS_SOLARIS
flags = 0; /* No flags used yet. */
int r = mount(pszShareName,
"vboxsf",
NULL, /* char *dataptr */
0, /* int datalen */
NULL, /* char *optptr */
0); /* int optlen */
if (r == 0)
{
VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" was mounted to \"%s\"\n", pszShareName, pszMountPoint);
}
else
{
VBoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\", error = %s\n",
}
#else /* !RT_OS_SOLARIS */
const char *szOptions = { "rw" };
struct vbsf_mount_info_new mntinf;
"vboxsf",
&mntinf);
if (r == 0)
{
VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" was mounted to \"%s\"\n", pszShareName, pszMountPoint);
switch (r)
{
case 0: /* Success. */
break;
case 1:
VBoxServiceError("VBoxServiceAutoMountWorker: Could not update mount table (failed to create memstream): %s\n", strerror(errno));
break;
case 2:
VBoxServiceError("VBoxServiceAutoMountWorker: Could not open mount table for update: %s\n", strerror(errno));
break;
case 3:
VBoxServiceError("VBoxServiceAutoMountWorker: Could not add an entry to the mount table: %s\n", strerror(errno));
break;
default:
VBoxServiceError("VBoxServiceAutoMountWorker: Unknown error while completing mount operation: %d\n", r);
break;
}
}
else /* r != 0 */
{
{
/* Sometimes the mount utility messes up the share name. Try to
* un-mangle it again. */
char szCWD[4096];
VBoxServiceError("VBoxServiceAutoMountWorker: Failed to get the current working directory\n");
{
++cchCWD;
/* We checked before that we have enough space */
}
}
{
/* New mount tool with old vboxsf module? Try again using the old
* vbsf_mount_info_old structure. */
struct vbsf_mount_info_old mntinf_old;
}
VBoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\", error = %s\n",
}
#endif /* !RT_OS_SOLARIS */
return RTErrConvertFromErrno(errno);
}
/** @copydoc VBOXSERVICE::pfnWorker */
{
/*
* Tell the control thread that it can continue
* spawning services.
*/
if (!RT_SUCCESS(rc))
VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Failed to connect to the shared folder service, error %Rrc\n", rc);
else
{
&paMappings, &cMappings);
if (RT_SUCCESS(rc))
{
#if 0
{
}
else
{
#endif
{
char *pszShareName = NULL;
if ( RT_SUCCESS(rc)
&& *pszShareName)
{
VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Connecting share %u (%s) ...\n", i+1, pszShareName);
char *pszMountPoint = NULL;
&& pszMountPoint)
{
/* We always use "/media" as our root mounting directory. */
/** @todo Detect the correct "media" directory, based on the current guest (?). */
if (RT_SUCCESS(rc))
{
}
else
VBoxServiceError("VBoxServiceAutoMountWorker: Could not create mount directory \"%s\", rc = %Rrc\n",
pszMountPoint, rc);
}
else
rc = VERR_NO_MEMORY;
}
else
VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder name for root node = %u, rc = %Rrc\n",
}
#if 0
}
#endif
}
else
VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder mappings, rc = %Rrc\n", rc);
}
return 0;
}
/** @copydoc VBOXSERVICE::pfnTerm */
static DECLCALLBACK(void) VBoxServiceAutoMountTerm(void)
{
return;
}
/** @copydoc VBOXSERVICE::pfnStop */
static DECLCALLBACK(void) VBoxServiceAutoMountStop(void)
{
}
/**
* The 'automount' service description.
*/
{
/* pszName. */
"automount",
/* pszDescription. */
"Auto-mount for Shared Folders",
/* pszUsage. */
NULL,
/* pszOptions. */
NULL,
/* methods */
};