]>
Commit | Line | Data |
---|---|---|
2bd0ea18 | 1 | /* |
f302e9e4 NS |
2 | * Copyright (c) 2000,2002-2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
5000d01d | 4 | * |
f302e9e4 NS |
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 | |
2bd0ea18 | 7 | * published by the Free Software Foundation. |
5000d01d | 8 | * |
f302e9e4 NS |
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. | |
5000d01d | 13 | * |
f302e9e4 NS |
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 | |
2bd0ea18 NS |
17 | */ |
18 | #ifndef __XFS_BMAP_BTREE_H__ | |
5000d01d | 19 | #define __XFS_BMAP_BTREE_H__ |
2bd0ea18 | 20 | |
5dfa5cd2 DC |
21 | #define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */ |
22 | #define XFS_BMAP_CRC_MAGIC 0x424d4133 /* 'BMA3' */ | |
2bd0ea18 NS |
23 | |
24 | struct xfs_btree_cur; | |
b3563c19 | 25 | struct xfs_btree_block; |
2bd0ea18 NS |
26 | struct xfs_mount; |
27 | struct xfs_inode; | |
b194c7d8 | 28 | struct xfs_trans; |
2bd0ea18 NS |
29 | |
30 | /* | |
31 | * Bmap root header, on-disk form only. | |
32 | */ | |
f302e9e4 NS |
33 | typedef struct xfs_bmdr_block { |
34 | __be16 bb_level; /* 0 is a leaf */ | |
35 | __be16 bb_numrecs; /* current # of data records */ | |
2bd0ea18 NS |
36 | } xfs_bmdr_block_t; |
37 | ||
38 | /* | |
39 | * Bmap btree record and extent descriptor. | |
2bd0ea18 NS |
40 | * l0:63 is an extent flag (value 1 indicates non-normal). |
41 | * l0:9-62 are startoff. | |
42 | * l0:0-8 and l1:21-63 are startblock. | |
43 | * l1:0-20 are blockcount. | |
44 | */ | |
5000d01d | 45 | #define BMBT_EXNTFLAG_BITLEN 1 |
5000d01d | 46 | #define BMBT_STARTOFF_BITLEN 54 |
5000d01d | 47 | #define BMBT_STARTBLOCK_BITLEN 52 |
5000d01d | 48 | #define BMBT_BLOCKCOUNT_BITLEN 21 |
2bd0ea18 | 49 | |
56b2de80 | 50 | typedef struct xfs_bmbt_rec { |
5e656dbb | 51 | __be64 l0, l1; |
56b2de80 | 52 | } xfs_bmbt_rec_t; |
2bd0ea18 | 53 | |
5000d01d | 54 | typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */ |
56b2de80 | 55 | typedef xfs_bmbt_rec_t xfs_bmdr_rec_t; |
2bd0ea18 | 56 | |
5e656dbb BN |
57 | typedef struct xfs_bmbt_rec_host { |
58 | __uint64_t l0, l1; | |
59 | } xfs_bmbt_rec_host_t; | |
60 | ||
2bd0ea18 NS |
61 | /* |
62 | * Values and macros for delayed-allocation startblock fields. | |
63 | */ | |
5000d01d | 64 | #define STARTBLOCKVALBITS 17 |
2b288ccf | 65 | #define STARTBLOCKMASKBITS (15 + XFS_BIG_BLKNOS * 20) |
5000d01d SL |
66 | #define DSTARTBLOCKMASKBITS (15 + 20) |
67 | #define STARTBLOCKMASK \ | |
2bd0ea18 | 68 | (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS) |
5000d01d | 69 | #define DSTARTBLOCKMASK \ |
2bd0ea18 | 70 | (((((xfs_dfsbno_t)1) << DSTARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS) |
f302e9e4 | 71 | |
f302e9e4 NS |
72 | static inline int isnullstartblock(xfs_fsblock_t x) |
73 | { | |
74 | return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK; | |
75 | } | |
76 | ||
f302e9e4 NS |
77 | static inline int isnulldstartblock(xfs_dfsbno_t x) |
78 | { | |
79 | return ((x) & DSTARTBLOCKMASK) == DSTARTBLOCKMASK; | |
80 | } | |
81 | ||
f302e9e4 NS |
82 | static inline xfs_fsblock_t nullstartblock(int k) |
83 | { | |
84 | ASSERT(k < (1 << STARTBLOCKVALBITS)); | |
85 | return STARTBLOCKMASK | (k); | |
86 | } | |
87 | ||
f302e9e4 NS |
88 | static inline xfs_filblks_t startblockval(xfs_fsblock_t x) |
89 | { | |
90 | return (xfs_filblks_t)((x) & ~STARTBLOCKMASK); | |
91 | } | |
2bd0ea18 NS |
92 | |
93 | /* | |
94 | * Possible extent formats. | |
95 | */ | |
5000d01d | 96 | typedef enum { |
2bd0ea18 NS |
97 | XFS_EXTFMT_NOSTATE = 0, |
98 | XFS_EXTFMT_HASSTATE | |
99 | } xfs_exntfmt_t; | |
100 | ||
101 | /* | |
102 | * Possible extent states. | |
103 | */ | |
5000d01d | 104 | typedef enum { |
2bd0ea18 | 105 | XFS_EXT_NORM, XFS_EXT_UNWRITTEN, |
062998e3 | 106 | XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID |
2bd0ea18 NS |
107 | } xfs_exntst_t; |
108 | ||
109 | /* | |
110 | * Extent state and extent format macros. | |
111 | */ | |
f302e9e4 | 112 | #define XFS_EXTFMT_INODE(x) \ |
5e656dbb | 113 | (xfs_sb_version_hasextflgbit(&((x)->i_mount->m_sb)) ? \ |
f302e9e4 | 114 | XFS_EXTFMT_HASSTATE : XFS_EXTFMT_NOSTATE) |
9440d84d | 115 | #define ISUNWRITTEN(x) ((x)->br_state == XFS_EXT_UNWRITTEN) |
2bd0ea18 NS |
116 | |
117 | /* | |
118 | * Incore version of above. | |
119 | */ | |
120 | typedef struct xfs_bmbt_irec | |
121 | { | |
122 | xfs_fileoff_t br_startoff; /* starting file offset */ | |
123 | xfs_fsblock_t br_startblock; /* starting block number */ | |
124 | xfs_filblks_t br_blockcount; /* number of blocks */ | |
125 | xfs_exntst_t br_state; /* extent state */ | |
126 | } xfs_bmbt_irec_t; | |
127 | ||
128 | /* | |
129 | * Key structure for non-leaf levels of the tree. | |
130 | */ | |
5e656dbb BN |
131 | typedef struct xfs_bmbt_key { |
132 | __be64 br_startoff; /* starting file offset */ | |
2bd0ea18 NS |
133 | } xfs_bmbt_key_t, xfs_bmdr_key_t; |
134 | ||
5e656dbb BN |
135 | /* btree pointer type */ |
136 | typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t; | |
137 | ||
b3563c19 BN |
138 | /* |
139 | * Btree block header size depends on a superblock flag. | |
b3563c19 | 140 | */ |
5dfa5cd2 DC |
141 | #define XFS_BMBT_BLOCK_LEN(mp) \ |
142 | (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \ | |
143 | XFS_BTREE_LBLOCK_LEN + XFS_BTREE_CRCBLOCK_ADD : \ | |
144 | XFS_BTREE_LBLOCK_LEN) | |
b3563c19 BN |
145 | |
146 | #define XFS_BMBT_REC_ADDR(mp, block, index) \ | |
147 | ((xfs_bmbt_rec_t *) \ | |
148 | ((char *)(block) + \ | |
149 | XFS_BMBT_BLOCK_LEN(mp) + \ | |
150 | ((index) - 1) * sizeof(xfs_bmbt_rec_t))) | |
151 | ||
152 | #define XFS_BMBT_KEY_ADDR(mp, block, index) \ | |
153 | ((xfs_bmbt_key_t *) \ | |
154 | ((char *)(block) + \ | |
155 | XFS_BMBT_BLOCK_LEN(mp) + \ | |
156 | ((index) - 1) * sizeof(xfs_bmbt_key_t))) | |
157 | ||
158 | #define XFS_BMBT_PTR_ADDR(mp, block, index, maxrecs) \ | |
159 | ((xfs_bmbt_ptr_t *) \ | |
160 | ((char *)(block) + \ | |
161 | XFS_BMBT_BLOCK_LEN(mp) + \ | |
162 | (maxrecs) * sizeof(xfs_bmbt_key_t) + \ | |
163 | ((index) - 1) * sizeof(xfs_bmbt_ptr_t))) | |
164 | ||
165 | #define XFS_BMDR_REC_ADDR(block, index) \ | |
166 | ((xfs_bmdr_rec_t *) \ | |
167 | ((char *)(block) + \ | |
168 | sizeof(struct xfs_bmdr_block) + \ | |
169 | ((index) - 1) * sizeof(xfs_bmdr_rec_t))) | |
170 | ||
171 | #define XFS_BMDR_KEY_ADDR(block, index) \ | |
172 | ((xfs_bmdr_key_t *) \ | |
173 | ((char *)(block) + \ | |
174 | sizeof(struct xfs_bmdr_block) + \ | |
175 | ((index) - 1) * sizeof(xfs_bmdr_key_t))) | |
176 | ||
177 | #define XFS_BMDR_PTR_ADDR(block, index, maxrecs) \ | |
178 | ((xfs_bmdr_ptr_t *) \ | |
179 | ((char *)(block) + \ | |
180 | sizeof(struct xfs_bmdr_block) + \ | |
181 | (maxrecs) * sizeof(xfs_bmdr_key_t) + \ | |
182 | ((index) - 1) * sizeof(xfs_bmdr_ptr_t))) | |
2bd0ea18 NS |
183 | |
184 | /* | |
185 | * These are to be used when we know the size of the block and | |
186 | * we don't have a cursor. | |
187 | */ | |
b3563c19 BN |
188 | #define XFS_BMAP_BROOT_PTR_ADDR(mp, bb, i, sz) \ |
189 | XFS_BMBT_PTR_ADDR(mp, bb, i, xfs_bmbt_maxrecs(mp, sz, 0)) | |
2bd0ea18 | 190 | |
5dfa5cd2 DC |
191 | #define XFS_BMAP_BROOT_SPACE_CALC(mp, nrecs) \ |
192 | (int)(XFS_BMBT_BLOCK_LEN(mp) + \ | |
f302e9e4 NS |
193 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) |
194 | ||
5dfa5cd2 DC |
195 | #define XFS_BMAP_BROOT_SPACE(mp, bb) \ |
196 | (XFS_BMAP_BROOT_SPACE_CALC(mp, be16_to_cpu((bb)->bb_numrecs))) | |
f302e9e4 NS |
197 | #define XFS_BMDR_SPACE_CALC(nrecs) \ |
198 | (int)(sizeof(xfs_bmdr_block_t) + \ | |
199 | ((nrecs) * (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t)))) | |
2bd0ea18 NS |
200 | |
201 | /* | |
202 | * Maximum number of bmap btree levels. | |
203 | */ | |
f302e9e4 | 204 | #define XFS_BM_MAXLEVELS(mp,w) ((mp)->m_bm_maxlevels[(w)]) |
2bd0ea18 | 205 | |
2bd0ea18 NS |
206 | /* |
207 | * Prototypes for xfs_bmap.c to call. | |
208 | */ | |
5dfa5cd2 | 209 | extern void xfs_bmdr_to_bmbt(struct xfs_inode *, xfs_bmdr_block_t *, int, |
b3563c19 | 210 | struct xfs_btree_block *, int); |
5e656dbb | 211 | extern void xfs_bmbt_get_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s); |
5e656dbb BN |
212 | extern xfs_filblks_t xfs_bmbt_get_blockcount(xfs_bmbt_rec_host_t *r); |
213 | extern xfs_fsblock_t xfs_bmbt_get_startblock(xfs_bmbt_rec_host_t *r); | |
214 | extern xfs_fileoff_t xfs_bmbt_get_startoff(xfs_bmbt_rec_host_t *r); | |
215 | extern xfs_exntst_t xfs_bmbt_get_state(xfs_bmbt_rec_host_t *r); | |
f302e9e4 | 216 | |
f302e9e4 | 217 | extern xfs_filblks_t xfs_bmbt_disk_get_blockcount(xfs_bmbt_rec_t *r); |
f302e9e4 | 218 | extern xfs_fileoff_t xfs_bmbt_disk_get_startoff(xfs_bmbt_rec_t *r); |
f302e9e4 | 219 | |
5e656dbb BN |
220 | extern void xfs_bmbt_set_all(xfs_bmbt_rec_host_t *r, xfs_bmbt_irec_t *s); |
221 | extern void xfs_bmbt_set_allf(xfs_bmbt_rec_host_t *r, xfs_fileoff_t o, | |
f302e9e4 | 222 | xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v); |
5e656dbb BN |
223 | extern void xfs_bmbt_set_blockcount(xfs_bmbt_rec_host_t *r, xfs_filblks_t v); |
224 | extern void xfs_bmbt_set_startblock(xfs_bmbt_rec_host_t *r, xfs_fsblock_t v); | |
225 | extern void xfs_bmbt_set_startoff(xfs_bmbt_rec_host_t *r, xfs_fileoff_t v); | |
226 | extern void xfs_bmbt_set_state(xfs_bmbt_rec_host_t *r, xfs_exntst_t v); | |
f302e9e4 | 227 | |
f302e9e4 NS |
228 | extern void xfs_bmbt_disk_set_allf(xfs_bmbt_rec_t *r, xfs_fileoff_t o, |
229 | xfs_fsblock_t b, xfs_filblks_t c, xfs_exntst_t v); | |
f9e56f43 | 230 | |
b3563c19 BN |
231 | extern void xfs_bmbt_to_bmdr(struct xfs_mount *, struct xfs_btree_block *, int, |
232 | xfs_bmdr_block_t *, int); | |
233 | ||
234 | extern int xfs_bmbt_get_maxrecs(struct xfs_btree_cur *, int level); | |
235 | extern int xfs_bmdr_maxrecs(struct xfs_mount *, int blocklen, int leaf); | |
236 | extern int xfs_bmbt_maxrecs(struct xfs_mount *, int blocklen, int leaf); | |
b194c7d8 BN |
237 | |
238 | extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *, | |
239 | struct xfs_trans *, struct xfs_inode *, int); | |
2bd0ea18 | 240 | |
a2ceac1f | 241 | extern const struct xfs_buf_ops xfs_bmbt_buf_ops; |
2bd0ea18 NS |
242 | |
243 | #endif /* __XFS_BMAP_BTREE_H__ */ |