socsvn commit: r255540 - soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs
oleksandr at FreeBSD.org
oleksandr at FreeBSD.org
Mon Aug 5 16:29:41 UTC 2013
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 <bsd.prog.mk>
+
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 <sys/param.h>
+#include <sys/stat.h>
+#include <sys/errno.h>
+#include <sys/linker.h>
+#include <sys/mount.h>
+#include <sys/uio.h>
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#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);
+}
More information about the svn-soc-all
mailing list