VirtualBox

source: vbox/trunk/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp

Last change on this file was 98103, checked in by vboxsync, 20 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: mount.vboxsf.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBoxSF - Darwin Shared Folders, Mount Utility.
4 */
5
6/*
7 * Copyright (C) 2013-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <errno.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <unistd.h>
36#include <sys/mount.h>
37
38#include "VBoxSFMount.h"
39#include <iprt/string.h>
40
41
42static RTEXITCODE usage(const char *pszArg0)
43{
44 fprintf(stderr, "usage: %s [OPTIONS] <shared folder name> <mount point>\n", pszArg0);
45 return RTEXITCODE_SYNTAX;
46}
47
48
49int main(int argc, char **argv)
50{
51 /*
52 * Skip past parameters.
53 */
54 int c;
55 while ((c = getopt(argc, argv, "o:")) != -1)
56 {
57 switch (c)
58 {
59 case 'o':
60 break;
61 default:
62 return usage(argv[0]);
63 }
64 }
65
66 /* Two arguments are rquired: <share name> and <mount point> */
67 if (argc - optind != 2)
68 return usage(argv[0]);
69 const char * const pszFolder = argv[optind++];
70 const char * const pszMountPoint = argv[optind];
71
72 /*
73 * Check that the folder is within bounds and doesn't include any shady characters.
74 */
75 size_t cchFolder = strlen(pszFolder);
76 if ( cchFolder < 1
77 || cchFolder >= RT_SIZEOFMEMB(VBOXSFDRWNMOUNTINFO, szFolder)
78 || strpbrk(pszFolder, "\\/") != NULL)
79 {
80 fprintf(stderr, "Invalid shared folder name '%s'!\n", pszFolder);
81 return RTEXITCODE_FAILURE;
82 }
83
84 /*
85 * Do the mounting.
86 */
87 VBOXSFDRWNMOUNTINFO MntInfo;
88 RT_ZERO(MntInfo);
89 MntInfo.u32Magic = VBOXSFDRWNMOUNTINFO_MAGIC;
90 memcpy(MntInfo.szFolder, pszFolder, cchFolder);
91 int rc = mount(VBOXSF_DARWIN_FS_NAME, pszMountPoint, 0, &MntInfo);
92 if (rc == 0)
93 return 0;
94
95 fprintf(stderr, "error mounting '%s' at '%s': %s (%d)\n", pszFolder, pszMountPoint, strerror(errno), errno);
96 return RTEXITCODE_FAILURE;
97}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette