From owner-svn-soc-all@FreeBSD.ORG Mon Aug 5 16:29:41 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 2B398AA4 for ; Mon, 5 Aug 2013 16:29:41 +0000 (UTC) (envelope-from oleksandr@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 097A126A1 for ; Mon, 5 Aug 2013 16:29:41 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r75GTe8T072653 for ; Mon, 5 Aug 2013 16:29:40 GMT (envelope-from oleksandr@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r75GTeHO072649 for svn-soc-all@FreeBSD.org; Mon, 5 Aug 2013 16:29:40 GMT (envelope-from oleksandr@FreeBSD.org) Date: Mon, 5 Aug 2013 16:29:40 GMT Message-Id: <201308051629.r75GTeHO072649@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to oleksandr@FreeBSD.org using -f From: oleksandr@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r255540 - soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Aug 2013 16:29:41 -0000 Author: oleksandr Date: Mon Aug 5 16:29:40 2013 New Revision: 255540 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255540 Log: Initial implemented mount_vbox utility, not tested yet Added: soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/ soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/Makefile soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.8 soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c Added: soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/Makefile Mon Aug 5 16:29:40 2013 (r255540) @@ -0,0 +1,11 @@ +PROG= mount_vboxfs +SRCS= mount_vboxfs.c getmntopts.c +MAN= mount_vboxfs.8 + +MOUNT= ${.CURDIR}/../mount +CFLAGS+=-I${MOUNT} + +.PATH: ${MOUNT} + +.include + Added: soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.8 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.8 Mon Aug 5 16:29:40 2013 (r255540) @@ -0,0 +1,53 @@ +.\" +.\" Copyright (c) 1992, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd August 5, 2013 +.Dt MOUNT_VBOXFS 8 +.Os +.Sh NAME +.Nm mount_vboxfs +.Nd "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT" +.Sh SYNOPSIS +.Nm +.Op Fl o Ar options +.Ar NAME +.Ar MOUNTPOINT +.Sh DESCRIPTION +The +.Nm +Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT +.Pp +The options are as follows: +.Bl -tag -width indent +.Fl w +mount the shared folder writably (the default) +.Fl r +mount the shared folder read-only +.Fl o +OPTION[,OPTION...] use the mount options specified +.El Added: soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c Mon Aug 5 16:29:40 2013 (r255540) @@ -0,0 +1,153 @@ +/* +* Copyright (c) 1992, 1993, 1994 +* The Regents of the University of California. All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* 4. Neither the name of the University nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +* SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "mntopts.h" + +static char mount_point[MAXPATHLEN + 1]; +static char vboxfs_vfsname[] = "vboxfs"; +static void usage(void) __dead2; + +int +main(int argc, char *argv[]) +{ + struct iovec *iov; + struct stat st; + // struct xvfsconf vfc; + char *host_name; + char errmsg[255]; + uid_t uid; + gid_t gid; + mode_t dir_mode, file_mode; + int iovlen; + int error, ch; + + iov = NULL; + iovlen = 0; + errmsg[0] = '\0'; + uid = (uid_t)-1; + gid = (gid_t)-1; + file_mode = 0; + dir_mode = 0; + + #if 0 + error = getvfsbyname(vboxfs_vfsname, &vfc); + + if (error) { + if (kldload(vboxfs_vfsname) < 0) + err(EX_OSERR, "kldload(%s)", vboxfs_vfsname); + error = getvfsbyname(vboxfs_vfsname, &vfc); + } + + if (error) + errx(EX_OSERR, "VBOXFS filesystem is not available"); + #endif + while ((ch = getopt(argc, argv, "o:")) != -1) + switch(ch) { + case 'o': + case '?': + usage(); + /*NOTREACHED*/ + default: + usage(); + } + if (argc - optind < 2) + usage(); + + host_name = argv[optind]; + realpath(argv[optind+1], mount_point); + + if (stat(mount_point, &st) == -1) + err(EX_OSERR, "could not find mount point %s", mount_point); + if (!S_ISDIR(st.st_mode)) { + errno = ENOTDIR; + err(EX_OSERR, "can't mount on %s", mount_point); + } + + if (uid == (uid_t)-1) + uid = st.st_uid; + if (gid == (gid_t)-1) + gid = st.st_gid; + if (file_mode == 0 ) + file_mode = st.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO); + if (dir_mode == 0) { + dir_mode = file_mode; + if (dir_mode & S_IRUSR) + dir_mode |= S_IXUSR; + if (dir_mode & S_IRGRP) + dir_mode |= S_IXGRP; + if (dir_mode & S_IROTH) + dir_mode |= S_IXOTH; + } + + build_iovec(&iov, &iovlen, "fstype", vboxfs_vfsname, (size_t)-1); + build_iovec(&iov, &iovlen, "fspath", mount_point, (size_t)-1); + build_iovec(&iov, &iovlen, "hostname", host_name, -1); + build_iovec(&iov, &iovlen, "mountpoint", mount_point, -1); + build_iovec_argf(&iov, &iovlen, "uid", "%d", uid); + build_iovec_argf(&iov, &iovlen, "gid", "%d", gid); + build_iovec_argf(&iov, &iovlen, "file_mode", "%d", file_mode); + build_iovec_argf(&iov, &iovlen, "dir_mode", "%d", dir_mode); + build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg)); + + error = nmount(iov, iovlen, MNT_RDONLY); + + if (error) { + if (errmsg[0] != 0) { + err(1,"mount error: %d %s %s", error, mount_point, errmsg); + exit(1); + } else { + err(1, "mount error: %d %s", error, mount_point); + exit(1); + } + } + + return 0; +} + +static void +usage(void) +{ + (void)fprintf(stderr, + "usage: mount_vboxfs [-o options] name mount-point\n"); + exit(1); +}