aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2/compr_rubin.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/jffs2/compr_rubin.c')
-rw-r--r--fs/jffs2/compr_rubin.c82
1 files changed, 77 insertions, 5 deletions
diff --git a/fs/jffs2/compr_rubin.c b/fs/jffs2/compr_rubin.c
index e792e675d624..1f3a4410523b 100644
--- a/fs/jffs2/compr_rubin.c
+++ b/fs/jffs2/compr_rubin.c
@@ -1,23 +1,95 @@
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
24struct rubin_state {
25 unsigned long p;
26 unsigned long q;
27 unsigned long rec_q;
28 long bit_number;
29 struct pushpull pp;
30 int bit_divider;
31 int bits[8];
32};
33
34#define BIT_DIVIDER_MIPS 1043
35static int bits_mips[8] = { 277,249,290,267,229,341,212,241}; /* mips32 */
36
37#include <linux/errno.h>
38
39struct pushpull {
40 unsigned char *buf;
41 unsigned int buflen;
42 unsigned int ofs;
43 unsigned int reserve;
44};
45
46
47static inline void init_pushpull(struct pushpull *pp, char *buf, unsigned buflen, unsigned ofs, unsigned reserve)
48{
49 pp->buf = buf;
50 pp->buflen = buflen;
51 pp->ofs = ofs;
52 pp->reserve = reserve;
53}
54
55static inline int pushbit(struct pushpull *pp, int bit, int use_reserved)
56{
57 if (pp->ofs >= pp->buflen - (use_reserved?0:pp->reserve)) {
58 return -ENOSPC;
59 }
60
61 if (bit) {
62 pp->buf[pp->ofs >> 3] |= (1<<(7-(pp->ofs &7)));
63 }
64 else {
65 pp->buf[pp->ofs >> 3] &= ~(1<<(7-(pp->ofs &7)));
66 }
67 pp->ofs++;
68
69 return 0;
70}
71
72static inline int pushedbits(struct pushpull *pp)
73{
74 return pp->ofs;
75}
76
77static inline int pullbit(struct pushpull *pp)
78{
79 int bit;
80
81 bit = (pp->buf[pp->ofs >> 3] >> (7-(pp->ofs & 7))) & 1;
82
83 pp->ofs++;
84 return bit;
85}
86
87static inline int pulledbits(struct pushpull *pp)
88{
89 return pp->ofs;
90}
91
92
21static void init_rubin(struct rubin_state *rs, int div, int *bits) 93static void init_rubin(struct rubin_state *rs, int div, int *bits)
22{ 94{
23 int c; 95 int c;