fs/ext4/fsmap.c
Source file repositories/reference/linux-study-clean/fs/ext4/fsmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/fsmap.c- Extension
.c- Size
- 22218 bytes
- Lines
- 793
- 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
ext4.hlinux/fsmap.hfsmap.hmballoc.hlinux/sort.hlinux/list_sort.htrace/events/ext4.h
Detected Declarations
struct ext4_getfsmap_infostruct ext4_getfsmap_devfunction Copyrightfunction ext4_fsmap_to_internalfunction ext4_getfsmap_dev_comparefunction ext4_getfsmap_rec_before_low_keyfunction ext4_getfsmap_helperfunction ext4_fsmap_next_pblkfunction ext4_getfsmap_meta_helperfunction ext4_getfsmap_datadev_helperfunction ext4_group_first_block_nofunction ext4_getfsmap_logdevfunction ext4_getfsmap_fillfunction ext4_getfsmap_find_sbfunction ext4_getfsmap_comparefunction ext4_getfsmap_merge_fixed_metadatafunction list_for_each_entry_safefunction ext4_getfsmap_free_fixed_metadatafunction list_for_each_entry_safefunction ext4_getfsmap_find_fixed_metadatafunction ext4_getfsmap_datadevfunction ext4_getfsmap_is_valid_devicefunction ext4_getfsmap_check_keysfunction ext4_getfsmap
Annotated Snippet
struct ext4_getfsmap_info {
struct ext4_fsmap_head *gfi_head;
ext4_fsmap_format_t gfi_formatter; /* formatting fn */
void *gfi_format_arg;/* format buffer */
ext4_fsblk_t gfi_next_fsblk; /* next fsblock we expect */
u32 gfi_dev; /* device id */
ext4_group_t gfi_agno; /* bg number, if applicable */
struct ext4_fsmap gfi_low; /* low rmap key */
struct ext4_fsmap gfi_high; /* high rmap key */
struct ext4_fsmap gfi_lastfree; /* free ext at end of last bg */
struct list_head gfi_meta_list; /* fixed metadata list */
bool gfi_last; /* last extent? */
};
/* Associate a device with a getfsmap handler. */
struct ext4_getfsmap_dev {
int (*gfd_fn)(struct super_block *sb,
struct ext4_fsmap *keys,
struct ext4_getfsmap_info *info);
u32 gfd_dev;
};
/* Compare two getfsmap device handlers. */
static int ext4_getfsmap_dev_compare(const void *p1, const void *p2)
{
const struct ext4_getfsmap_dev *d1 = p1;
const struct ext4_getfsmap_dev *d2 = p2;
return d1->gfd_dev - d2->gfd_dev;
}
/* Compare a record against our starting point */
static bool ext4_getfsmap_rec_before_low_key(struct ext4_getfsmap_info *info,
struct ext4_fsmap *rec)
{
return rec->fmr_physical + rec->fmr_length <=
info->gfi_low.fmr_physical;
}
/*
* Format a reverse mapping for getfsmap, having translated rm_startblock
* into the appropriate daddr units.
*/
static int ext4_getfsmap_helper(struct super_block *sb,
struct ext4_getfsmap_info *info,
struct ext4_fsmap *rec)
{
struct ext4_fsmap fmr;
struct ext4_sb_info *sbi = EXT4_SB(sb);
ext4_fsblk_t rec_fsblk = rec->fmr_physical;
ext4_group_t agno;
ext4_grpblk_t cno;
int error;
if (fatal_signal_pending(current))
return -EINTR;
/*
* Filter out records that start before our startpoint, if the
* caller requested that.
*/
if (ext4_getfsmap_rec_before_low_key(info, rec)) {
rec_fsblk += rec->fmr_length;
if (info->gfi_next_fsblk < rec_fsblk)
info->gfi_next_fsblk = rec_fsblk;
return EXT4_QUERY_RANGE_CONTINUE;
}
/* Are we just counting mappings? */
if (info->gfi_head->fmh_count == 0) {
if (info->gfi_head->fmh_entries == UINT_MAX)
return EXT4_QUERY_RANGE_ABORT;
if (rec_fsblk > info->gfi_next_fsblk)
info->gfi_head->fmh_entries++;
if (info->gfi_last)
return EXT4_QUERY_RANGE_CONTINUE;
info->gfi_head->fmh_entries++;
rec_fsblk += rec->fmr_length;
if (info->gfi_next_fsblk < rec_fsblk)
info->gfi_next_fsblk = rec_fsblk;
return EXT4_QUERY_RANGE_CONTINUE;
}
/*
* If the record starts past the last physical block we saw,
* then we've found a gap. Report the gap as being owned by
Annotation
- Immediate include surface: `ext4.h`, `linux/fsmap.h`, `fsmap.h`, `mballoc.h`, `linux/sort.h`, `linux/list_sort.h`, `trace/events/ext4.h`.
- Detected declarations: `struct ext4_getfsmap_info`, `struct ext4_getfsmap_dev`, `function Copyright`, `function ext4_fsmap_to_internal`, `function ext4_getfsmap_dev_compare`, `function ext4_getfsmap_rec_before_low_key`, `function ext4_getfsmap_helper`, `function ext4_fsmap_next_pblk`, `function ext4_getfsmap_meta_helper`, `function ext4_getfsmap_datadev_helper`.
- 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.