1 /* 1 /* 2 * JFFS2 -- Journalling Flash File System, Ver 2 * JFFS2 -- Journalling Flash File System, Version 2. 3 * 3 * 4 * Copyright © 2001-2007 Red Hat, Inc. !! 4 * Copyright (C) 2001 Red Hat, Inc. 5 * Copyright © 2004-2010 David Woodhouse <dwm << 6 * 5 * 7 * Created by Arjan van de Ven <arjanv@redhat. 6 * Created by Arjan van de Ven <arjanv@redhat.com> 8 * 7 * 9 * For licensing information, see the file 'LI !! 8 * The original JFFS, from which the design for JFFS2 was derived, >> 9 * was designed and implemented by Axis Communications AB. 10 * 10 * >> 11 * The contents of this file are subject to the Red Hat eCos Public >> 12 * License Version 1.1 (the "Licence"); you may not use this file >> 13 * except in compliance with the Licence. You may obtain a copy of >> 14 * the Licence at http://www.redhat.com/ >> 15 * >> 16 * Software distributed under the Licence is distributed on an "AS IS" >> 17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. >> 18 * See the Licence for the specific language governing rights and >> 19 * limitations under the Licence. >> 20 * >> 21 * The Original Code is JFFS2 - Journalling Flash File System, version 2 >> 22 * >> 23 * Alternatively, the contents of this file may be used under the >> 24 * terms of the GNU General Public License version 2 (the "GPL"), in >> 25 * which case the provisions of the GPL are applicable instead of the >> 26 * above. If you wish to allow the use of your version of this file >> 27 * only under the terms of the GPL and not to allow others to use your >> 28 * version of this file under the RHEPL, indicate your decision by >> 29 * deleting the provisions above and replace them with the notice and >> 30 * other provisions required by the GPL. If you do not delete the >> 31 * provisions above, a recipient may use your version of this file >> 32 * under either the RHEPL or the GPL. >> 33 * >> 34 * $Id: compr_rtime.c,v 1.5 2001/03/15 15:38:23 dwmw2 Exp $ 11 * 35 * 12 * 36 * 13 * Very simple lz77-ish encoder. 37 * Very simple lz77-ish encoder. 14 * 38 * 15 * Theory of operation: Both encoder and decod 39 * Theory of operation: Both encoder and decoder have a list of "last 16 * occurrences" for every possible source-valu !! 40 * occurances" for every possible source-value; after sending the 17 * first source-byte, the second byte indicate 41 * first source-byte, the second byte indicated the "run" length of 18 * matches 42 * matches 19 * 43 * 20 * The algorithm is intended to only send "who 44 * The algorithm is intended to only send "whole bytes", no bit-messing. 21 * 45 * 22 */ 46 */ 23 47 24 #include <linux/kernel.h> 48 #include <linux/kernel.h> 25 #include <linux/types.h> 49 #include <linux/types.h> 26 #include <linux/errno.h> 50 #include <linux/errno.h> 27 #include <linux/string.h> !! 51 #include <linux/string.h> 28 #include <linux/jffs2.h> << 29 #include "compr.h" << 30 52 31 /* _compress returns the compressed size, -1 i 53 /* _compress returns the compressed size, -1 if bigger */ 32 static int jffs2_rtime_compress(unsigned char !! 54 int rtime_compress(unsigned char *data_in, unsigned char *cpage_out, 33 unsigned char !! 55 __u32 *sourcelen, __u32 *dstlen) 34 uint32_t *sour << 35 { 56 { 36 unsigned short positions[256]; !! 57 int positions[256]; 37 int outpos = 0; 58 int outpos = 0; 38 int pos=0; 59 int pos=0; 39 60 40 if (*dstlen <= 3) !! 61 memset(positions,0,sizeof(positions)); 41 return -1; !! 62 42 << 43 memset(positions,0,sizeof(positions)); << 44 << 45 while (pos < (*sourcelen) && outpos <= 63 while (pos < (*sourcelen) && outpos <= (*dstlen)-2) { 46 int backpos, runlen=0; 64 int backpos, runlen=0; 47 unsigned char value; 65 unsigned char value; 48 !! 66 49 value = data_in[pos]; 67 value = data_in[pos]; 50 68 51 cpage_out[outpos++] = data_in[ 69 cpage_out[outpos++] = data_in[pos++]; 52 !! 70 53 backpos = positions[value]; 71 backpos = positions[value]; 54 positions[value]=pos; 72 positions[value]=pos; 55 !! 73 56 while ((backpos < pos) && (pos 74 while ((backpos < pos) && (pos < (*sourcelen)) && 57 (data_in[pos]==data_in[ 75 (data_in[pos]==data_in[backpos++]) && (runlen<255)) { 58 pos++; 76 pos++; 59 runlen++; 77 runlen++; 60 } 78 } 61 cpage_out[outpos++] = runlen; 79 cpage_out[outpos++] = runlen; 62 } 80 } 63 81 64 if (outpos >= pos) { 82 if (outpos >= pos) { 65 /* We failed */ 83 /* We failed */ 66 return -1; 84 return -1; 67 } 85 } 68 !! 86 69 /* Tell the caller how much we managed 87 /* Tell the caller how much we managed to compress, and how much space it took */ 70 *sourcelen = pos; 88 *sourcelen = pos; 71 *dstlen = outpos; 89 *dstlen = outpos; 72 return 0; 90 return 0; 73 } !! 91 } 74 92 75 93 76 static int jffs2_rtime_decompress(unsigned cha !! 94 void rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, 77 unsigned cha !! 95 __u32 srclen, __u32 destlen) 78 uint32_t src << 79 { 96 { 80 unsigned short positions[256]; !! 97 int positions[256]; 81 int outpos = 0; 98 int outpos = 0; 82 int pos=0; 99 int pos=0; 83 !! 100 84 memset(positions,0,sizeof(positions)); !! 101 memset(positions,0,sizeof(positions)); 85 !! 102 86 while (outpos<destlen) { 103 while (outpos<destlen) { 87 unsigned char value; 104 unsigned char value; 88 int backoffs; 105 int backoffs; 89 int repeat; 106 int repeat; 90 !! 107 91 value = data_in[pos++]; 108 value = data_in[pos++]; 92 cpage_out[outpos++] = value; / 109 cpage_out[outpos++] = value; /* first the verbatim copied byte */ 93 repeat = data_in[pos++]; 110 repeat = data_in[pos++]; 94 backoffs = positions[value]; 111 backoffs = positions[value]; 95 !! 112 96 positions[value]=outpos; 113 positions[value]=outpos; 97 if (repeat) { 114 if (repeat) { 98 if (backoffs + repeat 115 if (backoffs + repeat >= outpos) { 99 while(repeat) 116 while(repeat) { 100 cpage_ 117 cpage_out[outpos++] = cpage_out[backoffs++]; 101 repeat 118 repeat--; 102 } 119 } 103 } else { 120 } else { 104 memcpy(&cpage_ 121 memcpy(&cpage_out[outpos],&cpage_out[backoffs],repeat); 105 outpos+=repeat !! 122 outpos+=repeat; 106 } 123 } 107 } 124 } 108 } !! 125 } 109 return 0; !! 126 } 110 } << 111 << 112 static struct jffs2_compressor jffs2_rtime_com << 113 .priority = JFFS2_RTIME_PRIORITY, << 114 .name = "rtime", << 115 .compr = JFFS2_COMPR_RTIME, << 116 .compress = &jffs2_rtime_compress, << 117 .decompress = &jffs2_rtime_decompress, << 118 #ifdef JFFS2_RTIME_DISABLED << 119 .disabled = 1, << 120 #else << 121 .disabled = 0, << 122 #endif << 123 }; << 124 127 125 int jffs2_rtime_init(void) << 126 { << 127 return jffs2_register_compressor(&jffs2_rt << 128 } << 129 128 130 void jffs2_rtime_exit(void) << 131 { << 132 jffs2_unregister_compressor(&jffs2_rtime_c << 133 } << 134 129
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.