1 /* SPDX-License-Identifier: GPL-2.0 */
3 * linux/include/linux/hfsplus_raw.h
6 * Brad Boyer (flar@pants.nu)
7 * (C) 2003 Ardis Technologies <roman@ardistech.com>
9 * Format of structures on disk
10 * Information taken from Apple Technote #1150 (HFS Plus Volume Format)
14 #ifndef _LINUX_HFSPLUS_RAW_H
15 #define _LINUX_HFSPLUS_RAW_H
17 #include <linux/types.h>
20 #define HFSPLUS_SECTOR_SIZE 512
21 #define HFSPLUS_SECTOR_SHIFT 9
22 #define HFSPLUS_VOLHEAD_SECTOR 2
23 #define HFSPLUS_VOLHEAD_SIG 0x482b
24 #define HFSPLUS_VOLHEAD_SIGX 0x4858
25 #define HFSPLUS_SUPER_MAGIC 0x482b
26 #define HFSPLUS_MIN_VERSION 4
27 #define HFSPLUS_CURRENT_VERSION 5
29 #define HFSP_WRAP_MAGIC 0x4244
30 #define HFSP_WRAP_ATTRIB_SLOCK 0x8000
31 #define HFSP_WRAP_ATTRIB_SPARED 0x0200
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
40 #define HFSP_HIDDENDIR_NAME \
41 "\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80\xe2\x90\x80HFS+ Private Data"
43 #define HFSP_HARDLINK_TYPE 0x686c6e6b /* 'hlnk' */
44 #define HFSP_HFSPLUS_CREATOR 0x6866732b /* 'hfs+' */
46 #define HFSP_SYMLINK_TYPE 0x736c6e6b /* 'slnk' */
47 #define HFSP_SYMLINK_CREATOR 0x72686170 /* 'rhap' */
49 #define HFSP_MOUNT_VERSION 0x482b4c78 /* 'H+Lx' */
51 /* Structures used on disk */
53 typedef __be32 hfsplus_cnid
;
54 typedef __be16 hfsplus_unichr
;
56 #define HFSPLUS_MAX_STRLEN 255
57 #define HFSPLUS_ATTR_MAX_STRLEN 127
59 /* A "string" as used in filenames, etc. */
60 struct hfsplus_unistr
{
62 hfsplus_unichr unicode
[HFSPLUS_MAX_STRLEN
];
66 * A "string" is used in attributes file
67 * for name of extended attribute
69 struct hfsplus_attr_unistr
{
71 hfsplus_unichr unicode
[HFSPLUS_ATTR_MAX_STRLEN
];
74 /* POSIX permissions */
84 #define HFSPLUS_FLG_NODUMP 0x01
85 #define HFSPLUS_FLG_IMMUTABLE 0x02
86 #define HFSPLUS_FLG_APPEND 0x04
88 /* A single contiguous area of a file */
89 struct hfsplus_extent
{
93 typedef struct hfsplus_extent hfsplus_extent_rec
[8];
95 /* Information for a "Fork" in a file */
96 struct hfsplus_fork_raw
{
100 hfsplus_extent_rec extents
;
103 /* HFS+ Volume Header */
108 __be32 last_mount_vers
;
124 __be32 rsrc_clump_sz
;
125 __be32 data_clump_sz
;
126 hfsplus_cnid next_cnid
;
129 __be64 encodings_bmp
;
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
;
140 /* HFS+ volume attributes */
141 #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)
148 #define HFSPLUS_VOL_UNUSED_NODE_FIX (1 << 31)
150 /* HFS+ BTree node descriptor */
151 struct hfs_bnode_desc
{
160 /* HFS+ BTree node types */
161 #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 */
166 /* HFS+ BTree header */
167 struct hfs_btree_header_rec
{
185 /* BTree attributes */
186 #define HFS_TREE_BIGKEYS 2
187 #define HFS_TREE_VARIDXKEYS 4
189 /* HFS+ BTree misc info */
190 #define HFSPLUS_TREE_HEAD 0
191 #define HFSPLUS_NODE_MXSZ 32768
192 #define HFSPLUS_ATTR_TREE_NODE_SIZE 8192
193 #define HFSPLUS_BTREE_HDR_NODE_RECS_COUNT 3
194 #define HFSPLUS_BTREE_HDR_USER_BYTES 128
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 */
209 #define HFSPLUS_KEY_CASEFOLDING 0xCF /* case-insensitive */
210 #define HFSPLUS_KEY_BINARY 0xBC /* case-sensitive */
212 /* HFS+ catalog entry key */
213 struct hfsplus_cat_key
{
216 struct hfsplus_unistr name
;
219 #define HFSPLUS_CAT_KEYLEN (sizeof(struct hfsplus_cat_key))
221 /* Structs from hfs.h */
235 /* HFS directory info (stolen from hfs.h */
237 struct hfsp_rect frRect
;
239 struct hfsp_point frLocation
;
244 struct hfsp_point frScroll
;
251 /* HFS+ folder data (part of an hfsplus_cat_entry) */
252 struct hfsplus_cat_folder
{
258 __be32 content_mod_date
;
259 __be32 attribute_mod_date
;
262 struct hfsplus_perm permissions
;
263 struct DInfo user_info
;
264 struct DXInfo finder_info
;
265 __be32 text_encoding
;
266 __be32 subfolders
; /* Subfolder count in HFSX. Reserved in HFS+. */
269 /* HFS file info (stolen from hfs.h) */
274 struct hfsp_point fdLocation
;
285 /* HFS+ file data (part of a cat_entry) */
286 struct hfsplus_cat_file
{
292 __be32 content_mod_date
;
293 __be32 attribute_mod_date
;
296 struct hfsplus_perm permissions
;
297 struct FInfo user_info
;
298 struct FXInfo finder_info
;
299 __be32 text_encoding
;
302 struct hfsplus_fork_raw data_fork
;
303 struct hfsplus_fork_raw rsrc_fork
;
306 /* File and folder flag bits */
307 #define HFSPLUS_FILE_LOCKED 0x0001
308 #define HFSPLUS_FILE_THREAD_EXISTS 0x0002
309 #define HFSPLUS_XATTR_EXISTS 0x0004
310 #define HFSPLUS_ACL_EXISTS 0x0008
311 #define HFSPLUS_HAS_FOLDER_COUNT 0x0010 /* Folder has subfolder count
314 /* HFS+ catalog thread (part of a cat_entry) */
315 struct hfsplus_cat_thread
{
318 hfsplus_cnid parentID
;
319 struct hfsplus_unistr nodeName
;
322 #define HFSPLUS_MIN_THREAD_SZ 10
324 /* A data record in the catalog tree */
327 struct hfsplus_cat_folder folder
;
328 struct hfsplus_cat_file file
;
329 struct hfsplus_cat_thread thread
;
330 } __packed hfsplus_cat_entry
;
332 /* HFS+ catalog entry type */
333 #define HFSPLUS_FOLDER 0x0001
334 #define HFSPLUS_FILE 0x0002
335 #define HFSPLUS_FOLDER_THREAD 0x0003
336 #define HFSPLUS_FILE_THREAD 0x0004
338 /* HFS+ extents tree key */
339 struct hfsplus_ext_key
{
347 #define HFSPLUS_EXT_KEYLEN sizeof(struct hfsplus_ext_key)
349 #define HFSPLUS_XATTR_FINDER_INFO_NAME "com.apple.FinderInfo"
350 #define HFSPLUS_XATTR_ACL_NAME "com.apple.system.Security"
352 #define HFSPLUS_ATTR_INLINE_DATA 0x10
353 #define HFSPLUS_ATTR_FORK_DATA 0x20
354 #define HFSPLUS_ATTR_EXTENTS 0x30
356 /* HFS+ attributes tree key */
357 struct hfsplus_attr_key
{
362 struct hfsplus_attr_unistr key_name
;
365 #define HFSPLUS_ATTR_KEYLEN sizeof(struct hfsplus_attr_key)
367 /* HFS+ fork data attribute */
368 struct hfsplus_attr_fork_data
{
371 struct hfsplus_fork_raw the_fork
;
374 /* HFS+ extension attribute */
375 struct hfsplus_attr_extents
{
378 struct hfsplus_extent extents
;
381 #define HFSPLUS_MAX_INLINE_DATA_SIZE 3802
383 /* HFS+ attribute inline data */
384 struct hfsplus_attr_inline_data
{
389 u8 raw_bytes
[HFSPLUS_MAX_INLINE_DATA_SIZE
];
392 /* A data record in the attributes tree */
395 struct hfsplus_attr_fork_data fork_data
;
396 struct hfsplus_attr_extents extents
;
397 struct hfsplus_attr_inline_data inline_data
;
398 } __packed hfsplus_attr_entry
;
400 /* HFS+ generic BTree key */
403 struct hfsplus_cat_key cat
;
404 struct hfsplus_ext_key ext
;
405 struct hfsplus_attr_key attr
;
406 } __packed hfsplus_btree_key
;