blob: 9da5a8d4f184b6384638f4090b6441626a6a1ab0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
18#ifndef __XFS_BMAP_BTREE_H__
19#define __XFS_BMAP_BTREE_H__
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021struct xfs_btree_cur;
Christoph Hellwig136341b2008-10-30 17:11:40 +110022struct xfs_btree_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070023struct xfs_mount;
24struct xfs_inode;
Christoph Hellwig561f7d12008-10-30 16:53:59 +110025struct xfs_trans;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
27/*
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110028 * Btree block header size depends on a superblock flag.
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110029 */
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050030#define XFS_BMBT_BLOCK_LEN(mp) \
31 (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
32 XFS_BTREE_LBLOCK_CRC_LEN : XFS_BTREE_LBLOCK_LEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Christoph Hellwig136341b2008-10-30 17:11:40 +110034#define XFS_BMBT_REC_ADDR(mp, block, index) \
35 ((xfs_bmbt_rec_t *) \
36 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110037 XFS_BMBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110038 ((index) - 1) * sizeof(xfs_bmbt_rec_t)))
Eric Sandeen2c36dde2007-02-10 18:37:33 +110039
Christoph Hellwig136341b2008-10-30 17:11:40 +110040#define XFS_BMBT_KEY_ADDR(mp, block, index) \
41 ((xfs_bmbt_key_t *) \
42 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110043 XFS_BMBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110044 ((index) - 1) * sizeof(xfs_bmbt_key_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Christoph Hellwig136341b2008-10-30 17:11:40 +110046#define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
47 ((xfs_bmbt_ptr_t *) \
48 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110049 XFS_BMBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110050 (maxrecs) * sizeof(xfs_bmbt_key_t) + \
51 ((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
Eric Sandeen2c36dde2007-02-10 18:37:33 +110052
Christoph Hellwig136341b2008-10-30 17:11:40 +110053#define XFS_BMDR_REC_ADDR(block, index) \
54 ((xfs_bmdr_rec_t *) \
55 ((char *)(block) + \
56 sizeof(struct xfs_bmdr_block) + \
57 ((index) - 1) * sizeof(xfs_bmdr_rec_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Christoph Hellwig136341b2008-10-30 17:11:40 +110059#define XFS_BMDR_KEY_ADDR(block, index) \
60 ((xfs_bmdr_key_t *) \
61 ((char *)(block) + \
62 sizeof(struct xfs_bmdr_block) + \
63 ((index) - 1) * sizeof(xfs_bmdr_key_t)))
64
65#define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \
66 ((xfs_bmdr_ptr_t *) \
67 ((char *)(block) + \
68 sizeof(struct xfs_bmdr_block) + \
69 (maxrecs) * sizeof(xfs_bmdr_key_t) + \
70 ((index) - 1) * sizeof(xfs_bmdr_ptr_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72/*
73 * These are to be used when we know the size of the block and
74 * we don't have a cursor.
75 */
Christoph Hellwig136341b2008-10-30 17:11:40 +110076#define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \
77 XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0))
Nathan Scotta844f452005-11-02 14:38:42 +110078
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050079#define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \
80 (int)(XFS_BMBT_BLOCK_LEN(mp) + \
Nathan Scotta844f452005-11-02 14:38:42 +110081 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
82
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050083#define XFS_BMAP_BROOT_SPACE(mp, bb) \
84 (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))
Nathan Scotta844f452005-11-02 14:38:42 +110085#define XFS_BMDR_SPACE_CALC(nrecs) \
86 (int)(sizeof(xfs_bmdr_block_t) + \
87 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
Eric Sandeen427d9fe2012-03-27 15:40:26 -050088#define XFS_BMAP_BMDR_SPACE(bb) \
89 (XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/*
92 * Maximum number of bmap btree levels.
93 */
Nathan Scotta844f452005-11-02 14:38:42 +110094#define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)])
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/*
97 * Prototypes for xfs_bmap.c to call.
98 */
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050099extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int,
Christoph Hellwig7cc95a82008-10-30 17:14:34 +1100100 struct xfs_btree_block *, int);
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000101extern void xfs_bmbt_get_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000102extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_host_t *r);
103extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_host_t *r);
104extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_host_t *r);
105extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_host_t *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Nathan Scotta844f452005-11-02 14:38:42 +1100107extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r);
Nathan Scotta844f452005-11-02 14:38:42 +1100108extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000110extern void xfs_bmbt_set_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
111extern void xfs_bmbt_set_allf(xfs_bmbt_rec_host_t *r, xfs_fileoff_t o,
Nathan Scotta844f452005-11-02 14:38:42 +1100112 xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000113extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_host_t *r, xfs_filblks_t v);
114extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_host_t *r, xfs_fsblock_t v);
115extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_host_t *r, xfs_fileoff_t v);
116extern void xfs_bmbt_set_state(xfs_bmbt_rec_host_t *r, xfs_exntst_t v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Nathan Scotta844f452005-11-02 14:38:42 +1100118extern void xfs_bmbt_disk_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o,
119 xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
Christoph Hellwig7cc95a82008-10-30 17:14:34 +1100121extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
Christoph Hellwig60197e82008-10-30 17:11:19 +1100122 xfs_bmdr_block_t *, int);
123
124extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
Eric Sandeen152d93b2014-04-14 18:58:51 +1000125extern int xfs_bmdr_maxrecs(int blocklen, int leaf);
Christoph Hellwig60197e82008-10-30 17:11:19 +1100126extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Dave Chinner21b5c972013-08-30 10:23:44 +1000128extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
Dave Chinner638f44162013-08-30 10:23:45 +1000129 int whichfork, xfs_ino_t new_owner,
130 struct list_head *buffer_list);
Dave Chinner21b5c972013-08-30 10:23:44 +1000131
Christoph Hellwig561f7d12008-10-30 16:53:59 +1100132extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
133 struct xfs_trans *, struct xfs_inode *, int);
134
Christoph Hellwig0c1d9e42017-04-20 09:42:48 -0700135/*
136 * Check that the extent does not contain an invalid unwritten extent flag.
137 */
138static inline bool xfs_bmbt_validate_extent(struct xfs_mount *mp, int whichfork,
139 struct xfs_bmbt_rec_host *ep)
140{
141 if (ep->l0 >> (64 - BMBT_EXNTFLAG_BITLEN) == 0)
142 return true;
143 if (whichfork == XFS_DATA_FORK &&
144 xfs_sb_version_hasextflgbit(&mp->m_sb))
145 return true;
146 return false;
147}
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#endif /* __XFS_BMAP_BTREE_H__ */