1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2019 HUAWEI, Inc.
4 * https://www.huawei.com/
6 #ifndef __EROFS_FS_COMPRESS_H
7 #define __EROFS_FS_COMPRESS_H
11 struct z_erofs_decompress_req {
12 struct super_block *sb;
13 struct page **in, **out;
14 unsigned short pageofs_in, pageofs_out;
15 unsigned int inputsize, outputsize;
17 unsigned int alg; /* the algorithm for decompression */
18 bool inplace_io, partial_decoding, fillgaps;
19 gfp_t gfp; /* allocation flags for extra temporary buffers */
22 struct z_erofs_decompressor {
23 int (*config)(struct super_block *sb, struct erofs_super_block *dsb,
24 void *data, int size);
25 int (*decompress)(struct z_erofs_decompress_req *rq,
26 struct page **pagepool);
30 /* some special page->private (unsigned long, see below) */
31 #define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
32 #define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2)
35 * For all pages in a pcluster, page->private should be one of
36 * Type Last 2bits page->private
37 * short-lived page 00 Z_EROFS_SHORTLIVED_PAGE
38 * preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE
39 * cached/managed page 00 pointer to z_erofs_pcluster
40 * online page (file-backed, 01/10/11 sub-index << 2 | count
41 * some pages can be used for inplace I/O)
43 * page->mapping should be one of
45 * short-lived page NULL
46 * preallocated page NULL
47 * cached/managed page non-NULL or NULL (invalidated/truncated page)
48 * online page non-NULL
50 * For all managed pages, PG_private should be set with 1 extra refcount,
51 * which is used for page reclaim / migration.
55 * short-lived pages are pages directly from buddy system with specific
56 * page->private (no need to set PagePrivate since these are non-LRU /
57 * non-movable pages and bypass reclaim / migration code).
59 static inline bool z_erofs_is_shortlived_page(struct page *page)
61 if (page->private != Z_EROFS_SHORTLIVED_PAGE)
64 DBG_BUGON(page->mapping);
68 static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
71 if (!z_erofs_is_shortlived_page(page))
74 /* short-lived pages should not be used by others at the same time */
75 if (page_ref_count(page) > 1) {
78 /* follow the pcluster rule above. */
79 erofs_pagepool_add(pagepool, page);
84 #define MNGD_MAPPING(sbi) ((sbi)->managed_cache->i_mapping)
85 static inline bool erofs_page_is_managed(const struct erofs_sb_info *sbi,
88 return page->mapping == MNGD_MAPPING(sbi);
91 int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
92 unsigned int padbufsize);
93 extern const struct z_erofs_decompressor erofs_decompressors[];
95 /* prototypes for specific algorithms */
96 int z_erofs_load_lzma_config(struct super_block *sb,
97 struct erofs_super_block *dsb, void *data, int size);
98 int z_erofs_load_deflate_config(struct super_block *sb,
99 struct erofs_super_block *dsb, void *data, int size);
100 int z_erofs_lzma_decompress(struct z_erofs_decompress_req *rq,
101 struct page **pagepool);
102 int z_erofs_deflate_decompress(struct z_erofs_decompress_req *rq,
103 struct page **pagepool);