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 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_FS_HSFS_ISOSPEC_H 28 #define _SYS_FS_HSFS_ISOSPEC_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * ISO 9660 filesystem specification 34 */ 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 /* macros to parse binary integers */ 41 #define ZERO(x) (uint_t)(((uchar_t *)(x))[0]) 42 #define ONE(x) (uint_t)(((uchar_t *)(x))[1]) 43 #define TWO(x) (uint_t)(((uchar_t *)(x))[2]) 44 #define THREE(x) (uint_t)(((uchar_t *)(x))[3]) 45 46 #define MSB_INT(x) \ 47 ((((((ZERO(x) << 8) | ONE(x)) << 8) | TWO(x)) << 8) | THREE(x)) 48 #define LSB_INT(x) \ 49 ((((((THREE(x) << 8) | TWO(x)) << 8) | ONE(x)) << 8) | ZERO(x)) 50 #define MSB_SHORT(x) ((ZERO(x) << 8) | ONE(x)) 51 #define LSB_SHORT(x) ((ONE(x) << 8) | ZERO(x)) 52 53 #if defined(__i386) || defined(__amd64) 54 #define BOTH_SHORT(x) (short)*((short *)x) 55 #define BOTH_INT(x) (int)*((int *)x) 56 #elif defined(__sparc) 57 /* 58 * SPARC machines require that integers must 59 * be aligned on a full word boundary. CD-ROM data aligns 60 * to even word boundary only. Because of this mismatch, 61 * we have to move integer data from CD-ROM to memory one 62 * byte at a time. LSB data starts first. We therefore 63 * use this to do byte by byte copying. 64 */ 65 #define BOTH_SHORT(x) LSB_SHORT(x) 66 #define BOTH_INT(x) LSB_INT(x) 67 #endif 68 69 /* 70 * The following describes actual on-disk structures. 71 * To achieve portability, all structures are #defines 72 * rather than a structure definition. Macros are provided 73 * to get either the data or address of individual fields. 74 */ 75 76 /* Overall High Sierra disk structure */ 77 #define ISO_SECTOR_SIZE 2048 /* bytes per logical sector */ 78 #define ISO_SECTOR_SHIFT 11 /* sector<->byte shift count */ 79 #define ISO_SEC_PER_PAGE (PAGESIZE/HS_SECTOR_SIZE) 80 /* sectors per page */ 81 #define ISO_SYSAREA_SEC 0 /* 1st sector of system area */ 82 #define ISO_VOLDESC_SEC 16 /* 1st sector of volume descriptors */ 83 #define MAXISOOFFSET (ISO_SECTOR_SIZE - 1) 84 #define MAXISOMASK (~MAXISOOFFSET) 85 86 87 /* Standard File Structure Volume Descriptor */ 88 89 enum iso_voldesc_type { 90 ISO_VD_BOOT = 0, ISO_VD_PVD = 1, ISO_VD_SVD = 2, ISO_VD_VPD = 3, 91 ISO_VD_EOV = 255 92 }; 93 #define ISO_ID_STRING "CD001" /* ISO_std_id field */ 94 #define ISO_ID_STRLEN 5 /* ISO_std_id field length */ 95 #define ISO_ID_VER 1 /* ISO_std_ver field */ 96 #define ISO_FILE_STRUCT_ID_VER 1 /* ISO_file structure version field */ 97 #define ISO_SYS_ID_STRLEN 32 98 #define ISO_VOL_ID_STRLEN 32 99 #define ISO_VOL_SET_ID_STRLEN 128 100 #define ISO_PUB_ID_STRLEN 128 101 #define ISO_PREP_ID_STRLEN 128 102 #define ISO_APPL_ID_STRLEN 128 103 #define ISO_COPYR_ID_STRLEN 37 104 #define ISO_ABSTR_ID_STRLEN 37 105 #define ISO_SHORT_DATE_LEN 7 106 #define ISO_DATE_LEN 17 107 108 109 110 /* macros to get the address of each field */ 111 #define ISO_desc_type(x) (&((uchar_t *)x)[0]) 112 #define ISO_std_id(x) (&((uchar_t *)x)[1]) 113 #define ISO_std_ver(x) (&((uchar_t *)x)[6]) 114 #define ISO_sys_id(x) (&((uchar_t *)x)[8]) 115 #define ISO_vol_id(x) (&((uchar_t *)x)[40]) 116 #define ISO_vol_size(x) (&((uchar_t *)x)[80]) 117 #define ISO_set_size(x) (&((uchar_t *)x)[120]) 118 #define ISO_set_seq(x) (&((uchar_t *)x)[124]) 119 #define ISO_blk_size(x) (&((uchar_t *)x)[128]) 120 #define ISO_ptbl_size(x) (&((uchar_t *)x)[132]) 121 #define ISO_ptbl_man_ls(x) (&((uchar_t *)x)[140]) 122 #define ISO_ptbl_opt_ls1(x) (&((uchar_t *)x)[144]) 123 #define ISO_ptbl_man_ms(x) (&((uchar_t *)x)[148]) 124 #define ISO_ptbl_opt_ms1(x) (&((uchar_t *)x)[152]) 125 #define ISO_root_dir(x) (&((uchar_t *)x)[156]) 126 #define ISO_vol_set_id(x) (&((uchar_t *)x)[190]) 127 #define ISO_pub_id(x) (&((uchar_t *)x)[318]) 128 #define ISO_prep_id(x) (&((uchar_t *)x)[446]) 129 #define ISO_appl_id(x) (&((uchar_t *)x)[574]) 130 #define ISO_copyr_id(x) (&((uchar_t *)x)[702]) 131 #define ISO_abstr_id(x) (&((uchar_t *)x)[739]) 132 #define ISO_bibli_id(x) (&((uchar_t *)x)[776]) 133 #define ISO_cre_date(x) (&((uchar_t *)x)[813]) 134 #define ISO_mod_date(x) (&((uchar_t *)x)[830]) 135 #define ISO_exp_date(x) (&((uchar_t *)x)[847]) 136 #define ISO_eff_date(x) (&((uchar_t *)x)[864]) 137 #define ISO_file_struct_ver(x) (&((uchar_t *)x)[881]) 138 139 /* macros to get the values of each field (strings are returned as ptrs) */ 140 #define ISO_DESC_TYPE(x) ((enum hs_voldesc_type)*(ISO_desc_type(x))) 141 #define ISO_STD_ID(x) ISO_std_id(x) 142 #define ISO_STD_VER(x) *(ISO_std_ver(x)) 143 #define ISO_SYS_ID(x) ISO_sys_id(x) 144 #define ISO_VOL_ID(x) ISO_vol_id(x) 145 #define ISO_VOL_SIZE(x) BOTH_INT(ISO_vol_size(x)) 146 #define ISO_SET_SIZE(x) BOTH_SHORT(ISO_set_size(x)) 147 #define ISO_SET_SEQ(x) BOTH_SHORT(ISO_set_seq(x)) 148 #define ISO_BLK_SIZE(x) BOTH_SHORT(ISO_blk_size(x)) 149 #define ISO_PTBL_SIZE(x) BOTH_INT(ISO_ptbl_size(x)) 150 #define ISO_PTBL_MAN_LS(x) LSB_INT(ISO_ptbl_man_ls(x)) 151 #define ISO_PTBL_OPT_LS1(x) LSB_INT(ISO_ptbl_opt_ls1(x)) 152 #define ISO_PTBL_MAN_MS(x) MSB_INT(ISO_ptbl_man_ms(x)) 153 #define ISO_PTBL_OPT_MS1(x) MSB_INT(ISO_ptbl_opt_ms1(x)) 154 #define ISO_ROOT_DIR(x) ISO_root_dir(x) 155 #define ISO_VOL_SET_ID(x) ISO_vol_set_id(x) 156 #define ISO_PUB_ID(x) ISO_pub_id(x) 157 #define ISO_PREP_ID(x) ISO_prep_id(x) 158 #define ISO_APPL_ID(x) ISO_appl_id(x) 159 #define ISO_COPYR_ID(x) ISO_copyr_id(x) 160 #define ISO_ABSTR_ID(x) ISO_abstr_id(x) 161 #define ISO_BIBLI_ID(x) ISO_bibli_id(x) 162 #define ISO_CRE_DATE(x) HSV_cre_date(x) 163 #define ISO_MOD_DATE(x) HSV_mod_date(x) 164 #define ISO_EXP_DATE(x) HSV_exp_date(x) 165 #define ISO_EFF_DATE(x) HSV_eff_date(x) 166 #define ISO_FILE_STRUCT_VER(x) *(ISO_file_struct_ver(x)) 167 168 /* Standard File Structure Volume Descriptor date fields */ 169 #define ISO_DATE_2DIG(x) ((((x)[0] - '0') * 10) + \ 170 ((x)[1] - '0')) 171 #define ISO_DATE_4DIG(x) ((((x)[0] - '0') * 1000) + \ 172 (((x)[1] - '0') * 100) + \ 173 (((x)[2] - '0') * 10) + \ 174 ((x)[3] - '0')) 175 #define ISO_DATE_YEAR(x) ISO_DATE_4DIG(&((uchar_t *)x)[0]) 176 #define ISO_DATE_MONTH(x) ISO_DATE_2DIG(&((uchar_t *)x)[4]) 177 #define ISO_DATE_DAY(x) ISO_DATE_2DIG(&((uchar_t *)x)[6]) 178 #define ISO_DATE_HOUR(x) ISO_DATE_2DIG(&((uchar_t *)x)[8]) 179 #define ISO_DATE_MIN(x) ISO_DATE_2DIG(&((uchar_t *)x)[10]) 180 #define ISO_DATE_SEC(x) ISO_DATE_2DIG(&((uchar_t *)x)[12]) 181 #define ISO_DATE_HSEC(x) ISO_DATE_2DIG(&((uchar_t *)x)[14]) 182 #define ISO_DATE_GMTOFF(x) (((char *)x)[16]) 183 184 185 186 /* Directory Entry (Directory Record) */ 187 #define IDE_ROOT_DIR_REC_SIZE 34 /* size of root directory record */ 188 #define IDE_FDESIZE 33 /* fixed size for hsfs directory area */ 189 /* max size of a name */ 190 #define IDE_MAX_NAME_LEN (255 - IDE_FDESIZE) 191 192 193 /* macros to get the address of each field */ 194 #define IDE_dir_len(x) (&((uchar_t *)x)[0]) 195 #define IDE_xar_len(x) (&((uchar_t *)x)[1]) 196 #define IDE_ext_lbn(x) (&((uchar_t *)x)[2]) 197 #define IDE_ext_size(x) (&((uchar_t *)x)[10]) 198 #define IDE_cdate(x) (&((uchar_t *)x)[18]) 199 #define IDE_flags(x) (&((uchar_t *)x)[25]) 200 #define IDE_intrlv_size(x) (&((uchar_t *)x)[26]) 201 #define IDE_intrlv_skip(x) (&((uchar_t *)x)[27]) 202 #define IDE_vol_set(x) (&((uchar_t *)x)[28]) 203 #define IDE_name_len(x) (&((uchar_t *)x)[32]) 204 #define IDE_name(x) (&((uchar_t *)x)[33]) 205 #define IDE_sys_use_area(x) (&((uchar_t *)x)[IDE_NAME_LEN(x) + \ 206 IDE_PAD_LEN(x)] + IDE_FDESIZE) 207 208 /* macros to get the values of each field (strings are returned as ptrs) */ 209 #define IDE_DIR_LEN(x) *(IDE_dir_len(x)) 210 #define IDE_XAR_LEN(x) *(IDE_xar_len(x)) 211 #define IDE_EXT_LBN(x) BOTH_INT(IDE_ext_lbn(x)) 212 #define IDE_EXT_SIZE(x) BOTH_INT(IDE_ext_size(x)) 213 #define IDE_CDATE(x) IDE_cdate(x) 214 #define IDE_FLAGS(x) *(IDE_flags(x)) 215 #define IDE_INTRLV_SIZE(x) *(IDE_intrlv_size(x)) 216 #define IDE_INTRLV_SKIP(x) *(IDE_intrlv_skip(x)) 217 #define IDE_VOL_SET(x) BOTH_SHORT(IDE_vol_set(x)) 218 #define IDE_NAME_LEN(x) *(IDE_name_len(x)) 219 #define IDE_NAME(x) IDE_name(x) 220 #define IDE_PAD_LEN(x) ((IDE_NAME_LEN(x) % 2) ? 0 : 1) 221 #define IDE_SUA_LEN(x) (IDE_DIR_LEN(x) - IDE_FDESIZE - \ 222 IDE_NAME_LEN(x) - IDE_PAD_LEN(x)) 223 224 /* mask bits for IDE_FLAGS */ 225 #define IDE_EXISTENCE 0x01 /* zero if file exists */ 226 #define IDE_DIRECTORY 0x02 /* zero if file is not a directory */ 227 #define IDE_ASSOCIATED 0x04 /* zero if file is not Associated */ 228 #define IDE_RECORD 0x08 /* zero if no record attributes */ 229 #define IDE_PROTECTION 0x10 /* zero if no protection attributes */ 230 #define IDE_UNUSED_FLAGS 0x60 231 #define IDE_LAST_EXTENT 0x80 /* zero if last extent in file */ 232 #define IDE_PROHIBITED (IDE_DIRECTORY | IDE_RECORD | \ 233 IDE_LAST_EXTENT | IDE_UNUSED_FLAGS) 234 235 /* Directory Record date fields */ 236 #define IDE_DATE_YEAR(x) (((uchar_t *)x)[0] + 1900) 237 #define IDE_DATE_MONTH(x) (((uchar_t *)x)[1]) 238 #define IDE_DATE_DAY(x) (((uchar_t *)x)[2]) 239 #define IDE_DATE_HOUR(x) (((uchar_t *)x)[3]) 240 #define IDE_DATE_MIN(x) (((uchar_t *)x)[4]) 241 #define IDE_DATE_SEC(x) (((uchar_t *)x)[5]) 242 #define IDE_DATE_GMTOFF(x) (((char *)x)[6]) 243 244 /* tests for Interchange Levels 1 & 2 file types */ 245 #define IDE_REGULAR_FILE(x) (((x) & IDE_PROHIBITED) == 0) 246 #define IDE_REGULAR_DIR(x) (((x) & IDE_PROHIBITED) == IDE_DIRECTORY) 247 248 #define ISO_DIR_NAMELEN 31 /* max length of a directory name */ 249 #define ISO_FILE_NAMELEN 31 /* max length of a filename, */ 250 /* excluding ";" and version num */ 251 252 /* Path table enry */ 253 /* fix size of path table entry */ 254 #define IPE_FPESIZE 8 255 /* macros to get the address of each field */ 256 #define IPE_name_len(x) (&((uchar_t *)x)[0]) 257 #define IPE_xar_len(x) (&((uchar_t *)x)[1]) 258 #define IPE_ext_lbn(x) (&((uchar_t *)x)[2]) 259 #define IPE_parent_no(x) (&((uchar_t *)x)[6]) 260 #define IPE_name(x) (&((uchar_t *)x)[8]) 261 262 /* macros to get the values of each field */ 263 #define IPE_EXT_LBN(x) (MSB_INT(IPE_ext_lbn(x))) 264 #define IPE_XAR_LEN(x) *(IPE_xar_len(x)) 265 #define IPE_NAME_LEN(x) *(IPE_name_len(x)) 266 #define IPE_PARENT_NO(x) *(short *)(IPE_parent_no(x)) 267 #define IPE_NAME(x) IPE_name(x) 268 269 #ifdef __cplusplus 270 } 271 #endif 272 273 #endif /* _SYS_FS_HSFS_ISOSPEC_H */ 274