2 * linux/include/linux/hfsplus_fs.h
5 * Brad Boyer (flar@pants.nu)
6 * (C) 2003 Ardis Technologies <roman@ardistech.com>
10 #ifndef _LINUX_HFSPLUS_FS_H
11 #define _LINUX_HFSPLUS_FS_H
14 #include <linux/buffer_head.h>
15 #include "hfsplus_raw.h"
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
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)
30 #define dprint(flg, fmt, args...) \
31 if (flg & DBG_MASK) printk(fmt , ## args)
33 /* Runtime config options */
34 #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
36 #define HFSPLUS_TYPE_DATA 0x00
37 #define HFSPLUS_TYPE_RSRC 0xFF
39 typedef int (*btree_keycmp)(const hfsplus_btree_key *, const hfsplus_btree_key *);
41 #define NODE_HASH_SIZE 256
43 /* An HFS+ BTree held in memory */
45 struct super_block *sb;
58 unsigned int node_size;
59 unsigned int node_size_shift;
60 unsigned int max_key_len;
63 //unsigned int map1_size, map_size;
64 struct semaphore tree_lock;
66 unsigned int pages_per_bnode;
68 struct hfs_bnode *node_hash[NODE_HASH_SIZE];
74 /* An HFS+ BTree node in memory */
76 struct hfs_btree *tree;
87 struct hfs_bnode *next_hash;
89 wait_queue_head_t lock_wq;
91 unsigned int page_offset;
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
102 * HFS+ superblock info (built from Volume Header on disk)
108 struct 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;
118 /* Runtime variables */
123 /* Stuff in host order from Vol Header */
125 int alloc_blksz_shift;
132 u32 data_clump_blocks, rsrc_clump_blocks;
146 struct hlist_head rsrc_inodes;
149 #define HFSPLUS_SB_WRITEBACKUP 0x0001
150 #define HFSPLUS_SB_NODECOMPOSE 0x0002
151 #define HFSPLUS_SB_FORCE 0x0004
152 #define HFSPLUS_SB_HFSX 0x0008
155 struct hfsplus_inode_info {
156 struct semaphore extents_lock;
157 u32 clump_blocks, alloc_blocks;
159 /* Allocation extents from catalog record or volume header */
160 hfsplus_extent_rec first_extents;
162 hfsplus_extent_rec cached_extents;
163 u32 cached_start, cached_blocks;
166 struct inode *rsrc_inode;
170 /* Device number in hfsplus_permissions in catalog */
172 /* BSD system and user file flags */
176 struct list_head open_dir_list;
178 struct inode vfs_inode;
181 #define HFSPLUS_FLG_RSRC 0x0001
182 #define HFSPLUS_FLG_EXT_DIRTY 0x0002
183 #define HFSPLUS_FLG_EXT_NEW 0x0004
185 #define HFSPLUS_IS_DATA(inode) (!(HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC))
186 #define HFSPLUS_IS_RSRC(inode) (HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC)
188 struct hfs_find_data {
189 /* filled by caller */
190 hfsplus_btree_key *search_key;
191 hfsplus_btree_key *key;
193 struct hfs_btree *tree;
194 struct hfs_bnode *bnode;
195 /* filled by findrec */
197 int keyoffset, keylength;
198 int entryoffset, entrylength;
201 struct hfsplus_readdir_data {
202 struct list_head list;
204 struct hfsplus_cat_key key;
207 #define hfs_btree_open hfsplus_btree_open
208 #define hfs_btree_close hfsplus_btree_close
209 #define hfs_btree_write hfsplus_btree_write
210 #define hfs_bmap_alloc hfsplus_bmap_alloc
211 #define hfs_bmap_free hfsplus_bmap_free
212 #define hfs_bnode_read hfsplus_bnode_read
213 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
214 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
215 #define hfs_bnode_read_key hfsplus_bnode_read_key
216 #define hfs_bnode_write hfsplus_bnode_write
217 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
218 #define hfs_bnode_clear hfsplus_bnode_clear
219 #define hfs_bnode_copy hfsplus_bnode_copy
220 #define hfs_bnode_move hfsplus_bnode_move
221 #define hfs_bnode_dump hfsplus_bnode_dump
222 #define hfs_bnode_unlink hfsplus_bnode_unlink
223 #define hfs_bnode_findhash hfsplus_bnode_findhash
224 #define hfs_bnode_find hfsplus_bnode_find
225 #define hfs_bnode_unhash hfsplus_bnode_unhash
226 #define hfs_bnode_free hfsplus_bnode_free
227 #define hfs_bnode_create hfsplus_bnode_create
228 #define hfs_bnode_get hfsplus_bnode_get
229 #define hfs_bnode_put hfsplus_bnode_put
230 #define hfs_brec_lenoff hfsplus_brec_lenoff
231 #define hfs_brec_keylen hfsplus_brec_keylen
232 #define hfs_brec_insert hfsplus_brec_insert
233 #define hfs_brec_remove hfsplus_brec_remove
234 #define hfs_find_init hfsplus_find_init
235 #define hfs_find_exit hfsplus_find_exit
236 #define __hfs_brec_find __hplusfs_brec_find
237 #define hfs_brec_find hfsplus_brec_find
238 #define hfs_brec_read hfsplus_brec_read
239 #define hfs_brec_goto hfsplus_brec_goto
240 #define hfs_part_find hfsplus_part_find
243 * definitions for ext2 flag ioctls (linux really needs a generic
244 * interface for this).
247 /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
249 #define HFSPLUS_IOC_EXT2_GETFLAGS _IOR('f', 1, long)
250 #define HFSPLUS_IOC_EXT2_SETFLAGS _IOW('f', 2, long)
252 #define EXT2_FLAG_IMMUTABLE 0x00000010 /* Immutable file */
253 #define EXT2_FLAG_APPEND 0x00000020 /* writes to file may only append */
254 #define EXT2_FLAG_NODUMP 0x00000040 /* do not dump file */
258 * Functions in any *.c used in other files
262 int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
263 int hfsplus_block_free(struct super_block *, u32, u32);
266 struct hfs_btree *hfs_btree_open(struct super_block *, u32);
267 void hfs_btree_close(struct hfs_btree *);
268 void hfs_btree_write(struct hfs_btree *);
269 struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *);
270 void hfs_bmap_free(struct hfs_bnode *);
273 void hfs_bnode_read(struct hfs_bnode *, void *, int, int);
274 u16 hfs_bnode_read_u16(struct hfs_bnode *, int);
275 u8 hfs_bnode_read_u8(struct hfs_bnode *, int);
276 void hfs_bnode_read_key(struct hfs_bnode *, void *, int);
277 void hfs_bnode_write(struct hfs_bnode *, void *, int, int);
278 void hfs_bnode_write_u16(struct hfs_bnode *, int, u16);
279 void hfs_bnode_clear(struct hfs_bnode *, int, int);
280 void hfs_bnode_copy(struct hfs_bnode *, int,
281 struct hfs_bnode *, int, int);
282 void hfs_bnode_move(struct hfs_bnode *, int, int, int);
283 void hfs_bnode_dump(struct hfs_bnode *);
284 void hfs_bnode_unlink(struct hfs_bnode *);
285 struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32);
286 struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32);
287 void hfs_bnode_unhash(struct hfs_bnode *);
288 void hfs_bnode_free(struct hfs_bnode *);
289 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
290 void hfs_bnode_get(struct hfs_bnode *);
291 void hfs_bnode_put(struct hfs_bnode *);
294 u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
295 u16 hfs_brec_keylen(struct hfs_bnode *, u16);
296 int hfs_brec_insert(struct hfs_find_data *, void *, int);
297 int hfs_brec_remove(struct hfs_find_data *);
300 int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
301 void hfs_find_exit(struct hfs_find_data *);
302 int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *);
303 int hfs_brec_find(struct hfs_find_data *);
304 int hfs_brec_read(struct hfs_find_data *, void *, int);
305 int hfs_brec_goto(struct hfs_find_data *, int);
308 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
309 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
310 void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *, u32, struct qstr *);
311 int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *);
312 int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
313 int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
314 int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
315 struct inode *, struct qstr *);
318 int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
319 void hfsplus_ext_write_extent(struct inode *);
320 int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
321 int hfsplus_free_fork(struct super_block *, u32, struct hfsplus_fork_raw *, int);
322 int hfsplus_file_extend(struct inode *);
323 void hfsplus_file_truncate(struct inode *);
326 extern const struct address_space_operations hfsplus_aops;
327 extern const struct address_space_operations hfsplus_btree_aops;
329 void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
330 void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
331 int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *);
332 int hfsplus_cat_write_inode(struct inode *);
333 struct inode *hfsplus_new_inode(struct super_block *, int);
334 void hfsplus_delete_inode(struct inode *);
337 int hfsplus_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
339 int hfsplus_setxattr(struct dentry *dentry, const char *name,
340 const void *value, size_t size, int flags);
341 ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
342 void *value, size_t size);
343 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
346 int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
347 void hfsplus_fill_defaults(struct hfsplus_sb_info *);
348 int hfsplus_show_options(struct seq_file *, struct vfsmount *);
351 extern u16 hfsplus_case_fold_table[];
352 extern u16 hfsplus_decompose_table[];
353 extern u16 hfsplus_compose_table[];
356 int hfsplus_strcasecmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
357 int hfsplus_strcmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *);
358 int hfsplus_uni2asc(struct super_block *, const struct hfsplus_unistr *, char *, int *);
359 int hfsplus_asc2uni(struct super_block *, struct hfsplus_unistr *, const char *, int);
362 int hfsplus_read_wrapper(struct super_block *);
364 int hfs_part_find(struct super_block *, sector_t *, sector_t *);
368 static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
370 return sb->s_fs_info;
372 static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
374 return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
377 #define HFSPLUS_SB(super) (*(struct hfsplus_sb_info *)(super)->s_fs_info)
378 #define HFSPLUS_I(inode) (*list_entry(inode, struct hfsplus_inode_info, vfs_inode))
381 #define hfsplus_kmap(p) ({ struct page *__p = (p); kmap(__p); })
382 #define hfsplus_kunmap(p) ({ struct page *__p = (p); kunmap(__p); __p; })
384 #define hfsplus_kmap(p) kmap(p)
385 #define hfsplus_kunmap(p) kunmap(p)
388 #define sb_bread512(sb, sec, data) ({ \
389 struct buffer_head *__bh; \
394 __start = (loff_t)(sec) << HFSPLUS_SECTOR_SHIFT;\
395 __block = __start >> (sb)->s_blocksize_bits; \
396 __offset = __start & ((sb)->s_blocksize - 1); \
397 __bh = sb_bread((sb), __block); \
398 if (likely(__bh != NULL)) \
399 data = (void *)(__bh->b_data + __offset);\
406 #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
407 #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
410 #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
411 #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
412 #define hfsp_now2mt() __hfsp_ut2mt(get_seconds())
414 #define kdev_t_to_nr(x) (x)