comparison packages/fs/jffs2/current/src/pushpull.h @ 208:e0c0827131d1 ecos

Merge from eCos master repository on 2002-05-20-20:11:54-BST
author jlarmour
date Mon, 20 May 2002 22:19:26 +0000
parents
children a7947d436e85
comparison
equal deleted inserted replaced
207:74c807ddde34 208:e0c0827131d1
1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
10 * $Id: pushpull.h,v 1.6 2002/01/25 01:49:26 dwmw2 Exp $
11 *
12 */
13
14 #ifndef __PUSHPULL_H__
15 #define __PUSHPULL_H__
16
17 #ifndef __ECOS
18 #include <linux/errno.h>
19 #else
20 #include <errno.h>
21 #endif
22
23 struct pushpull {
24 unsigned char *buf;
25 unsigned int buflen;
26 unsigned int ofs;
27 unsigned int reserve;
28 };
29
30
31 static inline void init_pushpull(struct pushpull *pp, char *buf, unsigned buflen, unsigned ofs, unsigned reserve)
32 {
33 pp->buf = buf;
34 pp->buflen = buflen;
35 pp->ofs = ofs;
36 pp->reserve = reserve;
37 }
38
39 static inline int pushbit(struct pushpull *pp, int bit, int use_reserved)
40 {
41 if (pp->ofs >= pp->buflen - (use_reserved?0:pp->reserve)) {
42 return -ENOSPC;
43 }
44
45 if (bit) {
46 pp->buf[pp->ofs >> 3] |= (1<<(7-(pp->ofs &7)));
47 }
48 else {
49 pp->buf[pp->ofs >> 3] &= ~(1<<(7-(pp->ofs &7)));
50 }
51 pp->ofs++;
52
53 return 0;
54 }
55
56 static inline int pushedbits(struct pushpull *pp)
57 {
58 return pp->ofs;
59 }
60
61 static inline int pullbit(struct pushpull *pp)
62 {
63 int bit;
64
65 bit = (pp->buf[pp->ofs >> 3] >> (7-(pp->ofs & 7))) & 1;
66
67 pp->ofs++;
68 return bit;
69 }
70
71 static inline int pulledbits(struct pushpull *pp)
72 {
73 return pp->ofs;
74 }
75
76 #endif /* __PUSHPULL_H__ */