Automatic merge of rsync://rsync.kernel.org/pub/scm/linux/kernel/git/gregkh/driver...
[linux-2.6/verdex.git] / fs / jffs2 / pushpull.h
blobc0c2a9158dffb817b3abea9f0d841bf97b8cf836
1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright (C) 2001, 2002 Red Hat, Inc.
6 * Created by David Woodhouse <dwmw2@infradead.org>
8 * For licensing information, see the file 'LICENCE' in this directory.
10 * $Id: pushpull.h,v 1.10 2004/11/16 20:36:11 dwmw2 Exp $
14 #ifndef __PUSHPULL_H__
15 #define __PUSHPULL_H__
17 #include <linux/errno.h>
19 struct pushpull {
20 unsigned char *buf;
21 unsigned int buflen;
22 unsigned int ofs;
23 unsigned int reserve;
27 static inline void init_pushpull(struct pushpull *pp, char *buf, unsigned buflen, unsigned ofs, unsigned reserve)
29 pp->buf = buf;
30 pp->buflen = buflen;
31 pp->ofs = ofs;
32 pp->reserve = reserve;
35 static inline int pushbit(struct pushpull *pp, int bit, int use_reserved)
37 if (pp->ofs >= pp->buflen - (use_reserved?0:pp->reserve)) {
38 return -ENOSPC;
41 if (bit) {
42 pp->buf[pp->ofs >> 3] |= (1<<(7-(pp->ofs &7)));
44 else {
45 pp->buf[pp->ofs >> 3] &= ~(1<<(7-(pp->ofs &7)));
47 pp->ofs++;
49 return 0;
52 static inline int pushedbits(struct pushpull *pp)
54 return pp->ofs;
57 static inline int pullbit(struct pushpull *pp)
59 int bit;
61 bit = (pp->buf[pp->ofs >> 3] >> (7-(pp->ofs & 7))) & 1;
63 pp->ofs++;
64 return bit;
67 static inline int pulledbits(struct pushpull *pp)
69 return pp->ofs;
72 #endif /* __PUSHPULL_H__ */