0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LINUX_HFS_FS_H
0010 #define _LINUX_HFS_FS_H
0011
0012 #ifdef pr_fmt
0013 #undef pr_fmt
0014 #endif
0015
0016 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0017
0018 #include <linux/slab.h>
0019 #include <linux/types.h>
0020 #include <linux/mutex.h>
0021 #include <linux/buffer_head.h>
0022 #include <linux/fs.h>
0023 #include <linux/workqueue.h>
0024
0025 #include <asm/byteorder.h>
0026 #include <linux/uaccess.h>
0027
0028 #include "hfs.h"
0029
0030 #define DBG_BNODE_REFS 0x00000001
0031 #define DBG_BNODE_MOD 0x00000002
0032 #define DBG_CAT_MOD 0x00000004
0033 #define DBG_INODE 0x00000008
0034 #define DBG_SUPER 0x00000010
0035 #define DBG_EXTENT 0x00000020
0036 #define DBG_BITMAP 0x00000040
0037
0038
0039
0040
0041 #define DBG_MASK (0)
0042
0043 #define hfs_dbg(flg, fmt, ...) \
0044 do { \
0045 if (DBG_##flg & DBG_MASK) \
0046 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
0047 } while (0)
0048
0049 #define hfs_dbg_cont(flg, fmt, ...) \
0050 do { \
0051 if (DBG_##flg & DBG_MASK) \
0052 pr_cont(fmt, ##__VA_ARGS__); \
0053 } while (0)
0054
0055
0056
0057
0058
0059
0060
0061 struct hfs_inode_info {
0062 atomic_t opencnt;
0063
0064 unsigned int flags;
0065
0066
0067 int tz_secondswest;
0068
0069 struct hfs_cat_key cat_key;
0070
0071 struct list_head open_dir_list;
0072 spinlock_t open_dir_lock;
0073 struct inode *rsrc_inode;
0074
0075 struct mutex extents_lock;
0076
0077 u16 alloc_blocks, clump_blocks;
0078 sector_t fs_blocks;
0079
0080 hfs_extent_rec first_extents;
0081 u16 first_blocks;
0082 hfs_extent_rec cached_extents;
0083 u16 cached_start, cached_blocks;
0084
0085 loff_t phys_size;
0086 struct inode vfs_inode;
0087 };
0088
0089 #define HFS_FLG_RSRC 0x0001
0090 #define HFS_FLG_EXT_DIRTY 0x0002
0091 #define HFS_FLG_EXT_NEW 0x0004
0092
0093 #define HFS_IS_RSRC(inode) (HFS_I(inode)->flags & HFS_FLG_RSRC)
0094
0095
0096
0097
0098
0099
0100 struct hfs_sb_info {
0101 struct buffer_head *mdb_bh;
0102
0103
0104
0105 struct hfs_mdb *mdb;
0106 struct buffer_head *alt_mdb_bh;
0107
0108 struct hfs_mdb *alt_mdb;
0109 __be32 *bitmap;
0110
0111 struct hfs_btree *ext_tree;
0112
0113 struct hfs_btree *cat_tree;
0114
0115 u32 file_count;
0116
0117
0118 u32 folder_count;
0119
0120
0121 u32 next_id;
0122
0123 u32 clumpablks;
0124
0125
0126 u32 fs_start;
0127
0128
0129 u32 part_start;
0130 u16 root_files;
0131
0132
0133
0134
0135 u16 root_dirs;
0136
0137
0138 u16 fs_ablocks;
0139
0140
0141 u16 free_ablocks;
0142
0143
0144 u32 alloc_blksz;
0145
0146 int s_quiet;
0147
0148 __be32 s_type;
0149 __be32 s_creator;
0150 umode_t s_file_umask;
0151
0152 umode_t s_dir_umask;
0153
0154 kuid_t s_uid;
0155 kgid_t s_gid;
0156
0157 int session, part;
0158 struct nls_table *nls_io, *nls_disk;
0159 struct mutex bitmap_lock;
0160 unsigned long flags;
0161 u16 blockoffset;
0162 int fs_div;
0163 struct super_block *sb;
0164 int work_queued;
0165 struct delayed_work mdb_work;
0166 spinlock_t work_lock;
0167 };
0168
0169 #define HFS_FLG_BITMAP_DIRTY 0
0170 #define HFS_FLG_MDB_DIRTY 1
0171 #define HFS_FLG_ALT_MDB_DIRTY 2
0172
0173
0174 extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *);
0175 extern int hfs_clear_vbm_bits(struct super_block *, u16, u16);
0176
0177
0178 extern int hfs_cat_keycmp(const btree_key *, const btree_key *);
0179 struct hfs_find_data;
0180 extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *);
0181 extern int hfs_cat_create(u32, struct inode *, const struct qstr *, struct inode *);
0182 extern int hfs_cat_delete(u32, struct inode *, const struct qstr *);
0183 extern int hfs_cat_move(u32, struct inode *, const struct qstr *,
0184 struct inode *, const struct qstr *);
0185 extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, const struct qstr *);
0186
0187
0188 extern const struct file_operations hfs_dir_operations;
0189 extern const struct inode_operations hfs_dir_inode_operations;
0190
0191
0192 extern int hfs_ext_keycmp(const btree_key *, const btree_key *);
0193 extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int);
0194 extern int hfs_ext_write_extent(struct inode *);
0195 extern int hfs_extend_file(struct inode *);
0196 extern void hfs_file_truncate(struct inode *);
0197
0198 extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
0199
0200
0201 extern const struct address_space_operations hfs_aops;
0202 extern const struct address_space_operations hfs_btree_aops;
0203
0204 int hfs_write_begin(struct file *file, struct address_space *mapping,
0205 loff_t pos, unsigned len, struct page **pagep, void **fsdata);
0206 extern struct inode *hfs_new_inode(struct inode *, const struct qstr *, umode_t);
0207 extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *);
0208 extern int hfs_write_inode(struct inode *, struct writeback_control *);
0209 extern int hfs_inode_setattr(struct user_namespace *, struct dentry *,
0210 struct iattr *);
0211 extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
0212 __be32 log_size, __be32 phys_size, u32 clump_size);
0213 extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *);
0214 extern void hfs_evict_inode(struct inode *);
0215 extern void hfs_delete_inode(struct inode *);
0216
0217
0218 extern const struct xattr_handler *hfs_xattr_handlers[];
0219
0220
0221 extern int hfs_mdb_get(struct super_block *);
0222 extern void hfs_mdb_commit(struct super_block *);
0223 extern void hfs_mdb_close(struct super_block *);
0224 extern void hfs_mdb_put(struct super_block *);
0225
0226
0227 extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
0228
0229
0230 extern const struct dentry_operations hfs_dentry_operations;
0231
0232 extern int hfs_hash_dentry(const struct dentry *, struct qstr *);
0233 extern int hfs_strcmp(const unsigned char *, unsigned int,
0234 const unsigned char *, unsigned int);
0235 extern int hfs_compare_dentry(const struct dentry *dentry,
0236 unsigned int len, const char *str, const struct qstr *name);
0237
0238
0239 extern void hfs_asc2mac(struct super_block *, struct hfs_name *, const struct qstr *);
0240 extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *);
0241
0242
0243 extern void hfs_mark_mdb_dirty(struct super_block *sb);
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256 #define HFS_UTC_OFFSET 2082844800U
0257
0258 static inline time64_t __hfs_m_to_utime(__be32 mt)
0259 {
0260 time64_t ut = (u32)(be32_to_cpu(mt) - HFS_UTC_OFFSET);
0261
0262 return ut + sys_tz.tz_minuteswest * 60;
0263 }
0264
0265 static inline __be32 __hfs_u_to_mtime(time64_t ut)
0266 {
0267 ut -= sys_tz.tz_minuteswest * 60;
0268
0269 return cpu_to_be32(lower_32_bits(ut) + HFS_UTC_OFFSET);
0270 }
0271 #define HFS_I(inode) (container_of(inode, struct hfs_inode_info, vfs_inode))
0272 #define HFS_SB(sb) ((struct hfs_sb_info *)(sb)->s_fs_info)
0273
0274 #define hfs_m_to_utime(time) (struct timespec64){ .tv_sec = __hfs_m_to_utime(time) }
0275 #define hfs_u_to_mtime(time) __hfs_u_to_mtime((time).tv_sec)
0276 #define hfs_mtime() __hfs_u_to_mtime(ktime_get_real_seconds())
0277
0278 static inline const char *hfs_mdb_name(struct super_block *sb)
0279 {
0280 return sb->s_id;
0281 }
0282
0283 static inline void hfs_bitmap_dirty(struct super_block *sb)
0284 {
0285 set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
0286 hfs_mark_mdb_dirty(sb);
0287 }
0288
0289 #define sb_bread512(sb, sec, data) ({ \
0290 struct buffer_head *__bh; \
0291 sector_t __block; \
0292 loff_t __start; \
0293 int __offset; \
0294 \
0295 __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
0296 __block = __start >> (sb)->s_blocksize_bits; \
0297 __offset = __start & ((sb)->s_blocksize - 1); \
0298 __bh = sb_bread((sb), __block); \
0299 if (likely(__bh != NULL)) \
0300 data = (void *)(__bh->b_data + __offset);\
0301 else \
0302 data = NULL; \
0303 __bh; \
0304 })
0305
0306 #endif