2 * linux/include/linux/hfsplus_fs.h
5 * Brad Boyer (flar@pants.nu)
6 * (C) 2003 Ardis Technologies <roman@ardistech.com>
10 #ifndef _LINUX_HFSPLUS_FS_H
11 #define _LINUX_HFSPLUS_FS_H
14 #include <linux/mutex.h>
15 #include <linux/buffer_head.h>
16 #include "hfsplus_raw.h"
18 #define DBG_BNODE_REFS 0x00000001
19 #define DBG_BNODE_MOD 0x00000002
20 #define DBG_CAT_MOD 0x00000004
21 #define DBG_INODE 0x00000008
22 #define DBG_SUPER 0x00000010
23 #define DBG_EXTENT 0x00000020
24 #define DBG_BITMAP 0x00000040
26 //#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD)
27 //#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
28 //#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
31 #define dprint(flg, fmt, args...) \
32 if (flg & DBG_MASK) printk(fmt , ## args)
34 /* Runtime config options */
35 #define HFSPLUS_DEF_CR_TYPE 0x3F3F3F3F /* '????' */
37 #define HFSPLUS_TYPE_DATA 0x00
38 #define HFSPLUS_TYPE_RSRC 0xFF
40 typedef int (*btree_keycmp
)(const hfsplus_btree_key
*, const hfsplus_btree_key
*);
42 #define NODE_HASH_SIZE 256
44 /* An HFS+ BTree held in memory */
46 struct super_block
*sb
;
59 unsigned int node_size
;
60 unsigned int node_size_shift
;
61 unsigned int max_key_len
;
64 //unsigned int map1_size, map_size;
65 struct mutex tree_lock
;
67 unsigned int pages_per_bnode
;
69 struct hfs_bnode
*node_hash
[NODE_HASH_SIZE
];
75 /* An HFS+ BTree node in memory */
77 struct hfs_btree
*tree
;
88 struct hfs_bnode
*next_hash
;
90 wait_queue_head_t lock_wq
;
92 unsigned int page_offset
;
96 #define HFS_BNODE_LOCK 0
97 #define HFS_BNODE_ERROR 1
98 #define HFS_BNODE_NEW 2
99 #define HFS_BNODE_DIRTY 3
100 #define HFS_BNODE_DELETED 4
103 * HFS+ superblock info (built from Volume Header on disk)
109 struct hfsplus_sb_info
{
110 struct buffer_head
*s_vhbh
;
111 struct hfsplus_vh
*s_vhdr
;
112 struct hfs_btree
*ext_tree
;
113 struct hfs_btree
*cat_tree
;
114 struct hfs_btree
*attr_tree
;
115 struct inode
*alloc_file
;
116 struct inode
*hidden_dir
;
117 struct nls_table
*nls
;
119 /* Runtime variables */
124 /* immutable data from the volume header */
126 int alloc_blksz_shift
;
128 u32 data_clump_blocks
, rsrc_clump_blocks
;
130 /* mutable data from the volume header, protected by alloc_mutex */
132 struct mutex alloc_mutex
;
134 /* mutable data from the volume header, protected by vh_mutex */
138 struct mutex vh_mutex
;
153 #define HFSPLUS_SB_WRITEBACKUP 0
154 #define HFSPLUS_SB_NODECOMPOSE 1
155 #define HFSPLUS_SB_FORCE 2
156 #define HFSPLUS_SB_HFSX 3
157 #define HFSPLUS_SB_CASEFOLD 4
160 struct hfsplus_inode_info
{
164 * Extent allocation information, protected by extents_lock.
171 hfsplus_extent_rec first_extents
;
172 hfsplus_extent_rec cached_extents
;
174 struct mutex extents_lock
;
179 struct inode
*rsrc_inode
;
183 * Protected by sbi->vh_mutex.
188 * Protected by i_mutex.
191 u8 userflags
; /* BSD user file flags */
192 struct list_head open_dir_list
;
195 struct inode vfs_inode
;
198 #define HFSPLUS_FLG_RSRC 0x0001
199 #define HFSPLUS_FLG_EXT_DIRTY 0x0002
200 #define HFSPLUS_FLG_EXT_NEW 0x0004
202 #define HFSPLUS_IS_DATA(inode) (!(HFSPLUS_I(inode)->flags & HFSPLUS_FLG_RSRC))
203 #define HFSPLUS_IS_RSRC(inode) (HFSPLUS_I(inode)->flags & HFSPLUS_FLG_RSRC)
205 struct hfs_find_data
{
206 /* filled by caller */
207 hfsplus_btree_key
*search_key
;
208 hfsplus_btree_key
*key
;
210 struct hfs_btree
*tree
;
211 struct hfs_bnode
*bnode
;
212 /* filled by findrec */
214 int keyoffset
, keylength
;
215 int entryoffset
, entrylength
;
218 struct hfsplus_readdir_data
{
219 struct list_head list
;
221 struct hfsplus_cat_key key
;
224 #define hfs_btree_open hfsplus_btree_open
225 #define hfs_btree_close hfsplus_btree_close
226 #define hfs_btree_write hfsplus_btree_write
227 #define hfs_bmap_alloc hfsplus_bmap_alloc
228 #define hfs_bmap_free hfsplus_bmap_free
229 #define hfs_bnode_read hfsplus_bnode_read
230 #define hfs_bnode_read_u16 hfsplus_bnode_read_u16
231 #define hfs_bnode_read_u8 hfsplus_bnode_read_u8
232 #define hfs_bnode_read_key hfsplus_bnode_read_key
233 #define hfs_bnode_write hfsplus_bnode_write
234 #define hfs_bnode_write_u16 hfsplus_bnode_write_u16
235 #define hfs_bnode_clear hfsplus_bnode_clear
236 #define hfs_bnode_copy hfsplus_bnode_copy
237 #define hfs_bnode_move hfsplus_bnode_move
238 #define hfs_bnode_dump hfsplus_bnode_dump
239 #define hfs_bnode_unlink hfsplus_bnode_unlink
240 #define hfs_bnode_findhash hfsplus_bnode_findhash
241 #define hfs_bnode_find hfsplus_bnode_find
242 #define hfs_bnode_unhash hfsplus_bnode_unhash
243 #define hfs_bnode_free hfsplus_bnode_free
244 #define hfs_bnode_create hfsplus_bnode_create
245 #define hfs_bnode_get hfsplus_bnode_get
246 #define hfs_bnode_put hfsplus_bnode_put
247 #define hfs_brec_lenoff hfsplus_brec_lenoff
248 #define hfs_brec_keylen hfsplus_brec_keylen
249 #define hfs_brec_insert hfsplus_brec_insert
250 #define hfs_brec_remove hfsplus_brec_remove
251 #define hfs_find_init hfsplus_find_init
252 #define hfs_find_exit hfsplus_find_exit
253 #define __hfs_brec_find __hplusfs_brec_find
254 #define hfs_brec_find hfsplus_brec_find
255 #define hfs_brec_read hfsplus_brec_read
256 #define hfs_brec_goto hfsplus_brec_goto
257 #define hfs_part_find hfsplus_part_find
260 * definitions for ext2 flag ioctls (linux really needs a generic
261 * interface for this).
264 /* ext2 ioctls (EXT2_IOC_GETFLAGS and EXT2_IOC_SETFLAGS) to support
266 #define HFSPLUS_IOC_EXT2_GETFLAGS FS_IOC_GETFLAGS
267 #define HFSPLUS_IOC_EXT2_SETFLAGS FS_IOC_SETFLAGS
271 * Functions in any *.c used in other files
275 int hfsplus_block_allocate(struct super_block
*, u32
, u32
, u32
*);
276 int hfsplus_block_free(struct super_block
*, u32
, u32
);
279 struct hfs_btree
*hfs_btree_open(struct super_block
*, u32
);
280 void hfs_btree_close(struct hfs_btree
*);
281 void hfs_btree_write(struct hfs_btree
*);
282 struct hfs_bnode
*hfs_bmap_alloc(struct hfs_btree
*);
283 void hfs_bmap_free(struct hfs_bnode
*);
286 void hfs_bnode_read(struct hfs_bnode
*, void *, int, int);
287 u16
hfs_bnode_read_u16(struct hfs_bnode
*, int);
288 u8
hfs_bnode_read_u8(struct hfs_bnode
*, int);
289 void hfs_bnode_read_key(struct hfs_bnode
*, void *, int);
290 void hfs_bnode_write(struct hfs_bnode
*, void *, int, int);
291 void hfs_bnode_write_u16(struct hfs_bnode
*, int, u16
);
292 void hfs_bnode_clear(struct hfs_bnode
*, int, int);
293 void hfs_bnode_copy(struct hfs_bnode
*, int,
294 struct hfs_bnode
*, int, int);
295 void hfs_bnode_move(struct hfs_bnode
*, int, int, int);
296 void hfs_bnode_dump(struct hfs_bnode
*);
297 void hfs_bnode_unlink(struct hfs_bnode
*);
298 struct hfs_bnode
*hfs_bnode_findhash(struct hfs_btree
*, u32
);
299 struct hfs_bnode
*hfs_bnode_find(struct hfs_btree
*, u32
);
300 void hfs_bnode_unhash(struct hfs_bnode
*);
301 void hfs_bnode_free(struct hfs_bnode
*);
302 struct hfs_bnode
*hfs_bnode_create(struct hfs_btree
*, u32
);
303 void hfs_bnode_get(struct hfs_bnode
*);
304 void hfs_bnode_put(struct hfs_bnode
*);
307 u16
hfs_brec_lenoff(struct hfs_bnode
*, u16
, u16
*);
308 u16
hfs_brec_keylen(struct hfs_bnode
*, u16
);
309 int hfs_brec_insert(struct hfs_find_data
*, void *, int);
310 int hfs_brec_remove(struct hfs_find_data
*);
313 int hfs_find_init(struct hfs_btree
*, struct hfs_find_data
*);
314 void hfs_find_exit(struct hfs_find_data
*);
315 int __hfs_brec_find(struct hfs_bnode
*, struct hfs_find_data
*);
316 int hfs_brec_find(struct hfs_find_data
*);
317 int hfs_brec_read(struct hfs_find_data
*, void *, int);
318 int hfs_brec_goto(struct hfs_find_data
*, int);
321 int hfsplus_cat_case_cmp_key(const hfsplus_btree_key
*, const hfsplus_btree_key
*);
322 int hfsplus_cat_bin_cmp_key(const hfsplus_btree_key
*, const hfsplus_btree_key
*);
323 void hfsplus_cat_build_key(struct super_block
*sb
, hfsplus_btree_key
*, u32
, struct qstr
*);
324 int hfsplus_find_cat(struct super_block
*, u32
, struct hfs_find_data
*);
325 int hfsplus_create_cat(u32
, struct inode
*, struct qstr
*, struct inode
*);
326 int hfsplus_delete_cat(u32
, struct inode
*, struct qstr
*);
327 int hfsplus_rename_cat(u32
, struct inode
*, struct qstr
*,
328 struct inode
*, struct qstr
*);
329 void hfsplus_cat_set_perms(struct inode
*inode
, struct hfsplus_perm
*perms
);
332 extern const struct inode_operations hfsplus_dir_inode_operations
;
333 extern const struct file_operations hfsplus_dir_operations
;
336 int hfsplus_ext_cmp_key(const hfsplus_btree_key
*, const hfsplus_btree_key
*);
337 void hfsplus_ext_write_extent(struct inode
*);
338 int hfsplus_get_block(struct inode
*, sector_t
, struct buffer_head
*, int);
339 int hfsplus_free_fork(struct super_block
*, u32
, struct hfsplus_fork_raw
*, int);
340 int hfsplus_file_extend(struct inode
*);
341 void hfsplus_file_truncate(struct inode
*);
344 extern const struct address_space_operations hfsplus_aops
;
345 extern const struct address_space_operations hfsplus_btree_aops
;
346 extern const struct dentry_operations hfsplus_dentry_operations
;
348 void hfsplus_inode_read_fork(struct inode
*, struct hfsplus_fork_raw
*);
349 void hfsplus_inode_write_fork(struct inode
*, struct hfsplus_fork_raw
*);
350 int hfsplus_cat_read_inode(struct inode
*, struct hfs_find_data
*);
351 int hfsplus_cat_write_inode(struct inode
*);
352 struct inode
*hfsplus_new_inode(struct super_block
*, int);
353 void hfsplus_delete_inode(struct inode
*);
356 long hfsplus_ioctl(struct file
*filp
, unsigned int cmd
, unsigned long arg
);
357 int hfsplus_setxattr(struct dentry
*dentry
, const char *name
,
358 const void *value
, size_t size
, int flags
);
359 ssize_t
hfsplus_getxattr(struct dentry
*dentry
, const char *name
,
360 void *value
, size_t size
);
361 ssize_t
hfsplus_listxattr(struct dentry
*dentry
, char *buffer
, size_t size
);
364 int hfsplus_parse_options(char *, struct hfsplus_sb_info
*);
365 void hfsplus_fill_defaults(struct hfsplus_sb_info
*);
366 int hfsplus_show_options(struct seq_file
*, struct vfsmount
*);
369 struct inode
*hfsplus_iget(struct super_block
*, unsigned long);
370 int hfsplus_sync_fs(struct super_block
*sb
, int wait
);
373 extern u16 hfsplus_case_fold_table
[];
374 extern u16 hfsplus_decompose_table
[];
375 extern u16 hfsplus_compose_table
[];
378 int hfsplus_strcasecmp(const struct hfsplus_unistr
*, const struct hfsplus_unistr
*);
379 int hfsplus_strcmp(const struct hfsplus_unistr
*, const struct hfsplus_unistr
*);
380 int hfsplus_uni2asc(struct super_block
*, const struct hfsplus_unistr
*, char *, int *);
381 int hfsplus_asc2uni(struct super_block
*, struct hfsplus_unistr
*, const char *, int);
382 int hfsplus_hash_dentry(struct dentry
*dentry
, struct qstr
*str
);
383 int hfsplus_compare_dentry(struct dentry
*dentry
, struct qstr
*s1
, struct qstr
*s2
);
386 int hfsplus_read_wrapper(struct super_block
*);
388 int hfs_part_find(struct super_block
*, sector_t
*, sector_t
*);
391 static inline struct hfsplus_sb_info
*HFSPLUS_SB(struct super_block
*sb
)
393 return sb
->s_fs_info
;
396 static inline struct hfsplus_inode_info
*HFSPLUS_I(struct inode
*inode
)
398 return list_entry(inode
, struct hfsplus_inode_info
, vfs_inode
);
401 #define sb_bread512(sb, sec, data) ({ \
402 struct buffer_head *__bh; \
407 __start = (loff_t)(sec) << HFSPLUS_SECTOR_SHIFT;\
408 __block = __start >> (sb)->s_blocksize_bits; \
409 __offset = __start & ((sb)->s_blocksize - 1); \
410 __bh = sb_bread((sb), __block); \
411 if (likely(__bh != NULL)) \
412 data = (void *)(__bh->b_data + __offset);\
419 #define __hfsp_mt2ut(t) (be32_to_cpu(t) - 2082844800U)
420 #define __hfsp_ut2mt(t) (cpu_to_be32(t + 2082844800U))
423 #define hfsp_mt2ut(t) (struct timespec){ .tv_sec = __hfsp_mt2ut(t) }
424 #define hfsp_ut2mt(t) __hfsp_ut2mt((t).tv_sec)
425 #define hfsp_now2mt() __hfsp_ut2mt(get_seconds())