xfs: fix di_metatype field of inodes that won't load
authorDarrick J. Wong <djwong@kernel.org>
Mon, 4 Nov 2024 04:18:59 +0000 (20:18 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 5 Nov 2024 21:38:34 +0000 (13:38 -0800)
Make sure that the di_metatype field is at least set plausibly so that
later scrubbers could set the real type.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/scrub/inode.c
fs/xfs/scrub/inode_repair.c

index ac5c564..25ee66e 100644 (file)
@@ -443,8 +443,13 @@ xchk_dinode(
                break;
        case 2:
        case 3:
-               if (!xfs_dinode_is_metadir(dip) && dip->di_metatype)
-                       xchk_ino_set_corrupt(sc, ino);
+               if (xfs_dinode_is_metadir(dip)) {
+                       if (be16_to_cpu(dip->di_metatype) >= XFS_METAFILE_MAX)
+                               xchk_ino_set_corrupt(sc, ino);
+               } else {
+                       if (dip->di_metatype != 0)
+                               xchk_ino_set_corrupt(sc, ino);
+               }
 
                if (dip->di_mode == 0 && sc->ip)
                        xchk_ino_set_corrupt(sc, ino);
index eaa1e1a..5a58ddd 100644 (file)
@@ -526,8 +526,12 @@ xrep_dinode_nlinks(
                return;
        }
 
-       if (!xfs_dinode_is_metadir(dip))
+       if (xfs_dinode_is_metadir(dip)) {
+               if (be16_to_cpu(dip->di_metatype) >= XFS_METAFILE_MAX)
+                       dip->di_metatype = cpu_to_be16(XFS_METAFILE_UNKNOWN);
+       } else {
                dip->di_metatype = 0;
+       }
 }
 
 /* Fix any conflicting flags that the verifiers complain about. */