socsvn commit: r255842 - soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs
oleksandr at FreeBSD.org
oleksandr at FreeBSD.org
Mon Aug 12 14:00:56 UTC 2013
Author: oleksandr
Date: Mon Aug 12 14:00:55 2013
New Revision: 255842
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=255842
Log:
Correct mount_vboxfs utility, add double alternative way to mount vfs file system, if first is fault and correct usage() function
Modified:
soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c
Modified: soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c
==============================================================================
--- soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c Mon Aug 12 13:52:15 2013 (r255841)
+++ soc2013/oleksandr/SharedFolder-head/sbin/mount_vboxfs/mount_vboxfs.c Mon Aug 12 14:00:55 2013 (r255842)
@@ -43,24 +43,45 @@
#include "mntopts.h"
+#define MAX_HOST_NAME 256
static char mount_point[MAXPATHLEN + 1];
-static char vboxfs_vfsname[] = "vboxfs";
+static char vboxfs_vfsname[] = "vboxvfs";
+static struct mntopt mopts[] = {
+ MOPT_STDOPTS,
+ MOPT_END
+};
+
static void usage(void) __dead2;
+/**
+ * Print out a usage message and exit.
+ *
+ * @param name The name of the application
+ */
+static void
+usage(void)
+{
+ printf("Usage: [OPTIONS] NAME MOUNTPOINT\n"
+ "Mount the VirtualBox shared folder NAME from the host system to MOUNTPOINT.\n"
+ "\n"
+ " -w mount the shared folder writable \n"
+ " -r mount the shared folder read-only (the default)\n");
+ exit(1);
+}
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;
-
+ int error, ch, ronly = 0;
+ int mntflags = MNT_RDONLY;
+
iov = NULL;
iovlen = 0;
errmsg[0] = '\0';
@@ -69,40 +90,43 @@
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)
+ while ((ch = getopt(argc, argv, "rwo:h")) != -1)
switch(ch) {
- case 'o':
- case '?':
- usage();
- /*NOTREACHED*/
- default:
- usage();
+ default:
+ fprintf(stderr, "unknown option `%c:%#x'\n", ch, ch);
+ case '?':
+ case 'h':
+ usage();
+ case 'r':
+ ronly= 1;
+ break;
+ case 'w':
+ ronly = 0;
+ break;
+ case 'o':
+ getmntopts(optarg, mopts, &mntflags, 0);
+ break;
+ break;
}
if (argc - optind < 2)
- usage();
+ 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 (strlen(host_name) > MAX_HOST_NAME - 1)
+ err(EX_OSERR, "host name is too big %s", host_name);
+
+ if (!ronly)
+ mntflags |= MNT_ASYNC;
if (uid == (uid_t)-1)
uid = st.st_uid;
if (gid == (gid_t)-1)
@@ -129,7 +153,26 @@
build_iovec_argf(&iov, &iovlen, "dir_mode", "%d", dir_mode);
build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
- error = nmount(iov, iovlen, MNT_RDONLY);
+ error = nmount(iov, iovlen, mntflags);
+
+ if (error == -1 && errno == EPROTO)
+ {
+ /* Sometimes the mount utility messes up the share name. Try to
+ * un-mangle it again. */
+ char szCWD[4096];
+ size_t cchCWD;
+ if (!getcwd(szCWD, sizeof(szCWD)))
+ printf("%s: failed to get the current working directory", argv[0]);
+ cchCWD = strlen(szCWD);
+ if (!strncmp(host_name, szCWD, cchCWD))
+ {
+ while (host_name[cchCWD] == '/')
+ ++cchCWD;
+ /* We checked before that we have enough space */
+ strcpy(host_name, host_name + cchCWD);
+ }
+ error = nmount(iov, iovlen, mntflags);
+ }
if (error) {
if (errmsg[0] != 0) {
@@ -143,11 +186,3 @@
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