Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 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 |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 8 | * the COPYING file in the top-level squashfsory. |
Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 11 | struct squashfs_page_actor { |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 12 | struct page **page; |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 13 | void *pageaddr; |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 14 | int pages; |
| 15 | int length; |
| 16 | int next_page; |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 17 | void (*release_pages)(struct page **, int, int); |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 18 | }; |
| 19 | |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 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 | */ |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 35 | static inline void *squashfs_first_page(struct squashfs_page_actor *actor) |
| 36 | { |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 37 | actor->next_page = 1; |
| 38 | return actor->pageaddr = actor->page[0] ? kmap_atomic(actor->page[0]) |
| 39 | : NULL; |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 40 | } |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 41 | |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 42 | static inline void *squashfs_next_page(struct squashfs_page_actor *actor) |
| 43 | { |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 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; |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 54 | } |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 55 | |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 56 | static inline void squashfs_finish_page(struct squashfs_page_actor *actor) |
| 57 | { |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 58 | if (!IS_ERR_OR_NULL(actor->pageaddr)) |
| 59 | kunmap_atomic(actor->pageaddr); |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 60 | } |
Adrien Schildknecht | 0f1ddd1 | 2016-09-28 12:14:39 -0700 | [diff] [blame] | 61 | |
Adrien Schildknecht | 38840af | 2016-09-28 13:59:18 -0700 | [diff] [blame] | 62 | extern struct page **alloc_page_array(int, int); |
| 63 | extern void free_page_array(struct page **, int); |
| 64 | |
Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 65 | #endif |