fs/hfsplus/extents.c
Source file repositories/reference/linux-study-clean/fs/hfsplus/extents.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hfsplus/extents.c- Extension
.c- Size
- 16133 bytes
- Lines
- 635
- 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
linux/errno.hlinux/fs.hlinux/pagemap.hhfsplus_fs.hhfsplus_raw.h
Detected Declarations
function Copyrightfunction hfsplus_ext_build_keyfunction hfsplus_ext_find_blockfunction hfsplus_ext_block_countfunction hfsplus_ext_lastblockfunction __hfsplus_ext_write_extentfunction hfsplus_ext_write_extent_lockedfunction hfsplus_ext_write_extentfunction __hfsplus_ext_read_extentfunction __hfsplus_ext_cache_extentfunction hfsplus_ext_read_extentfunction hfsplus_get_blockfunction hfsplus_dump_extentfunction hfsplus_add_extentfunction hfsplus_free_extentsfunction hfsplus_free_forkfunction hfsplus_file_extendfunction hfsplus_file_truncate
Annotated Snippet
if (ablock >= hip->alloc_blocks) {
res = hfsplus_file_extend(inode, false);
if (res)
return res;
}
} else
create = 0;
if (ablock < hip->first_blocks) {
dblock = hfsplus_ext_find_block(hip->first_extents, ablock);
goto done;
}
if (inode->i_ino == HFSPLUS_EXT_CNID)
return -EIO;
mutex_lock(&hip->extents_lock);
/*
* hfsplus_ext_read_extent will write out a cached extent into
* the extents btree. In that case we may have to mark the inode
* dirty even for a pure read of an extent here.
*/
was_dirty = (hip->extent_state & HFSPLUS_EXT_DIRTY);
res = hfsplus_ext_read_extent(inode, ablock);
if (res) {
mutex_unlock(&hip->extents_lock);
return -EIO;
}
dblock = hfsplus_ext_find_block(hip->cached_extents,
ablock - hip->cached_start);
mutex_unlock(&hip->extents_lock);
done:
hfs_dbg("ino %llu, iblock %llu - dblock %u\n",
inode->i_ino, (long long)iblock, dblock);
mask = (1 << sbi->fs_shift) - 1;
sector = ((sector_t)dblock << sbi->fs_shift) +
sbi->blockoffset + (iblock & mask);
map_bh(bh_result, sb, sector);
if (create) {
set_buffer_new(bh_result);
hip->phys_size += sb->s_blocksize;
hip->fs_blocks++;
inode_add_bytes(inode, sb->s_blocksize);
}
if (create || was_dirty)
mark_inode_dirty(inode);
return 0;
}
static void hfsplus_dump_extent(struct hfsplus_extent *extent)
{
int i;
hfs_dbg("extent ");
for (i = 0; i < 8; i++)
hfs_dbg(" start_block %u, block_count %u",
be32_to_cpu(extent[i].start_block),
be32_to_cpu(extent[i].block_count));
hfs_dbg("\n");
}
static int hfsplus_add_extent(struct hfsplus_extent *extent, u32 offset,
u32 alloc_block, u32 block_count)
{
u32 count, start;
int i;
hfsplus_dump_extent(extent);
for (i = 0; i < 8; extent++, i++) {
count = be32_to_cpu(extent->block_count);
if (offset == count) {
start = be32_to_cpu(extent->start_block);
if (alloc_block != start + count) {
if (++i >= 8)
return -ENOSPC;
extent++;
extent->start_block = cpu_to_be32(alloc_block);
} else
block_count += count;
extent->block_count = cpu_to_be32(block_count);
return 0;
} else if (offset < count)
break;
offset -= count;
}
/* panic? */
Annotation
- Immediate include surface: `linux/errno.h`, `linux/fs.h`, `linux/pagemap.h`, `hfsplus_fs.h`, `hfsplus_raw.h`.
- Detected declarations: `function Copyright`, `function hfsplus_ext_build_key`, `function hfsplus_ext_find_block`, `function hfsplus_ext_block_count`, `function hfsplus_ext_lastblock`, `function __hfsplus_ext_write_extent`, `function hfsplus_ext_write_extent_locked`, `function hfsplus_ext_write_extent`, `function __hfsplus_ext_read_extent`, `function __hfsplus_ext_cache_extent`.
- 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.