blob: 98706113055d88d6147578bdbc3980a53d378bc7 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Mike Frysinger1fd98e02005-05-09 22:10:42 +00002/*
3 * bitops.c --- Bitmap frobbing code. See bitops.h for the inlined
Tim Rikerc1ef7bd2006-01-25 00:08:53 +00004 * routines.
5 *
Mike Frysinger1fd98e02005-05-09 22:10:42 +00006 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 *
8 * %Begin-Header%
9 * This file may be redistributed under the terms of the GNU Public
10 * License.
11 * %End-Header%
12 */
13
14#include <stdio.h>
15#if HAVE_SYS_TYPES_H
16#include <sys/types.h>
17#endif
18
19#include "ext2_fs.h"
20#include "ext2fs.h"
21
22#ifndef _EXT2_HAVE_ASM_BITOPS_
23
24/*
25 * For the benefit of those who are trying to port Linux to another
26 * architecture, here are some C-language equivalents. You should
27 * recode these in the native assmebly language, if at all possible.
28 *
29 * C language equivalents written by Theodore Ts'o, 9/26/92.
30 * Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian
31 * systems, as well as non-32 bit systems.
32 */
33
Mike Frysinger874af852006-03-08 07:03:27 +000034int ext2fs_set_bit(unsigned int nr,void * addr)
Mike Frysinger1fd98e02005-05-09 22:10:42 +000035{
36 int mask, retval;
37 unsigned char *ADDR = (unsigned char *) addr;
38
39 ADDR += nr >> 3;
40 mask = 1 << (nr & 0x07);
41 retval = mask & *ADDR;
42 *ADDR |= mask;
43 return retval;
44}
45
Mike Frysinger874af852006-03-08 07:03:27 +000046int ext2fs_clear_bit(unsigned int nr, void * addr)
Mike Frysinger1fd98e02005-05-09 22:10:42 +000047{
48 int mask, retval;
49 unsigned char *ADDR = (unsigned char *) addr;
50
51 ADDR += nr >> 3;
52 mask = 1 << (nr & 0x07);
53 retval = mask & *ADDR;
54 *ADDR &= ~mask;
55 return retval;
56}
57
Mike Frysinger874af852006-03-08 07:03:27 +000058int ext2fs_test_bit(unsigned int nr, const void * addr)
Mike Frysinger1fd98e02005-05-09 22:10:42 +000059{
60 int mask;
61 const unsigned char *ADDR = (const unsigned char *) addr;
62
63 ADDR += nr >> 3;
64 mask = 1 << (nr & 0x07);
65 return (mask & *ADDR);
66}
67
68#endif /* !_EXT2_HAVE_ASM_BITOPS_ */
69
70void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
71 const char *description)
72{
73#ifndef OMIT_COM_ERR
74 if (description)
Rob Landley7c94bed2006-05-03 21:58:45 +000075 bb_error_msg("#%lu for %s", arg, description);
Mike Frysinger1fd98e02005-05-09 22:10:42 +000076 else
Rob Landley7c94bed2006-05-03 21:58:45 +000077 bb_error_msg("#%lu", arg);
Mike Frysinger1fd98e02005-05-09 22:10:42 +000078#endif
79}
80
81void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
82 int code, unsigned long arg)
83{
84#ifndef OMIT_COM_ERR
85 if (bitmap->description)
Rob Landley7c94bed2006-05-03 21:58:45 +000086 bb_error_msg("#%lu for %s", arg, bitmap->description);
Mike Frysinger1fd98e02005-05-09 22:10:42 +000087 else
Rob Landley7c94bed2006-05-03 21:58:45 +000088 bb_error_msg("#%lu", arg);
Mike Frysinger1fd98e02005-05-09 22:10:42 +000089#endif
90}
91