blob: 5a126828d85eb011714b067976f0a14981103c7c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070018/* 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 Elliott2179d372006-01-18 17:43:08 -080023#define HFSPLUS_VOLHEAD_SIGX 0x4858
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#define HFSPLUS_SUPER_MAGIC 0x482b
David Elliott2179d372006-01-18 17:43:08 -080025#define HFSPLUS_MIN_VERSION 4
26#define HFSPLUS_CURRENT_VERSION 5
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
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
Anton Salikhmetov2753cc22010-12-16 18:08:38 +020039#define HFSP_HIDDENDIR_NAME \
40 "\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80HFS+ Private Data"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#define HFSP_HARDLINK_TYPE 0x686c6e6b /* 'hlnk' */
43#define HFSP_HFSPLUS_CREATOR 0x6866732b /* 'hfs+' */
44
Roman Zippel6b1928322006-01-18 17:43:12 -080045#define HFSP_SYMLINK_TYPE 0x736c6e6b /* 'slnk' */
46#define HFSP_SYMLINK_CREATOR 0x72686170 /* 'rhap' */
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define HFSP_MOUNT_VERSION 0x482b4c78 /* 'H+Lx' */
49
50/* Structures used on disk */
51
52typedef __be32 hfsplus_cnid;
53typedef __be16 hfsplus_unichr;
54
Vyacheslav Dubeyko9ed083d8c2013-02-27 17:03:00 -080055#define HFSPLUS_MAX_STRLEN 255
56#define HFSPLUS_ATTR_MAX_STRLEN 127
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/* A "string" as used in filenames, etc. */
59struct hfsplus_unistr {
60 __be16 length;
Vyacheslav Dubeyko9ed083d8c2013-02-27 17:03:00 -080061 hfsplus_unichr unicode[HFSPLUS_MAX_STRLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070062} __packed;
63
Vyacheslav Dubeyko9ed083d8c2013-02-27 17:03:00 -080064/*
65 * A "string" is used in attributes file
66 * for name of extended attribute
67 */
68struct hfsplus_attr_unistr {
69 __be16 length;
70 hfsplus_unichr unicode[HFSPLUS_ATTR_MAX_STRLEN];
71} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/* POSIX permissions */
74struct hfsplus_perm {
75 __be32 owner;
76 __be32 group;
77 u8 rootflags;
78 u8 userflags;
79 __be16 mode;
80 __be32 dev;
81} __packed;
82
83#define HFSPLUS_FLG_NODUMP 0x01
84#define HFSPLUS_FLG_IMMUTABLE 0x02
85#define HFSPLUS_FLG_APPEND 0x04
86
87/* A single contiguous area of a file */
88struct hfsplus_extent {
89 __be32 start_block;
90 __be32 block_count;
91} __packed;
92typedef struct hfsplus_extent hfsplus_extent_rec[8];
93
94/* Information for a "Fork" in a file */
95struct hfsplus_fork_raw {
96 __be64 total_size;
97 __be32 clump_size;
98 __be32 total_blocks;
99 hfsplus_extent_rec extents;
100} __packed;
101
102/* HFS+ Volume Header */
103struct hfsplus_vh {
104 __be16 signature;
105 __be16 version;
106 __be32 attributes;
107 __be32 last_mount_vers;
108 u32 reserved;
109
110 __be32 create_date;
111 __be32 modify_date;
112 __be32 backup_date;
113 __be32 checked_date;
114
115 __be32 file_count;
116 __be32 folder_count;
117
118 __be32 blocksize;
119 __be32 total_blocks;
120 __be32 free_blocks;
121
122 __be32 next_alloc;
123 __be32 rsrc_clump_sz;
124 __be32 data_clump_sz;
125 hfsplus_cnid next_cnid;
126
127 __be32 write_count;
128 __be64 encodings_bmp;
129
Matthew Garrett0347b6e2012-02-02 15:39:50 -0500130 u32 finder_info[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 struct hfsplus_fork_raw alloc_file;
133 struct hfsplus_fork_raw ext_file;
134 struct hfsplus_fork_raw cat_file;
135 struct hfsplus_fork_raw attr_file;
136 struct hfsplus_fork_raw start_file;
137} __packed;
138
139/* HFS+ volume attributes */
Roman Zippelb0b623c2005-11-29 19:34:41 -0800140#define HFSPLUS_VOL_UNMNT (1 << 8)
141#define HFSPLUS_VOL_SPARE_BLK (1 << 9)
142#define HFSPLUS_VOL_NOCACHE (1 << 10)
143#define HFSPLUS_VOL_INCNSTNT (1 << 11)
144#define HFSPLUS_VOL_NODEID_REUSED (1 << 12)
145#define HFSPLUS_VOL_JOURNALED (1 << 13)
146#define HFSPLUS_VOL_SOFTLOCK (1 << 15)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148/* HFS+ BTree node descriptor */
149struct hfs_bnode_desc {
150 __be32 next;
151 __be32 prev;
152 s8 type;
153 u8 height;
154 __be16 num_recs;
155 u16 reserved;
156} __packed;
157
158/* HFS+ BTree node types */
Michael Opdenacker74a797d2013-11-12 15:11:06 -0800159#define HFS_NODE_INDEX 0x00 /* An internal (index) node */
160#define HFS_NODE_HEADER 0x01 /* The tree header node (node 0) */
161#define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */
162#define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
164/* HFS+ BTree header */
165struct hfs_btree_header_rec {
166 __be16 depth;
167 __be32 root;
168 __be32 leaf_count;
169 __be32 leaf_head;
170 __be32 leaf_tail;
171 __be16 node_size;
172 __be16 max_key_len;
173 __be32 node_count;
174 __be32 free_nodes;
175 u16 reserved1;
176 __be32 clump_size;
177 u8 btree_type;
David Elliott2179d372006-01-18 17:43:08 -0800178 u8 key_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 __be32 attributes;
180 u32 reserved3[16];
181} __packed;
182
183/* BTree attributes */
184#define HFS_TREE_BIGKEYS 2
185#define HFS_TREE_VARIDXKEYS 4
186
187/* HFS+ BTree misc info */
188#define HFSPLUS_TREE_HEAD 0
189#define HFSPLUS_NODE_MXSZ 32768
Vyacheslav Dubeyko099e9242013-11-12 15:11:08 -0800190#define HFSPLUS_ATTR_TREE_NODE_SIZE 8192
191#define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3
192#define HFSPLUS_BTREE_HDR_USER_BYTES 128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194/* Some special File ID numbers (stolen from hfs.h) */
195#define HFSPLUS_POR_CNID 1 /* Parent Of the Root */
196#define HFSPLUS_ROOT_CNID 2 /* ROOT directory */
197#define HFSPLUS_EXT_CNID 3 /* EXTents B-tree */
198#define HFSPLUS_CAT_CNID 4 /* CATalog B-tree */
199#define HFSPLUS_BAD_CNID 5 /* BAD blocks file */
200#define HFSPLUS_ALLOC_CNID 6 /* ALLOCation file */
201#define HFSPLUS_START_CNID 7 /* STARTup file */
202#define HFSPLUS_ATTR_CNID 8 /* ATTRibutes file */
203#define HFSPLUS_EXCH_CNID 15 /* ExchangeFiles temp id */
204#define HFSPLUS_FIRSTUSER_CNID 16 /* first available user id */
205
David Elliott2179d372006-01-18 17:43:08 -0800206/* btree key type */
207#define HFSPLUS_KEY_CASEFOLDING 0xCF /* case-insensitive */
208#define HFSPLUS_KEY_BINARY 0xBC /* case-sensitive */
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210/* HFS+ catalog entry key */
211struct hfsplus_cat_key {
212 __be16 key_len;
213 hfsplus_cnid parent;
214 struct hfsplus_unistr name;
215} __packed;
216
Eric Sandeen9250f922010-10-14 09:53:48 -0400217#define HFSPLUS_CAT_KEYLEN (sizeof(struct hfsplus_cat_key))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219/* Structs from hfs.h */
220struct hfsp_point {
221 __be16 v;
222 __be16 h;
223} __packed;
224
225struct hfsp_rect {
226 __be16 top;
227 __be16 left;
228 __be16 bottom;
229 __be16 right;
230} __packed;
231
232
233/* HFS directory info (stolen from hfs.h */
234struct DInfo {
235 struct hfsp_rect frRect;
236 __be16 frFlags;
237 struct hfsp_point frLocation;
238 __be16 frView;
239} __packed;
240
241struct DXInfo {
242 struct hfsp_point frScroll;
243 __be32 frOpenChain;
244 __be16 frUnused;
245 __be16 frComment;
246 __be32 frPutAway;
247} __packed;
248
249/* HFS+ folder data (part of an hfsplus_cat_entry) */
250struct hfsplus_cat_folder {
251 __be16 type;
252 __be16 flags;
253 __be32 valence;
254 hfsplus_cnid id;
255 __be32 create_date;
256 __be32 content_mod_date;
257 __be32 attribute_mod_date;
258 __be32 access_date;
259 __be32 backup_date;
260 struct hfsplus_perm permissions;
261 struct DInfo user_info;
262 struct DXInfo finder_info;
263 __be32 text_encoding;
Sergei Antonovd7d673a2014-03-10 15:49:51 -0700264 __be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265} __packed;
266
267/* HFS file info (stolen from hfs.h) */
268struct FInfo {
269 __be32 fdType;
270 __be32 fdCreator;
271 __be16 fdFlags;
272 struct hfsp_point fdLocation;
273 __be16 fdFldr;
274} __packed;
275
276struct FXInfo {
277 __be16 fdIconID;
278 u8 fdUnused[8];
279 __be16 fdComment;
280 __be32 fdPutAway;
281} __packed;
282
283/* HFS+ file data (part of a cat_entry) */
284struct hfsplus_cat_file {
285 __be16 type;
286 __be16 flags;
287 u32 reserved1;
288 hfsplus_cnid id;
289 __be32 create_date;
290 __be32 content_mod_date;
291 __be32 attribute_mod_date;
292 __be32 access_date;
293 __be32 backup_date;
294 struct hfsplus_perm permissions;
295 struct FInfo user_info;
296 struct FXInfo finder_info;
297 __be32 text_encoding;
298 u32 reserved2;
299
300 struct hfsplus_fork_raw data_fork;
301 struct hfsplus_fork_raw rsrc_fork;
302} __packed;
303
Sergei Antonovd7d673a2014-03-10 15:49:51 -0700304/* File and folder flag bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305#define HFSPLUS_FILE_LOCKED 0x0001
306#define HFSPLUS_FILE_THREAD_EXISTS 0x0002
Vyacheslav Dubeyko9ed083d8c2013-02-27 17:03:00 -0800307#define HFSPLUS_XATTR_EXISTS 0x0004
308#define HFSPLUS_ACL_EXISTS 0x0008
Sergei Antonovd7d673a2014-03-10 15:49:51 -0700309#define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count
310 * (HFSX only) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
312/* HFS+ catalog thread (part of a cat_entry) */
313struct hfsplus_cat_thread {
314 __be16 type;
315 s16 reserved;
316 hfsplus_cnid parentID;
317 struct hfsplus_unistr nodeName;
318} __packed;
319
320#define HFSPLUS_MIN_THREAD_SZ 10
321
322/* A data record in the catalog tree */
323typedef union {
324 __be16 type;
325 struct hfsplus_cat_folder folder;
326 struct hfsplus_cat_file file;
327 struct hfsplus_cat_thread thread;
328} __packed hfsplus_cat_entry;
329
330/* HFS+ catalog entry type */
331#define HFSPLUS_FOLDER 0x0001
332#define HFSPLUS_FILE 0x0002
333#define HFSPLUS_FOLDER_THREAD 0x0003
334#define HFSPLUS_FILE_THREAD 0x0004
335
336/* HFS+ extents tree key */
337struct hfsplus_ext_key {
338 __be16 key_len;
339 u8 fork_type;
340 u8 pad;
341 hfsplus_cnid cnid;
342 __be32 start_block;
343} __packed;
344
Eric Sandeen9250f922010-10-14 09:53:48 -0400345#define HFSPLUS_EXT_KEYLEN sizeof(struct hfsplus_ext_key)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Vyacheslav Dubeyko9ed083d8c2013-02-27 17:03:00 -0800347#define HFSPLUS_XATTR_FINDER_INFO_NAME "com.apple.FinderInfo"
348#define HFSPLUS_XATTR_ACL_NAME "com.apple.system.Security"
349
350#define HFSPLUS_ATTR_INLINE_DATA 0x10
351#define HFSPLUS_ATTR_FORK_DATA 0x20
352#define HFSPLUS_ATTR_EXTENTS 0x30
353
354/* HFS+ attributes tree key */
355struct hfsplus_attr_key {
356 __be16 key_len;
357 __be16 pad;
358 hfsplus_cnid cnid;
359 __be32 start_block;
360 struct hfsplus_attr_unistr key_name;
361} __packed;
362
363#define HFSPLUS_ATTR_KEYLEN sizeof(struct hfsplus_attr_key)
364
365/* HFS+ fork data attribute */
366struct hfsplus_attr_fork_data {
367 __be32 record_type;
368 __be32 reserved;
369 struct hfsplus_fork_raw the_fork;
370} __packed;
371
372/* HFS+ extension attribute */
373struct hfsplus_attr_extents {
374 __be32 record_type;
375 __be32 reserved;
376 struct hfsplus_extent extents;
377} __packed;
378
379#define HFSPLUS_MAX_INLINE_DATA_SIZE 3802
380
381/* HFS+ attribute inline data */
382struct hfsplus_attr_inline_data {
383 __be32 record_type;
384 __be32 reserved1;
385 u8 reserved2[6];
386 __be16 length;
387 u8 raw_bytes[HFSPLUS_MAX_INLINE_DATA_SIZE];
388} __packed;
389
390/* A data record in the attributes tree */
391typedef union {
392 __be32 record_type;
393 struct hfsplus_attr_fork_data fork_data;
394 struct hfsplus_attr_extents extents;
395 struct hfsplus_attr_inline_data inline_data;
396} __packed hfsplus_attr_entry;
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398/* HFS+ generic BTree key */
399typedef union {
400 __be16 key_len;
401 struct hfsplus_cat_key cat;
402 struct hfsplus_ext_key ext;
Vyacheslav Dubeyko9ed083d8c2013-02-27 17:03:00 -0800403 struct hfsplus_attr_key attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404} __packed hfsplus_btree_key;
405
406#endif