18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2019 HUAWEI, Inc.
48c2ecf20Sopenharmony_ci *             https://www.huawei.com/
58c2ecf20Sopenharmony_ci * Created by Gao Xiang <gaoxiang25@huawei.com>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef __EROFS_FS_COMPRESS_H
88c2ecf20Sopenharmony_ci#define __EROFS_FS_COMPRESS_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include "internal.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_cienum {
138c2ecf20Sopenharmony_ci	Z_EROFS_COMPRESSION_SHIFTED = Z_EROFS_COMPRESSION_MAX,
148c2ecf20Sopenharmony_ci	Z_EROFS_COMPRESSION_RUNTIME_MAX
158c2ecf20Sopenharmony_ci};
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_cistruct z_erofs_decompress_req {
188c2ecf20Sopenharmony_ci	struct super_block *sb;
198c2ecf20Sopenharmony_ci	struct page **in, **out;
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci	unsigned short pageofs_out;
228c2ecf20Sopenharmony_ci	unsigned int inputsize, outputsize;
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci	/* indicate the algorithm will be used for decompression */
258c2ecf20Sopenharmony_ci	unsigned int alg;
268c2ecf20Sopenharmony_ci	bool inplace_io, partial_decoding;
278c2ecf20Sopenharmony_ci};
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci * - 0x5A110C8D ('sallocated', Z_EROFS_MAPPING_STAGING) -
318c2ecf20Sopenharmony_ci * used to mark temporary allocated pages from other
328c2ecf20Sopenharmony_ci * file/cached pages and NULL mapping pages.
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci#define Z_EROFS_MAPPING_STAGING         ((void *)0x5A110C8D)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* check if a page is marked as staging */
378c2ecf20Sopenharmony_cistatic inline bool z_erofs_page_is_staging(struct page *page)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	return page->mapping == Z_EROFS_MAPPING_STAGING;
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_cistatic inline bool z_erofs_put_stagingpage(struct list_head *pagepool,
438c2ecf20Sopenharmony_ci					   struct page *page)
448c2ecf20Sopenharmony_ci{
458c2ecf20Sopenharmony_ci	if (!z_erofs_page_is_staging(page))
468c2ecf20Sopenharmony_ci		return false;
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	/* staging pages should not be used by others at the same time */
498c2ecf20Sopenharmony_ci	if (page_ref_count(page) > 1)
508c2ecf20Sopenharmony_ci		put_page(page);
518c2ecf20Sopenharmony_ci	else
528c2ecf20Sopenharmony_ci		list_add(&page->lru, pagepool);
538c2ecf20Sopenharmony_ci	return true;
548c2ecf20Sopenharmony_ci}
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ciint z_erofs_decompress(struct z_erofs_decompress_req *rq,
578c2ecf20Sopenharmony_ci		       struct list_head *pagepool);
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#endif
608c2ecf20Sopenharmony_ci
61