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 path
= btrfs_alloc_path();
21 btrfs_init_path(path
);
22 ret
= btrfs_search_slot(NULL
, root
, &search_key
, path
, 0, 0);
26 l
= btrfs_buffer_leaf(path
->nodes
[0]);
27 BUG_ON(path
->slots
[0] == 0);
28 slot
= path
->slots
[0] - 1;
29 if (btrfs_disk_key_objectid(&l
->items
[slot
].key
) != objectid
) {
33 memcpy(item
, btrfs_item_ptr(l
, slot
, struct btrfs_root_item
),
35 btrfs_disk_key_to_cpu(key
, &l
->items
[slot
].key
);
38 btrfs_release_path(root
, path
);
39 btrfs_free_path(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
;
51 struct btrfs_root_item
*update_item
;
53 path
= btrfs_alloc_path();
55 btrfs_init_path(path
);
56 ret
= btrfs_search_slot(trans
, root
, key
, path
, 0, 1);
60 l
= btrfs_buffer_leaf(path
->nodes
[0]);
61 slot
= path
->slots
[0];
62 update_item
= btrfs_item_ptr(l
, slot
, struct btrfs_root_item
);
63 btrfs_memcpy(root
, l
, update_item
, item
, sizeof(*item
));
64 btrfs_mark_buffer_dirty(path
->nodes
[0]);
66 btrfs_release_path(root
, path
);
67 btrfs_free_path(path
);
71 int btrfs_insert_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
72 *root
, struct btrfs_key
*key
, struct btrfs_root_item
76 ret
= btrfs_insert_item(trans
, root
, key
, item
, sizeof(*item
));
81 int btrfs_del_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
82 struct btrfs_key
*key
)
84 struct btrfs_path
*path
;
87 path
= btrfs_alloc_path();
89 btrfs_init_path(path
);
90 ret
= btrfs_search_slot(trans
, root
, key
, path
, -1, 1);
94 ret
= btrfs_del_item(trans
, root
, path
);
96 btrfs_release_path(root
, path
);
97 btrfs_free_path(path
);
This page took 0.042628 seconds and 6 git commands to generate.