fs/hfs/inode.c
Source file repositories/reference/linux-study-clean/fs/hfs/inode.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hfs/inode.c- Extension
.c- Size
- 19722 bytes
- Lines
- 734
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/pagemap.hlinux/mpage.hlinux/sched.hlinux/cred.hlinux/uio.hlinux/xattr.hlinux/blkdev.hlinux/fileattr.hhfs_fs.hbtree.h
Detected Declarations
struct hfs_iget_datafunction hfs_read_foliofunction hfs_write_failedfunction hfs_write_beginfunction hfs_bmapfunction hfs_release_foliofunction hfs_direct_IOfunction hfs_writepagesfunction hfs_delete_inodefunction hfs_inode_read_forkfunction hfs_test_inodefunction hfs_read_inodefunction __hfs_igetfunction hfs_inode_write_forkfunction hfs_write_inodefunction hfs_evict_inodefunction hfs_file_openfunction hfs_file_releasefunction hfs_inode_setattrfunction hfs_file_fsyncfunction hfs_fileattr_get
Annotated Snippet
static const struct file_operations hfs_file_operations;
static const struct inode_operations hfs_file_inode_operations;
/*================ Variable-like macros ================*/
#define HFS_VALID_MODE_BITS (S_IFREG | S_IFDIR | S_IRWXUGO)
static int hfs_read_folio(struct file *file, struct folio *folio)
{
return block_read_full_folio(folio, hfs_get_block);
}
static void hfs_write_failed(struct address_space *mapping, loff_t to)
{
struct inode *inode = mapping->host;
if (to > inode->i_size) {
truncate_pagecache(inode, inode->i_size);
hfs_file_truncate(inode);
}
}
int hfs_write_begin(const struct kiocb *iocb, struct address_space *mapping,
loff_t pos, unsigned int len, struct folio **foliop,
void **fsdata)
{
int ret;
ret = cont_write_begin(iocb, mapping, pos, len, foliop, fsdata,
hfs_get_block,
&HFS_I(mapping->host)->phys_size);
if (unlikely(ret))
hfs_write_failed(mapping, pos + len);
return ret;
}
static sector_t hfs_bmap(struct address_space *mapping, sector_t block)
{
return generic_block_bmap(mapping, block, hfs_get_block);
}
static bool hfs_release_folio(struct folio *folio, gfp_t mask)
{
struct inode *inode = folio->mapping->host;
struct super_block *sb = inode->i_sb;
struct hfs_btree *tree;
struct hfs_bnode *node;
u32 nidx;
int i;
bool res = true;
switch (inode->i_ino) {
case HFS_EXT_CNID:
tree = HFS_SB(sb)->ext_tree;
break;
case HFS_CAT_CNID:
tree = HFS_SB(sb)->cat_tree;
break;
default:
BUG();
return false;
}
if (!tree)
return false;
if (tree->node_size >= PAGE_SIZE) {
nidx = folio->index >> (tree->node_size_shift - PAGE_SHIFT);
spin_lock(&tree->hash_lock);
node = hfs_bnode_findhash(tree, nidx);
if (!node)
;
else if (atomic_read(&node->refcnt))
res = false;
if (res && node) {
hfs_bnode_unhash(node);
hfs_bnode_free(node);
}
spin_unlock(&tree->hash_lock);
} else {
nidx = folio->index << (PAGE_SHIFT - tree->node_size_shift);
i = 1 << (PAGE_SHIFT - tree->node_size_shift);
spin_lock(&tree->hash_lock);
do {
node = hfs_bnode_findhash(tree, nidx++);
if (!node)
continue;
if (atomic_read(&node->refcnt)) {
res = false;
Annotation
- Immediate include surface: `linux/pagemap.h`, `linux/mpage.h`, `linux/sched.h`, `linux/cred.h`, `linux/uio.h`, `linux/xattr.h`, `linux/blkdev.h`, `linux/fileattr.h`.
- Detected declarations: `struct hfs_iget_data`, `function hfs_read_folio`, `function hfs_write_failed`, `function hfs_write_begin`, `function hfs_bmap`, `function hfs_release_folio`, `function hfs_direct_IO`, `function hfs_writepages`, `function hfs_delete_inode`, `function hfs_inode_read_fork`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: pattern 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.