rtc: isl12057: deprecate use of isl in compatible string for isil
[linux/fpc-iii.git] / fs / squashfs / page_actor.c
blob5a1c11f5644153b6a644d45fb1669ab0b3ef1f13
1 /*
2 * Copyright (c) 2013
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.
7 */
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
17 * page cache.
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)
26 actor->next_page = 1;
27 return actor->buffer[0];
30 static void *cache_next_page(struct squashfs_page_actor *actor)
32 if (actor->next_page == actor->pages)
33 return NULL;
35 return actor->buffer[actor->next_page++];
38 static void cache_finish_page(struct squashfs_page_actor *actor)
40 /* empty */
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);
48 if (actor == NULL)
49 return NULL;
51 actor->length = length ? : pages * PAGE_CACHE_SIZE;
52 actor->buffer = buffer;
53 actor->pages = pages;
54 actor->next_page = 0;
55 actor->squashfs_first_page = cache_first_page;
56 actor->squashfs_next_page = cache_next_page;
57 actor->squashfs_finish_page = cache_finish_page;
58 return actor;
61 /* Implementation of page_actor for decompressing directly into page cache. */
62 static void *direct_first_page(struct squashfs_page_actor *actor)
64 actor->next_page = 1;
65 return actor->pageaddr = kmap_atomic(actor->page[0]);
68 static void *direct_next_page(struct squashfs_page_actor *actor)
70 if (actor->pageaddr)
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)
79 if (actor->pageaddr)
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);
88 if (actor == NULL)
89 return NULL;
91 actor->length = length ? : pages * PAGE_CACHE_SIZE;
92 actor->page = page;
93 actor->pages = pages;
94 actor->next_page = 0;
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;
99 return actor;