1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 /* 29 * ISO 9660 filesystem specification 30 */ 31 32 #ifndef _ISO_SPEC_H_ 33 #define _ISO_SPEC_H_ 34 35 #include <sys/isa_defs.h> 36 37 /* routines required for date parsing */ 38 extern struct timeval iso_parse_dirdate(); /* parse date in directory */ 39 extern struct timeval iso__parse_longdate(); /* parse date in volume id */ 40 41 /* macros to parse binary integers */ 42 #define ZERO(x) (u_int) (((u_char *)(x))[0]) 43 #define ONE(x) (u_int) (((u_char *)(x))[1]) 44 #define TWO(x) (u_int) (((u_char *)(x))[2]) 45 #define THREE(x) (u_int) (((u_char *)(x))[3]) 46 47 #define MSB_INT(x) \ 48 ((((((ZERO(x) << 8) | ONE(x)) << 8) | TWO(x)) << 8) | THREE(x)) 49 #define LSB_INT(x) \ 50 ((((((THREE(x) << 8) | TWO(x)) << 8) | ONE(x)) << 8) | ZERO(x)) 51 #define MSB_SHORT(x) ((ZERO(x) << 8) | ONE(x)) 52 #define LSB_SHORT(x) ((ONE(x) << 8) | ZERO(x)) 53 54 #if defined(sparc) 55 /* 56 * Sparc machines requires that integer must 57 * be in a full word boundary. CD-ROM data aligns 58 * to even word boundary only. Because of this mismatch, 59 * we have to move integer data from CD-ROM to memory one 60 * byte at a time. LSB data starts first. We therefore 61 * use this to do byte by byte copying. 62 */ 63 #define BOTH_SHORT(x) LSB_SHORT(x) 64 #define BOTH_INT(x) LSB_INT(x) 65 66 #elif defined(_LITTLE_ENDIAN) 67 #define BOTH_SHORT(x) (short) *((short *)x) 68 #define BOTH_INT(x) (int) *((int *)x) 69 70 #elif defined(_BIG_ENDIAN) 71 #define BOTH_SHORT(x) (short) *((short *)x + 1) 72 #define BOTH_INT(x) (int) *((int *)x + 1) 73 #else 74 #error One of _BIG_ENDIAN and _LITTLE_ENDIAN must be defined 75 #endif 76 77 /* 78 * conversions to/from little endian format 79 */ 80 #if defined(_LITTLE_ENDIAN) 81 /* little endian machines */ 82 #define ltohs(S) (S) 83 #define ltohl(L) (L) 84 #define htols(S) (S) 85 #define htoll(L) (L) 86 #else 87 /* big endian machines */ 88 #define ltohs(S) LSB_SHORT((char *) (S)) 89 #define ltohl(L) LSB_INT((char *) (L)) 90 #define htols(S) LSB_SHORT((char *) (S)) 91 #define htoll(L) LSB_INT((char *) (L)) 92 #endif 93 94 /* 95 * The following describes actual on-disk structures. 96 * To achieve portability, all structures are #defines 97 * rather than a structure definition. Macros are provided 98 * to get either the data or address of individual fields. 99 */ 100 101 /* Overall High Sierra disk structure */ 102 #define ISO_SECTOR_SIZE 2048 /* bytes per logical sector */ 103 #define ISO_SECTOR_SHIFT 11 /* sector<->byte shift count */ 104 #define ISO_SEC_PER_PAGE (PAGESIZE/HS_SECTOR_SIZE) /* sectors per page */ 105 #define ISO_SYSAREA_SEC 0 /* 1st sector of system area */ 106 #define ISO_VOLDESC_SEC 16 /* 1st sector of volume descriptors */ 107 #define MAXISOOFFSET (ISO_SECTOR_SIZE - 1) 108 #define MAXISOMASK (~MAXISOOFFSET) 109 110 111 /* Standard File Structure Volume Descriptor */ 112 113 enum iso_voldesc_type { 114 ISO_VD_BOOT=0, ISO_VD_PVD=1, ISO_VD_SVD=2, ISO_VD_VPD=3, 115 ISO_VD_UNIX=4, /* UNIX extension */ 116 ISO_VD_EOV=255 117 }; 118 #define ISO_ID_STRING "CD001" /* ISO_std_id field */ 119 #define ISO_ID_STRLEN 5 /* ISO_std_id field length */ 120 #define ISO_ID_VER 1 /* ISO_std_ver field */ 121 #define ISO_FILE_STRUCT_ID_VER 1 /* ISO_file structure version field */ 122 #define ISO_DATE_TO_UNIX(x) iso_parse_longdate(x) /* returns a timeval */ 123 #define ISO_SYS_ID_STRLEN 32 124 #define ISO_VOL_ID_STRLEN 32 125 #define ISO_VOL_SET_ID_STRLEN 128 126 #define ISO_PUB_ID_STRLEN 128 127 #define ISO_PREP_ID_STRLEN 128 128 #define ISO_APPL_ID_STRLEN 128 129 #define ISO_COPYR_ID_STRLEN 37 130 #define ISO_ABSTR_ID_STRLEN 37 131 #define ISO_DATE_LEN 17 132 133 134 135 /* macros to get the address of each field */ 136 #define ISO_desc_type(x) (&((u_char *)x)[0]) 137 #define ISO_std_id(x) (&((u_char *)x)[1]) 138 #define ISO_std_ver(x) (&((u_char *)x)[6]) 139 #define ISO_sys_id(x) (&((u_char *)x)[8]) 140 #define ISO_vol_id(x) (&((u_char *)x)[40]) 141 #define ISO_vol_size(x) (&((u_char *)x)[80]) 142 #define ISO_set_size(x) (&((u_char *)x)[120]) 143 #define ISO_set_seq(x) (&((u_char *)x)[124]) 144 #define ISO_blk_size(x) (&((u_char *)x)[128]) 145 #define ISO_ptbl_size(x) (&((u_char *)x)[132]) 146 #define ISO_ptbl_man_ls(x) (&((u_char *)x)[140]) 147 #define ISO_ptbl_opt_ls1(x) (&((u_char *)x)[144]) 148 #define ISO_ptbl_man_ms(x) (&((u_char *)x)[148]) 149 #define ISO_ptbl_opt_ms1(x) (&((u_char *)x)[152]) 150 #define ISO_root_dir(x) (&((u_char *)x)[156]) 151 #define ISO_vol_set_id(x) (&((u_char *)x)[190]) 152 #define ISO_pub_id(x) (&((u_char *)x)[318]) 153 #define ISO_prep_id(x) (&((u_char *)x)[446]) 154 #define ISO_appl_id(x) (&((u_char *)x)[574]) 155 #define ISO_copyr_id(x) (&((u_char *)x)[702]) 156 #define ISO_abstr_id(x) (&((u_char *)x)[739]) 157 #define ISO_bibli_id(x) (&((u_char *)x)[776]) 158 #define ISO_cre_date(x) (&((u_char *)x)[813]) 159 #define ISO_mod_date(x) (&((u_char *)x)[830]) 160 #define ISO_exp_date(x) (&((u_char *)x)[847]) 161 #define ISO_eff_date(x) (&((u_char *)x)[864]) 162 #define ISO_file_struct_ver(x) (&((u_char *)x)[881]) 163 164 /* macros to get the values of each field (strings are returned as ptrs) */ 165 #define ISO_DESC_TYPE(x) ((enum hs_voldesc_type)*(ISO_desc_type(x))) 166 #define ISO_STD_ID(x) ISO_std_id(x) 167 #define ISO_STD_VER(x) *(ISO_std_ver(x)) 168 #define ISO_SYS_ID(x) ISO_sys_id(x) 169 #define ISO_VOL_ID(x) ISO_vol_id(x) 170 #define ISO_VOL_SIZE(x) BOTH_INT(ISO_vol_size(x)) 171 #define ISO_SET_SIZE(x) BOTH_SHORT(ISO_set_size(x)) 172 #define ISO_SET_SEQ(x) BOTH_SHORT(ISO_set_seq(x)) 173 #define ISO_BLK_SIZE(x) BOTH_SHORT(ISO_blk_size(x)) 174 #define ISO_PTBL_SIZE(x) BOTH_INT(ISO_ptbl_size(x)) 175 #define ISO_PTBL_MAN_LS(x) LSB_INT(ISO_ptbl_man_ls(x)) 176 #define ISO_PTBL_OPT_LS1(x) LSB_INT(ISO_ptbl_opt_ls1(x)) 177 #define ISO_PTBL_MAN_MS(x) MSB_INT(ISO_ptbl_man_ms(x)) 178 #define ISO_PTBL_OPT_MS1(x) MSB_INT(ISO_ptbl_opt_ms1(x)) 179 #define ISO_ROOT_DIR(x) ISO_root_dir(x) 180 #define ISO_VOL_SET_ID(x) ISO_vol_set_id(x) 181 #define ISO_PUB_ID(x) ISO_pub_id(x) 182 #define ISO_PREP_ID(x) ISO_prep_id(x) 183 #define ISO_APPL_ID(x) ISO_appl_id(x) 184 #define ISO_COPYR_ID(x) ISO_copyr_id(x) 185 #define ISO_ABSTR_ID(x) ISO_abstr_id(x) 186 #define ISO_BIBLI_ID(x) ISO_bibli_id(x) 187 #define ISO_CRE_DATE(x) ISO_DATE_TO_UNIX(HSV_cre_date(x)) 188 #define ISO_MOD_DATE(x) ISO_DATE_TO_UNIX(HSV_mod_date(x)) 189 #define ISO_EXP_DATE(x) ISO_DATE_TO_UNIX(HSV_exp_date(x)) 190 #define ISO_EFF_DATE(x) ISO_DATE_TO_UNIX(HSV_eff_date(x)) 191 #define ISO_FILE_STRUCT_VER(x) *(ISO_file_struct_ver(x)) 192 193 /* Standard File Structure Volume Descriptor date fields */ 194 #define ISO_DATE_2DIG(x) ( (((x)[0] - '0') * 10) + \ 195 ((x)[1] - '0') ) 196 #define ISO_DATE_4DIG(x) ( (((x)[0] - '0') * 1000) + \ 197 (((x)[1] - '0') * 100) + \ 198 (((x)[2] - '0') * 10) + \ 199 ((x)[3] - '0') ) 200 #define ISO_DATE_YEAR(x) ISO_DATE_4DIG(&((u_char *)x)[0]) 201 #define ISO_DATE_MONTH(x) ISO_DATE_2DIG(&((u_char *)x)[4]) 202 #define ISO_DATE_DAY(x) ISO_DATE_2DIG(&((u_char *)x)[6]) 203 #define ISO_DATE_HOUR(x) ISO_DATE_2DIG(&((u_char *)x)[8]) 204 #define ISO_DATE_MIN(x) ISO_DATE_2DIG(&((u_char *)x)[10]) 205 #define ISO_DATE_SEC(x) ISO_DATE_2DIG(&((u_char *)x)[12]) 206 #define ISO_DATE_HSEC(x) ISO_DATE_2DIG(&((u_char *)x)[14]) 207 208 209 210 /* Directory Entry (Directory Record) */ 211 #define IDE_ROOT_DIR_REC_SIZE 34 /* size of root directory record */ 212 #define IDE_FDESIZE 33 /* fixed size for hsfs directory area */ 213 /* max size of a name */ 214 #define IDE_MAX_NAME_LEN (255 - IDE_FDESIZE) 215 216 217 #define IDE_DATE_TO_UNIX(x) iso_parse_dirdate(x) /* returns a timeval */ 218 219 /* macros to get the address of each field */ 220 #define IDE_dir_len(x) (&((u_char *)x)[0]) 221 #define IDE_xar_len(x) (&((u_char *)x)[1]) 222 #define IDE_ext_lbn(x) (&((u_char *)x)[2]) 223 #define IDE_ext_size(x) (&((u_char *)x)[10]) 224 #define IDE_cdate(x) (&((u_char *)x)[18]) 225 #define IDE_flags(x) (&((u_char *)x)[25]) 226 #define IDE_intrlv_size(x) (&((u_char *)x)[26]) 227 #define IDE_intrlv_skip(x) (&((u_char *)x)[27]) 228 #define IDE_vol_set(x) (&((u_char *)x)[28]) 229 #define IDE_name_len(x) (&((u_char *)x)[32]) 230 #define IDE_name(x) (&((u_char *)x)[33]) 231 232 /* macros to get the values of each field (strings are returned as ptrs) */ 233 #define IDE_DIR_LEN(x) *(IDE_dir_len(x)) 234 #define IDE_XAR_LEN(x) *(IDE_xar_len(x)) 235 #define IDE_EXT_LBN(x) BOTH_INT(IDE_ext_lbn(x)) 236 #define IDE_EXT_SIZE(x) BOTH_INT(IDE_ext_size(x)) 237 #define IDE_CDATE(x) IDE_DATE_TO_UNIX(HDE_cdate(x)) 238 #define IDE_FLAGS(x) *(IDE_flags(x)) 239 #define IDE_INTRLV_SIZE(x) *(IDE_intrlv_size(x)) 240 #define IDE_INTRLV_SKIP(x) *(IDE_intrlv_skip(x)) 241 #define IDE_VOL_SET(x) BOTH_SHORT(IDE_vol_set(x)) 242 #define IDE_NAME_LEN(x) *(IDE_name_len(x)) 243 #define IDE_NAME(x) IDE_name(x) 244 245 /* mask bits for IDE_FLAGS */ 246 #define IDE_EXISTENCE 0x01 /* zero if file exists */ 247 #define IDE_DIRECTORY 0x02 /* zero if file is not a directory */ 248 #define IDE_ASSOCIATED 0x04 /* zero if file is not Associated */ 249 #define IDE_RECORD 0x08 /* zero if no record attributes */ 250 #define IDE_PROTECTION 0x10 /* zero if no protection attributes */ 251 #define IDE_UNUSED_FLAGS 0x60 252 #define IDE_LAST_EXTENT 0x80 /* zero if last extent in file */ 253 #define IDE_PROHIBITED (IDE_DIRECTORY | HDE_ASSOCIATED | HDE_RECORD | \ 254 IDE_LAST_EXTENT | IDE_UNUSED_FLAGS) 255 256 /* Directory Record date fields */ 257 #define IDE_DATE_YEAR(x) (((u_char *)x)[0] + 1900) 258 #define IDE_DATE_MONTH(x) (((u_char *)x)[1]) 259 #define IDE_DATE_DAY(x) (((u_char *)x)[2]) 260 #define IDE_DATE_HOUR(x) (((u_char *)x)[3]) 261 #define IDE_DATE_MIN(x) (((u_char *)x)[4]) 262 #define IDE_DATE_SEC(x) (((u_char *)x)[5]) 263 264 /* tests for Interchange Levels 1 & 2 file types */ 265 #define IDE_REGULAR_FILE(x) (((x) & IDE_PROHIBITED) == 0) 266 #define IDE_REGULAR_DIR(x) (((x) & IDE_PROHIBITED) == IDE_DIRECTORY) 267 268 #define ISO_DIR_NAMELEN 31 /* max length of a directory name */ 269 #define ISO_FILE_NAMELEN 31 /* max length of a filename */ 270 271 /* Path table enry */ 272 /* fix size of path table entry */ 273 #define IPE_FPESIZE 8 274 /* macros to get the address of each field */ 275 #define IPE_name_len(x) (&((u_char *)x)[0]) 276 #define IPE_xar_len(x) (&((u_char *)x)[1]) 277 #define IPE_ext_lbn(x) (&((u_char *)x)[2]) 278 #define IPE_parent_no(x) (&((u_char *)x)[6]) 279 #define IPE_name(x) (&((u_char *)x)[8]) 280 281 /* macros to get the values of each field */ 282 #define IPE_EXT_LBN(x) (MSB_INT(IPE_ext_lbn(x))) 283 #define IPE_XAR_LEN(x) *(IPE_xar_len(x)) 284 #define IPE_NAME_LEN(x) *(IPE_name_len(x)) 285 #define IPE_PARENT_NO(x) *(short *)(IPE_parent_no(x)) 286 #define IPE_NAME(x) IPE_name(x) 287 288 /* cdrom UNIX extension */ 289 /* UNIX Volume Descriptor */ 290 #define ISO_UNIX_ID_STRING "UNIXCD01" /* ISO_UNIX_std_id field */ 291 #define ISO_UNIX_ID_STRLEN 8 /* ISO_UNIX_std_id length */ 292 #define ISO_UNIX_FEATURE_SYMLNK 0x01 /* CD-ROM supports symbolic links */ 293 #define ISO_UNIX_FEATURE_LONGFN 0x02 /* CD-ROM supports long BSD file names */ 294 295 #define ISO_UNIX_feature(x) (&((u_char *)x)[7]) 296 #define ISO_UNIX_root_dir(x) (&((u_char *)x)[1395]) 297 #define ISO_UNIX_signature(x) (&((u_char *)x)[2040]) 298 299 #define ISO_UNIX_FEATURE(x) *(ISO_UNIX_feature(x)) 300 #define ISO_UNIX_ROOT_DIR(x) ISO_UNIX_root_dir(x) 301 #define ISO_UNIX_SIGNATURE(x) ISO_UNIX_signature(x) 302 303 /* UNIX extension to path table entry */ 304 /* fix size of path table entry */ 305 #define IPE_UNIX_FPESIZE 20 306 307 #define IPE_UNIX_mode(x) (&((u_char *)x)[0]) 308 #define IPE_UNIX_uid(x) (&((u_char *)x)[4]) 309 #define IPE_UNIX_gid(x) (&((u_char *)x)[8]) 310 311 /* macros to get the values of each field */ 312 #define IPE_UNIX_MODE(x) (MSB_INT(IPE_UNIX_mode(x))) 313 #define IPE_UNIX_UID(x) (MSB_INT(IPE_UNIX_uid(x))) 314 #define IPE_UNIX_GID(x) (MSB_INT(IPE_UNIX_gid(x))) 315 316 /* UNIX extension to directory entry */ 317 #define IDE_UNIX_SIG_UX "UX" /* UNIX extension signature */ 318 #define IDE_UNIX_SIG_TI "TI" /* UNIX extension signature for time */ 319 #define IDE_UNIX_USE_ID_VER 1 /* UNIX extension sys use id */ 320 #define IDE_UNIX_UX_LEN 36 /* length of UX */ 321 #define IDE_UNIX_TI_LEN 40 /* length of TI */ 322 323 #define IDE_UNIX_signature(x) (&((u_char *)x)[0]) 324 #define IDE_UNIX_ext_len(x) (&((u_char *)x)[2]) 325 #define IDE_UNIX_use_id(x) (&((u_char *)x)[3]) 326 #define IDE_UNIX_mode(x) (&((u_char *)x)[4]) 327 #define IDE_UNIX_nlink(x) (&((u_char *)x)[12]) 328 #define IDE_UNIX_uid(x) (&((u_char *)x)[20]) 329 #define IDE_UNIX_gid(x) (&((u_char *)x)[28]) 330 331 332 #define IDE_UNIX_cre_date(x) (&((u_char *)x)[4]) 333 #define IDE_UNIX_mod_date(x) (&((u_char *)x)[11]) 334 #define IDE_UNIX_exp_date(x) (&((u_char *)x)[18]) 335 #define IDE_UNIX_eff_date(x) (&((u_char *)x)[25]) 336 #define IDE_UNIX_acc_date(x) (&((u_char *)x)[32]) 337 #define IDE_UNIX_reserved(x) (&((u_char *)x)[39]) 338 339 #define IDE_UNIX_SIGNATURE(x) IDE_UNIX_signature(x) 340 #define IDE_UNIX_EXT_LEN(x) *(IDE_UNIX_ext_len(x)) 341 #define IDE_UNIX_USE_ID(x) *(IDE_UNIX_use_id(x)) 342 #define IDE_UNIX_MODE(x) BOTH_INT(IDE_UNIX_mode(x)) 343 #define IDE_UNIX_NLINK(x) BOTH_INT(IDE_UNIX_nlink(x)) 344 #define IDE_UNIX_UID(x) BOTH_INT(IDE_UNIX_uid(x)) 345 #define IDE_UNIX_GID(x) BOTH_INT(IDE_UNIX_gid(x)) 346 347 #define IDE_UNIX_CRE_DATE(x) IDE_UNIX_cre_date(x) 348 #define IDE_UNIX_MOD_DATE(x) IDE_UNIX_mod_date(x) 349 #define IDE_UNIX_EXP_DATE(x) IDE_UNIX_exp_date(x) 350 #define IDE_UNIX_EFF_DATE(x) IDE_UNIX_eff_date(x) 351 #define IDE_UNIX_ACC_DATE(x) IDE_UNIX_acc_date(x) 352 #define IDE_UNIX_RESERVED(x) *(IDE_UNIX_reserved(x)) 353 354 /* root record */ 355 /* size of root directory record */ 356 #define IDE_UNIX_ROOT_DIR_REC_SIZE 34+IDE_UNIX_UX_LEN 357 #define IDE_UNIX_MAX_NAME_LEN IDE_MAX_NAME_LEN - IDE_UNIX_UX_LEN 358 359 #endif /*!_ISO_SPEC_H_*/ 360