fs/ext2/balloc.c
Source file repositories/reference/linux-study-clean/fs/ext2/balloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ext2/balloc.c- Extension
.c- Size
- 46019 bytes
- Lines
- 1536
- 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
ext2.hlinux/quotaops.hlinux/slab.hlinux/sched.hlinux/cred.hlinux/buffer_head.hlinux/capability.h
Detected Declarations
function Copyrightfunction ext2_valid_block_bitmapfunction read_block_bitmapfunction group_adjust_blocksfunction __rsv_window_dumpfunction goal_in_my_reservationfunction search_reserve_windowfunction ext2_rsv_window_addfunction rsv_window_removefunction rsv_is_emptyfunction ext2_init_block_alloc_infofunction ext2_discard_reservationfunction ext2_free_blocksfunction bitmap_search_next_usable_blockfunction find_next_usable_blockfunction ext2_try_to_allocatefunction find_next_reservable_windowfunction listfunction try_to_extend_reservationfunction ext2_try_to_allocate_with_rsvfunction ext2_has_free_blocksfunction ext2_data_block_validfunction ext2_new_blocksfunction ext2_count_freefunction ext2_count_free_blocksfunction test_rootfunction ext2_group_sparsefunction superblockfunction ext2_bg_num_gdb
Annotated Snippet
if (rsv->rsv_start && rsv->rsv_start >= rsv->rsv_end) {
printk("Bad reservation %p (start >= end)\n",
rsv);
bad = 1;
}
if (prev && prev->rsv_end >= rsv->rsv_start) {
printk("Bad reservation %p (prev->end >= start)\n",
rsv);
bad = 1;
}
if (bad) {
if (!verbose) {
printk("Restarting reservation walk in verbose mode\n");
verbose = 1;
goto restart;
}
}
n = rb_next(n);
prev = rsv;
}
printk("Window map complete.\n");
BUG_ON(bad);
}
#define rsv_window_dump(root, verbose) \
__rsv_window_dump((root), (verbose), __func__)
#else
#define rsv_window_dump(root, verbose) do {} while (0)
#endif /* EXT2FS_DEBUG */
/**
* goal_in_my_reservation()
* @rsv: inode's reservation window
* @grp_goal: given goal block relative to the allocation block group
* @group: the current allocation block group
* @sb: filesystem super block
*
* Test if the given goal block (group relative) is within the file's
* own block reservation window range.
*
* If the reservation window is outside the goal allocation group, return 0;
* grp_goal (given goal block) could be -1, which means no specific
* goal block. In this case, always return 1.
* If the goal block is within the reservation window, return 1;
* otherwise, return 0;
*/
static int
goal_in_my_reservation(struct ext2_reserve_window *rsv, ext2_grpblk_t grp_goal,
unsigned int group, struct super_block * sb)
{
ext2_fsblk_t group_first_block, group_last_block;
group_first_block = ext2_group_first_block_no(sb, group);
group_last_block = ext2_group_last_block_no(sb, group);
if ((rsv->_rsv_start > group_last_block) ||
(rsv->_rsv_end < group_first_block))
return 0;
if ((grp_goal >= 0) && ((grp_goal + group_first_block < rsv->_rsv_start)
|| (grp_goal + group_first_block > rsv->_rsv_end)))
return 0;
return 1;
}
/**
* search_reserve_window()
* @root: root of reservation tree
* @goal: target allocation block
*
* Find the reserved window which includes the goal, or the previous one
* if the goal is not in any window.
* Returns NULL if there are no windows or if all windows start after the goal.
*/
static struct ext2_reserve_window_node *
search_reserve_window(struct rb_root *root, ext2_fsblk_t goal)
{
struct rb_node *n = root->rb_node;
struct ext2_reserve_window_node *rsv;
if (!n)
return NULL;
do {
rsv = rb_entry(n, struct ext2_reserve_window_node, rsv_node);
if (goal < rsv->rsv_start)
n = n->rb_left;
else if (goal > rsv->rsv_end)
n = n->rb_right;
else
return rsv;
Annotation
- Immediate include surface: `ext2.h`, `linux/quotaops.h`, `linux/slab.h`, `linux/sched.h`, `linux/cred.h`, `linux/buffer_head.h`, `linux/capability.h`.
- Detected declarations: `function Copyright`, `function ext2_valid_block_bitmap`, `function read_block_bitmap`, `function group_adjust_blocks`, `function __rsv_window_dump`, `function goal_in_my_reservation`, `function search_reserve_window`, `function ext2_rsv_window_add`, `function rsv_window_remove`, `function rsv_is_empty`.
- 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.