fs/proc/base.c
Source file repositories/reference/linux-study-clean/fs/proc/base.c
File Facts
- System
- Linux kernel
- Corpus path
fs/proc/base.c- Extension
.c- Size
- 98196 bytes
- Lines
- 3991
- 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.
- 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/uaccess.hlinux/errno.hlinux/time.hlinux/proc_fs.hlinux/stat.hlinux/task_io_accounting_ops.hlinux/init.hlinux/capability.hlinux/file.hlinux/generic-radix-tree.hlinux/string.hlinux/seq_file.hlinux/namei.hlinux/mnt_namespace.hlinux/mm.hlinux/swap.hlinux/rcupdate.hlinux/kallsyms.hlinux/stacktrace.hlinux/resource.hlinux/module.hlinux/mount.hlinux/security.hlinux/ptrace.hlinux/printk.hlinux/cache.hlinux/cgroup.hlinux/cpuset.hlinux/audit.hlinux/poll.hlinux/nsproxy.hlinux/oom.h
Detected Declarations
struct pid_entrystruct limit_namesstruct map_files_infostruct timers_privatestruct tgid_iterenum proc_mem_forcefunction early_proc_mem_force_overridefunction pid_entry_nlinkfunction get_task_rootfunction proc_cwd_linkfunction proc_root_linkfunction setproctitlefunction get_mm_cmdlinefunction get_task_cmdlinefunction proc_pid_cmdline_readfunction proc_pid_wchanfunction lock_tracefunction unlock_tracefunction proc_pid_stackfunction proc_pid_schedstatfunction lstats_show_procfunction lstats_openfunction lstats_writefunction proc_oom_scorefunction proc_pid_limitsfunction proc_pid_syscallfunction proc_nochmod_setattrfunction has_pid_permissionsfunction proc_pid_permissionfunction proc_single_showfunction proc_single_openfunction proc_mem_openfunction __mem_openfunction mem_openfunction proc_mem_foll_forcefunction mem_rwfunction mem_readfunction mem_writefunction mem_lseekfunction mem_releasefunction environ_openfunction environ_readfunction auxv_openfunction auxv_readfunction oom_adj_readfunction __set_oom_adjfunction for_each_processfunction oom_adj_write
Annotated Snippet
const struct file_operations *fop;
union proc_op op;
};
#define NOD(NAME, MODE, IOP, FOP, OP) { \
.name = (NAME), \
.len = sizeof(NAME) - 1, \
.mode = MODE, \
.iop = IOP, \
.fop = FOP, \
.op = OP, \
}
#define DIR(NAME, MODE, iops, fops) \
NOD(NAME, (S_IFDIR|(MODE)), &iops, &fops, {} )
#define LNK(NAME, get_link) \
NOD(NAME, (S_IFLNK|S_IRWXUGO), \
&proc_pid_link_inode_operations, NULL, \
{ .proc_get_link = get_link } )
#define REG(NAME, MODE, fops) \
NOD(NAME, (S_IFREG|(MODE)), NULL, &fops, {})
#define ONE(NAME, MODE, show) \
NOD(NAME, (S_IFREG|(MODE)), \
NULL, &proc_single_file_operations, \
{ .proc_show = show } )
#define ATTR(LSMID, NAME, MODE) \
NOD(NAME, (S_IFREG|(MODE)), \
NULL, &proc_pid_attr_operations, \
{ .lsmid = LSMID })
/*
* Count the number of hardlinks for the pid_entry table, excluding the .
* and .. links.
*/
static unsigned int __init pid_entry_nlink(const struct pid_entry *entries,
unsigned int n)
{
unsigned int i;
unsigned int count;
count = 2;
for (i = 0; i < n; ++i) {
if (S_ISDIR(entries[i].mode))
++count;
}
return count;
}
static int get_task_root(struct task_struct *task, struct path *root)
{
int result = -ENOENT;
task_lock(task);
if (task->fs) {
get_fs_root(task->fs, root);
result = 0;
}
task_unlock(task);
return result;
}
static int proc_cwd_link(struct dentry *dentry, struct path *path,
struct task_struct *task)
{
int result = -ENOENT;
task_lock(task);
if (task->fs) {
get_fs_pwd(task->fs, path);
result = 0;
}
task_unlock(task);
return result;
}
static int proc_root_link(struct dentry *dentry, struct path *path,
struct task_struct *task)
{
return get_task_root(task, path);
}
/*
* If the user used setproctitle(), we just get the string from
* user space at arg_start, and limit it to a maximum of one page.
*/
static ssize_t get_mm_proctitle(struct mm_struct *mm, char __user *buf,
size_t count, unsigned long pos,
unsigned long arg_start)
{
Annotation
- Immediate include surface: `linux/uaccess.h`, `linux/errno.h`, `linux/time.h`, `linux/proc_fs.h`, `linux/stat.h`, `linux/task_io_accounting_ops.h`, `linux/init.h`, `linux/capability.h`.
- Detected declarations: `struct pid_entry`, `struct limit_names`, `struct map_files_info`, `struct timers_private`, `struct tgid_iter`, `enum proc_mem_force`, `function early_proc_mem_force_override`, `function pid_entry_nlink`, `function get_task_root`, `function proc_cwd_link`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- 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.