3 * Phillip Lougher <phillip@squashfs.org.uk>
5 * This work is licensed under the terms of the GNU GPL, version 2. See
6 * the COPYING file in the top-level directory.
9 #include <linux/kernel.h>
10 #include <linux/slab.h>
11 #include <linux/pagemap.h>
12 #include "page_actor.h"
15 * This file contains implementations of page_actor for decompressing into
16 * an intermediate buffer, and for decompressing directly into the
19 * Calling code should avoid sleeping between calls to squashfs_first_page()
20 * and squashfs_finish_page().
23 /* Implementation of page_actor for decompressing into intermediate buffer */
24 static void *cache_first_page(struct squashfs_page_actor
*actor
)
27 return actor
->buffer
[0];
30 static void *cache_next_page(struct squashfs_page_actor
*actor
)
32 if (actor
->next_page
== actor
->pages
)
35 return actor
->buffer
[actor
->next_page
++];
38 static void cache_finish_page(struct squashfs_page_actor
*actor
)
43 struct squashfs_page_actor
*squashfs_page_actor_init(void **buffer
,
44 int pages
, int length
)
46 struct squashfs_page_actor
*actor
= kmalloc(sizeof(*actor
), GFP_KERNEL
);
51 actor
->length
= length
? : pages
* PAGE_CACHE_SIZE
;
52 actor
->buffer
= buffer
;
55 actor
->squashfs_first_page
= cache_first_page
;
56 actor
->squashfs_next_page
= cache_next_page
;
57 actor
->squashfs_finish_page
= cache_finish_page
;
61 /* Implementation of page_actor for decompressing directly into page cache. */
62 static void *direct_first_page(struct squashfs_page_actor
*actor
)
65 return actor
->pageaddr
= kmap_atomic(actor
->page
[0]);
68 static void *direct_next_page(struct squashfs_page_actor
*actor
)
71 kunmap_atomic(actor
->pageaddr
);
73 return actor
->pageaddr
= actor
->next_page
== actor
->pages
? NULL
:
74 kmap_atomic(actor
->page
[actor
->next_page
++]);
77 static void direct_finish_page(struct squashfs_page_actor
*actor
)
80 kunmap_atomic(actor
->pageaddr
);
83 struct squashfs_page_actor
*squashfs_page_actor_init_special(struct page
**page
,
84 int pages
, int length
)
86 struct squashfs_page_actor
*actor
= kmalloc(sizeof(*actor
), GFP_KERNEL
);
91 actor
->length
= length
? : pages
* PAGE_CACHE_SIZE
;
95 actor
->pageaddr
= NULL
;
96 actor
->squashfs_first_page
= direct_first_page
;
97 actor
->squashfs_next_page
= direct_next_page
;
98 actor
->squashfs_finish_page
= direct_finish_page
;