blob: 9889d0033b8f3821d670877c59497cdbc15d8eae [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Matthias Kaehlcke895c23f2008-07-25 01:46:36 -070014#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#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
David Elliott2179d372006-01-18 17:43:08 -080040typedef int (*btree_keycmp)(const hfsplus_btree_key *, const hfsplus_btree_key *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
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;
Thomas Gleixner467c3d92010-10-01 05:46:52 +020065 struct mutex tree_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
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 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 struct hfsplus_vh *s_vhdr;
Christoph Hellwig52399b12010-11-23 14:37:47 +0100111 struct hfsplus_vh *s_backup_vhdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 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;
Christoph Hellwig52399b12010-11-23 14:37:47 +0100121 sector_t part_start;
122 sector_t sect_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 int fs_shift;
124
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200125 /* immutable data from the volume header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 u32 alloc_blksz;
127 int alloc_blksz_shift;
128 u32 total_blocks;
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200129 u32 data_clump_blocks, rsrc_clump_blocks;
130
131 /* mutable data from the volume header, protected by alloc_mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 u32 free_blocks;
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200133 struct mutex alloc_mutex;
134
135 /* mutable data from the volume header, protected by vh_mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 u32 next_cnid;
137 u32 file_count;
138 u32 folder_count;
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200139 struct mutex vh_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152};
153
Christoph Hellwig84adede2010-10-01 05:45:20 +0200154#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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160
161struct hfsplus_inode_info {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 atomic_t opencnt;
163
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200164 /*
165 * Extent allocation information, protected by extents_lock.
166 */
167 u32 first_blocks;
168 u32 clump_blocks;
169 u32 alloc_blocks;
170 u32 cached_start;
171 u32 cached_blocks;
172 hfsplus_extent_rec first_extents;
173 hfsplus_extent_rec cached_extents;
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100174 unsigned int extent_state;
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200175 struct mutex extents_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200177 /*
178 * Immutable data.
179 */
180 struct inode *rsrc_inode;
Roman Zippel9a4cad92006-01-18 17:43:09 -0800181 __be32 create_date;
Christoph Hellwigf6089ff2010-10-14 09:54:28 -0400182
183 /*
184 * Protected by sbi->vh_mutex.
185 */
186 u32 linkid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200188 /*
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100189 * Accessed using atomic bitops.
190 */
191 unsigned long flags;
192
193 /*
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200194 * Protected by i_mutex.
195 */
196 sector_t fs_blocks;
Christoph Hellwig722c55d2010-10-14 09:54:33 -0400197 u8 userflags; /* BSD user file flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 struct list_head open_dir_list;
199 loff_t phys_size;
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 struct inode vfs_inode;
202};
203
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100204#define HFSPLUS_EXT_DIRTY 0x0001
205#define HFSPLUS_EXT_NEW 0x0002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100207#define HFSPLUS_I_RSRC 0 /* represents a resource fork */
208
209#define HFSPLUS_IS_RSRC(inode) \
210 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212struct hfs_find_data {
213 /* filled by caller */
214 hfsplus_btree_key *search_key;
215 hfsplus_btree_key *key;
216 /* filled by find */
217 struct hfs_btree *tree;
218 struct hfs_bnode *bnode;
219 /* filled by findrec */
220 int record;
221 int keyoffset, keylength;
222 int entryoffset, entrylength;
223};
224
225struct hfsplus_readdir_data {
226 struct list_head list;
227 struct file *file;
228 struct hfsplus_cat_key key;
229};
230
231#define hfs_btree_open hfsplus_btree_open
232#define hfs_btree_close hfsplus_btree_close
233#define hfs_btree_write hfsplus_btree_write
234#define hfs_bmap_alloc hfsplus_bmap_alloc
235#define hfs_bmap_free hfsplus_bmap_free
236#define hfs_bnode_read hfsplus_bnode_read
237#define hfs_bnode_read_u16 hfsplus_bnode_read_u16
238#define hfs_bnode_read_u8 hfsplus_bnode_read_u8
239#define hfs_bnode_read_key hfsplus_bnode_read_key
240#define hfs_bnode_write hfsplus_bnode_write
241#define hfs_bnode_write_u16 hfsplus_bnode_write_u16
242#define hfs_bnode_clear hfsplus_bnode_clear
243#define hfs_bnode_copy hfsplus_bnode_copy
244#define hfs_bnode_move hfsplus_bnode_move
245#define hfs_bnode_dump hfsplus_bnode_dump
246#define hfs_bnode_unlink hfsplus_bnode_unlink
247#define hfs_bnode_findhash hfsplus_bnode_findhash
248#define hfs_bnode_find hfsplus_bnode_find
249#define hfs_bnode_unhash hfsplus_bnode_unhash
250#define hfs_bnode_free hfsplus_bnode_free
251#define hfs_bnode_create hfsplus_bnode_create
252#define hfs_bnode_get hfsplus_bnode_get
253#define hfs_bnode_put hfsplus_bnode_put
254#define hfs_brec_lenoff hfsplus_brec_lenoff
255#define hfs_brec_keylen hfsplus_brec_keylen
256#define hfs_brec_insert hfsplus_brec_insert
257#define hfs_brec_remove hfsplus_brec_remove
258#define hfs_find_init hfsplus_find_init
259#define hfs_find_exit hfsplus_find_exit
260#define __hfs_brec_find __hplusfs_brec_find
261#define hfs_brec_find hfsplus_brec_find
262#define hfs_brec_read hfsplus_brec_read
263#define hfs_brec_goto hfsplus_brec_goto
264#define hfs_part_find hfsplus_part_find
265
266/*
267 * definitions for ext2 flag ioctls (linux really needs a generic
268 * interface for this).
269 */
270
271/* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
272 * chattr/lsattr */
David Howells36695672006-08-29 19:06:16 +0100273#define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
274#define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276
277/*
278 * Functions in any *.c used in other files
279 */
280
281/* bitmap.c */
282int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
283int hfsplus_block_free(struct super_block *, u32, u32);
284
285/* btree.c */
286struct hfs_btree *hfs_btree_open(struct super_block *, u32);
287void hfs_btree_close(struct hfs_btree *);
288void hfs_btree_write(struct hfs_btree *);
289struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *);
290void hfs_bmap_free(struct hfs_bnode *);
291
292/* bnode.c */
293void hfs_bnode_read(struct hfs_bnode *, void *, int, int);
294u16 hfs_bnode_read_u16(struct hfs_bnode *, int);
295u8 hfs_bnode_read_u8(struct hfs_bnode *, int);
296void hfs_bnode_read_key(struct hfs_bnode *, void *, int);
297void hfs_bnode_write(struct hfs_bnode *, void *, int, int);
298void hfs_bnode_write_u16(struct hfs_bnode *, int, u16);
299void hfs_bnode_clear(struct hfs_bnode *, int, int);
300void hfs_bnode_copy(struct hfs_bnode *, int,
301 struct hfs_bnode *, int, int);
302void hfs_bnode_move(struct hfs_bnode *, int, int, int);
303void hfs_bnode_dump(struct hfs_bnode *);
304void hfs_bnode_unlink(struct hfs_bnode *);
305struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32);
306struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32);
307void hfs_bnode_unhash(struct hfs_bnode *);
308void hfs_bnode_free(struct hfs_bnode *);
309struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
310void hfs_bnode_get(struct hfs_bnode *);
311void hfs_bnode_put(struct hfs_bnode *);
312
313/* brec.c */
314u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
315u16 hfs_brec_keylen(struct hfs_bnode *, u16);
316int hfs_brec_insert(struct hfs_find_data *, void *, int);
317int hfs_brec_remove(struct hfs_find_data *);
318
319/* bfind.c */
320int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
321void hfs_find_exit(struct hfs_find_data *);
322int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *);
323int hfs_brec_find(struct hfs_find_data *);
324int hfs_brec_read(struct hfs_find_data *, void *, int);
325int hfs_brec_goto(struct hfs_find_data *, int);
326
327/* catalog.c */
David Elliott2179d372006-01-18 17:43:08 -0800328int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
329int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *, u32, struct qstr *);
331int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *);
332int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
333int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
334int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
335 struct inode *, struct qstr *);
Christoph Hellwig90e61692010-10-14 09:54:39 -0400336void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Adrian Bunk4b0a8da2008-04-29 00:58:52 -0700338/* dir.c */
339extern const struct inode_operations hfsplus_dir_inode_operations;
340extern const struct file_operations hfsplus_dir_operations;
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/* extents.c */
David Elliott2179d372006-01-18 17:43:08 -0800343int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344void hfsplus_ext_write_extent(struct inode *);
345int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
346int hfsplus_free_fork(struct super_block *, u32, struct hfsplus_fork_raw *, int);
347int hfsplus_file_extend(struct inode *);
348void hfsplus_file_truncate(struct inode *);
349
350/* inode.c */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700351extern const struct address_space_operations hfsplus_aops;
352extern const struct address_space_operations hfsplus_btree_aops;
Al Viroe16404e2009-02-20 05:55:13 +0000353extern const struct dentry_operations hfsplus_dentry_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
356void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
357int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *);
358int hfsplus_cat_write_inode(struct inode *);
359struct inode *hfsplus_new_inode(struct super_block *, int);
360void hfsplus_delete_inode(struct inode *);
Christoph Hellwigeb29d662010-11-23 14:38:10 +0100361int hfsplus_file_fsync(struct file *file, int datasync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363/* ioctl.c */
Arnd Bergmann7cc4bcc2010-04-27 16:24:20 +0200364long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365int hfsplus_setxattr(struct dentry *dentry, const char *name,
366 const void *value, size_t size, int flags);
367ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
368 void *value, size_t size);
369ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
370
371/* options.c */
Roman Zippel717dd80e2005-09-06 15:18:48 -0700372int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
Christoph Hellwig6f80dfe2010-11-07 23:01:17 +0100373int hfsplus_parse_options_remount(char *input, int *force);
Roman Zippel717dd80e2005-09-06 15:18:48 -0700374void hfsplus_fill_defaults(struct hfsplus_sb_info *);
375int hfsplus_show_options(struct seq_file *, struct vfsmount *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
David Howells63525392008-02-07 00:15:40 -0800377/* super.c */
378struct inode *hfsplus_iget(struct super_block *, unsigned long);
Al Virob5fc5102010-07-04 12:24:09 +0400379int hfsplus_sync_fs(struct super_block *sb, int wait);
David Howells63525392008-02-07 00:15:40 -0800380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381/* tables.c */
382extern u16 hfsplus_case_fold_table[];
383extern u16 hfsplus_decompose_table[];
384extern u16 hfsplus_compose_table[];
385
386/* unicode.c */
David Elliott2179d372006-01-18 17:43:08 -0800387int hfsplus_strcasecmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
388int hfsplus_strcmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389int hfsplus_uni2asc(struct super_block *, const struct hfsplus_unistr *, char *, int *);
390int hfsplus_asc2uni(struct super_block *, struct hfsplus_unistr *, const char *, int);
Duane Griffind45bce82007-07-15 23:41:23 -0700391int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str);
392int hfsplus_compare_dentry(struct dentry *dentry, struct qstr *s1, struct qstr *s2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394/* wrapper.c */
395int hfsplus_read_wrapper(struct super_block *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396int hfs_part_find(struct super_block *, sector_t *, sector_t *);
Christoph Hellwig52399b12010-11-23 14:37:47 +0100397int hfsplus_submit_bio(struct block_device *bdev, sector_t sector,
398 void *data, int rw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400/* access macros */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
402{
403 return sb->s_fs_info;
404}
Christoph Hellwig6af502d2010-10-01 05:43:31 +0200405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
407{
408 return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
409}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411/* time macros */
412#define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
413#define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
414
415/* compatibility */
416#define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
417#define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
418#define hfsp_now2mt() __hfsp_ut2mt(get_seconds())
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420#endif