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