hfsplus_fs.h 18 KB

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