orphan.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (C) 2008 Red Hat. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include "ctree.h"
  19. #include "disk-io.h"
  20. int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
  21. struct btrfs_root *root, u64 offset)
  22. {
  23. struct btrfs_path *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_insert_empty_item(trans, root, path, &key, 0);
  33. btrfs_free_path(path);
  34. return ret;
  35. }
  36. int btrfs_del_orphan_item(struct btrfs_trans_handle *trans,
  37. struct btrfs_root *root, u64 offset)
  38. {
  39. struct btrfs_path *path;
  40. struct btrfs_key key;
  41. int ret = 0;
  42. key.objectid = BTRFS_ORPHAN_OBJECTID;
  43. key.type = BTRFS_ORPHAN_ITEM_KEY;
  44. key.offset = offset;
  45. path = btrfs_alloc_path();
  46. if (!path)
  47. return -ENOMEM;
  48. ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
  49. if (ret < 0)
  50. goto out;
  51. if (ret) { /* JDM: Really? */
  52. ret = -ENOENT;
  53. goto out;
  54. }
  55. ret = btrfs_del_item(trans, root, path);
  56. out:
  57. btrfs_free_path(path);
  58. return ret;
  59. }