aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/libxfs/xfs_bmap_btree.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/libxfs/xfs_bmap_btree.h')
-rw-r--r--fs/xfs/libxfs/xfs_bmap_btree.h143
1 files changed, 143 insertions, 0 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap_btree.h b/fs/xfs/libxfs/xfs_bmap_btree.h
new file mode 100644
index 000000000000..819a8a4dee95
--- /dev/null
+++ b/fs/xfs/libxfs/xfs_bmap_btree.h
@@ -0,0 +1,143 @@
1/*
2 * Copyright (c) 2000,2002-2005 Silicon Graphics, 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_BMAP_BTREE_H__
19#define __XFS_BMAP_BTREE_H__
20
21struct xfs_btree_cur;
22struct xfs_btree_block;
23struct xfs_mount;
24struct xfs_inode;
25struct xfs_trans;
26
27/*
28 * Extent state and extent format macros.
29 */
30#define XFS_EXTFMT_INODE(x) \
31 (xfs_sb_version_hasextflgbit(&((x)->i_mount->m_sb)) ? \
32 XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE)
33#define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN)
34
35/*
36 * Btree block header size depends on a superblock flag.
37 */
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)
41
42#define XFS_BMBT_REC_ADDR(mp, block, index) \
43 ((xfs_bmbt_rec_t *) \
44 ((char *)(block) + \
45 XFS_BMBT_BLOCK_LEN(mp) + \
46 ((index) - 1) * sizeof(xfs_bmbt_rec_t)))
47
48#define XFS_BMBT_KEY_ADDR(mp, block, index) \
49 ((xfs_bmbt_key_t *) \
50 ((char *)(block) + \
51 XFS_BMBT_BLOCK_LEN(mp) + \
52 ((index) - 1) * sizeof(xfs_bmbt_key_t)))
53
54#define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \
55 ((xfs_bmbt_ptr_t *) \
56 ((char *)(block) + \
57 XFS_BMBT_BLOCK_LEN(mp) + \
58 (maxrecs) * sizeof(xfs_bmbt_key_t) + \
59 ((index) - 1) * sizeof(xfs_bmbt_ptr_t)))
60
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)))
66
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)))
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 */
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))
86
87#define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \
88 (int)(XFS_BMBT_BLOCK_LEN(mp) + \
89 ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t))))
90
91#define XFS_BMAP_BROOT_SPACE(mp, bb) \
92 (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs)))
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))))
96#define XFS_BMAP_BMDR_SPACE(bb) \
97 (XFS_BMDR_SPACE_CALC(be16_to_cpu((bb)->bb_numrecs)))
98
99/*
100 * Maximum number of bmap btree levels.
101 */
102#define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)])
103
104/*
105 * Prototypes for xfs_bmap.c to call.
106 */
107extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int,
108 struct xfs_btree_block *, int);
109extern void xfs_bmbt_get_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
110extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_host_t *r);
111extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_host_t *r);
112extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_host_t *r);
113extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_host_t *r);
114
115extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r);
116extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r);
117
118extern void xfs_bmbt_set_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s);
119extern void xfs_bmbt_set_allf(xfs_bmbt_rec_host_t *r, xfs_fileoff_t o,
120 xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v);
121extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_host_t *r, xfs_filblks_t v);
122extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_host_t *r, xfs_fsblock_t v);
123extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_host_t *r, xfs_fileoff_t v);
124extern void xfs_bmbt_set_state(xfs_bmbt_rec_host_t *r, xfs_exntst_t v);
125
126extern 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);
128
129extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int,
130 xfs_bmdr_block_t *, int);
131
132extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level);
133extern int xfs_bmdr_maxrecs(int blocklen, int leaf);
134extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf);
135
136extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
137 int whichfork, xfs_ino_t new_owner,
138 struct list_head *buffer_list);
139
140extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
141 struct xfs_trans *, struct xfs_inode *, int);
142
143#endif /* __XFS_BMAP_BTREE_H__ */