xref: /linux/fs/xfs/libxfs/xfs_alloc_btree.h (revision 0ed5f7356daee74244b02e100b3cc043e886e686)
1508578f2SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */
284be0ffcSDave Chinner /*
384be0ffcSDave Chinner  * Copyright (c) 2000,2005 Silicon Graphics, Inc.
484be0ffcSDave Chinner  * All Rights Reserved.
584be0ffcSDave Chinner  */
684be0ffcSDave Chinner #ifndef __XFS_ALLOC_BTREE_H__
784be0ffcSDave Chinner #define	__XFS_ALLOC_BTREE_H__
884be0ffcSDave Chinner 
984be0ffcSDave Chinner /*
1084be0ffcSDave Chinner  * Freespace on-disk structures
1184be0ffcSDave Chinner  */
1284be0ffcSDave Chinner 
1384be0ffcSDave Chinner struct xfs_buf;
1484be0ffcSDave Chinner struct xfs_btree_cur;
1584be0ffcSDave Chinner struct xfs_mount;
16be9fb17dSDave Chinner struct xfs_perag;
17e6eb33d9SDarrick J. Wong struct xbtree_afakeroot;
1884be0ffcSDave Chinner 
1984be0ffcSDave Chinner /*
2084be0ffcSDave Chinner  * Btree block header size depends on a superblock flag.
2184be0ffcSDave Chinner  */
2284be0ffcSDave Chinner #define XFS_ALLOC_BLOCK_LEN(mp) \
2338c26bfdSDave Chinner 	(xfs_has_crc(((mp))) ? \
2484be0ffcSDave Chinner 		XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN)
2584be0ffcSDave Chinner 
2684be0ffcSDave Chinner /*
2784be0ffcSDave Chinner  * Record, key, and pointer address macros for btree blocks.
2884be0ffcSDave Chinner  *
2984be0ffcSDave Chinner  * (note that some of these may appear unused, but they are used in userspace)
3084be0ffcSDave Chinner  */
3184be0ffcSDave Chinner #define XFS_ALLOC_REC_ADDR(mp, block, index) \
3284be0ffcSDave Chinner 	((xfs_alloc_rec_t *) \
3384be0ffcSDave Chinner 		((char *)(block) + \
3484be0ffcSDave Chinner 		 XFS_ALLOC_BLOCK_LEN(mp) + \
3584be0ffcSDave Chinner 		 (((index) - 1) * sizeof(xfs_alloc_rec_t))))
3684be0ffcSDave Chinner 
3784be0ffcSDave Chinner #define XFS_ALLOC_KEY_ADDR(mp, block, index) \
3884be0ffcSDave Chinner 	((xfs_alloc_key_t *) \
3984be0ffcSDave Chinner 		((char *)(block) + \
4084be0ffcSDave Chinner 		 XFS_ALLOC_BLOCK_LEN(mp) + \
4184be0ffcSDave Chinner 		 ((index) - 1) * sizeof(xfs_alloc_key_t)))
4284be0ffcSDave Chinner 
4384be0ffcSDave Chinner #define XFS_ALLOC_PTR_ADDR(mp, block, index, maxrecs) \
4484be0ffcSDave Chinner 	((xfs_alloc_ptr_t *) \
4584be0ffcSDave Chinner 		((char *)(block) + \
4684be0ffcSDave Chinner 		 XFS_ALLOC_BLOCK_LEN(mp) + \
4784be0ffcSDave Chinner 		 (maxrecs) * sizeof(xfs_alloc_key_t) + \
4884be0ffcSDave Chinner 		 ((index) - 1) * sizeof(xfs_alloc_ptr_t)))
4984be0ffcSDave Chinner 
50289d38d2SDave Chinner extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *mp,
51289d38d2SDave Chinner 		struct xfs_trans *tp, struct xfs_buf *bp,
52289d38d2SDave Chinner 		struct xfs_perag *pag, xfs_btnum_t btnum);
53e6eb33d9SDarrick J. Wong struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp,
54289d38d2SDave Chinner 		struct xbtree_afakeroot *afake, struct xfs_perag *pag,
55e6eb33d9SDarrick J. Wong 		xfs_btnum_t btnum);
5684be0ffcSDave Chinner extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int);
5714861c47SDarrick J. Wong extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp,
5814861c47SDarrick J. Wong 		unsigned long long len);
5984be0ffcSDave Chinner 
60e6eb33d9SDarrick J. Wong void xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur,
61e6eb33d9SDarrick J. Wong 		struct xfs_trans *tp, struct xfs_buf *agbp);
62e6eb33d9SDarrick J. Wong 
63*0ed5f735SDarrick J. Wong unsigned int xfs_allocbt_maxlevels_ondisk(void);
64*0ed5f735SDarrick J. Wong 
6584be0ffcSDave Chinner #endif	/* __XFS_ALLOC_BTREE_H__ */
66