fs/xfs/scrub/parent.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/parent.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/parent.c- Extension
.c- Size
- 23534 bytes
- Lines
- 953
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
xfs_platform.hxfs_fs.hxfs_shared.hxfs_format.hxfs_trans_resv.hxfs_mount.hxfs_log_format.hxfs_trans.hxfs_inode.hxfs_icache.hxfs_dir2.hxfs_dir2_priv.hxfs_attr.hxfs_parent.hscrub/scrub.hscrub/common.hscrub/readdir.hscrub/tempfile.hscrub/repair.hscrub/listxattr.hscrub/xfile.hscrub/xfarray.hscrub/xfblob.hscrub/trace.h
Detected Declarations
struct xchk_parent_ctxstruct xchk_pptrstruct xchk_pptrsfunction Copyrightfunction xchk_parent_actorfunction xchk_parent_ilock_dirfunction xchk_parent_validatefunction xchk_parent_scan_dotdotfunction xchk_parent_pptr_and_dotdotfunction xchk_parent_lock_dirfunction xchk_parent_direntfunction xchk_parent_igetfunction xchk_parent_scan_attrfunction xchk_parent_revalidate_pptrfunction xchk_parent_slow_pptrfunction xchk_parent_finish_slow_pptrsfunction foreach_xfarray_idxfunction xchk_parent_count_pptrfunction xchk_parent_count_pptrsfunction xchk_parent_pptrfunction xchk_parentfunction xchk_pptr_looks_zapped
Annotated Snippet
struct xchk_parent_ctx {
struct xfs_scrub *sc;
xfs_nlink_t nlink;
};
/* Look for a single entry in a directory pointing to an inode. */
STATIC int
xchk_parent_actor(
struct xfs_scrub *sc,
struct xfs_inode *dp,
xfs_dir2_dataptr_t dapos,
const struct xfs_name *name,
xfs_ino_t ino,
void *priv)
{
struct xchk_parent_ctx *spc = priv;
int error = 0;
/* Does this name make sense? */
if (!xfs_dir2_namecheck(name->name, name->len))
error = -EFSCORRUPTED;
if (!xchk_fblock_xref_process_error(sc, XFS_DATA_FORK, 0, &error))
return error;
if (I_INO(sc->ip) == ino)
spc->nlink++;
if (xchk_should_terminate(spc->sc, &error))
return error;
return 0;
}
/*
* Try to lock a parent directory for checking dirents. Returns the inode
* flags for the locks we now hold, or zero if we failed.
*/
STATIC unsigned int
xchk_parent_ilock_dir(
struct xfs_inode *dp)
{
if (!xfs_ilock_nowait(dp, XFS_ILOCK_SHARED))
return 0;
if (!xfs_need_iread_extents(&dp->i_df))
return XFS_ILOCK_SHARED;
xfs_iunlock(dp, XFS_ILOCK_SHARED);
if (!xfs_ilock_nowait(dp, XFS_ILOCK_EXCL))
return 0;
return XFS_ILOCK_EXCL;
}
/*
* Given the inode number of the alleged parent of the inode being scrubbed,
* try to validate that the parent has exactly one directory entry pointing
* back to the inode being scrubbed. Returns -EAGAIN if we need to revalidate
* the dotdot entry.
*/
STATIC int
xchk_parent_validate(
struct xfs_scrub *sc,
xfs_ino_t parent_ino)
{
struct xchk_parent_ctx spc = {
.sc = sc,
.nlink = 0,
};
struct xfs_mount *mp = sc->mp;
xfs_ino_t ino = I_INO(sc->ip);
struct xfs_inode *dp = NULL;
xfs_nlink_t expected_nlink;
unsigned int lock_mode;
int error = 0;
/* Is this the root dir? Then '..' must point to itself. */
if (sc->ip == mp->m_rootip) {
if (ino != mp->m_sb.sb_rootino || ino != parent_ino)
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
return 0;
}
/* Is this the metadata root dir? Then '..' must point to itself. */
if (sc->ip == mp->m_metadirip) {
if (ino != mp->m_sb.sb_metadirino || ino != parent_ino)
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, 0);
return 0;
}
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_log_format.h`, `xfs_trans.h`.
- Detected declarations: `struct xchk_parent_ctx`, `struct xchk_pptr`, `struct xchk_pptrs`, `function Copyright`, `function xchk_parent_actor`, `function xchk_parent_ilock_dir`, `function xchk_parent_validate`, `function xchk_parent_scan_dotdot`, `function xchk_parent_pptr_and_dotdot`, `function xchk_parent_lock_dir`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.