1 /*- 2 * Copyright (c) 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 * @(#)cd9660_util.c 8.1 (Berkeley) 1/21/94 39 */ 40 41 #include <sys/param.h> 42 #include <sys/systm.h> 43 #include <sys/namei.h> 44 #include <sys/resourcevar.h> 45 #include <sys/kernel.h> 46 #include <sys/file.h> 47 #include <sys/stat.h> 48 #include <sys/buf.h> 49 #include <sys/proc.h> 50 #include <sys/conf.h> 51 #include <sys/mount.h> 52 #include <sys/vnode.h> 53 #include <miscfs/specfs/specdev.h> /* XXX */ 54 #include <miscfs/fifofs/fifo.h> /* XXX */ 55 #include <sys/malloc.h> 56 #include <sys/dir.h> 57 58 #include <isofs/cd9660/iso.h> 59 60 #ifdef __notanymore__ 61 int 62 isonum_711 (p) 63 unsigned char *p; 64 { 65 return (*p); 66 } 67 68 int 69 isonum_712 (p) 70 signed char *p; 71 { 72 return (*p); 73 } 74 75 int 76 isonum_721 (p) 77 unsigned char *p; 78 { 79 /* little endian short */ 80 #if BYTE_ORDER != LITTLE_ENDIAN 81 printf ("isonum_721 called on non little-endian machine!\n"); 82 #endif 83 84 return *(short *)p; 85 } 86 87 int 88 isonum_722 (p) 89 unsigned char *p; 90 { 91 /* big endian short */ 92 #if BYTE_ORDER != BIG_ENDIAN 93 printf ("isonum_722 called on non big-endian machine!\n"); 94 #endif 95 96 return *(short *)p; 97 } 98 99 int 100 isonum_723 (p) 101 unsigned char *p; 102 { 103 #if BYTE_ORDER == BIG_ENDIAN 104 return isonum_722 (p + 2); 105 #elif BYTE_ORDER == LITTLE_ENDIAN 106 return isonum_721 (p); 107 #else 108 printf ("isonum_723 unsupported byte order!\n"); 109 return 0; 110 #endif 111 } 112 113 int 114 isonum_731 (p) 115 unsigned char *p; 116 { 117 /* little endian long */ 118 #if BYTE_ORDER != LITTLE_ENDIAN 119 printf ("isonum_731 called on non little-endian machine!\n"); 120 #endif 121 122 return *(long *)p; 123 } 124 125 int 126 isonum_732 (p) 127 unsigned char *p; 128 { 129 /* big endian long */ 130 #if BYTE_ORDER != BIG_ENDIAN 131 printf ("isonum_732 called on non big-endian machine!\n"); 132 #endif 133 134 return *(long *)p; 135 } 136 137 int 138 isonum_733 (p) 139 unsigned char *p; 140 { 141 #if BYTE_ORDER == BIG_ENDIAN 142 return isonum_732 (p + 4); 143 #elif BYTE_ORDER == LITTLE_ENDIAN 144 return isonum_731 (p); 145 #else 146 printf ("isonum_733 unsupported byte order!\n"); 147 return 0; 148 #endif 149 } 150 #endif /* __notanymore__ */ 151 152 /* 153 * translate and compare a filename 154 * Note: Version number plus ';' may be omitted. 155 */ 156 int 157 isofncmp(unsigned char *fn,int fnlen,unsigned char *isofn,int isolen) 158 { 159 int i, j; 160 unsigned char c; 161 162 while (--fnlen >= 0) { 163 if (--isolen < 0) 164 return *fn; 165 if ((c = *isofn++) == ';') { 166 switch (*fn++) { 167 default: 168 return *--fn; 169 case 0: 170 return 0; 171 case ';': 172 break; 173 } 174 for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') { 175 if (*fn < '0' || *fn > '9') { 176 return -1; 177 } 178 } 179 for (j = 0; --isolen >= 0; j = j * 10 + *isofn++ - '0'); 180 return i - j; 181 } 182 if (c != *fn) { 183 if (c >= 'A' && c <= 'Z') { 184 if (c + ('a' - 'A') != *fn) { 185 if (*fn >= 'a' && *fn <= 'z') 186 return *fn - ('a' - 'A') - c; 187 else 188 return *fn - c; 189 } 190 } else 191 return *fn - c; 192 } 193 fn++; 194 } 195 if (isolen > 0) { 196 switch (*isofn) { 197 default: 198 return -1; 199 case '.': 200 if (isofn[1] != ';') 201 return -1; 202 case ';': 203 return 0; 204 } 205 } 206 return 0; 207 } 208 209 /* 210 * translate a filename 211 */ 212 void 213 isofntrans(unsigned char *infn,int infnlen, 214 unsigned char *outfn,unsigned short *outfnlen, 215 int original,int assoc) 216 { 217 int fnidx = 0; 218 219 if (assoc) { 220 *outfn++ = ASSOCCHAR; 221 fnidx++; 222 } 223 for (; fnidx < infnlen; fnidx++) { 224 char c = *infn++; 225 226 if (!original && c >= 'A' && c <= 'Z') 227 *outfn++ = c + ('a' - 'A'); 228 else if (!original && c == '.' && *infn == ';') 229 break; 230 else if (!original && c == ';') 231 break; 232 else 233 *outfn++ = c; 234 } 235 *outfnlen = fnidx; 236 } 237