diff --git a/extent-cache.c b/extent-cache.c index 7656ab25..d80aead6 100644 --- a/extent-cache.c +++ b/extent-cache.c @@ -230,6 +230,15 @@ struct cache_extent *first_cache_extent(struct cache_tree *tree) return rb_entry(node, struct cache_extent, rb_node); } +struct cache_extent *last_cache_extent(struct cache_tree *tree) +{ + struct rb_node *node = rb_last(&tree->root); + + if (!node) + return NULL; + return rb_entry(node, struct cache_extent, rb_node); +} + struct cache_extent *prev_cache_extent(struct cache_extent *pe) { struct rb_node *node = rb_prev(&pe->rb_node); diff --git a/extent-cache.h b/extent-cache.h index cba83d15..a9d07e18 100644 --- a/extent-cache.h +++ b/extent-cache.h @@ -41,6 +41,7 @@ struct cache_extent { void cache_tree_init(struct cache_tree *tree); struct cache_extent *first_cache_extent(struct cache_tree *tree); +struct cache_extent *last_cache_extent(struct cache_tree *tree); struct cache_extent *prev_cache_extent(struct cache_extent *pe); struct cache_extent *next_cache_extent(struct cache_extent *pe);