1 /*
   2     libparted - a library for manipulating disk partitions
   3     Copyright (C) 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
   4 
   5     This program is free software; you can redistribute it and/or modify
   6     it under the terms of the GNU General Public License as published by
   7     the Free Software Foundation; either version 3 of the License, or
   8     (at your option) any later version.
   9 
  10     This program is distributed in the hope that it will be useful,
  11     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13     GNU General Public License for more details.
  14 
  15     You should have received a copy of the GNU General Public License
  16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  17 */
  18 
  19 #ifndef _HFS_H
  20 #define _HFS_H
  21 
  22 /* WARNING : bn is used 2 times in theses macro */
  23 /* so _never_ use side effect operators when using them */
  24 #define TST_BLOC_OCCUPATION(tab,bn) \
  25         (((tab)[(bn)/8])  &  (1<<(7-((bn)&7))))
  26 #define SET_BLOC_OCCUPATION(tab,bn) \
  27         (((tab)[(bn)/8]) |=  (1<<(7-((bn)&7))))
  28 #define CLR_BLOC_OCCUPATION(tab,bn) \
  29         (((tab)[(bn)/8]) &= ~(1<<(7-((bn)&7))))
  30 
  31 /* Maximum number of blocks for the copy buffers */
  32 #define BLOCK_MAX_BUFF  256
  33 /* Maximum size of the copy buffers, in bytes */
  34 #define BYTES_MAX_BUFF  8388608
  35 
  36 /* Apple Creator Codes follow */
  37 #define HFSP_IMPL_Shnk  0x53686e6b      /* in use */
  38 #define HFSP_IMPL_Xpnd  0x58706e64      /* reserved */
  39 #define HFSP_IMPL_Resz  0x5265737a      /* reserved */
  40 #define HFSP_IMPL_PHpx  0x50482b78      /* reserved */
  41 #define HFSP_IMPL_traP  0x74726150      /* reserved */
  42 #define HFSP_IMPL_GnuP  0x476e7550      /* reserved */
  43 
  44 #define HFS_SIGNATURE   0x4244          /* 'BD' */
  45 #define HFSP_SIGNATURE  0x482B          /* 'H+' */
  46 #define HFSX_SIGNATURE  0x4858          /* 'HX' */
  47 
  48 #define HFSP_VERSION     4
  49 #define HFSX_VERSION     5
  50 
  51 #define HFS_HARD_LOCK    7
  52 #define HFS_UNMOUNTED    8
  53 #define HFS_BAD_SPARED   9
  54 #define HFS_SOFT_LOCK   15
  55 #define HFSP_NO_CACHE   10
  56 #define HFSP_INCONSISTENT 11
  57 #define HFSP_REUSE_CNID 12
  58 #define HFSP_JOURNALED  13
  59 
  60 #define HFS_IDX_NODE    0x00
  61 #define HFS_HDR_NODE    0x01
  62 #define HFS_MAP_NODE    0x02
  63 #define HFS_LEAF_NODE   0xFF
  64 
  65 #define HFS_FIRST_REC   0x0E
  66 #define HFS_NSD_HD_REC  0x78
  67 #define HFS_MAP_REC     0xF8
  68 
  69 #define HFS_DATA_FORK   0x00
  70 #define HFS_RES_FORK    0xFF
  71 
  72 #define HFS_CAT_DIR     0x01
  73 #define HFS_CAT_FILE    0x02
  74 #define HFS_CAT_DIR_TH  0x03
  75 #define HFS_CAT_FILE_TH 0x04
  76 
  77 #define HFSP_ATTR_INLINE        0x10
  78 #define HFSP_ATTR_FORK          0x20
  79 #define HFSP_ATTR_EXTENTS       0x30
  80 
  81 #define HFS_ROOT_PAR_ID         0x01
  82 #define HFS_ROOT_DIR_ID         0x02
  83 #define HFS_XTENT_ID            0x03
  84 #define HFS_CATALOG_ID          0x04
  85 #define HFS_BAD_BLOCK_ID        0x05
  86 #define HFSP_ALLOC_ID           0x06
  87 #define HFSP_STARTUP_ID         0x07
  88 #define HFSP_ATTRIB_ID          0x08
  89 #define HFSP_BOGUS_ID           0x0F
  90 #define HFSP_FIRST_AV_ID        0x10
  91 
  92 #define HFSJ_JOURN_IN_FS        0x00
  93 #define HFSJ_JOURN_OTHER_DEV    0x01
  94 #define HFSJ_JOURN_NEED_INIT    0x02
  95 
  96 #define HFSJ_HEADER_MAGIC       0x4a4e4c78
  97 #define HFSJ_ENDIAN_MAGIC       0x12345678
  98 
  99 #define HFSX_CASE_FOLDING       0xCF    /* case insensitive HFSX */
 100 #define HFSX_BINARY_COMPARE     0xBC    /* case sensitive   HFSX */
 101 
 102 #define HFS_EXT_NB      3
 103 #define HFSP_EXT_NB     8
 104 
 105 /* Define the filenames used by the FS extractor */
 106 #ifdef HFS_EXTRACT_FS
 107 
 108 #define HFS_MDB_FILENAME        "mdb.hfs"
 109 #define HFS_CATALOG_FILENAME    "catalog.hfs"
 110 #define HFS_EXTENTS_FILENAME    "extents.hfs"
 111 #define HFS_BITMAP_FILENAME     "bitmap.hfs"
 112 
 113 #define HFSP_VH_FILENAME        "vh.hfsplus"
 114 #define HFSP_CATALOG_FILENAME   "catalog.hfsplus"
 115 #define HFSP_EXTENTS_FILENAME   "extents.hfsplus"
 116 #define HFSP_BITMAP_FILENAME    "bitmap.hfsplus"
 117 #define HFSP_ATTRIB_FILENAME    "attributes.hfsplus"
 118 #define HFSP_STARTUP_FILENAME   "startup.hfsplus"
 119 
 120 #endif /* HFS_EXTRACT_FS */
 121 
 122 
 123 
 124 /* ----------------------------------- */
 125 /* --      HFS DATA STRUCTURES      -- */
 126 /* ----------------------------------- */
 127 
 128 #ifdef __sun
 129 #define __attribute__(X)        /*nothing*/
 130 #endif /* __sun */
 131 
 132 /* Extent descriptor */
 133 #ifdef __sun
 134 #pragma pack(1)
 135 #endif
 136 struct __attribute__ ((packed)) _HfsExtDescriptor {
 137         uint16_t        start_block;
 138         uint16_t        block_count;
 139 };
 140 #ifdef __sun
 141 #pragma pack()
 142 #endif
 143 typedef struct _HfsExtDescriptor HfsExtDescriptor;
 144 typedef HfsExtDescriptor HfsExtDataRec[HFS_EXT_NB];
 145 
 146 /* Volume header */
 147 #ifdef __sun
 148 #pragma pack(1)
 149 #endif
 150 struct __attribute__ ((packed)) _HfsMasterDirectoryBlock {
 151         uint16_t         signature;
 152         uint32_t         create_date;
 153         uint32_t         modify_date;
 154         uint16_t         volume_attributes;
 155         uint16_t         files_in_root;
 156         uint16_t         volume_bitmap_block;       /* in sectors */
 157         uint16_t         next_allocation;
 158         uint16_t         total_blocks;
 159         uint32_t         block_size;                /* in bytes */
 160         uint32_t         def_clump_size;            /* in bytes */
 161         uint16_t         start_block;               /* in sectors */
 162         uint32_t         next_free_node;
 163         uint16_t         free_blocks;
 164         uint8_t          name_length;
 165         char             name[27];
 166         uint32_t         backup_date;
 167         uint16_t         backup_number;
 168         uint32_t         write_count;
 169         uint32_t         extents_clump;
 170         uint32_t         catalog_clump;
 171         uint16_t         dirs_in_root;
 172         uint32_t         file_count;
 173         uint32_t         dir_count;
 174         uint32_t         finder_info[8];
 175         union __attribute__ ((packed)) {
 176                 struct __attribute__ ((packed)) {
 177                         uint16_t    volume_cache_size;    /* in blocks */
 178                         uint16_t    bitmap_cache_size;    /* in blocks */
 179                         uint16_t    common_cache_size;    /* in blocks */
 180                 } legacy;
 181                 struct __attribute__ ((packed)) {
 182                         uint16_t            signature;
 183                         HfsExtDescriptor    location;
 184                 } embedded;
 185         } old_new;
 186         uint32_t         extents_file_size;  /* in bytes, block size multiple */
 187         HfsExtDataRec    extents_file_rec;
 188         uint32_t         catalog_file_size;  /* in bytes, block size multiple */
 189         HfsExtDataRec    catalog_file_rec;
 190 };
 191 #ifdef __sun
 192 #pragma pack()
 193 #endif
 194 typedef struct _HfsMasterDirectoryBlock HfsMasterDirectoryBlock;
 195 
 196 /* B*-Tree Node Descriptor */
 197 #ifdef __sun
 198 #pragma pack(1)
 199 #endif
 200 struct __attribute__ ((packed)) _HfsNodeDescriptor {
 201         uint32_t        next;
 202         uint32_t        previous;
 203         int8_t          type;
 204         uint8_t         height;
 205         uint16_t        rec_nb;
 206         uint16_t        reserved;
 207 };
 208 #ifdef __sun
 209 #pragma pack()
 210 #endif
 211 typedef struct _HfsNodeDescriptor HfsNodeDescriptor;
 212 
 213 /* Header record of a whole B*-Tree */
 214 #ifdef __sun
 215 #pragma pack(1)
 216 #endif
 217 struct __attribute__ ((packed)) _HfsHeaderRecord {
 218         uint16_t        depth;
 219         uint32_t        root_node;
 220         uint32_t        leaf_records;
 221         uint32_t        first_leaf_node;
 222         uint32_t        last_leaf_node;
 223         uint16_t        node_size;
 224         uint16_t        max_key_len;
 225         uint32_t        total_nodes;
 226         uint32_t        free_nodes;
 227         int8_t          reserved[76];
 228 };
 229 #ifdef __sun
 230 #pragma pack()
 231 #endif
 232 typedef struct _HfsHeaderRecord HfsHeaderRecord;
 233 
 234 /* Catalog key for B*-Tree lookup in the catalog file */
 235 #ifdef __sun
 236 #pragma pack(1)
 237 #endif
 238 struct __attribute__ ((packed)) _HfsCatalogKey {
 239         uint8_t         key_length; /* length of the key without key_length */
 240         uint8_t         reserved;
 241         uint32_t        parent_ID;
 242         uint8_t         name_length;
 243         char            name[31];   /* in fact physicaly 1 upto 31 */
 244 };
 245 #ifdef __sun
 246 #pragma pack()
 247 #endif
 248 typedef struct _HfsCatalogKey HfsCatalogKey;
 249 
 250 /* Extents overflow key for B*-Tree lookup */
 251 #ifdef __sun
 252 #pragma pack(1)
 253 #endif
 254 struct __attribute__ ((packed)) _HfsExtentKey {
 255         uint8_t         key_length; /* length of the key without key_length */
 256         uint8_t         type;       /* data or ressource fork */
 257         uint32_t        file_ID;
 258         uint16_t        start;
 259 };
 260 #ifdef __sun
 261 #pragma pack()
 262 #endif
 263 typedef struct _HfsExtentKey HfsExtentKey;
 264 
 265 /* Catalog subdata case directory */
 266 #ifdef __sun
 267 #pragma pack(1)
 268 #endif
 269 struct __attribute__ ((packed)) _HfsDir {
 270         uint16_t        flags;
 271         uint16_t        valence;        /* number of files in this directory */
 272         uint32_t        dir_ID;
 273         uint32_t        create_date;
 274         uint32_t        modify_date;
 275         uint32_t        backup_date;
 276         int8_t          DInfo[16];      /* used by Finder, handle as reserved */
 277         int8_t          DXInfo[16];     /* used by Finder, handle as reserved */
 278         uint32_t        reserved[4];
 279 };
 280 #ifdef __sun
 281 #pragma pack()
 282 #endif
 283 typedef struct _HfsDir HfsDir;
 284 
 285 /* Catalog subdata case file */
 286 #ifdef __sun
 287 #pragma pack(1)
 288 #endif
 289 struct __attribute__ ((packed)) _HfsFile {
 290         int8_t          flags;
 291         int8_t          type;           /* should be 0 */
 292         int8_t          FInfo[16];      /* used by Finder, handle as reserved */
 293         uint32_t        file_ID;
 294         uint16_t        data_start_block;
 295         uint32_t        data_sz_byte;
 296         uint32_t        data_sz_block;
 297         uint16_t        res_start_block;
 298         uint32_t        res_sz_byte;
 299         uint32_t        res_sz_block;
 300         uint32_t        create_date;
 301         uint32_t        modify_date;
 302         uint32_t        backup_date;
 303         int8_t          FXInfo[16];     /* used by Finder, handle as reserved */
 304         uint16_t        clump_size;
 305         HfsExtDataRec   extents_data;
 306         HfsExtDataRec   extents_res;
 307         uint32_t        reserved;
 308 };
 309 #ifdef __sun
 310 #pragma pack()
 311 #endif
 312 typedef struct _HfsFile HfsFile;
 313 
 314 /* Catalog subdata case directory thread */
 315 #ifdef __sun
 316 #pragma pack(1)
 317 #endif
 318 struct __attribute__ ((packed)) _HfsDirTh {
 319         uint32_t        reserved[2];
 320         uint32_t        parent_ID;
 321         int8_t          name_length;
 322         char            name[31];
 323 };
 324 #ifdef __sun
 325 #pragma pack()
 326 #endif
 327 typedef struct _HfsDirTh HfsDirTh;
 328 
 329 /* Catalog subdata case file thread */
 330 typedef struct _HfsDirTh HfsFileTh;        /* same as directory thread */
 331 
 332 /* Catalog data */
 333 #ifdef __sun
 334 #pragma pack(1)
 335 #endif
 336 struct __attribute__ ((packed)) _HfsCatalog {
 337         int8_t          type;
 338         int8_t          reserved;
 339         union {
 340                 HfsDir       dir;
 341                 HfsFile      file;
 342                 HfsDirTh     dir_th;
 343                 HfsFileTh    file_th;
 344         } sel;
 345 };
 346 #ifdef __sun
 347 #pragma pack()
 348 #endif
 349 typedef struct _HfsCatalog HfsCatalog;
 350 
 351 
 352 
 353 /* ------------------------------------ */
 354 /* --      HFS+ DATA STRUCTURES      -- */
 355 /* ------------------------------------ */
 356 
 357 /* documented since 2004 in tn1150 */
 358 #ifdef __sun
 359 #pragma pack(1)
 360 #endif
 361 struct __attribute__ ((packed)) _HfsPPerms {
 362         uint32_t        owner_ID;
 363         uint32_t        group_ID;
 364         uint32_t        permissions;
 365         uint32_t        special_devices;
 366 };
 367 #ifdef __sun
 368 #pragma pack()
 369 #endif
 370 typedef struct _HfsPPerms HfsPPerms;
 371 
 372 /* HFS+ extent descriptor*/
 373 #ifdef __sun
 374 #pragma pack(1)
 375 #endif
 376 struct __attribute__ ((packed)) _HfsPExtDescriptor {
 377         uint32_t        start_block;
 378         uint32_t        block_count;
 379 };
 380 #ifdef __sun
 381 #pragma pack()
 382 #endif
 383 typedef struct _HfsPExtDescriptor HfsPExtDescriptor;
 384 typedef HfsPExtDescriptor HfsPExtDataRec[HFSP_EXT_NB];
 385 
 386 /* HFS+ fork data structure */
 387 #ifdef __sun
 388 #pragma pack(1)
 389 #endif
 390 struct __attribute__ ((packed)) _HfsPForkData {
 391         uint64_t        logical_size;
 392         uint32_t        clump_size;
 393         uint32_t        total_blocks;
 394         HfsPExtDataRec  extents;
 395 };
 396 #ifdef __sun
 397 #pragma pack()
 398 #endif
 399 typedef struct _HfsPForkData HfsPForkData;
 400 
 401 /* HFS+ catalog node ID */
 402 typedef uint32_t HfsPNodeID;
 403 
 404 /* HFS+ file names */
 405 typedef uint16_t unichar;
 406 #ifdef __sun
 407 #pragma pack(1)
 408 #endif
 409 struct __attribute__ ((packed)) _HfsPUniStr255 {
 410         uint16_t        length;
 411         unichar         unicode[255];        /* 1 upto 255 */
 412 };
 413 #ifdef __sun
 414 #pragma pack()
 415 #endif
 416 typedef struct _HfsPUniStr255 HfsPUniStr255;
 417 
 418 /* HFS+ volume header */
 419 #ifdef __sun
 420 #pragma pack(1)
 421 #endif
 422 struct __attribute__ ((packed)) _HfsPVolumeHeader {
 423         uint16_t        signature;
 424         uint16_t        version;
 425         uint32_t        attributes;
 426         uint32_t        last_mounted_version;
 427         uint32_t        journal_info_block;
 428         
 429         uint32_t        create_date;
 430         uint32_t        modify_date;
 431         uint32_t        backup_date;
 432         uint32_t        checked_date;
 433         
 434         uint32_t        file_count;
 435         uint32_t        dir_count;
 436         
 437         uint32_t        block_size;
 438         uint32_t        total_blocks;
 439         uint32_t        free_blocks;
 440         
 441         uint32_t        next_allocation;
 442         uint32_t        res_clump_size;
 443         uint32_t        data_clump_size;
 444         HfsPNodeID      next_catalog_ID;
 445         
 446         uint32_t        write_count;
 447         uint64_t        encodings_bitmap;
 448         
 449         uint8_t         finder_info[32];
 450         
 451         HfsPForkData    allocation_file;
 452         HfsPForkData    extents_file;
 453         HfsPForkData    catalog_file;
 454         HfsPForkData    attributes_file;
 455         HfsPForkData    startup_file;
 456 };
 457 #ifdef __sun
 458 #pragma pack()
 459 #endif
 460 typedef struct _HfsPVolumeHeader HfsPVolumeHeader;
 461 
 462 /* HFS+ B-Tree Node Descriptor. Same as HFS btree. */
 463 #ifdef __sun
 464 #pragma pack(1)
 465 #endif
 466 struct __attribute__ ((packed)) _HfsPNodeDescriptor {
 467         uint32_t        next;
 468         uint32_t        previous;
 469         int8_t          type;
 470         uint8_t         height;
 471         uint16_t        rec_nb;
 472         uint16_t        reserved;
 473 };
 474 #ifdef __sun
 475 #pragma pack()
 476 #endif
 477 typedef struct _HfsPNodeDescriptor HfsPNodeDescriptor;
 478 
 479 /* Header record of a whole HFS+ B-Tree. */
 480 #ifdef __sun
 481 #pragma pack(1)
 482 #endif
 483 struct __attribute__ ((packed)) _HfsPHeaderRecord {
 484         uint16_t        depth;
 485         uint32_t        root_node;
 486         uint32_t        leaf_records;
 487         uint32_t        first_leaf_node;
 488         uint32_t        last_leaf_node;
 489         uint16_t        node_size;
 490         uint16_t        max_key_len;
 491         uint32_t        total_nodes;
 492         uint32_t        free_nodes;        /* same as hfs btree until here */
 493         uint16_t        reserved1;
 494         
 495         uint32_t        clump_size;
 496         uint8_t         btree_type;        /* must be 0 for HFS+ B-Tree */
 497         uint8_t         key_compare_type; /* hfsx => 0xCF = case folding */
 498                                           /*         0xBC = binary compare */
 499                                           /* otherwise, reserved */
 500         uint32_t        attributes;
 501         uint32_t        reserved3[16];
 502 };
 503 #ifdef __sun
 504 #pragma pack()
 505 #endif
 506 typedef struct _HfsPHeaderRecord HfsPHeaderRecord;
 507 
 508 /* Catalog key for B-Tree lookup in the HFS+ catalog file */
 509 #ifdef __sun
 510 #pragma pack(1)
 511 #endif
 512 struct __attribute__ ((packed)) _HfsPCatalogKey {
 513         uint16_t        key_length;
 514         HfsPNodeID      parent_ID;
 515         HfsPUniStr255   node_name;
 516 };
 517 #ifdef __sun
 518 #pragma pack()
 519 #endif
 520 typedef struct _HfsPCatalogKey HfsPCatalogKey;
 521 
 522 /* HFS+ catalog subdata case dir */
 523 #ifdef __sun
 524 #pragma pack(1)
 525 #endif
 526 struct __attribute__ ((packed)) _HfsPDir {
 527         uint16_t        flags;
 528         uint32_t        valence;
 529         HfsPNodeID      dir_ID;
 530         uint32_t        create_date;
 531         uint32_t        modify_date;
 532         uint32_t        attrib_mod_date;
 533         uint32_t        access_date;
 534         uint32_t        backup_date;
 535         HfsPPerms       permissions;
 536         int8_t          DInfo[16];        /* used by Finder, handle as reserved */
 537         int8_t          DXInfo[16];       /* used by Finder, handle as reserved */
 538         uint32_t        text_encoding;
 539         uint32_t        reserved;
 540 };
 541 #ifdef __sun
 542 #pragma pack()
 543 #endif
 544 typedef struct _HfsPDir HfsPDir;
 545 
 546 /* HFS+ catalog subdata case file */
 547 #ifdef __sun
 548 #pragma pack(1)
 549 #endif
 550 struct __attribute__ ((packed)) _HfsPFile {
 551         uint16_t        flags;
 552         uint32_t        reserved1;
 553         HfsPNodeID      file_ID;
 554         uint32_t        create_date;
 555         uint32_t        modify_date;
 556         uint32_t        attrib_mod_date;
 557         uint32_t        access_date;
 558         uint32_t        backup_date;
 559         HfsPPerms       permissions;
 560         int8_t          FInfo[16];        /* used by Finder, handle as reserved */
 561         int8_t          FXInfo[16];       /* used by Finder, handle as reserved */
 562         uint32_t        text_encoding;
 563         uint32_t        reserved2;
 564         
 565         HfsPForkData    data_fork;
 566         HfsPForkData    res_fork;
 567 };
 568 #ifdef __sun
 569 #pragma pack()
 570 #endif
 571 typedef struct _HfsPFile HfsPFile;
 572 
 573 /* HFS+ catalog subdata case thread */
 574 #ifdef __sun
 575 #pragma pack(1)
 576 #endif
 577 struct __attribute__ ((packed)) _HfsPThread {
 578         int16_t         reserved;
 579         HfsPNodeID      parent_ID;
 580         HfsPUniStr255   node_name;
 581 };
 582 #ifdef __sun
 583 #pragma pack()
 584 #endif
 585 typedef struct _HfsPThread HfsPDirTh;
 586 typedef struct _HfsPThread HfsPFileTh;
 587 
 588 /* HFS+ Catalog leaf data */
 589 #ifdef __sun
 590 #pragma pack(1)
 591 #endif
 592 struct __attribute__ ((packed)) _HfsPCatalog {
 593         int16_t         type;
 594         union {
 595                 HfsPDir         dir;
 596                 HfsPFile        file;
 597                 HfsPDirTh       dir_th;
 598                 HfsPFileTh      file_th;
 599         } sel;
 600 };
 601 #ifdef __sun
 602 #pragma pack()
 603 #endif
 604 typedef struct _HfsPCatalog HfsPCatalog;
 605 
 606 /* HFS+ extents file key */
 607 #ifdef __sun
 608 #pragma pack(1)
 609 #endif
 610 struct __attribute__ ((packed)) _HfsPExtentKey {
 611         uint16_t        key_length;
 612         uint8_t         type;
 613         uint8_t         pad;
 614         HfsPNodeID      file_ID;
 615         uint32_t        start;
 616 };
 617 #ifdef __sun
 618 #pragma pack()
 619 #endif
 620 typedef struct _HfsPExtentKey HfsPExtentKey;
 621 
 622 /* extent file data is HfsPExtDataRec */
 623 
 624 /* Fork data attribute file */
 625 #ifdef __sun
 626 #pragma pack(1)
 627 #endif
 628 struct __attribute__ ((packed)) _HfsPForkDataAttr {
 629         uint32_t        record_type;
 630         uint32_t        reserved;
 631         union __attribute__ ((packed)) {
 632                 HfsPForkData        fork;
 633                 HfsPExtDataRec      extents;
 634         } fork_res;
 635 };
 636 #ifdef __sun
 637 #pragma pack()
 638 #endif
 639 typedef struct _HfsPForkDataAttr HfsPForkDataAttr;
 640 
 641 
 642 /* ----------- Journal data structures ----------- */
 643 
 644 /* Info block : stored in a block # defined in the VH */
 645 #ifdef __sun
 646 #pragma pack(1)
 647 #endif
 648 struct __attribute__ ((packed)) _HfsJJournalInfoBlock {
 649         uint32_t        flags;
 650         uint32_t        device_signature[8];
 651         uint64_t        offset;
 652         uint64_t        size;
 653         uint32_t        reserved[32];
 654 };
 655 #ifdef __sun
 656 #pragma pack()
 657 #endif
 658 typedef struct _HfsJJournalInfoBlock HfsJJournalInfoBlock;
 659 
 660 #ifdef __sun
 661 #pragma pack(1)
 662 #endif
 663 struct __attribute__ ((packed)) _HfsJJournalHeader {
 664         uint32_t        magic;
 665         uint32_t        endian;
 666         uint64_t        start;
 667         uint64_t        end;
 668         uint64_t        size;
 669         uint32_t        blhdr_size;
 670         uint32_t        checksum;
 671         uint32_t        jhdr_size;
 672 };
 673 #ifdef __sun
 674 #pragma pack()
 675 #endif
 676 typedef struct _HfsJJournalHeader HfsJJournalHeader;
 677 
 678 #ifdef __sun
 679 #pragma pack(1)
 680 #endif
 681 struct __attribute__ ((packed)) _HfsJBlockInfo {
 682         uint64_t        bnum;          /* sector number */
 683         uint32_t        bsize;         /* size in bytes */
 684         uint32_t        next;
 685 };
 686 #ifdef __sun
 687 #pragma pack()
 688 #endif
 689 typedef struct _HfsJBlockInfo HfsJBlockInfo;
 690 
 691 #ifdef __sun
 692 #pragma pack(1)
 693 #endif
 694 struct __attribute__ ((packed)) _HfsJBlockListHeader {
 695         uint16_t        max_blocks;    /* reserved */
 696         uint16_t        num_blocks;
 697         uint32_t        bytes_used;
 698         uint32_t        checksum;
 699         uint32_t        pad;
 700         HfsJBlockInfo   binfo[1];
 701 };
 702 #ifdef __sun
 703 #pragma pack()
 704 #endif
 705 typedef struct _HfsJBlockListHeader HfsJBlockListHeader;
 706 
 707 
 708 /* ---------------------------------------- */
 709 /* --      INTERNAL DATA STRUCTURES      -- */
 710 /* ---------------------------------------- */
 711 
 712 /* Data of an opened HFS file */
 713 struct _HfsPrivateFile {
 714         PedSector       sect_nb;
 715         PedFileSystem*  fs;
 716         uint32_t        CNID;          /* disk order (BE) */
 717         HfsExtDataRec   first;         /* disk order (BE) */
 718         HfsExtDataRec   cache;         /* disk order (BE) */
 719         uint16_t        start_cache;   /* CPU order */
 720 };
 721 typedef struct _HfsPrivateFile HfsPrivateFile;
 722 
 723 /* To store bad block list */
 724 struct _HfsPrivateLinkExtent {
 725         HfsExtDescriptor                 extent;
 726         struct _HfsPrivateLinkExtent*    next;
 727 };
 728 typedef struct _HfsPrivateLinkExtent HfsPrivateLinkExtent;
 729 
 730 /* HFS Filesystem specific data */
 731 struct _HfsPrivateFSData {
 732         uint8_t                     alloc_map[(1<<16) / 8];
 733         HfsMasterDirectoryBlock*    mdb;
 734         HfsPrivateFile*             extent_file;
 735         HfsPrivateFile*             catalog_file;
 736         HfsPrivateLinkExtent*       bad_blocks_xtent_list;
 737         unsigned int                bad_blocks_xtent_nb;
 738         char                        bad_blocks_loaded;
 739 };
 740 typedef struct _HfsPrivateFSData HfsPrivateFSData;
 741 
 742 /* Generic btree key */
 743 #ifdef __sun
 744 #pragma pack(1)
 745 #endif
 746 struct __attribute__ ((packed)) _HfsPrivateGenericKey {
 747         uint8_t         key_length;
 748         uint8_t         key_content[1];                /* we use 1 as a minimum size */
 749 };
 750 #ifdef __sun
 751 #pragma pack()
 752 #endif
 753 typedef struct _HfsPrivateGenericKey HfsPrivateGenericKey;
 754 
 755 /* ----- HFS+ ----- */
 756 
 757 /* Data of an opened HFS file */
 758 struct _HfsPPrivateFile {
 759         PedSector       sect_nb;
 760         PedFileSystem*  fs;
 761         HfsPNodeID      CNID;          /* disk order (BE) */
 762         HfsPExtDataRec  first;         /* disk order (BE) */
 763         HfsPExtDataRec  cache;         /* disk order (BE) */
 764         uint32_t        start_cache;   /* CPU order */
 765 };
 766 typedef struct _HfsPPrivateFile HfsPPrivateFile;
 767 
 768 struct _HfsPPrivateExtent {
 769         PedSector       start_sector;
 770         PedSector       sector_count;
 771 };
 772 typedef struct _HfsPPrivateExtent HfsPPrivateExtent;
 773 
 774 /* To store bad block list */
 775 struct _HfsPPrivateLinkExtent {
 776         HfsPExtDescriptor                 extent;
 777         struct _HfsPPrivateLinkExtent*    next;
 778 };
 779 typedef struct _HfsPPrivateLinkExtent HfsPPrivateLinkExtent;
 780 
 781 /* HFS+ file system specific data */
 782 struct _HfsPPrivateFSData {
 783         PedFileSystem*          wrapper;      /* NULL if hfs+ is not embedded */
 784         PedGeometry*            plus_geom;    /* Geometry of HFS+ _volume_ */
 785         uint8_t*                alloc_map;
 786         uint8_t*                dirty_alloc_map;
 787         HfsPVolumeHeader*       vh;
 788         HfsPPrivateFile*        extents_file;
 789         HfsPPrivateFile*        catalog_file;
 790         HfsPPrivateFile*        attributes_file;
 791         HfsPPrivateFile*        allocation_file;
 792         HfsPPrivateLinkExtent*  bad_blocks_xtent_list;
 793         uint32_t                jib_start_block;
 794         uint32_t                jl_start_block;
 795         unsigned int            bad_blocks_xtent_nb;
 796         char                    bad_blocks_loaded;
 797         char                    free_geom;    /* 1 = plus_geom must be freed */
 798 };
 799 typedef struct _HfsPPrivateFSData HfsPPrivateFSData;
 800 
 801 /* Generic + btree key */
 802 #ifdef __sun
 803 #pragma pack(1)
 804 #endif
 805 struct __attribute__ ((packed)) _HfsPPrivateGenericKey {
 806         uint16_t        key_length;
 807         uint8_t         key_content[1];       /* we use 1 as a minimum size */
 808 };
 809 #ifdef __sun
 810 #pragma pack()
 811 #endif
 812 typedef struct _HfsPPrivateGenericKey HfsPPrivateGenericKey;
 813 
 814 /* ---- common ---- */
 815 
 816 /* node and lead record reference for a BTree search */
 817 struct _HfsCPrivateLeafRec {
 818         unsigned int    node_size;     /* in sectors */
 819         unsigned int    node_number;
 820         unsigned int    record_pos;
 821         unsigned int    record_number;
 822 };
 823 typedef struct _HfsCPrivateLeafRec HfsCPrivateLeafRec;
 824 
 825 extern uint8_t*    hfs_block;
 826 extern uint8_t*    hfsp_block;
 827 extern unsigned    hfs_block_count;
 828 extern unsigned    hfsp_block_count;
 829 
 830 #endif /* _HFS_H */