3 #include "kerncompat.h"
4 #include "radix-tree.h"
7 #include "print-tree.h"
9 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
10 struct btrfs_root_item *item, struct btrfs_key *key)
12 struct btrfs_path path;
13 struct btrfs_key search_key;
18 search_key.objectid = objectid;
19 search_key.flags = (u32)-1;
20 search_key.offset = (u32)-1;
22 btrfs_init_path(&path);
23 ret = btrfs_search_slot(root, &search_key, &path, 0, 0);
27 l = &path.nodes[0]->leaf;
28 BUG_ON(path.slots[0] == 0);
29 slot = path.slots[0] - 1;
30 if (btrfs_key_objectid(&l->items[slot].key) != objectid) {
34 memcpy(item, btrfs_item_ptr(l, slot, struct btrfs_root_item),
36 btrfs_disk_key_to_cpu(key, &l->items[slot].key);
37 btrfs_release_path(root, &path);
43 int btrfs_update_root(struct btrfs_root *root, struct btrfs_key *key,
44 struct btrfs_root_item *item)
46 struct btrfs_path path;
51 btrfs_init_path(&path);
52 ret = btrfs_search_slot(root, key, &path, 0, 1);
56 l = &path.nodes[0]->leaf;
58 memcpy(btrfs_item_ptr(l, slot, struct btrfs_root_item), item,
61 btrfs_release_path(root, &path);
65 int btrfs_insert_root(struct btrfs_root *root, struct btrfs_key *key,
66 struct btrfs_root_item *item)
69 ret = btrfs_insert_item(root, key, item, sizeof(*item));
74 int btrfs_del_root(struct btrfs_root *root, struct btrfs_key *key)
76 struct btrfs_path path;
79 btrfs_init_path(&path);
80 ret = btrfs_search_slot(root, key, &path, -1, 1);
84 ret = btrfs_del_item(root, &path);
86 btrfs_release_path(root, &path);