]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
[contrib][linux] Expose zstd headers to avoid duplication
authorNick Terrell <terrelln@fb.com>
Thu, 3 Dec 2020 20:37:30 +0000 (12:37 -0800)
committerNick Terrell <terrelln@fb.com>
Tue, 16 Mar 2021 18:47:22 +0000 (11:47 -0700)
Expose the zstd headers in `include/linux` to avoid struct duplication.
This makes the member names not follow Kernel style guidelines, and
exposes the zstd symbols. But, the LMKL reviewers are okay with that.

contrib/linux-kernel/Makefile
contrib/linux-kernel/linux_zstd.h
contrib/linux-kernel/test/test.c
contrib/linux-kernel/zstd_compress_module.c
contrib/linux-kernel/zstd_decompress_module.c

index 1725e7d46c9c12d4920248416580d017ff449eef..1cbe3435f483dc0b237120f3a566c9476db59a13 100644 (file)
@@ -22,6 +22,8 @@ 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,6 +50,8 @@ libzstd:
                -RZSTDERRORLIB_VISIBILITY= \
                -DZSTD_HAVE_WEAK_SYMBOLS=0 \
                -DZSTD_TRACE=0
+       mv linux/lib/zstd/zstd.h linux/include/linux/zstd_lib.h
+       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
@@ -62,15 +66,18 @@ import: libzstd
        rm -f $(LINUX)/include/linux/zstd_errors.h
        rm -rf $(LINUX)/lib/zstd
        cp linux/include/linux/zstd.h $(LINUX)/include/linux
+       cp linux/include/linux/zstd_lib.h $(LINUX)/include/linux
+       cp linux/include/linux/zstd_errors.h $(LINUX)/include/linux
        cp -r linux/lib/zstd $(LINUX)/lib
 
 import-upstream:
        rm -rf $(LINUX)/lib/zstd
        mkdir $(LINUX)/lib/zstd
-       cp ../../lib/zstd.h $(LINUX)/lib/zstd
+       cp ../../lib/zstd.h $(LINUX)/include/linux/zstd_lib.h
        cp -r ../../lib/common $(LINUX)/lib/zstd
        cp -r ../../lib/compress $(LINUX)/lib/zstd
        cp -r ../../lib/decompress $(LINUX)/lib/zstd
+       mv $(LINUX)/lib/zstd/common/zstd_errors.h $(LINUX)/include/linux
        rm $(LINUX)/lib/zstd/common/threading.*
        rm $(LINUX)/lib/zstd/common/pool.*
        rm $(LINUX)/lib/zstd/common/xxhash.*
index dcd1ec18b6463f5bc2814427f762dcbf5c3b8349..fe64558709ab17d06ca49da6174082a37240d014 100644 (file)
@@ -27,6 +27,8 @@
 
 /* ======   Dependency   ====== */
 #include <linux/types.h>
+#include <linux/zstd_errors.h>
+#include <linux/zstd_lib.h>
 
 /* ======   Helper Functions   ====== */
 /**
@@ -45,13 +47,18 @@ size_t zstd_compress_bound(size_t src_size);
  */
 unsigned int zstd_is_error(size_t code);
 
+/**
+ * enum zstd_error_code - zstd error codes
+ */
+typedef ZSTD_ErrorCode zstd_error_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_error_code zstd_get_error_code(size_t code);
 
 /**
  * zstd_get_error_name() - translates an error function result to a string
@@ -66,71 +73,48 @@ const char *zstd_get_error_name(size_t code);
 /**
  * enum zstd_strategy - zstd compression search strategy
  *
- * From faster to stronger.
+ * From faster to stronger. See zstd_lib.h.
  */
