3
0

bitops.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * bitops.c --- Bitmap frobbing code. See bitops.h for the inlined
  4. * routines.
  5. *
  6. * 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. #include <stdio.h>
  14. #if HAVE_SYS_TYPES_H
  15. #include <sys/types.h>
  16. #endif
  17. #include "ext2_fs.h"
  18. #include "ext2fs.h"
  19. #ifndef _EXT2_HAVE_ASM_BITOPS_
  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. *
  25. * C language equivalents written by Theodore Ts'o, 9/26/92.
  26. * Modified by Pete A. Zaitcev 7/14/95 to be portable to big endian
  27. * systems, as well as non-32 bit systems.
  28. */
  29. int ext2fs_set_bit(unsigned int nr,void * addr)
  30. {
  31. int mask, retval;
  32. unsigned char *ADDR = (unsigned char *) addr;
  33. ADDR += nr >> 3;
  34. mask = 1 << (nr & 0x07);
  35. retval = mask & *ADDR;
  36. *ADDR |= mask;
  37. return retval;
  38. }
  39. int ext2fs_clear_bit(unsigned int nr, void * addr)
  40. {
  41. int mask, retval;
  42. unsigned char *ADDR = (unsigned char *) addr;
  43. ADDR += nr >> 3;
  44. mask = 1 << (nr & 0x07);
  45. retval = mask & *ADDR;
  46. *ADDR &= ~mask;
  47. return retval;
  48. }
  49. int ext2fs_test_bit(unsigned int nr, const void * addr)
  50. {
  51. int mask;
  52. const unsigned char *ADDR = (const unsigned char *) addr;
  53. ADDR += nr >> 3;
  54. mask = 1 << (nr & 0x07);
  55. return (mask & *ADDR);
  56. }
  57. #endif /* !_EXT2_HAVE_ASM_BITOPS_ */
  58. void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
  59. const char *description)
  60. {
  61. #ifndef OMIT_COM_ERR
  62. if (description)
  63. bb_error_msg("#%lu for %s", arg, description);
  64. else
  65. bb_error_msg("#%lu", arg);
  66. #endif
  67. }
  68. void ext2fs_warn_bitmap2(ext2fs_generic_bitmap bitmap,
  69. int code, unsigned long arg)
  70. {
  71. #ifndef OMIT_COM_ERR
  72. if (bitmap->description)
  73. bb_error_msg("#%lu for %s", arg, bitmap->description);
  74. else
  75. bb_error_msg("#%lu", arg);
  76. #endif
  77. }