blob: 862084a47a7e269a8ab4357d5bf75906688ee86c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_fs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_types.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_log.h"
23#include "xfs_trans.h"
24#include "xfs_sb.h"
25#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "xfs_mount.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include "xfs_bmap_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110028#include "xfs_alloc_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include "xfs_ialloc_btree.h"
Nathan Scotta844f452005-11-02 14:38:42 +110030#include "xfs_dinode.h"
31#include "xfs_inode.h"
32#include "xfs_inode_item.h"
33#include "xfs_alloc.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_btree.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "xfs_itable.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "xfs_bmap.h"
37#include "xfs_error.h"
38#include "xfs_quota.h"
39
Linus Torvalds1da177e2005-04-16 15:20:36 -070040/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * Determine the extent state.
42 */
43/* ARGSUSED */
44STATIC xfs_exntst_t
45xfs_extent_state(
46 xfs_filblks_t blks,
47 int extent_flag)
48{
49 if (extent_flag) {
50 ASSERT(blks != 0); /* saved for DMIG */
51 return XFS_EXT_UNWRITTEN;
52 }
53 return XFS_EXT_NORM;
54}
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * Convert on-disk form of btree root to in-memory form.
58 */
59void
60xfs_bmdr_to_bmbt(
Christoph Hellwig60197e82008-10-30 17:11:19 +110061 struct xfs_mount *mp,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 xfs_bmdr_block_t *dblock,
63 int dblocklen,
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110064 struct xfs_btree_block *rblock,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 int rblocklen)
66{
67 int dmxr;
68 xfs_bmbt_key_t *fkp;
Christoph Hellwig576039c2006-09-28 10:58:06 +100069 __be64 *fpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 xfs_bmbt_key_t *tkp;
Christoph Hellwig576039c2006-09-28 10:58:06 +100071 __be64 *tpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Christoph Hellwig16259e72005-11-02 15:11:25 +110073 rblock->bb_magic = cpu_to_be32(XFS_BMAP_MAGIC);
74 rblock->bb_level = dblock->bb_level;
75 ASSERT(be16_to_cpu(rblock->bb_level) > 0);
76 rblock->bb_numrecs = dblock->bb_numrecs;
Christoph Hellwig7cc95a82008-10-30 17:14:34 +110077 rblock->bb_u.l.bb_leftsib = cpu_to_be64(NULLDFSBNO);
78 rblock->bb_u.l.bb_rightsib = cpu_to_be64(NULLDFSBNO);
Christoph Hellwig60197e82008-10-30 17:11:19 +110079 dmxr = xfs_bmdr_maxrecs(mp, dblocklen, 0);
Christoph Hellwig136341b2008-10-30 17:11:40 +110080 fkp = XFS_BMDR_KEY_ADDR(dblock, 1);
81 tkp = XFS_BMBT_KEY_ADDR(mp, rblock, 1);
82 fpp = XFS_BMDR_PTR_ADDR(dblock, 1, dmxr);
Christoph Hellwig60197e82008-10-30 17:11:19 +110083 tpp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, rblocklen);
Christoph Hellwig16259e72005-11-02 15:11:25 +110084 dmxr = be16_to_cpu(dblock->bb_numrecs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 memcpy(tkp, fkp, sizeof(*fkp) * dmxr);
Christoph Hellwig576039c2006-09-28 10:58:06 +100086 memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
89/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 * Convert a compressed bmap extent record to an uncompressed form.
91 * This code must be in sync with the routines xfs_bmbt_get_startoff,
92 * xfs_bmbt_get_startblock, xfs_bmbt_get_blockcount and xfs_bmbt_get_state.
93 */
Christoph Hellwigb8f82a42009-11-14 16:17:22 +000094STATIC void
Linus Torvalds1da177e2005-04-16 15:20:36 -070095__xfs_bmbt_get_all(
96 __uint64_t l0,
97 __uint64_t l1,
98 xfs_bmbt_irec_t *s)
99{
100 int ext_flag;
101 xfs_exntst_t st;
102
103 ext_flag = (int)(l0 >> (64 - BMBT_EXNTFLAG_BITLEN));
104 s->br_startoff = ((xfs_fileoff_t)l0 &
Eric Sandeenfb825572009-01-09 15:53:54 +1100105 xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#if XFS_BIG_BLKNOS
Eric Sandeenfb825572009-01-09 15:53:54 +1100107 s->br_startblock = (((xfs_fsblock_t)l0 & xfs_mask64lo(9)) << 43) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 (((xfs_fsblock_t)l1) >> 21);
109#else
110#ifdef DEBUG
111 {
112 xfs_dfsbno_t b;
113
Eric Sandeenfb825572009-01-09 15:53:54 +1100114 b = (((xfs_dfsbno_t)l0 & xfs_mask64lo(9)) << 43) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 (((xfs_dfsbno_t)l1) >> 21);
Eric Sandeen9d87c312009-01-14 23:22:07 -0600116 ASSERT((b >> 32) == 0 || isnulldstartblock(b));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 s->br_startblock = (xfs_fsblock_t)b;
118 }
119#else /* !DEBUG */
120 s->br_startblock = (xfs_fsblock_t)(((xfs_dfsbno_t)l1) >> 21);
121#endif /* DEBUG */
122#endif /* XFS_BIG_BLKNOS */
Eric Sandeenfb825572009-01-09 15:53:54 +1100123 s->br_blockcount = (xfs_filblks_t)(l1 & xfs_mask64lo(21));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 /* This is xfs_extent_state() in-line */
125 if (ext_flag) {
126 ASSERT(s->br_blockcount != 0); /* saved for DMIG */
127 st = XFS_EXT_UNWRITTEN;
128 } else
129 st = XFS_EXT_NORM;
130 s->br_state = st;
131}
132
133void
134xfs_bmbt_get_all(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000135 xfs_bmbt_rec_host_t *r,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 xfs_bmbt_irec_t *s)
137{
138 __xfs_bmbt_get_all(r->l0, r->l1, s);
139}
140
141/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 * Extract the blockcount field from an in memory bmap extent record.
143 */
144xfs_filblks_t
145xfs_bmbt_get_blockcount(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000146 xfs_bmbt_rec_host_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Eric Sandeenfb825572009-01-09 15:53:54 +1100148 return (xfs_filblks_t)(r->l1 & xfs_mask64lo(21));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
151/*
152 * Extract the startblock field from an in memory bmap extent record.
153 */
154xfs_fsblock_t
155xfs_bmbt_get_startblock(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000156 xfs_bmbt_rec_host_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158#if XFS_BIG_BLKNOS
Eric Sandeenfb825572009-01-09 15:53:54 +1100159 return (((xfs_fsblock_t)r->l0 & xfs_mask64lo(9)) << 43) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 (((xfs_fsblock_t)r->l1) >> 21);
161#else
162#ifdef DEBUG
163 xfs_dfsbno_t b;
164
Eric Sandeenfb825572009-01-09 15:53:54 +1100165 b = (((xfs_dfsbno_t)r->l0 & xfs_mask64lo(9)) << 43) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 (((xfs_dfsbno_t)r->l1) >> 21);
Eric Sandeen9d87c312009-01-14 23:22:07 -0600167 ASSERT((b >> 32) == 0 || isnulldstartblock(b));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return (xfs_fsblock_t)b;
169#else /* !DEBUG */
170 return (xfs_fsblock_t)(((xfs_dfsbno_t)r->l1) >> 21);
171#endif /* DEBUG */
172#endif /* XFS_BIG_BLKNOS */
173}
174
175/*
176 * Extract the startoff field from an in memory bmap extent record.
177 */
178xfs_fileoff_t
179xfs_bmbt_get_startoff(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000180 xfs_bmbt_rec_host_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 return ((xfs_fileoff_t)r->l0 &
Eric Sandeenfb825572009-01-09 15:53:54 +1100183 xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
186xfs_exntst_t
187xfs_bmbt_get_state(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000188 xfs_bmbt_rec_host_t *r)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
190 int ext_flag;
191
192 ext_flag = (int)((r->l0) >> (64 - BMBT_EXNTFLAG_BITLEN));
193 return xfs_extent_state(xfs_bmbt_get_blockcount(r),
194 ext_flag);
195}
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/*
198 * Extract the blockcount field from an on disk bmap extent record.
199 */
200xfs_filblks_t
201xfs_bmbt_disk_get_blockcount(
202 xfs_bmbt_rec_t *r)
203{
Eric Sandeenfb825572009-01-09 15:53:54 +1100204 return (xfs_filblks_t)(be64_to_cpu(r->l1) & xfs_mask64lo(21));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
207/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 * Extract the startoff field from a disk format bmap extent record.
209 */
210xfs_fileoff_t
211xfs_bmbt_disk_get_startoff(
212 xfs_bmbt_rec_t *r)
213{
Christoph Hellwigcd8b0a92007-08-16 16:24:15 +1000214 return ((xfs_fileoff_t)be64_to_cpu(r->l0) &
Eric Sandeenfb825572009-01-09 15:53:54 +1100215 xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN)) >> 9;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219/*
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000220 * Set all the fields in a bmap extent record from the arguments.
221 */
222void
223xfs_bmbt_set_allf(
224 xfs_bmbt_rec_host_t *r,
225 xfs_fileoff_t startoff,
226 xfs_fsblock_t startblock,
227 xfs_filblks_t blockcount,
228 xfs_exntst_t state)
229{
230 int extent_flag = (state == XFS_EXT_NORM) ? 0 : 1;
231
232 ASSERT(state == XFS_EXT_NORM || state == XFS_EXT_UNWRITTEN);
Eric Sandeenfb825572009-01-09 15:53:54 +1100233 ASSERT((startoff & xfs_mask64hi(64-BMBT_STARTOFF_BITLEN)) == 0);
234 ASSERT((blockcount & xfs_mask64hi(64-BMBT_BLOCKCOUNT_BITLEN)) == 0);
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000235
236#if XFS_BIG_BLKNOS
Eric Sandeenfb825572009-01-09 15:53:54 +1100237 ASSERT((startblock & xfs_mask64hi(64-BMBT_STARTBLOCK_BITLEN)) == 0);
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000238
239 r->l0 = ((xfs_bmbt_rec_base_t)extent_flag << 63) |
240 ((xfs_bmbt_rec_base_t)startoff << 9) |
241 ((xfs_bmbt_rec_base_t)startblock >> 43);
242 r->l1 = ((xfs_bmbt_rec_base_t)startblock << 21) |
243 ((xfs_bmbt_rec_base_t)blockcount &
Eric Sandeenfb825572009-01-09 15:53:54 +1100244 (xfs_bmbt_rec_base_t)xfs_mask64lo(21));
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000245#else /* !XFS_BIG_BLKNOS */
Eric Sandeen9d87c312009-01-14 23:22:07 -0600246 if (isnullstartblock(startblock)) {
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000247 r->l0 = ((xfs_bmbt_rec_base_t)extent_flag << 63) |
248 ((xfs_bmbt_rec_base_t)startoff << 9) |
Eric Sandeenfb825572009-01-09 15:53:54 +1100249 (xfs_bmbt_rec_base_t)xfs_mask64lo(9);
250 r->l1 = xfs_mask64hi(11) |
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000251 ((xfs_bmbt_rec_base_t)startblock << 21) |
252 ((xfs_bmbt_rec_base_t)blockcount &
Eric Sandeenfb825572009-01-09 15:53:54 +1100253 (xfs_bmbt_rec_base_t)xfs_mask64lo(21));
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000254 } else {
255 r->l0 = ((xfs_bmbt_rec_base_t)extent_flag << 63) |
256 ((xfs_bmbt_rec_base_t)startoff << 9);
257 r->l1 = ((xfs_bmbt_rec_base_t)startblock << 21) |
258 ((xfs_bmbt_rec_base_t)blockcount &
Eric Sandeenfb825572009-01-09 15:53:54 +1100259 (xfs_bmbt_rec_base_t)xfs_mask64lo(21));
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000260 }
261#endif /* XFS_BIG_BLKNOS */
262}
263
264/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 * Set all the fields in a bmap extent record from the uncompressed form.
266 */
267void
268xfs_bmbt_set_all(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000269 xfs_bmbt_rec_host_t *r,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 xfs_bmbt_irec_t *s)
271{
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000272 xfs_bmbt_set_allf(r, s->br_startoff, s->br_startblock,
273 s->br_blockcount, s->br_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277/*
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000278 * Set all the fields in a disk format bmap extent record from the arguments.
279 */
280void
281xfs_bmbt_disk_set_allf(
282 xfs_bmbt_rec_t *r,
283 xfs_fileoff_t startoff,
284 xfs_fsblock_t startblock,
285 xfs_filblks_t blockcount,
286 xfs_exntst_t state)
287{
288 int extent_flag = (state == XFS_EXT_NORM) ? 0 : 1;
289
290 ASSERT(state == XFS_EXT_NORM || state == XFS_EXT_UNWRITTEN);
Eric Sandeenfb825572009-01-09 15:53:54 +1100291 ASSERT((startoff & xfs_mask64hi(64-BMBT_STARTOFF_BITLEN)) == 0);
292 ASSERT((blockcount & xfs_mask64hi(64-BMBT_BLOCKCOUNT_BITLEN)) == 0);
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000293
294#if XFS_BIG_BLKNOS
Eric Sandeenfb825572009-01-09 15:53:54 +1100295 ASSERT((startblock & xfs_mask64hi(64-BMBT_STARTBLOCK_BITLEN)) == 0);
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000296
Christoph Hellwigcd8b0a92007-08-16 16:24:15 +1000297 r->l0 = cpu_to_be64(
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000298 ((xfs_bmbt_rec_base_t)extent_flag << 63) |
299 ((xfs_bmbt_rec_base_t)startoff << 9) |
300 ((xfs_bmbt_rec_base_t)startblock >> 43));
Christoph Hellwigcd8b0a92007-08-16 16:24:15 +1000301 r->l1 = cpu_to_be64(
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000302 ((xfs_bmbt_rec_base_t)startblock << 21) |
303 ((xfs_bmbt_rec_base_t)blockcount &
Eric Sandeenfb825572009-01-09 15:53:54 +1100304 (xfs_bmbt_rec_base_t)xfs_mask64lo(21)));
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000305#else /* !XFS_BIG_BLKNOS */
Eric Sandeen9d87c312009-01-14 23:22:07 -0600306 if (isnullstartblock(startblock)) {
Christoph Hellwigcd8b0a92007-08-16 16:24:15 +1000307 r->l0 = cpu_to_be64(
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000308 ((xfs_bmbt_rec_base_t)extent_flag << 63) |
309 ((xfs_bmbt_rec_base_t)startoff << 9) |
Eric Sandeenfb825572009-01-09 15:53:54 +1100310 (xfs_bmbt_rec_base_t)xfs_mask64lo(9));
311 r->l1 = cpu_to_be64(xfs_mask64hi(11) |
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000312 ((xfs_bmbt_rec_base_t)startblock << 21) |
313 ((xfs_bmbt_rec_base_t)blockcount &
Eric Sandeenfb825572009-01-09 15:53:54 +1100314 (xfs_bmbt_rec_base_t)xfs_mask64lo(21)));
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000315 } else {
Christoph Hellwigcd8b0a92007-08-16 16:24:15 +1000316 r->l0 = cpu_to_be64(
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000317 ((xfs_bmbt_rec_base_t)extent_flag << 63) |
318 ((xfs_bmbt_rec_base_t)startoff << 9));
Christoph Hellwigcd8b0a92007-08-16 16:24:15 +1000319 r->l1 = cpu_to_be64(
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000320 ((xfs_bmbt_rec_base_t)startblock << 21) |
321 ((xfs_bmbt_rec_base_t)blockcount &
Eric Sandeenfb825572009-01-09 15:53:54 +1100322 (xfs_bmbt_rec_base_t)xfs_mask64lo(21)));
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000323 }
324#endif /* XFS_BIG_BLKNOS */
325}
326
327/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 * Set all the fields in a bmap extent record from the uncompressed form.
329 */
Eric Sandeen5d77c0d2009-11-19 15:52:00 +0000330STATIC void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331xfs_bmbt_disk_set_all(
332 xfs_bmbt_rec_t *r,
333 xfs_bmbt_irec_t *s)
334{
Christoph Hellwig8cba4342007-08-16 16:23:53 +1000335 xfs_bmbt_disk_set_allf(r, s->br_startoff, s->br_startblock,
336 s->br_blockcount, s->br_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339/*
340 * Set the blockcount field in a bmap extent record.
341 */
342void
343xfs_bmbt_set_blockcount(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000344 xfs_bmbt_rec_host_t *r,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 xfs_filblks_t v)
346{
Eric Sandeenfb825572009-01-09 15:53:54 +1100347 ASSERT((v & xfs_mask64hi(43)) == 0);
348 r->l1 = (r->l1 & (xfs_bmbt_rec_base_t)xfs_mask64hi(43)) |
349 (xfs_bmbt_rec_base_t)(v & xfs_mask64lo(21));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350}
351
352/*
353 * Set the startblock field in a bmap extent record.
354 */
355void
356xfs_bmbt_set_startblock(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000357 xfs_bmbt_rec_host_t *r,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 xfs_fsblock_t v)
359{
360#if XFS_BIG_BLKNOS
Eric Sandeenfb825572009-01-09 15:53:54 +1100361 ASSERT((v & xfs_mask64hi(12)) == 0);
362 r->l0 = (r->l0 & (xfs_bmbt_rec_base_t)xfs_mask64hi(55)) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 (xfs_bmbt_rec_base_t)(v >> 43);
Eric Sandeenfb825572009-01-09 15:53:54 +1100364 r->l1 = (r->l1 & (xfs_bmbt_rec_base_t)xfs_mask64lo(21)) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 (xfs_bmbt_rec_base_t)(v << 21);
366#else /* !XFS_BIG_BLKNOS */
Eric Sandeen9d87c312009-01-14 23:22:07 -0600367 if (isnullstartblock(v)) {
Eric Sandeenfb825572009-01-09 15:53:54 +1100368 r->l0 |= (xfs_bmbt_rec_base_t)xfs_mask64lo(9);
369 r->l1 = (xfs_bmbt_rec_base_t)xfs_mask64hi(11) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 ((xfs_bmbt_rec_base_t)v << 21) |
Eric Sandeenfb825572009-01-09 15:53:54 +1100371 (r->l1 & (xfs_bmbt_rec_base_t)xfs_mask64lo(21));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 } else {
Eric Sandeenfb825572009-01-09 15:53:54 +1100373 r->l0 &= ~(xfs_bmbt_rec_base_t)xfs_mask64lo(9);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 r->l1 = ((xfs_bmbt_rec_base_t)v << 21) |
Eric Sandeenfb825572009-01-09 15:53:54 +1100375 (r->l1 & (xfs_bmbt_rec_base_t)xfs_mask64lo(21));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 }
377#endif /* XFS_BIG_BLKNOS */
378}
379
380/*
381 * Set the startoff field in a bmap extent record.
382 */
383void
384xfs_bmbt_set_startoff(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000385 xfs_bmbt_rec_host_t *r,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 xfs_fileoff_t v)
387{
Eric Sandeenfb825572009-01-09 15:53:54 +1100388 ASSERT((v & xfs_mask64hi(9)) == 0);
389 r->l0 = (r->l0 & (xfs_bmbt_rec_base_t) xfs_mask64hi(1)) |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 ((xfs_bmbt_rec_base_t)v << 9) |
Eric Sandeenfb825572009-01-09 15:53:54 +1100391 (r->l0 & (xfs_bmbt_rec_base_t)xfs_mask64lo(9));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392}
393
394/*
395 * Set the extent state field in a bmap extent record.
396 */
397void
398xfs_bmbt_set_state(
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000399 xfs_bmbt_rec_host_t *r,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 xfs_exntst_t v)
401{
402 ASSERT(v == XFS_EXT_NORM || v == XFS_EXT_UNWRITTEN);
403 if (v == XFS_EXT_NORM)
Eric Sandeenfb825572009-01-09 15:53:54 +1100404 r->l0 &= xfs_mask64lo(64 - BMBT_EXNTFLAG_BITLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 else
Eric Sandeenfb825572009-01-09 15:53:54 +1100406 r->l0 |= xfs_mask64hi(BMBT_EXNTFLAG_BITLEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
409/*
410 * Convert in-memory form of btree root to on-disk form.
411 */
412void
413xfs_bmbt_to_bmdr(
Christoph Hellwig60197e82008-10-30 17:11:19 +1100414 struct xfs_mount *mp,
Christoph Hellwig7cc95a82008-10-30 17:14:34 +1100415 struct xfs_btree_block *rblock,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 int rblocklen,
417 xfs_bmdr_block_t *dblock,
418 int dblocklen)
419{
420 int dmxr;
421 xfs_bmbt_key_t *fkp;
Christoph Hellwig576039c2006-09-28 10:58:06 +1000422 __be64 *fpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 xfs_bmbt_key_t *tkp;
Christoph Hellwig576039c2006-09-28 10:58:06 +1000424 __be64 *tpp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Christoph Hellwig69ef9212011-07-08 14:36:05 +0200426 ASSERT(rblock->bb_magic == cpu_to_be32(XFS_BMAP_MAGIC));
427 ASSERT(rblock->bb_u.l.bb_leftsib == cpu_to_be64(NULLDFSBNO));
428 ASSERT(rblock->bb_u.l.bb_rightsib == cpu_to_be64(NULLDFSBNO));
429 ASSERT(rblock->bb_level != 0);
Christoph Hellwig16259e72005-11-02 15:11:25 +1100430 dblock->bb_level = rblock->bb_level;
431 dblock->bb_numrecs = rblock->bb_numrecs;
Christoph Hellwig60197e82008-10-30 17:11:19 +1100432 dmxr = xfs_bmdr_maxrecs(mp, dblocklen, 0);
Christoph Hellwig136341b2008-10-30 17:11:40 +1100433 fkp = XFS_BMBT_KEY_ADDR(mp, rblock, 1);
434 tkp = XFS_BMDR_KEY_ADDR(dblock, 1);
Christoph Hellwig60197e82008-10-30 17:11:19 +1100435 fpp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, rblocklen);
Christoph Hellwig136341b2008-10-30 17:11:40 +1100436 tpp = XFS_BMDR_PTR_ADDR(dblock, 1, dmxr);
Christoph Hellwig16259e72005-11-02 15:11:25 +1100437 dmxr = be16_to_cpu(dblock->bb_numrecs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 memcpy(tkp, fkp, sizeof(*fkp) * dmxr);
Christoph Hellwig576039c2006-09-28 10:58:06 +1000439 memcpy(tpp, fpp, sizeof(*fpp) * dmxr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442/*
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100443 * Check extent records, which have just been read, for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 * any bit in the extent flag field. ASSERT on debug
445 * kernels, as this condition should not occur.
446 * Return an error condition (1) if any flags found,
447 * otherwise return 0.
448 */
449
450int
451xfs_check_nostate_extents(
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100452 xfs_ifork_t *ifp,
453 xfs_extnum_t idx,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 xfs_extnum_t num)
455{
Mandy Kirkconnell4eea22f2006-03-14 13:29:52 +1100456 for (; num > 0; num--, idx++) {
Christoph Hellwiga6f64d42007-08-16 16:23:40 +1000457 xfs_bmbt_rec_host_t *ep = xfs_iext_get_ext(ifp, idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 if ((ep->l0 >>
459 (64 - BMBT_EXNTFLAG_BITLEN)) != 0) {
460 ASSERT(0);
461 return 1;
462 }
463 }
464 return 0;
465}
Christoph Hellwig561f7d12008-10-30 16:53:59 +1100466
467
468STATIC struct xfs_btree_cur *
469xfs_bmbt_dup_cursor(
470 struct xfs_btree_cur *cur)
471{
472 struct xfs_btree_cur *new;
473
474 new = xfs_bmbt_init_cursor(cur->bc_mp, cur->bc_tp,
475 cur->bc_private.b.ip, cur->bc_private.b.whichfork);
476
477 /*
478 * Copy the firstblock, flist, and flags values,
479 * since init cursor doesn't get them.
480 */
481 new->bc_private.b.firstblock = cur->bc_private.b.firstblock;
482 new->bc_private.b.flist = cur->bc_private.b.flist;
483 new->bc_private.b.flags = cur->bc_private.b.flags;
484
485 return new;
486}
487
Christoph Hellwig4b22a572008-10-30 16:57:40 +1100488STATIC void
489xfs_bmbt_update_cursor(
490 struct xfs_btree_cur *src,
491 struct xfs_btree_cur *dst)
492{
493 ASSERT((dst->bc_private.b.firstblock != NULLFSBLOCK) ||
494 (dst->bc_private.b.ip->i_d.di_flags & XFS_DIFLAG_REALTIME));
495 ASSERT(dst->bc_private.b.flist == src->bc_private.b.flist);
496
497 dst->bc_private.b.allocated += src->bc_private.b.allocated;
498 dst->bc_private.b.firstblock = src->bc_private.b.firstblock;
499
500 src->bc_private.b.allocated = 0;
501}
502
Christoph Hellwigce5e42d2008-10-30 16:55:23 +1100503STATIC int
Christoph Hellwigf5eb8e72008-10-30 16:57:03 +1100504xfs_bmbt_alloc_block(
505 struct xfs_btree_cur *cur,
506 union xfs_btree_ptr *start,
507 union xfs_btree_ptr *new,
508 int length,
509 int *stat)
510{
511 xfs_alloc_arg_t args; /* block allocation args */
512 int error; /* error return value */
513
514 memset(&args, 0, sizeof(args));
515 args.tp = cur->bc_tp;
516 args.mp = cur->bc_mp;
517 args.fsbno = cur->bc_private.b.firstblock;
518 args.firstblock = args.fsbno;
519
520 if (args.fsbno == NULLFSBLOCK) {
521 args.fsbno = be64_to_cpu(start->l);
522 args.type = XFS_ALLOCTYPE_START_BNO;
523 /*
524 * Make sure there is sufficient room left in the AG to
525 * complete a full tree split for an extent insert. If
526 * we are converting the middle part of an extent then
527 * we may need space for two tree splits.
528 *
529 * We are relying on the caller to make the correct block
530 * reservation for this operation to succeed. If the
531 * reservation amount is insufficient then we may fail a
532 * block allocation here and corrupt the filesystem.
533 */
534 args.minleft = xfs_trans_get_block_res(args.tp);
535 } else if (cur->bc_private.b.flist->xbf_low) {
536 args.type = XFS_ALLOCTYPE_START_BNO;
537 } else {
538 args.type = XFS_ALLOCTYPE_NEAR_BNO;
539 }
540
541 args.minlen = args.maxlen = args.prod = 1;
542 args.wasdel = cur->bc_private.b.flags & XFS_BTCUR_BPRV_WASDEL;
543 if (!args.wasdel && xfs_trans_get_block_res(args.tp) == 0) {
544 error = XFS_ERROR(ENOSPC);
545 goto error0;
546 }
547 error = xfs_alloc_vextent(&args);
548 if (error)
549 goto error0;
550
551 if (args.fsbno == NULLFSBLOCK && args.minleft) {
552 /*
553 * Could not find an AG with enough free space to satisfy
554 * a full btree split. Try again without minleft and if
555 * successful activate the lowspace algorithm.
556 */
557 args.fsbno = 0;
558 args.type = XFS_ALLOCTYPE_FIRST_AG;
559 args.minleft = 0;
560 error = xfs_alloc_vextent(&args);
561 if (error)
562 goto error0;
563 cur->bc_private.b.flist->xbf_low = 1;
564 }
565 if (args.fsbno == NULLFSBLOCK) {
566 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
567 *stat = 0;
568 return 0;
569 }
570 ASSERT(args.len == 1);
571 cur->bc_private.b.firstblock = args.fsbno;
572 cur->bc_private.b.allocated++;
573 cur->bc_private.b.ip->i_d.di_nblocks++;
574 xfs_trans_log_inode(args.tp, cur->bc_private.b.ip, XFS_ILOG_CORE);
Christoph Hellwig7d095252009-06-08 15:33:32 +0200575 xfs_trans_mod_dquot_byino(args.tp, cur->bc_private.b.ip,
Christoph Hellwigf5eb8e72008-10-30 16:57:03 +1100576 XFS_TRANS_DQ_BCOUNT, 1L);
577
578 new->l = cpu_to_be64(args.fsbno);
579
580 XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
581 *stat = 1;
582 return 0;
583
584 error0:
585 XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
586 return error;
587}
588
589STATIC int
Christoph Hellwigd4b3a4b2008-10-30 16:57:51 +1100590xfs_bmbt_free_block(
591 struct xfs_btree_cur *cur,
592 struct xfs_buf *bp)
593{
594 struct xfs_mount *mp = cur->bc_mp;
595 struct xfs_inode *ip = cur->bc_private.b.ip;
596 struct xfs_trans *tp = cur->bc_tp;
597 xfs_fsblock_t fsbno = XFS_DADDR_TO_FSB(mp, XFS_BUF_ADDR(bp));
598
599 xfs_bmap_add_free(fsbno, 1, cur->bc_private.b.flist, mp);
600 ip->i_d.di_nblocks--;
601
602 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
Christoph Hellwig7d095252009-06-08 15:33:32 +0200603 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L);
Christoph Hellwigd4b3a4b2008-10-30 16:57:51 +1100604 xfs_trans_binval(tp, bp);
605 return 0;
606}
607
608STATIC int
Christoph Hellwig91cca5df2008-10-30 16:58:01 +1100609xfs_bmbt_get_minrecs(
610 struct xfs_btree_cur *cur,
611 int level)
612{
Christoph Hellwig60197e82008-10-30 17:11:19 +1100613 if (level == cur->bc_nlevels - 1) {
614 struct xfs_ifork *ifp;
615
616 ifp = XFS_IFORK_PTR(cur->bc_private.b.ip,
617 cur->bc_private.b.whichfork);
618
619 return xfs_bmbt_maxrecs(cur->bc_mp,
620 ifp->if_broot_bytes, level == 0) / 2;
621 }
622
623 return cur->bc_mp->m_bmap_dmnr[level != 0];
Christoph Hellwig91cca5df2008-10-30 16:58:01 +1100624}
625
Christoph Hellwig60197e82008-10-30 17:11:19 +1100626int
Christoph Hellwigce5e42d2008-10-30 16:55:23 +1100627xfs_bmbt_get_maxrecs(
628 struct xfs_btree_cur *cur,
629 int level)
630{
Christoph Hellwig60197e82008-10-30 17:11:19 +1100631 if (level == cur->bc_nlevels - 1) {
632 struct xfs_ifork *ifp;
633
634 ifp = XFS_IFORK_PTR(cur->bc_private.b.ip,
635 cur->bc_private.b.whichfork);
636
637 return xfs_bmbt_maxrecs(cur->bc_mp,
638 ifp->if_broot_bytes, level == 0);
639 }
640
641 return cur->bc_mp->m_bmap_dmxr[level != 0];
642
Christoph Hellwigce5e42d2008-10-30 16:55:23 +1100643}
644
Christoph Hellwig4b22a572008-10-30 16:57:40 +1100645/*
646 * Get the maximum records we could store in the on-disk format.
647 *
648 * For non-root nodes this is equivalent to xfs_bmbt_get_maxrecs, but
649 * for the root node this checks the available space in the dinode fork
650 * so that we can resize the in-memory buffer to match it. After a
651 * resize to the maximum size this function returns the same value
652 * as xfs_bmbt_get_maxrecs for the root node, too.
653 */
654STATIC int
655xfs_bmbt_get_dmaxrecs(
656 struct xfs_btree_cur *cur,
657 int level)
658{
Christoph Hellwig60197e82008-10-30 17:11:19 +1100659 if (level != cur->bc_nlevels - 1)
660 return cur->bc_mp->m_bmap_dmxr[level != 0];
661 return xfs_bmdr_maxrecs(cur->bc_mp, cur->bc_private.b.forksize,
662 level == 0);
Christoph Hellwig4b22a572008-10-30 16:57:40 +1100663}
664
Christoph Hellwigfe033cc2008-10-30 16:56:09 +1100665STATIC void
666xfs_bmbt_init_key_from_rec(
667 union xfs_btree_key *key,
668 union xfs_btree_rec *rec)
669{
670 key->bmbt.br_startoff =
671 cpu_to_be64(xfs_bmbt_disk_get_startoff(&rec->bmbt));
672}
673
674STATIC void
Christoph Hellwig4b22a572008-10-30 16:57:40 +1100675xfs_bmbt_init_rec_from_key(
676 union xfs_btree_key *key,
677 union xfs_btree_rec *rec)
678{
679 ASSERT(key->bmbt.br_startoff != 0);
680
681 xfs_bmbt_disk_set_allf(&rec->bmbt, be64_to_cpu(key->bmbt.br_startoff),
682 0, 0, XFS_EXT_NORM);
683}
684
685STATIC void
686xfs_bmbt_init_rec_from_cur(
687 struct xfs_btree_cur *cur,
688 union xfs_btree_rec *rec)
689{
690 xfs_bmbt_disk_set_all(&rec->bmbt, &cur->bc_rec.b);
691}
692
693STATIC void
Christoph Hellwigfe033cc2008-10-30 16:56:09 +1100694xfs_bmbt_init_ptr_from_cur(
695 struct xfs_btree_cur *cur,
696 union xfs_btree_ptr *ptr)
697{
698 ptr->l = 0;
699}
700
701STATIC __int64_t
702xfs_bmbt_key_diff(
703 struct xfs_btree_cur *cur,
704 union xfs_btree_key *key)
705{
706 return (__int64_t)be64_to_cpu(key->bmbt.br_startoff) -
707 cur->bc_rec.b.br_startoff;
708}
709
Christoph Hellwig4a26e662008-10-30 16:58:32 +1100710#ifdef DEBUG
711STATIC int
712xfs_bmbt_keys_inorder(
713 struct xfs_btree_cur *cur,
714 union xfs_btree_key *k1,
715 union xfs_btree_key *k2)
716{
717 return be64_to_cpu(k1->bmbt.br_startoff) <
718 be64_to_cpu(k2->bmbt.br_startoff);
719}
720
721STATIC int
722xfs_bmbt_recs_inorder(
723 struct xfs_btree_cur *cur,
724 union xfs_btree_rec *r1,
725 union xfs_btree_rec *r2)
726{
727 return xfs_bmbt_disk_get_startoff(&r1->bmbt) +
728 xfs_bmbt_disk_get_blockcount(&r1->bmbt) <=
729 xfs_bmbt_disk_get_startoff(&r2->bmbt);
730}
731#endif /* DEBUG */
732
Christoph Hellwig561f7d12008-10-30 16:53:59 +1100733static const struct xfs_btree_ops xfs_bmbt_ops = {
Christoph Hellwig65f1eae2008-10-30 16:55:34 +1100734 .rec_len = sizeof(xfs_bmbt_rec_t),
735 .key_len = sizeof(xfs_bmbt_key_t),
736
Christoph Hellwig561f7d12008-10-30 16:53:59 +1100737 .dup_cursor = xfs_bmbt_dup_cursor,
Christoph Hellwig4b22a572008-10-30 16:57:40 +1100738 .update_cursor = xfs_bmbt_update_cursor,
Christoph Hellwigf5eb8e72008-10-30 16:57:03 +1100739 .alloc_block = xfs_bmbt_alloc_block,
Christoph Hellwigd4b3a4b2008-10-30 16:57:51 +1100740 .free_block = xfs_bmbt_free_block,
Christoph Hellwigce5e42d2008-10-30 16:55:23 +1100741 .get_maxrecs = xfs_bmbt_get_maxrecs,
Christoph Hellwig91cca5df2008-10-30 16:58:01 +1100742 .get_minrecs = xfs_bmbt_get_minrecs,
Christoph Hellwig4b22a572008-10-30 16:57:40 +1100743 .get_dmaxrecs = xfs_bmbt_get_dmaxrecs,
Christoph Hellwigfe033cc2008-10-30 16:56:09 +1100744 .init_key_from_rec = xfs_bmbt_init_key_from_rec,
Christoph Hellwig4b22a572008-10-30 16:57:40 +1100745 .init_rec_from_key = xfs_bmbt_init_rec_from_key,
746 .init_rec_from_cur = xfs_bmbt_init_rec_from_cur,
Christoph Hellwigfe033cc2008-10-30 16:56:09 +1100747 .init_ptr_from_cur = xfs_bmbt_init_ptr_from_cur,
748 .key_diff = xfs_bmbt_key_diff,
Christoph Hellwig4a26e662008-10-30 16:58:32 +1100749#ifdef DEBUG
750 .keys_inorder = xfs_bmbt_keys_inorder,
751 .recs_inorder = xfs_bmbt_recs_inorder,
752#endif
Christoph Hellwig561f7d12008-10-30 16:53:59 +1100753};
754
755/*
756 * Allocate a new bmap btree cursor.
757 */
758struct xfs_btree_cur * /* new bmap btree cursor */
759xfs_bmbt_init_cursor(
760 struct xfs_mount *mp, /* file system mount point */
761 struct xfs_trans *tp, /* transaction pointer */
762 struct xfs_inode *ip, /* inode owning the btree */
763 int whichfork) /* data or attr fork */
764{
765 struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
766 struct xfs_btree_cur *cur;
767
768 cur = kmem_zone_zalloc(xfs_btree_cur_zone, KM_SLEEP);
769
770 cur->bc_tp = tp;
771 cur->bc_mp = mp;
772 cur->bc_nlevels = be16_to_cpu(ifp->if_broot->bb_level) + 1;
773 cur->bc_btnum = XFS_BTNUM_BMAP;
774 cur->bc_blocklog = mp->m_sb.sb_blocklog;
775
776 cur->bc_ops = &xfs_bmbt_ops;
Christoph Hellwige99ab902008-10-30 16:54:33 +1100777 cur->bc_flags = XFS_BTREE_LONG_PTRS | XFS_BTREE_ROOT_IN_INODE;
Christoph Hellwig561f7d12008-10-30 16:53:59 +1100778
779 cur->bc_private.b.forksize = XFS_IFORK_SIZE(ip, whichfork);
780 cur->bc_private.b.ip = ip;
781 cur->bc_private.b.firstblock = NULLFSBLOCK;
782 cur->bc_private.b.flist = NULL;
783 cur->bc_private.b.allocated = 0;
784 cur->bc_private.b.flags = 0;
785 cur->bc_private.b.whichfork = whichfork;
786
787 return cur;
788}
Christoph Hellwig60197e82008-10-30 17:11:19 +1100789
790/*
791 * Calculate number of records in a bmap btree block.
792 */
793int
794xfs_bmbt_maxrecs(
795 struct xfs_mount *mp,
796 int blocklen,
797 int leaf)
798{
Christoph Hellwig7cc95a82008-10-30 17:14:34 +1100799 blocklen -= XFS_BMBT_BLOCK_LEN(mp);
Christoph Hellwig60197e82008-10-30 17:11:19 +1100800
801 if (leaf)
802 return blocklen / sizeof(xfs_bmbt_rec_t);
803 return blocklen / (sizeof(xfs_bmbt_key_t) + sizeof(xfs_bmbt_ptr_t));
804}
805
806/*
807 * Calculate number of records in a bmap btree inode root.
808 */
809int
810xfs_bmdr_maxrecs(
811 struct xfs_mount *mp,
812 int blocklen,
813 int leaf)
814{
815 blocklen -= sizeof(xfs_bmdr_block_t);
816
817 if (leaf)
818 return blocklen / sizeof(xfs_bmdr_rec_t);
819 return blocklen / (sizeof(xfs_bmdr_key_t) + sizeof(xfs_bmdr_ptr_t));
820}