1 #ifndef __LZ4_H__
2 #define __LZ4_H__
3 
4 /*
5  * LZ4 Kernel Interface
6  *
7  * Copyright (C) 2013, LG Electronics, Kyungsik Lee <kyungsik.lee@lge.com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 #define LZ4_MEM_COMPRESS	(4096 * sizeof(unsigned char *))
14 #define LZ4HC_MEM_COMPRESS	(65538 * sizeof(unsigned char *))
15 
16 /*
17  * lz4_compressbound()
18  * Provides the maximum size that LZ4 may output in a "worst case" scenario
19  * (input data not compressible)
20  */
lz4_compressbound(size_t isize)21 static inline size_t lz4_compressbound(size_t isize)
22 {
23 	return isize + (isize / 255) + 16;
24 }
25 
26 /*
27  * lz4_compress()
28  *	src     : source address of the original data
29  *	src_len : size of the original data
30  *	dst	: output buffer address of the compressed data
31  *		This requires 'dst' of size LZ4_COMPRESSBOUND.
32  *	dst_len : is the output size, which is returned after compress done
33  *	workmem : address of the working memory.
34  *		This requires 'workmem' of size LZ4_MEM_COMPRESS.
35  *	return  : Success if return 0
36  *		  Error if return (< 0)
37  *	note :  Destination buffer and workmem must be already allocated with
38  *		the defined size.
39  */
40 int lz4_compress(const unsigned char *src, size_t src_len,
41 		unsigned char *dst, size_t *dst_len, void *wrkmem);
42 
43  /*
44   * lz4hc_compress()
45   *	 src	 : source address of the original data
46   *	 src_len : size of the original data
47   *	 dst	 : output buffer address of the compressed data
48   *		This requires 'dst' of size LZ4_COMPRESSBOUND.
49   *	 dst_len : is the output size, which is returned after compress done
50   *	 workmem : address of the working memory.
51   *		This requires 'workmem' of size LZ4HC_MEM_COMPRESS.
52   *	 return  : Success if return 0
53   *		   Error if return (< 0)
54   *	 note :  Destination buffer and workmem must be already allocated with
55   *		 the defined size.
56   */
57 int lz4hc_compress(const unsigned char *src, size_t src_len,
58 		unsigned char *dst, size_t *dst_len, void *wrkmem);
59 
60 /*
61  * lz4_decompress()
62  *	src     : source address of the compressed data
63  *	src_len : is the input size, whcih is returned after decompress done
64  *	dest	: output buffer address of the decompressed data
65  *	actual_dest_len: is the size of uncompressed data, supposing it's known
66  *	return  : Success if return 0
67  *		  Error if return (< 0)
68  *	note :  Destination buffer must be already allocated.
69  *		slightly faster than lz4_decompress_unknownoutputsize()
70  */
71 int lz4_decompress(const unsigned char *src, size_t *src_len,
72 		unsigned char *dest, size_t actual_dest_len);
73 
74 /*
75  * lz4_decompress_unknownoutputsize()
76  *	src     : source address of the compressed data
77  *	src_len : is the input size, therefore the compressed size
78  *	dest	: output buffer address of the decompressed data
79  *	dest_len: is the max size of the destination buffer, which is
80  *			returned with actual size of decompressed data after
81  *			decompress done
82  *	return  : Success if return 0
83  *		  Error if return (< 0)
84  *	note :  Destination buffer must be already allocated.
85  */
86 int lz4_decompress_unknownoutputsize(const unsigned char *src, size_t src_len,
87 		unsigned char *dest, size_t *dest_len);
88 #endif
89