kernel-power v49 -> kernel-bfs
[kernel-bfs] / kernel-bfs-2.6.28 / debian / patches / nokia-20094102.6+0m5.diff
1 diff -Nurp kernel-2.6.28-20094102.3+0m5/crypto/lzo.c kernel-2.6.28-20094102.6+0m5/crypto/lzo.c
2 --- kernel-2.6.28-20094102.3+0m5/crypto/lzo.c   2008-12-25 00:26:37.000000000 +0100
3 +++ kernel-2.6.28-20094102.6+0m5/crypto/lzo.c   2011-09-04 11:36:23.000000000 +0200
4 @@ -37,6 +37,17 @@ static int lzo_init(struct crypto_tfm *t
5         return 0;
6  }
7  
8 +static int lzo999_init(struct crypto_tfm *tfm)
9 +{
10 +       struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
11 +
12 +       ctx->lzo_comp_mem = vmalloc(LZO1X_999_MEM_COMPRESS);
13 +       if (!ctx->lzo_comp_mem)
14 +               return -ENOMEM;
15 +
16 +       return 0;
17 +}
18 +
19  static void lzo_exit(struct crypto_tfm *tfm)
20  {
21         struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
22 @@ -60,6 +71,24 @@ static int lzo_compress(struct crypto_tf
23         return 0;
24  }
25  
26 +static int lzo999_compress(struct crypto_tfm *tfm, const u8 *src,
27 +                           unsigned int slen, u8 *dst, unsigned int *dlen)
28 +{
29 +       struct lzo_ctx *ctx = crypto_tfm_ctx(tfm);
30 +       size_t tmp_len = *dlen; /* size_t(ulong) <-> uint on 64 bit */
31 +       int err;
32 +
33 +       err = lzo1x_999_compress_level(src, slen, dst, &tmp_len,
34 +                                      ctx->lzo_comp_mem, NULL, 0 ,
35 +                                      (lzo_progress_callback_t) 0, 7);
36 +
37 +       if (err != LZO_E_OK)
38 +               return -EINVAL;
39 +
40 +       *dlen = tmp_len;
41 +       return 0;
42 +}
43 +
44  static int lzo_decompress(struct crypto_tfm *tfm, const u8 *src,
45                               unsigned int slen, u8 *dst, unsigned int *dlen)
46  {
47 @@ -89,13 +118,37 @@ static struct crypto_alg alg = {
48         .coa_decompress         = lzo_decompress } }
49  };
50  
51 +static struct crypto_alg alg999 = {
52 +       .cra_name               = "lzo999",
53 +       .cra_flags              = CRYPTO_ALG_TYPE_COMPRESS,
54 +       .cra_ctxsize            = sizeof(struct lzo_ctx),
55 +       .cra_module             = THIS_MODULE,
56 +       .cra_list               = LIST_HEAD_INIT(alg999.cra_list),
57 +       .cra_init               = lzo999_init,
58 +       .cra_exit               = lzo_exit,
59 +       .cra_u                  = { .compress = {
60 +       .coa_compress           = lzo999_compress,
61 +       .coa_decompress         = lzo_decompress } }
62 +};
63 +
64  static int __init lzo_mod_init(void)
65  {
66 -       return crypto_register_alg(&alg);
67 +       int ret;
68 +
69 +       ret = crypto_register_alg(&alg);
70 +       if (ret < 0)
71 +               return ret;
72 +
73 +       ret = crypto_register_alg(&alg999);
74 +       if (ret < 0)
75 +               crypto_unregister_alg(&alg);
76 +
77 +       return ret;
78  }
79  
80  static void __exit lzo_mod_fini(void)
81  {
82 +       crypto_unregister_alg(&alg999);
83         crypto_unregister_alg(&alg);
84  }
85  
86 diff -Nurp kernel-2.6.28-20094102.3+0m5/fs/ubifs/compress.c kernel-2.6.28-20094102.6+0m5/fs/ubifs/compress.c
87 --- kernel-2.6.28-20094102.3+0m5/fs/ubifs/compress.c    2011-09-04 11:34:12.000000000 +0200
88 +++ kernel-2.6.28-20094102.6+0m5/fs/ubifs/compress.c    2011-09-04 11:36:23.000000000 +0200
89 @@ -46,11 +46,24 @@ static struct ubifs_compressor lzo_compr
90         .name = "lzo",
91         .capi_name = "lzo",
92  };
93 +
94 +static DEFINE_MUTEX(lzo999_mutex);
95 +
96 +static struct ubifs_compressor lzo999_compr = {
97 +       .compr_type = UBIFS_COMPR_LZO999,
98 +       .comp_mutex = &lzo999_mutex,
99 +       .name = "lzo999",
100 +       .capi_name = "lzo999",
101 +};
102  #else
103  static struct ubifs_compressor lzo_compr = {
104         .compr_type = UBIFS_COMPR_LZO,
105         .name = "lzo",
106  };
107 +static struct ubifs_compressor lzo_compr = {
108 +       .compr_type = UBIFS_COMPR_LZO999,
109 +       .name = "lzo999",
110 +};
111  #endif
112  
113  #ifdef CONFIG_UBIFS_FS_ZLIB
114 @@ -125,6 +138,9 @@ void ubifs_compress(const void *in_buf,
115         if (in_len - *out_len < UBIFS_MIN_COMPRESS_DIFF)
116                 goto no_compr;
117  
118 +       if (*compr_type == UBIFS_COMPR_LZO999)
119 +               *compr_type = UBIFS_COMPR_LZO;
120 +
121         return;
122  
123  no_compr:
124 @@ -229,13 +245,19 @@ int __init ubifs_compressors_init(void)
125         if (err)
126                 return err;
127  
128 -       err = compr_init(&zlib_compr);
129 +       err = compr_init(&lzo999_compr);
130         if (err)
131                 goto out_lzo;
132  
133 +       err = compr_init(&zlib_compr);
134 +       if (err)
135 +               goto out_lzo999;
136 +
137         ubifs_compressors[UBIFS_COMPR_NONE] = &none_compr;
138         return 0;
139  
140 +out_lzo999:
141 +       compr_exit(&lzo999_compr);
142  out_lzo:
143         compr_exit(&lzo_compr);
144         return err;
145 @@ -246,6 +268,7 @@ out_lzo:
146   */
147  void ubifs_compressors_exit(void)
148  {
149 +       compr_exit(&lzo999_compr);
150         compr_exit(&lzo_compr);
151         compr_exit(&zlib_compr);
152  }
153 diff -Nurp kernel-2.6.28-20094102.3+0m5/fs/ubifs/journal.c kernel-2.6.28-20094102.6+0m5/fs/ubifs/journal.c
154 --- kernel-2.6.28-20094102.3+0m5/fs/ubifs/journal.c     2011-09-04 11:34:12.000000000 +0200
155 +++ kernel-2.6.28-20094102.6+0m5/fs/ubifs/journal.c     2011-09-04 11:36:23.000000000 +0200
156 @@ -469,7 +469,10 @@ static void pack_inode(struct ubifs_info
157         ino->flags = cpu_to_le32(ui->flags);
158         ino->size  = cpu_to_le64(ui->ui_size);
159         ino->nlink = cpu_to_le32(inode->i_nlink);
160 -       ino->compr_type  = cpu_to_le16(ui->compr_type);
161 +       if (ui->compr_type == UBIFS_COMPR_LZO999)
162 +               ino->compr_type  = cpu_to_le16(UBIFS_COMPR_LZO);
163 +       else
164 +               ino->compr_type  = cpu_to_le16(ui->compr_type);
165         ino->data_len    = cpu_to_le32(ui->data_len);
166         ino->xattr_cnt   = cpu_to_le32(ui->xattr_cnt);
167         ino->xattr_size  = cpu_to_le32(ui->xattr_size);
168 diff -Nurp kernel-2.6.28-20094102.3+0m5/fs/ubifs/sb.c kernel-2.6.28-20094102.6+0m5/fs/ubifs/sb.c
169 --- kernel-2.6.28-20094102.3+0m5/fs/ubifs/sb.c  2011-09-04 11:34:12.000000000 +0200
170 +++ kernel-2.6.28-20094102.6+0m5/fs/ubifs/sb.c  2011-09-04 11:36:23.000000000 +0200
171 @@ -181,9 +181,12 @@ static int create_default_filesystem(str
172         sup->lsave_cnt     = cpu_to_le32(c->lsave_cnt);
173         sup->fmt_version   = cpu_to_le32(UBIFS_FORMAT_VERSION);
174         sup->time_gran     = cpu_to_le32(DEFAULT_TIME_GRAN);
175 -       if (c->mount_opts.override_compr)
176 -               sup->default_compr = cpu_to_le16(c->mount_opts.compr_type);
177 -       else
178 +       if (c->mount_opts.override_compr) {
179 +               if (c->mount_opts.compr_type == UBIFS_COMPR_LZO999)
180 +                       sup->default_compr = cpu_to_le16(UBIFS_COMPR_LZO);
181 +               else
182 +                       sup->default_compr = cpu_to_le16(c->mount_opts.compr_type);
183 +       } else
184                 sup->default_compr = cpu_to_le16(UBIFS_COMPR_LZO);
185  
186         generate_random_uuid(sup->uuid);
187 diff -Nurp kernel-2.6.28-20094102.3+0m5/fs/ubifs/super.c kernel-2.6.28-20094102.6+0m5/fs/ubifs/super.c
188 --- kernel-2.6.28-20094102.3+0m5/fs/ubifs/super.c       2011-09-04 11:34:12.000000000 +0200
189 +++ kernel-2.6.28-20094102.6+0m5/fs/ubifs/super.c       2011-09-04 11:36:23.000000000 +0200
190 @@ -1001,6 +1001,8 @@ static int ubifs_parse_options(struct ub
191                                 c->mount_opts.compr_type = UBIFS_COMPR_LZO;
192                         else if (!strcmp(name, "zlib"))
193                                 c->mount_opts.compr_type = UBIFS_COMPR_ZLIB;
194 +                       else if (!strcmp(name, "lzo999"))
195 +                               c->mount_opts.compr_type = UBIFS_COMPR_LZO999;
196                         else {
197                                 ubifs_err("unknown compressor \"%s\"", name);
198                                 kfree(name);
199 diff -Nurp kernel-2.6.28-20094102.3+0m5/fs/ubifs/ubifs-media.h kernel-2.6.28-20094102.6+0m5/fs/ubifs/ubifs-media.h
200 --- kernel-2.6.28-20094102.3+0m5/fs/ubifs/ubifs-media.h 2011-09-04 11:34:12.000000000 +0200
201 +++ kernel-2.6.28-20094102.6+0m5/fs/ubifs/ubifs-media.h 2011-09-04 11:36:23.000000000 +0200
202 @@ -303,12 +303,14 @@ enum {
203   * UBIFS_COMPR_NONE: no compression
204   * UBIFS_COMPR_LZO: LZO compression
205   * UBIFS_COMPR_ZLIB: ZLIB compression
206 + * UBIFS_COMPR_LZO999: LZO999 compression
207   * UBIFS_COMPR_TYPES_CNT: count of supported compression types
208   */
209  enum {
210         UBIFS_COMPR_NONE,
211         UBIFS_COMPR_LZO,
212         UBIFS_COMPR_ZLIB,
213 +       UBIFS_COMPR_LZO999,
214         UBIFS_COMPR_TYPES_CNT,
215  };
216  
217 diff -Nurp kernel-2.6.28-20094102.3+0m5/include/linux/lzo.h kernel-2.6.28-20094102.6+0m5/include/linux/lzo.h
218 --- kernel-2.6.28-20094102.3+0m5/include/linux/lzo.h    2008-12-25 00:26:37.000000000 +0100
219 +++ kernel-2.6.28-20094102.6+0m5/include/linux/lzo.h    2011-09-04 11:36:23.000000000 +0200
220 @@ -17,6 +17,8 @@
221  #define LZO1X_MEM_COMPRESS     (16384 * sizeof(unsigned char *))
222  #define LZO1X_1_MEM_COMPRESS   LZO1X_MEM_COMPRESS
223  
224 +#define LZO1X_999_MEM_COMPRESS  ((unsigned) (14 * 16384L * sizeof(short)))
225 +
226  #define lzo1x_worst_compress(x) ((x) + ((x) / 16) + 64 + 3)
227  
228  /* This requires 'workmem' of size LZO1X_1_MEM_COMPRESS */
229 @@ -27,6 +29,27 @@ int lzo1x_1_compress(const unsigned char
230  int lzo1x_decompress_safe(const unsigned char *src, size_t src_len,
231                         unsigned char *dst, size_t *dst_len);
232  
233 +int
234 +lzo1x_999_compress ( const unsigned char *src, unsigned src_len,
235 +                                unsigned char *dst, unsigned * dst_len,
236 +                                void * wrkmem );
237 +
238 +int
239 +lzo1x_999_compress_dict ( const unsigned char *in , unsigned in_len,
240 +                                    unsigned char *out, unsigned * out_len,
241 +                                    void * wrkmem,
242 +                              const unsigned char *dict, unsigned dict_len );
243 +
244 +typedef void ( *lzo_progress_callback_t) (unsigned, unsigned);
245 +
246 +int
247 +lzo1x_999_compress_level ( const unsigned char *in , unsigned in_len,
248 +                                    unsigned char *out, unsigned * out_len,
249 +                                    void * wrkmem,
250 +                              const unsigned char *dict, unsigned dict_len,
251 +                                    lzo_progress_callback_t cb,
252 +                                    int compression_level );
253 +
254  /*
255   * Return values (< 0 = Error)
256   */
257 diff -Nurp kernel-2.6.28-20094102.3+0m5/lib/lzo/lzo1x_9x.c kernel-2.6.28-20094102.6+0m5/lib/lzo/lzo1x_9x.c
258 --- kernel-2.6.28-20094102.3+0m5/lib/lzo/lzo1x_9x.c     1970-01-01 01:00:00.000000000 +0100
259 +++ kernel-2.6.28-20094102.6+0m5/lib/lzo/lzo1x_9x.c     2011-09-04 11:36:23.000000000 +0200
260 @@ -0,0 +1,1272 @@
261 +/* lzo1x_9x.c -- implementation of the LZO1X-999 compression algorithm
262 +
263 +   This file is part of the LZO real-time data compression library.
264 +
265 +   Copyright (C) 1996-2002 Markus Franz Xaver Johannes Oberhumer
266 +   All Rights Reserved.
267 +
268 +   The LZO library is free software; you can redistribute it and/or
269 +   modify it under the terms of version 2 of the GNU General Public
270 +   License as published by the Free Software Foundation.
271 +
272 +   The LZO library 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 the LZO library; see the file COPYING.
279 +   If not, write to the Free Software Foundation, Inc.,
280 +   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
281 +
282 +   Markus F.X.J. Oberhumer
283 +   <markus@oberhumer.com>
284 + */
285 +
286 +#include <linux/module.h>
287 +#include <linux/string.h>
288 +
289 +typedef unsigned int lzo_uint32;
290 +typedef int lzo_int32;
291 +typedef unsigned int lzo_uint;
292 +typedef int lzo_int;
293 +typedef int lzo_bool;
294 +
295 +typedef void ( *lzo_progress_callback_t) (unsigned, unsigned);
296 +
297 +typedef struct
298 +{
299 + int init;
300 +
301 + lzo_uint look;
302 +
303 + lzo_uint m_len;
304 + lzo_uint m_off;
305 +
306 + lzo_uint last_m_len;
307 + lzo_uint last_m_off;
308 +
309 + const unsigned char *bp;
310 + const unsigned char *ip;
311 + const unsigned char *in;
312 + const unsigned char *in_end;
313 + unsigned char *out;
314 +
315 + lzo_progress_callback_t cb;
316 +
317 + lzo_uint textsize;
318 + lzo_uint codesize;
319 + lzo_uint printcount;
320 +
321 +
322 + unsigned long lit_bytes;
323 + unsigned long match_bytes;
324 + unsigned long rep_bytes;
325 + unsigned long lazy;
326 +
327 + lzo_uint r1_lit;
328 + lzo_uint r1_m_len;
329 +
330 + unsigned long m1a_m, m1b_m, m2_m, m3_m, m4_m;
331 + unsigned long lit1_r, lit2_r, lit3_r;
332 +}
333 +lzo1x_999_t;
334 +
335 +typedef unsigned short swd_uint;
336 +
337 +typedef struct
338 +{
339 + lzo_uint n;
340 + lzo_uint f;
341 + lzo_uint threshold;
342 +
343 + lzo_uint max_chain;
344 + lzo_uint nice_length;
345 + lzo_bool use_best_off;
346 + lzo_uint lazy_insert;
347 +
348 + lzo_uint m_len;
349 + lzo_uint m_off;
350 + lzo_uint look;
351 + int b_char;
352 +
353 + lzo_uint best_off[ (((8) >= (33) ? ((8) >= (9) ? (8) : (9)) : ((33) >= (9) ? (33) : (9))) + 1) ];
354 +
355 + lzo1x_999_t *c;
356 + lzo_uint m_pos;
357 +
358 + lzo_uint best_pos[ (((8) >= (33) ? ((8) >= (9) ? (8) : (9)) : ((33) >= (9) ? (33) : (9))) + 1) ];
359 +
360 + const unsigned char *dict;
361 + const unsigned char *dict_end;
362 + lzo_uint dict_len;
363 +
364 + lzo_uint ip;
365 + lzo_uint bp;
366 + lzo_uint rp;
367 + lzo_uint b_size;
368 +
369 + unsigned char *b_wrap;
370 +
371 + lzo_uint node_count;
372 + lzo_uint first_rp;
373 +
374 + unsigned char b [ 0xbfff + 2048 + 2048 ];
375 + swd_uint head3 [ 16384 ];
376 + swd_uint succ3 [ 0xbfff + 2048 ];
377 + swd_uint best3 [ 0xbfff + 2048 ];
378 + swd_uint llen3 [ 16384 ];
379 +
380 + swd_uint head2 [ 65536L ];
381 +}
382 +lzo1x_999_swd_t;
383 +
384 +static
385 +void swd_initdict(lzo1x_999_swd_t *s, const unsigned char *dict, lzo_uint dict_len)
386 +{
387 + s->dict = s->dict_end = ((void *)0);
388 + s->dict_len = 0;
389 +
390 + if (!dict || dict_len <= 0)
391 +  return;
392 + if (dict_len > s->n)
393 + {
394 +  dict += dict_len - s->n;
395 +  dict_len = s->n;
396 + }
397 +
398 + s->dict = dict;
399 + s->dict_len = dict_len;
400 + s->dict_end = dict + dict_len;
401 + memcpy(s->b,dict,dict_len);
402 + s->ip = dict_len;
403 +}
404 +
405 +
406 +static
407 +void swd_insertdict(lzo1x_999_swd_t *s, lzo_uint node, lzo_uint len)
408 +{
409 + lzo_uint key;
410 +
411 + s->node_count = s->n - len;
412 + s->first_rp = node;
413 +
414 + while (len-- > 0)
415 + {
416 +  key = (((0x9f5f*(((((lzo_uint32)s->b[node]<<5)^s->b[node+1])<<5)^s->b[node+2]))>>5) & (16384 -1));
417 +  s->succ3[node] = s->head3[key];
418 +  s->head3[key] = ((swd_uint)(node));
419 +  s->best3[node] = ((swd_uint)(s->f + 1));
420 +  s->llen3[key]++;
421 +  ((void) (0));
422 +
423 +
424 +  key = (* (unsigned short *) &(s->b[node]));
425 +  s->head2[key] = ((swd_uint)(node));
426 +
427 +
428 +  node++;
429 + }
430 +}
431 +
432 +
433 +
434 +
435 +
436 +
437 +static
438 +int swd_init(lzo1x_999_swd_t *s, const unsigned char *dict, lzo_uint dict_len)
439 +{
440 + lzo_uint i = 0;
441 + int c = 0;
442 +
443 + s->n = 0xbfff;
444 + s->f = 2048;
445 + s->threshold = 1;
446 +
447 +
448 + s->max_chain = 2048;
449 + s->nice_length = 2048;
450 + s->use_best_off = 0;
451 + s->lazy_insert = 0;
452 +
453 + s->b_size = s->n + s->f;
454 + if (2 * s->f >= s->n || s->b_size + s->f >= (32767 * 2 + 1))
455 +  return (-1);
456 + s->b_wrap = s->b + s->b_size;
457 + s->node_count = s->n;
458 +
459 + memset(s->llen3, 0, sizeof(s->llen3[0]) * 16384);
460 +
461 +
462 + memset(s->head2, 0xff, sizeof(s->head2[0]) * 65536L);
463 + ((void) (0));
464 +
465 +
466 +
467 +
468 +
469 +
470 + s->ip = 0;
471 + swd_initdict(s,dict,dict_len);
472 + s->bp = s->ip;
473 + s->first_rp = s->ip;
474 +
475 + ((void) (0));
476 +
477 + s->look = (lzo_uint) (s->c->in_end - s->c->ip);
478 + if (s->look > 0)
479 + {
480 +  if (s->look > s->f)
481 +   s->look = s->f;
482 +  memcpy(&s->b[s->ip],s->c->ip,s->look);
483 +  s->c->ip += s->look;
484 +  s->ip += s->look;
485 + }
486 +
487 + if (s->ip == s->b_size)
488 +  s->ip = 0;
489 +
490 + if (s->look >= 2 && s->dict_len > 0)
491 +  swd_insertdict(s,0,s->dict_len);
492 +
493 + s->rp = s->first_rp;
494 + if (s->rp >= s->node_count)
495 +  s->rp -= s->node_count;
496 + else
497 +  s->rp += s->b_size - s->node_count;
498 +
499 + ((void)&i);
500 + ((void)&c);
501 + return 0;
502 +}
503 +
504 +
505 +static
506 +void swd_exit(lzo1x_999_swd_t *s)
507 +{
508 +
509 + ((void)&s);
510 +
511 +}
512 +
513 +static __inline__
514 +void swd_getbyte(lzo1x_999_swd_t *s)
515 +{
516 + int c;
517 +
518 + if ((c = ((*(s->c)).ip < (*(s->c)).in_end ? *((*(s->c)).ip)++ : (-1))) < 0)
519 + {
520 +  if (s->look > 0)
521 +   --s->look;
522 +
523 +
524 +
525 +
526 +
527 +
528 + }
529 + else
530 + {
531 +  s->b[s->ip] = ((unsigned char) ((c) & 0xff));
532 +  if (s->ip < s->f)
533 +   s->b_wrap[s->ip] = ((unsigned char) ((c) & 0xff));
534 + }
535 + if (++s->ip == s->b_size)
536 +  s->ip = 0;
537 + if (++s->bp == s->b_size)
538 +  s->bp = 0;
539 + if (++s->rp == s->b_size)
540 +  s->rp = 0;
541 +}
542 +
543 +
544 +
545 +
546 +
547 +
548 +static __inline__
549 +void swd_remove_node(lzo1x_999_swd_t *s, lzo_uint node)
550 +{
551 + if (s->node_count == 0)
552 + {
553 +  lzo_uint key;
554 +
555 +  key = (((0x9f5f*(((((lzo_uint32)s->b[node]<<5)^s->b[node+1])<<5)^s->b[node+2]))>>5) & (16384 -1));
556 +  ((void) (0));
557 +  --s->llen3[key];
558 +
559 +
560 +  key = (* (unsigned short *) &(s->b[node]));
561 +  ((void) (0));
562 +  if ((lzo_uint) s->head2[key] == node)
563 +   s->head2[key] = (32767 * 2 + 1);
564 +
565 + }
566 + else
567 +  --s->node_count;
568 +}
569 +
570 +
571 +
572 +
573 +
574 +
575 +static
576 +void swd_accept(lzo1x_999_swd_t *s, lzo_uint n)
577 +{
578 + ((void) (0));
579 +
580 + while (n--)
581 + {
582 +  lzo_uint key;
583 +
584 +  swd_remove_node(s,s->rp);
585 +
586 +
587 +  key = (((0x9f5f*(((((lzo_uint32)s->b[s->bp]<<5)^s->b[s->bp+1])<<5)^s->b[s->bp+2]))>>5) & (16384 -1));
588 +  s->succ3[s->bp] = s->head3[key];
589 +  s->head3[key] = ((swd_uint)(s->bp));
590 +  s->best3[s->bp] = ((swd_uint)(s->f + 1));
591 +  s->llen3[key]++;
592 +  ((void) (0));
593 +
594 +
595 +
596 +  key = (* (unsigned short *) &(s->b[s->bp]));
597 +  s->head2[key] = ((swd_uint)(s->bp));
598 +
599 +
600 +  swd_getbyte(s);
601 + }
602 +}
603 +
604 +
605 +
606 +
607 +
608 +
609 +static
610 +void swd_search(lzo1x_999_swd_t *s, lzo_uint node, lzo_uint cnt)
611 +{
612 +
613 +
614 +
615 +
616 +
617 + const unsigned char *p1;
618 + const unsigned char *p2;
619 + const unsigned char *px;
620 +
621 + lzo_uint m_len = s->m_len;
622 + const unsigned char * b = s->b;
623 + const unsigned char * bp = s->b + s->bp;
624 + const unsigned char * bx = s->b + s->bp + s->look;
625 + unsigned char scan_end1;
626 +
627 + ((void) (0));
628 +
629 + scan_end1 = bp[m_len - 1];
630 + for ( ; cnt-- > 0; node = s->succ3[node])
631 + {
632 +  p1 = bp;
633 +  p2 = b + node;
634 +  px = bx;
635 +
636 +  ((void) (0));
637 +
638 +  if (
639 +
640 +      p2[m_len - 1] == scan_end1 &&
641 +      p2[m_len] == p1[m_len] &&
642 +
643 +      p2[0] == p1[0] &&
644 +      p2[1] == p1[1])
645 +  {
646 +   lzo_uint i;
647 +   ((void) (0));
648 +
649 +   p1 += 2; p2 += 2;
650 +   do {} while (++p1 < px && *p1 == *++p2);
651 +
652 +   i = p1 - bp;
653 +
654 +
655 +
656 +
657 +
658 +
659 +
660 +   ((void) (0));
661 +
662 +
663 +   if (i < (((8) >= (33) ? ((8) >= (9) ? (8) : (9)) : ((33) >= (9) ? (33) : (9))) + 1))
664 +   {
665 +    if (s->best_pos[i] == 0)
666 +     s->best_pos[i] = node + 1;
667 +   }
668 +
669 +   if (i > m_len)
670 +   {
671 +    s->m_len = m_len = i;
672 +    s->m_pos = node;
673 +    if (m_len == s->look)
674 +     return;
675 +    if (m_len >= s->nice_length)
676 +     return;
677 +    if (m_len > (lzo_uint) s->best3[node])
678 +     return;
679 +    scan_end1 = bp[m_len - 1];
680 +   }
681 +  }
682 + }
683 +}
684 +
685 +static
686 +lzo_bool swd_search2(lzo1x_999_swd_t *s)
687 +{
688 + lzo_uint key;
689 +
690 + ((void) (0));
691 + ((void) (0));
692 +
693 + key = s->head2[ (* (unsigned short *) &(s->b[s->bp])) ];
694 + if (key == (32767 * 2 + 1))
695 +  return 0;
696 +
697 +
698 +
699 +
700 +
701 + ((void) (0));
702 +
703 + if (s->best_pos[2] == 0)
704 +  s->best_pos[2] = key + 1;
705 +
706 +
707 + if (s->m_len < 2)
708 + {
709 +  s->m_len = 2;
710 +  s->m_pos = key;
711 + }
712 + return 1;
713 +}
714 +
715 +static
716 +void swd_findbest(lzo1x_999_swd_t *s)
717 +{
718 + lzo_uint key;
719 + lzo_uint cnt, node;
720 + lzo_uint len;
721 +
722 + ((void) (0));
723 +
724 +
725 + key = (((0x9f5f*(((((lzo_uint32)s->b[s->bp]<<5)^s->b[s->bp+1])<<5)^s->b[s->bp+2]))>>5) & (16384 -1));
726 + node = s->succ3[s->bp] = s->head3[key];
727 + cnt = s->llen3[key]++;
728 + ((void) (0));
729 + if (cnt > s->max_chain && s->max_chain > 0)
730 +  cnt = s->max_chain;
731 + s->head3[key] = ((swd_uint)(s->bp));
732 +
733 + s->b_char = s->b[s->bp];
734 + len = s->m_len;
735 + if (s->m_len >= s->look)
736 + {
737 +  if (s->look == 0)
738 +   s->b_char = -1;
739 +  s->m_off = 0;
740 +  s->best3[s->bp] = ((swd_uint)(s->f + 1));
741 + }
742 + else
743 + {
744 +
745 +  if (swd_search2(s))
746 +
747 +   if (s->look >= 3)
748 +    swd_search(s,node,cnt);
749 +  if (s->m_len > len)
750 +   s->m_off = (s->bp > (s->m_pos) ? s->bp - (s->m_pos) : s->b_size - ((s->m_pos) - s->bp));
751 +  s->best3[s->bp] = ((swd_uint)(s->m_len));
752 +
753 +
754 +  if (s->use_best_off)
755 +  {
756 +   int i;
757 +   for (i = 2; i < (((8) >= (33) ? ((8) >= (9) ? (8) : (9)) : ((33) >= (9) ? (33) : (9))) + 1); i++)
758 +    if (s->best_pos[i] > 0)
759 +     s->best_off[i] = (s->bp > (s->best_pos[i]-1) ? s->bp - (s->best_pos[i]-1) : s->b_size - ((s->best_pos[i]-1) - s->bp));
760 +    else
761 +     s->best_off[i] = 0;
762 +  }
763 +
764 + }
765 +
766 + swd_remove_node(s,s->rp);
767 +
768 +
769 +
770 + key = (* (unsigned short *) &(s->b[s->bp]));
771 + s->head2[key] = ((swd_uint)(s->bp));
772 +
773 +}
774 +
775 +
776 +
777 +
778 +
779 +
780 +
781 +
782 +static int
783 +init_match ( lzo1x_999_t *c, lzo1x_999_swd_t *s,
784 +    const unsigned char *dict, lzo_uint dict_len,
785 +    lzo_uint32 flags )
786 +{
787 + int r;
788 +
789 + ((void) (0));
790 + c->init = 1;
791 +
792 + s->c = c;
793 +
794 + c->last_m_len = c->last_m_off = 0;
795 +
796 + c->textsize = c->codesize = c->printcount = 0;
797 + c->lit_bytes = c->match_bytes = c->rep_bytes = 0;
798 + c->lazy = 0;
799 +
800 + r = swd_init(s,dict,dict_len);
801 + if (r != 0)
802 +  return r;
803 +
804 + s->use_best_off = (flags & 1) ? 1 : 0;
805 + return r;
806 +}
807 +
808 +
809 +
810 +
811 +
812 +
813 +static int
814 +find_match ( lzo1x_999_t *c, lzo1x_999_swd_t *s,
815 +    lzo_uint this_len, lzo_uint skip )
816 +{
817 + ((void) (0));
818 +
819 + if (skip > 0)
820 + {
821 +  ((void) (0));
822 +  swd_accept(s, this_len - skip);
823 +  c->textsize += this_len - skip + 1;
824 + }
825 + else
826 + {
827 +  ((void) (0));
828 +  c->textsize += this_len - skip;
829 + }
830 +
831 + s->m_len = 1;
832 + s->m_len = 1;
833 +
834 + if (s->use_best_off)
835 +  memset(s->best_pos,0,sizeof(s->best_pos));
836 +
837 + swd_findbest(s);
838 + c->m_len = s->m_len;
839 + c->m_off = s->m_off;
840 +
841 + swd_getbyte(s);
842 +
843 + if (s->b_char < 0)
844 + {
845 +  c->look = 0;
846 +  c->m_len = 0;
847 +  swd_exit(s);
848 + }
849 + else
850 + {
851 +  c->look = s->look + 1;
852 + }
853 + c->bp = c->ip - c->look;
854 +
855 + if (c->cb && c->textsize > c->printcount)
856 + {
857 +  (*c->cb)(c->textsize,c->codesize);
858 +  c->printcount += 1024;
859 + }
860 +
861 + return 0;
862 +}
863 +
864 +
865 +
866 +
867 +static int
868 +lzo1x_999_compress_internal ( const unsigned char *in , lzo_uint in_len,
869 +                                    unsigned char *out, lzo_uint * out_len,
870 +                                    void * wrkmem,
871 +                              const unsigned char *dict, lzo_uint dict_len,
872 +                                    lzo_progress_callback_t cb,
873 +                                    int try_lazy,
874 +                                    lzo_uint good_length,
875 +                                    lzo_uint max_lazy,
876 +                                    lzo_uint nice_length,
877 +                                    lzo_uint max_chain,
878 +                                    lzo_uint32 flags );
879 +
880 +
881 +
882 +
883 +
884 +
885 +static unsigned char *
886 +code_match ( lzo1x_999_t *c, unsigned char *op, lzo_uint m_len, lzo_uint m_off )
887 +{
888 + lzo_uint x_len = m_len;
889 + lzo_uint x_off = m_off;
890 +
891 + c->match_bytes += m_len;
892 +
893 + ((void) (0));
894 + if (m_len == 2)
895 + {
896 +  ((void) (0));
897 +  ((void) (0)); ((void) (0));
898 +  m_off -= 1;
899 +
900 +
901 +
902 +
903 +  *op++ = ((unsigned char) ((0 | ((m_off & 3) << 2)) & 0xff));
904 +  *op++ = ((unsigned char) ((m_off >> 2) & 0xff));
905 +
906 +  c->m1a_m++;
907 + }
908 +
909 +
910 +
911 + else if (m_len <= 8 && m_off <= 0x0800)
912 +
913 + {
914 +  ((void) (0));
915 +
916 +  m_off -= 1;
917 +  *op++ = ((unsigned char) ((((m_len - 1) << 5) | ((m_off & 7) << 2)) & 0xff));
918 +  *op++ = ((unsigned char) ((m_off >> 3) & 0xff));
919 +  ((void) (0));
920 +
921 +  c->m2_m++;
922 + }
923 + else if (m_len == 3 && m_off <= (0x0400 + 0x0800) && c->r1_lit >= 4)
924 + {
925 +  ((void) (0));
926 +  ((void) (0));
927 +  m_off -= 1 + 0x0800;
928 +
929 +
930 +
931 +
932 +  *op++ = ((unsigned char) ((0 | ((m_off & 3) << 2)) & 0xff));
933 +  *op++ = ((unsigned char) ((m_off >> 2) & 0xff));
934 +
935 +  c->m1b_m++;
936 + }
937 + else if (m_off <= 0x4000)
938 + {
939 +  ((void) (0));
940 +  m_off -= 1;
941 +  if (m_len <= 33)
942 +   *op++ = ((unsigned char) ((32 | (m_len - 2)) & 0xff));
943 +  else
944 +  {
945 +   m_len -= 33;
946 +   *op++ = 32 | 0;
947 +   while (m_len > 255)
948 +   {
949 +    m_len -= 255;
950 +    *op++ = 0;
951 +   }
952 +   ((void) (0));
953 +   *op++ = ((unsigned char) ((m_len) & 0xff));
954 +  }
955 +
956 +
957 +
958 +
959 +  *op++ = ((unsigned char) ((m_off << 2) & 0xff));
960 +  *op++ = ((unsigned char) ((m_off >> 6) & 0xff));
961 +
962 +  c->m3_m++;
963 + }
964 + else
965 + {
966 +  lzo_uint k;
967 +
968 +  ((void) (0));
969 +  ((void) (0)); ((void) (0));
970 +  m_off -= 0x4000;
971 +  k = (m_off & 0x4000) >> 11;
972 +  if (m_len <= 9)
973 +   *op++ = ((unsigned char) ((16 | k | (m_len - 2)) & 0xff));
974 +  else
975 +  {
976 +   m_len -= 9;
977 +   *op++ = ((unsigned char) ((16 | k | 0) & 0xff));
978 +   while (m_len > 255)
979 +   {
980 +    m_len -= 255;
981 +    *op++ = 0;
982 +   }
983 +   ((void) (0));
984 +   *op++ = ((unsigned char) ((m_len) & 0xff));
985 +  }
986 +
987 +
988 +
989 +
990 +  *op++ = ((unsigned char) ((m_off << 2) & 0xff));
991 +  *op++ = ((unsigned char) ((m_off >> 6) & 0xff));
992 +
993 +  c->m4_m++;
994 + }
995 +
996 + c->last_m_len = x_len;
997 + c->last_m_off = x_off;
998 + return op;
999 +}
1000 +
1001 +
1002 +static unsigned char *
1003 +STORE_RUN ( lzo1x_999_t *c, unsigned char *op, const unsigned char *ii, lzo_uint t )
1004 +{
1005 + c->lit_bytes += t;
1006 +
1007 + if (op == c->out && t <= 238)
1008 + {
1009 +  *op++ = ((unsigned char) ((17 + t) & 0xff));
1010 + }
1011 + else if (t <= 3)
1012 + {
1013 +
1014 +
1015 +
1016 +  op[-2] |= ((unsigned char) ((t) & 0xff));
1017 +
1018 +  c->lit1_r++;
1019 + }
1020 + else if (t <= 18)
1021 + {
1022 +  *op++ = ((unsigned char) ((t - 3) & 0xff));
1023 +  c->lit2_r++;
1024 + }
1025 + else
1026 + {
1027 +  lzo_uint tt = t - 18;
1028 +
1029 +  *op++ = 0;
1030 +  while (tt > 255)
1031 +  {
1032 +   tt -= 255;
1033 +   *op++ = 0;
1034 +  }
1035 +  ((void) (0));
1036 +  *op++ = ((unsigned char) ((tt) & 0xff));
1037 +  c->lit3_r++;
1038 + }
1039 + do *op++ = *ii++; while (--t > 0);
1040 +
1041 + return op;
1042 +}
1043 +
1044 +
1045 +static unsigned char *
1046 +code_run ( lzo1x_999_t *c, unsigned char *op, const unsigned char *ii,
1047 +           lzo_uint lit, lzo_uint m_len )
1048 +{
1049 + if (lit > 0)
1050 + {
1051 +  ((void) (0));
1052 +  op = STORE_RUN(c,op,ii,lit);
1053 +  c->r1_m_len = m_len;
1054 +  c->r1_lit = lit;
1055 + }
1056 + else
1057 + {
1058 +  ((void) (0));
1059 +  c->r1_m_len = 0;
1060 +  c->r1_lit = 0;
1061 + }
1062 +
1063 + return op;
1064 +}
1065 +
1066 +
1067 +
1068 +
1069 +
1070 +
1071 +static int
1072 +len_of_coded_match ( lzo_uint m_len, lzo_uint m_off, lzo_uint lit )
1073 +{
1074 + int n = 4;
1075 +
1076 + if (m_len < 2)
1077 +  return -1;
1078 + if (m_len == 2)
1079 +  return (m_off <= 0x0400 && lit > 0 && lit < 4) ? 2 : -1;
1080 + if (m_len <= 8 && m_off <= 0x0800)
1081 +  return 2;
1082 + if (m_len == 3 && m_off <= (0x0400 + 0x0800) && lit >= 4)
1083 +  return 2;
1084 + if (m_off <= 0x4000)
1085 + {
1086 +  if (m_len <= 33)
1087 +   return 3;
1088 +  m_len -= 33;
1089 +  while (m_len > 255)
1090 +  {
1091 +   m_len -= 255;
1092 +   n++;
1093 +  }
1094 +  return n;
1095 + }
1096 + if (m_off <= 0xbfff)
1097 + {
1098 +  if (m_len <= 9)
1099 +   return 3;
1100 +  m_len -= 9;
1101 +  while (m_len > 255)
1102 +  {
1103 +   m_len -= 255;
1104 +   n++;
1105 +  }
1106 +  return n;
1107 + }
1108 + return -1;
1109 +}
1110 +
1111 +
1112 +static lzo_int
1113 +min_gain(lzo_uint ahead, lzo_uint lit1, lzo_uint lit2, int l1, int l2, int l3)
1114 +{
1115 + lzo_int lazy_match_min_gain = 0;
1116 +
1117 + ((void) (0));
1118 + lazy_match_min_gain += ahead;
1119 +
1120 +
1121 +
1122 +
1123 +
1124 +
1125 + if (lit1 <= 3)
1126 +  lazy_match_min_gain += (lit2 <= 3) ? 0 : 2;
1127 + else if (lit1 <= 18)
1128 +  lazy_match_min_gain += (lit2 <= 18) ? 0 : 1;
1129 +
1130 + lazy_match_min_gain += (l2 - l1) * 2;
1131 + if (l3 > 0)
1132 +  lazy_match_min_gain -= (ahead - l3) * 2;
1133 +
1134 + if (lazy_match_min_gain < 0)
1135 +  lazy_match_min_gain = 0;
1136 +
1137 +
1138 +
1139 +
1140 +
1141 +
1142 +
1143 + return lazy_match_min_gain;
1144 +}
1145 +
1146 +static void
1147 +better_match ( const lzo1x_999_swd_t *swd, lzo_uint *m_len, lzo_uint *m_off )
1148 +{
1149 +
1150 +
1151 +
1152 +
1153 + if (*m_len <= 3)
1154 +  return;
1155 +
1156 + if (*m_off <= 0x0800)
1157 +  return;
1158 +
1159 +
1160 +
1161 + if (*m_off > 0x0800 &&
1162 +     *m_len >= 3 + 1 && *m_len <= 8 + 1 &&
1163 +     swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= 0x0800)
1164 + {
1165 +  *m_len = *m_len - 1;
1166 +  *m_off = swd->best_off[*m_len];
1167 +  return;
1168 + }
1169 +
1170 +
1171 +
1172 +
1173 + if (*m_off > 0x4000 &&
1174 +     *m_len >= 9 + 1 && *m_len <= 8 + 2 &&
1175 +     swd->best_off[*m_len-2] && swd->best_off[*m_len-2] <= 0x0800)
1176 + {
1177 +  *m_len = *m_len - 2;
1178 +  *m_off = swd->best_off[*m_len];
1179 +  return;
1180 + }
1181 +
1182 +
1183 +
1184 +
1185 + if (*m_off > 0x4000 &&
1186 +     *m_len >= 9 + 1 && *m_len <= 33 + 1 &&
1187 +     swd->best_off[*m_len-1] && swd->best_off[*m_len-1] <= 0x4000)
1188 + {
1189 +  *m_len = *m_len - 1;
1190 +  *m_off = swd->best_off[*m_len];
1191 + }
1192 +
1193 +}
1194 +
1195 + int
1196 +lzo1x_999_compress_internal ( const unsigned char *in , lzo_uint in_len,
1197 +                                    unsigned char *out, lzo_uint * out_len,
1198 +                                    void * wrkmem,
1199 +                              const unsigned char *dict, lzo_uint dict_len,
1200 +                                    lzo_progress_callback_t cb,
1201 +                                    int try_lazy,
1202 +                                    lzo_uint good_length,
1203 +                                    lzo_uint max_lazy,
1204 +                                    lzo_uint nice_length,
1205 +                                    lzo_uint max_chain,
1206 +                                    lzo_uint32 flags )
1207 +{
1208 + unsigned char *op;
1209 + const unsigned char *ii;
1210 + lzo_uint lit;
1211 + lzo_uint m_len, m_off;
1212 + lzo1x_999_t cc;
1213 + lzo1x_999_t * const c = &cc;
1214 + lzo1x_999_swd_t * const swd = (lzo1x_999_swd_t *) wrkmem;
1215 + int r;
1216 +
1217 +
1218 +
1219 +
1220 +
1221 +
1222 +
1223 + if (!(((lzo_uint32) (14 * 16384L * sizeof(short))) >= ((lzo_uint) (sizeof(lzo1x_999_swd_t)))))
1224 +  return (-1);
1225 +
1226 +
1227 +
1228 + if (try_lazy < 0)
1229 +  try_lazy = 1;
1230 +
1231 + if (good_length <= 0)
1232 +  good_length = 32;
1233 +
1234 + if (max_lazy <= 0)
1235 +  max_lazy = 32;
1236 +
1237 + if (nice_length <= 0)
1238 +  nice_length = 0;
1239 +
1240 + if (max_chain <= 0)
1241 +  max_chain = 2048;
1242 +
1243 + c->init = 0;
1244 + c->ip = c->in = in;
1245 + c->in_end = in + in_len;
1246 + c->out = out;
1247 + c->cb = cb;
1248 + c->m1a_m = c->m1b_m = c->m2_m = c->m3_m = c->m4_m = 0;
1249 + c->lit1_r = c->lit2_r = c->lit3_r = 0;
1250 +
1251 + op = out;
1252 + ii = c->ip;
1253 + lit = 0;
1254 + c->r1_lit = c->r1_m_len = 0;
1255 +
1256 + r = init_match(c,swd,dict,dict_len,flags);
1257 + if (r != 0)
1258 +  return r;
1259 + if (max_chain > 0)
1260 +  swd->max_chain = max_chain;
1261 + if (nice_length > 0)
1262 +  swd->nice_length = nice_length;
1263 +
1264 + r = find_match(c,swd,0,0);
1265 + if (r != 0)
1266 +  return r;
1267 + while (c->look > 0)
1268 + {
1269 +  lzo_uint ahead;
1270 +  lzo_uint max_ahead;
1271 +  int l1, l2, l3;
1272 +
1273 +  c->codesize = op - out;
1274 +
1275 +  m_len = c->m_len;
1276 +  m_off = c->m_off;
1277 +
1278 +  ((void) (0));
1279 +  ((void) (0));
1280 +  if (lit == 0)
1281 +   ii = c->bp;
1282 +  ((void) (0));
1283 +  ((void) (0));
1284 +
1285 +  if ( m_len < 2 ||
1286 +      (m_len == 2 && (m_off > 0x0400 || lit == 0 || lit >= 4)) ||
1287 +
1288 +
1289 +
1290 +
1291 +
1292 +      (m_len == 2 && op == out) ||
1293 +
1294 +   (op == out && lit == 0))
1295 +  {
1296 +
1297 +   m_len = 0;
1298 +  }
1299 +  else if (m_len == 3)
1300 +  {
1301 +
1302 +   if (m_off > (0x0400 + 0x0800) && lit >= 4)
1303 +    m_len = 0;
1304 +  }
1305 +
1306 +  if (m_len == 0)
1307 +  {
1308 +
1309 +   lit++;
1310 +   swd->max_chain = max_chain;
1311 +   r = find_match(c,swd,1,0);
1312 +   ((void) (0));
1313 +   continue;
1314 +  }
1315 +
1316 +
1317 +
1318 +  if (swd->use_best_off)
1319 +   better_match(swd,&m_len,&m_off);
1320 +
1321 +  ((void)0);
1322 +
1323 +
1324 +
1325 +
1326 +  ahead = 0;
1327 +  if (try_lazy <= 0 || m_len >= max_lazy)
1328 +  {
1329 +
1330 +   l1 = 0;
1331 +   max_ahead = 0;
1332 +  }
1333 +  else
1334 +  {
1335 +
1336 +   l1 = len_of_coded_match(m_len,m_off,lit);
1337 +   ((void) (0));
1338 +
1339 +   max_ahead = ((try_lazy) <= (l1 - 1) ? (try_lazy) : (l1 - 1));
1340 +
1341 +
1342 +
1343 +  }
1344 +
1345 +
1346 +  while (ahead < max_ahead && c->look > m_len)
1347 +  {
1348 +   lzo_int lazy_match_min_gain;
1349 +
1350 +   if (m_len >= good_length)
1351 +    swd->max_chain = max_chain >> 2;
1352 +   else
1353 +    swd->max_chain = max_chain;
1354 +   r = find_match(c,swd,1,0);
1355 +   ahead++;
1356 +
1357 +   ((void) (0));
1358 +   ((void) (0));
1359 +   ((void) (0));
1360 +
1361 +
1362 +
1363 +
1364 +
1365 +
1366 +   if (c->m_len < m_len)
1367 +    continue;
1368 +
1369 +   if (c->m_len == m_len && c->m_off >= m_off)
1370 +    continue;
1371 +
1372 +
1373 +   if (swd->use_best_off)
1374 +    better_match(swd,&c->m_len,&c->m_off);
1375 +
1376 +   l2 = len_of_coded_match(c->m_len,c->m_off,lit+ahead);
1377 +   if (l2 < 0)
1378 +    continue;
1379 +
1380 +   l3 = (op == out) ? -1 : len_of_coded_match(ahead,m_off,lit);
1381 +
1382 +
1383 +
1384 +
1385 +   lazy_match_min_gain = min_gain(ahead,lit,lit+ahead,l1,l2,l3);
1386 +   if (c->m_len >= m_len + lazy_match_min_gain)
1387 +   {
1388 +    c->lazy++;
1389 +    ((void)0);
1390 +
1391 +    if (l3 > 0)
1392 +    {
1393 +
1394 +     op = code_run(c,op,ii,lit,ahead);
1395 +     lit = 0;
1396 +
1397 +     op = code_match(c,op,ahead,m_off);
1398 +    }
1399 +    else
1400 +    {
1401 +     lit += ahead;
1402 +     ((void) (0));
1403 +    }
1404 +    goto lazy_match_done;
1405 +   }
1406 +  }
1407 +
1408 +
1409 +  ((void) (0));
1410 +
1411 +
1412 +  op = code_run(c,op,ii,lit,m_len);
1413 +  lit = 0;
1414 +
1415 +
1416 +  op = code_match(c,op,m_len,m_off);
1417 +  swd->max_chain = max_chain;
1418 +  r = find_match(c,swd,m_len,1+ahead);
1419 +  ((void) (0));
1420 +
1421 +lazy_match_done: ;
1422 + }
1423 +
1424 +
1425 +
1426 + if (lit > 0)
1427 +  op = STORE_RUN(c,op,ii,lit);
1428 +
1429 +
1430 + *op++ = 16 | 1;
1431 + *op++ = 0;
1432 + *op++ = 0;
1433 +
1434 +
1435 + c->codesize = op - out;
1436 + ((void) (0));
1437 +
1438 + *out_len = op - out;
1439 +
1440 + if (c->cb)
1441 +  (*c->cb)(c->textsize,c->codesize);
1442 +
1443 +
1444 +
1445 +
1446 +
1447 +
1448 +
1449 + ((void) (0));
1450 +
1451 + return 0;
1452 +}
1453 +
1454 +
1455 +
1456 +
1457 +
1458 +
1459 + int
1460 +lzo1x_999_compress_level ( const unsigned char *in , unsigned in_len,
1461 +                                    unsigned char *out, unsigned * out_len,
1462 +                                    void * wrkmem,
1463 +                              const unsigned char *dict, unsigned dict_len,
1464 +                                    lzo_progress_callback_t cb,
1465 +                                    int compression_level )
1466 +{
1467 + static const struct
1468 + {
1469 +  int try_lazy;
1470 +  lzo_uint good_length;
1471 +  lzo_uint max_lazy;
1472 +  lzo_uint nice_length;
1473 +  lzo_uint max_chain;
1474 +  lzo_uint32 flags;
1475 + } c[9] = {
1476 +  { 0, 0, 0, 8, 4, 0 },
1477 +  { 0, 0, 0, 16, 8, 0 },
1478 +  { 0, 0, 0, 32, 16, 0 },
1479 +
1480 +  { 1, 4, 4, 16, 16, 0 },
1481 +  { 1, 8, 16, 32, 32, 0 },
1482 +  { 1, 8, 16, 128, 128, 0 },
1483 +
1484 +  { 2, 8, 32, 128, 256, 0 },
1485 +  { 2, 32, 128, 2048, 2048, 1 },
1486 +  { 2, 2048, 2048, 2048, 4096, 1 }
1487 + };
1488 +
1489 + if (compression_level < 1 || compression_level > 9)
1490 +  return (-1);
1491 +
1492 + compression_level -= 1;
1493 + return lzo1x_999_compress_internal(in, in_len, out, out_len, wrkmem,
1494 +                                    dict, dict_len, cb,
1495 +                                    c[compression_level].try_lazy,
1496 +                                    c[compression_level].good_length,
1497 +                                    c[compression_level].max_lazy,
1498 +
1499 +
1500 +
1501 +                                    0,
1502 +
1503 +                                    c[compression_level].max_chain,
1504 +                                    c[compression_level].flags);
1505 +}
1506 +EXPORT_SYMBOL_GPL(lzo1x_999_compress_level);
1507 +
1508 +
1509 +
1510 +
1511 +
1512 + int
1513 +lzo1x_999_compress_dict ( const unsigned char *in , unsigned in_len,
1514 +                                    unsigned char *out, unsigned * out_len,
1515 +                                    void * wrkmem,
1516 +                              const unsigned char *dict, unsigned dict_len )
1517 +{
1518 + return lzo1x_999_compress_level(in, in_len, out, out_len, wrkmem,
1519 +                                 dict, dict_len, 0, 8);
1520 +}
1521 +EXPORT_SYMBOL_GPL(lzo1x_999_compress_dict);
1522 +
1523 + int
1524 +lzo1x_999_compress ( const unsigned char *in , unsigned in_len,
1525 +                            unsigned char *out, unsigned * out_len,
1526 +                            void * wrkmem )
1527 +{
1528 + return lzo1x_999_compress_level(in, in_len, out, out_len, wrkmem,
1529 +                                 ((void *)0), 0, 0, 8);
1530 +}
1531 +EXPORT_SYMBOL_GPL(lzo1x_999_compress);
1532 +
1533 diff -Nurp kernel-2.6.28-20094102.3+0m5/lib/lzo/Makefile kernel-2.6.28-20094102.6+0m5/lib/lzo/Makefile
1534 --- kernel-2.6.28-20094102.3+0m5/lib/lzo/Makefile       2008-12-25 00:26:37.000000000 +0100
1535 +++ kernel-2.6.28-20094102.6+0m5/lib/lzo/Makefile       2011-09-04 11:36:23.000000000 +0200
1536 @@ -1,4 +1,4 @@
1537 -lzo_compress-objs := lzo1x_compress.o
1538 +lzo_compress-objs := lzo1x_compress.o lzo1x_9x.o
1539  lzo_decompress-objs := lzo1x_decompress.o
1540  
1541  obj-$(CONFIG_LZO_COMPRESS) += lzo_compress.o