add GPLv2
[platform/upstream/btrfs-progs.git] / inode-item.c
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
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "kerncompat.h"
22 #include "radix-tree.h"
23 #include "ctree.h"
24 #include "disk-io.h"
25 #include "transaction.h"
26
27 int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
28                        *root, u64 objectid, struct btrfs_inode_item
29                        *inode_item)
30 {
31         struct btrfs_path path;
32         struct btrfs_key key;
33         int ret;
34         key.objectid = objectid;
35         key.flags = 0;
36         btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
37         key.offset = 0;
38
39         btrfs_init_path(&path);
40         ret = btrfs_insert_item(trans, root, &key, inode_item,
41                                 sizeof(*inode_item));
42         btrfs_release_path(root, &path);
43         return ret;
44 }
45
46 int btrfs_lookup_inode(struct btrfs_trans_handle *trans, struct btrfs_root
47                        *root, struct btrfs_path *path, u64 objectid, int mod)
48 {
49         struct btrfs_key key;
50         int ins_len = mod < 0 ? -1 : 0;
51         int cow = mod != 0;
52
53         key.objectid = objectid;
54         key.flags = 0;
55         btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY);
56         key.offset = 0;
57         return btrfs_search_slot(trans, root, &key, path, ins_len, cow);
58 }