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