bitops.c 2.0 KB

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