aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/root-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/root-tree.c')
-rw-r--r--fs/btrfs/root-tree.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 08f19ec88092..8bf21ba0a43b 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -21,6 +21,51 @@
21#include "disk-io.h" 21#include "disk-io.h"
22#include "print-tree.h" 22#include "print-tree.h"
23 23
24/*
25 * returns 0 on finding something, 1 if no more roots are there
26 * and < 0 on error
27 */
28int btrfs_search_root(struct btrfs_root *root, u64 search_start,
29 u64 *found_objectid)
30{
31 struct btrfs_path *path;
32 struct btrfs_key search_key;
33 int ret;
34
35 root = root->fs_info->tree_root;
36 search_key.objectid = search_start;
37 search_key.type = (u8)-1;
38 search_key.offset = (u64)-1;
39
40 path = btrfs_alloc_path();
41 BUG_ON(!path);
42again:
43 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
44 if (ret < 0)
45 goto out;
46 if (ret == 0) {
47 ret = 1;
48 goto out;
49 }
50 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
51 ret = btrfs_next_leaf(root, path);
52 if (ret)
53 goto out;
54 }
55 btrfs_item_key_to_cpu(path->nodes[0], &search_key, path->slots[0]);
56 if (search_key.type != BTRFS_ROOT_ITEM_KEY) {
57 search_key.offset++;
58 btrfs_release_path(root, path);
59 goto again;
60 }
61 ret = 0;
62 *found_objectid = search_key.objectid;
63
64out:
65 btrfs_free_path(path);
66 return ret;
67}
68
24int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, 69int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
25 struct btrfs_root_item *item, struct btrfs_key *key) 70 struct btrfs_root_item *item, struct btrfs_key *key)
26{ 71{
@@ -55,7 +100,6 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
55 memcpy(key, &found_key, sizeof(found_key)); 100 memcpy(key, &found_key, sizeof(found_key));
56 ret = 0; 101 ret = 0;
57out: 102out:
58 btrfs_release_path(root, path);
59 btrfs_free_path(path); 103 btrfs_free_path(path);
60 return ret; 104 return ret;
61} 105}