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: stable/11/sys/fs/cd9660/iso.h 332955 2018-04-24 18:13:28Z benno $ 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}; 96332955Sbenno#define ISO_DEFAULT_BLOCK_SHIFT 11 97332955Sbenno#define ISO_DEFAULT_BLOCK_SIZE (1 << ISO_DEFAULT_BLOCK_SHIFT) 981541Srgrimes 9945773Sdcs/* 10045773Sdcs * Used by Microsoft Joliet extension to ISO9660. Almost the same 10145773Sdcs * as PVD, but byte position 8 is a flag, and 89-120 is for escape. 10245773Sdcs */ 10345773Sdcs 10445773Sdcsstruct iso_supplementary_descriptor { 10545773Sdcs char type [ISODCL ( 1, 1)]; /* 711 */ 10645773Sdcs char id [ISODCL ( 2, 6)]; 10745773Sdcs char version [ISODCL ( 7, 7)]; /* 711 */ 10845773Sdcs char flags [ISODCL ( 8, 8)]; /* 711? */ 10945773Sdcs char system_id [ISODCL ( 9, 40)]; /* achars */ 11045773Sdcs char volume_id [ISODCL ( 41, 72)]; /* dchars */ 11145773Sdcs char unused2 [ISODCL ( 73, 80)]; 11245773Sdcs char volume_space_size [ISODCL ( 81, 88)]; /* 733 */ 11345773Sdcs char escape [ISODCL ( 89, 120)]; 11445773Sdcs char volume_set_size [ISODCL (121, 124)]; /* 723 */ 11545773Sdcs char volume_sequence_number [ISODCL (125, 128)]; /* 723 */ 11645773Sdcs char logical_block_size [ISODCL (129, 132)]; /* 723 */ 11745773Sdcs char path_table_size [ISODCL (133, 140)]; /* 733 */ 11845773Sdcs char type_l_path_table [ISODCL (141, 144)]; /* 731 */ 11945773Sdcs char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */ 12045773Sdcs char type_m_path_table [ISODCL (149, 152)]; /* 732 */ 12145773Sdcs char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */ 12245773Sdcs char root_directory_record [ISODCL (157, 190)]; /* 9.1 */ 12345773Sdcs char volume_set_id [ISODCL (191, 318)]; /* dchars */ 12445773Sdcs char publisher_id [ISODCL (319, 446)]; /* achars */ 12545773Sdcs char preparer_id [ISODCL (447, 574)]; /* achars */ 12645773Sdcs char application_id [ISODCL (575, 702)]; /* achars */ 12745773Sdcs char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */ 12845773Sdcs char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */ 12945773Sdcs char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */ 13045773Sdcs char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */ 13145773Sdcs char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */ 13245773Sdcs char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */ 13345773Sdcs char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */ 13445773Sdcs char file_structure_version [ISODCL (882, 882)]; /* 711 */ 13545773Sdcs char unused4 [ISODCL (883, 883)]; 13645773Sdcs char application_data [ISODCL (884, 1395)]; 13745773Sdcs char unused5 [ISODCL (1396, 2048)]; 13845773Sdcs}; 13945773Sdcs 1405651Sjoergstruct iso_sierra_primary_descriptor { 1415651Sjoerg char unknown1 [ISODCL ( 1, 8)]; /* 733 */ 1425651Sjoerg char type [ISODCL ( 9, 9)]; /* 711 */ 1435651Sjoerg char id [ISODCL ( 10, 14)]; 1445651Sjoerg char version [ISODCL ( 15, 15)]; /* 711 */ 1455651Sjoerg char unused1 [ISODCL ( 16, 16)]; 1465651Sjoerg char system_id [ISODCL ( 17, 48)]; /* achars */ 1475651Sjoerg char volume_id [ISODCL ( 49, 80)]; /* dchars */ 1485651Sjoerg char unused2 [ISODCL ( 81, 88)]; 1495651Sjoerg char volume_space_size [ISODCL ( 89, 96)]; /* 733 */ 1505651Sjoerg char unused3 [ISODCL ( 97, 128)]; 1515651Sjoerg char volume_set_size [ISODCL (129, 132)]; /* 723 */ 1525651Sjoerg char volume_sequence_number [ISODCL (133, 136)]; /* 723 */ 1535651Sjoerg char logical_block_size [ISODCL (137, 140)]; /* 723 */ 1545651Sjoerg char path_table_size [ISODCL (141, 148)]; /* 733 */ 1555651Sjoerg char type_l_path_table [ISODCL (149, 152)]; /* 731 */ 1565651Sjoerg char opt_type_l_path_table [ISODCL (153, 156)]; /* 731 */ 1575651Sjoerg char unknown2 [ISODCL (157, 160)]; /* 731 */ 1585651Sjoerg char unknown3 [ISODCL (161, 164)]; /* 731 */ 1595651Sjoerg char type_m_path_table [ISODCL (165, 168)]; /* 732 */ 1605651Sjoerg char opt_type_m_path_table [ISODCL (169, 172)]; /* 732 */ 1615651Sjoerg char unknown4 [ISODCL (173, 176)]; /* 732 */ 1625651Sjoerg char unknown5 [ISODCL (177, 180)]; /* 732 */ 1635651Sjoerg char root_directory_record [ISODCL (181, 214)]; /* 9.1 */ 1645651Sjoerg char volume_set_id [ISODCL (215, 342)]; /* dchars */ 1655651Sjoerg char publisher_id [ISODCL (343, 470)]; /* achars */ 1665651Sjoerg char preparer_id [ISODCL (471, 598)]; /* achars */ 1675651Sjoerg char application_id [ISODCL (599, 726)]; /* achars */ 1685651Sjoerg char copyright_id [ISODCL (727, 790)]; /* achars */ 1695651Sjoerg char creation_date [ISODCL (791, 806)]; /* ? */ 1705651Sjoerg char modification_date [ISODCL (807, 822)]; /* ? */ 1715651Sjoerg char expiration_date [ISODCL (823, 838)]; /* ? */ 1725651Sjoerg char effective_date [ISODCL (839, 854)]; /* ? */ 1735651Sjoerg char file_structure_version [ISODCL (855, 855)]; /* 711 */ 1745651Sjoerg char unused4 [ISODCL (856, 2048)]; 1755651Sjoerg}; 1765651Sjoerg 1771541Srgrimesstruct iso_directory_record { 1781541Srgrimes char length [ISODCL (1, 1)]; /* 711 */ 1791541Srgrimes char ext_attr_length [ISODCL (2, 2)]; /* 711 */ 18022521Sdyson u_char extent [ISODCL (3, 10)]; /* 733 */ 18122521Sdyson u_char size [ISODCL (11, 18)]; /* 733 */ 1821541Srgrimes char date [ISODCL (19, 25)]; /* 7 by 711 */ 1831541Srgrimes char flags [ISODCL (26, 26)]; 1841541Srgrimes char file_unit_size [ISODCL (27, 27)]; /* 711 */ 1851541Srgrimes char interleave [ISODCL (28, 28)]; /* 711 */ 1861541Srgrimes char volume_sequence_number [ISODCL (29, 32)]; /* 723 */ 1871541Srgrimes char name_len [ISODCL (33, 33)]; /* 711 */ 18822521Sdyson char name [1]; /* XXX */ 1891541Srgrimes}; 1901541Srgrimes/* can't take sizeof(iso_directory_record), because of possible alignment 1911541Srgrimes of the last entry (34 instead of 33) */ 1921541Srgrimes#define ISO_DIRECTORY_RECORD_SIZE 33 1931541Srgrimes 1941541Srgrimesstruct iso_extended_attributes { 19522521Sdyson u_char owner [ISODCL (1, 4)]; /* 723 */ 19622521Sdyson u_char group [ISODCL (5, 8)]; /* 723 */ 19722521Sdyson u_char perm [ISODCL (9, 10)]; /* 9.5.3 */ 1981541Srgrimes char ctime [ISODCL (11, 27)]; /* 8.4.26.1 */ 1991541Srgrimes char mtime [ISODCL (28, 44)]; /* 8.4.26.1 */ 2001541Srgrimes char xtime [ISODCL (45, 61)]; /* 8.4.26.1 */ 2011541Srgrimes char ftime [ISODCL (62, 78)]; /* 8.4.26.1 */ 2021541Srgrimes char recfmt [ISODCL (79, 79)]; /* 711 */ 2031541Srgrimes char recattr [ISODCL (80, 80)]; /* 711 */ 20422521Sdyson u_char reclen [ISODCL (81, 84)]; /* 723 */ 2051541Srgrimes char system_id [ISODCL (85, 116)]; /* achars */ 2061541Srgrimes char system_use [ISODCL (117, 180)]; 2071541Srgrimes char version [ISODCL (181, 181)]; /* 711 */ 2081541Srgrimes char len_esc [ISODCL (182, 182)]; /* 711 */ 2091541Srgrimes char reserved [ISODCL (183, 246)]; 21022521Sdyson u_char len_au [ISODCL (247, 250)]; /* 723 */ 2111541Srgrimes}; 2121541Srgrimes 21355206Speter#ifdef _KERNEL 21425531Sjoerg 2151541Srgrimes/* CD-ROM Format type */ 2165651Sjoergenum ISO_FTYPE { ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP, 21745773Sdcs ISO_FTYPE_JOLIET, ISO_FTYPE_ECMA, ISO_FTYPE_HIGH_SIERRA }; 2181541Srgrimes 2191541Srgrimes#ifndef ISOFSMNT_ROOT 2201541Srgrimes#define ISOFSMNT_ROOT 0 2211541Srgrimes#endif 2221541Srgrimes 2231541Srgrimesstruct iso_mnt { 224224290Smckusick uint64_t im_flags; 2251541Srgrimes 2261541Srgrimes struct mount *im_mountp; 227130585Sphk struct cdev *im_dev; 2281541Srgrimes struct vnode *im_devvp; 2291541Srgrimes 230137038Sphk struct g_consumer *im_cp; 231137038Sphk struct bufobj *im_bo; 232137038Sphk 2331541Srgrimes int logical_block_size; 2341541Srgrimes int im_bshift; 2351541Srgrimes int im_bmask; 2368876Srgrimes 2371541Srgrimes int volume_space_size; 2388876Srgrimes 2391541Srgrimes char root[ISODCL (157, 190)]; 2401541Srgrimes int root_extent; 2411541Srgrimes int root_size; 2425651Sjoerg enum ISO_FTYPE iso_ftype; 2438876Srgrimes 2441541Srgrimes int rr_skip; 2451541Srgrimes int rr_skip0; 24645773Sdcs 24745773Sdcs int joliet_level; 248120492Sfjoe 249120492Sfjoe void *im_d2l; 250120492Sfjoe void *im_l2d; 2511541Srgrimes}; 2521541Srgrimes 253166774Spjdstruct ifid { 254166774Spjd u_short ifid_len; 255166774Spjd u_short ifid_pad; 256166774Spjd int ifid_ino; 257166774Spjd long ifid_start; 258166774Spjd}; 259166774Spjd 2601541Srgrimes#define VFSTOISOFS(mp) ((struct iso_mnt *)((mp)->mnt_data)) 2611541Srgrimes 26222521Sdyson#define blkoff(imp, loc) ((loc) & (imp)->im_bmask) 26322521Sdyson#define lblktosize(imp, blk) ((blk) << (imp)->im_bshift) 26422521Sdyson#define lblkno(imp, loc) ((loc) >> (imp)->im_bshift) 26522521Sdyson#define blksize(imp, ip, lbn) ((imp)->logical_block_size) 2661541Srgrimes 26792765Salfredint cd9660_vget_internal(struct mount *, ino_t, int, struct vnode **, int, 26893075Sbde struct iso_directory_record *); 26992765Salfred#define cd9660_sysctl ((int (*)(int *, u_int, void *, size_t *, void *, \ 27093075Sbde size_t, struct proc *))eopnotsupp) 2711541Srgrimes 272138290Sphkextern struct vop_vector cd9660_vnodeops; 273138290Sphkextern struct vop_vector cd9660_fifoops; 2741541Srgrimes 275120492Sfjoeint isochar(u_char *, u_char *, int, u_short *, int *, int, void *); 276120492Sfjoeint isofncmp(u_char *, int, u_char *, int, int, int, void *, void *); 277120492Sfjoevoid isofntrans(u_char *, int, u_char *, u_short *, int, int, int, int, void *); 27892765Salfredino_t isodirino(struct iso_directory_record *, struct iso_mnt *); 279120492Sfjoeu_short sgetrune(const char *, size_t, char const **, int, void *); 28025531Sjoerg 28155206Speter#endif /* _KERNEL */ 28225531Sjoerg 28325531Sjoerg/* 28425531Sjoerg * The isonum_xxx functions are inlined anyway, and could come handy even 28525531Sjoerg * outside the kernel. Thus we don't hide them here. 28625531Sjoerg */ 28725531Sjoerg 288151447Sdes/* 289151447Sdes * 7xy 290151447Sdes * x -> 1 = 8 bits, 2 = 16 bits, 3 = 32 bits 291151447Sdes * y -> 1 = little-endian, 2 = big-endian, 3 = both (le then be) 292151447Sdes */ 293151447Sdes 294151447Sdesstatic __inline uint8_t 295253742Smariusisonum_711(const unsigned char *p) 2961541Srgrimes{ 297253742Smarius 298253742Smarius return (p[0]); 2991541Srgrimes} 3001541Srgrimes 301253742Smariusstatic __inline int8_t 302253742Smariusisonum_712(const unsigned char *p) 3031541Srgrimes{ 304253742Smarius 305253742Smarius return ((signed char)p[0]); 3061541Srgrimes} 3071541Srgrimes 308151447Sdesstatic __inline uint8_t 309253742Smariusisonum_713(const unsigned char *p) 310151447Sdes{ 311253742Smarius 312253742Smarius return (p[0]); 313151447Sdes} 31422521Sdyson 315151447Sdesstatic __inline uint16_t 316253742Smariusisonum_721(const unsigned char *p) 3171541Srgrimes{ 318253742Smarius 319151447Sdes return (p[0] | p[1] << 8); 3201541Srgrimes} 3211541Srgrimes 322151447Sdesstatic __inline uint16_t 323253742Smariusisonum_722(const unsigned char *p) 3241541Srgrimes{ 325253742Smarius 326151447Sdes return (p[1] | p[0] << 8); 3271541Srgrimes} 3281541Srgrimes 329151447Sdesstatic __inline uint16_t 330253742Smariusisonum_723(const unsigned char *p) 3311541Srgrimes{ 332253742Smarius 333151447Sdes return (p[0] | p[1] << 8); 3341541Srgrimes} 3351541Srgrimes 336151447Sdesstatic __inline uint32_t 337253742Smariusisonum_731(const unsigned char *p) 3381541Srgrimes{ 339253742Smarius 340151447Sdes return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24); 3411541Srgrimes} 3421541Srgrimes 343151447Sdesstatic __inline uint32_t 344253742Smariusisonum_732(const unsigned char *p) 3451541Srgrimes{ 346253742Smarius 347151447Sdes return (p[3] | p[2] << 8 | p[1] << 16 | p[0] << 24); 3481541Srgrimes} 3491541Srgrimes 350151447Sdesstatic __inline uint32_t 351253742Smariusisonum_733(const unsigned char *p) 3521541Srgrimes{ 353253742Smarius 354151447Sdes return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24); 3551541Srgrimes} 3561541Srgrimes 3571541Srgrimes/* 3581541Srgrimes * Associated files have a leading '='. 3591541Srgrimes */ 3601541Srgrimes#define ASSOCCHAR '=' 361