blob: c9305ebb69f634bd3c6ccffc9dd133a35bca19f6 [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_ALLOC_BTREE_H__
7#define __XFS_ALLOC_BTREE_H__
8
9/*
10 * Freespace on-disk structures
11 */
12
13struct xfs_buf;
14struct xfs_btree_cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015struct xfs_mount;
16
17/*
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110018 * Btree block header size depends on a superblock flag.
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110019 */
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050020#define XFS_ALLOC_BLOCK_LEN(mp) \
21 (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
22 XFS_BTREE_SBLOCK_CRC_LEN : XFS_BTREE_SBLOCK_LEN)
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110023
24/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * Record, key, and pointer address macros for btree blocks.
Christoph Hellwig136341b2008-10-30 17:11:40 +110026 *
27 * (note that some of these may appear unused, but they are used in userspace)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 */
Christoph Hellwig136341b2008-10-30 17:11:40 +110029#define XFS_ALLOC_REC_ADDR(mp, block, index) \
30 ((xfs_alloc_rec_t *) \
31 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110032 XFS_ALLOC_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110033 (((index) - 1) * sizeof(xfs_alloc_rec_t))))
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Christoph Hellwig136341b2008-10-30 17:11:40 +110035#define XFS_ALLOC_KEY_ADDR(mp, block, index) \
36 ((xfs_alloc_key_t *) \
37 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110038 XFS_ALLOC_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110039 ((index) - 1) * sizeof(xfs_alloc_key_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Christoph Hellwig136341b2008-10-30 17:11:40 +110041#define XFS_ALLOC_PTR_ADDR(mp, block, index, maxrecs) \
42 ((xfs_alloc_ptr_t *) \
43 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110044 XFS_ALLOC_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110045 (maxrecs) * sizeof(xfs_alloc_key_t) + \
46 ((index) - 1) * sizeof(xfs_alloc_ptr_t)))
Christoph Hellwig561f7d12008-10-30 16:53:59 +110047
48extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *,
49 struct xfs_trans *, struct xfs_buf *,
50 xfs_agnumber_t, xfs_btnum_t);
Christoph Hellwig60197e82008-10-30 17:11:19 +110051extern int xfs_allocbt_maxrecs(struct xfs_mount *, int, int);
Darrick J. Wong14861c42018-05-09 10:02:01 -070052extern xfs_extlen_t xfs_allocbt_calc_size(struct xfs_mount *mp,
53 unsigned long long len);
Christoph Hellwig561f7d12008-10-30 16:53:59 +110054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#endif /* __XFS_ALLOC_BTREE_H__ */