1 /*- 2 * Copyright (c) 1994 3 * 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 * @(#)iso.h 8.6 (Berkeley) 5/10/95 39 * $FreeBSD$ 40 */ 41 42 #define ISODCL(from, to) (to - from + 1) 43 44 struct iso_volume_descriptor { 45 char type[ISODCL(1,1)]; /* 711 */ 46 char id[ISODCL(2,6)]; 47 char version[ISODCL(7,7)]; 48 char unused[ISODCL(8,8)]; 49 char type_sierra[ISODCL(9,9)]; /* 711 */ 50 char id_sierra[ISODCL(10,14)]; 51 char version_sierra[ISODCL(15,15)]; 52 char data[ISODCL(16,2048)]; 53 }; 54 55 /* volume descriptor types */ 56 #define ISO_VD_PRIMARY 1 57 #define ISO_VD_END 255 58 59 #define ISO_STANDARD_ID "CD001" 60 #define ISO_ECMA_ID "CDW01" 61 62 #define ISO_SIERRA_ID "CDROM" 63 64 struct iso_primary_descriptor { 65 char type [ISODCL ( 1, 1)]; /* 711 */ 66 char id [ISODCL ( 2, 6)]; 67 char version [ISODCL ( 7, 7)]; /* 711 */ 68 char unused1 [ISODCL ( 8, 8)]; 69 char system_id [ISODCL ( 9, 40)]; /* achars */ 70 char volume_id [ISODCL ( 41, 72)]; /* dchars */ 71 char unused2 [ISODCL ( 73, 80)]; 72 char volume_space_size [ISODCL ( 81, 88)]; /* 733 */ 73 char unused3 [ISODCL ( 89, 120)]; 74 char volume_set_size [ISODCL (121, 124)]; /* 723 */ 75 char volume_sequence_number [ISODCL (125, 128)]; /* 723 */ 76 char logical_block_size [ISODCL (129, 132)]; /* 723 */ 77 char path_table_size [ISODCL (133, 140)]; /* 733 */ 78 char type_l_path_table [ISODCL (141, 144)]; /* 731 */ 79 char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */ 80 char type_m_path_table [ISODCL (149, 152)]; /* 732 */ 81 char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */ 82 char root_directory_record [ISODCL (157, 190)]; /* 9.1 */ 83 char volume_set_id [ISODCL (191, 318)]; /* dchars */ 84 char publisher_id [ISODCL (319, 446)]; /* achars */ 85 char preparer_id [ISODCL (447, 574)]; /* achars */ 86 char application_id [ISODCL (575, 702)]; /* achars */ 87 char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */ 88 char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */ 89 char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */ 90 char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */ 91 char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */ 92 char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */ 93 char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */ 94 char file_structure_version [ISODCL (882, 882)]; /* 711 */ 95 char unused4 [ISODCL (883, 883)]; 96 char application_data [ISODCL (884, 1395)]; 97 char unused5 [ISODCL (1396, 2048)]; 98 }; 99 #define ISO_DEFAULT_BLOCK_SIZE 2048 100 101 struct iso_sierra_primary_descriptor { 102 char unknown1 [ISODCL ( 1, 8)]; /* 733 */ 103 char type [ISODCL ( 9, 9)]; /* 711 */ 104 char id [ISODCL ( 10, 14)]; 105 char version [ISODCL ( 15, 15)]; /* 711 */ 106 char unused1 [ISODCL ( 16, 16)]; 107 char system_id [ISODCL ( 17, 48)]; /* achars */ 108 char volume_id [ISODCL ( 49, 80)]; /* dchars */ 109 char unused2 [ISODCL ( 81, 88)]; 110 char volume_space_size [ISODCL ( 89, 96)]; /* 733 */ 111 char unused3 [ISODCL ( 97, 128)]; 112 char volume_set_size [ISODCL (129, 132)]; /* 723 */ 113 char volume_sequence_number [ISODCL (133, 136)]; /* 723 */ 114 char logical_block_size [ISODCL (137, 140)]; /* 723 */ 115 char path_table_size [ISODCL (141, 148)]; /* 733 */ 116 char type_l_path_table [ISODCL (149, 152)]; /* 731 */ 117 char opt_type_l_path_table [ISODCL (153, 156)]; /* 731 */ 118 char unknown2 [ISODCL (157, 160)]; /* 731 */ 119 char unknown3 [ISODCL (161, 164)]; /* 731 */ 120 char type_m_path_table [ISODCL (165, 168)]; /* 732 */ 121 char opt_type_m_path_table [ISODCL (169, 172)]; /* 732 */ 122 char unknown4 [ISODCL (173, 176)]; /* 732 */ 123 char unknown5 [ISODCL (177, 180)]; /* 732 */ 124 char root_directory_record [ISODCL (181, 214)]; /* 9.1 */ 125 char volume_set_id [ISODCL (215, 342)]; /* dchars */ 126 char publisher_id [ISODCL (343, 470)]; /* achars */ 127 char preparer_id [ISODCL (471, 598)]; /* achars */ 128 char application_id [ISODCL (599, 726)]; /* achars */ 129 char copyright_id [ISODCL (727, 790)]; /* achars */ 130 char creation_date [ISODCL (791, 806)]; /* ? */ 131 char modification_date [ISODCL (807, 822)]; /* ? */ 132 char expiration_date [ISODCL (823, 838)]; /* ? */ 133 char effective_date [ISODCL (839, 854)]; /* ? */ 134 char file_structure_version [ISODCL (855, 855)]; /* 711 */ 135 char unused4 [ISODCL (856, 2048)]; 136 }; 137 138 struct iso_directory_record { 139 char length [ISODCL (1, 1)]; /* 711 */ 140 char ext_attr_length [ISODCL (2, 2)]; /* 711 */ 141 u_char extent [ISODCL (3, 10)]; /* 733 */ 142 u_char size [ISODCL (11, 18)]; /* 733 */ 143 char date [ISODCL (19, 25)]; /* 7 by 711 */ 144 char flags [ISODCL (26, 26)]; 145 char file_unit_size [ISODCL (27, 27)]; /* 711 */ 146 char interleave [ISODCL (28, 28)]; /* 711 */ 147 char volume_sequence_number [ISODCL (29, 32)]; /* 723 */ 148 char name_len [ISODCL (33, 33)]; /* 711 */ 149 char name [1]; /* XXX */ 150 }; 151 /* can't take sizeof(iso_directory_record), because of possible alignment 152 of the last entry (34 instead of 33) */ 153 #define ISO_DIRECTORY_RECORD_SIZE 33 154 155 struct iso_extended_attributes { 156 u_char owner [ISODCL (1, 4)]; /* 723 */ 157 u_char group [ISODCL (5, 8)]; /* 723 */ 158 u_char perm [ISODCL (9, 10)]; /* 9.5.3 */ 159 char ctime [ISODCL (11, 27)]; /* 8.4.26.1 */ 160 char mtime [ISODCL (28, 44)]; /* 8.4.26.1 */ 161 char xtime [ISODCL (45, 61)]; /* 8.4.26.1 */ 162 char ftime [ISODCL (62, 78)]; /* 8.4.26.1 */ 163 char recfmt [ISODCL (79, 79)]; /* 711 */ 164 char recattr [ISODCL (80, 80)]; /* 711 */ 165 u_char reclen [ISODCL (81, 84)]; /* 723 */ 166 char system_id [ISODCL (85, 116)]; /* achars */ 167 char system_use [ISODCL (117, 180)]; 168 char version [ISODCL (181, 181)]; /* 711 */ 169 char len_esc [ISODCL (182, 182)]; /* 711 */ 170 char reserved [ISODCL (183, 246)]; 171 u_char len_au [ISODCL (247, 250)]; /* 723 */ 172 }; 173 174 /* CD-ROM Format type */ 175 enum ISO_FTYPE { ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP, 176 ISO_FTYPE_ECMA, ISO_FTYPE_HIGH_SIERRA }; 177 178 #ifndef ISOFSMNT_ROOT 179 #define ISOFSMNT_ROOT 0 180 #endif 181 182 struct iso_mnt { 183 int im_flags; 184 185 struct mount *im_mountp; 186 dev_t im_dev; 187 struct vnode *im_devvp; 188 189 int logical_block_size; 190 int im_bshift; 191 int im_bmask; 192 193 int volume_space_size; 194 struct netexport im_export; 195 196 char root[ISODCL (157, 190)]; 197 int root_extent; 198 int root_size; 199 enum ISO_FTYPE iso_ftype; 200 201 int rr_skip; 202 int rr_skip0; 203 }; 204 205 #define VFSTOISOFS(mp) ((struct iso_mnt *)((mp)->mnt_data)) 206 207 #define blkoff(imp, loc) ((loc) & (imp)->im_bmask) 208 #define lblktosize(imp, blk) ((blk) << (imp)->im_bshift) 209 #define lblkno(imp, loc) ((loc) >> (imp)->im_bshift) 210 #define blksize(imp, ip, lbn) ((imp)->logical_block_size) 211 212 int cd9660_vget_internal __P((struct mount *, ino_t, struct vnode **, int, 213 struct iso_directory_record *)); 214 int cd9660_init __P((struct vfsconf *)); 215 #define cd9660_sysctl ((int (*) __P((int *, u_int, void *, size_t *, void *, \ 216 size_t, struct proc *)))eopnotsupp) 217 218 int cd9660_mountroot __P((void)); 219 220 extern vop_t **cd9660_vnodeop_p; 221 extern vop_t **cd9660_specop_p; 222 extern vop_t **cd9660_fifoop_p; 223 224 static __inline int isonum_711 __P((u_char *)); 225 static __inline int 226 isonum_711(p) 227 u_char *p; 228 { 229 return *p; 230 } 231 232 static __inline int isonum_712 __P((char *)); 233 static __inline int 234 isonum_712(p) 235 char *p; 236 { 237 return *p; 238 } 239 240 #ifndef UNALIGNED_ACCESS 241 242 static __inline int isonum_723 __P((u_char *)); 243 static __inline int 244 isonum_723(p) 245 u_char *p; 246 { 247 return *p|(p[1] << 8); 248 } 249 250 static __inline int isonum_733 __P((u_char *)); 251 static __inline int 252 isonum_733(p) 253 u_char *p; 254 { 255 return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24); 256 } 257 258 #else /* UNALIGNED_ACCESS */ 259 260 #if BYTE_ORDER == LITTLE_ENDIAN 261 262 static __inline int 263 isonum_723(p) 264 u_char *p 265 { 266 return *(u_int16t *)p; 267 } 268 269 static __inline int 270 isonum_733(p) 271 u_char *p; 272 { 273 return *(u_int32t *)p; 274 } 275 276 #endif 277 278 #if BYTE_ORDER == BIG_ENDIAN 279 280 static __inline int 281 isonum_723(p) 282 u_char *p 283 { 284 return *(u_int16t *)(p + 2); 285 } 286 287 static __inline int 288 isonum_733(p) 289 u_char *p; 290 { 291 return *(u_int32t *)(p + 4); 292 } 293 294 #endif 295 296 #endif /* UNALIGNED_ACCESS */ 297 298 int isofncmp __P((u_char *, int, u_char *, int)); 299 void isofntrans __P((u_char *, int, u_char *, u_short *, int, int)); 300 ino_t isodirino __P((struct iso_directory_record *, struct iso_mnt *)); 301 302 /* 303 * Associated files have a leading '='. 304 */ 305 #define ASSOCCHAR '=' 306