]> git.ipfire.org Git - people/ms/linux.git/blame - fs/hfsplus/hfsplus_fs.h
Merge tag 'soc-fixes-6.0-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[people/ms/linux.git] / fs / hfsplus / hfsplus_fs.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2/*
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
d6142673
JP
14#ifdef pr_fmt
15#undef pr_fmt
16#endif
17
18#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
1da177e4 20#include <linux/fs.h>
895c23f8 21#include <linux/mutex.h>
1da177e4 22#include <linux/buffer_head.h>
6596528e 23#include <linux/blkdev.h>
1da177e4
LT
24#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
324ef39a 33#define DBG_ATTR_MOD 0x00000080
1da177e4 34
21f2296a
AS
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
1da177e4
LT
40#define DBG_MASK (0)
41
d6142673
JP
42#define hfs_dbg(flg, fmt, ...) \
43do { \
44 if (DBG_##flg & DBG_MASK) \
45 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
c2b3e1f7
JP
46} while (0)
47
d6142673
JP
48#define hfs_dbg_cont(flg, fmt, ...) \
49do { \
50 if (DBG_##flg & DBG_MASK) \
51 pr_cont(fmt, ##__VA_ARGS__); \
c2b3e1f7 52} while (0)
1da177e4
LT
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
2753cc28
AS
60typedef int (*btree_keycmp)(const hfsplus_btree_key *,
61 const hfsplus_btree_key *);
1da177e4
LT
62
63#define NODE_HASH_SIZE 256
64
324ef39a
VD
65/* B-tree mutex nested subclasses */
66enum hfsplus_btree_mutex_classes {
67 CATALOG_BTREE_MUTEX,
68 EXTENTS_BTREE_MUTEX,
69 ATTR_BTREE_MUTEX,
70};
71
1da177e4
LT
72/* An HFS+ BTree held in memory */
73struct 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
467c3d9c 92 struct mutex tree_lock;
1da177e4
LT
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
100struct page;
101
102/* An HFS+ BTree node in memory */
103struct 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;
5e01fdff 120 struct page *page[];
1da177e4
LT
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
95e0d7db
VD
129/*
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
1da177e4
LT
137/*
138 * HFS+ superblock info (built from Volume Header on disk)
139 */
140
141struct hfsplus_vh;
142struct hfs_btree;
143
144struct hfsplus_sb_info {
6596528e 145 void *s_vhdr_buf;
1da177e4 146 struct hfsplus_vh *s_vhdr;
6596528e 147 void *s_backup_vhdr_buf;
52399b17 148 struct hfsplus_vh *s_backup_vhdr;
1da177e4
LT
149 struct hfs_btree *ext_tree;
150 struct hfs_btree *cat_tree;
151 struct hfs_btree *attr_tree;
95e0d7db 152 atomic_t attr_tree_state;
1da177e4
LT
153 struct inode *alloc_file;
154 struct inode *hidden_dir;
155 struct nls_table *nls;
156
157 /* Runtime variables */
158 u32 blockoffset;
52399b17
CH
159 sector_t part_start;
160 sector_t sect_count;
1da177e4
LT
161 int fs_shift;
162
7ac9fb9c 163 /* immutable data from the volume header */
1da177e4
LT
164 u32 alloc_blksz;
165 int alloc_blksz_shift;
166 u32 total_blocks;
7ac9fb9c
CH
167 u32 data_clump_blocks, rsrc_clump_blocks;
168
169 /* mutable data from the volume header, protected by alloc_mutex */
1da177e4 170 u32 free_blocks;
7ac9fb9c
CH
171 struct mutex alloc_mutex;
172
173 /* mutable data from the volume header, protected by vh_mutex */
1da177e4
LT
174 u32 next_cnid;
175 u32 file_count;
176 u32 folder_count;
7ac9fb9c 177 struct mutex vh_mutex;
1da177e4
LT
178
179 /* Config options */
180 u32 creator;
181 u32 type;
182
183 umode_t umask;
16525e3f
EB
184 kuid_t uid;
185 kgid_t gid;
1da177e4
LT
186
187 int part, session;
1da177e4 188 unsigned long flags;
9e6c5829
AB
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 */
1da177e4
LT
193};
194
84adede3
CH
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
34a2d313 200#define HFSPLUS_SB_NOBARRIER 5
1da177e4 201
e3494705
CH
202static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
203{
204 return sb->s_fs_info;
205}
1da177e4
LT
206
207
208struct hfsplus_inode_info {
1da177e4
LT
209 atomic_t opencnt;
210
7fcc99f4
CH
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;
b33b7921 221 unsigned int extent_state;
7fcc99f4 222 struct mutex extents_lock;
1da177e4 223
7fcc99f4
CH
224 /*
225 * Immutable data.
226 */
227 struct inode *rsrc_inode;
9a4cad95 228 __be32 create_date;
f6089ff8
CH
229
230 /*
231 * Protected by sbi->vh_mutex.
232 */
233 u32 linkid;
1da177e4 234
b33b7921
CH
235 /*
236 * Accessed using atomic bitops.
237 */
238 unsigned long flags;
239
7fcc99f4
CH
240 /*
241 * Protected by i_mutex.
242 */
243 sector_t fs_blocks;
722c55d1 244 u8 userflags; /* BSD user file flags */
d7d673a5 245 u32 subfolders; /* Subfolder count (HFSX only) */
1da177e4 246 struct list_head open_dir_list;
323ee8fc 247 spinlock_t open_dir_lock;
1da177e4 248 loff_t phys_size;
7fcc99f4 249
1da177e4
LT
250 struct inode vfs_inode;
251};
252
b33b7921
CH
253#define HFSPLUS_EXT_DIRTY 0x0001
254#define HFSPLUS_EXT_NEW 0x0002
255
256#define HFSPLUS_I_RSRC 0 /* represents a resource fork */
e3494705
CH
257#define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
258#define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
259#define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
324ef39a 260#define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
1da177e4 261
b33b7921
CH
262#define HFSPLUS_IS_RSRC(inode) \
263 test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
1da177e4 264
e3494705
CH
265static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
266{
db6172c4 267 return container_of(inode, struct hfsplus_inode_info, vfs_inode);
e3494705 268}
1da177e4 269
e3494705
CH
270/*
271 * Mark an inode dirty, and also mark the btree in which the
272 * specific type of metadata is stored.
273 * For data or metadata that gets written back by into the catalog btree
274 * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
275 */
276static inline void hfsplus_mark_inode_dirty(struct inode *inode,
277 unsigned int flag)
278{
279 set_bit(flag, &HFSPLUS_I(inode)->flags);
280 mark_inode_dirty(inode);
281}
1da177e4
LT
282
283struct hfs_find_data {
284 /* filled by caller */
285 hfsplus_btree_key *search_key;
286 hfsplus_btree_key *key;
287 /* filled by find */
288 struct hfs_btree *tree;
289 struct hfs_bnode *bnode;
290 /* filled by findrec */
291 int record;
292 int keyoffset, keylength;
293 int entryoffset, entrylength;
294};
295
296struct hfsplus_readdir_data {
297 struct list_head list;
298 struct file *file;
299 struct hfsplus_cat_key key;
300};
301
6596528e
SF
302/*
303 * Find minimum acceptible I/O size for an hfsplus sb.
304 */
305static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
306{
307 return max_t(unsigned short, bdev_logical_block_size(sb->s_bdev),
308 HFSPLUS_SECTOR_SIZE);
309}
310
1da177e4
LT
311#define hfs_btree_open hfsplus_btree_open
312#define hfs_btree_close hfsplus_btree_close
313#define hfs_btree_write hfsplus_btree_write
d92915c3 314#define hfs_bmap_reserve hfsplus_bmap_reserve
1da177e4
LT
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
324ef39a 341#define __hfs_brec_find __hfsplus_brec_find
1da177e4
LT
342#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
a051f71c
MG
347/*
348 * hfs+-specific ioctl for making the filesystem bootable
349 */
350#define HFSPLUS_IOC_BLESS _IO('h', 0x80)
351
324ef39a
VD
352typedef int (*search_strategy_t)(struct hfs_bnode *,
353 struct hfs_find_data *,
354 int *, int *, int *);
355
1da177e4
LT
356/*
357 * Functions in any *.c used in other files
358 */
359
324ef39a 360/* attributes.c */
c11e614d 361int __init hfsplus_create_attr_tree_cache(void);
324ef39a 362void hfsplus_destroy_attr_tree_cache(void);
ffbc0671
SA
363int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,
364 const hfsplus_btree_key *k2);
365int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,
366 u32 cnid, const char *name);
324ef39a 367hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);
ffbc0671
SA
368void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry);
369int hfsplus_find_attr(struct super_block *sb, u32 cnid, const char *name,
370 struct hfs_find_data *fd);
324ef39a 371int hfsplus_attr_exists(struct inode *inode, const char *name);
ffbc0671
SA
372int hfsplus_create_attr(struct inode *inode, const char *name,
373 const void *value, size_t size);
374int hfsplus_delete_attr(struct inode *inode, const char *name);
324ef39a
VD
375int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
376
1da177e4 377/* bitmap.c */
ffbc0671
SA
378int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset,
379 u32 *max);
380int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count);
1da177e4
LT
381
382/* btree.c */
ffbc0671
SA
383u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size, u64 sectors,
384 int file_id);
385struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id);
386void hfs_btree_close(struct hfs_btree *tree);
387int hfs_btree_write(struct hfs_btree *tree);
d92915c3 388int hfs_bmap_reserve(struct hfs_btree *tree, int rsvd_nodes);
ffbc0671
SA
389struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree);
390void hfs_bmap_free(struct hfs_bnode *node);
1da177e4
LT
391
392/* bnode.c */
ffbc0671
SA
393void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len);
394u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off);
395u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off);
396void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off);
397void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len);
398void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data);
399void hfs_bnode_clear(struct hfs_bnode *node, int off, int len);
400void hfs_bnode_copy(struct hfs_bnode *dst_node, int dst,
401 struct hfs_bnode *src_node, int src, int len);
402void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len);
403void hfs_bnode_dump(struct hfs_bnode *node);
404void hfs_bnode_unlink(struct hfs_bnode *node);
405struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid);
406void hfs_bnode_unhash(struct hfs_bnode *node);
407struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num);
408void hfs_bnode_free(struct hfs_bnode *node);
409struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num);
410void hfs_bnode_get(struct hfs_bnode *node);
411void hfs_bnode_put(struct hfs_bnode *node);
412bool hfs_bnode_need_zeroout(struct hfs_btree *tree);
1da177e4
LT
413
414/* brec.c */
ffbc0671
SA
415u16 hfs_brec_lenoff(struct hfs_bnode *node, u16 rec, u16 *off);
416u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec);
417int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len);
418int hfs_brec_remove(struct hfs_find_data *fd);
1da177e4
LT
419
420/* bfind.c */
ffbc0671
SA
421int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd);
422void hfs_find_exit(struct hfs_find_data *fd);
423int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode, struct hfs_find_data *fd,
424 int *begin, int *end, int *cur_rec);
425int hfs_find_rec_by_key(struct hfs_bnode *bnode, struct hfs_find_data *fd,
426 int *begin, int *end, int *cur_rec);
427int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd,
428 search_strategy_t rec_found);
429int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare);
430int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len);
431int hfs_brec_goto(struct hfs_find_data *fd, int cnt);
1da177e4
LT
432
433/* catalog.c */
ffbc0671
SA
434int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1,
435 const hfsplus_btree_key *k2);
436int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *k1,
437 const hfsplus_btree_key *k2);
89ac9b4d 438int hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key,
b5cce521 439 u32 parent, const struct qstr *str);
89ac9b4d
SS
440void hfsplus_cat_build_key_with_cnid(struct super_block *sb,
441 hfsplus_btree_key *key, u32 parent);
90e61690 442void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
ffbc0671
SA
443int hfsplus_find_cat(struct super_block *sb, u32 cnid,
444 struct hfs_find_data *fd);
b5cce521 445int hfsplus_create_cat(u32 cnid, struct inode *dir, const struct qstr *str,
ffbc0671 446 struct inode *inode);
b5cce521
AV
447int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str);
448int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_name,
449 struct inode *dst_dir, const struct qstr *dst_name);
1da177e4 450
4b0a8da7
AB
451/* dir.c */
452extern const struct inode_operations hfsplus_dir_inode_operations;
453extern const struct file_operations hfsplus_dir_operations;
454
1da177e4 455/* extents.c */
ffbc0671
SA
456int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
457 const hfsplus_btree_key *k2);
458int hfsplus_ext_write_extent(struct inode *inode);
459int hfsplus_get_block(struct inode *inode, sector_t iblock,
460 struct buffer_head *bh_result, int create);
461int hfsplus_free_fork(struct super_block *sb, u32 cnid,
462 struct hfsplus_fork_raw *fork, int type);
463int hfsplus_file_extend(struct inode *inode, bool zeroout);
464void hfsplus_file_truncate(struct inode *inode);
1da177e4
LT
465
466/* inode.c */
f5e54d6e
CH
467extern const struct address_space_operations hfsplus_aops;
468extern const struct address_space_operations hfsplus_btree_aops;
e16404ed 469extern const struct dentry_operations hfsplus_dentry_operations;
1da177e4 470
07a31f72
MWO
471int hfsplus_write_begin(struct file *file, struct address_space *mapping,
472 loff_t pos, unsigned len, struct page **pagep, void **fsdata);
b0cd38c7
EF
473struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
474 umode_t mode);
ffbc0671
SA
475void hfsplus_delete_inode(struct inode *inode);
476void hfsplus_inode_read_fork(struct inode *inode,
477 struct hfsplus_fork_raw *fork);
478void hfsplus_inode_write_fork(struct inode *inode,
479 struct hfsplus_fork_raw *fork);
480int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd);
481int hfsplus_cat_write_inode(struct inode *inode);
549c7297
CB
482int hfsplus_getattr(struct user_namespace *mnt_userns, const struct path *path,
483 struct kstat *stat, u32 request_mask,
484 unsigned int query_flags);
02c24a82
JB
485int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
486 int datasync);
9cbae748
MS
487int hfsplus_fileattr_get(struct dentry *dentry, struct fileattr *fa);
488int hfsplus_fileattr_set(struct user_namespace *mnt_userns,
489 struct dentry *dentry, struct fileattr *fa);
1da177e4
LT
490
491/* ioctl.c */
7cc4bcc6 492long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
1da177e4
LT
493
494/* options.c */
ffbc0671 495void hfsplus_fill_defaults(struct hfsplus_sb_info *opts);
6f80dfe5 496int hfsplus_parse_options_remount(char *input, int *force);
ffbc0671
SA
497int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi);
498int hfsplus_show_options(struct seq_file *seq, struct dentry *root);
499
500/* part_tbl.c */
501int hfs_part_find(struct super_block *sb, sector_t *part_start,
502 sector_t *part_size);
1da177e4 503
63525391 504/* super.c */
ffbc0671 505struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino);
9e6c5829 506void hfsplus_mark_mdb_dirty(struct super_block *sb);
63525391 507
1da177e4
LT
508/* tables.c */
509extern u16 hfsplus_case_fold_table[];
510extern u16 hfsplus_decompose_table[];
511extern u16 hfsplus_compose_table[];
512
513/* unicode.c */
ffbc0671
SA
514int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,
515 const struct hfsplus_unistr *s2);
516int hfsplus_strcmp(const struct hfsplus_unistr *s1,
517 const struct hfsplus_unistr *s2);
518int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr,
519 char *astr, int *len_p);
520int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
521 int max_unistr_len, const char *astr, int len);
da53be12 522int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str);
6fa67e70 523int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len,
ffbc0671 524 const char *str, const struct qstr *name);
1da177e4
LT
525
526/* wrapper.c */
ffbc0671 527int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf,
c85f9992 528 void **data, blk_opf_t opf);
ffbc0671 529int hfsplus_read_wrapper(struct super_block *sb);
1da177e4 530
4ddfc3dc
AB
531/*
532 * time helpers: convert between 1904-base and 1970-base timestamps
533 *
534 * HFS+ implementations are highly inconsistent, this one matches the
535 * traditional behavior of 64-bit Linux, giving the most useful
536 * time range between 1970 and 2106, by treating any on-disk timestamp
537 * under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
538 */
539#define HFSPLUS_UTC_OFFSET 2082844800U
540
541static inline time64_t __hfsp_mt2ut(__be32 mt)
542{
543 time64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET);
544
545 return ut;
546}
547
548static inline __be32 __hfsp_ut2mt(time64_t ut)
549{
550 return cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET);
551}
1da177e4
LT
552
553/* compatibility */
4ddfc3dc 554#define hfsp_mt2ut(t) (struct timespec64){ .tv_sec = __hfsp_mt2ut(t) }
1da177e4 555#define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
4ddfc3dc 556#define hfsp_now2mt() __hfsp_ut2mt(ktime_get_real_seconds())
1da177e4 557
1da177e4 558#endif