18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2000,2005 Silicon Graphics, Inc. 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __XFS_ALLOC_BTREE_H__ 78c2ecf20Sopenharmony_ci#define __XFS_ALLOC_BTREE_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci/* 108c2ecf20Sopenharmony_ci * Freespace on-disk structures 118c2ecf20Sopenharmony_ci */ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistruct xfs_buf; 148c2ecf20Sopenharmony_cistruct xfs_btree_cur; 158c2ecf20Sopenharmony_cistruct xfs_mount; 168c2ecf20Sopenharmony_cistruct xbtree_afakeroot; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* 198c2ecf20Sopenharmony_ci * Btree block header size depends on a superblock flag. 208c2ecf20Sopenharmony_ci */ 218c2ecf20Sopenharmony_ci#define XFS_ALLOC_BLOCK_LEN(mp) \ 228c2ecf20Sopenharmony_ci (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ 238c2ecf20Sopenharmony_ci XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN) 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * Record, key, and pointer address macros for btree blocks. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * (note that some of these may appear unused, but they are used in userspace) 298c2ecf20Sopenharmony_ci */ 308c2ecf20Sopenharmony_ci#define XFS_ALLOC_REC_ADDR(mp, block, index) \ 318c2ecf20Sopenharmony_ci ((xfs_alloc_rec_t *) \ 328c2ecf20Sopenharmony_ci ((char *)(block) + \ 338c2ecf20Sopenharmony_ci XFS_ALLOC_BLOCK_LEN(mp) + \ 348c2ecf20Sopenharmony_ci (((index) - 1) * sizeof(xfs_alloc_rec_t)))) 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define XFS_ALLOC_KEY_ADDR(mp, block, index) \ 378c2ecf20Sopenharmony_ci ((xfs_alloc_key_t *) \ 388c2ecf20Sopenharmony_ci ((char *)(block) + \ 398c2ecf20Sopenharmony_ci XFS_ALLOC_BLOCK_LEN(mp) + \ 408c2ecf20Sopenharmony_ci ((index) - 1) * sizeof(xfs_alloc_key_t))) 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci#define XFS_ALLOC_PTR_ADDR(mp, block, index, maxrecs) \ 438c2ecf20Sopenharmony_ci ((xfs_alloc_ptr_t *) \ 448c2ecf20Sopenharmony_ci ((char *)(block) + \ 458c2ecf20Sopenharmony_ci XFS_ALLOC_BLOCK_LEN(mp) + \ 468c2ecf20Sopenharmony_ci (maxrecs) * sizeof(xfs_alloc_key_t) + \ 478c2ecf20Sopenharmony_ci ((index) - 1) * sizeof(xfs_alloc_ptr_t))) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ciextern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *, 508c2ecf20Sopenharmony_ci struct xfs_trans *, struct xfs_buf *, 518c2ecf20Sopenharmony_ci xfs_agnumber_t, xfs_btnum_t); 528c2ecf20Sopenharmony_cistruct xfs_btree_cur *xfs_allocbt_stage_cursor(struct xfs_mount *mp, 538c2ecf20Sopenharmony_ci struct xbtree_afakeroot *afake, xfs_agnumber_t agno, 548c2ecf20Sopenharmony_ci xfs_btnum_t btnum); 558c2ecf20Sopenharmony_ciextern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int); 568c2ecf20Sopenharmony_ciextern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp, 578c2ecf20Sopenharmony_ci unsigned long long len); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_civoid xfs_allocbt_commit_staged_btree(struct xfs_btree_cur *cur, 608c2ecf20Sopenharmony_ci struct xfs_trans *tp, struct xfs_buf *agbp); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#endif /* __XFS_ALLOC_BTREE_H__ */ 63