fs/afs/file.c
Source file repositories/reference/linux-study-clean/fs/afs/file.c
File Facts
- System
- Linux kernel
- Corpus path
fs/afs/file.c- Extension
.c- Size
- 14616 bytes
- Lines
- 597
- 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/kernel.hlinux/module.hlinux/init.hlinux/fs.hlinux/pagemap.hlinux/writeback.hlinux/gfp.hlinux/task_io_accounting_ops.hlinux/mm.hlinux/swap.hlinux/netfs.htrace/events/netfs.hinternal.h
Detected Declarations
function afs_put_wb_keyfunction afs_cache_wb_keyfunction afs_openfunction afs_releasefunction afs_fetch_data_notifyfunction afs_fetch_data_successfunction afs_fetch_data_abortedfunction afs_issue_read_callfunction afs_end_readfunction afs_read_receivefunction afs_fetch_data_async_rxfunction afs_fetch_data_immediate_cancelfunction afs_issue_readfunction afs_init_requestfunction afs_check_write_beginfunction afs_free_requestfunction afs_set_i_sizefunction afs_update_i_sizefunction afs_netfs_invalidate_cachefunction afs_add_open_mmapfunction afs_drop_open_mmapfunction afs_file_mmap_preparefunction afs_mappedfunction afs_vm_openfunction afs_vm_closefunction afs_vm_map_pagesfunction afs_file_read_iterfunction afs_file_splice_read
Annotated Snippet
const struct file_operations afs_file_operations = {
.open = afs_open,
.release = afs_release,
.llseek = generic_file_llseek,
.read_iter = afs_file_read_iter,
.write_iter = netfs_file_write_iter,
.mmap_prepare = afs_file_mmap_prepare,
.splice_read = afs_file_splice_read,
.splice_write = iter_file_splice_write,
.fsync = afs_fsync,
.lock = afs_lock,
.flock = afs_flock,
};
const struct inode_operations afs_file_inode_operations = {
.getattr = afs_getattr,
.setattr = afs_setattr,
.permission = afs_permission,
};
const struct address_space_operations afs_file_aops = {
.direct_IO = noop_direct_IO,
.read_folio = netfs_read_folio,
.readahead = netfs_readahead,
.dirty_folio = netfs_dirty_folio,
.release_folio = netfs_release_folio,
.invalidate_folio = netfs_invalidate_folio,
.migrate_folio = filemap_migrate_folio,
.writepages = afs_writepages,
};
static const struct vm_operations_struct afs_vm_ops = {
.mapped = afs_mapped,
.open = afs_vm_open,
.close = afs_vm_close,
.fault = filemap_fault,
.map_pages = afs_vm_map_pages,
.page_mkwrite = afs_page_mkwrite,
};
/*
* Discard a pin on a writeback key.
*/
void afs_put_wb_key(struct afs_wb_key *wbk)
{
if (wbk && refcount_dec_and_test(&wbk->usage)) {
key_put(wbk->key);
kfree(wbk);
}
}
/*
* Cache key for writeback.
*/
int afs_cache_wb_key(struct afs_vnode *vnode, struct afs_file *af)
{
struct afs_wb_key *wbk, *p;
wbk = kzalloc_obj(struct afs_wb_key);
if (!wbk)
return -ENOMEM;
refcount_set(&wbk->usage, 2);
wbk->key = af->key;
spin_lock(&vnode->wb_lock);
list_for_each_entry(p, &vnode->wb_keys, vnode_link) {
if (p->key == wbk->key)
goto found;
}
key_get(wbk->key);
list_add_tail(&wbk->vnode_link, &vnode->wb_keys);
spin_unlock(&vnode->wb_lock);
af->wb = wbk;
return 0;
found:
refcount_inc(&p->usage);
spin_unlock(&vnode->wb_lock);
af->wb = p;
kfree(wbk);
return 0;
}
/*
* open an AFS file or directory and attach a key to it
*/
int afs_open(struct inode *inode, struct file *file)
{
struct afs_vnode *vnode = AFS_FS_I(inode);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/init.h`, `linux/fs.h`, `linux/pagemap.h`, `linux/writeback.h`, `linux/gfp.h`, `linux/task_io_accounting_ops.h`.
- Detected declarations: `function afs_put_wb_key`, `function afs_cache_wb_key`, `function afs_open`, `function afs_release`, `function afs_fetch_data_notify`, `function afs_fetch_data_success`, `function afs_fetch_data_aborted`, `function afs_issue_read_call`, `function afs_end_read`, `function afs_read_receive`.
- 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.