cd9660_util.c revision 8876
11541Srgrimes/*- 21541Srgrimes * Copyright (c) 1994 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed to Berkeley 61541Srgrimes * by Pace Willisson (pace@blitz.com). The Rock Ridge Extension 71541Srgrimes * Support code is derived from software contributed to Berkeley 81541Srgrimes * by Atsushi Murai (amurai@spec.co.jp). 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 3. All advertising materials mentioning features or use of this software 191541Srgrimes * must display the following acknowledgement: 201541Srgrimes * This product includes software developed by the University of 211541Srgrimes * California, Berkeley and its contributors. 221541Srgrimes * 4. Neither the name of the University nor the names of its contributors 231541Srgrimes * may be used to endorse or promote products derived from this software 241541Srgrimes * without specific prior written permission. 251541Srgrimes * 261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361541Srgrimes * SUCH DAMAGE. 371541Srgrimes * 381541Srgrimes * @(#)cd9660_util.c 8.1 (Berkeley) 1/21/94 398876Srgrimes * $Id: cd9660_util.c,v 1.3 1994/08/02 07:41:31 davidg Exp $ 401541Srgrimes */ 411541Srgrimes 421541Srgrimes#include <sys/param.h> 431541Srgrimes#include <sys/systm.h> 441541Srgrimes#include <sys/namei.h> 451541Srgrimes#include <sys/resourcevar.h> 461541Srgrimes#include <sys/kernel.h> 471541Srgrimes#include <sys/file.h> 481541Srgrimes#include <sys/stat.h> 491541Srgrimes#include <sys/buf.h> 501541Srgrimes#include <sys/proc.h> 511541Srgrimes#include <sys/conf.h> 521541Srgrimes#include <sys/mount.h> 531541Srgrimes#include <sys/vnode.h> 541541Srgrimes#include <miscfs/specfs/specdev.h> /* XXX */ 551541Srgrimes#include <miscfs/fifofs/fifo.h> /* XXX */ 561541Srgrimes#include <sys/malloc.h> 571541Srgrimes#include <sys/dir.h> 581541Srgrimes 591541Srgrimes#include <isofs/cd9660/iso.h> 601541Srgrimes 611541Srgrimes#ifdef __notanymore__ 621541Srgrimesint 631541Srgrimesisonum_711 (p) 641541Srgrimesunsigned char *p; 651541Srgrimes{ 661541Srgrimes return (*p); 671541Srgrimes} 681541Srgrimes 691541Srgrimesint 701541Srgrimesisonum_712 (p) 711541Srgrimessigned char *p; 721541Srgrimes{ 731541Srgrimes return (*p); 741541Srgrimes} 751541Srgrimes 761541Srgrimesint 771541Srgrimesisonum_721 (p) 781541Srgrimesunsigned char *p; 791541Srgrimes{ 801541Srgrimes /* little endian short */ 811541Srgrimes#if BYTE_ORDER != LITTLE_ENDIAN 821541Srgrimes printf ("isonum_721 called on non little-endian machine!\n"); 831541Srgrimes#endif 841541Srgrimes 851541Srgrimes return *(short *)p; 861541Srgrimes} 871541Srgrimes 881541Srgrimesint 891541Srgrimesisonum_722 (p) 901541Srgrimesunsigned char *p; 911541Srgrimes{ 921541Srgrimes /* big endian short */ 931541Srgrimes#if BYTE_ORDER != BIG_ENDIAN 941541Srgrimes printf ("isonum_722 called on non big-endian machine!\n"); 951541Srgrimes#endif 961541Srgrimes 971541Srgrimes return *(short *)p; 981541Srgrimes} 991541Srgrimes 1001541Srgrimesint 1011541Srgrimesisonum_723 (p) 1021541Srgrimesunsigned char *p; 1031541Srgrimes{ 1041541Srgrimes#if BYTE_ORDER == BIG_ENDIAN 1051541Srgrimes return isonum_722 (p + 2); 1061541Srgrimes#elif BYTE_ORDER == LITTLE_ENDIAN 1071541Srgrimes return isonum_721 (p); 1081541Srgrimes#else 1091541Srgrimes printf ("isonum_723 unsupported byte order!\n"); 1101541Srgrimes return 0; 1111541Srgrimes#endif 1121541Srgrimes} 1131541Srgrimes 1141541Srgrimesint 1151541Srgrimesisonum_731 (p) 1161541Srgrimesunsigned char *p; 1171541Srgrimes{ 1181541Srgrimes /* little endian long */ 1191541Srgrimes#if BYTE_ORDER != LITTLE_ENDIAN 1201541Srgrimes printf ("isonum_731 called on non little-endian machine!\n"); 1211541Srgrimes#endif 1221541Srgrimes 1231541Srgrimes return *(long *)p; 1241541Srgrimes} 1251541Srgrimes 1261541Srgrimesint 1271541Srgrimesisonum_732 (p) 1281541Srgrimesunsigned char *p; 1291541Srgrimes{ 1301541Srgrimes /* big endian long */ 1311541Srgrimes#if BYTE_ORDER != BIG_ENDIAN 1321541Srgrimes printf ("isonum_732 called on non big-endian machine!\n"); 1331541Srgrimes#endif 1341541Srgrimes 1351541Srgrimes return *(long *)p; 1361541Srgrimes} 1371541Srgrimes 1381541Srgrimesint 1391541Srgrimesisonum_733 (p) 1401541Srgrimesunsigned char *p; 1411541Srgrimes{ 1421541Srgrimes#if BYTE_ORDER == BIG_ENDIAN 1431541Srgrimes return isonum_732 (p + 4); 1441541Srgrimes#elif BYTE_ORDER == LITTLE_ENDIAN 1451541Srgrimes return isonum_731 (p); 1461541Srgrimes#else 1471541Srgrimes printf ("isonum_733 unsupported byte order!\n"); 1481541Srgrimes return 0; 1491541Srgrimes#endif 1501541Srgrimes} 1511541Srgrimes#endif /* __notanymore__ */ 1521541Srgrimes 1531541Srgrimes/* 1541541Srgrimes * translate and compare a filename 1551541Srgrimes * Note: Version number plus ';' may be omitted. 1561541Srgrimes */ 1571541Srgrimesint 1581541Srgrimesisofncmp(unsigned char *fn,int fnlen,unsigned char *isofn,int isolen) 1591541Srgrimes{ 1601541Srgrimes int i, j; 1611549Srgrimes unsigned char c; 1628876Srgrimes 1631541Srgrimes while (--fnlen >= 0) { 1641541Srgrimes if (--isolen < 0) 1651541Srgrimes return *fn; 1661541Srgrimes if ((c = *isofn++) == ';') { 1671541Srgrimes switch (*fn++) { 1681541Srgrimes default: 1691541Srgrimes return *--fn; 1701541Srgrimes case 0: 1711541Srgrimes return 0; 1721541Srgrimes case ';': 1731541Srgrimes break; 1741541Srgrimes } 1751541Srgrimes for (i = 0; --fnlen >= 0; i = i * 10 + *fn++ - '0') { 1761541Srgrimes if (*fn < '0' || *fn > '9') { 1771541Srgrimes return -1; 1781541Srgrimes } 1791541Srgrimes } 1801541Srgrimes for (j = 0; --isolen >= 0; j = j * 10 + *isofn++ - '0'); 1811541Srgrimes return i - j; 1821541Srgrimes } 1831541Srgrimes if (c != *fn) { 1841541Srgrimes if (c >= 'A' && c <= 'Z') { 1851541Srgrimes if (c + ('a' - 'A') != *fn) { 1861541Srgrimes if (*fn >= 'a' && *fn <= 'z') 1871541Srgrimes return *fn - ('a' - 'A') - c; 1881541Srgrimes else 1891541Srgrimes return *fn - c; 1901541Srgrimes } 1911541Srgrimes } else 1921541Srgrimes return *fn - c; 1931541Srgrimes } 1941541Srgrimes fn++; 1951541Srgrimes } 1961541Srgrimes if (isolen > 0) { 1971541Srgrimes switch (*isofn) { 1981541Srgrimes default: 1991541Srgrimes return -1; 2001541Srgrimes case '.': 2011541Srgrimes if (isofn[1] != ';') 2021541Srgrimes return -1; 2031541Srgrimes case ';': 2041541Srgrimes return 0; 2051541Srgrimes } 2061541Srgrimes } 2071541Srgrimes return 0; 2081541Srgrimes} 2091541Srgrimes 2101541Srgrimes/* 2111541Srgrimes * translate a filename 2121541Srgrimes */ 2131541Srgrimesvoid 2141541Srgrimesisofntrans(unsigned char *infn,int infnlen, 2151541Srgrimes unsigned char *outfn,unsigned short *outfnlen, 2161541Srgrimes int original,int assoc) 2171541Srgrimes{ 2181541Srgrimes int fnidx = 0; 2198876Srgrimes 2201541Srgrimes if (assoc) { 2211541Srgrimes *outfn++ = ASSOCCHAR; 2221541Srgrimes fnidx++; 2231541Srgrimes } 2241541Srgrimes for (; fnidx < infnlen; fnidx++) { 2251541Srgrimes char c = *infn++; 2268876Srgrimes 2271541Srgrimes if (!original && c >= 'A' && c <= 'Z') 2281541Srgrimes *outfn++ = c + ('a' - 'A'); 2291541Srgrimes else if (!original && c == '.' && *infn == ';') 2301541Srgrimes break; 2311541Srgrimes else if (!original && c == ';') 2321541Srgrimes break; 2331541Srgrimes else 2341541Srgrimes *outfn++ = c; 2351541Srgrimes } 2361541Srgrimes *outfnlen = fnidx; 2371541Srgrimes} 238