• Darrick J. Wong's avatar
    xfs: repair file modes by scanning for a dirent pointing to us · 5385f1a6
    Darrick J. Wong authored
    Repair might encounter an inode with a totally garbage i_mode.  To fix
    this problem, we have to figure out if the file was a regular file, a
    directory, or a special file.  One way to figure this out is to check if
    there are any directories with entries pointing down to the busted file.
    
    This patch recovers the file mode by scanning every directory entry on
    the filesystem to see if there are any that point to the busted file.
    If the ftype of all such dirents are consistent, the mode is recovered
    from the ftype.  If no dirents are found, the file becomes a regular
    file.  In all cases, ACLs are canceled and the file is made accessible
    only by root.
    
    A previous patch attempted to guess the mode by reading the beginning of
    the file data.  This was rejected by Christoph on the grounds that we
    cannot trust user-controlled data blocks.  Users do not have direct
    control over the ondisk contents of directory entries, so this method
    should be much safer.
    
    If all the dirents have the same ftype, then we can translate that back
    into an S_IFMT flag and fix the file.  If not, reset the mode to
    S_IFREG.
    Signed-off-by: default avatarDarrick J. Wong <djwong@kernel.org>
    Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
    5385f1a6
trace.h 59.8 KB