fs/ext4/balloc.c
Source file repositories/reference/linux-study-clean/fs/ext4/balloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext4/balloc.c- Extension
.c- Size
- 29718 bytes
- Lines
- 1004
- 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
linux/time.hlinux/capability.hlinux/fs.hlinux/quotaops.hlinux/buffer_head.hext4.hext4_jbd2.hmballoc.htrace/events/ext4.hkunit/static_stub.h
Detected Declarations
function ext4_get_group_numberfunction ext4_get_group_no_and_offsetfunction ext4_block_in_groupfunction ext4_num_overhead_clustersfunction num_clusters_in_groupfunction ext4_init_block_bitmapfunction ext4_free_clusters_after_initfunction mountedfunction add_new_gdbfunction ext4_valid_block_bitmap_paddingfunction ext4_valid_block_bitmapfunction ext4_validate_block_bitmapfunction ext4_simulate_failfunction ext4_read_block_bitmap_nowaitfunction ext4_wait_block_bitmapfunction ext4_read_block_bitmapfunction ext4_has_free_clustersfunction capablefunction ext4_claim_free_clustersfunction ext4_should_retry_allocfunction ext4_new_meta_blocksfunction ext4_count_free_clustersfunction test_rootfunction superblockfunction ext4_bg_num_gdb_metafunction ext4_bg_num_gdb_nometafunction ext4_bg_num_gdbfunction ext4_num_base_meta_blocksfunction ext4_num_base_meta_clustersfunction ext4_inode_to_goal_block
Annotated Snippet
ext4_simulate_fail(sb, EXT4_SIM_BBITMAP_CRC))) {
ext4_unlock_group(sb, block_group);
ext4_error(sb, "bg %u: bad block bitmap checksum", block_group);
ext4_mark_group_bitmap_corrupted(sb, block_group,
EXT4_GROUP_INFO_BBITMAP_CORRUPT);
return -EFSBADCRC;
}
blk = ext4_valid_block_bitmap(sb, desc, block_group, bh);
if (unlikely(blk != 0)) {
ext4_unlock_group(sb, block_group);
ext4_error(sb, "bg %u: block %llu: invalid block bitmap",
block_group, blk);
ext4_mark_group_bitmap_corrupted(sb, block_group,
EXT4_GROUP_INFO_BBITMAP_CORRUPT);
return -EFSCORRUPTED;
}
blk = ext4_valid_block_bitmap_padding(sb, block_group, bh);
if (unlikely(blk != 0)) {
ext4_unlock_group(sb, block_group);
ext4_error(sb, "bg %u: block %llu: padding at end of block bitmap is not set",
block_group, blk);
ext4_mark_group_bitmap_corrupted(sb, block_group,
EXT4_GROUP_INFO_BBITMAP_CORRUPT);
return -EFSCORRUPTED;
}
set_buffer_verified(bh);
verified:
ext4_unlock_group(sb, block_group);
return 0;
}
/**
* ext4_read_block_bitmap_nowait()
* @sb: super block
* @block_group: given block group
* @ignore_locked: ignore locked buffers
*
* Read the bitmap for a given block_group,and validate the
* bits for block/inode/inode tables are set in the bitmaps
*
* Return buffer_head on success or an ERR_PTR in case of failure.
*/
struct buffer_head *
ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group,
bool ignore_locked)
{
struct ext4_group_desc *desc;
struct ext4_sb_info *sbi = EXT4_SB(sb);
struct buffer_head *bh;
ext4_fsblk_t bitmap_blk;
int err;
KUNIT_STATIC_STUB_REDIRECT(ext4_read_block_bitmap_nowait,
sb, block_group, ignore_locked);
desc = ext4_get_group_desc(sb, block_group, NULL);
if (!desc)
return ERR_PTR(-EFSCORRUPTED);
bitmap_blk = ext4_block_bitmap(sb, desc);
if ((bitmap_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
(bitmap_blk >= ext4_blocks_count(sbi->s_es))) {
ext4_error(sb, "Invalid block bitmap block %llu in "
"block_group %u", bitmap_blk, block_group);
ext4_mark_group_bitmap_corrupted(sb, block_group,
EXT4_GROUP_INFO_BBITMAP_CORRUPT);
return ERR_PTR(-EFSCORRUPTED);
}
bh = sb_getblk(sb, bitmap_blk);
if (unlikely(!bh)) {
ext4_warning(sb, "Cannot get buffer for block bitmap - "
"block_group = %u, block_bitmap = %llu",
block_group, bitmap_blk);
return ERR_PTR(-ENOMEM);
}
if (ignore_locked && buffer_locked(bh)) {
/* buffer under IO already, return if called for prefetching */
put_bh(bh);
return NULL;
}
if (bitmap_uptodate(bh))
goto verify;
lock_buffer(bh);
if (bitmap_uptodate(bh)) {
unlock_buffer(bh);
goto verify;
}
ext4_lock_group(sb, block_group);
Annotation
- Immediate include surface: `linux/time.h`, `linux/capability.h`, `linux/fs.h`, `linux/quotaops.h`, `linux/buffer_head.h`, `ext4.h`, `ext4_jbd2.h`, `mballoc.h`.
- Detected declarations: `function ext4_get_group_number`, `function ext4_get_group_no_and_offset`, `function ext4_block_in_group`, `function ext4_num_overhead_clusters`, `function num_clusters_in_group`, `function ext4_init_block_bitmap`, `function ext4_free_clusters_after_init`, `function mounted`, `function add_new_gdb`, `function ext4_valid_block_bitmap_padding`.
- 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.