hfsplus_raw.h 9.3 KB

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