xref: /titanic_50/usr/src/uts/common/sys/fs/hsfs_spec.h (revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968)
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 2006 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	HS_MAXFILEOFF 4294967295U	/* Max file offset (4Gb - 1). */
94 #define	MAXHSOFFSET (HS_SECTOR_SIZE - 1)
95 #define	MAXHSMASK   (~MAXHSOFFSET)
96 
97 /* Standard File Structure Volume Descriptor */
98 
99 enum hs_voldesc_type {
100 	VD_BOOT = 0, VD_SFS = 1, VD_CCFS = 2, VD_UNSPEC = 3, VD_EOV = 255
101 };
102 #define	HSV_ID_STRING	"CDROM"		/* HSV_std_id field */
103 #define	HSV_ID_STRLEN	5		/* HSV_std_id field length */
104 #define	HSV_ID_VER	1		/* HSV_std_ver field */
105 #define	HSV_FILE_STRUCT_ID_VER	1	/* HSV_file_struct_ver field */
106 #define	HSV_SYS_ID_STRLEN	32	/* HSV_sys_id field length */
107 #define	HSV_VOL_ID_STRLEN	32	/* HSV_vol_id field length */
108 #define	HSV_VOL_SET_ID_STRLEN	128	/* HSV_vol_set_id field length */
109 #define	HSV_PUB_ID_STRLEN	128	/* HSV_pub_id field length */
110 #define	HSV_PREP_ID_STRLEN	128	/* HSV_prep_id field length */
111 #define	HSV_APPL_ID_STRLEN	128	/* HSV_appl_id field length */
112 #define	HSV_COPYR_ID_STRLEN	32	/* HSV_copyr_id field length */
113 #define	HSV_ABSTR_ID_STRLEN	32	/* HSV_abstr_id field length */
114 #define	HSV_DATE_LEN		16	/* HSV date filed length */
115 
116 /* macros to get the address of each field */
117 #define	HSV_desc_lbn(x)		(&((uchar_t *)x)[0])
118 #define	HSV_desc_type(x)	(&((uchar_t *)x)[8])
119 #define	HSV_std_id(x)		(&((uchar_t *)x)[9])
120 #define	HSV_std_ver(x)		(&((uchar_t *)x)[14])
121 #define	HSV_sys_id(x)		(&((uchar_t *)x)[16])
122 #define	HSV_vol_id(x)		(&((uchar_t *)x)[48])
123 #define	HSV_vol_size(x)		(&((uchar_t *)x)[88])
124 #define	HSV_set_size(x)		(&((uchar_t *)x)[128])
125 #define	HSV_set_seq(x)		(&((uchar_t *)x)[132])
126 #define	HSV_blk_size(x)		(&((uchar_t *)x)[136])
127 #define	HSV_ptbl_size(x)	(&((uchar_t *)x)[140])
128 #define	HSV_ptbl_man_ls(x)	(&((uchar_t *)x)[148])
129 #define	HSV_ptbl_opt_ls1(x)	(&((uchar_t *)x)[152])
130 #define	HSV_ptbl_opt_ls2(x)	(&((uchar_t *)x)[156])
131 #define	HSV_ptbl_opt_ls3(x)	(&((uchar_t *)x)[160])
132 #define	HSV_ptbl_man_ms(x)	(&((uchar_t *)x)[164])
133 #define	HSV_ptbl_opt_ms1(x)	(&((uchar_t *)x)[168])
134 #define	HSV_ptbl_opt_ms2(x)	(&((uchar_t *)x)[172])
135 #define	HSV_ptbl_opt_ms3(x)	(&((uchar_t *)x)[176])
136 #define	HSV_root_dir(x)		(&((uchar_t *)x)[180])
137 #define	HSV_vol_set_id(x)	(&((uchar_t *)x)[214])
138 #define	HSV_pub_id(x)		(&((uchar_t *)x)[342])
139 #define	HSV_prep_id(x)		(&((uchar_t *)x)[470])
140 #define	HSV_appl_id(x)		(&((uchar_t *)x)[598])
141 #define	HSV_copyr_id(x)		(&((uchar_t *)x)[726])
142 #define	HSV_abstr_id(x)		(&((uchar_t *)x)[758])
143 #define	HSV_cre_date(x)		(&((uchar_t *)x)[790])
144 #define	HSV_mod_date(x)		(&((uchar_t *)x)[806])
145 #define	HSV_exp_date(x)		(&((uchar_t *)x)[822])
146 #define	HSV_eff_date(x)		(&((uchar_t *)x)[838])
147 #define	HSV_file_struct_ver(x)	(&((uchar_t *)x)[854])
148 
149 /* macros to get the values of each field (strings are returned as ptrs) */
150 #define	HSV_DESC_LBN(x)		BOTH_INT(HSV_desc_lbn(x))
151 #define	HSV_DESC_TYPE(x)	((enum hs_voldesc_type)*(HSV_desc_type(x)))
152 #define	HSV_STD_ID(x)		HSV_std_id(x)
153 #define	HSV_STD_VER(x)		*(HSV_std_ver(x))
154 #define	HSV_SYS_ID(x)		HSV_sys_id(x)
155 #define	HSV_VOL_ID(x)		HSV_vol_id(x)
156 #define	HSV_VOL_SIZE(x)		BOTH_INT(HSV_vol_size(x))
157 #define	HSV_SET_SIZE(x)		BOTH_SHORT(HSV_set_size(x))
158 #define	HSV_SET_SEQ(x)		BOTH_SHORT(HSV_set_seq(x))
159 #define	HSV_BLK_SIZE(x)		BOTH_SHORT(HSV_blk_size(x))
160 #define	HSV_PTBL_SIZE(x)	BOTH_INT(HSV_ptbl_size(x))
161 #define	HSV_PTBL_MAN_LS(x)	LSB_INT(HSV_ptbl_man_ls(x))
162 #define	HSV_PTBL_OPT_LS1(x)	LSB_INT(HSV_ptbl_opt_ls1(x))
163 #define	HSV_PTBL_OPT_LS2(x)	LSB_INT(HSV_ptbl_opt_ls2(x))
164 #define	HSV_PTBL_OPT_LS3(x)	LSB_INT(HSV_ptbl_opt_ls3(x))
165 #define	HSV_PTBL_MAN_MS(x)	MSB_INT(HSV_ptbl_man_ms(x))
166 #define	HSV_PTBL_OPT_MS1(x)	MSB_INT(HSV_ptbl_opt_ms1(x))
167 #define	HSV_PTBL_OPT_MS2(x)	MSB_INT(HSV_ptbl_opt_ms2(x))
168 #define	HSV_PTBL_OPT_MS3(x)	MSB_INT(HSV_ptbl_opt_ms3(x))
169 #define	HSV_ROOT_DIR(x)		HSV_root_dir(x)
170 #define	HSV_VOL_SET_ID(x)	HSV_vol_set_id(x)
171 #define	HSV_PUB_ID(x)		HSV_pub_id(x)
172 #define	HSV_PREP_ID(x)		HSV_prep_id(x)
173 #define	HSV_APPL_ID(x)		HSV_appl_id(x)
174 #define	HSV_COPYR_ID(x)		HSV_copyr_id(x)
175 #define	HSV_ABSTR_ID(x)		HSV_abstr_id(x)
176 #define	HSV_CRE_DATE(x)		HSV_cre_date(x)
177 #define	HSV_MOD_DATE(x)		HSV_mod_date(x)
178 #define	HSV_EXP_DATE(x)		HSV_exp_date(x)
179 #define	HSV_EFF_DATE(x)		HSV_eff_date(x)
180 #define	HSV_FILE_STRUCT_VER(x)	*(HSV_file_struct_ver(x))
181 
182 /* Standard File Structure Volume Descriptor date fields */
183 #define	HSV_DATE_2DIG(x)	((((x)[0] - '0') * 10) + \
184 					((x)[1] - '0'))
185 #define	HSV_DATE_4DIG(x)	((((x)[0] - '0') * 1000) + \
186 					(((x)[1] - '0') * 100) + \
187 					(((x)[2] - '0') * 10) +	\
188 						((x)[3] - '0'))
189 #define	HSV_DATE_YEAR(x)	HSV_DATE_4DIG(&((uchar_t *)x)[0])
190 #define	HSV_DATE_MONTH(x)	HSV_DATE_2DIG(&((uchar_t *)x)[4])
191 #define	HSV_DATE_DAY(x)		HSV_DATE_2DIG(&((uchar_t *)x)[6])
192 #define	HSV_DATE_HOUR(x)	HSV_DATE_2DIG(&((uchar_t *)x)[8])
193 #define	HSV_DATE_MIN(x)		HSV_DATE_2DIG(&((uchar_t *)x)[10])
194 #define	HSV_DATE_SEC(x)		HSV_DATE_2DIG(&((uchar_t *)x)[12])
195 #define	HSV_DATE_HSEC(x)	HSV_DATE_2DIG(&((uchar_t *)x)[14])
196 #define	HSV_DATE_GMTOFF(x)	(((char *)x)[16])
197 
198 
199 /* Path table enry */
200 /* fix size of path table entry */
201 #define	HPE_FPESIZE		8
202 /* macros to get the address of each field */
203 #define	HPE_ext_lbn(x)		(&((uchar_t *)x)[0])
204 #define	HPE_xar_len(x)		(&((uchar_t *)x)[4])
205 #define	HPE_name_len(x)		(&((uchar_t *)x)[5])
206 #define	HPE_parent_no(x)	(&((uchar_t *)x)[6])
207 #define	HPE_name(x)		(&((uchar_t *)x)[8])
208 
209 /* macros to get the values of each field */
210 #if defined(__sparc)
211 #define	HPE_EXT_LBN(x)		(MSB_INT(HPE_ext_lbn(x)))
212 #else
213 #define	HPE_EXT_LBN(x)		*(int *)(HPE_ext_lbn(x))
214 #endif
215 #define	HPE_XAR_LEN(x)		*(HPE_xar_len(x))
216 #define	HPE_NAME_LEN(x)		*(HPE_name_len(x))
217 #define	HPE_PARENT_NO(x)	*(short *)(HPE_parent_no(x))
218 #define	HPE_NAME(x)		HPE_name(x)
219 
220 /* root record */
221 #define	HDE_ROOT_DIR_REC_SIZE	34	/* size of root directory record */
222 #define	HDE_FDESIZE		33	/* fixed size for hsfs directory area */
223 #define	HDE_FUSIZE		12	/* fixed size for unix area */
224 					/* max size of a name */
225 #define	HDE_MAX_NAME_LEN	(255 - HDE_FDESIZE - HDE_FUSIZE)
226 
227 /* Directory Entry (Directory Record) */
228 
229 #define	UNIX_TO_HDE_DATE(t, p)	parse_unixdate((t), (p))
230 
231 /* macros to get the address of each field */
232 #define	HDE_dir_len(x)		(&((uchar_t *)x)[0])
233 #define	HDE_xar_len(x)		(&((uchar_t *)x)[1])
234 #define	HDE_ext_lbn(x)		(&((uchar_t *)x)[2])
235 #define	HDE_ext_size(x)		(&((uchar_t *)x)[10])
236 #define	HDE_cdate(x)		(&((uchar_t *)x)[18])
237 #define	HDE_flags(x)		(&((uchar_t *)x)[24])
238 #define	HDE_reserved(x)		(&((uchar_t *)x)[25])
239 #define	HDE_intrlv_size(x)	(&((uchar_t *)x)[26])
240 #define	HDE_intrlv_skip(x)	(&((uchar_t *)x)[27])
241 #define	HDE_vol_set(x)		(&((uchar_t *)x)[28])
242 #define	HDE_name_len(x)		(&((uchar_t *)x)[32])
243 #define	HDE_name(x)		(&((uchar_t *)x)[33])
244 
245 /* **UNIX extension*** */
246 #define	HDE_mode(x)		(&((uchar_t *)x)[0])
247 #define	HDE_uid(x)		(&((uchar_t *)x)[4])
248 #define	HDE_gid(x)		(&((uchar_t *)x)[8])
249 
250 /* macros to get the values of each field (strings are returned as ptrs) */
251 #define	HDE_DIR_LEN(x)		*(HDE_dir_len(x))
252 #define	HDE_XAR_LEN(x)		*(HDE_xar_len(x))
253 #define	HDE_EXT_LBN(x)		BOTH_INT(HDE_ext_lbn(x))
254 #define	HDE_EXT_SIZE(x)		BOTH_INT(HDE_ext_size(x))
255 #define	HDE_CDATE(x)		HDE_cdate(x)
256 #define	HDE_FLAGS(x)		*(HDE_flags(x))
257 #define	HDE_RESERVED(x)		*(HDE_reserved(x))
258 #define	HDE_INTRLV_SIZE(x)	*(HDE_intrlv_size(x))
259 #define	HDE_INTRLV_SKIP(x)	*(HDE_intrlv_skip(x))
260 #define	HDE_VOL_SET(x)		BOTH_SHORT(HDE_vol_set(x))
261 #define	HDE_NAME_LEN(x)		*(HDE_name_len(x))
262 #define	HDE_NAME(x)		HDE_name(x)
263 
264 /* **UNIX EXTENSION**** */
265 #define	HDE_MODE(x)		*(HDE_mode(x))
266 #define	HDE_UID(x)		*(HDE_uid(x))
267 #define	HDE_GID(x)		*(HDE_gid(x))
268 
269 /* mask bits for HDE_FLAGS */
270 #define	HDE_EXISTENCE		0x01	/* zero if file exists */
271 #define	HDE_DIRECTORY		0x02	/* zero if file is not a directory */
272 #define	HDE_ASSOCIATED		0x04	/* zero if file is not Associated */
273 #define	HDE_RECORD		0x08	/* zero if no record attributes */
274 #define	HDE_PROTECTION		0x10	/* zero if no protection attributes */
275 #define	HDE_UNUSED_FLAGS	0x60
276 #define	HDE_LAST_EXTENT		0x80	/* zero if last extent in file */
277 #define	HDE_PROHIBITED	(HDE_DIRECTORY | HDE_RECORD | \
278 				HDE_LAST_EXTENT | HDE_UNUSED_FLAGS)
279 
280 /* Directory Record date fields */
281 #define	HDE_DATE_YEAR(x)	(((uchar_t *)x)[0] + 1900)
282 #define	HDE_DATE_MONTH(x)	(((uchar_t *)x)[1])
283 #define	HDE_DATE_DAY(x)		(((uchar_t *)x)[2])
284 #define	HDE_DATE_HOUR(x)	(((uchar_t *)x)[3])
285 #define	HDE_DATE_MIN(x)		(((uchar_t *)x)[4])
286 #define	HDE_DATE_SEC(x)		(((uchar_t *)x)[5])
287 #define	HDE_DATE_GMTOFF(x)	(((char *)x)[6])
288 
289 
290 /* tests for Interchange Levels 1 & 2 file types */
291 #define	HDE_REGULAR_FILE(x)	(((x) & HDE_PROHIBITED) == 0)
292 #define	HDE_REGULAR_DIR(x)	(((x) & HDE_PROHIBITED) == HDE_DIRECTORY)
293 
294 #define	HS_DIR_NAMELEN		31	/* max length of a directory name */
295 #define	HS_FILE_NAMELEN		31	/* max length of a filename */
296 
297 #ifdef	__cplusplus
298 }
299 #endif
300 
301 #endif	/* _SYS_FS_HSFS_SPEC_H */
302