]>
Commit | Line | Data |
---|---|---|
6cbd5570 CM |
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 | ||
1e1d2701 CM |
19 | #include "ctree.h" |
20 | #include "disk-io.h" | |
e089f05c | 21 | #include "transaction.h" |
1e1d2701 | 22 | |
e089f05c CM |
23 | int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
24 | *root, u64 objectid, struct btrfs_inode_item | |
25 | *inode_item) | |
1e1d2701 | 26 | { |
5caf2a00 | 27 | struct btrfs_path *path; |
1e1d2701 CM |
28 | struct btrfs_key key; |
29 | int ret; | |
30 | key.objectid = objectid; | |
31 | key.flags = 0; | |
32 | btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY); | |
33 | key.offset = 0; | |
34 | ||
5caf2a00 CM |
35 | path = btrfs_alloc_path(); |
36 | BUG_ON(!path); | |
e089f05c CM |
37 | ret = btrfs_insert_item(trans, root, &key, inode_item, |
38 | sizeof(*inode_item)); | |
5caf2a00 CM |
39 | btrfs_release_path(root, path); |
40 | btrfs_free_path(path); | |
1b05da2e CM |
41 | if (ret == 0 && objectid > root->highest_inode) |
42 | root->highest_inode = objectid; | |
1e1d2701 CM |
43 | return ret; |
44 | } | |
45 | ||
e089f05c | 46 | int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root |
d6e4a428 CM |
47 | *root, struct btrfs_path *path, |
48 | struct btrfs_key *location, int mod) | |
1e1d2701 | 49 | { |
1e1d2701 CM |
50 | int ins_len = mod < 0 ? -1 : 0; |
51 | int cow = mod != 0; | |
d6e4a428 CM |
52 | int ret; |
53 | int slot; | |
54 | struct btrfs_leaf *leaf; | |
55 | struct btrfs_key found_key; | |
1e1d2701 | 56 | |
d6e4a428 CM |
57 | ret = btrfs_search_slot(trans, root, location, path, ins_len, cow); |
58 | if (ret > 0 && btrfs_key_type(location) == BTRFS_ROOT_ITEM_KEY && | |
59 | location->offset == (u64)-1 && path->slots[0] != 0) { | |
60 | slot = path->slots[0] - 1; | |
61 | leaf = btrfs_buffer_leaf(path->nodes[0]); | |
62 | btrfs_disk_key_to_cpu(&found_key, &leaf->items[slot].key); | |
63 | if (found_key.objectid == location->objectid && | |
64 | btrfs_key_type(&found_key) == btrfs_key_type(location)) { | |
65 | path->slots[0]--; | |
66 | return 0; | |
67 | } | |
68 | } | |
69 | return ret; | |
1e1d2701 | 70 | } |