Merge branch 'gup_flag-cleanups'
[cascardo/linux.git] / fs / xfs / libxfs / xfs_rmap_btree.h
1 /*
2  * Copyright (c) 2014 Red Hat, Inc.
3  * All Rights Reserved.
4  *
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
7  * published by the Free Software Foundation.
8  *
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.
13  *
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
17  */
18 #ifndef __XFS_RMAP_BTREE_H__
19 #define __XFS_RMAP_BTREE_H__
20
21 struct xfs_buf;
22 struct xfs_btree_cur;
23 struct xfs_mount;
24
25 /* rmaps only exist on crc enabled filesystems */
26 #define XFS_RMAP_BLOCK_LEN      XFS_BTREE_SBLOCK_CRC_LEN
27
28 /*
29  * Record, key, and pointer address macros for btree blocks.
30  *
31  * (note that some of these may appear unused, but they are used in userspace)
32  */
33 #define XFS_RMAP_REC_ADDR(block, index) \
34         ((struct xfs_rmap_rec *) \
35                 ((char *)(block) + XFS_RMAP_BLOCK_LEN + \
36                  (((index) - 1) * sizeof(struct xfs_rmap_rec))))
37
38 #define XFS_RMAP_KEY_ADDR(block, index) \
39         ((struct xfs_rmap_key *) \
40                 ((char *)(block) + XFS_RMAP_BLOCK_LEN + \
41                  ((index) - 1) * 2 * sizeof(struct xfs_rmap_key)))
42
43 #define XFS_RMAP_HIGH_KEY_ADDR(block, index) \
44         ((struct xfs_rmap_key *) \
45                 ((char *)(block) + XFS_RMAP_BLOCK_LEN + \
46                  sizeof(struct xfs_rmap_key) + \
47                  ((index) - 1) * 2 * sizeof(struct xfs_rmap_key)))
48
49 #define XFS_RMAP_PTR_ADDR(block, index, maxrecs) \
50         ((xfs_rmap_ptr_t *) \
51                 ((char *)(block) + XFS_RMAP_BLOCK_LEN + \
52                  (maxrecs) * 2 * sizeof(struct xfs_rmap_key) + \
53                  ((index) - 1) * sizeof(xfs_rmap_ptr_t)))
54
55 struct xfs_btree_cur *xfs_rmapbt_init_cursor(struct xfs_mount *mp,
56                                 struct xfs_trans *tp, struct xfs_buf *bp,
57                                 xfs_agnumber_t agno);
58 int xfs_rmapbt_maxrecs(struct xfs_mount *mp, int blocklen, int leaf);
59 extern void xfs_rmapbt_compute_maxlevels(struct xfs_mount *mp);
60
61 extern xfs_extlen_t xfs_rmapbt_calc_size(struct xfs_mount *mp,
62                 unsigned long long len);
63 extern xfs_extlen_t xfs_rmapbt_max_size(struct xfs_mount *mp);
64
65 extern int xfs_rmapbt_calc_reserves(struct xfs_mount *mp,
66                 xfs_agnumber_t agno, xfs_extlen_t *ask, xfs_extlen_t *used);
67
68 #endif  /* __XFS_RMAP_BTREE_H__ */