fs/xfs/libxfs/xfs_bmap.c
Source file repositories/reference/linux-study-clean/fs/xfs/libxfs/xfs_bmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/xfs/libxfs/xfs_bmap.c- Extension
.c- Size
- 170167 bytes
- Lines
- 6265
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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_log_format.hxfs_trans_resv.hxfs_bit.hxfs_sb.hxfs_mount.hxfs_defer.hxfs_dir2.hxfs_inode.hxfs_btree.hxfs_trans.hxfs_alloc.hxfs_bmap.hxfs_bmap_util.hxfs_bmap_btree.hxfs_rtbitmap.hxfs_errortag.hxfs_error.hxfs_quota.hxfs_trans_space.hxfs_buf_item.hxfs_trace.hxfs_attr_leaf.hxfs_filestream.hxfs_rmap.hxfs_ag.hxfs_ag_resv.hxfs_refcount.hxfs_iomap.h
Detected Declarations
struct xfs_iread_statestruct xfs_bmap_query_rangefunction xfs_bmap_compute_attr_offsetfunction xfs_bmap_needs_btreefunction xfs_bmap_wants_extentsfunction worksfunction xfs_default_attroffsetfunction xfs_bmap_forkoff_resetfunction xfs_bmap_get_bpfunction xfs_check_blockfunction pointerfunction xfs_bmap_validate_retfunction for_each_xfs_iextfunction xfs_bmap_local_to_extents_emptyfunction xfs_bmap_set_attrforkofffunction xfs_bmap_complain_bad_recfunction xfs_iread_bmbt_blockfunction xfs_iread_extentsfunction xfs_bmap_last_extentfunction xfs_bmap_isaeoffunction xfs_bmap_last_offsetfunction xfs_bmap_same_rtgroupfunction xfs_bmap_adjacent_validfunction xfs_bmap_adjacent_validfunction xfs_bmap_longest_free_extentfunction xfs_bmap_select_minlenfunction xfs_bmap_btalloc_select_lengthsfunction xfs_bmap_alloc_accountfunction xfs_bmap_compute_alignmentsfunction xfs_bmap_process_allocated_extentfunction xfs_bmap_exact_minlen_extent_allocfunction xfs_bmap_btalloc_at_eoffunction xfs_bmap_btalloc_low_spacefunction xfs_bmap_btalloc_filestreamsfunction xfs_bmap_btalloc_best_lengthfunction xfs_bmap_btallocfunction xfs_trim_extentfunction xfs_bmapi_trim_mapfunction xfs_bmapi_update_mapfunction xfs_bmapi_readfunction xfs_bmapi_allocatefunction xfs_bmapi_convert_unwrittenfunction xfs_bmapi_minleftfunction xfs_bmapi_finishfunction xfs_bmapi_convert_one_delallocfunction xfs_bmapi_convert_delallocfunction xfs_bmapi_remapfunction xfs_bmap_del_extent_cow
Annotated Snippet
struct xfs_iread_state {
struct xfs_iext_cursor icur;
xfs_extnum_t loaded;
};
int
xfs_bmap_complain_bad_rec(
struct xfs_inode *ip,
int whichfork,
xfs_failaddr_t fa,
const struct xfs_bmbt_irec *irec)
{
struct xfs_mount *mp = ip->i_mount;
const char *forkname;
switch (whichfork) {
case XFS_DATA_FORK: forkname = "data"; break;
case XFS_ATTR_FORK: forkname = "attr"; break;
case XFS_COW_FORK: forkname = "CoW"; break;
default: forkname = "???"; break;
}
xfs_warn(mp,
"Bmap BTree record corruption in inode 0x%llx %s fork detected at %pS!",
I_INO(ip), forkname, fa);
xfs_warn(mp,
"Offset 0x%llx, start block 0x%llx, block count 0x%llx state 0x%x",
irec->br_startoff, irec->br_startblock, irec->br_blockcount,
irec->br_state);
return -EFSCORRUPTED;
}
/* Stuff every bmbt record from this block into the incore extent map. */
static int
xfs_iread_bmbt_block(
struct xfs_btree_cur *cur,
int level,
void *priv)
{
struct xfs_iread_state *ir = priv;
struct xfs_mount *mp = cur->bc_mp;
struct xfs_inode *ip = cur->bc_ino.ip;
struct xfs_btree_block *block;
struct xfs_buf *bp;
struct xfs_bmbt_rec *frp;
xfs_extnum_t num_recs;
xfs_extnum_t j;
int whichfork = cur->bc_ino.whichfork;
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork);
block = xfs_btree_get_block(cur, level, &bp);
/* Abort if we find more records than nextents. */
num_recs = xfs_btree_get_numrecs(block);
if (unlikely(ir->loaded + num_recs > ifp->if_nextents)) {
xfs_warn(ip->i_mount, "corrupt dinode %llu, (btree extents).",
(unsigned long long)I_INO(ip));
xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, block,
sizeof(*block), __this_address);
xfs_bmap_mark_sick(ip, whichfork);
return -EFSCORRUPTED;
}
/* Copy records into the incore cache. */
frp = xfs_bmbt_rec_addr(mp, block, 1);
for (j = 0; j < num_recs; j++, frp++, ir->loaded++) {
struct xfs_bmbt_irec new;
xfs_failaddr_t fa;
xfs_bmbt_disk_get_all(frp, &new);
fa = xfs_bmap_validate_extent(ip, whichfork, &new);
if (fa) {
xfs_inode_verifier_error(ip, -EFSCORRUPTED,
"xfs_iread_extents(2)", frp,
sizeof(*frp), fa);
xfs_bmap_mark_sick(ip, whichfork);
return xfs_bmap_complain_bad_rec(ip, whichfork, fa,
&new);
}
xfs_iext_insert(ip, &ir->icur, &new,
xfs_bmap_fork_to_state(whichfork));
trace_xfs_read_extent(ip, &ir->icur,
xfs_bmap_fork_to_state(whichfork), _THIS_IP_);
xfs_iext_next(ifp, &ir->icur);
}
return 0;
}
Annotation
- Immediate include surface: `xfs_platform.h`, `xfs_fs.h`, `xfs_shared.h`, `xfs_format.h`, `xfs_log_format.h`, `xfs_trans_resv.h`, `xfs_bit.h`, `xfs_sb.h`.
- Detected declarations: `struct xfs_iread_state`, `struct xfs_bmap_query_range`, `function xfs_bmap_compute_attr_offset`, `function xfs_bmap_needs_btree`, `function xfs_bmap_wants_extents`, `function works`, `function xfs_default_attroffset`, `function xfs_bmap_forkoff_reset`, `function xfs_bmap_get_bp`, `function xfs_check_block`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.