Lines Matching +full:ip +full:- +full:block

1 // SPDX-License-Identifier: GPL-2.0+
26 struct xfs_inode *ip) in xchk_setup_directory() argument
28 return xchk_setup_inode_contents(sc, ip, 0); in xchk_setup_directory()
36 /* VFS fill-directory iterator */
50 struct xfs_mount *mp = sdc->sc->mp; in xchk_dir_check_ftype()
51 struct xfs_inode *ip; in xchk_dir_check_ftype() local
55 if (!xfs_sb_version_hasftype(&mp->m_sb)) { in xchk_dir_check_ftype()
57 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, in xchk_dir_check_ftype()
70 error = xfs_iget(mp, sdc->sc->tp, inum, 0, 0, &ip); in xchk_dir_check_ftype()
71 if (!xchk_fblock_xref_process_error(sdc->sc, XFS_DATA_FORK, offset, in xchk_dir_check_ftype()
77 xfs_mode_to_ftype(VFS_I(ip)->i_mode)); in xchk_dir_check_ftype()
79 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, offset); in xchk_dir_check_ftype()
80 xfs_irele(ip); in xchk_dir_check_ftype()
103 struct xfs_inode *ip; in xchk_dir_actor() local
111 ip = sdc->sc->ip; in xchk_dir_actor()
112 mp = ip->i_mount; in xchk_dir_actor()
113 offset = xfs_dir2_db_to_da(mp->m_dir_geo, in xchk_dir_actor()
114 xfs_dir2_dataptr_to_db(mp->m_dir_geo, pos)); in xchk_dir_actor()
116 if (xchk_should_terminate(sdc->sc, &error)) in xchk_dir_actor()
121 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, offset); in xchk_dir_actor()
127 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, offset); in xchk_dir_actor()
133 if (xfs_sb_version_hasftype(&mp->m_sb) && type != DT_DIR) in xchk_dir_actor()
134 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, in xchk_dir_actor()
136 if (ino != ip->i_ino) in xchk_dir_actor()
137 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, in xchk_dir_actor()
144 if (xfs_sb_version_hasftype(&mp->m_sb) && type != DT_DIR) in xchk_dir_actor()
145 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, in xchk_dir_actor()
147 if (ip->i_ino == mp->m_sb.sb_rootino && ino != ip->i_ino) in xchk_dir_actor()
148 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, in xchk_dir_actor()
157 error = xfs_dir_lookup(sdc->sc->tp, ip, &xname, &lookup_ino, NULL); in xchk_dir_actor()
159 if (error == -ENOENT) in xchk_dir_actor()
160 error = -EFSCORRUPTED; in xchk_dir_actor()
161 if (!xchk_fblock_process_error(sdc->sc, XFS_DATA_FORK, offset, in xchk_dir_actor()
165 xchk_fblock_set_corrupt(sdc->sc, XFS_DATA_FORK, offset); in xchk_dir_actor()
179 if (error == 0 && sdc->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_dir_actor()
180 return -EFSCORRUPTED; in xchk_dir_actor()
190 struct xfs_da_state_blk *blk = &ds->state->path.blk[level]; in xchk_dir_rec()
191 struct xfs_mount *mp = ds->state->mp; in xchk_dir_rec()
192 struct xfs_inode *dp = ds->dargs.dp; in xchk_dir_rec()
193 struct xfs_da_geometry *geo = mp->m_dir_geo; in xchk_dir_rec()
210 ASSERT(blk->magic == XFS_DIR2_LEAF1_MAGIC || in xchk_dir_rec()
211 blk->magic == XFS_DIR2_LEAFN_MAGIC); in xchk_dir_rec()
213 xfs_dir2_leaf_hdr_from_disk(mp, &hdr, blk->bp->b_addr); in xchk_dir_rec()
214 ent = hdr.ents + blk->index; in xchk_dir_rec()
217 error = xchk_da_btree_hash(ds, level, &ent->hashval); in xchk_dir_rec()
222 ptr = be32_to_cpu(ent->address); in xchk_dir_rec()
231 if (rec_bno >= geo->leafblk) { in xchk_dir_rec()
235 error = xfs_dir3_data_read(ds->dargs.trans, dp, rec_bno, in xchk_dir_rec()
237 if (!xchk_fblock_process_error(ds->sc, XFS_DATA_FORK, rec_bno, in xchk_dir_rec()
241 xchk_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno); in xchk_dir_rec()
244 xchk_buffer_recheck(ds->sc, bp); in xchk_dir_rec()
246 if (ds->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_dir_rec()
249 dent = bp->b_addr + off; in xchk_dir_rec()
252 iter_off = geo->data_entry_offset; in xchk_dir_rec()
253 end = xfs_dir3_data_end_offset(geo, bp->b_addr); in xchk_dir_rec()
255 xchk_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno); in xchk_dir_rec()
259 struct xfs_dir2_data_entry *dep = bp->b_addr + iter_off; in xchk_dir_rec()
260 struct xfs_dir2_data_unused *dup = bp->b_addr + iter_off; in xchk_dir_rec()
263 xchk_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno); in xchk_dir_rec()
267 if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { in xchk_dir_rec()
268 iter_off += be16_to_cpu(dup->length); in xchk_dir_rec()
273 iter_off += xfs_dir2_data_entsize(mp, dep->namelen); in xchk_dir_rec()
277 ino = be64_to_cpu(dent->inumber); in xchk_dir_rec()
278 hash = be32_to_cpu(ent->hashval); in xchk_dir_rec()
281 xchk_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno); in xchk_dir_rec()
282 if (dent->namelen == 0) { in xchk_dir_rec()
283 xchk_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno); in xchk_dir_rec()
286 calc_hash = xfs_da_hashname(dent->name, dent->namelen); in xchk_dir_rec()
288 xchk_fblock_set_corrupt(ds->sc, XFS_DATA_FORK, rec_bno); in xchk_dir_rec()
291 xfs_trans_brelse(ds->dargs.trans, bp); in xchk_dir_rec()
311 dup_length = be16_to_cpu(dup->length); in xchk_directory_check_free_entry()
314 if (dup_length < be16_to_cpu(bf[XFS_DIR2_DATA_FD_COUNT - 1].length)) in xchk_directory_check_free_entry()
317 for (dfp = &bf[XFS_DIR2_DATA_FD_COUNT - 1]; dfp >= bf; dfp--) in xchk_directory_check_free_entry()
318 if (dup_length == be16_to_cpu(dfp->length)) in xchk_directory_check_free_entry()
325 /* Check free space info in a directory data block. */
336 struct xfs_mount *mp = sc->mp; in xchk_directory_data_bestfree()
347 /* dir block format */ in xchk_directory_data_bestfree()
350 error = xfs_dir3_block_read(sc->tp, sc->ip, &bp); in xchk_directory_data_bestfree()
353 error = xfs_dir3_data_read(sc->tp, sc->ip, lblk, 0, &bp); in xchk_directory_data_bestfree()
361 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory_data_bestfree()
365 bf = xfs_dir2_data_bestfree_p(mp, bp->b_addr); in xchk_directory_data_bestfree()
368 offset = be16_to_cpu(dfp->offset); in xchk_directory_data_bestfree()
371 if (offset >= mp->m_dir_geo->blksize) { in xchk_directory_data_bestfree()
375 dup = bp->b_addr + offset; in xchk_directory_data_bestfree()
379 if (dup->freetag != cpu_to_be16(XFS_DIR2_DATA_FREE_TAG) || in xchk_directory_data_bestfree()
380 be16_to_cpu(dup->length) != be16_to_cpu(dfp->length) || in xchk_directory_data_bestfree()
387 if (smallest_bestfree < be16_to_cpu(dfp->length)) { in xchk_directory_data_bestfree()
392 smallest_bestfree = be16_to_cpu(dfp->length); in xchk_directory_data_bestfree()
397 offset = mp->m_dir_geo->data_entry_offset; in xchk_directory_data_bestfree()
398 end = xfs_dir3_data_end_offset(mp->m_dir_geo, bp->b_addr); in xchk_directory_data_bestfree()
402 dup = bp->b_addr + offset; in xchk_directory_data_bestfree()
405 if (dup->freetag != cpu_to_be16(XFS_DIR2_DATA_FREE_TAG)) { in xchk_directory_data_bestfree()
406 struct xfs_dir2_data_entry *dep = bp->b_addr + offset; in xchk_directory_data_bestfree()
408 newlen = xfs_dir2_data_entsize(mp, dep->namelen); in xchk_directory_data_bestfree()
430 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory_data_bestfree()
434 newlen = be16_to_cpu(dup->length); in xchk_directory_data_bestfree()
452 xfs_trans_brelse(sc->tp, bp); in xchk_directory_data_bestfree()
458 * Does the free space length in the free space index block ($len) match
459 * the longest length in the directory data block's bestfree array?
460 * Assume that we've already checked that the data block's bestfree
472 dfp = xfs_dir2_data_bestfree_p(sc->mp, dbp->b_addr); in xchk_directory_check_freesp()
474 if (len != be16_to_cpu(dfp->length)) in xchk_directory_check_freesp()
477 if (len > 0 && be16_to_cpu(dfp->offset) == 0) in xchk_directory_check_freesp()
481 /* Check free space info in a directory leaf1 block. */
493 struct xfs_da_geometry *geo = sc->mp->m_dir_geo; in xchk_directory_leaf1_bestfree()
503 /* Read the free space block. */ in xchk_directory_leaf1_bestfree()
504 error = xfs_dir3_leaf_read(sc->tp, sc->ip, lblk, &bp); in xchk_directory_leaf1_bestfree()
509 leaf = bp->b_addr; in xchk_directory_leaf1_bestfree()
510 xfs_dir2_leaf_hdr_from_disk(sc->ip->i_mount, &leafhdr, leaf); in xchk_directory_leaf1_bestfree()
512 bestcount = be32_to_cpu(ltp->bestcount); in xchk_directory_leaf1_bestfree()
515 if (xfs_sb_version_hascrc(&sc->mp->m_sb)) { in xchk_directory_leaf1_bestfree()
516 struct xfs_dir3_leaf_hdr *hdr3 = bp->b_addr; in xchk_directory_leaf1_bestfree()
518 if (hdr3->pad != cpu_to_be32(0)) in xchk_directory_leaf1_bestfree()
526 if (bestcount != xfs_dir2_byte_to_db(geo, sc->ip->i_d.di_size)) { in xchk_directory_leaf1_bestfree()
532 if (leafhdr.count > geo->leaf_max_ents) { in xchk_directory_leaf1_bestfree()
555 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory_leaf1_bestfree()
561 error = xfs_dir3_data_read(sc->tp, sc->ip, in xchk_directory_leaf1_bestfree()
562 xfs_dir2_db_to_da(args->geo, i), in xchk_directory_leaf1_bestfree()
582 xfs_trans_brelse(sc->tp, dbp); in xchk_directory_leaf1_bestfree()
583 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory_leaf1_bestfree()
587 xfs_trans_brelse(sc->tp, bp); in xchk_directory_leaf1_bestfree()
591 /* Check free space info in a directory freespace block. */
606 /* Read the free space block */ in xchk_directory_free_bestfree()
607 error = xfs_dir2_free_read(sc->tp, sc->ip, lblk, &bp); in xchk_directory_free_bestfree()
612 if (xfs_sb_version_hascrc(&sc->mp->m_sb)) { in xchk_directory_free_bestfree()
613 struct xfs_dir3_free_hdr *hdr3 = bp->b_addr; in xchk_directory_free_bestfree()
615 if (hdr3->pad != cpu_to_be32(0)) in xchk_directory_free_bestfree()
620 xfs_dir2_free_hdr_from_disk(sc->ip->i_mount, &freehdr, bp->b_addr); in xchk_directory_free_bestfree()
627 error = xfs_dir3_data_read(sc->tp, sc->ip, in xchk_directory_free_bestfree()
628 (freehdr.firstdb + i) * args->geo->fsbcount, in xchk_directory_free_bestfree()
634 xfs_trans_brelse(sc->tp, dbp); in xchk_directory_free_bestfree()
640 xfs_trans_brelse(sc->tp, bp); in xchk_directory_free_bestfree()
651 struct xfs_ifork *ifp = XFS_IFORK_PTR(sc->ip, XFS_DATA_FORK); in xchk_directory_blocks()
652 struct xfs_mount *mp = sc->mp; in xchk_directory_blocks()
663 if (ifp->if_format != XFS_DINODE_FMT_EXTENTS && in xchk_directory_blocks()
664 ifp->if_format != XFS_DINODE_FMT_BTREE) in xchk_directory_blocks()
671 /* Is this a block dir? */ in xchk_directory_blocks()
672 args.dp = sc->ip; in xchk_directory_blocks()
673 args.geo = mp->m_dir_geo; in xchk_directory_blocks()
674 args.trans = sc->tp; in xchk_directory_blocks()
680 found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got); in xchk_directory_blocks()
681 while (found && !(sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) { in xchk_directory_blocks()
682 /* Block directories only have a single block at offset 0. */ in xchk_directory_blocks()
685 got.br_blockcount != args.geo->fsbcount)) { in xchk_directory_blocks()
696 * Check each data block's bestfree data. in xchk_directory_blocks()
698 * Iterate all the fsbcount-aligned block offsets in in xchk_directory_blocks()
699 * this directory. The directory block reading code is in xchk_directory_blocks()
702 * with the extent record, re-query the bmap at the in xchk_directory_blocks()
703 * next fsbcount-aligned offset to avoid redundant in xchk_directory_blocks()
704 * block checks. in xchk_directory_blocks()
707 args.geo->fsbcount); in xchk_directory_blocks()
709 lblk += args.geo->fsbcount) { in xchk_directory_blocks()
716 lblk = roundup(dabno, args.geo->fsbcount); in xchk_directory_blocks()
717 found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got); in xchk_directory_blocks()
720 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory_blocks()
723 /* Look for a leaf1 block, which has free info. */ in xchk_directory_blocks()
724 if (xfs_iext_lookup_extent(sc->ip, ifp, leaf_lblk, &icur, &got) && in xchk_directory_blocks()
726 got.br_blockcount == args.geo->fsbcount && in xchk_directory_blocks()
738 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory_blocks()
743 found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got); in xchk_directory_blocks()
744 while (found && !(sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)) { in xchk_directory_blocks()
747 * Single-block dirs shouldn't even be here. in xchk_directory_blocks()
760 * Check each dir free block's bestfree data. in xchk_directory_blocks()
762 * Iterate all the fsbcount-aligned block offsets in in xchk_directory_blocks()
763 * this directory. The directory block reading code is in xchk_directory_blocks()
766 * with the extent record, re-query the bmap at the in xchk_directory_blocks()
767 * next fsbcount-aligned offset to avoid redundant in xchk_directory_blocks()
768 * block checks. in xchk_directory_blocks()
771 args.geo->fsbcount); in xchk_directory_blocks()
773 lblk += args.geo->fsbcount) { in xchk_directory_blocks()
780 lblk = roundup(dabno, args.geo->fsbcount); in xchk_directory_blocks()
781 found = xfs_iext_lookup_extent(sc->ip, ifp, lblk, &icur, &got); in xchk_directory_blocks()
801 if (!S_ISDIR(VFS_I(sc->ip)->i_mode)) in xchk_directory()
802 return -ENOENT; in xchk_directory()
805 if (sc->ip->i_d.di_size < xfs_dir2_sf_hdr_size(0)) { in xchk_directory()
806 xchk_ino_set_corrupt(sc, sc->ip->i_ino); in xchk_directory()
815 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory()
823 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_directory()
831 sc->ip->i_d.di_size); in xchk_directory()
850 sc->ilock_flags &= ~XFS_ILOCK_EXCL; in xchk_directory()
851 xfs_iunlock(sc->ip, XFS_ILOCK_EXCL); in xchk_directory()
853 error = xfs_readdir(sc->tp, sc->ip, &sdc.dir_iter, bufsize); in xchk_directory()