Add bitops header for subsequent bloom filter implementation. This is borrowed from a part of the previous patch. See: https://lore.kernel.org/all/20230802091750.74181-3-jeffl...@linux.alibaba.com/.
Signed-off-by: Hongzhen Luo <hongz...@linux.alibaba.com> --- include/erofs/bitops.h | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/Makefile.am | 1 + 2 files changed, 43 insertions(+) create mode 100644 include/erofs/bitops.h diff --git a/include/erofs/bitops.h b/include/erofs/bitops.h new file mode 100644 index 0000000..ef60d6e --- /dev/null +++ b/include/erofs/bitops.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ +#ifndef __EROFS_BITOPS_H +#define __EROFS_BITOPS_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include "defs.h" + +struct bitmap { + unsigned long size; /* size of bitmap in bits */ + unsigned long *map; +}; + +static inline void set_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p |= mask; +} + +static inline void clear_bit(int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p &= ~mask; +} + +static inline int test_bit(int nr, const volatile unsigned long *addr) +{ + return 1UL & (addr[BIT_WORD(nr)] >> (nr & (BITS_PER_LONG-1))); +} + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/lib/Makefile.am b/lib/Makefile.am index 2cb4cab..6b52470 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -20,6 +20,7 @@ noinst_HEADERS = $(top_srcdir)/include/erofs_fs.h \ $(top_srcdir)/include/erofs/io.h \ $(top_srcdir)/include/erofs/list.h \ $(top_srcdir)/include/erofs/print.h \ + $(top_srcdir)/include/erofs/bitops.h \ $(top_srcdir)/include/erofs/tar.h \ $(top_srcdir)/include/erofs/trace.h \ $(top_srcdir)/include/erofs/xattr.h \ -- 2.43.5