1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5c9431faahl * Common Development and Distribution License (the "License").
6c9431faahl * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21c9431faahl
22fa9e406ahrens/*
23b24ab67Jeff Bonwick * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24fa9e406ahrens * Use is subject to license terms.
25fa9e406ahrens */
26a6f561bSašo Kiselkov/*
27a6f561bSašo Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
28770499eDan Kimmel * Copyright (c) 2015, 2016 by Delphix. All rights reserved.
29a6f561bSašo Kiselkov */
30fa9e406ahrens
31fa9e406ahrens#ifndef _SYS_ZIO_COMPRESS_H
32fa9e406ahrens#define	_SYS_ZIO_COMPRESS_H
33fa9e406ahrens
34770499eDan Kimmel#include <sys/abd.h>
35770499eDan Kimmel
36fa9e406ahrens#ifdef	__cplusplus
37fa9e406ahrensextern "C" {
38fa9e406ahrens#endif
39fa9e406ahrens
405602294Dan Kimmelenum zio_compress {
415602294Dan Kimmel	ZIO_COMPRESS_INHERIT = 0,
425602294Dan Kimmel	ZIO_COMPRESS_ON,
435602294Dan Kimmel	ZIO_COMPRESS_OFF,
445602294Dan Kimmel	ZIO_COMPRESS_LZJB,
455602294Dan Kimmel	ZIO_COMPRESS_EMPTY,
465602294Dan Kimmel	ZIO_COMPRESS_GZIP_1,
475602294Dan Kimmel	ZIO_COMPRESS_GZIP_2,
485602294Dan Kimmel	ZIO_COMPRESS_GZIP_3,
495602294Dan Kimmel	ZIO_COMPRESS_GZIP_4,
505602294Dan Kimmel	ZIO_COMPRESS_GZIP_5,
515602294Dan Kimmel	ZIO_COMPRESS_GZIP_6,
525602294Dan Kimmel	ZIO_COMPRESS_GZIP_7,
535602294Dan Kimmel	ZIO_COMPRESS_GZIP_8,
545602294Dan Kimmel	ZIO_COMPRESS_GZIP_9,
555602294Dan Kimmel	ZIO_COMPRESS_ZLE,
565602294Dan Kimmel	ZIO_COMPRESS_LZ4,
575602294Dan Kimmel	ZIO_COMPRESS_FUNCTIONS
585602294Dan Kimmel};
595602294Dan Kimmel
60f717074Will Andrews/* Common signature for all zio compress functions. */
61fa9e406ahrenstypedef size_t zio_compress_func_t(void *src, void *dst,
62c9431faahl    size_t s_len, size_t d_len, int);
63f717074Will Andrews/* Common signature for all zio decompress functions. */
64fa9e406ahrenstypedef int zio_decompress_func_t(void *src, void *dst,
65c9431faahl    size_t s_len, size_t d_len, int);
66770499eDan Kimmel/*
67770499eDan Kimmel * Common signature for all zio decompress functions using an ABD as input.
68770499eDan Kimmel * This is helpful if you have both compressed ARC and scatter ABDs enabled,
69770499eDan Kimmel * but is not a requirement for all compression algorithms.
70770499eDan Kimmel */
71770499eDan Kimmeltypedef int zio_decompress_abd_func_t(abd_t *src, void *dst,
72770499eDan Kimmel    size_t s_len, size_t d_len, int);
73fa9e406ahrens
74fa9e406ahrens/*
75fa9e406ahrens * Information about each compression function.
76fa9e406ahrens */
77fa9e406ahrenstypedef struct zio_compress_info {
78770499eDan Kimmel	char				*ci_name;
79770499eDan Kimmel	int				ci_level;
80770499eDan Kimmel	zio_compress_func_t		*ci_compress;
81770499eDan Kimmel	zio_decompress_func_t		*ci_decompress;
82fa9e406ahrens} zio_compress_info_t;
83fa9e406ahrens
84fa9e406ahrensextern zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS];
85fa9e406ahrens
86fa9e406ahrens/*
87fa9e406ahrens * Compression routines.
88fa9e406ahrens */
89c9431faahlextern size_t lzjb_compress(void *src, void *dst, size_t s_len, size_t d_len,
90c9431faahl    int level);
91c9431faahlextern int lzjb_decompress(void *src, void *dst, size_t s_len, size_t d_len,
92c9431faahl    int level);
93c9431faahlextern size_t gzip_compress(void *src, void *dst, size_t s_len, size_t d_len,
94c9431faahl    int level);
95c9431faahlextern int gzip_decompress(void *src, void *dst, size_t s_len, size_t d_len,
96c9431faahl    int level);
97b24ab67Jeff Bonwickextern size_t zle_compress(void *src, void *dst, size_t s_len, size_t d_len,
98b24ab67Jeff Bonwick    int level);
99b24ab67Jeff Bonwickextern int zle_decompress(void *src, void *dst, size_t s_len, size_t d_len,
100b24ab67Jeff Bonwick    int level);
101a6f561bSašo Kiselkovextern size_t lz4_compress(void *src, void *dst, size_t s_len, size_t d_len,
102a6f561bSašo Kiselkov    int level);
103a6f561bSašo Kiselkovextern int lz4_decompress(void *src, void *dst, size_t s_len, size_t d_len,
104a6f561bSašo Kiselkov    int level);
105fa9e406ahrens
106fa9e406ahrens/*
107fa9e406ahrens * Compress and decompress data if necessary.
108fa9e406ahrens */
109770499eDan Kimmelextern size_t zio_compress_data(enum zio_compress c, abd_t *src, void *dst,
110b24ab67Jeff Bonwick    size_t s_len);
111770499eDan Kimmelextern int zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
112770499eDan Kimmel    size_t s_len, size_t d_len);
113770499eDan Kimmelextern int zio_decompress_data_buf(enum zio_compress c, void *src, void *dst,
114b24ab67Jeff Bonwick    size_t s_len, size_t d_len);
115fa9e406ahrens
116fa9e406ahrens#ifdef	__cplusplus
117fa9e406ahrens}
118fa9e406ahrens#endif
119fa9e406ahrens
120fa9e406ahrens#endif	/* _SYS_ZIO_COMPRESS_H */
121