1 /* $NetBSD: ecma167-udf.h,v 1.14 2011/07/07 17:45:38 reinoud Exp $ */
4 * Copyright (c) 2003, 2004, 2005, 2006, 2008, 2009
5 * Reinoud Zandijk * <reinoud@NetBSD.org>
6 * Copyright (c) 2001, 2002 Scott Long <scottl@freebsd.org>
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Extended and adapted for UDFv2.50+ bij Reinoud Zandijk based on the
32 * original by Scott Long.
34 * 20030508 Made some small typo and explanatory comments
35 * 20030510 Added UDF 2.01 structures
36 * 20030519 Added/correct comments on multi-partitioned logical volume space
37 * 20050616 Added pseudo overwrite
38 * 20050624 Added the missing extended attribute types and `magic values'.
39 * 20051106 Reworked some implementation use parts
44 #ifndef _FS_UDF_ECMA167_UDF_H_
45 #define _FS_UDF_ECMA167_UDF_H_
49 * in case of an older gcc versions, define the __packed as explicit
54 * You may specify the `aligned' and `transparent_union' attributes either in
55 * a `typedef' declaration or just past the closing curly brace of a complete
56 * enum, struct or union type _definition_ and the `packed' attribute only
57 * past the closing brace of a definition. You may also specify attributes
58 * between the enum, struct or union tag and the name of the type rather than
59 * after the closing brace.
63 #define __packed __attribute__((packed))
69 /* Volume recognition sequence ECMA 167 rev. 3 16.1 */
72 uint8_t identifier
[5];
78 #define VRS_NSR02 "NSR02"
79 #define VRS_NSR03 "NSR03"
80 #define VRS_BEA01 "BEA01"
81 #define VRS_TEA01 "TEA01"
82 #define VRS_CD001 "CD001"
83 #define VRS_CDW02 "CDW02"
86 /* Structure/definitions/constants a la ECMA 167 rev. 3 */
89 #define MAX_TAGID_VOLUMES 9
92 TAGID_SPARING_TABLE
= 0,
99 TAGID_UNALLOC_SPACE
= 7,
101 TAGID_LOGVOL_INTEGRITY
= 9,
104 TAGID_ALLOCEXTENT
= 258,
105 TAGID_INDIRECTENTRY
= 259,
106 TAGID_ICB_TERM
= 260,
108 TAGID_EXTATTR_HDR
= 262,
109 TAGID_UNALL_SP_ENTRY
= 263,
110 TAGID_SPACE_BITMAP
= 264,
111 TAGID_PART_INTEGRITY
= 265,
112 TAGID_EXTFENTRY
= 266,
118 UDF_DOMAIN_FLAG_HARD_WRITE_PROTECT
= 1,
119 UDF_DOMAIN_FLAG_SOFT_WRITE_PROTECT
= 2
124 UDF_ACCESSTYPE_NOT_SPECIFIED
= 0, /* unknown */
125 UDF_ACCESSTYPE_PSEUDO_OVERWITE
= 0, /* pseudo overwritable, e.g. BD-R's LOW */
126 UDF_ACCESSTYPE_READ_ONLY
= 1, /* really only readable */
127 UDF_ACCESSTYPE_WRITE_ONCE
= 2, /* write once and you're done */
128 UDF_ACCESSTYPE_REWRITEABLE
= 3, /* may need extra work to rewrite */
129 UDF_ACCESSTYPE_OVERWRITABLE
= 4 /* no limits on rewriting; e.g. harddisc*/
133 /* Descriptor tag [3/7.2] */
136 uint16_t descriptor_ver
;
141 uint16_t desc_crc_len
;
144 #define UDF_DESC_TAG_LENGTH 16
147 /* Recorded Address [4/7.1] */
148 struct lb_addr
{ /* within partition space */
154 /* Extent Descriptor [3/7.1] */
161 /* Short Allocation Descriptor [4/14.14.1] */
168 /* Long Allocation Descriptor [4/14.14.2] */
169 struct UDF_ADImp_use
{
173 #define UDF_ADIMP_FLAGS_EXTENT_ERASED 1
178 struct lb_addr loc
; /* within a logical volume mapped partition space !! */
181 struct UDF_ADImp_use im_used
;
184 #define longad_uniqueid impl.im_used.unique_id
187 /* Extended Allocation Descriptor [4/14.14.3] ; identifies an extent of allocation descriptors ; also in UDF ? */
192 struct lb_addr ex_loc
;
197 /* ICB : Information Control Block; positioning */
199 struct short_ad s_ad
;
205 /* short/long/ext extent have flags encoded in length */
206 #define UDF_EXT_ALLOCATED (0<<30)
207 #define UDF_EXT_FREED (1<<30)
208 #define UDF_EXT_ALLOCATED_BUT_NOT_USED (1<<30)
209 #define UDF_EXT_FREE (2<<30)
210 #define UDF_EXT_REDIRECT (3<<30)
211 #define UDF_EXT_FLAGS(len) ((len) & (3<<30))
212 #define UDF_EXT_LEN(len) ((len) & ((1<<30)-1))
213 #define UDF_EXT_MAXLEN ((1<<30)-1)
216 /* Character set spec [1/7.2.1] */
226 uint16_t comp_filever
;
229 #define UDF_PATH_COMP_SIZE 4
230 #define UDF_PATH_COMP_RESERVED 0
231 #define UDF_PATH_COMP_ROOT 1
232 #define UDF_PATH_COMP_MOUNTROOT 2
233 #define UDF_PATH_COMP_PARENTDIR 3
234 #define UDF_PATH_COMP_CURDIR 4
235 #define UDF_PATH_COMP_NAME 5
238 /* Timestamp [1/7.3] */
251 #define UDF_TIMESTAMP_SIZE 12
254 /* Entity Identifier [1/7.4] */
255 #define UDF_REGID_ID_SIZE 23
258 uint8_t id
[UDF_REGID_ID_SIZE
];
259 uint8_t id_suffix
[8];
263 /* ICB Tag [4/14.6] */
265 uint32_t prev_num_dirs
;
267 uint8_t strat_param
[2];
268 uint16_t max_num_entries
;
271 struct lb_addr parent_icb
;
274 #define UDF_ICB_TAG_FLAGS_ALLOC_MASK 0x03
275 #define UDF_ICB_SHORT_ALLOC 0x00
276 #define UDF_ICB_LONG_ALLOC 0x01
277 #define UDF_ICB_EXT_ALLOC 0x02
278 #define UDF_ICB_INTERN_ALLOC 0x03
280 #define UDF_ICB_TAG_FLAGS_DIRORDERED (1<< 3)
281 #define UDF_ICB_TAG_FLAGS_NONRELOC (1<< 4)
282 #define UDF_ICB_TAG_FLAGS_CONTIGUES (1<< 9)
283 #define UDF_ICB_TAG_FLAGS_MULTIPLEVERS (1<<12)
285 #define UDF_ICB_TAG_FLAGS_SETUID (1<< 6)
286 #define UDF_ICB_TAG_FLAGS_SETGID (1<< 7)
287 #define UDF_ICB_TAG_FLAGS_STICKY (1<< 8)
289 #define UDF_ICB_FILETYPE_UNKNOWN 0
290 #define UDF_ICB_FILETYPE_UNALLOCSPACE 1
291 #define UDF_ICB_FILETYPE_PARTINTEGRITY 2
292 #define UDF_ICB_FILETYPE_INDIRECTENTRY 3
293 #define UDF_ICB_FILETYPE_DIRECTORY 4
294 #define UDF_ICB_FILETYPE_RANDOMACCESS 5
295 #define UDF_ICB_FILETYPE_BLOCKDEVICE 6
296 #define UDF_ICB_FILETYPE_CHARDEVICE 7
297 #define UDF_ICB_FILETYPE_EXTATTRREC 8
298 #define UDF_ICB_FILETYPE_FIFO 9
299 #define UDF_ICB_FILETYPE_SOCKET 10
300 #define UDF_ICB_FILETYPE_TERM 11
301 #define UDF_ICB_FILETYPE_SYMLINK 12
302 #define UDF_ICB_FILETYPE_STREAMDIR 13
303 #define UDF_ICB_FILETYPE_VAT 248
304 #define UDF_ICB_FILETYPE_REALTIME 249
305 #define UDF_ICB_FILETYPE_META_MAIN 250
306 #define UDF_ICB_FILETYPE_META_MIRROR 251
307 #define UDF_ICB_FILETYPE_META_BITMAP 252
310 /* Anchor Volume Descriptor Pointer [3/10.2] */
313 struct extent_ad main_vds_ex
; /* to main volume descriptor set ; 16 sectors min */
314 struct extent_ad reserve_vds_ex
; /* copy of main volume descriptor set ; 16 sectors min */
318 /* Volume Descriptor Pointer [3/10.3] */
319 struct vol_desc_ptr
{
320 struct desc_tag tag
; /* use for extending the volume descriptor space */
322 struct extent_ad next_vds_ex
; /* points to the next block for volume descriptor space */
326 /* Primary Volume Descriptor [3/10.1] */
327 struct pri_vol_desc
{
329 uint32_t seq_num
; /* MAX prevail */
330 uint32_t pvd_num
; /* assigned by author; 0 is special as in it may only occur once */
331 char vol_id
[32]; /* KEY ; main identifier of this disc */
332 uint16_t vds_num
; /* volume descriptor number; i.e. what volume number is it */
333 uint16_t max_vol_seq
; /* maximum volume descriptor number known */
335 uint16_t max_ichg_lvl
;
336 uint32_t charset_list
;
337 uint32_t max_charset_list
;
338 char volset_id
[128]; /* KEY ; if part of a multi-disc set or a band of volumes */
339 struct charspec desc_charset
; /* KEY according to ECMA 167 */
340 struct charspec explanatory_charset
;
341 struct extent_ad vol_abstract
;
342 struct extent_ad vol_copyright
;
344 struct timestamp time
;
347 uint32_t prev_vds_loc
; /* location of predecessor _lov ? */
348 uint16_t flags
; /* bit 0 : if set indicates volume set name is meaningful */
349 uint8_t reserved
[22];
353 /* UDF specific implementation use part of the implementation use volume descriptor */
355 struct charspec lvi_charset
;
362 struct regid impl_id
;
363 uint8_t impl_use
[128];
367 /* Implementation use Volume Descriptor */
371 struct regid impl_id
;
373 struct udf_lv_info lv_info
;
379 /* Logical Volume Descriptor [3/10.6] */
382 uint32_t seq_num
; /* MAX prevail */
383 struct charspec desc_charset
; /* KEY */
384 char logvol_id
[128]; /* KEY */
386 struct regid domain_id
;
388 struct long_ad fsd_loc
; /* to fileset descriptor SEQUENCE */
389 uint8_t logvol_content_use
[16];
391 uint32_t mt_l
; /* Partition map length */
392 uint32_t n_pm
; /* Number of partition maps */
394 uint8_t imp_use
[128];
395 struct extent_ad integrity_seq_loc
;
398 #define lv_fsd_loc _lvd_use.fsd_loc
400 #define UDF_INTEGRITY_OPEN 0
401 #define UDF_INTEGRITY_CLOSED 1
404 #define UDF_PMAP_SIZE 64
406 /* Type 1 Partition Map [3/10.7.2] */
410 uint16_t vol_seq_num
;
415 /* Type 2 Partition Map [3/10.7.3] */
420 struct regid part_id
;
421 uint16_t vol_seq_num
;
423 uint8_t reserved2
[24];
427 /* Virtual Partition Map [UDF 2.01/2.2.8] */
428 struct part_map_virt
{
433 uint16_t vol_seq_num
;
435 uint8_t reserved1
[24];
439 /* Sparable Partition Map [UDF 2.01/2.2.9] */
440 struct part_map_spare
{
445 uint16_t vol_seq_num
;
448 uint8_t n_st
; /* Number of redundant sparing tables range 1-4 */
450 uint32_t st_size
; /* size of EACH sparing table */
451 uint32_t st_loc
[1]; /* locations of sparing tables */
455 /* Metadata Partition Map [UDF 2.50/2.2.10] */
456 struct part_map_meta
{
461 uint16_t vol_seq_num
;
463 uint32_t meta_file_lbn
; /* logical block number for file entry within part_num */
464 uint32_t meta_mirror_file_lbn
;
465 uint32_t meta_bitmap_file_lbn
;
466 uint32_t alloc_unit_size
; /* allocation unit size in blocks */
467 uint16_t alignment_unit_size
; /* alignment necessary in blocks */
469 uint8_t reserved1
[5];
471 #define METADATA_DUPLICATED 1
475 uint8_t data
[UDF_PMAP_SIZE
];
476 struct part_map_1 pm1
;
477 struct part_map_2 pm2
;
478 struct part_map_virt pmv
;
479 struct part_map_spare pms
;
480 struct part_map_meta pmm
;
484 /* Sparing Map Entry [UDF 2.01/2.2.11] */
485 struct spare_map_entry
{
486 uint32_t org
; /* partition relative address */
487 uint32_t map
; /* absolute disc address (!) can be in partition, but doesn't have to be */
491 /* Sparing Table [UDF 2.01/2.2.11] */
492 struct udf_sparing_table
{
495 uint16_t rt_l
; /* Relocation Table len */
498 struct spare_map_entry entries
[1];
502 #define UDF_NO_PREV_VAT 0xffffffff
503 /* UDF 1.50 VAT suffix [UDF 2.2.10 (UDF 1.50 spec)] */
504 struct udf_oldvat_tail
{
505 struct regid id
; /* "*UDF Virtual Alloc Tbl" */
510 /* VAT table [UDF 2.0.1/2.2.10] */
513 uint16_t impl_use_len
;
514 char logvol_id
[128]; /* newer version of the LVD one */
517 uint32_t num_directories
;
518 uint16_t min_udf_readver
;
519 uint16_t min_udf_writever
;
520 uint16_t max_udf_writever
;
522 uint8_t data
[1]; /* impl.use followed by VAT entries (uint32_t) */
526 /* Space bitmap descriptor as found in the partition header descriptor */
527 struct space_bitmap_desc
{
528 struct desc_tag tag
; /* TagId 264 */
529 uint32_t num_bits
; /* number of bits */
530 uint32_t num_bytes
; /* bytes that contain it */
535 /* Unalloc space entry as found in the partition header descriptor */
536 struct space_entry_desc
{
537 struct desc_tag tag
; /* TagId 263 */
538 struct icb_tag icbtag
; /* type 1 */
539 uint32_t l_ad
; /* in bytes */
544 /* Partition header descriptor; in the contents_use of part_desc */
545 struct part_hdr_desc
{
546 struct short_ad unalloc_space_table
;
547 struct short_ad unalloc_space_bitmap
;
548 struct short_ad part_integrity_table
; /* has to be ZERO for UDF */
549 struct short_ad freed_space_table
;
550 struct short_ad freed_space_bitmap
;
551 uint8_t reserved
[88];
555 /* Partition Descriptor [3/10.5] */
558 uint32_t seq_num
; /* MAX prevailing */
559 uint16_t flags
; /* bit 0 : if set the space is allocated */
560 uint16_t part_num
; /* KEY */
561 struct regid contents
;
563 struct part_hdr_desc part_hdr
;
564 uint8_t contents_use
[128];
566 uint32_t access_type
; /* R/W, WORM etc. */
567 uint32_t start_loc
; /* start of partition with given length */
570 uint8_t imp_use
[128];
571 uint8_t reserved
[156];
573 #define pd_part_hdr _impl_use.part_hdr
574 #define UDF_PART_FLAG_ALLOCATED 1
577 /* Unallocated Space Descriptor (UDF 2.01/2.2.5) */
578 struct unalloc_sp_desc
{
580 uint32_t seq_num
; /* MAX prevailing */
581 uint32_t alloc_desc_num
;
582 struct extent_ad alloc_desc
[1];
586 /* Logical Volume Integrity Descriptor [3/30.10] */
588 uint64_t next_unique_id
;
593 struct udf_logvol_info
{
594 struct regid impl_id
;
596 uint32_t num_directories
;
597 uint16_t min_udf_readver
;
598 uint16_t min_udf_writever
;
599 uint16_t max_udf_writever
;
603 struct logvol_int_desc
{
605 struct timestamp time
;
606 uint32_t integrity_type
;
607 struct extent_ad next_extent
;
609 struct logvolhdr logvolhdr
;
614 uint32_t tables
[1]; /* Freespace table, Sizetable, Implementation use */
616 #define lvint_next_unique_id _impl_use.logvolhdr.next_unique_id
619 /* File Set Descriptor [4/14.1] */
620 struct fileset_desc
{
622 struct timestamp time
;
624 uint16_t max_ichg_lvl
;
625 uint32_t charset_list
;
626 uint32_t max_charset_list
;
627 uint32_t fileset_num
; /* key! */
628 uint32_t fileset_desc_num
;
629 struct charspec logvol_id_charset
;
630 char logvol_id
[128]; /* for recovery */
631 struct charspec fileset_charset
;
632 char fileset_id
[32]; /* Mountpoint !! */
633 char copyright_file_id
[32];
634 char abstract_file_id
[32];
635 struct long_ad rootdir_icb
; /* to rootdir; icb->virtual ? */
636 struct regid domain_id
;
637 struct long_ad next_ex
; /* to the next fileset_desc extent */
638 struct long_ad streamdir_icb
; /* streamdir; needed? */
639 uint8_t reserved
[32];
643 /* File Identifier Descriptor [4/14.4] */
646 uint16_t file_version_num
;
648 uint8_t l_fi
; /* Length of file identifier area */
650 uint16_t l_iu
; /* Length of implementation use area */
653 #define UDF_FID_SIZE 38
654 #define UDF_FILE_CHAR_VIS (1 << 0) /* Invisible */
655 #define UDF_FILE_CHAR_DIR (1 << 1) /* Directory */
656 #define UDF_FILE_CHAR_DEL (1 << 2) /* Deleted */
657 #define UDF_FILE_CHAR_PAR (1 << 3) /* Parent Directory */
658 #define UDF_FILE_CHAR_META (1 << 4) /* Stream metadata */
661 /* Extended attributes [4/14.10.1] */
662 struct extattrhdr_desc
{
664 uint32_t impl_attr_loc
; /* offsets within this descriptor */
665 uint32_t appl_attr_loc
; /* ditto */
667 #define UDF_IMPL_ATTR_LOC_NOT_PRESENT 0xffffffff
668 #define UDF_APPL_ATTR_LOC_NOT_PRESENT 0xffffffff
671 /* Extended attribute entry [4/48.10.2] */
672 struct extattr_entry
{
680 /* Extended attribute entry; type 2048 [4/48.10.8] */
681 struct impl_extattr_entry
{
682 struct extattr_entry hdr
;
689 /* Extended attribute entry; type 65 536 [4/48.10.9] */
690 struct appl_extattr_entry
{
691 struct extattr_entry hdr
;
693 struct regid appl_id
;
698 /* File Times attribute entry; type 5 or type 6 [4/48.10.5], [4/48.10.6] */
699 struct filetimes_extattr_entry
{
700 struct extattr_entry hdr
;
701 uint32_t d_l
; /* length of times[] data following */
702 uint32_t existence
; /* bitmask */
703 struct timestamp times
[1]; /* in order of ascending bits */
705 #define UDF_FILETIMES_ATTR_NO 5
706 #define UDF_FILETIMES_FILE_CREATION 1
707 #define UDF_FILETIMES_FILE_DELETION 4
708 #define UDF_FILETIMES_FILE_EFFECTIVE 8
709 #define UDF_FILETIMES_FILE_BACKUPED 16
710 #define UDF_FILETIMES_ATTR_SIZE(no) (20 + (no)*sizeof(struct timestamp))
713 /* Device Specification Extended Attribute [4/4.10.7] */
714 struct device_extattr_entry
{
715 struct extattr_entry hdr
;
716 uint32_t iu_l
; /* length of implementation use */
719 uint8_t data
[1]; /* UDF: if nonzero length, contain developer ID regid */
721 #define UDF_DEVICESPEC_ATTR_NO 12
724 /* VAT LV extension Extended Attribute [UDF 3.3.4.5.1.3] 1.50 errata */
725 struct vatlvext_extattr_entry
{
726 uint64_t unique_id_chk
; /* needs to be copy of ICB's */
728 uint32_t num_directories
;
729 char logvol_id
[128]; /* replaces logvol name */
733 /* File Entry [4/14.9] */
736 struct icb_tag icbtag
;
742 uint8_t rec_disp_attr
;
745 uint64_t logblks_rec
;
746 struct timestamp atime
;
747 struct timestamp mtime
;
748 struct timestamp attrtime
;
750 struct long_ad ex_attr_icb
;
753 uint32_t l_ea
; /* Length of extended attribute area */
754 uint32_t l_ad
; /* Length of allocation descriptors */
757 #define UDF_FENTRY_SIZE 176
758 #define UDF_FENTRY_PERM_USER_MASK 0x07
759 #define UDF_FENTRY_PERM_GRP_MASK 0xE0
760 #define UDF_FENTRY_PERM_OWNER_MASK 0x1C00
763 /* Extended File Entry [4/48.17] */
764 struct extfile_entry
{
766 struct icb_tag icbtag
;
772 uint8_t rec_disp_attr
;
776 uint64_t logblks_rec
;
777 struct timestamp atime
;
778 struct timestamp mtime
;
779 struct timestamp ctime
;
780 struct timestamp attrtime
;
783 struct long_ad ex_attr_icb
;
784 struct long_ad streamdir_icb
;
787 uint32_t l_ea
; /* Length of extended attribute area */
788 uint32_t l_ad
; /* Length of allocation descriptors */
791 #define UDF_EXTFENTRY_SIZE 216
794 /* Indirect entry [ecma 48.7] */
795 struct indirect_entry
{
797 struct icb_tag icbtag
;
798 struct long_ad indirect_icb
;
802 /* Allocation extent descriptor [ecma 48.5] */
803 struct alloc_ext_entry
{
813 struct anchor_vdp avdp
;
814 struct vol_desc_ptr vdp
;
815 struct pri_vol_desc pvd
;
816 struct logvol_desc lvd
;
817 struct unalloc_sp_desc usd
;
818 struct logvol_int_desc lvid
;
819 struct impvol_desc ivd
;
821 struct fileset_desc fsd
;
822 struct fileid_desc fid
;
823 struct file_entry fe
;
824 struct extfile_entry efe
;
825 struct extattrhdr_desc eahd
;
826 struct indirect_entry inde
;
827 struct alloc_ext_entry aee
;
828 struct udf_sparing_table spt
;
829 struct space_bitmap_desc sbd
;
830 struct space_entry_desc sed
;
834 #endif /* !_FS_UDF_ECMA167_UDF_H_ */