]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/xfs_dir2_block.c
xfs: add buffer types to directory and attribute buffers
[thirdparty/xfsprogs-dev.git] / libxfs / xfs_dir2_block.c
1 /*
2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
3 * Copyright (c) 2013 Red Hat, Inc.
4 * All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it would be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <xfs.h>
21
22 /*
23 * Local function prototypes.
24 */
25 static void xfs_dir2_block_log_leaf(xfs_trans_t *tp, struct xfs_buf *bp,
26 int first, int last);
27 static void xfs_dir2_block_log_tail(xfs_trans_t *tp, struct xfs_buf *bp);
28 static int xfs_dir2_block_lookup_int(xfs_da_args_t *args, struct xfs_buf **bpp,
29 int *entno);
30 static int xfs_dir2_block_sort(const void *a, const void *b);
31
32 static xfs_dahash_t xfs_dir_hash_dot, xfs_dir_hash_dotdot;
33
34 /*
35 * One-time startup routine called from xfs_init().
36 */
37 void
38 xfs_dir_startup(void)
39 {
40 xfs_dir_hash_dot = xfs_da_hashname((unsigned char *)".", 1);
41 xfs_dir_hash_dotdot = xfs_da_hashname((unsigned char *)"..", 2);
42 }
43
44 static bool
45 xfs_dir3_block_verify(
46 struct xfs_buf *bp)
47 {
48 struct xfs_mount *mp = bp->b_target->bt_mount;
49 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
50
51 if (xfs_sb_version_hascrc(&mp->m_sb)) {
52 if (hdr3->magic != cpu_to_be32(XFS_DIR3_BLOCK_MAGIC))
53 return false;
54 if (!uuid_equal(&hdr3->uuid, &mp->m_sb.sb_uuid))
55 return false;
56 if (be64_to_cpu(hdr3->blkno) != bp->b_bn)
57 return false;
58 } else {
59 if (hdr3->magic != cpu_to_be32(XFS_DIR2_BLOCK_MAGIC))
60 return false;
61 }
62 if (__xfs_dir3_data_check(NULL, bp))
63 return false;
64 return true;
65 }
66
67 static void
68 xfs_dir3_block_read_verify(
69 struct xfs_buf *bp)
70 {
71 struct xfs_mount *mp = bp->b_target->bt_mount;
72
73 if ((xfs_sb_version_hascrc(&mp->m_sb) &&
74 !xfs_verify_cksum(bp->b_addr, BBTOB(bp->b_length),
75 XFS_DIR3_DATA_CRC_OFF)) ||
76 !xfs_dir3_block_verify(bp)) {
77 XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr);
78 xfs_buf_ioerror(bp, EFSCORRUPTED);
79 }
80 }
81
82 static void
83 xfs_dir3_block_write_verify(
84 struct xfs_buf *bp)
85 {
86 struct xfs_mount *mp = bp->b_target->bt_mount;
87 struct xfs_buf_log_item *bip = bp->b_fspriv;
88 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
89
90 if (!xfs_dir3_block_verify(bp)) {
91 XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, bp->b_addr);
92 xfs_buf_ioerror(bp, EFSCORRUPTED);
93 return;
94 }
95
96 if (!xfs_sb_version_hascrc(&mp->m_sb))
97 return;
98
99 if (bip)
100 hdr3->lsn = cpu_to_be64(bip->bli_item.li_lsn);
101
102 xfs_update_cksum(bp->b_addr, BBTOB(bp->b_length), XFS_DIR3_DATA_CRC_OFF);
103 }
104
105 const struct xfs_buf_ops xfs_dir3_block_buf_ops = {
106 .verify_read = xfs_dir3_block_read_verify,
107 .verify_write = xfs_dir3_block_write_verify,
108 };
109
110 static int
111 xfs_dir3_block_read(
112 struct xfs_trans *tp,
113 struct xfs_inode *dp,
114 struct xfs_buf **bpp)
115 {
116 struct xfs_mount *mp = dp->i_mount;
117 int err;
118
119 err = xfs_da_read_buf(tp, dp, mp->m_dirdatablk, -1, bpp,
120 XFS_DATA_FORK, &xfs_dir3_block_buf_ops);
121 if (!err && tp)
122 xfs_trans_buf_set_type(tp, *bpp, XFS_BLF_DIR_BLOCK_BUF);
123 return err;
124 }
125
126 static void
127 xfs_dir3_block_init(
128 struct xfs_mount *mp,
129 struct xfs_trans *tp,
130 struct xfs_buf *bp,
131 struct xfs_inode *dp)
132 {
133 struct xfs_dir3_blk_hdr *hdr3 = bp->b_addr;
134
135 bp->b_ops = &xfs_dir3_block_buf_ops;
136 xfs_trans_buf_set_type(tp, bp, XFS_BLF_DIR_BLOCK_BUF);
137
138 if (xfs_sb_version_hascrc(&mp->m_sb)) {
139 memset(hdr3, 0, sizeof(*hdr3));
140 hdr3->magic = cpu_to_be32(XFS_DIR3_BLOCK_MAGIC);
141 hdr3->blkno = cpu_to_be64(bp->b_bn);
142 hdr3->owner = cpu_to_be64(dp->i_ino);
143 uuid_copy(&hdr3->uuid, &mp->m_sb.sb_uuid);
144 return;
145
146 }
147 hdr3->magic = cpu_to_be32(XFS_DIR2_BLOCK_MAGIC);
148 }
149
150 static void
151 xfs_dir2_block_need_space(
152 struct xfs_dir2_data_hdr *hdr,
153 struct xfs_dir2_block_tail *btp,
154 struct xfs_dir2_leaf_entry *blp,
155 __be16 **tagpp,
156 struct xfs_dir2_data_unused **dupp,
157 struct xfs_dir2_data_unused **enddupp,
158 int *compact,
159 int len)
160 {
161 struct xfs_dir2_data_free *bf;
162 __be16 *tagp = NULL;
163 struct xfs_dir2_data_unused *dup = NULL;
164 struct xfs_dir2_data_unused *enddup = NULL;
165
166 *compact = 0;
167 bf = xfs_dir3_data_bestfree_p(hdr);
168
169 /*
170 * If there are stale entries we'll use one for the leaf.
171 */
172 if (btp->stale) {
173 if (be16_to_cpu(bf[0].length) >= len) {
174 /*
175 * The biggest entry enough to avoid compaction.
176 */
177 dup = (xfs_dir2_data_unused_t *)
178 ((char *)hdr + be16_to_cpu(bf[0].offset));
179 goto out;
180 }
181
182 /*
183 * Will need to compact to make this work.
184 * Tag just before the first leaf entry.
185 */
186 *compact = 1;
187 tagp = (__be16 *)blp - 1;
188
189 /* Data object just before the first leaf entry. */
190 dup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp));
191
192 /*
193 * If it's not free then the data will go where the
194 * leaf data starts now, if it works at all.
195 */
196 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
197 if (be16_to_cpu(dup->length) + (be32_to_cpu(btp->stale) - 1) *
198 (uint)sizeof(*blp) < len)
199 dup = NULL;
200 } else if ((be32_to_cpu(btp->stale) - 1) * (uint)sizeof(*blp) < len)
201 dup = NULL;
202 else
203 dup = (xfs_dir2_data_unused_t *)blp;
204 goto out;
205 }
206
207 /*
208 * no stale entries, so just use free space.
209 * Tag just before the first leaf entry.
210 */
211 tagp = (__be16 *)blp - 1;
212
213 /* Data object just before the first leaf entry. */
214 enddup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp));
215
216 /*
217 * If it's not free then can't do this add without cleaning up:
218 * the space before the first leaf entry needs to be free so it
219 * can be expanded to hold the pointer to the new entry.
220 */
221 if (be16_to_cpu(enddup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
222 /*
223 * Check out the biggest freespace and see if it's the same one.
224 */
225 dup = (xfs_dir2_data_unused_t *)
226 ((char *)hdr + be16_to_cpu(bf[0].offset));
227 if (dup != enddup) {
228 /*
229 * Not the same free entry, just check its length.
230 */
231 if (be16_to_cpu(dup->length) < len)
232 dup = NULL;
233 goto out;
234 }
235
236 /*
237 * It is the biggest freespace, can it hold the leaf too?
238 */
239 if (be16_to_cpu(dup->length) < len + (uint)sizeof(*blp)) {
240 /*
241 * Yes, use the second-largest entry instead if it works.
242 */
243 if (be16_to_cpu(bf[1].length) >= len)
244 dup = (xfs_dir2_data_unused_t *)
245 ((char *)hdr + be16_to_cpu(bf[1].offset));
246 else
247 dup = NULL;
248 }
249 }
250 out:
251 *tagpp = tagp;
252 *dupp = dup;
253 *enddupp = enddup;
254 }
255
256 /*
257 * compact the leaf entries.
258 * Leave the highest-numbered stale entry stale.
259 * XXX should be the one closest to mid but mid is not yet computed.
260 */
261 static void
262 xfs_dir2_block_compact(
263 struct xfs_trans *tp,
264 struct xfs_buf *bp,
265 struct xfs_dir2_data_hdr *hdr,
266 struct xfs_dir2_block_tail *btp,
267 struct xfs_dir2_leaf_entry *blp,
268 int *needlog,
269 int *lfloghigh,
270 int *lfloglow)
271 {
272 int fromidx; /* source leaf index */
273 int toidx; /* target leaf index */
274 int needscan = 0;
275 int highstale; /* high stale index */
276
277 fromidx = toidx = be32_to_cpu(btp->count) - 1;
278 highstale = *lfloghigh = -1;
279 for (; fromidx >= 0; fromidx--) {
280 if (blp[fromidx].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR)) {
281 if (highstale == -1)
282 highstale = toidx;
283 else {
284 if (*lfloghigh == -1)
285 *lfloghigh = toidx;
286 continue;
287 }
288 }
289 if (fromidx < toidx)
290 blp[toidx] = blp[fromidx];
291 toidx--;
292 }
293 *lfloglow = toidx + 1 - (be32_to_cpu(btp->stale) - 1);
294 *lfloghigh -= be32_to_cpu(btp->stale) - 1;
295 be32_add_cpu(&btp->count, -(be32_to_cpu(btp->stale) - 1));
296 xfs_dir2_data_make_free(tp, bp,
297 (xfs_dir2_data_aoff_t)((char *)blp - (char *)hdr),
298 (xfs_dir2_data_aoff_t)((be32_to_cpu(btp->stale) - 1) * sizeof(*blp)),
299 needlog, &needscan);
300 blp += be32_to_cpu(btp->stale) - 1;
301 btp->stale = cpu_to_be32(1);
302 /*
303 * If we now need to rebuild the bestfree map, do so.
304 * This needs to happen before the next call to use_free.
305 */
306 if (needscan)
307 xfs_dir2_data_freescan(tp->t_mountp, hdr, needlog);
308 }
309
310 /*
311 * Add an entry to a block directory.
312 */
313 int /* error */
314 xfs_dir2_block_addname(
315 xfs_da_args_t *args) /* directory op arguments */
316 {
317 xfs_dir2_data_hdr_t *hdr; /* block header */
318 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
319 struct xfs_buf *bp; /* buffer for block */
320 xfs_dir2_block_tail_t *btp; /* block tail */
321 int compact; /* need to compact leaf ents */
322 xfs_dir2_data_entry_t *dep; /* block data entry */
323 xfs_inode_t *dp; /* directory inode */
324 xfs_dir2_data_unused_t *dup; /* block unused entry */
325 int error; /* error return value */
326 xfs_dir2_data_unused_t *enddup=NULL; /* unused at end of data */
327 xfs_dahash_t hash; /* hash value of found entry */
328 int high; /* high index for binary srch */
329 int highstale; /* high stale index */
330 int lfloghigh=0; /* last final leaf to log */
331 int lfloglow=0; /* first final leaf to log */
332 int len; /* length of the new entry */
333 int low; /* low index for binary srch */
334 int lowstale; /* low stale index */
335 int mid=0; /* midpoint for binary srch */
336 xfs_mount_t *mp; /* filesystem mount point */
337 int needlog; /* need to log header */
338 int needscan; /* need to rescan freespace */
339 __be16 *tagp; /* pointer to tag value */
340 xfs_trans_t *tp; /* transaction structure */
341
342 trace_xfs_dir2_block_addname(args);
343
344 dp = args->dp;
345 tp = args->trans;
346 mp = dp->i_mount;
347
348 /* Read the (one and only) directory block into bp. */
349 error = xfs_dir3_block_read(tp, dp, &bp);
350 if (error)
351 return error;
352
353 len = xfs_dir2_data_entsize(args->namelen);
354
355 /*
356 * Set up pointers to parts of the block.
357 */
358 hdr = bp->b_addr;
359 btp = xfs_dir2_block_tail_p(mp, hdr);
360 blp = xfs_dir2_block_leaf_p(btp);
361
362 /*
363 * Find out if we can reuse stale entries or whether we need extra
364 * space for entry and new leaf.
365 */
366 xfs_dir2_block_need_space(hdr, btp, blp, &tagp, &dup,
367 &enddup, &compact, len);
368
369 /*
370 * Done everything we need for a space check now.
371 */
372 if (args->op_flags & XFS_DA_OP_JUSTCHECK) {
373 xfs_trans_brelse(tp, bp);
374 if (!dup)
375 return XFS_ERROR(ENOSPC);
376 return 0;
377 }
378
379 /*
380 * If we don't have space for the new entry & leaf ...
381 */
382 if (!dup) {
383 /* Don't have a space reservation: return no-space. */
384 if (args->total == 0)
385 return XFS_ERROR(ENOSPC);
386 /*
387 * Convert to the next larger format.
388 * Then add the new entry in that format.
389 */
390 error = xfs_dir2_block_to_leaf(args, bp);
391 if (error)
392 return error;
393 return xfs_dir2_leaf_addname(args);
394 }
395
396 needlog = needscan = 0;
397
398 /*
399 * If need to compact the leaf entries, do it now.
400 */
401 if (compact) {
402 xfs_dir2_block_compact(tp, bp, hdr, btp, blp, &needlog,
403 &lfloghigh, &lfloglow);
404 /* recalculate blp post-compaction */
405 blp = xfs_dir2_block_leaf_p(btp);
406 } else if (btp->stale) {
407 /*
408 * Set leaf logging boundaries to impossible state.
409 * For the no-stale case they're set explicitly.
410 */
411 lfloglow = be32_to_cpu(btp->count);
412 lfloghigh = -1;
413 }
414
415 /*
416 * Find the slot that's first lower than our hash value, -1 if none.
417 */
418 for (low = 0, high = be32_to_cpu(btp->count) - 1; low <= high; ) {
419 mid = (low + high) >> 1;
420 if ((hash = be32_to_cpu(blp[mid].hashval)) == args->hashval)
421 break;
422 if (hash < args->hashval)
423 low = mid + 1;
424 else
425 high = mid - 1;
426 }
427 while (mid >= 0 && be32_to_cpu(blp[mid].hashval) >= args->hashval) {
428 mid--;
429 }
430 /*
431 * No stale entries, will use enddup space to hold new leaf.
432 */
433 if (!btp->stale) {
434 /*
435 * Mark the space needed for the new leaf entry, now in use.
436 */
437 xfs_dir2_data_use_free(tp, bp, enddup,
438 (xfs_dir2_data_aoff_t)
439 ((char *)enddup - (char *)hdr + be16_to_cpu(enddup->length) -
440 sizeof(*blp)),
441 (xfs_dir2_data_aoff_t)sizeof(*blp),
442 &needlog, &needscan);
443 /*
444 * Update the tail (entry count).
445 */
446 be32_add_cpu(&btp->count, 1);
447 /*
448 * If we now need to rebuild the bestfree map, do so.
449 * This needs to happen before the next call to use_free.
450 */
451 if (needscan) {
452 xfs_dir2_data_freescan(mp, hdr, &needlog);
453 needscan = 0;
454 }
455 /*
456 * Adjust pointer to the first leaf entry, we're about to move
457 * the table up one to open up space for the new leaf entry.
458 * Then adjust our index to match.
459 */
460 blp--;
461 mid++;
462 if (mid)
463 memmove(blp, &blp[1], mid * sizeof(*blp));
464 lfloglow = 0;
465 lfloghigh = mid;
466 }
467 /*
468 * Use a stale leaf for our new entry.
469 */
470 else {
471 for (lowstale = mid;
472 lowstale >= 0 &&
473 blp[lowstale].address !=
474 cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
475 lowstale--)
476 continue;
477 for (highstale = mid + 1;
478 highstale < be32_to_cpu(btp->count) &&
479 blp[highstale].address !=
480 cpu_to_be32(XFS_DIR2_NULL_DATAPTR) &&
481 (lowstale < 0 || mid - lowstale > highstale - mid);
482 highstale++)
483 continue;
484 /*
485 * Move entries toward the low-numbered stale entry.
486 */
487 if (lowstale >= 0 &&
488 (highstale == be32_to_cpu(btp->count) ||
489 mid - lowstale <= highstale - mid)) {
490 if (mid - lowstale)
491 memmove(&blp[lowstale], &blp[lowstale + 1],
492 (mid - lowstale) * sizeof(*blp));
493 lfloglow = MIN(lowstale, lfloglow);
494 lfloghigh = MAX(mid, lfloghigh);
495 }
496 /*
497 * Move entries toward the high-numbered stale entry.
498 */
499 else {
500 ASSERT(highstale < be32_to_cpu(btp->count));
501 mid++;
502 if (highstale - mid)
503 memmove(&blp[mid + 1], &blp[mid],
504 (highstale - mid) * sizeof(*blp));
505 lfloglow = MIN(mid, lfloglow);
506 lfloghigh = MAX(highstale, lfloghigh);
507 }
508 be32_add_cpu(&btp->stale, -1);
509 }
510 /*
511 * Point to the new data entry.
512 */
513 dep = (xfs_dir2_data_entry_t *)dup;
514 /*
515 * Fill in the leaf entry.
516 */
517 blp[mid].hashval = cpu_to_be32(args->hashval);
518 blp[mid].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
519 (char *)dep - (char *)hdr));
520 xfs_dir2_block_log_leaf(tp, bp, lfloglow, lfloghigh);
521 /*
522 * Mark space for the data entry used.
523 */
524 xfs_dir2_data_use_free(tp, bp, dup,
525 (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr),
526 (xfs_dir2_data_aoff_t)len, &needlog, &needscan);
527 /*
528 * Create the new data entry.
529 */
530 dep->inumber = cpu_to_be64(args->inumber);
531 dep->namelen = args->namelen;
532 memcpy(dep->name, args->name, args->namelen);
533 tagp = xfs_dir2_data_entry_tag_p(dep);
534 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
535 /*
536 * Clean up the bestfree array and log the header, tail, and entry.
537 */
538 if (needscan)
539 xfs_dir2_data_freescan(mp, hdr, &needlog);
540 if (needlog)
541 xfs_dir2_data_log_header(tp, bp);
542 xfs_dir2_block_log_tail(tp, bp);
543 xfs_dir2_data_log_entry(tp, bp, dep);
544 xfs_dir3_data_check(dp, bp);
545 return 0;
546 }
547
548 /*
549 * Log leaf entries from the block.
550 */
551 static void
552 xfs_dir2_block_log_leaf(
553 xfs_trans_t *tp, /* transaction structure */
554 struct xfs_buf *bp, /* block buffer */
555 int first, /* index of first logged leaf */
556 int last) /* index of last logged leaf */
557 {
558 xfs_dir2_data_hdr_t *hdr = bp->b_addr;
559 xfs_dir2_leaf_entry_t *blp;
560 xfs_dir2_block_tail_t *btp;
561
562 btp = xfs_dir2_block_tail_p(tp->t_mountp, hdr);
563 blp = xfs_dir2_block_leaf_p(btp);
564 xfs_trans_log_buf(tp, bp, (uint)((char *)&blp[first] - (char *)hdr),
565 (uint)((char *)&blp[last + 1] - (char *)hdr - 1));
566 }
567
568 /*
569 * Log the block tail.
570 */
571 static void
572 xfs_dir2_block_log_tail(
573 xfs_trans_t *tp, /* transaction structure */
574 struct xfs_buf *bp) /* block buffer */
575 {
576 xfs_dir2_data_hdr_t *hdr = bp->b_addr;
577 xfs_dir2_block_tail_t *btp;
578
579 btp = xfs_dir2_block_tail_p(tp->t_mountp, hdr);
580 xfs_trans_log_buf(tp, bp, (uint)((char *)btp - (char *)hdr),
581 (uint)((char *)(btp + 1) - (char *)hdr - 1));
582 }
583
584 /*
585 * Look up an entry in the block. This is the external routine,
586 * xfs_dir2_block_lookup_int does the real work.
587 */
588 int /* error */
589 xfs_dir2_block_lookup(
590 xfs_da_args_t *args) /* dir lookup arguments */
591 {
592 xfs_dir2_data_hdr_t *hdr; /* block header */
593 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
594 struct xfs_buf *bp; /* block buffer */
595 xfs_dir2_block_tail_t *btp; /* block tail */
596 xfs_dir2_data_entry_t *dep; /* block data entry */
597 xfs_inode_t *dp; /* incore inode */
598 int ent; /* entry index */
599 int error; /* error return value */
600 xfs_mount_t *mp; /* filesystem mount point */
601
602 trace_xfs_dir2_block_lookup(args);
603
604 /*
605 * Get the buffer, look up the entry.
606 * If not found (ENOENT) then return, have no buffer.
607 */
608 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent)))
609 return error;
610 dp = args->dp;
611 mp = dp->i_mount;
612 hdr = bp->b_addr;
613 xfs_dir3_data_check(dp, bp);
614 btp = xfs_dir2_block_tail_p(mp, hdr);
615 blp = xfs_dir2_block_leaf_p(btp);
616 /*
617 * Get the offset from the leaf entry, to point to the data.
618 */
619 dep = (xfs_dir2_data_entry_t *)((char *)hdr +
620 xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
621 /*
622 * Fill in inode number, CI name if appropriate, release the block.
623 */
624 args->inumber = be64_to_cpu(dep->inumber);
625 error = xfs_dir_cilookup_result(args, dep->name, dep->namelen);
626 xfs_trans_brelse(args->trans, bp);
627 return XFS_ERROR(error);
628 }
629
630 /*
631 * Internal block lookup routine.
632 */
633 static int /* error */
634 xfs_dir2_block_lookup_int(
635 xfs_da_args_t *args, /* dir lookup arguments */
636 struct xfs_buf **bpp, /* returned block buffer */
637 int *entno) /* returned entry number */
638 {
639 xfs_dir2_dataptr_t addr; /* data entry address */
640 xfs_dir2_data_hdr_t *hdr; /* block header */
641 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
642 struct xfs_buf *bp; /* block buffer */
643 xfs_dir2_block_tail_t *btp; /* block tail */
644 xfs_dir2_data_entry_t *dep; /* block data entry */
645 xfs_inode_t *dp; /* incore inode */
646 int error; /* error return value */
647 xfs_dahash_t hash; /* found hash value */
648 int high; /* binary search high index */
649 int low; /* binary search low index */
650 int mid; /* binary search current idx */
651 xfs_mount_t *mp; /* filesystem mount point */
652 xfs_trans_t *tp; /* transaction pointer */
653 enum xfs_dacmp cmp; /* comparison result */
654
655 dp = args->dp;
656 tp = args->trans;
657 mp = dp->i_mount;
658
659 error = xfs_dir3_block_read(tp, dp, &bp);
660 if (error)
661 return error;
662
663 hdr = bp->b_addr;
664 xfs_dir3_data_check(dp, bp);
665 btp = xfs_dir2_block_tail_p(mp, hdr);
666 blp = xfs_dir2_block_leaf_p(btp);
667 /*
668 * Loop doing a binary search for our hash value.
669 * Find our entry, ENOENT if it's not there.
670 */
671 for (low = 0, high = be32_to_cpu(btp->count) - 1; ; ) {
672 ASSERT(low <= high);
673 mid = (low + high) >> 1;
674 if ((hash = be32_to_cpu(blp[mid].hashval)) == args->hashval)
675 break;
676 if (hash < args->hashval)
677 low = mid + 1;
678 else
679 high = mid - 1;
680 if (low > high) {
681 ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);
682 xfs_trans_brelse(tp, bp);
683 return XFS_ERROR(ENOENT);
684 }
685 }
686 /*
687 * Back up to the first one with the right hash value.
688 */
689 while (mid > 0 && be32_to_cpu(blp[mid - 1].hashval) == args->hashval) {
690 mid--;
691 }
692 /*
693 * Now loop forward through all the entries with the
694 * right hash value looking for our name.
695 */
696 do {
697 if ((addr = be32_to_cpu(blp[mid].address)) == XFS_DIR2_NULL_DATAPTR)
698 continue;
699 /*
700 * Get pointer to the entry from the leaf.
701 */
702 dep = (xfs_dir2_data_entry_t *)
703 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, addr));
704 /*
705 * Compare name and if it's an exact match, return the index
706 * and buffer. If it's the first case-insensitive match, store
707 * the index and buffer and continue looking for an exact match.
708 */
709 cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen);
710 if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
711 args->cmpresult = cmp;
712 *bpp = bp;
713 *entno = mid;
714 if (cmp == XFS_CMP_EXACT)
715 return 0;
716 }
717 } while (++mid < be32_to_cpu(btp->count) &&
718 be32_to_cpu(blp[mid].hashval) == hash);
719
720 ASSERT(args->op_flags & XFS_DA_OP_OKNOENT);
721 /*
722 * Here, we can only be doing a lookup (not a rename or replace).
723 * If a case-insensitive match was found earlier, return success.
724 */
725 if (args->cmpresult == XFS_CMP_CASE)
726 return 0;
727 /*
728 * No match, release the buffer and return ENOENT.
729 */
730 xfs_trans_brelse(tp, bp);
731 return XFS_ERROR(ENOENT);
732 }
733
734 /*
735 * Remove an entry from a block format directory.
736 * If that makes the block small enough to fit in shortform, transform it.
737 */
738 int /* error */
739 xfs_dir2_block_removename(
740 xfs_da_args_t *args) /* directory operation args */
741 {
742 xfs_dir2_data_hdr_t *hdr; /* block header */
743 xfs_dir2_leaf_entry_t *blp; /* block leaf pointer */
744 struct xfs_buf *bp; /* block buffer */
745 xfs_dir2_block_tail_t *btp; /* block tail */
746 xfs_dir2_data_entry_t *dep; /* block data entry */
747 xfs_inode_t *dp; /* incore inode */
748 int ent; /* block leaf entry index */
749 int error; /* error return value */
750 xfs_mount_t *mp; /* filesystem mount point */
751 int needlog; /* need to log block header */
752 int needscan; /* need to fixup bestfree */
753 xfs_dir2_sf_hdr_t sfh; /* shortform header */
754 int size; /* shortform size */
755 xfs_trans_t *tp; /* transaction pointer */
756
757 trace_xfs_dir2_block_removename(args);
758
759 /*
760 * Look up the entry in the block. Gets the buffer and entry index.
761 * It will always be there, the vnodeops level does a lookup first.
762 */
763 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent))) {
764 return error;
765 }
766 dp = args->dp;
767 tp = args->trans;
768 mp = dp->i_mount;
769 hdr = bp->b_addr;
770 btp = xfs_dir2_block_tail_p(mp, hdr);
771 blp = xfs_dir2_block_leaf_p(btp);
772 /*
773 * Point to the data entry using the leaf entry.
774 */
775 dep = (xfs_dir2_data_entry_t *)
776 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
777 /*
778 * Mark the data entry's space free.
779 */
780 needlog = needscan = 0;
781 xfs_dir2_data_make_free(tp, bp,
782 (xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
783 xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan);
784 /*
785 * Fix up the block tail.
786 */
787 be32_add_cpu(&btp->stale, 1);
788 xfs_dir2_block_log_tail(tp, bp);
789 /*
790 * Remove the leaf entry by marking it stale.
791 */
792 blp[ent].address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
793 xfs_dir2_block_log_leaf(tp, bp, ent, ent);
794 /*
795 * Fix up bestfree, log the header if necessary.
796 */
797 if (needscan)
798 xfs_dir2_data_freescan(mp, hdr, &needlog);
799 if (needlog)
800 xfs_dir2_data_log_header(tp, bp);
801 xfs_dir3_data_check(dp, bp);
802 /*
803 * See if the size as a shortform is good enough.
804 */
805 size = xfs_dir2_block_sfsize(dp, hdr, &sfh);
806 if (size > XFS_IFORK_DSIZE(dp))
807 return 0;
808
809 /*
810 * If it works, do the conversion.
811 */
812 return xfs_dir2_block_to_sf(args, bp, size, &sfh);
813 }
814
815 /*
816 * Replace an entry in a V2 block directory.
817 * Change the inode number to the new value.
818 */
819 int /* error */
820 xfs_dir2_block_replace(
821 xfs_da_args_t *args) /* directory operation args */
822 {
823 xfs_dir2_data_hdr_t *hdr; /* block header */
824 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
825 struct xfs_buf *bp; /* block buffer */
826 xfs_dir2_block_tail_t *btp; /* block tail */
827 xfs_dir2_data_entry_t *dep; /* block data entry */
828 xfs_inode_t *dp; /* incore inode */
829 int ent; /* leaf entry index */
830 int error; /* error return value */
831 xfs_mount_t *mp; /* filesystem mount point */
832
833 trace_xfs_dir2_block_replace(args);
834
835 /*
836 * Lookup the entry in the directory. Get buffer and entry index.
837 * This will always succeed since the caller has already done a lookup.
838 */
839 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent))) {
840 return error;
841 }
842 dp = args->dp;
843 mp = dp->i_mount;
844 hdr = bp->b_addr;
845 btp = xfs_dir2_block_tail_p(mp, hdr);
846 blp = xfs_dir2_block_leaf_p(btp);
847 /*
848 * Point to the data entry we need to change.
849 */
850 dep = (xfs_dir2_data_entry_t *)
851 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
852 ASSERT(be64_to_cpu(dep->inumber) != args->inumber);
853 /*
854 * Change the inode number to the new value.
855 */
856 dep->inumber = cpu_to_be64(args->inumber);
857 xfs_dir2_data_log_entry(args->trans, bp, dep);
858 xfs_dir3_data_check(dp, bp);
859 return 0;
860 }
861
862 /*
863 * Qsort comparison routine for the block leaf entries.
864 */
865 static int /* sort order */
866 xfs_dir2_block_sort(
867 const void *a, /* first leaf entry */
868 const void *b) /* second leaf entry */
869 {
870 const xfs_dir2_leaf_entry_t *la; /* first leaf entry */
871 const xfs_dir2_leaf_entry_t *lb; /* second leaf entry */
872
873 la = a;
874 lb = b;
875 return be32_to_cpu(la->hashval) < be32_to_cpu(lb->hashval) ? -1 :
876 (be32_to_cpu(la->hashval) > be32_to_cpu(lb->hashval) ? 1 : 0);
877 }
878
879 /*
880 * Convert a V2 leaf directory to a V2 block directory if possible.
881 */
882 int /* error */
883 xfs_dir2_leaf_to_block(
884 xfs_da_args_t *args, /* operation arguments */
885 struct xfs_buf *lbp, /* leaf buffer */
886 struct xfs_buf *dbp) /* data buffer */
887 {
888 __be16 *bestsp; /* leaf bests table */
889 xfs_dir2_data_hdr_t *hdr; /* block header */
890 xfs_dir2_block_tail_t *btp; /* block tail */
891 xfs_inode_t *dp; /* incore directory inode */
892 xfs_dir2_data_unused_t *dup; /* unused data entry */
893 int error; /* error return value */
894 int from; /* leaf from index */
895 xfs_dir2_leaf_t *leaf; /* leaf structure */
896 xfs_dir2_leaf_entry_t *lep; /* leaf entry */
897 xfs_dir2_leaf_tail_t *ltp; /* leaf tail structure */
898 xfs_mount_t *mp; /* file system mount point */
899 int needlog; /* need to log data header */
900 int needscan; /* need to scan for bestfree */
901 xfs_dir2_sf_hdr_t sfh; /* shortform header */
902 int size; /* bytes used */
903 __be16 *tagp; /* end of entry (tag) */
904 int to; /* block/leaf to index */
905 xfs_trans_t *tp; /* transaction pointer */
906 struct xfs_dir2_leaf_entry *ents;
907 struct xfs_dir3_icleaf_hdr leafhdr;
908
909 trace_xfs_dir2_leaf_to_block(args);
910
911 dp = args->dp;
912 tp = args->trans;
913 mp = dp->i_mount;
914 leaf = lbp->b_addr;
915 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf);
916 ents = xfs_dir3_leaf_ents_p(leaf);
917 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
918
919 ASSERT(leafhdr.magic == XFS_DIR2_LEAF1_MAGIC ||
920 leafhdr.magic == XFS_DIR3_LEAF1_MAGIC);
921 /*
922 * If there are data blocks other than the first one, take this
923 * opportunity to remove trailing empty data blocks that may have
924 * been left behind during no-space-reservation operations.
925 * These will show up in the leaf bests table.
926 */
927 while (dp->i_d.di_size > mp->m_dirblksize) {
928 int hdrsz;
929
930 hdrsz = xfs_dir3_data_hdr_size(xfs_sb_version_hascrc(&mp->m_sb));
931 bestsp = xfs_dir2_leaf_bests_p(ltp);
932 if (be16_to_cpu(bestsp[be32_to_cpu(ltp->bestcount) - 1]) ==
933 mp->m_dirblksize - hdrsz) {
934 if ((error =
935 xfs_dir2_leaf_trim_data(args, lbp,
936 (xfs_dir2_db_t)(be32_to_cpu(ltp->bestcount) - 1))))
937 return error;
938 } else
939 return 0;
940 }
941 /*
942 * Read the data block if we don't already have it, give up if it fails.
943 */
944 if (!dbp) {
945 error = xfs_dir3_data_read(tp, dp, mp->m_dirdatablk, -1, &dbp);
946 if (error)
947 return error;
948 }
949 hdr = dbp->b_addr;
950 ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
951 hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC));
952
953 /*
954 * Size of the "leaf" area in the block.
955 */
956 size = (uint)sizeof(xfs_dir2_block_tail_t) +
957 (uint)sizeof(*lep) * (leafhdr.count - leafhdr.stale);
958 /*
959 * Look at the last data entry.
960 */
961 tagp = (__be16 *)((char *)hdr + mp->m_dirblksize) - 1;
962 dup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp));
963 /*
964 * If it's not free or is too short we can't do it.
965 */
966 if (be16_to_cpu(dup->freetag) != XFS_DIR2_DATA_FREE_TAG ||
967 be16_to_cpu(dup->length) < size)
968 return 0;
969
970 /*
971 * Start converting it to block form.
972 */
973 xfs_dir3_block_init(mp, tp, dbp, dp);
974
975 needlog = 1;
976 needscan = 0;
977 /*
978 * Use up the space at the end of the block (blp/btp).
979 */
980 xfs_dir2_data_use_free(tp, dbp, dup, mp->m_dirblksize - size, size,
981 &needlog, &needscan);
982 /*
983 * Initialize the block tail.
984 */
985 btp = xfs_dir2_block_tail_p(mp, hdr);
986 btp->count = cpu_to_be32(leafhdr.count - leafhdr.stale);
987 btp->stale = 0;
988 xfs_dir2_block_log_tail(tp, dbp);
989 /*
990 * Initialize the block leaf area. We compact out stale entries.
991 */
992 lep = xfs_dir2_block_leaf_p(btp);
993 for (from = to = 0; from < leafhdr.count; from++) {
994 if (ents[from].address == cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
995 continue;
996 lep[to++] = ents[from];
997 }
998 ASSERT(to == be32_to_cpu(btp->count));
999 xfs_dir2_block_log_leaf(tp, dbp, 0, be32_to_cpu(btp->count) - 1);
1000 /*
1001 * Scan the bestfree if we need it and log the data block header.
1002 */
1003 if (needscan)
1004 xfs_dir2_data_freescan(mp, hdr, &needlog);
1005 if (needlog)
1006 xfs_dir2_data_log_header(tp, dbp);
1007 /*
1008 * Pitch the old leaf block.
1009 */
1010 error = xfs_da_shrink_inode(args, mp->m_dirleafblk, lbp);
1011 if (error)
1012 return error;
1013
1014 /*
1015 * Now see if the resulting block can be shrunken to shortform.
1016 */
1017 size = xfs_dir2_block_sfsize(dp, hdr, &sfh);
1018 if (size > XFS_IFORK_DSIZE(dp))
1019 return 0;
1020
1021 return xfs_dir2_block_to_sf(args, dbp, size, &sfh);
1022 }
1023
1024 /*
1025 * Convert the shortform directory to block form.
1026 */
1027 int /* error */
1028 xfs_dir2_sf_to_block(
1029 xfs_da_args_t *args) /* operation arguments */
1030 {
1031 xfs_dir2_db_t blkno; /* dir-relative block # (0) */
1032 xfs_dir2_data_hdr_t *hdr; /* block header */
1033 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
1034 struct xfs_buf *bp; /* block buffer */
1035 xfs_dir2_block_tail_t *btp; /* block tail pointer */
1036 xfs_dir2_data_entry_t *dep; /* data entry pointer */
1037 xfs_inode_t *dp; /* incore directory inode */
1038 int dummy; /* trash */
1039 xfs_dir2_data_unused_t *dup; /* unused entry pointer */
1040 int endoffset; /* end of data objects */
1041 int error; /* error return value */
1042 int i; /* index */
1043 xfs_mount_t *mp; /* filesystem mount point */
1044 int needlog; /* need to log block header */
1045 int needscan; /* need to scan block freespc */
1046 int newoffset; /* offset from current entry */
1047 int offset; /* target block offset */
1048 xfs_dir2_sf_entry_t *sfep; /* sf entry pointer */
1049 xfs_dir2_sf_hdr_t *oldsfp; /* old shortform header */
1050 xfs_dir2_sf_hdr_t *sfp; /* shortform header */
1051 __be16 *tagp; /* end of data entry */
1052 xfs_trans_t *tp; /* transaction pointer */
1053 struct xfs_name name;
1054
1055 trace_xfs_dir2_sf_to_block(args);
1056
1057 dp = args->dp;
1058 tp = args->trans;
1059 mp = dp->i_mount;
1060 ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
1061 /*
1062 * Bomb out if the shortform directory is way too short.
1063 */
1064 if (dp->i_d.di_size < offsetof(xfs_dir2_sf_hdr_t, parent)) {
1065 ASSERT(XFS_FORCED_SHUTDOWN(mp));
1066 return XFS_ERROR(EIO);
1067 }
1068
1069 oldsfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
1070
1071 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
1072 ASSERT(dp->i_df.if_u1.if_data != NULL);
1073 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(oldsfp->i8count));
1074
1075 /*
1076 * Copy the directory into a temporary buffer.
1077 * Then pitch the incore inode data so we can make extents.
1078 */
1079 sfp = kmem_alloc(dp->i_df.if_bytes, KM_SLEEP);
1080 memcpy(sfp, oldsfp, dp->i_df.if_bytes);
1081
1082 xfs_idata_realloc(dp, -dp->i_df.if_bytes, XFS_DATA_FORK);
1083 dp->i_d.di_size = 0;
1084 xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
1085
1086 /*
1087 * Add block 0 to the inode.
1088 */
1089 error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, &blkno);
1090 if (error) {
1091 kmem_free(sfp);
1092 return error;
1093 }
1094 /*
1095 * Initialize the data block, then convert it to block format.
1096 */
1097 error = xfs_dir3_data_init(args, blkno, &bp);
1098 if (error) {
1099 kmem_free(sfp);
1100 return error;
1101 }
1102 xfs_dir3_block_init(mp, tp, bp, dp);
1103 hdr = bp->b_addr;
1104
1105 /*
1106 * Compute size of block "tail" area.
1107 */
1108 i = (uint)sizeof(*btp) +
1109 (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t);
1110 /*
1111 * The whole thing is initialized to free by the init routine.
1112 * Say we're using the leaf and tail area.
1113 */
1114 dup = xfs_dir3_data_unused_p(hdr);
1115 needlog = needscan = 0;
1116 xfs_dir2_data_use_free(tp, bp, dup, mp->m_dirblksize - i, i, &needlog,
1117 &needscan);
1118 ASSERT(needscan == 0);
1119 /*
1120 * Fill in the tail.
1121 */
1122 btp = xfs_dir2_block_tail_p(mp, hdr);
1123 btp->count = cpu_to_be32(sfp->count + 2); /* ., .. */
1124 btp->stale = 0;
1125 blp = xfs_dir2_block_leaf_p(btp);
1126 endoffset = (uint)((char *)blp - (char *)hdr);
1127 /*
1128 * Remove the freespace, we'll manage it.
1129 */
1130 xfs_dir2_data_use_free(tp, bp, dup,
1131 (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr),
1132 be16_to_cpu(dup->length), &needlog, &needscan);
1133 /*
1134 * Create entry for .
1135 */
1136 dep = xfs_dir3_data_dot_entry_p(hdr);
1137 dep->inumber = cpu_to_be64(dp->i_ino);
1138 dep->namelen = 1;
1139 dep->name[0] = '.';
1140 tagp = xfs_dir2_data_entry_tag_p(dep);
1141 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
1142 xfs_dir2_data_log_entry(tp, bp, dep);
1143 blp[0].hashval = cpu_to_be32(xfs_dir_hash_dot);
1144 blp[0].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
1145 (char *)dep - (char *)hdr));
1146 /*
1147 * Create entry for ..
1148 */
1149 dep = xfs_dir3_data_dotdot_entry_p(hdr);
1150 dep->inumber = cpu_to_be64(xfs_dir2_sf_get_parent_ino(sfp));
1151 dep->namelen = 2;
1152 dep->name[0] = dep->name[1] = '.';
1153 tagp = xfs_dir2_data_entry_tag_p(dep);
1154 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
1155 xfs_dir2_data_log_entry(tp, bp, dep);
1156 blp[1].hashval = cpu_to_be32(xfs_dir_hash_dotdot);
1157 blp[1].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
1158 (char *)dep - (char *)hdr));
1159 offset = xfs_dir3_data_first_offset(hdr);
1160 /*
1161 * Loop over existing entries, stuff them in.
1162 */
1163 i = 0;
1164 if (!sfp->count)
1165 sfep = NULL;
1166 else
1167 sfep = xfs_dir2_sf_firstentry(sfp);
1168 /*
1169 * Need to preserve the existing offset values in the sf directory.
1170 * Insert holes (unused entries) where necessary.
1171 */
1172 while (offset < endoffset) {
1173 /*
1174 * sfep is null when we reach the end of the list.
1175 */
1176 if (sfep == NULL)
1177 newoffset = endoffset;
1178 else
1179 newoffset = xfs_dir2_sf_get_offset(sfep);
1180 /*
1181 * There should be a hole here, make one.
1182 */
1183 if (offset < newoffset) {
1184 dup = (xfs_dir2_data_unused_t *)((char *)hdr + offset);
1185 dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
1186 dup->length = cpu_to_be16(newoffset - offset);
1187 *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(
1188 ((char *)dup - (char *)hdr));
1189 xfs_dir2_data_log_unused(tp, bp, dup);
1190 xfs_dir2_data_freeinsert(hdr, dup, &dummy);
1191 offset += be16_to_cpu(dup->length);
1192 continue;
1193 }
1194 /*
1195 * Copy a real entry.
1196 */
1197 dep = (xfs_dir2_data_entry_t *)((char *)hdr + newoffset);
1198 dep->inumber = cpu_to_be64(xfs_dir2_sfe_get_ino(sfp, sfep));
1199 dep->namelen = sfep->namelen;
1200 memcpy(dep->name, sfep->name, dep->namelen);
1201 tagp = xfs_dir2_data_entry_tag_p(dep);
1202 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
1203 xfs_dir2_data_log_entry(tp, bp, dep);
1204 name.name = sfep->name;
1205 name.len = sfep->namelen;
1206 blp[2 + i].hashval = cpu_to_be32(mp->m_dirnameops->
1207 hashname(&name));
1208 blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
1209 (char *)dep - (char *)hdr));
1210 offset = (int)((char *)(tagp + 1) - (char *)hdr);
1211 if (++i == sfp->count)
1212 sfep = NULL;
1213 else
1214 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
1215 }
1216 /* Done with the temporary buffer */
1217 kmem_free(sfp);
1218 /*
1219 * Sort the leaf entries by hash value.
1220 */
1221 xfs_sort(blp, be32_to_cpu(btp->count), sizeof(*blp), xfs_dir2_block_sort);
1222 /*
1223 * Log the leaf entry area and tail.
1224 * Already logged the header in data_init, ignore needlog.
1225 */
1226 ASSERT(needscan == 0);
1227 xfs_dir2_block_log_leaf(tp, bp, 0, be32_to_cpu(btp->count) - 1);
1228 xfs_dir2_block_log_tail(tp, bp);
1229 xfs_dir3_data_check(dp, bp);
1230 return 0;
1231 }