Sat Jan 3 20:11:04 2009 UTC ()
reset args. Add casetrans


(christos)
diff -r1.28 -r1.29 src/sbin/mount_cd9660/mount_cd9660.c

cvs diff -r1.28 -r1.29 src/sbin/mount_cd9660/mount_cd9660.c (switch to unified diff)

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