1 #include <linux/module.h>
4 #define BIT_ARRAY_BYTES 256
5 #define BIT_RADIX_BITS_PER_ARRAY ((BIT_ARRAY_BYTES - sizeof(unsigned long)) * 8)
7 extern struct kmem_cache *btrfs_bit_radix_cachep;
8 int set_radix_bit(struct radix_tree_root *radix, unsigned long bit)
15 slot = bit / BIT_RADIX_BITS_PER_ARRAY;
16 bit_slot = bit % BIT_RADIX_BITS_PER_ARRAY;
18 bits = radix_tree_lookup(radix, slot);
20 bits = kmem_cache_alloc(btrfs_bit_radix_cachep, GFP_NOFS);
23 memset(bits + 1, 0, BIT_ARRAY_BYTES - sizeof(unsigned long));
25 ret = radix_tree_insert(radix, slot, bits);
29 ret = test_and_set_bit(bit_slot, bits + 1);
35 int test_radix_bit(struct radix_tree_root *radix, unsigned long bit)
41 slot = bit / BIT_RADIX_BITS_PER_ARRAY;
42 bit_slot = bit % BIT_RADIX_BITS_PER_ARRAY;
44 bits = radix_tree_lookup(radix, slot);
47 return test_bit(bit_slot, bits + 1);
50 int clear_radix_bit(struct radix_tree_root *radix, unsigned long bit)
58 slot = bit / BIT_RADIX_BITS_PER_ARRAY;
59 bit_slot = bit % BIT_RADIX_BITS_PER_ARRAY;
61 bits = radix_tree_lookup(radix, slot);
64 clear_bit(bit_slot, bits + 1);
65 for (i = 1; i < BIT_ARRAY_BYTES / sizeof(unsigned long); i++) {
72 bits = radix_tree_delete(radix, slot);
74 kmem_cache_free(btrfs_bit_radix_cachep, bits);
79 int find_first_radix_bit(struct radix_tree_root *radix, unsigned long *retbits,
83 unsigned long *gang[4];
89 ret = radix_tree_gang_lookup(radix, (void **)gang, 0, ARRAY_SIZE(gang));
90 for (i = 0; i < ret && nr > 0; i++) {
94 found = find_next_bit(bits + 1,
95 BIT_RADIX_BITS_PER_ARRAY,
97 if (found < BIT_RADIX_BITS_PER_ARRAY) {
99 BIT_RADIX_BITS_PER_ARRAY + found;