summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ctree.h12
-rw-r--r--extent-tree.c2
-rw-r--r--hasher.c2
-rw-r--r--mkfs.c1
-rw-r--r--print-tree.c13
5 files changed, 26 insertions, 4 deletions
diff --git a/ctree.h b/ctree.h
index c9361d83..569504e3 100644
--- a/ctree.h
+++ b/ctree.h
@@ -45,6 +45,7 @@ struct btrfs_key {
struct btrfs_header {
u8 fsid[16]; /* FS specific uuid */
__le64 blocknr; /* which block this node is supposed to live in */
+ __le64 generation;
__le64 parentid; /* objectid of the tree root */
__le32 csum;
__le32 ham;
@@ -572,6 +573,17 @@ static inline void btrfs_set_header_blocknr(struct btrfs_header *h, u64 blocknr)
h->blocknr = cpu_to_le64(blocknr);
}
+static inline u64 btrfs_header_generation(struct btrfs_header *h)
+{
+ return le64_to_cpu(h->generation);
+}
+
+static inline void btrfs_set_header_generation(struct btrfs_header *h,
+ u64 val)
+{
+ h->generation = cpu_to_le64(val);
+}
+
static inline u64 btrfs_header_parentid(struct btrfs_header *h)
{
return le64_to_cpu(h->parentid);
diff --git a/extent-tree.c b/extent-tree.c
index 9bc4ad38..06ecbe3c 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -459,6 +459,8 @@ struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
}
buf = find_tree_block(root, ins.objectid);
dirty_tree_block(trans, root, buf);
+ btrfs_set_header_generation(&buf->node.header,
+ root->root_key.offset + 1);
return buf;
}
diff --git a/hasher.c b/hasher.c
index 96702da4..435dbfa5 100644
--- a/hasher.c
+++ b/hasher.c
@@ -15,6 +15,8 @@ int main() {
break;
if (strlen(line) == 0)
continue;
+ if (line[strlen(line)-1] == '\n')
+ line[strlen(line)-1] = '\0';
ret = btrfs_name_hash(line, strlen(line), &result);
BUG_ON(ret);
printf("hash returns %Lu\n", result);
diff --git a/mkfs.c b/mkfs.c
index f878e3e1..d8f99606 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -114,6 +114,7 @@ int mkfs(int fd, u64 num_blocks, u32 blocksize)
BTRFS_ROOT_TREE_OBJECTID);
btrfs_set_header_blocknr(&empty_leaf->header, start_block + 1);
btrfs_set_header_nritems(&empty_leaf->header, 3);
+ btrfs_set_header_generation(&empty_leaf->header, 0);
/* create the items for the root tree */
btrfs_set_root_blocknr(&root_item, start_block + 2);
diff --git a/print-tree.c b/print-tree.c
index caa07f5a..5259b6e9 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -17,9 +17,11 @@ void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
struct btrfs_inode_item *ii;
u32 type;
- printf("leaf %Lu total ptrs %d free space %d\n",
+ printf("leaf %Lu ptrs %d free space %d parent %Lu generation %Lu\n",
btrfs_header_blocknr(&l->header), nr,
- btrfs_leaf_free_space(root, l));
+ btrfs_leaf_free_space(root, l),
+ btrfs_header_parentid(&l->header),
+ btrfs_header_generation(&l->header));
fflush(stdout);
for (i = 0 ; i < nr ; i++) {
item = l->items + i;
@@ -87,9 +89,12 @@ void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
btrfs_print_leaf(root, (struct btrfs_leaf *)c);
return;
}
- printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
+ printf("node %Lu level %d ptrs %d free %u parent %Lu generation %Lu\n",
+ t->blocknr,
btrfs_header_level(&c->header), nr,
- (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
+ (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
+ btrfs_header_parentid(&c->header),
+ btrfs_header_generation(&c->header));
fflush(stdout);
for (i = 0; i < nr; i++) {
printf("\tkey %d (%Lu %u %Lu) block %Lu\n",