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 #ifdef pr_fmt 14 #undef pr_fmt 15 #endif 16 17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 18 19 #include <linux/fs.h> 20 #include <linux/mutex.h> 21 #include <linux/buffer_head.h> 22 #include <linux/blkdev.h> 23 #include "hfsplus_raw.h" 24 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 34 35 #if 0 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) 39 #endif 40 #define DBG_MASK (0) 41 42 #define hfs_dbg(flg, fmt, ...) \ 43 do { \ 44 if (DBG_##flg & DBG_MASK) \ 45 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ 46 } while (0) 47 48 #define hfs_dbg_cont(flg, fmt, ...) \ 49 do { \ 50 if (DBG_##flg & DBG_MASK) \ 51 pr_cont(fmt, ##__VA_ARGS__); \ 52 } while (0) 53 54 /* Runtime config options */ 55 #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */ 56 57 #define HFSPLUS_TYPE_DATA 0x00 58 #define HFSPLUS_TYPE_RSRC 0xFF 59 60 typedef int (*btree_keycmp)(const hfsplus_btree_key *, 61 const hfsplus_btree_key *); 62 63 #define NODE_HASH_SIZE 256 64 65 /* B-tree mutex nested subclasses */ 66 enum hfsplus_btree_mutex_classes { 67 CATALOG_BTREE_MUTEX, 68 EXTENTS_BTREE_MUTEX, 69 ATTR_BTREE_MUTEX, 70 }; 71 72 /* An HFS+ BTree held in memory */ 73 struct hfs_btree { 74 struct super_block *sb; 75 struct inode *inode; 76 btree_keycmp keycmp; 77 78 u32 cnid; 79 u32 root; 80 u32 leaf_count; 81 u32 leaf_head; 82 u32 leaf_tail; 83 u32 node_count; 84 u32 free_nodes; 85 u32 attributes; 86 87 unsigned int node_size; 88 unsigned int node_size_shift; 89 unsigned int max_key_len; 90 unsigned int depth; 91 92 struct mutex tree_lock; 93 94 unsigned int pages_per_bnode; 95 spinlock_t hash_lock; 96 struct hfs_bnode *node_hash[NODE_HASH_SIZE]; 97 int node_hash_cnt; 98 }; 99 100 struct page; 101 102 /* An HFS+ BTree node in memory */ 103 struct hfs_bnode { 104 struct hfs_btree *tree; 105 106 u32 prev; 107 u32 this; 108 u32 next; 109 u32 parent; 110 111 u16 num_recs; 112 u8 type; 113 u8 height; 114 115 struct hfs_bnode *next_hash; 116 unsigned long flags; 117 wait_queue_head_t lock_wq; 118 atomic_t refcnt; 119 unsigned int page_offset; 120 struct page *page[0]; 121 }; 122 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 128 129 /* 130 * HFS+ superblock info (built from Volume Header on disk) 131 */ 132 133 struct hfsplus_vh; 134 struct hfs_btree; 135 136 struct hfsplus_sb_info { 137 void *s_vhdr_buf; 138 struct hfsplus_vh *s_vhdr; 139 void *s_backup_vhdr_buf; 140 struct hfsplus_vh *s_backup_vhdr; 141 struct hfs_btree *ext_tree; 142 struct hfs_btree *cat_tree; 143 struct hfs_btree *attr_tree; 144 struct inode *alloc_file; 145 struct inode *hidden_dir; 146 struct nls_table *nls; 147 148 /* Runtime variables */ 149 u32 blockoffset; 150 sector_t part_start; 151 sector_t sect_count; 152 int fs_shift; 153 154 /* immutable data from the volume header */ 155 u32 alloc_blksz; 156 int alloc_blksz_shift; 157 u32 total_blocks; 158 u32 data_clump_blocks, rsrc_clump_blocks; 159 160 /* mutable data from the volume header, protected by alloc_mutex */ 161 u32 free_blocks; 162 struct mutex alloc_mutex; 163 164 /* mutable data from the volume header, protected by vh_mutex */ 165 u32 next_cnid; 166 u32 file_count; 167 u32 folder_count; 168 struct mutex vh_mutex; 169 170 /* Config options */ 171 u32 creator; 172 u32 type; 173 174 umode_t umask; 175 kuid_t uid; 176 kgid_t gid; 177 178 int part, session; 179 unsigned long flags; 180 181 int work_queued; /* non-zero delayed work is queued */ 182 struct delayed_work sync_work; /* FS sync delayed work */ 183 spinlock_t work_lock; /* protects sync_work and work_queued */ 184 }; 185 186 #define HFSPLUS_SB_WRITEBACKUP 0 187 #define HFSPLUS_SB_NODECOMPOSE 1 188 #define HFSPLUS_SB_FORCE 2 189 #define HFSPLUS_SB_HFSX 3 190 #define HFSPLUS_SB_CASEFOLD 4 191 #define HFSPLUS_SB_NOBARRIER 5 192 193 static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb) 194 { 195 return sb->s_fs_info; 196 } 197 198 199 struct hfsplus_inode_info { 200 atomic_t opencnt; 201 202 /* 203 * Extent allocation information, protected by extents_lock. 204 */ 205 u32 first_blocks; 206 u32 clump_blocks; 207 u32 alloc_blocks; 208 u32 cached_start; 209 u32 cached_blocks; 210 hfsplus_extent_rec first_extents; 211 hfsplus_extent_rec cached_extents; 212 unsigned int extent_state; 213 struct mutex extents_lock; 214 215 /* 216 * Immutable data. 217 */ 218 struct inode *rsrc_inode; 219 __be32 create_date; 220 221 /* 222 * Protected by sbi->vh_mutex. 223 */ 224 u32 linkid; 225 226 /* 227 * Accessed using atomic bitops. 228 */ 229 unsigned long flags; 230 231 /* 232 * Protected by i_mutex. 233 */ 234 sector_t fs_blocks; 235 u8 userflags; /* BSD user file flags */ 236 struct list_head open_dir_list; 237 loff_t phys_size; 238 239 struct inode vfs_inode; 240 }; 241 242 #define HFSPLUS_EXT_DIRTY 0x0001 243 #define HFSPLUS_EXT_NEW 0x0002 244 245 #define HFSPLUS_I_RSRC 0 /* represents a resource fork */ 246 #define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */ 247 #define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */ 248 #define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */ 249 #define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */ 250 251 #define HFSPLUS_IS_RSRC(inode) \ 252 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags) 253 254 static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) 255 { 256 return list_entry(inode, struct hfsplus_inode_info, vfs_inode); 257 } 258 259 /* 260 * Mark an inode dirty, and also mark the btree in which the 261 * specific type of metadata is stored. 262 * For data or metadata that gets written back by into the catalog btree 263 * by hfsplus_write_inode a plain mark_inode_dirty call is enough. 264 */ 265 static inline void hfsplus_mark_inode_dirty(struct inode *inode, 266 unsigned int flag) 267 { 268 set_bit(flag, &HFSPLUS_I(inode)->flags); 269 mark_inode_dirty(inode); 270 } 271 272 struct hfs_find_data { 273 /* filled by caller */ 274 hfsplus_btree_key *search_key; 275 hfsplus_btree_key *key; 276 /* filled by find */ 277 struct hfs_btree *tree; 278 struct hfs_bnode *bnode; 279 /* filled by findrec */ 280 int record; 281 int keyoffset, keylength; 282 int entryoffset, entrylength; 283 }; 284 285 struct hfsplus_readdir_data { 286 struct list_head list; 287 struct file *file; 288 struct hfsplus_cat_key key; 289 }; 290 291 /* 292 * Find minimum acceptible I/O size for an hfsplus sb. 293 */ 294 static inline unsigned short hfsplus_min_io_size(struct super_block *sb) 295 { 296 return max_t(unsigned short, bdev_logical_block_size(sb->s_bdev), 297 HFSPLUS_SECTOR_SIZE); 298 } 299 300 #define hfs_btree_open hfsplus_btree_open 301 #define hfs_btree_close hfsplus_btree_close 302 #define hfs_btree_write hfsplus_btree_write 303 #define hfs_bmap_alloc hfsplus_bmap_alloc 304 #define hfs_bmap_free hfsplus_bmap_free 305 #define hfs_bnode_read hfsplus_bnode_read 306 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16 307 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8 308 #define hfs_bnode_read_key hfsplus_bnode_read_key 309 #define hfs_bnode_write hfsplus_bnode_write 310 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16 311 #define hfs_bnode_clear hfsplus_bnode_clear 312 #define hfs_bnode_copy hfsplus_bnode_copy 313 #define hfs_bnode_move hfsplus_bnode_move 314 #define hfs_bnode_dump hfsplus_bnode_dump 315 #define hfs_bnode_unlink hfsplus_bnode_unlink 316 #define hfs_bnode_findhash hfsplus_bnode_findhash 317 #define hfs_bnode_find hfsplus_bnode_find 318 #define hfs_bnode_unhash hfsplus_bnode_unhash 319 #define hfs_bnode_free hfsplus_bnode_free 320 #define hfs_bnode_create hfsplus_bnode_create 321 #define hfs_bnode_get hfsplus_bnode_get 322 #define hfs_bnode_put hfsplus_bnode_put 323 #define hfs_brec_lenoff hfsplus_brec_lenoff 324 #define hfs_brec_keylen hfsplus_brec_keylen 325 #define hfs_brec_insert hfsplus_brec_insert 326 #define hfs_brec_remove hfsplus_brec_remove 327 #define hfs_find_init hfsplus_find_init 328 #define hfs_find_exit hfsplus_find_exit 329 #define __hfs_brec_find __hfsplus_brec_find 330 #define hfs_brec_find hfsplus_brec_find 331 #define hfs_brec_read hfsplus_brec_read 332 #define hfs_brec_goto hfsplus_brec_goto 333 #define hfs_part_find hfsplus_part_find 334 335 /* 336 * definitions for ext2 flag ioctls (linux really needs a generic 337 * interface for this). 338 */ 339 340 /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support 341 * chattr/lsattr */ 342 #define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS 343 #define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS 344 345 346 /* 347 * hfs+-specific ioctl for making the filesystem bootable 348 */ 349 #define HFSPLUS_IOC_BLESS _IO('h', 0x80) 350 351 typedef int (*search_strategy_t)(struct hfs_bnode *, 352 struct hfs_find_data *, 353 int *, int *, int *); 354 355 /* 356 * Functions in any *.c used in other files 357 */ 358 359 /* attributes.c */ 360 int hfsplus_create_attr_tree_cache(void); 361 void hfsplus_destroy_attr_tree_cache(void); 362 hfsplus_attr_entry *hfsplus_alloc_attr_entry(void); 363 void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry_p); 364 int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *, 365 const hfsplus_btree_key *); 366 int hfsplus_attr_build_key(struct super_block *, hfsplus_btree_key *, 367 u32, const char *); 368 void hfsplus_attr_build_key_uni(hfsplus_btree_key *key, 369 u32 cnid, 370 struct hfsplus_attr_unistr *name); 371 int hfsplus_find_attr(struct super_block *, u32, 372 const char *, struct hfs_find_data *); 373 int hfsplus_attr_exists(struct inode *inode, const char *name); 374 int hfsplus_create_attr(struct inode *, const char *, const void *, size_t); 375 int hfsplus_delete_attr(struct inode *, const char *); 376 int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid); 377 378 /* bitmap.c */ 379 int hfsplus_block_allocate(struct super_block *, u32, u32, u32 *); 380 int hfsplus_block_free(struct super_block *, u32, u32); 381 382 /* btree.c */ 383 struct hfs_btree *hfs_btree_open(struct super_block *, u32); 384 void hfs_btree_close(struct hfs_btree *); 385 int hfs_btree_write(struct hfs_btree *); 386 struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *); 387 void hfs_bmap_free(struct hfs_bnode *); 388 389 /* bnode.c */ 390 void hfs_bnode_read(struct hfs_bnode *, void *, int, int); 391 u16 hfs_bnode_read_u16(struct hfs_bnode *, int); 392 u8 hfs_bnode_read_u8(struct hfs_bnode *, int); 393 void hfs_bnode_read_key(struct hfs_bnode *, void *, int); 394 void hfs_bnode_write(struct hfs_bnode *, void *, int, int); 395 void hfs_bnode_write_u16(struct hfs_bnode *, int, u16); 396 void hfs_bnode_clear(struct hfs_bnode *, int, int); 397 void hfs_bnode_copy(struct hfs_bnode *, int, 398 struct hfs_bnode *, int, int); 399 void hfs_bnode_move(struct hfs_bnode *, int, int, int); 400 void hfs_bnode_dump(struct hfs_bnode *); 401 void hfs_bnode_unlink(struct hfs_bnode *); 402 struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *, u32); 403 struct hfs_bnode *hfs_bnode_find(struct hfs_btree *, u32); 404 void hfs_bnode_unhash(struct hfs_bnode *); 405 void hfs_bnode_free(struct hfs_bnode *); 406 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *, u32); 407 void hfs_bnode_get(struct hfs_bnode *); 408 void hfs_bnode_put(struct hfs_bnode *); 409 410 /* brec.c */ 411 u16 hfs_brec_lenoff(struct hfs_bnode *, u16, u16 *); 412 u16 hfs_brec_keylen(struct hfs_bnode *, u16); 413 int hfs_brec_insert(struct hfs_find_data *, void *, int); 414 int hfs_brec_remove(struct hfs_find_data *); 415 416 /* bfind.c */ 417 int hfs_find_init(struct hfs_btree *, struct hfs_find_data *); 418 void hfs_find_exit(struct hfs_find_data *); 419 int hfs_find_1st_rec_by_cnid(struct hfs_bnode *, 420 struct hfs_find_data *, 421 int *, int *, int *); 422 int hfs_find_rec_by_key(struct hfs_bnode *, 423 struct hfs_find_data *, 424 int *, int *, int *); 425 int __hfs_brec_find(struct hfs_bnode *, struct hfs_find_data *, 426 search_strategy_t); 427 int hfs_brec_find(struct hfs_find_data *, search_strategy_t); 428 int hfs_brec_read(struct hfs_find_data *, void *, int); 429 int hfs_brec_goto(struct hfs_find_data *, int); 430 431 /* catalog.c */ 432 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *, 433 const hfsplus_btree_key *); 434 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *, 435 const hfsplus_btree_key *); 436 void hfsplus_cat_build_key(struct super_block *sb, 437 hfsplus_btree_key *, u32, struct qstr *); 438 int hfsplus_find_cat(struct super_block *, u32, struct hfs_find_data *); 439 int hfsplus_create_cat(u32, struct inode *, struct qstr *, struct inode *); 440 int hfsplus_delete_cat(u32, struct inode *, struct qstr *); 441 int hfsplus_rename_cat(u32, struct inode *, struct qstr *, 442 struct inode *, struct qstr *); 443 void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms); 444 445 /* dir.c */ 446 extern const struct inode_operations hfsplus_dir_inode_operations; 447 extern const struct file_operations hfsplus_dir_operations; 448 449 /* extents.c */ 450 int hfsplus_ext_cmp_key(const hfsplus_btree_key *, const hfsplus_btree_key *); 451 int hfsplus_ext_write_extent(struct inode *); 452 int hfsplus_get_block(struct inode *, sector_t, struct buffer_head *, int); 453 int hfsplus_free_fork(struct super_block *, u32, 454 struct hfsplus_fork_raw *, int); 455 int hfsplus_file_extend(struct inode *); 456 void hfsplus_file_truncate(struct inode *); 457 458 /* inode.c */ 459 extern const struct address_space_operations hfsplus_aops; 460 extern const struct address_space_operations hfsplus_btree_aops; 461 extern const struct dentry_operations hfsplus_dentry_operations; 462 463 void hfsplus_inode_read_fork(struct inode *, struct hfsplus_fork_raw *); 464 void hfsplus_inode_write_fork(struct inode *, struct hfsplus_fork_raw *); 465 int hfsplus_cat_read_inode(struct inode *, struct hfs_find_data *); 466 int hfsplus_cat_write_inode(struct inode *); 467 struct inode *hfsplus_new_inode(struct super_block *, umode_t); 468 void hfsplus_delete_inode(struct inode *); 469 int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, 470 int datasync); 471 472 /* ioctl.c */ 473 long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); 474 475 /* options.c */ 476 int hfsplus_parse_options(char *, struct hfsplus_sb_info *); 477 int hfsplus_parse_options_remount(char *input, int *force); 478 void hfsplus_fill_defaults(struct hfsplus_sb_info *); 479 int hfsplus_show_options(struct seq_file *, struct dentry *); 480 481 /* super.c */ 482 struct inode *hfsplus_iget(struct super_block *, unsigned long); 483 void hfsplus_mark_mdb_dirty(struct super_block *sb); 484 485 /* tables.c */ 486 extern u16 hfsplus_case_fold_table[]; 487 extern u16 hfsplus_decompose_table[]; 488 extern u16 hfsplus_compose_table[]; 489 490 /* unicode.c */ 491 int hfsplus_strcasecmp(const struct hfsplus_unistr *, 492 const struct hfsplus_unistr *); 493 int hfsplus_strcmp(const struct hfsplus_unistr *, 494 const struct hfsplus_unistr *); 495 int hfsplus_uni2asc(struct super_block *, 496 const struct hfsplus_unistr *, char *, int *); 497 int hfsplus_asc2uni(struct super_block *, 498 struct hfsplus_unistr *, int, const char *, int); 499 int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str); 500 int hfsplus_compare_dentry(const struct dentry *parent, const struct dentry *dentry, 501 unsigned int len, const char *str, const struct qstr *name); 502 503 /* wrapper.c */ 504 int hfsplus_read_wrapper(struct super_block *); 505 int hfs_part_find(struct super_block *, sector_t *, sector_t *); 506 int hfsplus_submit_bio(struct super_block *sb, sector_t sector, 507 void *buf, void **data, int rw); 508 509 /* time macros */ 510 #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U) 511 #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U)) 512 513 /* compatibility */ 514 #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) } 515 #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec) 516 #define hfsp_now2mt() __hfsp_ut2mt(get_seconds()) 517 518 #endif 519