blob: 98537eab27e270d8b04f04b7d0db2ee519e21d46 [file] [log] [blame]
Phillip Lougher846b7302013-11-18 02:59:12 +00001#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
Alistair Strachan603dd202018-12-19 15:37:41 -08008 * the COPYING file in the top-level directory.
Phillip Lougher846b7302013-11-18 02:59:12 +00009 */
10
Alistair Strachan603dd202018-12-19 15:37:41 -080011#ifndef CONFIG_SQUASHFS_FILE_DIRECT
Phillip Lougher0d455c12013-11-13 02:04:19 +000012struct squashfs_page_actor {
Alistair Strachan603dd202018-12-19 15:37:41 -080013 void **page;
Phillip Lougher0d455c12013-11-13 02:04:19 +000014 int pages;
15 int length;
16 int next_page;
17};
18
Alistair Strachan603dd202018-12-19 15:37:41 -080019static inline struct squashfs_page_actor *squashfs_page_actor_init(void **page,
20 int pages, int length)
21{
22 struct squashfs_page_actor *actor = kmalloc(sizeof(*actor), GFP_KERNEL);
Adrien Schildknecht38840af2016-09-28 13:59:18 -070023
Alistair Strachan603dd202018-12-19 15:37:41 -080024 if (actor == NULL)
25 return NULL;
Adrien Schildknecht38840af2016-09-28 13:59:18 -070026
Alistair Strachan603dd202018-12-19 15:37:41 -080027 actor->length = length ? : pages * PAGE_SIZE;
28 actor->page = page;
29 actor->pages = pages;
30 actor->next_page = 0;
31 return actor;
32}
33
Phillip Lougher0d455c12013-11-13 02:04:19 +000034static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
35{
Adrien Schildknecht38840af2016-09-28 13:59:18 -070036 actor->next_page = 1;
Alistair Strachan603dd202018-12-19 15:37:41 -080037 return actor->page[0];
Phillip Lougher0d455c12013-11-13 02:04:19 +000038}
Adrien Schildknecht38840af2016-09-28 13:59:18 -070039
Phillip Lougher0d455c12013-11-13 02:04:19 +000040static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
41{
Alistair Strachan603dd202018-12-19 15:37:41 -080042 return actor->next_page == actor->pages ? NULL :
43 actor->page[actor->next_page++];
Phillip Lougher0d455c12013-11-13 02:04:19 +000044}
Adrien Schildknecht38840af2016-09-28 13:59:18 -070045
Phillip Lougher0d455c12013-11-13 02:04:19 +000046static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
47{
Alistair Strachan603dd202018-12-19 15:37:41 -080048 /* empty */
Phillip Lougher0d455c12013-11-13 02:04:19 +000049}
Alistair Strachan603dd202018-12-19 15:37:41 -080050#else
51struct squashfs_page_actor {
52 union {
53 void **buffer;
54 struct page **page;
55 };
56 void *pageaddr;
57 void *(*squashfs_first_page)(struct squashfs_page_actor *);
58 void *(*squashfs_next_page)(struct squashfs_page_actor *);
59 void (*squashfs_finish_page)(struct squashfs_page_actor *);
60 int pages;
61 int length;
62 int next_page;
63};
Adrien Schildknecht0f1ddd12016-09-28 12:14:39 -070064
Alistair Strachan603dd202018-12-19 15:37:41 -080065extern struct squashfs_page_actor *squashfs_page_actor_init(void **, int, int);
66extern struct squashfs_page_actor *squashfs_page_actor_init_special(struct page
67 **, int, int);
68static inline void *squashfs_first_page(struct squashfs_page_actor *actor)
69{
70 return actor->squashfs_first_page(actor);
71}
72static inline void *squashfs_next_page(struct squashfs_page_actor *actor)
73{
74 return actor->squashfs_next_page(actor);
75}
76static inline void squashfs_finish_page(struct squashfs_page_actor *actor)
77{
78 actor->squashfs_finish_page(actor);
79}
80#endif
Phillip Lougher846b7302013-11-18 02:59:12 +000081#endif