xref: /illumos-gate/usr/src/uts/common/sys/fs/hsfs_isospec.h (revision 0a44ef6d9afbfe052a7e975f55ea0d2954b62a82)
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 #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 ISO-9660:1988 */
95 #define	ISO_ID_VER2	2		/* ISO_std_ver field ISO-9660:1999 */
96 #define	ISO_FILE_STRUCT_ID_VER	1	/* ISO_file structure version  field */
97 #define	ISO_SYS_ID_STRLEN	32
98 #define	ISO_VOL_ID_STRLEN	32
99 #define	ISO_VOL_SET_ID_STRLEN	128
100 #define	ISO_PUB_ID_STRLEN	128
101 #define	ISO_PREP_ID_STRLEN	128
102 #define	ISO_APPL_ID_STRLEN	128
103 #define	ISO_COPYR_ID_STRLEN	37
104 #define	ISO_ABSTR_ID_STRLEN	37
105 #define	ISO_SHORT_DATE_LEN	7
106 #define	ISO_DATE_LEN		17
107 
108 
109 
110 /* macros to get the address of each field */
111 #define	ISO_desc_type(x)	(&((uchar_t *)x)[0])
112 #define	ISO_std_id(x)		(&((uchar_t *)x)[1])
113 #define	ISO_std_ver(x)		(&((uchar_t *)x)[6])
114 #define	ISO_sys_id(x)		(&((uchar_t *)x)[8])
115 #define	ISO_vol_id(x)		(&((uchar_t *)x)[40])
116 #define	ISO_vol_size(x)		(&((uchar_t *)x)[80])
117 #define	ISO_svd_esc(x)		(&((uchar_t *)x)[88])	/* Supplemental VD */
118 #define	ISO_set_size(x)		(&((uchar_t *)x)[120])
119 #define	ISO_set_seq(x)		(&((uchar_t *)x)[124])
120 #define	ISO_blk_size(x)		(&((uchar_t *)x)[128])
121 #define	ISO_ptbl_size(x)	(&((uchar_t *)x)[132])
122 #define	ISO_ptbl_man_ls(x)	(&((uchar_t *)x)[140])
123 #define	ISO_ptbl_opt_ls1(x)	(&((uchar_t *)x)[144])
124 #define	ISO_ptbl_man_ms(x)	(&((uchar_t *)x)[148])
125 #define	ISO_ptbl_opt_ms1(x)	(&((uchar_t *)x)[152])
126 #define	ISO_root_dir(x)		(&((uchar_t *)x)[156])
127 #define	ISO_vol_set_id(x)	(&((uchar_t *)x)[190])
128 #define	ISO_pub_id(x)		(&((uchar_t *)x)[318])
129 #define	ISO_prep_id(x)		(&((uchar_t *)x)[446])
130 #define	ISO_appl_id(x)		(&((uchar_t *)x)[574])
131 #define	ISO_copyr_id(x)		(&((uchar_t *)x)[702])
132 #define	ISO_abstr_id(x)		(&((uchar_t *)x)[739])
133 #define	ISO_bibli_id(x)		(&((uchar_t *)x)[776])
134 #define	ISO_cre_date(x)		(&((uchar_t *)x)[813])
135 #define	ISO_mod_date(x)		(&((uchar_t *)x)[830])
136 #define	ISO_exp_date(x)		(&((uchar_t *)x)[847])
137 #define	ISO_eff_date(x)		(&((uchar_t *)x)[864])
138 #define	ISO_file_struct_ver(x)	(&((uchar_t *)x)[881])
139 
140 /* macros to get the values of each field (strings are returned as ptrs) */
141 #define	ISO_DESC_TYPE(x)	((enum hs_voldesc_type)*(ISO_desc_type(x)))
142 #define	ISO_STD_ID(x)		ISO_std_id(x)
143 #define	ISO_STD_VER(x)		*(ISO_std_ver(x))
144 #define	ISO_SYS_ID(x)		ISO_sys_id(x)
145 #define	ISO_VOL_ID(x)		ISO_vol_id(x)
146 #define	ISO_VOL_SIZE(x)		BOTH_INT(ISO_vol_size(x))
147 #define	ISO_SET_SIZE(x)		BOTH_SHORT(ISO_set_size(x))
148 #define	ISO_SET_SEQ(x)		BOTH_SHORT(ISO_set_seq(x))
149 #define	ISO_BLK_SIZE(x)		BOTH_SHORT(ISO_blk_size(x))
150 #define	ISO_PTBL_SIZE(x)	BOTH_INT(ISO_ptbl_size(x))
151 #define	ISO_PTBL_MAN_LS(x)	LSB_INT(ISO_ptbl_man_ls(x))
152 #define	ISO_PTBL_OPT_LS1(x)	LSB_INT(ISO_ptbl_opt_ls1(x))
153 #define	ISO_PTBL_MAN_MS(x)	MSB_INT(ISO_ptbl_man_ms(x))
154 #define	ISO_PTBL_OPT_MS1(x)	MSB_INT(ISO_ptbl_opt_ms1(x))
155 #define	ISO_ROOT_DIR(x)		ISO_root_dir(x)
156 #define	ISO_VOL_SET_ID(x)	ISO_vol_set_id(x)
157 #define	ISO_PUB_ID(x)		ISO_pub_id(x)
158 #define	ISO_PREP_ID(x)		ISO_prep_id(x)
159 #define	ISO_APPL_ID(x)		ISO_appl_id(x)
160 #define	ISO_COPYR_ID(x)		ISO_copyr_id(x)
161 #define	ISO_ABSTR_ID(x)		ISO_abstr_id(x)
162 #define	ISO_BIBLI_ID(x)		ISO_bibli_id(x)
163 #define	ISO_CRE_DATE(x)		HSV_cre_date(x)
164 #define	ISO_MOD_DATE(x)		HSV_mod_date(x)
165 #define	ISO_EXP_DATE(x)		HSV_exp_date(x)
166 #define	ISO_EFF_DATE(x)		HSV_eff_date(x)
167 #define	ISO_FILE_STRUCT_VER(x)	*(ISO_file_struct_ver(x))
168 
169 /* Standard File Structure Volume Descriptor date fields */
170 #define	ISO_DATE_2DIG(x)	((((x)[0] - '0') * 10) +		\
171 					((x)[1] - '0'))
172 #define	ISO_DATE_4DIG(x)	((((x)[0] - '0') * 1000) +		\
173 					(((x)[1] - '0') * 100) +	\
174 					(((x)[2] - '0') * 10) +		\
175 					((x)[3] - '0'))
176 #define	ISO_DATE_YEAR(x)	ISO_DATE_4DIG(&((uchar_t *)x)[0])
177 #define	ISO_DATE_MONTH(x)	ISO_DATE_2DIG(&((uchar_t *)x)[4])
178 #define	ISO_DATE_DAY(x)		ISO_DATE_2DIG(&((uchar_t *)x)[6])
179 #define	ISO_DATE_HOUR(x)	ISO_DATE_2DIG(&((uchar_t *)x)[8])
180 #define	ISO_DATE_MIN(x)		ISO_DATE_2DIG(&((uchar_t *)x)[10])
181 #define	ISO_DATE_SEC(x)		ISO_DATE_2DIG(&((uchar_t *)x)[12])
182 #define	ISO_DATE_HSEC(x)	ISO_DATE_2DIG(&((uchar_t *)x)[14])
183 #define	ISO_DATE_GMTOFF(x)	(((char *)x)[16])
184 
185 
186 
187 /* Directory Entry (Directory Record) */
188 #define	IDE_ROOT_DIR_REC_SIZE	34	/* size of root directory record */
189 #define	IDE_FDESIZE		33	/* fixed size for hsfs directory area */
190 					/* max size of a name */
191 #define	IDE_MAX_NAME_LEN	(255 - IDE_FDESIZE)
192 
193 
194 /* macros to get the address of each field */
195 #define	IDE_dir_len(x)		(&((uchar_t *)x)[0])
196 #define	IDE_xar_len(x)		(&((uchar_t *)x)[1])
197 #define	IDE_ext_lbn(x)		(&((uchar_t *)x)[2])
198 #define	IDE_ext_size(x)		(&((uchar_t *)x)[10])
199 #define	IDE_cdate(x)		(&((uchar_t *)x)[18])
200 #define	IDE_flags(x)		(&((uchar_t *)x)[25])
201 #define	IDE_intrlv_size(x)	(&((uchar_t *)x)[26])
202 #define	IDE_intrlv_skip(x)	(&((uchar_t *)x)[27])
203 #define	IDE_vol_set(x)		(&((uchar_t *)x)[28])
204 #define	IDE_name_len(x)		(&((uchar_t *)x)[32])
205 #define	IDE_name(x)		(&((uchar_t *)x)[33])
206 #define	IDE_sys_use_area(x)	(&((uchar_t *)x)[IDE_NAME_LEN(x) + \
207 				IDE_PAD_LEN(x)] + IDE_FDESIZE)
208 
209 /* macros to get the values of each field (strings are returned as ptrs) */
210 #define	IDE_DIR_LEN(x)		*(IDE_dir_len(x))
211 #define	IDE_XAR_LEN(x)		*(IDE_xar_len(x))
212 #define	IDE_EXT_LBN(x)		BOTH_INT(IDE_ext_lbn(x))
213 #define	IDE_EXT_SIZE(x)		BOTH_INT(IDE_ext_size(x))
214 #define	IDE_CDATE(x)		IDE_cdate(x)
215 #define	IDE_FLAGS(x)		*(IDE_flags(x))
216 #define	IDE_INTRLV_SIZE(x)	*(IDE_intrlv_size(x))
217 #define	IDE_INTRLV_SKIP(x)	*(IDE_intrlv_skip(x))
218 #define	IDE_VOL_SET(x)		BOTH_SHORT(IDE_vol_set(x))
219 #define	IDE_NAME_LEN(x)		*(IDE_name_len(x))
220 #define	IDE_NAME(x)		IDE_name(x)
221 #define	IDE_PAD_LEN(x)		((IDE_NAME_LEN(x) % 2) ? 0 : 1)
222 #define	IDE_SUA_LEN(x)		((int)(IDE_DIR_LEN(x)) - (int)(IDE_FDESIZE) - \
223 				(int)(IDE_NAME_LEN(x)) - (int)(IDE_PAD_LEN(x)))
224 
225 /* mask bits for IDE_FLAGS */
226 #define	IDE_EXISTENCE		0x01	/* zero if file exists */
227 #define	IDE_DIRECTORY		0x02	/* zero if file is not a directory */
228 #define	IDE_ASSOCIATED		0x04	/* zero if file is not Associated */
229 #define	IDE_RECORD		0x08	/* zero if no record attributes */
230 #define	IDE_PROTECTION		0x10	/* zero if no protection attributes */
231 #define	IDE_UNUSED_FLAGS	0x60
232 #define	IDE_LAST_EXTENT		0x80	/* zero if last extent in file */
233 #define	IDE_PROHIBITED	(IDE_DIRECTORY | IDE_RECORD | \
234 				IDE_LAST_EXTENT | IDE_UNUSED_FLAGS)
235 
236 /* Directory Record date fields */
237 #define	IDE_DATE_YEAR(x)	(((uchar_t *)x)[0] + 1900)
238 #define	IDE_DATE_MONTH(x)	(((uchar_t *)x)[1])
239 #define	IDE_DATE_DAY(x)		(((uchar_t *)x)[2])
240 #define	IDE_DATE_HOUR(x)	(((uchar_t *)x)[3])
241 #define	IDE_DATE_MIN(x)		(((uchar_t *)x)[4])
242 #define	IDE_DATE_SEC(x)		(((uchar_t *)x)[5])
243 #define	IDE_DATE_GMTOFF(x)	(((char *)x)[6])
244 
245 /* tests for Interchange Levels 1 & 2 file types */
246 #define	IDE_REGULAR_FILE(x)	(((x) & IDE_PROHIBITED) == 0)
247 #define	IDE_REGULAR_DIR(x)	(((x) & IDE_PROHIBITED) == IDE_DIRECTORY)
248 
249 /*
250  * A ISO filename is: "ABCDE.EEE;1" -> <filename> '.' <ext> ';' <version #>
251  *
252  * The ISO-9660:1988 (Version 1) maximum needed string length is:
253  *	30 chars (filename + ext)
254  * +	 2 chars ('.' + ';')
255  * +	   strlen("32767")
256  * +	   null byte
257  * ================================
258  * =	38 chars
259  *
260  * ISO_DIR_NAMELEN counts 30 chars + '.'
261  */
262 #define	ISO_DIR_NAMELEN		31	/* max length of a directory name */
263 #define	ISO_FILE_NAMELEN	31	/* max length of a filename, */
264 					/* excluding ";" and version num */
265 #define	ISO_NAMELEN_V2		207	/* ISOv2: 254 - 33 - 14 (XA Record) */
266 #define	ISO_NAMELEN_V2_MAX	221	/* max length, ignorig ISOv2 */
267 #define	JOLIET_NAMELEN		64	/* Joliet file name length (spec) */
268 #define	JOLIET_NAMELEN_MAX	110	/* max Joliet file name length  */
269 
270 /* Path table enry */
271 /* fix size of path table entry */
272 #define	IPE_FPESIZE		8
273 /* macros to get the address of each field */
274 #define	IPE_name_len(x)		(&((uchar_t *)x)[0])
275 #define	IPE_xar_len(x)		(&((uchar_t *)x)[1])
276 #define	IPE_ext_lbn(x)		(&((uchar_t *)x)[2])
277 #define	IPE_parent_no(x)	(&((uchar_t *)x)[6])
278 #define	IPE_name(x)		(&((uchar_t *)x)[8])
279 
280 /* macros to get the values of each field */
281 #define	IPE_EXT_LBN(x)		(MSB_INT(IPE_ext_lbn(x)))
282 #define	IPE_XAR_LEN(x)		*(IPE_xar_len(x))
283 #define	IPE_NAME_LEN(x)		*(IPE_name_len(x))
284 #define	IPE_PARENT_NO(x)	*(short *)(IPE_parent_no(x))
285 #define	IPE_NAME(x)		IPE_name(x)
286 
287 #ifdef	__cplusplus
288 }
289 #endif
290 
291 #endif	/* _SYS_FS_HSFS_ISOSPEC_H */
292