2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright © 2007 Nokia Corporation. All rights reserved.
6 * Created by Richard Purdie <rpurdie@openedhand.com>
8 * For licensing information, see the file 'LICENCE' in this directory.
12 #include <linux/kernel.h>
13 #include <linux/sched.h>
14 #include <linux/vmalloc.h>
15 #include <linux/init.h>
16 #include <linux/lzo.h>
20 static void *lzo_compress_buf
;
21 static DEFINE_MUTEX(deflate_mutex
); /* for lzo_mem and lzo_compress_buf */
23 static void free_workspace(void)
26 vfree(lzo_compress_buf
);
29 static int __init
alloc_workspace(void)
31 lzo_mem
= vmalloc(LZO1X_MEM_COMPRESS
);
32 lzo_compress_buf
= vmalloc(lzo1x_worst_compress(PAGE_SIZE
));
34 if (!lzo_mem
|| !lzo_compress_buf
) {
35 printk(KERN_WARNING
"Failed to allocate lzo deflate workspace\n");
43 static int jffs2_lzo_compress(unsigned char *data_in
, unsigned char *cpage_out
,
44 uint32_t *sourcelen
, uint32_t *dstlen
, void *model
)
49 mutex_lock(&deflate_mutex
);
50 ret
= lzo1x_1_compress(data_in
, *sourcelen
, lzo_compress_buf
, &compress_size
, lzo_mem
);
54 if (compress_size
> *dstlen
)
57 memcpy(cpage_out
, lzo_compress_buf
, compress_size
);
58 mutex_unlock(&deflate_mutex
);
60 *dstlen
= compress_size
;
64 mutex_unlock(&deflate_mutex
);
68 static int jffs2_lzo_decompress(unsigned char *data_in
, unsigned char *cpage_out
,
69 uint32_t srclen
, uint32_t destlen
, void *model
)
74 ret
= lzo1x_decompress_safe(data_in
, srclen
, cpage_out
, &dl
);
76 if (ret
!= LZO_E_OK
|| dl
!= destlen
)
82 static struct jffs2_compressor jffs2_lzo_comp
= {
83 .priority
= JFFS2_LZO_PRIORITY
,
85 .compr
= JFFS2_COMPR_LZO
,
86 .compress
= &jffs2_lzo_compress
,
87 .decompress
= &jffs2_lzo_decompress
,
91 int __init
jffs2_lzo_init(void)
95 ret
= alloc_workspace();
99 ret
= jffs2_register_compressor(&jffs2_lzo_comp
);
106 void jffs2_lzo_exit(void)
108 jffs2_unregister_compressor(&jffs2_lzo_comp
);