1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * linux/include/linux/hfsplus_fs.h
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Copyright (C) 1999
61da177e4SLinus Torvalds * Brad Boyer (flar@pants.nu)
71da177e4SLinus Torvalds * (C) 2003 Ardis Technologies <roman@ardistech.com>
81da177e4SLinus Torvalds *
91da177e4SLinus Torvalds */
101da177e4SLinus Torvalds
111da177e4SLinus Torvalds #ifndef _LINUX_HFSPLUS_FS_H
121da177e4SLinus Torvalds #define _LINUX_HFSPLUS_FS_H
131da177e4SLinus Torvalds
14d6142673SJoe Perches #ifdef pr_fmt
15d6142673SJoe Perches #undef pr_fmt
16d6142673SJoe Perches #endif
17d6142673SJoe Perches
18d6142673SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19d6142673SJoe Perches
201da177e4SLinus Torvalds #include <linux/fs.h>
21895c23f8SMatthias Kaehlcke #include <linux/mutex.h>
221da177e4SLinus Torvalds #include <linux/buffer_head.h>
236596528eSSeth Forshee #include <linux/blkdev.h>
241da177e4SLinus Torvalds #include "hfsplus_raw.h"
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds #define DBG_BNODE_REFS 0x00000001
271da177e4SLinus Torvalds #define DBG_BNODE_MOD 0x00000002
281da177e4SLinus Torvalds #define DBG_CAT_MOD 0x00000004
291da177e4SLinus Torvalds #define DBG_INODE 0x00000008
301da177e4SLinus Torvalds #define DBG_SUPER 0x00000010
311da177e4SLinus Torvalds #define DBG_EXTENT 0x00000020
321da177e4SLinus Torvalds #define DBG_BITMAP 0x00000040
33324ef39aSVyacheslav Dubeyko #define DBG_ATTR_MOD 0x00000080
341da177e4SLinus Torvalds
3521f2296aSAnton Salikhmetov #if 0
3621f2296aSAnton Salikhmetov #define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
3721f2296aSAnton Salikhmetov #define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
3821f2296aSAnton Salikhmetov #define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
3921f2296aSAnton Salikhmetov #endif
401da177e4SLinus Torvalds #define DBG_MASK (0)
411da177e4SLinus Torvalds
42c2b3e1f7SJoe Perches #define hfs_dbg(flg, fmt, ...) \
43c2b3e1f7SJoe Perches do { \
44c2b3e1f7SJoe Perches if (DBG_##flg & DBG_MASK) \
45d6142673SJoe Perches printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
46c2b3e1f7SJoe Perches } while (0)
47c2b3e1f7SJoe Perches
48c2b3e1f7SJoe Perches #define hfs_dbg_cont(flg, fmt, ...) \
49c2b3e1f7SJoe Perches do { \
50c2b3e1f7SJoe Perches if (DBG_##flg & DBG_MASK) \
51d6142673SJoe Perches pr_cont(fmt, ##__VA_ARGS__); \
52c2b3e1f7SJoe Perches } while (0)
531da177e4SLinus Torvalds
541da177e4SLinus Torvalds /* Runtime config options */
551da177e4SLinus Torvalds #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
561da177e4SLinus Torvalds
571da177e4SLinus Torvalds #define HFSPLUS_TYPE_DATA 0x00
581da177e4SLinus Torvalds #define HFSPLUS_TYPE_RSRC 0xFF
591da177e4SLinus Torvalds
602753cc28SAnton Salikhmetov typedef int (*btree_keycmp)(const hfsplus_btree_key *,
612753cc28SAnton Salikhmetov const hfsplus_btree_key *);
621da177e4SLinus Torvalds
631da177e4SLinus Torvalds #define NODE_HASH_SIZE 256
641da177e4SLinus Torvalds
65324ef39aSVyacheslav Dubeyko /* B-tree mutex nested subclasses */
66324ef39aSVyacheslav Dubeyko enum hfsplus_btree_mutex_classes {
67324ef39aSVyacheslav Dubeyko CATALOG_BTREE_MUTEX,
68324ef39aSVyacheslav Dubeyko EXTENTS_BTREE_MUTEX,
69324ef39aSVyacheslav Dubeyko ATTR_BTREE_MUTEX,
70324ef39aSVyacheslav Dubeyko };
71324ef39aSVyacheslav Dubeyko
721da177e4SLinus Torvalds /* An HFS+ BTree held in memory */
731da177e4SLinus Torvalds struct hfs_btree {
741da177e4SLinus Torvalds struct super_block *sb;
751da177e4SLinus Torvalds struct inode *inode;
761da177e4SLinus Torvalds btree_keycmp keycmp;
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds u32 cnid;
791da177e4SLinus Torvalds u32 root;
801da177e4SLinus Torvalds u32 leaf_count;
811da177e4SLinus Torvalds u32 leaf_head;
821da177e4SLinus Torvalds u32 leaf_tail;
831da177e4SLinus Torvalds u32 node_count;
841da177e4SLinus Torvalds u32 free_nodes;
851da177e4SLinus Torvalds u32 attributes;
861da177e4SLinus Torvalds
871da177e4SLinus Torvalds unsigned int node_size;
881da177e4SLinus Torvalds unsigned int node_size_shift;
891da177e4SLinus Torvalds unsigned int max_key_len;
901da177e4SLinus Torvalds unsigned int depth;
911da177e4SLinus Torvalds
92467c3d9cSThomas Gleixner struct mutex tree_lock;
931da177e4SLinus Torvalds
941da177e4SLinus Torvalds unsigned int pages_per_bnode;
951da177e4SLinus Torvalds spinlock_t hash_lock;
961da177e4SLinus Torvalds struct hfs_bnode *node_hash[NODE_HASH_SIZE];
971da177e4SLinus Torvalds int node_hash_cnt;
981da177e4SLinus Torvalds };
991da177e4SLinus Torvalds
1001da177e4SLinus Torvalds struct page;
1011da177e4SLinus Torvalds
1021da177e4SLinus Torvalds /* An HFS+ BTree node in memory */
1031da177e4SLinus Torvalds struct hfs_bnode {
1041da177e4SLinus Torvalds struct hfs_btree *tree;
1051da177e4SLinus Torvalds
1061da177e4SLinus Torvalds u32 prev;
1071da177e4SLinus Torvalds u32 this;
1081da177e4SLinus Torvalds u32 next;
1091da177e4SLinus Torvalds u32 parent;
1101da177e4SLinus Torvalds
1111da177e4SLinus Torvalds u16 num_recs;
1121da177e4SLinus Torvalds u8 type;
1131da177e4SLinus Torvalds u8 height;
1141da177e4SLinus Torvalds
1151da177e4SLinus Torvalds struct hfs_bnode *next_hash;
1161da177e4SLinus Torvalds unsigned long flags;
1171da177e4SLinus Torvalds wait_queue_head_t lock_wq;
1181da177e4SLinus Torvalds atomic_t refcnt;
1191da177e4SLinus Torvalds unsigned int page_offset;
1205e01fdffSGustavo A. R. Silva struct page *page[];
1211da177e4SLinus Torvalds };
1221da177e4SLinus Torvalds
1231da177e4SLinus Torvalds #define HFS_BNODE_LOCK 0
1241da177e4SLinus Torvalds #define HFS_BNODE_ERROR 1
1251da177e4SLinus Torvalds #define HFS_BNODE_NEW 2
1261da177e4SLinus Torvalds #define HFS_BNODE_DIRTY 3
1271da177e4SLinus Torvalds #define HFS_BNODE_DELETED 4
1281da177e4SLinus Torvalds
1291da177e4SLinus Torvalds /*
13095e0d7dbSVyacheslav Dubeyko * Attributes file states
13195e0d7dbSVyacheslav Dubeyko */
13295e0d7dbSVyacheslav Dubeyko #define HFSPLUS_EMPTY_ATTR_TREE 0
13395e0d7dbSVyacheslav Dubeyko #define HFSPLUS_CREATING_ATTR_TREE 1
13495e0d7dbSVyacheslav Dubeyko #define HFSPLUS_VALID_ATTR_TREE 2
13595e0d7dbSVyacheslav Dubeyko #define HFSPLUS_FAILED_ATTR_TREE 3
13695e0d7dbSVyacheslav Dubeyko
13795e0d7dbSVyacheslav Dubeyko /*
1381da177e4SLinus Torvalds * HFS+ superblock info (built from Volume Header on disk)
1391da177e4SLinus Torvalds */
1401da177e4SLinus Torvalds
1411da177e4SLinus Torvalds struct hfsplus_vh;
1421da177e4SLinus Torvalds struct hfs_btree;
1431da177e4SLinus Torvalds
1441da177e4SLinus Torvalds struct hfsplus_sb_info {
1456596528eSSeth Forshee void *s_vhdr_buf;
1461da177e4SLinus Torvalds struct hfsplus_vh *s_vhdr;
1476596528eSSeth Forshee void *s_backup_vhdr_buf;
14852399b17SChristoph Hellwig struct hfsplus_vh *s_backup_vhdr;
1491da177e4SLinus Torvalds struct hfs_btree *ext_tree;
1501da177e4SLinus Torvalds struct hfs_btree *cat_tree;
1511da177e4SLinus Torvalds struct hfs_btree *attr_tree;
15295e0d7dbSVyacheslav Dubeyko atomic_t attr_tree_state;
1531da177e4SLinus Torvalds struct inode *alloc_file;
1541da177e4SLinus Torvalds struct inode *hidden_dir;
1551da177e4SLinus Torvalds struct nls_table *nls;
1561da177e4SLinus Torvalds
1571da177e4SLinus Torvalds /* Runtime variables */
1581da177e4SLinus Torvalds u32 blockoffset;
159*21900e84SThadeu Lima de Souza Cascardo u32 min_io_size;
16052399b17SChristoph Hellwig sector_t part_start;
16152399b17SChristoph Hellwig sector_t sect_count;
1621da177e4SLinus Torvalds int fs_shift;
1631da177e4SLinus Torvalds
1647ac9fb9cSChristoph Hellwig /* immutable data from the volume header */
1651da177e4SLinus Torvalds u32 alloc_blksz;
1661da177e4SLinus Torvalds int alloc_blksz_shift;
1671da177e4SLinus Torvalds u32 total_blocks;
1687ac9fb9cSChristoph Hellwig u32 data_clump_blocks, rsrc_clump_blocks;
1697ac9fb9cSChristoph Hellwig
1707ac9fb9cSChristoph Hellwig /* mutable data from the volume header, protected by alloc_mutex */
1711da177e4SLinus Torvalds u32 free_blocks;
1727ac9fb9cSChristoph Hellwig struct mutex alloc_mutex;
1737ac9fb9cSChristoph Hellwig
1747ac9fb9cSChristoph Hellwig /* mutable data from the volume header, protected by vh_mutex */
1751da177e4SLinus Torvalds u32 next_cnid;
1761da177e4SLinus Torvalds u32 file_count;
1771da177e4SLinus Torvalds u32 folder_count;
1787ac9fb9cSChristoph Hellwig struct mutex vh_mutex;
1791da177e4SLinus Torvalds
1801da177e4SLinus Torvalds /* Config options */
1811da177e4SLinus Torvalds u32 creator;
1821da177e4SLinus Torvalds u32 type;
1831da177e4SLinus Torvalds
1841da177e4SLinus Torvalds umode_t umask;
18516525e3fSEric W. Biederman kuid_t uid;
18616525e3fSEric W. Biederman kgid_t gid;
1871da177e4SLinus Torvalds
1881da177e4SLinus Torvalds int part, session;
1891da177e4SLinus Torvalds unsigned long flags;
1909e6c5829SArtem Bityutskiy
1919e6c5829SArtem Bityutskiy int work_queued; /* non-zero delayed work is queued */
1929e6c5829SArtem Bityutskiy struct delayed_work sync_work; /* FS sync delayed work */
1939e6c5829SArtem Bityutskiy spinlock_t work_lock; /* protects sync_work and work_queued */
1941da177e4SLinus Torvalds };
1951da177e4SLinus Torvalds
19684adede3SChristoph Hellwig #define HFSPLUS_SB_WRITEBACKUP 0
19784adede3SChristoph Hellwig #define HFSPLUS_SB_NODECOMPOSE 1
19884adede3SChristoph Hellwig #define HFSPLUS_SB_FORCE 2
19984adede3SChristoph Hellwig #define HFSPLUS_SB_HFSX 3
20084adede3SChristoph Hellwig #define HFSPLUS_SB_CASEFOLD 4
20134a2d313SChristoph Hellwig #define HFSPLUS_SB_NOBARRIER 5
2029f2b5debSAditya Garg #define HFSPLUS_SB_UID 6
2039f2b5debSAditya Garg #define HFSPLUS_SB_GID 7
2041da177e4SLinus Torvalds
HFSPLUS_SB(struct super_block * sb)205e3494705SChristoph Hellwig static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
206e3494705SChristoph Hellwig {
207e3494705SChristoph Hellwig return sb->s_fs_info;
208e3494705SChristoph Hellwig }
2091da177e4SLinus Torvalds
2101da177e4SLinus Torvalds
2111da177e4SLinus Torvalds struct hfsplus_inode_info {
2121da177e4SLinus Torvalds atomic_t opencnt;
2131da177e4SLinus Torvalds
2147fcc99f4SChristoph Hellwig /*
2157fcc99f4SChristoph Hellwig * Extent allocation information, protected by extents_lock.
2167fcc99f4SChristoph Hellwig */
2177fcc99f4SChristoph Hellwig u32 first_blocks;
2187fcc99f4SChristoph Hellwig u32 clump_blocks;
2197fcc99f4SChristoph Hellwig u32 alloc_blocks;
2207fcc99f4SChristoph Hellwig u32 cached_start;
2217fcc99f4SChristoph Hellwig u32 cached_blocks;
2227fcc99f4SChristoph Hellwig hfsplus_extent_rec first_extents;
2237fcc99f4SChristoph Hellwig hfsplus_extent_rec cached_extents;
224b33b7921SChristoph Hellwig unsigned int extent_state;
2257fcc99f4SChristoph Hellwig struct mutex extents_lock;
2261da177e4SLinus Torvalds
2277fcc99f4SChristoph Hellwig /*
2287fcc99f4SChristoph Hellwig * Immutable data.
2297fcc99f4SChristoph Hellwig */
2307fcc99f4SChristoph Hellwig struct inode *rsrc_inode;
2319a4cad95SRoman Zippel __be32 create_date;
232f6089ff8SChristoph Hellwig
233f6089ff8SChristoph Hellwig /*
234f6089ff8SChristoph Hellwig * Protected by sbi->vh_mutex.
235f6089ff8SChristoph Hellwig */
236f6089ff8SChristoph Hellwig u32 linkid;
2371da177e4SLinus Torvalds
2387fcc99f4SChristoph Hellwig /*
239b33b7921SChristoph Hellwig * Accessed using atomic bitops.
240b33b7921SChristoph Hellwig */
241b33b7921SChristoph Hellwig unsigned long flags;
242b33b7921SChristoph Hellwig
243b33b7921SChristoph Hellwig /*
2447fcc99f4SChristoph Hellwig * Protected by i_mutex.
2457fcc99f4SChristoph Hellwig */
2467fcc99f4SChristoph Hellwig sector_t fs_blocks;
247722c55d1SChristoph Hellwig u8 userflags; /* BSD user file flags */
248d7d673a5SSergei Antonov u32 subfolders; /* Subfolder count (HFSX only) */
2491da177e4SLinus Torvalds struct list_head open_dir_list;
250323ee8fcSAl Viro spinlock_t open_dir_lock;
2511da177e4SLinus Torvalds loff_t phys_size;
2527fcc99f4SChristoph Hellwig
2531da177e4SLinus Torvalds struct inode vfs_inode;
2541da177e4SLinus Torvalds };
2551da177e4SLinus Torvalds
256b33b7921SChristoph Hellwig #define HFSPLUS_EXT_DIRTY 0x0001
257b33b7921SChristoph Hellwig #define HFSPLUS_EXT_NEW 0x0002
2581da177e4SLinus Torvalds
259b33b7921SChristoph Hellwig #define HFSPLUS_I_RSRC 0 /* represents a resource fork */
260e3494705SChristoph Hellwig #define HFSPLUS_I_CAT_DIRTY 1 /* has changes in the catalog tree */
261e3494705SChristoph Hellwig #define HFSPLUS_I_EXT_DIRTY 2 /* has changes in the extent tree */
262e3494705SChristoph Hellwig #define HFSPLUS_I_ALLOC_DIRTY 3 /* has changes in the allocation file */
263324ef39aSVyacheslav Dubeyko #define HFSPLUS_I_ATTR_DIRTY 4 /* has changes in the attributes tree */
264b33b7921SChristoph Hellwig
265b33b7921SChristoph Hellwig #define HFSPLUS_IS_RSRC(inode) \
266b33b7921SChristoph Hellwig test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
2671da177e4SLinus Torvalds
HFSPLUS_I(struct inode * inode)268e3494705SChristoph Hellwig static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
269e3494705SChristoph Hellwig {
270db6172c4SRasmus Villemoes return container_of(inode, struct hfsplus_inode_info, vfs_inode);
271e3494705SChristoph Hellwig }
272e3494705SChristoph Hellwig
273e3494705SChristoph Hellwig /*
274e3494705SChristoph Hellwig * Mark an inode dirty, and also mark the btree in which the
275e3494705SChristoph Hellwig * specific type of metadata is stored.
276e3494705SChristoph Hellwig * For data or metadata that gets written back by into the catalog btree
277e3494705SChristoph Hellwig * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
278e3494705SChristoph Hellwig */
hfsplus_mark_inode_dirty(struct inode * inode,unsigned int flag)279e3494705SChristoph Hellwig static inline void hfsplus_mark_inode_dirty(struct inode *inode,
280e3494705SChristoph Hellwig unsigned int flag)
281e3494705SChristoph Hellwig {
282e3494705SChristoph Hellwig set_bit(flag, &HFSPLUS_I(inode)->flags);
283e3494705SChristoph Hellwig mark_inode_dirty(inode);
284e3494705SChristoph Hellwig }
2851da177e4SLinus Torvalds
2861da177e4SLinus Torvalds struct hfs_find_data {
2871da177e4SLinus Torvalds /* filled by caller */
2881da177e4SLinus Torvalds hfsplus_btree_key *search_key;
2891da177e4SLinus Torvalds hfsplus_btree_key *key;
2901da177e4SLinus Torvalds /* filled by find */
2911da177e4SLinus Torvalds struct hfs_btree *tree;
2921da177e4SLinus Torvalds struct hfs_bnode *bnode;
2931da177e4SLinus Torvalds /* filled by findrec */
2941da177e4SLinus Torvalds int record;
2951da177e4SLinus Torvalds int keyoffset, keylength;
2961da177e4SLinus Torvalds int entryoffset, entrylength;
2971da177e4SLinus Torvalds };
2981da177e4SLinus Torvalds
2991da177e4SLinus Torvalds struct hfsplus_readdir_data {
3001da177e4SLinus Torvalds struct list_head list;
3011da177e4SLinus Torvalds struct file *file;
3021da177e4SLinus Torvalds struct hfsplus_cat_key key;
3031da177e4SLinus Torvalds };
3041da177e4SLinus Torvalds
3056596528eSSeth Forshee /*
3066596528eSSeth Forshee * Find minimum acceptible I/O size for an hfsplus sb.
3076596528eSSeth Forshee */
hfsplus_min_io_size(struct super_block * sb)3086596528eSSeth Forshee static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
3096596528eSSeth Forshee {
310*21900e84SThadeu Lima de Souza Cascardo return max_t(unsigned short, HFSPLUS_SB(sb)->min_io_size,
3116596528eSSeth Forshee HFSPLUS_SECTOR_SIZE);
3126596528eSSeth Forshee }
3136596528eSSeth Forshee
3141da177e4SLinus Torvalds #define hfs_btree_open hfsplus_btree_open
3151da177e4SLinus Torvalds #define hfs_btree_close hfsplus_btree_close
3161da177e4SLinus Torvalds #define hfs_btree_write hfsplus_btree_write
317d92915c3SErnesto A. Fernández #define hfs_bmap_reserve hfsplus_bmap_reserve
3181da177e4SLinus Torvalds #define hfs_bmap_alloc hfsplus_bmap_alloc
3191da177e4SLinus Torvalds #define hfs_bmap_free hfsplus_bmap_free
3201da177e4SLinus Torvalds #define hfs_bnode_read hfsplus_bnode_read
3211da177e4SLinus Torvalds #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
3221da177e4SLinus Torvalds #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
3231da177e4SLinus Torvalds #define hfs_bnode_read_key hfsplus_bnode_read_key
3241da177e4SLinus Torvalds #define hfs_bnode_write hfsplus_bnode_write
3251da177e4SLinus Torvalds #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
3261da177e4SLinus Torvalds #define hfs_bnode_clear hfsplus_bnode_clear
3271da177e4SLinus Torvalds #define hfs_bnode_copy hfsplus_bnode_copy
3281da177e4SLinus Torvalds #define hfs_bnode_move hfsplus_bnode_move
3291da177e4SLinus Torvalds #define hfs_bnode_dump hfsplus_bnode_dump
3301da177e4SLinus Torvalds #define hfs_bnode_unlink hfsplus_bnode_unlink
3311da177e4SLinus Torvalds #define hfs_bnode_findhash hfsplus_bnode_findhash
3321da177e4SLinus Torvalds #define hfs_bnode_find hfsplus_bnode_find
3331da177e4SLinus Torvalds #define hfs_bnode_unhash hfsplus_bnode_unhash
3341da177e4SLinus Torvalds #define hfs_bnode_free hfsplus_bnode_free
3351da177e4SLinus Torvalds #define hfs_bnode_create hfsplus_bnode_create
3361da177e4SLinus Torvalds #define hfs_bnode_get hfsplus_bnode_get
3371da177e4SLinus Torvalds #define hfs_bnode_put hfsplus_bnode_put
3381da177e4SLinus Torvalds #define hfs_brec_lenoff hfsplus_brec_lenoff
3391da177e4SLinus Torvalds #define hfs_brec_keylen hfsplus_brec_keylen
3401da177e4SLinus Torvalds #define hfs_brec_insert hfsplus_brec_insert
3411da177e4SLinus Torvalds #define hfs_brec_remove hfsplus_brec_remove
3421da177e4SLinus Torvalds #define hfs_find_init hfsplus_find_init
3431da177e4SLinus Torvalds #define hfs_find_exit hfsplus_find_exit
344324ef39aSVyacheslav Dubeyko #define __hfs_brec_find __hfsplus_brec_find
3451da177e4SLinus Torvalds #define hfs_brec_find hfsplus_brec_find
3461da177e4SLinus Torvalds #define hfs_brec_read hfsplus_brec_read
3471da177e4SLinus Torvalds #define hfs_brec_goto hfsplus_brec_goto
3481da177e4SLinus Torvalds #define hfs_part_find hfsplus_part_find
3491da177e4SLinus Torvalds
3501da177e4SLinus Torvalds /*
351a051f71cSMatthew Garrett * hfs+-specific ioctl for making the filesystem bootable
352a051f71cSMatthew Garrett */
353a051f71cSMatthew Garrett #define HFSPLUS_IOC_BLESS _IO('h', 0x80)
354a051f71cSMatthew Garrett
355324ef39aSVyacheslav Dubeyko typedef int (*search_strategy_t)(struct hfs_bnode *,
356324ef39aSVyacheslav Dubeyko struct hfs_find_data *,
357324ef39aSVyacheslav Dubeyko int *, int *, int *);
358324ef39aSVyacheslav Dubeyko
359a051f71cSMatthew Garrett /*
3601da177e4SLinus Torvalds * Functions in any *.c used in other files
3611da177e4SLinus Torvalds */
3621da177e4SLinus Torvalds
363324ef39aSVyacheslav Dubeyko /* attributes.c */
364c11e614dSFabian Frederick int __init hfsplus_create_attr_tree_cache(void);
365324ef39aSVyacheslav Dubeyko void hfsplus_destroy_attr_tree_cache(void);
366ffbc0671SSergei Antonov int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,
367ffbc0671SSergei Antonov const hfsplus_btree_key *k2);
368ffbc0671SSergei Antonov int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,
369ffbc0671SSergei Antonov u32 cnid, const char *name);
370324ef39aSVyacheslav Dubeyko hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);
371ffbc0671SSergei Antonov void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry);
372ffbc0671SSergei Antonov int hfsplus_find_attr(struct super_block *sb, u32 cnid, const char *name,
373ffbc0671SSergei Antonov struct hfs_find_data *fd);
374324ef39aSVyacheslav Dubeyko int hfsplus_attr_exists(struct inode *inode, const char *name);
375ffbc0671SSergei Antonov int hfsplus_create_attr(struct inode *inode, const char *name,
376ffbc0671SSergei Antonov const void *value, size_t size);
377ffbc0671SSergei Antonov int hfsplus_delete_attr(struct inode *inode, const char *name);
378324ef39aSVyacheslav Dubeyko int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
379324ef39aSVyacheslav Dubeyko
3801da177e4SLinus Torvalds /* bitmap.c */
381ffbc0671SSergei Antonov int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset,
382ffbc0671SSergei Antonov u32 *max);
383ffbc0671SSergei Antonov int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count);
3841da177e4SLinus Torvalds
3851da177e4SLinus Torvalds /* btree.c */
386ffbc0671SSergei Antonov u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size, u64 sectors,
387ffbc0671SSergei Antonov int file_id);
388ffbc0671SSergei Antonov struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id);
389ffbc0671SSergei Antonov void hfs_btree_close(struct hfs_btree *tree);
390ffbc0671SSergei Antonov int hfs_btree_write(struct hfs_btree *tree);
391d92915c3SErnesto A. Fernández int hfs_bmap_reserve(struct hfs_btree *tree, int rsvd_nodes);
392ffbc0671SSergei Antonov struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree);
393ffbc0671SSergei Antonov void hfs_bmap_free(struct hfs_bnode *node);
3941da177e4SLinus Torvalds
3951da177e4SLinus Torvalds /* bnode.c */
396ffbc0671SSergei Antonov void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len);
397ffbc0671SSergei Antonov u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off);
398ffbc0671SSergei Antonov u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off);
399ffbc0671SSergei Antonov void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off);
400ffbc0671SSergei Antonov void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len);
401ffbc0671SSergei Antonov void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data);
402ffbc0671SSergei Antonov void hfs_bnode_clear(struct hfs_bnode *node, int off, int len);
403ffbc0671SSergei Antonov void hfs_bnode_copy(struct hfs_bnode *dst_node, int dst,
404ffbc0671SSergei Antonov struct hfs_bnode *src_node, int src, int len);
405ffbc0671SSergei Antonov void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len);
406ffbc0671SSergei Antonov void hfs_bnode_dump(struct hfs_bnode *node);
407ffbc0671SSergei Antonov void hfs_bnode_unlink(struct hfs_bnode *node);
408ffbc0671SSergei Antonov struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid);
409ffbc0671SSergei Antonov void hfs_bnode_unhash(struct hfs_bnode *node);
410ffbc0671SSergei Antonov struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num);
411ffbc0671SSergei Antonov void hfs_bnode_free(struct hfs_bnode *node);
412ffbc0671SSergei Antonov struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num);
413ffbc0671SSergei Antonov void hfs_bnode_get(struct hfs_bnode *node);
414ffbc0671SSergei Antonov void hfs_bnode_put(struct hfs_bnode *node);
415ffbc0671SSergei Antonov bool hfs_bnode_need_zeroout(struct hfs_btree *tree);
4161da177e4SLinus Torvalds
4171da177e4SLinus Torvalds /* brec.c */
418ffbc0671SSergei Antonov u16 hfs_brec_lenoff(struct hfs_bnode *node, u16 rec, u16 *off);
419ffbc0671SSergei Antonov u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec);
420ffbc0671SSergei Antonov int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len);
421ffbc0671SSergei Antonov int hfs_brec_remove(struct hfs_find_data *fd);
4221da177e4SLinus Torvalds
4231da177e4SLinus Torvalds /* bfind.c */
424ffbc0671SSergei Antonov int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd);
425ffbc0671SSergei Antonov void hfs_find_exit(struct hfs_find_data *fd);
426ffbc0671SSergei Antonov int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode, struct hfs_find_data *fd,
427ffbc0671SSergei Antonov int *begin, int *end, int *cur_rec);
428ffbc0671SSergei Antonov int hfs_find_rec_by_key(struct hfs_bnode *bnode, struct hfs_find_data *fd,
429ffbc0671SSergei Antonov int *begin, int *end, int *cur_rec);
430ffbc0671SSergei Antonov int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd,
431ffbc0671SSergei Antonov search_strategy_t rec_found);
432ffbc0671SSergei Antonov int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare);
433ffbc0671SSergei Antonov int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len);
434ffbc0671SSergei Antonov int hfs_brec_goto(struct hfs_find_data *fd, int cnt);
4351da177e4SLinus Torvalds
4361da177e4SLinus Torvalds /* catalog.c */
437ffbc0671SSergei Antonov int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1,
438ffbc0671SSergei Antonov const hfsplus_btree_key *k2);
439ffbc0671SSergei Antonov int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *k1,
440ffbc0671SSergei Antonov const hfsplus_btree_key *k2);
44189ac9b4dSSougata Santra int hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key,
442b5cce521SAl Viro u32 parent, const struct qstr *str);
44389ac9b4dSSougata Santra void hfsplus_cat_build_key_with_cnid(struct super_block *sb,
44489ac9b4dSSougata Santra hfsplus_btree_key *key, u32 parent);
44590e61690SChristoph Hellwig void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
446ffbc0671SSergei Antonov int hfsplus_find_cat(struct super_block *sb, u32 cnid,
447ffbc0671SSergei Antonov struct hfs_find_data *fd);
448b5cce521SAl Viro int hfsplus_create_cat(u32 cnid, struct inode *dir, const struct qstr *str,
449ffbc0671SSergei Antonov struct inode *inode);
450b5cce521SAl Viro int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str);
451b5cce521SAl Viro int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_name,
452b5cce521SAl Viro struct inode *dst_dir, const struct qstr *dst_name);
4531da177e4SLinus Torvalds
4544b0a8da7SAdrian Bunk /* dir.c */
4554b0a8da7SAdrian Bunk extern const struct inode_operations hfsplus_dir_inode_operations;
4564b0a8da7SAdrian Bunk extern const struct file_operations hfsplus_dir_operations;
4574b0a8da7SAdrian Bunk
4581da177e4SLinus Torvalds /* extents.c */
459ffbc0671SSergei Antonov int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
460ffbc0671SSergei Antonov const hfsplus_btree_key *k2);
461ffbc0671SSergei Antonov int hfsplus_ext_write_extent(struct inode *inode);
462ffbc0671SSergei Antonov int hfsplus_get_block(struct inode *inode, sector_t iblock,
463ffbc0671SSergei Antonov struct buffer_head *bh_result, int create);
464ffbc0671SSergei Antonov int hfsplus_free_fork(struct super_block *sb, u32 cnid,
465ffbc0671SSergei Antonov struct hfsplus_fork_raw *fork, int type);
466ffbc0671SSergei Antonov int hfsplus_file_extend(struct inode *inode, bool zeroout);
467ffbc0671SSergei Antonov void hfsplus_file_truncate(struct inode *inode);
4681da177e4SLinus Torvalds
4691da177e4SLinus Torvalds /* inode.c */
470f5e54d6eSChristoph Hellwig extern const struct address_space_operations hfsplus_aops;
471f5e54d6eSChristoph Hellwig extern const struct address_space_operations hfsplus_btree_aops;
472e16404edSAl Viro extern const struct dentry_operations hfsplus_dentry_operations;
4731da177e4SLinus Torvalds
47407a31f72SMatthew Wilcox (Oracle) int hfsplus_write_begin(struct file *file, struct address_space *mapping,
47507a31f72SMatthew Wilcox (Oracle) loff_t pos, unsigned len, struct page **pagep, void **fsdata);
476b0cd38c7SErnesto A. Fernandez struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
477b0cd38c7SErnesto A. Fernandez umode_t mode);
478ffbc0671SSergei Antonov void hfsplus_delete_inode(struct inode *inode);
479ffbc0671SSergei Antonov void hfsplus_inode_read_fork(struct inode *inode,
480ffbc0671SSergei Antonov struct hfsplus_fork_raw *fork);
481ffbc0671SSergei Antonov void hfsplus_inode_write_fork(struct inode *inode,
482ffbc0671SSergei Antonov struct hfsplus_fork_raw *fork);
483ffbc0671SSergei Antonov int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd);
484ffbc0671SSergei Antonov int hfsplus_cat_write_inode(struct inode *inode);
485b74d24f7SChristian Brauner int hfsplus_getattr(struct mnt_idmap *idmap, const struct path *path,
486549c7297SChristian Brauner struct kstat *stat, u32 request_mask,
487549c7297SChristian Brauner unsigned int query_flags);
48802c24a82SJosef Bacik int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
48902c24a82SJosef Bacik int datasync);
4909cbae748SMiklos Szeredi int hfsplus_fileattr_get(struct dentry *dentry, struct fileattr *fa);
4918782a9aeSChristian Brauner int hfsplus_fileattr_set(struct mnt_idmap *idmap,
4929cbae748SMiklos Szeredi struct dentry *dentry, struct fileattr *fa);
4931da177e4SLinus Torvalds
4941da177e4SLinus Torvalds /* ioctl.c */
4957cc4bcc6SArnd Bergmann long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
4961da177e4SLinus Torvalds
4971da177e4SLinus Torvalds /* options.c */
498ffbc0671SSergei Antonov void hfsplus_fill_defaults(struct hfsplus_sb_info *opts);
4996f80dfe5SChristoph Hellwig int hfsplus_parse_options_remount(char *input, int *force);
500ffbc0671SSergei Antonov int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi);
501ffbc0671SSergei Antonov int hfsplus_show_options(struct seq_file *seq, struct dentry *root);
502ffbc0671SSergei Antonov
503ffbc0671SSergei Antonov /* part_tbl.c */
504ffbc0671SSergei Antonov int hfs_part_find(struct super_block *sb, sector_t *part_start,
505ffbc0671SSergei Antonov sector_t *part_size);
5061da177e4SLinus Torvalds
50763525391SDavid Howells /* super.c */
508ffbc0671SSergei Antonov struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino);
5099e6c5829SArtem Bityutskiy void hfsplus_mark_mdb_dirty(struct super_block *sb);
51063525391SDavid Howells
5111da177e4SLinus Torvalds /* tables.c */
5121da177e4SLinus Torvalds extern u16 hfsplus_case_fold_table[];
5131da177e4SLinus Torvalds extern u16 hfsplus_decompose_table[];
5141da177e4SLinus Torvalds extern u16 hfsplus_compose_table[];
5151da177e4SLinus Torvalds
5161da177e4SLinus Torvalds /* unicode.c */
517ffbc0671SSergei Antonov int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,
518ffbc0671SSergei Antonov const struct hfsplus_unistr *s2);
519ffbc0671SSergei Antonov int hfsplus_strcmp(const struct hfsplus_unistr *s1,
520ffbc0671SSergei Antonov const struct hfsplus_unistr *s2);
521ffbc0671SSergei Antonov int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr,
522ffbc0671SSergei Antonov char *astr, int *len_p);
523ffbc0671SSergei Antonov int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
524ffbc0671SSergei Antonov int max_unistr_len, const char *astr, int len);
525da53be12SLinus Torvalds int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str);
5266fa67e70SAl Viro int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len,
527ffbc0671SSergei Antonov const char *str, const struct qstr *name);
5281da177e4SLinus Torvalds
5291da177e4SLinus Torvalds /* wrapper.c */
530ffbc0671SSergei Antonov int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf,
531c85f9992SBart Van Assche void **data, blk_opf_t opf);
532ffbc0671SSergei Antonov int hfsplus_read_wrapper(struct super_block *sb);
5331da177e4SLinus Torvalds
5344ddfc3dcSArnd Bergmann /*
5354ddfc3dcSArnd Bergmann * time helpers: convert between 1904-base and 1970-base timestamps
5364ddfc3dcSArnd Bergmann *
5374ddfc3dcSArnd Bergmann * HFS+ implementations are highly inconsistent, this one matches the
5384ddfc3dcSArnd Bergmann * traditional behavior of 64-bit Linux, giving the most useful
5394ddfc3dcSArnd Bergmann * time range between 1970 and 2106, by treating any on-disk timestamp
5404ddfc3dcSArnd Bergmann * under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
5414ddfc3dcSArnd Bergmann */
5424ddfc3dcSArnd Bergmann #define HFSPLUS_UTC_OFFSET 2082844800U
5434ddfc3dcSArnd Bergmann
__hfsp_mt2ut(__be32 mt)5444ddfc3dcSArnd Bergmann static inline time64_t __hfsp_mt2ut(__be32 mt)
5454ddfc3dcSArnd Bergmann {
5464ddfc3dcSArnd Bergmann time64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET);
5474ddfc3dcSArnd Bergmann
5484ddfc3dcSArnd Bergmann return ut;
5494ddfc3dcSArnd Bergmann }
5504ddfc3dcSArnd Bergmann
__hfsp_ut2mt(time64_t ut)5514ddfc3dcSArnd Bergmann static inline __be32 __hfsp_ut2mt(time64_t ut)
5524ddfc3dcSArnd Bergmann {
5534ddfc3dcSArnd Bergmann return cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET);
5544ddfc3dcSArnd Bergmann }
5551da177e4SLinus Torvalds
556f04da10dSChao Yu static inline enum hfsplus_btree_mutex_classes
hfsplus_btree_lock_class(struct hfs_btree * tree)557f04da10dSChao Yu hfsplus_btree_lock_class(struct hfs_btree *tree)
558f04da10dSChao Yu {
559f04da10dSChao Yu enum hfsplus_btree_mutex_classes class;
560f04da10dSChao Yu
561f04da10dSChao Yu switch (tree->cnid) {
562f04da10dSChao Yu case HFSPLUS_CAT_CNID:
563f04da10dSChao Yu class = CATALOG_BTREE_MUTEX;
564f04da10dSChao Yu break;
565f04da10dSChao Yu case HFSPLUS_EXT_CNID:
566f04da10dSChao Yu class = EXTENTS_BTREE_MUTEX;
567f04da10dSChao Yu break;
568f04da10dSChao Yu case HFSPLUS_ATTR_CNID:
569f04da10dSChao Yu class = ATTR_BTREE_MUTEX;
570f04da10dSChao Yu break;
571f04da10dSChao Yu default:
572f04da10dSChao Yu BUG();
573f04da10dSChao Yu }
574f04da10dSChao Yu return class;
575f04da10dSChao Yu }
576f04da10dSChao Yu
5771da177e4SLinus Torvalds /* compatibility */
5784ddfc3dcSArnd Bergmann #define hfsp_mt2ut(t) (struct timespec64){ .tv_sec = __hfsp_mt2ut(t) }
5791da177e4SLinus Torvalds #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
5804ddfc3dcSArnd Bergmann #define hfsp_now2mt() __hfsp_ut2mt(ktime_get_real_seconds())
5811da177e4SLinus Torvalds
5821da177e4SLinus Torvalds #endif
583