xref: /OK3568_Linux_fs/kernel/fs/jffs2/compr.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * JFFS2 -- Journalling Flash File System, Version 2.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright © 2004   Ferenc Havasi <havasi@inf.u-szeged.hu>,
5*4882a593Smuzhiyun  *		      University of Szeged, Hungary
6*4882a593Smuzhiyun  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * For licensing information, see the file 'LICENCE' in this directory.
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  */
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #ifndef __JFFS2_COMPR_H__
13*4882a593Smuzhiyun #define __JFFS2_COMPR_H__
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include <linux/kernel.h>
16*4882a593Smuzhiyun #include <linux/vmalloc.h>
17*4882a593Smuzhiyun #include <linux/list.h>
18*4882a593Smuzhiyun #include <linux/types.h>
19*4882a593Smuzhiyun #include <linux/string.h>
20*4882a593Smuzhiyun #include <linux/slab.h>
21*4882a593Smuzhiyun #include <linux/errno.h>
22*4882a593Smuzhiyun #include <linux/fs.h>
23*4882a593Smuzhiyun #include <linux/jffs2.h>
24*4882a593Smuzhiyun #include "jffs2_fs_i.h"
25*4882a593Smuzhiyun #include "jffs2_fs_sb.h"
26*4882a593Smuzhiyun #include "nodelist.h"
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #define JFFS2_RUBINMIPS_PRIORITY 10
29*4882a593Smuzhiyun #define JFFS2_DYNRUBIN_PRIORITY  20
30*4882a593Smuzhiyun #define JFFS2_LZARI_PRIORITY     30
31*4882a593Smuzhiyun #define JFFS2_RTIME_PRIORITY     50
32*4882a593Smuzhiyun #define JFFS2_ZLIB_PRIORITY      60
33*4882a593Smuzhiyun #define JFFS2_LZO_PRIORITY       80
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun #define JFFS2_RUBINMIPS_DISABLED /* RUBINs will be used only */
37*4882a593Smuzhiyun #define JFFS2_DYNRUBIN_DISABLED  /*	   for decompression */
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #define JFFS2_COMPR_MODE_NONE       0
40*4882a593Smuzhiyun #define JFFS2_COMPR_MODE_PRIORITY   1
41*4882a593Smuzhiyun #define JFFS2_COMPR_MODE_SIZE       2
42*4882a593Smuzhiyun #define JFFS2_COMPR_MODE_FAVOURLZO  3
43*4882a593Smuzhiyun #define JFFS2_COMPR_MODE_FORCELZO   4
44*4882a593Smuzhiyun #define JFFS2_COMPR_MODE_FORCEZLIB  5
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define FAVOUR_LZO_PERCENT 80
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun struct jffs2_compressor {
49*4882a593Smuzhiyun 	struct list_head list;
50*4882a593Smuzhiyun 	int priority;			/* used by prirority comr. mode */
51*4882a593Smuzhiyun 	char *name;
52*4882a593Smuzhiyun 	char compr;			/* JFFS2_COMPR_XXX */
53*4882a593Smuzhiyun 	int (*compress)(unsigned char *data_in, unsigned char *cpage_out,
54*4882a593Smuzhiyun 			uint32_t *srclen, uint32_t *destlen);
55*4882a593Smuzhiyun 	int (*decompress)(unsigned char *cdata_in, unsigned char *data_out,
56*4882a593Smuzhiyun 			  uint32_t cdatalen, uint32_t datalen);
57*4882a593Smuzhiyun 	int usecount;
58*4882a593Smuzhiyun 	int disabled;		/* if set the compressor won't compress */
59*4882a593Smuzhiyun 	unsigned char *compr_buf;	/* used by size compr. mode */
60*4882a593Smuzhiyun 	uint32_t compr_buf_size;	/* used by size compr. mode */
61*4882a593Smuzhiyun 	uint32_t stat_compr_orig_size;
62*4882a593Smuzhiyun 	uint32_t stat_compr_new_size;
63*4882a593Smuzhiyun 	uint32_t stat_compr_blocks;
64*4882a593Smuzhiyun 	uint32_t stat_decompr_blocks;
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun int jffs2_register_compressor(struct jffs2_compressor *comp);
68*4882a593Smuzhiyun int jffs2_unregister_compressor(struct jffs2_compressor *comp);
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun int jffs2_compressors_init(void);
71*4882a593Smuzhiyun int jffs2_compressors_exit(void);
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
74*4882a593Smuzhiyun 			unsigned char *data_in, unsigned char **cpage_out,
75*4882a593Smuzhiyun 			uint32_t *datalen, uint32_t *cdatalen);
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
78*4882a593Smuzhiyun 		     uint16_t comprtype, unsigned char *cdata_in,
79*4882a593Smuzhiyun 		     unsigned char *data_out, uint32_t cdatalen, uint32_t datalen);
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun /* Compressor modules */
84*4882a593Smuzhiyun /* These functions will be called by jffs2_compressors_init/exit */
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun #ifdef CONFIG_JFFS2_RUBIN
87*4882a593Smuzhiyun int jffs2_rubinmips_init(void);
88*4882a593Smuzhiyun void jffs2_rubinmips_exit(void);
89*4882a593Smuzhiyun int jffs2_dynrubin_init(void);
90*4882a593Smuzhiyun void jffs2_dynrubin_exit(void);
91*4882a593Smuzhiyun #endif
92*4882a593Smuzhiyun #ifdef CONFIG_JFFS2_RTIME
93*4882a593Smuzhiyun int jffs2_rtime_init(void);
94*4882a593Smuzhiyun void jffs2_rtime_exit(void);
95*4882a593Smuzhiyun #endif
96*4882a593Smuzhiyun #ifdef CONFIG_JFFS2_ZLIB
97*4882a593Smuzhiyun int jffs2_zlib_init(void);
98*4882a593Smuzhiyun void jffs2_zlib_exit(void);
99*4882a593Smuzhiyun #endif
100*4882a593Smuzhiyun #ifdef CONFIG_JFFS2_LZO
101*4882a593Smuzhiyun int jffs2_lzo_init(void);
102*4882a593Smuzhiyun void jffs2_lzo_exit(void);
103*4882a593Smuzhiyun #endif
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun #endif /* __JFFS2_COMPR_H__ */
106