Lines Matching +full:mode +full:- +full:flag

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2017-2023 Oracle. All Rights Reserved.
51 /* Install this scrub-by-handle inode and prepare it for scrubbing. */
78 struct xfs_mount *mp = sc->mp; in xchk_setup_inode()
79 struct xfs_inode *ip_in = XFS_I(file_inode(sc->file)); in xchk_setup_inode()
82 xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, sc->sm->sm_ino); in xchk_setup_inode()
89 if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino) { in xchk_setup_inode()
98 if (xfs_internal_inum(mp, sc->sm->sm_ino)) in xchk_setup_inode()
99 return -ENOENT; in xchk_setup_inode()
100 if (!xfs_verify_ino(sc->mp, sc->sm->sm_ino)) in xchk_setup_inode()
101 return -ENOENT; in xchk_setup_inode()
104 error = xchk_iget_safe(sc, sc->sm->sm_ino, &ip); in xchk_setup_inode()
107 if (error == -ENOENT) in xchk_setup_inode()
109 if (error != -EFSCORRUPTED && error != -EFSBADCRC && error != -EINVAL) in xchk_setup_inode()
126 * should flag the corruption and exit to userspace to let it fix the in xchk_setup_inode()
138 error = xchk_iget_agi(sc, sc->sm->sm_ino, &agi_bp, &ip); in xchk_setup_inode()
144 if (error == -ENOENT) in xchk_setup_inode()
146 if (error != -EFSCORRUPTED && error != -EFSBADCRC && error != -EINVAL) in xchk_setup_inode()
152 error = -ECANCELED; in xchk_setup_inode()
167 pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, sc->sm->sm_ino)); in xchk_setup_inode()
169 error = -EFSCORRUPTED; in xchk_setup_inode()
173 error = xfs_imap(pag, sc->tp, sc->sm->sm_ino, &imap, in xchk_setup_inode()
176 if (error == -EINVAL || error == -ENOENT) in xchk_setup_inode()
187 * the inode until we can flag the corruption in xchk_inode. The in xchk_setup_inode()
199 trace_xchk_op_error(sc, agno, XFS_INO_TO_AGBNO(mp, sc->sm->sm_ino), in xchk_setup_inode()
205 return -ENOENT; in xchk_setup_inode()
216 uint16_t mode, in xchk_inode_extsize() argument
220 uint32_t value = be32_to_cpu(dip->di_extsize); in xchk_inode_extsize()
222 fa = xfs_inode_validate_extsize(sc->mp, value, mode, flags); in xchk_inode_extsize()
232 * device. Flag this as an administrative warning since we will clean in xchk_inode_extsize()
237 xfs_extlen_to_rtxmod(sc->mp, value) > 0) in xchk_inode_extsize()
252 uint16_t mode, in xchk_inode_cowextsize() argument
258 fa = xfs_inode_validate_cowextsize(sc->mp, in xchk_inode_cowextsize()
259 be32_to_cpu(dip->di_cowextsize), mode, flags, in xchk_inode_cowextsize()
271 uint16_t mode, in xchk_inode_flags() argument
274 struct xfs_mount *mp = sc->mp; in xchk_inode_flags()
281 if ((flags & XFS_DIFLAG_REALTIME) && !mp->m_rtdev_targp) in xchk_inode_flags()
284 /* new rt bitmap flag only valid for rbmino */ in xchk_inode_flags()
285 if ((flags & XFS_DIFLAG_NEWRTBM) && ino != mp->m_sb.sb_rbmino) in xchk_inode_flags()
288 /* directory-only flags */ in xchk_inode_flags()
293 !S_ISDIR(mode)) in xchk_inode_flags()
296 /* file-only flags */ in xchk_inode_flags()
298 !S_ISREG(mode)) in xchk_inode_flags()
316 uint16_t mode, in xchk_inode_flags2() argument
320 struct xfs_mount *mp = sc->mp; in xchk_inode_flags2()
326 /* reflink flag requires reflink feature */ in xchk_inode_flags2()
331 /* cowextsize flag is checked w.r.t. mode separately */ in xchk_inode_flags2()
333 /* file/dir-only flags */ in xchk_inode_flags2()
334 if ((flags2 & XFS_DIFLAG2_DAX) && !(S_ISREG(mode) || S_ISDIR(mode))) in xchk_inode_flags2()
337 /* file-only flags */ in xchk_inode_flags2()
338 if ((flags2 & XFS_DIFLAG2_REFLINK) && !S_ISREG(mode)) in xchk_inode_flags2()
379 struct xfs_mount *mp = sc->mp; in xchk_dinode()
387 uint16_t mode; in xchk_dinode() local
389 flags = be16_to_cpu(dip->di_flags); in xchk_dinode()
390 if (dip->di_version >= 3) in xchk_dinode()
391 flags2 = be64_to_cpu(dip->di_flags2); in xchk_dinode()
396 mode = be16_to_cpu(dip->di_mode); in xchk_dinode()
397 switch (mode & S_IFMT) { in xchk_dinode()
405 /* mode is recognized */ in xchk_dinode()
413 switch (dip->di_version) { in xchk_dinode()
424 if (dip->di_onlink != 0) in xchk_dinode()
427 if (dip->di_mode == 0 && sc->ip) in xchk_dinode()
430 if (dip->di_projid_hi != 0 && in xchk_dinode()
434 prid = be16_to_cpu(dip->di_projid_lo); in xchk_dinode()
442 prid |= (prid_t)be16_to_cpu(dip->di_projid_hi) << 16; in xchk_dinode()
445 * di_uid/di_gid -- -1 isn't invalid, but there's no way that in xchk_dinode()
448 if (dip->di_uid == cpu_to_be32(-1U) || in xchk_dinode()
449 dip->di_gid == cpu_to_be32(-1U)) in xchk_dinode()
453 * project id of -1 isn't supposed to be valid, but the kernel didn't in xchk_dinode()
456 if (prid == -1U) in xchk_dinode()
460 switch (dip->di_format) { in xchk_dinode()
462 if (!S_ISCHR(mode) && !S_ISBLK(mode) && in xchk_dinode()
463 !S_ISFIFO(mode) && !S_ISSOCK(mode)) in xchk_dinode()
467 if (!S_ISDIR(mode) && !S_ISLNK(mode)) in xchk_dinode()
471 if (!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode)) in xchk_dinode()
475 if (!S_ISREG(mode) && !S_ISDIR(mode)) in xchk_dinode()
485 xchk_dinode_nsec(sc, ino, dip, dip->di_atime); in xchk_dinode()
486 xchk_dinode_nsec(sc, ino, dip, dip->di_mtime); in xchk_dinode()
487 xchk_dinode_nsec(sc, ino, dip, dip->di_ctime); in xchk_dinode()
491 * the VFS such as the upper bit being set and zero-length in xchk_dinode()
494 isize = be64_to_cpu(dip->di_size); in xchk_dinode()
499 if (!S_ISDIR(mode) && !S_ISREG(mode) && !S_ISLNK(mode) && isize != 0) in xchk_dinode()
503 if (S_ISDIR(mode) && (isize == 0 || isize >= XFS_DIR2_SPACE_SIZE)) in xchk_dinode()
507 if (S_ISLNK(mode) && (isize == 0 || isize >= XFS_SYMLINK_MAXLEN)) in xchk_dinode()
514 * overly large offsets, flag the inode for admin review. in xchk_dinode()
516 if (isize > mp->m_super->s_maxbytes) in xchk_dinode()
527 * best we can do without cross-referencing with the in xchk_dinode()
530 if (be64_to_cpu(dip->di_nblocks) >= in xchk_dinode()
531 mp->m_sb.sb_dblocks + mp->m_sb.sb_rblocks) in xchk_dinode()
534 if (be64_to_cpu(dip->di_nblocks) >= mp->m_sb.sb_dblocks) in xchk_dinode()
538 xchk_inode_flags(sc, dip, ino, mode, flags); in xchk_dinode()
540 xchk_inode_extsize(sc, dip, ino, mode, flags); in xchk_dinode()
547 switch (dip->di_format) { in xchk_dinode()
563 if (XFS_DFORK_BOFF(dip) >= mp->m_sb.sb_inodesize) in xchk_dinode()
565 if (naextents != 0 && dip->di_forkoff == 0) in xchk_dinode()
567 if (dip->di_forkoff == 0 && dip->di_aformat != XFS_DINODE_FMT_EXTENTS) in xchk_dinode()
571 if (dip->di_aformat != XFS_DINODE_FMT_LOCAL && in xchk_dinode()
572 dip->di_aformat != XFS_DINODE_FMT_EXTENTS && in xchk_dinode()
573 dip->di_aformat != XFS_DINODE_FMT_BTREE) in xchk_dinode()
578 switch (dip->di_aformat) { in xchk_dinode()
592 if (dip->di_version >= 3) { in xchk_dinode()
593 xchk_dinode_nsec(sc, ino, dip, dip->di_crtime); in xchk_dinode()
594 xchk_inode_flags2(sc, dip, ino, mode, flags, flags2); in xchk_dinode()
595 xchk_inode_cowextsize(sc, dip, ino, mode, flags, in xchk_dinode()
615 if (!sc->sa.fino_cur || xchk_skip_xref(sc->sm)) in xchk_inode_xref_finobt()
618 agino = XFS_INO_TO_AGINO(sc->mp, ino); in xchk_inode_xref_finobt()
624 error = xfs_inobt_lookup(sc->sa.fino_cur, agino, XFS_LOOKUP_LE, in xchk_inode_xref_finobt()
626 if (!xchk_should_check_xref(sc, &error, &sc->sa.fino_cur) || in xchk_inode_xref_finobt()
630 error = xfs_inobt_get_rec(sc->sa.fino_cur, &rec, &has_record); in xchk_inode_xref_finobt()
631 if (!xchk_should_check_xref(sc, &error, &sc->sa.fino_cur) || in xchk_inode_xref_finobt()
643 if (rec.ir_free & XFS_INOBT_MASK(agino - rec.ir_startino)) in xchk_inode_xref_finobt()
644 xchk_btree_xref_set_corrupt(sc, sc->sa.fino_cur, 0); in xchk_inode_xref_finobt()
658 if (xchk_skip_xref(sc->sm)) in xchk_inode_xref_bmap()
662 error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_DATA_FORK, in xchk_inode_xref_bmap()
667 xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino); in xchk_inode_xref_bmap()
669 error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_ATTR_FORK, in xchk_inode_xref_bmap()
674 xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino); in xchk_inode_xref_bmap()
677 if (count + acount != be64_to_cpu(dip->di_nblocks)) in xchk_inode_xref_bmap()
678 xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino); in xchk_inode_xref_bmap()
681 /* Cross-reference with the other btrees. */
692 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_inode_xref()
695 agno = XFS_INO_TO_AGNO(sc->mp, ino); in xchk_inode_xref()
696 agbno = XFS_INO_TO_AGBNO(sc->mp, ino); in xchk_inode_xref()
698 error = xchk_ag_init_existing(sc, agno, &sc->sa); in xchk_inode_xref()
710 xchk_ag_free(sc, &sc->sa); in xchk_inode_xref()
715 * either flag an error (shared extents w/ no flag) or a preen (flag set w/o
724 struct xfs_mount *mp = sc->mp; in xchk_inode_check_reflink_iflag()
731 error = xfs_reflink_inode_has_shared_extents(sc->tp, sc->ip, in xchk_inode_check_reflink_iflag()
736 if (xfs_is_reflink_inode(sc->ip) && !has_shared) in xchk_inode_check_reflink_iflag()
738 else if (!xfs_is_reflink_inode(sc->ip) && has_shared) in xchk_inode_check_reflink_iflag()
750 if (VFS_I(sc->ip)->i_nlink == 0) { in xchk_inode_check_unlinked()
751 if (!xfs_inode_on_unlinked_list(sc->ip)) in xchk_inode_check_unlinked()
752 xchk_ino_set_corrupt(sc, sc->ip->i_ino); in xchk_inode_check_unlinked()
754 if (xfs_inode_on_unlinked_list(sc->ip)) in xchk_inode_check_unlinked()
755 xchk_ino_set_corrupt(sc, sc->ip->i_ino); in xchk_inode_check_unlinked()
768 * If sc->ip is NULL, that means that the setup function called in xchk_inode()
770 * and a NULL inode, so flag the corruption error and return. in xchk_inode()
772 if (!sc->ip) { in xchk_inode()
773 xchk_ino_set_corrupt(sc, sc->sm->sm_ino); in xchk_inode()
778 xfs_inode_to_disk(sc->ip, &di, 0); in xchk_inode()
779 xchk_dinode(sc, &di, sc->ip->i_ino); in xchk_inode()
780 if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) in xchk_inode()
785 * iflag. We already checked the iflag against the file mode when in xchk_inode()
788 if (S_ISREG(VFS_I(sc->ip)->i_mode)) in xchk_inode()
789 xchk_inode_check_reflink_iflag(sc, sc->ip->i_ino); in xchk_inode()
793 xchk_inode_xref(sc, sc->ip->i_ino, &di); in xchk_inode()