1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (c) Facebook, Inc.
6 * This source code is licensed under both the BSD-style license (found in the
7 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
8 * in the COPYING file in the root directory of this source tree).
9 * You may select, at your option, one of the above-listed licenses.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/string.h>
15 #include <linux/zstd.h>
17 #include "common/zstd_deps.h"
19 /* Common symbols. zstd_compress must depend on zstd_decompress. */
21 unsigned int zstd_is_error(size_t code)
23 return ZSTD_isError(code);
25 EXPORT_SYMBOL(zstd_is_error);
27 zstd_error_code zstd_get_error_code(size_t code)
29 return ZSTD_getErrorCode(code);
31 EXPORT_SYMBOL(zstd_get_error_code);
33 const char *zstd_get_error_name(size_t code)
35 return ZSTD_getErrorName(code);
37 EXPORT_SYMBOL(zstd_get_error_name);
39 /* Decompression symbols. */
41 size_t zstd_dctx_workspace_bound(void)
43 return ZSTD_estimateDCtxSize();
45 EXPORT_SYMBOL(zstd_dctx_workspace_bound);
47 zstd_dctx *zstd_init_dctx(void *workspace, size_t workspace_size)
49 if (workspace == NULL)
51 return ZSTD_initStaticDCtx(workspace, workspace_size);
53 EXPORT_SYMBOL(zstd_init_dctx);
55 size_t zstd_decompress_dctx(zstd_dctx *dctx, void *dst, size_t dst_capacity,
56 const void *src, size_t src_size)
58 return ZSTD_decompressDCtx(dctx, dst, dst_capacity, src, src_size);
60 EXPORT_SYMBOL(zstd_decompress_dctx);
62 size_t zstd_dstream_workspace_bound(size_t max_window_size)
64 return ZSTD_estimateDStreamSize(max_window_size);
66 EXPORT_SYMBOL(zstd_dstream_workspace_bound);
68 zstd_dstream *zstd_init_dstream(size_t max_window_size, void *workspace,
69 size_t workspace_size)
71 if (workspace == NULL)
73 (void)max_window_size;
74 return ZSTD_initStaticDStream(workspace, workspace_size);
76 EXPORT_SYMBOL(zstd_init_dstream);
78 size_t zstd_reset_dstream(zstd_dstream *dstream)
80 return ZSTD_resetDStream(dstream);
82 EXPORT_SYMBOL(zstd_reset_dstream);
84 size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output,
85 zstd_in_buffer *input)
87 return ZSTD_decompressStream(dstream, output, input);
89 EXPORT_SYMBOL(zstd_decompress_stream);
91 size_t zstd_find_frame_compressed_size(const void *src, size_t src_size)
93 return ZSTD_findFrameCompressedSize(src, src_size);
95 EXPORT_SYMBOL(zstd_find_frame_compressed_size);
97 size_t zstd_get_frame_header(zstd_frame_header *header, const void *src,
100 return ZSTD_getFrameHeader(header, src, src_size);
102 EXPORT_SYMBOL(zstd_get_frame_header);
104 MODULE_LICENSE("Dual BSD/GPL");
105 MODULE_DESCRIPTION("Zstd Decompressor");