blob: 4f55651aaa51e888e6c6dbcb19b78384e20caa61 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/slab.h>
13#include <linux/types.h>
Matthias Kaehlcke3084b722008-07-25 01:46:34 -070014#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/buffer_head.h>
16#include <linux/fs.h>
17
18#include <asm/byteorder.h>
19#include <asm/uaccess.h>
20
21#include "hfs.h"
22
23#define DBG_BNODE_REFS 0x00000001
24#define DBG_BNODE_MOD 0x00000002
25#define DBG_CAT_MOD 0x00000004
26#define DBG_INODE 0x00000008
27#define DBG_SUPER 0x00000010
28#define DBG_EXTENT 0x00000020
29#define DBG_BITMAP 0x00000040
30
31//#define DBG_MASK (DBG_EXTENT|DBG_INODE|DBG_BNODE_MOD|DBG_CAT_MOD|DBG_BITMAP)
32//#define DBG_MASK (DBG_BNODE_MOD|DBG_CAT_MOD|DBG_INODE)
33//#define DBG_MASK (DBG_CAT_MOD|DBG_BNODE_REFS|DBG_INODE|DBG_EXTENT)
34#define DBG_MASK (0)
35
36#define dprint(flg, fmt, args...) \
37 if (flg & DBG_MASK) printk(fmt , ## args)
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/*
40 * struct hfs_inode_info
41 *
42 * The HFS-specific part of a Linux (struct inode)
43 */
44struct hfs_inode_info {
45 atomic_t opencnt;
46
47 unsigned int flags;
48
49 /* to deal with localtime ugliness */
50 int tz_secondswest;
51
52 struct hfs_cat_key cat_key;
53
54 struct list_head open_dir_list;
55 struct inode *rsrc_inode;
56
Matthias Kaehlcke39f8d472008-07-25 01:46:35 -070057 struct mutex extents_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59 u16 alloc_blocks, clump_blocks;
60 sector_t fs_blocks;
61 /* Allocation extents from catlog record or volume header */
62 hfs_extent_rec first_extents;
63 u16 first_blocks;
64 hfs_extent_rec cached_extents;
65 u16 cached_start, cached_blocks;
66
67 loff_t phys_size;
68 struct inode vfs_inode;
69};
70
71#define HFS_FLG_RSRC 0x0001
72#define HFS_FLG_EXT_DIRTY 0x0002
73#define HFS_FLG_EXT_NEW 0x0004
74
75#define HFS_IS_RSRC(inode) (HFS_I(inode)->flags & HFS_FLG_RSRC)
76
77/*
78 * struct hfs_sb_info
79 *
80 * The HFS-specific part of a Linux (struct super_block)
81 */
82struct hfs_sb_info {
83 struct buffer_head *mdb_bh; /* The hfs_buffer
84 holding the real
85 superblock (aka VIB
86 or MDB) */
87 struct hfs_mdb *mdb;
88 struct buffer_head *alt_mdb_bh; /* The hfs_buffer holding
89 the alternate superblock */
90 struct hfs_mdb *alt_mdb;
91 __be32 *bitmap; /* The page holding the
92 allocation bitmap */
93 struct hfs_btree *ext_tree; /* Information about
94 the extents b-tree */
95 struct hfs_btree *cat_tree; /* Information about
96 the catalog b-tree */
97 u32 file_count; /* The number of
98 regular files in
99 the filesystem */
100 u32 folder_count; /* The number of
101 directories in the
102 filesystem */
103 u32 next_id; /* The next available
104 file id number */
105 u32 clumpablks; /* The number of allocation
106 blocks to try to add when
107 extending a file */
108 u32 fs_start; /* The first 512-byte
109 block represented
110 in the bitmap */
111 u32 part_start;
112 u16 root_files; /* The number of
113 regular
114 (non-directory)
115 files in the root
116 directory */
117 u16 root_dirs; /* The number of
118 directories in the
119 root directory */
120 u16 fs_ablocks; /* The number of
121 allocation blocks
122 in the filesystem */
123 u16 free_ablocks; /* the number of unused
124 allocation blocks
125 in the filesystem */
126 u32 alloc_blksz; /* The size of an
127 "allocation block" */
128 int s_quiet; /* Silent failure when
129 changing owner or mode? */
130 __be32 s_type; /* Type for new files */
131 __be32 s_creator; /* Creator for new files */
132 umode_t s_file_umask; /* The umask applied to the
133 permissions on all files */
134 umode_t s_dir_umask; /* The umask applied to the
135 permissions on all dirs */
136 uid_t s_uid; /* The uid of all files */
137 gid_t s_gid; /* The gid of all files */
138
139 int session, part;
140
Roman Zippel328b9222005-09-06 15:18:49 -0700141 struct nls_table *nls_io, *nls_disk;
142
Matthias Kaehlcke3084b722008-07-25 01:46:34 -0700143 struct mutex bitmap_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 unsigned long flags;
146
147 u16 blockoffset;
148
149 int fs_div;
150
151 struct hlist_head rsrc_inodes;
152};
153
154#define HFS_FLG_BITMAP_DIRTY 0
155#define HFS_FLG_MDB_DIRTY 1
156#define HFS_FLG_ALT_MDB_DIRTY 2
157
158/* bitmap.c */
159extern u32 hfs_vbm_search_free(struct super_block *, u32, u32 *);
160extern int hfs_clear_vbm_bits(struct super_block *, u16, u16);
161
162/* catalog.c */
163extern int hfs_cat_keycmp(const btree_key *, const btree_key *);
164struct hfs_find_data;
165extern int hfs_cat_find_brec(struct super_block *, u32, struct hfs_find_data *);
166extern int hfs_cat_create(u32, struct inode *, struct qstr *, struct inode *);
167extern int hfs_cat_delete(u32, struct inode *, struct qstr *);
168extern int hfs_cat_move(u32, struct inode *, struct qstr *,
169 struct inode *, struct qstr *);
Roman Zippel328b9222005-09-06 15:18:49 -0700170extern void hfs_cat_build_key(struct super_block *, btree_key *, u32, struct qstr *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171
172/* dir.c */
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800173extern const struct file_operations hfs_dir_operations;
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -0800174extern const struct inode_operations hfs_dir_inode_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176/* extent.c */
177extern int hfs_ext_keycmp(const btree_key *, const btree_key *);
178extern int hfs_free_fork(struct super_block *, struct hfs_cat_file *, int);
179extern void hfs_ext_write_extent(struct inode *);
180extern int hfs_extend_file(struct inode *);
181extern void hfs_file_truncate(struct inode *);
182
183extern int hfs_get_block(struct inode *, sector_t, struct buffer_head *, int);
184
185/* inode.c */
Christoph Hellwigf5e54d62006-06-28 04:26:44 -0700186extern const struct address_space_operations hfs_aops;
187extern const struct address_space_operations hfs_btree_aops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189extern struct inode *hfs_new_inode(struct inode *, struct qstr *, int);
190extern void hfs_inode_write_fork(struct inode *, struct hfs_extent *, __be32 *, __be32 *);
Christoph Hellwiga9185b42010-03-05 09:21:37 +0100191extern int hfs_write_inode(struct inode *, struct writeback_control *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192extern int hfs_inode_setattr(struct dentry *, struct iattr *);
193extern void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
194 __be32 log_size, __be32 phys_size, u32 clump_size);
195extern struct inode *hfs_iget(struct super_block *, struct hfs_cat_key *, hfs_cat_rec *);
Al Virob57922d2010-06-07 14:34:48 -0400196extern void hfs_evict_inode(struct inode *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197extern void hfs_delete_inode(struct inode *);
198
199/* attr.c */
200extern int hfs_setxattr(struct dentry *dentry, const char *name,
201 const void *value, size_t size, int flags);
202extern ssize_t hfs_getxattr(struct dentry *dentry, const char *name,
203 void *value, size_t size);
204extern ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
205
206/* mdb.c */
207extern int hfs_mdb_get(struct super_block *);
208extern void hfs_mdb_commit(struct super_block *);
209extern void hfs_mdb_close(struct super_block *);
210extern void hfs_mdb_put(struct super_block *);
211
212/* part_tbl.c */
213extern int hfs_part_find(struct super_block *, sector_t *, sector_t *);
214
215/* string.c */
Al Viroe16404e2009-02-20 05:55:13 +0000216extern const struct dentry_operations hfs_dentry_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218extern int hfs_hash_dentry(struct dentry *, struct qstr *);
219extern int hfs_strcmp(const unsigned char *, unsigned int,
220 const unsigned char *, unsigned int);
221extern int hfs_compare_dentry(struct dentry *, struct qstr *, struct qstr *);
222
223/* trans.c */
Roman Zippel328b9222005-09-06 15:18:49 -0700224extern void hfs_asc2mac(struct super_block *, struct hfs_name *, struct qstr *);
225extern int hfs_mac2asc(struct super_block *, char *, const struct hfs_name *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227extern struct timezone sys_tz;
228
229/*
230 * There are two time systems. Both are based on seconds since
231 * a particular time/date.
232 * Unix: unsigned lil-endian since 00:00 GMT, Jan. 1, 1970
233 * mac: unsigned big-endian since 00:00 GMT, Jan. 1, 1904
234 *
235 */
236#define __hfs_u_to_mtime(sec) cpu_to_be32(sec + 2082844800U - sys_tz.tz_minuteswest * 60)
237#define __hfs_m_to_utime(sec) (be32_to_cpu(sec) - 2082844800U + sys_tz.tz_minuteswest * 60)
238
239#define HFS_I(inode) (list_entry(inode, struct hfs_inode_info, vfs_inode))
240#define HFS_SB(sb) ((struct hfs_sb_info *)(sb)->s_fs_info)
241
242#define hfs_m_to_utime(time) (struct timespec){ .tv_sec = __hfs_m_to_utime(time) }
243#define hfs_u_to_mtime(time) __hfs_u_to_mtime((time).tv_sec)
244#define hfs_mtime() __hfs_u_to_mtime(get_seconds())
245
246static inline const char *hfs_mdb_name(struct super_block *sb)
247{
248 return sb->s_id;
249}
250
251static inline void hfs_bitmap_dirty(struct super_block *sb)
252{
253 set_bit(HFS_FLG_BITMAP_DIRTY, &HFS_SB(sb)->flags);
254 sb->s_dirt = 1;
255}
256
257static inline void hfs_buffer_sync(struct buffer_head *bh)
258{
259 while (buffer_locked(bh)) {
260 wait_on_buffer(bh);
261 }
262 if (buffer_dirty(bh)) {
263 ll_rw_block(WRITE, 1, &bh);
264 wait_on_buffer(bh);
265 }
266}
267
268#define sb_bread512(sb, sec, data) ({ \
269 struct buffer_head *__bh; \
270 sector_t __block; \
271 loff_t __start; \
272 int __offset; \
273 \
274 __start = (loff_t)(sec) << HFS_SECTOR_SIZE_BITS;\
275 __block = __start >> (sb)->s_blocksize_bits; \
276 __offset = __start & ((sb)->s_blocksize - 1); \
277 __bh = sb_bread((sb), __block); \
278 if (likely(__bh != NULL)) \
279 data = (void *)(__bh->b_data + __offset);\
280 else \
281 data = NULL; \
282 __bh; \
283})
284
285#endif