fs/ocfs2/extent_map.c
Source file repositories/reference/linux-study-clean/fs/ocfs2/extent_map.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ocfs2/extent_map.c- Extension
.c- Size
- 24866 bytes
- Lines
- 1048
- 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/fs.hlinux/init.hlinux/slab.hlinux/types.hlinux/fiemap.hcluster/masklog.hocfs2.halloc.hdlmglue.hextent_map.hinode.hsuper.hsymlink.haops.hocfs2_trace.hbuffer_head_io.h
Detected Declarations
function Copyrightfunction __ocfs2_extent_map_lookupfunction list_for_each_entryfunction ocfs2_extent_map_lookupfunction ocfs2_extent_map_truncfunction list_for_each_entry_safefunction ocfs2_ei_is_containedfunction ocfs2_copy_emi_fieldsfunction ocfs2_try_to_merge_extent_mapfunction ocfs2_ei_is_containedfunction ocfs2_extent_map_insert_recfunction list_for_each_entryfunction ocfs2_last_eb_is_emptyfunction ocfs2_search_for_hole_indexfunction ocfs2_figure_hole_clustersfunction ocfs2_get_clusters_nocachefunction ocfs2_relative_extent_offsetsfunction ocfs2_xattr_get_clustersfunction ocfs2_get_clustersfunction ocfs2_extent_map_get_blocksfunction ocfs2_fiemap_inlinefunction ocfs2_fiemapfunction ocfs2_inode_is_fast_symlinkfunction ocfs2_overwrite_iofunction ocfs2_seek_data_hole_offsetfunction ocfs2_read_virt_blocks
Annotated Snippet
if (cpos >= emi->ei_cpos && cpos < range) {
list_move(&emi->ei_list, &em->em_list);
*ret_emi = emi;
break;
}
}
}
static int ocfs2_extent_map_lookup(struct inode *inode, unsigned int cpos,
unsigned int *phys, unsigned int *len,
unsigned int *flags)
{
unsigned int coff;
struct ocfs2_inode_info *oi = OCFS2_I(inode);
struct ocfs2_extent_map_item *emi;
spin_lock(&oi->ip_lock);
__ocfs2_extent_map_lookup(&oi->ip_extent_map, cpos, &emi);
if (emi) {
coff = cpos - emi->ei_cpos;
*phys = emi->ei_phys + coff;
if (len)
*len = emi->ei_clusters - coff;
if (flags)
*flags = emi->ei_flags;
}
spin_unlock(&oi->ip_lock);
if (emi == NULL)
return -ENOENT;
return 0;
}
/*
* Forget about all clusters equal to or greater than cpos.
*/
void ocfs2_extent_map_trunc(struct inode *inode, unsigned int cpos)
{
struct ocfs2_extent_map_item *emi, *n;
struct ocfs2_inode_info *oi = OCFS2_I(inode);
struct ocfs2_extent_map *em = &oi->ip_extent_map;
LIST_HEAD(tmp_list);
unsigned int range;
spin_lock(&oi->ip_lock);
list_for_each_entry_safe(emi, n, &em->em_list, ei_list) {
if (emi->ei_cpos >= cpos) {
/* Full truncate of this record. */
list_move(&emi->ei_list, &tmp_list);
BUG_ON(em->em_num_items == 0);
em->em_num_items--;
continue;
}
range = emi->ei_cpos + emi->ei_clusters;
if (range > cpos) {
/* Partial truncate */
emi->ei_clusters = cpos - emi->ei_cpos;
}
}
spin_unlock(&oi->ip_lock);
list_for_each_entry_safe(emi, n, &tmp_list, ei_list) {
list_del(&emi->ei_list);
kfree(emi);
}
}
/*
* Is any part of emi2 contained within emi1
*/
static int ocfs2_ei_is_contained(struct ocfs2_extent_map_item *emi1,
struct ocfs2_extent_map_item *emi2)
{
unsigned int range1, range2;
/*
* Check if logical start of emi2 is inside emi1
*/
range1 = emi1->ei_cpos + emi1->ei_clusters;
if (emi2->ei_cpos >= emi1->ei_cpos && emi2->ei_cpos < range1)
return 1;
/*
* Check if logical end of emi2 is inside emi1
*/
Annotation
- Immediate include surface: `linux/fs.h`, `linux/init.h`, `linux/slab.h`, `linux/types.h`, `linux/fiemap.h`, `cluster/masklog.h`, `ocfs2.h`, `alloc.h`.
- Detected declarations: `function Copyright`, `function __ocfs2_extent_map_lookup`, `function list_for_each_entry`, `function ocfs2_extent_map_lookup`, `function ocfs2_extent_map_trunc`, `function list_for_each_entry_safe`, `function ocfs2_ei_is_contained`, `function ocfs2_copy_emi_fields`, `function ocfs2_try_to_merge_extent_map`, `function ocfs2_ei_is_contained`.
- 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.