fs/adfs/map.c
Source file repositories/reference/linux-study-clean/fs/adfs/map.c
File Facts
- System
- Linux kernel
- Corpus path
fs/adfs/map.c- Extension
.c- Size
- 10343 bytes
- Lines
- 408
- 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/slab.hlinux/statfs.hlinux/unaligned.hadfs.h
Detected Declarations
function lookup_zonefunction scan_free_mapfunction scan_mapfunction adfs_map_statfsfunction adfs_map_lookupfunction adfs_calczonecheckfunction adfs_checkmapfunction adfs_map_layoutfunction adfs_map_readfunction adfs_map_relsefunction adfs_free_map
Annotated Snippet
if (start == freelink) {
freelink += frag & 0x7fff;
} else if (frag == frag_id) {
unsigned int length = fragend + 1 - start;
if (*offset < length)
return start + *offset;
*offset -= length;
}
start = fragend + 1;
} while (start < endbit);
return -1;
error:
printk(KERN_ERR "adfs: oversized fragment 0x%x at 0x%x-0x%x\n",
frag, start, fragend);
return -1;
}
/*
* Scan the free space map, for this zone, calculating the total
* number of map bits in each free space fragment.
*
* Note: idmask is limited to 15 bits [3.2]
*/
static unsigned int
scan_free_map(struct adfs_sb_info *asb, struct adfs_discmap *dm)
{
const unsigned int endbit = dm->dm_endbit;
const unsigned int idlen = asb->s_idlen;
const unsigned int frag_idlen = idlen <= 15 ? idlen : 15;
const u32 idmask = (1 << frag_idlen) - 1;
unsigned char *map = dm->dm_bh->b_data;
unsigned int start = 8, fragend;
u32 frag;
unsigned long total = 0;
/*
* get fragment id
*/
frag = GET_FRAG_ID(map, start, idmask);
/*
* If the freelink is null, then no free fragments
* exist in this zone.
*/
if (frag == 0)
return 0;
do {
start += frag;
frag = GET_FRAG_ID(map, start, idmask);
fragend = find_next_bit_le(map, endbit, start + idlen);
if (fragend >= endbit)
goto error;
total += fragend + 1 - start;
} while (frag >= idlen + 1);
if (frag != 0)
printk(KERN_ERR "adfs: undersized free fragment\n");
return total;
error:
printk(KERN_ERR "adfs: oversized free fragment\n");
return 0;
}
static int scan_map(struct adfs_sb_info *asb, unsigned int zone,
const u32 frag_id, unsigned int mapoff)
{
const unsigned int idlen = asb->s_idlen;
struct adfs_discmap *dm, *dm_end;
int result;
dm = asb->s_map + zone;
zone = asb->s_map_size;
dm_end = asb->s_map + zone;
do {
result = lookup_zone(dm, idlen, frag_id, &mapoff);
if (result != -1)
goto found;
dm ++;
if (dm == dm_end)
Annotation
- Immediate include surface: `linux/slab.h`, `linux/statfs.h`, `linux/unaligned.h`, `adfs.h`.
- Detected declarations: `function lookup_zone`, `function scan_free_map`, `function scan_map`, `function adfs_map_statfs`, `function adfs_map_lookup`, `function adfs_calczonecheck`, `function adfs_checkmap`, `function adfs_map_layout`, `function adfs_map_read`, `function adfs_map_relse`.
- 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.