1*3117ece4Schristos /* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */ 2*3117ece4Schristos /* 3*3117ece4Schristos * Copyright (c) Meta Platforms, Inc. and affiliates. 4*3117ece4Schristos * All rights reserved. 5*3117ece4Schristos * 6*3117ece4Schristos * This source code is licensed under both the BSD-style license (found in the 7*3117ece4Schristos * LICENSE file in the root directory of https://github.com/facebook/zstd) and 8*3117ece4Schristos * the GPLv2 (found in the COPYING file in the root directory of 9*3117ece4Schristos * https://github.com/facebook/zstd). You may select, at your option, one of the 10*3117ece4Schristos * above-listed licenses. 11*3117ece4Schristos */ 12*3117ece4Schristos 13*3117ece4Schristos #ifndef LINUX_ZSTD_H 14*3117ece4Schristos #define LINUX_ZSTD_H 15*3117ece4Schristos 16*3117ece4Schristos /** 17*3117ece4Schristos * This is a kernel-style API that wraps the upstream zstd API, which cannot be 18*3117ece4Schristos * used directly because the symbols aren't exported. It exposes the minimal 19*3117ece4Schristos * functionality which is currently required by users of zstd in the kernel. 20*3117ece4Schristos * Expose extra functions from lib/zstd/zstd.h as needed. 21*3117ece4Schristos */ 22*3117ece4Schristos 23*3117ece4Schristos /* ====== Dependency ====== */ 24*3117ece4Schristos #include <linux/types.h> 25*3117ece4Schristos #include <linux/zstd_errors.h> 26*3117ece4Schristos #include <linux/zstd_lib.h> 27*3117ece4Schristos 28*3117ece4Schristos /* ====== Helper Functions ====== */ 29*3117ece4Schristos /** 30*3117ece4Schristos * zstd_compress_bound() - maximum compressed size in worst case scenario 31*3117ece4Schristos * @src_size: The size of the data to compress. 32*3117ece4Schristos * 33*3117ece4Schristos * Return: The maximum compressed size in the worst case scenario. 34*3117ece4Schristos */ 35*3117ece4Schristos size_t zstd_compress_bound(size_t src_size); 36*3117ece4Schristos 37*3117ece4Schristos /** 38*3117ece4Schristos * zstd_is_error() - tells if a size_t function result is an error code 39*3117ece4Schristos * @code: The function result to check for error. 40*3117ece4Schristos * 41*3117ece4Schristos * Return: Non-zero iff the code is an error. 42*3117ece4Schristos */ 43*3117ece4Schristos unsigned int zstd_is_error(size_t code); 44*3117ece4Schristos 45*3117ece4Schristos /** 46*3117ece4Schristos * enum zstd_error_code - zstd error codes 47*3117ece4Schristos */ 48*3117ece4Schristos typedef ZSTD_ErrorCode zstd_error_code; 49*3117ece4Schristos 50*3117ece4Schristos /** 51*3117ece4Schristos * zstd_get_error_code() - translates an error function result to an error code 52*3117ece4Schristos * @code: The function result for which zstd_is_error(code) is true. 53*3117ece4Schristos * 54*3117ece4Schristos * Return: A unique error code for this error. 55*3117ece4Schristos */ 56*3117ece4Schristos zstd_error_code zstd_get_error_code(size_t code); 57*3117ece4Schristos 58*3117ece4Schristos /** 59*3117ece4Schristos * zstd_get_error_name() - translates an error function result to a string 60*3117ece4Schristos * @code: The function result for which zstd_is_error(code) is true. 61*3117ece4Schristos * 62*3117ece4Schristos * Return: An error string corresponding to the error code. 63*3117ece4Schristos */ 64*3117ece4Schristos const char *zstd_get_error_name(size_t code); 65*3117ece4Schristos 66*3117ece4Schristos /** 67*3117ece4Schristos * zstd_min_clevel() - minimum allowed compression level 68*3117ece4Schristos * 69*3117ece4Schristos * Return: The minimum allowed compression level. 70*3117ece4Schristos */ 71*3117ece4Schristos int zstd_min_clevel(void); 72*3117ece4Schristos 73*3117ece4Schristos /** 74*3117ece4Schristos * zstd_max_clevel() - maximum allowed compression level 75*3117ece4Schristos * 76*3117ece4Schristos * Return: The maximum allowed compression level. 77*3117ece4Schristos */ 78*3117ece4Schristos int zstd_max_clevel(void); 79*3117ece4Schristos 80*3117ece4Schristos /* ====== Parameter Selection ====== */ 81*3117ece4Schristos 82*3117ece4Schristos /** 83*3117ece4Schristos * enum zstd_strategy - zstd compression search strategy 84*3117ece4Schristos * 85*3117ece4Schristos * From faster to stronger. See zstd_lib.h. 86*3117ece4Schristos */ 87*3117ece4Schristos typedef ZSTD_strategy zstd_strategy; 88*3117ece4Schristos 89*3117ece4Schristos /** 90*3117ece4Schristos * struct zstd_compression_parameters - zstd compression parameters 91*3117ece4Schristos * @windowLog: Log of the largest match distance. Larger means more 92*3117ece4Schristos * compression, and more memory needed during decompression. 93*3117ece4Schristos * @chainLog: Fully searched segment. Larger means more compression, 94*3117ece4Schristos * slower, and more memory (useless for fast). 95*3117ece4Schristos * @hashLog: Dispatch table. Larger means more compression, 96*3117ece4Schristos * slower, and more memory. 97*3117ece4Schristos * @searchLog: Number of searches. Larger means more compression and slower. 98*3117ece4Schristos * @searchLength: Match length searched. Larger means faster decompression, 99*3117ece4Schristos * sometimes less compression. 100*3117ece4Schristos * @targetLength: Acceptable match size for optimal parser (only). Larger means 101*3117ece4Schristos * more compression, and slower. 102*3117ece4Schristos * @strategy: The zstd compression strategy. 103*3117ece4Schristos * 104*3117ece4Schristos * See zstd_lib.h. 105*3117ece4Schristos */ 106*3117ece4Schristos typedef ZSTD_compressionParameters zstd_compression_parameters; 107*3117ece4Schristos 108*3117ece4Schristos /** 109*3117ece4Schristos * struct zstd_frame_parameters - zstd frame parameters 110*3117ece4Schristos * @contentSizeFlag: Controls whether content size will be present in the 111*3117ece4Schristos * frame header (when known). 112*3117ece4Schristos * @checksumFlag: Controls whether a 32-bit checksum is generated at the 113*3117ece4Schristos * end of the frame for error detection. 114*3117ece4Schristos * @noDictIDFlag: Controls whether dictID will be saved into the frame 115*3117ece4Schristos * header when using dictionary compression. 116*3117ece4Schristos * 117*3117ece4Schristos * The default value is all fields set to 0. See zstd_lib.h. 118*3117ece4Schristos */ 119*3117ece4Schristos typedef ZSTD_frameParameters zstd_frame_parameters; 120*3117ece4Schristos 121*3117ece4Schristos /** 122*3117ece4Schristos * struct zstd_parameters - zstd parameters 123*3117ece4Schristos * @cParams: The compression parameters. 124*3117ece4Schristos * @fParams: The frame parameters. 125*3117ece4Schristos */ 126*3117ece4Schristos typedef ZSTD_parameters zstd_parameters; 127*3117ece4Schristos 128*3117ece4Schristos /** 129*3117ece4Schristos * zstd_get_params() - returns zstd_parameters for selected level 130*3117ece4Schristos * @level: The compression level 131*3117ece4Schristos * @estimated_src_size: The estimated source size to compress or 0 132*3117ece4Schristos * if unknown. 133*3117ece4Schristos * 134*3117ece4Schristos * Return: The selected zstd_parameters. 135*3117ece4Schristos */ 136*3117ece4Schristos zstd_parameters zstd_get_params(int level, 137*3117ece4Schristos unsigned long long estimated_src_size); 138*3117ece4Schristos 139*3117ece4Schristos /* ====== Single-pass Compression ====== */ 140*3117ece4Schristos 141*3117ece4Schristos typedef ZSTD_CCtx zstd_cctx; 142*3117ece4Schristos 143*3117ece4Schristos /** 144*3117ece4Schristos * zstd_cctx_workspace_bound() - max memory needed to initialize a zstd_cctx 145*3117ece4Schristos * @parameters: The compression parameters to be used. 146*3117ece4Schristos * 147*3117ece4Schristos * If multiple compression parameters might be used, the caller must call 148*3117ece4Schristos * zstd_cctx_workspace_bound() for each set of parameters and use the maximum 149*3117ece4Schristos * size. 150*3117ece4Schristos * 151*3117ece4Schristos * Return: A lower bound on the size of the workspace that is passed to 152*3117ece4Schristos * zstd_init_cctx(). 153*3117ece4Schristos */ 154*3117ece4Schristos size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *parameters); 155*3117ece4Schristos 156*3117ece4Schristos /** 157*3117ece4Schristos * zstd_init_cctx() - initialize a zstd compression context 158*3117ece4Schristos * @workspace: The workspace to emplace the context into. It must outlive 159*3117ece4Schristos * the returned context. 160*3117ece4Schristos * @workspace_size: The size of workspace. Use zstd_cctx_workspace_bound() to 161*3117ece4Schristos * determine how large the workspace must be. 162*3117ece4Schristos * 163*3117ece4Schristos * Return: A zstd compression context or NULL on error. 164*3117ece4Schristos */ 165*3117ece4Schristos zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size); 166*3117ece4Schristos 167*3117ece4Schristos /** 168*3117ece4Schristos * zstd_compress_cctx() - compress src into dst with the initialized parameters 169*3117ece4Schristos * @cctx: The context. Must have been initialized with zstd_init_cctx(). 170*3117ece4Schristos * @dst: The buffer to compress src into. 171*3117ece4Schristos * @dst_capacity: The size of the destination buffer. May be any size, but 172*3117ece4Schristos * ZSTD_compressBound(srcSize) is guaranteed to be large enough. 173*3117ece4Schristos * @src: The data to compress. 174*3117ece4Schristos * @src_size: The size of the data to compress. 175*3117ece4Schristos * @parameters: The compression parameters to be used. 176*3117ece4Schristos * 177*3117ece4Schristos * Return: The compressed size or an error, which can be checked using 178*3117ece4Schristos * zstd_is_error(). 179*3117ece4Schristos */ 180*3117ece4Schristos size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity, 181*3117ece4Schristos const void *src, size_t src_size, const zstd_parameters *parameters); 182*3117ece4Schristos 183*3117ece4Schristos /* ====== Single-pass Decompression ====== */ 184*3117ece4Schristos 185*3117ece4Schristos typedef ZSTD_DCtx zstd_dctx; 186*3117ece4Schristos 187*3117ece4Schristos /** 188*3117ece4Schristos * zstd_dctx_workspace_bound() - max memory needed to initialize a zstd_dctx 189*3117ece4Schristos * 190*3117ece4Schristos * Return: A lower bound on the size of the workspace that is passed to 191*3117ece4Schristos * zstd_init_dctx(). 192*3117ece4Schristos */ 193*3117ece4Schristos size_t zstd_dctx_workspace_bound(void); 194*3117ece4Schristos 195*3117ece4Schristos /** 196*3117ece4Schristos * zstd_init_dctx() - initialize a zstd decompression context 197*3117ece4Schristos * @workspace: The workspace to emplace the context into. It must outlive 198*3117ece4Schristos * the returned context. 199*3117ece4Schristos * @workspace_size: The size of workspace. Use zstd_dctx_workspace_bound() to 200*3117ece4Schristos * determine how large the workspace must be. 201*3117ece4Schristos * 202*3117ece4Schristos * Return: A zstd decompression context or NULL on error. 203*3117ece4Schristos */ 204*3117ece4Schristos zstd_dctx *zstd_init_dctx(void *workspace, size_t workspace_size); 205*3117ece4Schristos 206*3117ece4Schristos /** 207*3117ece4Schristos * zstd_decompress_dctx() - decompress zstd compressed src into dst 208*3117ece4Schristos * @dctx: The decompression context. 209*3117ece4Schristos * @dst: The buffer to decompress src into. 210*3117ece4Schristos * @dst_capacity: The size of the destination buffer. Must be at least as large 211*3117ece4Schristos * as the decompressed size. If the caller cannot upper bound the 212*3117ece4Schristos * decompressed size, then it's better to use the streaming API. 213*3117ece4Schristos * @src: The zstd compressed data to decompress. Multiple concatenated 214*3117ece4Schristos * frames and skippable frames are allowed. 215*3117ece4Schristos * @src_size: The exact size of the data to decompress. 216*3117ece4Schristos * 217*3117ece4Schristos * Return: The decompressed size or an error, which can be checked using 218*3117ece4Schristos * zstd_is_error(). 219*3117ece4Schristos */ 220*3117ece4Schristos size_t zstd_decompress_dctx(zstd_dctx *dctx, void *dst, size_t dst_capacity, 221*3117ece4Schristos const void *src, size_t src_size); 222*3117ece4Schristos 223*3117ece4Schristos /* ====== Streaming Buffers ====== */ 224*3117ece4Schristos 225*3117ece4Schristos /** 226*3117ece4Schristos * struct zstd_in_buffer - input buffer for streaming 227*3117ece4Schristos * @src: Start of the input buffer. 228*3117ece4Schristos * @size: Size of the input buffer. 229*3117ece4Schristos * @pos: Position where reading stopped. Will be updated. 230*3117ece4Schristos * Necessarily 0 <= pos <= size. 231*3117ece4Schristos * 232*3117ece4Schristos * See zstd_lib.h. 233*3117ece4Schristos */ 234*3117ece4Schristos typedef ZSTD_inBuffer zstd_in_buffer; 235*3117ece4Schristos 236*3117ece4Schristos /** 237*3117ece4Schristos * struct zstd_out_buffer - output buffer for streaming 238*3117ece4Schristos * @dst: Start of the output buffer. 239*3117ece4Schristos * @size: Size of the output buffer. 240*3117ece4Schristos * @pos: Position where writing stopped. Will be updated. 241*3117ece4Schristos * Necessarily 0 <= pos <= size. 242*3117ece4Schristos * 243*3117ece4Schristos * See zstd_lib.h. 244*3117ece4Schristos */ 245*3117ece4Schristos typedef ZSTD_outBuffer zstd_out_buffer; 246*3117ece4Schristos 247*3117ece4Schristos /* ====== Streaming Compression ====== */ 248*3117ece4Schristos 249*3117ece4Schristos typedef ZSTD_CStream zstd_cstream; 250*3117ece4Schristos 251*3117ece4Schristos /** 252*3117ece4Schristos * zstd_cstream_workspace_bound() - memory needed to initialize a zstd_cstream 253*3117ece4Schristos * @cparams: The compression parameters to be used for compression. 254*3117ece4Schristos * 255*3117ece4Schristos * Return: A lower bound on the size of the workspace that is passed to 256*3117ece4Schristos * zstd_init_cstream(). 257*3117ece4Schristos */ 258*3117ece4Schristos size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams); 259*3117ece4Schristos 260*3117ece4Schristos /** 261*3117ece4Schristos * zstd_init_cstream() - initialize a zstd streaming compression context 262*3117ece4Schristos * @parameters The zstd parameters to use for compression. 263*3117ece4Schristos * @pledged_src_size: If params.fParams.contentSizeFlag == 1 then the caller 264*3117ece4Schristos * must pass the source size (zero means empty source). 265*3117ece4Schristos * Otherwise, the caller may optionally pass the source 266*3117ece4Schristos * size, or zero if unknown. 267*3117ece4Schristos * @workspace: The workspace to emplace the context into. It must outlive 268*3117ece4Schristos * the returned context. 269*3117ece4Schristos * @workspace_size: The size of workspace. 270*3117ece4Schristos * Use zstd_cstream_workspace_bound(params->cparams) to 271*3117ece4Schristos * determine how large the workspace must be. 272*3117ece4Schristos * 273*3117ece4Schristos * Return: The zstd streaming compression context or NULL on error. 274*3117ece4Schristos */ 275*3117ece4Schristos zstd_cstream *zstd_init_cstream(const zstd_parameters *parameters, 276*3117ece4Schristos unsigned long long pledged_src_size, void *workspace, size_t workspace_size); 277*3117ece4Schristos 278*3117ece4Schristos /** 279*3117ece4Schristos * zstd_reset_cstream() - reset the context using parameters from creation 280*3117ece4Schristos * @cstream: The zstd streaming compression context to reset. 281*3117ece4Schristos * @pledged_src_size: Optionally the source size, or zero if unknown. 282*3117ece4Schristos * 283*3117ece4Schristos * Resets the context using the parameters from creation. Skips dictionary 284*3117ece4Schristos * loading, since it can be reused. If `pledged_src_size` is non-zero the frame 285*3117ece4Schristos * content size is always written into the frame header. 286*3117ece4Schristos * 287*3117ece4Schristos * Return: Zero or an error, which can be checked using 288*3117ece4Schristos * zstd_is_error(). 289*3117ece4Schristos */ 290*3117ece4Schristos size_t zstd_reset_cstream(zstd_cstream *cstream, 291*3117ece4Schristos unsigned long long pledged_src_size); 292*3117ece4Schristos 293*3117ece4Schristos /** 294*3117ece4Schristos * zstd_compress_stream() - streaming compress some of input into output 295*3117ece4Schristos * @cstream: The zstd streaming compression context. 296*3117ece4Schristos * @output: Destination buffer. `output->pos` is updated to indicate how much 297*3117ece4Schristos * compressed data was written. 298*3117ece4Schristos * @input: Source buffer. `input->pos` is updated to indicate how much data 299*3117ece4Schristos * was read. Note that it may not consume the entire input, in which 300*3117ece4Schristos * case `input->pos < input->size`, and it's up to the caller to 301*3117ece4Schristos * present remaining data again. 302*3117ece4Schristos * 303*3117ece4Schristos * The `input` and `output` buffers may be any size. Guaranteed to make some 304*3117ece4Schristos * forward progress if `input` and `output` are not empty. 305*3117ece4Schristos * 306*3117ece4Schristos * Return: A hint for the number of bytes to use as the input for the next 307*3117ece4Schristos * function call or an error, which can be checked using 308*3117ece4Schristos * zstd_is_error(). 309*3117ece4Schristos */ 310*3117ece4Schristos size_t zstd_compress_stream(zstd_cstream *cstream, zstd_out_buffer *output, 311*3117ece4Schristos zstd_in_buffer *input); 312*3117ece4Schristos 313*3117ece4Schristos /** 314*3117ece4Schristos * zstd_flush_stream() - flush internal buffers into output 315*3117ece4Schristos * @cstream: The zstd streaming compression context. 316*3117ece4Schristos * @output: Destination buffer. `output->pos` is updated to indicate how much 317*3117ece4Schristos * compressed data was written. 318*3117ece4Schristos * 319*3117ece4Schristos * zstd_flush_stream() must be called until it returns 0, meaning all the data 320*3117ece4Schristos * has been flushed. Since zstd_flush_stream() causes a block to be ended, 321*3117ece4Schristos * calling it too often will degrade the compression ratio. 322*3117ece4Schristos * 323*3117ece4Schristos * Return: The number of bytes still present within internal buffers or an 324*3117ece4Schristos * error, which can be checked using zstd_is_error(). 325*3117ece4Schristos */ 326*3117ece4Schristos size_t zstd_flush_stream(zstd_cstream *cstream, zstd_out_buffer *output); 327*3117ece4Schristos 328*3117ece4Schristos /** 329*3117ece4Schristos * zstd_end_stream() - flush internal buffers into output and end the frame 330*3117ece4Schristos * @cstream: The zstd streaming compression context. 331*3117ece4Schristos * @output: Destination buffer. `output->pos` is updated to indicate how much 332*3117ece4Schristos * compressed data was written. 333*3117ece4Schristos * 334*3117ece4Schristos * zstd_end_stream() must be called until it returns 0, meaning all the data has 335*3117ece4Schristos * been flushed and the frame epilogue has been written. 336*3117ece4Schristos * 337*3117ece4Schristos * Return: The number of bytes still present within internal buffers or an 338*3117ece4Schristos * error, which can be checked using zstd_is_error(). 339*3117ece4Schristos */ 340*3117ece4Schristos size_t zstd_end_stream(zstd_cstream *cstream, zstd_out_buffer *output); 341*3117ece4Schristos 342*3117ece4Schristos /* ====== Streaming Decompression ====== */ 343*3117ece4Schristos 344*3117ece4Schristos typedef ZSTD_DStream zstd_dstream; 345*3117ece4Schristos 346*3117ece4Schristos /** 347*3117ece4Schristos * zstd_dstream_workspace_bound() - memory needed to initialize a zstd_dstream 348*3117ece4Schristos * @max_window_size: The maximum window size allowed for compressed frames. 349*3117ece4Schristos * 350*3117ece4Schristos * Return: A lower bound on the size of the workspace that is passed 351*3117ece4Schristos * to zstd_init_dstream(). 352*3117ece4Schristos */ 353*3117ece4Schristos size_t zstd_dstream_workspace_bound(size_t max_window_size); 354*3117ece4Schristos 355*3117ece4Schristos /** 356*3117ece4Schristos * zstd_init_dstream() - initialize a zstd streaming decompression context 357*3117ece4Schristos * @max_window_size: The maximum window size allowed for compressed frames. 358*3117ece4Schristos * @workspace: The workspace to emplace the context into. It must outlive 359*3117ece4Schristos * the returned context. 360*3117ece4Schristos * @workspaceSize: The size of workspace. 361*3117ece4Schristos * Use zstd_dstream_workspace_bound(max_window_size) to 362*3117ece4Schristos * determine how large the workspace must be. 363*3117ece4Schristos * 364*3117ece4Schristos * Return: The zstd streaming decompression context. 365*3117ece4Schristos */ 366*3117ece4Schristos zstd_dstream *zstd_init_dstream(size_t max_window_size, void *workspace, 367*3117ece4Schristos size_t workspace_size); 368*3117ece4Schristos 369*3117ece4Schristos /** 370*3117ece4Schristos * zstd_reset_dstream() - reset the context using parameters from creation 371*3117ece4Schristos * @dstream: The zstd streaming decompression context to reset. 372*3117ece4Schristos * 373*3117ece4Schristos * Resets the context using the parameters from creation. Skips dictionary 374*3117ece4Schristos * loading, since it can be reused. 375*3117ece4Schristos * 376*3117ece4Schristos * Return: Zero or an error, which can be checked using zstd_is_error(). 377*3117ece4Schristos */ 378*3117ece4Schristos size_t zstd_reset_dstream(zstd_dstream *dstream); 379*3117ece4Schristos 380*3117ece4Schristos /** 381*3117ece4Schristos * zstd_decompress_stream() - streaming decompress some of input into output 382*3117ece4Schristos * @dstream: The zstd streaming decompression context. 383*3117ece4Schristos * @output: Destination buffer. `output.pos` is updated to indicate how much 384*3117ece4Schristos * decompressed data was written. 385*3117ece4Schristos * @input: Source buffer. `input.pos` is updated to indicate how much data was 386*3117ece4Schristos * read. Note that it may not consume the entire input, in which case 387*3117ece4Schristos * `input.pos < input.size`, and it's up to the caller to present 388*3117ece4Schristos * remaining data again. 389*3117ece4Schristos * 390*3117ece4Schristos * The `input` and `output` buffers may be any size. Guaranteed to make some 391*3117ece4Schristos * forward progress if `input` and `output` are not empty. 392*3117ece4Schristos * zstd_decompress_stream() will not consume the last byte of the frame until 393*3117ece4Schristos * the entire frame is flushed. 394*3117ece4Schristos * 395*3117ece4Schristos * Return: Returns 0 iff a frame is completely decoded and fully flushed. 396*3117ece4Schristos * Otherwise returns a hint for the number of bytes to use as the 397*3117ece4Schristos * input for the next function call or an error, which can be checked 398*3117ece4Schristos * using zstd_is_error(). The size hint will never load more than the 399*3117ece4Schristos * frame. 400*3117ece4Schristos */ 401*3117ece4Schristos size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output, 402*3117ece4Schristos zstd_in_buffer *input); 403*3117ece4Schristos 404*3117ece4Schristos /* ====== Frame Inspection Functions ====== */ 405*3117ece4Schristos 406*3117ece4Schristos /** 407*3117ece4Schristos * zstd_find_frame_compressed_size() - returns the size of a compressed frame 408*3117ece4Schristos * @src: Source buffer. It should point to the start of a zstd encoded 409*3117ece4Schristos * frame or a skippable frame. 410*3117ece4Schristos * @src_size: The size of the source buffer. It must be at least as large as the 411*3117ece4Schristos * size of the frame. 412*3117ece4Schristos * 413*3117ece4Schristos * Return: The compressed size of the frame pointed to by `src` or an error, 414*3117ece4Schristos * which can be check with zstd_is_error(). 415*3117ece4Schristos * Suitable to pass to ZSTD_decompress() or similar functions. 416*3117ece4Schristos */ 417*3117ece4Schristos size_t zstd_find_frame_compressed_size(const void *src, size_t src_size); 418*3117ece4Schristos 419*3117ece4Schristos /** 420*3117ece4Schristos * struct zstd_frame_params - zstd frame parameters stored in the frame header 421*3117ece4Schristos * @frameContentSize: The frame content size, or ZSTD_CONTENTSIZE_UNKNOWN if not 422*3117ece4Schristos * present. 423*3117ece4Schristos * @windowSize: The window size, or 0 if the frame is a skippable frame. 424*3117ece4Schristos * @blockSizeMax: The maximum block size. 425*3117ece4Schristos * @frameType: The frame type (zstd or skippable) 426*3117ece4Schristos * @headerSize: The size of the frame header. 427*3117ece4Schristos * @dictID: The dictionary id, or 0 if not present. 428*3117ece4Schristos * @checksumFlag: Whether a checksum was used. 429*3117ece4Schristos * 430*3117ece4Schristos * See zstd_lib.h. 431*3117ece4Schristos */ 432*3117ece4Schristos typedef ZSTD_frameHeader zstd_frame_header; 433*3117ece4Schristos 434*3117ece4Schristos /** 435*3117ece4Schristos * zstd_get_frame_header() - extracts parameters from a zstd or skippable frame 436*3117ece4Schristos * @params: On success the frame parameters are written here. 437*3117ece4Schristos * @src: The source buffer. It must point to a zstd or skippable frame. 438*3117ece4Schristos * @src_size: The size of the source buffer. 439*3117ece4Schristos * 440*3117ece4Schristos * Return: 0 on success. If more data is required it returns how many bytes 441*3117ece4Schristos * must be provided to make forward progress. Otherwise it returns 442*3117ece4Schristos * an error, which can be checked using zstd_is_error(). 443*3117ece4Schristos */ 444*3117ece4Schristos size_t zstd_get_frame_header(zstd_frame_header *params, const void *src, 445*3117ece4Schristos size_t src_size); 446*3117ece4Schristos 447*3117ece4Schristos #endif /* LINUX_ZSTD_H */ 448