VirtualBox

source: vbox/trunk/src/VBox/Additions/solaris/SharedFolders/vboxfs_mount.c@ 39561

Last change on this file since 39561 was 39072, checked in by vboxsync, 13 years ago

Additions/solaris/SharedFolders: implement umask and interpret as octal.

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