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