2 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
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.
21 #include "kerncompat.h"
22 #include "radix-tree.h"
25 #include "transaction.h"
27 int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
28 struct btrfs_root *root,
29 const char *name, int name_len,
30 u64 inode_objectid, u64 ref_objectid)
32 struct btrfs_path path;
34 struct btrfs_inode_ref *ref;
37 int ins_len = name_len + sizeof(*ref);
39 key.objectid = inode_objectid;
40 key.offset = ref_objectid;
41 btrfs_set_key_type(&key, BTRFS_INODE_REF_KEY);
43 btrfs_init_path(&path);
44 ret = btrfs_insert_empty_item(trans, root, &path, &key,
50 if (find_name_in_backref(path, name, name_len, &ref))
53 old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
54 ret = btrfs_extend_item(trans, root, path, ins_len);
56 ref = btrfs_item_ptr(path->nodes[0], path->slots[0],
57 struct btrfs_inode_ref);
58 ref = (struct btrfs_inode_ref *)((unsigned long)ref + old_size);
59 btrfs_set_inode_ref_name_len(path->nodes[0], ref, name_len);
60 ptr = (unsigned long)(ref + 1);
67 ref = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0],
68 struct btrfs_inode_ref);
69 btrfs_set_inode_ref_name_len(ref, name_len);
70 ptr = (char *)(ref + 1);
72 memcpy(ptr, name, name_len);
73 dirty_tree_block(trans, root, path.nodes[0]);
76 btrfs_release_path(root, &path);
80 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
81 *root, u64 objectid, struct btrfs_inode_item
84 struct btrfs_path path;
87 key.objectid = objectid;
88 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
91 btrfs_init_path(&path);
92 ret = btrfs_insert_item(trans, root, &key, inode_item,
94 btrfs_release_path(root, &path);
98 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
99 *root, struct btrfs_path *path, u64 objectid, int mod)
101 struct btrfs_key key;
102 int ins_len = mod < 0 ? -1 : 0;
105 key.objectid = objectid;
106 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
108 return btrfs_search_slot(trans, root, &key, path, ins_len, cow);