iso.h revision 138290
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 * 4. Neither the name of the University nor the names of its contributors 191541Srgrimes * may be used to endorse or promote products derived from this software 201541Srgrimes * without specific prior written permission. 211541Srgrimes * 221541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321541Srgrimes * SUCH DAMAGE. 331541Srgrimes * 3422521Sdyson * @(#)iso.h 8.6 (Berkeley) 5/10/95 3550477Speter * $FreeBSD: head/sys/fs/cd9660/iso.h 138290 2004-12-01 23:16:38Z phk $ 361541Srgrimes */ 371541Srgrimes 381541Srgrimes#define ISODCL(from, to) (to - from + 1) 391541Srgrimes 401541Srgrimesstruct iso_volume_descriptor { 411541Srgrimes char type[ISODCL(1,1)]; /* 711 */ 421541Srgrimes char id[ISODCL(2,6)]; 431541Srgrimes char version[ISODCL(7,7)]; 445651Sjoerg char unused[ISODCL(8,8)]; 455651Sjoerg char type_sierra[ISODCL(9,9)]; /* 711 */ 465651Sjoerg char id_sierra[ISODCL(10,14)]; 475651Sjoerg char version_sierra[ISODCL(15,15)]; 485651Sjoerg char data[ISODCL(16,2048)]; 491541Srgrimes}; 501541Srgrimes 511541Srgrimes/* volume descriptor types */ 521541Srgrimes#define ISO_VD_PRIMARY 1 5345773Sdcs#define ISO_VD_SUPPLEMENTARY 2 541541Srgrimes#define ISO_VD_END 255 551541Srgrimes 561541Srgrimes#define ISO_STANDARD_ID "CD001" 575651Sjoerg#define ISO_ECMA_ID "CDW01" 581541Srgrimes 595651Sjoerg#define ISO_SIERRA_ID "CDROM" 605651Sjoerg 611541Srgrimesstruct iso_primary_descriptor { 625651Sjoerg char type [ISODCL ( 1, 1)]; /* 711 */ 635651Sjoerg char id [ISODCL ( 2, 6)]; 645651Sjoerg char version [ISODCL ( 7, 7)]; /* 711 */ 655651Sjoerg char unused1 [ISODCL ( 8, 8)]; 661541Srgrimes char system_id [ISODCL ( 9, 40)]; /* achars */ 671541Srgrimes char volume_id [ISODCL ( 41, 72)]; /* dchars */ 681541Srgrimes char unused2 [ISODCL ( 73, 80)]; 691541Srgrimes char volume_space_size [ISODCL ( 81, 88)]; /* 733 */ 701541Srgrimes char unused3 [ISODCL ( 89, 120)]; 711541Srgrimes char volume_set_size [ISODCL (121, 124)]; /* 723 */ 721541Srgrimes char volume_sequence_number [ISODCL (125, 128)]; /* 723 */ 731541Srgrimes char logical_block_size [ISODCL (129, 132)]; /* 723 */ 741541Srgrimes char path_table_size [ISODCL (133, 140)]; /* 733 */ 751541Srgrimes char type_l_path_table [ISODCL (141, 144)]; /* 731 */ 761541Srgrimes char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */ 771541Srgrimes char type_m_path_table [ISODCL (149, 152)]; /* 732 */ 781541Srgrimes char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */ 791541Srgrimes char root_directory_record [ISODCL (157, 190)]; /* 9.1 */ 801541Srgrimes char volume_set_id [ISODCL (191, 318)]; /* dchars */ 811541Srgrimes char publisher_id [ISODCL (319, 446)]; /* achars */ 821541Srgrimes char preparer_id [ISODCL (447, 574)]; /* achars */ 831541Srgrimes char application_id [ISODCL (575, 702)]; /* achars */ 841541Srgrimes char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */ 851541Srgrimes char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */ 861541Srgrimes char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */ 871541Srgrimes char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */ 881541Srgrimes char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */ 891541Srgrimes char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */ 901541Srgrimes char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */ 911541Srgrimes char file_structure_version [ISODCL (882, 882)]; /* 711 */ 921541Srgrimes char unused4 [ISODCL (883, 883)]; 931541Srgrimes char application_data [ISODCL (884, 1395)]; 941541Srgrimes char unused5 [ISODCL (1396, 2048)]; 951541Srgrimes}; 961541Srgrimes#define ISO_DEFAULT_BLOCK_SIZE 2048 971541Srgrimes 9845773Sdcs/* 9945773Sdcs * Used by Microsoft Joliet extension to ISO9660. Almost the same 10045773Sdcs * as PVD, but byte position 8 is a flag, and 89-120 is for escape. 10145773Sdcs */ 10245773Sdcs 10345773Sdcsstruct iso_supplementary_descriptor { 10445773Sdcs char type [ISODCL ( 1, 1)]; /* 711 */ 10545773Sdcs char id [ISODCL ( 2, 6)]; 10645773Sdcs char version [ISODCL ( 7, 7)]; /* 711 */ 10745773Sdcs char flags [ISODCL ( 8, 8)]; /* 711? */ 10845773Sdcs char system_id [ISODCL ( 9, 40)]; /* achars */ 10945773Sdcs char volume_id [ISODCL ( 41, 72)]; /* dchars */ 11045773Sdcs char unused2 [ISODCL ( 73, 80)]; 11145773Sdcs char volume_space_size [ISODCL ( 81, 88)]; /* 733 */ 11245773Sdcs char escape [ISODCL ( 89, 120)]; 11345773Sdcs char volume_set_size [ISODCL (121, 124)]; /* 723 */ 11445773Sdcs char volume_sequence_number [ISODCL (125, 128)]; /* 723 */ 11545773Sdcs char logical_block_size [ISODCL (129, 132)]; /* 723 */ 11645773Sdcs char path_table_size [ISODCL (133, 140)]; /* 733 */ 11745773Sdcs char type_l_path_table [ISODCL (141, 144)]; /* 731 */ 11845773Sdcs char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */ 11945773Sdcs char type_m_path_table [ISODCL (149, 152)]; /* 732 */ 12045773Sdcs char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */ 12145773Sdcs char root_directory_record [ISODCL (157, 190)]; /* 9.1 */ 12245773Sdcs char volume_set_id [ISODCL (191, 318)]; /* dchars */ 12345773Sdcs char publisher_id [ISODCL (319, 446)]; /* achars */ 12445773Sdcs char preparer_id [ISODCL (447, 574)]; /* achars */ 12545773Sdcs char application_id [ISODCL (575, 702)]; /* achars */ 12645773Sdcs char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */ 12745773Sdcs char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */ 12845773Sdcs char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */ 12945773Sdcs char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */ 13045773Sdcs char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */ 13145773Sdcs char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */ 13245773Sdcs char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */ 13345773Sdcs char file_structure_version [ISODCL (882, 882)]; /* 711 */ 13445773Sdcs char unused4 [ISODCL (883, 883)]; 13545773Sdcs char application_data [ISODCL (884, 1395)]; 13645773Sdcs char unused5 [ISODCL (1396, 2048)]; 13745773Sdcs}; 13845773Sdcs 1395651Sjoergstruct iso_sierra_primary_descriptor { 1405651Sjoerg char unknown1 [ISODCL ( 1, 8)]; /* 733 */ 1415651Sjoerg char type [ISODCL ( 9, 9)]; /* 711 */ 1425651Sjoerg char id [ISODCL ( 10, 14)]; 1435651Sjoerg char version [ISODCL ( 15, 15)]; /* 711 */ 1445651Sjoerg char unused1 [ISODCL ( 16, 16)]; 1455651Sjoerg char system_id [ISODCL ( 17, 48)]; /* achars */ 1465651Sjoerg char volume_id [ISODCL ( 49, 80)]; /* dchars */ 1475651Sjoerg char unused2 [ISODCL ( 81, 88)]; 1485651Sjoerg char volume_space_size [ISODCL ( 89, 96)]; /* 733 */ 1495651Sjoerg char unused3 [ISODCL ( 97, 128)]; 1505651Sjoerg char volume_set_size [ISODCL (129, 132)]; /* 723 */ 1515651Sjoerg char volume_sequence_number [ISODCL (133, 136)]; /* 723 */ 1525651Sjoerg char logical_block_size [ISODCL (137, 140)]; /* 723 */ 1535651Sjoerg char path_table_size [ISODCL (141, 148)]; /* 733 */ 1545651Sjoerg char type_l_path_table [ISODCL (149, 152)]; /* 731 */ 1555651Sjoerg char opt_type_l_path_table [ISODCL (153, 156)]; /* 731 */ 1565651Sjoerg char unknown2 [ISODCL (157, 160)]; /* 731 */ 1575651Sjoerg char unknown3 [ISODCL (161, 164)]; /* 731 */ 1585651Sjoerg char type_m_path_table [ISODCL (165, 168)]; /* 732 */ 1595651Sjoerg char opt_type_m_path_table [ISODCL (169, 172)]; /* 732 */ 1605651Sjoerg char unknown4 [ISODCL (173, 176)]; /* 732 */ 1615651Sjoerg char unknown5 [ISODCL (177, 180)]; /* 732 */ 1625651Sjoerg char root_directory_record [ISODCL (181, 214)]; /* 9.1 */ 1635651Sjoerg char volume_set_id [ISODCL (215, 342)]; /* dchars */ 1645651Sjoerg char publisher_id [ISODCL (343, 470)]; /* achars */ 1655651Sjoerg char preparer_id [ISODCL (471, 598)]; /* achars */ 1665651Sjoerg char application_id [ISODCL (599, 726)]; /* achars */ 1675651Sjoerg char copyright_id [ISODCL (727, 790)]; /* achars */ 1685651Sjoerg char creation_date [ISODCL (791, 806)]; /* ? */ 1695651Sjoerg char modification_date [ISODCL (807, 822)]; /* ? */ 1705651Sjoerg char expiration_date [ISODCL (823, 838)]; /* ? */ 1715651Sjoerg char effective_date [ISODCL (839, 854)]; /* ? */ 1725651Sjoerg char file_structure_version [ISODCL (855, 855)]; /* 711 */ 1735651Sjoerg char unused4 [ISODCL (856, 2048)]; 1745651Sjoerg}; 1755651Sjoerg 1761541Srgrimesstruct iso_directory_record { 1771541Srgrimes char length [ISODCL (1, 1)]; /* 711 */ 1781541Srgrimes char ext_attr_length [ISODCL (2, 2)]; /* 711 */ 17922521Sdyson u_char extent [ISODCL (3, 10)]; /* 733 */ 18022521Sdyson u_char size [ISODCL (11, 18)]; /* 733 */ 1811541Srgrimes char date [ISODCL (19, 25)]; /* 7 by 711 */ 1821541Srgrimes char flags [ISODCL (26, 26)]; 1831541Srgrimes char file_unit_size [ISODCL (27, 27)]; /* 711 */ 1841541Srgrimes char interleave [ISODCL (28, 28)]; /* 711 */ 1851541Srgrimes char volume_sequence_number [ISODCL (29, 32)]; /* 723 */ 1861541Srgrimes char name_len [ISODCL (33, 33)]; /* 711 */ 18722521Sdyson char name [1]; /* XXX */ 1881541Srgrimes}; 1891541Srgrimes/* can't take sizeof(iso_directory_record), because of possible alignment 1901541Srgrimes of the last entry (34 instead of 33) */ 1911541Srgrimes#define ISO_DIRECTORY_RECORD_SIZE 33 1921541Srgrimes 1931541Srgrimesstruct iso_extended_attributes { 19422521Sdyson u_char owner [ISODCL (1, 4)]; /* 723 */ 19522521Sdyson u_char group [ISODCL (5, 8)]; /* 723 */ 19622521Sdyson u_char perm [ISODCL (9, 10)]; /* 9.5.3 */ 1971541Srgrimes char ctime [ISODCL (11, 27)]; /* 8.4.26.1 */ 1981541Srgrimes char mtime [ISODCL (28, 44)]; /* 8.4.26.1 */ 1991541Srgrimes char xtime [ISODCL (45, 61)]; /* 8.4.26.1 */ 2001541Srgrimes char ftime [ISODCL (62, 78)]; /* 8.4.26.1 */ 2011541Srgrimes char recfmt [ISODCL (79, 79)]; /* 711 */ 2021541Srgrimes char recattr [ISODCL (80, 80)]; /* 711 */ 20322521Sdyson u_char reclen [ISODCL (81, 84)]; /* 723 */ 2041541Srgrimes char system_id [ISODCL (85, 116)]; /* achars */ 2051541Srgrimes char system_use [ISODCL (117, 180)]; 2061541Srgrimes char version [ISODCL (181, 181)]; /* 711 */ 2071541Srgrimes char len_esc [ISODCL (182, 182)]; /* 711 */ 2081541Srgrimes char reserved [ISODCL (183, 246)]; 20922521Sdyson u_char len_au [ISODCL (247, 250)]; /* 723 */ 2101541Srgrimes}; 2111541Srgrimes 21255206Speter#ifdef _KERNEL 21325531Sjoerg 2141541Srgrimes/* CD-ROM Format type */ 2155651Sjoergenum ISO_FTYPE { ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP, 21645773Sdcs ISO_FTYPE_JOLIET, ISO_FTYPE_ECMA, ISO_FTYPE_HIGH_SIERRA }; 2171541Srgrimes 2181541Srgrimes#ifndef ISOFSMNT_ROOT 2191541Srgrimes#define ISOFSMNT_ROOT 0 2201541Srgrimes#endif 2211541Srgrimes 2221541Srgrimesstruct iso_mnt { 2231541Srgrimes int im_flags; 2241541Srgrimes 2251541Srgrimes struct mount *im_mountp; 226130585Sphk struct cdev *im_dev; 2271541Srgrimes struct vnode *im_devvp; 2281541Srgrimes 229137038Sphk struct g_consumer *im_cp; 230137038Sphk struct bufobj *im_bo; 231137038Sphk 2321541Srgrimes int logical_block_size; 2331541Srgrimes int im_bshift; 2341541Srgrimes int im_bmask; 2358876Srgrimes 2361541Srgrimes int volume_space_size; 2378876Srgrimes 2381541Srgrimes char root[ISODCL (157, 190)]; 2391541Srgrimes int root_extent; 2401541Srgrimes int root_size; 2415651Sjoerg enum ISO_FTYPE iso_ftype; 2428876Srgrimes 2431541Srgrimes int rr_skip; 2441541Srgrimes int rr_skip0; 24545773Sdcs 24645773Sdcs int joliet_level; 247120492Sfjoe 248120492Sfjoe void *im_d2l; 249120492Sfjoe void *im_l2d; 2501541Srgrimes}; 2511541Srgrimes 2521541Srgrimes#define VFSTOISOFS(mp) ((struct iso_mnt *)((mp)->mnt_data)) 2531541Srgrimes 25422521Sdyson#define blkoff(imp, loc) ((loc) & (imp)->im_bmask) 25522521Sdyson#define lblktosize(imp, blk) ((blk) << (imp)->im_bshift) 25622521Sdyson#define lblkno(imp, loc) ((loc) >> (imp)->im_bshift) 25722521Sdyson#define blksize(imp, ip, lbn) ((imp)->logical_block_size) 2581541Srgrimes 25992765Salfredint cd9660_vget_internal(struct mount *, ino_t, int, struct vnode **, int, 26093075Sbde struct iso_directory_record *); 26192765Salfredint cd9660_init(struct vfsconf *); 26292765Salfredint cd9660_uninit(struct vfsconf *); 26392765Salfred#define cd9660_sysctl ((int (*)(int *, u_int, void *, size_t *, void *, \ 26493075Sbde size_t, struct proc *))eopnotsupp) 2651541Srgrimes 266138290Sphkextern struct vop_vector cd9660_vnodeops; 267138290Sphkextern struct vop_vector cd9660_fifoops; 2681541Srgrimes 269120492Sfjoeint isochar(u_char *, u_char *, int, u_short *, int *, int, void *); 270120492Sfjoeint isofncmp(u_char *, int, u_char *, int, int, int, void *, void *); 271120492Sfjoevoid isofntrans(u_char *, int, u_char *, u_short *, int, int, int, int, void *); 27292765Salfredino_t isodirino(struct iso_directory_record *, struct iso_mnt *); 273120492Sfjoeu_short sgetrune(const char *, size_t, char const **, int, void *); 27425531Sjoerg 27555206Speter#endif /* _KERNEL */ 27625531Sjoerg 27725531Sjoerg/* 27825531Sjoerg * The isonum_xxx functions are inlined anyway, and could come handy even 27925531Sjoerg * outside the kernel. Thus we don't hide them here. 28025531Sjoerg */ 28125531Sjoerg 28292765Salfredstatic __inline int isonum_711(u_char *); 28322521Sdysonstatic __inline int 2841541Srgrimesisonum_711(p) 28522521Sdyson u_char *p; 2861541Srgrimes{ 2871541Srgrimes return *p; 2881541Srgrimes} 2891541Srgrimes 29092765Salfredstatic __inline int isonum_712(char *); 29122521Sdysonstatic __inline int 2921541Srgrimesisonum_712(p) 2931541Srgrimes char *p; 2941541Srgrimes{ 2951541Srgrimes return *p; 2961541Srgrimes} 2971541Srgrimes 29822521Sdyson#ifndef UNALIGNED_ACCESS 29922521Sdyson 30092765Salfredstatic __inline int isonum_723(u_char *); 30122521Sdysonstatic __inline int 30222521Sdysonisonum_723(p) 30322521Sdyson u_char *p; 3041541Srgrimes{ 30522521Sdyson return *p|(p[1] << 8); 3061541Srgrimes} 3071541Srgrimes 30892765Salfredstatic __inline int isonum_733(u_char *); 30922521Sdysonstatic __inline int 31022521Sdysonisonum_733(p) 31122521Sdyson u_char *p; 3121541Srgrimes{ 31322521Sdyson return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24); 3141541Srgrimes} 3151541Srgrimes 31622521Sdyson#else /* UNALIGNED_ACCESS */ 31722521Sdyson 31822521Sdyson#if BYTE_ORDER == LITTLE_ENDIAN 31922521Sdyson 32022521Sdysonstatic __inline int 3211541Srgrimesisonum_723(p) 32222521Sdyson u_char *p 3231541Srgrimes{ 32422521Sdyson return *(u_int16t *)p; 3251541Srgrimes} 3261541Srgrimes 32722521Sdysonstatic __inline int 32822521Sdysonisonum_733(p) 32922521Sdyson u_char *p; 3301541Srgrimes{ 33122521Sdyson return *(u_int32t *)p; 3321541Srgrimes} 3331541Srgrimes 33422521Sdyson#endif 33522521Sdyson 33622521Sdyson#if BYTE_ORDER == BIG_ENDIAN 33722521Sdyson 33822521Sdysonstatic __inline int 33922521Sdysonisonum_723(p) 34022521Sdyson u_char *p 3411541Srgrimes{ 34222521Sdyson return *(u_int16t *)(p + 2); 3431541Srgrimes} 3441541Srgrimes 34522521Sdysonstatic __inline int 3461541Srgrimesisonum_733(p) 34722521Sdyson u_char *p; 3481541Srgrimes{ 34922521Sdyson return *(u_int32t *)(p + 4); 3501541Srgrimes} 3511541Srgrimes 35222521Sdyson#endif 3531541Srgrimes 35422521Sdyson#endif /* UNALIGNED_ACCESS */ 35522521Sdyson 3561541Srgrimes/* 3571541Srgrimes * Associated files have a leading '='. 3581541Srgrimes */ 3591541Srgrimes#define ASSOCCHAR '=' 360