zcomp.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. struct zcomp_backend {
  26. int (*compress)(const unsigned char *src, unsigned char *dst,
  27. size_t *dst_len, void *private);
  28. int (*decompress)(const unsigned char *src, size_t src_len,
  29. unsigned char *dst);
  30. void *(*create)(gfp_t flags);
  31. void (*destroy)(void *private);
  32. const char *name;
  33. };
  34. /* dynamic per-device compression frontend */
  35. struct zcomp {
  36. void *stream;
  37. struct zcomp_backend *backend;
  38. struct zcomp_strm *(*strm_find)(struct zcomp *comp);
  39. void (*strm_release)(struct zcomp *comp, struct zcomp_strm *zstrm);
  40. bool (*set_max_streams)(struct zcomp *comp, int num_strm);
  41. void (*destroy)(struct zcomp *comp);
  42. };
  43. ssize_t zcomp_available_show(const char *comp, char *buf);
  44. struct zcomp *zcomp_create(const char *comp, int max_strm);
  45. void zcomp_destroy(struct zcomp *comp);
  46. struct zcomp_strm *zcomp_strm_find(struct zcomp *comp);
  47. void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm);
  48. int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm,
  49. const unsigned char *src, size_t *dst_len);
  50. int zcomp_decompress(struct zcomp *comp, const unsigned char *src,
  51. size_t src_len, unsigned char *dst);
  52. bool zcomp_set_max_streams(struct zcomp *comp, int num_strm);
  53. #endif /* _ZCOMP_H_ */