hfsplus_raw.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * linux/include/linux/hfsplus_raw.h
  4. *
  5. * Copyright (C) 1999
  6. * Brad Boyer (flar@pants.nu)
  7. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  8. *
  9. * Format of structures on disk
  10. * Information taken from Apple Technote #1150 (HFS Plus Volume Format)
  11. *
  12. */
  13. #ifndef _LINUX_HFSPLUS_RAW_H
  14. #define _LINUX_HFSPLUS_RAW_H
  15. #include <linux/types.h>
  16. /* Some constants */
  17. #define HFSPLUS_SECTOR_SIZE 512
  18. #define HFSPLUS_SECTOR_SHIFT 9
  19. #define HFSPLUS_VOLHEAD_SECTOR 2
  20. #define HFSPLUS_VOLHEAD_SIG 0x482b
  21. #define HFSPLUS_VOLHEAD_SIGX 0x4858
  22. #define HFSPLUS_SUPER_MAGIC 0x482b
  23. #define HFSPLUS_MIN_VERSION 4
  24. #define HFSPLUS_CURRENT_VERSION 5
  25. #define HFSP_WRAP_MAGIC 0x4244
  26. #define HFSP_WRAP_ATTRIB_SLOCK 0x8000
  27. #define HFSP_WRAP_ATTRIB_SPARED 0x0200
  28. #define HFSP_WRAPOFF_SIG 0x00
  29. #define HFSP_WRAPOFF_ATTRIB 0x0A
  30. #define HFSP_WRAPOFF_ABLKSIZE 0x14
  31. #define HFSP_WRAPOFF_ABLKSTART 0x1C
  32. #define HFSP_WRAPOFF_EMBEDSIG 0x7C
  33. #define HFSP_WRAPOFF_EMBEDEXT 0x7E
  34. #define HFSP_HIDDENDIR_NAME \
  35. "\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80HFS+ Private Data"
  36. #define HFSP_HARDLINK_TYPE 0x686c6e6b /* 'hlnk' */
  37. #define HFSP_HFSPLUS_CREATOR 0x6866732b /* 'hfs+' */
  38. #define HFSP_SYMLINK_TYPE 0x736c6e6b /* 'slnk' */
  39. #define HFSP_SYMLINK_CREATOR 0x72686170 /* 'rhap' */
  40. #define HFSP_MOUNT_VERSION 0x482b4c78 /* 'H+Lx' */
  41. /* Structures used on disk */
  42. typedef __be32 hfsplus_cnid;
  43. typedef __be16 hfsplus_unichr;
  44. #define HFSPLUS_MAX_STRLEN 255
  45. #define HFSPLUS_ATTR_MAX_STRLEN 127
  46. /* A "string" as used in filenames, etc. */
  47. struct hfsplus_unistr {
  48. __be16 length;
  49. hfsplus_unichr unicode[HFSPLUS_MAX_STRLEN];
  50. } __packed;
  51. /*
  52. * A "string" is used in attributes file
  53. * for name of extended attribute
  54. */
  55. struct hfsplus_attr_unistr {
  56. __be16 length;
  57. hfsplus_unichr unicode[HFSPLUS_ATTR_MAX_STRLEN];
  58. } __packed;
  59. /* POSIX permissions */
  60. struct hfsplus_perm {
  61. __be32 owner;
  62. __be32 group;
  63. u8 rootflags;
  64. u8 userflags;
  65. __be16 mode;
  66. __be32 dev;
  67. } __packed;
  68. #define HFSPLUS_FLG_NODUMP 0x01
  69. #define HFSPLUS_FLG_IMMUTABLE 0x02
  70. #define HFSPLUS_FLG_APPEND 0x04
  71. /* A single contiguous area of a file */
  72. struct hfsplus_extent {
  73. __be32 start_block;
  74. __be32 block_count;
  75. } __packed;
  76. typedef struct hfsplus_extent hfsplus_extent_rec[8];
  77. /* Information for a "Fork" in a file */
  78. struct hfsplus_fork_raw {
  79. __be64 total_size;
  80. __be32 clump_size;
  81. __be32 total_blocks;
  82. hfsplus_extent_rec extents;
  83. } __packed;
  84. /* HFS+ Volume Header */
  85. struct hfsplus_vh {
  86. __be16 signature;
  87. __be16 version;
  88. __be32 attributes;
  89. __be32 last_mount_vers;
  90. u32 reserved;
  91. __be32 create_date;
  92. __be32 modify_date;
  93. __be32 backup_date;
  94. __be32 checked_date;
  95. __be32 file_count;
  96. __be32 folder_count;
  97. __be32 blocksize;
  98. __be32 total_blocks;
  99. __be32 free_blocks;
  100. __be32 next_alloc;
  101. __be32 rsrc_clump_sz;
  102. __be32 data_clump_sz;
  103. hfsplus_cnid next_cnid;
  104. __be32 write_count;
  105. __be64 encodings_bmp;
  106. u32 finder_info[8];
  107. struct hfsplus_fork_raw alloc_file;
  108. struct hfsplus_fork_raw ext_file;
  109. struct hfsplus_fork_raw cat_file;
  110. struct hfsplus_fork_raw attr_file;
  111. struct hfsplus_fork_raw start_file;
  112. } __packed;
  113. /* HFS+ volume attributes */
  114. #define HFSPLUS_VOL_UNMNT (1 << 8)
  115. #define HFSPLUS_VOL_SPARE_BLK (1 << 9)
  116. #define HFSPLUS_VOL_NOCACHE (1 << 10)
  117. #define HFSPLUS_VOL_INCNSTNT (1 << 11)
  118. #define HFSPLUS_VOL_NODEID_REUSED (1 << 12)
  119. #define HFSPLUS_VOL_JOURNALED (1 << 13)
  120. #define HFSPLUS_VOL_SOFTLOCK (1 << 15)
  121. #define HFSPLUS_VOL_UNUSED_NODE_FIX (1 << 31)
  122. /* HFS+ BTree node descriptor */
  123. struct hfs_bnode_desc {
  124. __be32 next;
  125. __be32 prev;
  126. s8 type;
  127. u8 height;
  128. __be16 num_recs;
  129. u16 reserved;
  130. } __packed;
  131. /* HFS+ BTree node types */
  132. #define HFS_NODE_INDEX 0x00 /* An internal (index) node */
  133. #define HFS_NODE_HEADER 0x01 /* The tree header node (node 0) */
  134. #define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */
  135. #define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */
  136. /* HFS+ BTree header */
  137. struct hfs_btree_header_rec {
  138. __be16 depth;
  139. __be32 root;
  140. __be32 leaf_count;
  141. __be32 leaf_head;
  142. __be32 leaf_tail;
  143. __be16 node_size;
  144. __be16 max_key_len;
  145. __be32 node_count;
  146. __be32 free_nodes;
  147. u16 reserved1;
  148. __be32 clump_size;
  149. u8 btree_type;
  150. u8 key_type;
  151. __be32 attributes;
  152. u32 reserved3[16];
  153. } __packed;
  154. /* BTree attributes */
  155. #define HFS_TREE_BIGKEYS 2
  156. #define HFS_TREE_VARIDXKEYS 4
  157. /* HFS+ BTree misc info */
  158. #define HFSPLUS_TREE_HEAD 0
  159. #define HFSPLUS_NODE_MXSZ 32768
  160. #define HFSPLUS_ATTR_TREE_NODE_SIZE 8192
  161. #define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3
  162. #define HFSPLUS_BTREE_HDR_USER_BYTES 128
  163. /* Some special File ID numbers (stolen from hfs.h) */
  164. #define HFSPLUS_POR_CNID 1 /* Parent Of the Root */
  165. #define HFSPLUS_ROOT_CNID 2 /* ROOT directory */
  166. #define HFSPLUS_EXT_CNID 3 /* EXTents B-tree */
  167. #define HFSPLUS_CAT_CNID 4 /* CATalog B-tree */
  168. #define HFSPLUS_BAD_CNID 5 /* BAD blocks file */
  169. #define HFSPLUS_ALLOC_CNID 6 /* ALLOCation file */
  170. #define HFSPLUS_START_CNID 7 /* STARTup file */
  171. #define HFSPLUS_ATTR_CNID 8 /* ATTRibutes file */
  172. #define HFSPLUS_EXCH_CNID 15 /* ExchangeFiles temp id */
  173. #define HFSPLUS_FIRSTUSER_CNID 16 /* first available user id */
  174. /* btree key type */
  175. #define HFSPLUS_KEY_CASEFOLDING 0xCF /* case-insensitive */
  176. #define HFSPLUS_KEY_BINARY 0xBC /* case-sensitive */
  177. /* HFS+ catalog entry key */
  178. struct hfsplus_cat_key {
  179. __be16 key_len;
  180. hfsplus_cnid parent;
  181. struct hfsplus_unistr name;
  182. } __packed;
  183. #define HFSPLUS_CAT_KEYLEN (sizeof(struct hfsplus_cat_key))
  184. /* Structs from hfs.h */
  185. struct hfsp_point {
  186. __be16 v;
  187. __be16 h;
  188. } __packed;
  189. struct hfsp_rect {
  190. __be16 top;
  191. __be16 left;
  192. __be16 bottom;
  193. __be16 right;
  194. } __packed;
  195. /* HFS directory info (stolen from hfs.h */
  196. struct DInfo {
  197. struct hfsp_rect frRect;
  198. __be16 frFlags;
  199. struct hfsp_point frLocation;
  200. __be16 frView;
  201. } __packed;
  202. struct DXInfo {
  203. struct hfsp_point frScroll;
  204. __be32 frOpenChain;
  205. __be16 frUnused;
  206. __be16 frComment;
  207. __be32 frPutAway;
  208. } __packed;
  209. /* HFS+ folder data (part of an hfsplus_cat_entry) */
  210. struct hfsplus_cat_folder {
  211. __be16 type;
  212. __be16 flags;
  213. __be32 valence;
  214. hfsplus_cnid id;
  215. __be32 create_date;
  216. __be32 content_mod_date;
  217. __be32 attribute_mod_date;
  218. __be32 access_date;
  219. __be32 backup_date;
  220. struct hfsplus_perm permissions;
  221. struct DInfo user_info;
  222. struct DXInfo finder_info;
  223. __be32 text_encoding;
  224. __be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */
  225. } __packed;
  226. /* HFS file info (stolen from hfs.h) */
  227. struct FInfo {
  228. __be32 fdType;
  229. __be32 fdCreator;
  230. __be16 fdFlags;
  231. struct hfsp_point fdLocation;
  232. __be16 fdFldr;
  233. } __packed;
  234. struct FXInfo {
  235. __be16 fdIconID;
  236. u8 fdUnused[8];
  237. __be16 fdComment;
  238. __be32 fdPutAway;
  239. } __packed;
  240. /* HFS+ file data (part of a cat_entry) */
  241. struct hfsplus_cat_file {
  242. __be16 type;
  243. __be16 flags;
  244. u32 reserved1;
  245. hfsplus_cnid id;
  246. __be32 create_date;
  247. __be32 content_mod_date;
  248. __be32 attribute_mod_date;
  249. __be32 access_date;
  250. __be32 backup_date;
  251. struct hfsplus_perm permissions;
  252. struct FInfo user_info;
  253. struct FXInfo finder_info;
  254. __be32 text_encoding;
  255. u32 reserved2;
  256. struct hfsplus_fork_raw data_fork;
  257. struct hfsplus_fork_raw rsrc_fork;
  258. } __packed;
  259. /* File and folder flag bits */
  260. #define HFSPLUS_FILE_LOCKED 0x0001
  261. #define HFSPLUS_FILE_THREAD_EXISTS 0x0002
  262. #define HFSPLUS_XATTR_EXISTS 0x0004
  263. #define HFSPLUS_ACL_EXISTS 0x0008
  264. #define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count
  265. * (HFSX only) */
  266. /* HFS+ catalog thread (part of a cat_entry) */
  267. struct hfsplus_cat_thread {
  268. __be16 type;
  269. s16 reserved;
  270. hfsplus_cnid parentID;
  271. struct hfsplus_unistr nodeName;
  272. } __packed;
  273. #define HFSPLUS_MIN_THREAD_SZ 10
  274. /* A data record in the catalog tree */
  275. typedef union {
  276. __be16 type;
  277. struct hfsplus_cat_folder folder;
  278. struct hfsplus_cat_file file;
  279. struct hfsplus_cat_thread thread;
  280. } __packed hfsplus_cat_entry;
  281. /* HFS+ catalog entry type */
  282. #define HFSPLUS_FOLDER 0x0001
  283. #define HFSPLUS_FILE 0x0002
  284. #define HFSPLUS_FOLDER_THREAD 0x0003
  285. #define HFSPLUS_FILE_THREAD 0x0004
  286. /* HFS+ extents tree key */
  287. struct hfsplus_ext_key {
  288. __be16 key_len;
  289. u8 fork_type;
  290. u8 pad;
  291. hfsplus_cnid cnid;
  292. __be32 start_block;
  293. } __packed;
  294. #define HFSPLUS_EXT_KEYLEN sizeof(struct hfsplus_ext_key)
  295. #define HFSPLUS_XATTR_FINDER_INFO_NAME "com.apple.FinderInfo"
  296. #define HFSPLUS_XATTR_ACL_NAME "com.apple.system.Security"
  297. #define HFSPLUS_ATTR_INLINE_DATA 0x10
  298. #define HFSPLUS_ATTR_FORK_DATA 0x20
  299. #define HFSPLUS_ATTR_EXTENTS 0x30
  300. /* HFS+ attributes tree key */
  301. struct hfsplus_attr_key {
  302. __be16 key_len;
  303. __be16 pad;
  304. hfsplus_cnid cnid;
  305. __be32 start_block;
  306. struct hfsplus_attr_unistr key_name;
  307. } __packed;
  308. #define HFSPLUS_ATTR_KEYLEN sizeof(struct hfsplus_attr_key)
  309. /* HFS+ fork data attribute */
  310. struct hfsplus_attr_fork_data {
  311. __be32 record_type;
  312. __be32 reserved;
  313. struct hfsplus_fork_raw the_fork;
  314. } __packed;
  315. /* HFS+ extension attribute */
  316. struct hfsplus_attr_extents {
  317. __be32 record_type;
  318. __be32 reserved;
  319. struct hfsplus_extent extents;
  320. } __packed;
  321. #define HFSPLUS_MAX_INLINE_DATA_SIZE 3802
  322. /* HFS+ attribute inline data */
  323. struct hfsplus_attr_inline_data {
  324. __be32 record_type;
  325. __be32 reserved1;
  326. u8 reserved2[6];
  327. __be16 length;
  328. u8 raw_bytes[HFSPLUS_MAX_INLINE_DATA_SIZE];
  329. } __packed;
  330. /* A data record in the attributes tree */
  331. typedef union {
  332. __be32 record_type;
  333. struct hfsplus_attr_fork_data fork_data;
  334. struct hfsplus_attr_extents extents;
  335. struct hfsplus_attr_inline_data inline_data;
  336. } __packed hfsplus_attr_entry;
  337. /* HFS+ generic BTree key */
  338. typedef union {
  339. __be16 key_len;
  340. struct hfsplus_cat_key cat;
  341. struct hfsplus_ext_key ext;
  342. struct hfsplus_attr_key attr;
  343. } __packed hfsplus_btree_key;
  344. #endif