1 /*
2  * Copyright (C) 2016 Oracle.  All Rights Reserved.
3  *
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it would 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 the Free Software Foundation,
18  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
19  */
20 #ifndef __XFS_REFCOUNT_BTREE_H__
21 #define	__XFS_REFCOUNT_BTREE_H__
22 
23 /*
24  * Reference Count Btree on-disk structures
25  */
26 
27 struct xfs_buf;
28 struct xfs_btree_cur;
29 struct xfs_mount;
30 
31 /*
32  * Btree block header size
33  */
34 #define XFS_REFCOUNT_BLOCK_LEN	XFS_BTREE_SBLOCK_CRC_LEN
35 
36 /*
37  * Record, key, and pointer address macros for btree blocks.
38  *
39  * (note that some of these may appear unused, but they are used in userspace)
40  */
41 #define XFS_REFCOUNT_REC_ADDR(block, index) \
42 	((struct xfs_refcount_rec *) \
43 		((char *)(block) + \
44 		 XFS_REFCOUNT_BLOCK_LEN + \
45 		 (((index) - 1) * sizeof(struct xfs_refcount_rec))))
46 
47 #define XFS_REFCOUNT_KEY_ADDR(block, index) \
48 	((struct xfs_refcount_key *) \
49 		((char *)(block) + \
50 		 XFS_REFCOUNT_BLOCK_LEN + \
51 		 ((index) - 1) * sizeof(struct xfs_refcount_key)))
52 
53 #define XFS_REFCOUNT_PTR_ADDR(block, index, maxrecs) \
54 	((xfs_refcount_ptr_t *) \
55 		((char *)(block) + \
56 		 XFS_REFCOUNT_BLOCK_LEN + \
57 		 (maxrecs) * sizeof(struct xfs_refcount_key) + \
58 		 ((index) - 1) * sizeof(xfs_refcount_ptr_t)))
59 
60 extern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp,
61 		struct xfs_trans *tp, struct xfs_buf *agbp, xfs_agnumber_t agno,
62 		struct xfs_defer_ops *dfops);
63 extern int xfs_refcountbt_maxrecs(struct xfs_mount *mp, int blocklen,
64 		bool leaf);
65 extern void xfs_refcountbt_compute_maxlevels(struct xfs_mount *mp);
66 
67 extern xfs_extlen_t xfs_refcountbt_calc_size(struct xfs_mount *mp,
68 		unsigned long long len);
69 extern xfs_extlen_t xfs_refcountbt_max_size(struct xfs_mount *mp);
70 
71 extern int xfs_refcountbt_calc_reserves(struct xfs_mount *mp,
72 		xfs_agnumber_t agno, xfs_extlen_t *ask, xfs_extlen_t *used);
73 
74 #endif	/* __XFS_REFCOUNT_BTREE_H__ */
75