3 * The Regents of the University of California. All rights reserved.
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). Joliet support was added by
9 * Joachim Kuebart (joki@kuebart.stuttgart.netsurf.de).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * @(#)cd9660_util.c 8.3 (Berkeley) 12/5/94
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/mount.h>
44 #include <sys/vnode.h>
45 #include <sys/iconv.h>
47 #include <fs/cd9660/iso.h>
48 #include <fs/cd9660/cd9660_mount.h>
50 extern struct iconv_functions *cd9660_iconv;
53 * Get one character out of an iso filename
55 * Return number of bytes consumed
58 isochar(isofn, isoend, joliet_level, c, clen, flags, handle)
68 char inbuf[3], outbuf[3], *inp, *outp;
72 if (joliet_level == 0 || isofn == isoend)
73 /* (00) and (01) are one byte in Joliet, too */
76 if (flags & ISOFSMNT_KICONV && cd9660_iconv) {
78 inbuf[0]=(char)*(isofn - 1);
79 inbuf[1]=(char)*isofn;
83 cd9660_iconv->convchr(handle, (const char **)&inp, &i, &outp, &j);
85 if (clen) *clen = len;
88 *c |= (*(outp - len - 1) & 0xff) << (len << 3);
104 * translate and compare a filename
105 * returns (fn - isofn)
106 * Note: Version number plus ';' may be omitted.
109 isofncmp(fn, fnlen, isofn, isolen, joliet_level, flags, handle, lhandle)
121 u_char *fnend = fn + fnlen, *isoend = isofn + isolen;
123 for (; fn < fnend; ) {
124 d = sgetrune(fn, fnend - fn, (char const **)&fn, flags, lhandle);
127 isofn += isochar(isofn, isoend, joliet_level, &c, NULL, flags, handle);
131 for (i = 0; fn < fnend; i = i * 10 + *fn++ - '0') {
132 if (*fn < '0' || *fn > '9') {
136 for (j = 0; isofn != isoend; j = j * 10 + c - '0')
137 isofn += isochar(isofn, isoend,
139 NULL, flags, handle);
143 if (c >= 'A' && c <= 'Z') {
144 if (c + ('a' - 'A') != d) {
145 if (d >= 'a' && d <= 'z')
146 return d - ('a' - 'A') - c;
154 if (isofn != isoend) {
155 isofn += isochar(isofn, isoend, joliet_level, &c, NULL, flags, handle);
160 if (isofn != isoend) {
161 isochar(isofn, isoend, joliet_level, &c,
162 NULL, flags, handle);
175 * translate a filename of length > 0
178 isofntrans(infn, infnlen, outfn, outfnlen, original, assoc, joliet_level, flags, handle)
190 u_char *outp = outfn, *infnend = infn + infnlen;
196 for (; infn != infnend; ) {
197 infn += isochar(infn, infnend, joliet_level, &c, &clen, flags, handle);
199 if (!original && !joliet_level && c >= 'A' && c <= 'Z')
201 else if (!original && c == ';') {
207 *outp++ = c >> (clen << 3);
209 *outfnlen = outp - outfn;
213 * same as sgetrune(3)
216 sgetrune(string, n, result, flags, handle)
224 char outbuf[3], *outp;
227 len = i = (n < 2) ? n : 2;
231 if (flags & ISOFSMNT_KICONV && cd9660_iconv) {
232 cd9660_iconv->convchr(handle, (const char **)&string,
240 if (result) *result = string;
241 while(len--) c |= (*(string - len - 1) & 0xff) << (len << 3);