1 | /* $Id: mount.vboxsf.cpp 93115 2022-01-01 11:31:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxSF - Darwin Shared Folders, Mount Utility.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include <errno.h>
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <unistd.h>
|
---|
26 | #include <sys/mount.h>
|
---|
27 |
|
---|
28 | #include "VBoxSFMount.h"
|
---|
29 | #include <iprt/string.h>
|
---|
30 |
|
---|
31 |
|
---|
32 | static RTEXITCODE usage(const char *pszArg0)
|
---|
33 | {
|
---|
34 | fprintf(stderr, "usage: %s [OPTIONS] <shared folder name> <mount point>\n", pszArg0);
|
---|
35 | return RTEXITCODE_SYNTAX;
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | int main(int argc, char **argv)
|
---|
40 | {
|
---|
41 | /*
|
---|
42 | * Skip past parameters.
|
---|
43 | */
|
---|
44 | int c;
|
---|
45 | while ((c = getopt(argc, argv, "o:")) != -1)
|
---|
46 | {
|
---|
47 | switch (c)
|
---|
48 | {
|
---|
49 | case 'o':
|
---|
50 | break;
|
---|
51 | default:
|
---|
52 | return usage(argv[0]);
|
---|
53 | }
|
---|
54 | }
|
---|
55 |
|
---|
56 | /* Two arguments are rquired: <share name> and <mount point> */
|
---|
57 | if (argc - optind != 2)
|
---|
58 | return usage(argv[0]);
|
---|
59 | const char * const pszFolder = argv[optind++];
|
---|
60 | const char * const pszMountPoint = argv[optind];
|
---|
61 |
|
---|
62 | /*
|
---|
63 | * Check that the folder is within bounds and doesn't include any shady characters.
|
---|
64 | */
|
---|
65 | size_t cchFolder = strlen(pszFolder);
|
---|
66 | if ( cchFolder < 1
|
---|
67 | || cchFolder >= RT_SIZEOFMEMB(VBOXSFDRWNMOUNTINFO, szFolder)
|
---|
68 | || strpbrk(pszFolder, "\\/") != NULL)
|
---|
69 | {
|
---|
70 | fprintf(stderr, "Invalid shared folder name '%s'!\n", pszFolder);
|
---|
71 | return RTEXITCODE_FAILURE;
|
---|
72 | }
|
---|
73 |
|
---|
74 | /*
|
---|
75 | * Do the mounting.
|
---|
76 | */
|
---|
77 | VBOXSFDRWNMOUNTINFO MntInfo;
|
---|
78 | RT_ZERO(MntInfo);
|
---|
79 | MntInfo.u32Magic = VBOXSFDRWNMOUNTINFO_MAGIC;
|
---|
80 | memcpy(MntInfo.szFolder, pszFolder, cchFolder);
|
---|
81 | int rc = mount(VBOXSF_DARWIN_FS_NAME, pszMountPoint, 0, &MntInfo);
|
---|
82 | if (rc == 0)
|
---|
83 | return 0;
|
---|
84 |
|
---|
85 | fprintf(stderr, "error mounting '%s' at '%s': %s (%d)\n", pszFolder, pszMountPoint, strerror(errno), errno);
|
---|
86 | return RTEXITCODE_FAILURE;
|
---|
87 | }
|
---|