VirtualBox

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

Last change on this file since 30357 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.6 KB
Line 
1/* $Id: vboxfs_mount.c 28800 2010-04-27 08:22:32Z 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) 2008 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
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <stdio.h>
24#include <stdlib.h>
25#include <strings.h>
26#include <sys/vfs.h>
27#include <sys/mount.h>
28
29#include "vboxfs.h"
30
31/*******************************************************************************
32* Global Variables *
33*******************************************************************************/
34static char g_achOptBuf[MAX_MNTOPT_STR] = { '\0', };
35static int g_cbOptBuf = 0;
36static const int g_RetErr = 33;
37static const int g_RetMagic = 2;
38static const int g_RetOK = 0;
39
40static void Usage(char *pszName)
41{
42 fprintf(stderr, "Usage: %s [OPTIONS] NAME MOUNTPOINT\n"
43 "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT.\n"
44 "\n"
45 " -w mount the shared folder writably (the default)\n"
46 " -r mount the shared folder read-only\n"
47 " -o OPTION[,OPTION...] use the mount options specified\n"
48 "\n", pszName);
49 fprintf(stderr, "Available mount options are:\n"
50 "\n"
51 " rw mount writably (the default)\n"
52 " ro mount read only\n"
53 " uid=UID set the default file owner user id to UID\n"
54 " gid=GID set the default file owner group id to GID\n"
55 " ttl=TTL set the \"time to live\" to TID for the dentry\n"
56 " iocharset CHARSET use the character set CHARSET for i/o operations (default utf8)\n"
57 " convertcp CHARSET convert the shared folder name from the character set CHARSET to utf8\n\n");
58 fprintf(stderr, "Less common used options:\n"
59 " noexec,exec,nodev,dev,nosuid,suid\n");
60 exit(1);
61}
62
63int main(int argc, char **argv)
64{
65 char *pszName = NULL;
66 char *pszSpecial = NULL;
67 char *pszMount = NULL;
68 char achType[MAXFIDSZ];
69 int c = '?';
70 int rc = -1;
71 int parseError = 0;
72 int mntFlags = 0;
73 int quietFlag = 0;
74
75 pszName = strrchr(argv[0], '/');
76 pszName = pszName ? pszName + 1 : argv[0];
77 snprintf(achType, sizeof(achType), "%s_%s", DEVICE_NAME, pszName);
78
79 while ((c = getopt(argc, argv, "o:rmoQ")) != EOF)
80 {
81 switch (c)
82 {
83 case '?':
84 {
85 parseError = 1;
86 break;
87 }
88
89 case 'q':
90 {
91 quietFlag = 1;
92 break;
93 }
94
95 case 'r':
96 {
97 mntFlags |= MS_RDONLY;
98 break;
99 }
100
101 case 'O':
102 {
103 mntFlags |= MS_OVERLAY;
104 break;
105 }
106
107 case 'm':
108 {
109 mntFlags |= MS_NOMNTTAB;
110 break;
111 }
112
113 case 'o':
114 {
115 if (strlcpy(g_achOptBuf, optarg, sizeof(g_achOptBuf)) >= sizeof(g_achOptBuf))
116 {
117 fprintf(stderr, "%s: invalid argument: %s\n", pszName, optarg);
118 return g_RetMagic;
119 }
120 g_cbOptBuf = strlen(g_achOptBuf);
121 break;
122 }
123
124 default:
125 {
126 Usage(pszName);
127 break;
128 }
129 }
130 }
131
132 if ( argc - optind != 2
133 || parseError)
134 {
135 Usage(pszName);
136 }
137
138 pszSpecial = argv[argc - 2];
139 pszMount = argv[argc - 1];
140
141 rc = mount(pszSpecial, pszMount, mntFlags | MS_OPTIONSTR, DEVICE_NAME, NULL, 0, g_achOptBuf, MAX_MNTOPT_STR);
142 if (rc)
143 {
144 fprintf(stderr, "mount:");
145 perror(pszSpecial);
146 return g_RetErr;
147 }
148
149 return g_RetOK;
150}
151
Note: See TracBrowser for help on using the repository browser.

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