cd9660_util.c revision 22593
175584Sru/*- 275584Sru * Copyright (c) 1994 375584Sru * 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.3 (Berkeley) 12/5/94 39 * $FreeBSD: head/sys/fs/cd9660/cd9660_util.c 22593 1997-02-12 14:07:26Z bde $ 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/* 62 * translate and compare a filename 63 * Note: Version number plus ';' may be omitted. 64 */ 65int 66isofncmp(fn, fnlen, isofn, isolen) 67 u_char *fn; 68 int fnlen; 69 u_char *isofn; 70 int isolen; 71{ 72 int i, j; 73 unsigned char c; 74 75 while (--fnlen >= 0) { 76 if (--isolen < 0) 77 return *fn; 78 if ((c = *isofn++) == ';') { 79 switch (*fn++) { 80 default: 81 return *--fn; 82 case 0: 83 return 0; 84 case ';': 85 break; 86 } 87 for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') { 88 if (*fn < '0' || *fn > '9') { 89 return -1; 90 } 91 } 92 for (j = 0; --isolen >= 0; j = j * 10 + *isofn++ - '0'); 93 return i - j; 94 } 95 if (c != *fn) { 96 if (c >= 'A' && c <= 'Z') { 97 if (c + ('a' - 'A') != *fn) { 98 if (*fn >= 'a' && *fn <= 'z') 99 return *fn - ('a' - 'A') - c; 100 else 101 return *fn - c; 102 } 103 } else 104 return *fn - c; 105 } 106 fn++; 107 } 108 if (isolen > 0) { 109 switch (*isofn) { 110 default: 111 return -1; 112 case '.': 113 if (isofn[1] != ';') 114 return -1; 115 case ';': 116 return 0; 117 } 118 } 119 return 0; 120} 121 122/* 123 * translate a filename 124 */ 125void 126isofntrans(infn, infnlen, outfn, outfnlen, original, assoc) 127 u_char *infn; 128 int infnlen; 129 u_char *outfn; 130 u_short *outfnlen; 131 int original; 132 int assoc; 133{ 134 int fnidx = 0; 135 136 if (assoc) { 137 *outfn++ = ASSOCCHAR; 138 fnidx++; 139 infnlen++; 140 } 141 for (; fnidx < infnlen; fnidx++) { 142 char c = *infn++; 143 144 if (!original && c >= 'A' && c <= 'Z') 145 *outfn++ = c + ('a' - 'A'); 146 else if (!original && c == '.' && *infn == ';') 147 break; 148 else if (!original && c == ';') 149 break; 150 else 151 *outfn++ = c; 152 } 153 *outfnlen = fnidx; 154} 155