^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * linux/fs/hfs/hfs_fs.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 1995-1997 Paul H. Hargrove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) 2003 Ardis Technologies <roman@ardistech.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This file may be distributed under the terms of the GNU General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #ifndef _LINUX_HFS_FS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define _LINUX_HFS_FS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifdef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "hfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define DBG_BNODE_REFS 0x00000001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define DBG_BNODE_MOD 0x00000002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define DBG_CAT_MOD 0x00000004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DBG_INODE 0x00000008
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define DBG_SUPER 0x00000010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define DBG_EXTENT 0x00000020
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define DBG_BITMAP 0x00000040
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) //#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD|DBG_CAT_MOD|DBG_BITMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) //#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) //#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define DBG_MASK (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define hfs_dbg(flg, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) if (DBG_##flg & DBG_MASK) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define hfs_dbg_cont(flg, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) do { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (DBG_##flg & DBG_MASK) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) pr_cont(fmt, ##__VA_ARGS__); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * struct hfs_inode_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * The HFS-specific part of a Linux (struct inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct hfs_inode_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) atomic_t opencnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* to deal with localtime ugliness */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) int tz_secondswest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct hfs_cat_key cat_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct list_head open_dir_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) spinlock_t open_dir_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct inode *rsrc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct mutex extents_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) u16 alloc_blocks, clump_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) sector_t fs_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* Allocation extents from catlog record or volume header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) hfs_extent_rec first_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) u16 first_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) hfs_extent_rec cached_extents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) u16 cached_start, cached_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) loff_t phys_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct inode vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define HFS_FLG_RSRC 0x0001
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #define HFS_FLG_EXT_DIRTY 0x0002
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define HFS_FLG_EXT_NEW 0x0004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) #define HFS_IS_RSRC(inode) (HFS_I(inode)->flags & HFS_FLG_RSRC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * struct hfs_sb_info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * The HFS-specific part of a Linux (struct super_block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct hfs_sb_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct buffer_head *mdb_bh; /* The hfs_buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) holding the real
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) superblock (aka VIB
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) or MDB) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct hfs_mdb *mdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct buffer_head *alt_mdb_bh; /* The hfs_buffer holding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) the alternate superblock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct hfs_mdb *alt_mdb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) __be32 *bitmap; /* The page holding the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) allocation bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct hfs_btree *ext_tree; /* Information about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) the extents b-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct hfs_btree *cat_tree; /* Information about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) the catalog b-tree */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) u32 file_count; /* The number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) regular files in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) the filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) u32 folder_count; /* The number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) directories in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u32 next_id; /* The next available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) file id number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) u32 clumpablks; /* The number of allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) blocks to try to add when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) extending a file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) u32 fs_start; /* The first 512-byte
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) block represented
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) in the bitmap */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u32 part_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u16 root_files; /* The number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) regular
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) (non-directory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) files in the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u16 root_dirs; /* The number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) directories in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) root directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) u16 fs_ablocks; /* The number of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) allocation blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) in the filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u16 free_ablocks; /* the number of unused
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) allocation blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) in the filesystem */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u32 alloc_blksz; /* The size of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) "allocation block" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) int s_quiet; /* Silent failure when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) changing owner or mode? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) __be32 s_type; /* Type for new files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) __be32 s_creator; /* Creator for new files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) umode_t s_file_umask; /* The umask applied to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) permissions on all files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) umode_t s_dir_umask; /* The umask applied to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) permissions on all dirs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) kuid_t s_uid; /* The uid of all files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) kgid_t s_gid; /* The gid of all files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) int session, part;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct nls_table *nls_io, *nls_disk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct mutex bitmap_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) u16 blockoffset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int fs_div;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int work_queued; /* non-zero delayed work is queued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct delayed_work mdb_work; /* MDB flush delayed work */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) spinlock_t work_lock; /* protects mdb_work and work_queued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) #define HFS_FLG_BITMAP_DIRTY 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) #define HFS_FLG_MDB_DIRTY 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) #define HFS_FLG_ALT_MDB_DIRTY 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* bitmap.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) extern int hfs_clear_vbm_bits(struct super_block *, u16, u16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) /* catalog.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) extern int hfs_cat_keycmp(const btree_key *, const btree_key *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct hfs_find_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) extern int hfs_cat_create(u32, struct inode *, const struct qstr *, struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) extern int hfs_cat_delete(u32, struct inode *, const struct qstr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) extern int hfs_cat_move(u32, struct inode *, const struct qstr *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct inode *, const struct qstr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, const struct qstr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /* dir.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) extern const struct file_operations hfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) extern const struct inode_operations hfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) /* extent.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) extern int hfs_ext_keycmp(const btree_key *, const btree_key *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) extern int hfs_ext_write_extent(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) extern int hfs_extend_file(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) extern void hfs_file_truncate(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* inode.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) extern const struct address_space_operations hfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) extern const struct address_space_operations hfs_btree_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) extern struct inode *hfs_new_inode(struct inode *, const struct qstr *, umode_t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) extern int hfs_write_inode(struct inode *, struct writeback_control *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) extern int hfs_inode_setattr(struct dentry *, struct iattr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) __be32 log_size, __be32 phys_size, u32 clump_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) extern void hfs_evict_inode(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) extern void hfs_delete_inode(struct inode *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* attr.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) extern const struct xattr_handler *hfs_xattr_handlers[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /* mdb.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) extern int hfs_mdb_get(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) extern void hfs_mdb_commit(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) extern void hfs_mdb_close(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) extern void hfs_mdb_put(struct super_block *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* part_tbl.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* string.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) extern const struct dentry_operations hfs_dentry_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) extern int hfs_hash_dentry(const struct dentry *, struct qstr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) extern int hfs_strcmp(const unsigned char *, unsigned int,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) const unsigned char *, unsigned int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) extern int hfs_compare_dentry(const struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) unsigned int len, const char *str, const struct qstr *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) /* trans.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) extern void hfs_asc2mac(struct super_block *, struct hfs_name *, const struct qstr *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* super.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) extern void hfs_mark_mdb_dirty(struct super_block *sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * There are two time systems. Both are based on seconds since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * a particular time/date.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * Unix: signed little-endian since 00:00 GMT, Jan. 1, 1970
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * HFS implementations are highly inconsistent, this one matches the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * traditional behavior of 64-bit Linux, giving the most useful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * time range between 1970 and 2106, by treating any on-disk timestamp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * under HFS_UTC_OFFSET (Jan 1 1970) as a time between 2040 and 2106.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #define HFS_UTC_OFFSET 2082844800U
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static inline time64_t __hfs_m_to_utime(__be32 mt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return ut + sys_tz.tz_minuteswest * 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) static inline __be32 __hfs_u_to_mtime(time64_t ut)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ut -= sys_tz.tz_minuteswest * 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) return cpu_to_be32(lower_32_bits(ut) + HFS_UTC_OFFSET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #define HFS_I(inode) (container_of(inode, struct hfs_inode_info, vfs_inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) #define HFS_SB(sb) ((struct hfs_sb_info *)(sb)->s_fs_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) #define hfs_m_to_utime(time) (struct timespec64){ .tv_sec = __hfs_m_to_utime(time) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #define hfs_u_to_mtime(time) __hfs_u_to_mtime((time).tv_sec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #define hfs_mtime() __hfs_u_to_mtime(ktime_get_real_seconds())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static inline const char *hfs_mdb_name(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return sb->s_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static inline void hfs_bitmap_dirty(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) hfs_mark_mdb_dirty(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define sb_bread512(sb, sec, data) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct buffer_head *__bh; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) sector_t __block; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) loff_t __start; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int __offset; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) __block = __start >> (sb)->s_blocksize_bits; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) __offset = __start & ((sb)->s_blocksize - 1); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) __bh = sb_bread((sb), __block); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (likely(__bh != NULL)) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) data = (void *)(__bh->b_data + __offset);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) else \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) data = NULL; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) __bh; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) #endif