orphan.c 1.1 KB

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