/* Calculate the first and last possible inode number in an AG. */ void xfs_agino_range( struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agino_t *first, xfs_agino_t *last) { xfs_agblock_t bno; xfs_agblock_t eoag; eoag = xfs_ag_block_count(mp, agno); /* * Calculate the first inode, which will be in the first * cluster-aligned block after the AGFL. */ bno = round_up(XFS_AGFL_BLOCK(mp) + 1, mp->m_cluster_align); *first = XFS_AGB_TO_AGINO(mp, bno); /* * Calculate the last inode, which will be at the end of the * last (aligned) cluster that can be allocated in the AG. */ bno = round_down(eoag, mp->m_cluster_align); *last = XFS_AGB_TO_AGINO(mp, bno) - 1; }
/* * Verify that an AG block number pointer neither points outside the AG * nor points at static metadata. */ bool xfs_verify_agbno( struct xfs_mount *mp, xfs_agnumber_t agno, xfs_agblock_t agbno) { xfs_agblock_t eoag; eoag = xfs_ag_block_count(mp, agno); if (agbno >= eoag) return false; if (agbno <= XFS_AGFL_BLOCK(mp)) return false; return true; }
xfs_agblock_t xfs_agfl_block(xfs_mount_t *mp) { return XFS_AGFL_BLOCK(mp); }
/* Scrub an rmapbt record. */ STATIC int xchk_rmapbt_rec( struct xchk_btree *bs, union xfs_btree_rec *rec) { struct xfs_mount *mp = bs->cur->bc_mp; struct xfs_rmap_irec irec; xfs_agnumber_t agno = bs->cur->bc_private.a.agno; bool non_inode; bool is_unwritten; bool is_bmbt; bool is_attr; int error; error = xfs_rmap_btrec_to_irec(rec, &irec); if (!xchk_btree_process_error(bs->sc, bs->cur, 0, &error)) goto out; /* Check extent. */ if (irec.rm_startblock + irec.rm_blockcount <= irec.rm_startblock) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); if (irec.rm_owner == XFS_RMAP_OWN_FS) { /* * xfs_verify_agbno returns false for static fs metadata. * Since that only exists at the start of the AG, validate * that by hand. */ if (irec.rm_startblock != 0 || irec.rm_blockcount != XFS_AGFL_BLOCK(mp) + 1) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); } else { /* * Otherwise we must point somewhere past the static metadata * but before the end of the FS. Run the regular check. */ if (!xfs_verify_agbno(mp, agno, irec.rm_startblock) || !xfs_verify_agbno(mp, agno, irec.rm_startblock + irec.rm_blockcount - 1)) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); } /* Check flags. */ non_inode = XFS_RMAP_NON_INODE_OWNER(irec.rm_owner); is_bmbt = irec.rm_flags & XFS_RMAP_BMBT_BLOCK; is_attr = irec.rm_flags & XFS_RMAP_ATTR_FORK; is_unwritten = irec.rm_flags & XFS_RMAP_UNWRITTEN; if (is_bmbt && irec.rm_offset != 0) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); if (non_inode && irec.rm_offset != 0) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); if (is_unwritten && (is_bmbt || non_inode || is_attr)) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); if (non_inode && (is_bmbt || is_unwritten || is_attr)) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); if (!non_inode) { if (!xfs_verify_ino(mp, irec.rm_owner)) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); } else { /* Non-inode owner within the magic values? */ if (irec.rm_owner <= XFS_RMAP_OWN_MIN || irec.rm_owner > XFS_RMAP_OWN_FS) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); } xchk_rmapbt_xref(bs->sc, &irec); out: return error; }