PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/src/hfsp.h

https://github.com/cgsecurity/testdisk
C Header | 158 lines | 75 code | 17 blank | 66 comment | 0 complexity | 23b1b9721033549aba435d9a23c05a93 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. File: hfsp.h, TestDisk
  3. Copyright (C) 2005-2006 Christophe GRENIER <grenier@cgsecurity.org>
  4. Original header comes from libhfs - library for reading and writing
  5. Macintosh HFS volumes
  6. Copyright (C) 2000 Klaus Halfmann <klaus.halfmann@feri.de>
  7. Original work by 1996-1998 Robert Leslie <rob@mars.org>
  8. other work 2000 from Brad Boyer (flar@pants.nu)
  9. This software is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License along
  18. with this program; if not, write the Free Software Foundation, Inc., 51
  19. Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #ifndef _HFSP_H
  22. #define _HFSP_H
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. #define HFSP_BOOT_SECTOR_SIZE 512
  27. #define HFSP_BLOCKSZ 512 /* A sector for Apple is always 512 bytes */
  28. #define HFSP_BLOCKSZ_BITS 9 /* 1<<9 == 512 */
  29. #define HFSP_VOLHEAD_SIG 0x482B /* 'H+' */
  30. #define HFSX_VOLHEAD_SIG 0x4858 /* 'HX' */
  31. #define HFSP_VERSION 4
  32. #define HFSX_VERSION 5
  33. // Minimum Key size for all btrees
  34. #define HFSP_CAT_KEY_MIN_LEN 6
  35. // Maximum Key size for all btrees
  36. #define HFSP_CAT_KEY_MAX_LEN 516
  37. /* HFS+ includes POSIX permissions , although marked as reserved they will be
  38. * used as such. Is ignored by MacOS 8-9 but probably not by MacOS X.
  39. */
  40. typedef struct {
  41. uint32_t owner;
  42. uint32_t group;
  43. uint32_t mode;
  44. uint32_t dev;
  45. } hfsp_perm;
  46. /* A single contiguous area (fragment) of a file */
  47. typedef struct {
  48. uint32_t start_block;
  49. uint32_t block_count;
  50. } hfsp_extent;
  51. /* A file may contain up to 8 normale extents, all other
  52. are found in some extra extent area */
  53. typedef hfsp_extent hfsp_extent_rec[8];
  54. /* Information for a "Fork" in a file
  55. * Forks are the "usual" DATA and RSRC forks or special files
  56. * (e.g. the Volume Bitmap)
  57. */
  58. typedef struct {
  59. uint64_t total_size; // logical size
  60. uint32_t clump_size; // number of bytes to preallocate
  61. uint32_t total_blocks;
  62. hfsp_extent_rec extents; // initial (8) extents
  63. } hfsp_fork_raw;
  64. /* HFS+ Volume Header
  65. * Always found at block 2 of the disk, a copy is stored
  66. * at the second to last block of the disk.
  67. */
  68. typedef struct hfsp_vh {
  69. uint16_t signature; // 00: must be HFSPLUS_VOLHEAD_SIG 'H+'
  70. uint16_t version; // 02: 4 for HFS+, 5 for HFSX
  71. uint32_t attributes; // 04: See bit constants below
  72. uint32_t last_mount_vers; // 08
  73. // Use a registered creator code here (See libhfsp.h)
  74. // Mac OS uses '8.10' well
  75. uint32_t reserved; // 0C
  76. uint32_t create_date; // 10 local time !
  77. uint32_t modify_date; // 14 GMT (?)
  78. uint32_t backup_date; // 18 GMT (?)
  79. uint32_t checked_date; // 1C GMT (?) fsck ?
  80. uint32_t file_count; // 20
  81. // not including special files but including DATA and RSRC forks
  82. uint32_t folder_count; // 24 excluding the root folder
  83. uint32_t blocksize; // 28
  84. // must be multiple of HFSPLUS_SECTOR_SIZE,
  85. // should be a multiple of 4k for harddisk
  86. uint32_t total_blocks; // 2C
  87. uint32_t free_blocks; // 30
  88. // The total number of unused allocation blocks on the disk.
  89. uint32_t next_alloc;
  90. // hint where to search for next allocation blocks
  91. uint32_t rsrc_clump_sz;
  92. // default clump size for rsrc forks
  93. uint32_t data_clump_sz;
  94. // default clump size for data forks
  95. uint32_t next_cnid;
  96. // next unused catalog id
  97. uint32_t write_count;
  98. // increment on every mount (and write ?)
  99. uint64_t encodings_bmp;
  100. // for every encoding used on the disk a bit is set
  101. // ignored but eventually must be cared for
  102. char finder_info[32];
  103. hfsp_fork_raw alloc_file;
  104. // stores bitmap of use/free blocks
  105. hfsp_fork_raw ext_file;
  106. // stores oferflow extents
  107. hfsp_fork_raw cat_file;
  108. // This contains the root directory
  109. hfsp_fork_raw attr_file;
  110. hfsp_fork_raw start_file;
  111. // a special startup file may be described here (used by ?)
  112. } hfsp_vh;
  113. /* HFS+ volume attributes */
  114. /* 0-6 reserved, may be used in memory only */
  115. #define HFSPLUS_VOL_RESERVED1 0x000000FF
  116. #define HFSPLUS_VOL_HARDLOCK 0x00000080 // Used in Memory by finder only
  117. #define HFSPLUS_VOL_UNMNT 0x00000100
  118. // clear this bit when mounting, set as last step of unmounting
  119. // This is checked by (slower) ROM code
  120. #define HFSPLUS_VOL_SPARE_BLK 0x00000200
  121. #define HFSPLUS_VOL_NOCACHE 0x00000400
  122. // in case of RAM or ROM disk (try a HFS+ Ramdisk :)
  123. #define HFSPLUS_VOL_INCNSTNT 0x00000800
  124. // Reverse meaning as of HFSPLUS_VOL_UNMNT
  125. // This is checked by (faster) Mac OS code
  126. /* 12-14 reserved */
  127. #define HFSPLUS_VOL_RESERVED2 0x00007000
  128. #define HFSPLUS_VOL_SOFTLOCK 0x00008000
  129. #define HFSPLUS_VOL_RESERVED3 0xFFFF0000
  130. int check_HFSP(disk_t *disk_car,partition_t *partition,const int verbose);
  131. int test_HFSP(const disk_t *disk_car, const struct hfsp_vh *vh, const partition_t *partition, const int verbose, const int dump_ind);
  132. int recover_HFSP(disk_t *disk_car, const struct hfsp_vh *vh, partition_t *partition, const int verbose, const int dump_ind, const int backup);
  133. #ifdef __cplusplus
  134. } /* closing brace for extern "C" */
  135. #endif
  136. #endif