| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- /*
- * Copyright (C) 2014 Sergey Senozhatsky.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
- #include <linux/kernel.h>
- #include <linux/slab.h>
- #include <linux/lzo.h>
- #include "zcomp_lzo.h"
- static void *lzo_create(void)
- {
- return kzalloc(LZO1X_MEM_COMPRESS, GFP_KERNEL);
- }
- static void lzo_destroy(void *private)
- {
- kfree(private);
- }
- #ifdef CONFIG_ZSM
- static int lzo_compress_zram(const unsigned char *src, unsigned char *dst,
- size_t *dst_len, void *private, int *checksum)
- {
- int ret = lzo1x_1_compress_zram(src, PAGE_SIZE, dst, dst_len, private, checksum);
- return ret == LZO_E_OK ? 0 : ret;
- }
- #else
- static int lzo_compress(const unsigned char *src, unsigned char *dst,
- size_t *dst_len, void *private)
- {
- int ret = lzo1x_1_compress(src, PAGE_SIZE, dst, dst_len, private);
- return ret == LZO_E_OK ? 0 : ret;
- }
- #endif
- static int lzo_decompress(const unsigned char *src, size_t src_len,
- unsigned char *dst)
- {
- size_t dst_len = PAGE_SIZE;
- int ret = lzo1x_decompress_safe(src, src_len, dst, &dst_len);
- return ret == LZO_E_OK ? 0 : ret;
- }
- #ifdef CONFIG_ZSM
- struct zcomp_backend zcomp_lzo = {
- .compress = lzo_compress_zram,
- .decompress = lzo_decompress,
- .create = lzo_create,
- .destroy = lzo_destroy,
- .name = "lzo",
- };
- #else
- struct zcomp_backend zcomp_lzo = {
- .compress = lzo_compress,
- .decompress = lzo_decompress,
- .create = lzo_create,
- .destroy = lzo_destroy,
- .name = "lzo",
- };
- #endif
|