lz4.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. * lz4_compressbound()
  16. * Provides the maximum size that LZ4 may output in a "worst case" scenario
  17. * (input data not compressible)
  18. */
  19. static inline size_t lz4_compressbound(size_t isize)
  20. {
  21. return isize + (isize / 255) + 16;
  22. }
  23. /*
  24. * lz4_compress()
  25. * src : source address of the original data
  26. * src_len : size of the original data
  27. * dst : output buffer address of the compressed data
  28. * This requires 'dst' of size LZ4_COMPRESSBOUND.
  29. * dst_len : is the output size, which is returned after compress done
  30. * workmem : address of the working memory.
  31. * This requires 'workmem' of size LZ4_MEM_COMPRESS.
  32. * return : Success if return 0
  33. * Error if return (< 0)
  34. * note : Destination buffer and workmem must be already allocated with
  35. * the defined size.
  36. */
  37. int lz4_compress(const unsigned char *src, size_t src_len,
  38. unsigned char *dst, size_t *dst_len, void *wrkmem);
  39. /*
  40. * lz4hc_compress()
  41. * src : source address of the original data
  42. * src_len : size of the original data
  43. * dst : output buffer address of the compressed data
  44. * This requires 'dst' of size LZ4_COMPRESSBOUND.
  45. * dst_len : is the output size, which is returned after compress done
  46. * workmem : address of the working memory.
  47. * This requires 'workmem' of size LZ4HC_MEM_COMPRESS.
  48. * return : Success if return 0
  49. * Error if return (< 0)
  50. * note : Destination buffer and workmem must be already allocated with
  51. * the defined size.
  52. */
  53. int lz4hc_compress(const unsigned char *src, size_t src_len,
  54. unsigned char *dst, size_t *dst_len, void *wrkmem);
  55. /*
  56. * lz4_decompress()
  57. * src : source address of the compressed data
  58. * src_len : is the input size, whcih is returned after decompress done
  59. * dest : output buffer address of the decompressed data
  60. * actual_dest_len: is the size of uncompressed data, supposing it's known
  61. * return : Success if return 0
  62. * Error if return (< 0)
  63. * note : Destination buffer must be already allocated.
  64. * slightly faster than lz4_decompress_unknownoutputsize()
  65. */
  66. int lz4_decompress(const unsigned char *src, size_t *src_len,
  67. unsigned char *dest, size_t actual_dest_len);
  68. /*
  69. * lz4_decompress_unknownoutputsize()
  70. * src : source address of the compressed data
  71. * src_len : is the input size, therefore the compressed size
  72. * dest : output buffer address of the decompressed data
  73. * dest_len: is the max size of the destination buffer, which is
  74. * returned with actual size of decompressed data after
  75. * decompress done
  76. * return : Success if return 0
  77. * Error if return (< 0)
  78. * note : Destination buffer must be already allocated.
  79. */
  80. int lz4_decompress_unknownoutputsize(const unsigned char *src, size_t src_len,
  81. unsigned char *dest, size_t *dest_len);
  82. #endif