diff options
| -rw-r--r-- | fs/Kconfig | 11 | ||||
| -rw-r--r-- | fs/jffs2/Makefile | 1 | ||||
| -rw-r--r-- | fs/jffs2/compr.c | 6 | ||||
| -rw-r--r-- | fs/jffs2/compr.h | 3 | ||||
| -rw-r--r-- | fs/jffs2/compr_lzo.c | 108 | ||||
| -rw-r--r-- | include/linux/jffs2.h | 1 |
6 files changed, 129 insertions, 1 deletions
diff --git a/fs/Kconfig b/fs/Kconfig index e19423a2aa..a2ec0b375d 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 | ||
| 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 | config JFFS2_RTIME | 1328 | config 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 c32b241e3d..60e5d49ca0 100644 --- a/fs/jffs2/Makefile +++ b/fs/jffs2/Makefile | |||
| @@ -17,4 +17,5 @@ jffs2-$(CONFIG_JFFS2_FS_POSIX_ACL) += acl.o | |||
| 17 | jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o | 17 | jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o |
| 18 | jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o | 18 | jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o |
| 19 | jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o | 19 | jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o |
| 20 | jffs2-$(CONFIG_JFFS2_LZO) += compr_lzo.o | ||
| 20 | jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o | 21 | jffs2-$(CONFIG_JFFS2_SUMMARY) += summary.o |
diff --git a/fs/jffs2/compr.c b/fs/jffs2/compr.c index d90ca05e49..bcc28d266a 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) | |||
| 304 | int jffs2_compressors_exit(void) | 307 | int 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 1070275da5..a54828a4e9 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 0000000000..47b045797e --- /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 | |||
| 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 | } | ||
diff --git a/include/linux/jffs2.h b/include/linux/jffs2.h index 840631fa5f..6b563cae23 100644 --- a/include/linux/jffs2.h +++ b/include/linux/jffs2.h | |||
| @@ -46,6 +46,7 @@ | |||
| 46 | #define JFFS2_COMPR_COPY 0x04 | 46 | #define JFFS2_COMPR_COPY 0x04 |
| 47 | #define JFFS2_COMPR_DYNRUBIN 0x05 | 47 | #define JFFS2_COMPR_DYNRUBIN 0x05 |
| 48 | #define JFFS2_COMPR_ZLIB 0x06 | 48 | #define JFFS2_COMPR_ZLIB 0x06 |
| 49 | #define JFFS2_COMPR_LZO 0x07 | ||
| 49 | /* Compatibility flags. */ | 50 | /* Compatibility flags. */ |
| 50 | #define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */ | 51 | #define JFFS2_COMPAT_MASK 0xc000 /* What do to if an unknown nodetype is found */ |
| 51 | #define JFFS2_NODE_ACCURATE 0x2000 | 52 | #define JFFS2_NODE_ACCURATE 0x2000 |
