Index: /trunk/src/VBox/Additions/common/VBoxService/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/Makefile.kmk	(revision 31201)
+++ /trunk/src/VBox/Additions/common/VBoxService/Makefile.kmk	(revision 31202)
@@ -50,4 +50,10 @@
  VBoxService_DEFS        += VBOXSERVICE_CPUHOTPLUG
 endif
+ifdef VBOX_WITH_SHARED_FOLDERS
+ # darwin freebsd
+ if1of ($(KBUILD_TARGET), linux solaris)
+  VBoxService_DEFS        += VBOX_WITH_SHARED_FOLDERS
+ endif
+endif
 
 VBoxService_SOURCES       = \
@@ -56,4 +62,5 @@
 	VBoxServiceUtils.cpp \
 	VBoxServiceStats.cpp
+
 ifdef VBOX_WITH_GUEST_CONTROL
  VBoxService_SOURCES    += \
@@ -61,4 +68,5 @@
  	VBoxServiceControlExec.cpp
 endif
+
 ifdef VBOX_WITH_MEMBALLOON
  VBoxService_SOURCES    += \
@@ -69,4 +77,5 @@
  	VBoxServicePageSharing.cpp
 endif
+
 ifdef VBOX_WITH_GUEST_PROPS
  VBoxService_SOURCES.win  = \
@@ -76,8 +85,19 @@
  	VBoxServicePropCache.cpp
 endif
+
 if1of ($(KBUILD_TARGET), linux)
  VBoxService_SOURCES     += \
 	VBoxServiceCpuHotPlug.cpp
 endif
+
+ifdef VBOX_WITH_SHARED_FOLDERS
+ if1of ($(KBUILD_TARGET), linux solaris)
+  VBoxService_SOURCES          += \
+	VBoxServiceAutoMount.cpp
+  VBoxService_SOURCES.linux    += \
+	../../linux/sharedfolders/vbsfmount.c
+ endif
+endif
+
 VBoxService_SOURCES.win  += \
 	VBoxService-win.rc \
Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp	(revision 31201)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp	(revision 31202)
@@ -104,4 +104,7 @@
 #ifdef VBOX_WITH_PAGE_SHARING
     { &g_PageSharing, NIL_RTTHREAD, false, false, false, true },
