Skip to content

Commit c799aca

Browse files
Richard Purdiedwmw2
authored andcommitted
[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>
1 parent 8691a72 commit c799aca

6 files changed

Lines changed: 129 additions & 1 deletion

File tree

‎fs/Kconfig‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,17 @@ config JFFS2_ZLIB
13141314

13151315
Say 'Y' if unsure.
13161316

1317+
config 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+
13171328
config JFFS2_RTIME
13181329
bool "JFFS2 RTIME compression support" if JFFS2_COMPRESSION_OPTIONS
13191330
depends on JFFS2_FS

‎fs/jffs2/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ jffs2-$(CONFIG_JFFS2_FS_POSIX_ACL) += acl.o
1717
jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o
1818
jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o
1919
jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o
20+
jffs2-$(CONFIG_JFFS2_LZO) += compr_lzo.o
2021
jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o

‎fs/jffs2/compr.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,9 @@ int __init jffs2_compressors_init(void)
286286
jffs2_rubinmips_init();
287287
jffs2_dynrubin_init();
288288
#endif
289+
#ifdef CONFIG_JFFS2_LZO
290+
jffs2_lzo_init();
291+
#endif
289292
/* Setting default compression mode */
290293
#ifdef CONFIG_JFFS2_CMODE_NONE
291294
jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
@@ -304,6 +307,9 @@ int __init jffs2_compressors_init(void)
304307
int jffs2_compressors_exit(void)
305308
{
306309
/* Unregistering compressors */
310+
#ifdef CONFIG_JFFS2_LZO
311+
jffs2_lzo_exit();
312+
#endif
307313
#ifdef CONFIG_JFFS2_RUBIN
308314
jffs2_dynrubin_exit();
309315
jffs2_rubinmips_exit();

‎fs/jffs2/compr.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
#define JFFS2_RUBINMIPS_PRIORITY 10
2828
#define JFFS2_DYNRUBIN_PRIORITY 20
2929
#define JFFS2_LZARI_PRIORITY 30
30-
#define JFFS2_LZO_PRIORITY 40
3130
#define JFFS2_RTIME_PRIORITY 50
3231
#define JFFS2_ZLIB_PRIORITY 60
32+
#define JFFS2_LZO_PRIORITY 80
33+
3334

3435
#define JFFS2_RUBINMIPS_DISABLED /* RUBINs will be used only */
3536
#define JFFS2_DYNRUBIN_DISABLED /* for decompression */

‎fs/jffs2/compr_lzo.c‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
20+
static void *lzo_mem;
21+
static void *lzo_compress_buf;
22+
static DEFINE_MUTEX(deflate_mutex);
23+
24+
static void free_workspace(void)
25+
{
26+
vfree(lzo_mem);
27+
vfree(lzo_compress_buf);
28+
}
29+
30+
static 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+
44+
static 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+
66+
static 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+
80+
static 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+
89+
int __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+
104+
void jffs2_lzo_exit(void)
105+
{
106+
jffs2_unregister_compressor(&jffs2_lzo_comp);
107+
free_workspace();
108+
}

‎include/linux/jffs2.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define JFFS2_COMPR_COPY 0x04
4747
#define JFFS2_COMPR_DYNRUBIN 0x05
4848
#define JFFS2_COMPR_ZLIB 0x06
49+
#define JFFS2_COMPR_LZO 0x07
4950
/* Compatibility flags. */
5051
#define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */
5152
#define JFFS2_NODE_ACCURATE 0x2000

0 commit comments

Comments
 (0)