aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorRichard Purdie <rpurdie@openedhand.com>2007-07-10 05:28:36 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2007-07-11 10:03:53 -0400
commitc799aca31bfe61ba3a91133acf5a13a0773087d4 (patch)
treed05f44fbec08e26fd52b8b1f4c7b5d162cfe3c31 /fs
parent8691a729a2a3d739ee40a577053157393450aabd (diff)
[JFFS2] Add LZO compression support.
Add LZO1X compression/decompression support to jffs2. LZO's interface doesn't entirely match that required by jffs2 so a buffer and memcpy is unavoidable. Signed-off-by: Richard Purdie <rpurdie@openedhand.com> Signed-off-by: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/Kconfig11
-rw-r--r--fs/jffs2/Makefile1
-rw-r--r--fs/jffs2/compr.c6
-rw-r--r--fs/jffs2/compr.h3
-rw-r--r--fs/jffs2/compr_lzo.c108
5 files changed, 128 insertions, 1 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
index e19423a2aa7d..a2ec0b375dff 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -1314,6 +1314,17 @@ config JFFS2_ZLIB
1314 1314
1315 Say 'Y' if unsure. 1315 Say 'Y' if unsure.
1316 1316
1317config JFFS2_LZO
1318 bool "JFFS2 LZO compression support" if JFFS2_COMPRESSION_OPTIONS
1319 select LZO_COMPRESS
1320 select LZO_DECOMPRESS
1321 depends on JFFS2_FS
1322 default y
1323 help
1324 minilzo-based compression. Generally works better than Zlib.
1325
1326 Say 'Y' if unsure.
1327
1317config JFFS2_RTIME 1328config JFFS2_RTIME
1318 bool "JFFS2 RTIME compression support" if JFFS2_COMPRESSION_OPTIONS 1329 bool "JFFS2 RTIME compression support" if JFFS2_COMPRESSION_OPTIONS
1319 depends on JFFS2_FS 1330 depends on JFFS2_FS
diff --git a/fs/jffs2/Makefile b/fs/jffs2/Makefile
index c32b241e3d91..60e5d49ca03e 100644
--- a/fs/jffs2/Makefile
+++ b/fs/jffs2/Makefile
@@ -17,4 +17,5 @@ jffs2-$(CONFIG_JFFS2_FS_POSIX_ACL) += acl.o
17jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o 17jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o
18jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o 18jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o
19jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o 19jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o
20jffs2-$(CONFIG_JFFS2_LZO) += compr_lzo.o
20jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o 21jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o
diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c
index d90ca05e4992..bcc28d266a12 100644
--- a/fs/jffs2/compr.c
+++ b/fs/jffs2/compr.c
@@ -286,6 +286,9 @@ int __init jffs2_compressors_init(void)
286 jffs2_rubinmips_init(); 286 jffs2_rubinmips_init();
287 jffs2_dynrubin_init(); 287 jffs2_dynrubin_init();
288#endif 288#endif
289#ifdef CONFIG_JFFS2_LZO
290 jffs2_lzo_init();
291#endif
289/* Setting default compression mode */ 292/* Setting default compression mode */
290#ifdef CONFIG_JFFS2_CMODE_NONE 293#ifdef CONFIG_JFFS2_CMODE_NONE
291 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE; 294 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
@@ -304,6 +307,9 @@ int __init jffs2_compressors_init(void)
304int jffs2_compressors_exit(void) 307int jffs2_compressors_exit(void)
305{ 308{
306/* Unregistering compressors */ 309/* Unregistering compressors */
310#ifdef CONFIG_JFFS2_LZO
311 jffs2_lzo_exit();
312#endif
307#ifdef CONFIG_JFFS2_RUBIN 313#ifdef CONFIG_JFFS2_RUBIN
308 jffs2_dynrubin_exit(); 314 jffs2_dynrubin_exit();
309 jffs2_rubinmips_exit(); 315 jffs2_rubinmips_exit();
diff --git a/fs/jffs2/compr.h b/fs/jffs2/compr.h
index 1070275da58f..a54828a4e9c6 100644
--- a/fs/jffs2/compr.h
+++ b/fs/jffs2/compr.h
@@ -27,9 +27,10 @@
27#define JFFS2_RUBINMIPS_PRIORITY 10 27#define JFFS2_RUBINMIPS_PRIORITY 10
28#define JFFS2_DYNRUBIN_PRIORITY 20 28#define JFFS2_DYNRUBIN_PRIORITY 20
29#define JFFS2_LZARI_PRIORITY 30 29#define JFFS2_LZARI_PRIORITY 30
30#define JFFS2_LZO_PRIORITY 40
31#define JFFS2_RTIME_PRIORITY 50 30#define JFFS2_RTIME_PRIORITY 50
32#define JFFS2_ZLIB_PRIORITY 60 31#define JFFS2_ZLIB_PRIORITY 60
32#define JFFS2_LZO_PRIORITY 80
33
33 34
34#define JFFS2_RUBINMIPS_DISABLED /* RUBINs will be used only */ 35#define JFFS2_RUBINMIPS_DISABLED /* RUBINs will be used only */
35#define JFFS2_DYNRUBIN_DISABLED /* for decompression */ 36#define JFFS2_DYNRUBIN_DISABLED /* for decompression */
diff --git a/fs/jffs2/compr_lzo.c b/fs/jffs2/compr_lzo.c
new file mode 100644
index 000000000000..47b045797e42
--- /dev/null
+++ b/fs/jffs2/compr_lzo.c
@@ -0,0 +1,108 @@
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright © 2007 Nokia Corporation. All rights reserved.
5 *
6 * Created by Richard Purdie <rpurdie@openedhand.com>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/sched.h>
14#include <linux/slab.h>
15#include <linux/vmalloc.h>
16#include <linux/init.h>
17#include <linux/lzo.h>
18#include "compr.h"
19
20static void *lzo_mem;
21static void *lzo_compress_buf;
22static DEFINE_MUTEX(deflate_mutex);
23
24static void free_workspace(void)
25{
26 vfree(lzo_mem);
27 vfree(lzo_compress_buf);
28}
29
30static int __init alloc_workspace(void)
31{
32 lzo_mem = vmalloc(LZO1X_MEM_COMPRESS);
33 lzo_compress_buf = vmalloc(lzo1x_worst_compress(PAGE_SIZE));
34
35 if (!lzo_mem || !lzo_compress_buf) {
36 printk(KERN_WARNING "Failed to allocate lzo deflate workspace\n");
37 free_workspace();
38 return -ENOMEM;
39 }
40
41 return 0;
42}
43
44static int jffs2_lzo_compress(unsigned char *data_in, unsigned char *cpage_out,
45 uint32_t *sourcelen, uint32_t *dstlen, void *model)
46{
47 size_t compress_size;
48 int ret;
49
50 mutex_lock(&deflate_mutex);
51 ret = lzo1x_1_compress(data_in, *sourcelen, lzo_compress_buf, &compress_size, lzo_mem);
52 mutex_unlock(&deflate_mutex);
53
54 if (ret != LZO_E_OK)
55 return -1;
56
57 if (compress_size > *dstlen)
58 return -1;
59
60 memcpy(cpage_out, lzo_compress_buf, compress_size);
61 *dstlen = compress_size;
62
63 return 0;
64}
65
66static int jffs2_lzo_decompress(unsigned char *data_in, unsigned char *cpage_out,
67 uint32_t srclen, uint32_t destlen, void *model)
68{
69 size_t dl = destlen;
70 int ret;
71
72 ret = lzo1x_decompress_safe(data_in, srclen, cpage_out, &dl);
73
74 if (ret != LZO_E_OK || dl != destlen)
75 return -1;
76
77 return 0;
78}
79
80static struct jffs2_compressor jffs2_lzo_comp = {
81 .priority = JFFS2_LZO_PRIORITY,
82 .name = "lzo",
83 .compr = JFFS2_COMPR_LZO,
84 .compress = &jffs2_lzo_compress,
85 .decompress = &jffs2_lzo_decompress,
86 .disabled = 0,
87};
88
89int __init jffs2_lzo_init(void)
90{
91 int ret;
92
93 ret = alloc_workspace();
94 if (ret < 0)
95 return ret;
96
97 ret = jffs2_register_compressor(&jffs2_lzo_comp);
98 if (ret)
99 free_workspace();
100
101 return ret;
102}
103
104void jffs2_lzo_exit(void)
105{
106 jffs2_unregister_compressor(&jffs2_lzo_comp);
107 free_workspace();
108}