kernel/sysctl.c
Source file repositories/reference/linux-study-clean/kernel/sysctl.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/sysctl.c- Extension
.c- Size
- 36285 bytes
- Lines
- 1439
- Domain
- Core OS
- Bucket
- Scheduler, Processes, Timers, Sync, And Syscalls
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/sysctl.hlinux/bitmap.hlinux/proc_fs.hlinux/ctype.hlinux/init.hlinux/kernel.hlinux/kobject.hlinux/highuid.hlinux/writeback.hlinux/initrd.hlinux/limits.hlinux/syscalls.hlinux/capability.h../lib/kstrtox.hlinux/uaccess.hasm/processor.h
Detected Declarations
enum sysctl_writes_modefunction _proc_do_stringfunction warn_sysctl_writefunction proc_first_pos_non_zero_ignorefunction proc_dostringfunction proc_skip_spacesfunction proc_skip_charfunction strtoul_lenientfunction existsfunction proc_put_longfunction proc_put_charfunction proc_uint_u2k_conv_uopfunction proc_uint_k2u_convfunction proc_uint_convfunction proc_uint_u2k_convfunction do_proc_uint_convfunction do_proc_uint_conv_minmaxfunction proc_int_k2u_conv_kopfunction proc_int_u2k_conv_uopfunction proc_int_convfunction sysctl_user_to_kern_int_convfunction sysctl_kern_to_user_int_convfunction do_proc_int_convfunction do_proc_int_conv_minmaxfunction do_proc_dointvecfunction do_proc_douintvec_wfunction do_proc_douintvec_rfunction do_proc_douintvecfunction proc_douintvec_convfunction proc_dointvecfunction proc_douintvecfunction SYSCTL_USER_TO_KERNfunction SYSCTL_USER_TO_KERNfunction SYSCTL_USER_TO_KERNfunction do_proc_doulongvec_minmaxfunction proc_doulongvec_minmax_convfunction proc_doulongvec_minmaxfunction proc_dointvec_convfunction formatfunction leftfunction proc_dostringfunction proc_doboolfunction proc_dointvecfunction proc_douintvecfunction proc_dointvec_minmaxfunction proc_douintvec_minmaxfunction proc_douintvec_convfunction proc_uint_k2u_conv
Annotated Snippet
if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
/* Only continue writes not past the end of buffer. */
len = strlen(data);
if (len > maxlen - 1)
len = maxlen - 1;
if (*ppos > len)
return 0;
len = *ppos;
} else {
/* Start writing from beginning of buffer. */
len = 0;
}
*ppos += *lenp;
p = buffer;
while ((p - buffer) < *lenp && len < maxlen - 1) {
c = *(p++);
if (c == 0 || c == '\n')
break;
data[len++] = c;
}
data[len] = 0;
} else {
len = strlen(data);
if (len > maxlen)
len = maxlen;
if (*ppos > len) {
*lenp = 0;
return 0;
}
data += *ppos;
len -= *ppos;
if (len > *lenp)
len = *lenp;
if (len)
memcpy(buffer, data, len);
if (len < *lenp) {
buffer[len] = '\n';
len++;
}
*lenp = len;
*ppos += len;
}
return 0;
}
static void warn_sysctl_write(const struct ctl_table *table)
{
pr_warn_once("%s wrote to %s when file position was not 0!\n"
"This will not be supported in the future. To silence this\n"
"warning, set kernel.sysctl_writes_strict = -1\n",
current->comm, table->procname);
}
/**
* proc_first_pos_non_zero_ignore - check if first position is allowed
* @ppos: file position
* @table: the sysctl table
*
* Returns true if the first position is non-zero and the sysctl_writes_strict
* mode indicates this is not allowed for numeric input types. String proc
* handlers can ignore the return value.
*/
static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
const struct ctl_table *table)
{
if (!*ppos)
return false;
switch (sysctl_writes_strict) {
case SYSCTL_WRITES_STRICT:
return true;
case SYSCTL_WRITES_WARN:
warn_sysctl_write(table);
return false;
default:
return false;
}
}
/**
* proc_dostring - read a string sysctl
* @table: the sysctl table
* @dir: %TRUE if this is a write to the sysctl file
* @buffer: the user buffer
* @lenp: the size of the user buffer
Annotation
- Immediate include surface: `linux/sysctl.h`, `linux/bitmap.h`, `linux/proc_fs.h`, `linux/ctype.h`, `linux/init.h`, `linux/kernel.h`, `linux/kobject.h`, `linux/highuid.h`.
- Detected declarations: `enum sysctl_writes_mode`, `function _proc_do_string`, `function warn_sysctl_write`, `function proc_first_pos_non_zero_ignore`, `function proc_dostring`, `function proc_skip_spaces`, `function proc_skip_char`, `function strtoul_lenient`, `function exists`, `function proc_put_long`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: integration 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.