fs/hfs/bitmap.c
Source file repositories/reference/linux-study-clean/fs/hfs/bitmap.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hfs/bitmap.c- Extension
.c- Size
- 5950 bytes
- Lines
- 244
- 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
hfs_fs.h
Detected Declarations
function Copyrightfunction hfs_vbm_search_freefunction hfs_clear_vbm_bits
Annotated Snippet
if (~val) {
n = be32_to_cpu(val);
mask = 1 << 31;
for (i = 0; i < 32; mask >>= 1, i++) {
if (!(n & mask))
goto found;
}
}
}
return size;
found:
start = (curr - bitmap) * 32 + i;
if (start >= size)
return start;
/* do any partial u32 at the start */
len = min(size - start, len);
while (1) {
n |= mask;
if (++i >= 32)
break;
mask >>= 1;
if (!--len || n & mask)
goto done;
}
if (!--len)
goto done;
*curr++ = cpu_to_be32(n);
/* do full u32s */
while (1) {
n = be32_to_cpu(*curr);
if (len < 32)
break;
if (n) {
len = 32;
break;
}
*curr++ = cpu_to_be32(0xffffffff);
len -= 32;
}
/* do any partial u32 at end */
mask = 1U << 31;
for (i = 0; i < len; i++) {
if (n & mask)
break;
n |= mask;
mask >>= 1;
}
done:
*curr = cpu_to_be32(n);
*max = (curr - bitmap) * 32 + i - start;
return start;
}
/*
* hfs_vbm_search_free()
*
* Description:
* Search for 'num_bits' consecutive cleared bits in the bitmap blocks of
* the hfs MDB. 'mdb' had better be locked or the returned range
* may be no longer free, when this functions returns!
* XXX Currently the search starts from bit 0, but it should start with
* the bit number stored in 's_alloc_ptr' of the MDB.
* Input Variable(s):
* struct hfs_mdb *mdb: Pointer to the hfs MDB
* u16 *num_bits: Pointer to the number of cleared bits
* to search for
* Output Variable(s):
* u16 *num_bits: The number of consecutive clear bits of the
* returned range. If the bitmap is fragmented, this will be less than
* requested and it will be zero, when the disk is full.
* Returns:
* The number of the first bit of the range of cleared bits which has been
* found. When 'num_bits' is zero, this is invalid!
* Preconditions:
* 'mdb' points to a "valid" (struct hfs_mdb).
* 'num_bits' points to a variable of type (u16), which contains
* the number of cleared bits to find.
* Postconditions:
* 'num_bits' is set to the length of the found sequence.
*/
u32 hfs_vbm_search_free(struct super_block *sb, u32 goal, u32 *num_bits)
{
void *bitmap;
u32 pos;
/* make sure we have actual work to perform */
if (!*num_bits)
return 0;
Annotation
- Immediate include surface: `hfs_fs.h`.
- Detected declarations: `function Copyright`, `function hfs_vbm_search_free`, `function hfs_clear_vbm_bits`.
- 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.