1 //---------------------------------------------------------------------- 2 // This software is part of the OpenBeOS distribution and is covered 3 // by the OpenBeOS license. 4 // 5 // Copyright (c) 2003 Tyler Dauwalder, tyler@dauwalder.net 6 //--------------------------------------------------------------------- 7 #ifndef _UDF_DISK_STRUCTURES_H 8 #define _UDF_DISK_STRUCTURES_H 9 10 #include <string.h> 11 12 #include <ByteOrder.h> 13 #include <SupportDefs.h> 14 15 #include "kernel_cpp.h" 16 #include "UdfDebug.h" 17 18 #include "Array.h" 19 20 /*! \file UdfStructures.h 21 22 \brief UDF on-disk data structure declarations 23 24 UDF is a specialization of the ECMA-167 standard. For the most part, 25 ECMA-167 structures are used by UDF with special restrictions. In a 26 few instances, UDF introduces its own structures to augment those 27 supplied by ECMA-167; those structures are clearly marked. 28 29 For UDF info: <a href='http://www.osta.org'>http://www.osta.org</a> 30 For ECMA info: <a href='http://www.ecma-international.org'>http://www.ecma-international.org</a> 31 32 For lack of a better place to store this info, the structures that 33 are allowed to have length greater than the logical block size are 34 as follows (other length restrictions may be found in UDF-2.01 5.1): 35 - \c logical_volume_descriptor 36 - \c unallocated_space_descriptor 37 - \c logical_volume_integrity_descriptor 38 - \c space_bitmap_descriptor 39 40 Other links of interest: 41 - <a href='http://www.extra.research.philips.com/udf/'>Philips UDF verifier</a> 42 - <a href='http://www.hi-ho.ne.jp/y-komachi/committees/fpro/fpro.htm'>Possible test disc image generator (?)</a> 43 */ 44 45 namespace Udf { 46 47 //---------------------------------------------------------------------- 48 // ECMA-167 Part 1 49 //---------------------------------------------------------------------- 50 51 /*! \brief Character set specifications 52 53 The character_set_info field shall be set to the ASCII string 54 "OSTA Compressed Unicode" (padded right with NULL chars). 55 56 See also: ECMA 167 1/7.2.1, UDF-2.01 2.1.2 57 */ 58 struct charspec { 59 public: 60 charspec(uint8 type = 0, const char *info = NULL); 61 62 void dump() const; 63 64 uint8 character_set_type() const { return _character_set_type; } 65 const char* character_set_info() const { return _character_set_info; } 66 char* character_set_info() { return _character_set_info; } 67 68 void set_character_set_type(uint8 type) { _character_set_type = type; } 69 void set_character_set_info(const char *info); 70 private: 71 uint8 _character_set_type; //!< to be set to 0 to indicate CS0 72 char _character_set_info[63]; //!< "OSTA Compressed Unicode" 73 } __attribute__((packed)); 74 75 extern const charspec kCs0CharacterSet; 76 77 /*! \brief Date and time stamp 78 79 See also: ECMA 167 1/7.3, UDF-2.01 2.1.4 80 */ 81 class timestamp { 82 private: 83 union type_and_timezone_accessor { 84 uint16 type_and_timezone; 85 struct { 86 uint16 type:4, 87 timezone:12; 88 } bits; 89 }; 90 91 public: 92 timestamp() { _clear(); } 93 timestamp(time_t time); 94 95 void dump() const; 96 97 // Get functions 98 uint16 type_and_timezone() const { return B_LENDIAN_TO_HOST_INT16(_type_and_timezone); } 99 uint8 type() const { 100 type_and_timezone_accessor t; 101 t.type_and_timezone = type_and_timezone(); 102 return t.bits.type; 103 } 104 int16 timezone() const { 105 type_and_timezone_accessor t; 106 t.type_and_timezone = type_and_timezone(); 107 int16 result = t.bits.timezone; 108 // Fill the lefmost bits with ones if timezone is negative 109 result <<= 4; 110 result >>= 4; 111 return result; 112 } 113 uint16 year() const { return B_LENDIAN_TO_HOST_INT16(_year); } 114 uint8 month() const { return _month; } 115 uint8 day() const { return _day; } 116 uint8 hour() const { return _hour; } 117 uint8 minute() const { return _minute; } 118 uint8 second() const { return _second; } 119 uint8 centisecond() const { return _centisecond; } 120 uint8 hundred_microsecond() const { return _hundred_microsecond; } 121 uint8 microsecond() const { return _microsecond; } 122 123 // Set functions 124 void set_type_and_timezone(uint16 type_and_timezone) { _type_and_timezone = B_HOST_TO_LENDIAN_INT16(type_and_timezone); } 125 void set_type(uint8 type) { 126 type_and_timezone_accessor t; 127 t.type_and_timezone = type_and_timezone(); 128 t.bits.type = type; 129 set_type_and_timezone(t.type_and_timezone); 130 } 131 void set_timezone(int16 tz) { 132 type_and_timezone_accessor t; 133 t.type_and_timezone = type_and_timezone(); 134 t.bits.timezone = tz; 135 set_type_and_timezone(t.type_and_timezone); 136 } 137 void set_year(uint16 year) { _year = B_HOST_TO_LENDIAN_INT16(year); } 138 void set_month(uint8 month) { _month = month; } 139 void set_day(uint8 day) { _day = day; } 140 void set_hour(uint8 hour) { _hour = hour; } 141 void set_minute(uint8 minute) { _minute = minute; } 142 void set_second(uint8 second) { _second = second; } 143 void set_centisecond(uint8 centisecond) { _centisecond = centisecond; } 144 void set_hundred_microsecond(uint8 hundred_microsecond) { _hundred_microsecond = hundred_microsecond; } 145 void set_microsecond(uint8 microsecond) { _microsecond = microsecond; } 146 private: 147 void _clear(); 148 149 uint16 _type_and_timezone; 150 uint16 _year; 151 uint8 _month; 152 uint8 _day; 153 uint8 _hour; 154 uint8 _minute; 155 uint8 _second; 156 uint8 _centisecond; 157 uint8 _hundred_microsecond; 158 uint8 _microsecond; 159 160 } __attribute__((packed)); 161 162 163 /*! \brief Implementation ID Identify Suffix 164 165 See also: UDF 2.50 2.1.5.3 166 */ 167 struct implementation_id_suffix { 168 public: 169 implementation_id_suffix(uint8 os_class, uint8 os_identifier); 170 171 uint8 os_class() const { return _os_class; } 172 uint8 os_identifier() const { return _os_identifier; } 173 174 void set_os_class(uint8 os_class) { _os_class = os_class; } 175 void set_os_identifier(uint8 identifier) { _os_identifier = identifier; } 176 private: 177 uint8 _os_class; 178 uint8 _os_identifier; 179 array<uint8, 6> _implementation_use; 180 }; 181 182 /*! \brief Operating system classes for implementation_id_suffixes 183 184 See also: Udf 2.50 6.3 185 */ 186 enum { 187 OS_UNDEFINED = 0, 188 OS_DOS, 189 OS_OS2, 190 OS_MACOS, 191 OS_UNIX, 192 OS_WIN9X, 193 OS_WINNT, 194 OS_OS400, 195 OS_BEOS, 196 OS_WINCE 197 }; 198 199 /*! \brief BeOS operating system classes identifiers for implementation_id_suffixes 200 201 See also: Udf 2.50 6.3 202 */ 203 enum { 204 BEOS_GENERIC = 0, 205 BEOS_OPENBEOS = 1 // not part of the standard, but perhaps someday. :-) 206 }; 207 208 /*! \brief Domain ID Identify Suffix 209 210 See also: UDF 2.50 2.1.5.3 211 */ 212 struct domain_id_suffix { 213 public: 214 domain_id_suffix(uint16 udfRevision, uint8 domainFlags); 215 216 //! Note that revision 2.50 is denoted by 0x0250. 217 uint16 udf_revision() const { return _udf_revision; } 218 uint8 domain_flags() const { return _domain_flags; } 219 220 void set_udf_revision(uint16 revision) { _udf_revision = B_HOST_TO_LENDIAN_INT16(revision); } 221 void set_domain_flags(uint8 flags) { _domain_flags = flags; } 222 private: 223 uint8 _udf_revision; 224 uint8 _domain_flags; 225 array<uint8, 5> _reserved; 226 }; 227 228 /*! \brief Domain flags 229 230 See also: UDF 2.50 2.1.5.3 231 */ 232 enum { 233 DF_HARD_WRITE_PROTECT = 0x01, 234 DF_SOFT_WRITE_PROTECT = 0x02 235 }; 236 237 /*! \brief Identifier used to designate the implementation responsible 238 for writing associated data structures on the medium. 239 240 See also: ECMA 167 1/7.4, UDF 2.01 2.1.5 241 */ 242 struct entity_id { 243 public: 244 static const int kIdentifierLength = 23; 245 static const int kIdentifierSuffixLength = 8; 246 247 entity_id(uint8 flags = 0, char *identifier = NULL, 248 uint8 *identifier_suffix = NULL); 249 entity_id(uint8 flags, char *identifier, 250 const implementation_id_suffix &suffix); 251 entity_id(uint8 flags, char *identifier, 252 const domain_id_suffix &suffix); 253 254 void dump() const; 255 bool matches(const entity_id &id) const; 256 257 // Get functions 258 uint8 flags() const { return _flags; } 259 const char* identifier() const { return _identifier; } 260 char* identifier() { return _identifier; } 261 const array<uint8, kIdentifierSuffixLength>& identifier_suffix() const { return _identifier_suffix; } 262 array<uint8, kIdentifierSuffixLength>& identifier_suffix() { return _identifier_suffix; } 263 264 // Set functions 265 void set_flags(uint8 flags) { _flags = flags; } 266 private: 267 uint8 _flags; 268 char _identifier[kIdentifierLength]; 269 array<uint8, kIdentifierSuffixLength> _identifier_suffix; 270 } __attribute__((packed)); 271 272 extern const entity_id kMetadataPartitionMapId; 273 extern const entity_id kSparablePartitionMapId; 274 extern const entity_id kVirtualPartitionMapId; 275 extern const entity_id kImplementationId; 276 extern const entity_id kPartitionContentsId; 277 extern const entity_id kUdfId; 278 279 //---------------------------------------------------------------------- 280 // ECMA-167 Part 2 281 //---------------------------------------------------------------------- 282 283 284 /*! \brief Header for volume structure descriptors 285 286 Each descriptor consumes an entire block. All unused trailing 287 bytes in the descriptor should be set to 0. 288 289 The following descriptors contain no more information than 290 that contained in the header: 291 292 - BEA01: 293 - type: 0 294 - id: "BEA01" 295 - version: 1 296 297 - TEA01: 298 - type: 0 299 - id: "TEA01" 300 - version: 1 301 302 - NSR03: 303 - type: 0 304 - id: "NSR03" 305 - version: 1 306 307 See also: ECMA 167 2/9.1 308 */ 309 struct volume_structure_descriptor_header { 310 public: 311 volume_structure_descriptor_header(uint8 type, const char *id, uint8 version); 312 313 uint8 type; 314 char id[5]; 315 uint8 version; 316 317 bool id_matches(const char *id); 318 } __attribute__((packed)); 319 320 // Volume structure descriptor ids 321 extern const char* kVSDID_BEA; 322 extern const char* kVSDID_TEA; 323 extern const char* kVSDID_BOOT; 324 extern const char* kVSDID_ISO; 325 extern const char* kVSDID_ECMA167_2; 326 extern const char* kVSDID_ECMA167_3; 327 extern const char* kVSDID_ECMA168; 328 329 //---------------------------------------------------------------------- 330 // ECMA-167 Part 3 331 //---------------------------------------------------------------------- 332 333 334 /*! \brief Location and length of a contiguous chunk of data on the volume. 335 336 \c _location is an absolute block address. 337 338 See also: ECMA 167 3/7.1 339 */ 340 struct extent_address { 341 public: 342 extent_address(uint32 location = 0, uint32 length = 0); 343 344 void dump() const; 345 346 uint32 length() const { return B_LENDIAN_TO_HOST_INT32(_length); } 347 uint32 location() const { return B_LENDIAN_TO_HOST_INT32(_location); } 348 349 void set_length(int32 length) { _length = B_HOST_TO_LENDIAN_INT32(length); } 350 void set_location(int32 location) { _location = B_HOST_TO_LENDIAN_INT32(location); } 351 private: 352 uint32 _length; 353 uint32 _location; 354 } __attribute__((packed)); 355 356 357 /*! \brief Location of a logical block within a logical volume. 358 359 See also: ECMA 167 4/7.1 360 */ 361 struct logical_block_address { 362 public: 363 void dump() const; 364 logical_block_address(uint16 partition = 0, uint32 block = 0); 365 366 uint32 block() const { return B_LENDIAN_TO_HOST_INT32(_block); } 367 uint16 partition() const { return B_LENDIAN_TO_HOST_INT16(_partition); } 368 369 void set_block(uint32 block) { _block = B_HOST_TO_LENDIAN_INT32(block); } 370 void set_partition(uint16 partition) { _partition = B_HOST_TO_LENDIAN_INT16(partition); } 371 372 private: 373 uint32 _block; //!< Block location relative to start of corresponding partition 374 uint16 _partition; //!< Numeric partition id within logical volume 375 } __attribute__((packed)); 376 377 /*! \brief Extent types used in short_address, long_address, 378 and extended_address. 379 380 See also: ECMA-167 4/14.14.1.1 381 */ 382 enum extent_type { 383 EXTENT_TYPE_RECORDED = 0, //!< Allocated and recorded 384 EXTENT_TYPE_ALLOCATED, //!< Allocated but unrecorded 385 EXTENT_TYPE_UNALLOCATED, //!< Unallocated and unrecorded 386 EXTENT_TYPE_CONTINUATION, //!< Specifies next extent of descriptors 387 }; 388 389 390 /*! \brief Allocation descriptor. 391 392 See also: ECMA 167 4/14.14.1 393 */ 394 struct short_address { 395 private: 396 union type_and_length_accessor { 397 uint32 type_and_length; 398 struct { 399 uint32 length:30, 400 type:2; 401 // uint32 type:2, 402 // length:30; 403 } bits; 404 }; 405 406 public: 407 void dump() const; 408 409 uint8 type() const { 410 type_and_length_accessor t; 411 t.type_and_length = type_and_length(); 412 return t.bits.type; 413 } 414 uint32 length() const { 415 type_and_length_accessor t; 416 t.type_and_length = type_and_length(); 417 return t.bits.length; 418 } 419 uint32 block() const { return B_LENDIAN_TO_HOST_INT32(_block); } 420 421 void set_type(uint8 type) { 422 type_and_length_accessor t; 423 t.type_and_length = type_and_length(); 424 t.bits.type = type; 425 set_type_and_length(t.type_and_length); 426 } 427 void set_length(uint32 length) { 428 type_and_length_accessor t; 429 t.type_and_length = type_and_length(); 430 t.bits.length = length; 431 set_type_and_length(t.type_and_length); 432 } 433 void set_block(uint32 block) { _block = B_HOST_TO_LENDIAN_INT32(block); } 434 private: 435 uint32 type_and_length() const { return B_LENDIAN_TO_HOST_INT32(_type_and_length); } 436 void set_type_and_length(uint32 value) { _type_and_length = B_HOST_TO_LENDIAN_INT32(value); } 437 438 uint32 _type_and_length; 439 uint32 _block; 440 } __attribute__((packed)); 441 442 443 /*! \brief Allocation descriptor w/ 6 byte implementation use field. 444 445 See also: ECMA 167 4/14.14.2 446 */ 447 struct long_address { 448 private: 449 union type_and_length_accessor { 450 uint32 type_and_length; 451 struct { 452 uint32 length:30, 453 type:2; 454 } bits; 455 }; 456 457 public: 458 long_address(uint16 partition = 0, uint32 block = 0, uint32 length = 0, 459 uint8 type = 0); 460 461 void dump() const; 462 463 uint8 type() const { 464 type_and_length_accessor t; 465 t.type_and_length = type_and_length(); 466 return t.bits.type; 467 } 468 uint32 length() const { 469 type_and_length_accessor t; 470 t.type_and_length = type_and_length(); 471 return t.bits.length; 472 } 473 474 uint32 block() const { return _location.block(); } 475 uint16 partition() const { return _location.partition(); } 476 477 const array<uint8, 6>& implementation_use() const { return _implementation_use; } 478 array<uint8, 6>& implementation_use() { return _implementation_use; } 479 480 void set_type(uint8 type) { 481 type_and_length_accessor t; 482 t.type_and_length = type_and_length(); 483 t.bits.type = type; 484 set_type_and_length(t.type_and_length); 485 } 486 void set_length(uint32 length) { 487 type_and_length_accessor t; 488 t.type_and_length = type_and_length(); 489 t.bits.length = length; 490 set_type_and_length(t.type_and_length); 491 } 492 void set_block(uint32 block) { _location.set_block(block); } 493 void set_partition(uint16 partition) { _location.set_partition(partition); } 494 495 void set_to(uint32 block, uint16 partition, uint32 length = 1, 496 uint8 type = EXTENT_TYPE_RECORDED) 497 { 498 set_block(block); 499 set_partition(partition); 500 set_length(length); 501 set_type(type); 502 } 503 504 private: 505 uint32 type_and_length() const { return B_LENDIAN_TO_HOST_INT32(_type_and_length); } 506 void set_type_and_length(uint32 value) { _type_and_length = B_HOST_TO_LENDIAN_INT32(value); } 507 508 uint32 _type_and_length; 509 logical_block_address _location; 510 array<uint8, 6> _implementation_use; 511 } __attribute__((packed)); 512 513 /*! \brief Common tag found at the beginning of most udf descriptor structures. 514 515 For error checking, \c descriptor_tag structures have: 516 - The disk location of the tag redundantly stored in the tag itself 517 - A checksum value for the tag 518 - A CRC value and length 519 520 See also: ECMA 167 1/7.2, UDF 2.01 2.2.1, UDF 2.01 2.3.1 521 */ 522 struct descriptor_tag { 523 public: 524 void dump() const; 525 526 status_t init_check(uint32 block, bool calculateCrc = true); 527 528 uint16 id() const { return B_LENDIAN_TO_HOST_INT16(_id); } 529 uint16 version() const { return B_LENDIAN_TO_HOST_INT16(_version); } 530 uint8 checksum() const { return _checksum; } 531 uint16 serial_number() const { return B_LENDIAN_TO_HOST_INT16(_serial_number); } 532 uint16 crc() const { return B_LENDIAN_TO_HOST_INT16(_crc); } 533 uint16 crc_length() const { return B_LENDIAN_TO_HOST_INT16(_crc_length); } 534 uint32 location() const { return B_LENDIAN_TO_HOST_INT32(_location); } 535 536 void set_id(uint16 id) { _id = B_HOST_TO_LENDIAN_INT16(id); } 537 void set_version(uint16 version) { _version = B_HOST_TO_LENDIAN_INT16(version); } 538 void set_checksum(uint8 checksum) { _checksum = checksum; } 539 void set_serial_number(uint16 serial_number) { _serial_number = B_HOST_TO_LENDIAN_INT16(serial_number); } 540 void set_crc(uint16 crc) { _crc = B_HOST_TO_LENDIAN_INT16(crc); } 541 void set_crc_length(uint16 crc_length) { _crc_length = B_HOST_TO_LENDIAN_INT16(crc_length); } 542 void set_location(uint32 location) { _location = B_HOST_TO_LENDIAN_INT32(location); } 543 544 /*! \brief Calculates and sets the crc length, crc checksumm, and 545 checksum for the tag. 546 547 This function should not be called until all member variables in 548 the descriptor_tag's enclosing descriptor and all member variables 549 in the descriptor_tag itself other than crc_length, crc, and checksum 550 have been set (since the checksum is based off of values in the 551 descriptor_tag, and the crc is based off the values in and the 552 size of the enclosing descriptor). 553 554 \param The tag's enclosing descriptor. 555 \param The size of the tag's enclosing descriptor (including the 556 tag); only necessary if different from sizeof(Descriptor). 557 */ 558 template <class Descriptor> 559 void 560 set_checksums(Descriptor &descriptor, uint16 size = sizeof(Descriptor)) 561 { 562 563 // check that this tag is actually owned by 564 // the given descriptor 565 if (this == &descriptor.tag()) 566 { 567 // crc_length, based off provided descriptor 568 set_crc_length(size - sizeof(descriptor_tag)); 569 // crc 570 uint16 crc = Udf::calculate_crc(reinterpret_cast<uint8*>(this) 571 + sizeof(descriptor_tag), crc_length()); 572 set_crc(crc); 573 // checksum (which depends on the other two values) 574 uint32 sum = 0; 575 for (int i = 0; i <= 3; i++) 576 sum += reinterpret_cast<uint8*>(this)[i]; 577 for (int i = 5; i <= 15; i++) 578 sum += reinterpret_cast<uint8*>(this)[i]; 579 set_checksum(sum % 256); 580 } 581 } 582 private: 583 uint16 _id; 584 uint16 _version; 585 uint8 _checksum; //!< Sum modulo 256 of bytes 0-3 and 5-15 of this struct. 586 uint8 _reserved; //!< Set to #00. 587 uint16 _serial_number; 588 uint16 _crc; //!< May be 0 if \c crc_length field is 0. 589 /*! \brief Length of the data chunk used to calculate CRC. 590 591 If 0, no CRC was calculated, and the \c crc field must be 0. 592 593 According to UDF-2.01 2.3.1.2, the CRC shall be calculated for all descriptors 594 unless otherwise noted, and this field shall be set to: 595 596 <code>(descriptor length) - (descriptor tag length)</code> 597 */ 598 uint16 _crc_length; 599 /*! \brief Address of this tag within its partition (for error checking). 600 601 For virtually addressed structures (i.e. those accessed thru a VAT), this 602 shall be the virtual address, not the physical or logical address. 603 */ 604 uint32 _location; 605 606 } __attribute__((packed)); 607 608 609 /*! \c descriptor_tag ::id values 610 */ 611 enum tag_id { 612 TAGID_UNDEFINED = 0, 613 614 // ECMA 167, PART 3 615 TAGID_PRIMARY_VOLUME_DESCRIPTOR, 616 TAGID_ANCHOR_VOLUME_DESCRIPTOR_POINTER, 617 TAGID_VOLUME_DESCRIPTOR_POINTER, 618 TAGID_IMPLEMENTATION_USE_VOLUME_DESCRIPTOR, 619 TAGID_PARTITION_DESCRIPTOR, 620 TAGID_LOGICAL_VOLUME_DESCRIPTOR, 621 TAGID_UNALLOCATED_SPACE_DESCRIPTOR, 622 TAGID_TERMINATING_DESCRIPTOR, 623 TAGID_LOGICAL_VOLUME_INTEGRITY_DESCRIPTOR, 624 625 TAGID_CUSTOM_START = 65280, 626 TAGID_CUSTOM_END = 65535, 627 628 // ECMA 167, PART 4 629 TAGID_FILE_SET_DESCRIPTOR = 256, 630 TAGID_FILE_ID_DESCRIPTOR, 631 TAGID_ALLOCATION_EXTENT_DESCRIPTOR, 632 TAGID_INDIRECT_ENTRY, 633 TAGID_TERMINAL_ENTRY, 634 TAGID_FILE_ENTRY, 635 TAGID_EXTENDED_ATTRIBUTE_HEADER_DESCRIPTOR, 636 TAGID_UNALLOCATED_SPACE_ENTRY, 637 TAGID_SPACE_BITMAP_DESCRIPTOR, 638 TAGID_PARTITION_INTEGRITY_ENTRY, 639 TAGID_EXTENDED_FILE_ENTRY, 640 }; 641 642 const char *tag_id_to_string(tag_id id); 643 644 extern const uint16 kCrcTable[256]; 645 646 /*! \brief Primary volume descriptor 647 */ 648 struct primary_volume_descriptor { 649 public: 650 void dump() const; 651 652 // Get functions 653 const descriptor_tag & tag() const { return _tag; } 654 descriptor_tag & tag() { return _tag; } 655 656 uint32 vds_number() const { return B_LENDIAN_TO_HOST_INT32(_vds_number); } 657 uint32 primary_volume_descriptor_number() const { return B_LENDIAN_TO_HOST_INT32(_primary_volume_descriptor_number); } 658 659 const array<char, 32>& volume_identifier() const { return _volume_identifier; } 660 array<char, 32>& volume_identifier() { return _volume_identifier; } 661 662 uint16 volume_sequence_number() const { return B_LENDIAN_TO_HOST_INT16(_volume_sequence_number); } 663 uint16 max_volume_sequence_number() const { return B_LENDIAN_TO_HOST_INT16(_max_volume_sequence_number); } 664 uint16 interchange_level() const { return B_LENDIAN_TO_HOST_INT16(_interchange_level); } 665 uint16 max_interchange_level() const { return B_LENDIAN_TO_HOST_INT16(_max_interchange_level); } 666 uint32 character_set_list() const { return B_LENDIAN_TO_HOST_INT32(_character_set_list); } 667 uint32 max_character_set_list() const { return B_LENDIAN_TO_HOST_INT32(_max_character_set_list); } 668 669 const array<char, 128>& volume_set_identifier() const { return _volume_set_identifier; } 670 array<char, 128>& volume_set_identifier() { return _volume_set_identifier; } 671 672 const charspec& descriptor_character_set() const { return _descriptor_character_set; } 673 charspec& descriptor_character_set() { return _descriptor_character_set; } 674 675 const charspec& explanatory_character_set() const { return _explanatory_character_set; } 676 charspec& explanatory_character_set() { return _explanatory_character_set; } 677 678 const extent_address& volume_abstract() const { return _volume_abstract; } 679 extent_address& volume_abstract() { return _volume_abstract; } 680 const extent_address& volume_copyright_notice() const { return _volume_copyright_notice; } 681 extent_address& volume_copyright_notice() { return _volume_copyright_notice; } 682 683 const entity_id& application_id() const { return _application_id; } 684 entity_id& application_id() { return _application_id; } 685 686 const timestamp& recording_date_and_time() const { return _recording_date_and_time; } 687 timestamp& recording_date_and_time() { return _recording_date_and_time; } 688 689 const entity_id& implementation_id() const { return _implementation_id; } 690 entity_id& implementation_id() { return _implementation_id; } 691 692 const array<uint8, 64>& implementation_use() const { return _implementation_use; } 693 array<uint8, 64>& implementation_use() { return _implementation_use; } 694 695 uint32 predecessor_volume_descriptor_sequence_location() const 696 { return B_LENDIAN_TO_HOST_INT32(_predecessor_volume_descriptor_sequence_location); } 697 uint16 flags() const { return B_LENDIAN_TO_HOST_INT16(_flags); } 698 699 const array<uint8, 22>& reserved() const { return _reserved; } 700 array<uint8, 22>& reserved() { return _reserved; } 701 702 // Set functions 703 void set_vds_number(uint32 number) 704 { _vds_number = B_HOST_TO_LENDIAN_INT32(number); } 705 void set_primary_volume_descriptor_number(uint32 number) 706 { _primary_volume_descriptor_number = B_HOST_TO_LENDIAN_INT32(number); } 707 void set_volume_sequence_number(uint16 number) 708 { _volume_sequence_number = B_HOST_TO_LENDIAN_INT16(number); } 709 void set_max_volume_sequence_number(uint16 number) 710 { _max_volume_sequence_number = B_HOST_TO_LENDIAN_INT16(number); } 711 void set_interchange_level(uint16 level) 712 { _interchange_level = B_HOST_TO_LENDIAN_INT16(level); } 713 void set_max_interchange_level(uint16 level) 714 { _max_interchange_level = B_HOST_TO_LENDIAN_INT16(level); } 715 void set_character_set_list(uint32 list) 716 { _character_set_list = B_HOST_TO_LENDIAN_INT32(list); } 717 void set_max_character_set_list(uint32 list) 718 { _max_character_set_list = B_HOST_TO_LENDIAN_INT32(list); } 719 void set_predecessor_volume_descriptor_sequence_location(uint32 location) 720 { _predecessor_volume_descriptor_sequence_location = B_HOST_TO_LENDIAN_INT32(location); } 721 void set_flags(uint16 flags) 722 { _flags = B_HOST_TO_LENDIAN_INT16(flags); } 723 724 private: 725 descriptor_tag _tag; 726 uint32 _vds_number; 727 uint32 _primary_volume_descriptor_number; 728 array<char, 32> _volume_identifier; 729 uint16 _volume_sequence_number; 730 uint16 _max_volume_sequence_number; 731 uint16 _interchange_level; //!< to be set to 3 if part of multivolume set, 2 otherwise 732 uint16 _max_interchange_level; //!< to be set to 3 unless otherwise directed by user 733 uint32 _character_set_list; 734 uint32 _max_character_set_list; 735 array<char, 128> _volume_set_identifier; 736 737 /*! \brief Identifies the character set for the \c volume_identifier 738 and \c volume_set_identifier fields. 739 740 To be set to CS0. 741 */ 742 charspec _descriptor_character_set; 743 744 /*! \brief Identifies the character set used in the \c volume_abstract 745 and \c volume_copyright_notice extents. 746 747 To be set to CS0. 748 */ 749 charspec _explanatory_character_set; 750 751 extent_address _volume_abstract; 752 extent_address _volume_copyright_notice; 753 754 entity_id _application_id; 755 timestamp _recording_date_and_time; 756 entity_id _implementation_id; 757 array<uint8, 64> _implementation_use; 758 uint32 _predecessor_volume_descriptor_sequence_location; 759 uint16 _flags; 760 array<uint8, 22> _reserved; 761 762 } __attribute__((packed)); 763 764 765 /*! \brief Anchor Volume Descriptor Pointer 766 767 vd recorded at preset locations in the partition, used as a reference 768 point to the main vd sequences 769 770 According to UDF 2.01, an avdp shall be recorded in at least 2 of 771 the 3 following locations, where N is the last recordable sector 772 of the partition: 773 - 256 774 - (N - 256) 775 - N 776 777 See also: ECMA 167 3/10.2, UDF-2.01 2.2.3 778 */ 779 struct anchor_volume_descriptor { 780 public: 781 void dump() const; 782 783 descriptor_tag & tag() { return _tag; } 784 const descriptor_tag & tag() const { return _tag; } 785 786 extent_address& main_vds() { return _main_vds; } 787 const extent_address& main_vds() const { return _main_vds; } 788 789 extent_address& reserve_vds() { return _reserve_vds; } 790 const extent_address& reserve_vds() const { return _reserve_vds; } 791 private: 792 descriptor_tag _tag; 793 extent_address _main_vds; //!< min length of 16 sectors 794 extent_address _reserve_vds; //!< min length of 16 sectors 795 char _reserved[480]; 796 } __attribute__((packed)); 797 798 799 /*! \brief Volume Descriptor Pointer 800 801 Used to chain extents of volume descriptor sequences together. 802 803 See also: ECMA 167 3/10.3 804 */ 805 struct descriptor_pointer { 806 descriptor_tag tag; 807 uint32 vds_number; 808 extent_address next; 809 } __attribute__((packed)); 810 811 812 /*! \brief Implementation Use Volume Descriptor 813 814 See also: ECMA 167 3/10.4 815 */ 816 struct implementation_use_descriptor { 817 public: 818 void dump() const; 819 820 // Get functions 821 const descriptor_tag & tag() const { return _tag; } 822 descriptor_tag & tag() { return _tag; } 823 824 uint32 vds_number() const { return B_LENDIAN_TO_HOST_INT32(_vds_number); } 825 826 const entity_id& implementation_id() const { return _implementation_id; } 827 entity_id& implementation_id() { return _implementation_id; } 828 829 const array<uint8, 460>& implementation_use() const { return _implementation_use; } 830 array<uint8, 460>& implementation_use() { return _implementation_use; } 831 832 // Set functions 833 void set_vds_number(uint32 number) { _vds_number = B_HOST_TO_LENDIAN_INT32(number); } 834 private: 835 descriptor_tag _tag; 836 uint32 _vds_number; 837 entity_id _implementation_id; 838 array<uint8, 460> _implementation_use; 839 } __attribute__((packed)); 840 841 842 /*! \brief Maximum number of partition descriptors to be found in volume 843 descriptor sequence, per UDF-2.50 844 */ 845 extern const uint8 kMaxPartitionDescriptors; 846 #define UDF_MAX_PARTITION_MAPS 2 847 #define UDF_MAX_PARTITION_MAP_SIZE 64 848 849 /*! \brief Partition Descriptor 850 851 See also: ECMA 167 3/10.5 852 */ 853 struct partition_descriptor { 854 private: 855 union partition_flags_accessor { 856 uint16 partition_flags; 857 struct { 858 uint16 allocated:1, 859 reserved:15; 860 } bits; 861 }; 862 863 public: 864 void dump() const; 865 866 // Get functions 867 const descriptor_tag & tag() const { return _tag; } 868 descriptor_tag & tag() { return _tag; } 869 870 uint32 vds_number() const { return B_LENDIAN_TO_HOST_INT32(_vds_number); } 871 uint16 partition_flags() const { return B_LENDIAN_TO_HOST_INT16(_partition_flags); } 872 bool allocated() const { 873 partition_flags_accessor f; 874 f.partition_flags = partition_flags(); 875 return f.bits.allocated; 876 } 877 uint16 partition_number() const { return B_LENDIAN_TO_HOST_INT16(_partition_number); } 878 879 const entity_id& partition_contents() const { return _partition_contents; } 880 entity_id& partition_contents() { return _partition_contents; } 881 882 const array<uint8, 128>& partition_contents_use() const { return _partition_contents_use; } 883 array<uint8, 128>& partition_contents_use() { return _partition_contents_use; } 884 885 uint32 access_type() const { return B_LENDIAN_TO_HOST_INT32(_access_type); } 886 uint32 start() const { return B_LENDIAN_TO_HOST_INT32(_start); } 887 uint32 length() const { return B_LENDIAN_TO_HOST_INT32(_length); } 888 889 const entity_id& implementation_id() const { return _implementation_id; } 890 entity_id& implementation_id() { return _implementation_id; } 891 892 const array<uint8, 128>& implementation_use() const { return _implementation_use; } 893 array<uint8, 128>& implementation_use() { return _implementation_use; } 894 895 const array<uint8, 156>& reserved() const { return _reserved; } 896 array<uint8, 156>& reserved() { return _reserved; } 897 898 // Set functions 899 void set_vds_number(uint32 number) { _vds_number = B_HOST_TO_LENDIAN_INT32(number); } 900 void set_partition_flags(uint16 flags) { _partition_flags = B_HOST_TO_LENDIAN_INT16(flags); } 901 void set_allocated(bool allocated) { 902 partition_flags_accessor f; 903 f.partition_flags = partition_flags(); 904 f.bits.allocated = allocated; 905 set_partition_flags(f.partition_flags); 906 } 907 void set_partition_number(uint16 number) { _partition_number = B_HOST_TO_LENDIAN_INT16(number); } 908 void set_access_type(uint32 type) { _access_type = B_HOST_TO_LENDIAN_INT32(type); } 909 void set_start(uint32 start) { _start = B_HOST_TO_LENDIAN_INT32(start); } 910 void set_length(uint32 length) { _length = B_HOST_TO_LENDIAN_INT32(length); } 911 912 private: 913 descriptor_tag _tag; 914 uint32 _vds_number; 915 /*! Bit 0: If 0, shall mean volume space has not been allocated. If 1, 916 shall mean volume space has been allocated. 917 */ 918 uint16 _partition_flags; 919 uint16 _partition_number; 920 921 /*! - "+NSR03" Volume recorded according to ECMA-167, i.e. UDF 922 - "+CD001" Volume recorded according to ECMA-119, i.e. iso9660 923 - "+FDC01" Volume recorded according to ECMA-107 924 - "+CDW02" Volume recorded according to ECMA-168 925 */ 926 entity_id _partition_contents; 927 array<uint8, 128> _partition_contents_use; 928 929 /*! See \c partition_access_type enum 930 */ 931 uint32 _access_type; 932 uint32 _start; 933 uint32 _length; 934 entity_id _implementation_id; 935 array<uint8, 128> _implementation_use; 936 array<uint8, 156> _reserved; 937 } __attribute__((packed)); 938 939 940 enum partition_access_type { 941 ACCESS_UNSPECIFIED, 942 ACCESS_READ_ONLY, 943 ACCESS_WRITE_ONCE, 944 ACCESS_REWRITABLE, 945 ACCESS_OVERWRITABLE, 946 }; 947 948 949 /*! \brief Logical volume descriptor 950 951 See also: ECMA 167 3/10.6, UDF-2.01 2.2.4 952 */ 953 struct logical_volume_descriptor { 954 void dump() const; 955 956 // Get functions 957 const descriptor_tag & tag() const { return _tag; } 958 descriptor_tag & tag() { return _tag; } 959 960 uint32 vds_number() const { return B_LENDIAN_TO_HOST_INT32(_vds_number); } 961 962 const charspec& character_set() const { return _character_set; } 963 charspec& character_set() { return _character_set; } 964 965 const array<char, 128>& logical_volume_identifier() const { return _logical_volume_identifier; } 966 array<char, 128>& logical_volume_identifier() { return _logical_volume_identifier; } 967 968 uint32 logical_block_size() const { return B_LENDIAN_TO_HOST_INT32(_logical_block_size); } 969 970 const entity_id& domain_id() const { return _domain_id; } 971 entity_id& domain_id() { return _domain_id; } 972 973 const array<uint8, 16>& logical_volume_contents_use() const { return _logical_volume_contents_use; } 974 array<uint8, 16>& logical_volume_contents_use() { return _logical_volume_contents_use; } 975 976 const long_address& file_set_address() const { return *reinterpret_cast<const long_address*>(&_logical_volume_contents_use); } 977 long_address& file_set_address() { return *reinterpret_cast<long_address*>(&_logical_volume_contents_use); } 978 979 uint32 map_table_length() const { return B_LENDIAN_TO_HOST_INT32(_map_table_length); } 980 uint32 partition_map_count() const { return B_LENDIAN_TO_HOST_INT32(_partition_map_count); } 981 982 const entity_id& implementation_id() const { return _implementation_id; } 983 entity_id& implementation_id() { return _implementation_id; } 984 985 const array<uint8, 128>& implementation_use() const { return _implementation_use; } 986 array<uint8, 128>& implementation_use() { return _implementation_use; } 987 988 const extent_address& integrity_sequence_extent() const { return _integrity_sequence_extent; } 989 extent_address& integrity_sequence_extent() { return _integrity_sequence_extent; } 990 991 const uint8* partition_maps() const { return _partition_maps; } 992 uint8* partition_maps() { return _partition_maps; } 993 994 // Set functions 995 void set_vds_number(uint32 number) { _vds_number = B_HOST_TO_LENDIAN_INT32(number); } 996 void set_logical_block_size(uint32 size) { _logical_block_size = B_HOST_TO_LENDIAN_INT32(size); } 997 998 void set_map_table_length(uint32 length) { _map_table_length = B_HOST_TO_LENDIAN_INT32(length); } 999 void set_partition_map_count(uint32 count) { _partition_map_count = B_HOST_TO_LENDIAN_INT32(count); } 1000 1001 // Other functions 1002 logical_volume_descriptor& operator=(const logical_volume_descriptor &rhs); 1003 1004 private: 1005 descriptor_tag _tag; 1006 uint32 _vds_number; 1007 1008 /*! \brief Identifies the character set for the 1009 \c logical_volume_identifier field. 1010 1011 To be set to CS0. 1012 */ 1013 charspec _character_set; 1014 array<char, 128> _logical_volume_identifier; 1015 uint32 _logical_block_size; 1016 1017 /*! \brief To be set to 0 or "*OSTA UDF Compliant". See UDF specs. 1018 */ 1019 entity_id _domain_id; 1020 1021 /*! \brief For UDF, shall contain a \c long_address which identifies 1022 the location of the logical volume's first file set. 1023 */ 1024 array<uint8, 16> _logical_volume_contents_use; 1025 1026 uint32 _map_table_length; 1027 uint32 _partition_map_count; 1028 entity_id _implementation_id; 1029 array<uint8, 128> _implementation_use; 1030 1031 /*! \brief Logical volume integrity sequence location. 1032 1033 For re/overwritable media, shall be a min of 8KB in length. 1034 For WORM media, shall be quite frickin large, as a new volume 1035 must be added to the set if the extent fills up (since you 1036 can't chain lvis's I guess). 1037 */ 1038 extent_address _integrity_sequence_extent; 1039 1040 /*! \brief Restricted to maps of type 1 for normal maps and 1041 UDF type 2 for virtual maps or maps on systems not supporting 1042 defect management. 1043 1044 Note that we actually allocate memory for the partition maps 1045 here due to the fact that we allocate logical_volume_descriptor 1046 objects on the stack sometimes. 1047 1048 See UDF-2.01 2.2.8, 2.2.9 1049 */ 1050 uint8 _partition_maps[UDF_MAX_PARTITION_MAPS * UDF_MAX_PARTITION_MAP_SIZE]; 1051 } __attribute__((packed)); 1052 1053 //! Base size (excluding partition maps) of lvd 1054 extern const uint32 kLogicalVolumeDescriptorBaseSize; 1055 1056 /*! \brief (Mostly) common portion of various partition maps 1057 1058 See also: ECMA-167 3/10.7.1 1059 */ 1060 struct partition_map_header { 1061 public: 1062 uint8 type() const { return _type; } 1063 uint8 length() const { return _length; } 1064 uint8 *map_data() { return _map_data; } 1065 const uint8 *map_data() const { return _map_data; } 1066 1067 entity_id& partition_type_id() 1068 { return *reinterpret_cast<entity_id*>(&_map_data[2]); } 1069 const entity_id& partition_type_id() const 1070 { return *reinterpret_cast<const entity_id*>(&_map_data[2]); } 1071 1072 void set_type(uint8 type) { _type = type; } 1073 void set_length(uint8 length) { _length = length; } 1074 private: 1075 uint8 _type; 1076 uint8 _length; 1077 uint8 _map_data[0]; 1078 };// __attribute__((packed)); 1079 1080 1081 /*! \brief Physical partition map (i.e. ECMA-167 Type 1 partition map) 1082 1083 See also: ECMA-167 3/10.7.2 1084 */ 1085 struct physical_partition_map { 1086 public: 1087 void dump(); 1088 1089 uint8 type() const { return _type; } 1090 uint8 length() const { return _length; } 1091 1092 uint16 volume_sequence_number() const { 1093 return B_LENDIAN_TO_HOST_INT16(_volume_sequence_number); } 1094 uint16 partition_number() const { 1095 return B_LENDIAN_TO_HOST_INT16(_partition_number); } 1096 1097 void set_type(uint8 type) { _type = type; } 1098 void set_length(uint8 length) { _length = length; } 1099 void set_volume_sequence_number(uint16 number) { 1100 _volume_sequence_number = B_HOST_TO_LENDIAN_INT16(number); } 1101 void set_partition_number(uint16 number) { 1102 _partition_number = B_HOST_TO_LENDIAN_INT16(number); } 1103 private: 1104 uint8 _type; 1105 uint8 _length; 1106 uint16 _volume_sequence_number; 1107 uint16 _partition_number; 1108 } __attribute__((packed)); 1109 1110 1111 /* ----UDF Specific---- */ 1112 /*! \brief Virtual partition map 1113 1114 Note that this map is a customization of the ECMA-167 1115 type 2 partition map. 1116 1117 See also: UDF-2.01 2.2.8 1118 */ 1119 struct virtual_partition_map { 1120 uint8 type; 1121 uint8 length; 1122 uint8 reserved1[2]; 1123 1124 /*! - flags: 0 1125 - identifier: "*UDF Virtual Partition" 1126 - identifier_suffix: per UDF-2.01 2.1.5.3 1127 */ 1128 entity_id partition_type_id; 1129 uint16 volume_sequence_number; 1130 1131 /*! corresponding type 1 partition map in same logical volume 1132 */ 1133 uint16 partition_number; 1134 uint8 reserved2[24]; 1135 } __attribute__((packed)); 1136 1137 1138 /*! \brief Maximum number of redundant sparing tables found in 1139 sparable_partition_map structures. 1140 */ 1141 #define UDF_MAX_SPARING_TABLE_COUNT 4 1142 1143 /* ----UDF Specific---- */ 1144 /*! \brief Sparable partition map 1145 1146 Note that this map is a customization of the ECMA-167 1147 type 2 partition map. 1148 1149 See also: UDF-2.01 2.2.9 1150 */ 1151 struct sparable_partition_map { 1152 public: 1153 void dump(); 1154 1155 uint8 type() const { return _type; } 1156 uint8 length() const { return _length; } 1157 1158 entity_id& partition_type_id() { return _partition_type_id; } 1159 const entity_id& partition_type_id() const { return _partition_type_id; } 1160 1161 uint16 volume_sequence_number() const { 1162 return B_LENDIAN_TO_HOST_INT16(_volume_sequence_number); } 1163 uint16 partition_number() const { 1164 return B_LENDIAN_TO_HOST_INT16(_partition_number); } 1165 uint16 packet_length() const { 1166 return B_LENDIAN_TO_HOST_INT16(_packet_length); } 1167 uint8 sparing_table_count() const { return _sparing_table_count; } 1168 uint32 sparing_table_size() const { 1169 return B_LENDIAN_TO_HOST_INT32(_sparing_table_size); } 1170 uint32 sparing_table_location(uint8 index) const { 1171 return B_LENDIAN_TO_HOST_INT32(_sparing_table_locations[index]); } 1172 1173 1174 void set_type(uint8 type) { _type = type; } 1175 void set_length(uint8 length) { _length = length; } 1176 void set_volume_sequence_number(uint16 number) { 1177 _volume_sequence_number = B_HOST_TO_LENDIAN_INT16(number); } 1178 void set_partition_number(uint16 number) { 1179 _partition_number = B_HOST_TO_LENDIAN_INT16(number); } 1180 void set_packet_length(uint16 length) { 1181 _packet_length = B_HOST_TO_LENDIAN_INT16(length); } 1182 void set_sparing_table_count(uint8 count) { 1183 _sparing_table_count = count; } 1184 void set_sparing_table_size(uint32 size) { 1185 _sparing_table_size = B_HOST_TO_LENDIAN_INT32(size); } 1186 void set_sparing_table_location(uint8 index, uint32 location) { 1187 _sparing_table_locations[index] = B_HOST_TO_LENDIAN_INT32(location); } 1188 private: 1189 uint8 _type; 1190 uint8 _length; 1191 uint8 _reserved1[2]; 1192 1193 /*! - flags: 0 1194 - identifier: "*UDF Sparable Partition" 1195 - identifier_suffix: per UDF-2.01 2.1.5.3 1196 */ 1197 entity_id _partition_type_id; 1198 uint16 _volume_sequence_number; 1199 1200 //! partition number of corresponding partition descriptor 1201 uint16 _partition_number; 1202 uint16 _packet_length; 1203 uint8 _sparing_table_count; 1204 uint8 _reserved2; 1205 uint32 _sparing_table_size; 1206 uint32 _sparing_table_locations[UDF_MAX_SPARING_TABLE_COUNT]; 1207 } __attribute__((packed)); 1208 1209 1210 /* ----UDF Specific---- */ 1211 /*! \brief Metadata partition map 1212 1213 Note that this map is a customization of the ECMA-167 1214 type 2 partition map. 1215 1216 See also: UDF-2.50 2.2.10 1217 */ 1218 struct metadata_partition_map { 1219 uint8 type; 1220 uint8 length; 1221 uint8 reserved1[2]; 1222 1223 /*! - flags: 0 1224 - identifier: "*UDF Metadata Partition" 1225 - identifier_suffix: per UDF-2.50 2.1.5 1226 */ 1227 entity_id partition_type_id; 1228 uint16 volume_sequence_number; 1229 1230 /*! corresponding type 1 or type 2 sparable partition 1231 map in same logical volume 1232 */ 1233 uint16 partition_number; 1234 uint8 reserved2[24]; 1235 } __attribute__((packed)); 1236 1237 1238 /*! \brief Unallocated space descriptor 1239 1240 See also: ECMA-167 3/10.8 1241 */ 1242 struct unallocated_space_descriptor { 1243 void dump() const; 1244 1245 // Get functions 1246 const descriptor_tag & tag() const { return _tag; } 1247 descriptor_tag & tag() { return _tag; } 1248 uint32 vds_number() const { return B_LENDIAN_TO_HOST_INT32(_vds_number); } 1249 uint32 allocation_descriptor_count() const { return B_LENDIAN_TO_HOST_INT32(_allocation_descriptor_count); } 1250 extent_address* allocation_descriptors() { return _allocation_descriptors; } 1251 1252 // Set functions 1253 void set_vds_number(uint32 number) { _vds_number = B_HOST_TO_LENDIAN_INT32(number); } 1254 void set_allocation_descriptor_count(uint32 count) { _allocation_descriptor_count = B_HOST_TO_LENDIAN_INT32(count); } 1255 private: 1256 descriptor_tag _tag; 1257 uint32 _vds_number; 1258 uint32 _allocation_descriptor_count; 1259 extent_address _allocation_descriptors[0]; 1260 } __attribute__((packed)); 1261 1262 1263 /*! \brief Terminating descriptor 1264 1265 See also: ECMA-167 3/10.9 1266 */ 1267 struct terminating_descriptor { 1268 void dump() const; 1269 1270 // Get functions 1271 const descriptor_tag & tag() const { return _tag; } 1272 descriptor_tag & tag() { return _tag; } 1273 1274 private: 1275 descriptor_tag _tag; 1276 uint8 _reserved[496]; 1277 } __attribute__((packed)); 1278 1279 1280 /*! \brief Logical volume integrity descriptor 1281 1282 See also: ECMA-167 3/10.10 1283 */ 1284 struct logical_volume_integrity_descriptor { 1285 descriptor_tag tag; 1286 timestamp recording_time; 1287 uint32 integrity_type; 1288 extent_address next_integrity_extent; 1289 array<uint8, 32> logical_volume_contents_use; 1290 uint32 partition_count; 1291 uint32 implementation_use_length; 1292 1293 /*! \todo double-check the pointer arithmetic here. */ 1294 uint32* free_space_table() { return (uint32*)(this+80); } 1295 uint32* size_table() { return (uint32*)(free_space_table()+partition_count*sizeof(uint32)); } 1296 uint8* implementation_use() { return (uint8*)(size_table()+partition_count*sizeof(uint32)); } 1297 1298 } __attribute__((packed)); 1299 1300 /*! \brief Logical volume integrity types 1301 */ 1302 enum { 1303 LVIT_OPEN = 1, 1304 LVIT_CLOSED, 1305 }; 1306 1307 //---------------------------------------------------------------------- 1308 // ECMA-167 Part 4 1309 //---------------------------------------------------------------------- 1310 1311 1312 1313 /*! \brief File set descriptor 1314 1315 Contains all the pertinent info about a file set (i.e. a hierarchy of files) 1316 1317 According to UDF-2.01, only one file set descriptor shall be recorded, 1318 except on WORM media, where the following rules apply: 1319 - Multiple file sets are allowed only on WORM media 1320 - The default file set shall be the one with highest value \c file_set_number field. 1321 - Only the default file set may be flagged as writeable. All others shall be 1322 flagged as "hard write protect". 1323 - No writeable file set may reference metadata structures which are referenced 1324 (directly or indirectly) by any other file set. Writeable file sets may, however, 1325 reference actual file data extents that are also referenced by other file sets. 1326 */ 1327 struct file_set_descriptor { 1328 void dump() const; 1329 1330 // Get functions 1331 const descriptor_tag & tag() const { return _tag; } 1332 descriptor_tag & tag() { return _tag; } 1333 1334 const timestamp& recording_date_and_time() const { return _recording_date_and_time; } 1335 timestamp& recording_date_and_time() { return _recording_date_and_time; } 1336 1337 uint16 interchange_level() const { return B_LENDIAN_TO_HOST_INT16(_interchange_level); } 1338 uint16 max_interchange_level() const { return B_LENDIAN_TO_HOST_INT16(_max_interchange_level); } 1339 uint32 character_set_list() const { return B_LENDIAN_TO_HOST_INT32(_character_set_list); } 1340 uint32 max_character_set_list() const { return B_LENDIAN_TO_HOST_INT32(_max_character_set_list); } 1341 uint32 file_set_number() const { return B_LENDIAN_TO_HOST_INT32(_file_set_number); } 1342 uint32 file_set_descriptor_number() const { return B_LENDIAN_TO_HOST_INT32(_file_set_descriptor_number); } 1343 1344 const charspec& logical_volume_id_character_set() const { return _logical_volume_id_character_set; } 1345 charspec& logical_volume_id_character_set() { return _logical_volume_id_character_set; } 1346 1347 const array<char, 128>& logical_volume_id() const { return _logical_volume_id; } 1348 array<char, 128>& logical_volume_id() { return _logical_volume_id; } 1349 1350 const charspec& file_set_id_character_set() const { return _file_set_id_character_set; } 1351 charspec& file_set_id_character_set() { return _file_set_id_character_set; } 1352 1353 const array<char, 32>& file_set_id() const { return _file_set_id; } 1354 array<char, 32>& file_set_id() { return _file_set_id; } 1355 1356 const array<char, 32>& copyright_file_id() const { return _copyright_file_id; } 1357 array<char, 32>& copyright_file_id() { return _copyright_file_id; } 1358 1359 const array<char, 32>& abstract_file_id() const { return _abstract_file_id; } 1360 array<char, 32>& abstract_file_id() { return _abstract_file_id; } 1361 1362 const long_address& root_directory_icb() const { return _root_directory_icb; } 1363 long_address& root_directory_icb() { return _root_directory_icb; } 1364 1365 const entity_id& domain_id() const { return _domain_id; } 1366 entity_id& domain_id() { return _domain_id; } 1367 1368 const long_address& next_extent() const { return _next_extent; } 1369 long_address& next_extent() { return _next_extent; } 1370 1371 const long_address& system_stream_directory_icb() const { return _system_stream_directory_icb; } 1372 long_address& system_stream_directory_icb() { return _system_stream_directory_icb; } 1373 1374 const array<uint8, 32>& reserved() const { return _reserved; } 1375 array<uint8, 32>& reserved() { return _reserved; } 1376 1377 // Set functions 1378 void set_interchange_level(uint16 level) { _interchange_level = B_HOST_TO_LENDIAN_INT16(level); } 1379 void set_max_interchange_level(uint16 level) { _max_interchange_level = B_HOST_TO_LENDIAN_INT16(level); } 1380 void set_character_set_list(uint32 list) { _character_set_list = B_HOST_TO_LENDIAN_INT32(list); } 1381 void set_max_character_set_list(uint32 list) { _max_character_set_list = B_HOST_TO_LENDIAN_INT32(list); } 1382 void set_file_set_number(uint32 number) { _file_set_number = B_HOST_TO_LENDIAN_INT32(number); } 1383 void set_file_set_descriptor_number(uint32 number) { _file_set_descriptor_number = B_HOST_TO_LENDIAN_INT32(number); } 1384 private: 1385 descriptor_tag _tag; 1386 timestamp _recording_date_and_time; 1387 uint16 _interchange_level; //!< To be set to 3 (see UDF-2.01 2.3.2.1) 1388 uint16 _max_interchange_level; //!< To be set to 3 (see UDF-2.01 2.3.2.2) 1389 uint32 _character_set_list; 1390 uint32 _max_character_set_list; 1391 uint32 _file_set_number; 1392 uint32 _file_set_descriptor_number; 1393 charspec _logical_volume_id_character_set; //!< To be set to kCSOCharspec 1394 array<char, 128> _logical_volume_id; 1395 charspec _file_set_id_character_set; 1396 array<char, 32> _file_set_id; 1397 array<char, 32> _copyright_file_id; 1398 array<char, 32> _abstract_file_id; 1399 long_address _root_directory_icb; 1400 entity_id _domain_id; 1401 long_address _next_extent; 1402 long_address _system_stream_directory_icb; 1403 array<uint8, 32> _reserved; 1404 } __attribute__((packed)); 1405 1406 1407 /*! \brief Partition header descriptor 1408 1409 Contains references to unallocated and freed space data structures. 1410 1411 Note that unallocated space is space ready to be written with no 1412 preprocessing. Freed space is space needing preprocessing (i.e. 1413 a special write pass) before use. 1414 1415 Per UDF-2.01 2.3.3, the use of tables or bitmaps shall be consistent, 1416 i.e. only one type or the other shall be used, not both. 1417 1418 To indicate disuse of a certain field, the fields of the allocation 1419 descriptor shall all be set to 0. 1420 1421 See also: ECMA-167 4/14.3, UDF-2.01 2.2.3 1422 */ 1423 struct partition_header_descriptor { 1424 long_address unallocated_space_table; 1425 long_address unallocated_space_bitmap; 1426 /*! Unused, per UDF-2.01 2.2.3 */ 1427 long_address partition_integrity_table; 1428 long_address freed_space_table; 1429 long_address freed_space_bitmap; 1430 uint8 reserved[88]; 1431 } __attribute__((packed)); 1432 1433 #define kMaxFileIdSize (sizeof(file_id_descriptor)+512+3) 1434 1435 /*! \brief File identifier descriptor 1436 1437 Identifies the name of a file entry, and the location of its corresponding 1438 ICB. 1439 1440 See also: ECMA-167 4/14.4, UDF-2.01 2.3.4 1441 1442 \todo Check pointer arithmetic 1443 */ 1444 struct file_id_descriptor { 1445 public: 1446 void dump() const; 1447 1448 descriptor_tag & tag() { return _tag; } 1449 const descriptor_tag & tag() const { return _tag; } 1450 1451 uint16 version_number() const { return B_LENDIAN_TO_HOST_INT16(_version_number); } 1452 1453 uint8 characteristics() const { return _characteristics; } 1454 1455 bool may_be_hidden() const { 1456 characteristics_accessor c; 1457 c.all = characteristics(); 1458 return c.bits.may_be_hidden; 1459 } 1460 1461 bool is_directory() const { 1462 characteristics_accessor c; 1463 c.all = characteristics(); 1464 return c.bits.is_directory; 1465 } 1466 1467 bool is_deleted() const { 1468 characteristics_accessor c; 1469 c.all = characteristics(); 1470 return c.bits.is_deleted; 1471 } 1472 1473 bool is_parent() const { 1474 characteristics_accessor c; 1475 c.all = characteristics(); 1476 return c.bits.is_parent; 1477 } 1478 1479 bool is_metadata_stream() const { 1480 characteristics_accessor c; 1481 c.all = characteristics(); 1482 return c.bits.is_metadata_stream; 1483 } 1484 1485 uint8 id_length() const { return _id_length; } 1486 1487 long_address& icb() { return _icb; } 1488 const long_address& icb() const { return _icb; } 1489 1490 uint8 implementation_use_length() const { return _implementation_use_length; } 1491 1492 /*! If implementation_use_length is greater than 0, the first 32 1493 bytes of implementation_use() shall be an entity_id identifying 1494 the implementation that generated the rest of the data in the 1495 implementation_use() field. 1496 */ 1497 uint8* implementation_use() { return ((uint8*)this)+(38); } 1498 char* id() { return ((char*)this)+(38)+implementation_use_length(); } 1499 const char* id() const { return ((const char*)this)+(38)+implementation_use_length(); } 1500 1501 uint16 structure_length() const { return (38) + id_length() + implementation_use_length(); } 1502 uint16 padding_length() const { return ((structure_length()+3)/4)*4 - structure_length(); } 1503 uint16 total_length() const { return structure_length() + padding_length(); } 1504 1505 // Set functions 1506 void set_version_number(uint16 number) { _version_number = B_HOST_TO_LENDIAN_INT16(number); } 1507 1508 void set_characteristics(uint8 characteristics) { _characteristics = characteristics; } 1509 1510 void set_may_be_hidden(bool how) { 1511 characteristics_accessor c; 1512 c.all = characteristics(); 1513 c.bits.may_be_hidden = how; 1514 set_characteristics(c.all); 1515 } 1516 1517 void set_is_directory(bool how) { 1518 characteristics_accessor c; 1519 c.all = characteristics(); 1520 c.bits.is_directory = how; 1521 set_characteristics(c.all); 1522 } 1523 1524 void set_is_deleted(bool how) { 1525 characteristics_accessor c; 1526 c.all = characteristics(); 1527 c.bits.is_deleted = how; 1528 set_characteristics(c.all); 1529 } 1530 1531 void set_is_parent(bool how) { 1532 characteristics_accessor c; 1533 c.all = characteristics(); 1534 c.bits.is_parent = how; 1535 set_characteristics(c.all); 1536 } 1537 1538 void set_is_metadata_stream(bool how) { 1539 characteristics_accessor c; 1540 c.all = characteristics(); 1541 c.bits.is_metadata_stream = how; 1542 set_characteristics(c.all); 1543 } 1544 1545 1546 void set_id_length(uint8 id_length) { _id_length = id_length; } 1547 void set_implementation_use_length(uint8 implementation_use_length) { _implementation_use_length = implementation_use_length; } 1548 1549 1550 1551 private: 1552 union characteristics_accessor { 1553 uint8 all; 1554 struct { 1555 uint8 may_be_hidden:1, 1556 is_directory:1, 1557 is_deleted:1, 1558 is_parent:1, 1559 is_metadata_stream:1, 1560 reserved_characteristics:3; 1561 } bits; 1562 }; 1563 1564 descriptor_tag _tag; 1565 /*! According to ECMA-167: 1 <= valid version_number <= 32767, 32768 <= reserved <= 65535. 1566 1567 However, according to UDF-2.01, there shall be exactly one version of 1568 a file, and it shall be 1. 1569 */ 1570 uint16 _version_number; 1571 /*! \todo Check UDF-2.01 2.3.4.2 for some more restrictions. */ 1572 uint8 _characteristics; 1573 uint8 _id_length; 1574 long_address _icb; 1575 uint8 _implementation_use_length; 1576 } __attribute__((packed)); 1577 1578 1579 /*! \brief Allocation extent descriptor 1580 1581 See also: ECMA-167 4/14.5 1582 */ 1583 struct allocation_extent_descriptor { 1584 descriptor_tag tag; 1585 uint32 previous_allocation_extent_location; 1586 uint32 length_of_allocation_descriptors; 1587 1588 /*! \todo Check that this is really how things work: */ 1589 uint8* allocation_descriptors() { return (uint8*)(this+sizeof(allocation_extent_descriptor)); } 1590 } __attribute__((packed)); 1591 1592 1593 /*! \brief icb_tag::file_type values 1594 1595 See also ECMA-167 4/14.6.6 1596 */ 1597 enum icb_file_types { 1598 ICB_TYPE_UNSPECIFIED = 0, 1599 ICB_TYPE_UNALLOCATED_SPACE_ENTRY, 1600 ICB_TYPE_PARTITION_INTEGRITY_ENTRY, 1601 ICB_TYPE_INDIRECT_ENTRY, 1602 ICB_TYPE_DIRECTORY, 1603 ICB_TYPE_REGULAR_FILE, 1604 ICB_TYPE_BLOCK_SPECIAL_DEVICE, 1605 ICB_TYPE_CHARACTER_SPECIAL_DEVICE, 1606 ICB_TYPE_EXTENDED_ATTRIBUTES_FILE, 1607 ICB_TYPE_FIFO, 1608 ICB_TYPE_ISSOCK, 1609 ICB_TYPE_TERMINAL, 1610 ICB_TYPE_SYMLINK, 1611 ICB_TYPE_STREAM_DIRECTORY, 1612 1613 ICB_TYPE_RESERVED_START = 14, 1614 ICB_TYPE_RESERVED_END = 247, 1615 1616 ICB_TYPE_CUSTOM_START = 248, 1617 ICB_TYPE_CUSTOM_END = 255, 1618 }; 1619 1620 /*! \brief idb_entry_tag::_flags::descriptor_flags() values 1621 1622 See also ECMA-167 4/14.6.8 1623 */ 1624 enum icb_descriptor_types { 1625 ICB_DESCRIPTOR_TYPE_SHORT = 0, 1626 ICB_DESCRIPTOR_TYPE_LONG, 1627 ICB_DESCRIPTOR_TYPE_EXTENDED, 1628 ICB_DESCRIPTOR_TYPE_EMBEDDED, 1629 }; 1630 1631 /*! \brief idb_entry_tag::strategy_type() values 1632 1633 See also UDF-2.50 2.3.5.1 1634 */ 1635 enum icb_strategy_types { 1636 ICB_STRATEGY_SINGLE = 4, 1637 ICB_STRATEGY_LINKED_LIST = 4096 1638 }; 1639 1640 /*! \brief ICB entry tag 1641 1642 Common tag found in all ICB entries (in addition to, and immediately following, 1643 the descriptor tag). 1644 1645 See also: ECMA-167 4/14.6, UDF-2.01 2.3.5 1646 */ 1647 struct icb_entry_tag { 1648 public: 1649 union flags_accessor { 1650 uint16 all_flags; 1651 struct { 1652 uint16 descriptor_flags:3, 1653 if_directory_then_sort:1, //!< To be set to 0 per UDF-2.01 2.3.5.4 1654 non_relocatable:1, 1655 archive:1, 1656 setuid:1, 1657 setgid:1, 1658 sticky:1, 1659 contiguous:1, 1660 system:1, 1661 transformed:1, 1662 multi_version:1, //!< To be set to 0 per UDF-2.01 2.3.5.4 1663 is_stream:1, 1664 reserved_icb_entry_flags:2; 1665 } flags; 1666 }; 1667 1668 public: 1669 void dump() const; 1670 1671 uint32 prior_recorded_number_of_direct_entries() const { return B_LENDIAN_TO_HOST_INT32(_prior_recorded_number_of_direct_entries); } 1672 uint16 strategy_type() const { return B_LENDIAN_TO_HOST_INT16(_strategy_type); } 1673 1674 array<uint8, 2>& strategy_parameters() { return _strategy_parameters; } 1675 const array<uint8, 2>& strategy_parameters() const { return _strategy_parameters; } 1676 1677 uint16 entry_count() const { return B_LENDIAN_TO_HOST_INT16(_entry_count); } 1678 uint8& reserved() { return _reserved; } 1679 uint8 file_type() const { return _file_type; } 1680 logical_block_address& parent_icb_location() { return _parent_icb_location; } 1681 const logical_block_address& parent_icb_location() const { return _parent_icb_location; } 1682 1683 uint16 flags() const { return B_LENDIAN_TO_HOST_INT16(_flags); } 1684 flags_accessor& flags_access() { return *reinterpret_cast<flags_accessor*>(&_flags); } 1685 1686 // flags accessor functions 1687 uint8 descriptor_flags() const { 1688 flags_accessor f; 1689 f.all_flags = flags(); 1690 return f.flags.descriptor_flags; 1691 } 1692 /* void set_descriptor_flags(uint8 value) { 1693 flags_accessor f; 1694 f.all_flags = flags(); 1695 f.flags.descriptor_flags = value; 1696 set_flags 1697 */ 1698 1699 void set_prior_recorded_number_of_direct_entries(uint32 entries) { _prior_recorded_number_of_direct_entries = B_LENDIAN_TO_HOST_INT32(entries); } 1700 void set_strategy_type(uint16 type) { _strategy_type = B_HOST_TO_LENDIAN_INT16(type); } 1701 1702 void set_entry_count(uint16 count) { _entry_count = B_LENDIAN_TO_HOST_INT16(count); } 1703 void set_file_type(uint8 type) { _file_type = type; } 1704 1705 void set_flags(uint16 flags) { _flags = B_LENDIAN_TO_HOST_INT16(flags); } 1706 1707 private: 1708 uint32 _prior_recorded_number_of_direct_entries; 1709 /*! Per UDF-2.01 2.3.5.1, only strategy types 4 and 4096 shall be supported. 1710 1711 \todo Describe strategy types here. 1712 */ 1713 uint16 _strategy_type; 1714 array<uint8, 2> _strategy_parameters; 1715 uint16 _entry_count; 1716 uint8 _reserved; 1717 /*! \brief icb_file_type value identifying the type of this icb entry */ 1718 uint8 _file_type; 1719 logical_block_address _parent_icb_location; 1720 uint16 _flags; 1721 } __attribute__((packed)); 1722 1723 /*! \brief Header portion of an ICB entry. 1724 */ 1725 struct icb_header { 1726 public: 1727 void dump() const; 1728 1729 descriptor_tag &tag() { return _tag; } 1730 const descriptor_tag &tag() const { return _tag; } 1731 1732 icb_entry_tag &icb_tag() { return _icb_tag; } 1733 const icb_entry_tag &icb_tag() const { return _icb_tag; } 1734 private: 1735 descriptor_tag _tag; 1736 icb_entry_tag _icb_tag; 1737 }; 1738 1739 /*! \brief Indirect ICB entry 1740 */ 1741 struct indirect_icb_entry { 1742 descriptor_tag tag; 1743 icb_entry_tag icb_tag; 1744 long_address indirect_icb; 1745 } __attribute__((packed)); 1746 1747 1748 /*! \brief Terminal ICB entry 1749 */ 1750 struct terminal_icb_entry { 1751 descriptor_tag tag; 1752 icb_entry_tag icb_tag; 1753 } __attribute__((packed)); 1754 1755 enum permissions { 1756 OTHER_EXECUTE = 0x0001, 1757 OTHER_WRITE = 0x0002, 1758 OTHER_READ = 0x0004, 1759 OTHER_ATTRIBUTES = 0x0008, 1760 OTHER_DELETE = 0x0010, 1761 GROUP_EXECUTE = 0x0020, 1762 GROUP_WRITE = 0x0040, 1763 GROUP_READ = 0x0080, 1764 GROUP_ATTRIBUTES = 0x0100, 1765 GROUP_DELETE = 0x0200, 1766 USER_EXECUTE = 0x0400, 1767 USER_WRITE = 0x0800, 1768 USER_READ = 0x1000, 1769 USER_ATTRIBUTES = 0x2000, 1770 USER_DELETE = 0x4000, 1771 }; 1772 1773 /*! \brief File ICB entry 1774 1775 See also: ECMA-167 4/14.9 1776 1777 \todo Check pointer math. 1778 */ 1779 struct file_icb_entry { 1780 void dump() const; 1781 1782 // get functions 1783 descriptor_tag & tag() { return _tag; } 1784 const descriptor_tag & tag() const { return _tag; } 1785 1786 icb_entry_tag& icb_tag() { return _icb_tag; } 1787 const icb_entry_tag& icb_tag() const { return _icb_tag; } 1788 1789 uint32 uid() const { return B_LENDIAN_TO_HOST_INT32(_uid); } 1790 uint32 gid() const { return B_LENDIAN_TO_HOST_INT32(_gid); } 1791 uint32 permissions() const { return B_LENDIAN_TO_HOST_INT32(_permissions); } 1792 uint16 file_link_count() const { return B_LENDIAN_TO_HOST_INT16(_file_link_count); } 1793 uint8 record_format() const { return _record_format; } 1794 uint8 record_display_attributes() const { return _record_display_attributes; } 1795 uint8 record_length() const { return _record_length; } 1796 uint64 information_length() const { return B_LENDIAN_TO_HOST_INT64(_information_length); } 1797 uint64 logical_blocks_recorded() const { return B_LENDIAN_TO_HOST_INT64(_logical_blocks_recorded); } 1798 1799 timestamp& access_date_and_time() { return _access_date_and_time; } 1800 const timestamp& access_date_and_time() const { return _access_date_and_time; } 1801 1802 timestamp& modification_date_and_time() { return _modification_date_and_time; } 1803 const timestamp& modification_date_and_time() const { return _modification_date_and_time; } 1804 1805 timestamp& attribute_date_and_time() { return _attribute_date_and_time; } 1806 const timestamp& attribute_date_and_time() const { return _attribute_date_and_time; } 1807 1808 uint32 checkpoint() const { return B_LENDIAN_TO_HOST_INT32(_checkpoint); } 1809 1810 long_address& extended_attribute_icb() { return _extended_attribute_icb; } 1811 const long_address& extended_attribute_icb() const { return _extended_attribute_icb; } 1812 1813 entity_id& implementation_id() { return _implementation_id; } 1814 const entity_id& implementation_id() const { return _implementation_id; } 1815 1816 uint64 unique_id() const { return B_LENDIAN_TO_HOST_INT64(_unique_id); } 1817 uint32 extended_attributes_length() const { return B_LENDIAN_TO_HOST_INT32(_extended_attributes_length); } 1818 uint32 allocation_descriptors_length() const { return B_LENDIAN_TO_HOST_INT32(_allocation_descriptors_length); } 1819 1820 uint8* extended_attributes() const { return ((uint8*)(this))+sizeof(file_icb_entry); } 1821 uint8* allocation_descriptors() const { return ((uint8*)(this))+sizeof(file_icb_entry)+extended_attributes_length(); } 1822 1823 // set functions 1824 void set_uid(uint32 uid) { _uid = B_HOST_TO_LENDIAN_INT32(uid); } 1825 void set_gid(uint32 gid) { _gid = B_HOST_TO_LENDIAN_INT32(gid); } 1826 void set_permissions(uint32 permissions) { _permissions = B_HOST_TO_LENDIAN_INT32(permissions); } 1827 1828 void set_file_link_count(uint16 count) { _file_link_count = B_HOST_TO_LENDIAN_INT16(count); } 1829 void set_record_format(uint8 format) { _record_format = format; } 1830 void set_record_display_attributes(uint8 attributes) { _record_display_attributes = attributes; } 1831 void set_record_length(uint8 length) { _record_length = length; } 1832 1833 void set_information_length(uint64 length) { _information_length = B_HOST_TO_LENDIAN_INT64(length); } 1834 void set_logical_blocks_recorded(uint64 blocks) { _logical_blocks_recorded = B_HOST_TO_LENDIAN_INT64(blocks); } 1835 1836 void set_checkpoint(uint32 checkpoint) { _checkpoint = B_HOST_TO_LENDIAN_INT32(checkpoint); } 1837 1838 void set_unique_id(uint64 id) { _unique_id = B_HOST_TO_LENDIAN_INT64(id); } 1839 1840 void set_extended_attributes_length(uint32 length) { _extended_attributes_length = B_HOST_TO_LENDIAN_INT32(length); } 1841 void set_allocation_descriptors_length(uint32 length) { _allocation_descriptors_length = B_HOST_TO_LENDIAN_INT32(length); } 1842 1843 private: 1844 descriptor_tag _tag; 1845 icb_entry_tag _icb_tag; 1846 uint32 _uid; 1847 uint32 _gid; 1848 /*! \todo List perms in comment and add handy union thingy */ 1849 uint32 _permissions; 1850 /*! Identifies the number of file identifier descriptors referencing 1851 this icb. 1852 */ 1853 uint16 _file_link_count; 1854 uint8 _record_format; //!< To be set to 0 per UDF-2.01 2.3.6.1 1855 uint8 _record_display_attributes; //!< To be set to 0 per UDF-2.01 2.3.6.2 1856 uint8 _record_length; //!< To be set to 0 per UDF-2.01 2.3.6.3 1857 uint64 _information_length; 1858 uint64 _logical_blocks_recorded; //!< To be 0 for files and dirs with embedded data 1859 timestamp _access_date_and_time; 1860 timestamp _modification_date_and_time; 1861 1862 // NOTE: data members following this point in the descriptor are in 1863 // different locations in extended file entries 1864 1865 timestamp _attribute_date_and_time; 1866 /*! \brief Initially 1, may be incremented upon user request. */ 1867 uint32 _checkpoint; 1868 long_address _extended_attribute_icb; 1869 entity_id _implementation_id; 1870 /*! \brief The unique id identifying this file entry 1871 1872 The id of the root directory of a file set shall be 0. 1873 1874 \todo Detail the system specific requirements for unique ids from UDF-2.01 1875 */ 1876 uint64 _unique_id; 1877 uint32 _extended_attributes_length; 1878 uint32 _allocation_descriptors_length; 1879 1880 }; 1881 1882 1883 /*! \brief Extended file ICB entry 1884 1885 See also: ECMA-167 4/14.17 1886 1887 \todo Check pointer math. 1888 */ 1889 struct extended_file_icb_entry { 1890 void dump() const; 1891 1892 // get functions 1893 descriptor_tag & tag() { return _tag; } 1894 const descriptor_tag & tag() const { return _tag; } 1895 1896 icb_entry_tag& icb_tag() { return _icb_tag; } 1897 const icb_entry_tag& icb_tag() const { return _icb_tag; } 1898 1899 uint32 uid() const { return B_LENDIAN_TO_HOST_INT32(_uid); } 1900 uint32 gid() const { return B_LENDIAN_TO_HOST_INT32(_gid); } 1901 uint32 permissions() const { return B_LENDIAN_TO_HOST_INT32(_permissions); } 1902 uint16 file_link_count() const { return B_LENDIAN_TO_HOST_INT16(_file_link_count); } 1903 uint8 record_format() const { return _record_format; } 1904 uint8 record_display_attributes() const { return _record_display_attributes; } 1905 uint8 record_length() const { return _record_length; } 1906 uint64 information_length() const { return B_LENDIAN_TO_HOST_INT64(_information_length); } 1907 uint64 logical_blocks_recorded() const { return B_LENDIAN_TO_HOST_INT64(_logical_blocks_recorded); } 1908 1909 timestamp& access_date_and_time() { return _access_date_and_time; } 1910 const timestamp& access_date_and_time() const { return _access_date_and_time; } 1911 1912 timestamp& modification_date_and_time() { return _modification_date_and_time; } 1913 const timestamp& modification_date_and_time() const { return _modification_date_and_time; } 1914 1915 timestamp& creation_date_and_time() { return _creation_date_and_time; } 1916 const timestamp& creation_date_and_time() const { return _creation_date_and_time; } 1917 1918 timestamp& attribute_date_and_time() { return _attribute_date_and_time; } 1919 const timestamp& attribute_date_and_time() const { return _attribute_date_and_time; } 1920 1921 uint32 checkpoint() const { return B_LENDIAN_TO_HOST_INT32(_checkpoint); } 1922 1923 long_address& extended_attribute_icb() { return _extended_attribute_icb; } 1924 const long_address& extended_attribute_icb() const { return _extended_attribute_icb; } 1925 1926 long_address& stream_directory_icb() { return _stream_directory_icb; } 1927 const long_address& stream_directory_icb() const { return _stream_directory_icb; } 1928 1929 entity_id& implementation_id() { return _implementation_id; } 1930 const entity_id& implementation_id() const { return _implementation_id; } 1931 1932 uint64 unique_id() const { return B_LENDIAN_TO_HOST_INT64(_unique_id); } 1933 uint32 extended_attributes_length() const { return B_LENDIAN_TO_HOST_INT32(_extended_attributes_length); } 1934 uint32 allocation_descriptors_length() const { return B_LENDIAN_TO_HOST_INT32(_allocation_descriptors_length); } 1935 1936 uint8* extended_attributes() const { return (uint8*)(this+sizeof(extended_file_icb_entry)); } 1937 uint8* allocation_descriptors() const { return (uint8*)(this+sizeof(sizeof(extended_file_icb_entry))+extended_attributes_length()); } 1938 1939 // set functions 1940 void set_uid(uint32 uid) { _uid = B_HOST_TO_LENDIAN_INT32(uid); } 1941 void set_gid(uint32 gid) { _gid = B_HOST_TO_LENDIAN_INT32(gid); } 1942 void set_permissions(uint32 permissions) { _permissions = B_HOST_TO_LENDIAN_INT32(permissions); } 1943 1944 void set_file_link_count(uint16 count) { _file_link_count = B_HOST_TO_LENDIAN_INT16(count); } 1945 void set_record_format(uint8 format) { _record_format = format; } 1946 void set_record_display_attributes(uint8 attributes) { _record_display_attributes = attributes; } 1947 void set_record_length(uint8 length) { _record_length = length; } 1948 1949 void set_information_length(uint64 length) { _information_length = B_HOST_TO_LENDIAN_INT64(length); } 1950 void set_logical_blocks_recorded(uint64 blocks) { _logical_blocks_recorded = B_HOST_TO_LENDIAN_INT64(blocks); } 1951 1952 void set_checkpoint(uint32 checkpoint) { _checkpoint = B_HOST_TO_LENDIAN_INT32(checkpoint); } 1953 void set_reserved(uint32 reserved) { _reserved = B_HOST_TO_LENDIAN_INT32(reserved); } 1954 1955 void set_unique_id(uint64 id) { _unique_id = B_HOST_TO_LENDIAN_INT64(id); } 1956 1957 void set_extended_attributes_length(uint32 length) { _extended_attributes_length = B_HOST_TO_LENDIAN_INT32(length); } 1958 void set_allocation_descriptors_length(uint32 length) { _allocation_descriptors_length = B_HOST_TO_LENDIAN_INT32(length); } 1959 1960 private: 1961 descriptor_tag _tag; 1962 icb_entry_tag _icb_tag; 1963 uint32 _uid; 1964 uint32 _gid; 1965 /*! \todo List perms in comment and add handy union thingy */ 1966 uint32 _permissions; 1967 /*! Identifies the number of file identifier descriptors referencing 1968 this icb. 1969 */ 1970 uint16 _file_link_count; 1971 uint8 _record_format; //!< To be set to 0 per UDF-2.01 2.3.6.1 1972 uint8 _record_display_attributes; //!< To be set to 0 per UDF-2.01 2.3.6.2 1973 uint8 _record_length; //!< To be set to 0 per UDF-2.01 2.3.6.3 1974 uint64 _information_length; 1975 uint64 _logical_blocks_recorded; //!< To be 0 for files and dirs with embedded data 1976 timestamp _access_date_and_time; 1977 timestamp _modification_date_and_time; 1978 timestamp _creation_date_and_time; // <== EXTENDED FILE ENTRY ONLY 1979 timestamp _attribute_date_and_time; 1980 /*! \brief Initially 1, may be incremented upon user request. */ 1981 uint32 _checkpoint; 1982 uint32 _reserved; // <== EXTENDED FILE ENTRY ONLY 1983 long_address _extended_attribute_icb; 1984 long_address _stream_directory_icb; // <== EXTENDED FILE ENTRY ONLY 1985 entity_id _implementation_id; 1986 /*! \brief The unique id identifying this file entry 1987 1988 The id of the root directory of a file set shall be 0. 1989 1990 \todo Detail the system specific requirements for unique ids from UDF-2.01 3.2.1.1 1991 */ 1992 uint64 _unique_id; 1993 uint32 _extended_attributes_length; 1994 uint32 _allocation_descriptors_length; 1995 1996 }; 1997 1998 1999 }; // namespace Udf 2000 2001 #endif // _UDF_DISK_STRUCTURES_H 2002 2003