aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_leaf.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2011-07-08 08:35:38 -0400
committerChristoph Hellwig <hch@lst.de>2011-07-08 08:35:38 -0400
commitc2066e2662070e794f57a96a129c42575e77cfcb (patch)
treec1261009d7482af80db1b554a96b5a62f35b4877 /fs/xfs/xfs_dir2_leaf.c
parenta64b04179735de6bfd9f00c130a68ed7f20d18ef (diff)
xfs: avoid usage of struct xfs_dir2_data
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_data 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_leaf.c')
-rw-r--r--fs/xfs/xfs_dir2_leaf.c76
1 files changed, 38 insertions, 38 deletions
diff --git a/fs/xfs/xfs_dir2_leaf.c b/fs/xfs/xfs_dir2_leaf.c
index 1b048dad360f..d7b4d4494f2d 100644
--- a/fs/xfs/xfs_dir2_leaf.c
+++ b/fs/xfs/xfs_dir2_leaf.c
@@ -132,7 +132,7 @@ xfs_dir2_block_to_leaf(
132 */ 132 */
133 hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC); 133 hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC);
134 if (needscan) 134 if (needscan)
135 xfs_dir2_data_freescan(mp, (xfs_dir2_data_t *)hdr, &needlog); 135 xfs_dir2_data_freescan(mp, hdr, &needlog);
136 /* 136 /*
137 * Set up leaf tail and bests table. 137 * Set up leaf tail and bests table.
138 */ 138 */
@@ -278,7 +278,7 @@ xfs_dir2_leaf_addname(
278{ 278{
279 __be16 *bestsp; /* freespace table in leaf */ 279 __be16 *bestsp; /* freespace table in leaf */
280 int compact; /* need to compact leaves */ 280 int compact; /* need to compact leaves */
281 xfs_dir2_data_t *data; /* data block structure */ 281 xfs_dir2_data_hdr_t *hdr; /* data block header */
282 xfs_dabuf_t *dbp; /* data block buffer */ 282 xfs_dabuf_t *dbp; /* data block buffer */
283 xfs_dir2_data_entry_t *dep; /* data block entry */ 283 xfs_dir2_data_entry_t *dep; /* data block entry */
284 xfs_inode_t *dp; /* incore directory inode */ 284 xfs_inode_t *dp; /* incore directory inode */
@@ -486,8 +486,8 @@ xfs_dir2_leaf_addname(
486 */ 486 */
487 else 487 else
488 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block); 488 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block);
489 data = dbp->data; 489 hdr = dbp->data;
490 bestsp[use_block] = data->hdr.bestfree[0].length; 490 bestsp[use_block] = hdr->bestfree[0].length;
491 grown = 1; 491 grown = 1;
492 } 492 }
493 /* 493 /*
@@ -501,7 +501,7 @@ xfs_dir2_leaf_addname(
501 xfs_da_brelse(tp, lbp); 501 xfs_da_brelse(tp, lbp);
502 return error; 502 return error;
503 } 503 }
504 data = dbp->data; 504 hdr = dbp->data;
505 grown = 0; 505 grown = 0;
506 } 506 }
507 xfs_dir2_data_check(dp, dbp); 507 xfs_dir2_data_check(dp, dbp);
@@ -509,14 +509,14 @@ xfs_dir2_leaf_addname(
509 * Point to the biggest freespace in our data block. 509 * Point to the biggest freespace in our data block.
510 */ 510 */
511 dup = (xfs_dir2_data_unused_t *) 511 dup = (xfs_dir2_data_unused_t *)
512 ((char *)data + be16_to_cpu(data->hdr.bestfree[0].offset)); 512 ((char *)hdr + be16_to_cpu(hdr->bestfree[0].offset));
513 ASSERT(be16_to_cpu(dup->length) >= length); 513 ASSERT(be16_to_cpu(dup->length) >= length);
514 needscan = needlog = 0; 514 needscan = needlog = 0;
515 /* 515 /*
516 * Mark the initial part of our freespace in use for the new entry. 516 * Mark the initial part of our freespace in use for the new entry.
517 */ 517 */
518 xfs_dir2_data_use_free(tp, dbp, dup, 518 xfs_dir2_data_use_free(tp, dbp, dup,
519 (xfs_dir2_data_aoff_t)((char *)dup - (char *)data), length, 519 (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr), length,
520 &needlog, &needscan); 520 &needlog, &needscan);
521 /* 521 /*
522 * Initialize our new entry (at last). 522 * Initialize our new entry (at last).
@@ -526,12 +526,12 @@ xfs_dir2_leaf_addname(
526 dep->namelen = args->namelen; 526 dep->namelen = args->namelen;
527 memcpy(dep->name, args->name, dep->namelen); 527 memcpy(dep->name, args->name, dep->namelen);
528 tagp = xfs_dir2_data_entry_tag_p(dep); 528 tagp = xfs_dir2_data_entry_tag_p(dep);
529 *tagp = cpu_to_be16((char *)dep - (char *)data); 529 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
530 /* 530 /*
531 * Need to scan fix up the bestfree table. 531 * Need to scan fix up the bestfree table.
532 */ 532 */
533 if (needscan) 533 if (needscan)
534 xfs_dir2_data_freescan(mp, data, &needlog); 534 xfs_dir2_data_freescan(mp, hdr, &needlog);
535 /* 535 /*
536 * Need to log the data block's header. 536 * Need to log the data block's header.
537 */ 537 */
@@ -542,8 +542,8 @@ xfs_dir2_leaf_addname(
542 * If the bests table needs to be changed, do it. 542 * If the bests table needs to be changed, do it.
543 * Log the change unless we've already done that. 543 * Log the change unless we've already done that.
544 */ 544 */
545 if (be16_to_cpu(bestsp[use_block]) != be16_to_cpu(data->hdr.bestfree[0].length)) { 545 if (be16_to_cpu(bestsp[use_block]) != be16_to_cpu(hdr->bestfree[0].length)) {
546 bestsp[use_block] = data->hdr.bestfree[0].length; 546 bestsp[use_block] = hdr->bestfree[0].length;
547 if (!grown) 547 if (!grown)
548 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block); 548 xfs_dir2_leaf_log_bests(tp, lbp, use_block, use_block);
549 } 549 }
@@ -786,6 +786,7 @@ xfs_dir2_leaf_getdents(
786 xfs_dir2_db_t curdb; /* db for current block */ 786 xfs_dir2_db_t curdb; /* db for current block */
787 xfs_dir2_off_t curoff; /* current overall offset */ 787 xfs_dir2_off_t curoff; /* current overall offset */
788 xfs_dir2_data_t *data; /* data block structure */ 788 xfs_dir2_data_t *data; /* data block structure */
789 xfs_dir2_data_hdr_t *hdr; /* data block header */
789 xfs_dir2_data_entry_t *dep; /* data entry */ 790 xfs_dir2_data_entry_t *dep; /* data entry */
790 xfs_dir2_data_unused_t *dup; /* unused entry */ 791 xfs_dir2_data_unused_t *dup; /* unused entry */
791 int error = 0; /* error return value */ 792 int error = 0; /* error return value */
@@ -1044,6 +1045,7 @@ xfs_dir2_leaf_getdents(
1044 ASSERT(xfs_dir2_byte_to_db(mp, curoff) == 1045 ASSERT(xfs_dir2_byte_to_db(mp, curoff) ==
1045 curdb); 1046 curdb);
1046 data = bp->data; 1047 data = bp->data;
1048 hdr = &data->hdr;
1047 xfs_dir2_data_check(dp, bp); 1049 xfs_dir2_data_check(dp, bp);
1048 /* 1050 /*
1049 * Find our position in the block. 1051 * Find our position in the block.
@@ -1054,12 +1056,12 @@ xfs_dir2_leaf_getdents(
1054 * Skip past the header. 1056 * Skip past the header.
1055 */ 1057 */
1056 if (byteoff == 0) 1058 if (byteoff == 0)
1057 curoff += (uint)sizeof(data->hdr); 1059 curoff += (uint)sizeof(*hdr);
1058 /* 1060 /*
1059 * Skip past entries until we reach our offset. 1061 * Skip past entries until we reach our offset.
1060 */ 1062 */
1061 else { 1063 else {
1062 while ((char *)ptr - (char *)data < byteoff) { 1064 while ((char *)ptr - (char *)hdr < byteoff) {
1063 dup = (xfs_dir2_data_unused_t *)ptr; 1065 dup = (xfs_dir2_data_unused_t *)ptr;
1064 1066
1065 if (be16_to_cpu(dup->freetag) 1067 if (be16_to_cpu(dup->freetag)
@@ -1080,8 +1082,8 @@ xfs_dir2_leaf_getdents(
1080 curoff = 1082 curoff =
1081 xfs_dir2_db_off_to_byte(mp, 1083 xfs_dir2_db_off_to_byte(mp,
1082 xfs_dir2_byte_to_db(mp, curoff), 1084 xfs_dir2_byte_to_db(mp, curoff),
1083 (char *)ptr - (char *)data); 1085 (char *)ptr - (char *)hdr);
1084 if (ptr >= (char *)data + mp->m_dirblksize) { 1086 if (ptr >= (char *)hdr + mp->m_dirblksize) {
1085 continue; 1087 continue;
1086 } 1088 }
1087 } 1089 }
@@ -1462,7 +1464,7 @@ xfs_dir2_leaf_removename(
1462 xfs_da_args_t *args) /* operation arguments */ 1464 xfs_da_args_t *args) /* operation arguments */
1463{ 1465{
1464 __be16 *bestsp; /* leaf block best freespace */ 1466 __be16 *bestsp; /* leaf block best freespace */
1465 xfs_dir2_data_t *data; /* data block structure */ 1467 xfs_dir2_data_hdr_t *hdr; /* data block header */
1466 xfs_dir2_db_t db; /* data block number */ 1468 xfs_dir2_db_t db; /* data block number */
1467 xfs_dabuf_t *dbp; /* data block buffer */ 1469 xfs_dabuf_t *dbp; /* data block buffer */
1468 xfs_dir2_data_entry_t *dep; /* data entry structure */ 1470 xfs_dir2_data_entry_t *dep; /* data entry structure */
@@ -1492,7 +1494,7 @@ xfs_dir2_leaf_removename(
1492 tp = args->trans; 1494 tp = args->trans;
1493 mp = dp->i_mount; 1495 mp = dp->i_mount;
1494 leaf = lbp->data; 1496 leaf = lbp->data;
1495 data = dbp->data; 1497 hdr = dbp->data;
1496 xfs_dir2_data_check(dp, dbp); 1498 xfs_dir2_data_check(dp, dbp);
1497 /* 1499 /*
1498 * Point to the leaf entry, use that to point to the data entry. 1500 * Point to the leaf entry, use that to point to the data entry.
@@ -1500,9 +1502,9 @@ xfs_dir2_leaf_removename(
1500 lep = &leaf->ents[index]; 1502 lep = &leaf->ents[index];
1501 db = xfs_dir2_dataptr_to_db(mp, be32_to_cpu(lep->address)); 1503 db = xfs_dir2_dataptr_to_db(mp, be32_to_cpu(lep->address));
1502 dep = (xfs_dir2_data_entry_t *) 1504 dep = (xfs_dir2_data_entry_t *)
1503 ((char *)data + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address))); 1505 ((char *)hdr + xfs_dir2_dataptr_to_off(mp, be32_to_cpu(lep->address)));
1504 needscan = needlog = 0; 1506 needscan = needlog = 0;
1505 oldbest = be16_to_cpu(data->hdr.bestfree[0].length); 1507 oldbest = be16_to_cpu(hdr->bestfree[0].length);
1506 ltp = xfs_dir2_leaf_tail_p(mp, leaf); 1508 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1507 bestsp = xfs_dir2_leaf_bests_p(ltp); 1509 bestsp = xfs_dir2_leaf_bests_p(ltp);
1508 ASSERT(be16_to_cpu(bestsp[db]) == oldbest); 1510 ASSERT(be16_to_cpu(bestsp[db]) == oldbest);
@@ -1510,7 +1512,7 @@ xfs_dir2_leaf_removename(
1510 * Mark the former data entry unused. 1512 * Mark the former data entry unused.
1511 */ 1513 */
1512 xfs_dir2_data_make_free(tp, dbp, 1514 xfs_dir2_data_make_free(tp, dbp,
1513 (xfs_dir2_data_aoff_t)((char *)dep - (char *)data), 1515 (xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
1514 xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan); 1516 xfs_dir2_data_entsize(dep->namelen), &needlog, &needscan);
1515 /* 1517 /*
1516 * We just mark the leaf entry stale by putting a null in it. 1518 * We just mark the leaf entry stale by putting a null in it.
@@ -1524,23 +1526,23 @@ xfs_dir2_leaf_removename(
1524 * log the data block header if necessary. 1526 * log the data block header if necessary.
1525 */ 1527 */
1526 if (needscan) 1528 if (needscan)
1527 xfs_dir2_data_freescan(mp, data, &needlog); 1529 xfs_dir2_data_freescan(mp, hdr, &needlog);
1528 if (needlog) 1530 if (needlog)
1529 xfs_dir2_data_log_header(tp, dbp); 1531 xfs_dir2_data_log_header(tp, dbp);
1530 /* 1532 /*
1531 * If the longest freespace in the data block has changed, 1533 * If the longest freespace in the data block has changed,
1532 * put the new value in the bests table and log that. 1534 * put the new value in the bests table and log that.
1533 */ 1535 */
1534 if (be16_to_cpu(data->hdr.bestfree[0].length) != oldbest) { 1536 if (be16_to_cpu(hdr->bestfree[0].length) != oldbest) {
1535 bestsp[db] = data->hdr.bestfree[0].length; 1537 bestsp[db] = hdr->bestfree[0].length;
1536 xfs_dir2_leaf_log_bests(tp, lbp, db, db); 1538 xfs_dir2_leaf_log_bests(tp, lbp, db, db);
1537 } 1539 }
1538 xfs_dir2_data_check(dp, dbp); 1540 xfs_dir2_data_check(dp, dbp);
1539 /* 1541 /*
1540 * If the data block is now empty then get rid of the data block. 1542 * If the data block is now empty then get rid of the data block.
1541 */ 1543 */
1542 if (be16_to_cpu(data->hdr.bestfree[0].length) == 1544 if (be16_to_cpu(hdr->bestfree[0].length) ==
1543 mp->m_dirblksize - (uint)sizeof(data->hdr)) { 1545 mp->m_dirblksize - (uint)sizeof(*hdr)) {
1544 ASSERT(db != mp->m_dirdatablk); 1546 ASSERT(db != mp->m_dirdatablk);
1545 if ((error = xfs_dir2_shrink_inode(args, db, dbp))) { 1547 if ((error = xfs_dir2_shrink_inode(args, db, dbp))) {
1546 /* 1548 /*
@@ -1711,9 +1713,6 @@ xfs_dir2_leaf_trim_data(
1711 xfs_dir2_db_t db) /* data block number */ 1713 xfs_dir2_db_t db) /* data block number */
1712{ 1714{
1713 __be16 *bestsp; /* leaf bests table */ 1715 __be16 *bestsp; /* leaf bests table */
1714#ifdef DEBUG
1715 xfs_dir2_data_t *data; /* data block structure */
1716#endif
1717 xfs_dabuf_t *dbp; /* data block buffer */ 1716 xfs_dabuf_t *dbp; /* data block buffer */
1718 xfs_inode_t *dp; /* incore directory inode */ 1717 xfs_inode_t *dp; /* incore directory inode */
1719 int error; /* error return value */ 1718 int error; /* error return value */
@@ -1732,20 +1731,21 @@ xfs_dir2_leaf_trim_data(
1732 XFS_DATA_FORK))) { 1731 XFS_DATA_FORK))) {
1733 return error; 1732 return error;
1734 } 1733 }
1735#ifdef DEBUG
1736 data = dbp->data;
1737 ASSERT(be32_to_cpu(data->hdr.magic) == XFS_DIR2_DATA_MAGIC);
1738#endif
1739 /* this seems to be an error
1740 * data is only valid if DEBUG is defined?
1741 * RMC 09/08/1999
1742 */
1743 1734
1744 leaf = lbp->data; 1735 leaf = lbp->data;
1745 ltp = xfs_dir2_leaf_tail_p(mp, leaf); 1736 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
1746 ASSERT(be16_to_cpu(data->hdr.bestfree[0].length) == 1737
1747 mp->m_dirblksize - (uint)sizeof(data->hdr)); 1738#ifdef DEBUG
1739{
1740 struct xfs_dir2_data_hdr *hdr = dbp->data;
1741
1742 ASSERT(be32_to_cpu(hdr->magic) == XFS_DIR2_DATA_MAGIC);
1743 ASSERT(be16_to_cpu(hdr->bestfree[0].length) ==
1744 mp->m_dirblksize - (uint)sizeof(*hdr));
1748 ASSERT(db == be32_to_cpu(ltp->bestcount) - 1); 1745 ASSERT(db == be32_to_cpu(ltp->bestcount) - 1);
1746}
1747#endif
1748
1749 /* 1749 /*
1750 * Get rid of the data block. 1750 * Get rid of the data block.
1751 */ 1751 */