1
2
3
4
5
6
7
8
9#ifndef _LINUX_HFS_FS_H
10#define _LINUX_HFS_FS_H
11
12#ifdef pr_fmt
13#undef pr_fmt
14#endif
15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/slab.h>
19#include <linux/types.h>
20#include <linux/mutex.h>
21#include <linux/buffer_head.h>
22#include <linux/fs.h>
23#include <linux/workqueue.h>
24
25#include <asm/byteorder.h>
26#include <asm/uaccess.h>
27
28#include "hfs.h"
29
30#define DBG_BNODE_REFS 0x00000001
31#define DBG_BNODE_MOD 0x00000002
32#define DBG_CAT_MOD 0x00000004
33#define DBG_INODE 0x00000008
34#define DBG_SUPER 0x00000010
35#define DBG_EXTENT 0x00000020
36#define DBG_BITMAP 0x00000040
37
38
39
40
41#define DBG_MASK (0)
42
43#define hfs_dbg(flg, fmt, ...) \
44do { \
45 if (DBG_##flg & DBG_MASK) \
46 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
47} while (0)
48
49#define hfs_dbg_cont(flg, fmt, ...) \
50do { \
51 if (DBG_##flg & DBG_MASK) \
52 pr_cont(fmt, ##__VA_ARGS__); \
53} while (0)
54
55
56
57
58
59
60
61struct hfs_inode_info {
62 atomic_t opencnt;
63
64 unsigned int flags;
65
66
67 int tz_secondswest;
68
69 struct hfs_cat_key cat_key;
70
71 struct list_head open_dir_list;
72 struct inode *rsrc_inode;
73
74 struct mutex extents_lock;
75
76 u16 alloc_blocks, clump_blocks;
77 sector_t fs_blocks;
78
79 hfs_extent_rec first_extents;
80 u16 first_blocks;
81 hfs_extent_rec cached_extents;
82 u16 cached_start, cached_blocks;
83
84 loff_t phys_size;
85 struct inode vfs_inode;
86};
87
88#define HFS_FLG_RSRC 0x0001
89#define HFS_FLG_EXT_DIRTY 0x0002
90#define HFS_FLG_EXT_NEW 0x0004
91
92#define HFS_IS_RSRC(inode) (HFS_I(inode)->flags & HFS_FLG_RSRC)
93
94
95
96
97
98
99struct hfs_sb_info {
100 struct buffer_head *mdb_bh;
101
102
103
104 struct hfs_mdb *mdb;
105 struct buffer_head *alt_mdb_bh;
106
107 struct hfs_mdb *alt_mdb;
108 __be32 *bitmap;
109
110 struct hfs_btree *ext_tree;
111
112 struct hfs_btree *cat_tree;
113
114 u32 file_count;
115
116
117 u32 folder_count;
118
119
120 u32 next_id;
121
122 u32 clumpablks;
123
124
125 u32 fs_start;
126
127
128 u32 part_start;
129 u16 root_files;
130
131
132
133
134 u16 root_dirs;
135
136
137 u16 fs_ablocks;
138
139
140 u16 free_ablocks;
141
142
143 u32 alloc_blksz;
144
145 int s_quiet;
146
147 __be32 s_type;
148 __be32 s_creator;
149 umode_t s_file_umask;
150
151 umode_t s_dir_umask;
152
153 kuid_t s_uid;
154 kgid_t s_gid;
155
156 int session, part;
157 struct nls_table *nls_io, *nls_disk;
158 struct mutex bitmap_lock;
159 unsigned long flags;
160 u16 blockoffset;
161 int fs_div;
162 struct super_block *sb;
163 int work_queued;
164 struct delayed_work mdb_work;
165 spinlock_t work_lock;
166};
167
168#define HFS_FLG_BITMAP_DIRTY 0
169#define HFS_FLG_MDB_DIRTY 1
170#define HFS_FLG_ALT_MDB_DIRTY 2
171
172
173extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *);
174extern int hfs_clear_vbm_bits(struct super_block *, u16, u16);
175
176
177extern int hfs_cat_keycmp(const btree_key *, const btree_key *);
178struct hfs_find_data;
179extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *);
180extern int hfs_cat_create(u32, struct inode *, struct qstr *, struct inode *);
181extern int hfs_cat_delete(u32, struct inode *, struct qstr *);
182extern int hfs_cat_move(u32, struct inode *, struct qstr *,
183 struct inode *, struct qstr *);
184extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, struct qstr *);
185
186
187extern const struct file_operations hfs_dir_operations;
188extern const struct inode_operations hfs_dir_inode_operations;
189
190
191extern int hfs_ext_keycmp(const btree_key *, const btree_key *);
192extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int);
193extern int hfs_ext_write_extent(struct inode *);
194extern int hfs_extend_file(struct inode *);
195extern void hfs_file_truncate(struct inode *);
196
197extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
198
199
200extern const struct address_space_operations hfs_aops;
201extern const struct address_space_operations hfs_btree_aops;
202
203extern struct inode *hfs_new_inode(struct inode *, struct qstr *, umode_t);
204extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *);
205extern int hfs_write_inode(struct inode *, struct writeback_control *);
206extern int hfs_inode_setattr(struct dentry *, struct iattr *);
207extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
208 __be32 log_size, __be32 phys_size, u32 clump_size);
209extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *);
210extern void hfs_evict_inode(struct inode *);
211extern void hfs_delete_inode(struct inode *);
212
213
214extern int hfs_setxattr(struct dentry *dentry, const char *name,
215 const void *value, size_t size, int flags);
216extern ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
217 void *value, size_t size);
218extern ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
219
220
221extern int hfs_mdb_get(struct super_block *);
222extern void hfs_mdb_commit(struct super_block *);
223extern void hfs_mdb_close(struct super_block *);
224extern void hfs_mdb_put(struct super_block *);
225
226
227extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
228
229
230extern const struct dentry_operations hfs_dentry_operations;
231
232extern int hfs_hash_dentry(const struct dentry *, struct qstr *);
233extern int hfs_strcmp(const unsigned char *, unsigned int,
234 const unsigned char *, unsigned int);
235extern int hfs_compare_dentry(const struct dentry *parent, const struct dentry *dentry,
236 unsigned int len, const char *str, const struct qstr *name);
237
238
239extern void hfs_asc2mac(struct super_block *, struct hfs_name *, struct qstr *);
240extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *);
241
242
243extern void hfs_mark_mdb_dirty(struct super_block *sb);
244
245extern struct timezone sys_tz;
246
247
248
249
250
251
252
253
254#define __hfs_u_to_mtime(sec) cpu_to_be32(sec + 2082844800U - sys_tz.tz_minuteswest * 60)
255#define __hfs_m_to_utime(sec) (be32_to_cpu(sec) - 2082844800U + sys_tz.tz_minuteswest * 60)
256
257#define HFS_I(inode) (list_entry(inode, struct hfs_inode_info, vfs_inode))
258#define HFS_SB(sb) ((struct hfs_sb_info *)(sb)->s_fs_info)
259
260#define hfs_m_to_utime(time) (struct timespec){ .tv_sec = __hfs_m_to_utime(time) }
261#define hfs_u_to_mtime(time) __hfs_u_to_mtime((time).tv_sec)
262#define hfs_mtime() __hfs_u_to_mtime(get_seconds())
263
264static inline const char *hfs_mdb_name(struct super_block *sb)
265{
266 return sb->s_id;
267}
268
269static inline void hfs_bitmap_dirty(struct super_block *sb)
270{
271 set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
272 hfs_mark_mdb_dirty(sb);
273}
274
275#define sb_bread512(sb, sec, data) ({ \
276 struct buffer_head *__bh; \
277 sector_t __block; \
278 loff_t __start; \
279 int __offset; \
280 \
281 __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
282 __block = __start >> (sb)->s_blocksize_bits; \
283 __offset = __start & ((sb)->s_blocksize - 1); \
284 __bh = sb_bread((sb), __block); \
285 if (likely(__bh != NULL)) \
286 data = (void *)(__bh->b_data + __offset);\
287 else \
288 data = NULL; \
289 __bh; \
290})
291
292#endif
293