iso.h revision 166774
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 166774 2007-02-15 22:08:35Z pjd $ 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 252166774Spjdstruct ifid { 253166774Spjd u_short ifid_len; 254166774Spjd u_short ifid_pad; 255166774Spjd int ifid_ino; 256166774Spjd long ifid_start; 257166774Spjd}; 258166774Spjd 2591541Srgrimes#define VFSTOISOFS(mp) ((struct iso_mnt *)((mp)->mnt_data)) 2601541Srgrimes 26122521Sdyson#define blkoff(imp, loc) ((loc) & (imp)->im_bmask) 26222521Sdyson#define lblktosize(imp, blk) ((blk) << (imp)->im_bshift) 26322521Sdyson#define lblkno(imp, loc) ((loc) >> (imp)->im_bshift) 26422521Sdyson#define blksize(imp, ip, lbn) ((imp)->logical_block_size) 2651541Srgrimes 26692765Salfredint cd9660_vget_internal(struct mount *, ino_t, int, struct vnode **, int, 26793075Sbde struct iso_directory_record *); 26892765Salfred#define cd9660_sysctl ((int (*)(int *, u_int, void *, size_t *, void *, \ 26993075Sbde size_t, struct proc *))eopnotsupp) 2701541Srgrimes 271138290Sphkextern struct vop_vector cd9660_vnodeops; 272138290Sphkextern struct vop_vector cd9660_fifoops; 2731541Srgrimes 274120492Sfjoeint isochar(u_char *, u_char *, int, u_short *, int *, int, void *); 275120492Sfjoeint isofncmp(u_char *, int, u_char *, int, int, int, void *, void *); 276120492Sfjoevoid isofntrans(u_char *, int, u_char *, u_short *, int, int, int, int, void *); 27792765Salfredino_t isodirino(struct iso_directory_record *, struct iso_mnt *); 278120492Sfjoeu_short sgetrune(const char *, size_t, char const **, int, void *); 27925531Sjoerg 28055206Speter#endif /* _KERNEL */ 28125531Sjoerg 28225531Sjoerg/* 28325531Sjoerg * The isonum_xxx functions are inlined anyway, and could come handy even 28425531Sjoerg * outside the kernel. Thus we don't hide them here. 28525531Sjoerg */ 28625531Sjoerg 287151447Sdes/* 288151447Sdes * 7xy 289151447Sdes * x -> 1 = 8 bits, 2 = 16 bits, 3 = 32 bits 290151447Sdes * y -> 1 = little-endian, 2 = big-endian, 3 = both (le then be) 291151447Sdes */ 292151447Sdes 293151447Sdesstatic __inline uint8_t 294151447Sdesisonum_711(unsigned char *p) 2951541Srgrimes{ 296151447Sdes return p[0]; 2971541Srgrimes} 2981541Srgrimes 299151447Sdesstatic __inline uint8_t 300151447Sdesisonum_712(unsigned char *p) 3011541Srgrimes{ 302151447Sdes return p[0]; 3031541Srgrimes} 3041541Srgrimes 305151447Sdesstatic __inline uint8_t 306151447Sdesisonum_713(unsigned char *p) 307151447Sdes{ 308151447Sdes return p[0]; 309151447Sdes} 31022521Sdyson 311151447Sdesstatic __inline uint16_t 312151447Sdesisonum_721(unsigned char *p) 3131541Srgrimes{ 314151447Sdes return (p[0] | p[1] << 8); 3151541Srgrimes} 3161541Srgrimes 317151447Sdesstatic __inline uint16_t 318151447Sdesisonum_722(unsigned char *p) 3191541Srgrimes{ 320151447Sdes return (p[1] | p[0] << 8); 3211541Srgrimes} 3221541Srgrimes 323151447Sdesstatic __inline uint16_t 324151447Sdesisonum_723(unsigned char *p) 3251541Srgrimes{ 326151447Sdes return (p[0] | p[1] << 8); 3271541Srgrimes} 3281541Srgrimes 329151447Sdesstatic __inline uint32_t 330151447Sdesisonum_731(unsigned char *p) 3311541Srgrimes{ 332151447Sdes return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24); 3331541Srgrimes} 3341541Srgrimes 335151447Sdesstatic __inline uint32_t 336151447Sdesisonum_732(unsigned char *p) 3371541Srgrimes{ 338151447Sdes return (p[3] | p[2] << 8 | p[1] << 16 | p[0] << 24); 3391541Srgrimes} 3401541Srgrimes 341151447Sdesstatic __inline uint32_t 342151447Sdesisonum_733(unsigned char *p) 3431541Srgrimes{ 344151447Sdes return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24); 3451541Srgrimes} 3461541Srgrimes 3471541Srgrimes/* 3481541Srgrimes * Associated files have a leading '='. 3491541Srgrimes */ 3501541Srgrimes#define ASSOCCHAR '=' 351