fs/xfs/scrub/bmap_repair.c
Source file repositories/reference/linux-study-clean/fs/xfs/scrub/bmap_repair.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/scrub/bmap_repair.c- Extension
.c- Size
- 24974 bytes
- Lines
- 993
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- 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_defer.hxfs_btree.hxfs_btree_staging.hxfs_bit.hxfs_log_format.hxfs_trans.hxfs_sb.hxfs_inode.hxfs_inode_fork.hxfs_alloc.hxfs_rtalloc.hxfs_bmap.hxfs_bmap_util.hxfs_bmap_btree.hxfs_rmap.hxfs_rmap_btree.hxfs_rtrmap_btree.hxfs_refcount.hxfs_quota.hxfs_ialloc.hxfs_ag.hxfs_reflink.hxfs_rtgroup.hscrub/xfs_scrub.hscrub/scrub.hscrub/common.h
Detected Declarations
struct xrep_bmapenum reflink_scan_statefunction xrep_bmap_discover_sharedfunction xrep_bmap_from_rmapfunction xrep_bmap_check_fork_rmapfunction xrep_bmap_walk_rmapfunction xrep_bmap_extent_cmpfunction xrep_bmap_sort_recordsfunction foreach_xfarray_idxfunction xrep_bmap_scan_agfunction xrep_bmap_check_rtfork_rmapfunction xrep_bmap_walk_rtrmapfunction xrep_bmap_scan_rtgroupfunction xrep_bmap_scan_rtgroupfunction xrep_bmap_find_delallocfunction for_each_xfs_iextfunction xrep_bmap_find_mappingsfunction xrep_bmap_get_recordsfunction xrep_bmap_claim_blockfunction xrep_bmap_iroot_sizefunction xrep_bmap_reset_countersfunction xrep_bmap_extents_loadfunction xrep_bmap_btree_loadfunction xrep_bmap_build_new_forkfunction xrep_bmap_remove_old_treefunction xrep_bmap_check_inputsfunction xrep_bmap_init_reflink_scanfunction xrep_bmapfunction xrep_bmap_datafunction xrep_bmap_attr
Annotated Snippet
struct xrep_bmap {
/* Old bmbt blocks */
struct xfsb_bitmap old_bmbt_blocks;
/* New fork. */
struct xrep_newbt new_bmapbt;
/* List of new bmap records. */
struct xfarray *bmap_records;
struct xfs_scrub *sc;
/* How many blocks did we find allocated to this file? */
xfs_rfsblock_t nblocks;
/* How many bmbt blocks did we find for this fork? */
xfs_rfsblock_t old_bmbt_block_count;
/* get_records()'s position in the free space record array. */
xfarray_idx_t array_cur;
/* How many real (non-hole, non-delalloc) mappings do we have? */
uint64_t real_mappings;
/* Which fork are we fixing? */
int whichfork;
/* What d the REFLINK flag be set when the repair is over? */
enum reflink_scan_state reflink_scan;
/* Do we allow unwritten extents? */
bool allow_unwritten;
};
/* Is this space extent shared? Flag the inode if it is. */
STATIC int
xrep_bmap_discover_shared(
struct xrep_bmap *rb,
xfs_fsblock_t startblock,
xfs_filblks_t blockcount)
{
struct xfs_scrub *sc = rb->sc;
struct xfs_btree_cur *cur;
xfs_agblock_t agbno;
xfs_agblock_t fbno;
xfs_extlen_t flen;
int error;
if (XFS_IS_REALTIME_INODE(sc->ip)) {
agbno = xfs_rtb_to_rgbno(sc->mp, startblock);
cur = sc->sr.refc_cur;
} else {
agbno = XFS_FSB_TO_AGBNO(sc->mp, startblock);
cur = sc->sa.refc_cur;
}
error = xfs_refcount_find_shared(cur, agbno, blockcount, &fbno, &flen,
false);
if (error)
return error;
if (fbno != NULLAGBLOCK)
rb->reflink_scan = RLS_SET_IFLAG;
return 0;
}
/* Remember this reverse-mapping as a series of bmap records. */
STATIC int
xrep_bmap_from_rmap(
struct xrep_bmap *rb,
xfs_fileoff_t startoff,
xfs_fsblock_t startblock,
xfs_filblks_t blockcount,
bool unwritten)
{
struct xfs_bmbt_irec irec = {
.br_startoff = startoff,
.br_startblock = startblock,
.br_state = unwritten ? XFS_EXT_UNWRITTEN : XFS_EXT_NORM,
};
struct xfs_bmbt_rec rbe;
struct xfs_scrub *sc = rb->sc;
int error = 0;
/*
* If we're repairing the data fork of a non-reflinked regular file on
* a reflink filesystem, we need to figure out if this space extent is
* shared.
*/
if (rb->reflink_scan == RLS_UNKNOWN && !unwritten) {
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_trans_resv.h`, `xfs_mount.h`, `xfs_defer.h`, `xfs_btree.h`.
- Detected declarations: `struct xrep_bmap`, `enum reflink_scan_state`, `function xrep_bmap_discover_shared`, `function xrep_bmap_from_rmap`, `function xrep_bmap_check_fork_rmap`, `function xrep_bmap_walk_rmap`, `function xrep_bmap_extent_cmp`, `function xrep_bmap_sort_records`, `function foreach_xfarray_idx`, `function xrep_bmap_scan_ag`.
- 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.