error = xfs_dir_lookup(sdc->sc->tp, ip, &xname, &lookup_ino, NULL);
        if (!xfs_scrub_fblock_process_error(sdc->sc, XFS_DATA_FORK, offset,
                        &error))
-               goto fail_xref;
+               goto out;
        if (lookup_ino != ino) {
                xfs_scrub_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, offset);
                goto out;
        if (error)
                goto out;
 out:
-       return error;
-fail_xref:
+       /*
+        * A negative error code returned here is supposed to cause the
+        * dir_emit caller (xfs_readdir) to abort the directory iteration
+        * and return zero to xfs_scrub_directory.
+        */
+       if (error == 0 && sdc->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+               return -EFSCORRUPTED;
        return error;
 }
 
        }
        xfs_scrub_buffer_recheck(ds->sc, bp);
 
+       if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+               goto out_relse;
+
        dent = (struct xfs_dir2_data_entry *)(((char *)bp->b_addr) + off);
 
        /* Make sure we got a real directory entry. */
 
        /* XXX: Check xfs_dir3_data_hdr.pad is zero once we start setting it. */
 
+       if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+               goto out_buf;
+
        /* Do the bestfrees correspond to actual free space? */
        bf = d_ops->data_bestfree_p(bp->b_addr);
        smallest_bestfree = UINT_MAX;
 
                /* Spot check this free entry */
                tag = be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup));
-               if (tag != ((char *)dup - (char *)bp->b_addr))
+               if (tag != ((char *)dup - (char *)bp->b_addr)) {
                        xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk);
+                       goto out_buf;
+               }
 
                /*
                 * Either this entry is a bestfree or it's smaller than
                 * any of the bestfrees.
                 */
                xfs_scrub_directory_check_free_entry(sc, lblk, bf, dup);
+               if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+                       goto out_buf;
 
                /* Move on. */
                newlen = be16_to_cpu(dup->length);
        }
        if (leafhdr.stale != stale)
                xfs_scrub_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk);
+       if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+               goto out;
 
        /* Check all the bestfree entries. */
        for (i = 0; i < bestcount; i++, bestp++) {
                                i * args->geo->fsbcount, -1, &dbp);
                if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk,
                                &error))
-                       continue;
+                       break;
                xfs_scrub_directory_check_freesp(sc, lblk, dbp, best);
                xfs_trans_brelse(sc->tp, dbp);
+               if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
+                       goto out;
        }
 out:
        return error;
                                -1, &dbp);
                if (!xfs_scrub_fblock_process_error(sc, XFS_DATA_FORK, lblk,
                                &error))
-                       continue;
+                       break;
                xfs_scrub_directory_check_freesp(sc, lblk, dbp, best);
                xfs_trans_brelse(sc->tp, dbp);
        }
 
        /* Iterate all the data extents in the directory... */
        found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got);
-       while (found) {
+       while (found && !(sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) {
                /* Block directories only have a single block at offset 0. */
                if (is_block &&
                    (got.br_startoff > 0 ||
        /* Scan for free blocks */
        lblk = free_lblk;
        found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got);
-       while (found) {
+       while (found && !(sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) {
                /*
                 * Dirs can't have blocks mapped above 2^32.
                 * Single-block dirs shouldn't even be here.