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; |
| 24 | }; |
| 25 | |
| 26 | /* static compression backend */ |
| 27 | struct zcomp_backend { |
| 28 | int (*compress)(const unsigned char *src, unsigned char *dst, |
| 29 | size_t *dst_len, void *private); |
| 30 | |
| 31 | int (*decompress)(const unsigned char *src, size_t src_len, |
| 32 | unsigned char *dst); |
| 33 | |
| 34 | void *(*create)(void); |
| 35 | void (*destroy)(void *private); |
| 36 | |
| 37 | const char *name; |
| 38 | }; |
| 39 | |
| 40 | /* dynamic per-device compression frontend */ |
| 41 | struct zcomp { |
| 42 | struct mutex strm_lock; |
| 43 | struct zcomp_strm *zstrm; |
| 44 | struct zcomp_backend *backend; |
| 45 | }; |
| 46 | |
| 47 | struct zcomp *zcomp_create(const char *comp); |
| 48 | void zcomp_destroy(struct zcomp *comp); |
| 49 | |
| 50 | struct zcomp_strm *zcomp_strm_find(struct zcomp *comp); |
| 51 | void zcomp_strm_release(struct zcomp *comp, struct zcomp_strm *zstrm); |
| 52 | |
| 53 | int zcomp_compress(struct zcomp *comp, struct zcomp_strm *zstrm, |
| 54 | const unsigned char *src, size_t *dst_len); |
| 55 | |
| 56 | int zcomp_decompress(struct zcomp *comp, const unsigned char *src, |
| 57 | size_t src_len, unsigned char *dst); |
| 58 | #endif /* _ZCOMP_H_ */ |