mount_cd9660.c revision 1.20 1 /* $NetBSD: mount_cd9660.c,v 1.20 2005/02/05 14:49:36 xtraeme 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.20 2005/02/05 14:49:36 xtraeme 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 mount_cd9660(int argc, char **argv);
82 static void usage(void);
83
84 #ifndef MOUNT_NOMAIN
85 int
86 main(int argc, char **argv)
87 {
88 return mount_cd9660(argc, argv);
89 }
90 #endif
91
92 int
93 mount_cd9660(int argc, char **argv)
94 {
95 struct iso_args args;
96 int ch, mntflags, opts;
97 char *dev, *dir, canon_dev[MAXPATHLEN], canon_dir[MAXPATHLEN];
98
99 mntflags = opts = 0;
100 while ((ch = getopt(argc, argv, "egijo:r")) != -1)
101 switch (ch) {
102 case 'e':
103 /* obsolete, retained for compatibility only, use
104 * -o extatt */
105 opts |= ISOFSMNT_EXTATT;
106 break;
107 case 'g':
108 /* obsolete, retained for compatibility only, use
109 * -o gens */
110 opts |= ISOFSMNT_GENS;
111 break;
112 case 'j':
113 /* obsolete, retained fo compatibility only, use
114 * -o nojoliet */
115 opts |= ISOFSMNT_NOJOLIET;
116 break;
117 case 'o':
118 getmntopts(optarg, mopts, &mntflags, &opts);
119 break;
120 case 'r':
121 /* obsolete, retained for compatibility only, use
122 * -o norrip */
123 opts |= ISOFSMNT_NORRIP;
124 break;
125 case '?':
126 default:
127 usage();
128 }
129 argc -= optind;
130 argv += optind;
131
132 if (argc != 2)
133 usage();
134
135 dev = argv[0];
136 dir = argv[1];
137
138 if (realpath(dev, canon_dev) == NULL) /* Check device path */
139 err(1, "realpath %s", dev);
140 if (strncmp(dev, canon_dev, MAXPATHLEN)) {
141 warnx("\"%s\" is a relative path.", dev);
142 dev = canon_dev;
143 warnx("using \"%s\" instead.", dev);
144 }
145
146 if (realpath(dir, canon_dir) == NULL) /* Check mounton path */
147 err(1, "realpath %s", dir);
148 if (strncmp(dir, canon_dir, MAXPATHLEN)) {
149 warnx("\"%s\" is a relative path.", dir);
150 dir = canon_dir;
151 warnx("using \"%s\" instead.", dir);
152 }
153
154 #define DEFAULT_ROOTUID -2
155 /*
156 * ISO 9660 filesystems are not writable.
157 */
158 mntflags |= MNT_RDONLY;
159 args.export.ex_flags = MNT_EXRDONLY;
160 args.fspec = dev;
161 args.export.ex_root = DEFAULT_ROOTUID;
162 args.flags = opts;
163
164 if (mount(MOUNT_CD9660, dir, mntflags, &args) < 0)
165 err(1, "%s on %s", dev, dir);
166 if (mntflags & MNT_GETARGS) {
167 char buf[2048];
168 (void)snprintb(buf, sizeof(buf), ISOFSMNT_BITS, args.flags);
169 printf("%s\n", buf);
170 }
171 exit(0);
172 }
173
174 static void
175 usage(void)
176 {
177 (void)fprintf(stderr,
178 "usage: mount_cd9660 [-o options] special node\n");
179 exit(1);
180 }
181