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
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/mutex.h>
21 #include <linux/buffer_head.h>
22 #include <linux/blkdev.h>
23 #include "hfsplus_raw.h"
25 #define DBG_BNODE_REFS 0x00000001
26 #define DBG_BNODE_MOD 0x00000002
27 #define DBG_CAT_MOD 0x00000004
28 #define DBG_INODE 0x00000008
29 #define DBG_SUPER 0x00000010
30 #define DBG_EXTENT 0x00000020
31 #define DBG_BITMAP 0x00000040
32 #define DBG_ATTR_MOD 0x00000080
33 #define DBG_ACL_MOD 0x00000100
36 #define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
37 #define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
38 #define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
42 #define hfs_dbg(flg, fmt, ...) \
44 if (DBG_##flg & DBG_MASK) \
45 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
48 #define hfs_dbg_cont(flg, fmt, ...) \
50 if (DBG_##flg & DBG_MASK) \
51 pr_cont(fmt, ##__VA_ARGS__); \
54 /* Runtime config options */
55 #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
57 #define HFSPLUS_TYPE_DATA 0x00
58 #define HFSPLUS_TYPE_RSRC 0xFF
60 typedef int (*btree_keycmp
)(const hfsplus_btree_key
*,
61 const hfsplus_btree_key
*);
63 #define NODE_HASH_SIZE 256
65 /* B-tree mutex nested subclasses */
66 enum hfsplus_btree_mutex_classes
{
72 /* An HFS+ BTree held in memory */
74 struct super_block
*sb
;
87 unsigned int node_size
;
88 unsigned int node_size_shift
;
89 unsigned int max_key_len
;
92 struct mutex tree_lock
;
94 unsigned int pages_per_bnode
;
96 struct hfs_bnode
*node_hash
[NODE_HASH_SIZE
];
102 /* An HFS+ BTree node in memory */
104 struct hfs_btree
*tree
;
115 struct hfs_bnode
*next_hash
;
117 wait_queue_head_t lock_wq
;
119 unsigned int page_offset
;
120 struct page
*page
[0];
123 #define HFS_BNODE_LOCK 0
124 #define HFS_BNODE_ERROR 1
125 #define HFS_BNODE_NEW 2
126 #define HFS_BNODE_DIRTY 3
127 #define HFS_BNODE_DELETED 4
130 * Attributes file states
132 #define HFSPLUS_EMPTY_ATTR_TREE 0
133 #define HFSPLUS_CREATING_ATTR_TREE 1
134 #define HFSPLUS_VALID_ATTR_TREE 2
135 #define HFSPLUS_FAILED_ATTR_TREE 3
138 * HFS+ superblock info (built from Volume Header on disk)
144 struct hfsplus_sb_info
{
146 struct hfsplus_vh
*s_vhdr
;
147 void *s_backup_vhdr_buf
;
148 struct hfsplus_vh
*s_backup_vhdr
;
149 struct hfs_btree
*ext_tree
;
150 struct hfs_btree
*cat_tree
;
151 struct hfs_btree
*attr_tree
;
152 atomic_t attr_tree_state
;
153 struct inode
*alloc_file
;
154 struct inode
*hidden_dir
;
155 struct nls_table
*nls
;
157 /* Runtime variables */
163 /* immutable data from the volume header */
165 int alloc_blksz_shift
;
167 u32 data_clump_blocks
, rsrc_clump_blocks
;
169 /* mutable data from the volume header, protected by alloc_mutex */
171 struct mutex alloc_mutex
;
173 /* mutable data from the volume header, protected by vh_mutex */
177 struct mutex vh_mutex
;
190 int work_queued
; /* non-zero delayed work is queued */
191 struct delayed_work sync_work
; /* FS sync delayed work */
192 spinlock_t work_lock
; /* protects sync_work and work_queued */
195 #define HFSPLUS_SB_WRITEBACKUP 0
196 #define HFSPLUS_SB_NODECOMPOSE 1
197 #define HFSPLUS_SB_FORCE 2
198 #define HFSPLUS_SB_HFSX 3
199 #define HFSPLUS_SB_CASEFOLD 4
200 #define HFSPLUS_SB_NOBARRIER 5
202 static inline struct hfsplus_sb_info
*HFSPLUS_SB(struct super_block
*sb
)
204 return sb
->s_fs_info
;
208 struct hfsplus_inode_info
{
212 * Extent allocation information, protected by extents_lock.
219 hfsplus_extent_rec first_extents
;
220 hfsplus_extent_rec cached_extents
;
221 unsigned int extent_state
;
222 struct mutex extents_lock
;
227 struct inode
*rsrc_inode
;
231 * Protected by sbi->vh_mutex.
236 * Accessed using atomic bitops.
241 * Protected by i_mutex.
244 u8 userflags
; /* BSD user file flags */
245 u32 subfolders
; /* Subfolder count (HFSX only) */
246 struct list_head open_dir_list
;
247 spinlock_t open_dir_lock
;
250 struct inode vfs_inode
;
253 #define HFSPLUS_EXT_DIRTY 0x0001
254 #define HFSPLUS_EXT_NEW 0x0002
256 #define HFSPLUS_I_RSRC 0 /* represents a resource fork */
257 #define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
258 #define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
259 #define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
260 #define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
262 #define HFSPLUS_IS_RSRC(inode) \
263 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
265 static inline struct hfsplus_inode_info
*HFSPLUS_I(struct inode
*inode
)
267 return container_of(inode
, struct hfsplus_inode_info
, vfs_inode
);
271 * Mark an inode dirty, and also mark the btree in which the
272 * specific type of metadata is stored.
273 * For data or metadata that gets written back by into the catalog btree
274 * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
276 static inline void hfsplus_mark_inode_dirty(struct inode
*inode
,
279 set_bit(flag
, &HFSPLUS_I(inode
)->flags
);
280 mark_inode_dirty(inode
);
283 struct hfs_find_data
{
284 /* filled by caller */
285 hfsplus_btree_key
*search_key
;
286 hfsplus_btree_key
*key
;
288 struct hfs_btree
*tree
;
289 struct hfs_bnode
*bnode
;
290 /* filled by findrec */
292 int keyoffset
, keylength
;
293 int entryoffset
, entrylength
;
296 struct hfsplus_readdir_data
{
297 struct list_head list
;
299 struct hfsplus_cat_key key
;
303 * Find minimum acceptible I/O size for an hfsplus sb.
305 static inline unsigned short hfsplus_min_io_size(struct super_block
*sb
)
307 return max_t(unsigned short, bdev_logical_block_size(sb
->s_bdev
),
308 HFSPLUS_SECTOR_SIZE
);
311 #define hfs_btree_open hfsplus_btree_open
312 #define hfs_btree_close hfsplus_btree_close
313 #define hfs_btree_write hfsplus_btree_write
314 #define hfs_bmap_alloc hfsplus_bmap_alloc
315 #define hfs_bmap_free hfsplus_bmap_free
316 #define hfs_bnode_read hfsplus_bnode_read
317 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
318 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
319 #define hfs_bnode_read_key hfsplus_bnode_read_key
320 #define hfs_bnode_write hfsplus_bnode_write
321 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
322 #define hfs_bnode_clear hfsplus_bnode_clear
323 #define hfs_bnode_copy hfsplus_bnode_copy
324 #define hfs_bnode_move hfsplus_bnode_move
325 #define hfs_bnode_dump hfsplus_bnode_dump
326 #define hfs_bnode_unlink hfsplus_bnode_unlink
327 #define hfs_bnode_findhash hfsplus_bnode_findhash
328 #define hfs_bnode_find hfsplus_bnode_find
329 #define hfs_bnode_unhash hfsplus_bnode_unhash
330 #define hfs_bnode_free hfsplus_bnode_free
331 #define hfs_bnode_create hfsplus_bnode_create
332 #define hfs_bnode_get hfsplus_bnode_get
333 #define hfs_bnode_put hfsplus_bnode_put
334 #define hfs_brec_lenoff hfsplus_brec_lenoff
335 #define hfs_brec_keylen hfsplus_brec_keylen
336 #define hfs_brec_insert hfsplus_brec_insert
337 #define hfs_brec_remove hfsplus_brec_remove
338 #define hfs_find_init hfsplus_find_init
339 #define hfs_find_exit hfsplus_find_exit
340 #define __hfs_brec_find __hfsplus_brec_find
341 #define hfs_brec_find hfsplus_brec_find
342 #define hfs_brec_read hfsplus_brec_read
343 #define hfs_brec_goto hfsplus_brec_goto
344 #define hfs_part_find hfsplus_part_find
347 * definitions for ext2 flag ioctls (linux really needs a generic
348 * interface for this).
351 /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
353 #define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
354 #define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
358 * hfs+-specific ioctl for making the filesystem bootable
360 #define HFSPLUS_IOC_BLESS _IO('h', 0x80)
362 typedef int (*search_strategy_t
)(struct hfs_bnode
*,
363 struct hfs_find_data
*,
364 int *, int *, int *);
367 * Functions in any *.c used in other files
371 int __init
hfsplus_create_attr_tree_cache(void);
372 void hfsplus_destroy_attr_tree_cache(void);
373 int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key
*k1
,
374 const hfsplus_btree_key
*k2
);
375 int hfsplus_attr_build_key(struct super_block
*sb
, hfsplus_btree_key
*key
,
376 u32 cnid
, const char *name
);
377 hfsplus_attr_entry
*hfsplus_alloc_attr_entry(void);
378 void hfsplus_destroy_attr_entry(hfsplus_attr_entry
*entry
);
379 int hfsplus_find_attr(struct super_block
*sb
, u32 cnid
, const char *name
,
380 struct hfs_find_data
*fd
);
381 int hfsplus_attr_exists(struct inode
*inode
, const char *name
);
382 int hfsplus_create_attr(struct inode
*inode
, const char *name
,
383 const void *value
, size_t size
);
384 int hfsplus_delete_attr(struct inode
*inode
, const char *name
);
385 int hfsplus_delete_all_attrs(struct inode
*dir
, u32 cnid
);
388 int hfsplus_block_allocate(struct super_block
*sb
, u32 size
, u32 offset
,
390 int hfsplus_block_free(struct super_block
*sb
, u32 offset
, u32 count
);
393 u32
hfsplus_calc_btree_clump_size(u32 block_size
, u32 node_size
, u64 sectors
,
395 struct hfs_btree
*hfs_btree_open(struct super_block
*sb
, u32 id
);
396 void hfs_btree_close(struct hfs_btree
*tree
);
397 int hfs_btree_write(struct hfs_btree
*tree
);
398 struct hfs_bnode
*hfs_bmap_alloc(struct hfs_btree
*tree
);
399 void hfs_bmap_free(struct hfs_bnode
*node
);
402 void hfs_bnode_read(struct hfs_bnode
*node
, void *buf
, int off
, int len
);
403 u16
hfs_bnode_read_u16(struct hfs_bnode
*node
, int off
);
404 u8
hfs_bnode_read_u8(struct hfs_bnode
*node
, int off
);
405 void hfs_bnode_read_key(struct hfs_bnode
*node
, void *key
, int off
);
406 void hfs_bnode_write(struct hfs_bnode
*node
, void *buf
, int off
, int len
);
407 void hfs_bnode_write_u16(struct hfs_bnode
*node
, int off
, u16 data
);
408 void hfs_bnode_clear(struct hfs_bnode
*node
, int off
, int len
);
409 void hfs_bnode_copy(struct hfs_bnode
*dst_node
, int dst
,
410 struct hfs_bnode
*src_node
, int src
, int len
);
411 void hfs_bnode_move(struct hfs_bnode
*node
, int dst
, int src
, int len
);
412 void hfs_bnode_dump(struct hfs_bnode
*node
);
413 void hfs_bnode_unlink(struct hfs_bnode
*node
);
414 struct hfs_bnode
*hfs_bnode_findhash(struct hfs_btree
*tree
, u32 cnid
);
415 void hfs_bnode_unhash(struct hfs_bnode
*node
);
416 struct hfs_bnode
*hfs_bnode_find(struct hfs_btree
*tree
, u32 num
);
417 void hfs_bnode_free(struct hfs_bnode
*node
);
418 struct hfs_bnode
*hfs_bnode_create(struct hfs_btree
*tree
, u32 num
);
419 void hfs_bnode_get(struct hfs_bnode
*node
);
420 void hfs_bnode_put(struct hfs_bnode
*node
);
421 bool hfs_bnode_need_zeroout(struct hfs_btree
*tree
);
424 u16
hfs_brec_lenoff(struct hfs_bnode
*node
, u16 rec
, u16
*off
);
425 u16
hfs_brec_keylen(struct hfs_bnode
*node
, u16 rec
);
426 int hfs_brec_insert(struct hfs_find_data
*fd
, void *entry
, int entry_len
);
427 int hfs_brec_remove(struct hfs_find_data
*fd
);
430 int hfs_find_init(struct hfs_btree
*tree
, struct hfs_find_data
*fd
);
431 void hfs_find_exit(struct hfs_find_data
*fd
);
432 int hfs_find_1st_rec_by_cnid(struct hfs_bnode
*bnode
, struct hfs_find_data
*fd
,
433 int *begin
, int *end
, int *cur_rec
);
434 int hfs_find_rec_by_key(struct hfs_bnode
*bnode
, struct hfs_find_data
*fd
,
435 int *begin
, int *end
, int *cur_rec
);
436 int __hfs_brec_find(struct hfs_bnode
*bnode
, struct hfs_find_data
*fd
,
437 search_strategy_t rec_found
);
438 int hfs_brec_find(struct hfs_find_data
*fd
, search_strategy_t do_key_compare
);
439 int hfs_brec_read(struct hfs_find_data
*fd
, void *rec
, int rec_len
);
440 int hfs_brec_goto(struct hfs_find_data
*fd
, int cnt
);
443 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key
*k1
,
444 const hfsplus_btree_key
*k2
);
445 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key
*k1
,
446 const hfsplus_btree_key
*k2
);
447 int hfsplus_cat_build_key(struct super_block
*sb
, hfsplus_btree_key
*key
,
448 u32 parent
, struct qstr
*str
);
449 void hfsplus_cat_build_key_with_cnid(struct super_block
*sb
,
450 hfsplus_btree_key
*key
, u32 parent
);
451 void hfsplus_cat_set_perms(struct inode
*inode
, struct hfsplus_perm
*perms
);
452 int hfsplus_find_cat(struct super_block
*sb
, u32 cnid
,
453 struct hfs_find_data
*fd
);
454 int hfsplus_create_cat(u32 cnid
, struct inode
*dir
, struct qstr
*str
,
455 struct inode
*inode
);
456 int hfsplus_delete_cat(u32 cnid
, struct inode
*dir
, struct qstr
*str
);
457 int hfsplus_rename_cat(u32 cnid
, struct inode
*src_dir
, struct qstr
*src_name
,
458 struct inode
*dst_dir
, struct qstr
*dst_name
);
461 extern const struct inode_operations hfsplus_dir_inode_operations
;
462 extern const struct file_operations hfsplus_dir_operations
;
465 int hfsplus_ext_cmp_key(const hfsplus_btree_key
*k1
,
466 const hfsplus_btree_key
*k2
);
467 int hfsplus_ext_write_extent(struct inode
*inode
);
468 int hfsplus_get_block(struct inode
*inode
, sector_t iblock
,
469 struct buffer_head
*bh_result
, int create
);
470 int hfsplus_free_fork(struct super_block
*sb
, u32 cnid
,
471 struct hfsplus_fork_raw
*fork
, int type
);
472 int hfsplus_file_extend(struct inode
*inode
, bool zeroout
);
473 void hfsplus_file_truncate(struct inode
*inode
);
476 extern const struct address_space_operations hfsplus_aops
;
477 extern const struct address_space_operations hfsplus_btree_aops
;
478 extern const struct dentry_operations hfsplus_dentry_operations
;
480 struct inode
*hfsplus_new_inode(struct super_block
*sb
, umode_t mode
);
481 void hfsplus_delete_inode(struct inode
*inode
);
482 void hfsplus_inode_read_fork(struct inode
*inode
,
483 struct hfsplus_fork_raw
*fork
);
484 void hfsplus_inode_write_fork(struct inode
*inode
,
485 struct hfsplus_fork_raw
*fork
);
486 int hfsplus_cat_read_inode(struct inode
*inode
, struct hfs_find_data
*fd
);
487 int hfsplus_cat_write_inode(struct inode
*inode
);
488 int hfsplus_file_fsync(struct file
*file
, loff_t start
, loff_t end
,
492 long hfsplus_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
);
495 void hfsplus_fill_defaults(struct hfsplus_sb_info
*opts
);
496 int hfsplus_parse_options_remount(char *input
, int *force
);
497 int hfsplus_parse_options(char *input
, struct hfsplus_sb_info
*sbi
);
498 int hfsplus_show_options(struct seq_file
*seq
, struct dentry
*root
);
501 int hfs_part_find(struct super_block
*sb
, sector_t
*part_start
,
502 sector_t
*part_size
);
505 struct inode
*hfsplus_iget(struct super_block
*sb
, unsigned long ino
);
506 void hfsplus_mark_mdb_dirty(struct super_block
*sb
);
509 extern u16 hfsplus_case_fold_table
[];
510 extern u16 hfsplus_decompose_table
[];
511 extern u16 hfsplus_compose_table
[];
514 int hfsplus_strcasecmp(const struct hfsplus_unistr
*s1
,
515 const struct hfsplus_unistr
*s2
);
516 int hfsplus_strcmp(const struct hfsplus_unistr
*s1
,
517 const struct hfsplus_unistr
*s2
);
518 int hfsplus_uni2asc(struct super_block
*sb
, const struct hfsplus_unistr
*ustr
,
519 char *astr
, int *len_p
);
520 int hfsplus_asc2uni(struct super_block
*sb
, struct hfsplus_unistr
*ustr
,
521 int max_unistr_len
, const char *astr
, int len
);
522 int hfsplus_hash_dentry(const struct dentry
*dentry
, struct qstr
*str
);
523 int hfsplus_compare_dentry(const struct dentry
*parent
,
524 const struct dentry
*dentry
, unsigned int len
,
525 const char *str
, const struct qstr
*name
);
528 int hfsplus_submit_bio(struct super_block
*sb
, sector_t sector
, void *buf
,
529 void **data
, int op
, int op_flags
);
530 int hfsplus_read_wrapper(struct super_block
*sb
);
533 #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
534 #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
537 #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
538 #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
539 #define hfsp_now2mt() __hfsp_ut2mt(get_seconds())