1 #include <linux/module.h>
4 #include "print-tree.h"
6 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
7 struct btrfs_root_item *item, struct btrfs_key *key)
9 struct btrfs_path path;
10 struct btrfs_key search_key;
15 search_key.objectid = objectid;
16 search_key.flags = (u32)-1;
17 search_key.offset = (u32)-1;
19 btrfs_init_path(&path);
20 ret = btrfs_search_slot(NULL, root, &search_key, &path, 0, 0);
24 l = btrfs_buffer_leaf(path.nodes[0]);
25 BUG_ON(path.slots[0] == 0);
26 slot = path.slots[0] - 1;
27 if (btrfs_disk_key_objectid(&l->items[slot].key) != objectid) {
31 memcpy(item, btrfs_item_ptr(l, slot, struct btrfs_root_item),
33 btrfs_disk_key_to_cpu(key, &l->items[slot].key);
34 btrfs_release_path(root, &path);
40 int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
41 *root, struct btrfs_key *key, struct btrfs_root_item
44 struct btrfs_path path;
48 struct btrfs_root_item *update_item;
50 btrfs_init_path(&path);
51 ret = btrfs_search_slot(trans, root, key, &path, 0, 1);
55 l = btrfs_buffer_leaf(path.nodes[0]);
57 update_item = btrfs_item_ptr(l, slot, struct btrfs_root_item);
58 btrfs_memcpy(root, l, update_item, item, sizeof(*item));
59 btrfs_mark_buffer_dirty(path.nodes[0]);
61 btrfs_release_path(root, &path);
65 int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
66 *root, struct btrfs_key *key, struct btrfs_root_item
70 ret = btrfs_insert_item(trans, root, key, item, sizeof(*item));
75 int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
76 struct btrfs_key *key)
78 struct btrfs_path path;
81 btrfs_init_path(&path);
82 ret = btrfs_search_slot(trans, root, key, &path, -1, 1);
86 ret = btrfs_del_item(trans, root, &path);
88 btrfs_release_path(root, &path);