1 // SPDX-License-Identifier: GPL-2.0+
5 int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
6 struct btrfs_root_item *item, struct btrfs_key *key)
8 struct btrfs_path *path;
9 struct btrfs_key search_key;
10 struct btrfs_key found_key;
11 struct extent_buffer *l;
15 path = btrfs_alloc_path();
19 search_key.objectid = objectid;
20 search_key.type = BTRFS_ROOT_ITEM_KEY;
21 search_key.offset = (u64)-1;
23 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
26 if (path->slots[0] == 0) {
33 slot = path->slots[0] - 1;
34 btrfs_item_key_to_cpu(l, &found_key, slot);
35 if (found_key.type != BTRFS_ROOT_ITEM_KEY ||
36 found_key.objectid != objectid) {
40 read_extent_buffer(l, item, btrfs_item_ptr_offset(l, slot),
42 memcpy(key, &found_key, sizeof(found_key));
45 btrfs_free_path(path);