1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2007 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef _LIBCFS_BITMAP_H_
23 #define _LIBCFS_BITMAP_H_
28 unsigned long data[0];
31 #define CFS_BITMAP_SIZE(nbits) \
32 (((nbits/BITS_PER_LONG)+1)*sizeof(long)+sizeof(bitmap_t))
35 bitmap_t *ALLOCATE_BITMAP(int size)
39 OBD_ALLOC(ptr, CFS_BITMAP_SIZE(size));
48 #define FREE_BITMAP(ptr) OBD_FREE(ptr, CFS_BITMAP_SIZE(ptr->size))
51 void cfs_bitmap_set(bitmap_t *bitmap, int nbit)
53 set_bit(nbit, bitmap->data);
57 void cfs_bitmap_clear(bitmap_t *bitmap, int nbit)
59 clear_bit(nbit, bitmap->data);
63 int cfs_bitmap_check(bitmap_t *bitmap, int nbit)
65 return test_bit(nbit, bitmap->data);
68 /* return 0 is bitmap has none set bits */
70 int cfs_bitmap_check_empty(bitmap_t *bitmap)
72 return find_first_bit(bitmap->data, bitmap->size) == bitmap->size;
75 #define cfs_foreach_bit(bitmap, pos) \
76 for((pos)=find_first_bit((bitmap)->data, bitmap->size); \
77 (pos) < (bitmap)->size; \
78 (pos) = find_next_bit((bitmap)->data, (bitmap)->size, (pos)))