inode-item.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (C) 2007 Oracle. 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. #include "transaction.h"
  21. int btrfs_insert_empty_inode(struct btrfs_trans_handle *trans,
  22. struct btrfs_root *root,
  23. struct btrfs_path *path, u64 objectid)
  24. {
  25. struct btrfs_key key;
  26. int ret;
  27. key.objectid = objectid;
  28. btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
  29. key.offset = 0;
  30. ret = btrfs_insert_empty_item(trans, root, path, &key,
  31. sizeof(struct btrfs_inode_item));
  32. if (ret == 0 && objectid > root->highest_inode)
  33. root->highest_inode = objectid;
  34. return ret;
  35. }
  36. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  37. *root, struct btrfs_path *path,
  38. struct btrfs_key *location, int mod)
  39. {
  40. int ins_len = mod < 0 ? -1 : 0;
  41. int cow = mod != 0;
  42. int ret;
  43. int slot;
  44. struct extent_buffer *leaf;
  45. struct btrfs_key found_key;
  46. ret = btrfs_search_slot(trans, root, location, path, ins_len, cow);
  47. if (ret > 0 && btrfs_key_type(location) == BTRFS_ROOT_ITEM_KEY &&
  48. location->offset == (u64)-1 && path->slots[0] != 0) {
  49. slot = path->slots[0] - 1;
  50. leaf = path->nodes[0];
  51. btrfs_item_key_to_cpu(leaf, &found_key, slot);
  52. if (found_key.objectid == location->objectid &&
  53. btrfs_key_type(&found_key) == btrfs_key_type(location)) {
  54. path->slots[0]--;
  55. return 0;
  56. }
  57. }
  58. return ret;
  59. }