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/mutex.h>
15 #include <linux/buffer_head.h>
16 #include <linux/blkdev.h>
17 #include "hfsplus_raw.h"
19 #define DBG_BNODE_REFS 0x00000001
20 #define DBG_BNODE_MOD 0x00000002
21 #define DBG_CAT_MOD 0x00000004
22 #define DBG_INODE 0x00000008
23 #define DBG_SUPER 0x00000010
24 #define DBG_EXTENT 0x00000020
25 #define DBG_BITMAP 0x00000040
26 #define DBG_ATTR_MOD 0x00000080
29 #define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
30 #define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
31 #define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
35 #define dprint(flg, fmt, args...) \
39 /* Runtime config options */
40 #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
42 #define HFSPLUS_TYPE_DATA 0x00
43 #define HFSPLUS_TYPE_RSRC 0xFF
45 typedef int (*btree_keycmp)(const hfsplus_btree_key *,
46 const hfsplus_btree_key *);
48 #define NODE_HASH_SIZE 256
50 /* An HFS+ BTree held in memory */
52 struct super_block *sb;
65 unsigned int node_size;
66 unsigned int node_size_shift;
67 unsigned int max_key_len;
70 struct mutex tree_lock;
72 unsigned int pages_per_bnode;
74 struct hfs_bnode *node_hash[NODE_HASH_SIZE];
80 /* An HFS+ BTree node in memory */
82 struct hfs_btree *tree;
93 struct hfs_bnode *next_hash;
95 wait_queue_head_t lock_wq;
97 unsigned int page_offset;
101 #define HFS_BNODE_LOCK 0
102 #define HFS_BNODE_ERROR 1
103 #define HFS_BNODE_NEW 2
104 #define HFS_BNODE_DIRTY 3
105 #define HFS_BNODE_DELETED 4
108 * HFS+ superblock info (built from Volume Header on disk)
114 struct hfsplus_sb_info {
116 struct hfsplus_vh *s_vhdr;
117 void *s_backup_vhdr_buf;
118 struct hfsplus_vh *s_backup_vhdr;
119 struct hfs_btree *ext_tree;
120 struct hfs_btree *cat_tree;
121 struct hfs_btree *attr_tree;
122 struct inode *alloc_file;
123 struct inode *hidden_dir;
124 struct nls_table *nls;
126 /* Runtime variables */
132 /* immutable data from the volume header */
134 int alloc_blksz_shift;
136 u32 data_clump_blocks, rsrc_clump_blocks;
138 /* mutable data from the volume header, protected by alloc_mutex */
140 struct mutex alloc_mutex;
142 /* mutable data from the volume header, protected by vh_mutex */
146 struct mutex vh_mutex;
159 int work_queued; /* non-zero delayed work is queued */
160 struct delayed_work sync_work; /* FS sync delayed work */
161 spinlock_t work_lock; /* protects sync_work and work_queued */
164 #define HFSPLUS_SB_WRITEBACKUP 0
165 #define HFSPLUS_SB_NODECOMPOSE 1
166 #define HFSPLUS_SB_FORCE 2
167 #define HFSPLUS_SB_HFSX 3
168 #define HFSPLUS_SB_CASEFOLD 4
169 #define HFSPLUS_SB_NOBARRIER 5
171 static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
173 return sb->s_fs_info;
177 struct hfsplus_inode_info {
181 * Extent allocation information, protected by extents_lock.
188 hfsplus_extent_rec first_extents;
189 hfsplus_extent_rec cached_extents;
190 unsigned int extent_state;
191 struct mutex extents_lock;
196 struct inode *rsrc_inode;
200 * Protected by sbi->vh_mutex.
205 * Accessed using atomic bitops.
210 * Protected by i_mutex.
213 u8 userflags; /* BSD user file flags */
214 struct list_head open_dir_list;
217 struct inode vfs_inode;
220 #define HFSPLUS_EXT_DIRTY 0x0001
221 #define HFSPLUS_EXT_NEW 0x0002
223 #define HFSPLUS_I_RSRC 0 /* represents a resource fork */
224 #define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
225 #define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
226 #define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
227 #define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
229 #define HFSPLUS_IS_RSRC(inode) \
230 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
232 static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
234 return list_entry(inode, struct hfsplus_inode_info, vfs_inode);
238 * Mark an inode dirty, and also mark the btree in which the
239 * specific type of metadata is stored.
240 * For data or metadata that gets written back by into the catalog btree
241 * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
243 static inline void hfsplus_mark_inode_dirty(struct inode *inode,
246 set_bit(flag, &HFSPLUS_I(inode)->flags);
247 mark_inode_dirty(inode);
250 struct hfs_find_data {
251 /* filled by caller */
252 hfsplus_btree_key *search_key;
253 hfsplus_btree_key *key;
255 struct hfs_btree *tree;
256 struct hfs_bnode *bnode;
257 /* filled by findrec */
259 int keyoffset, keylength;
260 int entryoffset, entrylength;
263 struct hfsplus_readdir_data {
264 struct list_head list;
266 struct hfsplus_cat_key key;
270 * Find minimum acceptible I/O size for an hfsplus sb.
272 static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
274 return max_t(unsigned short, bdev_logical_block_size(sb->s_bdev),
275 HFSPLUS_SECTOR_SIZE);
278 #define hfs_btree_open hfsplus_btree_open
279 #define hfs_btree_close hfsplus_btree_close
280 #define hfs_btree_write hfsplus_btree_write
281 #define hfs_bmap_alloc hfsplus_bmap_alloc
282 #define hfs_bmap_free hfsplus_bmap_free
283 #define hfs_bnode_read hfsplus_bnode_read
284 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
285 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
286 #define hfs_bnode_read_key hfsplus_bnode_read_key
287 #define hfs_bnode_write hfsplus_bnode_write
288 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
289 #define hfs_bnode_clear hfsplus_bnode_clear
290 #define hfs_bnode_copy hfsplus_bnode_copy
291 #define hfs_bnode_move hfsplus_bnode_move
292 #define hfs_bnode_dump hfsplus_bnode_dump
293 #define hfs_bnode_unlink hfsplus_bnode_unlink
294 #define hfs_bnode_findhash hfsplus_bnode_findhash
295 #define hfs_bnode_find hfsplus_bnode_find
296 #define hfs_bnode_unhash hfsplus_bnode_unhash
297 #define hfs_bnode_free hfsplus_bnode_free
298 #define hfs_bnode_create hfsplus_bnode_create
299 #define hfs_bnode_get hfsplus_bnode_get
300 #define hfs_bnode_put hfsplus_bnode_put
301 #define hfs_brec_lenoff hfsplus_brec_lenoff
302 #define hfs_brec_keylen hfsplus_brec_keylen
303 #define hfs_brec_insert hfsplus_brec_insert
304 #define hfs_brec_remove hfsplus_brec_remove
305 #define hfs_find_init hfsplus_find_init
306 #define hfs_find_exit hfsplus_find_exit
307 #define __hfs_brec_find __hfsplus_brec_find
308 #define hfs_brec_find hfsplus_brec_find
309 #define hfs_brec_read hfsplus_brec_read
310 #define hfs_brec_goto hfsplus_brec_goto
311 #define hfs_part_find hfsplus_part_find
314 * definitions for ext2 flag ioctls (linux really needs a generic
315 * interface for this).
318 /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
320 #define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
321 #define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
325 * hfs+-specific ioctl for making the filesystem bootable
327 #define HFSPLUS_IOC_BLESS _IO('h', 0x80)
329 typedef int (*search_strategy_t)(struct hfs_bnode *,
330 struct hfs_find_data *,
331 int *, int *, int *);
334 * Functions in any *.c used in other files
338 int hfsplus_create_attr_tree_cache(void);
339 void hfsplus_destroy_attr_tree_cache(void);
340 hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);
341 void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry_p);
342 int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *,
343 const hfsplus_btree_key *);
344 int hfsplus_attr_build_key(struct super_block *, hfsplus_btree_key *,
346 void hfsplus_attr_build_key_uni(hfsplus_btree_key *key,
348 struct hfsplus_attr_unistr *name);
349 int hfsplus_find_attr(struct super_block *, u32,
350 const char *, struct hfs_find_data *);
351 int hfsplus_attr_exists(struct inode *inode, const char *name);
352 int hfsplus_create_attr(struct inode *, const char *, const void *, size_t);
353 int hfsplus_delete_attr(struct inode *, const char *);
354 int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
357 int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *);
358 int hfsplus_block_free(struct super_block *, u32, u32);
361 struct hfs_btree *hfs_btree_open(struct super_block *, u32);
362 void hfs_btree_close(struct hfs_btree *);
363 void hfs_btree_write(struct hfs_btree *);
364 struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *);
365 void hfs_bmap_free(struct hfs_bnode *);
368 void hfs_bnode_read(struct hfs_bnode *, void *, int, int);
369 u16 hfs_bnode_read_u16(struct hfs_bnode *, int);
370 u8 hfs_bnode_read_u8(struct hfs_bnode *, int);
371 void hfs_bnode_read_key(struct hfs_bnode *, void *, int);
372 void hfs_bnode_write(struct hfs_bnode *, void *, int, int);
373 void hfs_bnode_write_u16(struct hfs_bnode *, int, u16);
374 void hfs_bnode_clear(struct hfs_bnode *, int, int);
375 void hfs_bnode_copy(struct hfs_bnode *, int,
376 struct hfs_bnode *, int, int);
377 void hfs_bnode_move(struct hfs_bnode *, int, int, int);
378 void hfs_bnode_dump(struct hfs_bnode *);
379 void hfs_bnode_unlink(struct hfs_bnode *);
380 struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32);
381 struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32);
382 void hfs_bnode_unhash(struct hfs_bnode *);
383 void hfs_bnode_free(struct hfs_bnode *);
384 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32);
385 void hfs_bnode_get(struct hfs_bnode *);
386 void hfs_bnode_put(struct hfs_bnode *);
389 u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *);
390 u16 hfs_brec_keylen(struct hfs_bnode *, u16);
391 int hfs_brec_insert(struct hfs_find_data *, void *, int);
392 int hfs_brec_remove(struct hfs_find_data *);
395 int hfs_find_init(struct hfs_btree *, struct hfs_find_data *);
396 void hfs_find_exit(struct hfs_find_data *);
397 int hfs_find_1st_rec_by_cnid(struct hfs_bnode *,
398 struct hfs_find_data *,
399 int *, int *, int *);
400 int hfs_find_rec_by_key(struct hfs_bnode *,
401 struct hfs_find_data *,
402 int *, int *, int *);
403 int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *,
405 int hfs_brec_find(struct hfs_find_data *, search_strategy_t);
406 int hfs_brec_read(struct hfs_find_data *, void *, int);
407 int hfs_brec_goto(struct hfs_find_data *, int);
410 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *,
411 const hfsplus_btree_key *);
412 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *,
413 const hfsplus_btree_key *);
414 void hfsplus_cat_build_key(struct super_block *sb,
415 hfsplus_btree_key *, u32, struct qstr *);
416 int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *);
417 int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *);
418 int hfsplus_delete_cat(u32, struct inode *, struct qstr *);
419 int hfsplus_rename_cat(u32, struct inode *, struct qstr *,
420 struct inode *, struct qstr *);
421 void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
424 extern const struct inode_operations hfsplus_dir_inode_operations;
425 extern const struct file_operations hfsplus_dir_operations;
428 int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *);
429 int hfsplus_ext_write_extent(struct inode *);
430 int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int);
431 int hfsplus_free_fork(struct super_block *, u32,
432 struct hfsplus_fork_raw *, int);
433 int hfsplus_file_extend(struct inode *);
434 void hfsplus_file_truncate(struct inode *);
437 extern const struct address_space_operations hfsplus_aops;
438 extern const struct address_space_operations hfsplus_btree_aops;
439 extern const struct dentry_operations hfsplus_dentry_operations;
441 void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *);
442 void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *);
443 int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *);
444 int hfsplus_cat_write_inode(struct inode *);
445 struct inode *hfsplus_new_inode(struct super_block *, umode_t);
446 void hfsplus_delete_inode(struct inode *);
447 int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
451 long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
452 int hfsplus_setxattr(struct dentry *dentry, const char *name,
453 const void *value, size_t size, int flags);
454 ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name,
455 void *value, size_t size);
456 ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size);
457 int hfsplus_removexattr(struct dentry *dentry, const char *name);
460 int hfsplus_parse_options(char *, struct hfsplus_sb_info *);
461 int hfsplus_parse_options_remount(char *input, int *force);
462 void hfsplus_fill_defaults(struct hfsplus_sb_info *);
463 int hfsplus_show_options(struct seq_file *, struct dentry *);
466 struct inode *hfsplus_iget(struct super_block *, unsigned long);
467 void hfsplus_mark_mdb_dirty(struct super_block *sb);
470 extern u16 hfsplus_case_fold_table[];
471 extern u16 hfsplus_decompose_table[];
472 extern u16 hfsplus_compose_table[];
475 int hfsplus_strcasecmp(const struct hfsplus_unistr *,
476 const struct hfsplus_unistr *);
477 int hfsplus_strcmp(const struct hfsplus_unistr *,
478 const struct hfsplus_unistr *);
479 int hfsplus_uni2asc(struct super_block *,
480 const struct hfsplus_unistr *, char *, int *);
481 int hfsplus_asc2uni(struct super_block *,
482 struct hfsplus_unistr *, int, const char *, int);
483 int hfsplus_hash_dentry(const struct dentry *dentry,
484 const struct inode *inode, struct qstr *str);
485 int hfsplus_compare_dentry(const struct dentry *parent,
486 const struct inode *pinode,
487 const struct dentry *dentry, const struct inode *inode,
488 unsigned int len, const char *str, const struct qstr *name);
491 int hfsplus_read_wrapper(struct super_block *);
492 int hfs_part_find(struct super_block *, sector_t *, sector_t *);
493 int hfsplus_submit_bio(struct super_block *sb, sector_t sector,
494 void *buf, void **data, int rw);
497 #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
498 #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
501 #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
502 #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
503 #define hfsp_now2mt() __hfsp_ut2mt(get_seconds())