xref: /openbmc/linux/fs/nilfs2/btree.h (revision 6ee73861)
1 /*
2  * btree.h - NILFS B-tree.
3  *
4  * Copyright (C) 2005-2008 Nippon Telegraph and Telephone Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * Written by Koji Sato <koji@osrg.net>.
21  */
22 
23 #ifndef _NILFS_BTREE_H
24 #define _NILFS_BTREE_H
25 
26 #include <linux/types.h>
27 #include <linux/buffer_head.h>
28 #include <linux/list.h>
29 #include <linux/nilfs2_fs.h>
30 #include "btnode.h"
31 #include "bmap.h"
32 
33 struct nilfs_btree;
34 struct nilfs_btree_path;
35 
36 /**
37  * struct nilfs_btree_node - B-tree node
38  * @bn_flags: flags
39  * @bn_level: level
40  * @bn_nchildren: number of children
41  * @bn_pad: padding
42  */
43 struct nilfs_btree_node {
44 	__u8 bn_flags;
45 	__u8 bn_level;
46 	__le16 bn_nchildren;
47 	__le32 bn_pad;
48 };
49 
50 /* flags */
51 #define NILFS_BTREE_NODE_ROOT	0x01
52 
53 /* level */
54 #define NILFS_BTREE_LEVEL_DATA		0
55 #define NILFS_BTREE_LEVEL_NODE_MIN	(NILFS_BTREE_LEVEL_DATA + 1)
56 #define NILFS_BTREE_LEVEL_MAX		14
57 
58 /**
59  * struct nilfs_btree - B-tree structure
60  * @bt_bmap: bmap base structure
61  */
62 struct nilfs_btree {
63 	struct nilfs_bmap bt_bmap;
64 };
65 
66 
67 #define NILFS_BTREE_ROOT_SIZE		NILFS_BMAP_SIZE
68 #define NILFS_BTREE_ROOT_NCHILDREN_MAX					\
69 	((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) /	\
70 	 (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
71 #define NILFS_BTREE_ROOT_NCHILDREN_MIN	0
72 #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE	(sizeof(__le64))
73 #define NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize)			\
74 	(((nodesize) - sizeof(struct nilfs_btree_node) -		\
75 		NILFS_BTREE_NODE_EXTRA_PAD_SIZE) /			\
76 	 (sizeof(__le64 /* dkey */) + sizeof(__le64 /* dptr */)))
77 #define NILFS_BTREE_NODE_NCHILDREN_MIN(nodesize)			\
78 	((NILFS_BTREE_NODE_NCHILDREN_MAX(nodesize) - 1) / 2 + 1)
79 #define NILFS_BTREE_KEY_MIN	((__u64)0)
80 #define NILFS_BTREE_KEY_MAX	(~(__u64)0)
81 
82 
83 int nilfs_btree_path_cache_init(void);
84 void nilfs_btree_path_cache_destroy(void);
85 int nilfs_btree_init(struct nilfs_bmap *);
86 int nilfs_btree_convert_and_insert(struct nilfs_bmap *, __u64, __u64,
87 				   const __u64 *, const __u64 *, int);
88 void nilfs_btree_init_gc(struct nilfs_bmap *);
89 
90 #endif	/* _NILFS_BTREE_H */
91