fs/btrfs/backref.c
Source file repositories/reference/linux-study-clean/fs/btrfs/backref.c
File Facts
- System
- Linux kernel
- Corpus path
fs/btrfs/backref.c- Extension
.c- Size
- 103857 bytes
- Lines
- 3695
- 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.
- 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
linux/mm.hlinux/rbtree.htrace/events/btrfs.hctree.hdisk-io.hbackref.hulist.htransaction.hdelayed-ref.hlocking.hmisc.htree-mod-log.hfs.haccessors.hextent-tree.hrelocation.htree-checker.h
Detected Declarations
struct extent_inode_elemstruct preftreestruct preftreesstruct share_checkfunction check_extent_in_ebfunction free_inode_elem_listfunction find_extent_in_ebfunction extent_is_sharedfunction btrfs_prelim_ref_initfunction btrfs_prelim_ref_exitfunction free_preffunction blockfunction prelim_ref_rb_add_cmpfunction update_share_countfunction prelim_ref_insertfunction prelim_releasefunction rbtree_postorder_for_each_entry_safefunction refsfunction add_direct_reffunction add_indirect_reffunction is_shared_data_backreffunction add_all_parentsfunction is_shared_data_backreffunction formfunction unode_aux_to_inode_listfunction free_leaf_listfunction treefunction add_missing_keysfunction add_delayed_refsfunction add_inline_refsfunction add_keyed_refsfunction lookup_backref_shared_cachefunction store_backref_shared_cachefunction backrefsfunction sharedfunction samefunction prelim_ref_insertfunction btrfs_find_all_leafsfunction btrfs_find_all_roots_safefunction btrfs_find_all_rootsfunction btrfs_free_backref_share_ctxfunction callersfunction btrfs_find_one_extreffunction namefunction tofunction get_extent_inline_reffunction modifiedfunction iterate_leaf_refs
Annotated Snippet
struct extent_inode_elem {
u64 inum;
u64 offset;
u64 num_bytes;
struct extent_inode_elem *next;
};
static int check_extent_in_eb(struct btrfs_backref_walk_ctx *ctx,
const struct btrfs_key *key,
const struct extent_buffer *eb,
const struct btrfs_file_extent_item *fi,
struct extent_inode_elem **eie)
{
const u64 data_len = btrfs_file_extent_num_bytes(eb, fi);
u64 offset = key->offset;
struct extent_inode_elem *e;
const u64 *root_ids;
int root_count;
bool cached;
if (!ctx->ignore_extent_item_pos &&
!btrfs_file_extent_compression(eb, fi) &&
!btrfs_file_extent_encryption(eb, fi) &&
!btrfs_file_extent_other_encoding(eb, fi)) {
u64 data_offset;
data_offset = btrfs_file_extent_offset(eb, fi);
if (ctx->extent_item_pos < data_offset ||
ctx->extent_item_pos >= data_offset + data_len)
return 1;
offset += ctx->extent_item_pos - data_offset;
}
if (!ctx->indirect_ref_iterator || !ctx->cache_lookup)
goto add_inode_elem;
cached = ctx->cache_lookup(eb->start, ctx->user_ctx, &root_ids,
&root_count);
if (!cached)
goto add_inode_elem;
for (int i = 0; i < root_count; i++) {
int ret;
ret = ctx->indirect_ref_iterator(key->objectid, offset,
data_len, root_ids[i],
ctx->user_ctx);
if (ret)
return ret;
}
add_inode_elem:
e = kmalloc_obj(*e, GFP_NOFS);
if (!e)
return -ENOMEM;
e->next = *eie;
e->inum = key->objectid;
e->offset = offset;
e->num_bytes = data_len;
*eie = e;
return 0;
}
static void free_inode_elem_list(struct extent_inode_elem *eie)
{
struct extent_inode_elem *eie_next;
for (; eie; eie = eie_next) {
eie_next = eie->next;
kfree(eie);
}
}
static int find_extent_in_eb(struct btrfs_backref_walk_ctx *ctx,
const struct extent_buffer *eb,
struct extent_inode_elem **eie)
{
u64 disk_byte;
struct btrfs_key key;
struct btrfs_file_extent_item *fi;
int slot;
int nritems;
int extent_type;
int ret;
/*
* from the shared data ref, we only have the leaf but we need
Annotation
- Immediate include surface: `linux/mm.h`, `linux/rbtree.h`, `trace/events/btrfs.h`, `ctree.h`, `disk-io.h`, `backref.h`, `ulist.h`, `transaction.h`.
- Detected declarations: `struct extent_inode_elem`, `struct preftree`, `struct preftrees`, `struct share_check`, `function check_extent_in_eb`, `function free_inode_elem_list`, `function find_extent_in_eb`, `function extent_is_shared`, `function btrfs_prelim_ref_init`, `function btrfs_prelim_ref_exit`.
- 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.