inode-item.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <linux/module.h>
  2. #include "ctree.h"
  3. #include "disk-io.h"
  4. #include "transaction.h"
  5. int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  6. *root, u64 objectid, struct btrfs_inode_item
  7. *inode_item)
  8. {
  9. struct btrfs_path *path;
  10. struct btrfs_key key;
  11. int ret;
  12. key.objectid = objectid;
  13. key.flags = 0;
  14. btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
  15. key.offset = 0;
  16. path = btrfs_alloc_path();
  17. BUG_ON(!path);
  18. btrfs_init_path(path);
  19. ret = btrfs_insert_item(trans, root, &key, inode_item,
  20. sizeof(*inode_item));
  21. btrfs_release_path(root, path);
  22. btrfs_free_path(path);
  23. if (ret == 0 && objectid > root->highest_inode)
  24. root->highest_inode = objectid;
  25. return ret;
  26. }
  27. int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
  28. *root, struct btrfs_path *path,
  29. struct btrfs_key *location, int mod)
  30. {
  31. int ins_len = mod < 0 ? -1 : 0;
  32. int cow = mod != 0;
  33. int ret;
  34. int slot;
  35. struct btrfs_leaf *leaf;
  36. struct btrfs_key found_key;
  37. ret = btrfs_search_slot(trans, root, location, path, ins_len, cow);
  38. if (ret > 0 && btrfs_key_type(location) == BTRFS_ROOT_ITEM_KEY &&
  39. location->offset == (u64)-1 && path->slots[0] != 0) {
  40. slot = path->slots[0] - 1;
  41. leaf = btrfs_buffer_leaf(path->nodes[0]);
  42. btrfs_disk_key_to_cpu(&found_key, &leaf->items[slot].key);
  43. if (found_key.objectid == location->objectid &&
  44. btrfs_key_type(&found_key) == btrfs_key_type(location)) {
  45. path->slots[0]--;
  46. return 0;
  47. }
  48. }
  49. return ret;
  50. }