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