fs/xfs/scrub/dir.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/dir.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/dir.c- Extension
.c- Size
- 31213 bytes
- Lines
- 1184
- 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_health.hxfs_attr.hxfs_parent.hscrub/scrub.hscrub/common.hscrub/dabtree.hscrub/readdir.hscrub/health.hscrub/repair.hscrub/trace.hscrub/xfile.hscrub/xfarray.hscrub/xfblob.h
Detected Declarations
struct xchk_direntstruct xchk_dirfunction Copyrightfunction xchk_dir_check_ftypefunction xchk_dir_lock_childfunction xchk_dir_parent_pointerfunction xchk_dir_check_pptr_fastfunction xchk_dir_actorfunction xchk_dir_recfunction xchk_directory_check_free_entryfunction xchk_directory_data_bestfreefunction blockfunction xchk_directory_leaf1_bestfreefunction thisfunction xchk_directory_free_bestfreefunction xchk_directory_blocksfunction xchk_dir_revalidate_direntfunction xchk_dir_slow_direntfunction xchk_dir_finish_slow_direntsfunction foreach_xfarray_idxfunction xchk_directoryfunction xchk_dir_looks_zapped
Annotated Snippet
struct xchk_dirent {
/* Cookie for retrieval of the dirent name. */
xfblob_cookie name_cookie;
/* Child inode number. */
xfs_ino_t ino;
/* Length of the pptr name. */
uint8_t namelen;
};
struct xchk_dir {
struct xfs_scrub *sc;
/* information for parent pointer validation. */
struct xfs_parent_rec pptr_rec;
struct xfs_da_args pptr_args;
/* Fixed-size array of xchk_dirent structures. */
struct xfarray *dir_entries;
/* Blobs containing dirent names. */
struct xfblob *dir_names;
/* If we've cycled the ILOCK, we must revalidate deferred dirents. */
bool need_revalidate;
/* Name buffer for dirent revalidation. */
struct xfs_name xname;
uint8_t namebuf[MAXNAMELEN];
};
/* Scrub a directory entry. */
/* Check that an inode's mode matches a given XFS_DIR3_FT_* type. */
STATIC void
xchk_dir_check_ftype(
struct xfs_scrub *sc,
xfs_fileoff_t offset,
struct xfs_inode *ip,
int ftype)
{
struct xfs_mount *mp = sc->mp;
if (!xfs_has_ftype(mp)) {
if (ftype != XFS_DIR3_FT_UNKNOWN && ftype != XFS_DIR3_FT_DIR)
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
return;
}
if (xfs_mode_to_ftype(VFS_I(ip)->i_mode) != ftype)
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
/*
* Metadata and regular inodes cannot cross trees. This property
* cannot change without a full inode free and realloc cycle, so it's
* safe to check this without holding locks.
*/
if (xfs_is_metadir_inode(ip) != xfs_is_metadir_inode(sc->ip))
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, offset);
}
/*
* Try to lock a child file for checking parent pointers. Returns the inode
* flags for the locks we now hold, or zero if we failed.
*/
STATIC unsigned int
xchk_dir_lock_child(
struct xfs_scrub *sc,
struct xfs_inode *ip)
{
if (!xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED))
return 0;
if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) {
xfs_iunlock(ip, XFS_IOLOCK_SHARED);
return 0;
}
if (!xfs_inode_has_attr_fork(ip) || !xfs_need_iread_extents(&ip->i_af))
return XFS_IOLOCK_SHARED | XFS_ILOCK_SHARED;
xfs_iunlock(ip, XFS_ILOCK_SHARED);
if (!xfs_ilock_nowait(ip, XFS_ILOCK_EXCL)) {
xfs_iunlock(ip, XFS_IOLOCK_SHARED);
return 0;
}
return XFS_IOLOCK_SHARED | XFS_ILOCK_EXCL;
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_dirent`, `struct xchk_dir`, `function Copyright`, `function xchk_dir_check_ftype`, `function xchk_dir_lock_child`, `function xchk_dir_parent_pointer`, `function xchk_dir_check_pptr_fast`, `function xchk_dir_actor`, `function xchk_dir_rec`, `function xchk_directory_check_free_entry`.
- 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.