1 | /* $Id: vboxfs_mount.c 100317 2023-06-28 10:34:21Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox File System Mount Helper, Solaris host.
|
---|
4 | * Userspace mount wrapper that parses mount (or user-specified) options
|
---|
5 | * and passes it to mount(2) syscall
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox base platform packages, as
|
---|
12 | * available from https://www.virtualbox.org.
|
---|
13 | *
|
---|
14 | * This program is free software; you can redistribute it and/or
|
---|
15 | * modify it under the terms of the GNU General Public License
|
---|
16 | * as published by the Free Software Foundation, in version 3 of the
|
---|
17 | * License.
|
---|
18 | *
|
---|
19 | * This program is distributed in the hope that it will be useful, but
|
---|
20 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
22 | * General Public License for more details.
|
---|
23 | *
|
---|
24 | * You should have received a copy of the GNU General Public License
|
---|
25 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
26 | *
|
---|
27 | * The contents of this file may alternatively be used under the terms
|
---|
28 | * of the Common Development and Distribution License Version 1.0
|
---|
29 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
30 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
31 | * CDDL are applicable instead of those of the GPL.
|
---|
32 | *
|
---|
33 | * You may elect to license modified versions of this file under the
|
---|
34 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
35 | *
|
---|
36 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
37 | */
|
---|
38 |
|
---|
39 |
|
---|
40 | /*********************************************************************************************************************************
|
---|
41 | * Header Files *
|
---|
42 | *********************************************************************************************************************************/
|
---|
43 | #include <stdio.h>
|
---|
44 | #include <stdlib.h>
|
---|
45 | #include <strings.h>
|
---|
46 | #include <sys/vfs.h>
|
---|
47 | #include <sys/mount.h>
|
---|
48 |
|
---|
49 | #include <iprt/param.h> /* For PAGE_SIZE */
|
---|
50 |
|
---|
51 | #include "vboxfs.h"
|
---|
52 |
|
---|
53 |
|
---|
54 | /*********************************************************************************************************************************
|
---|
55 | * Global Variables *
|
---|
56 | *********************************************************************************************************************************/
|
---|
57 | static char g_achOptBuf[PAGE_SIZE] = { '\0', };
|
---|
58 | static const int g_RetErr = 33;
|
---|
59 | static const int g_RetMagic = 2;
|
---|
60 | static const int g_RetOK = 0;
|
---|
61 |
|
---|
62 | static void Usage(char *pszName)
|
---|
63 | {
|
---|
64 | fprintf(stderr, "Usage: %s [OPTIONS] NAME MOUNTPOINT\n"
|
---|
65 | "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT.\n"
|
---|
66 | "\n"
|
---|
67 | " -w mount the shared folder writable (the default)\n"
|
---|
68 | " -r mount the shared folder read-only\n"
|
---|
69 | " -o OPTION[,OPTION...] use the mount options specified\n"
|
---|
70 | "\n", pszName);
|
---|
71 | fprintf(stderr, "Available mount options are:\n"
|
---|
72 | "\n"
|
---|
73 | " rw mount writable (the default)\n"
|
---|
74 | " ro mount read only\n"
|
---|
75 | " uid=UID set the default file owner user id to UID\n"
|
---|
76 | " gid=GID set the default file owner group id to GID\n");
|
---|
77 | fprintf(stderr,
|
---|
78 | " dmode=MODE override the mode for all directories (octal) to MODE\n"
|
---|
79 | " fmode=MODE override the mode for all regular files (octal) to MODE\n"
|
---|
80 | " umask=UMASK set the umask (bitmask of permissions not present) in (octal) UMASK\n"
|
---|
81 | " dmask=UMASK set the umask applied to directories only in (octal) UMASK\n"
|
---|
82 | " fmask=UMASK set the umask applied to regular files only in (octal) UMASK\n"
|
---|
83 | " stat_ttl=TTL set the \"time to live\" (in ms) for the stat caches (default %d)\n", DEF_STAT_TTL_MS);
|
---|
84 | fprintf(stderr,
|
---|
85 | " fsync honor fsync calls instead of ignoring them\n"
|
---|
86 | " ttl=TTL set the \"time to live\" to TID for the dentry\n"
|
---|
87 | " iocharset CHARSET use the character set CHARSET for i/o operations (default utf8)\n"
|
---|
88 | " convertcp CHARSET convert the shared folder name from the character set CHARSET to utf8\n\n"
|
---|
89 | "Less common used options:\n"
|
---|
90 | " noexec,exec,nodev,dev,nosuid,suid\n");
|
---|
91 | exit(1);
|
---|
92 | }
|
---|
93 |
|
---|
94 | int main(int argc, char **argv)
|
---|
95 | {
|
---|
96 | char *pszName = NULL;
|
---|
97 | char *pszSpecial = NULL;
|
---|
98 | char *pszMount = NULL;
|
---|
99 | char achType[MAXFIDSZ];
|
---|
100 | int c = '?';
|
---|
101 | int rc = -1;
|
---|
102 | int parseError = 0;
|
---|
103 | int mntFlags = 0;
|
---|
104 | int quietFlag = 0;
|
---|
105 |
|
---|
106 | pszName = strrchr(argv[0], '/');
|
---|
107 | pszName = pszName ? pszName + 1 : argv[0];
|
---|
108 | snprintf(achType, sizeof(achType), "%s_%s", DEVICE_NAME, pszName);
|
---|
109 |
|
---|
110 | while ((c = getopt(argc, argv, "o:rmoQ")) != EOF)
|
---|
111 | {
|
---|
112 | switch (c)
|
---|
113 | {
|
---|
114 | case '?':
|
---|
115 | {
|
---|
116 | parseError = 1;
|
---|
117 | break;
|
---|
118 | }
|
---|
119 |
|
---|
120 | case 'q':
|
---|
121 | {
|
---|
122 | quietFlag = 1;
|
---|
123 | break;
|
---|
124 | }
|
---|
125 |
|
---|
126 | case 'r':
|
---|
127 | {
|
---|
128 | mntFlags |= MS_RDONLY;
|
---|
129 | break;
|
---|
130 | }
|
---|
131 |
|
---|
132 | case 'O':
|
---|
133 | {
|
---|
134 | mntFlags |= MS_OVERLAY;
|
---|
135 | break;
|
---|
136 | }
|
---|
137 |
|
---|
138 | case 'm':
|
---|
139 | {
|
---|
140 | mntFlags |= MS_NOMNTTAB;
|
---|
141 | break;
|
---|
142 | }
|
---|
143 |
|
---|
144 | case 'o':
|
---|
145 | {
|
---|
146 | if (strlcpy(g_achOptBuf, optarg, sizeof(g_achOptBuf)) >= sizeof(g_achOptBuf))
|
---|
147 | {
|
---|
148 | fprintf(stderr, "%s: invalid argument: %s\n", pszName, optarg);
|
---|
149 | return g_RetMagic;
|
---|
150 | }
|
---|
151 | break;
|
---|
152 | }
|
---|
153 |
|
---|
154 | default:
|
---|
155 | {
|
---|
156 | Usage(pszName);
|
---|
157 | break;
|
---|
158 | }
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | if ( argc - optind != 2
|
---|
163 | || parseError)
|
---|
164 | {
|
---|
165 | Usage(pszName);
|
---|
166 | }
|
---|
167 |
|
---|
168 | pszSpecial = argv[argc - 2];
|
---|
169 | pszMount = argv[argc - 1];
|
---|
170 |
|
---|
171 | rc = mount(pszSpecial, pszMount, mntFlags | MS_OPTIONSTR, DEVICE_NAME, NULL, 0, g_achOptBuf, sizeof(g_achOptBuf));
|
---|
172 | if (rc)
|
---|
173 | {
|
---|
174 | fprintf(stderr, "mount:");
|
---|
175 | perror(pszSpecial);
|
---|
176 | return g_RetErr;
|
---|
177 | }
|
---|
178 |
|
---|
179 | return g_RetOK;
|
---|
180 | }
|
---|
181 |
|
---|