18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2014 Red Hat, Inc. 48c2ecf20Sopenharmony_ci * All Rights Reserved. 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#ifndef __XFS_RMAP_BTREE_H__ 78c2ecf20Sopenharmony_ci#define __XFS_RMAP_BTREE_H__ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_cistruct xfs_buf; 108c2ecf20Sopenharmony_cistruct xfs_btree_cur; 118c2ecf20Sopenharmony_cistruct xfs_mount; 128c2ecf20Sopenharmony_cistruct xbtree_afakeroot; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci/* rmaps only exist on crc enabled filesystems */ 158c2ecf20Sopenharmony_ci#define XFS_RMAP_BLOCK_LEN XFS_BTREE_SBLOCK_CRC_LEN 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* 188c2ecf20Sopenharmony_ci * Record, key, and pointer address macros for btree blocks. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * (note that some of these may appear unused, but they are used in userspace) 218c2ecf20Sopenharmony_ci */ 228c2ecf20Sopenharmony_ci#define XFS_RMAP_REC_ADDR(block, index) \ 238c2ecf20Sopenharmony_ci ((struct xfs_rmap_rec *) \ 248c2ecf20Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 258c2ecf20Sopenharmony_ci (((index) - 1) * sizeof(struct xfs_rmap_rec)))) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci#define XFS_RMAP_KEY_ADDR(block, index) \ 288c2ecf20Sopenharmony_ci ((struct xfs_rmap_key *) \ 298c2ecf20Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 308c2ecf20Sopenharmony_ci ((index) - 1) * 2 * sizeof(struct xfs_rmap_key))) 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_ci#define XFS_RMAP_HIGH_KEY_ADDR(block, index) \ 338c2ecf20Sopenharmony_ci ((struct xfs_rmap_key *) \ 348c2ecf20Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 358c2ecf20Sopenharmony_ci sizeof(struct xfs_rmap_key) + \ 368c2ecf20Sopenharmony_ci ((index) - 1) * 2 * sizeof(struct xfs_rmap_key))) 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define XFS_RMAP_PTR_ADDR(block, index, maxrecs) \ 398c2ecf20Sopenharmony_ci ((xfs_rmap_ptr_t *) \ 408c2ecf20Sopenharmony_ci ((char *)(block) + XFS_RMAP_BLOCK_LEN + \ 418c2ecf20Sopenharmony_ci (maxrecs) * 2 * sizeof(struct xfs_rmap_key) + \ 428c2ecf20Sopenharmony_ci ((index) - 1) * sizeof(xfs_rmap_ptr_t))) 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cistruct xfs_btree_cur *xfs_rmapbt_init_cursor(struct xfs_mount *mp, 458c2ecf20Sopenharmony_ci struct xfs_trans *tp, struct xfs_buf *bp, 468c2ecf20Sopenharmony_ci xfs_agnumber_t agno); 478c2ecf20Sopenharmony_cistruct xfs_btree_cur *xfs_rmapbt_stage_cursor(struct xfs_mount *mp, 488c2ecf20Sopenharmony_ci struct xbtree_afakeroot *afake, xfs_agnumber_t agno); 498c2ecf20Sopenharmony_civoid xfs_rmapbt_commit_staged_btree(struct xfs_btree_cur *cur, 508c2ecf20Sopenharmony_ci struct xfs_trans *tp, struct xfs_buf *agbp); 518c2ecf20Sopenharmony_ciint xfs_rmapbt_maxrecs(int blocklen, int leaf); 528c2ecf20Sopenharmony_ciextern void xfs_rmapbt_compute_maxlevels(struct xfs_mount *mp); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ciextern xfs_extlen_t xfs_rmapbt_calc_size(struct xfs_mount *mp, 558c2ecf20Sopenharmony_ci unsigned long long len); 568c2ecf20Sopenharmony_ciextern xfs_extlen_t xfs_rmapbt_max_size(struct xfs_mount *mp, 578c2ecf20Sopenharmony_ci xfs_agblock_t agblocks); 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ciextern int xfs_rmapbt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, 608c2ecf20Sopenharmony_ci xfs_agnumber_t agno, xfs_extlen_t *ask, xfs_extlen_t *used); 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci#endif /* __XFS_RMAP_BTREE_H__ */ 63