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