summaryrefslogtreecommitdiff
path: root/lib/ext2fs/bitops.c
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>1997-04-26 13:21:57 +0000
committerTheodore Ts'o <tytso@mit.edu>1997-04-26 13:21:57 +0000
commit3839e65723771b85975f4263102dd3ceec4523c0 (patch)
tree02fde6f8259837e842e12bdc97bb9f92e4155b44 /lib/ext2fs/bitops.c
downloade2fsprogs-3839e65723771b85975f4263102dd3ceec4523c0.tar.gz
Many files:
Checkin of e2fsprogs 0.5b
Diffstat (limited to 'lib/ext2fs/bitops.c')
-rw-r--r--lib/ext2fs/bitops.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/lib/ext2fs/bitops.c b/lib/ext2fs/bitops.c
new file mode 100644
index 00000000..a53d8ee8
--- /dev/null
+++ b/lib/ext2fs/bitops.c
@@ -0,0 +1,95 @@
+/*
+ * 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>
+#include <linux/fs.h>
+#include <linux/ext2_fs.h>
+
+#include "ext2fs.h"
+
+#if (!defined(__i386__) && !defined(__i486__) && !defined(__i586__))
+
+/*
+ * 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.
+ * To guarantee atomicity, these routines call cli() and sti() to
+ * disable interrupts while they operate. (You have to provide inline
+ * routines to cli() and sti().)
+ *
+ * Also note, these routines assume that you have 32 bit integers.
+ * You will have to change this if you are trying to port Linux to the
+ * Alpha architecture or to a Cray. :-)
+ *
+ * C language equivalents written by Theodore Ts'o, 9/26/92
+ */
+
+int set_bit(int nr,void * addr)
+{
+ int mask, retval;
+ int *ADDR = (int *) addr;
+
+ ADDR += nr >> 5;
+ mask = 1 << (nr & 0x1f);
+ cli();
+ retval = (mask & *ADDR) != 0;
+ *ADDR |= mask;
+ sti();
+ return retval;
+}
+
+int clear_bit(int nr, void * addr)
+{
+ int mask, retval;
+ int *ADDR = (int *) addr;
+
+ ADDR += nr >> 5;
+ mask = 1 << (nr & 0x1f);
+ cli();
+ retval = (mask & *ADDR) != 0;
+ *ADDR &= ~mask;
+ sti();
+ return retval;
+}
+
+int test_bit(int nr, const void * addr)
+{
+ int mask;
+ const int *ADDR = (const int *) addr;
+
+ ADDR += nr >> 5;
+ mask = 1 << (nr & 0x1f);
+ return ((mask & *ADDR) != 0);
+}
+#endif /* !i386 */
+
+/*
+ * These are routines print warning messages; they are called by
+ * inline routines.
+ */
+const char *ext2fs_block_string = "block";
+const char *ext2fs_inode_string = "inode";
+const char *ext2fs_mark_string = "mark";
+const char *ext2fs_unmark_string = "unmark";
+const char *ext2fs_test_string = "test";
+
+void ext2fs_warn_bitmap(ext2_filsys fs, const char *op, const char *type,
+ int arg)
+{
+ char func[80];
+
+ sprintf(func, "ext2fs_%s_%s_bitmap", op, type);
+ com_err(func, 0, "INTERNAL ERROR: illegal %s #%d for %s",
+ type, arg, fs->device_name);
+}
+
+
+