blob: 68b4240c61916d08f2e5cad7c9239fbf8c974494 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/include/linux/hfsplus_raw.h
4 *
5 * Copyright (C) 1999
6 * Brad Boyer (flar@pants.nu)
7 * (C) 2003 Ardis Technologies <roman@ardistech.com>
8 *
9 * Format of structures on disk
10 * Information taken from Apple Technote #1150 (HFS Plus Volume Format)
11 *
12 */
13
14#ifndef _LINUX_HFSPLUS_RAW_H
15#define _LINUX_HFSPLUS_RAW_H
16
17#include <linux/types.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/* Some constants */
20#define HFSPLUS_SECTOR_SIZE 512
21#define HFSPLUS_SECTOR_SHIFT 9
22#define HFSPLUS_VOLHEAD_SECTOR 2
23#define HFSPLUS_VOLHEAD_SIG 0x482b
David Elliott2179d372006-01-18 17:43:08 -080024#define HFSPLUS_VOLHEAD_SIGX 0x4858
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#define HFSPLUS_SUPER_MAGIC 0x482b
David Elliott2179d372006-01-18 17:43:08 -080026#define HFSPLUS_MIN_VERSION 4
27#define HFSPLUS_CURRENT_VERSION 5
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
29#define HFSP_WRAP_MAGIC 0x4244
30#define HFSP_WRAP_ATTRIB_SLOCK 0x8000
31#define HFSP_WRAP_ATTRIB_SPARED 0x0200
32
33#define HFSP_WRAPOFF_SIG 0x00
34#define HFSP_WRAPOFF_ATTRIB 0x0A
35#define HFSP_WRAPOFF_ABLKSIZE 0x14
36#define HFSP_WRAPOFF_ABLKSTART 0x1C
37#define HFSP_WRAPOFF_EMBEDSIG 0x7C
38#define HFSP_WRAPOFF_EMBEDEXT 0x7E
39
Anton Salikhmetov2753cc22010-12-16 18:08:38 +020040#define HFSP_HIDDENDIR_NAME \
41 "\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80HFS+ Private Data"
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43#define HFSP_HARDLINK_TYPE 0x686c6e6b /* 'hlnk' */
44#define HFSP_HFSPLUS_CREATOR 0x6866732b /* 'hfs+' */
45
Roman Zippel6b1928322006-01-18 17:43:12 -080046#define HFSP_SYMLINK_TYPE 0x736c6e6b /* 'slnk' */
47#define HFSP_SYMLINK_CREATOR 0x72686170 /* 'rhap' */
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define HFSP_MOUNT_VERSION 0x482b4c78 /* 'H+Lx' */
50
51/* Structures used on disk */
52
53typedef __be32 hfsplus_cnid;
54typedef __be16 hfsplus_unichr;
55
Vyacheslav Dubeyko9ed083d2013-02-27 17:03:00 -080056#define HFSPLUS_MAX_STRLEN 255
57#define HFSPLUS_ATTR_MAX_STRLEN 127
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059/* A "string" as used in filenames, etc. */
60struct hfsplus_unistr {
61 __be16 length;
Vyacheslav Dubeyko9ed083d2013-02-27 17:03:00 -080062 hfsplus_unichr unicode[HFSPLUS_MAX_STRLEN];
Linus Torvalds1da177e2005-04-16 15:20:36 -070063} __packed;
64
Vyacheslav Dubeyko9ed083d2013-02-27 17:03:00 -080065/*
66 * A "string" is used in attributes file
67 * for name of extended attribute
68 */
69struct hfsplus_attr_unistr {
70 __be16 length;
71 hfsplus_unichr unicode[HFSPLUS_ATTR_MAX_STRLEN];
72} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/* POSIX permissions */
75struct hfsplus_perm {
76 __be32 owner;
77 __be32 group;
78 u8 rootflags;
79 u8 userflags;
80 __be16 mode;
81 __be32 dev;
82} __packed;
83
84#define HFSPLUS_FLG_NODUMP 0x01
85#define HFSPLUS_FLG_IMMUTABLE 0x02
86#define HFSPLUS_FLG_APPEND 0x04
87
88/* A single contiguous area of a file */
89struct hfsplus_extent {
90 __be32 start_block;
91 __be32 block_count;
92} __packed;
93typedef struct hfsplus_extent hfsplus_extent_rec[8];
94
95/* Information for a "Fork" in a file */
96struct hfsplus_fork_raw {
97 __be64 total_size;
98 __be32 clump_size;
99 __be32 total_blocks;
100 hfsplus_extent_rec extents;
101} __packed;
102
103/* HFS+ Volume Header */
104struct hfsplus_vh {
105 __be16 signature;
106 __be16 version;
107 __be32 attributes;
108 __be32 last_mount_vers;
109 u32 reserved;
110
111 __be32 create_date;
112 __be32 modify_date;
113 __be32 backup_date;
114 __be32 checked_date;
115
116 __be32 file_count;
117 __be32 folder_count;
118
119 __be32 blocksize;
120 __be32 total_blocks;
121 __be32 free_blocks;
122
123 __be32 next_alloc;
124 __be32 rsrc_clump_sz;
125 __be32 data_clump_sz;
126 hfsplus_cnid next_cnid;
127
128 __be32 write_count;
129 __be64 encodings_bmp;
130
Matthew Garrett0347b6e2012-02-02 15:39:50 -0500131 u32 finder_info[8];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 struct hfsplus_fork_raw alloc_file;
134 struct hfsplus_fork_raw ext_file;
135 struct hfsplus_fork_raw cat_file;
136 struct hfsplus_fork_raw attr_file;
137 struct hfsplus_fork_raw start_file;
138} __packed;
139
140/* HFS+ volume attributes */
Roman Zippelb0b623c2005-11-29 19:34:41 -0800141#define HFSPLUS_VOL_UNMNT (1 << 8)
142#define HFSPLUS_VOL_SPARE_BLK (1 << 9)
143#define HFSPLUS_VOL_NOCACHE (1 << 10)
144#define HFSPLUS_VOL_INCNSTNT (1 << 11)
145#define HFSPLUS_VOL_NODEID_REUSED (1 << 12)
146#define HFSPLUS_VOL_JOURNALED (1 << 13)
147#define HFSPLUS_VOL_SOFTLOCK (1 << 15)
Sergei Antonov2cd282a2014-06-06 14:36:28 -0700148#define HFSPLUS_VOL_UNUSED_NODE_FIX (1 << 31)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/* HFS+ BTree node descriptor */
151struct hfs_bnode_desc {
152 __be32 next;
153 __be32 prev;
154 s8 type;
155 u8 height;
156 __be16 num_recs;
157 u16 reserved;
158} __packed;
159
160/* HFS+ BTree node types */
Michael Opdenacker74a797d2013-11-12 15:11:06 -0800161#define HFS_NODE_INDEX 0x00 /* An internal (index) node */
162#define HFS_NODE_HEADER 0x01 /* The tree header node (node 0) */
163#define HFS_NODE_MAP 0x02 /* Holds part of the bitmap of used nodes */
164#define HFS_NODE_LEAF 0xFF /* A leaf (ndNHeight==1) node */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166/* HFS+ BTree header */
167struct hfs_btree_header_rec {
168 __be16 depth;
169 __be32 root;
170 __be32 leaf_count;
171 __be32 leaf_head;
172 __be32 leaf_tail;
173 __be16 node_size;
174 __be16 max_key_len;
175 __be32 node_count;
176 __be32 free_nodes;
177 u16 reserved1;
178 __be32 clump_size;
179 u8 btree_type;
David Elliott2179d372006-01-18 17:43:08 -0800180 u8 key_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 __be32 attributes;
182 u32 reserved3[16];
183} __packed;
184
185/* BTree attributes */
186#define HFS_TREE_BIGKEYS 2
187#define HFS_TREE_VARIDXKEYS 4
188
189/* HFS+ BTree misc info */
190#define HFSPLUS_TREE_HEAD 0
191#define HFSPLUS_NODE_MXSZ 32768
Vyacheslav Dubeyko099e9242013-11-12 15:11:08 -0800192#define HFSPLUS_ATTR_TREE_NODE_SIZE 8192
193#define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3
194#define HFSPLUS_BTREE_HDR_USER_BYTES 128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196/* Some special File ID numbers (stolen from hfs.h) */
197#define HFSPLUS_POR_CNID 1 /* Parent Of the Root */
198#define HFSPLUS_ROOT_CNID 2 /* ROOT directory */
199#define HFSPLUS_EXT_CNID 3 /* EXTents B-tree */
200#define HFSPLUS_CAT_CNID 4 /* CATalog B-tree */
201#define HFSPLUS_BAD_CNID 5 /* BAD blocks file */
202#define HFSPLUS_ALLOC_CNID 6 /* ALLOCation file */
203#define HFSPLUS_START_CNID 7 /* STARTup file */
204#define HFSPLUS_ATTR_CNID 8 /* ATTRibutes file */
205#define HFSPLUS_EXCH_CNID 15 /* ExchangeFiles temp id */
206#define HFSPLUS_FIRSTUSER_CNID 16 /* first available user id */
207
David Elliott2179d372006-01-18 17:43:08 -0800208/* btree key type */
209#define HFSPLUS_KEY_CASEFOLDING 0xCF /* case-insensitive */
210#define HFSPLUS_KEY_BINARY 0xBC /* case-sensitive */
211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/* HFS+ catalog entry key */
213struct hfsplus_cat_key {
214 __be16 key_len;
215 hfsplus_cnid parent;
216 struct hfsplus_unistr name;
217} __packed;
218
Eric Sandeen9250f922010-10-14 09:53:48 -0400219#define HFSPLUS_CAT_KEYLEN (sizeof(struct hfsplus_cat_key))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221/* Structs from hfs.h */
222struct hfsp_point {
223 __be16 v;
224 __be16 h;
225} __packed;
226
227struct hfsp_rect {
228 __be16 top;
229 __be16 left;
230 __be16 bottom;
231 __be16 right;
232} __packed;
233
234
235/* HFS directory info (stolen from hfs.h */
236struct DInfo {
237 struct hfsp_rect frRect;
238 __be16 frFlags;
239 struct hfsp_point frLocation;
240 __be16 frView;
241} __packed;
242
243struct DXInfo {
244 struct hfsp_point frScroll;
245 __be32 frOpenChain;
246 __be16 frUnused;
247 __be16 frComment;
248 __be32 frPutAway;
249} __packed;
250
251/* HFS+ folder data (part of an hfsplus_cat_entry) */
252struct hfsplus_cat_folder {
253 __be16 type;
254 __be16 flags;
255 __be32 valence;
256 hfsplus_cnid id;
257 __be32 create_date;
258 __be32 content_mod_date;
259 __be32 attribute_mod_date;
260 __be32 access_date;
261 __be32 backup_date;
262 struct hfsplus_perm permissions;
Kees Cooke35fa562022-01-19 18:09:47 -0800263 struct_group_attr(info, __packed,
264 struct DInfo user_info;
265 struct DXInfo finder_info;
266 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 __be32 text_encoding;
Sergei Antonovd7d673a2014-03-10 15:49:51 -0700268 __be32 subfolders; /* Subfolder count in HFSX. Reserved in HFS+. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269} __packed;
270
271/* HFS file info (stolen from hfs.h) */
272struct FInfo {
273 __be32 fdType;
274 __be32 fdCreator;
275 __be16 fdFlags;
276 struct hfsp_point fdLocation;
277 __be16 fdFldr;
278} __packed;
279
280struct FXInfo {
281 __be16 fdIconID;
282 u8 fdUnused[8];
283 __be16 fdComment;
284 __be32 fdPutAway;
285} __packed;
286
287/* HFS+ file data (part of a cat_entry) */
288struct hfsplus_cat_file {
289 __be16 type;
290 __be16 flags;
291 u32 reserved1;
292 hfsplus_cnid id;
293 __be32 create_date;
294 __be32 content_mod_date;
295 __be32 attribute_mod_date;
296 __be32 access_date;
297 __be32 backup_date;
298 struct hfsplus_perm permissions;
Kees Cooke35fa562022-01-19 18:09:47 -0800299 struct_group_attr(info, __packed,
300 struct FInfo user_info;
301 struct FXInfo finder_info;
302 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 __be32 text_encoding;
304 u32 reserved2;
305
306 struct hfsplus_fork_raw data_fork;
307 struct hfsplus_fork_raw rsrc_fork;
308} __packed;
309
Sergei Antonovd7d673a2014-03-10 15:49:51 -0700310/* File and folder flag bits */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311#define HFSPLUS_FILE_LOCKED 0x0001
312#define HFSPLUS_FILE_THREAD_EXISTS 0x0002
Vyacheslav Dubeyko9ed083d2013-02-27 17:03:00 -0800313#define HFSPLUS_XATTR_EXISTS 0x0004
314#define HFSPLUS_ACL_EXISTS 0x0008
Sergei Antonovd7d673a2014-03-10 15:49:51 -0700315#define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count
316 * (HFSX only) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
318/* HFS+ catalog thread (part of a cat_entry) */
319struct hfsplus_cat_thread {
320 __be16 type;
321 s16 reserved;
322 hfsplus_cnid parentID;
323 struct hfsplus_unistr nodeName;
324} __packed;
325
326#define HFSPLUS_MIN_THREAD_SZ 10
327
328/* A data record in the catalog tree */
329typedef union {
330 __be16 type;
331 struct hfsplus_cat_folder folder;
332 struct hfsplus_cat_file file;
333 struct hfsplus_cat_thread thread;
334} __packed hfsplus_cat_entry;
335
336/* HFS+ catalog entry type */
337#define HFSPLUS_FOLDER 0x0001
338#define HFSPLUS_FILE 0x0002
339#define HFSPLUS_FOLDER_THREAD 0x0003
340#define HFSPLUS_FILE_THREAD 0x0004
341
342/* HFS+ extents tree key */
343struct hfsplus_ext_key {
344 __be16 key_len;
345 u8 fork_type;
346 u8 pad;
347 hfsplus_cnid cnid;
348 __be32 start_block;
349} __packed;
350
Eric Sandeen9250f922010-10-14 09:53:48 -0400351#define HFSPLUS_EXT_KEYLEN sizeof(struct hfsplus_ext_key)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Vyacheslav Dubeyko9ed083d2013-02-27 17:03:00 -0800353#define HFSPLUS_XATTR_FINDER_INFO_NAME "com.apple.FinderInfo"
354#define HFSPLUS_XATTR_ACL_NAME "com.apple.system.Security"
355
356#define HFSPLUS_ATTR_INLINE_DATA 0x10
357#define HFSPLUS_ATTR_FORK_DATA 0x20
358#define HFSPLUS_ATTR_EXTENTS 0x30
359
360/* HFS+ attributes tree key */
361struct hfsplus_attr_key {
362 __be16 key_len;
363 __be16 pad;
364 hfsplus_cnid cnid;
365 __be32 start_block;
366 struct hfsplus_attr_unistr key_name;
367} __packed;
368
369#define HFSPLUS_ATTR_KEYLEN sizeof(struct hfsplus_attr_key)
370
371/* HFS+ fork data attribute */
372struct hfsplus_attr_fork_data {
373 __be32 record_type;
374 __be32 reserved;
375 struct hfsplus_fork_raw the_fork;
376} __packed;
377
378/* HFS+ extension attribute */
379struct hfsplus_attr_extents {
380 __be32 record_type;
381 __be32 reserved;
382 struct hfsplus_extent extents;
383} __packed;
384
385#define HFSPLUS_MAX_INLINE_DATA_SIZE 3802
386
387/* HFS+ attribute inline data */
388struct hfsplus_attr_inline_data {
389 __be32 record_type;
390 __be32 reserved1;
391 u8 reserved2[6];
392 __be16 length;
393 u8 raw_bytes[HFSPLUS_MAX_INLINE_DATA_SIZE];
394} __packed;
395
396/* A data record in the attributes tree */
397typedef union {
398 __be32 record_type;
399 struct hfsplus_attr_fork_data fork_data;
400 struct hfsplus_attr_extents extents;
401 struct hfsplus_attr_inline_data inline_data;
402} __packed hfsplus_attr_entry;
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404/* HFS+ generic BTree key */
405typedef union {
406 __be16 key_len;
407 struct hfsplus_cat_key cat;
408 struct hfsplus_ext_key ext;
Vyacheslav Dubeyko9ed083d2013-02-27 17:03:00 -0800409 struct hfsplus_attr_key attr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410} __packed hfsplus_btree_key;
411
412#endif