0001
0002
0003
0004
0005
0006 #include "ctree.h"
0007 #include "disk-io.h"
0008
0009 int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
0010 struct btrfs_root *root, u64 offset)
0011 {
0012 struct btrfs_path *path;
0013 struct btrfs_key key;
0014 int ret = 0;
0015
0016 key.objectid = BTRFS_ORPHAN_OBJECTID;
0017 key.type = BTRFS_ORPHAN_ITEM_KEY;
0018 key.offset = offset;
0019
0020 path = btrfs_alloc_path();
0021 if (!path)
0022 return -ENOMEM;
0023
0024 ret = btrfs_insert_empty_item(trans, root, path, &key, 0);
0025
0026 btrfs_free_path(path);
0027 return ret;
0028 }
0029
0030 int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
0031 struct btrfs_root *root, u64 offset)
0032 {
0033 struct btrfs_path *path;
0034 struct btrfs_key key;
0035 int ret = 0;
0036
0037 key.objectid = BTRFS_ORPHAN_OBJECTID;
0038 key.type = BTRFS_ORPHAN_ITEM_KEY;
0039 key.offset = offset;
0040
0041 path = btrfs_alloc_path();
0042 if (!path)
0043 return -ENOMEM;
0044
0045 ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
0046 if (ret < 0)
0047 goto out;
0048 if (ret) {
0049 ret = -ENOENT;
0050 goto out;
0051 }
0052
0053 ret = btrfs_del_item(trans, root, path);
0054
0055 out:
0056 btrfs_free_path(path);
0057 return ret;
0058 }