orphan.c 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2008 Red Hat. All rights reserved.
  4. */
  5. #include "ctree.h"
  6. #include "orphan.h"
  7. int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
  8. struct btrfs_root *root, u64 offset)
  9. {
  10. BTRFS_PATH_AUTO_FREE(path);
  11. struct btrfs_key key;
  12. key.objectid = BTRFS_ORPHAN_OBJECTID;
  13. key.type = BTRFS_ORPHAN_ITEM_KEY;
  14. key.offset = offset;
  15. path = btrfs_alloc_path();
  16. if (!path)
  17. return -ENOMEM;
  18. return btrfs_insert_empty_item(trans, root, path, &key, 0);
  19. }
  20. int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
  21. struct btrfs_root *root, u64 offset)
  22. {
  23. BTRFS_PATH_AUTO_FREE(path);
  24. struct btrfs_key key;
  25. int ret = 0;
  26. key.objectid = BTRFS_ORPHAN_OBJECTID;
  27. key.type = BTRFS_ORPHAN_ITEM_KEY;
  28. key.offset = offset;
  29. path = btrfs_alloc_path();
  30. if (!path)
  31. return -ENOMEM;
  32. ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
  33. if (ret < 0)
  34. return ret;
  35. if (ret)
  36. return -ENOENT;
  37. return btrfs_del_item(trans, root, path);
  38. }