xfs: move orphan files to lost and found [v30.3 10/16]

Orphaned files are defined to be files with nonzero ondisk link count
 but no observable parent directory.  This series enables online repair
 to reparent orphaned files into the filesystem directory tree, and wires
 up this reparenting ability into the directory, file link count, and
 parent pointer repair functions.  This is how we fix files with positive
 link count that are not reachable through the directory tree.
 
 This patch will also create the orphanage directory (lost+found) if it
 is not present.  In contrast to xfs_repair, we follow e2fsck in creating
 the lost+found without group or other-owner access to avoid accidental
 disclosure of files that were previously hidden by an 0700 directory.
 That's silly security, but people have been known to do it.
 
 This has been running on the djcloud for months with no problems.  Enjoy!
 
 Signed-off-by: Darrick J. Wong <djwong@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQQ2qTKExjcn+O1o2YRKO3ySh0YRpgUCZh23UwAKCRBKO3ySh0YR
 pnJ8AP4kTiYucq40QUjYbG9xZGxbRenrgtwmBltcn6Xzm9PUVAD+KrU1GQ5Qm2zW
 /Kl5nDRM9zqJgQ5CQiBGuu3puHfnOgw=
 =vJ6T
 -----END PGP SIGNATURE-----

Merge tag 'repair-orphanage-6.10_2024-04-15' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.10-mergeA

xfs: move orphan files to lost and found

Orphaned files are defined to be files with nonzero ondisk link count
but no observable parent directory.  This series enables online repair
to reparent orphaned files into the filesystem directory tree, and wires
up this reparenting ability into the directory, file link count, and
parent pointer repair functions.  This is how we fix files with positive
link count that are not reachable through the directory tree.

This patch will also create the orphanage directory (lost+found) if it
is not present.  In contrast to xfs_repair, we follow e2fsck in creating
the lost+found without group or other-owner access to avoid accidental
disclosure of files that were previously hidden by an 0700 directory.
That's silly security, but people have been known to do it.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>

* tag 'repair-orphanage-6.10_2024-04-15' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux:
  xfs: ensure dentry consistency when the orphanage adopts a file
  xfs: move files to orphanage instead of letting nlinks drop to zero
  xfs: move orphan files to the orphanage
This commit is contained in:
Chandan Babu R 2024-04-16 12:18:18 +05:30
commit 067d3f7100
16 changed files with 1139 additions and 38 deletions