fs/hpfs/alloc.c
Source file repositories/reference/linux-study-clean/fs/hpfs/alloc.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hpfs/alloc.c- Extension
.c- Size
- 14699 bytes
- Lines
- 583
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
hpfs_fn.h
Detected Declarations
function Patockafunction hpfs_claim_freefunction hpfs_claim_dirband_allocfunction hpfs_claim_dirband_freefunction chk_if_allocatedfunction sectorfunction alloc_in_bmpfunction hpfs_alloc_sectorfunction alloc_in_dirbandfunction hpfs_alloc_if_possiblefunction hpfs_free_sectorsfunction hpfs_check_free_dnodesfunction hpfs_free_dnodefunction find_runfunction do_trimfunction hpfs_trim_fs
Annotated Snippet
if (unlikely(!sbi->sb_n_free)) {
hpfs_error(s, "free count underflow, allocating sector %08x", sec);
sbi->sb_n_free = -1;
return;
}
sbi->sb_n_free--;
}
}
static void hpfs_claim_free(struct super_block *s, secno sec)
{
struct hpfs_sb_info *sbi = hpfs_sb(s);
if (sbi->sb_n_free != (unsigned)-1) {
if (unlikely(sbi->sb_n_free >= sbi->sb_fs_size)) {
hpfs_error(s, "free count overflow, freeing sector %08x", sec);
sbi->sb_n_free = -1;
return;
}
sbi->sb_n_free++;
}
}
static void hpfs_claim_dirband_alloc(struct super_block *s, secno sec)
{
struct hpfs_sb_info *sbi = hpfs_sb(s);
if (sbi->sb_n_free_dnodes != (unsigned)-1) {
if (unlikely(!sbi->sb_n_free_dnodes)) {
hpfs_error(s, "dirband free count underflow, allocating sector %08x", sec);
sbi->sb_n_free_dnodes = -1;
return;
}
sbi->sb_n_free_dnodes--;
}
}
static void hpfs_claim_dirband_free(struct super_block *s, secno sec)
{
struct hpfs_sb_info *sbi = hpfs_sb(s);
if (sbi->sb_n_free_dnodes != (unsigned)-1) {
if (unlikely(sbi->sb_n_free_dnodes >= sbi->sb_dirband_size / 4)) {
hpfs_error(s, "dirband free count overflow, freeing sector %08x", sec);
sbi->sb_n_free_dnodes = -1;
return;
}
sbi->sb_n_free_dnodes++;
}
}
/*
* Check if a sector is allocated in bitmap
* This is really slow. Turned on only if chk==2
*/
static int chk_if_allocated(struct super_block *s, secno sec, char *msg)
{
struct quad_buffer_head qbh;
__le32 *bmp;
if (!(bmp = hpfs_map_bitmap(s, sec >> 14, &qbh, "chk"))) goto fail;
if ((le32_to_cpu(bmp[(sec & 0x3fff) >> 5]) >> (sec & 0x1f)) & 1) {
hpfs_error(s, "sector '%s' - %08x not allocated in bitmap", msg, sec);
goto fail1;
}
hpfs_brelse4(&qbh);
if (sec >= hpfs_sb(s)->sb_dirband_start && sec < hpfs_sb(s)->sb_dirband_start + hpfs_sb(s)->sb_dirband_size) {
unsigned ssec = (sec - hpfs_sb(s)->sb_dirband_start) / 4;
if (!(bmp = hpfs_map_dnode_bitmap(s, &qbh))) goto fail;
if ((le32_to_cpu(bmp[ssec >> 5]) >> (ssec & 0x1f)) & 1) {
hpfs_error(s, "sector '%s' - %08x not allocated in directory bitmap", msg, sec);
goto fail1;
}
hpfs_brelse4(&qbh);
}
return 0;
fail1:
hpfs_brelse4(&qbh);
fail:
return 1;
}
/*
* Check if sector(s) have proper number and additionally check if they're
* allocated in bitmap.
*/
int hpfs_chk_sectors(struct super_block *s, secno start, int len, char *msg)
{
if (start + len < start || start < 0x12 ||
start + len > hpfs_sb(s)->sb_fs_size) {
hpfs_error(s, "sector(s) '%s' badly placed at %08x", msg, start);
return 1;
Annotation
- Immediate include surface: `hpfs_fn.h`.
- Detected declarations: `function Patocka`, `function hpfs_claim_free`, `function hpfs_claim_dirband_alloc`, `function hpfs_claim_dirband_free`, `function chk_if_allocated`, `function sector`, `function alloc_in_bmp`, `function hpfs_alloc_sector`, `function alloc_in_dirband`, `function hpfs_alloc_if_possible`.
- 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.