bitops.c revision 3839e65723771b85975f4263102dd3ceec4523c0
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#include <linux/fs.h>
14#include <linux/ext2_fs.h>
15
16#include "ext2fs.h"
17
18#if (!defined(__i386__) && !defined(__i486__) && !defined(__i586__))
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
35int 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
49int 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
63int 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}
72#endif	/* !i386 */
73
74/*
75 * These are routines print warning messages; they are called by
76 * inline routines.
77 */
78const char *ext2fs_block_string = "block";
79const char *ext2fs_inode_string = "inode";
80const char *ext2fs_mark_string = "mark";
81const char *ext2fs_unmark_string = "unmark";
82const char *ext2fs_test_string = "test";
83
84void ext2fs_warn_bitmap(ext2_filsys fs, const char *op, const char *type,
85			int arg)
86{
87	char	func[80];
88
89	sprintf(func, "ext2fs_%s_%s_bitmap", op, type);
90	com_err(func, 0, "INTERNAL ERROR: illegal %s #%d for %s",
91		type, arg, fs->device_name);
92}
93
94
95
96