aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_block.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2011-07-08 08:35:27 -0400
committerChristoph Hellwig <hch@lst.de>2011-07-08 08:35:27 -0400
commit4f6ae1a49ed5c81501d6f7385416bb4e07289e99 (patch)
treef9e302754cff53ad96eaca3b0b4de1fd91a9beb2 /fs/xfs/xfs_dir2_block.c
parent78f70cd7b7e8fd44dc89af4f72fb110d865338a1 (diff)
xfs: avoid usage of struct xfs_dir2_block
In most places we can simply pass around and use the struct xfs_dir2_data_hdr, which is the first and most important member of struct xfs_dir2_block instead of the full structure. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Alex Elder <aelder@sgi.com> Reviewed-by: Dave Chinner <dchinner@redhat.com>
Diffstat (limited to 'fs/xfs/xfs_dir2_block.c')
-rw-r--r--fs/xfs/xfs_dir2_block.c175
1 files changed, 86 insertions, 89 deletions
diff --git a/fs/xfs/xfs_dir2_block.c b/fs/xfs/xfs_dir2_block.c
index c66f194fc2a8..a0037cc4dd8c 100644
--- a/fs/xfs/xfs_dir2_block.c
+++ b/fs/xfs/xfs_dir2_block.c
@@ -67,7 +67,7 @@ xfs_dir2_block_addname(
67 xfs_da_args_t *args) /* directory op arguments */ 67 xfs_da_args_t *args) /* directory op arguments */
68{ 68{
69 xfs_dir2_data_free_t *bf; /* bestfree table in block */ 69 xfs_dir2_data_free_t *bf; /* bestfree table in block */
70 xfs_dir2_block_t *block; /* directory block structure */ 70 xfs_dir2_data_hdr_t *hdr; /* block header */
71 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */ 71 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
72 xfs_dabuf_t *bp; /* buffer for block */ 72 xfs_dabuf_t *bp; /* buffer for block */
73 xfs_dir2_block_tail_t *btp; /* block tail */ 73 xfs_dir2_block_tail_t *btp; /* block tail */
@@ -105,13 +105,13 @@ xfs_dir2_block_addname(
105 return error; 105 return error;
106 } 106 }
107 ASSERT(bp != NULL); 107 ASSERT(bp != NULL);
108 block = bp->data; 108 hdr = bp->data;
109 /* 109 /*
110 * Check the magic number, corrupted if wrong. 110 * Check the magic number, corrupted if wrong.
111 */ 111 */
112 if (unlikely(be32_to_cpu(block->hdr.magic) != XFS_DIR2_BLOCK_MAGIC)) { 112 if (unlikely(be32_to_cpu(hdr->magic) != XFS_DIR2_BLOCK_MAGIC)) {
113 XFS_CORRUPTION_ERROR("xfs_dir2_block_addname", 113 XFS_CORRUPTION_ERROR("xfs_dir2_block_addname",
114 XFS_ERRLEVEL_LOW, mp, block); 114 XFS_ERRLEVEL_LOW, mp, hdr);
115 xfs_da_brelse(tp, bp); 115 xfs_da_brelse(tp, bp);
116 return XFS_ERROR(EFSCORRUPTED); 116 return XFS_ERROR(EFSCORRUPTED);
117 } 117 }
@@ -119,8 +119,8 @@ xfs_dir2_block_addname(
119 /* 119 /*
120 * Set up pointers to parts of the block. 120 * Set up pointers to parts of the block.
121 */ 121 */
122 bf = block->hdr.bestfree; 122 bf = hdr->bestfree;
123 btp = xfs_dir2_block_tail_p(mp, block); 123 btp = xfs_dir2_block_tail_p(mp, hdr);
124 blp = xfs_dir2_block_leaf_p(btp); 124 blp = xfs_dir2_block_leaf_p(btp);
125 /* 125 /*
126 * No stale entries? Need space for entry and new leaf. 126 * No stale entries? Need space for entry and new leaf.
@@ -133,7 +133,7 @@ xfs_dir2_block_addname(
133 /* 133 /*
134 * Data object just before the first leaf entry. 134 * Data object just before the first leaf entry.
135 */ 135 */
136 enddup = (xfs_dir2_data_unused_t *)((char *)block + be16_to_cpu(*tagp)); 136 enddup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp));
137 /* 137 /*
138 * If it's not free then can't do this add without cleaning up: 138 * If it's not free then can't do this add without cleaning up:
139 * the space before the first leaf entry needs to be free so it 139 * the space before the first leaf entry needs to be free so it
@@ -146,7 +146,7 @@ xfs_dir2_block_addname(
146 */ 146 */
147 else { 147 else {
148 dup = (xfs_dir2_data_unused_t *) 148 dup = (xfs_dir2_data_unused_t *)
149 ((char *)block + be16_to_cpu(bf[0].offset)); 149 ((char *)hdr + be16_to_cpu(bf[0].offset));
150 if (dup == enddup) { 150 if (dup == enddup) {
151 /* 151 /*
152 * It is the biggest freespace, is it too small 152 * It is the biggest freespace, is it too small
@@ -159,7 +159,7 @@ xfs_dir2_block_addname(
159 */ 159 */
160 if (be16_to_cpu(bf[1].length) >= len) 160 if (be16_to_cpu(bf[1].length) >= len)
161 dup = (xfs_dir2_data_unused_t *) 161 dup = (xfs_dir2_data_unused_t *)
162 ((char *)block + 162 ((char *)hdr +
163 be16_to_cpu(bf[1].offset)); 163 be16_to_cpu(bf[1].offset));
164 else 164 else
165 dup = NULL; 165 dup = NULL;
@@ -182,7 +182,7 @@ xfs_dir2_block_addname(
182 */ 182 */
183 else if (be16_to_cpu(bf[0].length) >= len) { 183 else if (be16_to_cpu(bf[0].length) >= len) {
184 dup = (xfs_dir2_data_unused_t *) 184 dup = (xfs_dir2_data_unused_t *)
185 ((char *)block + be16_to_cpu(bf[0].offset)); 185 ((char *)hdr + be16_to_cpu(bf[0].offset));
186 compact = 0; 186 compact = 0;
187 } 187 }
188 /* 188 /*
@@ -196,7 +196,7 @@ xfs_dir2_block_addname(
196 /* 196 /*
197 * Data object just before the first leaf entry. 197 * Data object just before the first leaf entry.
198 */ 198 */
199 dup = (xfs_dir2_data_unused_t *)((char *)block + be16_to_cpu(*tagp)); 199 dup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp));
200 /* 200 /*
201 * If it's not free then the data will go where the 201 * If it's not free then the data will go where the
202 * leaf data starts now, if it works at all. 202 * leaf data starts now, if it works at all.
@@ -272,7 +272,7 @@ xfs_dir2_block_addname(
272 lfloghigh -= be32_to_cpu(btp->stale) - 1; 272 lfloghigh -= be32_to_cpu(btp->stale) - 1;
273 be32_add_cpu(&btp->count, -(be32_to_cpu(btp->stale) - 1)); 273 be32_add_cpu(&btp->count, -(be32_to_cpu(btp->stale) - 1));
274 xfs_dir2_data_make_free(tp, bp, 274 xfs_dir2_data_make_free(tp, bp,
275 (xfs_dir2_data_aoff_t)((char *)blp - (char *)block), 275 (xfs_dir2_data_aoff_t)((char *)blp - (char *)hdr),
276 (xfs_dir2_data_aoff_t)((be32_to_cpu(btp->stale) - 1) * sizeof(*blp)), 276 (xfs_dir2_data_aoff_t)((be32_to_cpu(btp->stale) - 1) * sizeof(*blp)),
277 &needlog, &needscan); 277 &needlog, &needscan);
278 blp += be32_to_cpu(btp->stale) - 1; 278 blp += be32_to_cpu(btp->stale) - 1;
@@ -282,7 +282,7 @@ xfs_dir2_block_addname(
282 * This needs to happen before the next call to use_free. 282 * This needs to happen before the next call to use_free.
283 */ 283 */
284 if (needscan) { 284 if (needscan) {
285 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog); 285 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
286 needscan = 0; 286 needscan = 0;
287 } 287 }
288 } 288 }
@@ -318,7 +318,7 @@ xfs_dir2_block_addname(
318 */ 318 */
319 xfs_dir2_data_use_free(tp, bp, enddup, 319 xfs_dir2_data_use_free(tp, bp, enddup,
320 (xfs_dir2_data_aoff_t) 320 (xfs_dir2_data_aoff_t)
321 ((char *)enddup - (char *)block + be16_to_cpu(enddup->length) - 321 ((char *)enddup - (char *)hdr + be16_to_cpu(enddup->length) -
322 sizeof(*blp)), 322 sizeof(*blp)),
323 (xfs_dir2_data_aoff_t)sizeof(*blp), 323 (xfs_dir2_data_aoff_t)sizeof(*blp),
324 &needlog, &needscan); 324 &needlog, &needscan);
@@ -331,7 +331,7 @@ xfs_dir2_block_addname(
331 * This needs to happen before the next call to use_free. 331 * This needs to happen before the next call to use_free.
332 */ 332 */
333 if (needscan) { 333 if (needscan) {
334 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, 334 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr,
335 &needlog); 335 &needlog);
336 needscan = 0; 336 needscan = 0;
337 } 337 }
@@ -397,13 +397,13 @@ xfs_dir2_block_addname(
397 */ 397 */
398 blp[mid].hashval = cpu_to_be32(args->hashval); 398 blp[mid].hashval = cpu_to_be32(args->hashval);
399 blp[mid].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp, 399 blp[mid].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
400 (char *)dep - (char *)block)); 400 (char *)dep - (char *)hdr));
401 xfs_dir2_block_log_leaf(tp, bp, lfloglow, lfloghigh); 401 xfs_dir2_block_log_leaf(tp, bp, lfloglow, lfloghigh);
402 /* 402 /*
403 * Mark space for the data entry used. 403 * Mark space for the data entry used.
404 */ 404 */
405 xfs_dir2_data_use_free(tp, bp, dup, 405 xfs_dir2_data_use_free(tp, bp, dup,
406 (xfs_dir2_data_aoff_t)((char *)dup - (char *)block), 406 (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr),
407 (xfs_dir2_data_aoff_t)len, &needlog, &needscan); 407 (xfs_dir2_data_aoff_t)len, &needlog, &needscan);
408 /* 408 /*
409 * Create the new data entry. 409 * Create the new data entry.
@@ -412,12 +412,12 @@ xfs_dir2_block_addname(
412 dep->namelen = args->namelen; 412 dep->namelen = args->namelen;
413 memcpy(dep->name, args->name, args->namelen); 413 memcpy(dep->name, args->name, args->namelen);
414 tagp = xfs_dir2_data_entry_tag_p(dep); 414 tagp = xfs_dir2_data_entry_tag_p(dep);
415 *tagp = cpu_to_be16((char *)dep - (char *)block); 415 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
416 /* 416 /*
417 * Clean up the bestfree array and log the header, tail, and entry. 417 * Clean up the bestfree array and log the header, tail, and entry.
418 */ 418 */
419 if (needscan) 419 if (needscan)
420 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog); 420 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
421 if (needlog) 421 if (needlog)
422 xfs_dir2_data_log_header(tp, bp); 422 xfs_dir2_data_log_header(tp, bp);
423 xfs_dir2_block_log_tail(tp, bp); 423 xfs_dir2_block_log_tail(tp, bp);
@@ -438,6 +438,7 @@ xfs_dir2_block_getdents(
438 filldir_t filldir) 438 filldir_t filldir)
439{ 439{
440 xfs_dir2_block_t *block; /* directory block structure */ 440 xfs_dir2_block_t *block; /* directory block structure */
441 xfs_dir2_data_hdr_t *hdr; /* block header */
441 xfs_dabuf_t *bp; /* buffer for block */ 442 xfs_dabuf_t *bp; /* buffer for block */
442 xfs_dir2_block_tail_t *btp; /* block tail */ 443 xfs_dir2_block_tail_t *btp; /* block tail */
443 xfs_dir2_data_entry_t *dep; /* block data entry */ 444 xfs_dir2_data_entry_t *dep; /* block data entry */
@@ -471,11 +472,12 @@ xfs_dir2_block_getdents(
471 */ 472 */
472 wantoff = xfs_dir2_dataptr_to_off(mp, *offset); 473 wantoff = xfs_dir2_dataptr_to_off(mp, *offset);
473 block = bp->data; 474 block = bp->data;
475 hdr = &block->hdr;
474 xfs_dir2_data_check(dp, bp); 476 xfs_dir2_data_check(dp, bp);
475 /* 477 /*
476 * Set up values for the loop. 478 * Set up values for the loop.
477 */ 479 */
478 btp = xfs_dir2_block_tail_p(mp, block); 480 btp = xfs_dir2_block_tail_p(mp, hdr);
479 ptr = (char *)block->u; 481 ptr = (char *)block->u;
480 endptr = (char *)xfs_dir2_block_leaf_p(btp); 482 endptr = (char *)xfs_dir2_block_leaf_p(btp);
481 483
@@ -502,11 +504,11 @@ xfs_dir2_block_getdents(
502 /* 504 /*
503 * The entry is before the desired starting point, skip it. 505 * The entry is before the desired starting point, skip it.
504 */ 506 */
505 if ((char *)dep - (char *)block < wantoff) 507 if ((char *)dep - (char *)hdr < wantoff)
506 continue; 508 continue;
507 509
508 cook = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk, 510 cook = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
509 (char *)dep - (char *)block); 511 (char *)dep - (char *)hdr);
510 512
511 /* 513 /*
512 * If it didn't fit, set the final offset to here & return. 514 * If it didn't fit, set the final offset to here & return.
@@ -540,17 +542,14 @@ xfs_dir2_block_log_leaf(
540 int first, /* index of first logged leaf */ 542 int first, /* index of first logged leaf */
541 int last) /* index of last logged leaf */ 543 int last) /* index of last logged leaf */
542{ 544{
543 xfs_dir2_block_t *block; /* directory block structure */ 545 xfs_dir2_data_hdr_t *hdr = bp->data;
544 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */ 546 xfs_dir2_leaf_entry_t *blp;
545 xfs_dir2_block_tail_t *btp; /* block tail */ 547 xfs_dir2_block_tail_t *btp;
546 xfs_mount_t *mp; /* filesystem mount point */
547 548
548 mp = tp->t_mountp; 549 btp = xfs_dir2_block_tail_p(tp->t_mountp, hdr);
549 block = bp->data;
550 btp = xfs_dir2_block_tail_p(mp, block);
551 blp = xfs_dir2_block_leaf_p(btp); 550 blp = xfs_dir2_block_leaf_p(btp);
552 xfs_da_log_buf(tp, bp, (uint)((char *)&blp[first] - (char *)block), 551 xfs_da_log_buf(tp, bp, (uint)((char *)&blp[first] - (char *)hdr),
553 (uint)((char *)&blp[last + 1] - (char *)block - 1)); 552 (uint)((char *)&blp[last + 1] - (char *)hdr - 1));
554} 553}
555 554
556/* 555/*
@@ -561,15 +560,12 @@ xfs_dir2_block_log_tail(
561 xfs_trans_t *tp, /* transaction structure */ 560 xfs_trans_t *tp, /* transaction structure */
562 xfs_dabuf_t *bp) /* block buffer */ 561 xfs_dabuf_t *bp) /* block buffer */
563{ 562{
564 xfs_dir2_block_t *block; /* directory block structure */ 563 xfs_dir2_data_hdr_t *hdr = bp->data;
565 xfs_dir2_block_tail_t *btp; /* block tail */ 564 xfs_dir2_block_tail_t *btp;
566 xfs_mount_t *mp; /* filesystem mount point */
567 565
568 mp = tp->t_mountp; 566 btp = xfs_dir2_block_tail_p(tp->t_mountp, hdr);
569 block = bp->data; 567 xfs_da_log_buf(tp, bp, (uint)((char *)btp - (char *)hdr),
570 btp = xfs_dir2_block_tail_p(mp, block); 568 (uint)((char *)(btp + 1) - (char *)hdr - 1));
571 xfs_da_log_buf(tp, bp, (uint)((char *)btp - (char *)block),
572 (uint)((char *)(btp + 1) - (char *)block - 1));
573} 569}
574 570
575/* 571/*
@@ -580,7 +576,7 @@ int /* error */
580xfs_dir2_block_lookup( 576xfs_dir2_block_lookup(
581 xfs_da_args_t *args) /* dir lookup arguments */ 577 xfs_da_args_t *args) /* dir lookup arguments */
582{ 578{
583 xfs_dir2_block_t *block; /* block structure */ 579 xfs_dir2_data_hdr_t *hdr; /* block header */
584 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */ 580 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
585 xfs_dabuf_t *bp; /* block buffer */ 581 xfs_dabuf_t *bp; /* block buffer */
586 xfs_dir2_block_tail_t *btp; /* block tail */ 582 xfs_dir2_block_tail_t *btp; /* block tail */
@@ -600,14 +596,14 @@ xfs_dir2_block_lookup(
600 return error; 596 return error;
601 dp = args->dp; 597 dp = args->dp;
602 mp = dp->i_mount; 598 mp = dp->i_mount;
603 block = bp->data; 599 hdr = bp->data;
604 xfs_dir2_data_check(dp, bp); 600 xfs_dir2_data_check(dp, bp);
605 btp = xfs_dir2_block_tail_p(mp, block); 601 btp = xfs_dir2_block_tail_p(mp, hdr);
606 blp = xfs_dir2_block_leaf_p(btp); 602 blp = xfs_dir2_block_leaf_p(btp);
607 /* 603 /*
608 * Get the offset from the leaf entry, to point to the data. 604 * Get the offset from the leaf entry, to point to the data.
609 */ 605 */
610 dep = (xfs_dir2_data_entry_t *)((char *)block + 606 dep = (xfs_dir2_data_entry_t *)((char *)hdr +
611 xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address))); 607 xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
612 /* 608 /*
613 * Fill in inode number, CI name if appropriate, release the block. 609 * Fill in inode number, CI name if appropriate, release the block.
@@ -628,7 +624,7 @@ xfs_dir2_block_lookup_int(
628 int *entno) /* returned entry number */ 624 int *entno) /* returned entry number */
629{ 625{
630 xfs_dir2_dataptr_t addr; /* data entry address */ 626 xfs_dir2_dataptr_t addr; /* data entry address */
631 xfs_dir2_block_t *block; /* block structure */ 627 xfs_dir2_data_hdr_t *hdr; /* block header */
632 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */ 628 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
633 xfs_dabuf_t *bp; /* block buffer */ 629 xfs_dabuf_t *bp; /* block buffer */
634 xfs_dir2_block_tail_t *btp; /* block tail */ 630 xfs_dir2_block_tail_t *btp; /* block tail */
@@ -654,9 +650,9 @@ xfs_dir2_block_lookup_int(
654 return error; 650 return error;
655 } 651 }
656 ASSERT(bp != NULL); 652 ASSERT(bp != NULL);
657 block = bp->data; 653 hdr = bp->data;
658 xfs_dir2_data_check(dp, bp); 654 xfs_dir2_data_check(dp, bp);
659 btp = xfs_dir2_block_tail_p(mp, block); 655 btp = xfs_dir2_block_tail_p(mp, hdr);
660 blp = xfs_dir2_block_leaf_p(btp); 656 blp = xfs_dir2_block_leaf_p(btp);
661 /* 657 /*
662 * Loop doing a binary search for our hash value. 658 * Loop doing a binary search for our hash value.
@@ -694,7 +690,7 @@ xfs_dir2_block_lookup_int(
694 * Get pointer to the entry from the leaf. 690 * Get pointer to the entry from the leaf.
695 */ 691 */
696 dep = (xfs_dir2_data_entry_t *) 692 dep = (xfs_dir2_data_entry_t *)
697 ((char *)block + xfs_dir2_dataptr_to_off(mp, addr)); 693 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, addr));
698 /* 694 /*
699 * Compare name and if it's an exact match, return the index 695 * Compare name and if it's an exact match, return the index
700 * and buffer. If it's the first case-insensitive match, store 696 * and buffer. If it's the first case-insensitive match, store
@@ -733,7 +729,7 @@ int /* error */
733xfs_dir2_block_removename( 729xfs_dir2_block_removename(
734 xfs_da_args_t *args) /* directory operation args */ 730 xfs_da_args_t *args) /* directory operation args */
735{ 731{
736 xfs_dir2_block_t *block; /* block structure */ 732 xfs_dir2_data_hdr_t *hdr; /* block header */
737 xfs_dir2_leaf_entry_t *blp; /* block leaf pointer */ 733 xfs_dir2_leaf_entry_t *blp; /* block leaf pointer */
738 xfs_dabuf_t *bp; /* block buffer */ 734 xfs_dabuf_t *bp; /* block buffer */
739 xfs_dir2_block_tail_t *btp; /* block tail */ 735 xfs_dir2_block_tail_t *btp; /* block tail */
@@ -760,20 +756,20 @@ xfs_dir2_block_removename(
760 dp = args->dp; 756 dp = args->dp;
761 tp = args->trans; 757 tp = args->trans;
762 mp = dp->i_mount; 758 mp = dp->i_mount;
763 block = bp->data; 759 hdr = bp->data;
764 btp = xfs_dir2_block_tail_p(mp, block); 760 btp = xfs_dir2_block_tail_p(mp, hdr);
765 blp = xfs_dir2_block_leaf_p(btp); 761 blp = xfs_dir2_block_leaf_p(btp);
766 /* 762 /*
767 * Point to the data entry using the leaf entry. 763 * Point to the data entry using the leaf entry.
768 */ 764 */
769 dep = (xfs_dir2_data_entry_t *) 765 dep = (xfs_dir2_data_entry_t *)
770 ((char *)block + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address))); 766 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
771 /* 767 /*
772 * Mark the data entry's space free. 768 * Mark the data entry's space free.
773 */ 769 */
774 needlog = needscan = 0; 770 needlog = needscan = 0;
775 xfs_dir2_data_make_free(tp, bp, 771 xfs_dir2_data_make_free(tp, bp,
776 (xfs_dir2_data_aoff_t)((char *)dep - (char *)block), 772 (xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
777 xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan); 773 xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan);
778 /* 774 /*
779 * Fix up the block tail. 775 * Fix up the block tail.
@@ -789,15 +785,15 @@ xfs_dir2_block_removename(
789 * Fix up bestfree, log the header if necessary. 785 * Fix up bestfree, log the header if necessary.
790 */ 786 */
791 if (needscan) 787 if (needscan)
792 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog); 788 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
793 if (needlog) 789 if (needlog)
794 xfs_dir2_data_log_header(tp, bp); 790 xfs_dir2_data_log_header(tp, bp);
795 xfs_dir2_data_check(dp, bp); 791 xfs_dir2_data_check(dp, bp);
796 /* 792 /*
797 * See if the size as a shortform is good enough. 793 * See if the size as a shortform is good enough.
798 */ 794 */
799 if ((size = xfs_dir2_block_sfsize(dp, block, &sfh)) > 795 size = xfs_dir2_block_sfsize(dp, hdr, &sfh);
800 XFS_IFORK_DSIZE(dp)) { 796 if (size > XFS_IFORK_DSIZE(dp)) {
801 xfs_da_buf_done(bp); 797 xfs_da_buf_done(bp);
802 return 0; 798 return 0;
803 } 799 }
@@ -815,7 +811,7 @@ int /* error */
815xfs_dir2_block_replace( 811xfs_dir2_block_replace(
816 xfs_da_args_t *args) /* directory operation args */ 812 xfs_da_args_t *args) /* directory operation args */
817{ 813{
818 xfs_dir2_block_t *block; /* block structure */ 814 xfs_dir2_data_hdr_t *hdr; /* block header */
819 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */ 815 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
820 xfs_dabuf_t *bp; /* block buffer */ 816 xfs_dabuf_t *bp; /* block buffer */
821 xfs_dir2_block_tail_t *btp; /* block tail */ 817 xfs_dir2_block_tail_t *btp; /* block tail */
@@ -836,14 +832,14 @@ xfs_dir2_block_replace(
836 } 832 }
837 dp = args->dp; 833 dp = args->dp;
838 mp = dp->i_mount; 834 mp = dp->i_mount;
839 block = bp->data; 835 hdr = bp->data;
840 btp = xfs_dir2_block_tail_p(mp, block); 836 btp = xfs_dir2_block_tail_p(mp, hdr);
841 blp = xfs_dir2_block_leaf_p(btp); 837 blp = xfs_dir2_block_leaf_p(btp);
842 /* 838 /*
843 * Point to the data entry we need to change. 839 * Point to the data entry we need to change.
844 */ 840 */
845 dep = (xfs_dir2_data_entry_t *) 841 dep = (xfs_dir2_data_entry_t *)
846 ((char *)block + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address))); 842 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(blp[ent].address)));
847 ASSERT(be64_to_cpu(dep->inumber) != args->inumber); 843 ASSERT(be64_to_cpu(dep->inumber) != args->inumber);
848 /* 844 /*
849 * Change the inode number to the new value. 845 * Change the inode number to the new value.
@@ -882,7 +878,7 @@ xfs_dir2_leaf_to_block(
882 xfs_dabuf_t *dbp) /* data buffer */ 878 xfs_dabuf_t *dbp) /* data buffer */
883{ 879{
884 __be16 *bestsp; /* leaf bests table */ 880 __be16 *bestsp; /* leaf bests table */
885 xfs_dir2_block_t *block; /* block structure */ 881 xfs_dir2_data_hdr_t *hdr; /* block header */
886 xfs_dir2_block_tail_t *btp; /* block tail */ 882 xfs_dir2_block_tail_t *btp; /* block tail */
887 xfs_inode_t *dp; /* incore directory inode */ 883 xfs_inode_t *dp; /* incore directory inode */
888 xfs_dir2_data_unused_t *dup; /* unused data entry */ 884 xfs_dir2_data_unused_t *dup; /* unused data entry */
@@ -917,7 +913,7 @@ xfs_dir2_leaf_to_block(
917 while (dp->i_d.di_size > mp->m_dirblksize) { 913 while (dp->i_d.di_size > mp->m_dirblksize) {
918 bestsp = xfs_dir2_leaf_bests_p(ltp); 914 bestsp = xfs_dir2_leaf_bests_p(ltp);
919 if (be16_to_cpu(bestsp[be32_to_cpu(ltp->bestcount) - 1]) == 915 if (be16_to_cpu(bestsp[be32_to_cpu(ltp->bestcount) - 1]) ==
920 mp->m_dirblksize - (uint)sizeof(block->hdr)) { 916 mp->m_dirblksize - (uint)sizeof(*hdr)) {
921 if ((error = 917 if ((error =
922 xfs_dir2_leaf_trim_data(args, lbp, 918 xfs_dir2_leaf_trim_data(args, lbp,
923 (xfs_dir2_db_t)(be32_to_cpu(ltp->bestcount) - 1)))) 919 (xfs_dir2_db_t)(be32_to_cpu(ltp->bestcount) - 1))))
@@ -935,18 +931,18 @@ xfs_dir2_leaf_to_block(
935 XFS_DATA_FORK))) { 931 XFS_DATA_FORK))) {
936 goto out; 932 goto out;
937 } 933 }
938 block = dbp->data; 934 hdr = dbp->data;
939 ASSERT(be32_to_cpu(block->hdr.magic) == XFS_DIR2_DATA_MAGIC); 935 ASSERT(be32_to_cpu(hdr->magic) == XFS_DIR2_DATA_MAGIC);
940 /* 936 /*
941 * Size of the "leaf" area in the block. 937 * Size of the "leaf" area in the block.
942 */ 938 */
943 size = (uint)sizeof(block->tail) + 939 size = (uint)sizeof(xfs_dir2_block_tail_t) +
944 (uint)sizeof(*lep) * (be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale)); 940 (uint)sizeof(*lep) * (be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale));
945 /* 941 /*
946 * Look at the last data entry. 942 * Look at the last data entry.
947 */ 943 */
948 tagp = (__be16 *)((char *)block + mp->m_dirblksize) - 1; 944 tagp = (__be16 *)((char *)hdr + mp->m_dirblksize) - 1;
949 dup = (xfs_dir2_data_unused_t *)((char *)block + be16_to_cpu(*tagp)); 945 dup = (xfs_dir2_data_unused_t *)((char *)hdr + be16_to_cpu(*tagp));
950 /* 946 /*
951 * If it's not free or is too short we can't do it. 947 * If it's not free or is too short we can't do it.
952 */ 948 */
@@ -958,7 +954,7 @@ xfs_dir2_leaf_to_block(
958 /* 954 /*
959 * Start converting it to block form. 955 * Start converting it to block form.
960 */ 956 */
961 block->hdr.magic = cpu_to_be32(XFS_DIR2_BLOCK_MAGIC); 957 hdr->magic = cpu_to_be32(XFS_DIR2_BLOCK_MAGIC);
962 needlog = 1; 958 needlog = 1;
963 needscan = 0; 959 needscan = 0;
964 /* 960 /*
@@ -969,7 +965,7 @@ xfs_dir2_leaf_to_block(
969 /* 965 /*
970 * Initialize the block tail. 966 * Initialize the block tail.
971 */ 967 */
972 btp = xfs_dir2_block_tail_p(mp, block); 968 btp = xfs_dir2_block_tail_p(mp, hdr);
973 btp->count = cpu_to_be32(be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale)); 969 btp->count = cpu_to_be32(be16_to_cpu(leaf->hdr.count) - be16_to_cpu(leaf->hdr.stale));
974 btp->stale = 0; 970 btp->stale = 0;
975 xfs_dir2_block_log_tail(tp, dbp); 971 xfs_dir2_block_log_tail(tp, dbp);
@@ -988,7 +984,7 @@ xfs_dir2_leaf_to_block(
988 * Scan the bestfree if we need it and log the data block header. 984 * Scan the bestfree if we need it and log the data block header.
989 */ 985 */
990 if (needscan) 986 if (needscan)
991 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)block, &needlog); 987 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog);
992 if (needlog) 988 if (needlog)
993 xfs_dir2_data_log_header(tp, dbp); 989 xfs_dir2_data_log_header(tp, dbp);
994 /* 990 /*
@@ -1002,8 +998,8 @@ xfs_dir2_leaf_to_block(
1002 /* 998 /*
1003 * Now see if the resulting block can be shrunken to shortform. 999 * Now see if the resulting block can be shrunken to shortform.
1004 */ 1000 */
1005 if ((size = xfs_dir2_block_sfsize(dp, block, &sfh)) > 1001 size = xfs_dir2_block_sfsize(dp, hdr, &sfh);
1006 XFS_IFORK_DSIZE(dp)) { 1002 if (size > XFS_IFORK_DSIZE(dp)) {
1007 error = 0; 1003 error = 0;
1008 goto out; 1004 goto out;
1009 } 1005 }
@@ -1025,6 +1021,7 @@ xfs_dir2_sf_to_block(
1025{ 1021{
1026 xfs_dir2_db_t blkno; /* dir-relative block # (0) */ 1022 xfs_dir2_db_t blkno; /* dir-relative block # (0) */
1027 xfs_dir2_block_t *block; /* block structure */ 1023 xfs_dir2_block_t *block; /* block structure */
1024 xfs_dir2_data_hdr_t *hdr; /* block header */
1028 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */ 1025 xfs_dir2_leaf_entry_t *blp; /* block leaf entries */
1029 xfs_dabuf_t *bp; /* block buffer */ 1026 xfs_dabuf_t *bp; /* block buffer */
1030 xfs_dir2_block_tail_t *btp; /* block tail pointer */ 1027 xfs_dir2_block_tail_t *btp; /* block tail pointer */
@@ -1095,7 +1092,8 @@ xfs_dir2_sf_to_block(
1095 return error; 1092 return error;
1096 } 1093 }
1097 block = bp->data; 1094 block = bp->data;
1098 block->hdr.magic = cpu_to_be32(XFS_DIR2_BLOCK_MAGIC); 1095 hdr = &block->hdr;
1096 hdr->magic = cpu_to_be32(XFS_DIR2_BLOCK_MAGIC);
1099 /* 1097 /*
1100 * Compute size of block "tail" area. 1098 * Compute size of block "tail" area.
1101 */ 1099 */
@@ -1113,45 +1111,45 @@ xfs_dir2_sf_to_block(
1113 /* 1111 /*
1114 * Fill in the tail. 1112 * Fill in the tail.
1115 */ 1113 */
1116 btp = xfs_dir2_block_tail_p(mp, block); 1114 btp = xfs_dir2_block_tail_p(mp, hdr);
1117 btp->count = cpu_to_be32(sfp->count + 2); /* ., .. */ 1115 btp->count = cpu_to_be32(sfp->count + 2); /* ., .. */
1118 btp->stale = 0; 1116 btp->stale = 0;
1119 blp = xfs_dir2_block_leaf_p(btp); 1117 blp = xfs_dir2_block_leaf_p(btp);
1120 endoffset = (uint)((char *)blp - (char *)block); 1118 endoffset = (uint)((char *)blp - (char *)hdr);
1121 /* 1119 /*
1122 * Remove the freespace, we'll manage it. 1120 * Remove the freespace, we'll manage it.
1123 */ 1121 */
1124 xfs_dir2_data_use_free(tp, bp, dup, 1122 xfs_dir2_data_use_free(tp, bp, dup,
1125 (xfs_dir2_data_aoff_t)((char *)dup - (char *)block), 1123 (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr),
1126 be16_to_cpu(dup->length), &needlog, &needscan); 1124 be16_to_cpu(dup->length), &needlog, &needscan);
1127 /* 1125 /*
1128 * Create entry for . 1126 * Create entry for .
1129 */ 1127 */
1130 dep = (xfs_dir2_data_entry_t *) 1128 dep = (xfs_dir2_data_entry_t *)
1131 ((char *)block + XFS_DIR2_DATA_DOT_OFFSET); 1129 ((char *)hdr + XFS_DIR2_DATA_DOT_OFFSET);
1132 dep->inumber = cpu_to_be64(dp->i_ino); 1130 dep->inumber = cpu_to_be64(dp->i_ino);
1133 dep->namelen = 1; 1131 dep->namelen = 1;
1134 dep->name[0] = '.'; 1132 dep->name[0] = '.';
1135 tagp = xfs_dir2_data_entry_tag_p(dep); 1133 tagp = xfs_dir2_data_entry_tag_p(dep);
1136 *tagp = cpu_to_be16((char *)dep - (char *)block); 1134 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
1137 xfs_dir2_data_log_entry(tp, bp, dep); 1135 xfs_dir2_data_log_entry(tp, bp, dep);
1138 blp[0].hashval = cpu_to_be32(xfs_dir_hash_dot); 1136 blp[0].hashval = cpu_to_be32(xfs_dir_hash_dot);
1139 blp[0].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp, 1137 blp[0].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
1140 (char *)dep - (char *)block)); 1138 (char *)dep - (char *)hdr));
1141 /* 1139 /*
1142 * Create entry for .. 1140 * Create entry for ..
1143 */ 1141 */
1144 dep = (xfs_dir2_data_entry_t *) 1142 dep = (xfs_dir2_data_entry_t *)
1145 ((char *)block + XFS_DIR2_DATA_DOTDOT_OFFSET); 1143 ((char *)hdr + XFS_DIR2_DATA_DOTDOT_OFFSET);
1146 dep->inumber = cpu_to_be64(xfs_dir2_sf_get_parent_ino(sfp)); 1144 dep->inumber = cpu_to_be64(xfs_dir2_sf_get_parent_ino(sfp));
1147 dep->namelen = 2; 1145 dep->namelen = 2;
1148 dep->name[0] = dep->name[1] = '.'; 1146 dep->name[0] = dep->name[1] = '.';
1149 tagp = xfs_dir2_data_entry_tag_p(dep); 1147 tagp = xfs_dir2_data_entry_tag_p(dep);
1150 *tagp = cpu_to_be16((char *)dep - (char *)block); 1148 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
1151 xfs_dir2_data_log_entry(tp, bp, dep); 1149 xfs_dir2_data_log_entry(tp, bp, dep);
1152 blp[1].hashval = cpu_to_be32(xfs_dir_hash_dotdot); 1150 blp[1].hashval = cpu_to_be32(xfs_dir_hash_dotdot);
1153 blp[1].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp, 1151 blp[1].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
1154 (char *)dep - (char *)block)); 1152 (char *)dep - (char *)hdr));
1155 offset = XFS_DIR2_DATA_FIRST_OFFSET; 1153 offset = XFS_DIR2_DATA_FIRST_OFFSET;
1156 /* 1154 /*
1157 * Loop over existing entries, stuff them in. 1155 * Loop over existing entries, stuff them in.
@@ -1177,14 +1175,13 @@ xfs_dir2_sf_to_block(
1177 * There should be a hole here, make one. 1175 * There should be a hole here, make one.
1178 */ 1176 */
1179 if (offset < newoffset) { 1177 if (offset < newoffset) {
1180 dup = (xfs_dir2_data_unused_t *) 1178 dup = (xfs_dir2_data_unused_t *)((char *)hdr + offset);
1181 ((char *)block + offset);
1182 dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG); 1179 dup->freetag = cpu_to_be16(XFS_DIR2_DATA_FREE_TAG);
1183 dup->length = cpu_to_be16(newoffset - offset); 1180 dup->length = cpu_to_be16(newoffset - offset);
1184 *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16( 1181 *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(
1185 ((char *)dup - (char *)block)); 1182 ((char *)dup - (char *)hdr));
1186 xfs_dir2_data_log_unused(tp, bp, dup); 1183 xfs_dir2_data_log_unused(tp, bp, dup);
1187 (void)xfs_dir2_data_freeinsert((xfs_dir2_data_t *)block, 1184 (void)xfs_dir2_data_freeinsert((xfs_dir2_data_t *)hdr,
1188 dup, &dummy); 1185 dup, &dummy);
1189 offset += be16_to_cpu(dup->length); 1186 offset += be16_to_cpu(dup->length);
1190 continue; 1187 continue;
@@ -1192,20 +1189,20 @@ xfs_dir2_sf_to_block(
1192 /* 1189 /*
1193 * Copy a real entry. 1190 * Copy a real entry.
1194 */ 1191 */
1195 dep = (xfs_dir2_data_entry_t *)((char *)block + newoffset); 1192 dep = (xfs_dir2_data_entry_t *)((char *)hdr + newoffset);
1196 dep->inumber = cpu_to_be64(xfs_dir2_sfe_get_ino(sfp, sfep)); 1193 dep->inumber = cpu_to_be64(xfs_dir2_sfe_get_ino(sfp, sfep));
1197 dep->namelen = sfep->namelen; 1194 dep->namelen = sfep->namelen;
1198 memcpy(dep->name, sfep->name, dep->namelen); 1195 memcpy(dep->name, sfep->name, dep->namelen);
1199 tagp = xfs_dir2_data_entry_tag_p(dep); 1196 tagp = xfs_dir2_data_entry_tag_p(dep);
1200 *tagp = cpu_to_be16((char *)dep - (char *)block); 1197 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
1201 xfs_dir2_data_log_entry(tp, bp, dep); 1198 xfs_dir2_data_log_entry(tp, bp, dep);
1202 name.name = sfep->name; 1199 name.name = sfep->name;
1203 name.len = sfep->namelen; 1200 name.len = sfep->namelen;
1204 blp[2 + i].hashval = cpu_to_be32(mp->m_dirnameops-> 1201 blp[2 + i].hashval = cpu_to_be32(mp->m_dirnameops->
1205 hashname(&name)); 1202 hashname(&name));
1206 blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp, 1203 blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp,
1207 (char *)dep - (char *)block)); 1204 (char *)dep - (char *)hdr));
1208 offset = (int)((char *)(tagp + 1) - (char *)block); 1205 offset = (int)((char *)(tagp + 1) - (char *)hdr);
1209 if (++i == sfp->count) 1206 if (++i == sfp->count)
1210 sfep = NULL; 1207 sfep = NULL;
1211 else 1208 else