mirror of
https://github.com/facebook/zstd.git
synced 2025-07-29 11:21:22 +03:00
[contrib][linux] Add wrapper API
Add the kernel wrapper API. This keeps the same API and semantics as the existing kernel API with name changes to be more kernel style and avoid symbol collisions with zstd.
This commit is contained in:
@ -22,8 +22,6 @@ libzstd:
|
||||
--xxh64-prefix 'xxh64' \
|
||||
--rewrite-include '<limits\.h>=<linux/limits.h>' \
|
||||
--rewrite-include '<stddef\.h>=<linux/types.h>' \
|
||||
--rewrite-include '"\.\./zstd.h"=<linux/zstd.h>' \
|
||||
--rewrite-include '"(\.\./common/)?zstd_errors.h"=<linux/zstd_errors.h>' \
|
||||
-DZSTD_NO_INTRINSICS \
|
||||
-DZSTD_NO_UNUSED_FUNCTIONS \
|
||||
-DZSTD_LEGACY_SUPPORT=0 \
|
||||
@ -48,8 +46,7 @@ libzstd:
|
||||
-U_WIN32 \
|
||||
-RZSTDLIB_VISIBILITY= \
|
||||
-RZSTDERRORLIB_VISIBILITY=
|
||||
mv linux/lib/zstd/zstd.h linux/include/linux
|
||||
mv linux/lib/zstd/common/zstd_errors.h linux/include/linux
|
||||
cp linux_zstd.h linux/include/linux/zstd.h
|
||||
cp zstd_compress_module.c linux/lib/zstd
|
||||
cp zstd_decompress_module.c linux/lib/zstd
|
||||
cp decompress_sources.h linux/lib/zstd
|
||||
@ -62,9 +59,8 @@ import: libzstd
|
||||
rm -f $(LINUX)/include/linux/zstd.h
|
||||
rm -f $(LINUX)/include/linux/zstd_errors.h
|
||||
rm -rf $(LINUX)/lib/zstd
|
||||
mv linux/include/linux/zstd.h $(LINUX)/include/linux
|
||||
mv linux/include/linux/zstd_errors.h $(LINUX)/include/linux
|
||||
mv linux/lib/zstd $(LINUX)/lib
|
||||
cp linux/include/linux/zstd.h $(LINUX)/include/linux
|
||||
cp -r linux/lib/zstd $(LINUX)/lib
|
||||
|
||||
.PHONY: test
|
||||
test: libzstd
|
||||
|
@ -16,3 +16,4 @@
|
||||
#include "decompress/zstd_ddict.c"
|
||||
#include "decompress/zstd_decompress.c"
|
||||
#include "decompress/zstd_decompress_block.c"
|
||||
#include "zstd_decompress_module.c"
|
||||
|
458
contrib/linux-kernel/linux_zstd.h
Normal file
458
contrib/linux-kernel/linux_zstd.h
Normal file
@ -0,0 +1,458 @@
|
||||
/*
|
||||
* Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of https://github.com/facebook/zstd.
|
||||
* An additional grant of patent rights can be found in the PATENTS file in the
|
||||
* same directory.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License version 2 as published by the
|
||||
* Free Software Foundation. This program is dual-licensed; you may select
|
||||
* either version 2 of the GNU General Public License ("GPL") or BSD license
|
||||
* ("BSD").
|
||||
*/
|
||||
|
||||
#ifndef LINUX_ZSTD_H
|
||||
#define LINUX_ZSTD_H
|
||||
|
||||
/**
|
||||
* This is a kernel-style API that wraps the upstream zstd API, which cannot be
|
||||
* used directly because the symbols aren't exported. It exposes the minimal
|
||||
* functionality which is currently required by users of zstd in the kernel.
|
||||
* Expose extra functions from lib/zstd/zstd.h as needed.
|
||||
*/
|
||||
|
||||
/* ====== Dependency ====== */
|
||||
#include <linux/types.h>
|
||||
|
||||
/* ====== Helper Functions ====== */
|
||||
/**
|
||||
* zstd_compress_bound() - maximum compressed size in worst case scenario
|
||||
* @src_size: The size of the data to compress.
|
||||
*
|
||||
* Return: The maximum compressed size in the worst case scenario.
|
||||
*/
|
||||
size_t zstd_compress_bound(size_t src_size);
|
||||
|
||||
/**
|
||||
* zstd_is_error() - tells if a size_t function result is an error code
|
||||
* @code: The function result to check for error.
|
||||
*
|
||||
* Return: Non-zero iff the code is an error.
|
||||
*/
|
||||
unsigned int zstd_is_error(size_t code);
|
||||
|
||||
/**
|
||||
* zstd_get_error_code() - translates an error function result to an error code
|
||||
* @code: The function result for which zstd_is_error(code) is true.
|
||||
*
|
||||
* Return: A unique error code for this error.
|
||||
*/
|
||||
int zstd_get_error_code(size_t code);
|
||||
|
||||
/**
|
||||
* zstd_get_error_name() - translates an error function result to a string
|
||||
* @code: The function result for which zstd_is_error(code) is true.
|
||||
*
|
||||
* Return: An error string corresponding to the error code.
|
||||
*/
|
||||
const char* zstd_get_error_name(size_t code);
|
||||
|
||||
/* ====== Parameter Selection ====== */
|
||||
|
||||
/**
|
||||
* enum zstd_strategy - zstd compression search strategy
|
||||
*
|
||||
* From faster to stronger.
|
||||
*/
|
||||
enum zstd_strategy {
|
||||
zstd_fast = 1,
|
||||
zstd_dfast = 2,
|
||||
zstd_greedy = 3,
|
||||
zstd_lazy = 4,
|
||||
zstd_lazy2 = 5,
|
||||
zstd_btlazy2 = 6,
|
||||
zstd_btopt = 7,
|
||||
zstd_btultra = 8,
|
||||
zstd_btultra2 = 9
|
||||
};
|
||||
|
||||
/**
|
||||
* struct zstd_compression_parameters - zstd compression parameters
|
||||
* @window_log: Log of the largest match distance. Larger means more
|
||||
* compression, and more memory needed during decompression.
|
||||
* @chain_log: Fully searched segment. Larger means more compression,
|
||||
* slower, and more memory (useless for fast).
|
||||
* @hash_log: Dispatch table. Larger means more compression,
|
||||
* slower, and more memory.
|
||||
* @search_log: Number of searches. Larger means more compression and slower.
|
||||
* @search_length: Match length searched. Larger means faster decompression,
|
||||
* sometimes less compression.
|
||||
* @target_length: Acceptable match size for optimal parser (only). Larger means
|
||||
* more compression, and slower.
|
||||
* @strategy: The zstd compression strategy.
|
||||
*/
|
||||
struct zstd_compression_parameters {
|
||||
unsigned int window_log;
|
||||
unsigned int chain_log;
|
||||
unsigned int hash_log;
|
||||
unsigned int search_log;
|
||||
unsigned int search_length;
|
||||
unsigned int target_length;
|
||||
enum zstd_strategy strategy;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct zstd_frame_parameters - zstd frame parameters
|
||||
* @content_size_flag: Controls whether content size will be present in the
|
||||
* frame header (when known).
|
||||
* @checksum_flag: Controls whether a 32-bit checksum is generated at the
|
||||
* end of the frame for error detection.
|
||||
* @no_dict_id_flag: Controls whether dictID will be saved into the frame
|
||||
* header when using dictionary compression.
|
||||
*
|
||||
* The default value is all fields set to 0.
|
||||
*/
|
||||
struct zstd_frame_parameters {
|
||||
unsigned int content_size_flag;
|
||||
unsigned int checksum_flag;
|
||||
unsigned int no_dict_id_flag;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct zstd_parameters - zstd parameters
|
||||
* @cparams: The compression parameters.
|
||||
* @fparams: The frame parameters.
|
||||
*/
|
||||
struct zstd_parameters {
|
||||
struct zstd_compression_parameters cparams;
|
||||
struct zstd_frame_parameters fparams;
|
||||
};
|
||||
|
||||
/**
|
||||
* zstd_get_params() - returns zstd_parameters for selected level
|
||||
* @level: The compression level
|
||||
* @estimated_src_size: The estimated source size to compress or 0
|
||||
* if unknown.
|
||||
*
|
||||
* Return: The selected zstd_parameters.
|
||||
*/
|
||||
struct zstd_parameters zstd_get_params(int level,
|
||||
unsigned long long estimated_src_size);
|
||||
|
||||
/* ====== Single-pass Compression ====== */
|
||||
|
||||
typedef struct ZSTD_CCtx_s zstd_cctx;
|
||||
|
||||
/**
|
||||
* zstd_cctx_workspace_bound() - max memory needed to initialize a zstd_cctx
|
||||
* @parameters: The compression parameters to be used.
|
||||
*
|
||||
* If multiple compression parameters might be used, the caller must call
|
||||
* zstd_cctx_workspace_bound() for each set of parameters and use the maximum
|
||||
* size.
|
||||
*
|
||||
* Return: A lower bound on the size of the workspace that is passed to
|
||||
* zstd_init_cctx().
|
||||
*/
|
||||
size_t zstd_cctx_workspace_bound(
|
||||
const struct zstd_compression_parameters *parameters);
|
||||
|
||||
/**
|
||||
* zstd_init_cctx() - initialize a zstd compression context
|
||||
* @workspace: The workspace to emplace the context into. It must outlive
|
||||
* the returned context.
|
||||
* @workspace_size: The size of workspace. Use zstd_cctx_workspace_bound() to
|
||||
* determine how large the workspace must be.
|
||||
*
|
||||
* Return: A zstd compression context or NULL on error.
|
||||
*/
|
||||
zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size);
|
||||
|
||||
/**
|
||||
* zstd_compress_cctx() - compress src into dst with the initialized parameters
|
||||
* @cctx: The context. Must have been initialized with zstd_init_cctx().
|
||||
* @dst: The buffer to compress src into.
|
||||
* @dst_capacity: The size of the destination buffer. May be any size, but
|
||||
* ZSTD_compressBound(srcSize) is guaranteed to be large enough.
|
||||
* @src: The data to compress.
|
||||
* @src_size: The size of the data to compress.
|
||||
* @parameters: The compression parameters to be used.
|
||||
*
|
||||
* Return: The compressed size or an error, which can be checked using
|
||||
* zstd_is_error().
|
||||
*/
|
||||
size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity,
|
||||
const void *src, size_t src_size, const struct zstd_parameters* parameters);
|
||||
|
||||
/* ====== Single-pass Decompression ====== */
|
||||
|
||||
typedef struct ZSTD_DCtx_s zstd_dctx;
|
||||
|
||||
/**
|
||||
* zstd_dctx_workspace_bound() - max memory needed to initialize a zstd_dctx
|
||||
*
|
||||
* Return: A lower bound on the size of the workspace that is passed to
|
||||
* zstd_init_dctx().
|
||||
*/
|
||||
size_t zstd_dctx_workspace_bound(void);
|
||||
|
||||
/**
|
||||
* zstd_init_dctx() - initialize a zstd decompression context
|
||||
* @workspace: The workspace to emplace the context into. It must outlive
|
||||
* the returned context.
|
||||
* @workspace_size: The size of workspace. Use zstd_dctx_workspace_bound() to
|
||||
* determine how large the workspace must be.
|
||||
*
|
||||
* Return: A zstd decompression context or NULL on error.
|
||||
*/
|
||||
zstd_dctx *zstd_init_dctx(void *workspace, size_t workspace_size);
|
||||
|
||||
/**
|
||||
* zstd_decompress_dctx() - decompress zstd compressed src into dst
|
||||
* @dctx: The decompression context.
|
||||
* @dst: The buffer to decompress src into.
|
||||
* @dst_capacity: The size of the destination buffer. Must be at least as large
|
||||
* as the decompressed size. If the caller cannot upper bound the
|
||||
* decompressed size, then it's better to use the streaming API.
|
||||
* @src: The zstd compressed data to decompress. Multiple concatenated
|
||||
* frames and skippable frames are allowed.
|
||||
* @src_size: The exact size of the data to decompress.
|
||||
*
|
||||
* Return: The decompressed size or an error, which can be checked using
|
||||
* zstd_is_error().
|
||||
*/
|
||||
size_t zstd_decompress_dctx(zstd_dctx *dctx, void *dst, size_t dst_capacity,
|
||||
const void *src, size_t src_size);
|
||||
|
||||
/* ====== Streaming Buffers ====== */
|
||||
|
||||
/**
|
||||
* struct zstd_in_buffer - input buffer for streaming
|
||||
* @src: Start of the input buffer.
|
||||
* @size: Size of the input buffer.
|
||||
* @pos: Position where reading stopped. Will be updated.
|
||||
* Necessarily 0 <= pos <= size.
|
||||
*/
|
||||
struct zstd_in_buffer {
|
||||
const void *src;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct zstd_out_buffer - output buffer for streaming
|
||||
* @dst: Start of the output buffer.
|
||||
* @size: Size of the output buffer.
|
||||
* @pos: Position where writing stopped. Will be updated.
|
||||
* Necessarily 0 <= pos <= size.
|
||||
*/
|
||||
struct zstd_out_buffer {
|
||||
void *dst;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
};
|
||||
|
||||
/* ====== Streaming Compression ====== */
|
||||
|
||||
typedef struct ZSTD_CCtx_s zstd_cstream;
|
||||
|
||||
/**
|
||||
* zstd_cstream_workspace_bound() - memory needed to initialize a zstd_cstream
|
||||
* @cparams: The compression parameters to be used for compression.
|
||||
*
|
||||
* Return: A lower bound on the size of the workspace that is passed to
|
||||
* zstd_init_cstream().
|
||||
*/
|
||||
size_t zstd_cstream_workspace_bound(
|
||||
const struct zstd_compression_parameters *cparams);
|
||||
|
||||
/**
|
||||
* zstd_init_cstream() - initialize a zstd streaming compression context
|
||||
* @parameters The zstd parameters to use for compression.
|
||||
* @pledged_src_size: If params.fParams.contentSizeFlag == 1 then the caller
|
||||
* must pass the source size (zero means empty source).
|
||||
* Otherwise, the caller may optionally pass the source
|
||||
* size, or zero if unknown.
|
||||
* @workspace: The workspace to emplace the context into. It must outlive
|
||||
* the returned context.
|
||||
* @workspace_size: The size of workspace.
|
||||
* Use zstd_cstream_workspace_bound(params->cparams) to
|
||||
* determine how large the workspace must be.
|
||||
*
|
||||
* Return: The zstd streaming compression context or NULL on error.
|
||||
*/
|
||||
zstd_cstream *zstd_init_cstream(const struct zstd_parameters *parameters,
|
||||
unsigned long long pledged_src_size, void *workspace, size_t workspace_size);
|
||||
|
||||
/**
|
||||
* zstd_reset_cstream() - reset the context using parameters from creation
|
||||
* @cstream: The zstd streaming compression context to reset.
|
||||
* @pledged_src_size: Optionally the source size, or zero if unknown.
|
||||
*
|
||||
* Resets the context using the parameters from creation. Skips dictionary
|
||||
* loading, since it can be reused. If `pledged_src_size` is non-zero the frame
|
||||
* content size is always written into the frame header.
|
||||
*
|
||||
* Return: Zero or an error, which can be checked using
|
||||
* zstd_is_error().
|
||||
*/
|
||||
size_t zstd_reset_cstream(zstd_cstream *cstream,
|
||||
unsigned long long pledged_src_size);
|
||||
|
||||
/**
|
||||
* zstd_compress_stream() - streaming compress some of input into output
|
||||
* @cstream: The zstd streaming compression context.
|
||||
* @output: Destination buffer. `output->pos` is updated to indicate how much
|
||||
* compressed data was written.
|
||||
* @input: Source buffer. `input->pos` is updated to indicate how much data
|
||||
* was read. Note that it may not consume the entire input, in which
|
||||
* case `input->pos < input->size`, and it's up to the caller to
|
||||
* present remaining data again.
|
||||
*
|
||||
* The `input` and `output` buffers may be any size. Guaranteed to make some
|
||||
* forward progress if `input` and `output` are not empty.
|
||||
*
|
||||
* Return: A hint for the number of bytes to use as the input for the next
|
||||
* function call or an error, which can be checked using
|
||||
* zstd_is_error().
|
||||
*/
|
||||
size_t zstd_compress_stream(zstd_cstream *cstream,
|
||||
struct zstd_out_buffer *output, struct zstd_in_buffer *input);
|
||||
|
||||
/**
|
||||
* zstd_flush_stream() - flush internal buffers into output
|
||||
* @cstream: The zstd streaming compression context.
|
||||
* @output: Destination buffer. `output->pos` is updated to indicate how much
|
||||
* compressed data was written.
|
||||
*
|
||||
* zstd_flush_stream() must be called until it returns 0, meaning all the data
|
||||
* has been flushed. Since zstd_flush_stream() causes a block to be ended,
|
||||
* calling it too often will degrade the compression ratio.
|
||||
*
|
||||
* Return: The number of bytes still present within internal buffers or an
|
||||
* error, which can be checked using zstd_is_error().
|
||||
*/
|
||||
size_t zstd_flush_stream(zstd_cstream *cstream, struct zstd_out_buffer *output);
|
||||
|
||||
/**
|
||||
* zstd_end_stream() - flush internal buffers into output and end the frame
|
||||
* @cstream: The zstd streaming compression context.
|
||||
* @output: Destination buffer. `output->pos` is updated to indicate how much
|
||||
* compressed data was written.
|
||||
*
|
||||
* zstd_end_stream() must be called until it returns 0, meaning all the data has
|
||||
* been flushed and the frame epilogue has been written.
|
||||
*
|
||||
* Return: The number of bytes still present within internal buffers or an
|
||||
* error, which can be checked using zstd_is_error().
|
||||
*/
|
||||
size_t zstd_end_stream(zstd_cstream *cstream, struct zstd_out_buffer *output);
|
||||
|
||||
/* ====== Streaming Decompression ====== */
|
||||
|
||||
typedef struct ZSTD_DCtx_s zstd_dstream;
|
||||
|
||||
/**
|
||||
* zstd_dstream_workspace_bound() - memory needed to initialize a zstd_dstream
|
||||
* @max_window_size: The maximum window size allowed for compressed frames.
|
||||
*
|
||||
* Return: A lower bound on the size of the workspace that is passed
|
||||
* to zstd_init_dstream().
|
||||
*/
|
||||
size_t zstd_dstream_workspace_bound(size_t max_window_size);
|
||||
|
||||
/**
|
||||
* zstd_init_dstream() - initialize a zstd streaming decompression context
|
||||
* @max_window_size: The maximum window size allowed for compressed frames.
|
||||
* @workspace: The workspace to emplace the context into. It must outlive
|
||||
* the returned context.
|
||||
* @workspaceSize: The size of workspace.
|
||||
* Use zstd_dstream_workspace_bound(max_window_size) to
|
||||
* determine how large the workspace must be.
|
||||
*
|
||||
* Return: The zstd streaming decompression context.
|
||||
*/
|
||||
zstd_dstream *zstd_init_dstream(size_t max_window_size, void* workspace,
|
||||
size_t workspace_size);
|
||||
|
||||
/**
|
||||
* zstd_reset_dstream() - reset the context using parameters from creation
|
||||
* @dstream: The zstd streaming decompression context to reset.
|
||||
*
|
||||
* Resets the context using the parameters from creation. Skips dictionary
|
||||
* loading, since it can be reused.
|
||||
*
|
||||
* Return: Zero or an error, which can be checked using zstd_is_error().
|
||||
*/
|
||||
size_t zstd_reset_dstream(zstd_dstream *dstream);
|
||||
|
||||
/**
|
||||
* zstd_decompress_stream() - streaming decompress some of input into output
|
||||
* @dstream: The zstd streaming decompression context.
|
||||
* @output: Destination buffer. `output.pos` is updated to indicate how much
|
||||
* decompressed data was written.
|
||||
* @input: Source buffer. `input.pos` is updated to indicate how much data was
|
||||
* read. Note that it may not consume the entire input, in which case
|
||||
* `input.pos < input.size`, and it's up to the caller to present
|
||||
* remaining data again.
|
||||
*
|
||||
* The `input` and `output` buffers may be any size. Guaranteed to make some
|
||||
* forward progress if `input` and `output` are not empty.
|
||||
* zstd_decompress_stream() will not consume the last byte of the frame until
|
||||
* the entire frame is flushed.
|
||||
*
|
||||
* Return: Returns 0 iff a frame is completely decoded and fully flushed.
|
||||
* Otherwise returns a hint for the number of bytes to use as the
|
||||
* input for the next function call or an error, which can be checked
|
||||
* using zstd_is_error(). The size hint will never load more than the
|
||||
* frame.
|
||||
*/
|
||||
size_t zstd_decompress_stream(zstd_dstream *dstream,
|
||||
struct zstd_out_buffer *output, struct zstd_in_buffer *input);
|
||||
|
||||
/* ====== Frame Inspection Functions ====== */
|
||||
|
||||
/**
|
||||
* zstd_find_frame_compressed_size() - returns the size of a compressed frame
|
||||
* @src: Source buffer. It should point to the start of a zstd encoded
|
||||
* frame or a skippable frame.
|
||||
* @src_size: The size of the source buffer. It must be at least as large as the
|
||||
* size of the frame.
|
||||
*
|
||||
* Return: The compressed size of the frame pointed to by `src` or an error,
|
||||
* which can be check with zstd_is_error().
|
||||
* Suitable to pass to ZSTD_decompress() or similar functions.
|
||||
*/
|
||||
size_t zstd_find_frame_compressed_size(const void *src, size_t src_size);
|
||||
|
||||
/**
|
||||
* struct zstd_frame_params - zstd frame parameters stored in the frame header
|
||||
* @frame_content_size: The frame content size, or 0 if not present.
|
||||
* @window_size: The window size, or 0 if the frame is a skippable frame.
|
||||
* @dict_id: The dictionary id, or 0 if not present.
|
||||
* @checksum_flag: Whether a checksum was used.
|
||||
*/
|
||||
struct zstd_frame_params {
|
||||
unsigned long long frame_content_size;
|
||||
unsigned int window_size;
|
||||
unsigned int dict_id;
|
||||
unsigned int checksum_flag;
|
||||
};
|
||||
|
||||
/**
|
||||
* zstd_get_frame_params() - extracts parameters from a zstd or skippable frame
|
||||
* @params: On success the frame parameters are written here.
|
||||
* @src: The source buffer. It must point to a zstd or skippable frame.
|
||||
* @src_size: The size of the source buffer.
|
||||
*
|
||||
* Return: 0 on success. If more data is required it returns how many bytes
|
||||
* must be provided to make forward progress. Otherwise it returns
|
||||
* an error, which can be checked using zstd_is_error().
|
||||
*/
|
||||
size_t zstd_get_frame_params(struct zstd_frame_params *params, const void *src,
|
||||
size_t src_size);
|
||||
|
||||
#endif /* LINUX_ZSTD_H */
|
@ -6,10 +6,11 @@ CPPFLAGS += -I$(LINUX)/include -I$(LINUX_ZSTDLIB) -Iinclude -DNDEBUG
|
||||
# Don't poison the workspace, it currently doesn't work with static allocation and workspace reuse
|
||||
CPPFLAGS += -DZSTD_ASAN_DONT_POISON_WORKSPACE
|
||||
|
||||
LINUX_ZSTD_MODULE := $(wildcard $(LINUX_ZSTDLIB)/*.c)
|
||||
LINUX_ZSTD_COMMON := $(wildcard $(LINUX_ZSTDLIB)/common/*.c)
|
||||
LINUX_ZSTD_COMPRESS := $(wildcard $(LINUX_ZSTDLIB)/compress/*.c)
|
||||
LINUX_ZSTD_DECOMPRESS := $(wildcard $(LINUX_ZSTDLIB)/decompress/*.c)
|
||||
LINUX_ZSTD_FILES := $(LINUX_ZSTD_COMMON) $(LINUX_ZSTD_COMPRESS) $(LINUX_ZSTD_DECOMPRESS)
|
||||
LINUX_ZSTD_FILES := $(LINUX_ZSTD_MODULE) $(LINUX_ZSTD_COMMON) $(LINUX_ZSTD_COMPRESS) $(LINUX_ZSTD_DECOMPRESS)
|
||||
LINUX_ZSTD_OBJECTS := $(LINUX_ZSTD_FILES:.c=.o)
|
||||
|
||||
liblinuxzstd.a: $(LINUX_ZSTD_OBJECTS)
|
||||
|
@ -31,13 +31,13 @@ static const char kEmptyZstdFrame[] = {
|
||||
static void test_decompress_unzstd() {
|
||||
fprintf(stderr, "Testing decompress unzstd... ");
|
||||
{
|
||||
size_t const wkspSize = ZSTD_estimateDCtxSize();
|
||||
size_t const wkspSize = zstd_dctx_workspace_bound();
|
||||
void* wksp = malloc(wkspSize);
|
||||
CONTROL(wksp != NULL);
|
||||
ZSTD_DCtx* dctx = ZSTD_initStaticDCtx(wksp, wkspSize);
|
||||
ZSTD_DCtx* dctx = zstd_init_dctx(wksp, wkspSize);
|
||||
CONTROL(dctx != NULL);
|
||||
size_t const dSize = ZSTD_decompressDCtx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
|
||||
CONTROL(!ZSTD_isError(dSize));
|
||||
size_t const dSize = zstd_decompress_dctx(dctx, NULL, 0, kEmptyZstdFrame, sizeof(kEmptyZstdFrame));
|
||||
CONTROL(!zstd_is_error(dSize));
|
||||
CONTROL(dSize == 0);
|
||||
free(wksp);
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ test_data_t create_test_data(void) {
|
||||
CONTROL(data.data != NULL);
|
||||
data.data2 = malloc(data.dataSize);
|
||||
CONTROL(data.data2 != NULL);
|
||||
data.compSize = ZSTD_compressBound(data.dataSize);
|
||||
data.compSize = zstd_compress_bound(data.dataSize);
|
||||
data.comp = malloc(data.compSize);
|
||||
CONTROL(data.comp != NULL);
|
||||
memset(data.data, 0, data.dataSize);
|
||||
@ -57,11 +57,11 @@ static void test_btrfs(test_data_t const *data) {
|
||||
fprintf(stderr, "testing btrfs use cases... ");
|
||||
size_t const size = MIN(data->dataSize, 128 * 1024);
|
||||
for (int level = -1; level < 16; ++level) {
|
||||
ZSTD_parameters params = ZSTD_getParams(level, size, 0);
|
||||
CONTROL(params.cParams.windowLog <= 17);
|
||||
struct zstd_parameters params = zstd_get_params(level, size);
|
||||
CONTROL(params.cparams.window_log <= 17);
|
||||
size_t const workspaceSize =
|
||||
MAX(ZSTD_estimateCStreamSize_usingCParams(params.cParams),
|
||||
ZSTD_estimateDStreamSize(size));
|
||||
MAX(zstd_cstream_workspace_bound(¶ms.cparams),
|
||||
zstd_dstream_workspace_bound(size));
|
||||
void *workspace = malloc(workspaceSize);
|
||||
CONTROL(workspace != NULL);
|
||||
|
||||
@ -70,12 +70,10 @@ static void test_btrfs(test_data_t const *data) {
|
||||
char *op = data->comp;
|
||||
char *oend = op + data->compSize;
|
||||
{
|
||||
ZSTD_CStream *cctx = ZSTD_initStaticCStream(workspace, workspaceSize);
|
||||
zstd_cstream *cctx = zstd_init_cstream(¶ms, size, workspace, workspaceSize);
|
||||
CONTROL(cctx != NULL);
|
||||
CONTROL(!ZSTD_isError(
|
||||
ZSTD_initCStream_advanced(cctx, NULL, 0, params, size)));
|
||||
ZSTD_outBuffer out = {NULL, 0, 0};
|
||||
ZSTD_inBuffer in = {NULL, 0, 0};
|
||||
struct zstd_out_buffer out = {NULL, 0, 0};
|
||||
struct zstd_in_buffer in = {NULL, 0, 0};
|
||||
for (;;) {
|
||||
if (in.pos == in.size) {
|
||||
in.src = ip;
|
||||
@ -92,10 +90,10 @@ static void test_btrfs(test_data_t const *data) {
|
||||
}
|
||||
|
||||
if (ip != iend || in.pos < in.size) {
|
||||
CONTROL(!ZSTD_isError(ZSTD_compressStream(cctx, &out, &in)));
|
||||
CONTROL(!zstd_is_error(zstd_compress_stream(cctx, &out, &in)));
|
||||
} else {
|
||||
size_t const ret = ZSTD_endStream(cctx, &out);
|
||||
CONTROL(!ZSTD_isError(ret));
|
||||
size_t const ret = zstd_end_stream(cctx, &out);
|
||||
CONTROL(!zstd_is_error(ret));
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
@ -109,10 +107,10 @@ static void test_btrfs(test_data_t const *data) {
|
||||
op = data->data2;
|
||||
oend = op + size;
|
||||
{
|
||||
ZSTD_DStream *dctx = ZSTD_initStaticDStream(workspace, workspaceSize);
|
||||
zstd_dstream *dctx = zstd_init_dstream(1ULL << params.cparams.window_log, workspace, workspaceSize);
|
||||
CONTROL(dctx != NULL);
|
||||
ZSTD_outBuffer out = {NULL, 0, 0};
|
||||
ZSTD_inBuffer in = {NULL, 0, 0};
|
||||
struct zstd_out_buffer out = {NULL, 0, 0};
|
||||
struct zstd_in_buffer in = {NULL, 0, 0};
|
||||
for (;;) {
|
||||
if (in.pos == in.size) {
|
||||
in.src = ip;
|
||||
@ -128,8 +126,8 @@ static void test_btrfs(test_data_t const *data) {
|
||||
op += out.size;
|
||||
}
|
||||
|
||||
size_t const ret = ZSTD_decompressStream(dctx, &out, &in);
|
||||
CONTROL(!ZSTD_isError(ret));
|
||||
size_t const ret = zstd_decompress_stream(dctx, &out, &in);
|
||||
CONTROL(!zstd_is_error(ret));
|
||||
if (ret == 0) {
|
||||
break;
|
||||
}
|
||||
@ -146,23 +144,24 @@ static void test_decompress_unzstd(test_data_t const *data) {
|
||||
fprintf(stderr, "Testing decompress unzstd... ");
|
||||
size_t cSize;
|
||||
{
|
||||
size_t const wkspSize = ZSTD_estimateCCtxSize(19);
|
||||
struct zstd_parameters params = zstd_get_params(19, 0);
|
||||
size_t const wkspSize = zstd_cctx_workspace_bound(¶ms.cparams);
|
||||
void* wksp = malloc(wkspSize);
|
||||
CONTROL(wksp != NULL);
|
||||
ZSTD_CCtx* cctx = ZSTD_initStaticCCtx(wksp, wkspSize);
|
||||
zstd_cctx* cctx = zstd_init_cctx(wksp, wkspSize);
|
||||
CONTROL(cctx != NULL);
|
||||
cSize = ZSTD_compressCCtx(cctx, data->comp, data->compSize, data->data, data->dataSize, 19);
|
||||
CONTROL(!ZSTD_isError(cSize));
|
||||
cSize = zstd_compress_cctx(cctx, data->comp, data->compSize, data->data, data->dataSize, ¶ms);
|
||||
CONTROL(!zstd_is_error(cSize));
|
||||
free(wksp);
|
||||
}
|
||||
{
|
||||
size_t const wkspSize = ZSTD_estimateDCtxSize();
|
||||
size_t const wkspSize = zstd_dctx_workspace_bound();
|
||||
void* wksp = malloc(wkspSize);
|
||||
CONTROL(wksp != NULL);
|
||||
ZSTD_DCtx* dctx = ZSTD_initStaticDCtx(wksp, wkspSize);
|
||||
zstd_dctx* dctx = zstd_init_dctx(wksp, wkspSize);
|
||||
CONTROL(dctx != NULL);
|
||||
size_t const dSize = ZSTD_decompressDCtx(dctx, data->data2, data->dataSize, data->comp, cSize);
|
||||
CONTROL(!ZSTD_isError(dSize));
|
||||
size_t const dSize = zstd_decompress_dctx(dctx, data->data2, data->dataSize, data->comp, cSize);
|
||||
CONTROL(!zstd_is_error(dSize));
|
||||
CONTROL(dSize == data->dataSize);
|
||||
CONTROL(!memcmp(data->data, data->data2, data->dataSize));
|
||||
free(wksp);
|
||||
|
@ -2,78 +2,176 @@
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/zstd.h>
|
||||
|
||||
EXPORT_SYMBOL(ZSTD_compressBound);
|
||||
EXPORT_SYMBOL(ZSTD_minCLevel);
|
||||
EXPORT_SYMBOL(ZSTD_maxCLevel);
|
||||
EXPORT_SYMBOL(ZSTD_freeCCtx);
|
||||
EXPORT_SYMBOL(ZSTD_compressCCtx);
|
||||
EXPORT_SYMBOL(ZSTD_cParam_getBounds);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_setParameter);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_setPledgedSrcSize);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_reset);
|
||||
EXPORT_SYMBOL(ZSTD_compress2);
|
||||
EXPORT_SYMBOL(ZSTD_freeCStream);
|
||||
EXPORT_SYMBOL(ZSTD_compressStream2);
|
||||
EXPORT_SYMBOL(ZSTD_CStreamInSize);
|
||||
EXPORT_SYMBOL(ZSTD_CStreamOutSize);
|
||||
EXPORT_SYMBOL(ZSTD_initCStream);
|
||||
EXPORT_SYMBOL(ZSTD_compressStream);
|
||||
EXPORT_SYMBOL(ZSTD_flushStream);
|
||||
EXPORT_SYMBOL(ZSTD_endStream);
|
||||
EXPORT_SYMBOL(ZSTD_compress_usingDict);
|
||||
EXPORT_SYMBOL(ZSTD_freeCDict);
|
||||
EXPORT_SYMBOL(ZSTD_compress_usingCDict);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_refCDict);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_refPrefix);
|
||||
EXPORT_SYMBOL(ZSTD_sizeof_CCtx);
|
||||
EXPORT_SYMBOL(ZSTD_sizeof_CStream);
|
||||
EXPORT_SYMBOL(ZSTD_sizeof_CDict);
|
||||
EXPORT_SYMBOL(ZSTD_getSequences);
|
||||
EXPORT_SYMBOL(ZSTD_estimateCCtxSize);
|
||||
EXPORT_SYMBOL(ZSTD_estimateCCtxSize_usingCParams);
|
||||
EXPORT_SYMBOL(ZSTD_estimateCCtxSize_usingCCtxParams);
|
||||
EXPORT_SYMBOL(ZSTD_estimateCStreamSize);
|
||||
EXPORT_SYMBOL(ZSTD_estimateCStreamSize_usingCParams);
|
||||
EXPORT_SYMBOL(ZSTD_estimateCDictSize);
|
||||
EXPORT_SYMBOL(ZSTD_estimateCDictSize_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_initStaticCCtx);
|
||||
EXPORT_SYMBOL(ZSTD_initStaticCStream);
|
||||
EXPORT_SYMBOL(ZSTD_initStaticCDict);
|
||||
EXPORT_SYMBOL(ZSTD_createCCtx_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_createCStream_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_createCDict_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_createCDict_byReference);
|
||||
EXPORT_SYMBOL(ZSTD_getCParams);
|
||||
EXPORT_SYMBOL(ZSTD_getParams);
|
||||
EXPORT_SYMBOL(ZSTD_checkCParams);
|
||||
EXPORT_SYMBOL(ZSTD_adjustCParams);
|
||||
EXPORT_SYMBOL(ZSTD_compress_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_compress_usingCDict_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_loadDictionary_byReference);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_loadDictionary_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_refPrefix_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_CCtx_getParameter);
|
||||
EXPORT_SYMBOL(ZSTD_compressStream2_simpleArgs);
|
||||
EXPORT_SYMBOL(ZSTD_initCStream_srcSize);
|
||||
EXPORT_SYMBOL(ZSTD_initCStream_usingDict);
|
||||
EXPORT_SYMBOL(ZSTD_initCStream_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_initCStream_usingCDict);
|
||||
EXPORT_SYMBOL(ZSTD_initCStream_usingCDict_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_resetCStream);
|
||||
EXPORT_SYMBOL(ZSTD_getFrameProgression);
|
||||
EXPORT_SYMBOL(ZSTD_toFlushNow);
|
||||
EXPORT_SYMBOL(ZSTD_compressBegin);
|
||||
EXPORT_SYMBOL(ZSTD_compressBegin_usingDict);
|
||||
EXPORT_SYMBOL(ZSTD_compressBegin_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_compressBegin_usingCDict);
|
||||
EXPORT_SYMBOL(ZSTD_compressBegin_usingCDict_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_copyCCtx);
|
||||
EXPORT_SYMBOL(ZSTD_compressContinue);
|
||||
EXPORT_SYMBOL(ZSTD_compressEnd);
|
||||
EXPORT_SYMBOL(ZSTD_getBlockSize);
|
||||
EXPORT_SYMBOL(ZSTD_compressBlock);
|
||||
#include "zstd.h"
|
||||
#include "common/zstd_deps.h"
|
||||
#include "common/zstd_internal.h"
|
||||
|
||||
static void zstd_check_structs(void) {
|
||||
/* Check that the structs have the same size. */
|
||||
ZSTD_STATIC_ASSERT(sizeof(ZSTD_parameters) == sizeof(struct zstd_parameters));
|
||||
ZSTD_STATIC_ASSERT(sizeof(ZSTD_compressionParameters) == sizeof(struct zstd_compression_parameters));
|
||||
ZSTD_STATIC_ASSERT(sizeof(ZSTD_frameParameters) == sizeof(struct zstd_frame_parameters));
|
||||
/* Zstd guarantees that the layout of the structs never change. Verify it. */
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_parameters, cParams) == offsetof(struct zstd_parameters, cparams));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_parameters, fParams) == offsetof(struct zstd_parameters, fparams));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, windowLog) == offsetof(struct zstd_compression_parameters, window_log));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, chainLog) == offsetof(struct zstd_compression_parameters, chain_log));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, hashLog) == offsetof(struct zstd_compression_parameters, hash_log));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, searchLog) == offsetof(struct zstd_compression_parameters, search_log));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, minMatch) == offsetof(struct zstd_compression_parameters, search_length));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, targetLength) == offsetof(struct zstd_compression_parameters, target_length));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_compressionParameters, strategy) == offsetof(struct zstd_compression_parameters, strategy));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_frameParameters, contentSizeFlag) == offsetof(struct zstd_frame_parameters, content_size_flag));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_frameParameters, checksumFlag) == offsetof(struct zstd_frame_parameters, checksum_flag));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_frameParameters, noDictIDFlag) == offsetof(struct zstd_frame_parameters, no_dict_id_flag));
|
||||
/* Check that the strategies are the same. This can change. */
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_fast == (int)zstd_fast);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_dfast == (int)zstd_dfast);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_greedy == (int)zstd_greedy);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_lazy == (int)zstd_lazy);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_lazy2 == (int)zstd_lazy2);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_btlazy2 == (int)zstd_btlazy2);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_btopt == (int)zstd_btopt);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_btultra == (int)zstd_btultra);
|
||||
ZSTD_STATIC_ASSERT((int)ZSTD_btultra2 == (int)zstd_btultra2);
|
||||
/* Check input buffer */
|
||||
ZSTD_STATIC_ASSERT(sizeof(ZSTD_inBuffer) == sizeof(struct zstd_in_buffer));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_inBuffer, src) == offsetof(struct zstd_in_buffer, src));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_inBuffer, size) == offsetof(struct zstd_in_buffer, size));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_inBuffer, pos) == offsetof(struct zstd_in_buffer, pos));
|
||||
/* Check output buffer */
|
||||
ZSTD_STATIC_ASSERT(sizeof(ZSTD_outBuffer) == sizeof(struct zstd_out_buffer));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_outBuffer, dst) == offsetof(struct zstd_out_buffer, dst));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_outBuffer, size) == offsetof(struct zstd_out_buffer, size));
|
||||
ZSTD_STATIC_ASSERT(offsetof(ZSTD_outBuffer, pos) == offsetof(struct zstd_out_buffer, pos));
|
||||
}
|
||||
|
||||
size_t zstd_compress_bound(size_t src_size)
|
||||
{
|
||||
return ZSTD_compressBound(src_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_compress_bound);
|
||||
|
||||
struct zstd_parameters zstd_get_params(int level, unsigned long long estimated_src_size)
|
||||
{
|
||||
const ZSTD_parameters params = ZSTD_getParams(level, estimated_src_size, 0);
|
||||
struct zstd_parameters out;
|
||||
|
||||
/* no-op */
|
||||
zstd_check_structs();
|
||||
ZSTD_memcpy(&out, ¶ms, sizeof(out));
|
||||
return out;
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_get_params);
|
||||
|
||||
size_t zstd_cctx_workspace_bound(const struct zstd_compression_parameters *cparams)
|
||||
{
|
||||
ZSTD_compressionParameters p;
|
||||
|
||||
ZSTD_memcpy(&p, cparams, sizeof(p));
|
||||
return ZSTD_estimateCCtxSize_usingCParams(p);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_cctx_workspace_bound);
|
||||
|
||||
zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size)
|
||||
{
|
||||
if (workspace == NULL)
|
||||
return NULL;
|
||||
return ZSTD_initStaticCCtx(workspace, workspace_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_init_cctx);
|
||||
|
||||
size_t zstd_compress_cctx(zstd_cctx *cctx, void *dst, size_t dst_capacity, const void *src, size_t src_size, const struct zstd_parameters* parameters)
|
||||
{
|
||||
ZSTD_parameters p;
|
||||
|
||||
ZSTD_memcpy(&p, parameters, sizeof(p));
|
||||
return ZSTD_compress_advanced(cctx, dst, dst_capacity, src, src_size, NULL, 0, p);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_compress_cctx);
|
||||
|
||||
size_t zstd_cstream_workspace_bound(const struct zstd_compression_parameters *cparams)
|
||||
{
|
||||
ZSTD_compressionParameters p;
|
||||
|
||||
ZSTD_memcpy(&p, cparams, sizeof(p));
|
||||
return ZSTD_estimateCStreamSize_usingCParams(p);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_cstream_workspace_bound);
|
||||
|
||||
zstd_cstream *zstd_init_cstream(const struct zstd_parameters *parameters, unsigned long long pledged_src_size, void *workspace, size_t workspace_size)
|
||||
{
|
||||
ZSTD_parameters p;
|
||||
zstd_cstream *cstream;
|
||||
size_t ret;
|
||||
|
||||
if (workspace == NULL)
|
||||
return NULL;
|
||||
|
||||
cstream = ZSTD_initStaticCStream(workspace, workspace_size);
|
||||
if (cstream == NULL)
|
||||
return NULL;
|
||||
|
||||
/* 0 means unknown in linux zstd API but means 0 in new zstd API */
|
||||
if (pledged_src_size == 0)
|
||||
pledged_src_size = ZSTD_CONTENTSIZE_UNKNOWN;
|
||||
|
||||
ZSTD_memcpy(&p, parameters, sizeof(p));
|
||||
ret = ZSTD_initCStream_advanced(cstream, NULL, 0, p, pledged_src_size);
|
||||
if (ZSTD_isError(ret))
|
||||
return NULL;
|
||||
|
||||
return cstream;
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_init_cstream);
|
||||
|
||||
size_t zstd_reset_cstream(zstd_cstream *cstream, unsigned long long pledged_src_size)
|
||||
{
|
||||
return ZSTD_resetCStream(cstream, pledged_src_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_reset_cstream);
|
||||
|
||||
size_t zstd_compress_stream(zstd_cstream *cstream, struct zstd_out_buffer *output, struct zstd_in_buffer *input)
|
||||
{
|
||||
ZSTD_outBuffer o;
|
||||
ZSTD_inBuffer i;
|
||||
size_t ret;
|
||||
|
||||
ZSTD_memcpy(&o, output, sizeof(o));
|
||||
ZSTD_memcpy(&i, input, sizeof(i));
|
||||
ret = ZSTD_compressStream(cstream, &o, &i);
|
||||
ZSTD_memcpy(output, &o, sizeof(o));
|
||||
ZSTD_memcpy(input, &i, sizeof(i));
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_compress_stream);
|
||||
|
||||
size_t zstd_flush_stream(zstd_cstream *cstream, struct zstd_out_buffer *output)
|
||||
{
|
||||
ZSTD_outBuffer o;
|
||||
size_t ret;
|
||||
|
||||
ZSTD_memcpy(&o, output, sizeof(o));
|
||||
ret = ZSTD_flushStream(cstream, &o);
|
||||
ZSTD_memcpy(output, &o, sizeof(o));
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_flush_stream);
|
||||
|
||||
size_t zstd_end_stream(zstd_cstream *cstream, struct zstd_out_buffer *output)
|
||||
{
|
||||
ZSTD_outBuffer o;
|
||||
size_t ret;
|
||||
|
||||
ZSTD_memcpy(&o, output, sizeof(o));
|
||||
ret = ZSTD_endStream(cstream, &o);
|
||||
ZSTD_memcpy(output, &o, sizeof(o));
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_end_stream);
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
MODULE_DESCRIPTION("Zstd Compressor");
|
||||
|
@ -2,78 +2,117 @@
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/string.h>
|
||||
#include <linux/zstd.h>
|
||||
#include <linux/zstd_errors.h>
|
||||
|
||||
// Common symbols. zstd_compress must depend on zstd_decompress.
|
||||
EXPORT_SYMBOL(ZSTD_versionNumber);
|
||||
EXPORT_SYMBOL(ZSTD_versionString);
|
||||
EXPORT_SYMBOL(ZSTD_isError);
|
||||
EXPORT_SYMBOL(ZSTD_getErrorName);
|
||||
EXPORT_SYMBOL(ZSTD_getErrorCode);
|
||||
EXPORT_SYMBOL(ZSTD_getErrorString);
|
||||
#include "zstd.h"
|
||||
#include "common/zstd_deps.h"
|
||||
#include "common/zstd_errors.h"
|
||||
|
||||
// Decompression symbols.
|
||||
EXPORT_SYMBOL(ZSTD_getFrameContentSize);
|
||||
EXPORT_SYMBOL(ZSTD_getDecompressedSize);
|
||||
EXPORT_SYMBOL(ZSTD_findFrameCompressedSize);
|
||||
EXPORT_SYMBOL(ZSTD_freeDCtx);
|
||||
EXPORT_SYMBOL(ZSTD_decompressDCtx);
|
||||
EXPORT_SYMBOL(ZSTD_dParam_getBounds);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_setParameter);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_reset);
|
||||
EXPORT_SYMBOL(ZSTD_freeDStream);
|
||||
EXPORT_SYMBOL(ZSTD_initDStream);
|
||||
EXPORT_SYMBOL(ZSTD_decompressStream);
|
||||
EXPORT_SYMBOL(ZSTD_DStreamInSize);
|
||||
EXPORT_SYMBOL(ZSTD_DStreamOutSize);
|
||||
EXPORT_SYMBOL(ZSTD_decompress_usingDict);
|
||||
EXPORT_SYMBOL(ZSTD_freeDDict);
|
||||
EXPORT_SYMBOL(ZSTD_decompress_usingDDict);
|
||||
EXPORT_SYMBOL(ZSTD_getDictID_fromDict);
|
||||
EXPORT_SYMBOL(ZSTD_getDictID_fromDDict);
|
||||
EXPORT_SYMBOL(ZSTD_getDictID_fromFrame);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_refDDict);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_refPrefix);
|
||||
EXPORT_SYMBOL(ZSTD_sizeof_DCtx);
|
||||
EXPORT_SYMBOL(ZSTD_sizeof_DStream);
|
||||
EXPORT_SYMBOL(ZSTD_sizeof_DDict);
|
||||
EXPORT_SYMBOL(ZSTD_findDecompressedSize);
|
||||
EXPORT_SYMBOL(ZSTD_decompressBound);
|
||||
EXPORT_SYMBOL(ZSTD_frameHeaderSize);
|
||||
EXPORT_SYMBOL(ZSTD_estimateDCtxSize);
|
||||
EXPORT_SYMBOL(ZSTD_estimateDStreamSize);
|
||||
EXPORT_SYMBOL(ZSTD_estimateDStreamSize_fromFrame);
|
||||
EXPORT_SYMBOL(ZSTD_estimateDDictSize);
|
||||
EXPORT_SYMBOL(ZSTD_initStaticDCtx);
|
||||
EXPORT_SYMBOL(ZSTD_initStaticDStream);
|
||||
EXPORT_SYMBOL(ZSTD_initStaticDDict);
|
||||
EXPORT_SYMBOL(ZSTD_createDCtx_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_createDStream_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_createDDict_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_isFrame);
|
||||
EXPORT_SYMBOL(ZSTD_createDDict_byReference);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_loadDictionary_byReference);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_loadDictionary_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_refPrefix_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_setMaxWindowSize);
|
||||
EXPORT_SYMBOL(ZSTD_DCtx_setFormat);
|
||||
EXPORT_SYMBOL(ZSTD_decompressStream_simpleArgs);
|
||||
EXPORT_SYMBOL(ZSTD_initDStream_usingDict);
|
||||
EXPORT_SYMBOL(ZSTD_initDStream_usingDDict);
|
||||
EXPORT_SYMBOL(ZSTD_resetDStream);
|
||||
EXPORT_SYMBOL(ZSTD_getFrameHeader);
|
||||
EXPORT_SYMBOL(ZSTD_getFrameHeader_advanced);
|
||||
EXPORT_SYMBOL(ZSTD_decodingBufferSize_min);
|
||||
EXPORT_SYMBOL(ZSTD_decompressBegin);
|
||||
EXPORT_SYMBOL(ZSTD_decompressBegin_usingDict);
|
||||
EXPORT_SYMBOL(ZSTD_decompressBegin_usingDDict);
|
||||
EXPORT_SYMBOL(ZSTD_nextSrcSizeToDecompress);
|
||||
EXPORT_SYMBOL(ZSTD_decompressContinue);
|
||||
EXPORT_SYMBOL(ZSTD_copyDCtx);
|
||||
EXPORT_SYMBOL(ZSTD_nextInputType);
|
||||
EXPORT_SYMBOL(ZSTD_decompressBlock);
|
||||
EXPORT_SYMBOL(ZSTD_insertBlock);
|
||||
/* Common symbols. zstd_compress must depend on zstd_decompress. */
|
||||
|
||||
unsigned int zstd_is_error(size_t code)
|
||||
{
|
||||
return ZSTD_isError(code);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_is_error);
|
||||
|
||||
int zstd_get_error_code(size_t code)
|
||||
{
|
||||
return ZSTD_getErrorCode(code);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_get_error_code);
|
||||
|
||||
const char *zstd_get_error_name(size_t code)
|
||||
{
|
||||
return ZSTD_getErrorName(code);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_get_error_name);
|
||||
|
||||
/* Decompression symbols. */
|
||||
|
||||
size_t zstd_dctx_workspace_bound(void)
|
||||
{
|
||||
return ZSTD_estimateDCtxSize();
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_dctx_workspace_bound);
|
||||
|
||||
zstd_dctx* zstd_init_dctx(void *workspace, size_t workspace_size)
|
||||
{
|
||||
if (workspace == NULL)
|
||||
return NULL;
|
||||
return ZSTD_initStaticDCtx(workspace, workspace_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_init_dctx);
|
||||
|
||||
size_t zstd_decompress_dctx(zstd_dctx *dctx, void *dst, size_t dst_capacity, const void *src, size_t src_size)
|
||||
{
|
||||
return ZSTD_decompressDCtx(dctx, dst, dst_capacity, src, src_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_decompress_dctx);
|
||||
|
||||
size_t zstd_dstream_workspace_bound(size_t max_window_size)
|
||||
{
|
||||
return ZSTD_estimateDStreamSize(max_window_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_dstream_workspace_bound);
|
||||
|
||||
zstd_dstream *zstd_init_dstream(size_t max_window_size, void *workspace, size_t workspace_size)
|
||||
{
|
||||
if (workspace == NULL)
|
||||
return NULL;
|
||||
(void)max_window_size;
|
||||
return ZSTD_initStaticDStream(workspace, workspace_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_init_dstream);
|
||||
|
||||
size_t zstd_reset_dstream(zstd_dstream *dstream)
|
||||
{
|
||||
return ZSTD_resetDStream(dstream);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_reset_dstream);
|
||||
|
||||
size_t zstd_decompress_stream(zstd_dstream *dstream, struct zstd_out_buffer *output, struct zstd_in_buffer *input)
|
||||
{
|
||||
ZSTD_outBuffer o;
|
||||
ZSTD_inBuffer i;
|
||||
size_t ret;
|
||||
|
||||
ZSTD_memcpy(&o, output, sizeof(o));
|
||||
ZSTD_memcpy(&i, input, sizeof(i));
|
||||
ret = ZSTD_decompressStream(dstream, &o, &i);
|
||||
ZSTD_memcpy(output, &o, sizeof(o));
|
||||
ZSTD_memcpy(input, &i, sizeof(i));
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_decompress_stream);
|
||||
|
||||
size_t zstd_find_frame_compressed_size(const void *src, size_t src_size)
|
||||
{
|
||||
return ZSTD_findFrameCompressedSize(src, src_size);
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_find_frame_compressed_size);
|
||||
|
||||
size_t zstd_get_frame_params(struct zstd_frame_params *params, const void *src, size_t src_size)
|
||||
{
|
||||
ZSTD_frameHeader h;
|
||||
const size_t ret = ZSTD_getFrameHeader(&h, src, src_size);
|
||||
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (h.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN)
|
||||
params->frame_content_size = h.frameContentSize;
|
||||
else
|
||||
params->frame_content_size = 0;
|
||||
|
||||
params->window_size = h.windowSize;
|
||||
params->dict_id = h.dictID;
|
||||
params->checksum_flag = h.checksumFlag;
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(zstd_get_frame_params);
|
||||
|
||||
MODULE_LICENSE("Dual BSD/GPL");
|
||||
MODULE_DESCRIPTION("Zstd Decompressor");
|
||||
|
Reference in New Issue
Block a user