hfsplus_raw.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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. #define HFSPLUS_VOL_UNUSED_NODE_FIX (1 << 31)
  121. /* HFS+ BTree node descriptor */
  122. struct hfs_bnode_desc {
  123. __be32 next;
  124. __be32 prev;
  125. s8 type;
  126. u8 height;
  127. __be16 num_recs;
  128. u16 reserved;
  129. } __packed;
  130. /* HFS+ BTree node types */
  131. #define HFS_NODE_INDEX 0x00 /* An internal (index) node */
  132. #define HFS_NODE_HEADER 0x01 /* The tree header node (node 0) */
  133. #define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */
  134. #define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */
  135. /* HFS+ BTree header */
  136. struct hfs_btree_header_rec {
  137. __be16 depth;
  138. __be32 root;
  139. __be32 leaf_count;
  140. __be32 leaf_head;
  141. __be32 leaf_tail;
  142. __be16 node_size;
  143. __be16 max_key_len;
  144. __be32 node_count;
  145. __be32 free_nodes;
  146. u16 reserved1;
  147. __be32 clump_size;
  148. u8 btree_type;
  149. u8 key_type;
  150. __be32 attributes;
  151. u32 reserved3[16];
  152. } __packed;
  153. /* BTree attributes */
  154. #define HFS_TREE_BIGKEYS 2
  155. #define HFS_TREE_VARIDXKEYS 4
  156. /* HFS+ BTree misc info */
  157. #define HFSPLUS_TREE_HEAD 0
  158. #define HFSPLUS_NODE_MXSZ 32768
  159. #define HFSPLUS_ATTR_TREE_NODE_SIZE 8192
  160. #define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3
  161. #define HFSPLUS_BTREE_HDR_USER_BYTES 128
  162. /* Some special File ID numbers (stolen from hfs.h) */
  163. #define HFSPLUS_POR_CNID 1 /* Parent Of the Root */
  164. #define HFSPLUS_ROOT_CNID 2 /* ROOT directory */
  165. #define HFSPLUS_EXT_CNID 3 /* EXTents B-tree */
  166. #define HFSPLUS_CAT_CNID 4 /* CATalog B-tree */
  167. #define HFSPLUS_BAD_CNID 5 /* BAD blocks file */
  168. #define HFSPLUS_ALLOC_CNID 6 /* ALLOCation file */
  169. #define HFSPLUS_START_CNID 7 /* STARTup file */
  170. #define HFSPLUS_ATTR_CNID 8 /* ATTRibutes file */
  171. #define HFSPLUS_EXCH_CNID 15 /* ExchangeFiles temp id */
  172. #define HFSPLUS_FIRSTUSER_CNID 16 /* first available user id */
  173. /* btree key type */
  174. #define HFSPLUS_KEY_CASEFOLDING 0xCF /* case-insensitive */
  175. #define HFSPLUS_KEY_BINARY 0xBC /* case-sensitive */
  176. /* HFS+ catalog entry key */
  177. struct hfsplus_cat_key {
  178. __be16 key_len;
  179. hfsplus_cnid parent;
  180. struct hfsplus_unistr name;
  181. } __packed;
  182. #define HFSPLUS_CAT_KEYLEN (sizeof(struct hfsplus_cat_key))
  183. /* Structs from hfs.h */
  184. struct hfsp_point {
  185. __be16 v;
  186. __be16 h;
  187. } __packed;
  188. struct hfsp_rect {
  189. __be16 top;
  190. __be16 left;
  191. __be16 bottom;
  192. __be16 right;
  193. } __packed;
  194. /* HFS directory info (stolen from hfs.h */
  195. struct DInfo {
  196. struct hfsp_rect frRect;
  197. __be16 frFlags;
  198. struct hfsp_point frLocation;
  199. __be16 frView;
  200. } __packed;
  201. struct DXInfo {
  202. struct hfsp_point frScroll;
  203. __be32 frOpenChain;
  204. __be16 frUnused;
  205. __be16 frComment;
  206. __be32 frPutAway;
  207. } __packed;
  208. /* HFS+ folder data (part of an hfsplus_cat_entry) */
  209. struct hfsplus_cat_folder {
  210. __be16 type;
  211. __be16 flags;
  212. __be32 valence;
  213. hfsplus_cnid id;
  214. __be32 create_date;
  215. __be32 content_mod_date;
  216. __be32 attribute_mod_date;
  217. __be32 access_date;
  218. __be32 backup_date;
  219. struct hfsplus_perm permissions;
  220. struct DInfo user_info;
  221. struct DXInfo finder_info;
  222. __be32 text_encoding;
  223. __be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */
  224. } __packed;
  225. /* HFS file info (stolen from hfs.h) */
  226. struct FInfo {
  227. __be32 fdType;
  228. __be32 fdCreator;
  229. __be16 fdFlags;
  230. struct hfsp_point fdLocation;
  231. __be16 fdFldr;
  232. } __packed;
  233. struct FXInfo {
  234. __be16 fdIconID;
  235. u8 fdUnused[8];
  236. __be16 fdComment;
  237. __be32 fdPutAway;
  238. } __packed;
  239. /* HFS+ file data (part of a cat_entry) */
  240. struct hfsplus_cat_file {
  241. __be16 type;
  242. __be16 flags;
  243. u32 reserved1;
  244. hfsplus_cnid id;
  245. __be32 create_date;
  246. __be32 content_mod_date;
  247. __be32 attribute_mod_date;
  248. __be32 access_date;
  249. __be32 backup_date;
  250. struct hfsplus_perm permissions;
  251. struct FInfo user_info;
  252. struct FXInfo finder_info;
  253. __be32 text_encoding;
  254. u32 reserved2;
  255. struct hfsplus_fork_raw data_fork;
  256. struct hfsplus_fork_raw rsrc_fork;
  257. } __packed;
  258. /* File and folder flag bits */
  259. #define HFSPLUS_FILE_LOCKED 0x0001
  260. #define HFSPLUS_FILE_THREAD_EXISTS 0x0002
  261. #define HFSPLUS_XATTR_EXISTS 0x0004
  262. #define HFSPLUS_ACL_EXISTS 0x0008
  263. #define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count
  264. * (HFSX only) */
  265. /* HFS+ catalog thread (part of a cat_entry) */
  266. struct hfsplus_cat_thread {
  267. __be16 type;
  268. s16 reserved;
  269. hfsplus_cnid parentID;
  270. struct hfsplus_unistr nodeName;
  271. } __packed;
  272. #define HFSPLUS_MIN_THREAD_SZ 10
  273. /* A data record in the catalog tree */
  274. typedef union {
  275. __be16 type;
  276. struct hfsplus_cat_folder folder;
  277. struct hfsplus_cat_file file;
  278. struct hfsplus_cat_thread thread;
  279. } __packed hfsplus_cat_entry;
  280. /* HFS+ catalog entry type */
  281. #define HFSPLUS_FOLDER 0x0001
  282. #define HFSPLUS_FILE 0x0002
  283. #define HFSPLUS_FOLDER_THREAD 0x0003
  284. #define HFSPLUS_FILE_THREAD 0x0004
  285. /* HFS+ extents tree key */
  286. struct hfsplus_ext_key {
  287. __be16 key_len;
  288. u8 fork_type;
  289. u8 pad;
  290. hfsplus_cnid cnid;
  291. __be32 start_block;
  292. } __packed;
  293. #define HFSPLUS_EXT_KEYLEN sizeof(struct hfsplus_ext_key)
  294. #define HFSPLUS_XATTR_FINDER_INFO_NAME "com.apple.FinderInfo"
  295. #define HFSPLUS_XATTR_ACL_NAME "com.apple.system.Security"
  296. #define HFSPLUS_ATTR_INLINE_DATA 0x10
  297. #define HFSPLUS_ATTR_FORK_DATA 0x20
  298. #define HFSPLUS_ATTR_EXTENTS 0x30
  299. /* HFS+ attributes tree key */
  300. struct hfsplus_attr_key {
  301. __be16 key_len;
  302. __be16 pad;
  303. hfsplus_cnid cnid;
  304. __be32 start_block;
  305. struct hfsplus_attr_unistr key_name;
  306. } __packed;
  307. #define HFSPLUS_ATTR_KEYLEN sizeof(struct hfsplus_attr_key)
  308. /* HFS+ fork data attribute */
  309. struct hfsplus_attr_fork_data {
  310. __be32 record_type;
  311. __be32 reserved;
  312. struct hfsplus_fork_raw the_fork;
  313. } __packed;
  314. /* HFS+ extension attribute */
  315. struct hfsplus_attr_extents {
  316. __be32 record_type;
  317. __be32 reserved;
  318. struct hfsplus_extent extents;
  319. } __packed;
  320. #define HFSPLUS_MAX_INLINE_DATA_SIZE 3802
  321. /* HFS+ attribute inline data */
  322. struct hfsplus_attr_inline_data {
  323. __be32 record_type;
  324. __be32 reserved1;
  325. u8 reserved2[6];
  326. __be16 length;
  327. u8 raw_bytes[HFSPLUS_MAX_INLINE_DATA_SIZE];
  328. } __packed;
  329. /* A data record in the attributes tree */
  330. typedef union {
  331. __be32 record_type;
  332. struct hfsplus_attr_fork_data fork_data;
  333. struct hfsplus_attr_extents extents;
  334. struct hfsplus_attr_inline_data inline_data;
  335. } __packed hfsplus_attr_entry;
  336. /* HFS+ generic BTree key */
  337. typedef union {
  338. __be16 key_len;
  339. struct hfsplus_cat_key cat;
  340. struct hfsplus_ext_key ext;
  341. struct hfsplus_attr_key attr;
  342. } __packed hfsplus_btree_key;
  343. #endif