~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/jffs2/compr_rtime.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/jffs2/compr_rtime.c (Version linux-6.12-rc7) and /fs/jffs2/compr_rtime.c (Version linux-5.16.20)


  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 © 2001-2007 Red Hat, Inc.
  5  * Copyright © 2004-2010 David Woodhouse <dwm      5  * Copyright © 2004-2010 David Woodhouse <dwmw2@infradead.org>
  6  *                                                  6  *
  7  * Created by Arjan van de Ven <arjanv@redhat.      7  * Created by Arjan van de Ven <arjanv@redhat.com>
  8  *                                                  8  *
  9  * For licensing information, see the file 'LI      9  * For licensing information, see the file 'LICENCE' in this directory.
 10  *                                                 10  *
 11  *                                                 11  *
 12  *                                                 12  *
 13  * Very simple lz77-ish encoder.                   13  * Very simple lz77-ish encoder.
 14  *                                                 14  *
 15  * Theory of operation: Both encoder and decod     15  * Theory of operation: Both encoder and decoder have a list of "last
 16  * occurrences" for every possible source-valu     16  * occurrences" for every possible source-value; after sending the
 17  * first source-byte, the second byte indicate     17  * first source-byte, the second byte indicated the "run" length of
 18  * matches                                         18  * matches
 19  *                                                 19  *
 20  * The algorithm is intended to only send "who     20  * The algorithm is intended to only send "whole bytes", no bit-messing.
 21  *                                                 21  *
 22  */                                                22  */
 23                                                    23 
 24 #include <linux/kernel.h>                          24 #include <linux/kernel.h>
 25 #include <linux/types.h>                           25 #include <linux/types.h>
 26 #include <linux/errno.h>                           26 #include <linux/errno.h>
 27 #include <linux/string.h>                          27 #include <linux/string.h>
 28 #include <linux/jffs2.h>                           28 #include <linux/jffs2.h>
 29 #include "compr.h"                                 29 #include "compr.h"
 30                                                    30 
 31 /* _compress returns the compressed size, -1 i     31 /* _compress returns the compressed size, -1 if bigger */
 32 static int jffs2_rtime_compress(unsigned char      32 static int jffs2_rtime_compress(unsigned char *data_in,
 33                                 unsigned char      33                                 unsigned char *cpage_out,
 34                                 uint32_t *sour     34                                 uint32_t *sourcelen, uint32_t *dstlen)
 35 {                                                  35 {
 36         unsigned short positions[256];             36         unsigned short positions[256];
 37         int outpos = 0;                            37         int outpos = 0;
 38         int pos=0;                                 38         int pos=0;
 39                                                    39 
 40         if (*dstlen <= 3)                          40         if (*dstlen <= 3)
 41                 return -1;                         41                 return -1;
 42                                                    42 
 43         memset(positions,0,sizeof(positions));     43         memset(positions,0,sizeof(positions));
 44                                                    44 
 45         while (pos < (*sourcelen) && outpos <=     45         while (pos < (*sourcelen) && outpos <= (*dstlen)-2) {
 46                 int backpos, runlen=0;             46                 int backpos, runlen=0;
 47                 unsigned char value;               47                 unsigned char value;
 48                                                    48 
 49                 value = data_in[pos];              49                 value = data_in[pos];
 50                                                    50 
 51                 cpage_out[outpos++] = data_in[     51                 cpage_out[outpos++] = data_in[pos++];
 52                                                    52 
 53                 backpos = positions[value];        53                 backpos = positions[value];
 54                 positions[value]=pos;              54                 positions[value]=pos;
 55                                                    55 
 56                 while ((backpos < pos) && (pos     56                 while ((backpos < pos) && (pos < (*sourcelen)) &&
 57                        (data_in[pos]==data_in[     57                        (data_in[pos]==data_in[backpos++]) && (runlen<255)) {
 58                         pos++;                     58                         pos++;
 59                         runlen++;                  59                         runlen++;
 60                 }                                  60                 }
 61                 cpage_out[outpos++] = runlen;      61                 cpage_out[outpos++] = runlen;
 62         }                                          62         }
 63                                                    63 
 64         if (outpos >= pos) {                       64         if (outpos >= pos) {
 65                 /* We failed */                    65                 /* We failed */
 66                 return -1;                         66                 return -1;
 67         }                                          67         }
 68                                                    68 
 69         /* Tell the caller how much we managed     69         /* Tell the caller how much we managed to compress, and how much space it took */
 70         *sourcelen = pos;                          70         *sourcelen = pos;
 71         *dstlen = outpos;                          71         *dstlen = outpos;
 72         return 0;                                  72         return 0;
 73 }                                                  73 }
 74                                                    74 
 75                                                    75 
 76 static int jffs2_rtime_decompress(unsigned cha     76 static int jffs2_rtime_decompress(unsigned char *data_in,
 77                                   unsigned cha     77                                   unsigned char *cpage_out,
 78                                   uint32_t src     78                                   uint32_t srclen, uint32_t destlen)
 79 {                                                  79 {
 80         unsigned short positions[256];             80         unsigned short positions[256];
 81         int outpos = 0;                            81         int outpos = 0;
 82         int pos=0;                                 82         int pos=0;
 83                                                    83 
 84         memset(positions,0,sizeof(positions));     84         memset(positions,0,sizeof(positions));
 85                                                    85 
 86         while (outpos<destlen) {                   86         while (outpos<destlen) {
 87                 unsigned char value;               87                 unsigned char value;
 88                 int backoffs;                      88                 int backoffs;
 89                 int repeat;                        89                 int repeat;
 90                                                    90 
 91                 value = data_in[pos++];            91                 value = data_in[pos++];
 92                 cpage_out[outpos++] = value; /     92                 cpage_out[outpos++] = value; /* first the verbatim copied byte */
 93                 repeat = data_in[pos++];           93                 repeat = data_in[pos++];
 94                 backoffs = positions[value];       94                 backoffs = positions[value];
 95                                                    95 
 96                 positions[value]=outpos;           96                 positions[value]=outpos;
 97                 if (repeat) {                      97                 if (repeat) {
 98                         if (backoffs + repeat      98                         if (backoffs + repeat >= outpos) {
 99                                 while(repeat)      99                                 while(repeat) {
100                                         cpage_    100                                         cpage_out[outpos++] = cpage_out[backoffs++];
101                                         repeat    101                                         repeat--;
102                                 }                 102                                 }
103                         } else {                  103                         } else {
104                                 memcpy(&cpage_    104                                 memcpy(&cpage_out[outpos],&cpage_out[backoffs],repeat);
105                                 outpos+=repeat    105                                 outpos+=repeat;
106                         }                         106                         }
107                 }                                 107                 }
108         }                                         108         }
109         return 0;                                 109         return 0;
110 }                                                 110 }
111                                                   111 
112 static struct jffs2_compressor jffs2_rtime_com    112 static struct jffs2_compressor jffs2_rtime_comp = {
113     .priority = JFFS2_RTIME_PRIORITY,             113     .priority = JFFS2_RTIME_PRIORITY,
114     .name = "rtime",                              114     .name = "rtime",
115     .compr = JFFS2_COMPR_RTIME,                   115     .compr = JFFS2_COMPR_RTIME,
116     .compress = &jffs2_rtime_compress,            116     .compress = &jffs2_rtime_compress,
117     .decompress = &jffs2_rtime_decompress,        117     .decompress = &jffs2_rtime_decompress,
118 #ifdef JFFS2_RTIME_DISABLED                       118 #ifdef JFFS2_RTIME_DISABLED
119     .disabled = 1,                                119     .disabled = 1,
120 #else                                             120 #else
121     .disabled = 0,                                121     .disabled = 0,
122 #endif                                            122 #endif
123 };                                                123 };
124                                                   124 
125 int jffs2_rtime_init(void)                        125 int jffs2_rtime_init(void)
126 {                                                 126 {
127     return jffs2_register_compressor(&jffs2_rt    127     return jffs2_register_compressor(&jffs2_rtime_comp);
128 }                                                 128 }
129                                                   129 
130 void jffs2_rtime_exit(void)                       130 void jffs2_rtime_exit(void)
131 {                                                 131 {
132     jffs2_unregister_compressor(&jffs2_rtime_c    132     jffs2_unregister_compressor(&jffs2_rtime_comp);
133 }                                                 133 }
134                                                   134 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php