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