2019-07-31 15:57:31 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2019-06-24 07:22:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 HUAWEI, Inc.
|
2020-07-13 13:09:44 +00:00
|
|
|
* https://www.huawei.com/
|
2019-06-24 07:22:54 +00:00
|
|
|
*/
|
|
|
|
#ifndef __EROFS_FS_COMPRESS_H
|
|
|
|
#define __EROFS_FS_COMPRESS_H
|
|
|
|
|
2019-06-24 07:22:55 +00:00
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
struct z_erofs_decompress_req {
|
2019-06-24 07:22:56 +00:00
|
|
|
struct super_block *sb;
|
2019-06-24 07:22:55 +00:00
|
|
|
struct page **in, **out;
|
2021-12-28 05:46:01 +00:00
|
|
|
unsigned short pageofs_in, pageofs_out;
|
2019-06-24 07:22:55 +00:00
|
|
|
unsigned int inputsize, outputsize;
|
|
|
|
|
2024-01-26 14:01:42 +00:00
|
|
|
unsigned int alg; /* the algorithm for decompression */
|
2022-07-15 15:42:03 +00:00
|
|
|
bool inplace_io, partial_decoding, fillgaps;
|
2024-01-26 14:01:42 +00:00
|
|
|
gfp_t gfp; /* allocation flags for extra temporary buffers */
|
2019-06-24 07:22:55 +00:00
|
|
|
};
|
|
|
|
|
2021-10-10 21:31:45 +00:00
|
|
|
struct z_erofs_decompressor {
|
2023-10-22 13:09:57 +00:00
|
|
|
int (*config)(struct super_block *sb, struct erofs_super_block *dsb,
|
|
|
|
void *data, int size);
|
2021-10-10 21:31:45 +00:00
|
|
|
int (*decompress)(struct z_erofs_decompress_req *rq,
|
2021-10-22 09:01:20 +00:00
|
|
|
struct page **pagepool);
|
2024-07-09 09:41:05 +00:00
|
|
|
int (*init)(void);
|
|
|
|
void (*exit)(void);
|
2021-10-10 21:31:45 +00:00
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
2020-12-08 09:58:32 +00:00
|
|
|
/* some special page->private (unsigned long, see below) */
|
|
|
|
#define Z_EROFS_SHORTLIVED_PAGE (-1UL << 2)
|
2020-12-09 12:37:17 +00:00
|
|
|
#define Z_EROFS_PREALLOCATED_PAGE (-2UL << 2)
|
2020-12-08 09:58:32 +00:00
|
|
|
|
2019-06-24 07:22:54 +00:00
|
|
|
/*
|
2020-12-08 09:58:32 +00:00
|
|
|
* For all pages in a pcluster, page->private should be one of
|
|
|
|
* Type Last 2bits page->private
|
|
|
|
* short-lived page 00 Z_EROFS_SHORTLIVED_PAGE
|
2020-12-09 12:37:17 +00:00
|
|
|
* preallocated page (tryalloc) 00 Z_EROFS_PREALLOCATED_PAGE
|
2020-12-08 09:58:32 +00:00
|
|
|
* cached/managed page 00 pointer to z_erofs_pcluster
|
|
|
|
* online page (file-backed, 01/10/11 sub-index << 2 | count
|
|
|
|
* some pages can be used for inplace I/O)
|
|
|
|
*
|
|
|
|
* page->mapping should be one of
|
|
|
|
* Type page->mapping
|
|
|
|
* short-lived page NULL
|
2020-12-09 12:37:17 +00:00
|
|
|
* preallocated page NULL
|
2020-12-08 09:58:32 +00:00
|
|
|
* cached/managed page non-NULL or NULL (invalidated/truncated page)
|
|
|
|
* online page non-NULL
|
|
|
|
*
|
|
|
|
* For all managed pages, PG_private should be set with 1 extra refcount,
|
|
|
|
* which is used for page reclaim / migration.
|
2019-06-24 07:22:54 +00:00
|
|
|
*/
|
|
|
|
|
2020-12-08 09:58:32 +00:00
|
|
|
/*
|
2024-07-11 05:36:59 +00:00
|
|
|
* Currently, short-lived pages are pages directly from buddy system
|
|
|
|
* with specific page->private (Z_EROFS_SHORTLIVED_PAGE).
|
|
|
|
* In the future world of Memdescs, it should be type 0 (Misc) memory
|
|
|
|
* which type can be checked with a new helper.
|
2020-12-08 09:58:32 +00:00
|
|
|
*/
|
|
|
|
static inline bool z_erofs_is_shortlived_page(struct page *page)
|
2019-06-24 07:22:54 +00:00
|
|
|
{
|
2024-07-11 05:36:59 +00:00
|
|
|
return page->private == Z_EROFS_SHORTLIVED_PAGE;
|
2019-06-24 07:22:54 +00:00
|
|
|
}
|
|
|
|
|
2021-10-22 09:01:20 +00:00
|
|
|
static inline bool z_erofs_put_shortlivedpage(struct page **pagepool,
|
2020-12-08 09:58:32 +00:00
|
|
|
struct page *page)
|
2019-06-24 07:22:54 +00:00
|
|
|
{
|
2020-12-08 09:58:32 +00:00
|
|
|
if (!z_erofs_is_shortlived_page(page))
|
2019-06-24 07:22:54 +00:00
|
|
|
return false;
|
2024-07-11 05:36:59 +00:00
|
|
|
erofs_pagepool_add(pagepool, page);
|
2019-06-24 07:22:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-07-09 09:41:04 +00:00
|
|
|
extern const struct z_erofs_decompressor z_erofs_lzma_decomp;
|
|
|
|
extern const struct z_erofs_decompressor z_erofs_deflate_decomp;
|
|
|
|
extern const struct z_erofs_decompressor z_erofs_zstd_decomp;
|
|
|
|
extern const struct z_erofs_decompressor *z_erofs_decomp[];
|
|
|
|
|
2024-07-09 09:41:06 +00:00
|
|
|
struct z_erofs_stream_dctx {
|
|
|
|
struct z_erofs_decompress_req *rq;
|
|
|
|
unsigned int inpages, outpages; /* # of {en,de}coded pages */
|
|
|
|
int no, ni; /* the current {en,de}coded page # */
|
|
|
|
|
|
|
|
unsigned int avail_out; /* remaining bytes in the decoded buffer */
|
|
|
|
unsigned int inbuf_pos, inbuf_sz;
|
|
|
|
/* current status of the encoded buffer */
|
|
|
|
u8 *kin, *kout; /* buffer mapped pointers */
|
|
|
|
void *bounce; /* bounce buffer for inplace I/Os */
|
|
|
|
bool bounced; /* is the bounce buffer used now? */
|
|
|
|
};
|
|
|
|
|
|
|
|
int z_erofs_stream_switch_bufs(struct z_erofs_stream_dctx *dctx, void **dst,
|
|
|
|
void **src, struct page **pgpl);
|
2021-12-28 05:46:01 +00:00
|
|
|
int z_erofs_fixup_insize(struct z_erofs_decompress_req *rq, const char *padbuf,
|
|
|
|
unsigned int padbufsize);
|
2024-07-09 09:41:05 +00:00
|
|
|
int __init z_erofs_init_decompressor(void);
|
|
|
|
void z_erofs_exit_decompressor(void);
|
2019-06-24 07:22:54 +00:00
|
|
|
#endif
|