Thomas Gleixner | 20c8ccb | 2019-06-04 10:11:32 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 2 | #ifndef PAGE_ACTOR_H |
| 3 | #define PAGE_ACTOR_H |
| 4 | /* |
| 5 | * Copyright (c) 2013 |
| 6 | * Phillip Lougher <phillip@squashfs.org.uk> |
Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 9 | #ifndef CONFIG_SQUASHFS_FILE_DIRECT |
Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 10 | struct squashfs_page_actor { |
| 11 | void **page; |
| 12 | int pages; |
| 13 | int length; |
| 14 | int next_page; |
| 15 | }; |
| 16 | |
| 17 | static inline struct squashfs_page_actor *squashfs_page_actor_init(void **page, |
| 18 | int pages, int length) |
| 19 | { |
| 20 | struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL); |
| 21 | |
| 22 | if (actor == NULL) |
| 23 | return NULL; |
| 24 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 25 | actor->length = length ? : pages * PAGE_SIZE; |
Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 26 | actor->page = page; |
| 27 | actor->pages = pages; |
| 28 | actor->next_page = 0; |
| 29 | return actor; |
| 30 | } |
| 31 | |
| 32 | static inline void *squashfs_first_page(struct squashfs_page_actor *actor) |
| 33 | { |
| 34 | actor->next_page = 1; |
| 35 | return actor->page[0]; |
| 36 | } |
| 37 | |
| 38 | static inline void *squashfs_next_page(struct squashfs_page_actor *actor) |
| 39 | { |
| 40 | return actor->next_page == actor->pages ? NULL : |
| 41 | actor->page[actor->next_page++]; |
| 42 | } |
| 43 | |
| 44 | static inline void squashfs_finish_page(struct squashfs_page_actor *actor) |
| 45 | { |
| 46 | /* empty */ |
| 47 | } |
Phillip Lougher | 0d455c1 | 2013-11-13 02:04:19 +0000 | [diff] [blame] | 48 | #else |
| 49 | struct squashfs_page_actor { |
| 50 | union { |
| 51 | void **buffer; |
| 52 | struct page **page; |
| 53 | }; |
| 54 | void *pageaddr; |
| 55 | void *(*squashfs_first_page)(struct squashfs_page_actor *); |
| 56 | void *(*squashfs_next_page)(struct squashfs_page_actor *); |
| 57 | void (*squashfs_finish_page)(struct squashfs_page_actor *); |
| 58 | int pages; |
| 59 | int length; |
| 60 | int next_page; |
| 61 | }; |
| 62 | |
| 63 | extern struct squashfs_page_actor *squashfs_page_actor_init(void **, int, int); |
| 64 | extern struct squashfs_page_actor *squashfs_page_actor_init_special(struct page |
| 65 | **, int, int); |
| 66 | static inline void *squashfs_first_page(struct squashfs_page_actor *actor) |
| 67 | { |
| 68 | return actor->squashfs_first_page(actor); |
| 69 | } |
| 70 | static inline void *squashfs_next_page(struct squashfs_page_actor *actor) |
| 71 | { |
| 72 | return actor->squashfs_next_page(actor); |
| 73 | } |
| 74 | static inline void squashfs_finish_page(struct squashfs_page_actor *actor) |
| 75 | { |
| 76 | actor->squashfs_finish_page(actor); |
| 77 | } |
| 78 | #endif |
Phillip Lougher | 846b730 | 2013-11-18 02:59:12 +0000 | [diff] [blame] | 79 | #endif |