-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
-};
+typedef ZSTD_strategy zstd_strategy;
 
 /**
  * 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;
-};
+ * @windowLog:    Log of the largest match distance. Larger means more
+ *                compression, and more memory needed during decompression.
+ * @chainLog:     Fully searched segment. Larger means more compression,
+ *                slower, and more memory (useless for fast).
+ * @hashLog:      Dispatch table. Larger means more compression,
+ *                slower, and more memory.
+ * @searchLog:    Number of searches. Larger means more compression and slower.
+ * @searchLength: Match length searched. Larger means faster decompression,
+ *                sometimes less compression.
+ * @targetLength: Acceptable match size for optimal parser (only). Larger means
+ *                more compression, and slower.
+ * @strategy:     The zstd compression strategy.
+ *
+ * See zstd_lib.h.
+ */
+typedef ZSTD_compressionParameters zstd_compression_parameters;
 
 /**
  * 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.
+ * @contentSizeFlag: Controls whether content size will be present in the
+ *                   frame header (when known).
+ * @checksumFlag:    Controls whether a 32-bit checksum is generated at the
+ *                   end of the frame for error detection.
+ * @noDictIDFlag:    Controls whether dictID will be saved into the frame
+ *                   header when using dictionary compression.
  *
- * The default value is all fields set to 0.
+ * The default value is all fields set to 0. See zstd_lib.h.
  */
-struct zstd_frame_parameters {
-       unsigned int content_size_flag;
-       unsigned int checksum_flag;
-       unsigned int no_dict_id_flag;
-};
+typedef ZSTD_frameParameters zstd_frame_parameters;
 
 /**
  * struct zstd_parameters - zstd parameters
- * @cparams: The compression parameters.
- * @fparams: The frame parameters.
+ * @cParams: The compression parameters.
+ * @fParams: The frame parameters.
  */
-struct zstd_parameters {
-       struct zstd_compression_parameters cparams;
-       struct zstd_frame_parameters fparams;
-};
+typedef ZSTD_parameters zstd_parameters;
 
 /**
  * zstd_get_params() - returns zstd_parameters for selected level
@@ -140,12 +124,12 @@ struct zstd_parameters {
  *
  * Return:              The selected zstd_parameters.
  */
