xref: /linux/fs/xfs/libxfs/xfs_alloc_btree.h (revision be9fb17d88f08af648a89784d30dbac83d893154)
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;
16*be9fb17dSDave 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) \
2384be0ffcSDave Chinner 	(xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
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 
5084be0ffcSDave Chinner extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *,
5184be0ffcSDave Chinner 		struct xfs_trans *, struct xfs_buf *,
52*be9fb17dSDave Chinner 		xfs_agnumber_t, struct xfs_perag *pag, xfs_btnum_t);
53e6eb33d9SDarrick J. Wong struct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp,
54e6eb33d9SDarrick J. Wong 		struct xbtree_afakeroot *afake, xfs_agnumber_t agno,
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 
6384be0ffcSDave Chinner #endif	/* __XFS_ALLOC_BTREE_H__ */
64