zcomp.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (C) 2014 Sergey Senozhatsky.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version
  7. * 2 of the License, or (at your option) any later version.
  8. */
  9. #ifndef _ZCOMP_H_
  10. #define _ZCOMP_H_
  11. #include <linux/mutex.h>
  12. struct zcomp_strm {
  13. /* compression/decompression buffer */
  14. void *buffer;
  15. /*
  16. * The private data of the compression stream, only compression
  17. * stream backend can touch this (e.g. compression algorithm
  18. * working memory)
  19. */
  20. void *private;
  21. /* used in multi stream backend, protected by backend strm_lock */
  22. struct list_head list;
  23. };
  24. /* static compression backend */
  25. #ifdef CONFIG_ZSM
  26. struct zcomp_backend {
  27. int (*compress)(const unsigned char *src, unsigned char *dst,
  28. size_t *dst_len, void *private, int *checksum);
  29. int (*decompress)(const unsigned char *src, size_t src_len,
  30. unsigned char *dst);
  31. void *(*create)(void);
  32. void (*destroy)(void *private);
  33. const char *name;
  34. };
  35. #else
  36. struct zcomp_backend {
  37. int (*compress)(const unsigned char *src, unsigned char *dst,
  38. size_t *dst_len, void *private);
  39. int (*decompress)(const unsigned char *src, size_t src_len,
  40. unsigned char *dst);
  41. void *(*create)(void);
  42. void (*destroy)(void *private);
  43. const char *name;
  44. };
  45. #endif
  46. /* dynamic per-device compression frontend */
  47. struct zcomp {
  48. void *stream;
  49. struct zcomp_backend *backend;
  50. struct zcomp_strm *(*strm_find)(struct zcomp *comp);
  51. void (*strm_release)(struct zcomp *comp, struct zcomp_strm *zstrm);
  52. bool (*set_max_streams)(struct zcomp *comp, int num_strm);
  53. void (*destroy)(struct zcomp *comp);
  54. };
  55. ssize_t zcomp_available_show(const char *comp, char *buf);
  56. struct zcomp *zcomp_create(const char *comp, int max_strm);
  57. void zcomp_destroy(struct zcomp *comp);
  58. struct zcomp_strm *zcomp_strm_find(struct zcomp *comp);
  59. void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm);
  60. #ifdef CONFIG_ZSM
  61. int zcomp_compress_zram(struct zcomp *comp, struct zcomp_strm *zstrm,
  62. const unsigned char *src, size_t *dst_len, int *checksum);
  63. #else
  64. int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
  65. const unsigned char *src, size_t *dst_len);
  66. #endif
  67. int zcomp_decompress(struct zcomp *comp, const unsigned char *src,
  68. size_t src_len, unsigned char *dst);
  69. bool zcomp_set_max_streams(struct zcomp *comp, int num_strm);
  70. #endif /* _ZCOMP_H_ */