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 (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _SYS_FS_HSFS_SPEC_H 27 #define _SYS_FS_HSFS_SPEC_H 28 29 #pragma ident "%Z%%M% %I% %E% SMI" 30 31 /* 32 * High Sierra filesystem specification 33 */ 34 35 #include <sys/types.h> 36 #include <sys/time.h> 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #ifdef _KERNEL 43 44 /* routines required for date parsing */ 45 extern void hs_parse_dirdate(uchar_t *, struct timeval *); 46 extern void hs_parse_longdate(uchar_t *, struct timeval *); 47 48 #endif /* _KERNEL */ 49 50 51 /* macros to parse binary integers */ 52 #define ZERO(x) (uint_t)(((uchar_t *)(x))[0]) 53 #define ONE(x) (uint_t)(((uchar_t *)(x))[1]) 54 #define TWO(x) (uint_t)(((uchar_t *)(x))[2]) 55 #define THREE(x) (uint_t)(((uchar_t *)(x))[3]) 56 57 #define MSB_INT(x) \ 58 ((((((ZERO(x) << 8) | ONE(x)) << 8) | TWO(x)) << 8) | THREE(x)) 59 #define LSB_INT(x) \ 60 ((((((THREE(x) << 8) | TWO(x)) << 8) | ONE(x)) << 8) | ZERO(x)) 61 #define MSB_SHORT(x) ((ZERO(x) << 8) | ONE(x)) 62 #define LSB_SHORT(x) ((ONE(x) << 8) | ZERO(x)) 63 64 #if defined(__i386) || defined(__amd64) 65 #define BOTH_SHORT(x) (short)*((short *)x) 66 #define BOTH_INT(x) (int)*((int *)x) 67 #elif defined(__sparc) 68 /* 69 * SPARC machines requires that integer must 70 * be in a full word boundary. CD-ROM data aligns 71 * to even word boundary only. Because of this mismatch, 72 * we have to move integer data from CD-ROM to memory one 73 * byte at a time. LSB data starts first. We therefore 74 * use this to do byte by byte copying. 75 */ 76 #define BOTH_SHORT(x) LSB_SHORT(x) 77 #define BOTH_INT(x) LSB_INT(x) 78 #endif 79 80 /* 81 * The following describes actual on-disk structures. 82 * To achieve portability, all structures are #defines 83 * rather than a structure definition. Macros are provided 84 * to get either the data or address of individual fields. 85 */ 86 87 /* Overall High Sierra disk structure */ 88 #define HS_SECTOR_SIZE 2048 /* bytes per logical sector */ 89 #define HS_SECTOR_SHIFT 11 /* sector<->byte shift count */ 90 #define HS_SEC_PER_PAGE (PAGESIZE/HS_SECTOR_SIZE) /* sectors per page */ 91 #define HS_SYSAREA_SEC 0 /* 1st sector of system area */ 92 #define HS_VOLDESC_SEC 16 /* 1st sector of volume descriptors */ 93 #define MAXHSOFFSET (HS_SECTOR_SIZE - 1) 94 #define MAXHSMASK (~MAXHSOFFSET) 95 96 /* Standard File Structure Volume Descriptor */ 97 98 enum hs_voldesc_type { 99 VD_BOOT = 0, VD_SFS = 1, VD_CCFS = 2, VD_UNSPEC = 3, VD_EOV = 255 100 }; 101 #define HSV_ID_STRING "CDROM" /* HSV_std_id field */ 102 #define HSV_ID_STRLEN 5 /* HSV_std_id field length */ 103 #define HSV_ID_VER 1 /* HSV_std_ver field */ 104 #define HSV_FILE_STRUCT_ID_VER 1 /* HSV_file_struct_ver field */ 105 #define HSV_SYS_ID_STRLEN 32 /* HSV_sys_id field length */ 106 #define HSV_VOL_ID_STRLEN 32 /* HSV_vol_id field length */ 107 #define HSV_VOL_SET_ID_STRLEN 128 /* HSV_vol_set_id field length */ 108 #define HSV_PUB_ID_STRLEN 128 /* HSV_pub_id field length */ 109 #define HSV_PREP_ID_STRLEN 128 /* HSV_prep_id field length */ 110 #define HSV_APPL_ID_STRLEN 128 /* HSV_appl_id field length */ 111 #define HSV_COPYR_ID_STRLEN 32 /* HSV_copyr_id field length */ 112 #define HSV_ABSTR_ID_STRLEN 32 /* HSV_abstr_id field length */ 113 #define HSV_DATE_LEN 16 /* HSV date filed length */ 114 115 /* macros to get the address of each field */ 116 #define HSV_desc_lbn(x) (&((uchar_t *)x)[0]) 117 #define HSV_desc_type(x) (&((uchar_t *)x)[8]) 118 #define HSV_std_id(x) (&((uchar_t *)x)[9]) 119 #define HSV_std_ver(x) (&((uchar_t *)x)[14]) 120 #define HSV_sys_id(x) (&((uchar_t *)x)[16]) 121 #define HSV_vol_id(x) (&((uchar_t *)x)[48]) 122 #define HSV_vol_size(x) (&((uchar_t *)x)[88]) 123 #define HSV_set_size(x) (&((uchar_t *)x)[128]) 124 #define HSV_set_seq(x) (&((uchar_t *)x)[132]) 125 #define HSV_blk_size(x) (&((uchar_t *)x)[136]) 126 #define HSV_ptbl_size(x) (&((uchar_t *)x)[140]) 127 #define HSV_ptbl_man_ls(x) (&((uchar_t *)x)[148]) 128 #define HSV_ptbl_opt_ls1(x) (&((uchar_t *)x)[152]) 129 #define HSV_ptbl_opt_ls2(x) (&((uchar_t *)x)[156]) 130 #define HSV_ptbl_opt_ls3(x) (&((uchar_t *)x)[160]) 131 #define HSV_ptbl_man_ms(x) (&((uchar_t *)x)[164]) 132 #define HSV_ptbl_opt_ms1(x) (&((uchar_t *)x)[168]) 133 #define HSV_ptbl_opt_ms2(x) (&((uchar_t *)x)[172]) 134 #define HSV_ptbl_opt_ms3(x) (&((uchar_t *)x)[176]) 135 #define HSV_root_dir(x) (&((uchar_t *)x)[180]) 136 #define HSV_vol_set_id(x) (&((uchar_t *)x)[214]) 137 #define HSV_pub_id(x) (&((uchar_t *)x)[342]) 138 #define HSV_prep_id(x) (&((uchar_t *)x)[470]) 139 #define HSV_appl_id(x) (&((uchar_t *)x)[598]) 140 #define HSV_copyr_id(x) (&((uchar_t *)x)[726]) 141 #define HSV_abstr_id(x) (&((uchar_t *)x)[758]) 142 #define HSV_cre_date(x) (&((uchar_t *)x)[790]) 143 #define HSV_mod_date(x) (&((uchar_t *)x)[806]) 144 #define HSV_exp_date(x) (&((uchar_t *)x)[822]) 145 #define HSV_eff_date(x) (&((uchar_t *)x)[838]) 146 #define HSV_file_struct_ver(x) (&((uchar_t *)x)[854]) 147 148 /* macros to get the values of each field (strings are returned as ptrs) */ 149 #define HSV_DESC_LBN(x) BOTH_INT(HSV_desc_lbn(x)) 150 #define HSV_DESC_TYPE(x) ((enum hs_voldesc_type)*(HSV_desc_type(x))) 151 #define HSV_STD_ID(x) HSV_std_id(x) 152 #define HSV_STD_VER(x) *(HSV_std_ver(x)) 153 #define HSV_SYS_ID(x) HSV_sys_id(x) 154 #define HSV_VOL_ID(x) HSV_vol_id(x) 155 #define HSV_VOL_SIZE(x) BOTH_INT(HSV_vol_size(x)) 156 #define HSV_SET_SIZE(x) BOTH_SHORT(HSV_set_size(x)) 157 #define HSV_SET_SEQ(x) BOTH_SHORT(HSV_set_seq(x)) 158 #define HSV_BLK_SIZE(x) BOTH_SHORT(HSV_blk_size(x)) 159 #define HSV_PTBL_SIZE(x) BOTH_INT(HSV_ptbl_size(x)) 160 #define HSV_PTBL_MAN_LS(x) LSB_INT(HSV_ptbl_man_ls(x)) 161 #define HSV_PTBL_OPT_LS1(x) LSB_INT(HSV_ptbl_opt_ls1(x)) 162 #define HSV_PTBL_OPT_LS2(x) LSB_INT(HSV_ptbl_opt_ls2(x)) 163 #define HSV_PTBL_OPT_LS3(x) LSB_INT(HSV_ptbl_opt_ls3(x)) 164 #define HSV_PTBL_MAN_MS(x) MSB_INT(HSV_ptbl_man_ms(x)) 165 #define HSV_PTBL_OPT_MS1(x) MSB_INT(HSV_ptbl_opt_ms1(x)) 166 #define HSV_PTBL_OPT_MS2(x) MSB_INT(HSV_ptbl_opt_ms2(x)) 167 #define HSV_PTBL_OPT_MS3(x) MSB_INT(HSV_ptbl_opt_ms3(x)) 168 #define HSV_ROOT_DIR(x) HSV_root_dir(x) 169 #define HSV_VOL_SET_ID(x) HSV_vol_set_id(x) 170 #define HSV_PUB_ID(x) HSV_pub_id(x) 171 #define HSV_PREP_ID(x) HSV_prep_id(x) 172 #define HSV_APPL_ID(x) HSV_appl_id(x) 173 #define HSV_COPYR_ID(x) HSV_copyr_id(x) 174 #define HSV_ABSTR_ID(x) HSV_abstr_id(x) 175 #define HSV_CRE_DATE(x) HSV_cre_date(x) 176 #define HSV_MOD_DATE(x) HSV_mod_date(x) 177 #define HSV_EXP_DATE(x) HSV_exp_date(x) 178 #define HSV_EFF_DATE(x) HSV_eff_date(x) 179 #define HSV_FILE_STRUCT_VER(x) *(HSV_file_struct_ver(x)) 180 181 /* Standard File Structure Volume Descriptor date fields */ 182 #define HSV_DATE_2DIG(x) ((((x)[0] - '0') * 10) + \ 183 ((x)[1] - '0')) 184 #define HSV_DATE_4DIG(x) ((((x)[0] - '0') * 1000) + \ 185 (((x)[1] - '0') * 100) + \ 186 (((x)[2] - '0') * 10) + \ 187 ((x)[3] - '0')) 188 #define HSV_DATE_YEAR(x) HSV_DATE_4DIG(&((uchar_t *)x)[0]) 189 #define HSV_DATE_MONTH(x) HSV_DATE_2DIG(&((uchar_t *)x)[4]) 190 #define HSV_DATE_DAY(x) HSV_DATE_2DIG(&((uchar_t *)x)[6]) 191 #define HSV_DATE_HOUR(x) HSV_DATE_2DIG(&((uchar_t *)x)[8]) 192 #define HSV_DATE_MIN(x) HSV_DATE_2DIG(&((uchar_t *)x)[10]) 193 #define HSV_DATE_SEC(x) HSV_DATE_2DIG(&((uchar_t *)x)[12]) 194 #define HSV_DATE_HSEC(x) HSV_DATE_2DIG(&((uchar_t *)x)[14]) 195 #define HSV_DATE_GMTOFF(x) (((char *)x)[16]) 196 197 198 /* Path table enry */ 199 /* fix size of path table entry */ 200 #define HPE_FPESIZE 8 201 /* macros to get the address of each field */ 202 #define HPE_ext_lbn(x) (&((uchar_t *)x)[0]) 203 #define HPE_xar_len(x) (&((uchar_t *)x)[4]) 204 #define HPE_name_len(x) (&((uchar_t *)x)[5]) 205 #define HPE_parent_no(x) (&((uchar_t *)x)[6]) 206 #define HPE_name(x) (&((uchar_t *)x)[8]) 207 208 /* macros to get the values of each field */ 209 #if defined(__sparc) 210 #define HPE_EXT_LBN(x) (MSB_INT(HPE_ext_lbn(x))) 211 #else 212 #define HPE_EXT_LBN(x) *(int *)(HPE_ext_lbn(x)) 213 #endif 214 #define HPE_XAR_LEN(x) *(HPE_xar_len(x)) 215 #define HPE_NAME_LEN(x) *(HPE_name_len(x)) 216 #define HPE_PARENT_NO(x) *(short *)(HPE_parent_no(x)) 217 #define HPE_NAME(x) HPE_name(x) 218 219 /* root record */ 220 #define HDE_ROOT_DIR_REC_SIZE 34 /* size of root directory record */ 221 #define HDE_FDESIZE 33 /* fixed size for hsfs directory area */ 222 #define HDE_FUSIZE 12 /* fixed size for unix area */ 223 /* max size of a name */ 224 #define HDE_MAX_NAME_LEN (255 - HDE_FDESIZE - HDE_FUSIZE) 225 226 /* Directory Entry (Directory Record) */ 227 228 #define UNIX_TO_HDE_DATE(t, p) parse_unixdate((t), (p)) 229 230 /* macros to get the address of each field */ 231 #define HDE_dir_len(x) (&((uchar_t *)x)[0]) 232 #define HDE_xar_len(x) (&((uchar_t *)x)[1]) 233 #define HDE_ext_lbn(x) (&((uchar_t *)x)[2]) 234 #define HDE_ext_size(x) (&((uchar_t *)x)[10]) 235 #define HDE_cdate(x) (&((uchar_t *)x)[18]) 236 #define HDE_flags(x) (&((uchar_t *)x)[24]) 237 #define HDE_reserved(x) (&((uchar_t *)x)[25]) 238 #define HDE_intrlv_size(x) (&((uchar_t *)x)[26]) 239 #define HDE_intrlv_skip(x) (&((uchar_t *)x)[27]) 240 #define HDE_vol_set(x) (&((uchar_t *)x)[28]) 241 #define HDE_name_len(x) (&((uchar_t *)x)[32]) 242 #define HDE_name(x) (&((uchar_t *)x)[33]) 243 244 /* **UNIX extension*** */ 245 #define HDE_mode(x) (&((uchar_t *)x)[0]) 246 #define HDE_uid(x) (&((uchar_t *)x)[4]) 247 #define HDE_gid(x) (&((uchar_t *)x)[8]) 248 249 /* macros to get the values of each field (strings are returned as ptrs) */ 250 #define HDE_DIR_LEN(x) *(HDE_dir_len(x)) 251 #define HDE_XAR_LEN(x) *(HDE_xar_len(x)) 252 #define HDE_EXT_LBN(x) BOTH_INT(HDE_ext_lbn(x)) 253 #define HDE_EXT_SIZE(x) BOTH_INT(HDE_ext_size(x)) 254 #define HDE_CDATE(x) HDE_cdate(x) 255 #define HDE_FLAGS(x) *(HDE_flags(x)) 256 #define HDE_RESERVED(x) *(HDE_reserved(x)) 257 #define HDE_INTRLV_SIZE(x) *(HDE_intrlv_size(x)) 258 #define HDE_INTRLV_SKIP(x) *(HDE_intrlv_skip(x)) 259 #define HDE_VOL_SET(x) BOTH_SHORT(HDE_vol_set(x)) 260 #define HDE_NAME_LEN(x) *(HDE_name_len(x)) 261 #define HDE_NAME(x) HDE_name(x) 262 263 /* **UNIX EXTENSION**** */ 264 #define HDE_MODE(x) *(HDE_mode(x)) 265 #define HDE_UID(x) *(HDE_uid(x)) 266 #define HDE_GID(x) *(HDE_gid(x)) 267 268 /* mask bits for HDE_FLAGS */ 269 #define HDE_EXISTENCE 0x01 /* zero if file exists */ 270 #define HDE_DIRECTORY 0x02 /* zero if file is not a directory */ 271 #define HDE_ASSOCIATED 0x04 /* zero if file is not Associated */ 272 #define HDE_RECORD 0x08 /* zero if no record attributes */ 273 #define HDE_PROTECTION 0x10 /* zero if no protection attributes */ 274 #define HDE_UNUSED_FLAGS 0x60 275 #define HDE_LAST_EXTENT 0x80 /* zero if last extent in file */ 276 #define HDE_PROHIBITED (HDE_DIRECTORY | HDE_RECORD | \ 277 HDE_LAST_EXTENT | HDE_UNUSED_FLAGS) 278 279 /* Directory Record date fields */ 280 #define HDE_DATE_YEAR(x) (((uchar_t *)x)[0] + 1900) 281 #define HDE_DATE_MONTH(x) (((uchar_t *)x)[1]) 282 #define HDE_DATE_DAY(x) (((uchar_t *)x)[2]) 283 #define HDE_DATE_HOUR(x) (((uchar_t *)x)[3]) 284 #define HDE_DATE_MIN(x) (((uchar_t *)x)[4]) 285 #define HDE_DATE_SEC(x) (((uchar_t *)x)[5]) 286 #define HDE_DATE_GMTOFF(x) (((char *)x)[6]) 287 288 289 /* tests for Interchange Levels 1 & 2 file types */ 290 #define HDE_REGULAR_FILE(x) (((x) & HDE_PROHIBITED) == 0) 291 #define HDE_REGULAR_DIR(x) (((x) & HDE_PROHIBITED) == HDE_DIRECTORY) 292 293 #define HS_DIR_NAMELEN 31 /* max length of a directory name */ 294 #define HS_FILE_NAMELEN 31 /* max length of a filename */ 295 296 #ifdef __cplusplus 297 } 298 #endif 299 300 #endif /* _SYS_FS_HSFS_SPEC_H */ 301