lz4.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * lz4_compress_zram()
  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 LZ4_MEM_COMPRESS.
  48. * checksum: checksum for input data.
  49. * return : Success if return 0
  50. * Error if return (< 0)
  51. * note : Destination buffer and workmem must be already allocated with
  52. * the defined size.
  53. */
  54. int lz4_compress_zram(const unsigned char *src, size_t src_len,
  55. unsigned char *dst, size_t *dst_len, void *wrkmem, int *checksum);
  56. /*
  57. * lz4hc_compress()
  58. * src : source address of the original data
  59. * src_len : size of the original data
  60. * dst : output buffer address of the compressed data
  61. * This requires 'dst' of size LZ4_COMPRESSBOUND.
  62. * dst_len : is the output size, which is returned after compress done
  63. * workmem : address of the working memory.
  64. * This requires 'workmem' of size LZ4HC_MEM_COMPRESS.
  65. * return : Success if return 0
  66. * Error if return (< 0)
  67. * note : Destination buffer and workmem must be already allocated with
  68. * the defined size.
  69. */
  70. int lz4hc_compress(const unsigned char *src, size_t src_len,
  71. unsigned char *dst, size_t *dst_len, void *wrkmem);
  72. /*
  73. * lz4_decompress()
  74. * src : source address of the compressed data
  75. * src_len : is the input size, whcih is returned after decompress done
  76. * dest : output buffer address of the decompressed data
  77. * actual_dest_len: is the size of uncompressed data, supposing it's known
  78. * return : Success if return 0
  79. * Error if return (< 0)
  80. * note : Destination buffer must be already allocated.
  81. * slightly faster than lz4_decompress_unknownoutputsize()
  82. */
  83. int lz4_decompress(const unsigned char *src, size_t *src_len,
  84. unsigned char *dest, size_t actual_dest_len);
  85. /*
  86. * lz4_decompress_unknownoutputsize()
  87. * src : source address of the compressed data
  88. * src_len : is the input size, therefore the compressed size
  89. * dest : output buffer address of the decompressed data
  90. * dest_len: is the max size of the destination buffer, which is
  91. * returned with actual size of decompressed data after
  92. * decompress done
  93. * return : Success if return 0
  94. * Error if return (< 0)
  95. * note : Destination buffer must be already allocated.
  96. */
  97. int lz4_decompress_unknownoutputsize(const unsigned char *src, size_t src_len,
  98. unsigned char *dest, size_t *dest_len);
  99. #endif