1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * erofs-utils/lib/compressor-lz4.c
4 *
5 * Copyright (C) 2018-2019 HUAWEI, Inc.
6 * http://www.huawei.com/
7 * Created by Gao Xiang <gaoxiang25@huawei.com>
8 */
9 #include <lz4.h>
10 #include "erofs/internal.h"
11 #include "compressor.h"
12
lz4_compress_destsize(struct erofs_compress * c,int compression_level,void * src,unsigned int * srcsize,void * dst,unsigned int dstsize)13 static int lz4_compress_destsize(struct erofs_compress *c,
14 int compression_level,
15 void *src, unsigned int *srcsize,
16 void *dst, unsigned int dstsize)
17 {
18 int srcSize = (int)*srcsize;
19 int rc = LZ4_compress_destSize(src, dst, &srcSize, (int)dstsize);
20
21 if (!rc)
22 return -EFAULT;
23 *srcsize = srcSize;
24 return rc;
25 }
26
compressor_lz4_exit(struct erofs_compress * c)27 static int compressor_lz4_exit(struct erofs_compress *c)
28 {
29 return 0;
30 }
31
compressor_lz4_init(struct erofs_compress * c)32 static int compressor_lz4_init(struct erofs_compress *c)
33 {
34 c->alg = &erofs_compressor_lz4;
35 return 0;
36 }
37
38 struct erofs_compressor erofs_compressor_lz4 = {
39 .name = "lz4",
40 .default_level = 0,
41 .best_level = 0,
42 .init = compressor_lz4_init,
43 .exit = compressor_lz4_exit,
44 .compress_destsize = lz4_compress_destsize,
45 };
46
47