kernel/bpf/inode.c
Source file repositories/reference/linux-study-clean/kernel/bpf/inode.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/bpf/inode.c- Extension
.c- Size
- 29717 bytes
- Lines
- 1320
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/init.hlinux/magic.hlinux/major.hlinux/mount.hlinux/namei.hlinux/fs.hlinux/fs_context.hlinux/fs_parser.hlinux/kdev_t.hlinux/filter.hlinux/bpf.hlinux/bpf_trace.hlinux/kstrtox.hlinux/xattr.hlinux/security.hpreload/bpf_preload.h
Detected Declarations
struct bpf_fs_inodestruct map_iterstruct bpffs_btf_enumsenum bpf_typefunction bpf_any_putfunction bpf_inode_typefunction bpf_dentry_finalizefunction map_iter_freefunction map_seq_stopfunction bpffs_map_openfunction bpffs_map_releasefunction bpffs_obj_openfunction bpf_mkobj_opsfunction bpf_mkprogfunction bpf_mkmapfunction bpf_mklinkfunction bpf_lookupfunction bpf_symlinkfunction bpf_iter_link_pin_kernelfunction bpf_obj_do_pinfunction bpf_obj_pin_userfunction bpf_obj_get_userfunction find_bpffs_btf_enumsfunction find_btf_enum_constfunction seq_print_delegate_optsfunction bpf_show_optionsfunction bpf_destroy_inodefunction pathwalkfunction bpf_fs_xattr_getfunction bpf_fs_xattr_setfunction bpf_fs_listxattrfunction bpf_fs_initxattrsfunction bpf_parse_paramfunction bpf_preload_mod_getfunction bpf_preload_mod_putfunction populate_bpffsfunction bpf_fill_superfunction bpf_get_treefunction bpf_free_fcfunction bpf_init_fs_contextfunction bpf_kill_superfunction bpf_fs_inode_init_oncefunction bpf_initmodule init bpf_initexport bpf_prog_get_type_pathexport bpf_preload_ops
Annotated Snippet
static const struct file_operations bpffs_map_fops = {
.open = bpffs_map_open,
.read = seq_read,
.release = bpffs_map_release,
};
static int bpffs_obj_open(struct inode *inode, struct file *file)
{
return -EIO;
}
static const struct file_operations bpffs_obj_fops = {
.open = bpffs_obj_open,
};
static int bpf_mkobj_ops(struct dentry *dentry, umode_t mode, void *raw,
const struct inode_operations *iops,
const struct file_operations *fops)
{
struct inode *dir = dentry->d_parent->d_inode;
struct inode *inode;
int ret;
inode = bpf_get_inode(dir->i_sb, dir, mode);
if (IS_ERR(inode))
return PTR_ERR(inode);
ret = security_inode_init_security(inode, dir, &dentry->d_name,
bpf_fs_initxattrs, NULL);
if (ret && ret != -EOPNOTSUPP) {
iput(inode);
return ret;
}
inode->i_op = iops;
inode->i_fop = fops;
inode->i_private = raw;
bpf_dentry_finalize(dentry, inode, dir);
return 0;
}
static int bpf_mkprog(struct dentry *dentry, umode_t mode, void *arg)
{
return bpf_mkobj_ops(dentry, mode, arg, &bpf_prog_iops,
&bpffs_obj_fops);
}
static int bpf_mkmap(struct dentry *dentry, umode_t mode, void *arg)
{
struct bpf_map *map = arg;
return bpf_mkobj_ops(dentry, mode, arg, &bpf_map_iops,
bpf_map_support_seq_show(map) ?
&bpffs_map_fops : &bpffs_obj_fops);
}
static int bpf_mklink(struct dentry *dentry, umode_t mode, void *arg)
{
struct bpf_link *link = arg;
return bpf_mkobj_ops(dentry, mode, arg, &bpf_link_iops,
bpf_link_is_iter(link) ?
&bpf_iter_fops : &bpffs_obj_fops);
}
static struct dentry *
bpf_lookup(struct inode *dir, struct dentry *dentry, unsigned flags)
{
/* Dots in names (e.g. "/sys/fs/bpf/foo.bar") are reserved for future
* extensions. That allows popoulate_bpffs() create special files.
*/
if ((dir->i_mode & S_IALLUGO) &&
strchr(dentry->d_name.name, '.'))
return ERR_PTR(-EPERM);
return simple_lookup(dir, dentry, flags);
}
static int bpf_symlink(struct mnt_idmap *idmap, struct inode *dir,
struct dentry *dentry, const char *target)
{
struct inode *inode;
char *link;
int ret;
link = kstrdup(target, GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
if (!link)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/init.h`, `linux/magic.h`, `linux/major.h`, `linux/mount.h`, `linux/namei.h`, `linux/fs.h`, `linux/fs_context.h`, `linux/fs_parser.h`.
- Detected declarations: `struct bpf_fs_inode`, `struct map_iter`, `struct bpffs_btf_enums`, `enum bpf_type`, `function bpf_any_put`, `function bpf_inode_type`, `function bpf_dentry_finalize`, `function map_iter_free`, `function map_seq_stop`, `function bpffs_map_open`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.