Btrfs progs v4.17.1
[btrfs-progs-unstable/devel.git] / kernel-lib / radix-tree.h
blobbf96d839f068dc301548ddd68362d3751e63594a
1 /*
2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
20 * Copyright (C) 2001 Momchil Velikov
21 * Portions Copyright (C) 2001 Christoph Hellwig
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License as
25 * published by the Free Software Foundation; either version 2, or (at
26 * your option) any later version.
28 * This program is distributed in the hope that it will be useful, but
29 * WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 * General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 #ifndef _LINUX_RADIX_TREE_H
38 #define _LINUX_RADIX_TREE_H
40 #if BTRFS_FLAT_INCLUDES
41 #include "kerncompat.h"
42 #else
43 #include <btrfs/kerncompat.h>
44 #endif /* BTRFS_FLAT_INCLUDES */
46 #define RADIX_TREE_MAX_TAGS 2
48 /* root tags are stored in gfp_mask, shifted by __GFP_BITS_SHIFT */
49 struct radix_tree_root {
50 unsigned int height;
51 gfp_t gfp_mask;
52 struct radix_tree_node *rnode;
55 #define RADIX_TREE_INIT(mask) { \
56 .height = 0, \
57 .gfp_mask = (mask), \
58 .rnode = NULL, \
61 #define RADIX_TREE(name, mask) \
62 struct radix_tree_root name = RADIX_TREE_INIT(mask)
64 #define INIT_RADIX_TREE(root, mask) \
65 do { \
66 (root)->height = 0; \
67 (root)->gfp_mask = (mask); \
68 (root)->rnode = NULL; \
69 } while (0)
71 int radix_tree_insert(struct radix_tree_root *, unsigned long, void *);
72 void *radix_tree_lookup(struct radix_tree_root *, unsigned long);
73 void **radix_tree_lookup_slot(struct radix_tree_root *, unsigned long);
74 void *radix_tree_delete(struct radix_tree_root *, unsigned long);
75 unsigned int
76 radix_tree_gang_lookup(struct radix_tree_root *root, void **results,
77 unsigned long first_index, unsigned int max_items);
78 int radix_tree_preload(gfp_t gfp_mask);
79 void radix_tree_init(void);
80 void *radix_tree_tag_set(struct radix_tree_root *root,
81 unsigned long index, unsigned int tag);
82 void *radix_tree_tag_clear(struct radix_tree_root *root,
83 unsigned long index, unsigned int tag);
84 int radix_tree_tag_get(struct radix_tree_root *root,
85 unsigned long index, unsigned int tag);
86 unsigned int
87 radix_tree_gang_lookup_tag(struct radix_tree_root *root, void **results,
88 unsigned long first_index, unsigned int max_items,
89 unsigned int tag);
90 int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag);
92 static inline void radix_tree_preload_end(void)
94 preempt_enable();
97 #endif /* _LINUX_RADIX_TREE_H */