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(NULL
, 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_disk_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_trans_handle
*trans
, struct btrfs_root
44 *root
, struct btrfs_key
*key
, struct btrfs_root_item
47 struct btrfs_path path
;
52 btrfs_init_path(&path
);
53 ret
= btrfs_search_slot(trans
, root
, key
, &path
, 0, 1);
57 l
= &path
.nodes
[0]->leaf
;
59 memcpy(btrfs_item_ptr(l
, slot
, struct btrfs_root_item
), item
,
62 btrfs_release_path(root
, &path
);
66 int btrfs_insert_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
67 *root
, struct btrfs_key
*key
, struct btrfs_root_item
71 ret
= btrfs_insert_item(trans
, root
, key
, item
, sizeof(*item
));
76 int btrfs_del_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
77 struct btrfs_key
*key
)
79 struct btrfs_path path
;
82 btrfs_init_path(&path
);
83 ret
= btrfs_search_slot(trans
, root
, key
, &path
, -1, 1);
87 ret
= btrfs_del_item(trans
, root
, &path
);
89 btrfs_release_path(root
, &path
);