mount_udf.c revision 102231
1129794Stackerman/*
2129794Stackerman * Copyright (c) 1992, 1993, 1994
3129794Stackerman *      The Regents of the University of California.  All rights reserved.
4129794Stackerman * Copyright (c) 2002 Scott Long
5129794Stackerman *
6129794Stackerman * This code is derived from software contributed to Berkeley
7129794Stackerman * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
8129794Stackerman * Support code is derived from software contributed to Berkeley
9129794Stackerman * by Atsushi Murai (amurai@spec.co.jp).
10129794Stackerman *
11129794Stackerman * Redistribution and use in source and binary forms, with or without
12129794Stackerman * modification, are permitted provided that the following conditions
13129794Stackerman * are met:
14129794Stackerman * 1. Redistributions of source code must retain the above copyright
15129794Stackerman *    notice, this list of conditions and the following disclaimer.
16129794Stackerman * 2. Redistributions in binary form must reproduce the above copyright
17129794Stackerman *    notice, this list of conditions and the following disclaimer in the
18129794Stackerman *    documentation and/or other materials provided with the distribution.
19129794Stackerman * 3. All advertising materials mentioning features or use of this software
20129794Stackerman *    must display the following acknowledgement:
21129794Stackerman *	This product includes software developed by the University of
22129794Stackerman *	California, Berkeley and its contributors.
23129794Stackerman * 4. Neither the name of the University nor the names of its contributors
24129794Stackerman *    may be used to endorse or promote products derived from this software
25129794Stackerman *    without specific prior written permission.
26129794Stackerman *
27129794Stackerman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28129794Stackerman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29129794Stackerman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30129794Stackerman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31129794Stackerman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32129794Stackerman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33129794Stackerman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34129794Stackerman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35129794Stackerman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36129794Stackerman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37129794Stackerman * SUCH DAMAGE.
38129794Stackerman *
39129794Stackerman * $FreeBSD: head/sbin/mount_udf/mount_udf.c 102231 2002-08-21 18:11:48Z trhodes $
40129794Stackerman */
41129794Stackerman
42129794Stackerman/*
43129794Stackerman * This is just a rip-off of mount_iso9660.c.  It's been vastly simplified
44129794Stackerman * because UDF doesn't take any options at this time.
45129794Stackerman */
46129794Stackerman
47129794Stackerman#include <sys/cdio.h>
48129794Stackerman#include <sys/file.h>
49129794Stackerman#include <sys/param.h>
50129794Stackerman#include <sys/mount.h>
51129794Stackerman#include <sys/uio.h>
52129794Stackerman
53129794Stackerman#include <err.h>
54129794Stackerman#include <errno.h>
55129794Stackerman#include <stdlib.h>
56129794Stackerman#include <stdio.h>
57129794Stackerman#include <string.h>
58129794Stackerman#include <sysexits.h>
59129794Stackerman#include <unistd.h>
60129794Stackerman
61129794Stackerman#include "mntopts.h"
62129794Stackerman
63129794Stackermanstruct mntopt mopts[] = {
64129794Stackerman	MOPT_STDOPTS,
65129794Stackerman	MOPT_UPDATE,
66129794Stackerman	{ NULL, 0, 0, 0 }
67129794Stackerman};
68129794Stackerman
69129794Stackermanvoid	usage(void);
70129794Stackerman
71129794Stackermanint
72129794Stackermanmain(int argc, char **argv)
73129794Stackerman{
74129794Stackerman	struct iovec iov[6];
75129794Stackerman	int ch, mntflags, opts;
76129794Stackerman	char *dev, *dir, mntpath[MAXPATHLEN];
77129794Stackerman	int verbose;
78129794Stackerman
79129794Stackerman	mntflags = opts = verbose = 0;
80129794Stackerman	while ((ch = getopt(argc, argv, "o:v")) != -1)
81129794Stackerman		switch (ch) {
82129794Stackerman		case 'o':
83129794Stackerman			getmntopts(optarg, mopts, &mntflags, &opts);
84129794Stackerman			break;
85129794Stackerman		case 'v':
86129794Stackerman			verbose++;
87129794Stackerman			break;
88129794Stackerman		case '?':
89129794Stackerman		default:
90129794Stackerman			usage();
91129794Stackerman		}
92129794Stackerman	argc -= optind;
93129794Stackerman	argv += optind;
94129794Stackerman
95129794Stackerman	if (argc != 2)
96129794Stackerman		usage();
97129794Stackerman
98129794Stackerman	dev = argv[0];
99129794Stackerman	dir = argv[1];
100129794Stackerman
101129794Stackerman	/*
102129794Stackerman	 * Resolve the mountpoint with realpath(3) and remove unnecessary
103129794Stackerman	 * slashes from the devicename if there are any.
104129794Stackerman	 */
105129794Stackerman	(void)checkpath(dir, mntpath);
106129794Stackerman	(void)rmslashes(dev, dev);
107129794Stackerman
108129794Stackerman	/*
109129794Stackerman	 * UDF file systems are not writeable.
110129794Stackerman	 */
111129794Stackerman	mntflags |= MNT_RDONLY;
112129794Stackerman
113129794Stackerman	iov[0].iov_base = "fstype";
114129794Stackerman	iov[0].iov_len = sizeof("fstype");
115129794Stackerman	iov[1].iov_base = "udf";
116129794Stackerman	iov[1].iov_len = strlen(iov[1].iov_base) + 1;
117129794Stackerman	iov[2].iov_base = "fspath";
118129794Stackerman	iov[2].iov_len = sizeof("fspath");
119129794Stackerman	iov[3].iov_base = mntpath;
120129794Stackerman	iov[3].iov_len = strlen(mntpath) + 1;
121129794Stackerman	iov[4].iov_base = "from";
122129794Stackerman	iov[4].iov_len = sizeof("from");
123129794Stackerman	iov[5].iov_base = dev;
124129794Stackerman	iov[5].iov_len = strlen(dev) + 1;
125129794Stackerman	if (nmount(iov, 6, mntflags) < 0)
126129794Stackerman		err(1, "%s", dev);
127129794Stackerman	exit(0);
128129794Stackerman}
129129794Stackerman
130129794Stackermanvoid
131129794Stackermanusage(void)
132129794Stackerman{
133129794Stackerman	(void)fprintf(stderr,
134129794Stackerman		"usage: mount_udf [-v] [-o options] special node\n");
135129794Stackerman	exit(EX_USAGE);
136129794Stackerman}
137129794Stackerman