fs/hostfs/hostfs_kern.c
Source file repositories/reference/linux-study-clean/fs/hostfs/hostfs_kern.c
File Facts
- System
- Linux kernel
- Corpus path
fs/hostfs/hostfs_kern.c- Extension
.c- Size
- 24367 bytes
- Lines
- 1097
- 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.
- 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/fs.hlinux/magic.hlinux/module.hlinux/mm.hlinux/pagemap.hlinux/statfs.hlinux/slab.hlinux/seq_file.hlinux/writeback.hlinux/mount.hlinux/fs_context.hlinux/fs_parser.hlinux/namei.hhostfs.hinit.hkern.h
Detected Declarations
struct hostfs_fs_infostruct hostfs_inode_infoenum hostfs_parmafunction hostfs_argsfunction hostfs_statfsfunction hostfs_evict_inodefunction hostfs_free_inodefunction hostfs_show_optionsfunction hostfs_readdirfunction hostfs_openfunction hostfs_file_releasefunction hostfs_fsyncfunction hostfs_writepagesfunction hostfs_read_foliofunction hostfs_write_beginfunction hostfs_write_endfunction hostfs_inode_updatefunction hostfs_inode_setfunction hostfs_inode_testfunction hostfs_createfunction hostfs_linkfunction hostfs_unlinkfunction hostfs_symlinkfunction hostfs_rmdirfunction hostfs_mknodfunction hostfs_rename2function hostfs_permissionfunction hostfs_setattrfunction hostfs_fill_superfunction hostfs_parse_paramfunction hostfs_parse_monolithicfunction hostfs_fc_get_treefunction hostfs_fc_freefunction hostfs_init_fs_contextfunction hostfs_kill_sbfunction init_hostfsfunction exit_hostfsmodule init init_hostfs
Annotated Snippet
static const struct file_operations hostfs_file_fops = {
.llseek = generic_file_llseek,
.splice_read = filemap_splice_read,
.splice_write = iter_file_splice_write,
.read_iter = generic_file_read_iter,
.write_iter = generic_file_write_iter,
.mmap_prepare = generic_file_mmap_prepare,
.open = hostfs_open,
.release = hostfs_file_release,
.fsync = hostfs_fsync,
};
static const struct file_operations hostfs_dir_fops = {
.llseek = generic_file_llseek,
.iterate_shared = hostfs_readdir,
.read = generic_read_dir,
.open = hostfs_open,
.fsync = hostfs_fsync,
};
static int hostfs_writepages(struct address_space *mapping,
struct writeback_control *wbc)
{
struct inode *inode = mapping->host;
struct folio *folio = NULL;
loff_t i_size = i_size_read(inode);
int err = 0;
while ((folio = writeback_iter(mapping, wbc, folio, &err))) {
loff_t pos = folio_pos(folio);
size_t count = folio_size(folio);
char *buffer;
int ret;
if (count > i_size - pos)
count = i_size - pos;
buffer = kmap_local_folio(folio, 0);
ret = write_file(HOSTFS_I(inode)->fd, &pos, buffer, count);
kunmap_local(buffer);
folio_unlock(folio);
if (ret != count) {
err = ret < 0 ? ret : -EIO;
mapping_set_error(mapping, err);
}
}
return err;
}
static int hostfs_read_folio(struct file *file, struct folio *folio)
{
char *buffer;
loff_t start = folio_pos(folio);
int bytes_read, ret = 0;
buffer = kmap_local_folio(folio, 0);
bytes_read = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer,
PAGE_SIZE);
if (bytes_read < 0)
ret = bytes_read;
else
buffer = folio_zero_tail(folio, bytes_read, buffer + bytes_read);
kunmap_local(buffer);
folio_end_read(folio, ret == 0);
return ret;
}
static int hostfs_write_begin(const struct kiocb *iocb,
struct address_space *mapping,
loff_t pos, unsigned len,
struct folio **foliop, void **fsdata)
{
pgoff_t index = pos >> PAGE_SHIFT;
*foliop = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping));
if (IS_ERR(*foliop))
return PTR_ERR(*foliop);
return 0;
}
static int hostfs_write_end(const struct kiocb *iocb,
struct address_space *mapping,
loff_t pos, unsigned len, unsigned copied,
struct folio *folio, void *fsdata)
{
struct inode *inode = mapping->host;
void *buffer;
Annotation
- Immediate include surface: `linux/fs.h`, `linux/magic.h`, `linux/module.h`, `linux/mm.h`, `linux/pagemap.h`, `linux/statfs.h`, `linux/slab.h`, `linux/seq_file.h`.
- Detected declarations: `struct hostfs_fs_info`, `struct hostfs_inode_info`, `enum hostfs_parma`, `function hostfs_args`, `function hostfs_statfs`, `function hostfs_evict_inode`, `function hostfs_free_inode`, `function hostfs_show_options`, `function hostfs_readdir`, `function hostfs_open`.
- 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.