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