home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / win95 / ext2tool.exe / EXT2FS / BITOPS.C < prev    next >
C/C++ Source or Header  |  1995-05-10  |  2KB  |  84 lines

  1. /*
  2.  * bitops.c --- Bitmap frobbing code.  See bitops.h for the inlined
  3.  *     routines.
  4.  * 
  5.  * Copyright (C) 1993, 1994 Theodore Ts'o.  This file may be
  6.  * redistributed under the terms of the GNU Public License.
  7.  * 
  8.  * Taken from <asm/bitops.h>, Copyright 1992, Linus Torvalds.
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <sys/types.h>
  13. #include <errno.h>
  14.  
  15. #include <linux/ext2_fs.h>
  16.  
  17. #include "ext2fs.h"
  18.  
  19. #ifndef _EXT2_HAVE_ASM_BITOPS_
  20.  
  21. /*
  22.  * For the benefit of those who are trying to port Linux to another
  23.  * architecture, here are some C-language equivalents.  You should
  24.  * recode these in the native assmebly language, if at all possible.
  25.  * To guarantee atomicity, these routines call cli() and sti() to
  26.  * disable interrupts while they operate.  (You have to provide inline
  27.  * routines to cli() and sti().)
  28.  *
  29.  * Also note, these routines assume that you have 32 bit integers.
  30.  * You will have to change this if you are trying to port Linux to the
  31.  * Alpha architecture or to a Cray.  :-)
  32.  * 
  33.  * C language equivalents written by Theodore Ts'o, 9/26/92
  34.  */
  35.  
  36. int set_bit(int nr,void * addr)
  37. {
  38.     int    mask, retval;
  39.     int    *ADDR = (int *) addr;
  40.  
  41.     ADDR += nr >> 5;
  42.     mask = 1 << (nr & 0x1f);
  43.     cli();
  44.     retval = (mask & *ADDR) != 0;
  45.     *ADDR |= mask;
  46.     sti();
  47.     return retval;
  48. }
  49.  
  50. int clear_bit(int nr, void * addr)
  51. {
  52.     int    mask, retval;
  53.     int    *ADDR = (int *) addr;
  54.  
  55.     ADDR += nr >> 5;
  56.     mask = 1 << (nr & 0x1f);
  57.     cli();
  58.     retval = (mask & *ADDR) != 0;
  59.     *ADDR &= ~mask;
  60.     sti();
  61.     return retval;
  62. }
  63.  
  64. int test_bit(int nr, const void * addr)
  65. {
  66.     int        mask;
  67.     const int    *ADDR = (const int *) addr;
  68.  
  69.     ADDR += nr >> 5;
  70.     mask = 1 << (nr & 0x1f);
  71.     return ((mask & *ADDR) != 0);
  72. }
  73. #endif    /* !_EXT2_HAVE_ASM_BITOPS_ */
  74.  
  75. void ext2fs_warn_bitmap(errcode_t errcode, unsigned long arg,
  76.             const char *description)
  77. {
  78.     if (description)
  79.         com_err(0, errcode, "#%u for %s", arg, description);
  80.     else
  81.         com_err(0, errcode, "#%u", arg);
  82. }
  83.  
  84.