hfsplus: flush disk caches in sync and fsync
[deliverable/linux.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>
895c23f8 14#include <linux/mutex.h>
1da177e4
LT
15#include <linux/buffer_head.h>
16#include "hfsplus_raw.h"
17
18#define DBG_BNODE_REFS 0x00000001
19#define DBG_BNODE_MOD 0x00000002
20#define DBG_CAT_MOD 0x00000004
21#define DBG_INODE 0x00000008
22#define DBG_SUPER 0x00000010
23#define DBG_EXTENT 0x00000020
24#define DBG_BITMAP 0x00000040
25
26//#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
27//#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
28//#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
29#define DBG_MASK (0)
30
31#define dprint(flg, fmt, args...) \
32 if (flg & DBG_MASK) printk(fmt , ## args)
33
34/* Runtime config options */
35#define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
36
37#define HFSPLUS_TYPE_DATA 0x00
38#define HFSPLUS_TYPE_RSRC 0xFF
39
2179d372 40typedef int (*btree_keycmp)(const hfsplus_btree_key *, const hfsplus_btree_key *);
1da177e4
LT
41
42#define NODE_HASH_SIZE 256
43
44/* An HFS+ BTree held in memory */
45struct hfs_btree {
46 struct super_block *sb;
47 struct inode *inode;
48 btree_keycmp keycmp;
49
50 u32 cnid;
51 u32 root;
52 u32 leaf_count;
53 u32 leaf_head;
54 u32 leaf_tail;
55 u32 node_count;
56 u32 free_nodes;
57 u32 attributes;
58
59 unsigned int node_size;
60 unsigned int node_size_shift;
61 unsigned int max_key_len;
62 unsigned int depth;
63
64 //unsigned int map1_size, map_size;
467c3d9c 65 struct mutex tree_lock;
1da177e4
LT
66
67 unsigned int pages_per_bnode;
68 spinlock_t hash_lock;
69 struct hfs_bnode *node_hash[NODE_HASH_SIZE];
70 int node_hash_cnt;
71};
72
73struct page;
74
75/* An HFS+ BTree node in memory */
76struct hfs_bnode {
77 struct hfs_btree *tree;
78
79 u32 prev;
80 u32 this;
81 u32 next;
82 u32 parent;
83
84 u16 num_recs;
85 u8 type;
86 u8 height;
87
88 struct hfs_bnode *next_hash;
89 unsigned long flags;
90 wait_queue_head_t lock_wq;
91 atomic_t refcnt;
92 unsigned int page_offset;
93 struct page *page[0];
94};
95
96#define HFS_BNODE_LOCK 0
97#define HFS_BNODE_ERROR 1
98#define HFS_BNODE_NEW 2
99#define HFS_BNODE_DIRTY 3
100#define HFS_BNODE_DELETED 4
101
102/*
103 * HFS+ superblock info (built from Volume Header on disk)
104 */
105
106struct hfsplus_vh;
107struct hfs_btree;
108
109struct hfsplus_sb_info {
1da177e4 110 struct hfsplus_vh *s_vhdr;
52399b17 111 struct hfsplus_vh *s_backup_vhdr;
1da177e4
LT
112 struct hfs_btree *ext_tree;
113 struct hfs_btree *cat_tree;
114 struct hfs_btree *attr_tree;
115 struct inode *alloc_file;
116 struct inode *hidden_dir;
117 struct nls_table *nls;
118
119 /* Runtime variables */
120 u32 blockoffset;
52399b17
CH
121 sector_t part_start;
122 sector_t sect_count;
1da177e4
LT
123 int fs_shift;
124
7ac9fb9c 125 /* immutable data from the volume header */
1da177e4
LT
126 u32 alloc_blksz;
127 int alloc_blksz_shift;
128 u32 total_blocks;
7ac9fb9c
CH
129 u32 data_clump_blocks, rsrc_clump_blocks;
130
131 /* mutable data from the volume header, protected by alloc_mutex */
1da177e4 132 u32 free_blocks;
7ac9fb9c
CH
133 struct mutex alloc_mutex;
134
135 /* mutable data from the volume header, protected by vh_mutex */
1da177e4
LT
136 u32 next_cnid;
137 u32 file_count;
138 u32 folder_count;
7ac9fb9c 139 struct mutex vh_mutex;
1da177e4
LT
140
141 /* Config options */
142 u32 creator;
143 u32 type;
144
145 umode_t umask;
146 uid_t uid;
147 gid_t gid;
148
149 int part, session;
150
151 unsigned long flags;
1da177e4
LT
152};
153
84adede3
CH
154#define HFSPLUS_SB_WRITEBACKUP 0
155#define HFSPLUS_SB_NODECOMPOSE 1
156#define HFSPLUS_SB_FORCE 2
157#define HFSPLUS_SB_HFSX 3
158#define HFSPLUS_SB_CASEFOLD 4
34a2d313 159#define HFSPLUS_SB_NOBARRIER 5
1da177e4 160
e3494705
CH
161static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
162{
163 return sb->s_fs_info;
164}
165
1da177e4
LT
166
167struct hfsplus_inode_info {
1da177e4
LT
168 atomic_t opencnt;
169
7fcc99f4
CH
170 /*
171 * Extent allocation information, protected by extents_lock.
172 */
173 u32 first_blocks;
174 u32 clump_blocks;
175 u32 alloc_blocks;
176 u32 cached_start;
177 u32 cached_blocks;
178 hfsplus_extent_rec first_extents;
179 hfsplus_extent_rec cached_extents;
b33b7921 180 unsigned int extent_state;
7fcc99f4 181 struct mutex extents_lock;
1da177e4 182
7fcc99f4
CH
183 /*
184 * Immutable data.
185 */
186 struct inode *rsrc_inode;
9a4cad95 187 __be32 create_date;
f6089ff8
CH
188
189 /*
190 * Protected by sbi->vh_mutex.
191 */
192 u32 linkid;
1da177e4 193
b33b7921
CH
194 /*
195 * Accessed using atomic bitops.
196 */
197 unsigned long flags;
198
7fcc99f4
CH
199 /*
200 * Protected by i_mutex.
201 */
202 sector_t fs_blocks;
722c55d1 203 u8 userflags; /* BSD user file flags */
1da177e4
LT
204 struct list_head open_dir_list;
205 loff_t phys_size;
7fcc99f4 206
1da177e4
LT
207 struct inode vfs_inode;
208};
209
b33b7921
CH
210#define HFSPLUS_EXT_DIRTY 0x0001
211#define HFSPLUS_EXT_NEW 0x0002
212
213#define HFSPLUS_I_RSRC 0 /* represents a resource fork */
e3494705
CH
214#define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
215#define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
216#define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
1da177e4 217
b33b7921
CH
218#define HFSPLUS_IS_RSRC(inode) \
219 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
1da177e4 220
e3494705
CH
221static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
222{
223 return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
224}
225
226/*
227 * Mark an inode dirty, and also mark the btree in which the
228 * specific type of metadata is stored.
229 * For data or metadata that gets written back by into the catalog btree
230 * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
231 */
232static inline void hfsplus_mark_inode_dirty(struct inode *inode,
233 unsigned int flag)
234{
235 set_bit(flag, &HFSPLUS_I(inode)->flags);
236 mark_inode_dirty(inode);
237}
238
1da177e4
LT
239struct hfs_find_data {
240 /* filled by caller */
241 hfsplus_btree_key *search_key;
242 hfsplus_btree_key *key;
243 /* filled by find */
244 struct hfs_btree *tree;
245 struct hfs_bnode *bnode;
246 /* filled by findrec */
247 int record;
248 int keyoffset, keylength;
249 int entryoffset, entrylength;
250};
251
252struct hfsplus_readdir_data {
253 struct list_head list;
254 struct file *file;
255 struct hfsplus_cat_key key;
256};
257
258#define hfs_btree_open hfsplus_btree_open
259#define hfs_btree_close hfsplus_btree_close
260#define hfs_btree_write hfsplus_btree_write
261#define hfs_bmap_alloc hfsplus_bmap_alloc
262#define hfs_bmap_free hfsplus_bmap_free
263#define hfs_bnode_read hfsplus_bnode_read
264#define hfs_bnode_read_u16 hfsplus_bnode_read_u16
265#define hfs_bnode_read_u8 hfsplus_bnode_read_u8
266#define hfs_bnode_read_key hfsplus_bnode_read_key
267#define hfs_bnode_write hfsplus_bnode_write
268#define hfs_bnode_write_u16 hfsplus_bnode_write_u16
269#define hfs_bnode_clear hfsplus_bnode_clear
270#define hfs_bnode_copy hfsplus_bnode_copy
271#define hfs_bnode_move hfsplus_bnode_move
272#define hfs_bnode_dump hfsplus_bnode_dump
273#define hfs_bnode_unlink hfsplus_bnode_unlink
274#define hfs_bnode_findhash hfsplus_bnode_findhash
275#define hfs_bnode_find hfsplus_bnode_find
276#define hfs_bnode_unhash hfsplus_bnode_unhash
277#define hfs_bnode_free hfsplus_bnode_free
278#define hfs_bnode_create hfsplus_bnode_create
279#define hfs_bnode_get hfsplus_bnode_get
280#define hfs_bnode_put hfsplus_bnode_put
281#define hfs_brec_lenoff hfsplus_brec_lenoff
282#define hfs_brec_keylen hfsplus_brec_keylen
283#define hfs_brec_insert hfsplus_brec_insert
284#define hfs_brec_remove hfsplus_brec_remove
285#define hfs_find_init hfsplus_find_init
286#define hfs_find_exit hfsplus_find_exit
287#define __hfs_brec_find __hplusfs_brec_find
288#define hfs_brec_find hfsplus_brec_find
289#define hfs_brec_read hfsplus_brec_read
290#define hfs_brec_goto hfsplus_brec_goto
291#define hfs_part_find hfsplus_part_find
292
293/*
294 * definitions for ext2 flag ioctls (linux really needs a generic
295 * interface for this).
296 */
297
298/* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
299 * chattr/lsattr */
36695673
DH
300#define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
301#define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
1da177e4
LT
302
303
304/*
305 * Functions in any *.c used in other files
306 */
307
308/* bitmap.c */
309int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
310int hfsplus_block_free(struct super_block *, u32, u32);
311
312/* btree.c */
313struct hfs_btree *hfs_btree_open(struct super_block *, u32);
314void hfs_btree_close(struct hfs_btree *);
315void hfs_btree_write(struct hfs_btree *);
316struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *);
317void hfs_bmap_free(struct hfs_bnode *);
318
319/* bnode.c */
320void hfs_bnode_read(struct hfs_bnode *, void *, int, int);
321u16 hfs_bnode_read_u16(struct hfs_bnode *, int);
322u8 hfs_bnode_read_u8(struct hfs_bnode *, int);
323void hfs_bnode_read_key(struct hfs_bnode *, void *, int);
324void hfs_bnode_write(struct hfs_bnode *, void *, int, int);
325void hfs_bnode_write_u16(struct hfs_bnode *, int, u16);
326void hfs_bnode_clear(struct hfs_bnode *, int, int);
327void hfs_bnode_copy(struct hfs_bnode *, int,
328 struct hfs_bnode *, int, int);
329void hfs_bnode_move(struct hfs_bnode *, int, int, int);
330void hfs_bnode_dump(struct hfs_bnode *);
331void hfs_bnode_unlink(struct hfs_bnode *);
332struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32);
333struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32);
334void hfs_bnode_unhash(struct hfs_bnode *);
335void hfs_bnode_free(struct hfs_bnode *);
336struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
337void hfs_bnode_get(struct hfs_bnode *);
338void hfs_bnode_put(struct hfs_bnode *);
339
340/* brec.c */
341u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
342u16 hfs_brec_keylen(struct hfs_bnode *, u16);
343int hfs_brec_insert(struct hfs_find_data *, void *, int);
344int hfs_brec_remove(struct hfs_find_data *);
345
346/* bfind.c */
347int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
348void hfs_find_exit(struct hfs_find_data *);
349int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *);
350int hfs_brec_find(struct hfs_find_data *);
351int hfs_brec_read(struct hfs_find_data *, void *, int);
352int hfs_brec_goto(struct hfs_find_data *, int);
353
354/* catalog.c */
2179d372
DE
355int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
356int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
1da177e4
LT
357void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *, u32, struct qstr *);
358int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *);
359int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
360int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
361int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
362 struct inode *, struct qstr *);
90e61690 363void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
1da177e4 364
4b0a8da7
AB
365/* dir.c */
366extern const struct inode_operations hfsplus_dir_inode_operations;
367extern const struct file_operations hfsplus_dir_operations;
368
1da177e4 369/* extents.c */
2179d372 370int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
1da177e4
LT
371void hfsplus_ext_write_extent(struct inode *);
372int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
373int hfsplus_free_fork(struct super_block *, u32, struct hfsplus_fork_raw *, int);
374int hfsplus_file_extend(struct inode *);
375void hfsplus_file_truncate(struct inode *);
376
377/* inode.c */
f5e54d6e
CH
378extern const struct address_space_operations hfsplus_aops;
379extern const struct address_space_operations hfsplus_btree_aops;
e16404ed 380extern const struct dentry_operations hfsplus_dentry_operations;
1da177e4
LT
381
382void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
383void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
384int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *);
385int hfsplus_cat_write_inode(struct inode *);
386struct inode *hfsplus_new_inode(struct super_block *, int);
387void hfsplus_delete_inode(struct inode *);
eb29d66d 388int hfsplus_file_fsync(struct file *file, int datasync);
1da177e4
LT
389
390/* ioctl.c */
7cc4bcc6 391long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
1da177e4
LT
392int hfsplus_setxattr(struct dentry *dentry, const char *name,
393 const void *value, size_t size, int flags);
394ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
395 void *value, size_t size);
396ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
397
398/* options.c */
717dd80e 399int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
6f80dfe5 400int hfsplus_parse_options_remount(char *input, int *force);
717dd80e
RZ
401void hfsplus_fill_defaults(struct hfsplus_sb_info *);
402int hfsplus_show_options(struct seq_file *, struct vfsmount *);
1da177e4 403
63525391
DH
404/* super.c */
405struct inode *hfsplus_iget(struct super_block *, unsigned long);
b5fc510c 406int hfsplus_sync_fs(struct super_block *sb, int wait);
63525391 407
1da177e4
LT
408/* tables.c */
409extern u16 hfsplus_case_fold_table[];
410extern u16 hfsplus_decompose_table[];
411extern u16 hfsplus_compose_table[];
412
413/* unicode.c */
2179d372
DE
414int hfsplus_strcasecmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
415int hfsplus_strcmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
1da177e4
LT
416int hfsplus_uni2asc(struct super_block *, const struct hfsplus_unistr *, char *, int *);
417int hfsplus_asc2uni(struct super_block *, struct hfsplus_unistr *, const char *, int);
d45bce8f
DG
418int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str);
419int hfsplus_compare_dentry(struct dentry *dentry, struct qstr *s1, struct qstr *s2);
1da177e4
LT
420
421/* wrapper.c */
422int hfsplus_read_wrapper(struct super_block *);
1da177e4 423int hfs_part_find(struct super_block *, sector_t *, sector_t *);
52399b17
CH
424int hfsplus_submit_bio(struct block_device *bdev, sector_t sector,
425 void *data, int rw);
1da177e4 426
1da177e4
LT
427/* time macros */
428#define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
429#define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
430
431/* compatibility */
432#define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
433#define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
434#define hfsp_now2mt() __hfsp_ut2mt(get_seconds())
435
1da177e4 436#endif
This page took 0.521411 seconds and 5 git commands to generate.