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, UDF-2.50 2.2.6 1283 */ 1284 struct logical_volume_integrity_descriptor { 1285 public: 1286 void dump() const; 1287 1288 descriptor_tag& tag() { return _tag; } 1289 const descriptor_tag& tag() const { return _tag; } 1290 1291 timestamp& recording_time() { return _recording_time; } 1292 const timestamp& recording_time() const { return _recording_time; } 1293 1294 uint32 integrity_type() const { return B_LENDIAN_TO_HOST_INT32(_integrity_type); } 1295 1296 extent_address& next_integrity_extent() { return _next_integrity_extent; } 1297 const extent_address& next_integrity_extent() const { return _next_integrity_extent; } 1298 1299 array<uint8, 32>& logical_volume_contents_use() { return _logical_volume_contents_use; } 1300 const array<uint8, 32>& logical_volume_contents_use() const { return _logical_volume_contents_use; } 1301 1302 uint32 partition_count() const { return B_LENDIAN_TO_HOST_INT32(_partition_count); } 1303 uint32 implementation_use_length() const { return B_LENDIAN_TO_HOST_INT32(_implementation_use_length); } 1304 1305 /*! \todo double-check the pointer arithmetic here. */ 1306 uint32* free_space_table() { return reinterpret_cast<uint32*>(this+80); } 1307 const uint32* free_space_table() const { return reinterpret_cast<const uint32*>(this+80); } 1308 uint32* size_table() { return reinterpret_cast<uint32*>(free_space_table()+partition_count()*sizeof(uint32)); } 1309 const uint32* size_table() const { return reinterpret_cast<const uint32*>(free_space_table()+partition_count()*sizeof(uint32)); } 1310 uint8* implementation_use() { return reinterpret_cast<uint8*>(size_table()+partition_count()*sizeof(uint32)); } 1311 const uint8* implementation_use() const { return reinterpret_cast<const uint8*>(size_table()+partition_count()*sizeof(uint32)); } 1312 1313 // accessors for fields stored in implementation_use() field per UDF-2.50 2.2.6.4 1314 entity_id& id() { return _accessor().id; } 1315 const entity_id& id() const { return _accessor().id; } 1316 uint32 file_count() const { return B_LENDIAN_TO_HOST_INT32(_accessor().file_count); } 1317 uint32 directory_count() const { return B_LENDIAN_TO_HOST_INT32(_accessor().directory_count); } 1318 uint16 minimum_udf_read_revision() const { return B_LENDIAN_TO_HOST_INT16(_accessor().minimum_udf_read_revision); } 1319 uint16 minimum_udf_write_revision() const { return B_LENDIAN_TO_HOST_INT16(_accessor().minimum_udf_write_revision); } 1320 uint16 maximum_udf_write_revision() const { return B_LENDIAN_TO_HOST_INT16(_accessor().maximum_udf_write_revision); } 1321 1322 // set functions 1323 void set_integrity_type(uint32 type) { _integrity_type = B_HOST_TO_LENDIAN_INT32(type); } 1324 void set_partition_count(uint32 count) { _partition_count = B_HOST_TO_LENDIAN_INT32(count); } 1325 void set_impelementation_use_length(uint32 length) { _implementation_use_length = B_HOST_TO_LENDIAN_INT32(length); } 1326 1327 // set functions for fields stored in implementation_use() field per UDF-2.50 2.2.6.4 1328 void set_file_count(uint32 count) { _accessor().file_count = B_HOST_TO_LENDIAN_INT32(count); } 1329 void set_directory_count(uint32 count) { _accessor().directory_count = B_HOST_TO_LENDIAN_INT32(count); } 1330 void set_minimum_udf_read_revision(uint16 revision) { _accessor().minimum_udf_read_revision = B_HOST_TO_LENDIAN_INT16(revision); } 1331 void set_minimum_udf_write_revision(uint16 revision) { _accessor().minimum_udf_write_revision = B_HOST_TO_LENDIAN_INT16(revision); } 1332 void set_maximum_udf_write_revision(uint16 revision) { _accessor().maximum_udf_write_revision = B_HOST_TO_LENDIAN_INT16(revision); } 1333 1334 private: 1335 struct _lvid_implementation_use_accessor { 1336 entity_id id; 1337 uint32 file_count; 1338 uint32 directory_count; 1339 uint16 minimum_udf_read_revision; 1340 uint16 minimum_udf_write_revision; 1341 uint16 maximum_udf_write_revision; 1342 }; 1343 1344 _lvid_implementation_use_accessor& _accessor() { 1345 return *reinterpret_cast<_lvid_implementation_use_accessor*>(implementation_use()); 1346 } 1347 const _lvid_implementation_use_accessor& _accessor() const { 1348 return *reinterpret_cast<const _lvid_implementation_use_accessor*>(implementation_use()); 1349 } 1350 1351 descriptor_tag _tag; 1352 timestamp _recording_time; 1353 uint32 _integrity_type; 1354 extent_address _next_integrity_extent; 1355 array<uint8, 32> _logical_volume_contents_use; 1356 uint32 _partition_count; 1357 uint32 _implementation_use_length; 1358 1359 } __attribute__((packed)); 1360 1361 /*! \brief Logical volume integrity types 1362 */ 1363 enum { 1364 INTEGRITY_OPEN = 0, 1365 INTEGRITY_CLOSED = 1, 1366 }; 1367 1368 //---------------------------------------------------------------------- 1369 // ECMA-167 Part 4 1370 //---------------------------------------------------------------------- 1371 1372 1373 1374 /*! \brief File set descriptor 1375 1376 Contains all the pertinent info about a file set (i.e. a hierarchy of files) 1377 1378 According to UDF-2.01, only one file set descriptor shall be recorded, 1379 except on WORM media, where the following rules apply: 1380 - Multiple file sets are allowed only on WORM media 1381 - The default file set shall be the one with highest value \c file_set_number field. 1382 - Only the default file set may be flagged as writeable. All others shall be 1383 flagged as "hard write protect". 1384 - No writeable file set may reference metadata structures which are referenced 1385 (directly or indirectly) by any other file set. Writeable file sets may, however, 1386 reference actual file data extents that are also referenced by other file sets. 1387 */ 1388 struct file_set_descriptor { 1389 void dump() const; 1390 1391 // Get functions 1392 const descriptor_tag & tag() const { return _tag; } 1393 descriptor_tag & tag() { return _tag; } 1394 1395 const timestamp& recording_date_and_time() const { return _recording_date_and_time; } 1396 timestamp& recording_date_and_time() { return _recording_date_and_time; } 1397 1398 uint16 interchange_level() const { return B_LENDIAN_TO_HOST_INT16(_interchange_level); } 1399 uint16 max_interchange_level() const { return B_LENDIAN_TO_HOST_INT16(_max_interchange_level); } 1400 uint32 character_set_list() const { return B_LENDIAN_TO_HOST_INT32(_character_set_list); } 1401 uint32 max_character_set_list() const { return B_LENDIAN_TO_HOST_INT32(_max_character_set_list); } 1402 uint32 file_set_number() const { return B_LENDIAN_TO_HOST_INT32(_file_set_number); } 1403 uint32 file_set_descriptor_number() const { return B_LENDIAN_TO_HOST_INT32(_file_set_descriptor_number); } 1404 1405 const charspec& logical_volume_id_character_set() const { return _logical_volume_id_character_set; } 1406 charspec& logical_volume_id_character_set() { return _logical_volume_id_character_set; } 1407 1408 const array<char, 128>& logical_volume_id() const { return _logical_volume_id; } 1409 array<char, 128>& logical_volume_id() { return _logical_volume_id; } 1410 1411 const charspec& file_set_id_character_set() const { return _file_set_id_character_set; } 1412 charspec& file_set_id_character_set() { return _file_set_id_character_set; } 1413 1414 const array<char, 32>& file_set_id() const { return _file_set_id; } 1415 array<char, 32>& file_set_id() { return _file_set_id; } 1416 1417 const array<char, 32>& copyright_file_id() const { return _copyright_file_id; } 1418 array<char, 32>& copyright_file_id() { return _copyright_file_id; } 1419 1420 const array<char, 32>& abstract_file_id() const { return _abstract_file_id; } 1421 array<char, 32>& abstract_file_id() { return _abstract_file_id; } 1422 1423 const long_address& root_directory_icb() const { return _root_directory_icb; } 1424 long_address& root_directory_icb() { return _root_directory_icb; } 1425 1426 const entity_id& domain_id() const { return _domain_id; } 1427 entity_id& domain_id() { return _domain_id; } 1428 1429 const long_address& next_extent() const { return _next_extent; } 1430 long_address& next_extent() { return _next_extent; } 1431 1432 const long_address& system_stream_directory_icb() const { return _system_stream_directory_icb; } 1433 long_address& system_stream_directory_icb() { return _system_stream_directory_icb; } 1434 1435 const array<uint8, 32>& reserved() const { return _reserved; } 1436 array<uint8, 32>& reserved() { return _reserved; } 1437 1438 // Set functions 1439 void set_interchange_level(uint16 level) { _interchange_level = B_HOST_TO_LENDIAN_INT16(level); } 1440 void set_max_interchange_level(uint16 level) { _max_interchange_level = B_HOST_TO_LENDIAN_INT16(level); } 1441 void set_character_set_list(uint32 list) { _character_set_list = B_HOST_TO_LENDIAN_INT32(list); } 1442 void set_max_character_set_list(uint32 list) { _max_character_set_list = B_HOST_TO_LENDIAN_INT32(list); } 1443 void set_file_set_number(uint32 number) { _file_set_number = B_HOST_TO_LENDIAN_INT32(number); } 1444 void set_file_set_descriptor_number(uint32 number) { _file_set_descriptor_number = B_HOST_TO_LENDIAN_INT32(number); } 1445 private: 1446 descriptor_tag _tag; 1447 timestamp _recording_date_and_time; 1448 uint16 _interchange_level; //!< To be set to 3 (see UDF-2.01 2.3.2.1) 1449 uint16 _max_interchange_level; //!< To be set to 3 (see UDF-2.01 2.3.2.2) 1450 uint32 _character_set_list; 1451 uint32 _max_character_set_list; 1452 uint32 _file_set_number; 1453 uint32 _file_set_descriptor_number; 1454 charspec _logical_volume_id_character_set; //!< To be set to kCSOCharspec 1455 array<char, 128> _logical_volume_id; 1456 charspec _file_set_id_character_set; 1457 array<char, 32> _file_set_id; 1458 array<char, 32> _copyright_file_id; 1459 array<char, 32> _abstract_file_id; 1460 long_address _root_directory_icb; 1461 entity_id _domain_id; 1462 long_address _next_extent; 1463 long_address _system_stream_directory_icb; 1464 array<uint8, 32> _reserved; 1465 } __attribute__((packed)); 1466 1467 1468 /*! \brief Partition header descriptor 1469 1470 Contains references to unallocated and freed space data structures. 1471 1472 Note that unallocated space is space ready to be written with no 1473 preprocessing. Freed space is space needing preprocessing (i.e. 1474 a special write pass) before use. 1475 1476 Per UDF-2.01 2.3.3, the use of tables or bitmaps shall be consistent, 1477 i.e. only one type or the other shall be used, not both. 1478 1479 To indicate disuse of a certain field, the fields of the allocation 1480 descriptor shall all be set to 0. 1481 1482 See also: ECMA-167 4/14.3, UDF-2.01 2.2.3 1483 */ 1484 struct partition_header_descriptor { 1485 long_address unallocated_space_table; 1486 long_address unallocated_space_bitmap; 1487 /*! Unused, per UDF-2.01 2.2.3 */ 1488 long_address partition_integrity_table; 1489 long_address freed_space_table; 1490 long_address freed_space_bitmap; 1491 uint8 reserved[88]; 1492 } __attribute__((packed)); 1493 1494 #define kMaxFileIdSize (sizeof(file_id_descriptor)+512+3) 1495 1496 /*! \brief File identifier descriptor 1497 1498 Identifies the name of a file entry, and the location of its corresponding 1499 ICB. 1500 1501 See also: ECMA-167 4/14.4, UDF-2.01 2.3.4 1502 1503 \todo Check pointer arithmetic 1504 */ 1505 struct file_id_descriptor { 1506 public: 1507 void dump() const; 1508 1509 descriptor_tag & tag() { return _tag; } 1510 const descriptor_tag & tag() const { return _tag; } 1511 1512 uint16 version_number() const { return B_LENDIAN_TO_HOST_INT16(_version_number); } 1513 1514 uint8 characteristics() const { return _characteristics; } 1515 1516 bool may_be_hidden() const { 1517 characteristics_accessor c; 1518 c.all = characteristics(); 1519 return c.bits.may_be_hidden; 1520 } 1521 1522 bool is_directory() const { 1523 characteristics_accessor c; 1524 c.all = characteristics(); 1525 return c.bits.is_directory; 1526 } 1527 1528 bool is_deleted() const { 1529 characteristics_accessor c; 1530 c.all = characteristics(); 1531 return c.bits.is_deleted; 1532 } 1533 1534 bool is_parent() const { 1535 characteristics_accessor c; 1536 c.all = characteristics(); 1537 return c.bits.is_parent; 1538 } 1539 1540 bool is_metadata_stream() const { 1541 characteristics_accessor c; 1542 c.all = characteristics(); 1543 return c.bits.is_metadata_stream; 1544 } 1545 1546 uint8 id_length() const { return _id_length; } 1547 1548 long_address& icb() { return _icb; } 1549 const long_address& icb() const { return _icb; } 1550 1551 uint8 implementation_use_length() const { return _implementation_use_length; } 1552 1553 /*! If implementation_use_length is greater than 0, the first 32 1554 bytes of implementation_use() shall be an entity_id identifying 1555 the implementation that generated the rest of the data in the 1556 implementation_use() field. 1557 */ 1558 uint8* implementation_use() { return ((uint8*)this)+(38); } 1559 char* id() { return ((char*)this)+(38)+implementation_use_length(); } 1560 const char* id() const { return ((const char*)this)+(38)+implementation_use_length(); } 1561 1562 uint16 structure_length() const { return (38) + id_length() + implementation_use_length(); } 1563 uint16 padding_length() const { return ((structure_length()+3)/4)*4 - structure_length(); } 1564 uint16 total_length() const { return structure_length() + padding_length(); } 1565 1566 // Set functions 1567 void set_version_number(uint16 number) { _version_number = B_HOST_TO_LENDIAN_INT16(number); } 1568 1569 void set_characteristics(uint8 characteristics) { _characteristics = characteristics; } 1570 1571 void set_may_be_hidden(bool how) { 1572 characteristics_accessor c; 1573 c.all = characteristics(); 1574 c.bits.may_be_hidden = how; 1575 set_characteristics(c.all); 1576 } 1577 1578 void set_is_directory(bool how) { 1579 characteristics_accessor c; 1580 c.all = characteristics(); 1581 c.bits.is_directory = how; 1582 set_characteristics(c.all); 1583 } 1584 1585 void set_is_deleted(bool how) { 1586 characteristics_accessor c; 1587 c.all = characteristics(); 1588 c.bits.is_deleted = how; 1589 set_characteristics(c.all); 1590 } 1591 1592 void set_is_parent(bool how) { 1593 characteristics_accessor c; 1594 c.all = characteristics(); 1595 c.bits.is_parent = how; 1596 set_characteristics(c.all); 1597 } 1598 1599 void set_is_metadata_stream(bool how) { 1600 characteristics_accessor c; 1601 c.all = characteristics(); 1602 c.bits.is_metadata_stream = how; 1603 set_characteristics(c.all); 1604 } 1605 1606 1607 void set_id_length(uint8 id_length) { _id_length = id_length; } 1608 void set_implementation_use_length(uint8 implementation_use_length) { _implementation_use_length = implementation_use_length; } 1609 1610 1611 1612 private: 1613 union characteristics_accessor { 1614 uint8 all; 1615 struct { 1616 uint8 may_be_hidden:1, 1617 is_directory:1, 1618 is_deleted:1, 1619 is_parent:1, 1620 is_metadata_stream:1, 1621 reserved_characteristics:3; 1622 } bits; 1623 }; 1624 1625 descriptor_tag _tag; 1626 /*! According to ECMA-167: 1 <= valid version_number <= 32767, 32768 <= reserved <= 65535. 1627 1628 However, according to UDF-2.01, there shall be exactly one version of 1629 a file, and it shall be 1. 1630 */ 1631 uint16 _version_number; 1632 /*! \todo Check UDF-2.01 2.3.4.2 for some more restrictions. */ 1633 uint8 _characteristics; 1634 uint8 _id_length; 1635 long_address _icb; 1636 uint8 _implementation_use_length; 1637 } __attribute__((packed)); 1638 1639 1640 /*! \brief Allocation extent descriptor 1641 1642 See also: ECMA-167 4/14.5 1643 */ 1644 struct allocation_extent_descriptor { 1645 descriptor_tag tag; 1646 uint32 previous_allocation_extent_location; 1647 uint32 length_of_allocation_descriptors; 1648 1649 /*! \todo Check that this is really how things work: */ 1650 uint8* allocation_descriptors() { return (uint8*)(this+sizeof(allocation_extent_descriptor)); } 1651 } __attribute__((packed)); 1652 1653 1654 /*! \brief icb_tag::file_type values 1655 1656 See also ECMA-167 4/14.6.6 1657 */ 1658 enum icb_file_types { 1659 ICB_TYPE_UNSPECIFIED = 0, 1660 ICB_TYPE_UNALLOCATED_SPACE_ENTRY, 1661 ICB_TYPE_PARTITION_INTEGRITY_ENTRY, 1662 ICB_TYPE_INDIRECT_ENTRY, 1663 ICB_TYPE_DIRECTORY, 1664 ICB_TYPE_REGULAR_FILE, 1665 ICB_TYPE_BLOCK_SPECIAL_DEVICE, 1666 ICB_TYPE_CHARACTER_SPECIAL_DEVICE, 1667 ICB_TYPE_EXTENDED_ATTRIBUTES_FILE, 1668 ICB_TYPE_FIFO, 1669 ICB_TYPE_ISSOCK, 1670 ICB_TYPE_TERMINAL, 1671 ICB_TYPE_SYMLINK, 1672 ICB_TYPE_STREAM_DIRECTORY, 1673 1674 ICB_TYPE_RESERVED_START = 14, 1675 ICB_TYPE_RESERVED_END = 247, 1676 1677 ICB_TYPE_CUSTOM_START = 248, 1678 ICB_TYPE_CUSTOM_END = 255, 1679 }; 1680 1681 /*! \brief idb_entry_tag::_flags::descriptor_flags() values 1682 1683 See also ECMA-167 4/14.6.8 1684 */ 1685 enum icb_descriptor_types { 1686 ICB_DESCRIPTOR_TYPE_SHORT = 0, 1687 ICB_DESCRIPTOR_TYPE_LONG, 1688 ICB_DESCRIPTOR_TYPE_EXTENDED, 1689 ICB_DESCRIPTOR_TYPE_EMBEDDED, 1690 }; 1691 1692 /*! \brief idb_entry_tag::strategy_type() values 1693 1694 See also UDF-2.50 2.3.5.1 1695 */ 1696 enum icb_strategy_types { 1697 ICB_STRATEGY_SINGLE = 4, 1698 ICB_STRATEGY_LINKED_LIST = 4096 1699 }; 1700 1701 /*! \brief ICB entry tag 1702 1703 Common tag found in all ICB entries (in addition to, and immediately following, 1704 the descriptor tag). 1705 1706 See also: ECMA-167 4/14.6, UDF-2.01 2.3.5 1707 */ 1708 struct icb_entry_tag { 1709 public: 1710 union flags_accessor { 1711 uint16 all_flags; 1712 struct { 1713 uint16 descriptor_flags:3, 1714 if_directory_then_sort:1, //!< To be set to 0 per UDF-2.01 2.3.5.4 1715 non_relocatable:1, 1716 archive:1, 1717 setuid:1, 1718 setgid:1, 1719 sticky:1, 1720 contiguous:1, 1721 system:1, 1722 transformed:1, 1723 multi_version:1, //!< To be set to 0 per UDF-2.01 2.3.5.4 1724 is_stream:1, 1725 reserved_icb_entry_flags:2; 1726 } flags; 1727 }; 1728 1729 public: 1730 void dump() const; 1731 1732 uint32 prior_recorded_number_of_direct_entries() const { return B_LENDIAN_TO_HOST_INT32(_prior_recorded_number_of_direct_entries); } 1733 uint16 strategy_type() const { return B_LENDIAN_TO_HOST_INT16(_strategy_type); } 1734 1735 array<uint8, 2>& strategy_parameters() { return _strategy_parameters; } 1736 const array<uint8, 2>& strategy_parameters() const { return _strategy_parameters; } 1737 1738 uint16 entry_count() const { return B_LENDIAN_TO_HOST_INT16(_entry_count); } 1739 uint8& reserved() { return _reserved; } 1740 uint8 file_type() const { return _file_type; } 1741 logical_block_address& parent_icb_location() { return _parent_icb_location; } 1742 const logical_block_address& parent_icb_location() const { return _parent_icb_location; } 1743 1744 uint16 flags() const { return B_LENDIAN_TO_HOST_INT16(_flags); } 1745 flags_accessor& flags_access() { return *reinterpret_cast<flags_accessor*>(&_flags); } 1746 1747 // flags accessor functions 1748 uint8 descriptor_flags() const { 1749 flags_accessor f; 1750 f.all_flags = flags(); 1751 return f.flags.descriptor_flags; 1752 } 1753 /* void set_descriptor_flags(uint8 value) { 1754 flags_accessor f; 1755 f.all_flags = flags(); 1756 f.flags.descriptor_flags = value; 1757 set_flags 1758 */ 1759 1760 void set_prior_recorded_number_of_direct_entries(uint32 entries) { _prior_recorded_number_of_direct_entries = B_LENDIAN_TO_HOST_INT32(entries); } 1761 void set_strategy_type(uint16 type) { _strategy_type = B_HOST_TO_LENDIAN_INT16(type); } 1762 1763 void set_entry_count(uint16 count) { _entry_count = B_LENDIAN_TO_HOST_INT16(count); } 1764 void set_file_type(uint8 type) { _file_type = type; } 1765 1766 void set_flags(uint16 flags) { _flags = B_LENDIAN_TO_HOST_INT16(flags); } 1767 1768 private: 1769 uint32 _prior_recorded_number_of_direct_entries; 1770 /*! Per UDF-2.01 2.3.5.1, only strategy types 4 and 4096 shall be supported. 1771 1772 \todo Describe strategy types here. 1773 */ 1774 uint16 _strategy_type; 1775 array<uint8, 2> _strategy_parameters; 1776 uint16 _entry_count; 1777 uint8 _reserved; 1778 /*! \brief icb_file_type value identifying the type of this icb entry */ 1779 uint8 _file_type; 1780 logical_block_address _parent_icb_location; 1781 uint16 _flags; 1782 } __attribute__((packed)); 1783 1784 /*! \brief Header portion of an ICB entry. 1785 */ 1786 struct icb_header { 1787 public: 1788 void dump() const; 1789 1790 descriptor_tag &tag() { return _tag; } 1791 const descriptor_tag &tag() const { return _tag; } 1792 1793 icb_entry_tag &icb_tag() { return _icb_tag; } 1794 const icb_entry_tag &icb_tag() const { return _icb_tag; } 1795 private: 1796 descriptor_tag _tag; 1797 icb_entry_tag _icb_tag; 1798 }; 1799 1800 /*! \brief Indirect ICB entry 1801 */ 1802 struct indirect_icb_entry { 1803 descriptor_tag tag; 1804 icb_entry_tag icb_tag; 1805 long_address indirect_icb; 1806 } __attribute__((packed)); 1807 1808 1809 /*! \brief Terminal ICB entry 1810 */ 1811 struct terminal_icb_entry { 1812 descriptor_tag tag; 1813 icb_entry_tag icb_tag; 1814 } __attribute__((packed)); 1815 1816 enum permissions { 1817 OTHER_EXECUTE = 0x0001, 1818 OTHER_WRITE = 0x0002, 1819 OTHER_READ = 0x0004, 1820 OTHER_ATTRIBUTES = 0x0008, 1821 OTHER_DELETE = 0x0010, 1822 GROUP_EXECUTE = 0x0020, 1823 GROUP_WRITE = 0x0040, 1824 GROUP_READ = 0x0080, 1825 GROUP_ATTRIBUTES = 0x0100, 1826 GROUP_DELETE = 0x0200, 1827 USER_EXECUTE = 0x0400, 1828 USER_WRITE = 0x0800, 1829 USER_READ = 0x1000, 1830 USER_ATTRIBUTES = 0x2000, 1831 USER_DELETE = 0x4000, 1832 }; 1833 1834 /*! \brief File ICB entry 1835 1836 See also: ECMA-167 4/14.9 1837 1838 \todo Check pointer math. 1839 */ 1840 struct file_icb_entry { 1841 void dump() const; 1842 1843 // get functions 1844 descriptor_tag & tag() { return _tag; } 1845 const descriptor_tag & tag() const { return _tag; } 1846 1847 icb_entry_tag& icb_tag() { return _icb_tag; } 1848 const icb_entry_tag& icb_tag() const { return _icb_tag; } 1849 1850 uint32 uid() const { return B_LENDIAN_TO_HOST_INT32(_uid); } 1851 uint32 gid() const { return B_LENDIAN_TO_HOST_INT32(_gid); } 1852 uint32 permissions() const { return B_LENDIAN_TO_HOST_INT32(_permissions); } 1853 uint16 file_link_count() const { return B_LENDIAN_TO_HOST_INT16(_file_link_count); } 1854 uint8 record_format() const { return _record_format; } 1855 uint8 record_display_attributes() const { return _record_display_attributes; } 1856 uint8 record_length() const { return _record_length; } 1857 uint64 information_length() const { return B_LENDIAN_TO_HOST_INT64(_information_length); } 1858 uint64 logical_blocks_recorded() const { return B_LENDIAN_TO_HOST_INT64(_logical_blocks_recorded); } 1859 1860 timestamp& access_date_and_time() { return _access_date_and_time; } 1861 const timestamp& access_date_and_time() const { return _access_date_and_time; } 1862 1863 timestamp& modification_date_and_time() { return _modification_date_and_time; } 1864 const timestamp& modification_date_and_time() const { return _modification_date_and_time; } 1865 1866 timestamp& attribute_date_and_time() { return _attribute_date_and_time; } 1867 const timestamp& attribute_date_and_time() const { return _attribute_date_and_time; } 1868 1869 uint32 checkpoint() const { return B_LENDIAN_TO_HOST_INT32(_checkpoint); } 1870 1871 long_address& extended_attribute_icb() { return _extended_attribute_icb; } 1872 const long_address& extended_attribute_icb() const { return _extended_attribute_icb; } 1873 1874 entity_id& implementation_id() { return _implementation_id; } 1875 const entity_id& implementation_id() const { return _implementation_id; } 1876 1877 uint64 unique_id() const { return B_LENDIAN_TO_HOST_INT64(_unique_id); } 1878 uint32 extended_attributes_length() const { return B_LENDIAN_TO_HOST_INT32(_extended_attributes_length); } 1879 uint32 allocation_descriptors_length() const { return B_LENDIAN_TO_HOST_INT32(_allocation_descriptors_length); } 1880 1881 uint8* extended_attributes() const { return ((uint8*)(this))+sizeof(file_icb_entry); } 1882 uint8* allocation_descriptors() const { return ((uint8*)(this))+sizeof(file_icb_entry)+extended_attributes_length(); } 1883 1884 // set functions 1885 void set_uid(uint32 uid) { _uid = B_HOST_TO_LENDIAN_INT32(uid); } 1886 void set_gid(uint32 gid) { _gid = B_HOST_TO_LENDIAN_INT32(gid); } 1887 void set_permissions(uint32 permissions) { _permissions = B_HOST_TO_LENDIAN_INT32(permissions); } 1888 1889 void set_file_link_count(uint16 count) { _file_link_count = B_HOST_TO_LENDIAN_INT16(count); } 1890 void set_record_format(uint8 format) { _record_format = format; } 1891 void set_record_display_attributes(uint8 attributes) { _record_display_attributes = attributes; } 1892 void set_record_length(uint8 length) { _record_length = length; } 1893 1894 void set_information_length(uint64 length) { _information_length = B_HOST_TO_LENDIAN_INT64(length); } 1895 void set_logical_blocks_recorded(uint64 blocks) { _logical_blocks_recorded = B_HOST_TO_LENDIAN_INT64(blocks); } 1896 1897 void set_checkpoint(uint32 checkpoint) { _checkpoint = B_HOST_TO_LENDIAN_INT32(checkpoint); } 1898 1899 void set_unique_id(uint64 id) { _unique_id = B_HOST_TO_LENDIAN_INT64(id); } 1900 1901 void set_extended_attributes_length(uint32 length) { _extended_attributes_length = B_HOST_TO_LENDIAN_INT32(length); } 1902 void set_allocation_descriptors_length(uint32 length) { _allocation_descriptors_length = B_HOST_TO_LENDIAN_INT32(length); } 1903 1904 private: 1905 descriptor_tag _tag; 1906 icb_entry_tag _icb_tag; 1907 uint32 _uid; 1908 uint32 _gid; 1909 /*! \todo List perms in comment and add handy union thingy */ 1910 uint32 _permissions; 1911 /*! Identifies the number of file identifier descriptors referencing 1912 this icb. 1913 */ 1914 uint16 _file_link_count; 1915 uint8 _record_format; //!< To be set to 0 per UDF-2.01 2.3.6.1 1916 uint8 _record_display_attributes; //!< To be set to 0 per UDF-2.01 2.3.6.2 1917 uint8 _record_length; //!< To be set to 0 per UDF-2.01 2.3.6.3 1918 uint64 _information_length; 1919 uint64 _logical_blocks_recorded; //!< To be 0 for files and dirs with embedded data 1920 timestamp _access_date_and_time; 1921 timestamp _modification_date_and_time; 1922 1923 // NOTE: data members following this point in the descriptor are in 1924 // different locations in extended file entries 1925 1926 timestamp _attribute_date_and_time; 1927 /*! \brief Initially 1, may be incremented upon user request. */ 1928 uint32 _checkpoint; 1929 long_address _extended_attribute_icb; 1930 entity_id _implementation_id; 1931 /*! \brief The unique id identifying this file entry 1932 1933 The id of the root directory of a file set shall be 0. 1934 1935 \todo Detail the system specific requirements for unique ids from UDF-2.01 1936 */ 1937 uint64 _unique_id; 1938 uint32 _extended_attributes_length; 1939 uint32 _allocation_descriptors_length; 1940 1941 }; 1942 1943 1944 /*! \brief Extended file ICB entry 1945 1946 See also: ECMA-167 4/14.17 1947 1948 \todo Check pointer math. 1949 */ 1950 struct extended_file_icb_entry { 1951 void dump() const; 1952 1953 // get functions 1954 descriptor_tag & tag() { return _tag; } 1955 const descriptor_tag & tag() const { return _tag; } 1956 1957 icb_entry_tag& icb_tag() { return _icb_tag; } 1958 const icb_entry_tag& icb_tag() const { return _icb_tag; } 1959 1960 uint32 uid() const { return B_LENDIAN_TO_HOST_INT32(_uid); } 1961 uint32 gid() const { return B_LENDIAN_TO_HOST_INT32(_gid); } 1962 uint32 permissions() const { return B_LENDIAN_TO_HOST_INT32(_permissions); } 1963 uint16 file_link_count() const { return B_LENDIAN_TO_HOST_INT16(_file_link_count); } 1964 uint8 record_format() const { return _record_format; } 1965 uint8 record_display_attributes() const { return _record_display_attributes; } 1966 uint8 record_length() const { return _record_length; } 1967 uint64 information_length() const { return B_LENDIAN_TO_HOST_INT64(_information_length); } 1968 uint64 logical_blocks_recorded() const { return B_LENDIAN_TO_HOST_INT64(_logical_blocks_recorded); } 1969 1970 timestamp& access_date_and_time() { return _access_date_and_time; } 1971 const timestamp& access_date_and_time() const { return _access_date_and_time; } 1972 1973 timestamp& modification_date_and_time() { return _modification_date_and_time; } 1974 const timestamp& modification_date_and_time() const { return _modification_date_and_time; } 1975 1976 timestamp& creation_date_and_time() { return _creation_date_and_time; } 1977 const timestamp& creation_date_and_time() const { return _creation_date_and_time; } 1978 1979 timestamp& attribute_date_and_time() { return _attribute_date_and_time; } 1980 const timestamp& attribute_date_and_time() const { return _attribute_date_and_time; } 1981 1982 uint32 checkpoint() const { return B_LENDIAN_TO_HOST_INT32(_checkpoint); } 1983 1984 long_address& extended_attribute_icb() { return _extended_attribute_icb; } 1985 const long_address& extended_attribute_icb() const { return _extended_attribute_icb; } 1986 1987 long_address& stream_directory_icb() { return _stream_directory_icb; } 1988 const long_address& stream_directory_icb() const { return _stream_directory_icb; } 1989 1990 entity_id& implementation_id() { return _implementation_id; } 1991 const entity_id& implementation_id() const { return _implementation_id; } 1992 1993 uint64 unique_id() const { return B_LENDIAN_TO_HOST_INT64(_unique_id); } 1994 uint32 extended_attributes_length() const { return B_LENDIAN_TO_HOST_INT32(_extended_attributes_length); } 1995 uint32 allocation_descriptors_length() const { return B_LENDIAN_TO_HOST_INT32(_allocation_descriptors_length); } 1996 1997 uint8* extended_attributes() const { return (uint8*)(this+sizeof(extended_file_icb_entry)); } 1998 uint8* allocation_descriptors() const { return (uint8*)(this+sizeof(sizeof(extended_file_icb_entry))+extended_attributes_length()); } 1999 2000 // set functions 2001 void set_uid(uint32 uid) { _uid = B_HOST_TO_LENDIAN_INT32(uid); } 2002 void set_gid(uint32 gid) { _gid = B_HOST_TO_LENDIAN_INT32(gid); } 2003 void set_permissions(uint32 permissions) { _permissions = B_HOST_TO_LENDIAN_INT32(permissions); } 2004 2005 void set_file_link_count(uint16 count) { _file_link_count = B_HOST_TO_LENDIAN_INT16(count); } 2006 void set_record_format(uint8 format) { _record_format = format; } 2007 void set_record_display_attributes(uint8 attributes) { _record_display_attributes = attributes; } 2008 void set_record_length(uint8 length) { _record_length = length; } 2009 2010 void set_information_length(uint64 length) { _information_length = B_HOST_TO_LENDIAN_INT64(length); } 2011 void set_logical_blocks_recorded(uint64 blocks) { _logical_blocks_recorded = B_HOST_TO_LENDIAN_INT64(blocks); } 2012 2013 void set_checkpoint(uint32 checkpoint) { _checkpoint = B_HOST_TO_LENDIAN_INT32(checkpoint); } 2014 void set_reserved(uint32 reserved) { _reserved = B_HOST_TO_LENDIAN_INT32(reserved); } 2015 2016 void set_unique_id(uint64 id) { _unique_id = B_HOST_TO_LENDIAN_INT64(id); } 2017 2018 void set_extended_attributes_length(uint32 length) { _extended_attributes_length = B_HOST_TO_LENDIAN_INT32(length); } 2019 void set_allocation_descriptors_length(uint32 length) { _allocation_descriptors_length = B_HOST_TO_LENDIAN_INT32(length); } 2020 2021 private: 2022 descriptor_tag _tag; 2023 icb_entry_tag _icb_tag; 2024 uint32 _uid; 2025 uint32 _gid; 2026 /*! \todo List perms in comment and add handy union thingy */ 2027 uint32 _permissions; 2028 /*! Identifies the number of file identifier descriptors referencing 2029 this icb. 2030 */ 2031 uint16 _file_link_count; 2032 uint8 _record_format; //!< To be set to 0 per UDF-2.01 2.3.6.1 2033 uint8 _record_display_attributes; //!< To be set to 0 per UDF-2.01 2.3.6.2 2034 uint8 _record_length; //!< To be set to 0 per UDF-2.01 2.3.6.3 2035 uint64 _information_length; 2036 uint64 _logical_blocks_recorded; //!< To be 0 for files and dirs with embedded data 2037 timestamp _access_date_and_time; 2038 timestamp _modification_date_and_time; 2039 timestamp _creation_date_and_time; // <== EXTENDED FILE ENTRY ONLY 2040 timestamp _attribute_date_and_time; 2041 /*! \brief Initially 1, may be incremented upon user request. */ 2042 uint32 _checkpoint; 2043 uint32 _reserved; // <== EXTENDED FILE ENTRY ONLY 2044 long_address _extended_attribute_icb; 2045 long_address _stream_directory_icb; // <== EXTENDED FILE ENTRY ONLY 2046 entity_id _implementation_id; 2047 /*! \brief The unique id identifying this file entry 2048 2049 The id of the root directory of a file set shall be 0. 2050 2051 \todo Detail the system specific requirements for unique ids from UDF-2.01 3.2.1.1 2052 */ 2053 uint64 _unique_id; 2054 uint32 _extended_attributes_length; 2055 uint32 _allocation_descriptors_length; 2056 2057 }; 2058 2059 2060 }; // namespace Udf 2061 2062 #endif // _UDF_DISK_STRUCTURES_H 2063 2064