fs/proc/proc_sysctl.c
Source file repositories/reference/linux-study-clean/fs/proc/proc_sysctl.c
File Facts
- System
- Linux kernel
- Corpus path
fs/proc/proc_sysctl.c- Extension
.c- Size
- 45241 bytes
- Lines
- 1726
- 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/init.hlinux/sysctl.hlinux/poll.hlinux/proc_fs.hlinux/printk.hlinux/security.hlinux/sched.hlinux/cred.hlinux/namei.hlinux/mm.hlinux/uio.hlinux/module.hlinux/bpf-cgroup.hlinux/mount.hlinux/kmemleak.hlinux/lockdep.hinternal.h
Detected Declarations
struct sysctl_aliasfunction register_sysctl_mount_pointfunction proc_sys_poll_notifyfunction sysctl_print_dirfunction namecmpfunction insert_entryfunction erase_entryfunction init_headerfunction list_for_each_table_entryfunction erase_headerfunction insert_headerfunction use_tablefunction unuse_tablefunction proc_sys_invalidate_dcachefunction start_unregisteringfunction sysctl_head_finishfunction lookup_header_setfunction first_entryfunction next_entryfunction test_permfunction sysctl_permfunction proc_sys_evict_inodefunction proc_sys_call_handlerfunction proc_sys_readfunction proc_sys_writefunction proc_sys_openfunction proc_sys_pollfunction proc_sys_fill_cachefunction proc_sys_link_fill_cachefunction scanfunction proc_sys_readdirfunction proc_sys_permissionfunction proc_sys_setattrfunction proc_sys_getattrfunction proc_sys_revalidatefunction proc_sys_deletefunction sysctl_is_seenfunction proc_sys_comparefunction sysctl_follow_linkfunction sysctl_errfunction sysctl_check_table_arrayfunction sysctl_check_tablefunction list_for_each_table_entryfunction get_linksfunction insert_linksfunction proc_dostringfunction unregister_sysctl_tablefunction __register_sysctl_init
Annotated Snippet
static const struct file_operations proc_sys_file_operations;
static const struct inode_operations proc_sys_inode_operations;
static const struct file_operations proc_sys_dir_file_operations;
static const struct inode_operations proc_sys_dir_operations;
/*
* Support for permanently empty directories.
* Must be non-empty to avoid sharing an address with other tables.
*/
static const struct ctl_table sysctl_mount_point[] = {
{ }
};
/**
* register_sysctl_mount_point() - registers a sysctl mount point
* @path: path for the mount point
*
* Used to create a permanently empty directory to serve as mount point.
* There are some subtle but important permission checks this allows in the
* case of unprivileged mounts.
*/
struct ctl_table_header *register_sysctl_mount_point(const char *path)
{
return register_sysctl_sz(path, sysctl_mount_point, 0);
}
EXPORT_SYMBOL(register_sysctl_mount_point);
#define sysctl_is_perm_empty_ctl_header(hptr) \
(hptr->type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
#define sysctl_set_perm_empty_ctl_header(hptr) \
(hptr->type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
#define sysctl_clear_perm_empty_ctl_header(hptr) \
(hptr->type = SYSCTL_TABLE_TYPE_DEFAULT)
void proc_sys_poll_notify(struct ctl_table_poll *poll)
{
if (!poll)
return;
atomic_inc(&poll->event);
wake_up_interruptible(&poll->wait);
}
static const struct ctl_table root_table[] = {
{
.procname = "",
.mode = S_IFDIR|S_IRUGO|S_IXUGO,
},
};
static struct ctl_table_root sysctl_table_root = {
.default_set.dir.header = {
{{.count = 1,
.nreg = 1,
.ctl_table = root_table }},
.ctl_table_arg = root_table,
.root = &sysctl_table_root,
.set = &sysctl_table_root.default_set,
},
};
static DEFINE_SPINLOCK(sysctl_lock);
static void drop_sysctl_table(struct ctl_table_header *header);
static int sysctl_follow_link(struct ctl_table_header **phead,
const struct ctl_table **pentry);
static int insert_links(struct ctl_table_header *head);
static void put_links(struct ctl_table_header *header);
static void sysctl_print_dir(struct ctl_dir *dir)
{
if (dir->header.parent)
sysctl_print_dir(dir->header.parent);
pr_cont("%s/", dir->header.ctl_table[0].procname);
}
static int namecmp(const char *name1, int len1, const char *name2, int len2)
{
int cmp;
cmp = memcmp(name1, name2, min(len1, len2));
if (cmp == 0)
cmp = len1 - len2;
return cmp;
}
static const struct ctl_table *find_entry(struct ctl_table_header **phead,
struct ctl_dir *dir, const char *name, int namelen)
{
struct ctl_table_header *head;
const struct ctl_table *entry;
Annotation
- Immediate include surface: `linux/init.h`, `linux/sysctl.h`, `linux/poll.h`, `linux/proc_fs.h`, `linux/printk.h`, `linux/security.h`, `linux/sched.h`, `linux/cred.h`.
- Detected declarations: `struct sysctl_alias`, `function register_sysctl_mount_point`, `function proc_sys_poll_notify`, `function sysctl_print_dir`, `function namecmp`, `function insert_entry`, `function erase_entry`, `function init_header`, `function list_for_each_table_entry`, `function erase_header`.
- 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.