summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2004-11-25 13:37:19 +0000
committerphk <phk@FreeBSD.org>2004-11-25 13:37:19 +0000
commit762f6433e76fe390f9ed9d2b2bde17abc2fca034 (patch)
tree39b0f8696d8a08672019243b41378d6ef25bd651 /sbin
parent8499c6beb775b4bedd48be50da73083c403debc7 (diff)
downloadFreeBSD-src-762f6433e76fe390f9ed9d2b2bde17abc2fca034.zip
FreeBSD-src-762f6433e76fe390f9ed9d2b2bde17abc2fca034.tar.gz
Add first cut at dethaumagizing UFS mounting.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/mount_ufs/Makefile16
-rw-r--r--sbin/mount_ufs/mount_ufs.c134
2 files changed, 150 insertions, 0 deletions
diff --git a/sbin/mount_ufs/Makefile b/sbin/mount_ufs/Makefile
new file mode 100644
index 0000000..2c35d20
--- /dev/null
+++ b/sbin/mount_ufs/Makefile
@@ -0,0 +1,16 @@
+# $FreeBSD$
+
+PROG= mount_ufs
+SRCS= mount_ufs.c getmntopts.c
+MAN= mount_ufs.8
+
+MOUNT= ${.CURDIR}/../mount
+CFLAGS+= -I${MOUNT} -I${.CURDIR}/../../sys -Wall
+.PATH: ${MOUNT}
+WARNS?= 1
+
+# Needs to be dynamically linked for optional dlopen() access to
+# userland libiconv
+NOSHARED?= NO
+
+.include <bsd.prog.mk>
diff --git a/sbin/mount_ufs/mount_ufs.c b/sbin/mount_ufs/mount_ufs.c
new file mode 100644
index 0000000..e37eadc
--- /dev/null
+++ b/sbin/mount_ufs/mount_ufs.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 1992, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * Copyright (c) 2002 Scott Long
+ *
+ * This code is derived from software contributed to Berkeley
+ * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension
+ * Support code is derived from software contributed to Berkeley
+ * by Atsushi Murai (amurai@spec.co.jp).
+ *
+ * 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.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdio.h>
+#include <sys/file.h>
+#include <sys/iconv.h>
+#include <sys/param.h>
+#include <sys/linker.h>
+#include <sys/module.h>
+#include <sys/mount.h>
+#include <sys/uio.h>
+
+#include <err.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sysexits.h>
+#include <unistd.h>
+
+#include "mntopts.h"
+
+struct mntopt mopts[] = {
+ MOPT_STDOPTS,
+ MOPT_ASYNC,
+ MOPT_FORCE,
+ MOPT_SYNC,
+ MOPT_UPDATE,
+ MOPT_SNAPSHOT,
+ { NULL }
+};
+
+void usage(void);
+
+int
+main(int argc, char **argv)
+{
+ struct iovec *iov;
+ int iovlen;
+ struct export_args export;
+ int ch, i, mntflags, opts, ufs_flags;
+ char *dev, *dir, mntpath[MAXPATHLEN];
+ char *cs_disk, *cs_local;
+ int verbose;
+
+ i = mntflags = opts = ufs_flags = verbose = 0;
+ cs_disk = cs_local = NULL;
+ while ((ch = getopt(argc, argv, "o:v")) != -1)
+ switch (ch) {
+ case 'o':
+ getmntopts(optarg, mopts, &mntflags, &opts);
+ break;
+ case 'v':
+ verbose++;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ argc -= optind;
+ argv += optind;
+
+ if (argc != 2)
+ usage();
+
+ dev = argv[0];
+ dir = argv[1];
+
+#define DEFAULT_ROOTUID -2
+ export.ex_root = DEFAULT_ROOTUID;
+ if (mntflags & MNT_RDONLY)
+ export.ex_flags = MNT_EXRDONLY;
+ else
+ export.ex_flags = 0;
+
+ /*
+ * Resolve the mountpoint with realpath(3) and remove unnecessary
+ * slashes from the devicename if there are any.
+ */
+ (void)checkpath(dir, mntpath);
+ (void)rmslashes(dev, dev);
+
+ iov = NULL;
+ build_iovec(&iov, &iovlen, "fstype", "ufs", -1);
+ build_iovec(&iov, &iovlen, "fspath", mntpath, -1);
+ build_iovec(&iov, &iovlen, "from", dev, -1);
+ build_iovec(&iov, &iovlen, "flags", &ufs_flags, sizeof ufs_flags);
+ build_iovec(&iov, &iovlen, "export", &export, sizeof export);
+ if (nmount(iov, iovlen, mntflags) < 0)
+ err(1, "%s", dev);
+ exit(0);
+}
+
+void
+usage(void)
+{
+ (void)fprintf(stderr,
+ "usage: mount_ufs [-v] [-o options] special node\n");
+ exit(EX_USAGE);
+}
OpenPOWER on IntegriCloud