e2fsprogs/lib/ext2fs/bitops.c

85 lines
1.9 KiB
C
Raw Normal View History

1997-04-26 17:21:57 +04:00
/*
* bitops.c --- Bitmap frobbing code. See bitops.h for the inlined
* routines.
*
* Copyright (C) 1993, 1994 Theodore Ts'o. This file may be
* redistributed under the terms of the GNU Public License.
*
* Taken from <asm/bitops.h>, Copyright 1992, Linus Torvalds.
*/
#include <stdio.h>
#include <sys/types.h>
1997-04-26 17:34:30 +04:00
1997-04-26 17:21:57 +04:00
#include <linux/ext2_fs.h>
#include "ext2fs.h"
1997-04-26 17:34:30 +04:00
#ifndef _EXT2_HAVE_ASM_BITOPS_
1997-04-26 17:21:57 +04:00
/*
* For the benefit of those who are trying to port Linux to another
* architecture, here are some C-language equivalents. You should
* recode these in the native assmebly language, if at all possible.
*
1997-04-26 17:58:21 +04:00
* C language equivalents written by Theodore Ts'o, 9/26/92.
* Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian
* systems, as well as non-32 bit systems.
1997-04-26 17:21:57 +04:00
*/
1997-04-26 18:37:06 +04:00
int ext2fs_set_bit(int nr,void * addr)
1997-04-26 17:21:57 +04:00
{
1997-04-26 17:58:21 +04:00
int mask, retval;
unsigned char *ADDR = (unsigned char *) addr;
1997-04-26 17:21:57 +04:00
1997-04-26 17:58:21 +04:00
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
1997-04-26 17:21:57 +04:00
retval = (mask & *ADDR) != 0;
*ADDR |= mask;
return retval;
}
1997-04-26 18:37:06 +04:00
int ext2fs_clear_bit(int nr, void * addr)
1997-04-26 17:21:57 +04:00
{
1997-04-26 17:58:21 +04:00
int mask, retval;
unsigned char *ADDR = (unsigned char *) addr;
1997-04-26 17:21:57 +04:00
1997-04-26 17:58:21 +04:00
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
1997-04-26 17:21:57 +04:00
retval = (mask & *ADDR) != 0;
*ADDR &= ~mask;
return retval;
}
1997-04-26 18:37:06 +04:00
int ext2fs_test_bit(int nr, const void * addr)
1997-04-26 17:21:57 +04:00
{
1997-04-26 17:58:21 +04:00
int mask;
const unsigned char *ADDR = (const unsigned char *) addr;
1997-04-26 17:21:57 +04:00
1997-04-26 17:58:21 +04:00
ADDR += nr >> 3;
mask = 1 << (nr & 0x07);
1997-04-26 17:21:57 +04:00
return ((mask & *ADDR) != 0);
}
1997-04-26 17:58:21 +04:00
1997-04-26 17:34:30 +04:00
#endif /* !_EXT2_HAVE_ASM_BITOPS_ */
1997-04-26 17:21:57 +04:00
1997-04-26 17:34:30 +04:00
void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
const char *description)
1997-04-26 17:21:57 +04:00
{
1997-04-26 17:34:30 +04:00
if (description)
com_err(0, errcode, "#%u for %s", arg, description);
else
com_err(0, errcode, "#%u", arg);
1997-04-26 17:21:57 +04:00
}
1997-04-29 18:53:37 +04:00
void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
int code, unsigned long arg)
{
if (bitmap->description)
com_err(0, bitmap->base_error_code+code,
"#%u for %s", arg, bitmap->description);
else
com_err(0, bitmap->base_error_code + code, "#%u", arg);
}