summaryrefslogtreecommitdiff
path: root/fs/xfs/scrub/trace.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2024-02-22 23:30:51 +0300
committerDarrick J. Wong <djwong@kernel.org>2024-02-22 23:30:51 +0300
commit5385f1a60d4e5b73e8ecd2757865352b68f54fb9 (patch)
tree1a76b9909e0943501456089e5a3bd3457dd24198 /fs/xfs/scrub/trace.c
parent3c79e6a87221e063064e3680946a8b4bcd9fe78d (diff)
downloadlinux-5385f1a60d4e5b73e8ecd2757865352b68f54fb9.tar.xz
xfs: repair file modes by scanning for a dirent pointing to us
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: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'fs/xfs/scrub/trace.c')
-rw-r--r--fs/xfs/scrub/trace.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/fs/xfs/scrub/trace.c b/fs/xfs/scrub/trace.c
index 4542eeebab6f..5ed75cc33b92 100644
--- a/fs/xfs/scrub/trace.c
+++ b/fs/xfs/scrub/trace.c
@@ -16,6 +16,7 @@
#include "xfs_rtbitmap.h"
#include "xfs_quota.h"
#include "xfs_quota_defs.h"
+#include "xfs_da_format.h"
#include "scrub/scrub.h"
#include "scrub/xfile.h"
#include "scrub/xfarray.h"