Commit | Line | Data |
---|---|---|
c1d7c514 | 1 | // SPDX-License-Identifier: GPL-2.0 |
7b128766 JB |
2 | /* |
3 | * Copyright (C) 2008 Red Hat. All rights reserved. | |
7b128766 JB |
4 | */ |
5 | ||
6 | #include "ctree.h" | |
7 | #include "disk-io.h" | |
aa5d3003 | 8 | #include "orphan.h" |
7b128766 JB |
9 | |
10 | int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans, | |
11 | struct btrfs_root *root, u64 offset) | |
12 | { | |
13 | struct btrfs_path *path; | |
14 | struct btrfs_key key; | |
15 | int ret = 0; | |
16 | ||
17 | key.objectid = BTRFS_ORPHAN_OBJECTID; | |
962a298f | 18 | key.type = BTRFS_ORPHAN_ITEM_KEY; |
7b128766 JB |
19 | key.offset = offset; |
20 | ||
21 | path = btrfs_alloc_path(); | |
22 | if (!path) | |
23 | return -ENOMEM; | |
24 | ||
25 | ret = btrfs_insert_empty_item(trans, root, path, &key, 0); | |
26 | ||
27 | btrfs_free_path(path); | |
28 | return ret; | |
29 | } | |
30 | ||
31 | int btrfs_del_orphan_item(struct btrfs_trans_handle *trans, | |
32 | struct btrfs_root *root, u64 offset) | |
33 | { | |
34 | struct btrfs_path *path; | |
35 | struct btrfs_key key; | |
36 | int ret = 0; | |
37 | ||
38 | key.objectid = BTRFS_ORPHAN_OBJECTID; | |
962a298f | 39 | key.type = BTRFS_ORPHAN_ITEM_KEY; |
7b128766 JB |
40 | key.offset = offset; |
41 | ||
42 | path = btrfs_alloc_path(); | |
43 | if (!path) | |
44 | return -ENOMEM; | |
45 | ||
46 | ret = btrfs_search_slot(trans, root, &key, path, -1, 1); | |
7e1fea73 | 47 | if (ret < 0) |
7b128766 | 48 | goto out; |
79787eaa | 49 | if (ret) { /* JDM: Really? */ |
7e1fea73 JB |
50 | ret = -ENOENT; |
51 | goto out; | |
52 | } | |
7b128766 JB |
53 | |
54 | ret = btrfs_del_item(trans, root, path); | |
55 | ||
56 | out: | |
57 | btrfs_free_path(path); | |
58 | return ret; | |
59 | } |