2 * BTRFS filesystem implementation for U-Boot
4 * 2017 Marek Behun, CZ.NIC, marek.behun@nic.cz
6 * SPDX-License-Identifier: GPL-2.0+
11 static void read_root_item(struct btrfs_path *p, struct btrfs_root_item *item)
16 len = btrfs_path_item_size(p);
17 memcpy(item, btrfs_path_item_ptr(p, struct btrfs_root_item), len);
18 btrfs_root_item_to_cpu(item);
20 if (len < sizeof(*item))
22 if (!reset && item->generation != item->generation_v2) {
23 if (item->generation_v2 != 0)
24 printf("%s: generation != generation_v2 in root item",
29 memset(&item->generation_v2, 0,
30 sizeof(*item) - offsetof(struct btrfs_root_item,
35 int btrfs_find_root(u64 objectid, struct btrfs_root *root,
36 struct btrfs_root_item *root_item)
38 struct btrfs_path path;
39 struct btrfs_root_item my_root_item;
41 if (!btrfs_search_tree_key_type(&btrfs_info.tree_root, objectid,
42 BTRFS_ROOT_ITEM_KEY, &path))
46 root_item = &my_root_item;
47 read_root_item(&path, root_item);
50 root->objectid = objectid;
51 root->bytenr = root_item->bytenr;
52 root->root_dirid = root_item->root_dirid;
55 btrfs_free_path(&path);
59 u64 btrfs_lookup_root_ref(u64 subvolid, struct btrfs_root_ref *refp, char *name)
61 struct btrfs_path path;
62 struct btrfs_key *key;
63 struct btrfs_root_ref *ref;
66 key = btrfs_search_tree_key_type(&btrfs_info.tree_root, subvolid,
67 BTRFS_ROOT_BACKREF_KEY, &path);
72 ref = btrfs_path_item_ptr(&path, struct btrfs_root_ref);
73 btrfs_root_ref_to_cpu(ref);
79 if (ref->name_len > BTRFS_VOL_NAME_MAX) {
80 printf("%s: volume name too long: %u\n", __func__,
85 memcpy(name, ref + 1, ref->name_len);
90 btrfs_free_path(&path);