{
        xfs_extnum_t    idx;            /* extent record index */
        xfs_ifork_t     *ifp;           /* inode fork pointer */
-       int             state = 0;
-
-       if (whichfork == XFS_ATTR_FORK)
-               state |= BMAP_ATTRFORK;
-       else if (whichfork == XFS_COW_FORK)
-               state |= BMAP_COWFORK;
+       int             state = xfs_bmap_fork_to_state(whichfork);
 
        ifp = XFS_IFORK_PTR(ip, whichfork);
        ASSERT(cnt == xfs_iext_count(ifp));
        rec.br_state = XFS_EXT_NORM;
        xfs_iext_insert(ip, 0, 1, &rec, 0);
 
-       trace_xfs_bmap_post_update(ip, 0,
-                       whichfork == XFS_ATTR_FORK ? BMAP_ATTRFORK : 0,
+       trace_xfs_bmap_post_update(ip, 0, xfs_bmap_fork_to_state(whichfork),
                        _THIS_IP_);
        XFS_IFORK_NEXT_SET(ip, whichfork, 1);
        ip->i_d.di_nblocks = 1;
        xfs_bmbt_irec_t         r[3];   /* neighbor extent entries */
                                        /* left is 0, right is 1, prev is 2 */
        int                     rval=0; /* return value (logging flags) */
-       int                     state = 0;/* state bits, accessed thru macros */
+       int                     state = xfs_bmap_fork_to_state(whichfork);
        xfs_filblks_t           da_new; /* new count del alloc blocks used */
        xfs_filblks_t           da_old; /* old count del alloc blocks used */
        xfs_filblks_t           temp=0; /* value for da_new calculations */
 #define        RIGHT           r[1]
 #define        PREV            r[2]
 
-       if (whichfork == XFS_COW_FORK)
-               state |= BMAP_COWFORK;
-
        /*
         * Set up a bunch of variables to make the tests simpler.
         */
        xfs_bmbt_irec_t         r[3];   /* neighbor extent entries */
                                        /* left is 0, right is 1, prev is 2 */
        int                     rval=0; /* return value (logging flags) */
-       int                     state = 0;/* state bits, accessed thru macros */
+       int                     state = xfs_bmap_fork_to_state(whichfork);
        struct xfs_mount        *mp = ip->i_mount;
        struct xfs_bmbt_irec    old;
 
 
        cur = *curp;
        ifp = XFS_IFORK_PTR(ip, whichfork);
-       if (whichfork == XFS_COW_FORK)
-               state |= BMAP_COWFORK;
 
        ASSERT(*idx >= 0);
        ASSERT(*idx <= xfs_iext_count(ifp));
        xfs_filblks_t           newlen=0;       /* new indirect size */
        xfs_filblks_t           oldlen=0;       /* old indirect size */
        xfs_bmbt_irec_t         right;  /* right neighbor extent entry */
-       int                     state;  /* state bits, accessed thru macros */
+       int                     state = xfs_bmap_fork_to_state(whichfork);
        xfs_filblks_t           temp;    /* temp for indirect calculations */
 
        ifp = XFS_IFORK_PTR(ip, whichfork);
-       state = 0;
-       if (whichfork == XFS_COW_FORK)
-               state |= BMAP_COWFORK;
        ASSERT(isnullstartblock(new->br_startblock));
 
        /*
        xfs_bmbt_irec_t         left;   /* left neighbor extent entry */
        xfs_bmbt_irec_t         right;  /* right neighbor extent entry */
        int                     rval=0; /* return value (logging flags) */
-       int                     state;  /* state bits, accessed thru macros */
+       int                     state = xfs_bmap_fork_to_state(whichfork);
        struct xfs_bmbt_irec    old;
 
        ASSERT(*idx >= 0);
 
        XFS_STATS_INC(mp, xs_add_exlist);
 
-       state = 0;
-       if (whichfork == XFS_ATTR_FORK)
-               state |= BMAP_ATTRFORK;
-       if (whichfork == XFS_COW_FORK)
-               state |= BMAP_COWFORK;
-
        /*
         * Check and set flags if this segment has a left neighbor.
         */
        int64_t                 da_old, da_new, da_diff = 0;
        xfs_fileoff_t           del_endoff, got_endoff;
        xfs_filblks_t           got_indlen, new_indlen, stolen;
-       int                     error = 0, state = 0;
+       int                     state = xfs_bmap_fork_to_state(whichfork);
+       int                     error = 0;
        bool                    isrt;
 
        XFS_STATS_INC(mp, xs_del_exlist);
                return error;
        ip->i_delayed_blks -= del->br_blockcount;
 
-       if (whichfork == XFS_COW_FORK)
-               state |= BMAP_COWFORK;
-
        if (got->br_startoff == del->br_startoff)
                state |= BMAP_LEFT_FILLING;
        if (got_endoff == del_endoff)
        xfs_bmbt_irec_t         new;    /* new record to be inserted */
        /* REFERENCED */
        uint                    qfield; /* quota field to update */
-       int                     state = 0;
+       int                     state = xfs_bmap_fork_to_state(whichfork);
        struct xfs_bmbt_irec    old;
 
        mp = ip->i_mount;
        XFS_STATS_INC(mp, xs_del_exlist);
 
-       if (whichfork == XFS_ATTR_FORK)
-               state |= BMAP_ATTRFORK;
-       else if (whichfork == XFS_COW_FORK)
-               state |= BMAP_COWFORK;
-
        ifp = XFS_IFORK_PTR(ip, whichfork);
        ASSERT((*idx >= 0) && (*idx < xfs_iext_count(ifp)));
        ASSERT(del->br_blockcount > 0);