From: Darrick J. Wong <djwong@xxxxxxxxxx> If an inode claims to be a metadata inode but wasn't linked in either directory tree, remove the attr fork and reset the data fork if the contents weren't regular extent mappings before moving the inode to the lost+found. We don't ifree the inode, because it's possible that the inode was not actually a metadata inode but simply got corrupted due to bitflips or something, and we'd rather let the sysadmin examine what's left of the file instead of photorec'ing it. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- repair/phase6.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/repair/phase6.c b/repair/phase6.c index 964342c31d6..13094730407 100644 --- a/repair/phase6.c +++ b/repair/phase6.c @@ -1220,6 +1220,53 @@ mk_orphanage( return(ino); } +/* Don't let metadata inode contents leak to lost+found. */ +static void +trunc_metadata_inode( + struct xfs_inode *ip) +{ + struct xfs_trans *tp; + struct xfs_mount *mp = ip->i_mount; + int err; + + err = -libxfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); + if (err) + do_error( + _("space reservation failed (%d), filesystem may be out of space\n"), + err); + + libxfs_trans_ijoin(tp, ip, 0); + ip->i_diflags2 &= ~XFS_DIFLAG2_METADATA; + + switch (VFS_I(ip)->i_mode & S_IFMT) { + case S_IFIFO: + case S_IFCHR: + case S_IFBLK: + case S_IFSOCK: + ip->i_df.if_format = XFS_DINODE_FMT_DEV; + break; + case S_IFREG: + switch (ip->i_df.if_format) { + case XFS_DINODE_FMT_EXTENTS: + case XFS_DINODE_FMT_BTREE: + break; + default: + ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS; + ip->i_df.if_nextents = 0; + break; + } + break; + } + + libxfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); + + err = -libxfs_trans_commit(tp); + if (err) + do_error( + _("truncation of metadata inode 0x%llx failed, err=%d\n"), + (unsigned long long)ip->i_ino, err); +} + /* * move a file to the orphange. */ @@ -1262,6 +1309,9 @@ mv_orphanage( if (err) do_error(_("%d - couldn't iget disconnected inode\n"), err); + if (xfs_is_metadata_inode(ino_p)) + trunc_metadata_inode(ino_p); + xname.type = libxfs_mode_to_ftype(VFS_I(ino_p)->i_mode); if (isa_dir) {