inode-item.c 1.0 KB
Newer Older
1
#include <linux/module.h>
C
Chris Mason 已提交
2 3
#include "ctree.h"
#include "disk-io.h"
4
#include "transaction.h"
C
Chris Mason 已提交
5

6 7 8
int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
		       *root, u64 objectid, struct btrfs_inode_item
		       *inode_item)
C
Chris Mason 已提交
9
{
10
	struct btrfs_path *path;
C
Chris Mason 已提交
11 12 13 14 15 16 17
	struct btrfs_key key;
	int ret;
	key.objectid = objectid;
	key.flags = 0;
	btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
	key.offset = 0;

18 19 20
	path = btrfs_alloc_path();
	BUG_ON(!path);
	btrfs_init_path(path);
21 22
	ret = btrfs_insert_item(trans, root, &key, inode_item,
				sizeof(*inode_item));
23 24
	btrfs_release_path(root, path);
	btrfs_free_path(path);
C
Chris Mason 已提交
25 26 27
	return ret;
}

28 29
int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
		       *root, struct btrfs_path *path, u64 objectid, int mod)
C
Chris Mason 已提交
30 31 32 33 34 35 36 37 38
{
	struct btrfs_key key;
	int ins_len = mod < 0 ? -1 : 0;
	int cow = mod != 0;

	key.objectid = objectid;
	key.flags = 0;
	btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
	key.offset = 0;
39
	return btrfs_search_slot(trans, root, &key, path, ins_len, cow);
C
Chris Mason 已提交
40
}