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
21 typedef struct { USHORT le16
; } Uint16
;
22 typedef struct { USHORT le16
; } Int16
;
23 typedef struct { ULONG le32
; } Uint32
;
24 typedef struct { ULONG le32
; } Int32
;
25 typedef struct { UQUAD le32
; } Uint64
;
26 typedef struct { UQUAD le32
; } Int64
;
28 typedef struct osta_compressed
{
30 #define OSTA_COMPRESSIONID_8BIT 8 // UTF-8 stream
31 #define OSTA_COMPRESSIONID_16BIT 16 // UTF-16 stream
35 typedef struct charspec
{
36 Uint8 CharacterSetType
;
37 #define UDF_CS0 0 /* UDF OSTA Compressed Unicode */
38 #define UDF_CS1 1 /* ECMA-6 (ISO/IEC 10646-1) */
39 #define UDF_CS2 2 /* ECMA-119 file identifiers:
41 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
43 #define UDF_CS3 3 /* ISO/IEC 9945-1:
45 * abcdefghijklmnopqrstuvwxyz
46 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
48 #define UDF_CS4 4 /* International ECMA-6 */
49 #define UDF_CS5 5 /* ECMA-94 (Latin-1) */
50 #define UDF_CS6 6 /* ECMA-35 + ECMA-48 */
51 #define UDF_CS7 7 /* EMCA-35 + ECMA-48 + their extension characters */
52 #define UDF_CS8 8 /* Portable set:
53 * 0123456789._-!#$%&'()^`{}~
54 * abcdefghijklmnopqrstuvwxyz
55 * ABCDEFGHIJKLMNOPQRSTUVWXYZ
57 UBYTE CharacterSetInfo
[63];
58 #define UDF_CS0_OSTA_INFORMATION "OSTA Compressed Unicode"
59 /* CS0 - Valid graphic characters
60 * CS1 - Valid graphic characters
65 * CS6 - Valid graphic characters
66 * CS7 - Valid graphic characters
70 // UDF 1.02 calls 'charspec' 'Charspec'
71 #define Charspec charspec
73 typedef struct dstring
{
78 typedef struct timestamp
{
80 #define UDF_TZ_TYPE_of(x) (((x) >> 12) & 0xf)
81 #define UDF_TZ_TYPE_UCT 0
82 #define UDF_TZ_TYPE_LOCAL 1
83 #define UDF_TZ_TYPE_UNKNOWN 2
84 #define UDF_TZ_of(x) (((x) & 0x7ff) | (((x) >> 11) * 0xf800))
85 #define UDF_TZ_UNSPEC -2047
86 Int16 Year
; // 1 - 9999
87 Uint8 Month
; // 1 - 12
90 Uint8 Minute
; // 0 - 59
91 Uint8 Second
; // 0 - 59
92 Uint8 Centiseconds
; // 0 - 99
93 Uint8 HundredsofMicrosecs
; // 0 - 99
94 Uint8 Microseconds
; // 0 - 99
99 #define UDF_REGID_DIRTY (1 << 0)
100 #define UDF_REGID_PROTECTED (1 << 1)
101 UBYTE Identifier
[23];
104 struct DomainIdentifierSuffix
{
107 #define UDF_REGID_DOMAINFLAGS_WPROTECT_HARD (1 << 0)
108 #define UDF_REGID_DOMAINFLAGS_WPROTECT_SOFT (1 << 1)
111 struct UDFIdentifierSuffix
{
114 #define UTF_OSCLASS_UNDEFINED 0
115 #define UTF_OSCLASS_DOS 1
116 #define UTF_OSCLASS_OS2 2
117 #define UTF_OSCLASS_MACOS 3
118 #define UTF_OSCLASS_UNIX 4
119 #define UTF_OSCLASS_WIN9X 5
120 #define UTF_OSCLASS_WINNT 6
121 #define UTF_OSCLASS_OS400 7
122 #define UTF_OSCLASS_BEOS 8
123 #define UTF_OSCLASS_WINCE 9
127 struct ImplentationIdentifierSuffix
{
130 UBYTE ImplementationUse
[6];
131 } ImplementationSuffix
;
135 // UDF 1.02 calls 'regid' 'EntityID' (following ISO 13346 1/7.4 naming)
136 #define EnityID regid
139 typedef struct extent_ad
{
142 } extent_ad __packed
;
145 Uint16 TagIdentifier
;
146 #define UDF_TAG_PRIMARY_VOLUME 1
147 #define UDF_TAG_ANCHOR_VOLUME_PTR 2
148 #define UDF_TAG_VOLUME_PTR 3
150 #define UDF_TAG_PARTITION 5
151 #define UDF_TAG_LOGICAL_VOLUME 6
152 #define UDF_TAG_UNALLOCATED_SPACE 7
153 #define UDF_TAG_TERMINATING 8
154 #define UDF_TAG_LOGICAL_VOLUME_INT 9
155 Uint16 DescriptorVersion
; /* 2 = NSR02, 3 = NSR03 */
156 Uint8 TagChecksum
; /* Checksum of bytes 0-3 & 5-15 mod 256 */
158 Uint16 TagSerialNumber
;
159 Uint16 DescriptorCRC
; /* CRC-ITU-T (x^16 + x^12 + x^5 + 1) */
160 Uint16 DescriptorCRCLength
;
161 UInt32 TagLocation
; /* Extent of this tag */
164 /****************** Volume & Partitions ******************/
167 Uint8 Type
; /* 0 0 0 */
168 UBYTE Id
[5]; /* BEA01, BOOT2, NSR02, NSR03, TEA01 */
169 Uint8 Version
; /* 1 1 1 */
172 struct UDF_VolumeDescriptor_BOOT2
{
174 regid ArchitectureType
;
175 regid BootIdentifier
;
176 Uint32 BootExtentLocation
;
177 Uint32 BootExtentLength
;
180 timestamp CreationTime
;
182 #define UDF_BOOT2_IGNORE (1 << 0)
192 struct udfPrimaryVolume
{
194 Uint32 VolumeDescriptorSequenceNumber
;
195 Uint32 PrimaryVolumeDescriptorNumber
;
197 dstring VolumeIdentifier
;
198 UBYTE VolumeIdentifier_
[32];
200 Uint16 VolumeSequenceNumber
;
201 Uint16 MaximumVolumeSequenceNumber
;
202 Uint16 InterchangeLevel
;
203 #define UDF_VOLUME_INTERCHANGE_SINGLE 2
204 #define UDF_VOLUME_INTERCHANGE_MULTI 3
205 Uint16 MaximumInterchangeLevel
;
206 Uint32 CharacterSetList
;
207 #define UDF_VOLUME_CHARACTERSETLIST (1 << 0) // This is the ONLY value allowed!
208 Uint32 MaximumCharacterSetList
;
210 dstring VolumeSetIdentifier
;
211 UBYTE VolumeSetIdentifier_
[128];
213 charspec DescriptorCharacterSet
;
214 charspec ExplanatoryCharacterSet
;
215 extent_ad VolumeAbstract
;
216 extent_ad VolumeCopyright
;
217 regid ApplicationIdentifier
;
218 timestamp RecordingDateandTime
;
219 regid ImplementationIdentifier
;
220 UBYTE ImplementationUse
[64];
221 Uint32 PredecessorVolumeDescriptorSequenceLocation
;
223 #define UDF_PRIMARY_VOLUME_COMMON (1 << 0)
227 struct udfAnchorVolumePointer
{
229 extent_ad MainVolumeDescriptorSequenceExtent
;
230 extent_ad ReserveVolumeDescriptorSequenceExtent
;
234 struct udfVolumePointer
{
236 Uint32 VolumeSequenceNumber
;
237 extent_ad NextVolumeExtent
;
241 struct udfPartition
{
243 Uint32 VolumeSequenceNumber
;
245 #define UDF_PARTITION_FLAGS_ALLOCATED (1 << 0)
247 regid Contents
; /* "+FDC01" - ECMA-107
248 * "+CD001" - ECMA-119
249 * "+CDW02" - ECMA-168
250 * "+NSR02" - ECMA-167/2
251 * "+NSR03" - ECMA-167
253 UBYTE ContentsUse
[128];
255 #define UDF_PARTITION_ACCESSTYPE_RO 1 /* Read only */
256 #define UDF_PARTITION_ACCESSTYPE_WORM 2 /* Write once */
257 #define UDF_PARTITION_ACCESSTYPE_REW 3 /* Read/Erase/Write */
258 #define UDF_PARTITION_ACCESSTYPE_RW 4 /* Read/Write */
259 Uint32 StartingLocation
;
261 regid ImplementationIdentifier
;
262 UBYTE ImplementationUse
[128];
266 struct udfLogicalVolume
{
268 Uint32 VolumeDescriptorSequenceNumber
;
269 charspec DescriptorCharacterSet
;
272 UBYTE Identifier_
[128];
274 Uint32 LogicalBlockSize
;
275 regid DomainIdentifier
;
276 UBYTE LogicalVolumeContentsUse
[16];
277 Uint32 MapTableLength
; /* MT_L */
278 Uint32 NumberOfParititionMaps
;
279 regid ImplementationIdentifier
;
280 UBYTE ImplementationUse
[128];
281 extent_ad IntegritySequenceExtent
;
282 UBYTE PartitionMaps
[0];
285 struct udfPartitionMap
{
287 #define UDF_PARTITIONMAP_TYPE_1 1
288 #define UDF_PARTITIONMAP_TYPE_2 2
293 Uint16 VolumeSequenceNumber
;
294 Uint16 PartitionNumber
;
298 regid PartitionTypeIdentifier
;
299 Uint16 VolumeSequenceNumber
;
300 Uint16 PartitionNumber
;
306 struct udfSparingTable
{
311 Uint32 SequenceNumber
;
312 struct udfSparingMapEntry
{
313 Uint32 OriginalLocation
;
314 #define UDF_MAPENTRY_AVAILABLE 0xffffffff
315 #define UDF_MAPENTRY_DEFECTIVE 0xfffffff0
316 Uint32 MappedLocation
;
320 struct udfUnallocatedSpaceDesc
{
322 Uint32 VolumeDescriptorSequenceNumber
;
323 Uint32 NumberofAlloctionDescriptors
;
324 extent_ad AlloctionDescriptor
[0];
327 struct udfTerminating
{
332 struct udfLogicalVolumeIntegrityDesc
{
334 timestamp RecordingDateandTime
;
335 Uint32 IntegrityType
;
336 #define UDF_LOGICALVOLUMEINTEGRITY_TYPE_OPEN 0
337 #define UDF_LOGICALVOLUMEINTEGRITY_TYPE_CLOSE 1
338 extent_ad NextIntegrityExtent
;
339 UBYTE LogicalVolumeContentsUse
[32];
340 Uint32 NumberOfPartitions
;
341 Uint32 LengthOfImplementationUse
;
342 Uint32 Data
[0]; /* Free Space Table, Size Table, Impl. Use */
345 struct udfLogicalVolumeIntegrityImplementationUse
{
346 regid ImplementationID
;
347 Uint32 NumberofFiles
;
348 Uint32 NumberofDirectories
;
349 Uint16 MinimumUDFReadRevision
;
350 Uint16 MinimumUDFWriteRevision
;
351 Uint16 MaximumUDFWriteRevision
;
352 UBYTE ImplementationUse
[0];
355 struct udfImpUseVolume
{
357 Uint32 VolumeDescriptorSequenceNumber
;
358 regid ImplementationIdentifier
;
360 UBYTE ImplementationUse
[460];
361 struct LVInformation
{
364 dstring LogicalVolumeIdentifier
;
365 UBYTE LogicalVolumeIdentifier_
[128];
379 regid ImplementationId
;
380 UBYTE ImplementationUse
[128];
387 /****************** Filesystem ***************************/
389 typedef struct lb_addr
{
394 typedef struct short_ad
{
396 #define UDF_SHORT_AD_LENGTH_of(x) ((x) & 0x3fffffff)
397 #define UDF_SHORT_AD_TYPE_of(x) (((x) >> 30) & 3)
398 #define UDF_SHORT_AD_TYPE_RECORDED 0
399 #define UDF_SHORT_AD_TYPE_ALLOCATED 1
400 #define UDF_SHORT_AD_TYPE_FREE 2
401 #define UDF_SHORT_AD_TYPE_NEXT 3
402 Uint32 ExtentLocation
;
405 typedef struct long_ad
{
407 lb_addr ExtentLocation
;
409 UBYTE ImplementationUse
[6];
417 /* NOTE: This is here for completeness
418 * ext_ad structures ARE NOT USED in UDF <= 2.60
420 typedef struct ext_ad
{
422 Uint32 RecordedLength
;
423 Uint32 InformationLength
;
424 lb_addr ExtentLocation
;
425 UBYTE ImplementationUse
[2];
428 #define UDF_TAG_FILE_SET 256
429 #define UDF_TAG_FILE_IDENTIFIER 257
430 #define UDF_TAG_ALLOCATION_EXTENT 258
431 #define UDF_TAG_INDIRECT_ENTRY 259
432 #define UDF_TAG_TERMINAL_ENTRY 260
433 #define UDF_TAG_FILE_ENTRY 261
434 #define UDF_TAG_EXTENDED_ATTRIBUTE 262
435 #define UDF_TAG_UNALLOCATED_SPACE 263
436 #define UDF_TAG_SPACE_BITMAP 264
437 #define UDF_TAG_PARTITION_INTEGRITY 265
438 #define UDF_TAG_EXTENDED_FILE 266
443 timestamp RecordingDateandTime
;
444 Uint16 InterchangeLevel
;
445 Uint16 MaximumInterchangeLevel
;
446 Uint32 CharacterSetList
;
447 Uint32 MaximumCharacterSetList
;
448 Uint32 FileSetNumber
;
449 Uint32 FileSetDescriptorNumber
;
450 charspec LogicalVolumeIdentifierCharacterSet
;
452 dstring LogicalVolumeIdentifier
;
453 UBYTE LogicalVolumeIdentifier_
[128];
455 charspec FileSetCharacterSet
;
458 UBYTE Identifier_
[32];
461 dstring CopyrightFileIdentifier
;
462 UBYTE CopyrightFileIdentifier_
[32];
465 dstring AbstractFileIdentifier
;
466 UBYTE AbstractFileIdentifier_
[32];
468 long_ad RootDirectoryICB
;
469 regid DomainIdentifier
;
475 struct udfPartitionHeader
{
476 short_ad UnallocatedSpaceTable
;
477 short_ad UnallocatedSpaceBitmap
;
478 short_ad PartitionIntegrityTable
;
479 short_ad FreedSpaceTable
;
480 short_ad FreedSpaceBitmap
;
485 struct udfFileIdentifier
{
487 Uint16 FileVersionNumber
;
488 Uint8 FileCharacteristics
;
489 #define UDF_FILEID_FLAGS_HIDDEN (1 << 0)
490 #define UDF_FILEID_FLAGS_DIRECTORY (1 << 1)
491 #define UDF_FILEID_FLAGS_DELETED (1 << 2)
492 #define UDF_FILEID_FLAGS_PARENT (1 << 3)
493 #define UDF_FILEID_FLAGS_METADATA (1 << 4)
494 Uint8 FileIdentifierLength
; /* L_FI */
496 Uint16 ImplementationUseLength
; /* L_IU */
497 UBYTE Data
[0]; /* L_IU + L_FI */
501 struct udfAllocationExtent
{
503 Uint32 PreviousAllocationExtentLocation
; // Must be 0
504 Uint32 AllocationDescriptorLength
;
505 // allocation descriptors follow
509 typedef struct icbtag
{
510 Uint32 PriorRecordedNumberofDirectEntries
;
512 #define UDF_ICBTAG_STRATEGY_1 // ECMA-167 4/A.2 Unused in UDF
513 #define UDF_ICBTAG_STRATEGY_2 // ECMA-167 4/A.3 Unused in UDF
514 #define UDF_ICBTAG_STRATEGY_3 // ECMA-167 4/A.4 Unused in UDF
515 #define UDF_ICBTAG_STRATEGY_4 // ECMA-167 4/A.5 UDF <= 2.60
516 #define UDF_ICBTAG_STRATEGY_4096 // UDF specific
517 UBYTE StrategyParameter
[2];
518 Uint16 NumberofEntries
;
521 #define UDF_FILETYPE_UNALLOCATED_SPACE 1
522 #define UDF_FILETYPE_PARTITION_INTEGRITY 2
523 #define UDF_FILETYPE_INDIRECT_ENTRY 3
524 #define UDF_FILETYPE_DIRECTORY 4
525 #define UDF_FILETYPE_FILE 5
526 #define UDF_FILETYPE_DEVICE_BLOCK 6
527 #define UDF_FILETYPE_DEVICE_CHAR 7
528 #define UDF_FILETYPE_EXTENDED_ATTRIBUTE 8
529 #define UDF_FILETYPE_DEVICE_FIFO 9
530 #define UDF_FILETYPE_DEVICE_SOCKET 10
531 #define UDF_FILETYPE_TERMINAL_ENTRY 11
532 #define UDF_FILETYPE_SYMLINK 12
533 #define UDF_FILETYPE_STREAM_DIRECTORY 13
534 lb_addr ParentICBLocation
;
536 #define UDF_ICBTAG_FLAGS_ALLOCTYPE_of(x) ((x) & 7)
537 #define UDF_ALLOCTYPE_SHORT_AD 0
538 #define UDF_ALLOCTYPE_LONG_AD 1
539 #define UDF_ALLOCTYPE_EXTENDED_AD 2 // NOT USED IN UDF!
540 #define UDF_ALLOCTYPE_TINY 3
541 #define UDF_ICBTAG_FLAGS_DIRECTORY_SORT (1 << 3)
542 #define UDF_ICBTAG_FLAGS_NON_RELOCATABLE (1 << 4)
543 #define UDF_ICBTAG_FLAGS_ARCHIVE (1 << 5)
544 #define UDF_ICBTAG_FLAGS_SETUID (1 << 6)
545 #define UDF_ICBTAG_FLAGS_SETGID (1 << 7)
546 #define UDF_ICBTAG_FLAGS_STICKY (1 << 8)
547 #define UDF_ICBTAG_FLAGS_CONTIGUOUS (1 << 9)
548 #define UDF_ICBTAG_FLAGS_SYSTEM (1 << 10)
549 #define UDF_ICBTAG_FLAGS_TRANSFORMED (1 << 11)
550 #define UDF_ICBTAG_FLAGS_MULTIVERSION (1 << 12)
551 #define UDF_ICBTAG_FLAGS_STREAM (1 << 13)
555 struct udfICBIndirect
{
562 struct udfICBTerminal
{
568 struct udfICBFileEntry
{
574 #define UDF_FILEPERM_OX (1 << 0)
575 #define UDF_FILEPERM_OW (1 << 1)
576 #define UDF_FILEPERM_OR (1 << 2)
577 #define UDF_FILEPERM_OA (1 << 3)
578 #define UDF_FILEPERM_OD (1 << 4)
579 #define UDF_FILEPERM_GX (1 << 5)
580 #define UDF_FILEPERM_GW (1 << 6)
581 #define UDF_FILEPERM_GR (1 << 7)
582 #define UDF_FILEPERM_GA (1 << 8)
583 #define UDF_FILEPERM_GD (1 << 9)
584 #define UDF_FILEPERM_UX (1 << 10)
585 #define UDF_FILEPERM_UW (1 << 11)
586 #define UDF_FILEPERM_UR (1 << 12)
587 #define UDF_FILEPERM_UA (1 << 13)
588 #define UDF_FILEPERM_UD (1 << 14)
589 Uint16 FileLinkCount
;
591 #define UDF_RECORDFORMAT_BIN 0 /* We only support this for now */
592 Uint8 RecordDisplayAttributes
;
593 #define UDF_RECORDATTR_BIN 0 /* We only support this for now */
595 Uint64 InformationLength
;
596 Uint64 LogicalBlocksRecorded
;
597 timestamp AccessTime
;
598 timestamp ModificationTime
;
599 timestamp AttributeTime
;
601 long_ad ExtendedAttributeICB
;
602 regid ImplementationIdentifier
;
604 Uint32 ExtendedAttributeLength
; // L_EA
605 Uint32 AllocationDescriptorLength
; // L_AD
606 UBYTE Data
[0]; // L_EA + L_AD
609 // ECMA-167 4/14.10 - Extended Attributes are ignored
611 // ECMA-167 4/14.11 - Unallocated Space
612 struct udfICBUnallocatedSpace
{
615 Uint32 AllocationDescriptorLength
; // L_AD
616 UBYTE Data
[0]; // L_AD
619 // ECMA-167 4/14.12 - Space Bitmap Descriptor
620 struct udfSpaceBitmap
{
624 UBYTE Bitmap
[0]; // N_B
627 // ECMA-167 4/14.13 - Partition Integrity
628 struct udfICBPartitionIntegrity
{
631 timestamp RecordingTime
;
633 #define UDF_PARTITIONINTEGRITY_OPEN 0
634 #define UDF_PARTITIONINTEGRITY_CLOSE 1
635 #define UDF_PARTITIONINTEGRITY_STABLE 2
637 regid ImplementationIdentifier
;
638 UBYTE ImplementationUse
[256];
641 // ECMA-167 4/14.16 - Pathname
642 struct udfPathComponent
{
644 #define UDF_PATHTYPE_ROOT 1
645 #define UDF_PATHTYPE_ROOT_OF 2 /* ":" */
646 #define UDF_PATHTYPE_PARENT_OF 3 /* "/" */
647 #define UDF_PATHTYPE_DIR_OF 4 /* "" */
648 #define UDF_PATHTYPE_FILE 5
649 Uint8 IdentifierLength
; // L_CI
650 Uint16 FileVersion
; // Shall be 0
651 UBYTE Identifier
[0]; // L_CI bytes