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