Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 13 | #ifdef pr_fmt |
| 14 | #undef pr_fmt |
| 15 | #endif |
| 16 | |
| 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/fs.h> |
Matthias Kaehlcke | 895c23f | 2008-07-25 01:46:36 -0700 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/buffer_head.h> |
Seth Forshee | 6596528 | 2011-07-18 08:06:23 -0700 | [diff] [blame] | 22 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 32 | #define DBG_ATTR_MOD 0x00000080 |
Vyacheslav Dubeyko | 2c92057 | 2013-09-11 14:24:28 -0700 | [diff] [blame] | 33 | #define DBG_ACL_MOD 0x00000100 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Anton Salikhmetov | 21f2296 | 2010-12-16 18:08:39 +0200 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define DBG_MASK (0) |
| 41 | |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 42 | #define hfs_dbg(flg, fmt, ...) \ |
| 43 | do { \ |
| 44 | if (DBG_##flg & DBG_MASK) \ |
| 45 | printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \ |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 46 | } while (0) |
| 47 | |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 48 | #define hfs_dbg_cont(flg, fmt, ...) \ |
| 49 | do { \ |
| 50 | if (DBG_##flg & DBG_MASK) \ |
| 51 | pr_cont(fmt, ##__VA_ARGS__); \ |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 52 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Anton Salikhmetov | 2753cc2 | 2010-12-16 18:08:38 +0200 | [diff] [blame] | 60 | typedef int (*btree_keycmp)(const hfsplus_btree_key *, |
| 61 | const hfsplus_btree_key *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
| 63 | #define NODE_HASH_SIZE 256 |
| 64 | |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Thomas Gleixner | 467c3d9 | 2010-10-01 05:46:52 +0200 | [diff] [blame] | 92 | struct mutex tree_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | /* |
Vyacheslav Dubeyko | 95e0d7d | 2013-11-12 15:11:09 -0800 | [diff] [blame] | 130 | * Attributes file states |
| 131 | */ |
| 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 |
| 136 | |
| 137 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | * HFS+ superblock info (built from Volume Header on disk) |
| 139 | */ |
| 140 | |
| 141 | struct hfsplus_vh; |
| 142 | struct hfs_btree; |
| 143 | |
| 144 | struct hfsplus_sb_info { |
Seth Forshee | 6596528 | 2011-07-18 08:06:23 -0700 | [diff] [blame] | 145 | void *s_vhdr_buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | struct hfsplus_vh *s_vhdr; |
Seth Forshee | 6596528 | 2011-07-18 08:06:23 -0700 | [diff] [blame] | 147 | void *s_backup_vhdr_buf; |
Christoph Hellwig | 52399b1 | 2010-11-23 14:37:47 +0100 | [diff] [blame] | 148 | struct hfsplus_vh *s_backup_vhdr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | struct hfs_btree *ext_tree; |
| 150 | struct hfs_btree *cat_tree; |
| 151 | struct hfs_btree *attr_tree; |
Vyacheslav Dubeyko | 95e0d7d | 2013-11-12 15:11:09 -0800 | [diff] [blame] | 152 | atomic_t attr_tree_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | struct inode *alloc_file; |
| 154 | struct inode *hidden_dir; |
| 155 | struct nls_table *nls; |
| 156 | |
| 157 | /* Runtime variables */ |
| 158 | u32 blockoffset; |
Christoph Hellwig | 52399b1 | 2010-11-23 14:37:47 +0100 | [diff] [blame] | 159 | sector_t part_start; |
| 160 | sector_t sect_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | int fs_shift; |
| 162 | |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 163 | /* immutable data from the volume header */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | u32 alloc_blksz; |
| 165 | int alloc_blksz_shift; |
| 166 | u32 total_blocks; |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 167 | u32 data_clump_blocks, rsrc_clump_blocks; |
| 168 | |
| 169 | /* mutable data from the volume header, protected by alloc_mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | u32 free_blocks; |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 171 | struct mutex alloc_mutex; |
| 172 | |
| 173 | /* mutable data from the volume header, protected by vh_mutex */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | u32 next_cnid; |
| 175 | u32 file_count; |
| 176 | u32 folder_count; |
Christoph Hellwig | 7ac9fb9 | 2010-10-01 05:45:08 +0200 | [diff] [blame] | 177 | struct mutex vh_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
| 179 | /* Config options */ |
| 180 | u32 creator; |
| 181 | u32 type; |
| 182 | |
| 183 | umode_t umask; |
Eric W. Biederman | 16525e3 | 2012-02-07 16:27:17 -0800 | [diff] [blame] | 184 | kuid_t uid; |
| 185 | kgid_t gid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | int part, session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | unsigned long flags; |
Artem Bityutskiy | 9e6c582 | 2012-07-12 17:26:31 +0300 | [diff] [blame] | 189 | |
| 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 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | }; |
| 194 | |
Christoph Hellwig | 84adede | 2010-10-01 05:45:20 +0200 | [diff] [blame] | 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 |
Christoph Hellwig | 34a2d31 | 2010-11-23 14:38:21 +0100 | [diff] [blame] | 200 | #define HFSPLUS_SB_NOBARRIER 5 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Christoph Hellwig | e349470 | 2010-11-23 14:38:15 +0100 | [diff] [blame] | 202 | static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb) |
| 203 | { |
| 204 | return sb->s_fs_info; |
| 205 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | |
| 208 | struct hfsplus_inode_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | atomic_t opencnt; |
| 210 | |
Christoph Hellwig | 7fcc99f | 2010-10-01 05:46:31 +0200 | [diff] [blame] | 211 | /* |
| 212 | * Extent allocation information, protected by extents_lock. |
| 213 | */ |
| 214 | u32 first_blocks; |
| 215 | u32 clump_blocks; |
| 216 | u32 alloc_blocks; |
| 217 | u32 cached_start; |
| 218 | u32 cached_blocks; |
| 219 | hfsplus_extent_rec first_extents; |
| 220 | hfsplus_extent_rec cached_extents; |
Christoph Hellwig | b33b792 | 2010-11-23 14:38:13 +0100 | [diff] [blame] | 221 | unsigned int extent_state; |
Christoph Hellwig | 7fcc99f | 2010-10-01 05:46:31 +0200 | [diff] [blame] | 222 | struct mutex extents_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Christoph Hellwig | 7fcc99f | 2010-10-01 05:46:31 +0200 | [diff] [blame] | 224 | /* |
| 225 | * Immutable data. |
| 226 | */ |
| 227 | struct inode *rsrc_inode; |
Roman Zippel | 9a4cad9 | 2006-01-18 17:43:09 -0800 | [diff] [blame] | 228 | __be32 create_date; |
Christoph Hellwig | f6089ff | 2010-10-14 09:54:28 -0400 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * Protected by sbi->vh_mutex. |
| 232 | */ |
| 233 | u32 linkid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Christoph Hellwig | 7fcc99f | 2010-10-01 05:46:31 +0200 | [diff] [blame] | 235 | /* |
Christoph Hellwig | b33b792 | 2010-11-23 14:38:13 +0100 | [diff] [blame] | 236 | * Accessed using atomic bitops. |
| 237 | */ |
| 238 | unsigned long flags; |
| 239 | |
| 240 | /* |
Christoph Hellwig | 7fcc99f | 2010-10-01 05:46:31 +0200 | [diff] [blame] | 241 | * Protected by i_mutex. |
| 242 | */ |
| 243 | sector_t fs_blocks; |
Christoph Hellwig | 722c55d | 2010-10-14 09:54:33 -0400 | [diff] [blame] | 244 | u8 userflags; /* BSD user file flags */ |
Sergei Antonov | d7d673a | 2014-03-10 15:49:51 -0700 | [diff] [blame] | 245 | u32 subfolders; /* Subfolder count (HFSX only) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | struct list_head open_dir_list; |
| 247 | loff_t phys_size; |
Christoph Hellwig | 7fcc99f | 2010-10-01 05:46:31 +0200 | [diff] [blame] | 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | struct inode vfs_inode; |
| 250 | }; |
| 251 | |
Christoph Hellwig | b33b792 | 2010-11-23 14:38:13 +0100 | [diff] [blame] | 252 | #define HFSPLUS_EXT_DIRTY 0x0001 |
| 253 | #define HFSPLUS_EXT_NEW 0x0002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Christoph Hellwig | b33b792 | 2010-11-23 14:38:13 +0100 | [diff] [blame] | 255 | #define HFSPLUS_I_RSRC 0 /* represents a resource fork */ |
Christoph Hellwig | e349470 | 2010-11-23 14:38:15 +0100 | [diff] [blame] | 256 | #define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */ |
| 257 | #define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */ |
| 258 | #define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */ |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 259 | #define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */ |
Christoph Hellwig | b33b792 | 2010-11-23 14:38:13 +0100 | [diff] [blame] | 260 | |
| 261 | #define HFSPLUS_IS_RSRC(inode) \ |
| 262 | test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Christoph Hellwig | e349470 | 2010-11-23 14:38:15 +0100 | [diff] [blame] | 264 | static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode) |
| 265 | { |
Rasmus Villemoes | db6172c | 2015-03-19 12:28:04 +0100 | [diff] [blame^] | 266 | return container_of(inode, struct hfsplus_inode_info, vfs_inode); |
Christoph Hellwig | e349470 | 2010-11-23 14:38:15 +0100 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | /* |
| 270 | * Mark an inode dirty, and also mark the btree in which the |
| 271 | * specific type of metadata is stored. |
| 272 | * For data or metadata that gets written back by into the catalog btree |
| 273 | * by hfsplus_write_inode a plain mark_inode_dirty call is enough. |
| 274 | */ |
| 275 | static inline void hfsplus_mark_inode_dirty(struct inode *inode, |
| 276 | unsigned int flag) |
| 277 | { |
| 278 | set_bit(flag, &HFSPLUS_I(inode)->flags); |
| 279 | mark_inode_dirty(inode); |
| 280 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | struct hfs_find_data { |
| 283 | /* filled by caller */ |
| 284 | hfsplus_btree_key *search_key; |
| 285 | hfsplus_btree_key *key; |
| 286 | /* filled by find */ |
| 287 | struct hfs_btree *tree; |
| 288 | struct hfs_bnode *bnode; |
| 289 | /* filled by findrec */ |
| 290 | int record; |
| 291 | int keyoffset, keylength; |
| 292 | int entryoffset, entrylength; |
| 293 | }; |
| 294 | |
| 295 | struct hfsplus_readdir_data { |
| 296 | struct list_head list; |
| 297 | struct file *file; |
| 298 | struct hfsplus_cat_key key; |
| 299 | }; |
| 300 | |
Seth Forshee | 6596528 | 2011-07-18 08:06:23 -0700 | [diff] [blame] | 301 | /* |
| 302 | * Find minimum acceptible I/O size for an hfsplus sb. |
| 303 | */ |
| 304 | static inline unsigned short hfsplus_min_io_size(struct super_block *sb) |
| 305 | { |
| 306 | return max_t(unsigned short, bdev_logical_block_size(sb->s_bdev), |
| 307 | HFSPLUS_SECTOR_SIZE); |
| 308 | } |
| 309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | #define hfs_btree_open hfsplus_btree_open |
| 311 | #define hfs_btree_close hfsplus_btree_close |
| 312 | #define hfs_btree_write hfsplus_btree_write |
| 313 | #define hfs_bmap_alloc hfsplus_bmap_alloc |
| 314 | #define hfs_bmap_free hfsplus_bmap_free |
| 315 | #define hfs_bnode_read hfsplus_bnode_read |
| 316 | #define hfs_bnode_read_u16 hfsplus_bnode_read_u16 |
| 317 | #define hfs_bnode_read_u8 hfsplus_bnode_read_u8 |
| 318 | #define hfs_bnode_read_key hfsplus_bnode_read_key |
| 319 | #define hfs_bnode_write hfsplus_bnode_write |
| 320 | #define hfs_bnode_write_u16 hfsplus_bnode_write_u16 |
| 321 | #define hfs_bnode_clear hfsplus_bnode_clear |
| 322 | #define hfs_bnode_copy hfsplus_bnode_copy |
| 323 | #define hfs_bnode_move hfsplus_bnode_move |
| 324 | #define hfs_bnode_dump hfsplus_bnode_dump |
| 325 | #define hfs_bnode_unlink hfsplus_bnode_unlink |
| 326 | #define hfs_bnode_findhash hfsplus_bnode_findhash |
| 327 | #define hfs_bnode_find hfsplus_bnode_find |
| 328 | #define hfs_bnode_unhash hfsplus_bnode_unhash |
| 329 | #define hfs_bnode_free hfsplus_bnode_free |
| 330 | #define hfs_bnode_create hfsplus_bnode_create |
| 331 | #define hfs_bnode_get hfsplus_bnode_get |
| 332 | #define hfs_bnode_put hfsplus_bnode_put |
| 333 | #define hfs_brec_lenoff hfsplus_brec_lenoff |
| 334 | #define hfs_brec_keylen hfsplus_brec_keylen |
| 335 | #define hfs_brec_insert hfsplus_brec_insert |
| 336 | #define hfs_brec_remove hfsplus_brec_remove |
| 337 | #define hfs_find_init hfsplus_find_init |
| 338 | #define hfs_find_exit hfsplus_find_exit |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 339 | #define __hfs_brec_find __hfsplus_brec_find |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | #define hfs_brec_find hfsplus_brec_find |
| 341 | #define hfs_brec_read hfsplus_brec_read |
| 342 | #define hfs_brec_goto hfsplus_brec_goto |
| 343 | #define hfs_part_find hfsplus_part_find |
| 344 | |
| 345 | /* |
| 346 | * definitions for ext2 flag ioctls (linux really needs a generic |
| 347 | * interface for this). |
| 348 | */ |
| 349 | |
| 350 | /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support |
| 351 | * chattr/lsattr */ |
David Howells | 3669567 | 2006-08-29 19:06:16 +0100 | [diff] [blame] | 352 | #define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS |
| 353 | #define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | |
| 356 | /* |
Matthew Garrett | a051f71 | 2012-02-06 15:14:40 -0500 | [diff] [blame] | 357 | * hfs+-specific ioctl for making the filesystem bootable |
| 358 | */ |
| 359 | #define HFSPLUS_IOC_BLESS _IO('h', 0x80) |
| 360 | |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 361 | typedef int (*search_strategy_t)(struct hfs_bnode *, |
| 362 | struct hfs_find_data *, |
| 363 | int *, int *, int *); |
| 364 | |
Matthew Garrett | a051f71 | 2012-02-06 15:14:40 -0500 | [diff] [blame] | 365 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | * Functions in any *.c used in other files |
| 367 | */ |
| 368 | |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 369 | /* attributes.c */ |
Fabian Frederick | c11e614 | 2014-04-03 14:50:35 -0700 | [diff] [blame] | 370 | int __init hfsplus_create_attr_tree_cache(void); |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 371 | void hfsplus_destroy_attr_tree_cache(void); |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 372 | int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1, |
| 373 | const hfsplus_btree_key *k2); |
| 374 | int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key, |
| 375 | u32 cnid, const char *name); |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 376 | hfsplus_attr_entry *hfsplus_alloc_attr_entry(void); |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 377 | void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry); |
| 378 | int hfsplus_find_attr(struct super_block *sb, u32 cnid, const char *name, |
| 379 | struct hfs_find_data *fd); |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 380 | int hfsplus_attr_exists(struct inode *inode, const char *name); |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 381 | int hfsplus_create_attr(struct inode *inode, const char *name, |
| 382 | const void *value, size_t size); |
| 383 | int hfsplus_delete_attr(struct inode *inode, const char *name); |
Vyacheslav Dubeyko | 324ef39 | 2013-02-27 17:03:04 -0800 | [diff] [blame] | 384 | int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid); |
| 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | /* bitmap.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 387 | int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset, |
| 388 | u32 *max); |
| 389 | int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /* btree.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 392 | u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size, u64 sectors, |
| 393 | int file_id); |
| 394 | struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id); |
| 395 | void hfs_btree_close(struct hfs_btree *tree); |
| 396 | int hfs_btree_write(struct hfs_btree *tree); |
| 397 | struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree); |
| 398 | void hfs_bmap_free(struct hfs_bnode *node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
| 400 | /* bnode.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 401 | void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len); |
| 402 | u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off); |
| 403 | u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off); |
| 404 | void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off); |
| 405 | void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len); |
| 406 | void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data); |
| 407 | void hfs_bnode_clear(struct hfs_bnode *node, int off, int len); |
| 408 | void hfs_bnode_copy(struct hfs_bnode *dst_node, int dst, |
| 409 | struct hfs_bnode *src_node, int src, int len); |
| 410 | void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len); |
| 411 | void hfs_bnode_dump(struct hfs_bnode *node); |
| 412 | void hfs_bnode_unlink(struct hfs_bnode *node); |
| 413 | struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid); |
| 414 | void hfs_bnode_unhash(struct hfs_bnode *node); |
| 415 | struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num); |
| 416 | void hfs_bnode_free(struct hfs_bnode *node); |
| 417 | struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num); |
| 418 | void hfs_bnode_get(struct hfs_bnode *node); |
| 419 | void hfs_bnode_put(struct hfs_bnode *node); |
| 420 | bool hfs_bnode_need_zeroout(struct hfs_btree *tree); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | /* brec.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 423 | u16 hfs_brec_lenoff(struct hfs_bnode *node, u16 rec, u16 *off); |
| 424 | u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec); |
| 425 | int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len); |
| 426 | int hfs_brec_remove(struct hfs_find_data *fd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
| 428 | /* bfind.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 429 | int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd); |
| 430 | void hfs_find_exit(struct hfs_find_data *fd); |
| 431 | int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode, struct hfs_find_data *fd, |
| 432 | int *begin, int *end, int *cur_rec); |
| 433 | int hfs_find_rec_by_key(struct hfs_bnode *bnode, struct hfs_find_data *fd, |
| 434 | int *begin, int *end, int *cur_rec); |
| 435 | int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd, |
| 436 | search_strategy_t rec_found); |
| 437 | int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare); |
| 438 | int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len); |
| 439 | int hfs_brec_goto(struct hfs_find_data *fd, int cnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | |
| 441 | /* catalog.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 442 | int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1, |
| 443 | const hfsplus_btree_key *k2); |
| 444 | int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *k1, |
| 445 | const hfsplus_btree_key *k2); |
Sougata Santra | 89ac9b4 | 2014-12-18 16:17:12 -0800 | [diff] [blame] | 446 | int hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key, |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 447 | u32 parent, struct qstr *str); |
Sougata Santra | 89ac9b4 | 2014-12-18 16:17:12 -0800 | [diff] [blame] | 448 | void hfsplus_cat_build_key_with_cnid(struct super_block *sb, |
| 449 | hfsplus_btree_key *key, u32 parent); |
Christoph Hellwig | 90e6169 | 2010-10-14 09:54:39 -0400 | [diff] [blame] | 450 | void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms); |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 451 | int hfsplus_find_cat(struct super_block *sb, u32 cnid, |
| 452 | struct hfs_find_data *fd); |
| 453 | int hfsplus_create_cat(u32 cnid, struct inode *dir, struct qstr *str, |
| 454 | struct inode *inode); |
| 455 | int hfsplus_delete_cat(u32 cnid, struct inode *dir, struct qstr *str); |
| 456 | int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, struct qstr *src_name, |
| 457 | struct inode *dst_dir, struct qstr *dst_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
Adrian Bunk | 4b0a8da | 2008-04-29 00:58:52 -0700 | [diff] [blame] | 459 | /* dir.c */ |
| 460 | extern const struct inode_operations hfsplus_dir_inode_operations; |
| 461 | extern const struct file_operations hfsplus_dir_operations; |
| 462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | /* extents.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 464 | int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1, |
| 465 | const hfsplus_btree_key *k2); |
| 466 | int hfsplus_ext_write_extent(struct inode *inode); |
| 467 | int hfsplus_get_block(struct inode *inode, sector_t iblock, |
| 468 | struct buffer_head *bh_result, int create); |
| 469 | int hfsplus_free_fork(struct super_block *sb, u32 cnid, |
| 470 | struct hfsplus_fork_raw *fork, int type); |
| 471 | int hfsplus_file_extend(struct inode *inode, bool zeroout); |
| 472 | void hfsplus_file_truncate(struct inode *inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | /* inode.c */ |
Christoph Hellwig | f5e54d6 | 2006-06-28 04:26:44 -0700 | [diff] [blame] | 475 | extern const struct address_space_operations hfsplus_aops; |
| 476 | extern const struct address_space_operations hfsplus_btree_aops; |
Al Viro | e16404e | 2009-02-20 05:55:13 +0000 | [diff] [blame] | 477 | extern const struct dentry_operations hfsplus_dentry_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 479 | struct inode *hfsplus_new_inode(struct super_block *sb, umode_t mode); |
| 480 | void hfsplus_delete_inode(struct inode *inode); |
| 481 | void hfsplus_inode_read_fork(struct inode *inode, |
| 482 | struct hfsplus_fork_raw *fork); |
| 483 | void hfsplus_inode_write_fork(struct inode *inode, |
| 484 | struct hfsplus_fork_raw *fork); |
| 485 | int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd); |
| 486 | int hfsplus_cat_write_inode(struct inode *inode); |
Josef Bacik | 02c24a8 | 2011-07-16 20:44:56 -0400 | [diff] [blame] | 487 | int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end, |
| 488 | int datasync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | /* ioctl.c */ |
Arnd Bergmann | 7cc4bcc | 2010-04-27 16:24:20 +0200 | [diff] [blame] | 491 | long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | /* options.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 494 | void hfsplus_fill_defaults(struct hfsplus_sb_info *opts); |
Christoph Hellwig | 6f80dfe | 2010-11-07 23:01:17 +0100 | [diff] [blame] | 495 | int hfsplus_parse_options_remount(char *input, int *force); |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 496 | int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi); |
| 497 | int hfsplus_show_options(struct seq_file *seq, struct dentry *root); |
| 498 | |
| 499 | /* part_tbl.c */ |
| 500 | int hfs_part_find(struct super_block *sb, sector_t *part_start, |
| 501 | sector_t *part_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
David Howells | 6352539 | 2008-02-07 00:15:40 -0800 | [diff] [blame] | 503 | /* super.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 504 | struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino); |
Artem Bityutskiy | 9e6c582 | 2012-07-12 17:26:31 +0300 | [diff] [blame] | 505 | void hfsplus_mark_mdb_dirty(struct super_block *sb); |
David Howells | 6352539 | 2008-02-07 00:15:40 -0800 | [diff] [blame] | 506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | /* tables.c */ |
| 508 | extern u16 hfsplus_case_fold_table[]; |
| 509 | extern u16 hfsplus_decompose_table[]; |
| 510 | extern u16 hfsplus_compose_table[]; |
| 511 | |
| 512 | /* unicode.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 513 | int hfsplus_strcasecmp(const struct hfsplus_unistr *s1, |
| 514 | const struct hfsplus_unistr *s2); |
| 515 | int hfsplus_strcmp(const struct hfsplus_unistr *s1, |
| 516 | const struct hfsplus_unistr *s2); |
| 517 | int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr, |
| 518 | char *astr, int *len_p); |
| 519 | int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr, |
| 520 | int max_unistr_len, const char *astr, int len); |
Linus Torvalds | da53be1 | 2013-05-21 15:22:44 -0700 | [diff] [blame] | 521 | int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str); |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 522 | int hfsplus_compare_dentry(const struct dentry *parent, |
| 523 | const struct dentry *dentry, unsigned int len, |
| 524 | const char *str, const struct qstr *name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | /* wrapper.c */ |
Sergei Antonov | ffbc067 | 2014-06-06 14:36:30 -0700 | [diff] [blame] | 527 | int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf, |
| 528 | void **data, int rw); |
| 529 | int hfsplus_read_wrapper(struct super_block *sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | /* time macros */ |
| 532 | #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U) |
| 533 | #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U)) |
| 534 | |
| 535 | /* compatibility */ |
| 536 | #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) } |
| 537 | #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec) |
| 538 | #define hfsp_now2mt() __hfsp_ut2mt(get_seconds()) |
| 539 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | #endif |