• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0
2 /*
3  * Copyright (C) 2018-2019 HUAWEI, Inc.
4  *             http://www.huawei.com/
5  * Created by Gao Xiang <gaoxiang25@huawei.com>
6  */
7 #include <lz4.h>
8 #include "erofs/internal.h"
9 #include "compressor.h"
10 
11 #ifndef LZ4_DISTANCE_MAX	/* history window size */
12 #define LZ4_DISTANCE_MAX 65535	/* set to maximum value by default */
13 #endif
14 
lz4_compress_destsize(const struct erofs_compress * c,const void * src,unsigned int * srcsize,void * dst,unsigned int dstsize)15 static int lz4_compress_destsize(const struct erofs_compress *c,
16 				 const void *src, unsigned int *srcsize,
17 				 void *dst, unsigned int dstsize)
18 {
19 	int srcSize = (int)*srcsize;
20 	int rc = LZ4_compress_destSize(src, dst, &srcSize, (int)dstsize);
21 
22 	if (!rc)
23 		return -EFAULT;
24 	*srcsize = srcSize;
25 	return rc;
26 }
27 
compressor_lz4_exit(struct erofs_compress * c)28 static int compressor_lz4_exit(struct erofs_compress *c)
29 {
30 	return 0;
31 }
32 
compressor_lz4_init(struct erofs_compress * c)33 static int compressor_lz4_init(struct erofs_compress *c)
34 {
35 	c->sbi->lz4_max_distance = LZ4_DISTANCE_MAX;
36 	return 0;
37 }
38 
39 const struct erofs_compressor erofs_compressor_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