fs/ntfs3/bitmap.c
Source file repositories/reference/linux-study-clean/fs/ntfs3/bitmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/ntfs3/bitmap.c- Extension
.c- Size
- 33314 bytes
- Lines
- 1565
- 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
linux/buffer_head.hlinux/fs.hlinux/kernel.hntfs.hntfs_fs.h
Detected Declarations
struct rb_node_keystruct e_nodefunction ntfs3_init_bitmapfunction ntfs3_exit_bitmapfunction wnd_scanfunction wnd_closefunction rb_insert_countfunction rb_insert_startfunction wnd_add_free_extfunction wnd_remove_free_extfunction wnd_rescanfunction wnd_initfunction wnd_set_freefunction wnd_set_usedfunction wnd_set_used_safefunction wnd_is_free_hlpfunction wnd_is_freefunction wnd_is_usedfunction wnd_findfunction wnd_extendfunction wnd_zone_setfunction ntfs_trim_fsfunction ntfs_bitmap_set_lefunction ntfs_bitmap_clear_lefunction ntfs_bitmap_weight_le
Annotated Snippet
struct rb_node_key {
struct rb_node node;
size_t key;
};
struct e_node {
struct rb_node_key start; /* Tree sorted by start. */
struct rb_node_key count; /* Tree sorted by len. */
};
static int wnd_rescan(struct wnd_bitmap *wnd);
static struct buffer_head *wnd_map(struct wnd_bitmap *wnd, size_t iw);
static bool wnd_is_free_hlp(struct wnd_bitmap *wnd, size_t bit, size_t bits);
static struct kmem_cache *ntfs_enode_cachep;
int __init ntfs3_init_bitmap(void)
{
ntfs_enode_cachep = kmem_cache_create("ntfs3_enode_cache",
sizeof(struct e_node), 0,
SLAB_RECLAIM_ACCOUNT, NULL);
return ntfs_enode_cachep ? 0 : -ENOMEM;
}
void ntfs3_exit_bitmap(void)
{
kmem_cache_destroy(ntfs_enode_cachep);
}
/*
* wnd_scan
*
* b_pos + b_len - biggest fragment.
* Scan range [wpos wbits) window @buf.
*
* Return: -1 if not found.
*/
static size_t wnd_scan(const void *buf, size_t wbit, u32 wpos, u32 wend,
size_t to_alloc, size_t *prev_tail, size_t *b_pos,
size_t *b_len)
{
while (wpos < wend) {
size_t free_len;
u32 free_bits, end;
u32 used = find_next_zero_bit_le(buf, wend, wpos);
if (used >= wend) {
if (*b_len < *prev_tail) {
*b_pos = wbit - *prev_tail;
*b_len = *prev_tail;
}
*prev_tail = 0;
return -1;
}
if (used > wpos) {
wpos = used;
if (*b_len < *prev_tail) {
*b_pos = wbit - *prev_tail;
*b_len = *prev_tail;
}
*prev_tail = 0;
}
/*
* Now we have a fragment [wpos, wend) staring with 0.
*/
end = wpos + to_alloc - *prev_tail;
free_bits = find_next_bit_le(buf, min(end, wend), wpos);
free_len = *prev_tail + free_bits - wpos;
if (*b_len < free_len) {
*b_pos = wbit + wpos - *prev_tail;
*b_len = free_len;
}
if (free_len >= to_alloc)
return wbit + wpos - *prev_tail;
if (free_bits >= wend) {
*prev_tail += free_bits - wpos;
return -1;
}
wpos = free_bits + 1;
*prev_tail = 0;
Annotation
- Immediate include surface: `linux/buffer_head.h`, `linux/fs.h`, `linux/kernel.h`, `ntfs.h`, `ntfs_fs.h`.
- Detected declarations: `struct rb_node_key`, `struct e_node`, `function ntfs3_init_bitmap`, `function ntfs3_exit_bitmap`, `function wnd_scan`, `function wnd_close`, `function rb_insert_count`, `function rb_insert_start`, `function wnd_add_free_ext`, `function wnd_remove_free_ext`.
- 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.