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