summaryrefslogtreecommitdiffstats
path: root/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:17:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:17:27 +0000
commitf215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch)
tree6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp
parentInitial commit. (diff)
downloadvirtualbox-upstream/7.0.14-dfsg.tar.xz
virtualbox-upstream/7.0.14-dfsg.zip
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp')
-rw-r--r--src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp b/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp
new file mode 100644
index 00000000..57db36bc
--- /dev/null
+++ b/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp
@@ -0,0 +1,97 @@
+/* $Id: mount.vboxsf.cpp $ */
+/** @file
+ * VBoxSF - Darwin Shared Folders, Mount Utility.
+ */
+
+/*
+ * Copyright (C) 2013-2023 Oracle and/or its affiliates.
+ *
+ * This file is part of VirtualBox base platform packages, as
+ * available from https://www.virtualbox.org.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, in version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+
+/*********************************************************************************************************************************
+* Header Files *
+*********************************************************************************************************************************/
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/mount.h>
+
+#include "VBoxSFMount.h"
+#include <iprt/string.h>
+
+
+static RTEXITCODE usage(const char *pszArg0)
+{
+ fprintf(stderr, "usage: %s [OPTIONS] <shared folder name> <mount point>\n", pszArg0);
+ return RTEXITCODE_SYNTAX;
+}
+
+
+int main(int argc, char **argv)
+{
+ /*
+ * Skip past parameters.
+ */
+ int c;
+ while ((c = getopt(argc, argv, "o:")) != -1)
+ {
+ switch (c)
+ {
+ case 'o':
+ break;
+ default:
+ return usage(argv[0]);
+ }
+ }
+
+ /* Two arguments are rquired: <share name> and <mount point> */
+ if (argc - optind != 2)
+ return usage(argv[0]);
+ const char * const pszFolder = argv[optind++];
+ const char * const pszMountPoint = argv[optind];
+
+ /*
+ * Check that the folder is within bounds and doesn't include any shady characters.
+ */
+ size_t cchFolder = strlen(pszFolder);
+ if ( cchFolder < 1
+ || cchFolder >= RT_SIZEOFMEMB(VBOXSFDRWNMOUNTINFO, szFolder)
+ || strpbrk(pszFolder, "\\/") != NULL)
+ {
+ fprintf(stderr, "Invalid shared folder name '%s'!\n", pszFolder);
+ return RTEXITCODE_FAILURE;
+ }
+
+ /*
+ * Do the mounting.
+ */
+ VBOXSFDRWNMOUNTINFO MntInfo;
+ RT_ZERO(MntInfo);
+ MntInfo.u32Magic = VBOXSFDRWNMOUNTINFO_MAGIC;
+ memcpy(MntInfo.szFolder, pszFolder, cchFolder);
+ int rc = mount(VBOXSF_DARWIN_FS_NAME, pszMountPoint, 0, &MntInfo);
+ if (rc == 0)
+ return 0;
+
+ fprintf(stderr, "error mounting '%s' at '%s': %s (%d)\n", pszFolder, pszMountPoint, strerror(errno), errno);
+ return RTEXITCODE_FAILURE;
+}