Commit | Line | Data |
---|---|---|
846b730e PL |
1 | #ifndef PAGE_ACTOR_H |
2 | #define PAGE_ACTOR_H | |
3 | /* | |
4 | * Copyright (c) 2013 | |
5 | * Phillip Lougher <phillip@squashfs.org.uk> | |
6 | * | |
7 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
417aca47 | 8 | * the COPYING file in the top-level squashfsory. |
846b730e PL |
9 | */ |
10 | ||
0d455c12 | 11 | struct squashfs_page_actor { |
417aca47 | 12 | struct page **page; |
0d455c12 | 13 | void *pageaddr; |
0d455c12 PL |
14 | int pages; |
15 | int length; | |
16 | int next_page; | |
417aca47 | 17 | void (*release_pages)(struct page **, int, int); |
0d455c12 PL |
18 | }; |
19 | ||
417aca47 AS |
20 | extern struct squashfs_page_actor *squashfs_page_actor_init(struct page **, |
21 | int, int, void (*)(struct page **, int, int)); | |
22 | extern void squashfs_page_actor_free(struct squashfs_page_actor *, int); | |
23 | ||
24 | extern void squashfs_actor_to_buf(struct squashfs_page_actor *, void *, int); | |
25 | extern void squashfs_buf_to_actor(void *, struct squashfs_page_actor *, int); | |
26 | extern void squashfs_bh_to_actor(struct buffer_head **, int, | |
27 | struct squashfs_page_actor *, int, int, int); | |
28 | extern void squashfs_bh_to_buf(struct buffer_head **, int, void *, int, int, | |
29 | int); | |
30 | ||
31 | /* | |
32 | * Calling code should avoid sleeping between calls to squashfs_first_page() | |
33 | * and squashfs_finish_page(). | |
34 | */ | |
0d455c12 PL |
35 | static inline void *squashfs_first_page(struct squashfs_page_actor *actor) |
36 | { | |
417aca47 AS |
37 | actor->next_page = 1; |
38 | return actor->pageaddr = actor->page[0] ? kmap_atomic(actor->page[0]) | |
39 | : NULL; | |
0d455c12 | 40 | } |
417aca47 | 41 | |
0d455c12 PL |
42 | static inline void *squashfs_next_page(struct squashfs_page_actor *actor) |
43 | { | |
417aca47 AS |
44 | if (!IS_ERR_OR_NULL(actor->pageaddr)) |
45 | kunmap_atomic(actor->pageaddr); | |
46 | ||
47 | if (actor->next_page == actor->pages) | |
48 | return actor->pageaddr = ERR_PTR(-ENODATA); | |
49 | ||
50 | actor->pageaddr = actor->page[actor->next_page] ? | |
51 | kmap_atomic(actor->page[actor->next_page]) : NULL; | |
52 | ++actor->next_page; | |
53 | return actor->pageaddr; | |
0d455c12 | 54 | } |
417aca47 | 55 | |
0d455c12 PL |
56 | static inline void squashfs_finish_page(struct squashfs_page_actor *actor) |
57 | { | |
417aca47 AS |
58 | if (!IS_ERR_OR_NULL(actor->pageaddr)) |
59 | kunmap_atomic(actor->pageaddr); | |
0d455c12 | 60 | } |
50dcddba | 61 | |
417aca47 AS |
62 | extern struct page **alloc_page_array(int, int); |
63 | extern void free_page_array(struct page **, int); | |
64 | ||
846b730e | 65 | #endif |