+#endif
+#ifdef VBOX_WITH_SHARED_FOLDERS
+    { &g_AutoMount, NIL_RTTHREAD, false, false, false, true },
 #endif
 };
Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp	(revision 31202)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceAutoMount.cpp	(revision 31202)
@@ -0,0 +1,338 @@
+/* $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;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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/assert.h>
+#include <iprt/dir.h>
+#include <iprt/mem.h>
+#include <iprt/string.h>
+#include <iprt/semaphore.h>
+#include <VBox/VBoxGuestLib.h>
+#include "VBoxServiceInternal.h"
+#include "VBoxServiceUtils.h"
+
+#include <errno.h>
+#include <sys/mount.h>
+#ifdef RT_OS_SOLARIS
+#include <sys/vfs.h>
+#endif
+#include <unistd.h>
+
+#ifdef RT_OS_LINUX
+ RT_C_DECLS_BEGIN
+    #include "../../linux/sharedfolders/vbsfmount.h"
+ RT_C_DECLS_END
+#endif
+
+/*******************************************************************************
+*   Global Variables                                                           *
+*******************************************************************************/
+/** The semaphore we're blocking on. */
+static RTSEMEVENTMULTI  g_AutoMountEvent = NIL_RTSEMEVENTMULTI;
+
+
+/** @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)
+{
+    NOREF(ppszShort);
+    NOREF(argc);
+    NOREF(argv);
+    NOREF(pi);
+    return VINF_SUCCESS;
+}
+
+
+/** @copydoc VBOXSERVICE::pfnInit */
+static DECLCALLBACK(int) VBoxServiceAutoMountInit(void)
+{
+    VBoxServiceVerbose(3, "VBoxServiceAutoMountInit\n");
+
+    int rc = RTSemEventMultiCreate(&g_AutoMountEvent);
+    AssertRCReturn(rc, rc);
+
+    return rc;
+}
+
+
+static int VBoxServiceAutoMountSharedFolder(const char *pszShareName, const char *pszMountPoint)
+{
+    unsigned long flags = MS_NODEV;
+    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,
+                  pszMountPoint,
+                  flags,
+                  "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
+    {
+        if (errno != EBUSY) /* Share is already mounted? Then skip error msg. */
+            VBoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\", error = %s\n",
+                             pszShareName, pszMountPoint, strerror(errno));
+    }
+#else /* !RT_OS_SOLARIS */
+    const char *szOptions = { "rw" };
+    struct vbsf_mount_info_new mntinf;
+
+    mntinf.nullchar     = '\0';
+    mntinf.signature[0] = VBSF_MOUNT_SIGNATURE_BYTE_0;
+    mntinf.signature[1] = VBSF_MOUNT_SIGNATURE_BYTE_1;
+    mntinf.signature[2] = VBSF_MOUNT_SIGNATURE_BYTE_2;
+    mntinf.length       = sizeof(mntinf);
+
+    mntinf.uid   = 0;
+    mntinf.gid   = 0;
+    mntinf.ttl   = 0;
+    mntinf.dmode = ~0;
+    mntinf.fmode = ~0;
+    mntinf.dmask = 0;
+    mntinf.fmask = 0;
+
+    strcpy(mntinf.name, pszShareName);
+    strcpy(mntinf.nls_name, "\0");
+
+    int r = mount(NULL,
+                  pszMountPoint,
+                  "vboxsf",
+                  flags,
+                  &mntinf);
+    if (r == 0)
+    {
+        VBoxServiceVerbose(0, "VBoxServiceAutoMountWorker: Shared folder \"%s\" was mounted to \"%s\"\n", pszShareName, pszMountPoint);
+
+        r = vbsfmount_complete(pszShareName, pszMountPoint, flags, &opts);
+        switch (r)
+        {
+            case 0: /* Success. */
+                errno = 0; /* Clear all errors/warnings. */
+                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 */
+    {
+        if (errno == EPROTO)
+        {
+            /* Sometimes the mount utility messes up the share name.  Try to
+             * un-mangle it again. */
+            char szCWD[4096];
+            size_t cchCWD;
+            if (!getcwd(szCWD, sizeof(szCWD)))
+                VBoxServiceError("VBoxServiceAutoMountWorker: Failed to get the current working directory\n");
+            cchCWD = strlen(szCWD);
+            if (!strncmp(pszMountPoint, szCWD, cchCWD))
+            {
+                while (pszMountPoint[cchCWD] == '/')
+                    ++cchCWD;
+                /* We checked before that we have enough space */
+                strcpy(mntinf.name, pszMountPoint + cchCWD);
+            }
+            r = mount(NULL, pszMountPoint, "vboxsf", flags, &mntinf);
+        }
+        if (errno == EPROTO)
+        {
+            /* New mount tool with old vboxsf module? Try again using the old
+             * vbsf_mount_info_old structure. */
+            struct vbsf_mount_info_old mntinf_old;
+            memcpy(&mntinf_old.name, &mntinf.name, MAX_HOST_NAME);
+            memcpy(&mntinf_old.nls_name, mntinf.nls_name, MAX_NLS_NAME);
+            mntinf_old.uid = mntinf.uid;
+            mntinf_old.gid = mntinf.gid;
+            mntinf_old.ttl = mntinf.ttl;
+            r = mount(NULL, pszMountPoint, "vboxsf", flags, &mntinf_old);
+        }
+        if (errno != EBUSY) /* Share is already mounted? Then skip error msg. */
+            VBoxServiceError("VBoxServiceAutoMountWorker: Could not mount shared folder \"%s\" to \"%s\", error = %s\n",
+                             pszShareName, pszMountPoint, strerror(errno));
+    }
+#endif /* !RT_OS_SOLARIS */
+
+    VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Mounting returned with errno=%d, error=%s\n",
+                       errno, strerror(errno));
+    return RTErrConvertFromErrno(errno);
+}
+
+
+/** @copydoc VBOXSERVICE::pfnWorker */
+DECLCALLBACK(int) VBoxServiceAutoMountWorker(bool volatile *pfShutdown)
+{
+    /*
+     * Tell the control thread that it can continue
+     * spawning services.
+     */
+    RTThreadUserSignal(RTThreadSelf());
+
+    uint32_t u32ClientId;
+    int rc = VbglR3SharedFolderConnect(&u32ClientId);
+    if (!RT_SUCCESS(rc))
+        VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Failed to connect to the shared folder service, error %Rrc\n", rc);
+    else
+    {
+        uint32_t cMappings;
+        VBGLR3SHAREDFOLDERMAPPING *paMappings;
+
+        rc = VbglR3SharedFolderGetMappings(u32ClientId, true /* Only process auto-mounted folders */,
+                                           &paMappings, &cMappings);
+        if (RT_SUCCESS(rc))
+        {
+#if 0
+            /* Check for a fixed/virtual auto-mount share. */
+            if (VbglR3SharedFolderExists(u32ClientId, "vbsfAutoMount"))
+            {
+                VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Host supports auto-mount root\n");
+            }
+            else
+            {
+#endif
+                VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Got %u shared folder mappings\n", cMappings);
+                for (uint32_t i = 0; i < cMappings && RT_SUCCESS(rc); i++)
+                {
+                    char *pszShareName = NULL;
+                    rc = VbglR3SharedFolderGetName(u32ClientId, paMappings[i].u32Root, &pszShareName);
+                    if (   RT_SUCCESS(rc)
+                        && *pszShareName)
+                    {
+                        VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Connecting share %u (%s) ...\n", i+1, pszShareName);
+
+                        char *pszMountPoint = NULL;
+                        if (   RTStrAPrintf(&pszMountPoint, "/media/sf_%s", pszShareName) > 0
+                            && pszMountPoint)
+                        {
+                            /* We always use "/media" as our root mounting directory. */
+                            /** @todo Detect the correct "media" directory, based on the current guest (?). */
+                            RTFMODE fMode = 0777;
+                            rc = RTDirCreateFullPath(pszMountPoint, fMode);
+                            if (RT_SUCCESS(rc))
+                            {
+                                rc = VBoxServiceAutoMountSharedFolder(pszShareName, pszMountPoint);
+                            }
+                            else
+                                VBoxServiceError("VBoxServiceAutoMountWorker: Could not create mount directory \"%s\", rc = %Rrc\n",
+                                                 pszMountPoint, rc);
+                            RTStrFree(pszMountPoint);
+                        }
+                        else
+                            rc = VERR_NO_MEMORY;
+                        RTStrFree(pszShareName);
+                    }
+                    else
+                        VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder name for root node = %u, rc = %Rrc\n",
+                                         paMappings[i].u32Root, rc);
+                }
+#if 0
+            }
+#endif
+            RTMemFree(paMappings);
+        }
+        else
+            VBoxServiceError("VBoxServiceAutoMountWorker: Error while getting the shared folder mappings, rc = %Rrc\n", rc);
+        VbglR3SharedFolderDisconnect(u32ClientId);
+    }
+
+    RTSemEventMultiDestroy(g_AutoMountEvent);
+    g_AutoMountEvent = NIL_RTSEMEVENTMULTI;
+
+    VBoxServiceVerbose(3, "VBoxServiceAutoMountWorker: Finished\n");
+    return 0;
+}
+
+/** @copydoc VBOXSERVICE::pfnTerm */
+static DECLCALLBACK(void) VBoxServiceAutoMountTerm(void)
+{
+    VBoxServiceVerbose(3, "VBoxServiceAutoMountTerm\n");
+    return;
+}
+
+
+/** @copydoc VBOXSERVICE::pfnStop */
+static DECLCALLBACK(void) VBoxServiceAutoMountStop(void)
+{
+    RTSemEventMultiSignal(g_AutoMountEvent);
+}
+
+
+/**
+ * The 'automount' service description.
+ */
+VBOXSERVICE g_AutoMount =
+{
+    /* pszName. */
+    "automount",
+    /* pszDescription. */
+    "Auto-mount for Shared Folders",
+    /* pszUsage. */
+    NULL,
+    /* pszOptions. */
+    NULL,
+    /* methods */
+    VBoxServiceAutoMountPreInit,
+    VBoxServiceAutoMountOption,
+    VBoxServiceAutoMountInit,
+    VBoxServiceAutoMountWorker,
+    VBoxServiceAutoMountStop,
+    VBoxServiceAutoMountTerm
+};
Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h	(revision 31201)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h	(revision 31202)
@@ -250,4 +250,7 @@
 extern VBOXSERVICE  g_PageSharing;
 #endif
