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
35 #define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
36 #define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
37 #define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
41 #define hfs_dbg(flg, fmt, ...) \
43 if (DBG_##flg & DBG_MASK) \
44 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
47 #define hfs_dbg_cont(flg, fmt, ...) \
49 if (DBG_##flg & DBG_MASK) \
50 pr_cont(fmt, ##__VA_ARGS__); \
53 /* Runtime config options */
54 #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
56 #define HFSPLUS_TYPE_DATA 0x00
57 #define HFSPLUS_TYPE_RSRC 0xFF
59 typedef int (*btree_keycmp
)(const hfsplus_btree_key
*,
60 const hfsplus_btree_key
*);
62 #define NODE_HASH_SIZE 256
64 /* B-tree mutex nested subclasses */
65 enum hfsplus_btree_mutex_classes
{
71 /* An HFS+ BTree held in memory */
73 struct super_block
*sb
;
86 unsigned int node_size
;
87 unsigned int node_size_shift
;
88 unsigned int max_key_len
;
91 struct mutex tree_lock
;
93 unsigned int pages_per_bnode
;
95 struct hfs_bnode
*node_hash
[NODE_HASH_SIZE
];
101 /* An HFS+ BTree node in memory */
103 struct hfs_btree
*tree
;
114 struct hfs_bnode
*next_hash
;
116 wait_queue_head_t lock_wq
;
118 unsigned int page_offset
;
119 struct page
*page
[0];
122 #define HFS_BNODE_LOCK 0
123 #define HFS_BNODE_ERROR 1
124 #define HFS_BNODE_NEW 2
125 #define HFS_BNODE_DIRTY 3
126 #define HFS_BNODE_DELETED 4
129 * HFS+ superblock info (built from Volume Header on disk)
135 struct hfsplus_sb_info
{
137 struct hfsplus_vh
*s_vhdr
;
138 void *s_backup_vhdr_buf
;
139 struct hfsplus_vh
*s_backup_vhdr
;
140 struct hfs_btree
*ext_tree
;
141 struct hfs_btree
*cat_tree
;
142 struct hfs_btree
*attr_tree
;
143 struct inode
*alloc_file
;
144 struct inode
*hidden_dir
;
145 struct nls_table
*nls
;
147 /* Runtime variables */
153 /* immutable data from the volume header */
155 int alloc_blksz_shift
;
157 u32 data_clump_blocks
, rsrc_clump_blocks
;
159 /* mutable data from the volume header, protected by alloc_mutex */
161 struct mutex alloc_mutex
;
163 /* mutable data from the volume header, protected by vh_mutex */
167 struct mutex vh_mutex
;
180 int work_queued
; /* non-zero delayed work is queued */
181 struct delayed_work sync_work
; /* FS sync delayed work */
182 spinlock_t work_lock
; /* protects sync_work and work_queued */
185 #define HFSPLUS_SB_WRITEBACKUP 0
186 #define HFSPLUS_SB_NODECOMPOSE 1
187 #define HFSPLUS_SB_FORCE 2
188 #define HFSPLUS_SB_HFSX 3
189 #define HFSPLUS_SB_CASEFOLD 4
190 #define HFSPLUS_SB_NOBARRIER 5
192 static inline struct hfsplus_sb_info
*HFSPLUS_SB(struct super_block
*sb
)
194 return sb
->s_fs_info
;
198 struct hfsplus_inode_info
{
202 * Extent allocation information, protected by extents_lock.
209 hfsplus_extent_rec first_extents
;
210 hfsplus_extent_rec cached_extents
;
211 unsigned int extent_state
;
212 struct mutex extents_lock
;
217 struct inode
*rsrc_inode
;
221 * Protected by sbi->vh_mutex.
226 * Accessed using atomic bitops.
231 * Protected by i_mutex.
234 u8 userflags
; /* BSD user file flags */
235 struct list_head open_dir_list
;
238 struct inode vfs_inode
;
241 #define HFSPLUS_EXT_DIRTY 0x0001
242 #define HFSPLUS_EXT_NEW 0x0002
244 #define HFSPLUS_I_RSRC 0 /* represents a resource fork */
245 #define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
246 #define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
247 #define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
248 #define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
250 #define HFSPLUS_IS_RSRC(inode) \
251 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
253 static inline struct hfsplus_inode_info
*HFSPLUS_I(struct inode
*inode
)
255 return list_entry(inode
, struct hfsplus_inode_info
, vfs_inode
);
259 * Mark an inode dirty, and also mark the btree in which the
260 * specific type of metadata is stored.
261 * For data or metadata that gets written back by into the catalog btree
262 * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
264 static inline void hfsplus_mark_inode_dirty(struct inode
*inode
,
267 set_bit(flag
, &HFSPLUS_I(inode
)->flags
);
268 mark_inode_dirty(inode
);
271 struct hfs_find_data
{
272 /* filled by caller */
273 hfsplus_btree_key
*search_key
;
274 hfsplus_btree_key
*key
;
276 struct hfs_btree
*tree
;
277 struct hfs_bnode
*bnode
;
278 /* filled by findrec */
280 int keyoffset
, keylength
;
281 int entryoffset
, entrylength
;
284 struct hfsplus_readdir_data
{
285 struct list_head list
;
287 struct hfsplus_cat_key key
;
291 * Find minimum acceptible I/O size for an hfsplus sb.
293 static inline unsigned short hfsplus_min_io_size(struct super_block
*sb
)
295 return max_t(unsigned short, bdev_logical_block_size(sb
->s_bdev
),
296 HFSPLUS_SECTOR_SIZE
);
299 #define hfs_btree_open hfsplus_btree_open
300 #define hfs_btree_close hfsplus_btree_close
301 #define hfs_btree_write hfsplus_btree_write
302 #define hfs_bmap_alloc hfsplus_bmap_alloc
303 #define hfs_bmap_free hfsplus_bmap_free
304 #define hfs_bnode_read hfsplus_bnode_read
305 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
306 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
307 #define hfs_bnode_read_key hfsplus_bnode_read_key
308 #define hfs_bnode_write hfsplus_bnode_write
309 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
310 #define hfs_bnode_clear hfsplus_bnode_clear
311 #define hfs_bnode_copy hfsplus_bnode_copy
312 #define hfs_bnode_move hfsplus_bnode_move
313 #define hfs_bnode_dump hfsplus_bnode_dump
314 #define hfs_bnode_unlink hfsplus_bnode_unlink
315 #define hfs_bnode_findhash hfsplus_bnode_findhash
316 #define hfs_bnode_find hfsplus_bnode_find
317 #define hfs_bnode_unhash hfsplus_bnode_unhash
318 #define hfs_bnode_free hfsplus_bnode_free
319 #define hfs_bnode_create hfsplus_bnode_create
320 #define hfs_bnode_get hfsplus_bnode_get
321 #define hfs_bnode_put hfsplus_bnode_put
322 #define hfs_brec_lenoff hfsplus_brec_lenoff
323 #define hfs_brec_keylen hfsplus_brec_keylen
324 #define hfs_brec_insert hfsplus_brec_insert
325 #define hfs_brec_remove hfsplus_brec_remove
326 #define hfs_find_init hfsplus_find_init
327 #define hfs_find_exit hfsplus_find_exit
328 #define __hfs_brec_find __hfsplus_brec_find
329 #define hfs_brec_find hfsplus_brec_find
330 #define hfs_brec_read hfsplus_brec_read
331 #define hfs_brec_goto hfsplus_brec_goto
332 #define hfs_part_find hfsplus_part_find
335 * definitions for ext2 flag ioctls (linux really needs a generic
336 * interface for this).
339 /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
341 #define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
342 #define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
346 * hfs+-specific ioctl for making the filesystem bootable
348 #define HFSPLUS_IOC_BLESS _IO('h', 0x80)
350 typedef int (*search_strategy_t
)(struct hfs_bnode
*,
351 struct hfs_find_data
*,
352 int *, int *, int *);
355 * Functions in any *.c used in other files
359 int hfsplus_create_attr_tree_cache(void);
360 void hfsplus_destroy_attr_tree_cache(void);
361 hfsplus_attr_entry
*hfsplus_alloc_attr_entry(void);
362 void hfsplus_destroy_attr_entry(hfsplus_attr_entry
*entry_p
);
363 int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key
*,
364 const hfsplus_btree_key
*);
365 int hfsplus_attr_build_key(struct super_block
*, hfsplus_btree_key
*,
367 void hfsplus_attr_build_key_uni(hfsplus_btree_key
*key
,
369 struct hfsplus_attr_unistr
*name
);
370 int hfsplus_find_attr(struct super_block
*, u32
,
371 const char *, struct hfs_find_data
*);
372 int hfsplus_attr_exists(struct inode
*inode
, const char *name
);
373 int hfsplus_create_attr(struct inode
*, const char *, const void *, size_t);
374 int hfsplus_delete_attr(struct inode
*, const char *);
375 int hfsplus_delete_all_attrs(struct inode
*dir
, u32 cnid
);
378 int hfsplus_block_allocate(struct super_block
*, u32
, u32
, u32
*);
379 int hfsplus_block_free(struct super_block
*, u32
, u32
);
382 struct hfs_btree
*hfs_btree_open(struct super_block
*, u32
);
383 void hfs_btree_close(struct hfs_btree
*);
384 int hfs_btree_write(struct hfs_btree
*);
385 struct hfs_bnode
*hfs_bmap_alloc(struct hfs_btree
*);
386 void hfs_bmap_free(struct hfs_bnode
*);
389 void hfs_bnode_read(struct hfs_bnode
*, void *, int, int);
390 u16
hfs_bnode_read_u16(struct hfs_bnode
*, int);
391 u8
hfs_bnode_read_u8(struct hfs_bnode
*, int);
392 void hfs_bnode_read_key(struct hfs_bnode
*, void *, int);
393 void hfs_bnode_write(struct hfs_bnode
*, void *, int, int);
394 void hfs_bnode_write_u16(struct hfs_bnode
*, int, u16
);
395 void hfs_bnode_clear(struct hfs_bnode
*, int, int);
396 void hfs_bnode_copy(struct hfs_bnode
*, int,
397 struct hfs_bnode
*, int, int);
398 void hfs_bnode_move(struct hfs_bnode
*, int, int, int);
399 void hfs_bnode_dump(struct hfs_bnode
*);
400 void hfs_bnode_unlink(struct hfs_bnode
*);
401 struct hfs_bnode
*hfs_bnode_findhash(struct hfs_btree
*, u32
);
402 struct hfs_bnode
*hfs_bnode_find(struct hfs_btree
*, u32
);
403 void hfs_bnode_unhash(struct hfs_bnode
*);
404 void hfs_bnode_free(struct hfs_bnode
*);
405 struct hfs_bnode
*hfs_bnode_create(struct hfs_btree
*, u32
);
406 void hfs_bnode_get(struct hfs_bnode
*);
407 void hfs_bnode_put(struct hfs_bnode
*);
410 u16
hfs_brec_lenoff(struct hfs_bnode
*, u16
, u16
*);
411 u16
hfs_brec_keylen(struct hfs_bnode
*, u16
);
412 int hfs_brec_insert(struct hfs_find_data
*, void *, int);
413 int hfs_brec_remove(struct hfs_find_data
*);
416 int hfs_find_init(struct hfs_btree
*, struct hfs_find_data
*);
417 void hfs_find_exit(struct hfs_find_data
*);
418 int hfs_find_1st_rec_by_cnid(struct hfs_bnode
*,
419 struct hfs_find_data
*,
420 int *, int *, int *);
421 int hfs_find_rec_by_key(struct hfs_bnode
*,
422 struct hfs_find_data
*,
423 int *, int *, int *);
424 int __hfs_brec_find(struct hfs_bnode
*, struct hfs_find_data
*,
426 int hfs_brec_find(struct hfs_find_data
*, search_strategy_t
);
427 int hfs_brec_read(struct hfs_find_data
*, void *, int);
428 int hfs_brec_goto(struct hfs_find_data
*, int);
431 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key
*,
432 const hfsplus_btree_key
*);
433 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key
*,
434 const hfsplus_btree_key
*);
435 void hfsplus_cat_build_key(struct super_block
*sb
,
436 hfsplus_btree_key
*, u32
, struct qstr
*);
437 int hfsplus_find_cat(struct super_block
*, u32
, struct hfs_find_data
*);
438 int hfsplus_create_cat(u32
, struct inode
*, struct qstr
*, struct inode
*);
439 int hfsplus_delete_cat(u32
, struct inode
*, struct qstr
*);
440 int hfsplus_rename_cat(u32
, struct inode
*, struct qstr
*,
441 struct inode
*, struct qstr
*);
442 void hfsplus_cat_set_perms(struct inode
*inode
, struct hfsplus_perm
*perms
);
445 extern const struct inode_operations hfsplus_dir_inode_operations
;
446 extern const struct file_operations hfsplus_dir_operations
;
449 int hfsplus_ext_cmp_key(const hfsplus_btree_key
*, const hfsplus_btree_key
*);
450 int hfsplus_ext_write_extent(struct inode
*);
451 int hfsplus_get_block(struct inode
*, sector_t
, struct buffer_head
*, int);
452 int hfsplus_free_fork(struct super_block
*, u32
,
453 struct hfsplus_fork_raw
*, int);
454 int hfsplus_file_extend(struct inode
*);
455 void hfsplus_file_truncate(struct inode
*);
458 extern const struct address_space_operations hfsplus_aops
;
459 extern const struct address_space_operations hfsplus_btree_aops
;
460 extern const struct dentry_operations hfsplus_dentry_operations
;
462 void hfsplus_inode_read_fork(struct inode
*, struct hfsplus_fork_raw
*);
463 void hfsplus_inode_write_fork(struct inode
*, struct hfsplus_fork_raw
*);
464 int hfsplus_cat_read_inode(struct inode
*, struct hfs_find_data
*);
465 int hfsplus_cat_write_inode(struct inode
*);
466 struct inode
*hfsplus_new_inode(struct super_block
*, umode_t
);
467 void hfsplus_delete_inode(struct inode
*);
468 int hfsplus_file_fsync(struct file
*file
, loff_t start
, loff_t end
,
472 long hfsplus_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
);
475 int hfsplus_parse_options(char *, struct hfsplus_sb_info
*);
476 int hfsplus_parse_options_remount(char *input
, int *force
);
477 void hfsplus_fill_defaults(struct hfsplus_sb_info
*);
478 int hfsplus_show_options(struct seq_file
*, struct dentry
*);
481 struct inode
*hfsplus_iget(struct super_block
*, unsigned long);
482 void hfsplus_mark_mdb_dirty(struct super_block
*sb
);
485 extern u16 hfsplus_case_fold_table
[];
486 extern u16 hfsplus_decompose_table
[];
487 extern u16 hfsplus_compose_table
[];
490 int hfsplus_strcasecmp(const struct hfsplus_unistr
*,
491 const struct hfsplus_unistr
*);
492 int hfsplus_strcmp(const struct hfsplus_unistr
*,
493 const struct hfsplus_unistr
*);
494 int hfsplus_uni2asc(struct super_block
*,
495 const struct hfsplus_unistr
*, char *, int *);
496 int hfsplus_asc2uni(struct super_block
*,
497 struct hfsplus_unistr
*, int, const char *, int);
498 int hfsplus_hash_dentry(const struct dentry
*dentry
, struct qstr
*str
);
499 int hfsplus_compare_dentry(const struct dentry
*parent
, const struct dentry
*dentry
,
500 unsigned int len
, const char *str
, const struct qstr
*name
);
503 int hfsplus_read_wrapper(struct super_block
*);
504 int hfs_part_find(struct super_block
*, sector_t
*, sector_t
*);
505 int hfsplus_submit_bio(struct super_block
*sb
, sector_t sector
,
506 void *buf
, void **data
, int rw
);
509 #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
510 #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
513 #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
514 #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
515 #define hfsp_now2mt() __hfsp_ut2mt(get_seconds())