Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifndef __XFS_BMAP_BTREE_H__ |
| 19 | #define __XFS_BMAP_BTREE_H__ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | struct xfs_btree_cur; |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 22 | struct xfs_btree_block; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | struct xfs_mount; |
| 24 | struct xfs_inode; |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 25 | struct xfs_trans; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * Extent state and extent format macros. |
| 29 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 30 | #define XFS_EXTFMT_INODE(x) \ |
Eric Sandeen | 6211870 | 2008-03-06 13:44:28 +1100 | [diff] [blame] | 31 | (xfs_sb_version_hasextflgbit(&((x)->i_mount->m_sb)) ? \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 32 | XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN) |
| 34 | |
| 35 | /* |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 36 | * Btree block header size depends on a superblock flag. |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 37 | */ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 38 | #define XFS_BMBT_BLOCK_LEN(mp) \ |
| 39 | (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ |
| 40 | XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 42 | #define XFS_BMBT_REC_ADDR(mp, block, index) \ |
| 43 | ((xfs_bmbt_rec_t *) \ |
| 44 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 45 | XFS_BMBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 46 | ((index) - 1) * sizeof(xfs_bmbt_rec_t))) |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 47 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 48 | #define XFS_BMBT_KEY_ADDR(mp, block, index) \ |
| 49 | ((xfs_bmbt_key_t *) \ |
| 50 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 51 | XFS_BMBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 52 | ((index) - 1) * sizeof(xfs_bmbt_key_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 54 | #define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \ |
| 55 | ((xfs_bmbt_ptr_t *) \ |
| 56 | ((char *)(block) + \ |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 57 | XFS_BMBT_BLOCK_LEN(mp) + \ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 58 | (maxrecs) * sizeof(xfs_bmbt_key_t) + \ |
| 59 | ((index) - 1) * sizeof(xfs_bmbt_ptr_t))) |
Eric Sandeen | 2c36dde | 2007-02-10 18:37:33 +1100 | [diff] [blame] | 60 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 61 | #define XFS_BMDR_REC_ADDR(block, index) \ |
| 62 | ((xfs_bmdr_rec_t *) \ |
| 63 | ((char *)(block) + \ |
| 64 | sizeof(struct xfs_bmdr_block) + \ |
| 65 | ((index) - 1) * sizeof(xfs_bmdr_rec_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 67 | #define XFS_BMDR_KEY_ADDR(block, index) \ |
| 68 | ((xfs_bmdr_key_t *) \ |
| 69 | ((char *)(block) + \ |
| 70 | sizeof(struct xfs_bmdr_block) + \ |
| 71 | ((index) - 1) * sizeof(xfs_bmdr_key_t))) |
| 72 | |
| 73 | #define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \ |
| 74 | ((xfs_bmdr_ptr_t *) \ |
| 75 | ((char *)(block) + \ |
| 76 | sizeof(struct xfs_bmdr_block) + \ |
| 77 | (maxrecs) * sizeof(xfs_bmdr_key_t) + \ |
| 78 | ((index) - 1) * sizeof(xfs_bmdr_ptr_t))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * These are to be used when we know the size of the block and |
| 82 | * we don't have a cursor. |
| 83 | */ |
Christoph Hellwig | 136341b | 2008-10-30 17:11:40 +1100 | [diff] [blame] | 84 | #define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \ |
| 85 | 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] | 86 | |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 87 | #define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \ |
| 88 | (int)(XFS_BMBT_BLOCK_LEN(mp) + \ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 89 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) |
| 90 | |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 91 | #define XFS_BMAP_BROOT_SPACE(mp, bb) \ |
| 92 | (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs))) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 93 | #define XFS_BMDR_SPACE_CALC(nrecs) \ |
| 94 | (int)(sizeof(xfs_bmdr_block_t) + \ |
| 95 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) |
Eric Sandeen | 427d9fe | 2012-03-27 15:40:26 -0500 | [diff] [blame] | 96 | #define XFS_BMAP_BMDR_SPACE(bb) \ |
| 97 | (XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | /* |
| 100 | * Maximum number of bmap btree levels. |
| 101 | */ |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 102 | #define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | /* |
| 105 | * Prototypes for xfs_bmap.c to call. |
| 106 | */ |
Christoph Hellwig | ee1a47a | 2013-04-21 14:53:46 -0500 | [diff] [blame] | 107 | 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] | 108 | struct xfs_btree_block *, int); |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame] | 109 | extern void xfs_bmbt_get_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s); |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame] | 110 | extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_host_t *r); |
| 111 | extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_host_t *r); |
| 112 | extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_host_t *r); |
| 113 | extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_host_t *r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 115 | 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] | 116 | extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame] | 118 | extern void xfs_bmbt_set_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s); |
| 119 | extern void xfs_bmbt_set_allf(xfs_bmbt_rec_host_t *r, xfs_fileoff_t o, |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 120 | xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v); |
Christoph Hellwig | a6f64d4 | 2007-08-16 16:23:40 +1000 | [diff] [blame] | 121 | extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_host_t *r, xfs_filblks_t v); |
| 122 | extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_host_t *r, xfs_fsblock_t v); |
| 123 | extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_host_t *r, xfs_fileoff_t v); |
| 124 | extern void xfs_bmbt_set_state(xfs_bmbt_rec_host_t *r, xfs_exntst_t v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 126 | extern void xfs_bmbt_disk_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o, |
| 127 | xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Christoph Hellwig | 7cc95a8 | 2008-10-30 17:14:34 +1100 | [diff] [blame] | 129 | 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] | 130 | xfs_bmdr_block_t *, int); |
| 131 | |
| 132 | extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level); |
| 133 | extern int xfs_bmdr_maxrecs(struct xfs_mount *, int blocklen, int leaf); |
| 134 | extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
Dave Chinner | 21b5c97 | 2013-08-30 10:23:44 +1000 | [diff] [blame] | 136 | 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] | 137 | int whichfork, xfs_ino_t new_owner, |
| 138 | struct list_head *buffer_list); |
Dave Chinner | 21b5c97 | 2013-08-30 10:23:44 +1000 | [diff] [blame] | 139 | |
Christoph Hellwig | 561f7d1 | 2008-10-30 16:53:59 +1100 | [diff] [blame] | 140 | extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, |
| 141 | struct xfs_trans *, struct xfs_inode *, int); |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | #endif /* __XFS_BMAP_BTREE_H__ */ |