]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/btrfs/inode-item.c
Btrfs: no slashes in subvolume names
[net-next-2.6.git] / fs / btrfs / inode-item.c
CommitLineData
2e635a27 1#include <linux/module.h>
1e1d2701
CM
2#include "ctree.h"
3#include "disk-io.h"
e089f05c 4#include "transaction.h"
1e1d2701 5
e089f05c
CM
6int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
7 *root, u64 objectid, struct btrfs_inode_item
8 *inode_item)
1e1d2701 9{
5caf2a00 10 struct btrfs_path *path;
1e1d2701
CM
11 struct btrfs_key key;
12 int ret;
13 key.objectid = objectid;
14 key.flags = 0;
15 btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
16 key.offset = 0;
17
5caf2a00
CM
18 path = btrfs_alloc_path();
19 BUG_ON(!path);
20 btrfs_init_path(path);
e089f05c
CM
21 ret = btrfs_insert_item(trans, root, &key, inode_item,
22 sizeof(*inode_item));
5caf2a00
CM
23 btrfs_release_path(root, path);
24 btrfs_free_path(path);
1b05da2e
CM
25 if (ret == 0 && objectid > root->highest_inode)
26 root->highest_inode = objectid;
1e1d2701
CM
27 return ret;
28}
29
e089f05c 30int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
d6e4a428
CM
31 *root, struct btrfs_path *path,
32 struct btrfs_key *location, int mod)
1e1d2701 33{
1e1d2701
CM
34 int ins_len = mod < 0 ? -1 : 0;
35 int cow = mod != 0;
d6e4a428
CM
36 int ret;
37 int slot;
38 struct btrfs_leaf *leaf;
39 struct btrfs_key found_key;
1e1d2701 40
d6e4a428
CM
41 ret = btrfs_search_slot(trans, root, location, path, ins_len, cow);
42 if (ret > 0 && btrfs_key_type(location) == BTRFS_ROOT_ITEM_KEY &&
43 location->offset == (u64)-1 && path->slots[0] != 0) {
44 slot = path->slots[0] - 1;
45 leaf = btrfs_buffer_leaf(path->nodes[0]);
46 btrfs_disk_key_to_cpu(&found_key, &leaf->items[slot].key);
47 if (found_key.objectid == location->objectid &&
48 btrfs_key_type(&found_key) == btrfs_key_type(location)) {
49 path->slots[0]--;
50 return 0;
51 }
52 }
53 return ret;
1e1d2701 54}