X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=root-tree.c;h=6b8f8c1ce6c5cee3a810b4bc765ecfd30c67cfba;hb=cebf3b37228cbde730a5448ad2dfb044600d5e03;hp=934d02ef1cbf1070453046eda023bf49d5638350;hpb=31afed36899169cdb22c8bba16f8075aeae4007f;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/root-tree.c b/root-tree.c index 934d02e..6b8f8c1 100644 --- a/root-tree.c +++ b/root-tree.c @@ -31,12 +31,14 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, int ret; int slot; + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + search_key.objectid = objectid; search_key.type = BTRFS_ROOT_ITEM_KEY; search_key.offset = (u64)-1; - path = btrfs_alloc_path(); - BUG_ON(!path); ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0); if (ret < 0) goto out; @@ -49,7 +51,8 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, l = path->nodes[0]; slot = path->slots[0] - 1; btrfs_item_key_to_cpu(l, &found_key, slot); - if (found_key.objectid != objectid) { + if (found_key.type != BTRFS_ROOT_ITEM_KEY || + found_key.objectid != objectid) { ret = -ENOENT; goto out; } @@ -74,7 +77,9 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root u32 old_len; path = btrfs_alloc_path(); - BUG_ON(!path); + if (!path) + return -ENOMEM; + ret = btrfs_search_slot(trans, root, key, path, 0, 1); if (ret < 0) goto out; @@ -139,6 +144,31 @@ int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root return ret; } +/* drop the root item for 'key' from 'root' */ +int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, + struct btrfs_key *key) +{ + struct btrfs_path *path; + int ret; + + path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; + ret = btrfs_search_slot(trans, root, key, path, -1, 1); + if (ret < 0) + goto out; + + if (ret != 0) { + ret = -ENOENT; + goto out; + } + + ret = btrfs_del_item(trans, root, path); +out: + btrfs_free_path(path); + return ret; +} + /* * add a btrfs_root_ref item. type is either BTRFS_ROOT_REF_KEY * or BTRFS_ROOT_BACKREF_KEY.