Sergey Senozhatsky | e7e1ef4 | 2014-04-07 15:38:11 -0700 | [diff] [blame] | 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 | |
| 10 | #ifndef _ZCOMP_H_ |
| 11 | #define _ZCOMP_H_ |
| 12 | |
| 13 | #include <linux/mutex.h> |
| 14 | |
| 15 | struct zcomp_strm { |
| 16 | /* compression/decompression buffer */ |
| 17 | void *buffer; |
| 18 | /* |
| 19 | * The private data of the compression stream, only compression |
| 20 | * stream backend can touch this (e.g. compression algorithm |
| 21 | * working memory) |
| 22 | */ |
| 23 | void *private; |
Sergey Senozhatsky | beca3ec | 2014-04-07 15:38:14 -0700 | [diff] [blame] | 24 | /* used in multi stream backend, protected by backend strm_lock */ |
| 25 | struct list_head list; |
Sergey Senozhatsky | e7e1ef4 | 2014-04-07 15:38:11 -0700 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | /* static compression backend */ |
| 29 | struct zcomp_backend { |
| 30 | int (*compress)(const unsigned char *src, unsigned char *dst, |
| 31 | size_t *dst_len, void *private); |
| 32 | |
| 33 | int (*decompress)(const unsigned char *src, size_t src_len, |
| 34 | unsigned char *dst); |
| 35 | |
| 36 | void *(*create)(void); |
| 37 | void (*destroy)(void *private); |
| 38 | |
| 39 | const char *name; |
| 40 | }; |
| 41 | |
| 42 | /* dynamic per-device compression frontend */ |
| 43 | struct zcomp { |
Sergey Senozhatsky | 9cc9752 | 2014-04-07 15:38:13 -0700 | [diff] [blame] | 44 | void *stream; |
Sergey Senozhatsky | e7e1ef4 | 2014-04-07 15:38:11 -0700 | [diff] [blame] | 45 | struct zcomp_backend *backend; |
Sergey Senozhatsky | 9cc9752 | 2014-04-07 15:38:13 -0700 | [diff] [blame] | 46 | |
| 47 | struct zcomp_strm *(*strm_find)(struct zcomp *comp); |
| 48 | void (*strm_release)(struct zcomp *comp, struct zcomp_strm *zstrm); |
Minchan Kim | 60a726e | 2014-04-07 15:38:21 -0700 | [diff] [blame] | 49 | bool (*set_max_streams)(struct zcomp *comp, int num_strm); |
Sergey Senozhatsky | 9cc9752 | 2014-04-07 15:38:13 -0700 | [diff] [blame] | 50 | void (*destroy)(struct zcomp *comp); |
Sergey Senozhatsky | e7e1ef4 | 2014-04-07 15:38:11 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Sergey Senozhatsky | e46b8a0 | 2014-04-07 15:38:17 -0700 | [diff] [blame] | 53 | ssize_t zcomp_available_show(const char *comp, char *buf); |
Sergey Senozhatsky | d93435c | 2015-06-25 15:00:32 -0700 | [diff] [blame] | 54 | bool zcomp_available_algorithm(const char *comp); |
Sergey Senozhatsky | e46b8a0 | 2014-04-07 15:38:17 -0700 | [diff] [blame] | 55 | |
Sergey Senozhatsky | beca3ec | 2014-04-07 15:38:14 -0700 | [diff] [blame] | 56 | struct zcomp *zcomp_create(const char *comp, int max_strm); |
Sergey Senozhatsky | e7e1ef4 | 2014-04-07 15:38:11 -0700 | [diff] [blame] | 57 | void zcomp_destroy(struct zcomp *comp); |
| 58 | |
| 59 | struct zcomp_strm *zcomp_strm_find(struct zcomp *comp); |
| 60 | void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm); |
| 61 | |
| 62 | int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, |
| 63 | const unsigned char *src, size_t *dst_len); |
| 64 | |
| 65 | int zcomp_decompress(struct zcomp *comp, const unsigned char *src, |
| 66 | size_t src_len, unsigned char *dst); |
Sergey Senozhatsky | fe8eb12 | 2014-04-07 15:38:15 -0700 | [diff] [blame] | 67 | |
Minchan Kim | 60a726e | 2014-04-07 15:38:21 -0700 | [diff] [blame] | 68 | bool zcomp_set_max_streams(struct zcomp *comp, int num_strm); |
Sergey Senozhatsky | e7e1ef4 | 2014-04-07 15:38:11 -0700 | [diff] [blame] | 69 | #endif /* _ZCOMP_H_ */ |