+#ifdef VBOX_WITH_SHARED_FOLDERS
+extern VBOXSERVICE  g_AutoMount;
+#endif
 
 extern RTEXITCODE   VBoxServiceSyntax(const char *pszFormat, ...);
Index: /trunk/src/VBox/Additions/linux/sharedfolders/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Additions/linux/sharedfolders/Makefile.kmk	(revision 31201)
+++ /trunk/src/VBox/Additions/linux/sharedfolders/Makefile.kmk	(revision 31202)
@@ -88,6 +88,6 @@
 mount.vboxsf_DEFS        = _GNU_SOURCE
 mount.vboxsf_SOURCES     = \
-	mount.vboxsf.c
-
+	mount.vboxsf.c \
+	vbsfmount.c
 
 ## Scripts needed for building kernel modules
Index: /trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c
===================================================================
--- /trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c	(revision 31201)
+++ /trunk/src/VBox/Additions/linux/sharedfolders/mount.vboxsf.c	(revision 31202)
@@ -8,5 +8,5 @@
 
 /*
- * Copyright (C) 2006-2007 Oracle Corporation
+ * Copyright (C) 2006-2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -53,22 +53,4 @@
     } while (0)
 
-struct opts
-{
-    int  uid;
-    int  gid;
-    int  ttl;
-    int  dmode;
-    int  fmode;
-    int  dmask;
-    int  fmask;
-    int  ronly;
-    int  noexec;
-    int  nodev;
-    int  nosuid;
-    int  remount;
-    char nls_name[MAX_NLS_NAME];
-    char *convertcp;
-};
-
 #define PANIC_ATTR __attribute ((noreturn, __format__ (__printf__, 1, 2)))
 
@@ -113,5 +95,5 @@
 
 static void
-process_mount_opts(const char *s, struct opts *opts)
+process_mount_opts(const char *s, struct vbsf_mount_opts *opts)
 {
     const char *next = s;
@@ -319,69 +301,4 @@
             exit(EXIT_FAILURE);
         }
-    }
-}
-
-static void
-complete(char *host_name, char *mount_point,
-          unsigned long flags, struct opts *opts)
-{
-    FILE *f, *m;
-    char *buf;
-    size_t size;
-    struct mntent e;
-
-    m = open_memstream(&buf, &size);
-    if (!m)
-        panic_err("could not update mount table (failed to create memstream)");
-
-    if (opts->uid)
-        fprintf(m, "uid=%d,", opts->uid);
-    if (opts->gid)
-        fprintf(m, "gid=%d,", opts->gid);
-    if (opts->ttl)
-        fprintf(m, "ttl=%d,", opts->ttl);
-    if (*opts->nls_name)
-        fprintf(m, "iocharset=%s,", opts->nls_name);
-    if (flags & MS_NOSUID)
-        fprintf(m, "%s,", MNTOPT_NOSUID);
-    if (flags & MS_RDONLY)
-        fprintf(m, "%s,", MNTOPT_RO);
-    else
-        fprintf(m, "%s,", MNTOPT_RW);
-
-    fclose(m);
-
-    if (size > 0)
-        buf[size - 1] = 0;
-    else
-        buf = "defaults";
-
-    f = setmntent(MOUNTED, "a+");
-    if (!f)
-        panic_err("could not open mount table for update");
-
-    e.mnt_fsname = host_name;
-    e.mnt_dir = mount_point;
-    e.mnt_type = "vboxsf";
-    e.mnt_opts = buf;
-    e.mnt_freq = 0;
-    e.mnt_passno = 0;
-
-    if (addmntent(f, &e))
-    {
-        if (size > 0)
-        {
-            memset(buf, 0, size);
-            free(buf);
-        }
-        panic_err("could not add an entry to the mount table");
-    }
-
-    endmntent(f);
-
-    if (size > 0)
-    {
-        memset(buf, 0, size);
-        free(buf);
     }
 }
@@ -461,5 +378,5 @@
     char *mount_point;
     struct vbsf_mount_info_new mntinf;
-    struct opts opts =
+    struct vbsf_mount_opts opts =
     {
         0,     /* uid */
