1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 #ifndef PAGE_ACTOR_H 3 #define PAGE_ACTOR_H 4 /* 5 * Copyright (c) 2013 6 * Phillip Lougher <phillip@squashfs.org.uk> 7 */ 8 9 #ifndef CONFIG_SQUASHFS_FILE_DIRECT 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 25 actor->length = length ? : pages * PAGE_SIZE; 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 } 48 49 static inline void squashfs_actor_nobuff(struct squashfs_page_actor *actor) 50 { 51 /* empty */ 52 } 53 #else 54 struct squashfs_page_actor { 55 union { 56 void **buffer; 57 struct page **page; 58 }; 59 void *pageaddr; 60 void *tmp_buffer; 61 void *(*squashfs_first_page)(struct squashfs_page_actor *); 62 void *(*squashfs_next_page)(struct squashfs_page_actor *); 63 void (*squashfs_finish_page)(struct squashfs_page_actor *); 64 int pages; 65 int length; 66 int next_page; 67 int alloc_buffer; 68 int returned_pages; 69 pgoff_t next_index; 70 }; 71 72 extern struct squashfs_page_actor *squashfs_page_actor_init(void **buffer, 73 int pages, int length); 74 extern struct squashfs_page_actor *squashfs_page_actor_init_special( 75 struct squashfs_sb_info *msblk, 76 struct page **page, int pages, int length); 77 static inline void *squashfs_first_page(struct squashfs_page_actor *actor) 78 { 79 return actor->squashfs_first_page(actor); 80 } 81 static inline void *squashfs_next_page(struct squashfs_page_actor *actor) 82 { 83 return actor->squashfs_next_page(actor); 84 } 85 static inline void squashfs_finish_page(struct squashfs_page_actor *actor) 86 { 87 actor->squashfs_finish_page(actor); 88 } 89 static inline void squashfs_actor_nobuff(struct squashfs_page_actor *actor) 90 { 91 actor->alloc_buffer = 0; 92 } 93 #endif 94 #endif 95