xref: /dragonfly/sys/vfs/udf/ecma167-udf.h (revision c9f721c2)
1 /*-
2  * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD: src/sys/fs/udf/ecma167-udf.h,v 1.4 2002/09/23 18:54:30 alfred Exp $
27  * $DragonFly: src/sys/vfs/udf/ecma167-udf.h,v 1.1 2004/03/12 22:38:15 joerg Exp $
28  */
29 
30 /* ecma167-udf.h */
31 /* Structure/definitions/constants a la ECMA 167 rev. 3 */
32 
33 /* Tag identifiers */
34 enum {
35 	TAGID_PRI_VOL =		1,
36 	TAGID_ANCHOR =		2,
37 	TAGID_VOL = 		3,
38 	TAGID_IMP_VOL =		4,
39 	TAGID_PARTITION =	5,
40 	TAGID_LOGVOL =		6,
41 	TAGID_UNALLOC_SPACE =	7,
42 	TAGID_TERM =		8,
43 	TAGID_LOGVOL_INTEGRITY = 9,
44 	TAGID_FSD =		256,
45 	TAGID_FID =		257,
46 	TAGID_FENTRY =		261
47 };
48 
49 /* Descriptor tag [3/7.2] */
50 struct desc_tag {
51 	uint16_t	id;
52 	uint16_t	descriptor_ver;
53 	uint8_t		cksum;
54 	uint8_t		reserved;
55 	uint16_t	serial_num;
56 	uint16_t	desc_crc;
57 	uint16_t	desc_crc_len;
58 	uint32_t	tag_loc;
59 } __packed;
60 
61 /* Recorded Address [4/7.1] */
62 struct lb_addr {
63 	uint32_t	lb_num;
64 	uint16_t	part_num;
65 } __packed;
66 
67 /* Extent Descriptor [3/7.1] */
68 struct extent_ad {
69 	uint32_t	len;
70 	uint32_t	loc;
71 } __packed;
72 
73 /* Short Allocation Descriptor [4/14.14.1] */
74 struct short_ad {
75 	uint32_t	len;
76 	uint32_t	pos;
77 } __packed;
78 
79 /* Long Allocation Descriptor [4/14.14.2] */
80 struct long_ad {
81 	uint32_t	len;
82 	struct lb_addr	loc;
83 	uint16_t	ad_flags;
84 	uint32_t	ad_id;
85 } __packed;
86 
87 /* Extended Allocation Descriptor [4/14.14.3] */
88 struct ext_ad {
89 	uint32_t	ex_len;
90 	uint32_t	rec_len;
91 	uint32_t	inf_len;
92 	struct lb_addr	ex_loc;
93 	uint8_t		reserved[2];
94 } __packed;
95 
96 union icb {
97 	struct short_ad	s_ad;
98 	struct long_ad	l_ad;
99 	struct ext_ad	e_ad;
100 };
101 
102 /* Character set spec [1/7.2.1] */
103 struct charspec {
104 	uint8_t		type;
105 	uint8_t		inf[63];
106 } __packed;
107 
108 /* Timestamp [1/7.3] */
109 struct timestamp {
110 	uint16_t	type_tz;
111 	uint16_t	year;
112 	uint8_t		month;
113 	uint8_t		day;
114 	uint8_t		hour;
115 	uint8_t		minute;
116 	uint8_t		second;
117 	uint8_t		centisec;
118 	uint8_t		hund_usec;
119 	uint8_t		usec;
120 } __packed;
121 
122 /* Entity Identifier [1/7.4] */
123 #define	UDF_REGID_ID_SIZE	23
124 struct regid {
125 	uint8_t		flags;
126 	uint8_t		id[UDF_REGID_ID_SIZE];
127 	uint8_t		id_suffix[8];
128 } __packed;
129 
130 /* ICB Tag [4/14.6] */
131 struct icb_tag {
132 	uint32_t	prev_num_dirs;
133 	uint16_t	strat_type;
134 	uint8_t		strat_param[2];
135 	uint16_t	max_num_entries;
136 	uint8_t		reserved;
137 	uint8_t		file_type;
138 	struct lb_addr	parent_icb;
139 	uint16_t	flags;
140 } __packed;
141 #define	UDF_ICB_TAG_FLAGS_SETUID	0x40
142 #define	UDF_ICB_TAG_FLAGS_SETGID	0x80
143 #define	UDF_ICB_TAG_FLAGS_STICKY	0x100
144 
145 /* Anchor Volume Descriptor Pointer [3/10.2] */
146 struct anchor_vdp {
147 	struct desc_tag		tag;
148 	struct extent_ad	main_vds_ex;
149 	struct extent_ad	reserve_vds_ex;
150 } __packed;
151 
152 /* Volume Descriptor Pointer [3/10.3] */
153 struct vol_desc_ptr {
154 	struct desc_tag		tag;
155 	uint32_t		vds_number;
156 	struct extent_ad	next_vds_ex;
157 } __packed;
158 
159 /* Primary Volume Descriptor [3/10.1] */
160 struct pri_vol_desc {
161 	struct desc_tag		tag;
162 	uint32_t		seq_num;
163 	uint32_t		pdv_num;
164 	char			vol_id[32];
165 	uint16_t		vds_num;
166 	uint16_t		max_vol_seq;
167 	uint16_t		ichg_lvl;
168 	uint16_t		max_ichg_lvl;
169 	uint32_t		charset_list;
170 	uint32_t		max_charset_list;
171 	char			volset_id[128];
172 	struct charspec		desc_charset;
173 	struct charspec		explanatory_charset;
174 	struct extent_ad	vol_abstract;
175 	struct extent_ad	vol_copyright;
176 	struct regid		app_id;
177 	struct timestamp	time;
178 	struct regid		imp_id;
179 	uint8_t			imp_use[64];
180 	uint32_t		prev_vds_lov;
181 	uint16_t		flags;
182 	uint8_t			reserved[22];
183 } __packed;
184 
185 /* Logical Volume Descriptor [3/10.6] */
186 struct logvol_desc {
187 	struct desc_tag		tag;
188 	uint32_t		seq_num;
189 	struct charspec		desc_charset;
190 	char			logvol_id[128];
191 	uint32_t		lb_size;
192 	struct regid		domain_id;
193 	union {
194 		struct long_ad	fsd_loc;
195 		uint8_t		logvol_content_use[16];
196 	} _lvd_use;
197 	uint32_t		mt_l; /* Partition map length */
198 	uint32_t		n_pm; /* Number of partition maps */
199 	struct regid		imp_id;
200 	uint8_t			imp_use[128];
201 	struct extent_ad	integrity_seq_id;
202 	uint8_t			maps[1];
203 } __packed;
204 
205 #define	UDF_PMAP_SIZE	64
206 
207 /* Type 1 Partition Map [3/10.7.2] */
208 struct part_map_1 {
209 	uint8_t			type;
210 	uint8_t			len;
211 	uint16_t		vol_seq_num;
212 	uint16_t		part_num;
213 } __packed;
214 
215 /* Type 2 Partition Map [3/10.7.3] */
216 struct part_map_2 {
217 	uint8_t			type;
218 	uint8_t			len;
219 	uint8_t			part_id[62];
220 } __packed;
221 
222 /* Virtual Partition Map [UDF 2.01/2.2.8] */
223 struct part_map_virt {
224 	uint8_t			type;
225 	uint8_t			len;
226 	uint8_t			reserved[2];
227 	struct regid		id;
228 	uint16_t		vol_seq_num;
229 	uint16_t		part_num;
230 	uint8_t			reserved1[24];
231 } __packed;
232 
233 /* Sparable Partition Map [UDF 2.01/2.2.9] */
234 struct part_map_spare {
235 	uint8_t			type;
236 	uint8_t			len;
237 	uint8_t			reserved[2];
238 	struct regid		id;
239 	uint16_t		vol_seq_num;
240 	uint16_t		part_num;
241 	uint16_t		packet_len;
242 	uint8_t			n_st;	/* Number of Sparing Tables */
243 	uint8_t			reserved1;
244 	uint32_t		st_size;
245 	uint32_t		st_loc[1];
246 } __packed;
247 
248 union udf_pmap {
249 	uint8_t			data[UDF_PMAP_SIZE];
250 	struct part_map_1	pm1;
251 	struct part_map_2	pm2;
252 	struct part_map_virt	pmv;
253 	struct part_map_spare	pms;
254 };
255 
256 /* Sparing Map Entry [UDF 2.01/2.2.11] */
257 struct spare_map_entry {
258 	uint32_t		org;
259 	uint32_t		map;
260 } __packed;
261 
262 /* Sparing Table [UDF 2.01/2.2.11] */
263 struct udf_sparing_table {
264 	struct desc_tag		tag;
265 	struct regid		id;
266 	uint16_t		rt_l;	/* Relocation Table len */
267 	uint8_t			reserved[2];
268 	uint32_t		seq_num;
269 	struct spare_map_entry	entries[1];
270 } __packed;
271 
272 /* Partition Descriptor [3/10.5] */
273 struct part_desc {
274 	struct desc_tag	tag;
275 	uint32_t	seq_num;
276 	uint16_t	flags;
277 	uint16_t	part_num;
278 	struct regid	contents;
279 	uint8_t		contents_use[128];
280 	uint32_t	access_type;
281 	uint32_t	start_loc;
282 	uint32_t	part_len;
283 	struct regid	imp_id;
284 	uint8_t		imp_use[128];
285 	uint8_t		reserved[156];
286 } __packed;
287 
288 /* File Set Descriptor [4/14.1] */
289 struct fileset_desc {
290 	struct desc_tag		tag;
291 	struct timestamp	time;
292 	uint16_t		ichg_lvl;
293 	uint16_t		max_ichg_lvl;
294 	uint32_t		charset_list;
295 	uint32_t		max_charset_list;
296 	uint32_t		fileset_num;
297 	uint32_t		fileset_desc_num;
298 	struct charspec		logvol_id_charset;
299 	char			logvol_id[128];
300 	struct charspec		fileset_charset;
301 	char			fileset_id[32];
302 	char			copyright_file_id[32];
303 	char			abstract_file_id[32];
304 	struct long_ad		rootdir_icb;
305 	struct regid		domain_id;
306 	struct long_ad		next_ex;
307 	struct long_ad		streamdir_icb;
308 	uint8_t			reserved[32];
309 } __packed;
310 
311 /* File Identifier Descriptor [4/14.4] */
312 struct fileid_desc {
313 	struct desc_tag	tag;
314 	uint16_t	file_num;
315 	uint8_t		file_char;
316 	uint8_t		l_fi;	/* Length of file identifier area */
317 	struct long_ad	icb;
318 	uint16_t	l_iu;	/* Length of implementaion use area */
319 	uint8_t		data[1];
320 } __packed;
321 #define	UDF_FID_SIZE	38
322 #define	UDF_FILE_CHAR_VIS	(1 << 0) /* Visible */
323 #define	UDF_FILE_CHAR_DIR	(1 << 1) /* Directory */
324 #define	UDF_FILE_CHAR_DEL	(1 << 2) /* Deleted */
325 #define	UDF_FILE_CHAR_PAR	(1 << 3) /* Parent Directory */
326 #define	UDF_FILE_CHAR_META	(1 << 4) /* Stream metadata */
327 
328 /* File Entry [4/14.9] */
329 struct file_entry {
330 	struct desc_tag		tag;
331 	struct icb_tag		icbtag;
332 	uint32_t		uid;
333 	uint32_t		gid;
334 	uint32_t		perm;
335 	uint16_t		link_cnt;
336 	uint8_t			rec_format;
337 	uint8_t			rec_disp_attr;
338 	uint32_t		rec_len;
339 	uint64_t		inf_len;
340 	uint64_t		logblks_rec;
341 	struct timestamp	atime;
342 	struct timestamp	mtime;
343 	struct timestamp	attrtime;
344 	uint32_t		ckpoint;
345 	struct long_ad		ex_attr_icb;
346 	struct regid		imp_id;
347 	uint64_t		unique_id;
348 	uint32_t		l_ea;	/* Length of extended attribute area */
349 	uint32_t		l_ad;	/* Length of allocation descriptors */
350 	uint8_t			data[1];
351 } __packed;
352 #define	UDF_FENTRY_SIZE	176
353 #define	UDF_FENTRY_PERM_USER_MASK	0x07
354 #define	UDF_FENTRY_PERM_GRP_MASK	0xE0
355 #define	UDF_FENTRY_PERM_OWNER_MASK	0x1C00
356 
357 union dscrptr {
358 	struct desc_tag		tag;
359 	struct anchor_vdp	avdp;
360 	struct vol_desc_ptr	vdp;
361 	struct pri_vol_desc	pvd;
362 	struct logvol_desc	lvd;
363 	struct part_desc	pd;
364 	struct fileset_desc	fsd;
365 	struct fileid_desc	fid;
366 	struct file_entry	fe;
367 };
368 
369 /* Useful defines */
370 
371 #define	GETICB(ad_type, fentry, offset)	\
372 	(struct ad_type *)&fentry->data[offset]
373 
374 #define	GETICBLEN(ad_type, icb)	((struct ad_type *)(icb))->len
375