[PATCH] hfs: add HFSX support
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / hfsplus / hfsplus_fs.h
CommitLineData
1da177e4
LT
1/*
2 * linux/include/linux/hfsplus_fs.h
3 *
4 * Copyright (C) 1999
5 * Brad Boyer (flar@pants.nu)
6 * (C) 2003 Ardis Technologies <roman@ardistech.com>
7 *
8 */
9
10#ifndef _LINUX_HFSPLUS_FS_H
11#define _LINUX_HFSPLUS_FS_H
12
13#include <linux/fs.h>
1da177e4
LT
14#include <linux/buffer_head.h>
15#include "hfsplus_raw.h"
16
17#define DBG_BNODE_REFS 0x00000001
18#define DBG_BNODE_MOD 0x00000002
19#define DBG_CAT_MOD 0x00000004
20#define DBG_INODE 0x00000008
21#define DBG_SUPER 0x00000010
22#define DBG_EXTENT 0x00000020
23#define DBG_BITMAP 0x00000040
24
25//#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
26//#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
27//#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
28#define DBG_MASK (0)
29
30#define dprint(flg, fmt, args...) \
31 if (flg & DBG_MASK) printk(fmt , ## args)
32
33/* Runtime config options */
34#define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
35
36#define HFSPLUS_TYPE_DATA 0x00
37#define HFSPLUS_TYPE_RSRC 0xFF
38
2179d372 39typedef int (*btree_keycmp)(const hfsplus_btree_key *, const hfsplus_btree_key *);
1da177e4
LT
40
41#define NODE_HASH_SIZE 256
42
43/* An HFS+ BTree held in memory */
44struct hfs_btree {
45 struct super_block *sb;
46 struct inode *inode;
47 btree_keycmp keycmp;
48
49 u32 cnid;
50 u32 root;
51 u32 leaf_count;
52 u32 leaf_head;
53 u32 leaf_tail;
54 u32 node_count;
55 u32 free_nodes;
56 u32 attributes;
57
58 unsigned int node_size;
59 unsigned int node_size_shift;
60 unsigned int max_key_len;
61 unsigned int depth;
62
63 //unsigned int map1_size, map_size;
64 struct semaphore tree_lock;
65
66 unsigned int pages_per_bnode;
67 spinlock_t hash_lock;
68 struct hfs_bnode *node_hash[NODE_HASH_SIZE];
69 int node_hash_cnt;
70};
71
72struct page;
73
74/* An HFS+ BTree node in memory */
75struct hfs_bnode {
76 struct hfs_btree *tree;
77
78 u32 prev;
79 u32 this;
80 u32 next;
81 u32 parent;
82
83 u16 num_recs;
84 u8 type;
85 u8 height;
86
87 struct hfs_bnode *next_hash;
88 unsigned long flags;
89 wait_queue_head_t lock_wq;
90 atomic_t refcnt;
91 unsigned int page_offset;
92 struct page *page[0];
93};
94
95#define HFS_BNODE_LOCK 0
96#define HFS_BNODE_ERROR 1
97#define HFS_BNODE_NEW 2
98#define HFS_BNODE_DIRTY 3
99#define HFS_BNODE_DELETED 4
100
101/*
102 * HFS+ superblock info (built from Volume Header on disk)
103 */
104
105struct hfsplus_vh;
106struct hfs_btree;
107
108struct hfsplus_sb_info {
109 struct buffer_head *s_vhbh;
110 struct hfsplus_vh *s_vhdr;
111 struct hfs_btree *ext_tree;
112 struct hfs_btree *cat_tree;
113 struct hfs_btree *attr_tree;
114 struct inode *alloc_file;
115 struct inode *hidden_dir;
116 struct nls_table *nls;
117
118 /* Runtime variables */
119 u32 blockoffset;
120 u32 sect_count;
121 int fs_shift;
122
123 /* Stuff in host order from Vol Header */
124 u32 alloc_blksz;
125 int alloc_blksz_shift;
126 u32 total_blocks;
127 u32 free_blocks;
128 u32 next_alloc;
129 u32 next_cnid;
130 u32 file_count;
131 u32 folder_count;
132 u32 data_clump_blocks, rsrc_clump_blocks;
133
134 /* Config options */
135 u32 creator;
136 u32 type;
137
138 umode_t umask;
139 uid_t uid;
140 gid_t gid;
141
142 int part, session;
143
144 unsigned long flags;
145
1da177e4
LT
146 struct hlist_head rsrc_inodes;
147};
148
149#define HFSPLUS_SB_WRITEBACKUP 0x0001
150#define HFSPLUS_SB_NODECOMPOSE 0x0002
b0b623c3 151#define HFSPLUS_SB_FORCE 0x0004
2179d372 152#define HFSPLUS_SB_HFSX 0x0008
1da177e4
LT
153
154
155struct hfsplus_inode_info {
156 struct semaphore extents_lock;
157 u32 clump_blocks, alloc_blocks;
158 sector_t fs_blocks;
159 /* Allocation extents from catalog record or volume header */
160 hfsplus_extent_rec first_extents;
161 u32 first_blocks;
162 hfsplus_extent_rec cached_extents;
163 u32 cached_start, cached_blocks;
164 atomic_t opencnt;
165
166 struct inode *rsrc_inode;
167 unsigned long flags;
168
169 /* Device number in hfsplus_permissions in catalog */
170 u32 dev;
171 /* BSD system and user file flags */
172 u8 rootflags;
173 u8 userflags;
174
175 struct list_head open_dir_list;
176 loff_t phys_size;
177 struct inode vfs_inode;
178};
179
180#define HFSPLUS_FLG_RSRC 0x0001
181#define HFSPLUS_FLG_EXT_DIRTY 0x0002
182#define HFSPLUS_FLG_EXT_NEW 0x0004
183
184#define HFSPLUS_IS_DATA(inode) (!(HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC))
185#define HFSPLUS_IS_RSRC(inode) (HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC)
186
187struct hfs_find_data {
188 /* filled by caller */
189 hfsplus_btree_key *search_key;
190 hfsplus_btree_key *key;
191 /* filled by find */
192 struct hfs_btree *tree;
193 struct hfs_bnode *bnode;
194 /* filled by findrec */
195 int record;
196 int keyoffset, keylength;
197 int entryoffset, entrylength;
198};
199
200struct hfsplus_readdir_data {
201 struct list_head list;
202 struct file *file;
203 struct hfsplus_cat_key key;
204};
205
206#define hfs_btree_open hfsplus_btree_open
207#define hfs_btree_close hfsplus_btree_close
208#define hfs_btree_write hfsplus_btree_write
209#define hfs_bmap_alloc hfsplus_bmap_alloc
210#define hfs_bmap_free hfsplus_bmap_free
211#define hfs_bnode_read hfsplus_bnode_read
212#define hfs_bnode_read_u16 hfsplus_bnode_read_u16
213#define hfs_bnode_read_u8 hfsplus_bnode_read_u8
214#define hfs_bnode_read_key hfsplus_bnode_read_key
215#define hfs_bnode_write hfsplus_bnode_write
216#define hfs_bnode_write_u16 hfsplus_bnode_write_u16
217#define hfs_bnode_clear hfsplus_bnode_clear
218#define hfs_bnode_copy hfsplus_bnode_copy
219#define hfs_bnode_move hfsplus_bnode_move
220#define hfs_bnode_dump hfsplus_bnode_dump
221#define hfs_bnode_unlink hfsplus_bnode_unlink
222#define hfs_bnode_findhash hfsplus_bnode_findhash
223#define hfs_bnode_find hfsplus_bnode_find
224#define hfs_bnode_unhash hfsplus_bnode_unhash
225#define hfs_bnode_free hfsplus_bnode_free
226#define hfs_bnode_create hfsplus_bnode_create
227#define hfs_bnode_get hfsplus_bnode_get
228#define hfs_bnode_put hfsplus_bnode_put
229#define hfs_brec_lenoff hfsplus_brec_lenoff
230#define hfs_brec_keylen hfsplus_brec_keylen
231#define hfs_brec_insert hfsplus_brec_insert
232#define hfs_brec_remove hfsplus_brec_remove
233#define hfs_find_init hfsplus_find_init
234#define hfs_find_exit hfsplus_find_exit
235#define __hfs_brec_find __hplusfs_brec_find
236#define hfs_brec_find hfsplus_brec_find
237#define hfs_brec_read hfsplus_brec_read
238#define hfs_brec_goto hfsplus_brec_goto
239#define hfs_part_find hfsplus_part_find
240
241/*
242 * definitions for ext2 flag ioctls (linux really needs a generic
243 * interface for this).
244 */
245
246/* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
247 * chattr/lsattr */
248#define HFSPLUS_IOC_EXT2_GETFLAGS _IOR('f', 1, long)
249#define HFSPLUS_IOC_EXT2_SETFLAGS _IOW('f', 2, long)
250
251#define EXT2_FLAG_IMMUTABLE 0x00000010 /* Immutable file */
252#define EXT2_FLAG_APPEND 0x00000020 /* writes to file may only append */
253#define EXT2_FLAG_NODUMP 0x00000040 /* do not dump file */
254
255
256/*
257 * Functions in any *.c used in other files
258 */
259
260/* bitmap.c */
261int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
262int hfsplus_block_free(struct super_block *, u32, u32);
263
264/* btree.c */
265struct hfs_btree *hfs_btree_open(struct super_block *, u32);
266void hfs_btree_close(struct hfs_btree *);
267void hfs_btree_write(struct hfs_btree *);
268struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *);
269void hfs_bmap_free(struct hfs_bnode *);
270
271/* bnode.c */
272void hfs_bnode_read(struct hfs_bnode *, void *, int, int);
273u16 hfs_bnode_read_u16(struct hfs_bnode *, int);
274u8 hfs_bnode_read_u8(struct hfs_bnode *, int);
275void hfs_bnode_read_key(struct hfs_bnode *, void *, int);
276void hfs_bnode_write(struct hfs_bnode *, void *, int, int);
277void hfs_bnode_write_u16(struct hfs_bnode *, int, u16);
278void hfs_bnode_clear(struct hfs_bnode *, int, int);
279void hfs_bnode_copy(struct hfs_bnode *, int,
280 struct hfs_bnode *, int, int);
281void hfs_bnode_move(struct hfs_bnode *, int, int, int);
282void hfs_bnode_dump(struct hfs_bnode *);
283void hfs_bnode_unlink(struct hfs_bnode *);
284struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32);
285struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32);
286void hfs_bnode_unhash(struct hfs_bnode *);
287void hfs_bnode_free(struct hfs_bnode *);
288struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
289void hfs_bnode_get(struct hfs_bnode *);
290void hfs_bnode_put(struct hfs_bnode *);
291
292/* brec.c */
293u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
294u16 hfs_brec_keylen(struct hfs_bnode *, u16);
295int hfs_brec_insert(struct hfs_find_data *, void *, int);
296int hfs_brec_remove(struct hfs_find_data *);
297
298/* bfind.c */
299int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
300void hfs_find_exit(struct hfs_find_data *);
301int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *);
302int hfs_brec_find(struct hfs_find_data *);
303int hfs_brec_read(struct hfs_find_data *, void *, int);
304int hfs_brec_goto(struct hfs_find_data *, int);
305
306/* catalog.c */
2179d372
DE
307int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
308int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
1da177e4
LT
309void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *, u32, struct qstr *);
310int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *);
311int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
312int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
313int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
314 struct inode *, struct qstr *);
315
316/* extents.c */
2179d372 317int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
1da177e4
LT
318void hfsplus_ext_write_extent(struct inode *);
319int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
320int hfsplus_free_fork(struct super_block *, u32, struct hfsplus_fork_raw *, int);
321int hfsplus_file_extend(struct inode *);
322void hfsplus_file_truncate(struct inode *);
323
324/* inode.c */
325extern struct address_space_operations hfsplus_aops;
326extern struct address_space_operations hfsplus_btree_aops;
327
328void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
329void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
330int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *);
331int hfsplus_cat_write_inode(struct inode *);
332struct inode *hfsplus_new_inode(struct super_block *, int);
333void hfsplus_delete_inode(struct inode *);
334
335/* ioctl.c */
336int hfsplus_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
337 unsigned long arg);
338int hfsplus_setxattr(struct dentry *dentry, const char *name,
339 const void *value, size_t size, int flags);
340ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
341 void *value, size_t size);
342ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
343
344/* options.c */
717dd80e
RZ
345int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
346void hfsplus_fill_defaults(struct hfsplus_sb_info *);
347int hfsplus_show_options(struct seq_file *, struct vfsmount *);
1da177e4
LT
348
349/* tables.c */
350extern u16 hfsplus_case_fold_table[];
351extern u16 hfsplus_decompose_table[];
352extern u16 hfsplus_compose_table[];
353
354/* unicode.c */
2179d372
DE
355int hfsplus_strcasecmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
356int hfsplus_strcmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
1da177e4
LT
357int hfsplus_uni2asc(struct super_block *, const struct hfsplus_unistr *, char *, int *);
358int hfsplus_asc2uni(struct super_block *, struct hfsplus_unistr *, const char *, int);
359
360/* wrapper.c */
361int hfsplus_read_wrapper(struct super_block *);
362
363int hfs_part_find(struct super_block *, sector_t *, sector_t *);
364
365/* access macros */
366/*
367static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
368{
369 return sb->s_fs_info;
370}
371static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
372{
373 return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
374}
375*/
376#define HFSPLUS_SB(super) (*(struct hfsplus_sb_info *)(super)->s_fs_info)
377#define HFSPLUS_I(inode) (*list_entry(inode, struct hfsplus_inode_info, vfs_inode))
378
379#if 1
380#define hfsplus_kmap(p) ({ struct page *__p = (p); kmap(__p); })
381#define hfsplus_kunmap(p) ({ struct page *__p = (p); kunmap(__p); __p; })
382#else
383#define hfsplus_kmap(p) kmap(p)
384#define hfsplus_kunmap(p) kunmap(p)
385#endif
386
387#define sb_bread512(sb, sec, data) ({ \
388 struct buffer_head *__bh; \
389 sector_t __block; \
390 loff_t __start; \
391 int __offset; \
392 \
393 __start = (loff_t)(sec) << HFSPLUS_SECTOR_SHIFT;\
394 __block = __start >> (sb)->s_blocksize_bits; \
395 __offset = __start & ((sb)->s_blocksize - 1); \
396 __bh = sb_bread((sb), __block); \
397 if (likely(__bh != NULL)) \
398 data = (void *)(__bh->b_data + __offset);\
399 else \
400 data = NULL; \
401 __bh; \
402})
403
404/* time macros */
405#define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
406#define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
407
408/* compatibility */
409#define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
410#define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
411#define hfsp_now2mt() __hfsp_ut2mt(get_seconds())
412
413#define kdev_t_to_nr(x) (x)
414
415#endif