blob: 29b407d053b4e9fd948b92415a9e2c94d8022c83 [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,2002-2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
6#ifndef __XFS_BMAP_BTREE_H__
7#define __XFS_BMAP_BTREE_H__
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009struct xfs_btree_cur;
Christoph Hellwig136341b2008-10-30 17:11:40 +110010struct xfs_btree_block;
Linus Torvalds1da177e2005-04-16 15:20:36 -070011struct xfs_mount;
12struct xfs_inode;
Christoph Hellwig561f7d12008-10-30 16:53:59 +110013struct xfs_trans;
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15/*
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110016 * Btree block header size depends on a superblock flag.
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110017 */
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050018#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 Torvalds1da177e2005-04-16 15:20:36 -070021
Christoph Hellwig136341b2008-10-30 17:11:40 +110022#define XFS_BMBT_REC_ADDR(mp, block, index) \
23 ((xfs_bmbt_rec_t *) \
24 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110025 XFS_BMBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110026 ((index) - 1) * sizeof(xfs_bmbt_rec_t)))
Eric Sandeen2c36dde2007-02-10 18:37:33 +110027
Christoph Hellwig136341b2008-10-30 17:11:40 +110028#define XFS_BMBT_KEY_ADDR(mp, block, index) \
29 ((xfs_bmbt_key_t *) \
30 ((char *)(block) + \
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110031 XFS_BMBT_BLOCK_LEN(mp) + \
Christoph Hellwig136341b2008-10-30 17:11:40 +110032 ((index) - 1) * sizeof(xfs_bmbt_key_t)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Christoph Hellwig136341b2008-10-30 17:11:40 +110034#define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
35 ((xfs_bmbt_ptr_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 (maxrecs) * sizeof(xfs_bmbt_key_t) + \
39 ((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
Eric Sandeen2c36dde2007-02-10 18:37:33 +110040
Christoph Hellwig136341b2008-10-30 17:11:40 +110041#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 Torvalds1da177e2005-04-16 15:20:36 -070046
Christoph Hellwig136341b2008-10-30 17:11:40 +110047#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 Torvalds1da177e2005-04-16 15:20:36 -070059
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 Hellwig136341b2008-10-30 17:11:40 +110064#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 Scotta844f452005-11-02 14:38:42 +110066
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050067#define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \
68 (int)(XFS_BMBT_BLOCK_LEN(mp) + \
Nathan Scotta844f452005-11-02 14:38:42 +110069 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
70
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050071#define XFS_BMAP_BROOT_SPACE(mp, bb) \
72 (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))
Nathan Scotta844f452005-11-02 14:38:42 +110073#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 Sandeen427d9fe2012-03-27 15:40:26 -050076#define XFS_BMAP_BMDR_SPACE(bb) \
77 (XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/*
80 * Maximum number of bmap btree levels.
81 */
Nathan Scotta844f452005-11-02 14:38:42 +110082#define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)])
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Linus Torvalds1da177e2005-04-16 15:20:36 -070084/*
85 * Prototypes for xfs_bmap.c to call.
86 */
Christoph Hellwigee1a47a2013-04-21 14:53:46 -050087extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int,
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110088 struct xfs_btree_block *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Christoph Hellwiga67d00a2017-10-17 14:16:26 -070090void xfs_bmbt_disk_set_all(struct xfs_bmbt_rec *r, struct xfs_bmbt_irec *s);
Nathan Scotta844f452005-11-02 14:38:42 +110091extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r);
Nathan Scotta844f452005-11-02 14:38:42 +110092extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r);
Christoph Hellwig6bdcf262017-11-03 10:34:46 -070093extern void xfs_bmbt_disk_get_all(xfs_bmbt_rec_t *r, xfs_bmbt_irec_t *s);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110095extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
Christoph Hellwig60197e82008-10-30 17:11:19 +110096 xfs_bmdr_block_t *, int);
97
98extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
Eric Sandeen152d93b2014-04-14 18:58:51 +100099extern int xfs_bmdr_maxrecs(int blocklen, int leaf);
Christoph Hellwig60197e82008-10-30 17:11:19 +1100100extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Dave Chinner21b5c972013-08-30 10:23:44 +1000102extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
Dave Chinner638f44162013-08-30 10:23:45 +1000103 int whichfork, xfs_ino_t new_owner,
104 struct list_head *buffer_list);
Dave Chinner21b5c972013-08-30 10:23:44 +1000105
Christoph Hellwig561f7d12008-10-30 16:53:59 +1100106extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
107 struct xfs_trans *, struct xfs_inode *, int);
108
Darrick J. Wong14861c42018-05-09 10:02:01 -0700109extern unsigned long long xfs_bmbt_calc_size(struct xfs_mount *mp,
110 unsigned long long len);
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112#endif /* __XFS_BMAP_BTREE_H__ */