@@ -558,4 +475,9 @@
     mntinf.fmask = opts.fmask;
 
+    /*
+     * Note: When adding and/or modifying parameters of the vboxsf mounting
+     *       options you also would have to adjust VBoxServiceAutoMount.cpp
+     *       to keep this code here slick without having VbglR3.
+     */
     err = mount(NULL, mount_point, "vboxsf", flags, &mntinf);
     if (err == -1 && errno == EPROTO)
@@ -593,5 +515,28 @@
 
     if (!nomtab)
-        complete(host_name, mount_point, flags, &opts);
+    {
+        err = vbsfmount_complete(host_name, mount_point, flags, &opts);
+        switch (err)
+        {
+            case 0: /* Success. */
+                break;
+
+            case 1:
+                panic_err("%s: Could not update mount table (failed to create memstream).", argv[0]);
+                break;
+
+            case 2:
+                panic_err("%s: Could not open mount table for update.", argv[0]);
+                break;
+
+            case 3:
+                panic_err("%s: Could not add an entry to the mount table.", argv[0]);
+                break;
+
+            default:
+                panic_err("%s: Unknown error while completing mount operation: %d", argv[0], err);
+                break;
+        }
+    }
 
     exit(EXIT_SUCCESS);
Index: /trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.c
===================================================================
--- /trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.c	(revision 31202)
+++ /trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.c	(revision 31202)
@@ -0,0 +1,92 @@
+/* $Id$ */
+/** @file
+ * vbsfmount - Commonly used code to mount shared folders on Linux-based
+ *             systems.  Currently used by mount.vboxsf and VBoxService.
+ */
+
+/*
+ * 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;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * 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 "vbsfmount.h"
+
+#include <ctype.h>
+#include <mntent.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mount.h>
+
+
+/** @todo Use defines for return values! */
+int vbsfmount_complete(const char *host_name, const char *mount_point,
+					   unsigned long flags, struct vbsf_mount_opts *opts)
+{
+    FILE *f, *m;
+    char *buf;
+    size_t size;
+    struct mntent e;
+	int rc = 0;
+
+    m = open_memstream(&buf, &size);
+    if (!m)
+        return 1; /* Could not update mount table (failed to create memstream). */
+
+    if (opts->uid)
+        fprintf(m, "uid=%d,", opts->uid);
+    if (opts->gid)
+        fprintf(m, "gid=%d,", opts->gid);
+    if (opts->ttl)
+        fprintf(m, "ttl=%d,", opts->ttl);
+    if (*opts->nls_name)
+        fprintf(m, "iocharset=%s,", opts->nls_name);
+    if (flags & MS_NOSUID)
+        fprintf(m, "%s,", MNTOPT_NOSUID);
+    if (flags & MS_RDONLY)
+        fprintf(m, "%s,", MNTOPT_RO);
+    else
+        fprintf(m, "%s,", MNTOPT_RW);
+
+    fclose(m);
+
+    if (size > 0)
+        buf[size - 1] = 0;
+    else
+        buf = "defaults";
+
+    f = setmntent(MOUNTED, "a+");
+    if (!f)
+	{
+		rc = 2; /* Could not open mount table for update. */
+	}
+	else
+	{
+		e.mnt_fsname = (char*)host_name;
+		e.mnt_dir = (char*)mount_point;
+		e.mnt_type = "vboxsf";
+		e.mnt_opts = buf;
+		e.mnt_freq = 0;
+		e.mnt_passno = 0;
+
+		if (addmntent(f, &e))
+			rc = 3;  /* Could not add an entry to the mount table. */
+
+		endmntent(f);
+	}
+
+    if (size > 0)
+    {
+        memset(buf, 0, size);
+        free(buf);
+    }
+
+	return rc;
+}
Index: /trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.h
===================================================================
--- /trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.h	(revision 31201)
+++ /trunk/src/VBox/Additions/linux/sharedfolders/vbsfmount.h	(revision 31202)
@@ -4,5 +4,5 @@
 
 /*
- * Copyright (C) 2006-2007 Oracle Corporation
+ * Copyright (C) 2006-2010 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -21,5 +21,5 @@
 #define MAX_NLS_NAME    32
 
-/* Linux constraints the size of data mount argument to PAGE_SIZE - 1 */
+/* Linux constraints the size of data mount argument to PAGE_SIZE - 1. */
 struct vbsf_mount_info_old
 {
@@ -53,3 +53,25 @@
 };
 
+struct vbsf_mount_opts
+{
+    int  uid;
+    int  gid;
+    int  ttl;
+    int  dmode;
+    int  fmode;
+    int  dmask;
+    int  fmask;
+    int  ronly;
+    int  noexec;
+    int  nodev;
+    int  nosuid;
+    int  remount;
+    char nls_name[MAX_NLS_NAME];
+    char *convertcp;
+};
+
+/** Completes the mount operation by adding the new mount point to mtab if required. */
+int vbsfmount_complete(const char *host_name, const char *mount_point,
+                       unsigned long flags, struct vbsf_mount_opts *opts);
+
 #endif /* vbsfmount.h */
