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