diff options
Diffstat (limited to 'fs/jffs2/pushpull.h')
-rw-r--r-- | fs/jffs2/pushpull.h | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/fs/jffs2/pushpull.h b/fs/jffs2/pushpull.h new file mode 100644 index 000000000000..c0c2a9158dff --- /dev/null +++ b/fs/jffs2/pushpull.h | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * JFFS2 -- Journalling Flash File System, Version 2. | ||
3 | * | ||
4 | * Copyright (C) 2001, 2002 Red Hat, Inc. | ||
5 | * | ||
6 | * Created by David Woodhouse <dwmw2@infradead.org> | ||
7 | * | ||
8 | * For licensing information, see the file 'LICENCE' in this directory. | ||
9 | * | ||
10 | * $Id: pushpull.h,v 1.10 2004/11/16 20:36:11 dwmw2 Exp $ | ||
11 | * | ||
12 | */ | ||
13 | |||
14 | #ifndef __PUSHPULL_H__ | ||
15 | #define __PUSHPULL_H__ | ||
16 | |||
17 | #include <linux/errno.h> | ||
18 | |||
19 | struct pushpull { | ||
20 | unsigned char *buf; | ||
21 | unsigned int buflen; | ||
22 | unsigned int ofs; | ||
23 | unsigned int reserve; | ||
24 | }; | ||
25 | |||
26 | |||
27 | static inline void init_pushpull(struct pushpull *pp, char *buf, unsigned buflen, unsigned ofs, unsigned reserve) | ||
28 | { | ||
29 | pp->buf = buf; | ||
30 | pp->buflen = buflen; | ||
31 | pp->ofs = ofs; | ||
32 | pp->reserve = reserve; | ||
33 | } | ||
34 | |||
35 | static inline int pushbit(struct pushpull *pp, int bit, int use_reserved) | ||
36 | { | ||
37 | if (pp->ofs >= pp->buflen - (use_reserved?0:pp->reserve)) { | ||
38 | return -ENOSPC; | ||
39 | } | ||
40 | |||
41 | if (bit) { | ||
42 | pp->buf[pp->ofs >> 3] |= (1<<(7-(pp->ofs &7))); | ||
43 | } | ||
44 | else { | ||
45 | pp->buf[pp->ofs >> 3] &= ~(1<<(7-(pp->ofs &7))); | ||
46 | } | ||
47 | pp->ofs++; | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||
52 | static inline int pushedbits(struct pushpull *pp) | ||
53 | { | ||
54 | return pp->ofs; | ||
55 | } | ||
56 | |||
57 | static inline int pullbit(struct pushpull *pp) | ||
58 | { | ||
59 | int bit; | ||
60 | |||
61 | bit = (pp->buf[pp->ofs >> 3] >> (7-(pp->ofs & 7))) & 1; | ||
62 | |||
63 | pp->ofs++; | ||
64 | return bit; | ||
65 | } | ||
66 | |||
67 | static inline int pulledbits(struct pushpull *pp) | ||
68 | { | ||
69 | return pp->ofs; | ||
70 | } | ||
71 | |||
72 | #endif /* __PUSHPULL_H__ */ | ||