1/* 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> 14#include <linux/mutex.h> 15#include <linux/buffer_head.h> 16#include "hfsplus_jbd.h" 17#include "hfsplus_raw.h" 18 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_JOURNAL 0x00000080 27#define DBG_JREPLAY 0x00000100 28#define DBG_JTRANS 0x00000200 29#define DBG_JCOMMIT 0x00000400 30#define DBG_JCHKPT 0x00000800 31 32//#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD) 33//#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE) 34//#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT) 35//#define DBG_MASK (0) 36#define DBG_MASK (DBG_JOURNAL|DBG_JREPLAY) 37 38#define HFSPLUS_JOURNAL_PRESENT 1 39#define HFSPLUS_JOURNAL_CONSISTENT 0 40#define HFSPLUS_JOURNAL_INCONSISTENT 1 41#define HFSPLUS_JOURNAL_UIBYTE 0x5A /* Unimportant byte value */ 42#define HFSPLUS_JOURNAL_SUCCESS 0 43#define HFSPLUS_JOURNAL_FAIL 1 44#define HFSPLUS_JOURNAL_SWAP 1 45 46#define dprint(flg, fmt, args...) \ 47 if (flg & DBG_MASK) printk(fmt , ## args) 48 49/* Runtime config options */ 50#define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */ 51 52#define HFSPLUS_TYPE_DATA 0x00 53#define HFSPLUS_TYPE_RSRC 0xFF 54 55typedef int (*btree_keycmp)(const hfsplus_btree_key *, const hfsplus_btree_key *); 56 57#define NODE_HASH_SIZE 256 58 59/* An HFS+ BTree held in memory */ 60struct hfs_btree { 61 struct super_block *sb; 62 struct inode *inode; 63 btree_keycmp keycmp; 64 65 u32 cnid; 66 u32 root; 67 u32 leaf_count; 68 u32 leaf_head; 69 u32 leaf_tail; 70 u32 node_count; 71 u32 free_nodes; 72 u32 attributes; 73 74 unsigned int node_size; 75 unsigned int node_size_shift; 76 unsigned int max_key_len; 77 unsigned int depth; 78 79 struct mutex tree_lock; 80 81 unsigned int pages_per_bnode; 82 spinlock_t hash_lock; 83 struct hfs_bnode *node_hash[NODE_HASH_SIZE]; 84 int node_hash_cnt; 85}; 86 87struct page; 88 89/* An HFS+ BTree node in memory */ 90struct hfs_bnode { 91 struct hfs_btree *tree; 92 93 u32 prev; 94 u32 this; 95 u32 next; 96 u32 parent; 97 98 u16 num_recs; 99 u8 type; 100 u8 height; 101 102 struct hfs_bnode *next_hash; 103 unsigned long flags; 104 wait_queue_head_t lock_wq; 105 atomic_t refcnt; 106 unsigned int page_offset; 107 struct page *page[0]; 108}; 109 110#define HFS_BNODE_LOCK 0 111#define HFS_BNODE_ERROR 1 112#define HFS_BNODE_NEW 2 113#define HFS_BNODE_DIRTY 3 114#define HFS_BNODE_DELETED 4 115 116/* An HFS+ Journal held in memory */ 117struct hfsplus_journal { 118 struct semaphore jnl_lock; 119 u32 journaled; 120 u32 flags; 121 122 /* Journal info block specific */ 123 struct buffer_head *jib_bh; 124 struct hfsplus_journal_info_block *jibhdr; 125 u64 jib_offset; 126 127 /* Journal header specific */ 128 struct buffer_head *jh_bh; 129 u32 jh_bh_size; 130 u64 jh_offset; 131 struct hfsplus_journal_header *jhdr; 132 133 /* block number of meta-data */ 134 u32 ext_block; 135 u32 alloc_block; 136 u32 catalog_block; 137 u32 attr_block; 138 139 /* Pointer of JBD */ 140 struct hfsplus_jbd_s *s_journal; 141 142 /* Maximum number of blocks allowed in a single transaction */ 143 u16 journal_maxblock; 144 145 struct super_block *sbp; 146}; 147 148/* 149 * HFS+ superblock info (built from Volume Header on disk) 150 */ 151 152struct hfsplus_vh; 153struct hfs_btree; 154 155struct hfsplus_sb_info { 156 struct buffer_head *s_vhbh; 157 struct hfsplus_vh *s_vhdr; 158 struct hfs_btree *ext_tree; 159 struct hfs_btree *cat_tree; 160 struct hfs_btree *attr_tree; 161 struct inode *alloc_file; 162 struct inode *hidden_dir; 163 struct nls_table *nls; 164 165 /* Runtime variables */ 166 u32 blockoffset; 167 sector_t part_start; 168 sector_t sect_count; 169 int fs_shift; 170 171 /* Stuff in host order from Vol Header */ 172 struct hfsplus_journal jnl; 173 u32 alloc_blksz; 174 int alloc_blksz_shift; 175 u32 total_blocks; 176 u32 data_clump_blocks, rsrc_clump_blocks; 177 178 /* mutable data from the volume header, protected by alloc_mutex */ 179 u32 free_blocks; 180 struct mutex alloc_mutex; 181 182 /* mutable data from the volume header, protected by vh_mutex */ 183 u32 next_cnid; 184 u32 file_count; 185 u32 folder_count; 186 struct mutex vh_mutex; 187 188 /* Config options */ 189 u32 creator; 190 u32 type; 191 192 umode_t umask; 193 uid_t uid; 194 gid_t gid; 195 196 int part, session; 197 198 unsigned long flags; 199 200 struct hlist_head rsrc_inodes; 201}; 202 203#define HFSPLUS_SB_WRITEBACKUP 0 204#define HFSPLUS_SB_NODECOMPOSE 1 205#define HFSPLUS_SB_FORCE 2 206#define HFSPLUS_SB_HFSX 3 207#define HFSPLUS_SB_CASEFOLD 4 208#define HFSPLUS_SB_NOBARRIER 5 209 210 211struct hfsplus_inode_info { 212 atomic_t opencnt; 213 /* 214 * Extent allocation information, protected by extents_lock. 215 */ 216 u32 first_blocks; 217 u32 clump_blocks; 218 u32 alloc_blocks; 219 u32 cached_start; 220 u32 cached_blocks; 221 hfsplus_extent_rec first_extents; 222 hfsplus_extent_rec cached_extents; 223 unsigned long flags; 224 struct mutex extents_lock; 225 226 struct inode *rsrc_inode; 227 __be32 create_date; 228 /* Device number in hfsplus_permissions in catalog */ 229 u32 linkid; 230 /* BSD system and user file flags */ 231 sector_t fs_blocks; 232 u8 userflags; 233 234 struct list_head open_dir_list; 235 loff_t phys_size; 236 struct inode vfs_inode; 237}; 238 239#define HFSPLUS_FLG_RSRC 0x0001 240#define HFSPLUS_FLG_EXT_DIRTY 0x0002 241#define HFSPLUS_FLG_EXT_NEW 0x0004 242 243#define HFSPLUS_IS_DATA(inode) (!(HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC)) 244#define HFSPLUS_IS_RSRC(inode) (HFSPLUS_I(inode).flags & HFSPLUS_FLG_RSRC) 245 246#define HFSPLUS_SB(super) (*(struct hfsplus_sb_info *)(super)->s_fs_info) 247#define HFSPLUS_I(inode) (*list_entry(inode, struct hfsplus_inode_info, vfs_inode)) 248 249/* 250 * Mark an inode dirty, and also mark the btree in which the 251 * specific type of metadata is stored. 252 * For data or metadata that gets written back by into the catalog btree 253 * by hfsplus_write_inode a plain mark_inode_dirty call is enough. 254 */ 255static inline void hfsplus_mark_inode_dirty(struct inode *inode, 256 unsigned int flag) 257{ 258 set_bit(flag, &HFSPLUS_I(inode).flags); 259 mark_inode_dirty(inode); 260} 261 262struct hfs_find_data { 263 /* filled by caller */ 264 hfsplus_btree_key *search_key; 265 hfsplus_btree_key *key; 266 /* filled by find */ 267 struct hfs_btree *tree; 268 struct hfs_bnode *bnode; 269 /* filled by findrec */ 270 int record; 271 int keyoffset, keylength; 272 int entryoffset, entrylength; 273}; 274 275struct hfsplus_readdir_data { 276 struct list_head list; 277 struct file *file; 278 struct hfsplus_cat_key key; 279}; 280 281#define hfs_btree_open hfsplus_btree_open 282#define hfs_btree_close hfsplus_btree_close 283#define hfs_btree_write hfsplus_btree_write 284#define hfs_bmap_alloc hfsplus_bmap_alloc 285#define hfs_bmap_free hfsplus_bmap_free 286#define hfs_bnode_read hfsplus_bnode_read 287#define hfs_bnode_read_u16 hfsplus_bnode_read_u16 288#define hfs_bnode_read_u8 hfsplus_bnode_read_u8 289#define hfs_bnode_read_key hfsplus_bnode_read_key 290#define hfs_bnode_write hfsplus_bnode_write 291#define hfs_bnode_write_u16 hfsplus_bnode_write_u16 292#define hfs_bnode_clear hfsplus_bnode_clear 293#define hfs_bnode_copy hfsplus_bnode_copy 294#define hfs_bnode_move hfsplus_bnode_move 295#define hfs_bnode_dump hfsplus_bnode_dump 296#define hfs_bnode_unlink hfsplus_bnode_unlink 297#define hfs_bnode_findhash hfsplus_bnode_findhash 298#define hfs_bnode_find hfsplus_bnode_find 299#define hfs_bnode_unhash hfsplus_bnode_unhash 300#define hfs_bnode_free hfsplus_bnode_free 301#define hfs_bnode_create hfsplus_bnode_create 302#define hfs_bnode_get hfsplus_bnode_get 303#define hfs_bnode_put hfsplus_bnode_put 304#define hfs_brec_lenoff hfsplus_brec_lenoff 305#define hfs_brec_keylen hfsplus_brec_keylen 306#define hfs_brec_insert hfsplus_brec_insert 307#define hfs_brec_remove hfsplus_brec_remove 308#define hfs_find_init hfsplus_find_init 309#define hfs_find_exit hfsplus_find_exit 310#define __hfs_brec_find __hplusfs_brec_find 311#define hfs_brec_find hfsplus_brec_find 312#define hfs_brec_read hfsplus_brec_read 313#define hfs_brec_goto hfsplus_brec_goto 314#define hfs_part_find hfsplus_part_find 315 316/* 317 * definitions for ext2 flag ioctls (linux really needs a generic 318 * interface for this). 319 */ 320 321/* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support 322 * chattr/lsattr */ 323#define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS 324#define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS 325 326 327/* 328 * Functions in any *.c used in other files 329 */ 330 331/* bitmap.c */ 332int hfsplus_block_allocate(hfsplus_handle_t *, struct super_block *, u32, u32, u32 *); 333int hfsplus_block_free(hfsplus_handle_t *, struct super_block *, u32, u32); 334 335/* btree.c */ 336struct hfs_btree *hfs_btree_open(struct super_block *, u32); 337void hfs_btree_close(struct hfs_btree *); 338int hfs_btree_write(hfsplus_handle_t *,struct hfs_btree *); 339struct hfs_bnode *hfs_bmap_alloc(hfsplus_handle_t *, struct hfs_btree *); 340void hfs_bmap_free(hfsplus_handle_t *, struct hfs_bnode *); 341 342/* bnode.c */ 343void hfs_bnode_read(struct hfs_bnode *, void *, int, int); 344u16 hfs_bnode_read_u16(struct hfs_bnode *, int); 345u8 hfs_bnode_read_u8(struct hfs_bnode *, int); 346void hfs_bnode_read_key(struct hfs_bnode *, void *, int); 347void hfs_bnode_write(hfsplus_handle_t *, struct hfs_bnode *, void *, int, int); 348void hfs_bnode_write_u16(hfsplus_handle_t *, struct hfs_bnode *, int, u16); 349void hfs_bnode_clear(hfsplus_handle_t *, struct hfs_bnode *, int, int); 350void hfs_bnode_copy(hfsplus_handle_t *, struct hfs_bnode *, int, 351 struct hfs_bnode *, int, int); 352void hfs_bnode_move(hfsplus_handle_t *, struct hfs_bnode *, int, int, int); 353void hfs_bnode_dump(struct hfs_bnode *); 354void hfs_bnode_unlink(hfsplus_handle_t *, struct hfs_bnode *); 355struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32); 356struct hfs_bnode *hfs_bnode_find(hfsplus_handle_t *, struct hfs_btree *, u32); 357void hfs_bnode_unhash(struct hfs_bnode *); 358void hfs_bnode_free(struct hfs_bnode *); 359struct hfs_bnode *hfs_bnode_create(hfsplus_handle_t *, struct hfs_btree *, u32); 360void hfs_bnode_get(struct hfs_bnode *); 361void hfs_bnode_put(hfsplus_handle_t *, struct hfs_bnode *); 362 363/* brec.c */ 364u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *); 365u16 hfs_brec_keylen(struct hfs_bnode *, u16); 366int hfs_brec_insert(hfsplus_handle_t *, struct hfs_find_data *, void *, int); 367int hfs_brec_remove(hfsplus_handle_t *, struct hfs_find_data *); 368 369/* bfind.c */ 370int hfs_find_init(struct hfs_btree *, struct hfs_find_data *); 371void hfs_find_exit(hfsplus_handle_t *, struct hfs_find_data *); 372int hfsplus_journalled_find_init(struct hfs_btree *, struct hfs_find_data *); 373void hfsplus_journalled_find_exit(hfsplus_handle_t *, struct hfs_find_data *); 374int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *); 375int hfs_brec_find(hfsplus_handle_t *, struct hfs_find_data *); 376int hfs_brec_read(hfsplus_handle_t *, struct hfs_find_data *, void *, int); 377int hfs_brec_goto(hfsplus_handle_t *, struct hfs_find_data *, int); 378 379/* catalog.c */ 380int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *); 381int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *); 382void hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *, u32, struct qstr *); 383int hfsplus_find_cat(hfsplus_handle_t *, struct super_block *, u32, struct hfs_find_data *); 384int hfsplus_create_cat(hfsplus_handle_t *, u32, struct inode *, struct qstr *, struct inode *); 385int hfsplus_delete_cat(hfsplus_handle_t *, u32, struct inode *, struct qstr *); 386int hfsplus_rename_cat(hfsplus_handle_t *, u32, struct inode *, struct qstr *, 387 struct inode *, struct qstr *); 388void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms); 389 390/* dir.c */ 391extern const struct inode_operations hfsplus_dir_inode_operations; 392extern const struct file_operations hfsplus_dir_operations; 393 394/* extents.c */ 395int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *); 396int hfsplus_ext_write_extent(hfsplus_handle_t *, struct inode *); 397int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int); 398int hfsplus_free_fork(hfsplus_handle_t *handle, struct super_block *, u32, struct hfsplus_fork_raw *, int); 399int hfsplus_file_extend(hfsplus_handle_t *, struct inode *); 400void hfsplus_file_truncate(struct inode *); 401 402/* inode.c */ 403extern const struct address_space_operations hfsplus_aops; 404extern const struct address_space_operations hfsplus_btree_aops; 405extern const struct dentry_operations hfsplus_dentry_operations; 406extern struct address_space_operations hfsplus_journalled_aops; 407extern struct address_space_operations hfsplus_journalled_btree_aops; 408 409void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *); 410void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *); 411int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *); 412int hfsplus_cat_write_inode(hfsplus_handle_t *, struct inode *); 413struct inode *hfsplus_new_inode(hfsplus_handle_t *, struct super_block *, int); 414void hfsplus_delete_inode(hfsplus_handle_t *, struct inode *); 415int hfsplus_do_journal_get_write_access(hfsplus_handle_t *, struct buffer_head *); 416int hfsplus_commit_write_fn(hfsplus_handle_t *, struct buffer_head *); 417int hfsplus_walk_page_buffers(hfsplus_handle_t *, struct buffer_head *, unsigned , 418 unsigned , int *, int (*fn)(hfsplus_handle_t *, struct buffer_head *)); 419int hfsplus_file_fsync(struct file *file, int datasync); 420 421/* ioctl.c */ 422long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 423int hfsplus_setxattr(struct dentry *dentry, const char *name, 424 const void *value, size_t size, int flags); 425ssize_t hfsplus_getxattr(struct dentry *dentry, const char *name, 426 void *value, size_t size); 427ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size); 428 429/* options.c */ 430int hfsplus_parse_options(char *, struct hfsplus_sb_info *); 431int hfsplus_parse_options_remount(char *input, int *force); 432void hfsplus_fill_defaults(struct hfsplus_sb_info *); 433int hfsplus_show_options(struct seq_file *, struct vfsmount *); 434 435/* super.c */ 436struct inode *hfsplus_iget(struct super_block *, unsigned long); 437int hfsplus_sync_fs(struct super_block *sb, int wait); 438 439/* tables.c */ 440extern u16 hfsplus_case_fold_table[]; 441extern u16 hfsplus_decompose_table[]; 442extern u16 hfsplus_compose_table[]; 443 444/* unicode.c */ 445int hfsplus_strcasecmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *); 446int hfsplus_strcmp(const struct hfsplus_unistr *, const struct hfsplus_unistr *); 447int hfsplus_uni2asc(struct super_block *, const struct hfsplus_unistr *, char *, int *); 448int hfsplus_asc2uni(struct super_block *, struct hfsplus_unistr *, const char *, int); 449int hfsplus_hash_dentry(struct dentry *dentry, struct qstr *str); 450int hfsplus_compare_dentry(struct dentry *dentry, struct qstr *s1, struct qstr *s2); 451 452/* wrapper.c */ 453int hfsplus_read_wrapper(struct super_block *); 454 455int hfs_part_find(struct super_block *, sector_t *, sector_t *); 456 457int hfsplus_submit_bio(struct block_device *bdev, sector_t sector, 458 void *data, int rw); 459 460/* journal.c */ 461void hfsplus_journalled_init(struct super_block *, struct hfsplus_vh *); 462void hfsplus_journalled_deinit(struct super_block *); 463int hfsplus_journalled_create(struct super_block *); 464int hfsplus_journalled_check(struct super_block *); 465void print_volume_header(struct super_block *); 466void swap_block_list_header(struct hfsplus_blhdr *); 467hfsplus_jbd_t * hfsplus_get_dev_journal(struct super_block *); 468int hfsplus_journalled_mark_inode_dirty(const char *, hfsplus_handle_t *, struct inode *); 469int hfsplus_journalled_set_page_dirty(hfsplus_handle_t *, struct page *); 470int hfsplus_journal_start(const char *, struct super_block *sb, hfsplus_handle_t *hfsplus_handle); 471int hfsplus_journal_stop(hfsplus_handle_t *); 472int hfsplus_journal_get_write_access(const char *, hfsplus_handle_t *, struct buffer_head *); 473int hfsplus_journal_dirty_metadata(const char *, struct buffer_head *, hfsplus_handle_t *); 474int hfsplus_force_commit(struct super_block *); 475void hfsplus_jhdr_checksum_calculate(hfsplus_jbd_t *); 476void hfsplus_journal_header_start_update(hfsplus_jbd_t *, unsigned long); 477void hfsplus_journal_header_end_update(hfsplus_jbd_t *, struct hfsplus_journal_header *); 478void hfsplus_journal_mark_journal_empty(hfsplus_jbd_t *); 479void hfsplus_test_block_list_header(const char *, struct hfsplus_journal_header *, struct hfsplus_journal *); 480 481/* access macros */ 482/* 483static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb) 484{ 485 return sb->s_fs_info; 486} 487static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) 488{ 489 return list_entry(inode, struct hfsplus_inode_info, vfs_inode); 490} 491*/ 492 493#define hfsplus_kmap(p) ({ struct page *__p = (p); kmap(__p); }) 494#define hfsplus_kunmap(p) ({ struct page *__p = (p); kunmap(__p); __p; }) 495 496#define sb_bread512(sb, sec, data) ({ \ 497 struct buffer_head *__bh; \ 498 sector_t __block; \ 499 loff_t __start; \ 500 int __offset; \ 501 \ 502 __start = (loff_t)(sec) << HFSPLUS_SECTOR_SHIFT;\ 503 __block = __start >> (sb)->s_blocksize_bits; \ 504 __offset = __start & ((sb)->s_blocksize - 1); \ 505 __bh = sb_bread((sb), __block); \ 506 if (likely(__bh != NULL)) \ 507 data = (void *)(__bh->b_data + __offset);\ 508 else \ 509 data = NULL; \ 510 __bh; \ 511}) 512 513/* time macros */ 514#define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U) 515#define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U)) 516 517/* compatibility */ 518#define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) } 519#define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec) 520#define hfsp_now2mt() __hfsp_ut2mt(get_seconds()) 521 522#define kdev_t_to_nr(x) (x) 523 524#endif 525