diff options
Diffstat (limited to 'fs/jffs2/compr_rubin.c')
-rw-r--r-- | fs/jffs2/compr_rubin.c | 81 |
1 files changed, 76 insertions, 5 deletions
diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c index e792e675d624..ea0431e047d5 100644 --- a/fs/jffs2/compr_rubin.c +++ b/fs/jffs2/compr_rubin.c | |||
@@ -1,23 +1,94 @@ | |||
1 | /* | 1 | /* |
2 | * JFFS2 -- Journalling Flash File System, Version 2. | 2 | * JFFS2 -- Journalling Flash File System, Version 2. |
3 | * | 3 | * |
4 | * Copyright (C) 2001, 2002 Red Hat, Inc. | 4 | * Copyright © 2001-2007 Red Hat, Inc. |
5 | * | 5 | * |
6 | * Created by Arjan van de Ven <arjanv@redhat.com> | 6 | * Created by Arjan van de Ven <arjanv@redhat.com> |
7 | * | 7 | * |
8 | * For licensing information, see the file 'LICENCE' in this directory. | 8 | * For licensing information, see the file 'LICENCE' in this directory. |
9 | * | 9 | * |
10 | * $Id: compr_rubin.c,v 1.20 2004/06/23 16:34:40 havasi Exp $ | ||
11 | * | ||
12 | */ | 10 | */ |
13 | 11 | ||
14 | #include <linux/string.h> | 12 | #include <linux/string.h> |
15 | #include <linux/types.h> | 13 | #include <linux/types.h> |
16 | #include <linux/jffs2.h> | 14 | #include <linux/jffs2.h> |
17 | #include "compr_rubin.h" | 15 | #include <linux/errno.h> |
18 | #include "histo_mips.h" | ||
19 | #include "compr.h" | 16 | #include "compr.h" |
20 | 17 | ||
18 | |||
19 | #define RUBIN_REG_SIZE 16 | ||
20 | #define UPPER_BIT_RUBIN (((long) 1)<<(RUBIN_REG_SIZE-1)) | ||
21 | #define LOWER_BITS_RUBIN ((((long) 1)<<(RUBIN_REG_SIZE-1))-1) | ||
22 | |||
23 | |||
24 | #define BIT_DIVIDER_MIPS 1043 | ||
25 | static int bits_mips[8] = { 277,249,290,267,229,341,212,241}; /* mips32 */ | ||
26 | |||
27 | #include <linux/errno.h> | ||
28 | |||
29 | struct pushpull { | ||
30 | unsigned char *buf; | ||
31 | unsigned int buflen; | ||
32 | unsigned int ofs; | ||
33 | unsigned int reserve; | ||
34 | }; | ||
35 | |||
36 | struct rubin_state { | ||
37 | unsigned long p; | ||
38 | unsigned long q; | ||
39 | unsigned long rec_q; | ||
40 | long bit_number; | ||
41 | struct pushpull pp; | ||
42 | int bit_divider; | ||
43 | int bits[8]; | ||
44 | }; | ||
45 | |||
46 | static inline void init_pushpull(struct pushpull *pp, char *buf, unsigned buflen, unsigned ofs, unsigned reserve) | ||
47 | { | ||
48 | pp->buf = buf; | ||
49 | pp->buflen = buflen; | ||
50 | pp->ofs = ofs; | ||
51 | pp->reserve = reserve; | ||
52 | } | ||
53 | |||
54 | static inline int pushbit(struct pushpull *pp, int bit, int use_reserved) | ||
55 | { | ||
56 | if (pp->ofs >= pp->buflen - (use_reserved?0:pp->reserve)) { | ||
57 | return -ENOSPC; | ||
58 | } | ||
59 | |||
60 | if (bit) { | ||
61 | pp->buf[pp->ofs >> 3] |= (1<<(7-(pp->ofs &7))); | ||
62 | } | ||
63 | else { | ||
64 | pp->buf[pp->ofs >> 3] &= ~(1<<(7-(pp->ofs &7))); | ||
65 | } | ||
66 | pp->ofs++; | ||
67 | |||
68 | return 0; | ||
69 | } | ||
70 | |||
71 | static inline int pushedbits(struct pushpull *pp) | ||
72 | { | ||
73 | return pp->ofs; | ||
74 | } | ||
75 | |||
76 | static inline int pullbit(struct pushpull *pp) | ||
77 | { | ||
78 | int bit; | ||
79 | |||
80 | bit = (pp->buf[pp->ofs >> 3] >> (7-(pp->ofs & 7))) & 1; | ||
81 | |||
82 | pp->ofs++; | ||
83 | return bit; | ||
84 | } | ||
85 | |||
86 | static inline int pulledbits(struct pushpull *pp) | ||
87 | { | ||
88 | return pp->ofs; | ||
89 | } | ||
90 | |||
91 | |||
21 | static void init_rubin(struct rubin_state *rs, int div, int *bits) | 92 | static void init_rubin(struct rubin_state *rs, int div, int *bits) |
22 | { | 93 | { |
23 | int c; | 94 | int c; |