1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Oracle.  All Rights Reserved.
4  * Author: Darrick J. Wong <darrick.wong@oracle.com>
5  */
6 #ifndef __XFS_REFCOUNT_BTREE_H__
7 #define	__XFS_REFCOUNT_BTREE_H__
8 
9 /*
10  * Reference Count Btree on-disk structures
11  */
12 
13 struct xfs_buf;
14 struct xfs_btree_cur;
15 struct xfs_mount;
16 
17 /*
18  * Btree block header size
19  */
20 #define XFS_REFCOUNT_BLOCK_LEN	XFS_BTREE_SBLOCK_CRC_LEN
21 
22 /*
23  * Record, key, and pointer address macros for btree blocks.
24  *
25  * (note that some of these may appear unused, but they are used in userspace)
26  */
27 #define XFS_REFCOUNT_REC_ADDR(block, index) \
28 	((struct xfs_refcount_rec *) \
29 		((char *)(block) + \
30 		 XFS_REFCOUNT_BLOCK_LEN + \
31 		 (((index) - 1) * sizeof(struct xfs_refcount_rec))))
32 
33 #define XFS_REFCOUNT_KEY_ADDR(block, index) \
34 	((struct xfs_refcount_key *) \
35 		((char *)(block) + \
36 		 XFS_REFCOUNT_BLOCK_LEN + \
37 		 ((index) - 1) * sizeof(struct xfs_refcount_key)))
38 
39 #define XFS_REFCOUNT_PTR_ADDR(block, index, maxrecs) \
40 	((xfs_refcount_ptr_t *) \
41 		((char *)(block) + \
42 		 XFS_REFCOUNT_BLOCK_LEN + \
43 		 (maxrecs) * sizeof(struct xfs_refcount_key) + \
44 		 ((index) - 1) * sizeof(xfs_refcount_ptr_t)))
45 
46 extern struct xfs_btree_cur *xfs_refcountbt_init_cursor(struct xfs_mount *mp,
47 		struct xfs_trans *tp, struct xfs_buf *agbp,
48 		xfs_agnumber_t agno);
49 extern int xfs_refcountbt_maxrecs(int blocklen, bool leaf);
50 extern void xfs_refcountbt_compute_maxlevels(struct xfs_mount *mp);
51 
52 extern xfs_extlen_t xfs_refcountbt_calc_size(struct xfs_mount *mp,
53 		unsigned long long len);
54 extern xfs_extlen_t xfs_refcountbt_max_size(struct xfs_mount *mp,
55 		xfs_agblock_t agblocks);
56 
57 extern int xfs_refcountbt_calc_reserves(struct xfs_mount *mp,
58 		struct xfs_trans *tp, xfs_agnumber_t agno, xfs_extlen_t *ask,
59 		xfs_extlen_t *used);
60 
61 #endif	/* __XFS_REFCOUNT_BTREE_H__ */
62