Skip to content

Commit d96f569

Browse files
pfactumsirlucjan
authored andcommitted
zstd: import upstream v1.5.7
Signed-off-by: Oleksandr Natalenko <[email protected]>
1 parent 0ad2507 commit d96f569

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+8746
-4379
lines changed

include/linux/zstd.h

+82-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
22
/*
3-
* Copyright (c) Yann Collet, Facebook, Inc.
3+
* Copyright (c) Meta Platforms, Inc. and affiliates.
44
* All rights reserved.
55
*
66
* This source code is licensed under both the BSD-style license (found in the
@@ -160,6 +160,19 @@ typedef ZSTD_parameters zstd_parameters;
160160
zstd_parameters zstd_get_params(int level,
161161
unsigned long long estimated_src_size);
162162

163+
typedef ZSTD_CCtx zstd_cctx;
164+
typedef ZSTD_cParameter zstd_cparameter;
165+
166+
/**
167+
* zstd_cctx_set_param() - sets a compression parameter
168+
* @cctx: The context. Must have been initialized with zstd_init_cctx().
169+
* @param: The parameter to set.
170+
* @value: The value to set the parameter to.
171+
*
172+
* Return: Zero or an error, which can be checked using zstd_is_error().
173+
*/
174+
size_t zstd_cctx_set_param(zstd_cctx *cctx, zstd_cparameter param, int value);
175+
163176

164177
/**
165178
* zstd_get_cparams() - returns zstd_compression_parameters for selected level
@@ -175,8 +188,6 @@ zstd_compression_parameters zstd_get_cparams(int level,
175188

176189
/* ====== Single-pass Compression ====== */
177190

178-
typedef ZSTD_CCtx zstd_cctx;
179-
180191
/**
181192
* zstd_cctx_workspace_bound() - max memory needed to initialize a zstd_cctx
182193
* @parameters: The compression parameters to be used.
@@ -190,6 +201,20 @@ typedef ZSTD_CCtx zstd_cctx;
190201
*/
191202
size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *parameters);
192203

204+
/**
205+
* zstd_cctx_workspace_bound_with_ext_seq_prod() - max memory needed to
206+
* initialize a zstd_cctx when using the block-level external sequence
207+
* producer API.
208+
* @parameters: The compression parameters to be used.
209+
*
210+
* If multiple compression parameters might be used, the caller must call
211+
* this function for each set of parameters and use the maximum size.
212+
*
213+
* Return: A lower bound on the size of the workspace that is passed to
214+
* zstd_init_cctx().
215+
*/
216+
size_t zstd_cctx_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *parameters);
217+
193218
/**
194219
* zstd_init_cctx() - initialize a zstd compression context
195220
* @workspace: The workspace to emplace the context into. It must outlive
@@ -424,6 +449,16 @@ typedef ZSTD_CStream zstd_cstream;
424449
*/
425450
size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams);
426451

452+
/**
453+
* zstd_cstream_workspace_bound_with_ext_seq_prod() - memory needed to initialize
454+
* a zstd_cstream when using the block-level external sequence producer API.
455+
* @cparams: The compression parameters to be used for compression.
456+
*
457+
* Return: A lower bound on the size of the workspace that is passed to
458+
* zstd_init_cstream().
459+
*/
460+
size_t zstd_cstream_workspace_bound_with_ext_seq_prod(const zstd_compression_parameters *cparams);
461+
427462
/**
428463
* zstd_init_cstream() - initialize a zstd streaming compression context
429464
* @parameters The zstd parameters to use for compression.
@@ -583,6 +618,18 @@ size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output,
583618
*/
584619
size_t zstd_find_frame_compressed_size(const void *src, size_t src_size);
585620

621+
/**
622+
* zstd_register_sequence_producer() - exposes the zstd library function
623+
* ZSTD_registerSequenceProducer(). This is used for the block-level external
624+
* sequence producer API. See upstream zstd.h for detailed documentation.
625+
*/
626+
typedef ZSTD_sequenceProducer_F zstd_sequence_producer_f;
627+
void zstd_register_sequence_producer(
628+
zstd_cctx *cctx,
629+
void* sequence_producer_state,
630+
zstd_sequence_producer_f sequence_producer
631+
);
632+
586633
/**
587634
* struct zstd_frame_params - zstd frame parameters stored in the frame header
588635
* @frameContentSize: The frame content size, or ZSTD_CONTENTSIZE_UNKNOWN if not
@@ -596,7 +643,7 @@ size_t zstd_find_frame_compressed_size(const void *src, size_t src_size);
596643
*
597644
* See zstd_lib.h.
598645
*/
599-
typedef ZSTD_frameHeader zstd_frame_header;
646+
typedef ZSTD_FrameHeader zstd_frame_header;
600647

