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-rc4-xfsa @ Mon Jul 31 20:08:27 PDT 2023 Lines: 254 308 82.5 %
Date: 2023-07-31 20:08:27 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    40496973 : xfs_attr_shortform_compare(const void *a, const void *b)
      29             : {
      30    40496973 :         xfs_attr_sf_sort_t *sa, *sb;
      31             : 
      32    40496973 :         sa = (xfs_attr_sf_sort_t *)a;
      33    40496973 :         sb = (xfs_attr_sf_sort_t *)b;
      34    40496973 :         if (sa->hash < sb->hash) {
      35             :                 return -1;
      36    20252512 :         } else if (sa->hash > sb->hash) {
      37             :                 return 1;
      38             :         } else {
      39         190 :                 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   194036218 : xfs_attr_shortform_list(
      55             :         struct xfs_attr_list_context    *context)
      56             : {
      57   194036218 :         struct xfs_attrlist_cursor_kern *cursor = &context->cursor;
      58   194036218 :         struct xfs_inode                *dp = context->dp;
      59   194036218 :         struct xfs_attr_sf_sort         *sbuf, *sbp;
      60   194036218 :         struct xfs_attr_shortform       *sf;
      61   194036218 :         struct xfs_attr_sf_entry        *sfe;
      62   194036218 :         struct xfs_mount                *mp;
      63   194036218 :         int                             sbsize, nsbuf, count, i;
      64   194036218 :         int                             error = 0;
      65             : 
      66   194036218 :         ASSERT(context != NULL);
      67   194036218 :         ASSERT(dp != NULL);
      68   194036218 :         mp = dp->i_mount;
      69   194036218 :         sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data;
      70   194036218 :         ASSERT(sf != NULL);
      71   194036218 :         if (!sf->hdr.count)
      72             :                 return 0;
      73             : 
      74   194008851 :         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   194007790 :         if (context->bufsize == 0 ||
      86   185030358 :             (XFS_ISRESET_CURSOR(cursor) &&
      87   185032367 :              (dp->i_af.if_bytes + sf->hdr.count * 16) < context->bufsize)) {
      88   464068523 :                 for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
      89   277055670 :                         if (XFS_IS_CORRUPT(context->dp->i_mount,
      90             :                                            !xfs_attr_namecheck(mp, sfe->nameval,
      91             :                                                                sfe->namelen,
      92             :                                                                sfe->flags))) {
      93           2 :                                 xfs_dirattr_mark_sick(context->dp, XFS_ATTR_FORK);
      94           2 :                                 return -EFSCORRUPTED;
      95             :                         }
      96   277058357 :                         context->put_listent(context,
      97   277058357 :                                              sfe->flags,
      98             :                                              sfe->nameval,
      99   277058357 :                                              (int)sfe->namelen,
     100   277058357 :                                              &sfe->nameval[sfe->namelen],
     101   277058357 :                                              (int)sfe->valuelen);
     102             :                         /*
     103             :                          * Either search callback finished early or
     104             :                          * didn't fit it all in the buffer after all.
     105             :                          */
     106   277069433 :                         if (context->seen_enough)
     107             :                                 break;
     108   277069433 :                         sfe = xfs_attr_sf_nextentry(sfe);
     109             :                 }
     110   187012853 :                 trace_xfs_attr_list_sf_all(context);
     111   187012853 :                 return 0;
     112             :         }
     113             : 
     114             :         /* do no more for a search callback */
     115     7008700 :         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     7008700 :         sbsize = sf->hdr.count * sizeof(*sbuf);
     122     7008700 :         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     7013744 :         nsbuf = 0;
     129    32321947 :         for (i = 0, sfe = &sf->list[0]; i < sf->hdr.count; i++) {
     130    25308210 :                 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    25308210 :                 sbp->entno = i;
     143    25308210 :                 sbp->hash = xfs_da_hashname(sfe->nameval, sfe->namelen);
     144    25308203 :                 sbp->name = sfe->nameval;
     145    25308203 :                 sbp->namelen = sfe->namelen;
     146             :                 /* These are bytes, and both on-disk, don't endian-flip */
     147    25308203 :                 sbp->value = &sfe->nameval[sfe->namelen],
     148    25308203 :                 sbp->valuelen = sfe->valuelen;
     149    25308203 :                 sbp->flags = sfe->flags;
     150    25308203 :                 sfe = xfs_attr_sf_nextentry(sfe);
     151    25308203 :                 sbp++;
     152    25308203 :                 nsbuf++;
     153             :         }
     154             : 
     155             :         /*
     156             :          * Sort the entries on hash then entno.
     157             :          */
     158     7013737 :         xfs_sort(sbuf, nsbuf, sizeof(*sbuf), xfs_attr_shortform_compare);
     159             : 
     160             :         /*
     161             :          * Re-find our place IN THE SORTED LIST.
     162             :          */
     163     7013689 :         count = 0;
     164     7013689 :         cursor->initted = 1;
     165     7013689 :         cursor->blkno = 0;
     166     7013694 :         for (sbp = sbuf, i = 0; i < nsbuf; i++, sbp++) {
     167     7013728 :                 if (sbp->hash == cursor->hashval) {
     168           0 :                         if (cursor->offset == count) {
     169             :                                 break;
     170             :                         }
     171           0 :                         count++;
     172     7013728 :                 } else if (sbp->hash > cursor->hashval) {
     173             :                         break;
     174             :                 }
     175             :         }
     176     7013689 :         if (i == nsbuf)
     177           0 :                 goto out;
     178             : 
     179             :         /*
     180             :          * Loop putting entries into the user buffer.
     181             :          */
     182    32321613 :         for ( ; i < nsbuf; i++, sbp++) {
     183    25307903 :                 if (cursor->hashval != sbp->hash) {
     184    25307728 :                         cursor->hashval = sbp->hash;
     185    25307728 :                         cursor->offset = 0;
     186             :                 }
     187    25307903 :                 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    25307961 :                 context->put_listent(context,
     196    25307961 :                                      sbp->flags,
     197             :                                      sbp->name,
     198    25307961 :                                      sbp->namelen,
     199             :                                      sbp->value,
     200    25307961 :                                      sbp->valuelen);
     201    25307932 :                 if (context->seen_enough)
     202             :                         break;
     203    25307924 :                 cursor->offset++;
     204             :         }
     205     7013718 : out:
     206     7013718 :         kmem_free(sbuf);
     207     7013718 :         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     1960512 : 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     1960512 :         struct xfs_da3_icnode_hdr       nodehdr;
     221     1960512 :         struct xfs_da_intnode           *node;
     222     1960512 :         struct xfs_da_node_entry        *btree;
     223     1960512 :         struct xfs_inode                *dp = context->dp;
     224     1960512 :         struct xfs_mount                *mp = dp->i_mount;
     225     1960512 :         struct xfs_trans                *tp = context->tp;
     226     1960512 :         struct xfs_buf                  *bp;
     227     1960512 :         xfs_failaddr_t                  fa;
     228     1960512 :         int                             i;
     229     1960512 :         int                             error = 0;
     230     1960512 :         unsigned int                    expected_level = 0;
     231     1960512 :         uint16_t                        magic;
     232             : 
     233     1960512 :         ASSERT(*pbp == NULL);
     234     1960512 :         cursor->blkno = 0;
     235     4003066 :         for (;;) {
     236     4003066 :                 error = xfs_da3_node_read(tp, dp, cursor->blkno, &bp,
     237             :                                 XFS_ATTR_FORK);
     238     4003060 :                 if (error)
     239           0 :                         return error;
     240     4003060 :                 node = bp->b_addr;
     241     4003060 :                 magic = be16_to_cpu(node->hdr.info.magic);
     242     4003060 :                 if (magic == XFS_ATTR_LEAF_MAGIC ||
     243     4003060 :                     magic == XFS_ATTR3_LEAF_MAGIC)
     244             :                         break;
     245     2042558 :                 if (magic != XFS_DA_NODE_MAGIC &&
     246     2042558 :                     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     2042558 :                 fa = xfs_da3_node_header_check(bp, dp->i_ino);
     253     2042550 :                 if (fa)
     254           0 :                         goto out_corruptbuf;
     255             : 
     256     2042550 :                 xfs_da3_node_hdr_from_disk(mp, &nodehdr, node);
     257             : 
     258             :                 /* Tree taller than we can handle; bail out! */
     259     2042550 :                 if (nodehdr.level >= XFS_DA_NODE_MAXDEPTH)
     260           0 :                         goto out_corruptbuf;
     261             : 
     262             :                 /* Check the level from the root node. */
     263     2042550 :                 if (cursor->blkno == 0)
     264     1960293 :                         expected_level = nodehdr.level - 1;
     265       82257 :                 else if (expected_level != nodehdr.level)
     266           0 :                         goto out_corruptbuf;
     267             :                 else
     268       82257 :                         expected_level--;
     269             : 
     270     2042550 :                 btree = nodehdr.btree;
     271     2042520 :                 for (i = 0; i < nodehdr.count; btree++, i++) {
     272     4085022 :                         if (cursor->hashval <= be32_to_cpu(btree->hashval)) {
     273     2042541 :                                 cursor->blkno = be32_to_cpu(btree->before);
     274     2042541 :                                 trace_xfs_attr_list_node_descend(context,
     275             :                                                 btree);
     276     2042541 :                                 break;
     277             :                         }
     278             :                 }
     279     2042552 :                 xfs_trans_brelse(tp, bp);
     280             : 
     281     2042554 :                 if (i == nodehdr.count)
     282             :                         return 0;
     283             : 
     284             :                 /* We can't point back to the root. */
     285     2042554 :                 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     1960502 :         fa = xfs_attr3_leaf_header_check(bp, dp->i_ino);
     292     1960506 :         if (fa) {
     293           0 :                 __xfs_buf_mark_corrupt(bp, fa);
     294           0 :                 goto out_releasebuf;
     295             :         }
     296             : 
     297     1960506 :         if (expected_level != 0)
     298           0 :                 goto out_corruptbuf;
     299             : 
     300     1960506 :         *pbp = bp;
     301     1960506 :         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     1960560 : xfs_attr_node_list(
     313             :         struct xfs_attr_list_context    *context)
     314             : {
     315     1960560 :         struct xfs_attrlist_cursor_kern *cursor = &context->cursor;
     316     1960560 :         struct xfs_attr3_icleaf_hdr     leafhdr;
     317     1960560 :         struct xfs_attr_leafblock       *leaf;
     318     1960560 :         struct xfs_da_intnode           *node;
     319     1960560 :         struct xfs_buf                  *bp;
     320     1960560 :         struct xfs_inode                *dp = context->dp;
     321     1960560 :         struct xfs_mount                *mp = dp->i_mount;
     322     1960560 :         xfs_failaddr_t                  fa;
     323     1960560 :         int                             error = 0;
     324             : 
     325     1960560 :         trace_xfs_attr_node_list(context);
     326             : 
     327     1960543 :         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     1960543 :         bp = NULL;
     335     1960543 :         if (cursor->blkno > 0) {
     336         363 :                 error = xfs_da3_node_read(context->tp, dp, cursor->blkno, &bp,
     337             :                                 XFS_ATTR_FORK);
     338         363 :                 if (xfs_metadata_is_sick(error))
     339           0 :                         xfs_dirattr_mark_sick(dp, XFS_ATTR_FORK);
     340         363 :                 if ((error != 0) && (error != -EFSCORRUPTED))
     341             :                         return error;
     342         363 :                 if (bp) {
     343         363 :                         struct xfs_attr_leaf_entry *entries;
     344             : 
     345         363 :                         node = bp->b_addr;
     346         363 :                         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         363 :                         case XFS_ATTR_LEAF_MAGIC:
     360             :                         case XFS_ATTR3_LEAF_MAGIC:
     361         363 :                                 leaf = bp->b_addr;
     362         363 :                                 fa = xfs_attr3_leaf_header_check(bp,
     363             :                                                 dp->i_ino);
     364         363 :                                 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         363 :                                 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo,
     372             :                                                              &leafhdr, leaf);
     373         363 :                                 entries = xfs_attr3_leaf_entryp(leaf);
     374         726 :                                 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         726 :                                 } else if (cursor->hashval <= be32_to_cpu(
     380             :                                                 entries[0].hashval)) {
     381         325 :                                         trace_xfs_attr_list_wrong_blk(context);
     382         325 :                                         xfs_trans_brelse(context->tp, bp);
     383         325 :                                         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     1960543 :         if (bp == NULL) {
     400     1960522 :                 error = xfs_attr_node_list_lookup(context, cursor, &bp);
     401     1960510 :                 if (error || !bp)
     402             :                         return error;
     403             :         }
     404     1960531 :         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   309181007 :         for (;;) {
     412   309181007 :                 leaf = bp->b_addr;
     413   309181007 :                 error = xfs_attr3_leaf_list_int(bp, context);
     414   309180886 :                 if (error)
     415             :                         break;
     416   309180886 :                 xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &leafhdr, leaf);
     417   309181042 :                 if (context->seen_enough || leafhdr.forw == 0)
     418             :                         break;
     419   307220487 :                 cursor->blkno = leafhdr.forw;
     420   307220487 :                 xfs_trans_brelse(context->tp, bp);
     421   307220595 :                 error = xfs_attr3_leaf_read(context->tp, dp, dp->i_ino,
     422             :                                 cursor->blkno, &bp);
     423   307220476 :                 if (error)
     424           0 :                         return error;
     425             :         }
     426     1960555 :         xfs_trans_brelse(context->tp, bp);
     427     1960555 :         return error;
     428             : }
     429             : 
     430             : /*
     431             :  * Copy out attribute list entries for attr_list(), for leaf attribute lists.
     432             :  */
     433             : int
     434   398224010 : xfs_attr3_leaf_list_int(
     435             :         struct xfs_buf                  *bp,
     436             :         struct xfs_attr_list_context    *context)
     437             : {
     438   398224010 :         struct xfs_attrlist_cursor_kern *cursor = &context->cursor;
     439   398224010 :         struct xfs_attr_leafblock       *leaf;
     440   398224010 :         struct xfs_attr3_icleaf_hdr     ichdr;
     441   398224010 :         struct xfs_attr_leaf_entry      *entries;
     442   398224010 :         struct xfs_attr_leaf_entry      *entry;
     443   398224010 :         int                             i;
     444   398224010 :         struct xfs_mount                *mp = context->dp->i_mount;
     445             : 
     446   398224010 :         trace_xfs_attr_list_leaf(context);
     447             : 
     448   398225763 :         leaf = bp->b_addr;
     449   398225763 :         xfs_attr3_leaf_hdr_from_disk(mp->m_attr_geo, &ichdr, leaf);
     450   398234097 :         entries = xfs_attr3_leaf_entryp(leaf);
     451             : 
     452   398234097 :         cursor->initted = 1;
     453             : 
     454             :         /*
     455             :          * Re-find our place in the leaf block if this is a new syscall.
     456             :          */
     457   398234097 :         if (context->resynch) {
     458             :                 entry = &entries[0];
     459   100709278 :                 for (i = 0; i < ichdr.count; entry++, i++) {
     460   200214838 :                         if (be32_to_cpu(entry->hashval) == cursor->hashval) {
     461     9091265 :                                 if (cursor->offset == context->dupcnt) {
     462         365 :                                         context->dupcnt = 0;
     463         365 :                                         break;
     464             :                                 }
     465     9090900 :                                 context->dupcnt++;
     466    91016154 :                         } else if (be32_to_cpu(entry->hashval) >
     467             :                                         cursor->hashval) {
     468    91014700 :                                 context->dupcnt = 0;
     469    91014700 :                                 break;
     470             :                         }
     471             :                 }
     472    91616924 :                 if (i == ichdr.count) {
     473      601859 :                         trace_xfs_attr_list_notfound(context);
     474      601859 :                         return 0;
     475             :                 }
     476             :         } else {
     477             :                 entry = &entries[0];
     478             :                 i = 0;
     479             :         }
     480   397632238 :         context->resynch = 0;
     481             : 
     482             :         /*
     483             :          * We have found our place, start copying out the new attributes.
     484             :          */
     485  7107929056 :         for (; i < ichdr.count; entry++, i++) {
     486  6710295594 :                 char *name;
     487  6710295594 :                 void *value;
     488  6710295594 :                 int namelen, valuelen;
     489             : 
     490 13420591188 :                 if (be32_to_cpu(entry->hashval) != cursor->hashval) {
     491  2166703474 :                         cursor->hashval = be32_to_cpu(entry->hashval);
     492  2166703474 :                         cursor->offset = 0;
     493             :                 }
     494             : 
     495  6710295594 :                 if ((entry->flags & XFS_ATTR_INCOMPLETE) &&
     496           0 :                     !context->allow_incomplete)
     497           0 :                         continue;
     498             : 
     499  6710295594 :                 if (entry->flags & XFS_ATTR_LOCAL) {
     500  6710295366 :                         xfs_attr_leaf_name_local_t *name_loc;
     501             : 
     502  6710295366 :                         name_loc = xfs_attr3_leaf_name_local(leaf, i);
     503  6710295366 :                         name = name_loc->nameval;
     504  6710295366 :                         namelen = name_loc->namelen;
     505  6710295366 :                         value = &name_loc->nameval[name_loc->namelen];
     506  6710295366 :                         valuelen = be16_to_cpu(name_loc->valuelen);
     507             :                 } else {
     508         228 :                         xfs_attr_leaf_name_remote_t *name_rmt;
     509             : 
     510         228 :                         name_rmt = xfs_attr3_leaf_name_remote(leaf, i);
     511         228 :                         name = name_rmt->name;
     512         228 :                         namelen = name_rmt->namelen;
     513         228 :                         value = NULL;
     514         228 :                         valuelen = be32_to_cpu(name_rmt->valuelen);
     515             :                 }
     516             : 
     517  6710295594 :                 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  6729010468 :                 context->put_listent(context, entry->flags,
     524             :                                               name, namelen, value, valuelen);
     525  6710297187 :                 if (context->seen_enough)
     526             :                         break;
     527  6710296818 :                 cursor->offset++;
     528             :         }
     529   397633831 :         trace_xfs_attr_list_leaf_end(context);
     530   397633831 :         return 0;
     531             : }
     532             : 
     533             : /*
     534             :  * Copy out attribute entries for attr_list(), for leaf attribute lists.
     535             :  */
     536             : STATIC int
     537    89054308 : xfs_attr_leaf_list(
     538             :         struct xfs_attr_list_context    *context)
     539             : {
     540    89054308 :         struct xfs_buf                  *bp;
     541    89054308 :         int                             error;
     542             : 
     543    89054308 :         trace_xfs_attr_leaf_list(context);
     544             : 
     545    89059594 :         context->cursor.blkno = 0;
     546    89059594 :         error = xfs_attr3_leaf_read(context->tp, context->dp,
     547             :                         context->dp->i_ino, 0, &bp);
     548    89045405 :         if (error)
     549             :                 return error;
     550             : 
     551    89045263 :         error = xfs_attr3_leaf_list_int(bp, context);
     552    89055224 :         xfs_trans_brelse(context->tp, bp);
     553    89055224 :         return error;
     554             : }
     555             : 
     556             : int
     557   287140987 : xfs_attr_list_ilocked(
     558             :         struct xfs_attr_list_context    *context)
     559             : {
     560   287140987 :         struct xfs_inode                *dp = context->dp;
     561             : 
     562   287140987 :         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   287148058 :         if (!xfs_inode_hasattr(dp))
     568             :                 return 0;
     569   285057219 :         if (dp->i_af.if_format == XFS_DINODE_FMT_LOCAL)
     570   194035427 :                 return xfs_attr_shortform_list(context);
     571    91021792 :         if (xfs_attr_is_leaf(dp))
     572    89056336 :                 return xfs_attr_leaf_list(context);
     573     1960561 :         return xfs_attr_node_list(context);
     574             : }
     575             : 
     576             : int
     577   287125592 : xfs_attr_list(
     578             :         struct xfs_attr_list_context    *context)
     579             : {
     580   287125592 :         struct xfs_inode                *dp = context->dp;
     581   287125592 :         uint                            lock_mode;
     582   287125592 :         int                             error;
     583             : 
     584   287125592 :         XFS_STATS_INC(dp->i_mount, xs_attr_list);
     585             : 
     586   574251184 :         if (xfs_is_shutdown(dp->i_mount))
     587             :                 return -EIO;
     588             : 
     589   287125592 :         lock_mode = xfs_ilock_attr_map_shared(dp);
     590   287148432 :         error = xfs_attr_list_ilocked(context);
     591   287119774 :         xfs_iunlock(dp, lock_mode);
     592   287119774 :         return error;
     593             : }

Generated by: LCOV version 1.14