-struct zstd_parameters zstd_get_params(int level,
+zstd_parameters zstd_get_params(int level,
        unsigned long long estimated_src_size);
 
 /* ======   Single-pass Compression   ====== */
 
-typedef struct ZSTD_CCtx_s zstd_cctx;
+typedef ZSTD_CCtx zstd_cctx;
 
 /**
  * zstd_cctx_workspace_bound() - max memory needed to initialize a zstd_cctx
@@ -158,8 +142,7 @@ typedef struct ZSTD_CCtx_s zstd_cctx;
  * 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);
+size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *parameters);
 
 /**
  * zstd_init_cctx() - initialize a zstd compression context
@@ -186,11 +169,11 @@ zstd_cctx *zstd_init_cctx(void *workspace, size_t workspace_size);
  *                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);
+       const void *src, size_t src_size, const zstd_parameters *parameters);
 
 /* ======   Single-pass Decompression   ====== */
 
-typedef struct ZSTD_DCtx_s zstd_dctx;
+typedef ZSTD_DCtx zstd_dctx;
 
 /**
  * zstd_dctx_workspace_bound() - max memory needed to initialize a zstd_dctx
@@ -236,12 +219,10 @@ size_t zstd_decompress_dctx(zstd_dctx *dctx, void *dst, size_t dst_capacity,
  * @size: Size of the input buffer.
  * @pos:  Position where reading stopped. Will be updated.
  *        Necessarily 0 <= pos <= size.
+ *
+ * See zstd_lib.h.
  */
-struct zstd_in_buffer {
-       const void *src;
-       size_t size;
-       size_t pos;
-};
+typedef ZSTD_inBuffer zstd_in_buffer;
 
 /**
  * struct zstd_out_buffer - output buffer for streaming
@@ -249,16 +230,14 @@ struct zstd_in_buffer {
  * @size: Size of the output buffer.
  * @pos:  Position where writing stopped. Will be updated.
  *        Necessarily 0 <= pos <= size.
+ *
+ * See zstd_lib.h.
  */
-struct zstd_out_buffer {
-       void *dst;
-       size_t size;
-       size_t pos;
-};
+typedef ZSTD_outBuffer zstd_out_buffer;
 
 /* ======   Streaming Compression   ====== */
 
-typedef struct ZSTD_CCtx_s zstd_cstream;
+typedef ZSTD_CStream zstd_cstream;
 
 /**
  * zstd_cstream_workspace_bound() - memory needed to initialize a zstd_cstream
@@ -267,8 +246,7 @@ typedef struct ZSTD_CCtx_s zstd_cstream;
  * 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);
+size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams);
 
 /**
  * zstd_init_cstream() - initialize a zstd streaming compression context
@@ -285,7 +263,7 @@ size_t zstd_cstream_workspace_bound(
  *
  * Return:            The zstd streaming compression context or NULL on error.
  */
-zstd_cstream *zstd_init_cstream(const struct zstd_parameters *parameters,
+zstd_cstream *zstd_init_cstream(const zstd_parameters *parameters,
        unsigned long long pledged_src_size, void *workspace, size_t workspace_size);
 
 /**
@@ -320,8 +298,8 @@ size_t zstd_reset_cstream(zstd_cstream *cstream,
  *           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);
+size_t zstd_compress_stream(zstd_cstream *cstream, zstd_out_buffer *output,
+       zstd_in_buffer *input);
 
 /**
  * zstd_flush_stream() - flush internal buffers into output
@@ -336,7 +314,7 @@ size_t zstd_compress_stream(zstd_cstream *cstream,
  * 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);
+size_t zstd_flush_stream(zstd_cstream *cstream, zstd_out_buffer *output);
 
 /**
  * zstd_end_stream() - flush internal buffers into output and end the frame
@@ -350,11 +328,11 @@ size_t zstd_flush_stream(zstd_cstream *cstream, struct zstd_out_buffer *output);
  * 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);
+size_t zstd_end_stream(zstd_cstream *cstream, zstd_out_buffer *output);
 
 /* ======   Streaming Decompression   ====== */
 
-typedef struct ZSTD_DCtx_s zstd_dstream;
+typedef ZSTD_DStream zstd_dstream;
 
 /**
  * zstd_dstream_workspace_bound() - memory needed to initialize a zstd_dstream
@@ -411,8 +389,8 @@ size_t zstd_reset_dstream(zstd_dstream *dstream);
  *           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);
+size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output,
+       zstd_in_buffer *input);
 
 /* ======   Frame Inspection Functions ====== */
 
@@ -431,20 +409,21 @@ 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.
+ * @frameContentSize: The frame content size, or ZSTD_CONTENTSIZE_UNKNOWN if not
+ *                    present.
+ * @windowSize:       The window size, or 0 if the frame is a skippable frame.
+ * @blockSizeMax:     The maximum block size.
+ * @frameType:        The frame type (zstd or skippable)
+ * @headerSize:       The size of the frame header.
+ * @dictID:           The dictionary id, or 0 if not present.
+ * @checksumFlag:     Whether a checksum was used.
+ *
+ * See zstd_lib.h.
  */
-struct zstd_frame_params {
-       unsigned long long frame_content_size;
-       unsigned int window_size;
-       unsigned int dict_id;
-       unsigned int checksum_flag;
-};
+typedef ZSTD_frameHeader zstd_frame_header;
 
 /**
- * zstd_get_frame_params() - extracts parameters from a zstd or skippable frame
+ * zstd_get_frame_header() - 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.
@@ -453,7 +432,7 @@ struct zstd_frame_params {
  *            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 zstd_get_frame_header(zstd_frame_header *params, const void *src,
        size_t src_size);
 
 #endif  /* LINUX_ZSTD_H */
index 47af82f19a2e237637bcaebccb356cd4afdf4c64..0a33a9a76b474bf7cd013bd3abe2933aed0f50a3 100644 (file)
@@ -57,10 +57,10 @@ 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) {
-    struct zstd_parameters params = zstd_get_params(level, size);
-    CONTROL(params.cparams.window_log <= 17);
+    zstd_parameters params = zstd_get_params(level, size);
+    CONTROL(params.cParams.windowLog <= 17);
     size_t const workspaceSize =
-        MAX(zstd_cstream_workspace_bound(&params.cparams),
+        MAX(zstd_cstream_workspace_bound(&params.cParams),
             zstd_dstream_workspace_bound(size));
     void *workspace = malloc(workspaceSize);
     CONTROL(workspace != NULL);
@@ -72,8 +72,8 @@ static void test_btrfs(test_data_t const *data) {
     {
       zstd_cstream *cctx = zstd_init_cstream(&params, size, workspace, workspaceSize);
       CONTROL(cctx != NULL);
-      struct zstd_out_buffer out = {NULL, 0, 0};
-      struct zstd_in_buffer in = {NULL, 0, 0};
+      zstd_out_buffer out = {NULL, 0, 0};
+      zstd_in_buffer in = {NULL, 0, 0};
       for (;;) {
         if (in.pos == in.size) {
           in.src = ip;
@@ -107,10 +107,10 @@ static void test_btrfs(test_data_t const *data) {
     op = data->data2;
     oend = op + size;
     {
-      zstd_dstream *dctx = zstd_init_dstream(1ULL << params.cparams.window_log, workspace, workspaceSize);
+      zstd_dstream *dctx = zstd_init_dstream(1ULL << params.cParams.windowLog, workspace, workspaceSize);
       CONTROL(dctx != NULL);
-      struct zstd_out_buffer out = {NULL, 0, 0};
-      struct zstd_in_buffer in = {NULL, 0, 0};
+      zstd_out_buffer out = {NULL, 0, 0};
+      zstd_in_buffer in = {NULL, 0, 0};
       for (;;) {
         if (in.pos == in.size) {
           in.src = ip;
@@ -144,8 +144,8 @@ static void test_decompress_unzstd(test_data_t const *data) {
     fprintf(stderr, "Testing decompress unzstd... ");
     size_t cSize;
     {
-        struct zstd_parameters params = zstd_get_params(19, 0);
-        size_t const wkspSize = zstd_cctx_workspace_bound(&params.cparams);
+        zstd_parameters params = zstd_get_params(19, 0);
+        size_t const wkspSize = zstd_cctx_workspace_bound(&params.cParams);
         void* wksp = malloc(wkspSize);
         CONTROL(wksp != NULL);
         zstd_cctx* cctx = zstd_init_cctx(wksp, wkspSize);
index bab79afb0f00722333ea3d6641df773f669b9788..0a29abb5379b6a9bb2e37a2f70f922a0af319d68 100644 (file)
@@ -5,98 +5,25 @@
 #include <linux/string.h>
 #include <linux/zstd.h>
 
-#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,
+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, &params, sizeof(out));
-       return out;
+       return ZSTD_getParams(level, estimated_src_size, 0);
 }
 EXPORT_SYMBOL(zstd_get_params);
 
-size_t zstd_cctx_workspace_bound(
-       const struct zstd_compression_parameters *cparams)
+size_t zstd_cctx_workspace_bound(const zstd_compression_parameters *cparams)
 {
-       ZSTD_compressionParameters p;
-
-       ZSTD_memcpy(&p, cparams, sizeof(p));
-       return ZSTD_estimateCCtxSize_usingCParams(p);
+       return ZSTD_estimateCCtxSize_usingCParams(*cparams);
 }
 EXPORT_SYMBOL(zstd_cctx_workspace_bound);
 
@@ -109,29 +36,21 @@ zstd_cctx *zstd_init_cctx(void *workspace, size_t 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)
+       const void *src, size_t src_size, const 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);
+       return ZSTD_compress_advanced(cctx, dst, dst_capacity, src, src_size, NULL, 0, *parameters);
 }
 EXPORT_SYMBOL(zstd_compress_cctx);
 
-size_t zstd_cstream_workspace_bound(
-       const struct zstd_compression_parameters *cparams)
+size_t zstd_cstream_workspace_bound(const zstd_compression_parameters *cparams)
 {
-       ZSTD_compressionParameters p;
-
-       ZSTD_memcpy(&p, cparams, sizeof(p));
-       return ZSTD_estimateCStreamSize_usingCParams(p);
+       return ZSTD_estimateCStreamSize_usingCParams(*cparams);
 }
 EXPORT_SYMBOL(zstd_cstream_workspace_bound);
 
-zstd_cstream *zstd_init_cstream(const struct zstd_parameters *parameters,
+zstd_cstream *zstd_init_cstream(const zstd_parameters *parameters,
        unsigned long long pledged_src_size, void *workspace, size_t workspace_size)
 {
-       ZSTD_parameters p;
        zstd_cstream *cstream;
        size_t ret;
 
@@ -146,8 +65,7 @@ zstd_cstream *zstd_init_cstream(const struct zstd_parameters *parameters,
        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);
+       ret = ZSTD_initCStream_advanced(cstream, NULL, 0, *parameters, pledged_src_size);
        if (ZSTD_isError(ret))
                return NULL;
 
@@ -162,43 +80,22 @@ size_t zstd_reset_cstream(zstd_cstream *cstream,
 }
 EXPORT_SYMBOL(zstd_reset_cstream);
 
-size_t zstd_compress_stream(zstd_cstream *cstream,
-       struct zstd_out_buffer *output, struct zstd_in_buffer *input)
+size_t zstd_compress_stream(zstd_cstream *cstream, zstd_out_buffer *output,
+       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;
+       return ZSTD_compressStream(cstream, output, input);
 }
 EXPORT_SYMBOL(zstd_compress_stream);
 
-size_t zstd_flush_stream(zstd_cstream *cstream, struct zstd_out_buffer *output)
+size_t zstd_flush_stream(zstd_cstream *cstream, 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;
+       return ZSTD_flushStream(cstream, output);
 }
 EXPORT_SYMBOL(zstd_flush_stream);
 
-size_t zstd_end_stream(zstd_cstream *cstream, struct zstd_out_buffer *output)
+size_t zstd_end_stream(zstd_cstream *cstream, 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;
+       return ZSTD_endStream(cstream, output);
 }
 EXPORT_SYMBOL(zstd_end_stream);
 
index 988fdb57200e50289829fce7dbb0548b39402794..bac348daab7fc8117a60b0c642a9406220d89649 100644 (file)
@@ -5,9 +5,7 @@
 #include <linux/string.h>
 #include <linux/zstd.h>
 
-#include "zstd.h"
 #include "common/zstd_deps.h"
-#include "common/zstd_errors.h"
 
 /* Common symbols. zstd_compress must depend on zstd_decompress. */
 
@@ -17,7 +15,7 @@ unsigned int zstd_is_error(size_t code)
 }
 EXPORT_SYMBOL(zstd_is_error);
 
-int zstd_get_error_code(size_t code)
+zstd_error_code zstd_get_error_code(size_t code)
 {
        return ZSTD_getErrorCode(code);
 }
@@ -74,19 +72,10 @@ size_t zstd_reset_dstream(zstd_dstream *dstream)
 }
 EXPORT_SYMBOL(zstd_reset_dstream);
 
-size_t zstd_decompress_stream(zstd_dstream *dstream,
-       struct zstd_out_buffer *output, struct zstd_in_buffer *input)
+size_t zstd_decompress_stream(zstd_dstream *dstream, zstd_out_buffer *output,
+       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;
+       return ZSTD_decompressStream(dstream, output, input);
 }
 EXPORT_SYMBOL(zstd_decompress_stream);
 
@@ -96,27 +85,12 @@ size_t zstd_find_frame_compressed_size(const void *src, size_t 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 zstd_get_frame_header(zstd_frame_header *header, 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;
+       return ZSTD_getFrameHeader(header, src, src_size);
 }
-EXPORT_SYMBOL(zstd_get_frame_params);
+EXPORT_SYMBOL(zstd_get_frame_header);
 
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_DESCRIPTION("Zstd Decompressor");