vboxvfs_mount.c revision 34d1c9a81582b1acc9831732458231fcd8ddf2a5
78a072e1b56619e3230735ae073668311232ec94vboxsync/* $Id$ */
78a072e1b56619e3230735ae073668311232ec94vboxsync/** @file
78a072e1b56619e3230735ae073668311232ec94vboxsync * VirtualBox File System Mount Helper, Solaris host.
78a072e1b56619e3230735ae073668311232ec94vboxsync * Userspace mount wrapper that parses mount (or user-specified) options
78a072e1b56619e3230735ae073668311232ec94vboxsync * and passes it to mount(2) syscall
78a072e1b56619e3230735ae073668311232ec94vboxsync */
772269936494ffaddd0750ba9e28e805ba81398cvboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync/*
2f139cbf73f9adba01382892f33558ad7bcb40cbvboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
2f139cbf73f9adba01382892f33558ad7bcb40cbvboxsync *
2f139cbf73f9adba01382892f33558ad7bcb40cbvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
2f139cbf73f9adba01382892f33558ad7bcb40cbvboxsync * available from http://www.virtualbox.org. This file is free software;
2f139cbf73f9adba01382892f33558ad7bcb40cbvboxsync * you can redistribute it and/or modify it under the terms of the GNU
2f139cbf73f9adba01382892f33558ad7bcb40cbvboxsync * General Public License (GPL) as published by the Free Software
2f139cbf73f9adba01382892f33558ad7bcb40cbvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
78a072e1b56619e3230735ae073668311232ec94vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
78a072e1b56619e3230735ae073668311232ec94vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
78a072e1b56619e3230735ae073668311232ec94vboxsync *
772269936494ffaddd0750ba9e28e805ba81398cvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
78a072e1b56619e3230735ae073668311232ec94vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
78a072e1b56619e3230735ae073668311232ec94vboxsync * additional information or have any questions.
78a072e1b56619e3230735ae073668311232ec94vboxsync */
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync/*******************************************************************************
78a072e1b56619e3230735ae073668311232ec94vboxsync* Header Files *
78a072e1b56619e3230735ae073668311232ec94vboxsync*******************************************************************************/
78a072e1b56619e3230735ae073668311232ec94vboxsync#include <stdio.h>
78a072e1b56619e3230735ae073668311232ec94vboxsync#include <stdlib.h>
78a072e1b56619e3230735ae073668311232ec94vboxsync#include <strings.h>
78a072e1b56619e3230735ae073668311232ec94vboxsync#include <sys/vfs.h>
78a072e1b56619e3230735ae073668311232ec94vboxsync#include <sys/mount.h>
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync#include "vboxvfs.h"
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsync/*******************************************************************************
dc5cd2ea4ab36898ba3231203f52460a39189263vboxsync* Global Variables *
dc5cd2ea4ab36898ba3231203f52460a39189263vboxsync*******************************************************************************/
dc5cd2ea4ab36898ba3231203f52460a39189263vboxsyncstatic char g_achOptBuf[MAX_MNTOPT_STR] = { '\0', };
78a072e1b56619e3230735ae073668311232ec94vboxsyncstatic int g_cbOptBuf = 0;
78a072e1b56619e3230735ae073668311232ec94vboxsyncstatic const int g_RetErr = 33;
78a072e1b56619e3230735ae073668311232ec94vboxsyncstatic const int g_RetMagic = 2;
78a072e1b56619e3230735ae073668311232ec94vboxsyncstatic const int g_RetOK = 0;
78a072e1b56619e3230735ae073668311232ec94vboxsync
78a072e1b56619e3230735ae073668311232ec94vboxsyncstatic void Usage(char *pszName)
bbc0a3fc49446bf8fa1fcfe669c10875701692bcvboxsync{
bbc0a3fc49446bf8fa1fcfe669c10875701692bcvboxsync fprintf(stderr, "Usage: %s [OPTIONS] NAME MOUNTPOINT\n"
bbc0a3fc49446bf8fa1fcfe669c10875701692bcvboxsync "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT.\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync "\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync " -w mount the shared folder writably (the default)\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync " -r mount the shared folder read-only\n"
bbc0a3fc49446bf8fa1fcfe669c10875701692bcvboxsync " -o OPTION[,OPTION...] use the mount options specified\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync "\n", pszName);
78a072e1b56619e3230735ae073668311232ec94vboxsync fprintf(stderr, "Available mount options are:\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync "\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync " rw mount writably (the default)\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync " ro mount read only\n"
772269936494ffaddd0750ba9e28e805ba81398cvboxsync " uid=UID set the default file owner user id to UID\n"
78a072e1b56619e3230735ae073668311232ec94vboxsync " gid=GID set the default file owner group id to GID\n"
" ttl=TTL set the \"time to live\" to TID for the dentry\n"
" iocharset CHARSET use the character set CHARSET for i/o operations (default utf8)\n"
" convertcp CHARSET convert the shared folder name from the character set CHARSET to utf8\n");
fprintf(stderr, "Less common used options:\n"
" noexec,exec,nodev,dev,nosuid,suid\n");
exit(1);
}
int main(int argc, char **argv)
{
char *pszName = NULL;
char *pszSpecial = NULL;
char *pszMount = NULL;
char *pszOptBufCpy = NULL;
char achType[MAXFIDSZ];
int c = '?';
int rc = -1;
int parseError = 0;
int mntFlags = 0;
int quietFlag = 0;
pszName = strrchr(argv[0], '/');
pszName = pszName ? pszName + 1 : argv[0];
snprintf(achType, sizeof(achType), "%s_%s", DEVICE_NAME, pszName);
while ((c = getopt(argc, argv, "o:rmoQ")) != EOF)
{
switch (c)
{
case '?':
{
parseError = 1;
break;
}
case 'q':
{
quietFlag = 1;
break;
}
case 'r':
{
mntFlags |= MS_RDONLY;
break;
}
case 'O':
{
mntFlags |= MS_OVERLAY;
break;
}
case 'm':
{
mntFlags |= MS_NOMNTTAB;
break;
}
case 'o':
{
if (strlcpy(g_achOptBuf, optarg, sizeof(g_achOptBuf)) >= sizeof(g_achOptBuf))
{
fprintf(stderr, "%s: invalid argument: %s\n", pszName, optarg);
return g_RetMagic;
}
g_cbOptBuf = strlen(g_achOptBuf);
break;
}
default:
{
Usage(pszName);
break;
}
}
}
if ( argc - optind != 2
|| parseError)
{
Usage(pszName);
}
pszSpecial = argv[argc - 2];
pszMount = argv[argc - 1];
#if 0
pszOptBufCpy = strdup(g_achOptBuf);
if (!pszOptBufCpy)
{
fprintf(stderr, "%s: out of memory.\n", pszName);
return g_RetMagic;
}
#endif
rc = mount(pszSpecial, pszMount, mntFlags | MS_OPTIONSTR, DEVICE_NAME, NULL, 0, g_achOptBuf, MAX_MNTOPT_STR);
if (rc)
{
fprintf(stderr, "mount:");
perror(pszSpecial);
free(pszOptBufCpy);
return g_RetErr;
}
return g_RetOK;
}