aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/root-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-13 16:47:54 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-13 16:47:54 -0400
commit3768f3689fc76ecea17414936dff7a02746a4355 (patch)
tree0494b12e3ba0be0a25f122922e205bc91d88957b /fs/btrfs/root-tree.c
parenteaee50e881b88766d9a781c54c4142456cf5e527 (diff)
Btrfs: Change the super to point to a tree of trees to enable persistent snapshots
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/root-tree.c')
-rw-r--r--fs/btrfs/root-tree.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
new file mode 100644
index 000000000000..0ab90cfea98f
--- /dev/null
+++ b/fs/btrfs/root-tree.c
@@ -0,0 +1,88 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "kerncompat.h"
4#include "radix-tree.h"
5#include "ctree.h"
6#include "disk-io.h"
7#include "print-tree.h"
8
9int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
10 struct btrfs_root_item *item, struct btrfs_key *key)
11{
12 struct btrfs_path path;
13 struct btrfs_key search_key;
14 struct btrfs_leaf *l;
15 int ret;
16 int slot;
17
18 search_key.objectid = objectid;
19 search_key.flags = (u32)-1;
20 search_key.offset = (u32)-1;
21
22 btrfs_init_path(&path);
23 ret = btrfs_search_slot(root, &search_key, &path, 0, 0);
24 if (ret < 0)
25 goto out;
26 BUG_ON(ret == 0);
27 l = &path.nodes[0]->leaf;
28 BUG_ON(path.slots[0] == 0);
29 slot = path.slots[0] - 1;
30 if (btrfs_key_objectid(&l->items[slot].key) != objectid) {
31 ret = 1;
32 goto out;
33 }
34 memcpy(item, l->data + btrfs_item_offset(l->items + slot),
35 sizeof(*item));
36 btrfs_disk_key_to_cpu(key, &l->items[slot].key);
37 btrfs_release_path(root, &path);
38 ret = 0;
39out:
40 return ret;
41}
42
43int btrfs_update_root(struct btrfs_root *root, struct btrfs_key *key,
44 struct btrfs_root_item *item)
45{
46 struct btrfs_path path;
47 struct btrfs_leaf *l;
48 int ret;
49 int slot;
50
51 btrfs_init_path(&path);
52 ret = btrfs_search_slot(root, key, &path, 0, 1);
53 if (ret < 0)
54 goto out;
55 BUG_ON(ret != 0);
56 l = &path.nodes[0]->leaf;
57 slot = path.slots[0];
58 memcpy(l->data + btrfs_item_offset(l->items + slot), item,
59 sizeof(*item));
60out:
61 btrfs_release_path(root, &path);
62 return ret;
63}
64
65int btrfs_insert_root(struct btrfs_root *root, struct btrfs_key *key,
66 struct btrfs_root_item *item)
67{
68 int ret;
69 ret = btrfs_insert_item(root, key, item, sizeof(*item));
70 BUG_ON(ret);
71 return ret;
72}
73
74int btrfs_del_root(struct btrfs_root *root, struct btrfs_key *key)
75{
76 struct btrfs_path path;
77 int ret;
78
79 btrfs_init_path(&path);
80 ret = btrfs_search_slot(root, key, &path, -1, 1);
81 if (ret < 0)
82 goto out;
83 BUG_ON(ret != 0);
84 ret = btrfs_del_item(root, &path);
85out:
86 btrfs_release_path(root, &path);
87 return ret;
88}