xref: /freebsd/sbin/mount_cd9660/mount_cd9660.c (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
1 /*
2  * Copyright (c) 1992, 1993, 1994
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley
6  * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
7  * Support code is derived from software contributed to Berkeley
8  * by Atsushi Murai (amurai@spec.co.jp).
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)mount_cd9660.c	8.7 (Berkeley) 5/1/95
39  */
40 
41 #ifndef lint
42 static char copyright[] =
43 "@(#) Copyright (c) 1992, 1993, 1994\n\
44         The Regents of the University of California.  All rights reserved.\n";
45 #endif /* not lint */
46 
47 #ifndef lint
48 /*
49 static char sccsid[] = "@(#)mount_cd9660.c	8.7 (Berkeley) 5/1/95";
50 */
51 static const char rcsid[] =
52 	"$Id: mount_cd9660.c,v 1.9 1997/02/22 14:32:44 peter Exp $";
53 #endif /* not lint */
54 
55 #include <sys/param.h>
56 #include <sys/mount.h>
57 #include <sys/../isofs/cd9660/cd9660_mount.h>
58 
59 #include <err.h>
60 #include <stdlib.h>
61 #include <stdio.h>
62 #include <string.h>
63 #include <sysexits.h>
64 #include <unistd.h>
65 
66 #include "mntopts.h"
67 
68 struct mntopt mopts[] = {
69 	MOPT_STDOPTS,
70 	MOPT_UPDATE,
71 	{ "extatt", 0, ISOFSMNT_EXTATT, 1 },
72 	{ "gens", 0, ISOFSMNT_GENS, 1 },
73 	{ "rrip", 1, ISOFSMNT_NORRIP, 1 },
74 	{ NULL }
75 };
76 
77 void	usage __P((void));
78 
79 int
80 main(argc, argv)
81 	int argc;
82 	char **argv;
83 {
84 	struct iso_args args;
85 	int ch, mntflags, opts;
86 	char *dev, *dir;
87 	struct vfsconf vfc;
88 	int error;
89 
90 	mntflags = opts = 0;
91 	while ((ch = getopt(argc, argv, "ego:r")) != EOF)
92 		switch (ch) {
93 		case 'e':
94 			opts |= ISOFSMNT_EXTATT;
95 			break;
96 		case 'g':
97 			opts |= ISOFSMNT_GENS;
98 			break;
99 		case 'o':
100 			getmntopts(optarg, mopts, &mntflags, &opts);
101 			break;
102 		case 'r':
103 			opts |= ISOFSMNT_NORRIP;
104 			break;
105 		case '?':
106 		default:
107 			usage();
108 		}
109 	argc -= optind;
110 	argv += optind;
111 
112 	if (argc != 2)
113 		usage();
114 
115 	dev = argv[0];
116 	dir = argv[1];
117 
118 #define DEFAULT_ROOTUID	-2
119 	/*
120 	 * ISO 9660 filesystems are not writeable.
121 	 */
122 	mntflags |= MNT_RDONLY;
123 	args.export.ex_flags = MNT_EXRDONLY;
124 	args.fspec = dev;
125 	args.export.ex_root = DEFAULT_ROOTUID;
126 	args.flags = opts;
127 
128 	error = getvfsbyname("cd9660", &vfc);
129 	if (error && vfsisloadable("cd9660")) {
130 		if (vfsload("cd9660"))
131 			err(EX_OSERR, "vfsload(cd9660)");
132 		endvfsent();	/* flush cache */
133 		error = getvfsbyname("cd9660", &vfc);
134 	}
135 	if (error)
136 		errx(1, "cd9660 filesystem is not available");
137 
138 	if (mount(vfc.vfc_name, dir, mntflags, &args) < 0)
139 		err(1, NULL);
140 	exit(0);
141 }
142 
143 void
144 usage()
145 {
146 	(void)fprintf(stderr,
147 		"usage: mount_cd9660 [-egrt] [-o options] special node\n");
148 	exit(EX_USAGE);
149 }
150