aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h123
1 files changed, 107 insertions, 16 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 5dfcc90812c..0968899fb7f 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -4,8 +4,13 @@
4#include "list.h" 4#include "list.h"
5#include "kerncompat.h" 5#include "kerncompat.h"
6 6
7#define BTRFS_MAGIC "_BtRfS_M"
7#define BTRFS_BLOCKSIZE 1024 8#define BTRFS_BLOCKSIZE 1024
8 9
10#define BTRFS_ROOT_TREE_OBJECTID 1
11#define BTRFS_EXTENT_TREE_OBJECTID 2
12#define BTRFS_FS_TREE_OBJECTID 3
13
9/* 14/*
10 * the key defines the order in the tree, and so it also defines (optimal) 15 * the key defines the order in the tree, and so it also defines (optimal)
11 * block layout. objectid corresonds to the inode number. The flags 16 * block layout. objectid corresonds to the inode number. The flags
@@ -36,7 +41,7 @@ struct btrfs_key {
36 * every tree block (leaf or node) starts with this header. 41 * every tree block (leaf or node) starts with this header.
37 */ 42 */
38struct btrfs_header { 43struct btrfs_header {
39 __le64 fsid[2]; /* FS specific uuid */ 44 u8 fsid[16]; /* FS specific uuid */
40 __le64 blocknr; /* which block this node is supposed to live in */ 45 __le64 blocknr; /* which block this node is supposed to live in */
41 __le64 parentid; /* objectid of the tree root */ 46 __le64 parentid; /* objectid of the tree root */
42 __le32 csum; 47 __le32 csum;
@@ -52,6 +57,14 @@ struct btrfs_header {
52 57
53struct btrfs_buffer; 58struct btrfs_buffer;
54 59
60struct btrfs_root_item {
61 __le64 blocknr;
62 __le32 flags;
63 __le64 block_limit;
64 __le64 blocks_used;
65 __le32 refs;
66};
67
55/* 68/*
56 * in ram representation of the tree. extent_root is used for all allocations 69 * in ram representation of the tree. extent_root is used for all allocations
57 * and for the extent tree extent_root root. current_insert is used 70 * and for the extent tree extent_root root. current_insert is used
@@ -61,6 +74,7 @@ struct btrfs_root {
61 struct btrfs_buffer *node; 74 struct btrfs_buffer *node;
62 struct btrfs_buffer *commit_root; 75 struct btrfs_buffer *commit_root;
63 struct btrfs_root *extent_root; 76 struct btrfs_root *extent_root;
77 struct btrfs_root *tree_root;
64 struct btrfs_key current_insert; 78 struct btrfs_key current_insert;
65 struct btrfs_key last_insert; 79 struct btrfs_key last_insert;
66 int fp; 80 int fp;
@@ -69,28 +83,25 @@ struct btrfs_root {
69 struct list_head trans; 83 struct list_head trans;
70 struct list_head cache; 84 struct list_head cache;
71 int cache_size; 85 int cache_size;
86 int ref_cows;
87 struct btrfs_root_item root_item;
88 struct btrfs_key root_key;
72}; 89};
73 90
74/* 91/*
75 * describes a tree on disk
76 */
77struct btrfs_root_info {
78 u64 fsid[2]; /* FS specific uuid */
79 u64 blocknr; /* blocknr of this block */
80 u64 objectid; /* inode number of this root */
81 u64 tree_root; /* the tree root block */
82 u32 csum;
83 u32 ham;
84 u64 snapuuid[2]; /* root specific uuid */
85} __attribute__ ((__packed__));
86
87/*
88 * the super block basically lists the main trees of the FS 92 * the super block basically lists the main trees of the FS
89 * it currently lacks any block count etc etc 93 * it currently lacks any block count etc etc
90 */ 94 */
91struct btrfs_super_block { 95struct btrfs_super_block {
92 struct btrfs_root_info root_info; 96 u8 fsid[16]; /* FS specific uuid */
93 struct btrfs_root_info extent_info; 97 __le64 blocknr; /* this block number */
98 __le32 csum;
99 __le64 magic;
100 __le16 blocksize;
101 __le64 generation;
102 __le64 root;
103 __le64 total_blocks;
104 __le64 blocks_used;
94} __attribute__ ((__packed__)); 105} __attribute__ ((__packed__));
95 106
96/* 107/*
@@ -317,6 +328,79 @@ static inline int btrfs_is_leaf(struct btrfs_node *n)
317 return (btrfs_header_level(&n->header) == 0); 328 return (btrfs_header_level(&n->header) == 0);
318} 329}
319 330
331static inline u64 btrfs_root_blocknr(struct btrfs_root_item *item)
332{
333 return le64_to_cpu(item->blocknr);
334}
335
336static inline void btrfs_set_root_blocknr(struct btrfs_root_item *item, u64 val)
337{
338 item->blocknr = cpu_to_le64(val);
339}
340
341static inline u32 btrfs_root_refs(struct btrfs_root_item *item)
342{
343 return le32_to_cpu(item->refs);
344}
345
346static inline void btrfs_set_root_refs(struct btrfs_root_item *item, u32 val)
347{
348 item->refs = cpu_to_le32(val);
349}
350
351static inline u64 btrfs_super_blocknr(struct btrfs_super_block *s)
352{
353 return le64_to_cpu(s->blocknr);
354}
355
356static inline void btrfs_set_super_blocknr(struct btrfs_super_block *s, u64 val)
357{
358 s->blocknr = cpu_to_le64(val);
359}
360
361static inline u64 btrfs_super_root(struct btrfs_super_block *s)
362{
363 return le64_to_cpu(s->root);
364}
365
366static inline void btrfs_set_super_root(struct btrfs_super_block *s, u64 val)
367{
368 s->root = cpu_to_le64(val);
369}
370
371static inline u64 btrfs_super_total_blocks(struct btrfs_super_block *s)
372{
373 return le64_to_cpu(s->total_blocks);
374}
375
376static inline void btrfs_set_super_total_blocks(struct btrfs_super_block *s,
377 u64 val)
378{
379 s->total_blocks = cpu_to_le64(val);
380}
381
382static inline u64 btrfs_super_blocks_used(struct btrfs_super_block *s)
383{
384 return le64_to_cpu(s->blocks_used);
385}
386
387static inline void btrfs_set_super_blocks_used(struct btrfs_super_block *s,
388 u64 val)
389{
390 s->blocks_used = cpu_to_le64(val);
391}
392
393static inline u16 btrfs_super_blocksize(struct btrfs_super_block *s)
394{
395 return le16_to_cpu(s->blocksize);
396}
397
398static inline void btrfs_set_super_blocksize(struct btrfs_super_block *s,
399 u16 val)
400{
401 s->blocksize = cpu_to_le16(val);
402}
403
320struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root); 404struct btrfs_buffer *btrfs_alloc_free_block(struct btrfs_root *root);
321int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf); 405int btrfs_inc_ref(struct btrfs_root *root, struct btrfs_buffer *buf);
322int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks); 406int btrfs_free_extent(struct btrfs_root *root, u64 blocknr, u64 num_blocks);
@@ -331,4 +415,11 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path);
331int btrfs_leaf_free_space(struct btrfs_leaf *leaf); 415int btrfs_leaf_free_space(struct btrfs_leaf *leaf);
332int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap); 416int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_buffer *snap);
333int btrfs_finish_extent_commit(struct btrfs_root *root); 417int btrfs_finish_extent_commit(struct btrfs_root *root);
418int btrfs_del_root(struct btrfs_root *root, struct btrfs_key *key);
419int btrfs_insert_root(struct btrfs_root *root, struct btrfs_key *key,
420 struct btrfs_root_item *item);
421int btrfs_update_root(struct btrfs_root *root, struct btrfs_key *key,
422 struct btrfs_root_item *item);
423int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
424 struct btrfs_root_item *item, struct btrfs_key *key);
334#endif 425#endif