1*fe8c2806Swdenk /*
2*fe8c2806Swdenk * JFFS2 -- Journalling Flash File System, Version 2.
3*fe8c2806Swdenk *
4*fe8c2806Swdenk * Copyright (C) 2001 Red Hat, Inc.
5*fe8c2806Swdenk *
6*fe8c2806Swdenk * Created by Arjan van de Ven <arjanv@redhat.com>
7*fe8c2806Swdenk *
8*fe8c2806Swdenk * The original JFFS, from which the design for JFFS2 was derived,
9*fe8c2806Swdenk * was designed and implemented by Axis Communications AB.
10*fe8c2806Swdenk *
11*fe8c2806Swdenk * The contents of this file are subject to the Red Hat eCos Public
12*fe8c2806Swdenk * License Version 1.1 (the "Licence"); you may not use this file
13*fe8c2806Swdenk * except in compliance with the Licence. You may obtain a copy of
14*fe8c2806Swdenk * the Licence at http://www.redhat.com/
15*fe8c2806Swdenk *
16*fe8c2806Swdenk * Software distributed under the Licence is distributed on an "AS IS"
17*fe8c2806Swdenk * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
18*fe8c2806Swdenk * See the Licence for the specific language governing rights and
19*fe8c2806Swdenk * limitations under the Licence.
20*fe8c2806Swdenk *
21*fe8c2806Swdenk * The Original Code is JFFS2 - Journalling Flash File System, version 2
22*fe8c2806Swdenk *
23*fe8c2806Swdenk * Alternatively, the contents of this file may be used under the
24*fe8c2806Swdenk * terms of the GNU General Public License version 2 (the "GPL"), in
25*fe8c2806Swdenk * which case the provisions of the GPL are applicable instead of the
26*fe8c2806Swdenk * above. If you wish to allow the use of your version of this file
27*fe8c2806Swdenk * only under the terms of the GPL and not to allow others to use your
28*fe8c2806Swdenk * version of this file under the RHEPL, indicate your decision by
29*fe8c2806Swdenk * deleting the provisions above and replace them with the notice and
30*fe8c2806Swdenk * other provisions required by the GPL. If you do not delete the
31*fe8c2806Swdenk * provisions above, a recipient may use your version of this file
32*fe8c2806Swdenk * under either the RHEPL or the GPL.
33*fe8c2806Swdenk *
34*fe8c2806Swdenk * $Id: compr_rtime.c,v 1.2 2002/01/24 22:58:42 rfeany Exp $
35*fe8c2806Swdenk *
36*fe8c2806Swdenk *
37*fe8c2806Swdenk * Very simple lz77-ish encoder.
38*fe8c2806Swdenk *
39*fe8c2806Swdenk * Theory of operation: Both encoder and decoder have a list of "last
40*fe8c2806Swdenk * occurances" for every possible source-value; after sending the
41*fe8c2806Swdenk * first source-byte, the second byte indicated the "run" length of
42*fe8c2806Swdenk * matches
43*fe8c2806Swdenk *
44*fe8c2806Swdenk * The algorithm is intended to only send "whole bytes", no bit-messing.
45*fe8c2806Swdenk *
46*fe8c2806Swdenk */
47*fe8c2806Swdenk
48*fe8c2806Swdenk #include <config.h>
49*fe8c2806Swdenk #include <jffs2/jffs2.h>
50*fe8c2806Swdenk
rtime_decompress(unsigned char * data_in,unsigned char * cpage_out,u32 srclen,u32 destlen)51*fe8c2806Swdenk void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out,
52*fe8c2806Swdenk u32 srclen, u32 destlen)
53*fe8c2806Swdenk {
54*fe8c2806Swdenk int positions[256];
55*fe8c2806Swdenk int outpos;
56*fe8c2806Swdenk int pos;
57*fe8c2806Swdenk int i;
58*fe8c2806Swdenk
59*fe8c2806Swdenk outpos = pos = 0;
60*fe8c2806Swdenk
61*fe8c2806Swdenk for (i = 0; i < 256; positions[i++] = 0);
62*fe8c2806Swdenk
63*fe8c2806Swdenk while (outpos<destlen) {
64*fe8c2806Swdenk unsigned char value;
65*fe8c2806Swdenk int backoffs;
66*fe8c2806Swdenk int repeat;
67*fe8c2806Swdenk
68*fe8c2806Swdenk value = data_in[pos++];
69*fe8c2806Swdenk cpage_out[outpos++] = value; /* first the verbatim copied byte */
70*fe8c2806Swdenk repeat = data_in[pos++];
71*fe8c2806Swdenk backoffs = positions[value];
72*fe8c2806Swdenk
73*fe8c2806Swdenk positions[value]=outpos;
74*fe8c2806Swdenk if (repeat) {
75*fe8c2806Swdenk if (backoffs + repeat >= outpos) {
76*fe8c2806Swdenk while(repeat) {
77*fe8c2806Swdenk cpage_out[outpos++] = cpage_out[backoffs++];
78*fe8c2806Swdenk repeat--;
79*fe8c2806Swdenk }
80*fe8c2806Swdenk } else {
81*fe8c2806Swdenk for (i = 0; i < repeat; i++)
82*fe8c2806Swdenk *(cpage_out + outpos + i) = *(cpage_out + backoffs + i);
83*fe8c2806Swdenk outpos+=repeat;
84*fe8c2806Swdenk }
85*fe8c2806Swdenk }
86*fe8c2806Swdenk }
87*fe8c2806Swdenk }
88