~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/lib/zstd/zstd_compress_module.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
  2 /*
  3  * Copyright (c) Facebook, Inc.
  4  * All rights reserved.
  5  *
  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.
 10  */
 11 
 12 #include <linux/kernel.h>
 13 #include <linux/module.h>
 14 #include <linux/string.h>
 15 #include <linux/zstd.h>
 16 
 17 #include "common/zstd_deps.h"
 18 #include "common/zstd_internal.h"
 19 
 20 #define ZSTD_FORWARD_IF_ERR(ret)            \
 21         do {                                \
 22                 size_t const __ret = (ret); \
 23                 if (ZSTD_isError(__ret))    \
 24                         return __ret;       \
 25         } while (0)
 26 
 27 static size_t zstd_cctx_init(zstd_cctx *cctx, const zstd_parameters *parameters,
 28         unsigned long long pledged_src_size)
 29 {
 30         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_reset(
 31                 cctx, ZSTD_reset_session_and_parameters));
 32         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setPledgedSrcSize(
 33                 cctx, pledged_src_size));
 34         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 35                 cctx, ZSTD_c_windowLog, parameters->cParams.windowLog));
 36         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 37                 cctx, ZSTD_c_hashLog, parameters->cParams.hashLog));
 38         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 39                 cctx, ZSTD_c_chainLog, parameters->cParams.chainLog));
 40         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 41                 cctx, ZSTD_c_searchLog, parameters->cParams.searchLog));
 42         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 43                 cctx, ZSTD_c_minMatch, parameters->cParams.minMatch));
 44         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 45                 cctx, ZSTD_c_targetLength, parameters->cParams.targetLength));
 46         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 47                 cctx, ZSTD_c_strategy, parameters->cParams.strategy));
 48         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 49                 cctx, ZSTD_c_contentSizeFlag, parameters->fParams.contentSizeFlag));
 50         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 51                 cctx, ZSTD_c_checksumFlag, parameters->fParams.checksumFlag));
 52         ZSTD_FORWARD_IF_ERR(ZSTD_CCtx_setParameter(
 53                 cctx, ZSTD_c_dictIDFlag, !parameters->fParams.noDictIDFlag));
 54         return 0;
 55 }
 56 
 57 int zstd_min_clevel(void)
 58 {
 59         return ZSTD_minCLevel();
 60 }
 61 EXPORT_SYMBOL(zstd_min_clevel);
 62 
 63 int zstd_max_clevel(void)
 64 {
 65         return ZSTD_maxCLevel();
 66 }
 67 EXPORT_SYMBOL(zstd_max_clevel);
 68 
 69 size_t zstd_compress_bound(size_t src_size)
 70 {
 71         return ZSTD_compressBound(src_size);
 72 }
 73 EXPORT_SYMBOL(zstd_compress_bound);
 74 
 75 zstd_parameters zstd_get_params(int level,
 76         unsigned long long estimated_src_size)
 77 {
 78         return ZSTD_getParams(level, estimated_src_size, 0);
 79 }
 80 EXPORT_SYMBOL(zstd_get_params);
 81 
 82 size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *cparams)
 83 {
 84         return ZSTD_estimateCCtxSize_usingCParams(*cparams);
 85 }
 86 EXPORT_SYMBOL(zstd_cctx_workspace_bound);
 87 
 88 zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size)
 89 {
 90         if (workspace == NULL)
 91                 return NULL;
 92         return ZSTD_initStaticCCtx(workspace, workspace_size);
 93 }
 94 EXPORT_SYMBOL(zstd_init_cctx);
 95 
 96 size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity,
 97         const void *src, size_t src_size, const zstd_parameters *parameters)
 98 {
 99         ZSTD_FORWARD_IF_ERR(zstd_cctx_init(cctx, parameters, src_size));
100         return ZSTD_compress2(cctx, dst, dst_capacity, src, src_size);
101 }
102 EXPORT_SYMBOL(zstd_compress_cctx);
103 
104 size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams)
105 {
106         return ZSTD_estimateCStreamSize_usingCParams(*cparams);
107 }
108 EXPORT_SYMBOL(zstd_cstream_workspace_bound);
109 
110 zstd_cstream *zstd_init_cstream(const zstd_parameters *parameters,
111         unsigned long long pledged_src_size, void *workspace, size_t workspace_size)
112 {
113         zstd_cstream *cstream;
114 
115         if (workspace == NULL)
116                 return NULL;
117 
118         cstream = ZSTD_initStaticCStream(workspace, workspace_size);
119         if (cstream == NULL)
120                 return NULL;
121 
122         /* 0 means unknown in linux zstd API but means 0 in new zstd API */
123         if (pledged_src_size == 0)
124                 pledged_src_size = ZSTD_CONTENTSIZE_UNKNOWN;
125 
126         if (ZSTD_isError(zstd_cctx_init(cstream, parameters, pledged_src_size)))
127                 return NULL;
128 
129         return cstream;
130 }
131 EXPORT_SYMBOL(zstd_init_cstream);
132 
133 size_t zstd_reset_cstream(zstd_cstream *cstream,
134         unsigned long long pledged_src_size)
135 {
136         if (pledged_src_size == 0)
137                 pledged_src_size = ZSTD_CONTENTSIZE_UNKNOWN;
138         ZSTD_FORWARD_IF_ERR( ZSTD_CCtx_reset(cstream, ZSTD_reset_session_only) );
139         ZSTD_FORWARD_IF_ERR( ZSTD_CCtx_setPledgedSrcSize(cstream, pledged_src_size) );
140         return 0;
141 }
142 EXPORT_SYMBOL(zstd_reset_cstream);
143 
144 size_t zstd_compress_stream(zstd_cstream *cstream, zstd_out_buffer *output,
145         zstd_in_buffer *input)
146 {
147         return ZSTD_compressStream(cstream, output, input);
148 }
149 EXPORT_SYMBOL(zstd_compress_stream);
150 
151 size_t zstd_flush_stream(zstd_cstream *cstream, zstd_out_buffer *output)
152 {
153         return ZSTD_flushStream(cstream, output);
154 }
155 EXPORT_SYMBOL(zstd_flush_stream);
156 
157 size_t zstd_end_stream(zstd_cstream *cstream, zstd_out_buffer *output)
158 {
159         return ZSTD_endStream(cstream, output);
160 }
161 EXPORT_SYMBOL(zstd_end_stream);
162 
163 MODULE_LICENSE("Dual BSD/GPL");
164 MODULE_DESCRIPTION("Zstd Compressor");
165 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php