VirtualBox

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

Last change on this file since 33682 was 33550, checked in by vboxsync, 14 years ago

some more spelling fixes, thanks Timeless!

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.3 KB
Line 
1/* $Id: vboxfs_mount.c 33550 2010-10-28 10:53:57Z 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 int g_cbOptBuf = 0;
45static const int g_RetErr = 33;
46static const int g_RetMagic = 2;
47static const int g_RetOK = 0;
48
49static void Usage(char *pszName)
50{
51 fprintf(stderr, "Usage: %s [OPTIONS] NAME MOUNTPOINT\n"
52 "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT.\n"
53 "\n"
54 " -w mount the shared folder writable (the default)\n"
55 " -r mount the shared folder read-only\n"
56 " -o OPTION[,OPTION...] use the mount options specified\n"
57 "\n", pszName);
58 fprintf(stderr, "Available mount options are:\n"
59 "\n"
60 " rw mount writable (the default)\n"
61 " ro mount read only\n"
62 " uid=UID set the default file owner user id to UID\n"
63 " gid=GID set the default file owner group id to GID\n"
64 " stat_ttl=TTL set the \"time to live\" (in ms) for the stat caches (default %d)\n"
65 " fsync honor fsync calls instead of ignoring them\n"
66 " ttl=TTL set the \"time to live\" to TID for the dentry\n"
67 " iocharset CHARSET use the character set CHARSET for i/o operations (default utf8)\n"
68 " convertcp CHARSET convert the shared folder name from the character set CHARSET to utf8\n\n", DEF_STAT_TTL_MS);
69 fprintf(stderr, "Less common used options:\n"
70 " noexec,exec,nodev,dev,nosuid,suid\n");
71 exit(1);
72}
73
74int main(int argc, char **argv)
75{
76 char *pszName = NULL;
77 char *pszSpecial = NULL;
78 char *pszMount = NULL;
79 char achType[MAXFIDSZ];
80 int c = '?';
81 int rc = -1;
82 int parseError = 0;
83 int mntFlags = 0;
84 int quietFlag = 0;
85
86 pszName = strrchr(argv[0], '/');
87 pszName = pszName ? pszName + 1 : argv[0];
88 snprintf(achType, sizeof(achType), "%s_%s", DEVICE_NAME, pszName);
89
90 while ((c = getopt(argc, argv, "o:rmoQ")) != EOF)
91 {
92 switch (c)
93 {
94 case '?':
95 {
96 parseError = 1;
97 break;
98 }
99
100 case 'q':
101 {
102 quietFlag = 1;
103 break;
104 }
105
106 case 'r':
107 {
108 mntFlags |= MS_RDONLY;
109 break;
110 }
111
112 case 'O':
113 {
114 mntFlags |= MS_OVERLAY;
115 break;
116 }
117
118 case 'm':
119 {
120 mntFlags |= MS_NOMNTTAB;
121 break;
122 }
123
124 case 'o':
125 {
126 if (strlcpy(g_achOptBuf, optarg, sizeof(g_achOptBuf)) >= sizeof(g_achOptBuf))
127 {
128 fprintf(stderr, "%s: invalid argument: %s\n", pszName, optarg);
129 return g_RetMagic;
130 }
131 g_cbOptBuf = strlen(g_achOptBuf);
132 break;
133 }
134
135 default:
136 {
137 Usage(pszName);
138 break;
139 }
140 }
141 }
142
143 if ( argc - optind != 2
144 || parseError)
145 {
146 Usage(pszName);
147 }
148
149 pszSpecial = argv[argc - 2];
150 pszMount = argv[argc - 1];
151
152 rc = mount(pszSpecial, pszMount, mntFlags | MS_OPTIONSTR, DEVICE_NAME, NULL, 0, g_achOptBuf, MAX_MNTOPT_STR);
153 if (rc)
154 {
155 fprintf(stderr, "mount:");
156 perror(pszSpecial);
157 return g_RetErr;
158 }
159
160 return g_RetOK;
161}
162
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