2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
21 #include "kerncompat.h"
22 #include "radix-tree.h"
25 #include "print-tree.h"
27 int btrfs_find_last_root(struct btrfs_root
*root
, u64 objectid
,
28 struct btrfs_root_item
*item
, struct btrfs_key
*key
)
30 struct btrfs_path path
;
31 struct btrfs_key search_key
;
36 search_key
.objectid
= objectid
;
37 search_key
.type
= (u8
)-1;
38 search_key
.offset
= (u64
)-1;
40 btrfs_init_path(&path
);
41 ret
= btrfs_search_slot(NULL
, root
, &search_key
, &path
, 0, 0);
45 l
= &path
.nodes
[0]->leaf
;
46 BUG_ON(path
.slots
[0] == 0);
47 slot
= path
.slots
[0] - 1;
48 if (btrfs_disk_key_objectid(&l
->items
[slot
].key
) != objectid
) {
52 memcpy(item
, btrfs_item_ptr(l
, slot
, struct btrfs_root_item
),
54 btrfs_disk_key_to_cpu(key
, &l
->items
[slot
].key
);
55 btrfs_release_path(root
, &path
);
61 int btrfs_update_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
62 *root
, struct btrfs_key
*key
, struct btrfs_root_item
65 struct btrfs_path path
;
70 btrfs_init_path(&path
);
71 ret
= btrfs_search_slot(trans
, root
, key
, &path
, 0, 1);
75 l
= &path
.nodes
[0]->leaf
;
77 memcpy(btrfs_item_ptr(l
, slot
, struct btrfs_root_item
), item
,
80 btrfs_release_path(root
, &path
);
84 int btrfs_insert_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
85 *root
, struct btrfs_key
*key
, struct btrfs_root_item
89 ret
= btrfs_insert_item(trans
, root
, key
, item
, sizeof(*item
));
94 int btrfs_del_root(struct btrfs_trans_handle
*trans
, struct btrfs_root
*root
,
95 struct btrfs_key
*key
)
97 struct btrfs_path path
;
100 btrfs_init_path(&path
);
101 ret
= btrfs_search_slot(trans
, root
, key
, &path
, -1, 1);
105 ret
= btrfs_del_item(trans
, root
, &path
);
107 btrfs_release_path(root
, &path
);