finally move buildroot-ng to trunk
[openwrt/staging/dedeckeh.git] / target / linux / generic-2.4 / patches / 003-jffs2_compression.patch
1 diff -Nur linux-mips-cvs/Documentation/Configure.help linux-mips/Documentation/Configure.help
2 --- linux-mips-cvs/Documentation/Configure.help 2005-01-20 03:19:21.000000000 +0100
3 +++ linux-mips/Documentation/Configure.help 2005-02-07 05:08:35.000000000 +0100
4 @@ -17528,6 +17528,32 @@
5 If reporting bugs, please try to have available a full dump of the
6 messages at debug level 1 while the misbehaviour was occurring.
7
8 +ARMLIB compression support for BBC (EXPERIMENTAL)
9 +CONFIG_JFFS2_BBC_ARMLIB
10 + This enables ARMLIB support for BBC.
11 +
12 +LZO1X-* compression support for BBC (EXPERIMENTAL)
13 +CONFIG_JFFS2_BBC_LZO
14 + This enables LZO1X-1 and LZO1X-999 support for BBC. (fast & good
15 + compressor, beats ZLIB in everything)
16 +
17 +LZARI compression support for BBC (EXPERIMENTAL)
18 +CONFIG_JFFS2_BBC_LZARI
19 + This enables LempelZiv-Storer-Szymanski compression for BBC with
20 + additional arithmetic coding (damn slow, but best compresor).
21 +
22 +LZHD compression support for BBC (EXPERIMENTAL)
23 +CONFIG_JFFS2_BBC_LZHD
24 + This enables LempelZiv-Storer-Szymanski compression for BBC with
25 + additional dynamic Huffman coding (a little faster than LZARI, and
26 + it's compression ratio is a little worse than LZARI's)
27 +
28 +LZSS compression support for BBC (EXPERIMENTAL)
29 +CONFIG_JFFS2_BBC_LZSS
30 + This enables simple LempelZiv-Storer-Szymanski compression for BBC
31 + (faster than LZHD, and, and has a not-so-good compression ratio,
32 + was included just for testing)
33 +
34 JFFS stats available in /proc filesystem
35 CONFIG_JFFS_PROC_FS
36 Enabling this option will cause statistics from mounted JFFS file systems
37 diff -Nur linux-mips-cvs/fs/Config.in linux-mips/fs/Config.in
38 --- linux-mips-cvs/fs/Config.in 2004-11-19 01:28:47.000000000 +0100
39 +++ linux-mips/fs/Config.in 2005-02-07 05:08:34.000000000 +0100
40 @@ -50,6 +50,12 @@
41 if [ "$CONFIG_JFFS2_FS" = "y" -o "$CONFIG_JFFS2_FS" = "m" ] ; then
42 int 'JFFS2 debugging verbosity (0 = quiet, 2 = noisy)' CONFIG_JFFS2_FS_DEBUG 0
43 fi
44 +dep_mbool ' ARMLIB compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_ARMLIB $CONFIG_JFFS2_FS
45 +dep_mbool ' LZO1X-* compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZO $CONFIG_JFFS2_FS
46 +dep_mbool ' LZARI compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZARI $CONFIG_JFFS2_FS
47 +dep_mbool ' LZHD compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZHD $CONFIG_JFFS2_FS
48 +dep_mbool ' LZSS compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZSS $CONFIG_JFFS2_FS
49 +
50 tristate 'Compressed ROM file system support' CONFIG_CRAMFS
51 bool 'Virtual memory file system support (former shm fs)' CONFIG_TMPFS
52 define_bool CONFIG_RAMFS y
53 diff -Nur linux-mips-cvs/fs/jffs2/Config.in.bbc.inc linux-mips/fs/jffs2/Config.in.bbc.inc
54 --- linux-mips-cvs/fs/jffs2/Config.in.bbc.inc 1970-01-01 01:00:00.000000000 +0100
55 +++ linux-mips/fs/jffs2/Config.in.bbc.inc 2005-02-07 05:08:34.000000000 +0100
56 @@ -0,0 +1,5 @@
57 +dep_mbool ' ARMLIB compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_ARMLIB $CONFIG_JFFS2_FS
58 +dep_mbool ' LZO1X-* compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZO $CONFIG_JFFS2_FS
59 +dep_mbool ' LZARI compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZARI $CONFIG_JFFS2_FS
60 +dep_mbool ' LZHD compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZHD $CONFIG_JFFS2_FS
61 +dep_mbool ' LZSS compression support for BBC (EXPERIMENTAL)' CONFIG_JFFS2_BBC_LZSS $CONFIG_JFFS2_FS
62 diff -Nur linux-mips-cvs/fs/jffs2/Configure.help.bbc.inc linux-mips/fs/jffs2/Configure.help.bbc.inc
63 --- linux-mips-cvs/fs/jffs2/Configure.help.bbc.inc 1970-01-01 01:00:00.000000000 +0100
64 +++ linux-mips/fs/jffs2/Configure.help.bbc.inc 2005-02-07 05:08:34.000000000 +0100
65 @@ -0,0 +1,25 @@
66 +ARMLIB compression support for BBC (EXPERIMENTAL)
67 +CONFIG_JFFS2_BBC_ARMLIB
68 + This enables ARMLIB support for BBC.
69 +
70 +LZO1X-* compression support for BBC (EXPERIMENTAL)
71 +CONFIG_JFFS2_BBC_LZO
72 + This enables LZO1X-1 and LZO1X-999 support for BBC. (fast & good
73 + compressor, beats ZLIB in everything)
74 +
75 +LZARI compression support for BBC (EXPERIMENTAL)
76 +CONFIG_JFFS2_BBC_LZARI
77 + This enables LempelZiv-Storer-Szymanski compression for BBC with
78 + additional arithmetic coding (damn slow, but best compresor).
79 +
80 +LZHD compression support for BBC (EXPERIMENTAL)
81 +CONFIG_JFFS2_BBC_LZHD
82 + This enables LempelZiv-Storer-Szymanski compression for BBC with
83 + additional dynamic Huffman coding (a little faster than LZARI, and
84 + it's compression ratio is a little worse than LZARI's)
85 +
86 +LZSS compression support for BBC (EXPERIMENTAL)
87 +CONFIG_JFFS2_BBC_LZSS
88 + This enables simple LempelZiv-Storer-Szymanski compression for BBC
89 + (faster than LZHD, and, and has a not-so-good compression ratio,
90 + was included just for testing)
91 diff -Nur linux-mips-cvs/fs/jffs2/Kconfig.bbc.inc linux-mips/fs/jffs2/Kconfig.bbc.inc
92 --- linux-mips-cvs/fs/jffs2/Kconfig.bbc.inc 1970-01-01 01:00:00.000000000 +0100
93 +++ linux-mips/fs/jffs2/Kconfig.bbc.inc 2005-02-07 05:08:34.000000000 +0100
94 @@ -0,0 +1,40 @@
95 +config JFFS2_BBC_ARMLIB
96 + bool "ARMLIB compression support for BBC (EXPERIMENTAL)"
97 + depends on JFFS2_FS && EXPERIMENTAL
98 + default y
99 + help
100 + This enables ARMLIB support for BBC.
101 +
102 +config JFFS2_BBC_LZO
103 + bool "LZO1X-* compression support for BBC (EXPERIMENTAL)"
104 + depends on JFFS2_FS && EXPERIMENTAL
105 + default y
106 + help
107 + This enables LZO1X-1 and LZO1X-999 support for BBC. (fast & good
108 + compressor)
109 +
110 +config JFFS2_BBC_LZARI
111 + bool "LZARI compression support for BBC (EXPERIMENTAL)"
112 + depends on JFFS2_FS && EXPERIMENTAL
113 + default y
114 + help
115 + This enables LempelZiv-Storer-Szymanski compression for BBC with
116 + additional arithmetic coding (damn slow, but best compresor).
117 +
118 +config JFFS2_BBC_LZHD
119 + bool "LZHD compression support for BBC (EXPERIMENTAL)"
120 + depends on JFFS2_FS && EXPERIMENTAL
121 + default y
122 + help
123 + This enables LempelZiv-Storer-Szymanski compression for BBC with
124 + additional dynamic Huffman coding (a little faster than LZARI, and
125 + it's compression ratio is a little worse than LZARI's)
126 +
127 +config JFFS2_BBC_LZSS
128 + bool "LZSS compression support for BBC (EXPERIMENTAL)"
129 + depends on JFFS2_FS && EXPERIMENTAL
130 + default y
131 + help
132 + This enables simple LempelZiv-Storer-Szymanski compression for BBC
133 + (faster than LZHD, and, and has a not-so-good compression ratio,
134 + was included just for testing)
135 diff -Nur linux-mips-cvs/fs/jffs2/Makefile linux-mips/fs/jffs2/Makefile
136 --- linux-mips-cvs/fs/jffs2/Makefile 2003-08-13 19:19:25.000000000 +0200
137 +++ linux-mips/fs/jffs2/Makefile 2005-02-07 05:08:34.000000000 +0100
138 @@ -10,9 +10,23 @@
139 # Note 2! The CFLAGS definitions are now in the main makefile...
140
141
142 +JFFS2_BBC_KERNEL_OBJS-y = jffs2_bbc_framework.o jffs2_bbc_fs.o
143 +
144 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_ARMLIB) += jffs2_bbc_armlib_comp.o
145 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZO) += jffs2_bbc_lzo_comp.o
146 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZSS) += jffs2_bbc_lzss_comp.o
147 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZARI) += jffs2_bbc_lzari_comp.o
148 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZHD) += jffs2_bbc_lzhd_comp.o
149 +
150 +JFFS2_BBC_KERNEL_OBJS := $(JFFS2_BBC_KERNEL_OBJS-y)
151 +
152 +JFFS2_BBC_MKFS_OBJS = jffs2_bbc_mkfs.o jffs2_bbc_framework.o jffs2_bbc_armlib_comp.o jffs2_bbc_lzo_comp.o\
153 + jffs2_bbc_lzss_comp.o jffs2_bbc_lzari_comp.o jffs2_bbc_lzhd_comp.o
154 +
155 COMPR_OBJS := compr.o compr_rubin.o compr_rtime.o pushpull.o \
156 compr_zlib.o
157 JFFS2_OBJS := dir.o file.o ioctl.o nodelist.o malloc.o \
158 + $(JFFS2_BBC_KERNEL_OBJS) \
159 read.o nodemgmt.o readinode.o super.o write.o scan.o gc.o \
160 symlink.o build.o erase.o background.o
161
162 diff -Nur linux-mips-cvs/fs/jffs2/Makefile.bbc.inc linux-mips/fs/jffs2/Makefile.bbc.inc
163 --- linux-mips-cvs/fs/jffs2/Makefile.bbc.inc 1970-01-01 01:00:00.000000000 +0100
164 +++ linux-mips/fs/jffs2/Makefile.bbc.inc 2005-02-07 05:08:34.000000000 +0100
165 @@ -0,0 +1,12 @@
166 +JFFS2_BBC_KERNEL_OBJS-y = jffs2_bbc_framework.o jffs2_bbc_fs.o
167 +
168 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_ARMLIB) += jffs2_bbc_armlib_comp.o
169 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZO) += jffs2_bbc_lzo_comp.o
170 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZSS) += jffs2_bbc_lzss_comp.o
171 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZARI) += jffs2_bbc_lzari_comp.o
172 +JFFS2_BBC_KERNEL_OBJS-$(CONFIG_JFFS2_BBC_LZHD) += jffs2_bbc_lzhd_comp.o
173 +
174 +JFFS2_BBC_KERNEL_OBJS := $(JFFS2_BBC_KERNEL_OBJS-y)
175 +
176 +JFFS2_BBC_MKFS_OBJS = jffs2_bbc_mkfs.o jffs2_bbc_framework.o jffs2_bbc_armlib_comp.o jffs2_bbc_lzo_comp.o\
177 + jffs2_bbc_lzss_comp.o jffs2_bbc_lzari_comp.o jffs2_bbc_lzhd_comp.o
178 diff -Nur linux-mips-cvs/fs/jffs2/compr_zlib.c linux-mips/fs/jffs2/compr_zlib.c
179 --- linux-mips-cvs/fs/jffs2/compr_zlib.c 2003-01-11 18:53:17.000000000 +0100
180 +++ linux-mips/fs/jffs2/compr_zlib.c 2005-02-07 05:08:35.000000000 +0100
181 @@ -85,7 +85,7 @@
182 vfree(inflate_workspace);
183 }
184
185 -int zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
186 +int jffs2_zlib_compress2(unsigned char *data_in, unsigned char *cpage_out,
187 __u32 *sourcelen, __u32 *dstlen)
188 {
189 z_stream strm;
190 @@ -145,7 +145,7 @@
191 return 0;
192 }
193
194 -void zlib_decompress(unsigned char *data_in, unsigned char *cpage_out,
195 +void jffs2_zlib_decompress2(unsigned char *data_in, unsigned char *cpage_out,
196 __u32 srclen, __u32 destlen)
197 {
198 z_stream strm;
199 @@ -175,3 +175,19 @@
200 zlib_inflateEnd(&strm);
201 up(&inflate_sem);
202 }
203 +
204 +extern int jffs2_zlib_compress(unsigned char *data_in, unsigned char *cpage_out, __u32 * sourcelen, __u32 * dstlen);
205 +extern void jffs2_zlib_decompress(unsigned char *data_in, unsigned char *cpage_out, __u32 srclen, __u32 destlen);
206 +
207 +int zlib_compress(unsigned char *data_in, unsigned char *cpage_out,
208 + __u32 *sourcelen, __u32 *dstlen)
209 +{
210 + return jffs2_zlib_compress(data_in,cpage_out,sourcelen,dstlen);
211 +}
212 +
213 +void zlib_decompress(unsigned char *data_in, unsigned char *cpage_out,
214 + __u32 srclen, __u32 destlen)
215 +{
216 + jffs2_zlib_decompress(data_in,cpage_out,srclen,destlen);
217 +}
218 +
219 diff -Nur linux-mips-cvs/fs/jffs2/file.c linux-mips/fs/jffs2/file.c
220 --- linux-mips-cvs/fs/jffs2/file.c 2003-11-17 02:07:44.000000000 +0100
221 +++ linux-mips/fs/jffs2/file.c 2005-02-07 05:08:35.000000000 +0100
222 @@ -35,6 +35,7 @@
223 *
224 */
225
226 +#include "jffs2_bbc_framework.h" /**BBC**/
227 #include <linux/kernel.h>
228 #include <linux/mtd/compatmac.h> /* for min() */
229 #include <linux/slab.h>
230 @@ -459,6 +460,7 @@
231
232 comprbuf = kmalloc(cdatalen, GFP_KERNEL);
233 if (comprbuf) {
234 + jffs2_bbc_model_set_act_sb(c); /**BBC**/
235 comprtype = jffs2_compress(page_address(pg)+ (file_ofs & (PAGE_CACHE_SIZE-1)), comprbuf, &datalen, &cdatalen);
236 }
237 if (comprtype == JFFS2_COMPR_NONE) {
238 diff -Nur linux-mips-cvs/fs/jffs2/gc.c linux-mips/fs/jffs2/gc.c
239 --- linux-mips-cvs/fs/jffs2/gc.c 2003-11-17 02:07:44.000000000 +0100
240 +++ linux-mips/fs/jffs2/gc.c 2005-02-07 05:08:35.000000000 +0100
241 @@ -35,6 +35,7 @@
242 *
243 */
244
245 +#include "jffs2_bbc_framework.h" /**BBC**/
246 #include <linux/kernel.h>
247 #include <linux/mtd/mtd.h>
248 #include <linux/slab.h>
249 @@ -651,6 +652,7 @@
250 writebuf = pg_ptr + (offset & (PAGE_CACHE_SIZE -1));
251
252 if (comprbuf) {
253 + jffs2_bbc_model_set_act_sb(c); /**BBC**/
254 comprtype = jffs2_compress(writebuf, comprbuf, &datalen, &cdatalen);
255 }
256 if (comprtype) {
257 diff -Nur linux-mips-cvs/fs/jffs2/hpatch linux-mips/fs/jffs2/hpatch
258 --- linux-mips-cvs/fs/jffs2/hpatch 1970-01-01 01:00:00.000000000 +0100
259 +++ linux-mips/fs/jffs2/hpatch 2005-02-07 05:08:34.000000000 +0100
260 @@ -0,0 +1,191 @@
261 +#!/usr/bin/perl
262 +# A patch-like utility
263 +# Designed for patching different version of jffs2 with the same hpatch file
264 +#
265 +# Copyright (C) 2004, Ferenc Havasi
266 +#
267 +# This program is free software; you can redistribute it and/or
268 +# modify it under the terms of the GNU General Public License
269 +# as published by the Free Software Foundation; either version 2
270 +# of the License, or (at your option) any later version.
271 +#
272 +# This program is distributed in the hope that it will be useful,
273 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
274 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
275 +# GNU General Public License for more details.
276 +#
277 +# You should have received a copy of the GNU General Public License
278 +# along with this program; if not, write to the Free Software
279 +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
280 +
281 +$filename_tmp1="file1.tmp";
282 +$filename_tmp2="file2.tmp";
283 +
284 +$filename_in="";
285 +$filename_out=$filename_tmp1;
286 +$filename_cnt=0;
287 +
288 +# Modes:
289 +# 0: expecting =
290 +# 1: normal_cmd
291 +# 2: skip until =
292 +# 3: expecting F (first state)
293 +$mode=3;
294 +
295 +%rules = ();
296 +
297 +sub file_end {
298 + if (($mode!=2)&&($modified==1)) {
299 + while (<SRC>) {
300 + print DST $_;
301 + }
302 + close(SRC);
303 + close(DST);
304 + if ($cmd_name ne "") { $rules{"$cmd_name"}=1; }
305 + $filename_result=$filename_out;
306 + if ($filename_result ne $filename_in_save) {
307 + open(RES,"<$filename_result") or die "Cannot open $filename_result.\n";
308 + open(DST,">$filename_in_save") or die "Cannot open $filename_in_save.\n";
309 + while (<RES>) {
310 + print DST $_;
311 + }
312 + close(DST);
313 + close(RES);
314 + }
315 + unlink($filename_tmp1) && unlink($filename_tmp2);
316 + }
317 + else {
318 + close(SRC);
319 + close(DST);
320 + $filename_result=$filename_in;
321 + if ($filename_result ne $filename_in_save) {
322 + open(RES,"<$filename_result") or die "Cannot open $filename_result.\n";
323 + open(DST,">$filename_in_save") or die "Cannot open $filename_in_save.\n";
324 + while (<RES>) {
325 + print DST $_;
326 + }
327 + close(DST);
328 + close(RES);
329 + }
330 + unlink($filename_tmp1);
331 + }
332 + $modified=0;
333 + foreach $rulename (keys %rules) {
334 + if ($rules{"$rulename"}==0) { print(STDERR "On $filename_in_save error applying rule $rulename.\n"); }
335 + }
336 + %rules = ();
337 +}
338 +
339 +if ($#ARGV<0) {
340 + print ("usage: hpatch hpatch_file\n");
341 + exit;
342 +}
343 +
344 +open(CMD,"<$ARGV[0]") or die "Cannot open $ARGV[0].\n";
345 +$cmd_linenum=0;
346 +
347 +while (chomp($cmd_line=<CMD>)) {
348 + $cmd_linenum++;
349 + if ($cmd_line eq "") {next;}
350 + #$cmd_line =~ s/\#.*//;
351 + $cmd_line =~ s/\ *$//;
352 + if ($cmd_line eq "") {next;}
353 + if ($cmd_line =~ /^F(.*)/) {
354 + $tmp_filename_in=$1;
355 + if ($mode!=3) {
356 + file_end();
357 + }
358 + $filename_in=$tmp_filename_in;
359 + $filename_in_save=$filename_in;
360 + open(SRC,"<$filename_in") or die "Cannot open $filename_in.\n";
361 + open(DST,">$filename_out") or die "Cannot open $filename_out.\n";;
362 + $modified=0;
363 + $mode=0;
364 + next;
365 + }
366 + if ($mode==3) {die "error: F expression expected in line $cmd_linenum\n";}
367 + if ($cmd_line =~ /^=(.*)/) {
368 + $tmp_cmd_name=$1;
369 + if (($mode!=2)&&($modified==1)) {
370 + while (<SRC>) {
371 + print DST $_;
372 + }
373 + close(SRC);
374 + close(DST);
375 + if (($cmd_name ne "")) {$rules{"$cmd_name"}=1;};
376 + $filename_cnt++;
377 + if ($filename_cnt%2==1) {
378 + $filename_in=$filename_tmp1;
379 + $filename_out=$filename_tmp2;
380 + }
381 + else {
382 + $filename_in=$filename_tmp2;
383 + $filename_out=$filename_tmp1;
384 + }
385 + }
386 + else {
387 + close(SRC);
388 + close(DST);
389 + }
390 + $mode=1;
391 + $cmd_name=$tmp_cmd_name;
392 + if (($cmd_name ne "")) {
393 + if ($rules{"$cmd_name"}==1) {
394 + $mode=2;
395 + }
396 + else {
397 + $rules{"$cmd_name"}=0;
398 + }
399 + }
400 + open(SRC,"<$filename_in") or die "Cannot open $filename_in.\n";
401 + open(DST,">$filename_out") or die "Cannot open $filename_out.\n";
402 + $modified=0;
403 + next;
404 + }
405 + if ($mode == 0) {die "error: = expression expected in line $cmd_linenum\n";}
406 + if ($mode == 2) {next;}
407 + if ($cmd_line =~ /^!(.*)/) {
408 + print "$1\n";
409 + $modified=1;
410 + next;
411 + }
412 + if ($cmd_line =~ /^\?(.*)/) {
413 + $search_str=$1;
414 + $found=0;
415 + while (<SRC>) {
416 + print DST $_;
417 + if (index($_,$search_str)>=0) {$found=1; last;}
418 + }
419 + if ($found==0) { $mode=2; }
420 + next;
421 + }
422 + if ($cmd_line =~ /^\+(.*)/) {
423 + print DST "$1\n";
424 + $modified=1;
425 + next;
426 + }
427 + if ($cmd_line =~ /^\-(.*)/) {
428 + $search_str=$1;
429 + $found=0;
430 + while (<SRC>) {
431 + if (index($_,$search_str)>=0) {$saved_line=$_; $found=1; $modified=1; last;}
432 + print DST $_;
433 + }
434 + if ($found==0) { $mode=2; }
435 + next;
436 + }
437 + if ($cmd_line =~ /^i(.*)/) {
438 + $filename_inc=$1;
439 + open(INCSRC,"<$filename_inc") or die "Cannot open $filename_inc.\n";
440 + while (<INCSRC>) {
441 + print DST $_;
442 + }
443 + next;
444 + }
445 + if ($cmd_line =~ /^I/) {
446 + print DST $saved_line;
447 + next;
448 + }
449 +}
450 +file_end();
451 +close(CMD);
452 diff -Nur linux-mips-cvs/fs/jffs2/jffs2_bbc_armlib_comp.c linux-mips/fs/jffs2/jffs2_bbc_armlib_comp.c
453 --- linux-mips-cvs/fs/jffs2/jffs2_bbc_armlib_comp.c 1970-01-01 01:00:00.000000000 +0100
454 +++ linux-mips/fs/jffs2/jffs2_bbc_armlib_comp.c 2005-02-07 05:08:34.000000000 +0100
455 @@ -0,0 +1,2224 @@
456 +/*
457 + * JFFS2-BBC: armlib compressor plugin
458 + *
459 + * $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
460 + *
461 + * Copyright (C) 2004, Ferenc Havasi & Tamas Gergely
462 + *
463 + * This program is free software; you can redistribute it and/or
464 + * modify it under the terms of the GNU General Public License
465 + * as published by the Free Software Foundation; either version 2
466 + * of the License, or (at your option) any later version.
467 + *
468 + * This program is distributed in the hope that it will be useful,
469 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
470 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
471 + * GNU General Public License for more details.
472 + *
473 + * You should have received a copy of the GNU General Public License
474 + * along with this program; if not, write to the Free Software
475 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
476 + *
477 + */
478 +
479 +#include "jffs2_bbc_framework.h"
480 +
481 +#ifdef __KERNEL__
482 +#include <linux/string.h>
483 +#else
484 +#include <string.h>
485 +#endif
486 +
487 +//ORIGIN: include/DataStructures/TypeDefs.h
488 +
489 +/*******************************************************************************
490 +* FILE: TypeDefs.h
491 +* AUTHOR: Tamás Gergely
492 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
493 +*******************************************************************************/
494 +
495 +#ifndef TYPEDEFS_H
496 +#define TYPEDEFS_H
497 +
498 +#pragma pack(4)
499 +
500 +#ifndef bool
501 +#define bool char
502 +#define true 1
503 +#define false 0
504 +#endif
505 +
506 +#ifndef u8
507 +#define u8 unsigned char
508 +#endif
509 +#ifndef u16
510 +#define u16 unsigned short
511 +#endif
512 +#ifndef u32
513 +#define u32 unsigned long
514 +#endif
515 +#ifndef s8
516 +#define s8 signed char
517 +#endif
518 +#ifndef s16
519 +#define s16 signed short
520 +#endif
521 +#ifndef s32
522 +#define s32 signed long
523 +#endif
524 +
525 +typedef struct
526 +{
527 + u32 capacity;
528 + u32 size;
529 + u32 alloc_size;
530 + void *ptr;
531 +} vector;
532 +
533 +#define VECTOR_P_END(vct) ((void*)(((char*)((vct)->ptr)) + (vct)->size))
534 +#define VECTOR_S_END(vct) ((void*)(((char*)((vct).ptr)) + (vct).size))
535 +
536 +static void vector_clear(vector *);
537 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
538 +static void vector_reset(vector *);
539 +static void vector_clr_ptr(vector *);
540 +static void vector_add_u8(vector *, u8);
541 +static void vector_add_u16(vector *, u16);
542 +static void vector_add_u32(vector *, u32);
543 +static void vector_add_s8(vector *, s8);
544 +static void vector_add_s16(vector *, s16);
545 +static void vector_add_s32(vector *, s32);
546 +static void vector_add_ptr(vector *, void *);
547 +static void vector_concat(vector *, vector *);
548 +#endif
549 +
550 +#endif
551 +
552 +//ORIGIN: include/DataStructures/DataTypes.h
553 +
554 +/*******************************************************************************
555 +* FILE: DataTypes.h
556 +* AUTHOR: Tamás Gergely
557 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
558 +*******************************************************************************/
559 +
560 +#ifndef DATATYPES_H
561 +#define DATATYPES_H
562 +
563 +//#include "DataStructures/TypeDefs.h"
564 +
565 +typedef u16 THUMB_DataType;
566 +typedef u32 ARM_DataType;
567 +typedef u8 TokenType;
568 +typedef u8 PredictorType;
569 +typedef u8 *ProbDist;
570 +
571 +typedef vector RawData;
572 +typedef vector RawBlocks;
573 +typedef vector TokenStream;
574 +typedef vector TokenBlocks;
575 +typedef vector LatType;
576 +
577 +#define THUMB_DATA_LENGTH 16
578 +#define ARM_DATA_LENGTH 32
579 +#define TOKEN_LENGTH 8
580 +#define TOKEN_MAXVALUE 0xff
581 +#define PREDICTOR_LENGTH 8
582 +#define PREDICTOR_MAXVALUE 0xff
583 +
584 +#endif
585 +
586 +//ORIGIN: include/DataStructures/BitVector.h
587 +
588 +/*******************************************************************************
589 +* FILE: BitVector.h
590 +* AUTHOR: Tamás Gergely
591 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
592 +*******************************************************************************/
593 +
594 +#ifndef BITVECTOR_H
595 +#define BITVECTOR_H
596 +
597 +//#include "DataStructures/TypeDefs.h"
598 +
599 +typedef vector BitBlocks;
600 +
601 +#pragma pack(4)
602 +
603 +typedef struct
604 +{
605 + u32 freebits;
606 + u32 capacity;
607 + u32 size;
608 + u8 *base;
609 + u8 *ptr;
610 +} BitVector;
611 +
612 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
613 +static void bitblocks_clear(BitBlocks *);
614 +static void bitvector_clear(BitVector *);
615 +static void bitvector_W_reset(BitVector *);
616 +static void bitvector_W_add0(BitVector *);
617 +static void bitvector_W_add1(BitVector *);
618 +static void bitvector_W_concat_b(BitVector *, BitVector *);
619 +static void bitvector_W_concat_v(BitVector *, vector *);
620 +static void bitvector_W_flush(BitVector *);
621 +static void bitvector_R_reset(BitVector *);
622 +static u8 bitvector_R_get1(BitVector *);
623 +static u8 bitvector_R_get8(BitVector *);
624 +#endif
625 +
626 +#define BITVECTOR_P_END(bv) ((void*)(((bv)->base)+((bv)->size)))
627 +#define BITVECTOR_S_END(bv) ((void*)( ((bv).base)+ ((bv).size)))
628 +#define BITVECTOR_SKIP(bv,num) ((bv)->ptr) += (num)
629 +
630 +#endif
631 +
632 +//ORIGIN: include/DataStructures/DecisionTree.h
633 +
634 +/*******************************************************************************
635 +* FILE: DecisionTree.h
636 +* AUTHOR: Tamás Gergely
637 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
638 +*******************************************************************************/
639 +
640 +#ifndef DECISIONTREE_H
641 +#define DECISIONTREE_H
642 +
643 +//#include "DataStructures/DataTypes.h"
644 +
645 +#pragma pack(4)
646 +
647 +#define TREENODETYPE_NULLNODE 0
648 +#define TREENODETYPE_NODE_BINARY_EQ 1
649 +#define TREENODETYPE_LEAF_P 2
650 +#define TREENODETYPE_LEAF_C 3
651 +#define TREENODETYPE_NODE_BINARY_LT 5
652 +#define TREENODETYPE_IS_NODE(n) (((n) == TREENODETYPE_NODE_BINARY_EQ) || \
653 + ((n) == TREENODETYPE_NODE_BINARY_LT))
654 +#define TREENODETYPE_IS_NODE_BINARY(n) (((n) == TREENODETYPE_NODE_BINARY_EQ) || \
655 + ((n) == TREENODETYPE_NODE_BINARY_LT))
656 +
657 +#define TREENODETYPE_IS_LEAF(n) (((n) == TREENODETYPE_LEAF_P) || \
658 + ((n) == TREENODETYPE_LEAF_C))
659 +
660 +
661 +#define TREE_SUBTREE_RELATION_LEFT_EQ !=
662 +#define TREE_SUBTREE_RELATION_RIGHT_EQ ==
663 +#define TREE_SUBTREE_RELATION_LEFT_LT <
664 +#define TREE_SUBTREE_RELATION_RIGHT_LT >=
665 +
666 +#define GET_NODE_PTR_TYPE(n) (((TreeNodeDummy*)(n))->type)
667 +
668 +typedef struct
669 +{
670 + u8 type;
671 +} TreeNodeDummy;
672 +
673 +typedef struct
674 +{
675 + u8 type; // [TREENODETYPE_NODE_BINARY]
676 + u8 attribute;
677 + PredictorType value;
678 + void *left;
679 + void *right;
680 +} TreeNodeBinary;
681 +
682 +typedef struct
683 +{
684 + u8 type; // [TREENODETYPE_LEAF_P]
685 + u16 pairs;
686 + PredictorType *probabilities;
687 +} TreeLeafP;
688 +
689 +typedef struct
690 +{
691 + u8 type; // [TREENODETYPE_LEAF_C]
692 + PredictorType predicted_class;
693 +} TreeLeafC;
694 +
695 +typedef struct
696 +{
697 + u32 high;
698 + u32 low;
699 + u32 max;
700 +} ProbabilityType;
701 +
702 +
703 +typedef struct
704 +{
705 + void *root;
706 + u16 number_of_classes;
707 + u16 number_of_predictors;
708 + PredictorType *predictor_max_values;
709 +} DecisionTree;
710 +
711 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
712 +static void decisiontree_delete(DecisionTree *);
713 +static void decisiontree_get_probability_for_token(void *, PredictorType *, TokenType, ProbabilityType *);
714 +static TokenType decisiontree_get_token_for_range(void *, PredictorType *, u32, u32, ProbabilityType *);
715 +#endif
716 +
717 +#endif
718 +
719 +//ORIGIN: include/DataStructures/PredictorTable.h
720 +
721 +/*******************************************************************************
722 +* FILE: PredictorTable.h
723 +* AUTHOR: Tamás Gergely
724 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
725 +*******************************************************************************/
726 +
727 +#ifndef PREDICTORTABLE_H
728 +#define PREDICTORTABLE_H
729 +
730 +//#include "DataStructures/TypeDefs.h"
731 +//#include "DataStructures/DataTypes.h"
732 +////#include "DataStructures/Filter.h"
733 +////#include "DataStructures/Converter.h"
734 +////#include "DataStructures/Manipulator.h"
735 +
736 +#define NUMBER_OF_PREDICTORS_ARM 17
737 +
738 +#ifndef __KERNEL__
739 +#define NUMBER_OF_PREDICTORS_TXT 2
740 +#else
741 +#undef TXT_TOKENS
742 +#endif // __KERNEL__
743 +
744 +#ifdef TXT_TOKENS
745 +#define NUMBER_OF_PREDICTORS NUMBER_OF_PREDICTORS_TXT
746 +#define predictortable_reset predictortable_resetTXT
747 +#define predictortable_update predictortable_updateTXT
748 +#define predictortable_minvalue predictortable_minvalueTXT
749 +#define predictortable_maxvalue predictortable_maxvalueTXT
750 +#else
751 +#define NUMBER_OF_PREDICTORS NUMBER_OF_PREDICTORS_ARM
752 +#define predictortable_reset predictortable_resetARM
753 +#define predictortable_update predictortable_updateARM
754 +#define predictortable_minvalue predictortable_minvalueARM
755 +#define predictortable_maxvalue predictortable_maxvalueARM
756 +#endif
757 +
758 +
759 +#pragma pack(4)
760 +
761 +typedef struct
762 +{
763 + PredictorType *predictors;
764 +} PredictorTable;
765 +
766 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
767 +static void predictortable_clear(PredictorTable *);
768 +static void predictortable_free(PredictorTable *);
769 +static void predictortable_resetARM(PredictorTable *);
770 +static void predictortable_updateARM(PredictorTable *, TokenType);
771 +static PredictorType predictortable_minvalueARM(PredictorTable *, u32);
772 +static PredictorType predictortable_maxvalueARM(PredictorTable *, u32);
773 +#endif
774 +
775 +#ifndef __KERNEL__
776 +/*
777 +static void predictortable_resetTXT(PredictorTable *);
778 +static void predictortable_updateTXT(PredictorTable *, TokenType);
779 +static PredictorType predictortable_minvalueTXT(PredictorTable *, u32);
780 +static PredictorType predictortable_maxvalueTXT(PredictorTable *, u32);
781 +*/
782 +#endif // __KERNEL__
783 +
784 +#endif
785 +
786 +//ORIGIN: include/DataStructures/ipack_model.h
787 +
788 +/*******************************************************************************
789 +* FILE: ipack_model.h
790 +* AUTHOR: Tamás Gergely
791 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
792 +*******************************************************************************/
793 +
794 +#ifndef IPACK_MODEL_H
795 +#define IPACK_MODEL_H
796 +
797 +//#include "DataStructures/DataTypes.h"
798 +//#include "DataStructures/DecisionTree.h"
799 +//#include "DataStructures/PredictorTable.h"
800 +
801 +#define PROBABILITY_SHIFT 12
802 +#define PROBABILITY_MAX 0x00001000l
803 +
804 +#define NUMBER_OF_TOKENS_ARM 16
805 +#define NUMBER_OF_TOKENS_PER_INSTRUCTION_ARM 8
806 +
807 +#ifndef __KERNEL__
808 +#define NUMBER_OF_TOKENS_TXT 256
809 +#define NUMBER_OF_TOKENS_PER_INSTRUCTION_TXT 4
810 +#else
811 +#undef TXT_TOKENS
812 +#endif // __KERNEL__
813 +
814 +#ifdef TXT_TOKENS
815 +#define NUMBER_OF_TOKENS NUMBER_OF_TOKENS_TXT
816 +#define NUMBER_OF_TOKENS_PER_INSTRUCTION NUMBER_OF_TOKENS_PER_INSTRUCTION_TXT
817 +#else
818 +#define NUMBER_OF_TOKENS NUMBER_OF_TOKENS_ARM
819 +#define NUMBER_OF_TOKENS_PER_INSTRUCTION NUMBER_OF_TOKENS_PER_INSTRUCTION_ARM
820 +#endif
821 +
822 +#pragma pack(4)
823 +
824 +/*
825 + Data structure of an internal node of the tree
826 +*/
827 +typedef struct
828 +{
829 + PredictorType *attribute_ptr;
830 + u32 value; // PredictorType
831 + void *right_child_ptr;
832 +} ipack_treenodeBin;
833 +/*
834 + Data structure of a leaf with probabilities
835 +*/
836 +typedef struct
837 +{
838 + u16 probabilities[0]; // PredictorType[0]
839 +} ipack_treeleafP;
840 +/*
841 + Data structure of a leaf with class prediction
842 +*/
843 +typedef struct
844 +{
845 + PredictorType predicted_class; // PredictorType
846 +} ipack_treeleafC;
847 +/*
848 + Possible data structures of a tree node
849 +*/
850 +typedef union
851 +{
852 + ipack_treenodeBin nodeBin;
853 + ipack_treeleafP leafP;
854 + ipack_treeleafC leafC;
855 +} ipack_node_data;
856 +/*
857 + Tree node
858 +*/
859 +typedef struct
860 +{
861 + u32 type; // u8
862 + ipack_node_data data; // ipack_node_data
863 +} ipack_nodetype;
864 +/*
865 + Nullnode
866 +*/
867 +typedef struct
868 +{
869 + u32 type;
870 + u16 probabilities[NUMBER_OF_TOKENS];
871 +} ipack_nullnode;
872 +/*
873 + Model for ipack project
874 +*/
875 +typedef struct
876 +{
877 + char ID[4]; // char[4]
878 + char block_sign[4]; // only the first 2 are used!
879 + void *tree_root_ptr; // void*
880 + void *tree_code; // generated ARM code
881 + PredictorType *predictors_ptr; // PredictorType*
882 + ipack_nullnode nullnode;
883 +} ipack_model_type;
884 +
885 +typedef struct
886 +{
887 + u32 high;
888 + u32 low;
889 +} ipack_probability_type;
890 +
891 +
892 +static void ipack_model_get_probability_for_token(ipack_nodetype *, TokenType, ipack_probability_type *);
893 +static TokenType ipack_model_get_token_for_range(ipack_nodetype *, u32, u32, ipack_probability_type *);
894 +/*void ipack_model_predictortable_reset (PredictorType*);
895 +void ipack_model_predictortable_update (PredictorType*, TokenType);*/
896 +
897 +#ifndef __KERNEL__
898 +/*static void ipack_model_printinfo(ipack_model_type *);
899 +static void ipack_dumpmodel(void *);*/
900 +#endif
901 +
902 +#endif
903 +
904 +//ORIGIN: include/Builders/PredictorGenerator.h
905 +
906 +/*******************************************************************************
907 +* FILE: PredictorGenerator.h
908 +* AUTHOR: Tamás Gergely
909 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
910 +*******************************************************************************/
911 +
912 +#ifndef PREDICTORGENERATOR_H
913 +#define PREDICTORGENERATOR_H
914 +
915 +//#include "DataStructures.h"
916 +
917 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
918 +static PredictorTable *predictorgenerator_generate(void);
919 +#endif
920 +
921 +#endif
922 +
923 +//ORIGIN: include/Builders/Coder.h
924 +
925 +/*******************************************************************************
926 +* FILE: Coder.h
927 +* AUTHOR: Tamás Gergely
928 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
929 +*******************************************************************************/
930 +
931 +#ifndef CODER_H
932 +#define CODER_H
933 +
934 +#define CODER_VALUEBITS 16
935 +#define CODER_VALUEMAX 0x00010000l
936 +#define CODER_VALUE3RD 0x0000c000l
937 +#define CODER_VALUEHLF 0x00008000l
938 +#define CODER_VALUE1ST 0x00004000l
939 +
940 +#endif
941 +
942 +//ORIGIN: DataStructures/src/TypeDefs.c
943 +
944 +/*******************************************************************************
945 +* FILE: TypeDefs.c
946 +* AUTHOR: Tamás Gergely
947 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
948 +*******************************************************************************/
949 +
950 +//#include "ipack_common.h"
951 +//#include "DataStructures/TypeDefs.h"
952 +#ifndef __KERNEL__
953 +#include <memory.h>
954 +#endif
955 +
956 +#define VECTOR_ALLOC_SIZE 0x00001000
957 +
958 +static void vector_clear(vector * vct)
959 +{
960 + if (vct->ptr)
961 + jffs2_bbc_free(vct->ptr);
962 + vct->capacity = 0;
963 + vct->size = 0;
964 + vct->ptr = 0;
965 +}
966 +
967 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
968 +static void vector_extend(vector * vct)
969 +{
970 + void *tmp;
971 + vct->capacity += vct->alloc_size;
972 + tmp = jffs2_bbc_malloc(vct->capacity);
973 + if (vct->ptr) {
974 + memcpy(tmp, vct->ptr, vct->size);
975 + jffs2_bbc_free(vct->ptr);
976 + }
977 + vct->ptr = tmp;
978 +}
979 +
980 +static void vector_reset(vector * vct)
981 +{
982 + vct->capacity = 0;
983 + vct->size = 0;
984 + vct->alloc_size = VECTOR_ALLOC_SIZE;
985 + vct->ptr = 0;
986 +}
987 +
988 +static void vector_clr_ptr(vector * vct)
989 +{
990 + void **it;
991 + void *end_it;
992 + for (it = vct->ptr, end_it = (((char *) (vct->ptr)) + vct->size); it != end_it; it++) {
993 + vector_clear(*it);
994 + jffs2_bbc_free(*it);
995 + }
996 + if (vct->ptr)
997 + jffs2_bbc_free(vct->ptr);
998 + vct->capacity = 0;
999 + vct->size = 0;
1000 + vct->ptr = 0;
1001 +}
1002 +
1003 +static void vector_add_u8(vector * vct, u8 val)
1004 +{
1005 + if ((vct->size) + sizeof(u8) > (vct->capacity)) {
1006 + vector_extend(vct);
1007 + }
1008 + *(u8 *) ((char *) (vct->ptr) + (vct->size)) = val;
1009 + vct->size += sizeof(u8);
1010 +};
1011 +
1012 +static void vector_add_u16(vector * vct, u16 val)
1013 +{
1014 + if ((vct->size) + sizeof(u16) > (vct->capacity)) {
1015 + vector_extend(vct);
1016 + }
1017 + *(u16 *) ((char *) (vct->ptr) + (vct->size)) = val;
1018 + vct->size += sizeof(u16);
1019 +};
1020 +
1021 +static void vector_add_u32(vector * vct, u32 val)
1022 +{
1023 + if ((vct->size) + sizeof(u32) > (vct->capacity)) {
1024 + vector_extend(vct);
1025 + }
1026 + *(u32 *) ((char *) (vct->ptr) + (vct->size)) = val;
1027 + vct->size += sizeof(u32);
1028 +};
1029 +
1030 +static void vector_add_s8(vector * vct, s8 val)
1031 +{
1032 + if ((vct->size) + sizeof(s8) > (vct->capacity)) {
1033 + vector_extend(vct);
1034 + }
1035 + *(s8 *) ((char *) (vct->ptr) + (vct->size)) = val;
1036 + vct->size += sizeof(s8);
1037 +};
1038 +
1039 +static void vector_add_s16(vector * vct, s16 val)
1040 +{
1041 + if ((vct->size) + sizeof(s16) > (vct->capacity)) {
1042 + vector_extend(vct);
1043 + }
1044 + *(s16 *) ((char *) (vct->ptr) + (vct->size)) = val;
1045 + vct->size += sizeof(s16);
1046 +};
1047 +
1048 +static void vector_add_s32(vector * vct, s32 val)
1049 +{
1050 + if ((vct->size) + sizeof(s32) > (vct->capacity)) {
1051 + vector_extend(vct);
1052 + }
1053 + *(s32 *) ((char *) (vct->ptr) + (vct->size)) = val;
1054 + vct->size += sizeof(s32);
1055 +};
1056 +
1057 +static void vector_add_ptr(vector * vct, void *ptr)
1058 +{
1059 + if ((vct->size) + sizeof(void *) > (vct->capacity)) {
1060 + vector_extend(vct);
1061 + }
1062 + *(void **) ((char *) (vct->ptr) + (vct->size)) = ptr;
1063 + vct->size += sizeof(void *);
1064 +}
1065 +
1066 +static void vector_concat(vector * lhs, vector * rhs)
1067 +{
1068 + void *tmp;
1069 + if (!(rhs->size)) {
1070 + return;
1071 + }
1072 + tmp = lhs->ptr;
1073 + lhs->capacity = (lhs->size) + (rhs->size);
1074 + lhs->ptr = jffs2_bbc_malloc(lhs->capacity);
1075 + if (tmp) {
1076 + memcpy(lhs->ptr, tmp, lhs->size);
1077 + jffs2_bbc_free(tmp);
1078 + }
1079 + memcpy((((u8 *) lhs->ptr) + lhs->size), rhs->ptr, rhs->size);
1080 + lhs->size += rhs->size;
1081 +}
1082 +
1083 +#endif
1084 +
1085 +//ORIGIN: DataStructures/src/BitVector.c
1086 +
1087 +/*******************************************************************************
1088 +* FILE: BitVector.c
1089 +* AUTHOR: Tamás Gergely
1090 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
1091 +*******************************************************************************/
1092 +
1093 +//#include "ipack_common.h"
1094 +//#include "DataStructures/BitVector.h"
1095 +#ifndef __KERNEL__
1096 +#include <memory.h>
1097 +#endif
1098 +
1099 +#define VECTOR_ALLOC_SIZE 0x00001000
1100 +
1101 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
1102 +
1103 +static void bitblocks_clear(BitBlocks * this)
1104 +{
1105 + BitVector **it;
1106 + void *end_it;
1107 + for (it = this->ptr, end_it = VECTOR_P_END(this); it != end_it; it++) {
1108 + bitvector_clear(*it);
1109 + jffs2_bbc_free(*it);
1110 + }
1111 + jffs2_bbc_free(this->ptr);
1112 + this->ptr = 0;
1113 +}
1114 +
1115 +static void bitvector_clear(BitVector * this)
1116 +{
1117 + if (this->base) {
1118 + jffs2_bbc_free(this->base);
1119 + }
1120 + this->freebits = 0;
1121 + this->capacity = 0;
1122 + this->size = 0;
1123 + this->base = 0;
1124 + this->ptr = 0;
1125 +}
1126 +
1127 +static void bitvector_W_reset(BitVector * this)
1128 +{
1129 + this->freebits = 0;
1130 + this->capacity = 0;
1131 + this->size = 0;
1132 + this->base = 0;
1133 + this->ptr = 0;
1134 +}
1135 +
1136 +static void bitvector_W_add0(BitVector * this)
1137 +{
1138 + if (!(this->freebits)) {
1139 + if (this->size == this->capacity) {
1140 + void *tmp = this->base;
1141 + this->capacity += VECTOR_ALLOC_SIZE;
1142 + this->base = jffs2_bbc_malloc(this->capacity);
1143 + this->ptr = ((u8 *) (this->base)) + this->size;
1144 + memcpy(this->base, tmp, this->size);
1145 + jffs2_bbc_free(tmp);
1146 + }
1147 + else {
1148 + this->ptr++;
1149 + }
1150 + this->size++;
1151 + this->freebits = 7;
1152 + *(this->ptr) = 0x00;
1153 + }
1154 + else {
1155 + this->freebits--;
1156 + (*(this->ptr)) <<= 1;
1157 + }
1158 +}
1159 +
1160 +static void bitvector_W_add1(BitVector * this)
1161 +{
1162 + if (!(this->freebits)) {
1163 + if (this->size == this->capacity) {
1164 + void *tmp = this->base;
1165 + this->capacity += VECTOR_ALLOC_SIZE;
1166 + this->base = jffs2_bbc_malloc(this->capacity);
1167 + this->ptr = ((u8 *) (this->base)) + this->size;
1168 + memcpy(this->base, tmp, this->size);
1169 + jffs2_bbc_free(tmp);
1170 + }
1171 + else {
1172 + this->ptr++;
1173 + }
1174 + this->size++;
1175 + this->freebits = 7;
1176 + *(this->ptr) = 0x01;
1177 + }
1178 + else {
1179 + this->freebits--;
1180 + (*(this->ptr)) <<= 1;
1181 + (*(this->ptr)) |= 0x01;
1182 + }
1183 +}
1184 +
1185 +static void bitvector_W_concat_b(BitVector * lhs, BitVector * rhs)
1186 +{
1187 + void *tmp;
1188 + if (!(rhs->size)) {
1189 + return;
1190 + }
1191 + tmp = lhs->base;
1192 + lhs->capacity = ((((lhs->size) + (rhs->size) - 1) / VECTOR_ALLOC_SIZE) + 1) * VECTOR_ALLOC_SIZE;
1193 + lhs->base = jffs2_bbc_malloc(lhs->capacity);
1194 + if (tmp) {
1195 + memcpy(lhs->base, tmp, lhs->size);
1196 + jffs2_bbc_free(tmp);
1197 + }
1198 + memcpy((((u8 *) (lhs->base)) + lhs->size), rhs->base, rhs->size);
1199 + lhs->freebits = 0;
1200 + lhs->size += rhs->size;
1201 + lhs->ptr = ((u8 *) (lhs->base)) + lhs->size;
1202 +}
1203 +
1204 +static void bitvector_W_concat_v(BitVector * lhs, vector * rhs)
1205 +{
1206 + void *tmp;
1207 + if (!(rhs->size)) {
1208 + return;
1209 + }
1210 + tmp = lhs->base;
1211 + lhs->capacity = ((((lhs->size) + (rhs->size) - 1) / VECTOR_ALLOC_SIZE) + 1) * VECTOR_ALLOC_SIZE;
1212 + lhs->base = jffs2_bbc_malloc(lhs->capacity);
1213 + if (tmp) {
1214 + memcpy(lhs->base, tmp, lhs->size);
1215 + jffs2_bbc_free(tmp);
1216 + }
1217 + memcpy((((u8 *) (lhs->base)) + lhs->size), rhs->ptr, rhs->size);
1218 + lhs->freebits = 0;
1219 + lhs->size += rhs->size;
1220 + lhs->ptr = ((u8 *) (lhs->base)) + lhs->size;
1221 +}
1222 +
1223 +static void bitvector_W_flush(BitVector * this)
1224 +{
1225 + (*(this->ptr)) <<= this->freebits;
1226 + this->freebits = 0;
1227 +}
1228 +
1229 +static void bitvector_R_reset(BitVector * this)
1230 +{
1231 + this->freebits = 7;
1232 + this->ptr = this->base;
1233 +}
1234 +
1235 +static u8 bitvector_R_get1(BitVector * this)
1236 +{
1237 + u8 tmp = ((*(this->ptr)) >> this->freebits) & 0x01;
1238 + if (!(this->freebits)) {
1239 + this->freebits = 7;
1240 + this->ptr++;
1241 + }
1242 + else {
1243 + this->freebits--;
1244 + }
1245 + return tmp;
1246 +}
1247 +
1248 +static u8 bitvector_R_get8(BitVector * this)
1249 +{
1250 + u8 tmp = (*(this->ptr));
1251 + this->ptr++;
1252 + return tmp;
1253 +}
1254 +
1255 +#endif
1256 +
1257 +//ORIGIN: DataStructures/src/DecisionTree.c
1258 +
1259 +/*******************************************************************************
1260 +* FILE: DecisionTree.c
1261 +* AUTHOR: Tamás Gergely
1262 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
1263 +*******************************************************************************/
1264 +
1265 +//#include "ipack_common.h"
1266 +//#include "DataStructures/DecisionTree.h"
1267 +
1268 +static void decisiontree_delete_node(void *root)
1269 +{
1270 + u8 tmp = GET_NODE_PTR_TYPE(root);
1271 + if (TREENODETYPE_IS_NODE_BINARY(tmp)) {
1272 + decisiontree_delete_node(((TreeNodeBinary *) root)->left);
1273 + decisiontree_delete_node(((TreeNodeBinary *) root)->right);
1274 + }
1275 + else if ((tmp) == TREENODETYPE_LEAF_P) {
1276 + if (((TreeLeafP *) root)->probabilities) {
1277 + jffs2_bbc_free(((TreeLeafP *) root)->probabilities);
1278 + }
1279 + }
1280 + else if ((tmp) == TREENODETYPE_LEAF_C) {
1281 + }
1282 + jffs2_bbc_free(root);
1283 +}
1284 +
1285 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
1286 +
1287 +static void decisiontree_delete(DecisionTree * dt)
1288 +{
1289 + decisiontree_delete_node(dt->root);
1290 + jffs2_bbc_free(dt->predictor_max_values);
1291 +}
1292 +
1293 +static void decisiontree_get_probability_for_token(void *root, PredictorType * preds, TokenType token, ProbabilityType * prob)
1294 +{
1295 + void *tmp = root;
1296 + while (TREENODETYPE_IS_NODE(((TreeNodeBinary *) tmp)->type)) {
1297 + if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_NODE_BINARY_EQ) {
1298 + if (preds[((TreeNodeBinary *) tmp)->attribute] TREE_SUBTREE_RELATION_LEFT_EQ((TreeNodeBinary *) tmp)->value) {
1299 + tmp = ((TreeNodeBinary *) tmp)->left;
1300 + }
1301 + else {
1302 + tmp = ((TreeNodeBinary *) tmp)->right;
1303 + }
1304 + }
1305 + else if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_NODE_BINARY_LT) {
1306 + if (preds[((TreeNodeBinary *) tmp)->attribute] TREE_SUBTREE_RELATION_LEFT_LT((TreeNodeBinary *) tmp)->value) {
1307 + tmp = ((TreeNodeBinary *) tmp)->left;
1308 + }
1309 + else {
1310 + tmp = ((TreeNodeBinary *) tmp)->right;
1311 + }
1312 + }
1313 + }
1314 + prob->high = 0;
1315 + prob->low = 0;
1316 + prob->max = 0;
1317 + if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_LEAF_P) {
1318 + u32 i;
1319 + u32 lngth = ((TreeLeafP *) tmp)->pairs << 1;
1320 + for (i = 0; i < lngth;) {
1321 + TokenType at = ((TreeLeafP *) tmp)->probabilities[i++];
1322 + TokenType av = ((TreeLeafP *) tmp)->probabilities[i++];
1323 + if (token > at)
1324 + prob->low += av;
1325 + if (token >= at)
1326 + prob->high += av;
1327 + prob->max += av;
1328 + }
1329 + }
1330 + else if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_LEAF_C) {
1331 + if (((TreeLeafC *) tmp)->predicted_class == token) {
1332 + prob->high = TOKEN_MAXVALUE;
1333 + prob->max = TOKEN_MAXVALUE;
1334 + }
1335 + }
1336 +}
1337 +
1338 +static TokenType decisiontree_get_token_for_range(void *root, PredictorType * preds, u32 value, u32 range, ProbabilityType * prob)
1339 +{
1340 + void *tmp = root;
1341 + TokenType token = 0;
1342 + while (TREENODETYPE_IS_NODE(((TreeNodeBinary *) tmp)->type)) {
1343 + if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_NODE_BINARY_EQ) {
1344 + if (preds[((TreeNodeBinary *) tmp)->attribute] TREE_SUBTREE_RELATION_LEFT_EQ((TreeNodeBinary *) tmp)->value) {
1345 + tmp = ((TreeNodeBinary *) tmp)->left;
1346 + }
1347 + else {
1348 + tmp = ((TreeNodeBinary *) tmp)->right;
1349 + }
1350 + }
1351 + else if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_NODE_BINARY_LT) {
1352 + if (preds[((TreeNodeBinary *) tmp)->attribute] TREE_SUBTREE_RELATION_LEFT_LT((TreeNodeBinary *) tmp)->value) {
1353 + tmp = ((TreeNodeBinary *) tmp)->left;
1354 + }
1355 + else {
1356 + tmp = ((TreeNodeBinary *) tmp)->right;
1357 + }
1358 + }
1359 + }
1360 + prob->high = 0;
1361 + prob->low = 0;
1362 + prob->max = 0;
1363 + if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_LEAF_P) {
1364 + u32 i;
1365 + u32 norm;
1366 + TokenType at = 0;
1367 + TokenType av;
1368 + u32 lngth = ((TreeLeafP *) tmp)->pairs << 1;
1369 + for (i = 0; i < lngth;) {
1370 + i++;
1371 + prob->max += ((TreeLeafP *) tmp)->probabilities[i++];
1372 + }
1373 + norm = (value * prob->max - 1) / range;
1374 + for (i = 0; prob->high <= norm;) {
1375 + at = ((TreeLeafP *) tmp)->probabilities[i++];
1376 + av = ((TreeLeafP *) tmp)->probabilities[i++];
1377 + prob->high += av;
1378 + if (prob->high <= norm)
1379 + prob->low += av;
1380 + }
1381 + token = at;
1382 + }
1383 + else if (((TreeNodeBinary *) tmp)->type == TREENODETYPE_LEAF_C) {
1384 + token = ((TreeLeafC *) tmp)->predicted_class;
1385 + prob->high = TOKEN_MAXVALUE;
1386 + prob->max = TOKEN_MAXVALUE;
1387 + }
1388 + return token;
1389 +}
1390 +#endif
1391 +
1392 +//ORIGIN: DataStructures/src/PredictorTable.c
1393 +
1394 +/*******************************************************************************
1395 +* FILE: PredictorTable.c
1396 +* AUTHOR: Tamás Gergely
1397 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
1398 +*******************************************************************************/
1399 +
1400 +//#include "ipack_common.h"
1401 +//#include "DataStructures/PredictorTable.h"
1402 +
1403 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
1404 +
1405 +static void predictortable_clear(PredictorTable * table)
1406 +{
1407 + table->predictors = 0;
1408 +}
1409 +
1410 +static void predictortable_free(PredictorTable * table)
1411 +{
1412 + if (table->predictors) {
1413 + jffs2_bbc_free(table->predictors);
1414 + table->predictors = 0;
1415 + }
1416 +}
1417 +
1418 +static void predictortable_resetARM(PredictorTable * table)
1419 +{
1420 + register PredictorType *ptr = table->predictors;
1421 + register PredictorType *end = ptr + NUMBER_OF_PREDICTORS_ARM;
1422 + while (ptr < end) {
1423 + *(ptr++) = 0;
1424 + }
1425 +}
1426 +
1427 +static void predictortable_updateARM(PredictorTable * table, TokenType token)
1428 +{
1429 + register PredictorType *ptr = table->predictors;
1430 + register u32 ndx = ptr[0] + 1;
1431 + ptr[ndx + 8] = ptr[ndx];
1432 + ptr[ndx] = token;
1433 + if (ndx == 8) {
1434 + ptr[0] = 0;
1435 + }
1436 + else {
1437 + ++ptr[0];
1438 + }
1439 +}
1440 +
1441 +static PredictorType predictortable_minvalueARM(PredictorTable * table, u32 index)
1442 +{
1443 + return 0;
1444 +}
1445 +
1446 +static PredictorType predictortable_maxvalueARM(PredictorTable * table, u32 index)
1447 +{
1448 + if (index == 0) {
1449 + return 7;
1450 + }
1451 + else {
1452 + return 15;
1453 + }
1454 +}
1455 +
1456 +#endif
1457 +
1458 +#ifndef __KERNEL__
1459 +
1460 +/*static void predictortable_resetTXT(PredictorTable * table)
1461 +{
1462 + register PredictorType *ptr = table->predictors;
1463 + register PredictorType *end = ptr + NUMBER_OF_PREDICTORS_TXT;
1464 + while (ptr < end) {
1465 + *(ptr++) = 0;
1466 + }
1467 +}
1468 +
1469 +static void predictortable_updateTXT(PredictorTable * table, TokenType token)
1470 +{ //TODO: modify
1471 + register PredictorType *ptr = table->predictors;
1472 +// register u32 ndx;
1473 + ptr[0] = token;
1474 + if ((('a' <= token) && (token <= 'z')) || (('A' <= token) && (token <= 'Z'))) {
1475 + ++(ptr[1]);
1476 + }
1477 + else {
1478 + ptr[1] = 0;
1479 + }
1480 +}
1481 +
1482 +static PredictorType predictortable_minvalueTXT(PredictorTable * table, u32 index)
1483 +{
1484 + return 0;
1485 +}
1486 +
1487 +static PredictorType predictortable_maxvalueTXT(PredictorTable * table, u32 index)
1488 +{ //TODO: modify
1489 + return 254;
1490 +}*/
1491 +
1492 +#endif // __KERNEL__
1493 +
1494 +//ORIGIN: DataStructures/src/ipack_model.c
1495 +
1496 +/*******************************************************************************
1497 +* FILE: ipack_model.c
1498 +* AUTHOR: Tamás Gergely
1499 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
1500 +*******************************************************************************/
1501 +
1502 +//#include "DataStructures/ipack_model.h"
1503 +//#include "measuredef.h"
1504 +//#include "ipack_common.h"
1505 +
1506 +#ifdef __MEASURE_TIME_MODEL_GETPROB
1507 +#define __MT_P_MAX 256
1508 +#define __MT_P_DIV 128
1509 +#define __MT_P_MIN 0
1510 +#endif
1511 +
1512 +static void ipack_model_get_probability_for_token(ipack_nodetype * tmp, TokenType token, ipack_probability_type * prob)
1513 +{
1514 +// register ipack_nodetype* tmp = model->tree_root_ptr;
1515 +// register ipack_nodetype* tmp = root;
1516 + while (TREENODETYPE_IS_NODE(tmp->type)) {
1517 + if (tmp->type == TREENODETYPE_NODE_BINARY_EQ) {
1518 + if (*(tmp->data.nodeBin.attribute_ptr) TREE_SUBTREE_RELATION_LEFT_EQ tmp->data.nodeBin.value) {
1519 + ((char *) tmp) += sizeof(tmp->type) + sizeof(ipack_treenodeBin);
1520 + }
1521 + else {
1522 + tmp = tmp->data.nodeBin.right_child_ptr;
1523 + }
1524 + }
1525 + else if (tmp->type == TREENODETYPE_NODE_BINARY_LT) {
1526 + if (*(tmp->data.nodeBin.attribute_ptr) TREE_SUBTREE_RELATION_LEFT_LT tmp->data.nodeBin.value) {
1527 + ((char *) tmp) += sizeof(tmp->type) + sizeof(ipack_treenodeBin);
1528 + }
1529 + else {
1530 + tmp = tmp->data.nodeBin.right_child_ptr;
1531 + }
1532 + }
1533 + }
1534 + prob->high = 0;
1535 + prob->low = 0;
1536 +// prob->max = 0;
1537 + if (tmp->type == TREENODETYPE_LEAF_P) {
1538 + if (token) {
1539 + prob->low = tmp->data.leafP.probabilities[token - 1];
1540 + }
1541 + prob->high = tmp->data.leafP.probabilities[token];
1542 +// prob->max = tmp->data.leafP.probabilities[15];
1543 + }
1544 + else if (tmp->type == TREENODETYPE_LEAF_C) {
1545 + if (tmp->data.leafC.predicted_class == token) {
1546 + prob->high = TOKEN_MAXVALUE;
1547 +// prob->max = TOKEN_MAXVALUE;
1548 + }
1549 + }
1550 +}
1551 +
1552 +#ifndef IPACK_ARM_ASM
1553 +
1554 +//return ipack_model_get_token_for_range2(tmp,value,range,prob);
1555 +
1556 +static TokenType ipack_model_get_token_for_range(ipack_nodetype * tmp, u32 value, u32 range, ipack_probability_type * prob)
1557 +{
1558 +// register ipack_nodetype* tmp = model->tree_root_ptr;
1559 +// register ipack_nodetype* tmp = root;
1560 + register TokenType token = 0;
1561 + while (TREENODETYPE_IS_NODE(tmp->type)) {
1562 + if (tmp->type == TREENODETYPE_NODE_BINARY_EQ) {
1563 + if (*(tmp->data.nodeBin.attribute_ptr) TREE_SUBTREE_RELATION_LEFT_EQ tmp->data.nodeBin.value) {
1564 + ((char *) tmp) += sizeof(tmp->type) + sizeof(ipack_treenodeBin);
1565 + }
1566 + else {
1567 + tmp = tmp->data.nodeBin.right_child_ptr;
1568 + }
1569 + }
1570 + else if (tmp->type == TREENODETYPE_NODE_BINARY_LT) {
1571 + if (*(tmp->data.nodeBin.attribute_ptr) TREE_SUBTREE_RELATION_LEFT_LT tmp->data.nodeBin.value) {
1572 + ((char *) tmp) += sizeof(tmp->type) + sizeof(ipack_treenodeBin);
1573 + }
1574 + else {
1575 + tmp = tmp->data.nodeBin.right_child_ptr;
1576 + }
1577 + }
1578 + }
1579 + prob->high = 0;
1580 + prob->low = 0;
1581 +// prob->max = 0;
1582 + if (tmp->type == TREENODETYPE_LEAF_P) {
1583 + u32 i;
1584 + u32 norm;
1585 +// prob->max = tmp->data.leafP.probabilities[15];
1586 +/* norm = (value * prob->max -1)/range;
1587 + for(i = 0; i < 15; ++i) {
1588 + if(tmp->data.leafP.probabilities[i] > norm) {
1589 + break;
1590 + }
1591 + }*/
1592 + norm = ((value << PROBABILITY_SHIFT) - 1);
1593 + for (i = 0; i < NUMBER_OF_TOKENS; ++i) {
1594 + if (range * tmp->data.leafP.probabilities[i] > norm) {
1595 + break;
1596 + }
1597 + }
1598 + token = (TokenType) i;
1599 + prob->high = tmp->data.leafP.probabilities[i];
1600 + if (token) {
1601 + prob->low = tmp->data.leafP.probabilities[token - 1];
1602 + }
1603 + }
1604 + else if (tmp->type == TREENODETYPE_LEAF_C) {
1605 + token = tmp->data.leafC.predicted_class;
1606 + prob->high = PROBABILITY_MAX;
1607 +// prob->max = PROBABILITY_MAX;
1608 + }
1609 + return token;
1610 +}
1611 +#endif
1612 +/*
1613 +void ipack_model_predictortable_reset(PredictorType* ptr)
1614 +{
1615 +// register PredictorType* ptr = model->predictors_ptr;
1616 +// register PredictorType* ptr = preds;
1617 + register PredictorType* end = ptr + NUMBER_OF_PREDICTORS;
1618 + while(ptr < end) {
1619 + *(ptr++) = 0;
1620 + }
1621 +}
1622 +
1623 +void ipack_model_predictortable_update(PredictorType* ptr, TokenType token)
1624 +{
1625 +// register PredictorType* ptr = model->predictors_ptr;
1626 +// register PredictorType* ptr = preds;
1627 + register u32 ndx = ptr[0] + 1;
1628 + ptr[ndx + 8] = ptr[ndx];
1629 + ptr[ndx] = token;
1630 + if(ndx == 8) {
1631 + ptr[0] = 0;
1632 + } else {
1633 + ++ ptr[0];
1634 + }
1635 +}*/
1636 +/****************************************************************************/
1637 +
1638 +#ifndef __KERNEL__
1639 +static void ipack_model_countpreds(void *ptr, ipack_nodetype * node, double *table, double val)
1640 +{
1641 + if ((node->type == TREENODETYPE_NODE_BINARY_EQ) || (node->type == TREENODETYPE_NODE_BINARY_LT)) {
1642 + table[(u32) (node->data.nodeBin.attribute_ptr) - (u32) (ptr)] += val;
1643 + ipack_model_countpreds(ptr, (void *) (((u8 *) (node)) + sizeof(node->type) + sizeof(ipack_treenodeBin)), table, val / 2);
1644 + ipack_model_countpreds(ptr, node->data.nodeBin.right_child_ptr, table, val / 2);
1645 + }
1646 + else {
1647 + }
1648 +}
1649 +
1650 +/*static void ipack_model_printinfo(ipack_model_type * model)
1651 +{
1652 + double *prcnt = jffs2_bbc_malloc(sizeof(double) * NUMBER_OF_PREDICTORS);
1653 + u32 i;
1654 + for (i = 0; i < NUMBER_OF_PREDICTORS; i++) {
1655 + prcnt[i] = 0.0;
1656 + }
1657 + ipack_model_countpreds(model->predictors_ptr, model->tree_root_ptr, prcnt, 100);
1658 + for (i = 0; i < NUMBER_OF_PREDICTORS; i++) {
1659 + jffs2_bbc_print3(" p[%3d] = %10.6lf\n", (int) i, prcnt[i]);
1660 + }
1661 + jffs2_bbc_free(prcnt);
1662 +}*/
1663 +
1664 +static void ipack_dumpnode(unsigned char **ptr, FILE * file, char *prefs)
1665 +{
1666 + switch (*((*ptr)++)) {
1667 + u32 i;
1668 + u32 j;
1669 + u32 x;
1670 + u32 y;
1671 + case TREENODETYPE_NODE_BINARY_EQ:
1672 + x = *((*ptr)++);
1673 + y = *((*ptr)++);
1674 + fprintf(file, "%s+->\tBinary node: P[%u] equals %u\n", prefs, (unsigned int)x, (unsigned int)y);
1675 + for (j = 0; j < 4096 && prefs[j]; ++j);
1676 + prefs[j] = '\t';
1677 + prefs[++j] = '|';
1678 + ipack_dumpnode(ptr, file, prefs);
1679 + prefs[j--] = 0;
1680 + ipack_dumpnode(ptr, file, prefs);
1681 + prefs[j] = 0;
1682 + break;
1683 + case TREENODETYPE_NODE_BINARY_LT:
1684 + x = *((*ptr)++);
1685 + y = *((*ptr)++);
1686 + fprintf(file, "%s+->\tBinary node: P[%u] greater than %u\n", prefs, (unsigned int)x, (unsigned int)y);
1687 + for (j = 0; j < 4096 && prefs[j]; ++j);
1688 + prefs[j] = '\t';
1689 + prefs[++j] = '|';
1690 + ipack_dumpnode(ptr, file, prefs);
1691 + prefs[j--] = 0;
1692 + ipack_dumpnode(ptr, file, prefs);
1693 + prefs[j] = 0;
1694 + break;
1695 + case TREENODETYPE_LEAF_P:
1696 + x = *((*ptr)++);
1697 + fprintf(file, "%s+->\tLeaf: %u pairs\n", prefs, (unsigned int)x);
1698 + (*ptr) += (x << 1);
1699 + break;
1700 + case TREENODETYPE_LEAF_C:
1701 + x = *((*ptr)++);
1702 + fprintf(file, "%s+->\tLeaf: class %u\n", prefs, (unsigned int)x);
1703 + break;
1704 + default:
1705 + fprintf(file, "%s+->\tLeaf: nullnode\n", prefs);
1706 + }
1707 +}
1708 +
1709 +/*static void ipack_dumpmodel(void *model)
1710 +{
1711 + unsigned char *tmp_ptr = model;
1712 + FILE *file;
1713 + char C[4096];
1714 + if ((file = fopen("DUMPED_MODEL", "wa"))) {
1715 + int i;
1716 + for (i = 0; i < 4096; C[i++] = 0);
1717 + tmp_ptr += 8;
1718 + tmp_ptr += sizeof(u32);
1719 + ipack_dumpnode(&tmp_ptr, file, C);
1720 + fclose(file);
1721 + }
1722 +}*/
1723 +
1724 +#endif
1725 +
1726 +//ORIGIN: Builders/src/PredictorGenerator.c
1727 +
1728 +/*******************************************************************************
1729 +* FILE: PredictorGenerator.c
1730 +* AUTHOR: Tamás Gergely
1731 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
1732 +*******************************************************************************/
1733 +
1734 +//#include "ipack_common.h"
1735 +//#include "Builders/PredictorGenerator.h"
1736 +
1737 +#ifdef JFFS2_BBC_ARMLIB_MODELGEN
1738 +static PredictorTable *predictorgenerator_generate( /*PredictorGeneratorSettings* settings */ )
1739 +{
1740 + PredictorTable *ptr = jffs2_bbc_malloc(sizeof(PredictorTable));
1741 + predictortable_clear(ptr);
1742 + ptr->predictors = jffs2_bbc_malloc(NUMBER_OF_PREDICTORS * sizeof(PredictorType));
1743 + return ptr;
1744 +}
1745 +#endif
1746 +
1747 +//ORIGIN: Builders/src/ipack_armlib_compressor.c
1748 +
1749 +/*******************************************************************************
1750 +* FILE: ipack_armlim_compressor.c
1751 +* AUTHOR: Tamás Gergely
1752 +* MODIFIED: $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
1753 +*******************************************************************************/
1754 +
1755 +//#include "ipack_common.h"
1756 +//#include "DataStructures.h"
1757 +//#include "Builders/PredictorGenerator.h"
1758 +//#include "Builders/Tokenizer.h"
1759 +//#include "Builders/Coder.h"
1760 +
1761 +#define EC_NO_ERROR 0
1762 +#define EC_NOT_IPMF_FILE -1
1763 +#define EC_NOT_IPMF_MODEL -2
1764 +#define EC_NOT_HG_BLOCK -3
1765 +#define EC_WRONG_INPUT_LENGTH -501
1766 +#define EC_CODER_WRONG_PROBABILITY 1
1767 +#define EC_CODER_WRONG_RANGE 2
1768 +#define EC_BUFFER_OVERFLOW 501
1769 +#define EC_BUFFER_UNDERFLOW 502
1770 +#define EC_UNKNOWN_TOKEN_TYPE 1001
1771 +#define EC_UNKNOWN_FILTER 1002
1772 +#define EC_UNKNOWN_CONVERTER 1003
1773 +#define EC_UNKNOWN_MANIPULATOR 1004
1774 +
1775 +/*******************************************************************************
1776 +
1777 + COMPRESSOR INIT FUNCTIONS
1778 +
1779 +*******************************************************************************/
1780 +
1781 +#define ROUND_UP_TO_DWORD(val) ( ( (val) + 3 ) & 0xfffffffc )
1782 +
1783 +#ifndef __KERNEL__
1784 +int ipack_glb_endian_X;
1785 +#endif
1786 +
1787 +static int ipack_compressor_init_tree(unsigned char **ptr, ipack_model_type * model, ipack_nodetype * node, void *nullnode)
1788 +{
1789 + int retval = 0;
1790 + node->type = *((*ptr)++);
1791 + switch (node->type) {
1792 + u32 i;
1793 + u32 j;
1794 + u32 lngth;
1795 + u32 tmpret;
1796 + TokenType at;
1797 + u16 av;
1798 + case TREENODETYPE_NODE_BINARY_EQ:
1799 + case TREENODETYPE_NODE_BINARY_LT:
1800 + node->data.nodeBin.attribute_ptr = (model->predictors_ptr) + (*((*ptr)++));
1801 + node->data.nodeBin.value = *((*ptr)++);
1802 + retval = sizeof(node->data.nodeBin);
1803 + retval += ipack_compressor_init_tree(ptr, model, (void *) ROUND_UP_TO_DWORD(((u32) node) + sizeof(node->type) + sizeof(node->data.nodeBin)), nullnode);
1804 + node->data.nodeBin.right_child_ptr = (void *) ROUND_UP_TO_DWORD(((u32) node) + retval + sizeof(node->type));
1805 + retval += ipack_compressor_init_tree(ptr, model, node->data.nodeBin.right_child_ptr, nullnode);
1806 + break;
1807 + case TREENODETYPE_LEAF_P:
1808 + lngth = *((*ptr)++);
1809 + av = 0;
1810 + for (i = 0, j = 0; i < lngth; ++i) {
1811 + at = *((*ptr)++);
1812 + while (j < at) {
1813 + node->data.leafP.probabilities[j++] = av;
1814 + }
1815 + av += *((*ptr)++);
1816 + }
1817 + while (j < NUMBER_OF_TOKENS) {
1818 + node->data.leafP.probabilities[j++] = av;
1819 + }
1820 + for (i = 0; i < NUMBER_OF_TOKENS; ++i) {
1821 + node->data.leafP.probabilities[i] = ((node->data.leafP.probabilities[i] << PROBABILITY_SHIFT) / node->data.leafP.probabilities[NUMBER_OF_TOKENS - 1]);
1822 + }
1823 + retval = ROUND_UP_TO_DWORD(NUMBER_OF_TOKENS * sizeof(u16));
1824 + break;
1825 + case TREENODETYPE_LEAF_C:
1826 + node->data.leafC.predicted_class = *((*ptr)++);
1827 + retval = sizeof(node->data.leafC);
1828 + retval = ROUND_UP_TO_DWORD(retval);
1829 + break;
1830 + default:
1831 + return 0;
1832 + }
1833 + return retval + sizeof(node->type);
1834 +}
1835 +
1836 +#define IPACK_TREE_CONVERT_REPLACE 0
1837 +#define IPACK_TREE_CONVERT_KEEP 1
1838 +
1839 +static void *ipack_tree_to_code(ipack_model_type * model, int *code_size);
1840 +
1841 +static int ipack_armlib_convert_tree_to_code(ipack_model_type * model_img, int mode)
1842 +{
1843 +#ifdef IPACK_TREE_TO_CODE
1844 + int tree_size;
1845 +
1846 + model_img->tree_code = ipack_tree_to_code(model_img, &tree_size);
1847 + jffs2_bbc_print2("Convertation done. Code size=%d\n", tree_size);
1848 + if (mode == IPACK_TREE_CONVERT_REPLACE) {
1849 + jffs2_bbc_print1("Freeing original tree.\n");
1850 + jffs2_bbc_free(model_img->tree_root_ptr);
1851 + model_img->tree_root_ptr = NULL;
1852 + }
1853 +#endif
1854 + return 0;
1855 +}
1856 +
1857 +
1858 +static int ipack_armlib_compressor_init(void **model)
1859 +{
1860 + int retval = EC_NO_ERROR;
1861 + unsigned char *tmp_ptr = *model;
1862 + u32 i;
1863 + ipack_model_type *model_img;
1864 + char tmp_c[2];
1865 +
1866 + if (*(tmp_ptr++) != 'i') {
1867 + return EC_NOT_IPMF_FILE;
1868 + }
1869 + else if (*(tmp_ptr++) != 'P') {
1870 + return EC_NOT_IPMF_FILE;
1871 + }
1872 + else if (*(tmp_ptr++) != 'M') {
1873 + return EC_NOT_IPMF_FILE;
1874 + }
1875 + else if (*(tmp_ptr++) != 'F') {
1876 + return EC_NOT_IPMF_FILE;
1877 + }
1878 + tmp_c[0] = *(tmp_ptr++);
1879 + tmp_c[1] = *(tmp_ptr++);
1880 + tmp_ptr += 2;
1881 +
1882 + //model_img = jffs2_bbc_malloc(*((u32*)tmp_ptr));
1883 + model_img = jffs2_bbc_malloc(sizeof(ipack_model_type) + ROUND_UP_TO_DWORD(NUMBER_OF_PREDICTORS));
1884 + model_img->tree_root_ptr = jffs2_bbc_malloc(*((u32 *) tmp_ptr)); //it is smaller a little but, but...
1885 +
1886 + tmp_ptr += sizeof(u32);
1887 +
1888 + model_img->ID[0] = 'i';
1889 + model_img->ID[1] = 'P';
1890 + model_img->ID[2] = 'M';
1891 + model_img->ID[3] = 'F';
1892 +
1893 + model_img->block_sign[0] = tmp_c[0];
1894 + model_img->block_sign[1] = tmp_c[1];
1895 +
1896 + model_img->nullnode.type = TREENODETYPE_LEAF_P;
1897 + for (i = 0; i < NUMBER_OF_TOKENS; ++i) {
1898 + model_img->nullnode.probabilities[i] = 0;
1899 + }
1900 + model_img->predictors_ptr = (void *) (((u32) model_img) + sizeof(ipack_model_type));
1901 + //model_img->tree_root_ptr = (void*)ROUND_UP_TO_DWORD(((u32)(model_img->predictors_ptr)) + NUMBER_OF_PREDICTORS);//ALIGN
1902 +
1903 + ipack_compressor_init_tree(&tmp_ptr, model_img, model_img->tree_root_ptr, &(model_img->nullnode));
1904 +
1905 +#ifdef IPACK_TREE_TO_CODE
1906 +#ifdef IPACK_AUTO_TREE_TO_CODE
1907 + jffs2_bbc_print1("Automatically converting tree to ARM code...\n");
1908 + ipack_armlib_convert_tree_to_code(model_img, IPACK_TREE_CONVERT_REPLACE);
1909 +#else
1910 + model_img->tree_code = NULL;
1911 +#endif
1912 +#else
1913 + model_img->tree_code = NULL;
1914 +#endif
1915 +
1916 + jffs2_bbc_free(*model);
1917 + *model = model_img;
1918 + return retval;
1919 +}
1920 +
1921 +/*******************************************************************************
1922 +
1923 + COMPRESSOR DEINIT FUNCTIONS
1924 +
1925 +*******************************************************************************/
1926 +
1927 +
1928 +/* Descructor of compressor (model will be freed with jffs2_bbc_free() after it)*/
1929 +static void ipack_armlib_compressor_deinit(void)
1930 +{
1931 +}
1932 +
1933 +/*******************************************************************************
1934 +
1935 + COMPRESS FUNCTIONS
1936 +
1937 +*******************************************************************************/
1938 +
1939 +static int writebits0(unsigned char **dest, u8 * freebits, u32 * opposite, unsigned char *end)
1940 +{
1941 + if (!(*freebits)) {
1942 + ++(*dest);
1943 + *freebits = 7;
1944 + **dest = 0x00;
1945 + }
1946 + else {
1947 + --(*freebits);
1948 + (**dest) <<= 1;
1949 + }
1950 + if ((*dest == end) && !(*freebits)) {
1951 + return EC_BUFFER_OVERFLOW;
1952 + }
1953 + while (*opposite) {
1954 + --(*opposite);
1955 + if (!(*freebits)) {
1956 + ++(*dest);
1957 + *freebits = 7;
1958 + **dest = 0x01;
1959 + }
1960 + else {
1961 + --(*freebits);
1962 + (**dest) <<= 1;
1963 + (**dest) |= 0x01;
1964 + }
1965 + if ((*dest == end) && !(*freebits)) {
1966 + return EC_BUFFER_OVERFLOW;
1967 + }
1968 + }
1969 + return 0;
1970 +}
1971 +
1972 +static int writebits1(unsigned char **dest, u8 * freebits, u32 * opposite, unsigned char *end)
1973 +{
1974 + if (!(*freebits)) {
1975 + ++(*dest);
1976 + *freebits = 7;
1977 + **dest = 0x01;
1978 + }
1979 + else {
1980 + --(*freebits);
1981 + (**dest) <<= 1;
1982 + (**dest) |= 0x01;
1983 + }
1984 + if ((*dest == end) && !(*freebits)) {
1985 + return EC_BUFFER_OVERFLOW;
1986 + }
1987 + while (*opposite) {
1988 + --(*opposite);
1989 + if (!(*freebits)) {
1990 + ++(*dest);
1991 + *freebits = 7;
1992 + **dest = 0x00;
1993 + }
1994 + else {
1995 + --(*freebits);
1996 + (**dest) <<= 1;
1997 + }
1998 + if ((*dest == end) && !(*freebits)) {
1999 + return EC_BUFFER_OVERFLOW;
2000 + }
2001 + }
2002 + return 0;
2003 +}
2004 +
2005 +
2006 +
2007 +
2008 +/* Compress block
2009 + * *dstlen bytes are allocated.
2010 + * if it is not enough write *sourcelen over to the processed amount of data
2011 + * returns non zero if fails
2012 + */
2013 +static int ipack_armlib_compress(void *model, unsigned char *input, unsigned char *output, unsigned long *sourcelen, unsigned long *dstlen)
2014 +{
2015 + register u32 coder_high = CODER_VALUEMAX - 1;
2016 + register u32 coder_low = 0;
2017 + u32 coder_opbits = 0;
2018 + u8 bitvector_freebits = 8;
2019 + unsigned char *bitvector_ptr = output;
2020 + unsigned char *bitvector_end = output + (*dstlen - 1);
2021 + ARM_DataType *tmpp;
2022 + TokenStream tmpv;
2023 + TokenType *it;
2024 + void *end_it;
2025 +
2026 + ipack_nodetype *treeroot = ((ipack_model_type *) model)->tree_root_ptr;
2027 + PredictorType *predctrs = ((ipack_model_type *) model)->predictors_ptr;
2028 +
2029 +#ifdef IPACK_TREE_TO_CODE
2030 + void (*treefunc) (ipack_nodetype *, TokenType, ipack_probability_type *);
2031 +
2032 + treefunc = ((ipack_model_type *) model)->tree_code;
2033 + if (treefunc != NULL)
2034 + treefunc += 4;
2035 +#endif
2036 +
2037 + if ((*sourcelen % 4) != 0) {
2038 + return EC_WRONG_INPUT_LENGTH;
2039 + }
2040 + if (*dstlen <= 4) {
2041 + return EC_BUFFER_OVERFLOW;
2042 + }
2043 +
2044 + if (((ipack_model_type *) model)->ID[0] != 'i') {
2045 + return EC_NOT_IPMF_MODEL;
2046 + }
2047 + else if (((ipack_model_type *) model)->ID[1] != 'P') {
2048 + return EC_NOT_IPMF_MODEL;
2049 + }
2050 + else if (((ipack_model_type *) model)->ID[2] != 'M') {
2051 + return EC_NOT_IPMF_MODEL;
2052 + }
2053 + else if (((ipack_model_type *) model)->ID[3] != 'F') {
2054 + return EC_NOT_IPMF_MODEL;
2055 + }
2056 +#ifdef TXT_TOKENS
2057 + tmpv.capacity = (*sourcelen);
2058 +#else
2059 + tmpv.capacity = (*sourcelen) << 1;
2060 +#endif
2061 + tmpv.size = tmpv.capacity;
2062 + tmpv.ptr = jffs2_bbc_malloc(tmpv.size);
2063 + it = tmpv.ptr;
2064 +
2065 +#ifndef __KERNEL__
2066 + if (ipack_glb_endian_X) {
2067 + for (tmpp = (void *) input; (u32) tmpp < (u32) (input + *sourcelen); ++tmpp) {
2068 +#ifdef TXT_TOKENS
2069 + *(it++) = (u8) ((*tmpp & 0xff000000) >> 24);
2070 + *(it++) = (u8) ((*tmpp & 0x00ff0000) >> 16);
2071 + *(it++) = (u8) ((*tmpp & 0x0000ff00) >> 8);
2072 + *(it++) = (u8) ((*tmpp & 0x000000ff));
2073 +#else
2074 + *(it++) = (u8) ((*tmpp & 0x0000f000) >> 12);
2075 + *(it++) = (u8) ((*tmpp & 0x0000000f));
2076 + *(it++) = (u8) ((*tmpp & 0xf0000000) >> 28);
2077 + *(it++) = (u8) ((*tmpp & 0x000f0000) >> 16);
2078 + *(it++) = (u8) ((*tmpp & 0x00000f00) >> 8);
2079 + *(it++) = (u8) ((*tmpp & 0x00f00000) >> 20);
2080 + *(it++) = (u8) ((*tmpp & 0x0f000000) >> 24);
2081 + *(it++) = (u8) ((*tmpp & 0x000000f0) >> 4);
2082 +#endif //TXT_TOKENS
2083 + }
2084 + }
2085 + else {
2086 +#endif
2087 + for (tmpp = (void *) input; (u32) tmpp < (u32) (input + *sourcelen); ++tmpp) {
2088 +#ifdef TXT_TOKENS
2089 + *(it++) = (u8) ((*tmpp & 0x000000ff));
2090 + *(it++) = (u8) ((*tmpp & 0x0000ff00) >> 8);
2091 + *(it++) = (u8) ((*tmpp & 0x00ff0000) >> 16);
2092 + *(it++) = (u8) ((*tmpp & 0xff000000) >> 24);
2093 +#else
2094 + *(it++) = (u8) ((*tmpp & 0x00f00000) >> 20);
2095 + *(it++) = (u8) ((*tmpp & 0x0f000000) >> 24);
2096 + *(it++) = (u8) ((*tmpp & 0x000000f0) >> 4);
2097 + *(it++) = (u8) ((*tmpp & 0x00000f00) >> 8);
2098 + *(it++) = (u8) ((*tmpp & 0x000f0000) >> 16);
2099 + *(it++) = (u8) ((*tmpp & 0x0000f000) >> 12);
2100 + *(it++) = (u8) ((*tmpp & 0x0000000f));
2101 + *(it++) = (u8) ((*tmpp & 0xf0000000) >> 28);
2102 +#endif //TXT_TOKENS
2103 + }
2104 +#ifndef __KERNEL__
2105 + }
2106 +#endif
2107 +/*
2108 + ENCODE
2109 +*/
2110 + { //predictor reset
2111 + register PredictorType *ptr = predctrs;
2112 + register PredictorType *end = ptr + NUMBER_OF_PREDICTORS;
2113 + while (ptr < end) {
2114 + *(ptr++) = 0;
2115 + }
2116 + }
2117 +
2118 + //*(bitvector_ptr++) = 'H';
2119 + //*(bitvector_ptr++) = 'G';
2120 + *(bitvector_ptr++) = ((ipack_model_type *) model)->block_sign[0];
2121 + *(bitvector_ptr++) = ((ipack_model_type *) model)->block_sign[1];
2122 +
2123 + *(bitvector_ptr++) = (unsigned char) (((*sourcelen) >> 8) & 0xff);
2124 + *(bitvector_ptr++) = (unsigned char) ((*sourcelen) & 0xff);
2125 + for (it = tmpv.ptr, end_it = VECTOR_S_END(tmpv); it != end_it; ++it) {
2126 + ipack_probability_type prob;
2127 + u32 range;
2128 +
2129 +#ifdef IPACK_TREE_TO_CODE
2130 + if (treefunc != NULL)
2131 + (*treefunc) (treeroot, *it, &prob);
2132 + else
2133 + ipack_model_get_probability_for_token(treeroot, *it, &prob);
2134 +#else
2135 + ipack_model_get_probability_for_token(treeroot, *it, &prob);
2136 +#endif
2137 +
2138 + if (prob.high == prob.low) {
2139 + vector_clear(&tmpv);
2140 + return EC_CODER_WRONG_PROBABILITY;
2141 + }
2142 + range = coder_high - coder_low + 1;
2143 + coder_high = coder_low + ((range * prob.high) >> PROBABILITY_SHIFT) - 1;
2144 + coder_low += ((range * prob.low) >> PROBABILITY_SHIFT);
2145 + for (;;) {
2146 + if (coder_high < CODER_VALUEHLF) {
2147 + if (writebits0(&bitvector_ptr, &bitvector_freebits, &coder_opbits, bitvector_end)) {
2148 + vector_clear(&tmpv);
2149 + return EC_BUFFER_OVERFLOW;
2150 + }
2151 + }
2152 + else if (coder_low >= CODER_VALUEHLF) {
2153 + if (writebits1(&bitvector_ptr, &bitvector_freebits, &coder_opbits, bitvector_end)) {
2154 + vector_clear(&tmpv);
2155 + return EC_BUFFER_OVERFLOW;
2156 + }
2157 + coder_high -= CODER_VALUEHLF;
2158 + coder_low -= CODER_VALUEHLF;
2159 + }
2160 + else if ((CODER_VALUE1ST <= coder_low) && (coder_high < CODER_VALUE3RD)) {
2161 + ++coder_opbits;
2162 + coder_high -= CODER_VALUE1ST;
2163 + coder_low -= CODER_VALUE1ST;
2164 + }
2165 + else {
2166 + break;
2167 + }
2168 + coder_high <<= 1;
2169 + ++coder_high;
2170 + coder_low <<= 1;
2171 + if (coder_high < coder_low) {
2172 + vector_clear(&tmpv);
2173 + return EC_CODER_WRONG_RANGE;
2174 + }
2175 + }
2176 + {
2177 +#ifdef TXT_TOKENS
2178 +// register u32 ndx;
2179 + predctrs[0] = *it;
2180 + if ((('a' <= *it) && (*it <= 'z')) || (('A' <= *it) && (*it <= 'Z'))) {
2181 + ++(predctrs[1]);
2182 + }
2183 + else {
2184 + predctrs[1] = 0;
2185 + }
2186 +#else
2187 + register u32 ndx = predctrs[0] + 1;
2188 + predctrs[ndx + 8] = predctrs[ndx];
2189 + predctrs[ndx] = *it;
2190 + if (ndx == 8) {
2191 + predctrs[0] = 0;
2192 + }
2193 + else {
2194 + ++predctrs[0];
2195 + }
2196 +#endif
2197 + }
2198 +
2199 + }
2200 + vector_clear(&tmpv);
2201 + ++coder_opbits;
2202 + if (coder_low < CODER_VALUE1ST) {
2203 + if (writebits0(&bitvector_ptr, &bitvector_freebits, &coder_opbits, bitvector_end)) {
2204 + return EC_BUFFER_OVERFLOW;
2205 + }
2206 + }
2207 + else {
2208 + if (writebits1(&bitvector_ptr, &bitvector_freebits, &coder_opbits, bitvector_end)) {
2209 + return EC_BUFFER_OVERFLOW;
2210 + }
2211 + }
2212 + (*(bitvector_ptr)) <<= bitvector_freebits;
2213 + *dstlen = ((u32) bitvector_ptr - (u32) output + 1);
2214 + return EC_NO_ERROR;
2215 +}
2216 +
2217 +/*******************************************************************************
2218 +
2219 + DECOMPRESS FUNCTIONS
2220 +
2221 +*******************************************************************************/
2222 +
2223 +typedef struct
2224 +{
2225 + u32 high;
2226 + u32 low;
2227 + u32 value;
2228 + u32 overread;
2229 +} ipack_decompressor_values;
2230 +
2231 +typedef struct
2232 +{
2233 + u8 freebits;
2234 + unsigned char *ptr;
2235 + unsigned char *end;
2236 +} ipack_decompressor_bitvector;
2237 +
2238 +static u8 ipack_bitvector_R_get1(ipack_decompressor_bitvector * bv)
2239 +{
2240 + u8 tmp;
2241 + if (bv->ptr == bv->end) {
2242 + bv->freebits = 0;
2243 + return 0;
2244 + }
2245 + tmp = (*(bv->ptr) >> bv->freebits) & 0x01;
2246 + if (!(bv->freebits)) {
2247 + bv->freebits = 7;
2248 + ++(bv->ptr);
2249 + }
2250 + else {
2251 + --(bv->freebits);
2252 + }
2253 + return tmp;
2254 +}
2255 +
2256 +/* Decompress block
2257 + * returns non zero if fails
2258 + */
2259 +static int ipack_armlib_decompress(void *model, unsigned char *input, unsigned char *output, unsigned long sourcelen, unsigned long dstlen)
2260 +{
2261 + ARM_DataType *data;
2262 + register u32 coder_high = CODER_VALUEMAX - 1;
2263 + register u32 coder_low = 0;
2264 + register u32 coder_value = 0;
2265 + u32 coder_overread = 0;
2266 + ipack_decompressor_bitvector bitvector;
2267 + u32 lngth;
2268 + u32 i;
2269 + u32 cntbytes;
2270 + TokenType tkns[8];
2271 + TokenType *tptr;
2272 +
2273 + ipack_nodetype *treeroot = ((ipack_model_type *) model)->tree_root_ptr;
2274 + PredictorType *predctrs = ((ipack_model_type *) model)->predictors_ptr;
2275 +
2276 +#ifdef IPACK_TREE_TO_CODE
2277 + TokenType(*treefunc) (ipack_nodetype *, u32, u32, ipack_probability_type *);
2278 +
2279 + treefunc = ((ipack_model_type *) model)->tree_code;
2280 +#endif
2281 +
2282 +
2283 + if (((ipack_model_type *) model)->ID[0] != 'i') {
2284 + return EC_NOT_IPMF_MODEL;
2285 + }
2286 + else if (((ipack_model_type *) model)->ID[1] != 'P') {
2287 + return EC_NOT_IPMF_MODEL;
2288 + }
2289 + else if (((ipack_model_type *) model)->ID[2] != 'M') {
2290 + return EC_NOT_IPMF_MODEL;
2291 + }
2292 + else if (((ipack_model_type *) model)->ID[3] != 'F') {
2293 + return EC_NOT_IPMF_MODEL;
2294 + }
2295 +
2296 + bitvector.freebits = 7;
2297 + bitvector.ptr = input;
2298 + bitvector.end = input + sourcelen;
2299 +
2300 + /*if(*(bitvector.ptr++) != 'H') {
2301 + return EC_NOT_HG_BLOCK;
2302 + } else if(*(bitvector.ptr++) != 'G') {
2303 + return EC_NOT_HG_BLOCK;
2304 + } */
2305 + bitvector.ptr++;
2306 + bitvector.ptr++;
2307 +
2308 + data = (void *) output;
2309 + cntbytes = *(bitvector.ptr++);
2310 + cntbytes <<= 8;
2311 + cntbytes += *(bitvector.ptr++);
2312 +
2313 + { //predictor reset
2314 + register PredictorType *ptr = predctrs;
2315 + register PredictorType *end = ptr + NUMBER_OF_PREDICTORS;
2316 + while (ptr < end) {
2317 + *(ptr++) = 0;
2318 + }
2319 + }
2320 + for (i = 0; i < CODER_VALUEBITS; ++i) {
2321 + coder_value <<= 1;
2322 + coder_value += ipack_bitvector_R_get1(&bitvector);
2323 + }
2324 + lngth = dstlen >> 2;
2325 + if (lngth > (cntbytes >> 2)) {
2326 + lngth = cntbytes >> 2;
2327 + }
2328 + for (i = 0; (i < lngth); ++i) {
2329 + TokenType itoken;
2330 + u32 j;
2331 + tptr = tkns;
2332 + for (j = 0; j < NUMBER_OF_TOKENS_PER_INSTRUCTION; ++j) {
2333 + ipack_probability_type prob;
2334 + u32 range = coder_high - coder_low + 1;
2335 +
2336 +#ifdef IPACK_TREE_TO_CODE
2337 + if (treefunc != NULL)
2338 + itoken = (*treefunc) (treeroot, coder_value - coder_low + 1, range, &prob);
2339 + else
2340 +#endif
2341 + itoken = ipack_model_get_token_for_range(treeroot, coder_value - coder_low + 1, range, &prob);
2342 +
2343 +
2344 + if (prob.high == prob.low) {
2345 + return EC_CODER_WRONG_PROBABILITY;
2346 + }
2347 + coder_high = coder_low + ((range * prob.high) >> PROBABILITY_SHIFT) - 1;
2348 + coder_low += ((range * prob.low) >> PROBABILITY_SHIFT);
2349 + for (;;) {
2350 + if (coder_high < CODER_VALUEHLF) {
2351 + }
2352 + else if (CODER_VALUEHLF <= coder_low) {
2353 + coder_value -= CODER_VALUEHLF;
2354 + coder_high -= CODER_VALUEHLF;
2355 + coder_low -= CODER_VALUEHLF;
2356 + }
2357 + else if ((CODER_VALUE1ST <= coder_low) && (coder_high < CODER_VALUE3RD)) {
2358 + coder_value -= CODER_VALUE1ST;
2359 + coder_high -= CODER_VALUE1ST;
2360 + coder_low -= CODER_VALUE1ST;
2361 + }
2362 + else {
2363 + break;
2364 + }
2365 + coder_low <<= 1;
2366 + coder_high <<= 1;
2367 + ++(coder_high);
2368 + coder_value <<= 1;
2369 + if (bitvector.ptr == bitvector.end) {
2370 + bitvector.freebits = 0;
2371 + }
2372 + coder_value += ((*(bitvector.ptr) >> bitvector.freebits) & 0x01);
2373 + if (bitvector.freebits) {
2374 + --bitvector.freebits;
2375 + }
2376 + else {
2377 + bitvector.freebits = 7;
2378 + ++bitvector.ptr;
2379 + }
2380 + if (coder_high < coder_low) {
2381 + return EC_CODER_WRONG_RANGE;
2382 + }
2383 + if ((bitvector.ptr == bitvector.end) && !(bitvector.freebits)) {
2384 + if ((coder_overread++) > CODER_VALUEBITS) {
2385 + return EC_BUFFER_UNDERFLOW;
2386 + }
2387 + }
2388 + }
2389 + {
2390 +#ifdef TXT_TOKENS
2391 +// register u32 ndx;
2392 + predctrs[0] = itoken;
2393 + if ((('a' <= itoken) && (itoken <= 'z')) || (('A' <= itoken) && (itoken <= 'Z'))) {
2394 + ++(predctrs[1]);
2395 + }
2396 + else {
2397 + predctrs[1] = 0;
2398 + }
2399 +
2400 +#else
2401 + register u32 ndx = predctrs[0] + 1;
2402 + predctrs[ndx + 8] = predctrs[ndx];
2403 + predctrs[ndx] = itoken;
2404 + if (ndx == 8) {
2405 + predctrs[0] = 0;
2406 + }
2407 + else {
2408 + ++predctrs[0];
2409 + }
2410 +#endif
2411 + }
2412 +
2413 + (*(tptr++)) = itoken;
2414 + }
2415 + tptr = tkns;
2416 +#ifndef __KERNEL__
2417 + if (ipack_glb_endian_X) {
2418 +#ifdef TXT_TOKENS
2419 + (*data) = ((*tptr) << 24);
2420 + ++tptr;
2421 + (*data) |= ((*tptr) << 16);
2422 + ++tptr;
2423 + (*data) |= ((*tptr) << 8);
2424 + ++tptr;
2425 + (*data) |= (*tptr);
2426 + ++data;
2427 +#else
2428 + (*data) = (((*tptr) & 0xf) << 12);
2429 + ++tptr;
2430 + (*data) |= ((*tptr) & 0xf);
2431 + ++tptr;
2432 + (*data) |= (((*tptr) & 0xf) << 28);
2433 + ++tptr;
2434 + (*data) |= (((*tptr) & 0xf) << 16);
2435 + ++tptr;
2436 + (*data) |= (((*tptr) & 0xf) << 8);
2437 + ++tptr;
2438 + (*data) |= (((*tptr) & 0xf) << 20);
2439 + ++tptr;
2440 + (*data) |= (((*tptr) & 0xf) << 24);
2441 + ++tptr;
2442 + (*data) |= (((*tptr) & 0xf) << 4);
2443 + ++data;
2444 +#endif
2445 + }
2446 + else {
2447 +#endif
2448 +#ifdef TXT_TOKENS
2449 + (*data) = (*tptr);
2450 + ++tptr;
2451 + (*data) |= ((*tptr) << 8);
2452 + ++tptr;
2453 + (*data) |= ((*tptr) << 16);
2454 + ++tptr;
2455 + (*data) |= ((*tptr) << 24);
2456 + ++data;
2457 +#else
2458 + (*data) = (((*tptr) & 0xf) << 20);
2459 + ++tptr;
2460 + (*data) |= (((*tptr) & 0xf) << 24);
2461 + ++tptr;
2462 + (*data) |= (((*tptr) & 0xf) << 4);
2463 + ++tptr;
2464 + (*data) |= (((*tptr) & 0xf) << 8);
2465 + ++tptr;
2466 + (*data) |= (((*tptr) & 0xf) << 16);
2467 + ++tptr;
2468 + (*data) |= (((*tptr) & 0xf) << 12);
2469 + ++tptr;
2470 + (*data) |= ((*tptr) & 0xf);
2471 + ++tptr;
2472 + (*data) |= (((*tptr) & 0xf) << 28);
2473 + ++data;
2474 +#endif
2475 +#ifndef __KERNEL__
2476 + }
2477 +#endif
2478 + }
2479 + return EC_NO_ERROR;
2480 +}
2481 +
2482 +static int ipack_armlib_estimate(void *model, unsigned char *input, unsigned long sourcelen, unsigned long *dstlen, unsigned long *readtime, unsigned long *writetime)
2483 +{
2484 + int i, tmp, tmp2, max, maxi;
2485 + int cnt_cond[] = { 0, 0, 0, 0 };
2486 + int cnt_inst[] = { 0, 0, 0, 0 };
2487 +
2488 + // TODO: make a more precise estimation!!!
2489 + *readtime = JFFS2_BBC_ZLIB_READ_TIME * 6;
2490 + *writetime = JFFS2_BBC_ZLIB_WRITE_TIME * 2;
2491 +
2492 + if (sourcelen % 4 != 0) {
2493 + *dstlen = sourcelen;
2494 + return 0;
2495 + }
2496 + for (i = 0; i < sourcelen; i++, input++) {
2497 + tmp2 = tmp = *input;
2498 + tmp = ((tmp) & 0xf0) >> 4;
2499 + tmp2 = tmp2 & 0xf;
2500 + if (tmp == 14)
2501 + cnt_cond[i % 4]++;
2502 + if ((tmp2 == 2) || (tmp2 == 3))
2503 + cnt_inst[i % 4]++;
2504 + }
2505 + maxi = -1;
2506 + max = -1;
2507 + for (i = 0; i < 4; i++)
2508 + if (max < cnt_cond[i]) {
2509 + max = cnt_cond[i];
2510 + maxi = i;
2511 + }
2512 + /*jffs2_bbc_print("armlib_EST: %d/%d : %d/%d %d/%d %d/%d %d/%d",
2513 + cnt_cond[maxi],cnt_inst[maxi],
2514 + cnt_cond[0],cnt_inst[0],
2515 + cnt_cond[1],cnt_inst[1],
2516 + cnt_cond[2],cnt_inst[2],
2517 + cnt_cond[3],cnt_inst[3]); */
2518 +
2519 + if (cnt_cond[maxi] < (sourcelen >> 4)) {
2520 + *dstlen = sourcelen;
2521 + }
2522 + else {
2523 + *dstlen = sourcelen / 3;
2524 + }
2525 +
2526 + return 0;
2527 +}
2528 +
2529 +static char *ipack_armlib_proc_info(void);
2530 +static int ipack_armlib_proc_command(char *command);
2531 +static void ipack_armlib_destroy_model(void **model);
2532 +
2533 +struct jffs2_bbc_compressor_type jffs2_bbc_armlib = {
2534 + "armlib",
2535 + 0x464d5069,
2536 + {0, 0, 0, 0},
2537 + NULL, // init
2538 + ipack_armlib_compressor_init, // init_model
2539 + ipack_armlib_destroy_model, // destroy_model
2540 + ipack_armlib_compressor_deinit, // deinit
2541 + ipack_armlib_compress,
2542 + ipack_armlib_estimate,
2543 + ipack_armlib_decompress,
2544 + ipack_armlib_proc_info,
2545 + ipack_armlib_proc_command
2546 +};
2547 +
2548 +
2549 +static char *ipack_armlib_proc_info()
2550 +{
2551 +#ifdef IPACK_TREE_TO_CODE
2552 +#ifdef IPACK_AUTO_TREE_TO_CODE
2553 + return "automatic tree to code conversion";
2554 +#else
2555 + return "manual tree to code conversion possibility";
2556 +#endif
2557 +#else
2558 + return "tree in memory version";
2559 +#endif
2560 +}
2561 +
2562 +static int ipack_armlib_proc_command(char *command)
2563 +{
2564 + struct jffs2_bbc_model_list_node *model;
2565 + ipack_model_type *armlib_model;
2566 +
2567 + if ((*command == 'g') || (*command == 'G')) {
2568 + jffs2_bbc_print1("Converting tree(s) to ARM code... (keeping original)\n");
2569 + model = jffs2_bbc_armlib.models;
2570 + if (model == NULL)
2571 + jffs2_bbc_print1("no model found!\n");
2572 + while (model != NULL) {
2573 + armlib_model = model->model;
2574 + if (armlib_model == NULL) {
2575 + jffs2_bbc_print1("Error: NULL model!\n");
2576 + }
2577 + else {
2578 + ipack_armlib_convert_tree_to_code(armlib_model, IPACK_TREE_CONVERT_KEEP);
2579 + }
2580 + model = model->next_compr_model;
2581 + }
2582 + }
2583 + else if ((*command == 'r') || (*command == 'R')) {
2584 + jffs2_bbc_print1("Converting tree(s) to ARM code... (deleting original)\n");
2585 + model = jffs2_bbc_armlib.models;
2586 + if (model == NULL)
2587 + jffs2_bbc_print1("no model found!\n");
2588 + while (model != NULL) {
2589 + armlib_model = model->model;
2590 + if (armlib_model == NULL) {
2591 + jffs2_bbc_print1("Error: NULL model!\n");
2592 + }
2593 + else {
2594 + //armlib_model->tree_code = ipack_tree_to_code(armlib_model, &tree_size);
2595 + //jffs2_bbc_print("Convertation done. Code size=%d\n",tree_size);
2596 + ipack_armlib_convert_tree_to_code(armlib_model, IPACK_TREE_CONVERT_REPLACE);
2597 + }
2598 + model = model->next_compr_model;
2599 + }
2600 + }
2601 + else if ((*command == 'c') || (*command == 'C')) {
2602 + jffs2_bbc_print1("Deleting ARM representation of the tree(s)...\n");
2603 + model = jffs2_bbc_armlib.models;
2604 + if (model == NULL)
2605 + jffs2_bbc_print1("no model found!\n");
2606 + while (model != NULL) {
2607 + armlib_model = model->model;
2608 + if (armlib_model == NULL) {
2609 + jffs2_bbc_print1("Error: NULL model!\n");
2610 + }
2611 + else {
2612 + if (armlib_model->tree_code == NULL) {
2613 + jffs2_bbc_print1("already deleted.\n");
2614 + }
2615 + else {
2616 + if (armlib_model->tree_root_ptr == NULL) {
2617 + jffs2_bbc_print1("cannot delete this ARM tree - original tree has deleted\n");
2618 + }
2619 + else {
2620 + jffs2_bbc_print1("deleting...");
2621 + jffs2_bbc_free(armlib_model->tree_code);
2622 + armlib_model->tree_code = NULL;
2623 + jffs2_bbc_print1("done.\n");
2624 + }
2625 + }
2626 + }
2627 + model = model->next_compr_model;
2628 + }
2629 + }
2630 + else if (*command == '?') {
2631 + jffs2_bbc_print1("ARMLIB commands:\n");
2632 + jffs2_bbc_print1(" g: convert TREEs to ARM code and keep the original\n");
2633 + jffs2_bbc_print1(" r: convert TREEs to ARM code and remove the original\n");
2634 + jffs2_bbc_print1(" c: delete the original TREEs - if there is any\n");
2635 + }
2636 + else {
2637 + jffs2_bbc_print1("Unknown command.\n");
2638 + }
2639 + return 0;
2640 +}
2641 +
2642 +static void ipack_armlib_destroy_model(void **model)
2643 +{
2644 + ipack_model_type *model_img;
2645 +
2646 + model_img = *model;
2647 + if (model_img == NULL) {
2648 + jffs2_bbc_print1("jffs2.bbc: armlib: NULL model at destoying model!\n");
2649 + return;
2650 + }
2651 + if (model_img->tree_code != NULL) {
2652 + //jffs2_bbc_print1("jffs2.bbc: armlib: debug: freeing code...\n");
2653 + jffs2_bbc_free(model_img->tree_code);
2654 + model_img->tree_code = NULL;
2655 + }
2656 + if (model_img->tree_root_ptr != NULL) {
2657 + //jffs2_bbc_print1("jffs2.bbc: armlib: debug: freeing tree...\n");
2658 + jffs2_bbc_free(model_img->tree_root_ptr);
2659 + model_img->tree_root_ptr = NULL;
2660 + }
2661 +
2662 + jffs2_bbc_free(model_img);
2663 + *model = NULL;
2664 +}
2665 +
2666 +struct jffs2_bbc_compressor_type *jffs2_bbc_armlib_init(int mode)
2667 +{
2668 + if (jffs2_bbc_register_compressor(&jffs2_bbc_armlib) == 0)
2669 + return &jffs2_bbc_armlib;
2670 + else
2671 + return NULL;
2672 +}
2673 +
2674 +void jffs2_bbc_armlib_deinit(void)
2675 +{
2676 + jffs2_bbc_unregister_compressor(&jffs2_bbc_armlib);
2677 +}
2678 +
2679 +/*END OF ARMLIB*/
2680 diff -Nur linux-mips-cvs/fs/jffs2/jffs2_bbc_framework.c linux-mips/fs/jffs2/jffs2_bbc_framework.c
2681 --- linux-mips-cvs/fs/jffs2/jffs2_bbc_framework.c 1970-01-01 01:00:00.000000000 +0100
2682 +++ linux-mips/fs/jffs2/jffs2_bbc_framework.c 2005-02-07 05:08:34.000000000 +0100
2683 @@ -0,0 +1,1324 @@
2684 +/*
2685 + * JFFS2-BBC: Compression Framework
2686 + *
2687 + * $Id: 301-jffs-compression,v 1.1 2005/03/26 10:33:31 wbx Exp $
2688 + *
2689 + * Copyright (C) 2004, Ferenc Havasi
2690 + *
2691 + * This program is free software; you can redistribute it and/or
2692 + * modify it under the terms of the GNU General Public License
2693 + * as published by the Free Software Foundation; either version 2
2694 + * of the License, or (at your option) any later version.
2695 + *
2696 + * This program is distributed in the hope that it will be useful,
2697 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2698 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2699 + * GNU General Public License for more details.
2700 + *
2701 + * You should have received a copy of the GNU General Public License
2702 + * along with this program; if not, write to the Free Software
2703 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2704 + *
2705 + */
2706 +
2707 +/* USE JFFS2_BBC_STANDALONE define if you don't want to compile without JFFS2 */
2708 +
2709 +//#define DEBUG_COMPRESSORS
2710 +//#define DEBUG_SHOW_BLOCK_SIZES
2711 +
2712 +#define JFFS2_BBC_STAT_BUFF_SIZE 8000
2713 +
2714 +#ifndef __KERNEL__
2715 +
2716 +#include <stdio.h>
2717 +#include <malloc.h>
2718 +typedef unsigned long uint32_t;
2719 +
2720 +#else
2721 +
2722 +#include <linux/kernel.h>
2723 +#include <linux/slab.h>
2724 +#include <linux/vmalloc.h>
2725 +
2726 +#endif
2727 +
2728 +#define JFFS2_BBC_ZLIB_BLOCK_SIGN_0 (120)
2729 +#define JFFS2_BBC_ZLIB_BLOCK_SIGN_1 (94)
2730 +
2731 +#define JFFS2_BBC_DUMMY_BLOCKSIGN_0 (0x54)
2732 +#define JFFS2_BBC_DUMMY_BLOCKSIGN_1 (0x01)
2733 +
2734 +#ifndef NULL
2735 +#define NULL ((void*)(0))
2736 +#endif
2737 +
2738 +#include "jffs2_bbc_framework.h"
2739 +
2740 +/*********************************************************************
2741 + * Global data *
2742 + *********************************************************************/
2743 +
2744 +static int jffs2_bbc_compression_mode = JFFS2_BBC_ZLIB_MODE;
2745 +static struct jffs2_bbc_compressor_type *jffs2_bbc_manual_compressor = NULL;
2746 +static struct jffs2_bbc_compressor_type *jffs2_bbc_compressors = NULL;
2747 +static struct jffs2_bbc_model_list_node *jffs2_bbc_model_list = NULL;
2748 +static void *last_sb = NULL; /* previously activated sb */
2749 +
2750 +/*********************************************************************
2751 + * Compressor initialization *
2752 + *********************************************************************/
2753 +
2754 +#ifndef JFFS2_BBC_STANDALONE
2755 +
2756 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_ARMLIB)
2757 +struct jffs2_bbc_compressor_type *jffs2_bbc_armlib_init(void);
2758 +void jffs2_bbc_armlib_deinit(void);
2759 +#endif
2760 +
2761 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZO)
2762 +struct jffs2_bbc_compressor_type *jffs2_bbc_lzo_init(void);
2763 +void jffs2_bbc_lzo_deinit(void);
2764 +#endif
2765 +
2766 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZSS)
2767 +struct jffs2_bbc_compressor_type *jffs2_bbc_lzss_init(void);
2768 +void jffs2_bbc_lzss_deinit(void);
2769 +#endif
2770 +
2771 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZARI)
2772 +struct jffs2_bbc_compressor_type *jffs2_bbc_lzari_init(void);
2773 +void jffs2_bbc_lzari_deinit(void);
2774 +#endif
2775 +
2776 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZHD)
2777 +struct jffs2_bbc_compressor_type *jffs2_bbc_lzhd_init(void);
2778 +void jffs2_bbc_lzhd_deinit(void);
2779 +#endif
2780 +
2781 +void jffs2_bbc_compressor_init()
2782 +{
2783 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_ARMLIB)
2784 + jffs2_bbc_armlib_init();
2785 +#endif
2786 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZO)
2787 + jffs2_bbc_lzo_init();
2788 +#endif
2789 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZSS)
2790 + jffs2_bbc_lzss_init();
2791 +#endif
2792 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZARI)
2793 + jffs2_bbc_lzari_init();
2794 +#endif
2795 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZHD)
2796 + jffs2_bbc_lzhd_init();
2797 +#endif
2798 +}
2799 +
2800 +void jffs2_bbc_compressor_deinit()
2801 +{
2802 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZHD)
2803 + jffs2_bbc_lzhd_deinit();
2804 +#endif
2805 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZARI)
2806 + jffs2_bbc_lzari_deinit();
2807 +#endif
2808 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZSS)
2809 + jffs2_bbc_lzss_deinit();
2810 +#endif
2811 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_LZO)
2812 + jffs2_bbc_lzo_deinit();
2813 +#endif
2814 +#if !defined(__KERNEL__) || defined(CONFIG_JFFS2_BBC_ARMLIB)
2815 + jffs2_bbc_armlib_deinit();
2816 +#endif
2817 +}
2818 +
2819 +#endif
2820 +
2821 +#ifndef JFFS2_BBC_STANDALONE
2822 +
2823 +/*********************************************************************
2824 + * ZLIB COMPRESSOR *
2825 + *********************************************************************/
2826 +
2827 +extern int jffs2_zlib_compress2(unsigned char *data_in, unsigned char *cpage_out, uint32_t * sourcelen, uint32_t * dstlen);
2828 +extern void jffs2_zlib_decompress2(unsigned char *data_in, unsigned char *cpage_out, uint32_t srclen, uint32_t destlen);
2829 +
2830 +static int jffs2_bbc_zlib_compress(void *model, unsigned char *input, unsigned char *output, unsigned long *sourcelen, unsigned long *dstlen)
2831 +{
2832 + return jffs2_zlib_compress2(input, output, sourcelen, dstlen);
2833 +}
2834 +
2835 +static int jffs2_bbc_zlib_decompress(void *model, unsigned char *input, unsigned char *output, unsigned long sourcelen, unsigned long dstlen)
2836 +{
2837 + jffs2_zlib_decompress2(input, output, sourcelen, dstlen);
2838 + return 0;
2839 +}
2840 +
2841 +static int jffs2_bbc_zlib_estimate(void *model, unsigned char *input, unsigned long sourcelen, unsigned long *dstlen, unsigned long *readtime, unsigned long *writetime)
2842 +{
2843 + *dstlen = sourcelen * 65 / 100;
2844 + *readtime = JFFS2_BBC_ZLIB_READ_TIME;
2845 + *writetime = JFFS2_BBC_ZLIB_WRITE_TIME;
2846 + return 0;
2847 +}
2848 +
2849 +static struct jffs2_bbc_compressor_type jffs2_bbc_zlib = {
2850 + "zlib",
2851 + 0,
2852 + {JFFS2_BBC_ZLIB_BLOCK_SIGN_0, JFFS2_BBC_ZLIB_BLOCK_SIGN_1, 0, 0},
2853 + NULL,
2854 + NULL,
2855 + NULL,
2856 + NULL,
2857 + jffs2_bbc_zlib_compress,
2858 + jffs2_bbc_zlib_estimate,
2859 + jffs2_bbc_zlib_decompress,
2860 + NULL,
2861 + NULL,
2862 + 1
2863 +};
2864 +
2865 +static struct jffs2_bbc_compressor_type *jffs2_bbc_original_compressor = &jffs2_bbc_zlib;
2866 +
2867 +#endif
2868 +
2869 +/*********************************************************************
2870 + * Compression mode handling *
2871 + *********************************************************************/
2872 +
2873 +int jffs2_bbc_get_compression_mode(void)
2874 +{
2875 + return jffs2_bbc_compression_mode;
2876 +}
2877 +
2878 +void jffs2_bbc_set_compression_mode(int mode)
2879 +{
2880 + jffs2_bbc_compression_mode = mode;
2881 +}
2882 +
2883 +void jffs2_bbc_set_manual_compressor(struct jffs2_bbc_compressor_type *c)
2884 +{
2885 + jffs2_bbc_manual_compressor = c;
2886 + jffs2_bbc_set_compression_mode(JFFS2_BBC_MANUAL_MODE);
2887 +}
2888 +
2889 +int jffs2_bbc_set_manual_compressor_by_name(char *name)
2890 +{
2891 + struct jffs2_bbc_compressor_type *l;
2892 + int i;
2893 +
2894 + l = jffs2_bbc_compressors;
2895 + while (l != NULL) {
2896 + for (i = 0; i < 1000; i++) {
2897 + if (l->name[i] == 0) {
2898 + jffs2_bbc_set_manual_compressor(l);
2899 + return 0;
2900 + }
2901 + else if (name[i] == 0)
2902 + i = 1000;
2903 + else if (name[i] != l->name[i])
2904 + i = 1000;
2905 + }
2906 + l = l->next;
2907 + }
2908 + jffs2_bbc_set_manual_compressor(NULL);
2909 + return 1;
2910 +}
2911 +
2912 +static struct jffs2_bbc_compressor_type *jffs2_bbc_get_compressor_by_name(char *name)
2913 +{
2914 + struct jffs2_bbc_compressor_type *l;
2915 + int i;
2916 +
2917 +#ifndef JFFS2_BBC_STANDALONE
2918 + l = jffs2_bbc_original_compressor;
2919 + for (i = 0; i < 1000; i++) {
2920 + if (l->name[i] == 0) {
2921 + return l;
2922 + }
2923 + else if (name[i] == 0)
2924 + i = 1000;
2925 + else if (name[i] != l->name[i])
2926 + i = 1000;
2927 + }
2928 +#endif
2929 +
2930 + l = jffs2_bbc_compressors;
2931 + while (l != NULL) {
2932 + for (i = 0; i < 1000; i++) {
2933 + if (l->name[i] == 0) {
2934 + return l;
2935 + }
2936 + else if (name[i] == 0)
2937 + i = 1000;
2938 + else if (name[i] != l->name[i])
2939 + i = 1000;
2940 + }
2941 + l = l->next;
2942 + }
2943 +
2944 + return NULL;
2945 +}
2946 +
2947 +int jffs2_bbc_disable_compressor_by_name(char *name)
2948 +{
2949 + struct jffs2_bbc_compressor_type *l;
2950 +
2951 + l = jffs2_bbc_get_compressor_by_name(name);
2952 + if (l == NULL) return 1;
2953 + l->enabled = 0;
2954 + return 0;
2955 +}
2956 +
2957 +int jffs2_bbc_enable_compressor_by_name(char *name)
2958 +{
2959 + struct jffs2_bbc_compressor_type *l;
2960 +
2961 + l = jffs2_bbc_get_compressor_by_name(name);
2962 + if (l == NULL) return 1;
2963 + l->enabled = 1;
2964 + return 0;
2965 +}
2966 +
2967 +void jffs2_bbc_compressor_command_by_name(char *name_and_command)
2968 +{
2969 + struct jffs2_bbc_compressor_type *l;
2970 + int i;
2971 +
2972 + l = jffs2_bbc_compressors;
2973 + while (l != NULL) {
2974 + for (i = 0; i < 1000; i++) {
2975 + if (l->name[i] == 0) {
2976 + if (name_and_command[i] != ':') {
2977 + jffs2_bbc_print1("jffs2.bbc: ':' missing after compressor name\n");
2978 + }
2979 + else {
2980 + if (l->proc_command != NULL)
2981 + l->proc_command(name_and_command + i + 1);
2982 + }
2983 + i = 1000;
2984 + return;
2985 + }
2986 + else if (name_and_command[i] == 0) {
2987 + i = 1000;
2988 + }
2989 + else if (name_and_command[i] != l->name[i]) {
2990 + i = 1000;
2991 + }
2992 + }
2993 + l = l->next;
2994 + }
2995 +}
2996 +
2997 +struct jffs2_bbc_compressor_type *jffs2_bbc_get_manual_compressor(void)
2998 +{
2999 + if (jffs2_bbc_get_compression_mode() != JFFS2_BBC_MANUAL_MODE) {
3000 + jffs2_bbc_manual_compressor = NULL;
3001 + }
3002 + return jffs2_bbc_manual_compressor;
3003 +}
3004 +
3005 +/*********************************************************************
3006 + * Compressor handling *
3007 + *********************************************************************/
3008 +
3009 +struct jffs2_bbc_compressor_type *jffs2_bbc_get_compressor_list(void)
3010 +{
3011 + return jffs2_bbc_compressors;
3012 +}
3013 +
3014 +struct jffs2_bbc_model_list_node *jffs2_bbc_get_model_list(void)
3015 +{
3016 + return jffs2_bbc_model_list;
3017 +}
3018 +
3019 +int jffs2_bbc_register_compressor(struct jffs2_bbc_compressor_type *c)
3020 +{
3021 + struct jffs2_bbc_compressor_type *l;
3022 + struct jffs2_bbc_model_list_node *l2;
3023 + int model_found = 0;
3024 +
3025 + l = jffs2_bbc_compressors;
3026 + /* Check for confilcts */
3027 + while (l != NULL) {
3028 + c->name[15] = 0;
3029 + /*if (strcmp(c->name,l->name)==0) {
3030 + jffs2_bbc_print1("jffs2.bbc: compressor is already loaded.");
3031 + return -1;
3032 + } */
3033 + if ((l->model_file_sign == c->model_file_sign) && (c->model_file_sign != 0)) {
3034 + jffs2_bbc_print1("jffs2.bbc: already used model file sign. fail.");
3035 + return -1;
3036 + }
3037 + l = l->next;
3038 + }
3039 + /* Search and initialize model */
3040 + c->models = NULL;
3041 + c->mounted = 0;
3042 + if (c->init != NULL) {
3043 + if (c->init() != 0) {
3044 + jffs2_bbc_print2("jffs2.bbc: cannot initialize compressor %s.\n", c->name);
3045 + return -1;
3046 + }
3047 + }
3048 + if (c->model_file_sign != 0) {
3049 + l2 = jffs2_bbc_model_list;
3050 + while (1) {
3051 + if (l2 == NULL)
3052 + break;
3053 + if (c->model_file_sign == l2->sign) {
3054 + if (l2->compressor != NULL) {
3055 + jffs2_bbc_print2("jffs2.bbc: register for %s: BUG, model file already reserved!!!!\n", c->name);
3056 + }
3057 + else {
3058 + if (c->init_model(&(l2->model)) != 0) {
3059 + jffs2_bbc_print2("jffs2.bbc: cannot initialize compressor %s for a model", c->name);
3060 + }
3061 + else {
3062 + l2->compressor = c;
3063 + l2->next_compr_model = c->models;
3064 + c->models = l2;
3065 + c->mounted++;
3066 + model_found++;
3067 + }
3068 + }
3069 + }
3070 + l2 = l2->next_model;
3071 + }
3072 + /*if (model_found==0) {
3073 + jffs2_bbc_print2("jffs2.bbc: no macthing model file found for %s at this time (maybe later)\n",c->name);
3074 + } */
3075 + }
3076 + /* Insert to the end of the compressor list */
3077 + c->enabled = 1;
3078 + c->buffer = NULL;
3079 + c->buffer_size = 0;
3080 + c->stat_compr_orig = c->stat_compr_new = c->stat_decompr = 0;
3081 + c->next = NULL;
3082 + if (jffs2_bbc_compressors == NULL) {
3083 + jffs2_bbc_compressors = c;
3084 + }
3085 + else {
3086 + l = jffs2_bbc_compressors;
3087 + while (l->next != NULL)
3088 + l = l->next;
3089 + l->next = c;
3090 + }
3091 + return 0;
3092 +}
3093 +
3094 +int jffs2_bbc_unregister_compressor(struct jffs2_bbc_compressor_type *c)
3095 +{
3096 + struct jffs2_bbc_compressor_type *l;
3097 + struct jffs2_bbc_model_list_node *l2;
3098 +
3099 + if (c->mounted != 0) {
3100 + jffs2_bbc_print1("jffs2.bbc: Compressor is in use. Sorry.");
3101 + return -1;
3102 + }
3103 + if (jffs2_bbc_compressors == NULL) {
3104 + jffs2_bbc_print1("jffs2.bbc: unregister: empty list.");
3105 + return -1;
3106 + }
3107 + else if (jffs2_bbc_compressors == c) {
3108 + if (c->deinit != NULL)
3109 + c->deinit();
3110 + jffs2_bbc_compressors = c->next;
3111 + }
3112 + else {
3113 + l = jffs2_bbc_compressors;
3114 + while (l->next != c) {
3115 + if (l->next == NULL) {
3116 + jffs2_bbc_print2("jffs2.bbc: unregister: cannot find compressor %s in the list.", c->name);
3117 + return -1;
3118 + }
3119 + l = l->next;
3120 + }
3121 + if (c->deinit != NULL)
3122 + c->deinit();
3123 + l->next = c->next;
3124 + }
3125 + if (c->buffer != NULL) {
3126 + jffs2_bbc_free(c->buffer);
3127 + c->buffer = NULL;
3128 + c->buffer_size = 0;
3129 + }
3130 +
3131 + l2 = jffs2_bbc_model_list;
3132 + while (l2 != NULL) {
3133 + if (l2->compressor == c) {
3134 + jffs2_bbc_print1("jffs2.bbc: unregister: BUG: model found!!!");
3135 + l2->compressor = NULL;
3136 + l2->next_compr_model = NULL;
3137 + }
3138 + l2 = l2->next_model;
3139 + }
3140 +
3141 + return 0;
3142 +}
3143 +
3144 +int jffs2_bbc_model_new(void *sb, int i_num, void *model)
3145 +{
3146 + struct jffs2_bbc_model_list_node *node;
3147 + struct jffs2_bbc_compressor_type *l;
3148 + char block_sign[2];
3149 +
3150 + int sign;
3151 +
3152 + /* check for conflicts... */
3153 + sign = *((int *) model);
3154 + block_sign[0] = *(((char *) model) + 4);
3155 + block_sign[1] = *(((char *) model) + 5);
3156 + node = jffs2_bbc_model_list;
3157 + while (node != NULL) {
3158 + if ((node->block_sign[0] == block_sign[0]) && (node->block_sign[1] == block_sign[1]) && (node->sb == sb)) {
3159 + //jffs2_bbc_print2("jffs2.bbc: model_new: model conflict (inode=%d)!\n",i_num);
3160 + return -1;
3161 + }
3162 + node = node->next_model;
3163 + }
3164 +
3165 + /* insertion */
3166 + node = jffs2_bbc_malloc_small((long)sizeof(struct jffs2_bbc_model_list_node));
3167 + node->sb = sb;
3168 + node->model = model;
3169 + node->sign = *((int *) model);
3170 + node->block_sign[0] = *(((char *) model) + 4);
3171 + node->block_sign[1] = *(((char *) model) + 5);
3172 + node->inode = i_num;
3173 + node->next_model = jffs2_bbc_model_list;
3174 + node->compressor = NULL;
3175 + node->stat_decompr = 0;
3176 + node->next_compr_model = NULL;
3177 + jffs2_bbc_model_list = node;
3178 +
3179 + /* search for matching compressor */
3180 + l = jffs2_bbc_compressors;
3181 + while (l != NULL) {
3182 + if (l->model_file_sign == sign) {
3183 + //jffs2_bbc_print2("jffs2.bbc: compressor for model found: %s ",l->name);
3184 + if (l->init_model(&(node->model)) != 0) {
3185 + jffs2_bbc_print1("jffs2.bbc: cannot initialize compressor for a model");
3186 + }
3187 + else {
3188 + l->mounted++;
3189 + node->compressor = l;
3190 + node->next_compr_model = l->models;
3191 + l->models = node;
3192 + }
3193 + break;
3194 + }
3195 + l = l->next;
3196 + }
3197 + return 0;
3198 +}
3199 +
3200 +static void jffs2_bbc_model_del_from_compressor(struct jffs2_bbc_model_list_node *node)
3201 +{
3202 + struct jffs2_bbc_model_list_node *l;
3203 +
3204 + if (node->model != NULL) {
3205 + if (node->compressor != NULL) {
3206 + if (node->compressor->destroy_model == NULL) {
3207 + jffs2_bbc_free(node->model);
3208 + node->model = NULL;
3209 + }
3210 + else {
3211 + node->compressor->destroy_model(&(node->model));
3212 + if (node->model != NULL)
3213 + jffs2_bbc_print1("jffs2.bbc: warning: not NULL model after destroying!\n");
3214 + }
3215 + }
3216 + }
3217 +
3218 + if (node->compressor == NULL) {
3219 + jffs2_bbc_print1("jffs2.bbc: jffs2_bbc_model_del_from_compressor: no compressor!\n");
3220 + return;
3221 + }
3222 + l = node->compressor->models;
3223 + if (l == NULL) {
3224 + jffs2_bbc_print1("jffs2.bbc: jffs2_bbc_model_del_from_compressor error, models=NULL!\n");
3225 + return;
3226 + }
3227 + if (l == node) {
3228 + node->compressor->models = node->next_compr_model;
3229 + node->compressor->mounted--;
3230 + return;
3231 + }
3232 + while (1) {
3233 + if (l->next_compr_model == node) {
3234 + l->next_compr_model = node->next_compr_model;
3235 + node->compressor->mounted--;
3236 + return;
3237 + }
3238 + l = l->next_compr_model;
3239 + if (l == NULL) {
3240 + jffs2_bbc_print1("jffs2.bbc: jffs2_bbc_model_del_from_compressor: not found\n");
3241 + return;
3242 + }
3243 + }
3244 +}
3245 +
3246 +void jffs2_bbc_model_del(void *sb)
3247 +{
3248 + struct jffs2_bbc_model_list_node *l, *l2;
3249 +
3250 + l = jffs2_bbc_model_list;
3251 + if (l == NULL)
3252 + return;
3253 + if (l->sb == sb) {
3254 + jffs2_bbc_model_list = l->next_model;
3255 + jffs2_bbc_model_del_from_compressor(l);
3256 + jffs2_bbc_free_small(l);
3257 + jffs2_bbc_model_del(sb);
3258 + return;
3259 + }
3260 + while (1) {
3261 + if (l->next_model == NULL) {
3262 + break;
3263 + }
3264 + if (l->next_model->sb == sb) {
3265 + l2 = l->next_model;
3266 + l->next_model = l->next_model->next_model;
3267 + jffs2_bbc_model_del_from_compressor(l2);
3268 + jffs2_bbc_free_small(l2);
3269 + jffs2_bbc_model_del(sb);
3270 + return;
3271 + }
3272 + l = l->next_model;
3273 + }
3274 + last_sb = NULL;
3275 +}
3276 +
3277 +void jffs2_bbc_model_set_act_sb(void *sb)
3278 +{
3279 + last_sb = sb;
3280 +}
3281 +
3282 +void *jffs2_bbc_model_get_act_sb(void)
3283 +{
3284 + return last_sb;
3285 +}
3286 +
3287 +void *jffs2_bbc_model_get_newest(struct jffs2_bbc_compressor_type *compressor)
3288 +{
3289 + struct jffs2_bbc_model_list_node *m, *best_m;
3290 + int max_sign, sign;
3291 +
3292 + if (compressor == NULL) {
3293 + jffs2_bbc_print1("jffs2.bbc: jffs2_bbc_model_get: NULL!!\n");
3294 + return NULL;
3295 + }
3296 +
3297 + best_m = NULL;
3298 + max_sign = -1;
3299 + m = compressor->models;
3300 + while (m != NULL) {
3301 + if (m->sb == last_sb) {
3302 + sign = (int) (m->block_sign[0]) * 256 + (int) (m->block_sign[1]);
3303 + if (sign > max_sign) {
3304 + max_sign = sign;
3305 + best_m = m;
3306 + }
3307 + }
3308 + m = m->next_compr_model;
3309 + }
3310 + if (best_m != NULL)
3311 + return best_m->model;
3312 + else
3313 + return NULL;
3314 +}
3315 +
3316 +/*********************************************************************
3317 + * Statistics *
3318 + *********************************************************************/
3319 +
3320 +static char *jffs2_bbc_stat_buff = NULL;
3321 +
3322 +char *jffs2_bbc_get_model_stats(void)
3323 +{
3324 + char *b;
3325 + struct jffs2_bbc_model_list_node *m;
3326 + struct jffs2_bbc_compressor_type *c;
3327 +
3328 + if (jffs2_bbc_stat_buff == NULL)
3329 + jffs2_bbc_stat_buff = jffs2_bbc_malloc(8000);
3330 +
3331 + b = jffs2_bbc_stat_buff;
3332 +
3333 + b += sprintf(b, "Loaded compressors:");
3334 + c = jffs2_bbc_compressors;
3335 + while (c != NULL) {
3336 + b += sprintf(b, "\n %s (%d) ", c->name, c->enabled);
3337 + if (c->model_file_sign != 0) {
3338 + b += sprintf(b, "m_sign=%d ", c->model_file_sign);
3339 + b += sprintf(b, "models=");
3340 + m = c->models;
3341 + while (m != NULL) {
3342 + b += sprintf(b, "(inode=%d)", m->inode);
3343 + m = m->next_compr_model;
3344 + }
3345 + }
3346 + else {
3347 + b += sprintf(b, "b_sign=(%d,%d) nomodel", (int) (c->block_sign[0]), (int) (c->block_sign[1]));
3348 + }
3349 + if (c->proc_info != NULL) {
3350 + b += sprintf(b, "\n %s", c->proc_info());
3351 + }
3352 + c = c->next;
3353 + }
3354 +
3355 + m = jffs2_bbc_model_list;
3356 +
3357 + if (m == NULL) {
3358 + b += sprintf(b, "\nPresent models: NONE\n");
3359 + }
3360 + else {
3361 + b += sprintf(b, "\nPresent models:\n");
3362 + while (m != NULL) {
3363 + b += sprintf(b, " b_sign=(%d,%d),inode=%d,decompr=%d", (int) (m->block_sign[0]), (int) (m->block_sign[1]), m->inode, m->stat_decompr);
3364 + if (m->compressor == NULL)
3365 + b += sprintf(b, ",compressor=NULL\n");
3366 + else
3367 + b += sprintf(b, ",compressor=%s\n", m->compressor->name);
3368 + m = m->next_model;
3369 + }
3370 + }
3371 +
3372 + return jffs2_bbc_stat_buff;
3373 +}
3374 +
3375 +/*********************************************************************
3376 + * Memory handling, debug *
3377 + *********************************************************************/
3378 +
3379 +static int jffs2_bbc_mem_counter = 0;
3380 +
3381 +#ifdef __KERNEL__
3382 +
3383 +void *jffs2_bbc_malloc(long size)
3384 +{
3385 + void *addr = vmalloc(size);
3386 + if (addr != NULL)
3387 + jffs2_bbc_mem_counter++;
3388 + else {
3389 + jffs2_bbc_print2("DEBUG: not enough memory (%ld)\n", size);
3390 + }
3391 + return addr;
3392 +}
3393 +
3394 +void jffs2_bbc_free(void *addr)
3395 +{
3396 + jffs2_bbc_mem_counter--;
3397 + vfree(addr);
3398 +}
3399 +
3400 +void *jffs2_bbc_malloc_small(long size)
3401 +{
3402 + void *addr;
3403 + addr = kmalloc(size, 0);
3404 + if (addr != NULL)
3405 + jffs2_bbc_mem_counter++;
3406 + return addr;
3407 +}
3408 +
3409 +void jffs2_bbc_free_small(void *addr)
3410 +{
3411 + jffs2_bbc_mem_counter--;
3412 + kfree(addr);
3413 +}
3414 +
3415 +#else
3416 +
3417 +void *jffs2_bbc_malloc(long size)
3418 +{
3419 + void *addr = malloc(size);
3420 + if (addr != NULL)
3421 + jffs2_bbc_mem_counter++;
3422 + return addr;
3423 +}
3424 +
3425 +void jffs2_bbc_free(void *addr)
3426 +{
3427 + jffs2_bbc_mem_counter--;
3428 + free(addr);
3429 +}
3430 +
3431 +void *jffs2_bbc_malloc_small(long size)
3432 +{
3433 + return jffs2_bbc_malloc(size);
3434 +}
3435 +
3436 +void jffs2_bbc_free_small(void *addr)
3437 +{
3438 + jffs2_bbc_free(addr);
3439 +}
3440 +
3441 +#endif
3442 +
3443 +int jffs2_bbc_test_memory_counter(int verbose)
3444 +{
3445 + if (verbose > 0) {
3446 + jffs2_bbc_print2("jffs2.bbc: mem_counter=%d!\n", jffs2_bbc_mem_counter);
3447 + }
3448 + return jffs2_bbc_mem_counter;
3449 +}
3450 +
3451 +int jffs2_bbc_get_memory_counter(void)
3452 +{
3453 + return jffs2_bbc_mem_counter;
3454 +}
3455 +
3456 +static char mem_stat[200];
3457 +
3458 +char *jffs2_bbc_get_mem_stats(void)
3459 +{
3460 + sprintf(mem_stat, "Memcounter=%d\n", jffs2_bbc_mem_counter);
3461 + return mem_stat;
3462 +}
3463 +
3464 +void jffs2_bbc_print_flush(void)
3465 +{
3466 +#ifdef __KERNEL__
3467 + return;
3468 +#else
3469 + fflush(stdout);
3470 + fflush(stderr);
3471 +#endif
3472 +}
3473 +
3474 +/*********************************************************************
3475 + * FRAMEWORK - ZLIB REPLACEMENT *
3476 + *********************************************************************/
3477 +
3478 +#ifndef JFFS2_BBC_STANDALONE
3479 +
3480 +/* Temorary buffers */
3481 +static char stat_str[JFFS2_BBC_STAT_BUFF_SIZE];
3482 +static int tmp_buffer_size = 0;
3483 +static char *tmp_buffer = NULL;
3484 +
3485 +/* Statistic - used by /proc/jffs2_bbc and mkfs.jffs2 */
3486 +char *jffs2_bbc_get_compr_stats(void)
3487 +{
3488 + struct jffs2_bbc_compressor_type *l;
3489 + char *s = stat_str;
3490 +
3491 + s += sprintf(s, "Compression statistics:\n");
3492 + l = jffs2_bbc_original_compressor;
3493 + //s += sprintf(s, " zlib: compr=%d/%d decompr=%d\n", stat_zlib_compr_new, stat_zlib_compr_orig, stat_zlib_decompr);