4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Copyright (c) 2019, Allan Jude
25 * Copyright (c) 2019, Klara Inc.
26 * Use is subject to license terms.
27 * Copyright (c) 2015, 2016 by Delphix. All rights reserved.
30 #ifndef _SYS_ZIO_COMPRESS_H
31 #define _SYS_ZIO_COMPRESS_H
40 ZIO_COMPRESS_INHERIT = 0,
57 ZIO_COMPRESS_FUNCTIONS
60 /* Compression algorithms that have levels */
61 #define ZIO_COMPRESS_HASLEVEL(compress) ((compress == ZIO_COMPRESS_ZSTD || \
62 (compress >= ZIO_COMPRESS_GZIP_1 && \
63 compress <= ZIO_COMPRESS_GZIP_9)))
65 #define ZIO_COMPLEVEL_INHERIT 0
66 #define ZIO_COMPLEVEL_DEFAULT 255
68 enum zio_zstd_levels {
69 ZIO_ZSTD_LEVEL_INHERIT = 0,
71 #define ZIO_ZSTD_LEVEL_MIN ZIO_ZSTD_LEVEL_1
74 #define ZIO_ZSTD_LEVEL_DEFAULT ZIO_ZSTD_LEVEL_3
91 #define ZIO_ZSTD_LEVEL_MAX ZIO_ZSTD_LEVEL_19
92 ZIO_ZSTD_LEVEL_RESERVE = 101, /* Leave room for new positive levels */
93 ZIO_ZSTD_LEVEL_FAST, /* Fast levels are negative */
94 ZIO_ZSTD_LEVEL_FAST_1,
95 #define ZIO_ZSTD_LEVEL_FAST_DEFAULT ZIO_ZSTD_LEVEL_FAST_1
96 ZIO_ZSTD_LEVEL_FAST_2,
97 ZIO_ZSTD_LEVEL_FAST_3,
98 ZIO_ZSTD_LEVEL_FAST_4,
99 ZIO_ZSTD_LEVEL_FAST_5,
100 ZIO_ZSTD_LEVEL_FAST_6,
101 ZIO_ZSTD_LEVEL_FAST_7,
102 ZIO_ZSTD_LEVEL_FAST_8,
103 ZIO_ZSTD_LEVEL_FAST_9,
104 ZIO_ZSTD_LEVEL_FAST_10,
105 ZIO_ZSTD_LEVEL_FAST_20,
106 ZIO_ZSTD_LEVEL_FAST_30,
107 ZIO_ZSTD_LEVEL_FAST_40,
108 ZIO_ZSTD_LEVEL_FAST_50,
109 ZIO_ZSTD_LEVEL_FAST_60,
110 ZIO_ZSTD_LEVEL_FAST_70,
111 ZIO_ZSTD_LEVEL_FAST_80,
112 ZIO_ZSTD_LEVEL_FAST_90,
113 ZIO_ZSTD_LEVEL_FAST_100,
114 ZIO_ZSTD_LEVEL_FAST_500,
115 ZIO_ZSTD_LEVEL_FAST_1000,
116 #define ZIO_ZSTD_LEVEL_FAST_MAX ZIO_ZSTD_LEVEL_FAST_1000
117 ZIO_ZSTD_LEVEL_AUTO = 251, /* Reserved for future use */
118 ZIO_ZSTD_LEVEL_LEVELS
121 /* Forward Declaration to avoid visibility problems */
124 /* Common signature for all zio compress functions. */
125 typedef size_t zio_compress_func_t(void *src, void *dst,
126 size_t s_len, size_t d_len, int);
127 /* Common signature for all zio decompress functions. */
128 typedef int zio_decompress_func_t(void *src, void *dst,
129 size_t s_len, size_t d_len, int);
130 /* Common signature for all zio decompress and get level functions. */
131 typedef int zio_decompresslevel_func_t(void *src, void *dst,
132 size_t s_len, size_t d_len, uint8_t *level);
133 /* Common signature for all zio get-compression-level functions. */
134 typedef int zio_getlevel_func_t(void *src, size_t s_len, uint8_t *level);
138 * Common signature for all zio decompress functions using an ABD as input.
139 * This is helpful if you have both compressed ARC and scatter ABDs enabled,
140 * but is not a requirement for all compression algorithms.
142 typedef int zio_decompress_abd_func_t(abd_t *src, void *dst,
143 size_t s_len, size_t d_len, int);
145 * Information about each compression function.
147 typedef const struct zio_compress_info {
150 zio_compress_func_t *ci_compress;
151 zio_decompress_func_t *ci_decompress;
152 zio_decompresslevel_func_t *ci_decompress_level;
153 } zio_compress_info_t;
155 extern zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS];
158 * lz4 compression init & free
160 extern void lz4_init(void);
161 extern void lz4_fini(void);
164 * Compression routines.
166 extern size_t lzjb_compress(void *src, void *dst, size_t s_len, size_t d_len,
168 extern int lzjb_decompress(void *src, void *dst, size_t s_len, size_t d_len,
170 extern size_t gzip_compress(void *src, void *dst, size_t s_len, size_t d_len,
172 extern int gzip_decompress(void *src, void *dst, size_t s_len, size_t d_len,
174 extern size_t zle_compress(void *src, void *dst, size_t s_len, size_t d_len,
176 extern int zle_decompress(void *src, void *dst, size_t s_len, size_t d_len,
178 extern size_t lz4_compress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
180 extern int lz4_decompress_zfs(void *src, void *dst, size_t s_len, size_t d_len,
184 * Compress and decompress data if necessary.
186 extern size_t zio_compress_data(enum zio_compress c, abd_t *src, void *dst,
187 size_t s_len, uint8_t level);
188 extern int zio_decompress_data(enum zio_compress c, abd_t *src, void *dst,
189 size_t s_len, size_t d_len, uint8_t *level);
190 extern int zio_decompress_data_buf(enum zio_compress c, void *src, void *dst,
191 size_t s_len, size_t d_len, uint8_t *level);
192 extern int zio_compress_to_feature(enum zio_compress comp);
198 #endif /* _SYS_ZIO_COMPRESS_H */