1 /* Copyright (c) 2010 The Regents of the University of California
2 * Barret Rhoden <brho@cs.berkeley.edu>
3 * See LICENSE for details.
5 * Page mapping: maps an object (inode or block dev) in page size chunks.
6 * Analagous to Linux's "struct address space". While this is closely coupled
7 * with the VFS, block devices also use it (hence the separate header and c
10 #ifndef ROS_KERN_PAGEMAP_H
11 #define ROS_KERN_PAGEMAP_H
16 /* Need to be careful, due to some ghetto circular references */
20 struct page_map_operations;
22 /* Every object that has pages, like an inode or the swap (or even direct block
23 * devices) has a page_map, tracking which of its pages are currently in memory.
24 * It is a map, per object, from index to physical page frame. */
27 struct inode *pm_host; /* inode of the owner, if any */
28 struct block_device *pm_bdev; /* bdev of the owner, if any */
30 struct radix_tree pm_tree; /* tracks present pages */
31 spinlock_t pm_tree_lock; /* spinlock => we can't block */
32 unsigned long pm_num_pages; /* how many pages are present */
33 struct page_map_operations *pm_op;
34 unsigned int pm_flags;
35 /*... and private lists, backing block dev info, other mappings, etc. */
38 /* Operations performed on a page_map. These are usually FS specific, which
39 * get assigned when the inode is created.
40 * Will fill these in as they are created/needed/used. */
41 struct page_map_operations {
42 int (*readpage) (struct page_map *, struct page *);
43 /* readpages: read a list of pages
44 writepage: write from a page to its backing store
45 writepages: write a list of pages
46 sync_page: start the IO of already scheduled ops
47 set_page_dirty: mark the given page dirty
48 prepare_write: prepare to write (disk backed pages)
49 commit_write: complete a write (disk backed pages)
50 bmap: get a logical block number from a file block index
51 invalidate page: invalidate, part of truncating
52 release page: prepare to release
53 direct_io: bypass the page cache */
56 /* Page cache functions */
57 void pm_init(struct page_map *pm, struct page_map_operations *op, void *host);
58 struct page *pm_find_page(struct page_map *pm, unsigned long index);
59 int pm_insert_page(struct page_map *pm, unsigned long index, struct page *page);
60 int pm_remove_page(struct page_map *pm, struct page *page);
61 int pm_load_page(struct page_map *pm, unsigned long index, struct page **pp);
63 #endif /* ROS_KERN_PAGEMAP_H */