blob: 26451cb76b98bb306d6d50d13b2f290ec1d58b52 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_IALLOC_BTREE_H__
7#define __XFS_IALLOC_BTREE_H__
8
9/*
10 * Inode map on-disk structures
11 */
12
13struct xfs_buf;
14struct xfs_btree_cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015struct xfs_mount;
Dave Chinnerbe9fb172021-06-02 10:48:24 +100016struct xfs_perag;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/*
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110019 * Btree block header size depends on a superblock flag.
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110020 */
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050021#define XFS_INOBT_BLOCK_LEN(mp) \
Dave Chinner38c26bf2021-08-18 18:46:37 -070022 (xfs_has_crc(((mp))) ? \
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050023 XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN)
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110024
25/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 * Record, key, and pointer address macros for btree blocks.
Christoph Hellwig136341b2008-10-30 17:11:40 +110027 *
28 * (note that some of these may appear unused, but they are used in userspace)
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 */
Christoph Hellwig136341b2008-10-30 17:11:40 +110030#define XFS_INOBT_REC_ADDR(mp, block, index) \
31 ((xfs_inobt_rec_t *) \
32 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110033 XFS_INOBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110034 (((index) - 1) * sizeof(xfs_inobt_rec_t))))
Eric Sandeen2c36dde2007-02-10 18:37:33 +110035
Christoph Hellwig136341b2008-10-30 17:11:40 +110036#define XFS_INOBT_KEY_ADDR(mp, block, index) \
37 ((xfs_inobt_key_t *) \
38 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110039 XFS_INOBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110040 ((index) - 1) * sizeof(xfs_inobt_key_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Christoph Hellwig136341b2008-10-30 17:11:40 +110042#define XFS_INOBT_PTR_ADDR(mp, block, index, maxrecs) \
43 ((xfs_inobt_ptr_t *) \
44 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110045 XFS_INOBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110046 (maxrecs) * sizeof(xfs_inobt_key_t) + \
47 ((index) - 1) * sizeof(xfs_inobt_ptr_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Dave Chinnerbe9fb172021-06-02 10:48:24 +100049extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *mp,
Dave Chinner7b13c512021-06-02 10:48:24 +100050 struct xfs_trans *tp, struct xfs_buf *agbp,
Dave Chinnerbe9fb172021-06-02 10:48:24 +100051 struct xfs_perag *pag, xfs_btnum_t btnum);
Darrick J. Wongc29ce8f2020-03-11 11:01:04 -070052struct xfs_btree_cur *xfs_inobt_stage_cursor(struct xfs_mount *mp,
Dave Chinner7b13c512021-06-02 10:48:24 +100053 struct xbtree_afakeroot *afake, struct xfs_perag *pag,
Darrick J. Wongc29ce8f2020-03-11 11:01:04 -070054 xfs_btnum_t btnum);
Christoph Hellwig60197e82008-10-30 17:11:19 +110055extern int xfs_inobt_maxrecs(struct xfs_mount *, int, int);
Christoph Hellwig561f7d12008-10-30 16:53:59 +110056
Brian Foster4148c342015-05-29 09:09:05 +100057/* ir_holemask to inode allocation bitmap conversion */
58uint64_t xfs_inobt_irec_to_allocmask(struct xfs_inobt_rec_incore *);
59
Brian Foster56d11152015-05-29 09:18:32 +100060#if defined(DEBUG) || defined(XFS_WARN)
61int xfs_inobt_rec_check_count(struct xfs_mount *,
62 struct xfs_inobt_rec_incore *);
63#else
64#define xfs_inobt_rec_check_count(mp, rec) 0
65#endif /* DEBUG */
66
Darrick J. Wongebcbef32018-07-29 22:37:08 -070067int xfs_finobt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp,
Dave Chinner30933122021-06-02 10:48:24 +100068 struct xfs_perag *pag, xfs_extlen_t *ask, xfs_extlen_t *used);
Darrick J. Wong14861c42018-05-09 10:02:01 -070069extern xfs_extlen_t xfs_iallocbt_calc_size(struct xfs_mount *mp,
70 unsigned long long len);
Darrick J. Wonga2114322019-07-02 09:39:38 -070071int xfs_inobt_cur(struct xfs_mount *mp, struct xfs_trans *tp,
Dave Chinner7b13c512021-06-02 10:48:24 +100072 struct xfs_perag *pag, xfs_btnum_t btnum,
Darrick J. Wonga2114322019-07-02 09:39:38 -070073 struct xfs_btree_cur **curpp, struct xfs_buf **agi_bpp);
Christoph Hellwig76d771b2017-01-25 07:49:35 -080074
Darrick J. Wongc29ce8f2020-03-11 11:01:04 -070075void xfs_inobt_commit_staged_btree(struct xfs_btree_cur *cur,
76 struct xfs_trans *tp, struct xfs_buf *agbp);
77
Darrick J. Wong0ed5f732021-09-23 10:32:06 -070078unsigned int xfs_iallocbt_maxlevels_ondisk(void);
79
Darrick J. Wong9fa47bd2021-09-23 12:21:37 -070080int __init xfs_inobt_init_cur_cache(void);
81void xfs_inobt_destroy_cur_cache(void);
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083#endif /* __XFS_IALLOC_BTREE_H__ */