mount_udf.c revision 102231
194663Sscottl/*
294663Sscottl * Copyright (c) 1992, 1993, 1994
394663Sscottl *      The Regents of the University of California.  All rights reserved.
494663Sscottl * Copyright (c) 2002 Scott Long
594663Sscottl *
694663Sscottl * This code is derived from software contributed to Berkeley
794663Sscottl * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
894663Sscottl * Support code is derived from software contributed to Berkeley
994663Sscottl * by Atsushi Murai (amurai@spec.co.jp).
1094663Sscottl *
1194663Sscottl * Redistribution and use in source and binary forms, with or without
1294663Sscottl * modification, are permitted provided that the following conditions
1394663Sscottl * are met:
1494663Sscottl * 1. Redistributions of source code must retain the above copyright
1594663Sscottl *    notice, this list of conditions and the following disclaimer.
1694663Sscottl * 2. Redistributions in binary form must reproduce the above copyright
1794663Sscottl *    notice, this list of conditions and the following disclaimer in the
1894663Sscottl *    documentation and/or other materials provided with the distribution.
1994663Sscottl * 3. All advertising materials mentioning features or use of this software
2094663Sscottl *    must display the following acknowledgement:
2194663Sscottl *	This product includes software developed by the University of
2294663Sscottl *	California, Berkeley and its contributors.
2394663Sscottl * 4. Neither the name of the University nor the names of its contributors
2494663Sscottl *    may be used to endorse or promote products derived from this software
2594663Sscottl *    without specific prior written permission.
2694663Sscottl *
2794663Sscottl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2894663Sscottl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2994663Sscottl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3094663Sscottl * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3194663Sscottl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3294663Sscottl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3394663Sscottl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3494663Sscottl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3594663Sscottl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3694663Sscottl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3794663Sscottl * SUCH DAMAGE.
3894663Sscottl *
3994663Sscottl * $FreeBSD: head/sbin/mount_udf/mount_udf.c 102231 2002-08-21 18:11:48Z trhodes $
4094663Sscottl */
4194663Sscottl
4294663Sscottl/*
4394663Sscottl * This is just a rip-off of mount_iso9660.c.  It's been vastly simplified
4494663Sscottl * because UDF doesn't take any options at this time.
4594663Sscottl */
4694663Sscottl
4794663Sscottl#include <sys/cdio.h>
4894663Sscottl#include <sys/file.h>
4994663Sscottl#include <sys/param.h>
5094663Sscottl#include <sys/mount.h>
51101829Smux#include <sys/uio.h>
5294663Sscottl
5394663Sscottl#include <err.h>
5494663Sscottl#include <errno.h>
5594663Sscottl#include <stdlib.h>
5694663Sscottl#include <stdio.h>
5794663Sscottl#include <string.h>
5894663Sscottl#include <sysexits.h>
5994663Sscottl#include <unistd.h>
6094663Sscottl
6194663Sscottl#include "mntopts.h"
6294663Sscottl
6394663Sscottlstruct mntopt mopts[] = {
6494663Sscottl	MOPT_STDOPTS,
6594663Sscottl	MOPT_UPDATE,
6694796Sasmodai	{ NULL, 0, 0, 0 }
6794663Sscottl};
6894663Sscottl
6994663Sscottlvoid	usage(void);
7094663Sscottl
7194663Sscottlint
7294663Sscottlmain(int argc, char **argv)
7394663Sscottl{
7498265Smux	struct iovec iov[6];
7594663Sscottl	int ch, mntflags, opts;
7694663Sscottl	char *dev, *dir, mntpath[MAXPATHLEN];
77101270Smux	int verbose;
7894663Sscottl
7994663Sscottl	mntflags = opts = verbose = 0;
8094663Sscottl	while ((ch = getopt(argc, argv, "o:v")) != -1)
8194663Sscottl		switch (ch) {
8294663Sscottl		case 'o':
8394663Sscottl			getmntopts(optarg, mopts, &mntflags, &opts);
8494663Sscottl			break;
8594663Sscottl		case 'v':
8694663Sscottl			verbose++;
8794663Sscottl			break;
8894663Sscottl		case '?':
8994663Sscottl		default:
9094663Sscottl			usage();
9194663Sscottl		}
9294663Sscottl	argc -= optind;
9394663Sscottl	argv += optind;
9494663Sscottl
9594663Sscottl	if (argc != 2)
9694663Sscottl		usage();
9794663Sscottl
9894663Sscottl	dev = argv[0];
9994663Sscottl	dir = argv[1];
10094663Sscottl
10194663Sscottl	/*
10294663Sscottl	 * Resolve the mountpoint with realpath(3) and remove unnecessary
10394663Sscottl	 * slashes from the devicename if there are any.
10494663Sscottl	 */
10594663Sscottl	(void)checkpath(dir, mntpath);
10694663Sscottl	(void)rmslashes(dev, dev);
10794663Sscottl
10894663Sscottl	/*
109102231Strhodes	 * UDF file systems are not writeable.
11094663Sscottl	 */
11194663Sscottl	mntflags |= MNT_RDONLY;
11294663Sscottl
11398265Smux	iov[0].iov_base = "fstype";
11498265Smux	iov[0].iov_len = sizeof("fstype");
115101270Smux	iov[1].iov_base = "udf";
116101270Smux	iov[1].iov_len = strlen(iov[1].iov_base) + 1;
11798265Smux	iov[2].iov_base = "fspath";
11898265Smux	iov[2].iov_len = sizeof("fspath");
11998265Smux	iov[3].iov_base = mntpath;
12098265Smux	iov[3].iov_len = strlen(mntpath) + 1;
12198265Smux	iov[4].iov_base = "from";
12298265Smux	iov[4].iov_len = sizeof("from");
12398265Smux	iov[5].iov_base = dev;
12498265Smux	iov[5].iov_len = strlen(dev) + 1;
12598265Smux	if (nmount(iov, 6, mntflags) < 0)
12698265Smux		err(1, "%s", dev);
12794663Sscottl	exit(0);
12894663Sscottl}
12994663Sscottl
13094663Sscottlvoid
13194663Sscottlusage(void)
13294663Sscottl{
13394663Sscottl	(void)fprintf(stderr,
13494663Sscottl		"usage: mount_udf [-v] [-o options] special node\n");
13594663Sscottl	exit(EX_USAGE);
13694663Sscottl}
137