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