Dave Chinner | 0b61f8a | 2018-06-05 19:42:14 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 3 | * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc. |
| 4 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | #ifndef __XFS_BMAP_BTREE_H__ |
| 7 | #define __XFS_BMAP_BTREE_H__ |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | struct xfs_btree_cur; |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 10 | struct xfs_btree_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | struct xfs_mount; |
| 12 | struct xfs_inode; |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 13 | struct xfs_trans; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | /* |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 16 | * Btree block header size depends on a superblock flag. |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 17 | */ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 18 | #define XFS_BMBT_BLOCK_LEN(mp) \ |
| 19 | (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ |
| 20 | XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 22 | #define XFS_BMBT_REC_ADDR(mp, block, index) \ |
| 23 | ((xfs_bmbt_rec_t *) \ |
| 24 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 25 | XFS_BMBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 26 | ((index) - 1) * sizeof(xfs_bmbt_rec_t))) |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 27 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 28 | #define XFS_BMBT_KEY_ADDR(mp, block, index) \ |
| 29 | ((xfs_bmbt_key_t *) \ |
| 30 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 31 | XFS_BMBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 32 | ((index) - 1) * sizeof(xfs_bmbt_key_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 34 | #define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \ |
| 35 | ((xfs_bmbt_ptr_t *) \ |
| 36 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 37 | XFS_BMBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 38 | (maxrecs) * sizeof(xfs_bmbt_key_t) + \ |
| 39 | ((index) - 1) * sizeof(xfs_bmbt_ptr_t))) |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 40 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 41 | #define XFS_BMDR_REC_ADDR(block, index) \ |
| 42 | ((xfs_bmdr_rec_t *) \ |
| 43 | ((char *)(block) + \ |
| 44 | sizeof(struct xfs_bmdr_block) + \ |
| 45 | ((index) - 1) * sizeof(xfs_bmdr_rec_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 47 | #define XFS_BMDR_KEY_ADDR(block, index) \ |
| 48 | ((xfs_bmdr_key_t *) \ |
| 49 | ((char *)(block) + \ |
| 50 | sizeof(struct xfs_bmdr_block) + \ |
| 51 | ((index) - 1) * sizeof(xfs_bmdr_key_t))) |
| 52 | |
| 53 | #define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \ |
| 54 | ((xfs_bmdr_ptr_t *) \ |
| 55 | ((char *)(block) + \ |
| 56 | sizeof(struct xfs_bmdr_block) + \ |
| 57 | (maxrecs) * sizeof(xfs_bmdr_key_t) + \ |
| 58 | ((index) - 1) * sizeof(xfs_bmdr_ptr_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * These are to be used when we know the size of the block and |
| 62 | * we don't have a cursor. |
| 63 | */ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 64 | #define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \ |
| 65 | XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0)) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 66 | |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 67 | #define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \ |
| 68 | (int)(XFS_BMBT_BLOCK_LEN(mp) + \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 69 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) |
| 70 | |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 71 | #define XFS_BMAP_BROOT_SPACE(mp, bb) \ |
| 72 | (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs))) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 73 | #define XFS_BMDR_SPACE_CALC(nrecs) \ |
| 74 | (int)(sizeof(xfs_bmdr_block_t) + \ |
| 75 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) |
Eric Sandeen | 427d9fe | 2012-03-27 15:40:26 -0500 | [diff] [blame] | 76 | #define XFS_BMAP_BMDR_SPACE(bb) \ |
| 77 | (XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Maximum number of bmap btree levels. |
| 81 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 82 | #define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* |
| 85 | * Prototypes for xfs_bmap.c to call. |
| 86 | */ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 87 | extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int, |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 88 | struct xfs_btree_block *, int); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Christoph Hellwig | a67d00a | 2017-10-17 14:16:26 -0700 | [diff] [blame] | 90 | void xfs_bmbt_disk_set_all(struct xfs_bmbt_rec *r, struct xfs_bmbt_irec *s); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 91 | extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r); |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 92 | extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r); |
Christoph Hellwig | 6bdcf26 | 2017-11-03 10:34:46 -0700 | [diff] [blame] | 93 | extern void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 95 | extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int, |
Christoph Hellwig | 60197e8 | 2008-10-30 17:11:19 +1100 | [diff] [blame] | 96 | xfs_bmdr_block_t *, int); |
| 97 | |
| 98 | extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level); |
Eric Sandeen | 152d93b | 2014-04-14 18:58:51 +1000 | [diff] [blame] | 99 | extern int xfs_bmdr_maxrecs(int blocklen, int leaf); |
Christoph Hellwig | 60197e8 | 2008-10-30 17:11:19 +1100 | [diff] [blame] | 100 | extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Dave Chinner | 21b5c97 | 2013-08-30 10:23:44 +1000 | [diff] [blame] | 102 | extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip, |
Dave Chinner | 638f4416 | 2013-08-30 10:23:45 +1000 | [diff] [blame] | 103 | int whichfork, xfs_ino_t new_owner, |
| 104 | struct list_head *buffer_list); |
Dave Chinner | 21b5c97 | 2013-08-30 10:23:44 +1000 | [diff] [blame] | 105 | |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 106 | extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, |
| 107 | struct xfs_trans *, struct xfs_inode *, int); |
| 108 | |
Darrick J. Wong | 14861c4 | 2018-05-09 10:02:01 -0700 | [diff] [blame] | 109 | extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp, |
| 110 | unsigned long long len); |
| 111 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #endif /* __XFS_BMAP_BTREE_H__ */ |