1#ifndef _LINUX_PAGEMAP_H
2#define _LINUX_PAGEMAP_H
3
4
5
6
7#include <linux/mm.h>
8#include <linux/fs.h>
9#include <linux/list.h>
10#include <linux/highmem.h>
11#include <linux/compiler.h>
12#include <asm/uaccess.h>
13#include <linux/gfp.h>
14#include <linux/bitops.h>
15
16
17
18
19
20#define AS_EIO (__GFP_BITS_SHIFT + 0)
21#define AS_ENOSPC (__GFP_BITS_SHIFT + 1)
22
23static inline void mapping_set_error(struct address_space *mapping, int error)
24{
25 if (error) {
26 if (error == -ENOSPC)
27 set_bit(AS_ENOSPC, &mapping->flags);
28 else
29 set_bit(AS_EIO, &mapping->flags);
30 }
31}
32
33static inline gfp_t mapping_gfp_mask(struct address_space * mapping)
34{
35 return (__force gfp_t)mapping->flags & __GFP_BITS_MASK;
36}
37
38
39
40
41
42static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask)
43{
44 m->flags = (m->flags & ~(__force unsigned long)__GFP_BITS_MASK) |
45 (__force unsigned long)mask;
46}
47
48
49
50
51
52
53
54
55
56#define PAGE_CACHE_SHIFT PAGE_SHIFT
57#define PAGE_CACHE_SIZE PAGE_SIZE
58#define PAGE_CACHE_MASK PAGE_MASK
59#define PAGE_CACHE_ALIGN(addr) (((addr)+PAGE_CACHE_SIZE-1)&PAGE_CACHE_MASK)
60
61#define page_cache_get(page) get_page(page)
62#define page_cache_release(page) put_page(page)
63void release_pages(struct page **pages, int nr, int cold);
64
65#ifdef CONFIG_NUMA
66extern struct page *__page_cache_alloc(gfp_t gfp);
67#else
68static inline struct page *__page_cache_alloc(gfp_t gfp)
69{
70 return alloc_pages(gfp, 0);
71}
72#endif
73
74static inline struct page *page_cache_alloc(struct address_space *x)
75{
76 return __page_cache_alloc(mapping_gfp_mask(x));
77}
78
79static inline struct page *page_cache_alloc_cold(struct address_space *x)
80{
81 return __page_cache_alloc(mapping_gfp_mask(x)|__GFP_COLD);
82}
83
84typedef int filler_t(void *, struct page *);
85
86extern struct page * find_get_page(struct address_space *mapping,
87 pgoff_t index);
88extern struct page * find_lock_page(struct address_space *mapping,
89 pgoff_t index);
90extern struct page * find_or_create_page(struct address_space *mapping,
91 pgoff_t index, gfp_t gfp_mask);
92unsigned find_get_pages(struct address_space *mapping, pgoff_t start,
93 unsigned int nr_pages, struct page **pages);
94unsigned find_get_pages_contig(struct address_space *mapping, pgoff_t start,
95 unsigned int nr_pages, struct page **pages);
96unsigned find_get_pages_tag(struct address_space *mapping, pgoff_t *index,
97 int tag, unsigned int nr_pages, struct page **pages);
98
99struct page *__grab_cache_page(struct address_space *mapping, pgoff_t index);
100
101
102
103
104static inline struct page *grab_cache_page(struct address_space *mapping,
105 pgoff_t index)
106{
107 return find_or_create_page(mapping, index, mapping_gfp_mask(mapping));
108}
109
110extern struct page * grab_cache_page_nowait(struct address_space *mapping,
111 pgoff_t index);
112extern struct page * read_cache_page_async(struct address_space *mapping,
113 pgoff_t index, filler_t *filler,
114 void *data);
115extern struct page * read_cache_page(struct address_space *mapping,
116 pgoff_t index, filler_t *filler,
117 void *data);
118extern int read_cache_pages(struct address_space *mapping,
119 struct list_head *pages, filler_t *filler, void *data);
120
121static inline struct page *read_mapping_page_async(
122 struct address_space *mapping,
123 pgoff_t index, void *data)
124{
125 filler_t *filler = (filler_t *)mapping->a_ops->readpage;
126 return read_cache_page_async(mapping, index, filler, data);
127}
128
129static inline struct page *read_mapping_page(struct address_space *mapping,
130 pgoff_t index, void *data)
131{
132 filler_t *filler = (filler_t *)mapping->a_ops->readpage;
133 return read_cache_page(mapping, index, filler, data);
134}
135
136int add_to_page_cache(struct page *page, struct address_space *mapping,
137 pgoff_t index, gfp_t gfp_mask);
138int add_to_page_cache_lru(struct page *page, struct address_space *mapping,
139 pgoff_t index, gfp_t gfp_mask);
140extern void remove_from_page_cache(struct page *page);
141extern void __remove_from_page_cache(struct page *page);
142
143
144
145
146static inline loff_t page_offset(struct page *page)
147{
148 return ((loff_t)page->index) << PAGE_CACHE_SHIFT;
149}
150
151static inline pgoff_t linear_page_index(struct vm_area_struct *vma,
152 unsigned long address)
153{
154 pgoff_t pgoff = (address - vma->vm_start) >> PAGE_SHIFT;
155 pgoff += vma->vm_pgoff;
156 return pgoff >> (PAGE_CACHE_SHIFT - PAGE_SHIFT);
157}
158
159extern void FASTCALL(__lock_page(struct page *page));
160extern void FASTCALL(__lock_page_nosync(struct page *page));
161extern void FASTCALL(unlock_page(struct page *page));
162
163
164
165
166static inline void lock_page(struct page *page)
167{
168 might_sleep();
169 if (TestSetPageLocked(page))
170 __lock_page(page);
171}
172
173
174
175
176
177static inline void lock_page_nosync(struct page *page)
178{
179 might_sleep();
180 if (TestSetPageLocked(page))
181 __lock_page_nosync(page);
182}
183
184
185
186
187
188extern void FASTCALL(wait_on_page_bit(struct page *page, int bit_nr));
189
190
191
192
193
194
195
196
197static inline void wait_on_page_locked(struct page *page)
198{
199 if (PageLocked(page))
200 wait_on_page_bit(page, PG_locked);
201}
202
203
204
205
206static inline void wait_on_page_writeback(struct page *page)
207{
208 if (PageWriteback(page))
209 wait_on_page_bit(page, PG_writeback);
210}
211
212extern void end_page_writeback(struct page *page);
213
214
215
216
217
218
219
220static inline int fault_in_pages_writeable(char __user *uaddr, int size)
221{
222 int ret;
223
224 if (unlikely(size == 0))
225 return 0;
226
227
228
229
230
231 ret = __put_user(0, uaddr);
232 if (ret == 0) {
233 char __user *end = uaddr + size - 1;
234
235
236
237
238
239 if (((unsigned long)uaddr & PAGE_MASK) !=
240 ((unsigned long)end & PAGE_MASK))
241 ret = __put_user(0, end);
242 }
243 return ret;
244}
245
246static inline int fault_in_pages_readable(const char __user *uaddr, int size)
247{
248 volatile char c;
249 int ret;
250
251 if (unlikely(size == 0))
252 return 0;
253
254 ret = __get_user(c, uaddr);
255 if (ret == 0) {
256 const char __user *end = uaddr + size - 1;
257
258 if (((unsigned long)uaddr & PAGE_MASK) !=
259 ((unsigned long)end & PAGE_MASK))
260 ret = __get_user(c, end);
261 }
262 return ret;
263}
264
265#endif
266