Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Richard Purdie and committed by
David Woodhouse
c799aca3 8691a729

+129 -1
+11
fs/Kconfig
··· 1314 1314 1315 1315 Say 'Y' if unsure. 1316 1316 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 + 1317 1328 config JFFS2_RTIME 1318 1329 bool "JFFS2 RTIME compression support" if JFFS2_COMPRESSION_OPTIONS 1319 1330 depends on JFFS2_FS
+1
fs/jffs2/Makefile
··· 17 17 jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o 18 18 jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o 19 19 jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o 20 + jffs2-$(CONFIG_JFFS2_LZO) += compr_lzo.o 20 21 jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o
+6
fs/jffs2/compr.c
··· 286 286 jffs2_rubinmips_init(); 287 287 jffs2_dynrubin_init(); 288 288 #endif 289 + #ifdef CONFIG_JFFS2_LZO 290 + jffs2_lzo_init(); 291 + #endif 289 292 /* Setting default compression mode */ 290 293 #ifdef CONFIG_JFFS2_CMODE_NONE 291 294 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE; ··· 307 304 int jffs2_compressors_exit(void) 308 305 { 309 306 /* Unregistering compressors */ 307 + #ifdef CONFIG_JFFS2_LZO 308 + jffs2_lzo_exit(); 309 + #endif 310 310 #ifdef CONFIG_JFFS2_RUBIN 311 311 jffs2_dynrubin_exit(); 312 312 jffs2_rubinmips_exit();
+2 -1
fs/jffs2/compr.h
··· 27 27 #define JFFS2_RUBINMIPS_PRIORITY 10 28 28 #define JFFS2_DYNRUBIN_PRIORITY 20 29 29 #define JFFS2_LZARI_PRIORITY 30 30 - #define JFFS2_LZO_PRIORITY 40 31 30 #define JFFS2_RTIME_PRIORITY 50 32 31 #define JFFS2_ZLIB_PRIORITY 60 32 + #define JFFS2_LZO_PRIORITY 80 33 + 33 34 34 35 #define JFFS2_RUBINMIPS_DISABLED /* RUBINs will be used only */ 35 36 #define JFFS2_DYNRUBIN_DISABLED /* for decompression */
+108
fs/jffs2/compr_lzo.c
··· 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 + }
+1
include/linux/jffs2.h
··· 46 46 #define JFFS2_COMPR_COPY 0x04 47 47 #define JFFS2_COMPR_DYNRUBIN 0x05 48 48 #define JFFS2_COMPR_ZLIB 0x06 49 + #define JFFS2_COMPR_LZO 0x07 49 50 /* Compatibility flags. */ 50 51 #define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */ 51 52 #define JFFS2_NODE_ACCURATE 0x2000