btrfs-progs: Fix the argument requirement for '--subvol-extents'
[btrfs-progs-unstable/devel.git] / extent-cache.h
blobcba83d1515f31dc669d50a95937ed5bf2c90d441
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.
19 #ifndef __EXTENT_CACHE_H__
20 #define __EXTENT_CACHE_H__
22 #if BTRFS_FLAT_INCLUDES
23 #include "kerncompat.h"
24 #include "rbtree.h"
25 #else
26 #include <btrfs/kerncompat.h>
27 #include <btrfs/rbtree.h>
28 #endif /* BTRFS_FLAT_INCLUDES */
30 struct cache_tree {
31 struct rb_root root;
34 struct cache_extent {
35 struct rb_node rb_node;
36 u64 objectid;
37 u64 start;
38 u64 size;
41 void cache_tree_init(struct cache_tree *tree);
43 struct cache_extent *first_cache_extent(struct cache_tree *tree);
44 struct cache_extent *prev_cache_extent(struct cache_extent *pe);
45 struct cache_extent *next_cache_extent(struct cache_extent *pe);
47 struct cache_extent *search_cache_extent(struct cache_tree *tree, u64 start);
48 struct cache_extent *lookup_cache_extent(struct cache_tree *tree,
49 u64 start, u64 size);
51 int add_cache_extent(struct cache_tree *tree, u64 start, u64 size);
52 int insert_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
53 void remove_cache_extent(struct cache_tree *tree, struct cache_extent *pe);
55 static inline int cache_tree_empty(struct cache_tree *tree)
57 return RB_EMPTY_ROOT(&tree->root);
60 typedef void (*free_cache_extent)(struct cache_extent *pe);
62 void cache_tree_free_extents(struct cache_tree *tree,
63 free_cache_extent free_func);
65 #define FREE_EXTENT_CACHE_BASED_TREE(name, free_func) \
66 static void free_##name##_tree(struct cache_tree *tree) \
67 { \
68 cache_tree_free_extents(tree, free_func); \
71 void free_extent_cache_tree(struct cache_tree *tree);
73 struct cache_extent *search_cache_extent2(struct cache_tree *tree,
74 u64 objectid, u64 start);
75 struct cache_extent *lookup_cache_extent2(struct cache_tree *tree,
76 u64 objectid, u64 start, u64 size);
77 int add_cache_extent2(struct cache_tree *tree,
78 u64 objectid, u64 start, u64 size);
79 int insert_cache_extent2(struct cache_tree *tree, struct cache_extent *pe);
81 #endif