blob: a015044daa053a3b55fef920d235483e2e46a3e4 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * linux/include/linux/hfsplus_fs.h
4 *
5 * Copyright (C) 1999
6 * Brad Boyer (flar@pants.nu)
7 * (C) 2003 Ardis Technologies <roman@ardistech.com>
8 *
9 */
10
11#ifndef _LINUX_HFSPLUS_FS_H
12#define _LINUX_HFSPLUS_FS_H
13
Joe Perchesd6142672013-04-30 15:27:55 -070014#ifdef pr_fmt
15#undef pr_fmt
16#endif
17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/fs.h>
Matthias Kaehlcke895c23f2008-07-25 01:46:36 -070021#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/buffer_head.h>
Seth Forshee65965282011-07-18 08:06:23 -070023#include <linux/blkdev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "hfsplus_raw.h"
25
26#define DBG_BNODE_REFS 0x00000001
27#define DBG_BNODE_MOD 0x00000002
28#define DBG_CAT_MOD 0x00000004
29#define DBG_INODE 0x00000008
30#define DBG_SUPER 0x00000010
31#define DBG_EXTENT 0x00000020
32#define DBG_BITMAP 0x00000040
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -080033#define DBG_ATTR_MOD 0x00000080
Vyacheslav Dubeyko2c920572013-09-11 14:24:28 -070034#define DBG_ACL_MOD 0x00000100
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Anton Salikhmetov21f22962010-12-16 18:08:39 +020036#if 0
37#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
38#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
39#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
40#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#define DBG_MASK (0)
42
Joe Perchesd6142672013-04-30 15:27:55 -070043#define hfs_dbg(flg, fmt, ...) \
44do { \
45 if (DBG_##flg & DBG_MASK) \
46 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
Joe Perchesc2b3e1f2013-04-30 15:27:54 -070047} while (0)
48
Joe Perchesd6142672013-04-30 15:27:55 -070049#define hfs_dbg_cont(flg, fmt, ...) \
50do { \
51 if (DBG_##flg & DBG_MASK) \
52 pr_cont(fmt, ##__VA_ARGS__); \
Joe Perchesc2b3e1f2013-04-30 15:27:54 -070053} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/* Runtime config options */
56#define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
57
58#define HFSPLUS_TYPE_DATA 0x00
59#define HFSPLUS_TYPE_RSRC 0xFF
60
Anton Salikhmetov2753cc22010-12-16 18:08:38 +020061typedef int (*btree_keycmp)(const hfsplus_btree_key *,
62 const hfsplus_btree_key *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#define NODE_HASH_SIZE 256
65
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -080066/* B-tree mutex nested subclasses */
67enum hfsplus_btree_mutex_classes {
68 CATALOG_BTREE_MUTEX,
69 EXTENTS_BTREE_MUTEX,
70 ATTR_BTREE_MUTEX,
71};
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* An HFS+ BTree held in memory */
74struct hfs_btree {
75 struct super_block *sb;
76 struct inode *inode;
77 btree_keycmp keycmp;
78
79 u32 cnid;
80 u32 root;
81 u32 leaf_count;
82 u32 leaf_head;
83 u32 leaf_tail;
84 u32 node_count;
85 u32 free_nodes;
86 u32 attributes;
87
88 unsigned int node_size;
89 unsigned int node_size_shift;
90 unsigned int max_key_len;
91 unsigned int depth;
92
Thomas Gleixner467c3d92010-10-01 05:46:52 +020093 struct mutex tree_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
95 unsigned int pages_per_bnode;
96 spinlock_t hash_lock;
97 struct hfs_bnode *node_hash[NODE_HASH_SIZE];
98 int node_hash_cnt;
99};
100
101struct page;
102
103/* An HFS+ BTree node in memory */
104struct hfs_bnode {
105 struct hfs_btree *tree;
106
107 u32 prev;
108 u32 this;
109 u32 next;
110 u32 parent;
111
112 u16 num_recs;
113 u8 type;
114 u8 height;
115
116 struct hfs_bnode *next_hash;
117 unsigned long flags;
118 wait_queue_head_t lock_wq;
119 atomic_t refcnt;
120 unsigned int page_offset;
121 struct page *page[0];
122};
123
124#define HFS_BNODE_LOCK 0
125#define HFS_BNODE_ERROR 1
126#define HFS_BNODE_NEW 2
127#define HFS_BNODE_DIRTY 3
128#define HFS_BNODE_DELETED 4
129
130/*
Vyacheslav Dubeyko95e0d7d2013-11-12 15:11:09 -0800131 * Attributes file states
132 */
133#define HFSPLUS_EMPTY_ATTR_TREE 0
134#define HFSPLUS_CREATING_ATTR_TREE 1
135#define HFSPLUS_VALID_ATTR_TREE 2
136#define HFSPLUS_FAILED_ATTR_TREE 3
137
138/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 * HFS+ superblock info (built from Volume Header on disk)
140 */
141
142struct hfsplus_vh;
143struct hfs_btree;
144
145struct hfsplus_sb_info {
Seth Forshee65965282011-07-18 08:06:23 -0700146 void *s_vhdr_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 struct hfsplus_vh *s_vhdr;
Seth Forshee65965282011-07-18 08:06:23 -0700148 void *s_backup_vhdr_buf;
Christoph Hellwig52399b12010-11-23 14:37:47 +0100149 struct hfsplus_vh *s_backup_vhdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 struct hfs_btree *ext_tree;
151 struct hfs_btree *cat_tree;
152 struct hfs_btree *attr_tree;
Vyacheslav Dubeyko95e0d7d2013-11-12 15:11:09 -0800153 atomic_t attr_tree_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 struct inode *alloc_file;
155 struct inode *hidden_dir;
156 struct nls_table *nls;
157
158 /* Runtime variables */
159 u32 blockoffset;
Christoph Hellwig52399b12010-11-23 14:37:47 +0100160 sector_t part_start;
161 sector_t sect_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 int fs_shift;
163
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200164 /* immutable data from the volume header */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 u32 alloc_blksz;
166 int alloc_blksz_shift;
167 u32 total_blocks;
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200168 u32 data_clump_blocks, rsrc_clump_blocks;
169
170 /* mutable data from the volume header, protected by alloc_mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 u32 free_blocks;
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200172 struct mutex alloc_mutex;
173
174 /* mutable data from the volume header, protected by vh_mutex */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 u32 next_cnid;
176 u32 file_count;
177 u32 folder_count;
Christoph Hellwig7ac9fb92010-10-01 05:45:08 +0200178 struct mutex vh_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 /* Config options */
181 u32 creator;
182 u32 type;
183
184 umode_t umask;
Eric W. Biederman16525e32012-02-07 16:27:17 -0800185 kuid_t uid;
186 kgid_t gid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188 int part, session;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 unsigned long flags;
Artem Bityutskiy9e6c5822012-07-12 17:26:31 +0300190
191 int work_queued; /* non-zero delayed work is queued */
192 struct delayed_work sync_work; /* FS sync delayed work */
193 spinlock_t work_lock; /* protects sync_work and work_queued */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194};
195
Christoph Hellwig84adede2010-10-01 05:45:20 +0200196#define HFSPLUS_SB_WRITEBACKUP 0
197#define HFSPLUS_SB_NODECOMPOSE 1
198#define HFSPLUS_SB_FORCE 2
199#define HFSPLUS_SB_HFSX 3
200#define HFSPLUS_SB_CASEFOLD 4
Christoph Hellwig34a2d312010-11-23 14:38:21 +0100201#define HFSPLUS_SB_NOBARRIER 5
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Christoph Hellwige3494702010-11-23 14:38:15 +0100203static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
204{
205 return sb->s_fs_info;
206}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208
209struct hfsplus_inode_info {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 atomic_t opencnt;
211
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200212 /*
213 * Extent allocation information, protected by extents_lock.
214 */
215 u32 first_blocks;
216 u32 clump_blocks;
217 u32 alloc_blocks;
218 u32 cached_start;
219 u32 cached_blocks;
220 hfsplus_extent_rec first_extents;
221 hfsplus_extent_rec cached_extents;
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100222 unsigned int extent_state;
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200223 struct mutex extents_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200225 /*
226 * Immutable data.
227 */
228 struct inode *rsrc_inode;
Roman Zippel9a4cad92006-01-18 17:43:09 -0800229 __be32 create_date;
Christoph Hellwigf6089ff2010-10-14 09:54:28 -0400230
231 /*
232 * Protected by sbi->vh_mutex.
233 */
234 u32 linkid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200236 /*
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100237 * Accessed using atomic bitops.
238 */
239 unsigned long flags;
240
241 /*
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200242 * Protected by i_mutex.
243 */
244 sector_t fs_blocks;
Christoph Hellwig722c55d2010-10-14 09:54:33 -0400245 u8 userflags; /* BSD user file flags */
Sergei Antonovd7d673a2014-03-10 15:49:51 -0700246 u32 subfolders; /* Subfolder count (HFSX only) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 struct list_head open_dir_list;
Al Viro323ee8f2016-05-12 20:02:09 -0400248 spinlock_t open_dir_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 loff_t phys_size;
Christoph Hellwig7fcc99f2010-10-01 05:46:31 +0200250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 struct inode vfs_inode;
252};
253
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100254#define HFSPLUS_EXT_DIRTY 0x0001
255#define HFSPLUS_EXT_NEW 0x0002
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100257#define HFSPLUS_I_RSRC 0 /* represents a resource fork */
Christoph Hellwige3494702010-11-23 14:38:15 +0100258#define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
259#define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
260#define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800261#define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
Christoph Hellwigb33b7922010-11-23 14:38:13 +0100262
263#define HFSPLUS_IS_RSRC(inode) \
264 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Christoph Hellwige3494702010-11-23 14:38:15 +0100266static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
267{
Rasmus Villemoesdb6172c2015-03-19 12:28:04 +0100268 return container_of(inode, struct hfsplus_inode_info, vfs_inode);
Christoph Hellwige3494702010-11-23 14:38:15 +0100269}
270
271/*
272 * Mark an inode dirty, and also mark the btree in which the
273 * specific type of metadata is stored.
274 * For data or metadata that gets written back by into the catalog btree
275 * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
276 */
277static inline void hfsplus_mark_inode_dirty(struct inode *inode,
278 unsigned int flag)
279{
280 set_bit(flag, &HFSPLUS_I(inode)->flags);
281 mark_inode_dirty(inode);
282}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284struct hfs_find_data {
285 /* filled by caller */
286 hfsplus_btree_key *search_key;
287 hfsplus_btree_key *key;
288 /* filled by find */
289 struct hfs_btree *tree;
290 struct hfs_bnode *bnode;
291 /* filled by findrec */
292 int record;
293 int keyoffset, keylength;
294 int entryoffset, entrylength;
295};
296
297struct hfsplus_readdir_data {
298 struct list_head list;
299 struct file *file;
300 struct hfsplus_cat_key key;
301};
302
Seth Forshee65965282011-07-18 08:06:23 -0700303/*
304 * Find minimum acceptible I/O size for an hfsplus sb.
305 */
306static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
307{
308 return max_t(unsigned short, bdev_logical_block_size(sb->s_bdev),
309 HFSPLUS_SECTOR_SIZE);
310}
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312#define hfs_btree_open hfsplus_btree_open
313#define hfs_btree_close hfsplus_btree_close
314#define hfs_btree_write hfsplus_btree_write
315#define hfs_bmap_alloc hfsplus_bmap_alloc
316#define hfs_bmap_free hfsplus_bmap_free
317#define hfs_bnode_read hfsplus_bnode_read
318#define hfs_bnode_read_u16 hfsplus_bnode_read_u16
319#define hfs_bnode_read_u8 hfsplus_bnode_read_u8
320#define hfs_bnode_read_key hfsplus_bnode_read_key
321#define hfs_bnode_write hfsplus_bnode_write
322#define hfs_bnode_write_u16 hfsplus_bnode_write_u16
323#define hfs_bnode_clear hfsplus_bnode_clear
324#define hfs_bnode_copy hfsplus_bnode_copy
325#define hfs_bnode_move hfsplus_bnode_move
326#define hfs_bnode_dump hfsplus_bnode_dump
327#define hfs_bnode_unlink hfsplus_bnode_unlink
328#define hfs_bnode_findhash hfsplus_bnode_findhash
329#define hfs_bnode_find hfsplus_bnode_find
330#define hfs_bnode_unhash hfsplus_bnode_unhash
331#define hfs_bnode_free hfsplus_bnode_free
332#define hfs_bnode_create hfsplus_bnode_create
333#define hfs_bnode_get hfsplus_bnode_get
334#define hfs_bnode_put hfsplus_bnode_put
335#define hfs_brec_lenoff hfsplus_brec_lenoff
336#define hfs_brec_keylen hfsplus_brec_keylen
337#define hfs_brec_insert hfsplus_brec_insert
338#define hfs_brec_remove hfsplus_brec_remove
339#define hfs_find_init hfsplus_find_init
340#define hfs_find_exit hfsplus_find_exit
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800341#define __hfs_brec_find __hfsplus_brec_find
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342#define hfs_brec_find hfsplus_brec_find
343#define hfs_brec_read hfsplus_brec_read
344#define hfs_brec_goto hfsplus_brec_goto
345#define hfs_part_find hfsplus_part_find
346
347/*
348 * definitions for ext2 flag ioctls (linux really needs a generic
349 * interface for this).
350 */
351
352/* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
353 * chattr/lsattr */
David Howells36695672006-08-29 19:06:16 +0100354#define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
355#define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357
358/*
Matthew Garretta051f712012-02-06 15:14:40 -0500359 * hfs+-specific ioctl for making the filesystem bootable
360 */
361#define HFSPLUS_IOC_BLESS _IO('h', 0x80)
362
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800363typedef int (*search_strategy_t)(struct hfs_bnode *,
364 struct hfs_find_data *,
365 int *, int *, int *);
366
Matthew Garretta051f712012-02-06 15:14:40 -0500367/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 * Functions in any *.c used in other files
369 */
370
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800371/* attributes.c */
Fabian Frederickc11e6142014-04-03 14:50:35 -0700372int __init hfsplus_create_attr_tree_cache(void);
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800373void hfsplus_destroy_attr_tree_cache(void);
Sergei Antonovffbc0672014-06-06 14:36:30 -0700374int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,
375 const hfsplus_btree_key *k2);
376int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,
377 u32 cnid, const char *name);
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800378hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);
Sergei Antonovffbc0672014-06-06 14:36:30 -0700379void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry);
380int hfsplus_find_attr(struct super_block *sb, u32 cnid, const char *name,
381 struct hfs_find_data *fd);
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800382int hfsplus_attr_exists(struct inode *inode, const char *name);
Sergei Antonovffbc0672014-06-06 14:36:30 -0700383int hfsplus_create_attr(struct inode *inode, const char *name,
384 const void *value, size_t size);
385int hfsplus_delete_attr(struct inode *inode, const char *name);
Vyacheslav Dubeyko324ef392013-02-27 17:03:04 -0800386int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/* bitmap.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700389int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset,
390 u32 *max);
391int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393/* btree.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700394u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size, u64 sectors,
395 int file_id);
396struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id);
397void hfs_btree_close(struct hfs_btree *tree);
398int hfs_btree_write(struct hfs_btree *tree);
399struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree);
400void hfs_bmap_free(struct hfs_bnode *node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402/* bnode.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700403void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len);
404u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off);
405u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off);
406void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off);
407void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len);
408void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data);
409void hfs_bnode_clear(struct hfs_bnode *node, int off, int len);
410void hfs_bnode_copy(struct hfs_bnode *dst_node, int dst,
411 struct hfs_bnode *src_node, int src, int len);
412void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len);
413void hfs_bnode_dump(struct hfs_bnode *node);
414void hfs_bnode_unlink(struct hfs_bnode *node);
415struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid);
416void hfs_bnode_unhash(struct hfs_bnode *node);
417struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num);
418void hfs_bnode_free(struct hfs_bnode *node);
419struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num);
420void hfs_bnode_get(struct hfs_bnode *node);
421void hfs_bnode_put(struct hfs_bnode *node);
422bool hfs_bnode_need_zeroout(struct hfs_btree *tree);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424/* brec.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700425u16 hfs_brec_lenoff(struct hfs_bnode *node, u16 rec, u16 *off);
426u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec);
427int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len);
428int hfs_brec_remove(struct hfs_find_data *fd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430/* bfind.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700431int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd);
432void hfs_find_exit(struct hfs_find_data *fd);
433int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode, struct hfs_find_data *fd,
434 int *begin, int *end, int *cur_rec);
435int hfs_find_rec_by_key(struct hfs_bnode *bnode, struct hfs_find_data *fd,
436 int *begin, int *end, int *cur_rec);
437int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd,
438 search_strategy_t rec_found);
439int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare);
440int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len);
441int hfs_brec_goto(struct hfs_find_data *fd, int cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
443/* catalog.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700444int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1,
445 const hfsplus_btree_key *k2);
446int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *k1,
447 const hfsplus_btree_key *k2);
Sougata Santra89ac9b42014-12-18 16:17:12 -0800448int hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key,
Al Virob5cce522016-07-20 16:17:26 -0400449 u32 parent, const struct qstr *str);
Sougata Santra89ac9b42014-12-18 16:17:12 -0800450void hfsplus_cat_build_key_with_cnid(struct super_block *sb,
451 hfsplus_btree_key *key, u32 parent);
Christoph Hellwig90e61692010-10-14 09:54:39 -0400452void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
Sergei Antonovffbc0672014-06-06 14:36:30 -0700453int hfsplus_find_cat(struct super_block *sb, u32 cnid,
454 struct hfs_find_data *fd);
Al Virob5cce522016-07-20 16:17:26 -0400455int hfsplus_create_cat(u32 cnid, struct inode *dir, const struct qstr *str,
Sergei Antonovffbc0672014-06-06 14:36:30 -0700456 struct inode *inode);
Al Virob5cce522016-07-20 16:17:26 -0400457int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str);
458int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_name,
459 struct inode *dst_dir, const struct qstr *dst_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Adrian Bunk4b0a8da2008-04-29 00:58:52 -0700461/* dir.c */
462extern const struct inode_operations hfsplus_dir_inode_operations;
463extern const struct file_operations hfsplus_dir_operations;
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465/* extents.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700466int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
467 const hfsplus_btree_key *k2);
468int hfsplus_ext_write_extent(struct inode *inode);
469int hfsplus_get_block(struct inode *inode, sector_t iblock,
470 struct buffer_head *bh_result, int create);
471int hfsplus_free_fork(struct super_block *sb, u32 cnid,
472 struct hfsplus_fork_raw *fork, int type);
473int hfsplus_file_extend(struct inode *inode, bool zeroout);
474void hfsplus_file_truncate(struct inode *inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476/* inode.c */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700477extern const struct address_space_operations hfsplus_aops;
478extern const struct address_space_operations hfsplus_btree_aops;
Al Viroe16404e2009-02-20 05:55:13 +0000479extern const struct dentry_operations hfsplus_dentry_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Sergei Antonovffbc0672014-06-06 14:36:30 -0700481struct inode *hfsplus_new_inode(struct super_block *sb, umode_t mode);
482void hfsplus_delete_inode(struct inode *inode);
483void hfsplus_inode_read_fork(struct inode *inode,
484 struct hfsplus_fork_raw *fork);
485void hfsplus_inode_write_fork(struct inode *inode,
486 struct hfsplus_fork_raw *fork);
487int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd);
488int hfsplus_cat_write_inode(struct inode *inode);
Josef Bacik02c24a82011-07-16 20:44:56 -0400489int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
490 int datasync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
492/* ioctl.c */
Arnd Bergmann7cc4bcc2010-04-27 16:24:20 +0200493long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495/* options.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700496void hfsplus_fill_defaults(struct hfsplus_sb_info *opts);
Christoph Hellwig6f80dfe2010-11-07 23:01:17 +0100497int hfsplus_parse_options_remount(char *input, int *force);
Sergei Antonovffbc0672014-06-06 14:36:30 -0700498int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi);
499int hfsplus_show_options(struct seq_file *seq, struct dentry *root);
500
501/* part_tbl.c */
502int hfs_part_find(struct super_block *sb, sector_t *part_start,
503 sector_t *part_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
David Howells63525392008-02-07 00:15:40 -0800505/* super.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700506struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino);
Artem Bityutskiy9e6c5822012-07-12 17:26:31 +0300507void hfsplus_mark_mdb_dirty(struct super_block *sb);
David Howells63525392008-02-07 00:15:40 -0800508
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509/* tables.c */
510extern u16 hfsplus_case_fold_table[];
511extern u16 hfsplus_decompose_table[];
512extern u16 hfsplus_compose_table[];
513
514/* unicode.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700515int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,
516 const struct hfsplus_unistr *s2);
517int hfsplus_strcmp(const struct hfsplus_unistr *s1,
518 const struct hfsplus_unistr *s2);
519int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr,
520 char *astr, int *len_p);
521int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
522 int max_unistr_len, const char *astr, int len);
Linus Torvaldsda53be12013-05-21 15:22:44 -0700523int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str);
Al Viro6fa67e72016-07-31 16:37:25 -0400524int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len,
Sergei Antonovffbc0672014-06-06 14:36:30 -0700525 const char *str, const struct qstr *name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
527/* wrapper.c */
Sergei Antonovffbc0672014-06-06 14:36:30 -0700528int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf,
Mike Christie67ed2592016-06-05 14:31:58 -0500529 void **data, int op, int op_flags);
Sergei Antonovffbc0672014-06-06 14:36:30 -0700530int hfsplus_read_wrapper(struct super_block *sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532/* time macros */
533#define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
534#define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
535
536/* compatibility */
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())
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541#endif