fs/kernfs/file.c
Source file repositories/reference/linux-study-clean/fs/kernfs/file.c
File Facts
- System
- Linux kernel
- Corpus path
fs/kernfs/file.c- Extension
.c- Size
- 28025 bytes
- Lines
- 1086
- 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/seq_file.hlinux/slab.hlinux/poll.hlinux/pagemap.hlinux/sched/mm.hlinux/fsnotify.hlinux/uio.hkernfs-internal.h
Detected Declarations
struct kernfs_open_nodefunction kernfs_put_active_offunction kernfs_open_file_mutex_ptrfunction kernfs_seq_stopfunction kernfs_seq_stopfunction kernfs_seq_showfunction readfunction kernfs_fop_read_iterfunction kernfs_fop_write_iterfunction kernfs_vma_openfunction kernfs_vma_faultfunction kernfs_vma_page_mkwritefunction kernfs_vma_accessfunction kernfs_fop_mmapfunction contextfunction kernfs_unlink_open_filefunction kernfs_fop_openfunction kernfs_release_filefunction kernfs_fop_releasefunction kernfs_should_drain_open_filesfunction kernfs_drain_open_filesfunction list_for_each_entryfunction pollfunction kernfs_fop_pollfunction kernfs_fop_llseekfunction kernfs_notify_workfnfunction kernfs_notifyexport kernfs_notify
Annotated Snippet
const struct file_operations kernfs_file_fops = {
.read_iter = kernfs_fop_read_iter,
.write_iter = kernfs_fop_write_iter,
.llseek = kernfs_fop_llseek,
.mmap = kernfs_fop_mmap,
.open = kernfs_fop_open,
.release = kernfs_fop_release,
.poll = kernfs_fop_poll,
.fsync = noop_fsync,
.splice_read = copy_splice_read,
.splice_write = iter_file_splice_write,
};
/**
* __kernfs_create_file - kernfs internal function to create a file
* @parent: directory to create the file in
* @name: name of the file
* @mode: mode of the file
* @uid: uid of the file
* @gid: gid of the file
* @size: size of the file
* @ops: kernfs operations for the file
* @priv: private data for the file
* @ns: optional namespace tag of the file
* @key: lockdep key for the file's active_ref, %NULL to disable lockdep
*
* Return: the created node on success, ERR_PTR() value on error.
*/
struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
const char *name,
umode_t mode, kuid_t uid, kgid_t gid,
loff_t size,
const struct kernfs_ops *ops,
void *priv, const struct ns_common *ns,
struct lock_class_key *key)
{
struct kernfs_node *kn;
unsigned flags;
int rc;
flags = KERNFS_FILE;
kn = kernfs_new_node(parent, name, (mode & S_IALLUGO) | S_IFREG,
uid, gid, flags);
if (!kn)
return ERR_PTR(-ENOMEM);
kn->attr.ops = ops;
kn->attr.size = size;
kn->ns = ns;
kn->priv = priv;
#ifdef CONFIG_DEBUG_LOCK_ALLOC
if (key) {
lockdep_init_map(&kn->dep_map, "kn->active", key, 0);
kn->flags |= KERNFS_LOCKDEP;
}
#endif
/*
* kn->attr.ops is accessible only while holding active ref. We
* need to know whether some ops are implemented outside active
* ref. Cache their existence in flags.
*/
if (ops->seq_show)
kn->flags |= KERNFS_HAS_SEQ_SHOW;
if (ops->mmap)
kn->flags |= KERNFS_HAS_MMAP;
if (ops->release)
kn->flags |= KERNFS_HAS_RELEASE;
rc = kernfs_add_one(kn);
if (rc) {
kernfs_put(kn);
return ERR_PTR(rc);
}
return kn;
}
Annotation
- Immediate include surface: `linux/fs.h`, `linux/seq_file.h`, `linux/slab.h`, `linux/poll.h`, `linux/pagemap.h`, `linux/sched/mm.h`, `linux/fsnotify.h`, `linux/uio.h`.
- Detected declarations: `struct kernfs_open_node`, `function kernfs_put_active_of`, `function kernfs_open_file_mutex_ptr`, `function kernfs_seq_stop`, `function kernfs_seq_stop`, `function kernfs_seq_show`, `function read`, `function kernfs_fop_read_iter`, `function kernfs_fop_write_iter`, `function kernfs_vma_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.