601648
/**
602649
* zstd_get_frame_header() - extracts parameters from a zstd or skippable frame
@@ -611,4 +658,35 @@ typedef ZSTD_frameHeader zstd_frame_header;
611658
size_t zstd_get_frame_header(zstd_frame_header *params, const void *src,
612659
size_t src_size);
613660

661+
/**
662+
* struct zstd_sequence - a sequence of literals or a match
663+
*
664+
* @offset: The offset of the match
665+
* @litLength: The literal length of the sequence
666+
* @matchLength: The match length of the sequence
667+
* @rep: Represents which repeat offset is used
668+
*/
669+
typedef ZSTD_Sequence zstd_sequence;
670+
671+
/**
672+
* zstd_compress_sequences_and_literals() - compress an array of zstd_sequence and literals
673+
*
674+
* @cctx: The zstd compression context.
675+
* @dst: The buffer to compress the data into.
676+
* @dst_capacity: The size of the destination buffer.
677+
* @in_seqs: The array of zstd_sequence to compress.
678+
* @in_seqs_size: The number of sequences in in_seqs.
679+
* @literals: The literals associated to the sequences to be compressed.
680+
* @lit_size: The size of the literals in the literals buffer.
681+
* @lit_capacity: The size of the literals buffer.
682+
* @decompressed_size: The size of the input data
683+
*
684+
* Return: The compressed size or an error, which can be checked using
685+
* zstd_is_error().
686+
*/
687+
size_t zstd_compress_sequences_and_literals(zstd_cctx *cctx, void* dst, size_t dst_capacity,
688+
const zstd_sequence *in_seqs, size_t in_seqs_size,
689+
const void* literals, size_t lit_size, size_t lit_capacity,
690+
size_t decompressed_size);
691+
614692
#endif /* LINUX_ZSTD_H */

include/linux/zstd_errors.h

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
12
/*
2-
* Copyright (c) Yann Collet, Facebook, Inc.
3+
* Copyright (c) Meta Platforms, Inc. and affiliates.
34
* All rights reserved.
45
*
56
* This source code is licensed under both the BSD-style license (found in the
@@ -12,13 +13,18 @@
1213
#define ZSTD_ERRORS_H_398273423
1314

1415

15-
/*===== dependency =====*/
16-
#include <linux/types.h> /* size_t */
16+
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
17+
#define ZSTDERRORLIB_VISIBLE
1718

19+
#ifndef ZSTDERRORLIB_HIDDEN
20+
# if (__GNUC__ >= 4) && !defined(__MINGW32__)
21+
# define ZSTDERRORLIB_HIDDEN __attribute__ ((visibility ("hidden")))
22+
# else
23+
# define ZSTDERRORLIB_HIDDEN
24+
# endif
25+
#endif
1826

19-
/* ===== ZSTDERRORLIB_API : control library symbols visibility ===== */
20-
#define ZSTDERRORLIB_VISIBILITY
21-
#define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBILITY
27+
#define ZSTDERRORLIB_API ZSTDERRORLIB_VISIBLE
2228

2329
/*-*********************************************
2430
* Error codes list
@@ -43,33 +49,37 @@ typedef enum {
4349
ZSTD_error_frameParameter_windowTooLarge = 16,
4450
ZSTD_error_corruption_detected = 20,
4551
ZSTD_error_checksum_wrong = 22,
52+
ZSTD_error_literals_headerWrong = 24,
4653
ZSTD_error_dictionary_corrupted = 30,
4754
ZSTD_error_dictionary_wrong = 32,
4855
ZSTD_error_dictionaryCreation_failed = 34,
4956
ZSTD_error_parameter_unsupported = 40,
57+
ZSTD_error_parameter_combination_unsupported = 41,
5058
ZSTD_error_parameter_outOfBound = 42,
5159
ZSTD_error_tableLog_tooLarge = 44,
5260
ZSTD_error_maxSymbolValue_tooLarge = 46,
5361
ZSTD_error_maxSymbolValue_tooSmall = 48,
62+
ZSTD_error_cannotProduce_uncompressedBlock = 49,
63+
ZSTD_error_stabilityCondition_notRespected = 50,
5464
ZSTD_error_stage_wrong = 60,
5565
ZSTD_error_init_missing = 62,
5666
ZSTD_error_memory_allocation = 64,
5767
ZSTD_error_workSpace_tooSmall= 66,
5868
ZSTD_error_dstSize_tooSmall = 70,
5969
ZSTD_error_srcSize_wrong = 72,
6070
ZSTD_error_dstBuffer_null = 74,
71+
ZSTD_error_noForwardProgress_destFull = 80,
72+
ZSTD_error_noForwardProgress_inputEmpty = 82,
6173
/* following error codes are __NOT STABLE__, they can be removed or changed in future versions */
6274
ZSTD_error_frameIndex_tooLarge = 100,
6375
ZSTD_error_seekableIO = 102,
6476
ZSTD_error_dstBuffer_wrong = 104,
6577
ZSTD_error_srcBuffer_wrong = 105,
78+
ZSTD_error_sequenceProducer_failed = 106,
79+
ZSTD_error_externalSequences_invalid = 107,
6680
ZSTD_error_maxCode = 120 /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */
6781
} ZSTD_ErrorCode;
6882

69-
/*! ZSTD_getErrorCode() :
70-
convert a `size_t` function result into a `ZSTD_ErrorCode` enum type,
71-
which can be used to compare with enum list published above */
72-
ZSTDERRORLIB_API ZSTD_ErrorCode ZSTD_getErrorCode(size_t functionResult);
7383
ZSTDERRORLIB_API const char* ZSTD_getErrorString(ZSTD_ErrorCode code); /*< Same as ZSTD_getErrorName, but using a `ZSTD_ErrorCode` enum argument */
7484

7585

0 commit comments

Comments
 (0)