Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * bitops.c --- Bitmap frobbing code. See bitops.h for the inlined |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 3 | * routines. |
| 4 | * |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 5 | * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. |
| 6 | * |
| 7 | * %Begin-Header% |
| 8 | * This file may be redistributed under the terms of the GNU Public |
| 9 | * License. |
| 10 | * %End-Header% |
| 11 | */ |
| 12 | |
| 13 | #include <stdio.h> |
| 14 | #if HAVE_SYS_TYPES_H |
| 15 | #include <sys/types.h> |
| 16 | #endif |
| 17 | |
| 18 | #include "ext2_fs.h" |
| 19 | #include "ext2fs.h" |
| 20 | |
| 21 | #ifndef _EXT2_HAVE_ASM_BITOPS_ |
| 22 | |
| 23 | /* |
| 24 | * For the benefit of those who are trying to port Linux to another |
| 25 | * architecture, here are some C-language equivalents. You should |
| 26 | * recode these in the native assmebly language, if at all possible. |
| 27 | * |
| 28 | * C language equivalents written by Theodore Ts'o, 9/26/92. |
| 29 | * Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian |
| 30 | * systems, as well as non-32 bit systems. |
| 31 | */ |
| 32 | |
Mike Frysinger | 874af85 | 2006-03-08 07:03:27 +0000 | [diff] [blame] | 33 | int ext2fs_set_bit(unsigned int nr,void * addr) |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 34 | { |
| 35 | int mask, retval; |
| 36 | unsigned char *ADDR = (unsigned char *) addr; |
| 37 | |
| 38 | ADDR += nr >> 3; |
| 39 | mask = 1 << (nr & 0x07); |
| 40 | retval = mask & *ADDR; |
| 41 | *ADDR |= mask; |
| 42 | return retval; |
| 43 | } |
| 44 | |
Mike Frysinger | 874af85 | 2006-03-08 07:03:27 +0000 | [diff] [blame] | 45 | int ext2fs_clear_bit(unsigned int nr, void * addr) |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 46 | { |
| 47 | int mask, retval; |
| 48 | unsigned char *ADDR = (unsigned char *) addr; |
| 49 | |
| 50 | ADDR += nr >> 3; |
| 51 | mask = 1 << (nr & 0x07); |
| 52 | retval = mask & *ADDR; |
| 53 | *ADDR &= ~mask; |
| 54 | return retval; |
| 55 | } |
| 56 | |
Mike Frysinger | 874af85 | 2006-03-08 07:03:27 +0000 | [diff] [blame] | 57 | int ext2fs_test_bit(unsigned int nr, const void * addr) |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 58 | { |
| 59 | int mask; |
| 60 | const unsigned char *ADDR = (const unsigned char *) addr; |
| 61 | |
| 62 | ADDR += nr >> 3; |
| 63 | mask = 1 << (nr & 0x07); |
| 64 | return (mask & *ADDR); |
| 65 | } |
| 66 | |
| 67 | #endif /* !_EXT2_HAVE_ASM_BITOPS_ */ |
| 68 | |
| 69 | void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg, |
| 70 | const char *description) |
| 71 | { |
| 72 | #ifndef OMIT_COM_ERR |
| 73 | if (description) |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame^] | 74 | bb_error_msg("#%lu for %s", arg, description); |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 75 | else |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame^] | 76 | bb_error_msg("#%lu", arg); |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 77 | #endif |
| 78 | } |
| 79 | |
| 80 | void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap, |
| 81 | int code, unsigned long arg) |
| 82 | { |
| 83 | #ifndef OMIT_COM_ERR |
| 84 | if (bitmap->description) |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame^] | 85 | bb_error_msg("#%lu for %s", arg, bitmap->description); |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 86 | else |
Rob Landley | 7c94bed | 2006-05-03 21:58:45 +0000 | [diff] [blame^] | 87 | bb_error_msg("#%lu", arg); |
Mike Frysinger | 1fd98e0 | 2005-05-09 22:10:42 +0000 | [diff] [blame] | 88 | #endif |
| 89 | } |
| 90 | |