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