Whamcloud - gitweb
Many files:
[tools/e2fsprogs.git] / lib / ext2fs / bitops.c
1 /*
2  * bitops.c --- Bitmap frobbing code.  See bitops.h for the inlined
3  *      routines.
4  * 
5  * Copyright (C) 1993, 1994 Theodore Ts'o.  This file may be
6  * redistributed under the terms of the GNU Public License.
7  * 
8  * Taken from <asm/bitops.h>, Copyright 1992, Linus Torvalds.
9  */
10
11 #include <stdio.h>
12 #include <sys/types.h>
13
14 #include <linux/ext2_fs.h>
15
16 #include "ext2fs.h"
17
18 #ifndef _EXT2_HAVE_ASM_BITOPS_
19
20 /*
21  * For the benefit of those who are trying to port Linux to another
22  * architecture, here are some C-language equivalents.  You should
23  * recode these in the native assmebly language, if at all possible.
24  *
25  * C language equivalents written by Theodore Ts'o, 9/26/92.
26  * Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian
27  * systems, as well as non-32 bit systems.
28  */
29
30 int set_bit(int nr,void * addr)
31 {
32         int             mask, retval;
33         unsigned char   *ADDR = (unsigned char *) addr;
34
35         ADDR += nr >> 3;
36         mask = 1 << (nr & 0x07);
37         retval = (mask & *ADDR) != 0;
38         *ADDR |= mask;
39         return retval;
40 }
41
42 int clear_bit(int nr, void * addr)
43 {
44         int             mask, retval;
45         unsigned char   *ADDR = (unsigned char *) addr;
46
47         ADDR += nr >> 3;
48         mask = 1 << (nr & 0x07);
49         retval = (mask & *ADDR) != 0;
50         *ADDR &= ~mask;
51         return retval;
52 }
53
54 int test_bit(int nr, const void * addr)
55 {
56         int                     mask;
57         const unsigned char     *ADDR = (const unsigned char *) addr;
58
59         ADDR += nr >> 3;
60         mask = 1 << (nr & 0x07);
61         return ((mask & *ADDR) != 0);
62 }
63
64 #endif  /* !_EXT2_HAVE_ASM_BITOPS_ */
65
66 void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
67                         const char *description)
68 {
69         if (description)
70                 com_err(0, errcode, "#%u for %s", arg, description);
71         else
72                 com_err(0, errcode, "#%u", arg);
73 }
74