2 * Copyright (C) 2013, The AROS Development Team
4 * Author: Jason S. McMullan <jason.mcmullan@gmail.com>
6 * Licensed under the AROS PUBLIC LICENSE (APL) Version 1.1
12 #include <exec/types.h>
14 /* UDF 1.5 support, based off of the OSTA subset of ECMA-167
15 * Data structures for Plain, Spare, and VAT filesystems
19 #define __packed __attribute__((__packed__))
24 typedef struct { USHORT le16
; } Uint16
;
25 typedef struct { USHORT le16
; } Int16
;
26 typedef struct { ULONG le32
; } Uint32
;
27 typedef struct { ULONG le32
; } Int32
;
28 typedef struct { UQUAD le32
; } Uint64
;
29 typedef struct { UQUAD le32
; } Int64
;
31 typedef struct osta_compressed
{
33 #define OSTA_COMPRESSIONID_8BIT 8 // UTF-8 stream
34 #define OSTA_COMPRESSIONID_16BIT 16 // UTF-16 stream
38 typedef struct charspec
{
39 Uint8 CharacterSetType
;
40 #define UDF_CS0 0 /* UDF OSTA Compressed Unicode */
41 #define UDF_CS1 1 /* ECMA-6 (ISO/IEC 10646-1) */
42 #define UDF_CS2 2 /* ECMA-119 file identifiers:
44 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
46 #define UDF_CS3 3 /* ISO/IEC 9945-1:
48 * abcdefghijklmnopqrstuvwxyz
49 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
51 #define UDF_CS4 4 /* International ECMA-6 */
52 #define UDF_CS5 5 /* ECMA-94 (Latin-1) */
53 #define UDF_CS6 6 /* ECMA-35 + ECMA-48 */
54 #define UDF_CS7 7 /* EMCA-35 + ECMA-48 + their extension characters */
55 #define UDF_CS8 8 /* Portable set:
56 * 0123456789._-!#$%&'()^`{}~
57 * abcdefghijklmnopqrstuvwxyz
58 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
60 UBYTE CharacterSetInfo
[63];
61 #define UDF_CS0_OSTA_INFORMATION "OSTA Compressed Unicode"
62 /* CS0 - Valid graphic characters
63 * CS1 - Valid graphic characters
68 * CS6 - Valid graphic characters
69 * CS7 - Valid graphic characters
73 // UDF 1.02 calls 'charspec' 'Charspec'
74 #define Charspec charspec
76 typedef struct dstring
{
81 typedef struct timestamp
{
83 #define UDF_TZ_TYPE_of(x) (((x) >> 12) & 0xf)
84 #define UDF_TZ_TYPE_UCT 0
85 #define UDF_TZ_TYPE_LOCAL 1
86 #define UDF_TZ_TYPE_UNKNOWN 2
87 #define UDF_TZ_of(x) (((x) & 0x7ff) | (((x) >> 11) * 0xf800))
88 #define UDF_TZ_UNSPEC -2047
89 Int16 Year
; // 1 - 9999
90 Uint8 Month
; // 1 - 12
93 Uint8 Minute
; // 0 - 59
94 Uint8 Second
; // 0 - 59
95 Uint8 Centiseconds
; // 0 - 99
96 Uint8 HundredsofMicrosecs
; // 0 - 99
97 Uint8 Microseconds
; // 0 - 99
102 #define UDF_REGID_DIRTY (1 << 0)
103 #define UDF_REGID_PROTECTED (1 << 1)
104 UBYTE Identifier
[23];
107 struct DomainIdentifierSuffix
{
110 #define UDF_REGID_DOMAINFLAGS_WPROTECT_HARD (1 << 0)
111 #define UDF_REGID_DOMAINFLAGS_WPROTECT_SOFT (1 << 1)
114 struct UDFIdentifierSuffix
{
117 #define UTF_OSCLASS_UNDEFINED 0
118 #define UTF_OSCLASS_DOS 1
119 #define UTF_OSCLASS_OS2 2
120 #define UTF_OSCLASS_MACOS 3
121 #define UTF_OSCLASS_UNIX 4
122 #define UTF_OSCLASS_WIN9X 5
123 #define UTF_OSCLASS_WINNT 6
124 #define UTF_OSCLASS_OS400 7
125 #define UTF_OSCLASS_BEOS 8
126 #define UTF_OSCLASS_WINCE 9
130 struct ImplentationIdentifierSuffix
{
133 UBYTE ImplementationUse
[6];
134 } ImplementationSuffix
;
138 // UDF 1.02 calls 'regid' 'EntityID' (following ISO 13346 1/7.4 naming)
139 #define EnityID regid
142 typedef struct extent_ad
{
145 } extent_ad __packed
;
148 Uint16 TagIdentifier
;
149 #define UDF_TAG_PRIMARY_VOLUME 1
150 #define UDF_TAG_ANCHOR_VOLUME_PTR 2
151 #define UDF_TAG_VOLUME_PTR 3
153 #define UDF_TAG_PARTITION 5
154 #define UDF_TAG_LOGICAL_VOLUME 6
155 #define UDF_TAG_UNALLOCATED_SPACE 7
156 #define UDF_TAG_TERMINATING 8
157 #define UDF_TAG_LOGICAL_VOLUME_INT 9
158 Uint16 DescriptorVersion
; /* 2 = NSR02, 3 = NSR03 */
159 Uint8 TagChecksum
; /* Checksum of bytes 0-3 & 5-15 mod 256 */
161 Uint16 TagSerialNumber
;
162 Uint16 DescriptorCRC
; /* CRC-ITU-T (x^16 + x^12 + x^5 + 1) */
163 Uint16 DescriptorCRCLength
;
164 UInt32 TagLocation
; /* Extent of this tag */
167 /****************** Volume & Partitions ******************/
170 Uint8 Type
; /* 0 0 0 */
171 UBYTE Id
[5]; /* BEA01, BOOT2, NSR02, NSR03, TEA01 */
172 Uint8 Version
; /* 1 1 1 */
175 struct UDF_VolumeDescriptor_BOOT2
{
177 regid ArchitectureType
;
178 regid BootIdentifier
;
179 Uint32 BootExtentLocation
;
180 Uint32 BootExtentLength
;
183 timestamp CreationTime
;
185 #define UDF_BOOT2_IGNORE (1 << 0)
195 struct udfPrimaryVolume
{
197 Uint32 VolumeDescriptorSequenceNumber
;
198 Uint32 PrimaryVolumeDescriptorNumber
;
200 dstring VolumeIdentifier
;
201 UBYTE VolumeIdentifier_
[32];
203 Uint16 VolumeSequenceNumber
;
204 Uint16 MaximumVolumeSequenceNumber
;
205 Uint16 InterchangeLevel
;
206 #define UDF_VOLUME_INTERCHANGE_SINGLE 2
207 #define UDF_VOLUME_INTERCHANGE_MULTI 3
208 Uint16 MaximumInterchangeLevel
;
209 Uint32 CharacterSetList
;
210 #define UDF_VOLUME_CHARACTERSETLIST (1 << 0) // This is the ONLY value allowed!
211 Uint32 MaximumCharacterSetList
;
213 dstring VolumeSetIdentifier
;
214 UBYTE VolumeSetIdentifier_
[128];
216 charspec DescriptorCharacterSet
;
217 charspec ExplanatoryCharacterSet
;
218 extent_ad VolumeAbstract
;
219 extent_ad VolumeCopyright
;
220 regid ApplicationIdentifier
;
221 timestamp RecordingDateandTime
;
222 regid ImplementationIdentifier
;
223 UBYTE ImplementationUse
[64];
224 Uint32 PredecessorVolumeDescriptorSequenceLocation
;
226 #define UDF_PRIMARY_VOLUME_COMMON (1 << 0)
230 struct udfAnchorVolumePointer
{
232 extent_ad MainVolumeDescriptorSequenceExtent
;
233 extent_ad ReserveVolumeDescriptorSequenceExtent
;
237 struct udfVolumePointer
{
239 Uint32 VolumeSequenceNumber
;
240 extent_ad NextVolumeExtent
;
244 struct udfPartition
{
246 Uint32 VolumeSequenceNumber
;
248 #define UDF_PARTITION_FLAGS_ALLOCATED (1 << 0)
250 regid Contents
; /* "+FDC01" - ECMA-107
251 * "+CD001" - ECMA-119
252 * "+CDW02" - ECMA-168
253 * "+NSR02" - ECMA-167/2
254 * "+NSR03" - ECMA-167
256 UBYTE ContentsUse
[128];
258 #define UDF_PARTITION_ACCESSTYPE_RO 1 /* Read only */
259 #define UDF_PARTITION_ACCESSTYPE_WORM 2 /* Write once */
260 #define UDF_PARTITION_ACCESSTYPE_REW 3 /* Read/Erase/Write */
261 #define UDF_PARTITION_ACCESSTYPE_RW 4 /* Read/Write */
262 Uint32 StartingLocation
;
264 regid ImplementationIdentifier
;
265 UBYTE ImplementationUse
[128];
269 struct udfLogicalVolume
{
271 Uint32 VolumeDescriptorSequenceNumber
;
272 charspec DescriptorCharacterSet
;
275 UBYTE Identifier_
[128];
277 Uint32 LogicalBlockSize
;
278 regid DomainIdentifier
;
279 UBYTE LogicalVolumeContentsUse
[16];
280 Uint32 MapTableLength
; /* MT_L */
281 Uint32 NumberOfParititionMaps
;
282 regid ImplementationIdentifier
;
283 UBYTE ImplementationUse
[128];
284 extent_ad IntegritySequenceExtent
;
285 UBYTE PartitionMaps
[0];
288 struct udfPartitionMap
{
290 #define UDF_PARTITIONMAP_TYPE_1 1
291 #define UDF_PARTITIONMAP_TYPE_2 2
296 Uint16 VolumeSequenceNumber
;
297 Uint16 PartitionNumber
;
301 regid PartitionTypeIdentifier
;
302 Uint16 VolumeSequenceNumber
;
303 Uint16 PartitionNumber
;
309 struct udfSparingTable
{
314 Uint32 SequenceNumber
;
315 struct udfSparingMapEntry
{
316 Uint32 OriginalLocation
;
317 #define UDF_MAPENTRY_AVAILABLE 0xffffffff
318 #define UDF_MAPENTRY_DEFECTIVE 0xfffffff0
319 Uint32 MappedLocation
;
323 struct udfUnallocatedSpaceDesc
{
325 Uint32 VolumeDescriptorSequenceNumber
;
326 Uint32 NumberofAlloctionDescriptors
;
327 extent_ad AlloctionDescriptor
[0];
330 struct udfTerminating
{
335 struct udfLogicalVolumeIntegrityDesc
{
337 timestamp RecordingDateandTime
;
338 Uint32 IntegrityType
;
339 #define UDF_LOGICALVOLUMEINTEGRITY_TYPE_OPEN 0
340 #define UDF_LOGICALVOLUMEINTEGRITY_TYPE_CLOSE 1
341 extent_ad NextIntegrityExtent
;
342 UBYTE LogicalVolumeContentsUse
[32];
343 Uint32 NumberOfPartitions
;
344 Uint32 LengthOfImplementationUse
;
345 Uint32 Data
[0]; /* Free Space Table, Size Table, Impl. Use */
348 struct udfLogicalVolumeIntegrityImplementationUse
{
349 regid ImplementationID
;
350 Uint32 NumberofFiles
;
351 Uint32 NumberofDirectories
;
352 Uint16 MinimumUDFReadRevision
;
353 Uint16 MinimumUDFWriteRevision
;
354 Uint16 MaximumUDFWriteRevision
;
355 UBYTE ImplementationUse
[0];
358 struct udfImpUseVolume
{
360 Uint32 VolumeDescriptorSequenceNumber
;
361 regid ImplementationIdentifier
;
363 UBYTE ImplementationUse
[460];
364 struct LVInformation
{
367 dstring LogicalVolumeIdentifier
;
368 UBYTE LogicalVolumeIdentifier_
[128];
382 regid ImplementationId
;
383 UBYTE ImplementationUse
[128];
390 /****************** Filesystem ***************************/
392 typedef struct lb_addr
{
397 typedef struct short_ad
{
399 #define UDF_SHORT_AD_LENGTH_of(x) ((x) & 0x3fffffff)
400 #define UDF_SHORT_AD_TYPE_of(x) (((x) >> 30) & 3)
401 #define UDF_SHORT_AD_TYPE_RECORDED 0
402 #define UDF_SHORT_AD_TYPE_ALLOCATED 1
403 #define UDF_SHORT_AD_TYPE_FREE 2
404 #define UDF_SHORT_AD_TYPE_NEXT 3
405 Uint32 ExtentLocation
;
408 typedef struct long_ad
{
410 lb_addr ExtentLocation
;
412 UBYTE ImplementationUse
[6];
420 /* NOTE: This is here for completeness
421 * ext_ad structures ARE NOT USED in UDF <= 2.60
423 typedef struct ext_ad
{
425 Uint32 RecordedLength
;
426 Uint32 InformationLength
;
427 lb_addr ExtentLocation
;
428 UBYTE ImplementationUse
[2];
431 #define UDF_TAG_FILE_SET 256
432 #define UDF_TAG_FILE_IDENTIFIER 257
433 #define UDF_TAG_ALLOCATION_EXTENT 258
434 #define UDF_TAG_INDIRECT_ENTRY 259
435 #define UDF_TAG_TERMINAL_ENTRY 260
436 #define UDF_TAG_FILE_ENTRY 261
437 #define UDF_TAG_EXTENDED_ATTRIBUTE 262
438 #define UDF_TAG_UNALLOCATED_SPACE 263
439 #define UDF_TAG_SPACE_BITMAP 264
440 #define UDF_TAG_PARTITION_INTEGRITY 265
441 #define UDF_TAG_EXTENDED_FILE 266
446 timestamp RecordingDateandTime
;
447 Uint16 InterchangeLevel
;
448 Uint16 MaximumInterchangeLevel
;
449 Uint32 CharacterSetList
;
450 Uint32 MaximumCharacterSetList
;
451 Uint32 FileSetNumber
;
452 Uint32 FileSetDescriptorNumber
;
453 charspec LogicalVolumeIdentifierCharacterSet
;
455 dstring LogicalVolumeIdentifier
;
456 UBYTE LogicalVolumeIdentifier_
[128];
458 charspec FileSetCharacterSet
;
461 UBYTE Identifier_
[32];
464 dstring CopyrightFileIdentifier
;
465 UBYTE CopyrightFileIdentifier_
[32];
468 dstring AbstractFileIdentifier
;
469 UBYTE AbstractFileIdentifier_
[32];
471 long_ad RootDirectoryICB
;
472 regid DomainIdentifier
;
478 struct udfPartitionHeader
{
479 short_ad UnallocatedSpaceTable
;
480 short_ad UnallocatedSpaceBitmap
;
481 short_ad PartitionIntegrityTable
;
482 short_ad FreedSpaceTable
;
483 short_ad FreedSpaceBitmap
;
488 struct udfFileIdentifier
{
490 Uint16 FileVersionNumber
;
491 Uint8 FileCharacteristics
;
492 #define UDF_FILEID_FLAGS_HIDDEN (1 << 0)
493 #define UDF_FILEID_FLAGS_DIRECTORY (1 << 1)
494 #define UDF_FILEID_FLAGS_DELETED (1 << 2)
495 #define UDF_FILEID_FLAGS_PARENT (1 << 3)
496 #define UDF_FILEID_FLAGS_METADATA (1 << 4)
497 Uint8 FileIdentifierLength
; /* L_FI */
499 Uint16 ImplementationUseLength
; /* L_IU */
500 UBYTE Data
[0]; /* L_IU + L_FI */
504 struct udfAllocationExtent
{
506 Uint32 PreviousAllocationExtentLocation
; // Must be 0
507 Uint32 AllocationDescriptorLength
;
508 // allocation descriptors follow
512 typedef struct icbtag
{
513 Uint32 PriorRecordedNumberofDirectEntries
;
515 #define UDF_ICBTAG_STRATEGY_1 // ECMA-167 4/A.2 Unused in UDF
516 #define UDF_ICBTAG_STRATEGY_2 // ECMA-167 4/A.3 Unused in UDF
517 #define UDF_ICBTAG_STRATEGY_3 // ECMA-167 4/A.4 Unused in UDF
518 #define UDF_ICBTAG_STRATEGY_4 // ECMA-167 4/A.5 UDF <= 2.60
519 #define UDF_ICBTAG_STRATEGY_4096 // UDF specific
520 UBYTE StrategyParameter
[2];
521 Uint16 NumberofEntries
;
524 #define UDF_FILETYPE_UNALLOCATED_SPACE 1
525 #define UDF_FILETYPE_PARTITION_INTEGRITY 2
526 #define UDF_FILETYPE_INDIRECT_ENTRY 3
527 #define UDF_FILETYPE_DIRECTORY 4
528 #define UDF_FILETYPE_FILE 5
529 #define UDF_FILETYPE_DEVICE_BLOCK 6
530 #define UDF_FILETYPE_DEVICE_CHAR 7
531 #define UDF_FILETYPE_EXTENDED_ATTRIBUTE 8
532 #define UDF_FILETYPE_DEVICE_FIFO 9
533 #define UDF_FILETYPE_DEVICE_SOCKET 10
534 #define UDF_FILETYPE_TERMINAL_ENTRY 11
535 #define UDF_FILETYPE_SYMLINK 12
536 #define UDF_FILETYPE_STREAM_DIRECTORY 13
537 lb_addr ParentICBLocation
;
539 #define UDF_ICBTAG_FLAGS_ALLOCTYPE_of(x) ((x) & 7)
540 #define UDF_ALLOCTYPE_SHORT_AD 0
541 #define UDF_ALLOCTYPE_LONG_AD 1
542 #define UDF_ALLOCTYPE_EXTENDED_AD 2 // NOT USED IN UDF!
543 #define UDF_ALLOCTYPE_TINY 3
544 #define UDF_ICBTAG_FLAGS_DIRECTORY_SORT (1 << 3)
545 #define UDF_ICBTAG_FLAGS_NON_RELOCATABLE (1 << 4)
546 #define UDF_ICBTAG_FLAGS_ARCHIVE (1 << 5)
547 #define UDF_ICBTAG_FLAGS_SETUID (1 << 6)
548 #define UDF_ICBTAG_FLAGS_SETGID (1 << 7)
549 #define UDF_ICBTAG_FLAGS_STICKY (1 << 8)
550 #define UDF_ICBTAG_FLAGS_CONTIGUOUS (1 << 9)
551 #define UDF_ICBTAG_FLAGS_SYSTEM (1 << 10)
552 #define UDF_ICBTAG_FLAGS_TRANSFORMED (1 << 11)
553 #define UDF_ICBTAG_FLAGS_MULTIVERSION (1 << 12)
554 #define UDF_ICBTAG_FLAGS_STREAM (1 << 13)
558 struct udfICBIndirect
{
565 struct udfICBTerminal
{
571 struct udfICBFileEntry
{
577 #define UDF_FILEPERM_OX (1 << 0)
578 #define UDF_FILEPERM_OW (1 << 1)
579 #define UDF_FILEPERM_OR (1 << 2)
580 #define UDF_FILEPERM_OA (1 << 3)
581 #define UDF_FILEPERM_OD (1 << 4)
582 #define UDF_FILEPERM_GX (1 << 5)
583 #define UDF_FILEPERM_GW (1 << 6)
584 #define UDF_FILEPERM_GR (1 << 7)
585 #define UDF_FILEPERM_GA (1 << 8)
586 #define UDF_FILEPERM_GD (1 << 9)
587 #define UDF_FILEPERM_UX (1 << 10)
588 #define UDF_FILEPERM_UW (1 << 11)
589 #define UDF_FILEPERM_UR (1 << 12)
590 #define UDF_FILEPERM_UA (1 << 13)
591 #define UDF_FILEPERM_UD (1 << 14)
592 Uint16 FileLinkCount
;
594 #define UDF_RECORDFORMAT_BIN 0 /* We only support this for now */
595 Uint8 RecordDisplayAttributes
;
596 #define UDF_RECORDATTR_BIN 0 /* We only support this for now */
598 Uint64 InformationLength
;
599 Uint64 LogicalBlocksRecorded
;
600 timestamp AccessTime
;
601 timestamp ModificationTime
;
602 timestamp AttributeTime
;
604 long_ad ExtendedAttributeICB
;
605 regid ImplementationIdentifier
;
607 Uint32 ExtendedAttributeLength
; // L_EA
608 Uint32 AllocationDescriptorLength
; // L_AD
609 UBYTE Data
[0]; // L_EA + L_AD
612 // ECMA-167 4/14.10 - Extended Attributes are ignored
614 // ECMA-167 4/14.11 - Unallocated Space
615 struct udfICBUnallocatedSpace
{
618 Uint32 AllocationDescriptorLength
; // L_AD
619 UBYTE Data
[0]; // L_AD
622 // ECMA-167 4/14.12 - Space Bitmap Descriptor
623 struct udfSpaceBitmap
{
627 UBYTE Bitmap
[0]; // N_B
630 // ECMA-167 4/14.13 - Partition Integrity
631 struct udfICBPartitionIntegrity
{
634 timestamp RecordingTime
;
636 #define UDF_PARTITIONINTEGRITY_OPEN 0
637 #define UDF_PARTITIONINTEGRITY_CLOSE 1
638 #define UDF_PARTITIONINTEGRITY_STABLE 2
640 regid ImplementationIdentifier
;
641 UBYTE ImplementationUse
[256];
644 // ECMA-167 4/14.16 - Pathname
645 struct udfPathComponent
{
647 #define UDF_PATHTYPE_ROOT 1
648 #define UDF_PATHTYPE_ROOT_OF 2 /* ":" */
649 #define UDF_PATHTYPE_PARENT_OF 3 /* "/" */
650 #define UDF_PATHTYPE_DIR_OF 4 /* "" */
651 #define UDF_PATHTYPE_FILE 5
652 Uint8 IdentifierLength
; // L_CI
653 Uint16 FileVersion
; // Shall be 0
654 UBYTE Identifier
[0]; // L_CI bytes