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