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