LCOV - code coverage report
Current view: top level - fs/xfs - xfs_attr_list.c (source / functions) Hit Total Coverage
Test: fstests of 6.5.0-rc3-achx @ Mon Jul 31 20:08:12 PDT 2023 Lines: 254 308 82.5 %
Date: 2023-07-31 20:08:12 Functions: 8 8 100.0 %

          Line data    Source code
       1             : // SPDX-License-Identifier: GPL-2.0
       2             : /*
       3             :  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
       4             :  * Copyright (c) 2013 Red Hat, Inc.
       5             :  * All Rights Reserved.
       6             :  */
       7             : #include "xfs.h"
       8             : #include "xfs_fs.h"
       9             : #include "xfs_shared.h"
      10             : #include "xfs_format.h"
      11             : #include "xfs_log_format.h"
      12             : #include "xfs_trans_resv.h"
      13             : #include "xfs_mount.h"
      14             : #include "xfs_da_format.h"
      15             : #include "xfs_inode.h"
      16             : #include "xfs_trans.h"
      17             : #include "xfs_bmap.h"
      18             : #include "xfs_da_btree.h"
      19             : #include "xfs_attr.h"
      20             : #include "xfs_attr_sf.h"
      21             : #include "xfs_attr_leaf.h"
      22             : #include "xfs_error.h"
      23             : #include "xfs_trace.h"
      24             : #include "xfs_dir2.h"
      25             : #include "xfs_health.h"
      26             : 
      27             : STATIC int
      28    21484795 : xfs_attr_shortform_compare(const void *a, const void *b)
      29             : {
      30    21484795 :         xfs_attr_sf_sort_t *sa, *sb;
      31             : 
      32    21484795 :         sa = (xfs_attr_sf_sort_t *)a;
      33    21484795 :         sb = (xfs_attr_sf_sort_t *)b;
      34    21484795 :         if (sa->hash < sb->hash) {
      35             :                 return -1;
      36    10773746 :         } else if (sa->hash > sb->hash) {
      37             :                 return 1;
      38             :         } else {
      39         209 :                 return sa->entno - sb->entno;
      40             :         }
      41             : }
      42             : 
      43             : #define XFS_ISRESET_CURSOR(cursor) \
      44             :         (!((cursor)->initted) && !((cursor)->hashval) && \
      45             :          !((cursor)->blkno) && !((cursor)->offset))
      46             : /*
      47             :  * Copy out entries of shortform attribute lists for attr_list().
      48             :  * Shortform attribute lists are not stored in hashval sorted order.
      49             :  * If the output buffer is not large enough to hold them all, then
      50             :  * we have to calculate each entries' hashvalue and sort them before
      51             :  * we can begin returning them to the user.
      52             :  */
      53             : static int
      54   739018730 : xfs_attr_shortform_list(
      55             :         struct xfs_attr_list_context    *context)
      56             : {
      57   739018730 :         struct xfs_attrlist_cursor_kern *cursor = &context->cursor;
      58   739018730 :         struct xfs_inode                *dp = context->dp;
      59   739018730 :         struct xfs_attr_sf_sort         *sbuf, *sbp;
      60   739018730 :         struct xfs_attr_shortform       *sf;
      61   739018730 :         struct xfs_attr_sf_entry        *sfe;
      62   739018730 :         struct xfs_mount                *mp;
      63   739018730 :         int                             sbsize, nsbuf, count, i;
      64   739018730 :         int                             error = 0;
      65             : 
      66   739018730 :         ASSERT(context != NULL);
      67   739018730 :         ASSERT(dp != NULL);
      68   739018730 :         mp = dp->i_mount;
      69   739018730 :         sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data;
      70   739018730 :         ASSERT(sf != NULL);
      71   739018730 :         if (!sf->hdr.count)
      72             :                 return 0;
      73             : 
      74   741887399 :         trace_xfs_attr_list_sf(context);
      75             : 
      76             :         /*
      77             :          * If the buffer is large enough and the cursor is at the start,
      78             :          * do not bother with sorting since we will return everything in
      79             :          * one buffer and another call using the cursor won't need to be
      80             :          * made.
      81             :          * Note the generous fudge factor of 16 overhead bytes per entry.
      82             :          * If bufsize is zero then put_listent must be a search function
      83             :          * and can just scan through what we have.
      84             :          */
      85   741723342 :         if (context->bufsize == 0 ||
      86   736161905 :             (XFS_ISRESET_CURSOR(cursor) &&
      87   736332354 :              (dp->i_af.if_bytes + sf->hdr.count * 16) < context->bufsize)) {
      88  1624027910 :                 for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
      89   889605589 :                         if (XFS_IS_CORRUPT(context->dp->i_mount,
      90             :                                            !xfs_attr_namecheck(mp, sfe->nameval,
      91             :                                                                sfe->namelen,
      92             :                                                                sfe->flags))) {
      93          11 :                                 xfs_dirattr_mark_sick(context->dp, XFS_ATTR_FORK);
      94          11 :                                 return -EFSCORRUPTED;
      95             :                         }
      96   887592591 :                         context->put_listent(context,
      97   887592591 :                                              sfe->flags,
      98             :                                              sfe->nameval,
      99             :                                              (int)sfe->namelen,
     100   887592591 :                                              &sfe->nameval[sfe->namelen],
     101   887592591 :                                              (int)sfe->valuelen);
     102             :                         /*
     103             :                          * Either search callback finished early or
     104             :                          * didn't fit it all in the buffer after all.
     105             :                          */
     106   885914978 :                         if (context->seen_enough)
     107             :                                 break;
     108   885914978 :                         sfe = xfs_attr_sf_nextentry(sfe);
     109             :                 }
     110   734422321 :                 trace_xfs_attr_list_sf_all(context);
     111   734422321 :                 return 0;
     112             :         }
     113             : 
     114             :         /* do no more for a search callback */
     115     3622224 :         if (context->bufsize == 0)
     116             :                 return 0;
     117             : 
     118             :         /*
     119             :          * It didn't all fit, so we have to sort everything on hashval.
     120             :          */
     121     3622224 :         sbsize = sf->hdr.count * sizeof(*sbuf);
     122     3622224 :         sbp = sbuf = kmem_alloc(sbsize, KM_NOFS);
     123             : 
     124             :         /*
     125             :          * Scan the attribute list for the rest of the entries, storing
     126             :          * the relevant info from only those that match into a buffer.
     127             :          */
     128     3923201 :         nsbuf = 0;
     129    17698356 :         for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
     130    13775202 :                 if (unlikely(
     131             :                     ((char *)sfe < (char *)sf) ||
     132             :                     ((char *)sfe >= ((char *)sf + dp->i_af.if_bytes)))) {
     133           0 :                         XFS_CORRUPTION_ERROR("xfs_attr_shortform_list",
     134             :                                              XFS_ERRLEVEL_LOW,
     135             :                                              context->dp->i_mount, sfe,
     136             :                                              sizeof(*sfe));
     137           0 :                         kmem_free(sbuf);
     138           0 :                         xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
     139           0 :                         return -EFSCORRUPTED;
     140             :                 }
     141             : 
     142    13775202 :                 sbp->entno = i;
     143    13775202 :                 sbp->hash = xfs_da_hashname(sfe->nameval, sfe->namelen);
     144    13775155 :                 sbp->name = sfe->nameval;
     145    13775155 :                 sbp->namelen = sfe->namelen;
     146             :                 /* These are bytes, and both on-disk, don't endian-flip */
     147    13775155 :                 sbp->value = &sfe->nameval[sfe->namelen],
     148    13775155 :                 sbp->valuelen = sfe->valuelen;
     149    13775155 :                 sbp->flags = sfe->flags;
     150    13775155 :                 sfe = xfs_attr_sf_nextentry(sfe);
     151    13775155 :                 sbp++;
     152    13775155 :                 nsbuf++;
     153             :         }
     154             : 
     155             :         /*
     156             :          * Sort the entries on hash then entno.
     157             :          */
     158     3923154 :         xfs_sort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare);
     159             : 
     160             :         /*
     161             :          * Re-find our place IN THE SORTED LIST.
     162             :          */
     163     3923195 :         count = 0;
     164     3923195 :         cursor->initted = 1;
     165     3923195 :         cursor->blkno = 0;
     166     3923221 :         for (sbp = sbuf, i = 0; i < nsbuf; i++, sbp++) {
     167     3923060 :                 if (sbp->hash == cursor->hashval) {
     168           0 :                         if (cursor->offset == count) {
     169             :                                 break;
     170             :                         }
     171           0 :                         count++;
     172     3923060 :                 } else if (sbp->hash > cursor->hashval) {
     173             :                         break;
     174             :                 }
     175             :         }
     176     3923195 :         if (i == nsbuf)
     177           0 :                 goto out;
     178             : 
     179             :         /*
     180             :          * Loop putting entries into the user buffer.
     181             :          */
     182    17698107 :         for ( ; i < nsbuf; i++, sbp++) {
     183    13774884 :                 if (cursor->hashval != sbp->hash) {
     184    13774693 :                         cursor->hashval = sbp->hash;
     185    13774693 :                         cursor->offset = 0;
     186             :                 }
     187    13774884 :                 if (XFS_IS_CORRUPT(context->dp->i_mount,
     188             :                                    !xfs_attr_namecheck(mp, sbp->name,
     189             :                                                        sbp->namelen,
     190             :                                                        sbp->flags))) {
     191           0 :                         xfs_dirattr_mark_sick(context->dp, XFS_ATTR_FORK);
     192           0 :                         error = -EFSCORRUPTED;
     193           0 :                         goto out;
     194             :                 }
     195    13775190 :                 context->put_listent(context,
     196    13775190 :                                      sbp->flags,
     197             :                                      sbp->name,
     198    13775190 :                                      sbp->namelen,
     199             :                                      sbp->value,
     200    13775190 :                                      sbp->valuelen);
     201    13774956 :                 if (context->seen_enough)
     202             :                         break;
     203    13774912 :                 cursor->offset++;
     204             :         }
     205     3923267 : out:
     206     3923267 :         kmem_free(sbuf);
     207     3923267 :         return error;
     208             : }
     209             : 
     210             : /*
     211             :  * We didn't find the block & hash mentioned in the cursor state, so
     212             :  * walk down the attr btree looking for the hash.
     213             :  */
     214             : STATIC int
     215     1195107 : xfs_attr_node_list_lookup(
     216             :         struct xfs_attr_list_context    *context,
     217             :         struct xfs_attrlist_cursor_kern *cursor,
     218             :         struct xfs_buf                  **pbp)
     219             : {
     220     1195107 :         struct xfs_da3_icnode_hdr       nodehdr;
     221     1195107 :         struct xfs_da_intnode           *node;
     222     1195107 :         struct xfs_da_node_entry        *btree;
     223     1195107 :         struct xfs_inode                *dp = context->dp;
     224     1195107 :         struct xfs_mount                *mp = dp->i_mount;
     225     1195107 :         struct xfs_trans                *tp = context->tp;
     226     1195107 :         struct xfs_buf                  *bp;
     227     1195107 :         xfs_failaddr_t                  fa;
     228     1195107 :         int                             i;
     229     1195107 :         int                             error = 0;
     230     1195107 :         unsigned int                    expected_level = 0;
     231     1195107 :         uint16_t                        magic;
     232             : 
     233     1195107 :         ASSERT(*pbp == NULL);
     234     1195107 :         cursor->blkno = 0;
     235     2619758 :         for (;;) {
     236     2619758 :                 error = xfs_da3_node_read(tp, dp, cursor->blkno, &bp,
     237             :                                 XFS_ATTR_FORK);
     238     2619768 :                 if (error)
     239           0 :                         return error;
     240     2619768 :                 node = bp->b_addr;
     241     2619768 :                 magic = be16_to_cpu(node->hdr.info.magic);
     242     2619768 :                 if (magic == XFS_ATTR_LEAF_MAGIC ||
     243     2619768 :                     magic == XFS_ATTR3_LEAF_MAGIC)
     244             :                         break;
     245     1424640 :                 if (magic != XFS_DA_NODE_MAGIC &&
     246     1424640 :                     magic != XFS_DA3_NODE_MAGIC) {
     247           0 :                         XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp,
     248             :                                         node, sizeof(*node));
     249           0 :                         goto out_corruptbuf;
     250             :                 }
     251             : 
     252     1424640 :                 fa = xfs_da3_node_header_check(bp, dp->i_ino);
     253     1424636 :                 if (fa)
     254           0 :                         goto out_corruptbuf;
     255             : 
     256     1424636 :                 xfs_da3_node_hdr_from_disk(mp, &nodehdr, node);
     257             : 
     258             :                 /* Tree taller than we can handle; bail out! */
     259     1424631 :                 if (nodehdr.level >= XFS_DA_NODE_MAXDEPTH)
     260           0 :                         goto out_corruptbuf;
     261             : 
     262             :                 /* Check the level from the root node. */
     263     1424631 :                 if (cursor->blkno == 0)
     264     1194132 :                         expected_level = nodehdr.level - 1;
     265      230499 :                 else if (expected_level != nodehdr.level)
     266           0 :                         goto out_corruptbuf;
     267             :                 else
     268      230499 :                         expected_level--;
     269             : 
     270     1424631 :                 btree = nodehdr.btree;
     271     1424813 :                 for (i = 0; i < nodehdr.count; btree++, i++) {
     272     1424818 :                         if (cursor->hashval <= be32_to_cpu(btree->hashval)) {
     273     1424636 :                                 cursor->blkno = be32_to_cpu(btree->before);
     274     1424636 :                                 trace_xfs_attr_list_node_descend(context,
     275             :                                                 btree);
     276     1424636 :                                 break;
     277             :                         }
     278             :                 }
     279     1424621 :                 xfs_trans_brelse(tp, bp);
     280             : 
     281     1424651 :                 if (i == nodehdr.count)
     282             :                         return 0;
     283             : 
     284             :                 /* We can't point back to the root. */
     285     1424651 :                 if (XFS_IS_CORRUPT(mp, cursor->blkno == 0)) {
     286           0 :                         xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
     287           0 :                         return -EFSCORRUPTED;
     288             :                 }
     289             :         }
     290             : 
     291     1195128 :         fa = xfs_attr3_leaf_header_check(bp, dp->i_ino);
     292     1195114 :         if (fa) {
     293           0 :                 __xfs_buf_mark_corrupt(bp, fa);
     294           0 :                 goto out_releasebuf;
     295             :         }
     296             : 
     297     1195114 :         if (expected_level != 0)
     298           0 :                 goto out_corruptbuf;
     299             : 
     300     1195114 :         *pbp = bp;
     301     1195114 :         return 0;
     302             : 
     303           0 : out_corruptbuf:
     304           0 :         xfs_buf_mark_corrupt(bp);
     305           0 : out_releasebuf:
     306           0 :         xfs_trans_brelse(tp, bp);
     307           0 :         xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
     308           0 :         return -EFSCORRUPTED;
     309             : }
     310             : 
     311             : STATIC int
     312     1195212 : xfs_attr_node_list(
     313             :         struct xfs_attr_list_context    *context)
     314             : {
     315     1195212 :         struct xfs_attrlist_cursor_kern *cursor = &context->cursor;
     316     1195212 :         struct xfs_attr3_icleaf_hdr     leafhdr;
     317     1195212 :         struct xfs_attr_leafblock       *leaf;
     318     1195212 :         struct xfs_da_intnode           *node;
     319     1195212 :         struct xfs_buf                  *bp;
     320     1195212 :         struct xfs_inode                *dp = context->dp;
     321     1195212 :         struct xfs_mount                *mp = dp->i_mount;
     322     1195212 :         xfs_failaddr_t                  fa;
     323     1195212 :         int                             error = 0;
     324             : 
     325     1195212 :         trace_xfs_attr_node_list(context);
     326             : 
     327     1195207 :         cursor->initted = 1;
     328             : 
     329             :         /*
     330             :          * Do all sorts of validation on the passed-in cursor structure.
     331             :          * If anything is amiss, ignore the cursor and look up the hashval
     332             :          * starting from the btree root.
     333             :          */
     334     1195207 :         bp = NULL;
     335     1195207 :         if (cursor->blkno > 0) {
     336        1078 :                 error = xfs_da3_node_read(context->tp, dp, cursor->blkno, &bp,
     337             :                                 XFS_ATTR_FORK);
     338        1078 :                 if (xfs_metadata_is_sick(error))
     339           0 :                         xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
     340        1078 :                 if ((error != 0) && (error != -EFSCORRUPTED))
     341             :                         return error;
     342        1078 :                 if (bp) {
     343        1078 :                         struct xfs_attr_leaf_entry *entries;
     344             : 
     345        1078 :                         node = bp->b_addr;
     346        1078 :                         switch (be16_to_cpu(node->hdr.info.magic)) {
     347           0 :                         case XFS_DA_NODE_MAGIC:
     348             :                         case XFS_DA3_NODE_MAGIC:
     349           0 :                                 trace_xfs_attr_list_wrong_blk(context);
     350           0 :                                 fa = xfs_da3_node_header_check(bp,
     351             :                                                 dp->i_ino);
     352           0 :                                 if (fa) {
     353           0 :                                         __xfs_buf_mark_corrupt(bp, fa);
     354           0 :                                         xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
     355             :                                 }
     356           0 :                                 xfs_trans_brelse(context->tp, bp);
     357           0 :                                 bp = NULL;
     358           0 :                                 break;
     359        1078 :                         case XFS_ATTR_LEAF_MAGIC:
     360             :                         case XFS_ATTR3_LEAF_MAGIC:
     361        1078 :                                 leaf = bp->b_addr;
     362        1078 :                                 fa = xfs_attr3_leaf_header_check(bp,
     363             :                                                 dp->i_ino);
     364        1078 :                                 if (fa) {
     365           0 :                                         __xfs_buf_mark_corrupt(bp, fa);
     366           0 :                                         xfs_trans_brelse(context->tp, bp);
     367           0 :                                         xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
     368           0 :                                         bp = NULL;
     369           0 :                                         break;
     370             :                                 }
     371        1078 :                                 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo,
     372             :                                                              &leafhdr, leaf);
     373        1078 :                                 entries = xfs_attr3_leaf_entryp(leaf);
     374        1078 :                                 if (cursor->hashval > be32_to_cpu(
     375             :                                                 entries[leafhdr.count - 1].hashval)) {
     376           0 :                                         trace_xfs_attr_list_wrong_blk(context);
     377           0 :                                         xfs_trans_brelse(context->tp, bp);
     378           0 :                                         bp = NULL;
     379        1078 :                                 } else if (cursor->hashval <= be32_to_cpu(
     380             :                                                 entries[0].hashval)) {
     381         977 :                                         trace_xfs_attr_list_wrong_blk(context);
     382         977 :                                         xfs_trans_brelse(context->tp, bp);
     383         977 :                                         bp = NULL;
     384             :                                 }
     385             :                                 break;
     386           0 :                         default:
     387           0 :                                 trace_xfs_attr_list_wrong_blk(context);
     388           0 :                                 xfs_trans_brelse(context->tp, bp);
     389           0 :                                 bp = NULL;
     390             :                         }
     391             :                 }
     392             :         }
     393             : 
     394             :         /*
     395             :          * We did not find what we expected given the cursor's contents,
     396             :          * so we start from the top and work down based on the hash value.
     397             :          * Note that start of node block is same as start of leaf block.
     398             :          */
     399     1195207 :         if (bp == NULL) {
     400     1195106 :                 error = xfs_attr_node_list_lookup(context, cursor, &bp);
     401     1195117 :                 if (error || !bp)
     402             :                         return error;
     403             :         }
     404     1195218 :         ASSERT(bp != NULL);
     405             : 
     406             :         /*
     407             :          * Roll upward through the blocks, processing each leaf block in
     408             :          * order.  As long as there is space in the result buffer, keep
     409             :          * adding the information.
     410             :          */
     411   478949656 :         for (;;) {
     412   478949656 :                 leaf = bp->b_addr;
     413   478949656 :                 error = xfs_attr3_leaf_list_int(bp, context);
     414   478949545 :                 if (error)
     415             :                         break;
     416   478949545 :                 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf);
     417   478949604 :                 if (context->seen_enough || leafhdr.forw == 0)
     418             :                         break;
     419   477754379 :                 cursor->blkno = leafhdr.forw;
     420   477754379 :                 xfs_trans_brelse(context->tp, bp);
     421   477754491 :                 error = xfs_attr3_leaf_read(context->tp, dp, dp->i_ino,
     422             :                                 cursor->blkno, &bp);
     423   477754438 :                 if (error)
     424           0 :                         return error;
     425             :         }
     426     1195225 :         xfs_trans_brelse(context->tp, bp);
     427     1195225 :         return error;
     428             : }
     429             : 
     430             : /*
     431             :  * Copy out attribute list entries for attr_list(), for leaf attribute lists.
     432             :  */
     433             : int
     434   529814033 : xfs_attr3_leaf_list_int(
     435             :         struct xfs_buf                  *bp,
     436             :         struct xfs_attr_list_context    *context)
     437             : {
     438   529814033 :         struct xfs_attrlist_cursor_kern *cursor = &context->cursor;
     439   529814033 :         struct xfs_attr_leafblock       *leaf;
     440   529814033 :         struct xfs_attr3_icleaf_hdr     ichdr;
     441   529814033 :         struct xfs_attr_leaf_entry      *entries;
     442   529814033 :         struct xfs_attr_leaf_entry      *entry;
     443   529814033 :         int                             i;
     444   529814033 :         struct xfs_mount                *mp = context->dp->i_mount;
     445             : 
     446   529814033 :         trace_xfs_attr_list_leaf(context);
     447             : 
     448   529796401 :         leaf = bp->b_addr;
     449   529796401 :         xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
     450   529789571 :         entries = xfs_attr3_leaf_entryp(leaf);
     451             : 
     452   529789571 :         cursor->initted = 1;
     453             : 
     454             :         /*
     455             :          * Re-find our place in the leaf block if this is a new syscall.
     456             :          */
     457   529789571 :         if (context->resynch) {
     458             :                 entry = &entries[0];
     459    61165120 :                 for (i = 0; i < ichdr.count; entry++, i++) {
     460    60151811 :                         if (be32_to_cpu(entry->hashval) == cursor->hashval) {
     461     8109188 :                                 if (cursor->offset == context->dupcnt) {
     462        1088 :                                         context->dupcnt = 0;
     463        1088 :                                         break;
     464             :                                 }
     465     8108100 :                                 context->dupcnt++;
     466    52042623 :                         } else if (be32_to_cpu(entry->hashval) >
     467             :                                         cursor->hashval) {
     468    52040025 :                                 context->dupcnt = 0;
     469    52040025 :                                 break;
     470             :                         }
     471             :                 }
     472    53054422 :                 if (i == ichdr.count) {
     473     1013309 :                         trace_xfs_attr_list_notfound(context);
     474     1013309 :                         return 0;
     475             :                 }
     476             :         } else {
     477             :                 entry = &entries[0];
     478             :                 i = 0;
     479             :         }
     480   528776262 :         context->resynch = 0;
     481             : 
     482             :         /*
     483             :          * We have found our place, start copying out the new attributes.
     484             :          */
     485  5747471130 :         for (; i < ichdr.count; entry++, i++) {
     486  5218659104 :                 char *name;
     487  5218659104 :                 void *value;
     488  5218659104 :                 int namelen, valuelen;
     489             : 
     490  5218659104 :                 if (be32_to_cpu(entry->hashval) != cursor->hashval) {
     491  1458885198 :                         cursor->hashval = be32_to_cpu(entry->hashval);
     492  1458885198 :                         cursor->offset = 0;
     493             :                 }
     494             : 
     495  5218659104 :                 if ((entry->flags & XFS_ATTR_INCOMPLETE) &&
     496           0 :                     !context->allow_incomplete)
     497           0 :                         continue;
     498             : 
     499  5218659104 :                 if (entry->flags & XFS_ATTR_LOCAL) {
     500  5218657679 :                         xfs_attr_leaf_name_local_t *name_loc;
     501             : 
     502  5218657679 :                         name_loc = xfs_attr3_leaf_name_local(leaf, i);
     503  5218657679 :                         name = name_loc->nameval;
     504  5218657679 :                         namelen = name_loc->namelen;
     505  5218657679 :                         value = &name_loc->nameval[name_loc->namelen];
     506  5218657679 :                         valuelen = be16_to_cpu(name_loc->valuelen);
     507             :                 } else {
     508        1425 :                         xfs_attr_leaf_name_remote_t *name_rmt;
     509             : 
     510        1425 :                         name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
     511        1425 :                         name = name_rmt->name;
     512        1425 :                         namelen = name_rmt->namelen;
     513        1425 :                         value = NULL;
     514        1425 :                         valuelen = be32_to_cpu(name_rmt->valuelen);
     515             :                 }
     516             : 
     517  5218659104 :                 if (XFS_IS_CORRUPT(context->dp->i_mount,
     518             :                                    !xfs_attr_namecheck(mp, name, namelen,
     519             :                                                        entry->flags))) {
     520           0 :                         xfs_dirattr_mark_sick(context->dp, XFS_ATTR_FORK);
     521           0 :                         return -EFSCORRUPTED;
     522             :                 }
     523  5218689527 :                 context->put_listent(context, entry->flags,
     524             :                                               name, namelen, value, valuelen);
     525  5218696004 :                 if (context->seen_enough)
     526             :                         break;
     527  5218694868 :                 cursor->offset++;
     528             :         }
     529   528813162 :         trace_xfs_attr_list_leaf_end(context);
     530   528813162 :         return 0;
     531             : }
     532             : 
     533             : /*
     534             :  * Copy out attribute entries for attr_list(), for leaf attribute lists.
     535             :  */
     536             : STATIC int
     537    50876112 : xfs_attr_leaf_list(
     538             :         struct xfs_attr_list_context    *context)
     539             : {
     540    50876112 :         struct xfs_buf                  *bp;
     541    50876112 :         int                             error;
     542             : 
     543    50876112 :         trace_xfs_attr_leaf_list(context);
     544             : 
     545    50862785 :         context->cursor.blkno = 0;
     546    50862785 :         error = xfs_attr3_leaf_read(context->tp, context->dp,
     547    50862785 :                         context->dp->i_ino, 0, &bp);
     548    50858515 :         if (error)
     549             :                 return error;
     550             : 
     551    50858977 :         error = xfs_attr3_leaf_list_int(bp, context);
     552    50872169 :         xfs_trans_brelse(context->tp, bp);
     553    50872169 :         return error;
     554             : }
     555             : 
     556             : int
     557   876254870 : xfs_attr_list_ilocked(
     558             :         struct xfs_attr_list_context    *context)
     559             : {
     560   876254870 :         struct xfs_inode                *dp = context->dp;
     561             : 
     562   876254870 :         ASSERT(xfs_isilocked(dp, XFS_ILOCK_SHARED | XFS_ILOCK_EXCL));
     563             : 
     564             :         /*
     565             :          * Decide on what work routines to call based on the inode size.
     566             :          */
     567   870568086 :         if (!xfs_inode_hasattr(dp))
     568             :                 return 0;
     569   791148090 :         if (dp->i_af.if_format == XFS_DINODE_FMT_LOCAL)
     570   739100553 :                 return xfs_attr_shortform_list(context);
     571    52047537 :         if (xfs_attr_is_leaf(dp))
     572    50880831 :                 return xfs_attr_leaf_list(context);
     573     1195217 :         return xfs_attr_node_list(context);
     574             : }
     575             : 
     576             : int
     577   875918816 : xfs_attr_list(
     578             :         struct xfs_attr_list_context    *context)
     579             : {
     580   875918816 :         struct xfs_inode                *dp = context->dp;
     581   875918816 :         uint                            lock_mode;
     582   875918816 :         int                             error;
     583             : 
     584   875918816 :         XFS_STATS_INC(dp->i_mount, xs_attr_list);
     585             : 
     586  1751507890 :         if (xfs_is_shutdown(dp->i_mount))
     587             :                 return -EIO;
     588             : 
     589   875753944 :         lock_mode = xfs_ilock_attr_map_shared(dp);
     590   875393555 :         error = xfs_attr_list_ilocked(context);
     591   868907557 :         xfs_iunlock(dp, lock_mode);
     592   868907557 :         return error;
     593             : }

Generated by: LCOV version 1.14