1
2
3
4
5
6
7#ifndef _LINUX_BUFFER_HEAD_H
8#define _LINUX_BUFFER_HEAD_H
9
10#include <linux/types.h>
11#include <linux/fs.h>
12#include <linux/linkage.h>
13#include <asm/atomic.h>
14
15enum bh_state_bits {
16 BH_Uptodate,
17 BH_Dirty,
18 BH_Lock,
19 BH_Req,
20
21 BH_Mapped,
22 BH_New,
23 BH_Async_Read,
24 BH_Async_Write,
25
26 BH_Boundary,
27 BH_PrivateStart,
28
29
30};
31
32#define MAX_BUF_PER_PAGE (PAGE_CACHE_SIZE / 512)
33
34struct page;
35struct kiobuf;
36struct buffer_head;
37struct address_space;
38typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
39
40
41
42
43
44
45struct buffer_head {
46
47 unsigned long b_state;
48 atomic_t b_count;
49 struct buffer_head *b_this_page;
50 struct page *b_page;
51
52 sector_t b_blocknr;
53 u32 b_size;
54 char *b_data;
55
56 struct block_device *b_bdev;
57 bh_end_io_t *b_end_io;
58 void *b_private;
59 struct list_head b_assoc_buffers;
60};
61
62
63
64
65
66
67#define BUFFER_FNS(bit, name) \
68static inline void set_buffer_##name(struct buffer_head *bh) \
69{ \
70 set_bit(BH_##bit, &(bh)->b_state); \
71} \
72static inline void clear_buffer_##name(struct buffer_head *bh) \
73{ \
74 clear_bit(BH_##bit, &(bh)->b_state); \
75} \
76static inline int buffer_##name(struct buffer_head *bh) \
77{ \
78 return test_bit(BH_##bit, &(bh)->b_state); \
79}
80
81
82
83
84#define TAS_BUFFER_FNS(bit, name) \
85static inline int test_set_buffer_##name(struct buffer_head *bh) \
86{ \
87 return test_and_set_bit(BH_##bit, &(bh)->b_state); \
88} \
89static inline int test_clear_buffer_##name(struct buffer_head *bh) \
90{ \
91 return test_and_clear_bit(BH_##bit, &(bh)->b_state); \
92} \
93
94
95
96
97
98
99BUFFER_FNS(Uptodate, uptodate)
100BUFFER_FNS(Dirty, dirty)
101TAS_BUFFER_FNS(Dirty, dirty)
102BUFFER_FNS(Lock, locked)
103TAS_BUFFER_FNS(Lock, locked)
104BUFFER_FNS(Req, req)
105BUFFER_FNS(Mapped, mapped)
106BUFFER_FNS(New, new)
107BUFFER_FNS(Async_Read, async_read)
108BUFFER_FNS(Async_Write, async_write)
109BUFFER_FNS(Boundary, boundary)
110
111#define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
112#define touch_buffer(bh) mark_page_accessed(bh->b_page)
113
114
115#define page_buffers(page) \
116 ({ \
117 if (!PagePrivate(page)) \
118 BUG(); \
119 ((struct buffer_head *)(page)->private); \
120 })
121#define page_has_buffers(page) PagePrivate(page)
122
123#define invalidate_buffers(dev) __invalidate_buffers((dev), 0)
124
125
126
127
128
129
130void FASTCALL(mark_buffer_dirty(struct buffer_head *bh));
131void init_buffer(struct buffer_head *, bh_end_io_t *, void *);
132void set_bh_page(struct buffer_head *bh,
133 struct page *page, unsigned long offset);
134int try_to_free_buffers(struct page *);
135void create_empty_buffers(struct page *, unsigned long,
136 unsigned long b_state);
137void end_buffer_io_sync(struct buffer_head *bh, int uptodate);
138
139
140void buffer_insert_list(spinlock_t *lock,
141 struct buffer_head *, struct list_head *);
142void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode);
143int write_mapping_buffers(struct address_space *mapping);
144int inode_has_buffers(struct inode *);
145void invalidate_inode_buffers(struct inode *);
146int fsync_buffers_list(spinlock_t *lock, struct list_head *);
147int sync_mapping_buffers(struct address_space *mapping);
148void unmap_underlying_metadata(struct block_device *bdev, sector_t block);
149
150void mark_buffer_async_read(struct buffer_head *bh);
151void mark_buffer_async_write(struct buffer_head *bh);
152void invalidate_bdev(struct block_device *, int);
153void __invalidate_buffers(kdev_t dev, int);
154int sync_blockdev(struct block_device *bdev);
155void __wait_on_buffer(struct buffer_head *);
156void sleep_on_buffer(struct buffer_head *bh);
157void wake_up_buffer(struct buffer_head *bh);
158int fsync_bdev(struct block_device *);
159int fsync_super(struct super_block *);
160int fsync_no_super(struct block_device *);
161struct buffer_head *__find_get_block(struct block_device *, sector_t, int);
162struct buffer_head * __getblk(struct block_device *, sector_t, int);
163void __brelse(struct buffer_head *);
164void __bforget(struct buffer_head *);
165struct buffer_head *__bread(struct block_device *, sector_t block, int size);
166void wakeup_bdflush(void);
167struct buffer_head *alloc_buffer_head(void);
168void free_buffer_head(struct buffer_head * bh);
169void FASTCALL(unlock_buffer(struct buffer_head *bh));
170
171
172
173
174
175int try_to_release_page(struct page * page, int gfp_mask);
176int block_invalidatepage(struct page *page, unsigned long offset);
177int block_write_full_page(struct page*, get_block_t*);
178int block_read_full_page(struct page*, get_block_t*);
179int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
180int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
181 loff_t *);
182int generic_cont_expand(struct inode *inode, loff_t size) ;
183int block_commit_write(struct page *page, unsigned from, unsigned to);
184int block_sync_page(struct page *);
185sector_t generic_block_bmap(struct address_space *, sector_t, get_block_t *);
186int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
187int block_truncate_page(struct address_space *, loff_t, get_block_t *);
188int file_fsync(struct file *, struct dentry *, int);
189
190#define OSYNC_METADATA (1<<0)
191#define OSYNC_DATA (1<<1)
192#define OSYNC_INODE (1<<2)
193int generic_osync_inode(struct inode *, int);
194
195
196
197
198
199
200static inline void get_bh(struct buffer_head *bh)
201{
202 atomic_inc(&bh->b_count);
203}
204
205static inline void put_bh(struct buffer_head *bh)
206{
207 smp_mb__before_atomic_dec();
208 atomic_dec(&bh->b_count);
209}
210
211static inline void brelse(struct buffer_head *bh)
212{
213 if (bh)
214 __brelse(bh);
215}
216
217static inline void bforget(struct buffer_head *bh)
218{
219 if (bh)
220 __bforget(bh);
221}
222
223static inline struct buffer_head *sb_bread(struct super_block *sb, sector_t block)
224{
225 return __bread(sb->s_bdev, block, sb->s_blocksize);
226}
227
228static inline struct buffer_head *sb_getblk(struct super_block *sb, sector_t block)
229{
230 return __getblk(sb->s_bdev, block, sb->s_blocksize);
231}
232
233static inline struct buffer_head *
234sb_find_get_block(struct super_block *sb, sector_t block)
235{
236 return __find_get_block(sb->s_bdev, block, sb->s_blocksize);
237}
238
239static inline void
240map_bh(struct buffer_head *bh, struct super_block *sb, sector_t block)
241{
242 set_buffer_mapped(bh);
243 bh->b_bdev = sb->s_bdev;
244 bh->b_blocknr = block;
245}
246
247static inline void wait_on_buffer(struct buffer_head *bh)
248{
249 if (buffer_locked(bh))
250 __wait_on_buffer(bh);
251}
252
253static inline void lock_buffer(struct buffer_head *bh)
254{
255 while (test_set_buffer_locked(bh))
256 __wait_on_buffer(bh);
257}
258
259
260
261
262
263void __buffer_error(char *file, int line);
264#define buffer_error() __buffer_error(__FILE__, __LINE__)
265
266#endif
267