-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 68484 b: refs/heads/master c: c799aca h: refs/heads/master v: v3
- Loading branch information
Richard Purdie
authored and
David Woodhouse
committed
Jul 11, 2007
1 parent
a78a116
commit 22102b2
Showing
7 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 8691a729a2a3d739ee40a577053157393450aabd | ||
refs/heads/master: c799aca31bfe61ba3a91133acf5a13a0773087d4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* JFFS2 -- Journalling Flash File System, Version 2. | ||
* | ||
* Copyright © 2007 Nokia Corporation. All rights reserved. | ||
* | ||
* Created by Richard Purdie <rpurdie@openedhand.com> | ||
* | ||
* For licensing information, see the file 'LICENCE' in this directory. | ||
* | ||
*/ | ||
|
||
#include <linux/kernel.h> | ||
#include <linux/sched.h> | ||
#include <linux/slab.h> | ||
#include <linux/vmalloc.h> | ||
#include <linux/init.h> | ||
#include <linux/lzo.h> | ||
#include "compr.h" | ||
|
||
static void *lzo_mem; | ||
static void *lzo_compress_buf; | ||
static DEFINE_MUTEX(deflate_mutex); | ||
|
||
static void free_workspace(void) | ||
{ | ||
vfree(lzo_mem); | ||
vfree(lzo_compress_buf); | ||
} | ||
|
||
static int __init alloc_workspace(void) | ||
{ | ||
lzo_mem = vmalloc(LZO1X_MEM_COMPRESS); | ||
lzo_compress_buf = vmalloc(lzo1x_worst_compress(PAGE_SIZE)); | ||
|
||
if (!lzo_mem || !lzo_compress_buf) { | ||
printk(KERN_WARNING "Failed to allocate lzo deflate workspace\n"); | ||
free_workspace(); | ||
return -ENOMEM; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static int jffs2_lzo_compress(unsigned char *data_in, unsigned char *cpage_out, | ||
uint32_t *sourcelen, uint32_t *dstlen, void *model) | ||
{ | ||
size_t compress_size; | ||
int ret; | ||
|
||
mutex_lock(&deflate_mutex); | ||
ret = lzo1x_1_compress(data_in, *sourcelen, lzo_compress_buf, &compress_size, lzo_mem); | ||
mutex_unlock(&deflate_mutex); | ||
|
||
if (ret != LZO_E_OK) | ||
return -1; | ||
|
||
if (compress_size > *dstlen) | ||
return -1; | ||
|
||
memcpy(cpage_out, lzo_compress_buf, compress_size); | ||
*dstlen = compress_size; | ||
|
||
return 0; | ||
} | ||
|
||
static int jffs2_lzo_decompress(unsigned char *data_in, unsigned char *cpage_out, | ||
uint32_t srclen, uint32_t destlen, void *model) | ||
{ | ||
size_t dl = destlen; | ||
int ret; | ||
|
||
ret = lzo1x_decompress_safe(data_in, srclen, cpage_out, &dl); | ||
|
||
if (ret != LZO_E_OK || dl != destlen) | ||
return -1; | ||
|
||
return 0; | ||
} | ||
|
||
static struct jffs2_compressor jffs2_lzo_comp = { | ||
.priority = JFFS2_LZO_PRIORITY, | ||
.name = "lzo", | ||
.compr = JFFS2_COMPR_LZO, | ||
.compress = &jffs2_lzo_compress, | ||
.decompress = &jffs2_lzo_decompress, | ||
.disabled = 0, | ||
}; | ||
|
||
int __init jffs2_lzo_init(void) | ||
{ | ||
int ret; | ||
|
||
ret = alloc_workspace(); | ||
if (ret < 0) | ||
return ret; | ||
|
||
ret = jffs2_register_compressor(&jffs2_lzo_comp); | ||
if (ret) | ||
free_workspace(); | ||
|
||
return ret; | ||
} | ||
|
||
void jffs2_lzo_exit(void) | ||
{ | ||
jffs2_unregister_compressor(&jffs2_lzo_comp); | ||
free_workspace(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters