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 #pragma ident "%Z%%M% %I% %E% SMI" 23 24 /* 25 * High Sierra filesystem specification 26 * Copyright (c) 1989 by Sun Microsystem, Inc. 27 */ 28 29 #ifndef _HSFS_SPEC_H_ 30 #define _HSFS_SPEC_H_ 31 32 #include <sys/isa_defs.h> /* for ENDIAN defines */ 33 34 /* routines required for date parsing */ 35 extern void hs_parse_dirdate(); /* parse date in directory */ 36 extern void hs_parse_longdate(); /* parse date in volume id */ 37 38 /* macros to parse binary integers */ 39 #define ZERO(x) (u_int) (((u_char *)(x))[0]) 40 #define ONE(x) (u_int) (((u_char *)(x))[1]) 41 #define TWO(x) (u_int) (((u_char *)(x))[2]) 42 #define THREE(x) (u_int) (((u_char *)(x))[3]) 43 44 #define MSB_INT(x) \ 45 ((((((ZERO(x) << 8) | ONE(x)) << 8) | TWO(x)) << 8) | THREE(x)) 46 #define LSB_INT(x) \ 47 ((((((THREE(x) << 8) | TWO(x)) << 8) | ONE(x)) << 8) | ZERO(x)) 48 #define MSB_SHORT(x) ((ZERO(x) << 8) | ONE(x)) 49 #define LSB_SHORT(x) ((ONE(x) << 8) | ZERO(x)) 50 51 #if defined(_LITTLE_ENDIAN) 52 #define BOTH_SHORT(x) (short) *((short *)x) 53 #define BOTH_INT(x) (int) *((int *)x) 54 #endif 55 56 /* 57 * The following describes actual on-disk structures. 58 * To achieve portability, all structures are #defines 59 * rather than a structure definition. Macros are provided 60 * to get either the data or address of individual fields. 61 */ 62 63 /* Overall High Sierra disk structure */ 64 #define HS_SECTOR_SIZE 2048 /* bytes per logical sector */ 65 #define HS_SECTOR_SHIFT 11 /* sector<->byte shift count */ 66 #define HS_SEC_PER_PAGE (PAGESIZE/HS_SECTOR_SIZE) /* sectors per page */ 67 #define HS_SYSAREA_SEC 0 /* 1st sector of system area */ 68 #define HS_VOLDESC_SEC 16 /* 1st sector of volume descriptors */ 69 #define MAXHSOFFSET (HS_SECTOR_SIZE - 1) 70 #define MAXHSMASK (~MAXHSOFFSET) 71 72 /* Standard File Structure Volume Descriptor */ 73 74 enum hs_voldesc_type { 75 VD_BOOT=0, VD_SFS=1, VD_CCFS=2, VD_UNSPEC=3, VD_EOV=255 76 }; 77 #define HSV_ID_STRING "CDROM" /* HSV_std_id field */ 78 #define HSV_ID_STRLEN 5 /* HSV_std_id field length */ 79 #define HSV_ID_VER 1 /* HSV_std_ver field */ 80 #define HSV_FILE_STRUCT_ID_VER 1 /* HSV_file_struct_ver field */ 81 #define HSV_SYS_ID_STRLEN 32 /* HSV_sys_id field length */ 82 #define HSV_VOL_ID_STRLEN 32 /* HSV_vol_id field length */ 83 #define HSV_VOL_SET_ID_STRLEN 128 /* HSV_vol_set_id field length */ 84 #define HSV_PUB_ID_STRLEN 128 /* HSV_pub_id field length */ 85 #define HSV_PREP_ID_STRLEN 128 /* HSV_prep_id field length */ 86 #define HSV_APPL_ID_STRLEN 128 /* HSV_appl_id field length */ 87 #define HSV_COPYR_ID_STRLEN 32 /* HSV_copyr_id field length */ 88 #define HSV_ABSTR_ID_STRLEN 32 /* HSV_abstr_id field length */ 89 #define HSV_DATE_LEN 16 /* HSV date filed length */ 90 91 /* macros to get the address of each field */ 92 #define HSV_desc_lbn(x) (&((u_char *)x)[0]) 93 #define HSV_desc_type(x) (&((u_char *)x)[8]) 94 #define HSV_std_id(x) (&((u_char *)x)[9]) 95 #define HSV_std_ver(x) (&((u_char *)x)[14]) 96 #define HSV_sys_id(x) (&((u_char *)x)[16]) 97 #define HSV_vol_id(x) (&((u_char *)x)[48]) 98 #define HSV_vol_size(x) (&((u_char *)x)[88]) 99 #define HSV_set_size(x) (&((u_char *)x)[128]) 100 #define HSV_set_seq(x) (&((u_char *)x)[132]) 101 #define HSV_blk_size(x) (&((u_char *)x)[136]) 102 #define HSV_ptbl_size(x) (&((u_char *)x)[140]) 103 #define HSV_ptbl_man_ls(x) (&((u_char *)x)[148]) 104 #define HSV_ptbl_opt_ls1(x) (&((u_char *)x)[152]) 105 #define HSV_ptbl_opt_ls2(x) (&((u_char *)x)[156]) 106 #define HSV_ptbl_opt_ls3(x) (&((u_char *)x)[160]) 107 #define HSV_ptbl_man_ms(x) (&((u_char *)x)[164]) 108 #define HSV_ptbl_opt_ms1(x) (&((u_char *)x)[168]) 109 #define HSV_ptbl_opt_ms2(x) (&((u_char *)x)[172]) 110 #define HSV_ptbl_opt_ms3(x) (&((u_char *)x)[176]) 111 #define HSV_root_dir(x) (&((u_char *)x)[180]) 112 #define HSV_vol_set_id(x) (&((u_char *)x)[214]) 113 #define HSV_pub_id(x) (&((u_char *)x)[342]) 114 #define HSV_prep_id(x) (&((u_char *)x)[470]) 115 #define HSV_appl_id(x) (&((u_char *)x)[598]) 116 #define HSV_copyr_id(x) (&((u_char *)x)[726]) 117 #define HSV_abstr_id(x) (&((u_char *)x)[758]) 118 #define HSV_cre_date(x) (&((u_char *)x)[790]) 119 #define HSV_mod_date(x) (&((u_char *)x)[806]) 120 #define HSV_exp_date(x) (&((u_char *)x)[822]) 121 #define HSV_eff_date(x) (&((u_char *)x)[838]) 122 #define HSV_file_struct_ver(x) (&((u_char *)x)[854]) 123 124 /* macros to get the values of each field (strings are returned as ptrs) */ 125 #define HSV_DESC_LBN(x) BOTH_INT(HSV_desc_lbn(x)) 126 #define HSV_DESC_TYPE(x) ((enum hs_voldesc_type)*(HSV_desc_type(x))) 127 #define HSV_STD_ID(x) HSV_std_id(x) 128 #define HSV_STD_VER(x) *(HSV_std_ver(x)) 129 #define HSV_SYS_ID(x) HSV_sys_id(x) 130 #define HSV_VOL_ID(x) HSV_vol_id(x) 131 #define HSV_VOL_SIZE(x) BOTH_INT(HSV_vol_size(x)) 132 #define HSV_SET_SIZE(x) BOTH_SHORT(HSV_set_size(x)) 133 #define HSV_SET_SEQ(x) BOTH_SHORT(HSV_set_seq(x)) 134 #define HSV_BLK_SIZE(x) BOTH_SHORT(HSV_blk_size(x)) 135 #define HSV_PTBL_SIZE(x) BOTH_INT(HSV_ptbl_size(x)) 136 #define HSV_PTBL_MAN_LS(x) LSB_INT(HSV_ptbl_man_ls(x)) 137 #define HSV_PTBL_OPT_LS1(x) LSB_INT(HSV_ptbl_opt_ls1(x)) 138 #define HSV_PTBL_OPT_LS2(x) LSB_INT(HSV_ptbl_opt_ls2(x)) 139 #define HSV_PTBL_OPT_LS3(x) LSB_INT(HSV_ptbl_opt_ls3(x)) 140 #define HSV_PTBL_MAN_MS(x) MSB_INT(HSV_ptbl_man_ms(x)) 141 #define HSV_PTBL_OPT_MS1(x) MSB_INT(HSV_ptbl_opt_ms1(x)) 142 #define HSV_PTBL_OPT_MS2(x) MSB_INT(HSV_ptbl_opt_ms2(x)) 143 #define HSV_PTBL_OPT_MS3(x) MSB_INT(HSV_ptbl_opt_ms3(x)) 144 #define HSV_ROOT_DIR(x) HSV_root_dir(x) 145 #define HSV_VOL_SET_ID(x) HSV_vol_set_id(x) 146 #define HSV_PUB_ID(x) HSV_pub_id(x) 147 #define HSV_PREP_ID(x) HSV_prep_id(x) 148 #define HSV_APPL_ID(x) HSV_appl_id(x) 149 #define HSV_COPYR_ID(x) HSV_copyr_id(x) 150 #define HSV_ABSTR_ID(x) HSV_abstr_id(x) 151 #define HSV_CRE_DATE(x) HSV_cre_date(x) 152 #define HSV_MOD_DATE(x) HSV_mod_date(x) 153 #define HSV_EXP_DATE(x) HSV_exp_date(x) 154 #define HSV_EFF_DATE(x) HSV_eff_date(x) 155 #define HSV_FILE_STRUCT_VER(x) *(HSV_file_struct_ver(x)) 156 157 /* Standard File Structure Volume Descriptor date fields */ 158 #define HSV_DATE_2DIG(x) ( (((x)[0] - '0') * 10) + \ 159 ((x)[1] - '0') ) 160 #define HSV_DATE_4DIG(x) ( (((x)[0] - '0') * 1000) + \ 161 (((x)[1] - '0') * 100) + \ 162 (((x)[2] - '0') * 10) + \ 163 ((x)[3] - '0') ) 164 #define HSV_DATE_YEAR(x) HSV_DATE_4DIG(&((u_char *)x)[0]) 165 #define HSV_DATE_MONTH(x) HSV_DATE_2DIG(&((u_char *)x)[4]) 166 #define HSV_DATE_DAY(x) HSV_DATE_2DIG(&((u_char *)x)[6]) 167 #define HSV_DATE_HOUR(x) HSV_DATE_2DIG(&((u_char *)x)[8]) 168 #define HSV_DATE_MIN(x) HSV_DATE_2DIG(&((u_char *)x)[10]) 169 #define HSV_DATE_SEC(x) HSV_DATE_2DIG(&((u_char *)x)[12]) 170 #define HSV_DATE_HSEC(x) HSV_DATE_2DIG(&((u_char *)x)[14]) 171 172 /* Path table enry */ 173 /* fix size of path table entry */ 174 #define HPE_FPESIZE 8 175 /* macros to get the address of each field */ 176 #define HPE_ext_lbn(x) (&((u_char *)x)[0]) 177 #define HPE_xar_len(x) (&((u_char *)x)[4]) 178 #define HPE_name_len(x) (&((u_char *)x)[5]) 179 #define HPE_parent_no(x) (&((u_char *)x)[6]) 180 #define HPE_name(x) (&((u_char *)x)[8]) 181 182 /* macros to get the values of each field */ 183 #if sun4 184 #define HPE_EXT_LBN(x) (MSB_INT(HPE_ext_lbn(x))) 185 #else 186 #define HPE_EXT_LBN(x) *(int *)(HPE_ext_lbn(x)) 187 #endif 188 #define HPE_XAR_LEN(x) *(HPE_xar_len(x)) 189 #define HPE_NAME_LEN(x) *(HPE_name_len(x)) 190 #define HPE_PARENT_NO(x) *(short *)(HPE_parent_no(x)) 191 #define HPE_NAME(x) HPE_name(x) 192 193 /* root record */ 194 #define HDE_ROOT_DIR_REC_SIZE 34 /* size of root directory record */ 195 #define HDE_FDESIZE 33 /* fixed size for hsfs directory area */ 196 #define HDE_FUSIZE 12 /* fixed size for unix areaa */ 197 /* max size of a name */ 198 #define HDE_MAX_NAME_LEN (255 - HDE_FDESIZE - HDE_FUSIZE) 199 200 /* Directory Entry (Directory Record) */ 201 202 #define UNIX_TO_HDE_DATE(t,p) parse_unixdate(t, p) /* return val at p */ 203 204 /* macros to get the address of each field */ 205 #define HDE_dir_len(x) (&((u_char *)x)[0]) 206 #define HDE_xar_len(x) (&((u_char *)x)[1]) 207 #define HDE_ext_lbn(x) (&((u_char *)x)[2]) 208 #define HDE_ext_size(x) (&((u_char *)x)[10]) 209 #define HDE_cdate(x) (&((u_char *)x)[18]) 210 #define HDE_flags(x) (&((u_char *)x)[24]) 211 #define HDE_reserved(x) (&((u_char *)x)[25]) 212 #define HDE_intrlv_size(x) (&((u_char *)x)[26]) 213 #define HDE_intrlv_skip(x) (&((u_char *)x)[27]) 214 #define HDE_vol_set(x) (&((u_char *)x)[28]) 215 #define HDE_name_len(x) (&((u_char *)x)[32]) 216 #define HDE_name(x) (&((u_char *)x)[33]) 217 218 /***UNIX extension****/ 219 #define HDE_mode(x) (&((u_char *)x)[0]) 220 #define HDE_uid(x) (&((u_char *)x)[4]) 221 #define HDE_gid(x) (&((u_char *)x)[8]) 222 223 /* macros to get the values of each field (strings are returned as ptrs) */ 224 #define HDE_DIR_LEN(x) *(HDE_dir_len(x)) 225 #define HDE_XAR_LEN(x) *(HDE_xar_len(x)) 226 #define HDE_EXT_LBN(x) BOTH_INT(HDE_ext_lbn(x)) 227 #define HDE_EXT_SIZE(x) BOTH_INT(HDE_ext_size(x)) 228 #define HDE_CDATE(x) HDE_cdate(x) 229 #define HDE_FLAGS(x) *(HDE_flags(x)) 230 #define HDE_RESERVED(x) *(HDE_reserved(x)) 231 #define HDE_INTRLV_SIZE(x) *(HDE_intrlv_size(x)) 232 #define HDE_INTRLV_SKIP(x) *(HDE_intrlv_skip(x)) 233 #define HDE_VOL_SET(x) BOTH_SHORT(HDE_vol_set(x)) 234 #define HDE_NAME_LEN(x) *(HDE_name_len(x)) 235 #define HDE_NAME(x) HDE_name(x) 236 237 /***UNIX EXTENSION*****/ 238 #define HDE_MODE(x) *(HDE_mode(x)) 239 #define HDE_UID(x) *(HDE_uid(x)) 240 #define HDE_GID(x) *(HDE_gid(x)) 241 242 /* mask bits for HDE_FLAGS */ 243 #define HDE_EXISTENCE 0x01 /* zero if file exists */ 244 #define HDE_DIRECTORY 0x02 /* zero if file is not a directory */ 245 #define HDE_ASSOCIATED 0x04 /* zero if file is not Associated */ 246 #define HDE_RECORD 0x08 /* zero if no record attributes */ 247 #define HDE_PROTECTION 0x10 /* zero if no protection attributes */ 248 #define HDE_UNUSED_FLAGS 0x60 249 #define HDE_LAST_EXTENT 0x80 /* zero if last extent in file */ 250 #define HDE_PROHIBITED (HDE_DIRECTORY | HDE_ASSOCIATED | HDE_RECORD | \ 251 HDE_LAST_EXTENT | HDE_UNUSED_FLAGS) 252 253 /* Directory Record date fields */ 254 #define HDE_DATE_YEAR(x) (((u_char *)x)[0] + 1900) 255 #define HDE_DATE_MONTH(x) (((u_char *)x)[1]) 256 #define HDE_DATE_DAY(x) (((u_char *)x)[2]) 257 #define HDE_DATE_HOUR(x) (((u_char *)x)[3]) 258 #define HDE_DATE_MIN(x) (((u_char *)x)[4]) 259 #define HDE_DATE_SEC(x) (((u_char *)x)[5]) 260 261 /* tests for Interchange Levels 1 & 2 file types */ 262 #define HDE_REGULAR_FILE(x) (((x) & HDE_PROHIBITED) == 0) 263 #define HDE_REGULAR_DIR(x) (((x) & HDE_PROHIBITED) == HDE_DIRECTORY) 264 265 #define HS_DIR_NAMELEN 31 /* max length of a directory name */ 266 #define HS_FILE_NAMELEN 31 /* max length of a filename */ 267 268 #endif /*!_HSFS_SPEC_H_*/ 269