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