]>
Commit | Line | Data |
---|---|---|
3839e657 TT |
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> | |
f3db3566 | 13 | |
3839e657 TT |
14 | #include <linux/ext2_fs.h> |
15 | ||
16 | #include "ext2fs.h" | |
17 | ||
f3db3566 | 18 | #ifndef _EXT2_HAVE_ASM_BITOPS_ |
3839e657 TT |
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 | * To guarantee atomicity, these routines call cli() and sti() to | |
25 | * disable interrupts while they operate. (You have to provide inline | |
26 | * routines to cli() and sti().) | |
27 | * | |
28 | * Also note, these routines assume that you have 32 bit integers. | |
29 | * You will have to change this if you are trying to port Linux to the | |
30 | * Alpha architecture or to a Cray. :-) | |
31 | * | |
32 | * C language equivalents written by Theodore Ts'o, 9/26/92 | |
33 | */ | |
34 | ||
35 | int set_bit(int nr,void * addr) | |
36 | { | |
37 | int mask, retval; | |
38 | int *ADDR = (int *) addr; | |
39 | ||
40 | ADDR += nr >> 5; | |
41 | mask = 1 << (nr & 0x1f); | |
42 | cli(); | |
43 | retval = (mask & *ADDR) != 0; | |
44 | *ADDR |= mask; | |
45 | sti(); | |
46 | return retval; | |
47 | } | |
48 | ||
49 | int clear_bit(int nr, void * addr) | |
50 | { | |
51 | int mask, retval; | |
52 | int *ADDR = (int *) addr; | |
53 | ||
54 | ADDR += nr >> 5; | |
55 | mask = 1 << (nr & 0x1f); | |
56 | cli(); | |
57 | retval = (mask & *ADDR) != 0; | |
58 | *ADDR &= ~mask; | |
59 | sti(); | |
60 | return retval; | |
61 | } | |
62 | ||
63 | int test_bit(int nr, const void * addr) | |
64 | { | |
65 | int mask; | |
66 | const int *ADDR = (const int *) addr; | |
67 | ||
68 | ADDR += nr >> 5; | |
69 | mask = 1 << (nr & 0x1f); | |
70 | return ((mask & *ADDR) != 0); | |
71 | } | |
f3db3566 | 72 | #endif /* !_EXT2_HAVE_ASM_BITOPS_ */ |
3839e657 | 73 | |
f3db3566 TT |
74 | void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg, |
75 | const char *description) | |
3839e657 | 76 | { |
f3db3566 TT |
77 | if (description) |
78 | com_err(0, errcode, "#%u for %s", arg, description); | |
79 | else | |
80 | com_err(0, errcode, "#%u", arg); | |
3839e657 TT |
81 | } |
82 |