Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  *  linux/include/linux/hfsplus_fs.h
0004  *
0005  * Copyright (C) 1999
0006  * Brad Boyer (flar@pants.nu)
0007  * (C) 2003 Ardis Technologies <roman@ardistech.com>
0008  *
0009  */
0010 
0011 #ifndef _LINUX_HFSPLUS_FS_H
0012 #define _LINUX_HFSPLUS_FS_H
0013 
0014 #ifdef pr_fmt
0015 #undef pr_fmt
0016 #endif
0017 
0018 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0019 
0020 #include <linux/fs.h>
0021 #include <linux/mutex.h>
0022 #include <linux/buffer_head.h>
0023 #include <linux/blkdev.h>
0024 #include "hfsplus_raw.h"
0025 
0026 #define DBG_BNODE_REFS  0x00000001
0027 #define DBG_BNODE_MOD   0x00000002
0028 #define DBG_CAT_MOD 0x00000004
0029 #define DBG_INODE   0x00000008
0030 #define DBG_SUPER   0x00000010
0031 #define DBG_EXTENT  0x00000020
0032 #define DBG_BITMAP  0x00000040
0033 #define DBG_ATTR_MOD    0x00000080
0034 
0035 #if 0
0036 #define DBG_MASK    (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
0037 #define DBG_MASK    (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
0038 #define DBG_MASK    (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
0039 #endif
0040 #define DBG_MASK    (0)
0041 
0042 #define hfs_dbg(flg, fmt, ...)                  \
0043 do {                                \
0044     if (DBG_##flg & DBG_MASK)               \
0045         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__);  \
0046 } while (0)
0047 
0048 #define hfs_dbg_cont(flg, fmt, ...)             \
0049 do {                                \
0050     if (DBG_##flg & DBG_MASK)               \
0051         pr_cont(fmt, ##__VA_ARGS__);            \
0052 } while (0)
0053 
0054 /* Runtime config options */
0055 #define HFSPLUS_DEF_CR_TYPE    0x3F3F3F3F  /* '????' */
0056 
0057 #define HFSPLUS_TYPE_DATA 0x00
0058 #define HFSPLUS_TYPE_RSRC 0xFF
0059 
0060 typedef int (*btree_keycmp)(const hfsplus_btree_key *,
0061         const hfsplus_btree_key *);
0062 
0063 #define NODE_HASH_SIZE  256
0064 
0065 /* B-tree mutex nested subclasses */
0066 enum hfsplus_btree_mutex_classes {
0067     CATALOG_BTREE_MUTEX,
0068     EXTENTS_BTREE_MUTEX,
0069     ATTR_BTREE_MUTEX,
0070 };
0071 
0072 /* An HFS+ BTree held in memory */
0073 struct hfs_btree {
0074     struct super_block *sb;
0075     struct inode *inode;
0076     btree_keycmp keycmp;
0077 
0078     u32 cnid;
0079     u32 root;
0080     u32 leaf_count;
0081     u32 leaf_head;
0082     u32 leaf_tail;
0083     u32 node_count;
0084     u32 free_nodes;
0085     u32 attributes;
0086 
0087     unsigned int node_size;
0088     unsigned int node_size_shift;
0089     unsigned int max_key_len;
0090     unsigned int depth;
0091 
0092     struct mutex tree_lock;
0093 
0094     unsigned int pages_per_bnode;
0095     spinlock_t hash_lock;
0096     struct hfs_bnode *node_hash[NODE_HASH_SIZE];
0097     int node_hash_cnt;
0098 };
0099 
0100 struct page;
0101 
0102 /* An HFS+ BTree node in memory */
0103 struct hfs_bnode {
0104     struct hfs_btree *tree;
0105 
0106     u32 prev;
0107     u32 this;
0108     u32 next;
0109     u32 parent;
0110 
0111     u16 num_recs;
0112     u8 type;
0113     u8 height;
0114 
0115     struct hfs_bnode *next_hash;
0116     unsigned long flags;
0117     wait_queue_head_t lock_wq;
0118     atomic_t refcnt;
0119     unsigned int page_offset;
0120     struct page *page[];
0121 };
0122 
0123 #define HFS_BNODE_LOCK      0
0124 #define HFS_BNODE_ERROR     1
0125 #define HFS_BNODE_NEW       2
0126 #define HFS_BNODE_DIRTY     3
0127 #define HFS_BNODE_DELETED   4
0128 
0129 /*
0130  * Attributes file states
0131  */
0132 #define HFSPLUS_EMPTY_ATTR_TREE     0
0133 #define HFSPLUS_CREATING_ATTR_TREE  1
0134 #define HFSPLUS_VALID_ATTR_TREE     2
0135 #define HFSPLUS_FAILED_ATTR_TREE    3
0136 
0137 /*
0138  * HFS+ superblock info (built from Volume Header on disk)
0139  */
0140 
0141 struct hfsplus_vh;
0142 struct hfs_btree;
0143 
0144 struct hfsplus_sb_info {
0145     void *s_vhdr_buf;
0146     struct hfsplus_vh *s_vhdr;
0147     void *s_backup_vhdr_buf;
0148     struct hfsplus_vh *s_backup_vhdr;
0149     struct hfs_btree *ext_tree;
0150     struct hfs_btree *cat_tree;
0151     struct hfs_btree *attr_tree;
0152     atomic_t attr_tree_state;
0153     struct inode *alloc_file;
0154     struct inode *hidden_dir;
0155     struct nls_table *nls;
0156 
0157     /* Runtime variables */
0158     u32 blockoffset;
0159     sector_t part_start;
0160     sector_t sect_count;
0161     int fs_shift;
0162 
0163     /* immutable data from the volume header */
0164     u32 alloc_blksz;
0165     int alloc_blksz_shift;
0166     u32 total_blocks;
0167     u32 data_clump_blocks, rsrc_clump_blocks;
0168 
0169     /* mutable data from the volume header, protected by alloc_mutex */
0170     u32 free_blocks;
0171     struct mutex alloc_mutex;
0172 
0173     /* mutable data from the volume header, protected by vh_mutex */
0174     u32 next_cnid;
0175     u32 file_count;
0176     u32 folder_count;
0177     struct mutex vh_mutex;
0178 
0179     /* Config options */
0180     u32 creator;
0181     u32 type;
0182 
0183     umode_t umask;
0184     kuid_t uid;
0185     kgid_t gid;
0186 
0187     int part, session;
0188     unsigned long flags;
0189 
0190     int work_queued;               /* non-zero delayed work is queued */
0191     struct delayed_work sync_work; /* FS sync delayed work */
0192     spinlock_t work_lock;          /* protects sync_work and work_queued */
0193 };
0194 
0195 #define HFSPLUS_SB_WRITEBACKUP  0
0196 #define HFSPLUS_SB_NODECOMPOSE  1
0197 #define HFSPLUS_SB_FORCE    2
0198 #define HFSPLUS_SB_HFSX     3
0199 #define HFSPLUS_SB_CASEFOLD 4
0200 #define HFSPLUS_SB_NOBARRIER    5
0201 
0202 static inline struct hfsplus_sb_info *HFSPLUS_SB(struct super_block *sb)
0203 {
0204     return sb->s_fs_info;
0205 }
0206 
0207 
0208 struct hfsplus_inode_info {
0209     atomic_t opencnt;
0210 
0211     /*
0212      * Extent allocation information, protected by extents_lock.
0213      */
0214     u32 first_blocks;
0215     u32 clump_blocks;
0216     u32 alloc_blocks;
0217     u32 cached_start;
0218     u32 cached_blocks;
0219     hfsplus_extent_rec first_extents;
0220     hfsplus_extent_rec cached_extents;
0221     unsigned int extent_state;
0222     struct mutex extents_lock;
0223 
0224     /*
0225      * Immutable data.
0226      */
0227     struct inode *rsrc_inode;
0228     __be32 create_date;
0229 
0230     /*
0231      * Protected by sbi->vh_mutex.
0232      */
0233     u32 linkid;
0234 
0235     /*
0236      * Accessed using atomic bitops.
0237      */
0238     unsigned long flags;
0239 
0240     /*
0241      * Protected by i_mutex.
0242      */
0243     sector_t fs_blocks;
0244     u8 userflags;       /* BSD user file flags */
0245     u32 subfolders;     /* Subfolder count (HFSX only) */
0246     struct list_head open_dir_list;
0247     spinlock_t open_dir_lock;
0248     loff_t phys_size;
0249 
0250     struct inode vfs_inode;
0251 };
0252 
0253 #define HFSPLUS_EXT_DIRTY   0x0001
0254 #define HFSPLUS_EXT_NEW     0x0002
0255 
0256 #define HFSPLUS_I_RSRC      0   /* represents a resource fork */
0257 #define HFSPLUS_I_CAT_DIRTY 1   /* has changes in the catalog tree */
0258 #define HFSPLUS_I_EXT_DIRTY 2   /* has changes in the extent tree */
0259 #define HFSPLUS_I_ALLOC_DIRTY   3   /* has changes in the allocation file */
0260 #define HFSPLUS_I_ATTR_DIRTY    4   /* has changes in the attributes tree */
0261 
0262 #define HFSPLUS_IS_RSRC(inode) \
0263     test_bit(HFSPLUS_I_RSRC, &HFSPLUS_I(inode)->flags)
0264 
0265 static inline struct hfsplus_inode_info *HFSPLUS_I(struct inode *inode)
0266 {
0267     return container_of(inode, struct hfsplus_inode_info, vfs_inode);
0268 }
0269 
0270 /*
0271  * Mark an inode dirty, and also mark the btree in which the
0272  * specific type of metadata is stored.
0273  * For data or metadata that gets written back by into the catalog btree
0274  * by hfsplus_write_inode a plain mark_inode_dirty call is enough.
0275  */
0276 static inline void hfsplus_mark_inode_dirty(struct inode *inode,
0277         unsigned int flag)
0278 {
0279     set_bit(flag, &HFSPLUS_I(inode)->flags);
0280     mark_inode_dirty(inode);
0281 }
0282 
0283 struct hfs_find_data {
0284     /* filled by caller */
0285     hfsplus_btree_key *search_key;
0286     hfsplus_btree_key *key;
0287     /* filled by find */
0288     struct hfs_btree *tree;
0289     struct hfs_bnode *bnode;
0290     /* filled by findrec */
0291     int record;
0292     int keyoffset, keylength;
0293     int entryoffset, entrylength;
0294 };
0295 
0296 struct hfsplus_readdir_data {
0297     struct list_head list;
0298     struct file *file;
0299     struct hfsplus_cat_key key;
0300 };
0301 
0302 /*
0303  * Find minimum acceptible I/O size for an hfsplus sb.
0304  */
0305 static inline unsigned short hfsplus_min_io_size(struct super_block *sb)
0306 {
0307     return max_t(unsigned short, bdev_logical_block_size(sb->s_bdev),
0308              HFSPLUS_SECTOR_SIZE);
0309 }
0310 
0311 #define hfs_btree_open hfsplus_btree_open
0312 #define hfs_btree_close hfsplus_btree_close
0313 #define hfs_btree_write hfsplus_btree_write
0314 #define hfs_bmap_reserve hfsplus_bmap_reserve
0315 #define hfs_bmap_alloc hfsplus_bmap_alloc
0316 #define hfs_bmap_free hfsplus_bmap_free
0317 #define hfs_bnode_read hfsplus_bnode_read
0318 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
0319 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
0320 #define hfs_bnode_read_key hfsplus_bnode_read_key
0321 #define hfs_bnode_write hfsplus_bnode_write
0322 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
0323 #define hfs_bnode_clear hfsplus_bnode_clear
0324 #define hfs_bnode_copy hfsplus_bnode_copy
0325 #define hfs_bnode_move hfsplus_bnode_move
0326 #define hfs_bnode_dump hfsplus_bnode_dump
0327 #define hfs_bnode_unlink hfsplus_bnode_unlink
0328 #define hfs_bnode_findhash hfsplus_bnode_findhash
0329 #define hfs_bnode_find hfsplus_bnode_find
0330 #define hfs_bnode_unhash hfsplus_bnode_unhash
0331 #define hfs_bnode_free hfsplus_bnode_free
0332 #define hfs_bnode_create hfsplus_bnode_create
0333 #define hfs_bnode_get hfsplus_bnode_get
0334 #define hfs_bnode_put hfsplus_bnode_put
0335 #define hfs_brec_lenoff hfsplus_brec_lenoff
0336 #define hfs_brec_keylen hfsplus_brec_keylen
0337 #define hfs_brec_insert hfsplus_brec_insert
0338 #define hfs_brec_remove hfsplus_brec_remove
0339 #define hfs_find_init hfsplus_find_init
0340 #define hfs_find_exit hfsplus_find_exit
0341 #define __hfs_brec_find __hfsplus_brec_find
0342 #define hfs_brec_find hfsplus_brec_find
0343 #define hfs_brec_read hfsplus_brec_read
0344 #define hfs_brec_goto hfsplus_brec_goto
0345 #define hfs_part_find hfsplus_part_find
0346 
0347 /*
0348  * hfs+-specific ioctl for making the filesystem bootable
0349  */
0350 #define HFSPLUS_IOC_BLESS _IO('h', 0x80)
0351 
0352 typedef int (*search_strategy_t)(struct hfs_bnode *,
0353                 struct hfs_find_data *,
0354                 int *, int *, int *);
0355 
0356 /*
0357  * Functions in any *.c used in other files
0358  */
0359 
0360 /* attributes.c */
0361 int __init hfsplus_create_attr_tree_cache(void);
0362 void hfsplus_destroy_attr_tree_cache(void);
0363 int hfsplus_attr_bin_cmp_key(const hfsplus_btree_key *k1,
0364                  const hfsplus_btree_key *k2);
0365 int hfsplus_attr_build_key(struct super_block *sb, hfsplus_btree_key *key,
0366                u32 cnid, const char *name);
0367 hfsplus_attr_entry *hfsplus_alloc_attr_entry(void);
0368 void hfsplus_destroy_attr_entry(hfsplus_attr_entry *entry);
0369 int hfsplus_find_attr(struct super_block *sb, u32 cnid, const char *name,
0370               struct hfs_find_data *fd);
0371 int hfsplus_attr_exists(struct inode *inode, const char *name);
0372 int hfsplus_create_attr(struct inode *inode, const char *name,
0373             const void *value, size_t size);
0374 int hfsplus_delete_attr(struct inode *inode, const char *name);
0375 int hfsplus_delete_all_attrs(struct inode *dir, u32 cnid);
0376 
0377 /* bitmap.c */
0378 int hfsplus_block_allocate(struct super_block *sb, u32 size, u32 offset,
0379                u32 *max);
0380 int hfsplus_block_free(struct super_block *sb, u32 offset, u32 count);
0381 
0382 /* btree.c */
0383 u32 hfsplus_calc_btree_clump_size(u32 block_size, u32 node_size, u64 sectors,
0384                   int file_id);
0385 struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id);
0386 void hfs_btree_close(struct hfs_btree *tree);
0387 int hfs_btree_write(struct hfs_btree *tree);
0388 int hfs_bmap_reserve(struct hfs_btree *tree, int rsvd_nodes);
0389 struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree);
0390 void hfs_bmap_free(struct hfs_bnode *node);
0391 
0392 /* bnode.c */
0393 void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len);
0394 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off);
0395 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off);
0396 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off);
0397 void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len);
0398 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data);
0399 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len);
0400 void hfs_bnode_copy(struct hfs_bnode *dst_node, int dst,
0401             struct hfs_bnode *src_node, int src, int len);
0402 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len);
0403 void hfs_bnode_dump(struct hfs_bnode *node);
0404 void hfs_bnode_unlink(struct hfs_bnode *node);
0405 struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid);
0406 void hfs_bnode_unhash(struct hfs_bnode *node);
0407 struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num);
0408 void hfs_bnode_free(struct hfs_bnode *node);
0409 struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num);
0410 void hfs_bnode_get(struct hfs_bnode *node);
0411 void hfs_bnode_put(struct hfs_bnode *node);
0412 bool hfs_bnode_need_zeroout(struct hfs_btree *tree);
0413 
0414 /* brec.c */
0415 u16 hfs_brec_lenoff(struct hfs_bnode *node, u16 rec, u16 *off);
0416 u16 hfs_brec_keylen(struct hfs_bnode *node, u16 rec);
0417 int hfs_brec_insert(struct hfs_find_data *fd, void *entry, int entry_len);
0418 int hfs_brec_remove(struct hfs_find_data *fd);
0419 
0420 /* bfind.c */
0421 int hfs_find_init(struct hfs_btree *tree, struct hfs_find_data *fd);
0422 void hfs_find_exit(struct hfs_find_data *fd);
0423 int hfs_find_1st_rec_by_cnid(struct hfs_bnode *bnode, struct hfs_find_data *fd,
0424                  int *begin, int *end, int *cur_rec);
0425 int hfs_find_rec_by_key(struct hfs_bnode *bnode, struct hfs_find_data *fd,
0426             int *begin, int *end, int *cur_rec);
0427 int __hfs_brec_find(struct hfs_bnode *bnode, struct hfs_find_data *fd,
0428             search_strategy_t rec_found);
0429 int hfs_brec_find(struct hfs_find_data *fd, search_strategy_t do_key_compare);
0430 int hfs_brec_read(struct hfs_find_data *fd, void *rec, int rec_len);
0431 int hfs_brec_goto(struct hfs_find_data *fd, int cnt);
0432 
0433 /* catalog.c */
0434 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key *k1,
0435                  const hfsplus_btree_key *k2);
0436 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key *k1,
0437                 const hfsplus_btree_key *k2);
0438 int hfsplus_cat_build_key(struct super_block *sb, hfsplus_btree_key *key,
0439                u32 parent, const struct qstr *str);
0440 void hfsplus_cat_build_key_with_cnid(struct super_block *sb,
0441                      hfsplus_btree_key *key, u32 parent);
0442 void hfsplus_cat_set_perms(struct inode *inode, struct hfsplus_perm *perms);
0443 int hfsplus_find_cat(struct super_block *sb, u32 cnid,
0444              struct hfs_find_data *fd);
0445 int hfsplus_create_cat(u32 cnid, struct inode *dir, const struct qstr *str,
0446                struct inode *inode);
0447 int hfsplus_delete_cat(u32 cnid, struct inode *dir, const struct qstr *str);
0448 int hfsplus_rename_cat(u32 cnid, struct inode *src_dir, const struct qstr *src_name,
0449                struct inode *dst_dir, const struct qstr *dst_name);
0450 
0451 /* dir.c */
0452 extern const struct inode_operations hfsplus_dir_inode_operations;
0453 extern const struct file_operations hfsplus_dir_operations;
0454 
0455 /* extents.c */
0456 int hfsplus_ext_cmp_key(const hfsplus_btree_key *k1,
0457             const hfsplus_btree_key *k2);
0458 int hfsplus_ext_write_extent(struct inode *inode);
0459 int hfsplus_get_block(struct inode *inode, sector_t iblock,
0460               struct buffer_head *bh_result, int create);
0461 int hfsplus_free_fork(struct super_block *sb, u32 cnid,
0462               struct hfsplus_fork_raw *fork, int type);
0463 int hfsplus_file_extend(struct inode *inode, bool zeroout);
0464 void hfsplus_file_truncate(struct inode *inode);
0465 
0466 /* inode.c */
0467 extern const struct address_space_operations hfsplus_aops;
0468 extern const struct address_space_operations hfsplus_btree_aops;
0469 extern const struct dentry_operations hfsplus_dentry_operations;
0470 
0471 int hfsplus_write_begin(struct file *file, struct address_space *mapping,
0472         loff_t pos, unsigned len, struct page **pagep, void **fsdata);
0473 struct inode *hfsplus_new_inode(struct super_block *sb, struct inode *dir,
0474                 umode_t mode);
0475 void hfsplus_delete_inode(struct inode *inode);
0476 void hfsplus_inode_read_fork(struct inode *inode,
0477                  struct hfsplus_fork_raw *fork);
0478 void hfsplus_inode_write_fork(struct inode *inode,
0479                   struct hfsplus_fork_raw *fork);
0480 int hfsplus_cat_read_inode(struct inode *inode, struct hfs_find_data *fd);
0481 int hfsplus_cat_write_inode(struct inode *inode);
0482 int hfsplus_getattr(struct user_namespace *mnt_userns, const struct path *path,
0483             struct kstat *stat, u32 request_mask,
0484             unsigned int query_flags);
0485 int hfsplus_file_fsync(struct file *file, loff_t start, loff_t end,
0486                int datasync);
0487 int hfsplus_fileattr_get(struct dentry *dentry, struct fileattr *fa);
0488 int hfsplus_fileattr_set(struct user_namespace *mnt_userns,
0489              struct dentry *dentry, struct fileattr *fa);
0490 
0491 /* ioctl.c */
0492 long hfsplus_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
0493 
0494 /* options.c */
0495 void hfsplus_fill_defaults(struct hfsplus_sb_info *opts);
0496 int hfsplus_parse_options_remount(char *input, int *force);
0497 int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi);
0498 int hfsplus_show_options(struct seq_file *seq, struct dentry *root);
0499 
0500 /* part_tbl.c */
0501 int hfs_part_find(struct super_block *sb, sector_t *part_start,
0502           sector_t *part_size);
0503 
0504 /* super.c */
0505 struct inode *hfsplus_iget(struct super_block *sb, unsigned long ino);
0506 void hfsplus_mark_mdb_dirty(struct super_block *sb);
0507 
0508 /* tables.c */
0509 extern u16 hfsplus_case_fold_table[];
0510 extern u16 hfsplus_decompose_table[];
0511 extern u16 hfsplus_compose_table[];
0512 
0513 /* unicode.c */
0514 int hfsplus_strcasecmp(const struct hfsplus_unistr *s1,
0515                const struct hfsplus_unistr *s2);
0516 int hfsplus_strcmp(const struct hfsplus_unistr *s1,
0517            const struct hfsplus_unistr *s2);
0518 int hfsplus_uni2asc(struct super_block *sb, const struct hfsplus_unistr *ustr,
0519             char *astr, int *len_p);
0520 int hfsplus_asc2uni(struct super_block *sb, struct hfsplus_unistr *ustr,
0521             int max_unistr_len, const char *astr, int len);
0522 int hfsplus_hash_dentry(const struct dentry *dentry, struct qstr *str);
0523 int hfsplus_compare_dentry(const struct dentry *dentry, unsigned int len,
0524                const char *str, const struct qstr *name);
0525 
0526 /* wrapper.c */
0527 int hfsplus_submit_bio(struct super_block *sb, sector_t sector, void *buf,
0528                void **data, blk_opf_t opf);
0529 int hfsplus_read_wrapper(struct super_block *sb);
0530 
0531 /*
0532  * time helpers: convert between 1904-base and 1970-base timestamps
0533  *
0534  * HFS+ implementations are highly inconsistent, this one matches the
0535  * traditional behavior of 64-bit Linux, giving the most useful
0536  * time range between 1970 and 2106, by treating any on-disk timestamp
0537  * under HFSPLUS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
0538  */
0539 #define HFSPLUS_UTC_OFFSET 2082844800U
0540 
0541 static inline time64_t __hfsp_mt2ut(__be32 mt)
0542 {
0543     time64_t ut = (u32)(be32_to_cpu(mt) - HFSPLUS_UTC_OFFSET);
0544 
0545     return ut;
0546 }
0547 
0548 static inline __be32 __hfsp_ut2mt(time64_t ut)
0549 {
0550     return cpu_to_be32(lower_32_bits(ut) + HFSPLUS_UTC_OFFSET);
0551 }
0552 
0553 /* compatibility */
0554 #define hfsp_mt2ut(t)       (struct timespec64){ .tv_sec = __hfsp_mt2ut(t) }
0555 #define hfsp_ut2mt(t)       __hfsp_ut2mt((t).tv_sec)
0556 #define hfsp_now2mt()       __hfsp_ut2mt(ktime_get_real_seconds())
0557 
0558 #endif