iso.h revision 1.5 1 /* $NetBSD: iso.h,v 1.5 2005/06/22 17:34:30 junyoung Exp $ */
2
3 /*-
4 * Copyright (c) 1994
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley
8 * by Pace Willisson (pace (at) blitz.com). The Rock Ridge Extension
9 * Support code is derived from software contributed to Berkeley
10 * by Atsushi Murai (amurai (at) spec.co.jp).
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)iso.h 8.6 (Berkeley) 5/10/95
37 */
38
39 /*
40 * Definitions describing ISO9660 file system structure, as well as
41 * the functions necessary to access fields of ISO9660 file system
42 * structures.
43 */
44
45 #define ISODCL(from, to) (to - from + 1)
46
47 struct iso_volume_descriptor {
48 char type[ISODCL(1,1)]; /* 711 */
49 char id[ISODCL(2,6)];
50 char version[ISODCL(7,7)];
51 char data[ISODCL(8,2048)];
52 };
53
54 /* volume descriptor types */
55 #define ISO_VD_PRIMARY 1
56 #define ISO_VD_SUPPLEMENTARY 2
57 #define ISO_VD_END 255
58
59 #define ISO_STANDARD_ID "CD001"
60 #define ISO_ECMA_ID "CDW01"
61
62 struct iso_primary_descriptor {
63 char type [ISODCL ( 1, 1)]; /* 711 */
64 char id [ISODCL ( 2, 6)];
65 char version [ISODCL ( 7, 7)]; /* 711 */
66 char unused1 [ISODCL ( 8, 8)];
67 char system_id [ISODCL ( 9, 40)]; /* achars */
68 char volume_id [ISODCL ( 41, 72)]; /* dchars */
69 char unused2 [ISODCL ( 73, 80)];
70 char volume_space_size [ISODCL ( 81, 88)]; /* 733 */
71 char unused3 [ISODCL ( 89, 120)];
72 char volume_set_size [ISODCL (121, 124)]; /* 723 */
73 char volume_sequence_number [ISODCL (125, 128)]; /* 723 */
74 char logical_block_size [ISODCL (129, 132)]; /* 723 */
75 char path_table_size [ISODCL (133, 140)]; /* 733 */
76 char type_l_path_table [ISODCL (141, 144)]; /* 731 */
77 char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */
78 char type_m_path_table [ISODCL (149, 152)]; /* 732 */
79 char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */
80 char root_directory_record [ISODCL (157, 190)]; /* 9.1 */
81 char volume_set_id [ISODCL (191, 318)]; /* dchars */
82 char publisher_id [ISODCL (319, 446)]; /* achars */
83 char preparer_id [ISODCL (447, 574)]; /* achars */
84 char application_id [ISODCL (575, 702)]; /* achars */
85 char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */
86 char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */
87 char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */
88 char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */
89 char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */
90 char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */
91 char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */
92 char file_structure_version [ISODCL (882, 882)]; /* 711 */
93 char unused4 [ISODCL (883, 883)];
94 char application_data [ISODCL (884, 1395)];
95 char unused5 [ISODCL (1396, 2048)];
96 };
97 #define ISO_DEFAULT_BLOCK_SIZE 2048
98
99 struct iso_supplementary_descriptor {
100 char type [ISODCL ( 1, 1)]; /* 711 */
101 char id [ISODCL ( 2, 6)];
102 char version [ISODCL ( 7, 7)]; /* 711 */
103 char flags [ISODCL ( 8, 8)]; /* 711? */
104 char system_id [ISODCL ( 9, 40)]; /* achars */
105 char volume_id [ISODCL ( 41, 72)]; /* dchars */
106 char unused2 [ISODCL ( 73, 80)];
107 char volume_space_size [ISODCL ( 81, 88)]; /* 733 */
108 char escape [ISODCL ( 89, 120)];
109 char volume_set_size [ISODCL (121, 124)]; /* 723 */
110 char volume_sequence_number [ISODCL (125, 128)]; /* 723 */
111 char logical_block_size [ISODCL (129, 132)]; /* 723 */
112 char path_table_size [ISODCL (133, 140)]; /* 733 */
113 char type_l_path_table [ISODCL (141, 144)]; /* 731 */
114 char opt_type_l_path_table [ISODCL (145, 148)]; /* 731 */
115 char type_m_path_table [ISODCL (149, 152)]; /* 732 */
116 char opt_type_m_path_table [ISODCL (153, 156)]; /* 732 */
117 char root_directory_record [ISODCL (157, 190)]; /* 9.1 */
118 char volume_set_id [ISODCL (191, 318)]; /* dchars */
119 char publisher_id [ISODCL (319, 446)]; /* achars */
120 char preparer_id [ISODCL (447, 574)]; /* achars */
121 char application_id [ISODCL (575, 702)]; /* achars */
122 char copyright_file_id [ISODCL (703, 739)]; /* 7.5 dchars */
123 char abstract_file_id [ISODCL (740, 776)]; /* 7.5 dchars */
124 char bibliographic_file_id [ISODCL (777, 813)]; /* 7.5 dchars */
125 char creation_date [ISODCL (814, 830)]; /* 8.4.26.1 */
126 char modification_date [ISODCL (831, 847)]; /* 8.4.26.1 */
127 char expiration_date [ISODCL (848, 864)]; /* 8.4.26.1 */
128 char effective_date [ISODCL (865, 881)]; /* 8.4.26.1 */
129 char file_structure_version [ISODCL (882, 882)]; /* 711 */
130 char unused4 [ISODCL (883, 883)];
131 char application_data [ISODCL (884, 1395)];
132 char unused5 [ISODCL (1396, 2048)];
133 };
134
135 struct iso_directory_record {
136 char length [ISODCL (1, 1)]; /* 711 */
137 char ext_attr_length [ISODCL (2, 2)]; /* 711 */
138 u_char extent [ISODCL (3, 10)]; /* 733 */
139 u_char size [ISODCL (11, 18)]; /* 733 */
140 char date [ISODCL (19, 25)]; /* 7 by 711 */
141 char flags [ISODCL (26, 26)];
142 char file_unit_size [ISODCL (27, 27)]; /* 711 */
143 char interleave [ISODCL (28, 28)]; /* 711 */
144 char volume_sequence_number [ISODCL (29, 32)]; /* 723 */
145 char name_len [ISODCL (33, 33)]; /* 711 */
146 char name [1]; /* XXX */
147 };
148 /* can't take sizeof(iso_directory_record), because of possible alignment
149 of the last entry (34 instead of 33) */
150 #define ISO_DIRECTORY_RECORD_SIZE 33
151
152 struct iso_extended_attributes {
153 u_char owner [ISODCL (1, 4)]; /* 723 */
154 u_char group [ISODCL (5, 8)]; /* 723 */
155 u_char perm [ISODCL (9, 10)]; /* 9.5.3 */
156 char ctime [ISODCL (11, 27)]; /* 8.4.26.1 */
157 char mtime [ISODCL (28, 44)]; /* 8.4.26.1 */
158 char xtime [ISODCL (45, 61)]; /* 8.4.26.1 */
159 char ftime [ISODCL (62, 78)]; /* 8.4.26.1 */
160 char recfmt [ISODCL (79, 79)]; /* 711 */
161 char recattr [ISODCL (80, 80)]; /* 711 */
162 u_char reclen [ISODCL (81, 84)]; /* 723 */
163 char system_id [ISODCL (85, 116)]; /* achars */
164 char system_use [ISODCL (117, 180)];
165 char version [ISODCL (181, 181)]; /* 711 */
166 char len_esc [ISODCL (182, 182)]; /* 711 */
167 char reserved [ISODCL (183, 246)];
168 u_char len_au [ISODCL (247, 250)]; /* 723 */
169 };
170
171 static __inline int isonum_711(u_char *) __attribute__ ((unused));
172 static __inline int isonum_712(char *) __attribute__ ((unused));
173 static __inline uint16_t isonum_721(u_char *) __attribute__ ((unused));
174 static __inline uint16_t isonum_722(u_char *) __attribute__ ((unused));
175 static __inline uint16_t isonum_723(u_char *) __attribute__ ((unused));
176 static __inline uint32_t isonum_731(u_char *) __attribute__ ((unused));
177 static __inline uint32_t isonum_732(u_char *) __attribute__ ((unused));
178 static __inline uint32_t isonum_733(u_char *) __attribute__ ((unused));
179
180 /* 7.1.1: unsigned char */
181 static __inline int
182 isonum_711(u_char *p)
183 {
184 return *p;
185 }
186
187 /* 7.1.2: signed(?) char */
188 static __inline int
189 isonum_712(char *p)
190 {
191 return *p;
192 }
193
194 /* 7.2.1: unsigned little-endian 16-bit value. NOT USED IN KERNEL. */
195 static __inline uint16_t
196 isonum_721(u_char *p)
197 {
198 #if defined(UNALIGNED_ACCESS) && (BYTE_ORDER == LITTLE_ENDIAN)
199 return *(uint16_t *)p;
200 #else
201 return *p|((char)p[1] << 8);
202 #endif
203 }
204
205 /* 7.2.2: unsigned big-endian 16-bit value. NOT USED IN KERNEL. */
206 static __inline uint16_t
207 isonum_722(u_char *p)
208 {
209 #if defined(UNALIGNED_ACCESS) && (BYTE_ORDER == BIG_ENDIAN)
210 return *(uint16_t *)p;
211 #else
212 return ((char)*p << 8)|p[1];
213 #endif
214 }
215
216 /* 7.2.3: unsigned both-endian (little, then big) 16-bit value */
217 static __inline uint16_t
218 isonum_723(u_char *p)
219 {
220 #if defined(UNALIGNED_ACCESS) && \
221 ((BYTE_ORDER == LITTLE_ENDIAN) || (BYTE_ORDER == BIG_ENDIAN))
222 #if BYTE_ORDER == LITTLE_ENDIAN
223 return *(uint16_t *)p;
224 #else
225 return *(uint16_t *)(p + 2);
226 #endif
227 #else /* !UNALIGNED_ACCESS or weird byte order */
228 return *p|(p[1] << 8);
229 #endif
230 }
231
232 /* 7.3.1: unsigned little-endian 32-bit value. NOT USED IN KERNEL. */
233 static __inline uint32_t
234 isonum_731(u_char *p)
235 {
236 #if defined(UNALIGNED_ACCESS) && (BYTE_ORDER == LITTLE_ENDIAN)
237 return *(uint32_t *)p;
238 #else
239 return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24);
240 #endif
241 }
242
243 /* 7.3.2: unsigned big-endian 32-bit value. NOT USED IN KERNEL. */
244 static __inline uint32_t
245 isonum_732(u_char *p)
246 {
247 #if defined(UNALIGNED_ACCESS) && (BYTE_ORDER == BIG_ENDIAN)
248 return *(uint32_t *)p;
249 #else
250 return (*p << 24)|(p[1] << 16)|(p[2] << 8)|p[3];
251 #endif
252 }
253
254 /* 7.3.3: unsigned both-endian (little, then big) 32-bit value */
255 static __inline uint32_t
256 isonum_733(u_char *p)
257 {
258 #if defined(UNALIGNED_ACCESS) && \
259 ((BYTE_ORDER == LITTLE_ENDIAN) || (BYTE_ORDER == BIG_ENDIAN))
260 #if BYTE_ORDER == LITTLE_ENDIAN
261 return *(uint32_t *)p;
262 #else
263 return *(uint32_t *)(p + 4);
264 #endif
265 #else /* !UNALIGNED_ACCESS or weird byte order */
266 return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24);
267 #endif
268 }
269
270 /*
271 * Associated files have a leading '='.
272 */
273 #define ASSOCCHAR '='
274