Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * Copyright (C) 2019 HUAWEI, Inc.
4 * https://www.huawei.com/
5 */
6#ifndef __EROFS_FS_COMPRESS_H
7#define __EROFS_FS_COMPRESS_H
8
9#include "internal.h"
10
11struct z_erofs_decompress_req {
12 struct super_block *sb;
13 struct page **in, **out;
14 unsigned int inpages, outpages;
15 unsigned short pageofs_in, pageofs_out;
16 unsigned int inputsize, outputsize;
17
18 unsigned int alg; /* the algorithm for decompression */
19 bool inplace_io, partial_decoding, fillgaps;
20 gfp_t gfp; /* allocation flags for extra temporary buffers */
21};
22
23struct z_erofs_decompressor {
24 int (*config)(struct super_block *sb, struct erofs_super_block *dsb,
25 void *data, int size);
26 const char *(*decompress)(struct z_erofs_decompress_req *rq,
27 struct page **pagepool);
28 int (*init)(void);
29 void (*exit)(void);
30 char *name;
31};
32
33#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
34#define Z_EROFS_PREALLOCATED_FOLIO ((void *)(-2UL << 2))
35
36/*
37 * Currently, short-lived pages are pages directly from buddy system
38 * with specific page->private (Z_EROFS_SHORTLIVED_PAGE).
39 * In the future world of Memdescs, it should be type 0 (Misc) memory
40 * which type can be checked with a new helper.
41 */
42static inline bool z_erofs_is_shortlived_page(struct page *page)
43{
44 return page->private == Z_EROFS_SHORTLIVED_PAGE;
45}
46
47static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
48 struct page *page)
49{
50 if (!z_erofs_is_shortlived_page(page))
51 return false;
52 erofs_pagepool_add(pagepool, page);
53 return true;
54}
55
56extern const struct z_erofs_decompressor z_erofs_lzma_decomp;
57extern const struct z_erofs_decompressor z_erofs_deflate_decomp;
58extern const struct z_erofs_decompressor z_erofs_zstd_decomp;
59extern const struct z_erofs_decompressor *z_erofs_decomp[];
60
61struct z_erofs_stream_dctx {
62 struct z_erofs_decompress_req *rq;
63 int no, ni; /* the current {en,de}coded page # */
64
65 unsigned int avail_out; /* remaining bytes in the decoded buffer */
66 unsigned int inbuf_pos, inbuf_sz;
67 /* current status of the encoded buffer */
68 u8 *kin, *kout; /* buffer mapped pointers */
69 void *bounce; /* bounce buffer for inplace I/Os */
70 bool bounced; /* is the bounce buffer used now? */
71};
72
73const char *z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx,
74 void **dst, void **src, struct page **pgpl);
75const char *z_erofs_fixup_insize(struct z_erofs_decompress_req *rq,
76 const char *padbuf, unsigned int padbufsize);
77int __init z_erofs_init_decompressor(void);
78void z_erofs_exit_decompressor(void);
79int z_erofs_crypto_decompress(struct z_erofs_decompress_req *rq,
80 struct page **pgpl);
81int z_erofs_crypto_enable_engine(const char *name, int len);
82#ifdef CONFIG_EROFS_FS_ZIP_ACCEL
83void z_erofs_crypto_disable_all_engines(void);
84int z_erofs_crypto_show_engines(char *buf, int size, char sep);
85#else
86static inline void z_erofs_crypto_disable_all_engines(void) {}
87static inline int z_erofs_crypto_show_engines(char *buf, int size, char sep) { return 0; }
88#endif
89#endif